@guihz/trading-vue-editor-tes 0.0.275 → 0.0.277
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/assets/{parserTccWorker-DF7HO8qN.js → parserTccWorker-BCVw4E3z.js} +4 -4
- package/lib/assets/{scriptsRunWorker-CBj4zTFf.js → scriptsRunWorker-CsFlwqZT.js} +3 -3
- package/lib/components/editor/parseScript/parseToJs.d.ts +1 -0
- package/lib/packages/entryMethod.d.ts +1 -0
- package/lib/trading-vue-editor.cjs.methods.mjs +60 -0
- package/lib/{trading-vue-editor.umd.cjs → trading-vue-editor.cjs.packages.mjs} +25 -57
- package/lib/trading-vue-editor.es.methods.js +24182 -0
- package/lib/{trading-vue-editor.js → trading-vue-editor.es.packages.js} +4135 -8488
- package/lib/type-B7TbDTjv.js +4594 -0
- package/lib/type-CsI9kzgl.cjs +31 -0
- package/package.json +5 -5
@@ -65,7 +65,7 @@ Example:
|
|
65
65
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
66
66
|
**/(function(M,e){(function(t){var r=2e3,o={s:1,n:0,d:1};function n(q,_){if(isNaN(q=parseInt(q,10)))throw A();return q*_}function b(q,_){if(_===0)throw d();var m=Object.create(l.prototype);m.s=q<0?-1:1,q=q<0?-q:q;var L=u(q,_);return m.n=q/L,m.d=_/L,m}function z(q){for(var _={},m=q,L=2,g=4;g<=m;){for(;m%L===0;)m/=L,_[L]=(_[L]||0)+1;g+=1+2*L++}return m!==q?m>1&&(_[m]=(_[m]||0)+1):_[q]=(_[q]||0)+1,_}var i=function(q,_){var m=0,L=1,g=1,v=0,y=0,X=0,T=1,N=1,D=0,C=1,P=1,H=1,G=1e7,k;if(q!=null)if(_!==void 0){if(m=q,L=_,g=m*L,m%1!==0||L%1!==0)throw h()}else switch(typeof q){case"object":{if("d"in q&&"n"in q)m=q.n,L=q.d,"s"in q&&(m*=q.s);else if(0 in q)m=q[0],1 in q&&(L=q[1]);else throw A();g=m*L;break}case"number":{if(q<0&&(g=q,q=-q),q%1===0)m=q;else if(q>0){for(q>=1&&(N=Math.pow(10,Math.floor(1+Math.log(q)/Math.LN10)),q/=N);C<=G&&H<=G;)if(k=(D+P)/(C+H),q===k){C+H<=G?(m=D+P,L=C+H):H>C?(m=P,L=H):(m=D,L=C);break}else q>k?(D+=P,C+=H):(P+=D,H+=C),C>G?(m=P,L=H):(m=D,L=C);m*=N}else(isNaN(q)||isNaN(_))&&(L=m=NaN);break}case"string":{if(C=q.match(/\d+|./g),C===null)throw A();if(C[D]==="-"?(g=-1,D++):C[D]==="+"&&D++,C.length===D+1?y=n(C[D++],g):C[D+1]==="."||C[D]==="."?(C[D]!=="."&&(v=n(C[D++],g)),D++,(D+1===C.length||C[D+1]==="("&&C[D+3]===")"||C[D+1]==="'"&&C[D+3]==="'")&&(y=n(C[D],g),T=Math.pow(10,C[D].length),D++),(C[D]==="("&&C[D+2]===")"||C[D]==="'"&&C[D+2]==="'")&&(X=n(C[D+1],g),N=Math.pow(10,C[D+1].length)-1,D+=3)):C[D+1]==="/"||C[D+1]===":"?(y=n(C[D],g),T=n(C[D+2],1),D+=3):C[D+3]==="/"&&C[D+1]===" "&&(v=n(C[D],g),y=n(C[D+2],g),T=n(C[D+4],1),D+=5),C.length<=D){L=T*N,g=m=X+L*v+N*y;break}}default:throw A()}if(L===0)throw d();o.s=g<0?-1:1,o.n=Math.abs(m),o.d=Math.abs(L)};function s(q,_,m){for(var L=1;_>0;q=q*q%m,_>>=1)_&1&&(L=L*q%m);return L}function a(q,_){for(;_%2===0;_/=2);for(;_%5===0;_/=5);if(_===1)return 0;for(var m=10%_,L=1;m!==1;L++)if(m=m*10%_,L>r)return 0;return L}function O(q,_,m){for(var L=1,g=s(10,m,_),v=0;v<300;v++){if(L===g)return v;L=L*10%_,g=g*10%_}return 0}function u(q,_){if(!q)return _;if(!_)return q;for(;;){if(q%=_,!q)return _;if(_%=q,!_)return q}}function l(q,_){if(i(q,_),this instanceof l)q=u(o.d,o.n),this.s=o.s,this.n=o.n/q,this.d=o.d/q;else return b(o.s*o.n,o.d)}var d=function(){return new Error("Division by Zero")},A=function(){return new Error("Invalid argument")},h=function(){return new Error("Parameters must be integer")};l.prototype={s:1,n:0,d:1,abs:function(){return b(this.n,this.d)},neg:function(){return b(-this.s*this.n,this.d)},add:function(q,_){return i(q,_),b(this.s*this.n*o.d+o.s*this.d*o.n,this.d*o.d)},sub:function(q,_){return i(q,_),b(this.s*this.n*o.d-o.s*this.d*o.n,this.d*o.d)},mul:function(q,_){return i(q,_),b(this.s*o.s*this.n*o.n,this.d*o.d)},div:function(q,_){return i(q,_),b(this.s*o.s*this.n*o.d,this.d*o.n)},clone:function(){return b(this.s*this.n,this.d)},mod:function(q,_){if(isNaN(this.n)||isNaN(this.d))return new l(NaN);if(q===void 0)return b(this.s*this.n%this.d,1);if(i(q,_),o.n===0&&this.d===0)throw d();return b(this.s*(o.d*this.n)%(o.n*this.d),o.d*this.d)},gcd:function(q,_){return i(q,_),b(u(o.n,this.n)*u(o.d,this.d),o.d*this.d)},lcm:function(q,_){return i(q,_),o.n===0&&this.n===0?b(0,1):b(o.n*this.n,u(o.n,this.n)*u(o.d,this.d))},ceil:function(q){return q=Math.pow(10,q||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.ceil(q*this.s*this.n/this.d),q)},floor:function(q){return q=Math.pow(10,q||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.floor(q*this.s*this.n/this.d),q)},round:function(q){return q=Math.pow(10,q||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.round(q*this.s*this.n/this.d),q)},inverse:function(){return b(this.s*this.d,this.n)},pow:function(q,_){if(i(q,_),o.d===1)return o.s<0?b(Math.pow(this.s*this.d,o.n),Math.pow(this.n,o.n)):b(Math.pow(this.s*this.n,o.n),Math.pow(this.d,o.n));if(this.s<0)return null;var m=z(this.n),L=z(this.d),g=1,v=1;for(var y in m)if(y!=="1"){if(y==="0"){g=0;break}if(m[y]*=o.n,m[y]%o.d===0)m[y]/=o.d;else return null;g*=Math.pow(y,m[y])}for(var y in L)if(y!=="1"){if(L[y]*=o.n,L[y]%o.d===0)L[y]/=o.d;else return null;v*=Math.pow(y,L[y])}return o.s<0?b(v,g):b(g,v)},equals:function(q,_){return i(q,_),this.s*this.n*o.d===o.s*o.n*this.d},compare:function(q,_){i(q,_);var m=this.s*this.n*o.d-o.s*o.n*this.d;return(0<m)-(m<0)},simplify:function(q){if(isNaN(this.n)||isNaN(this.d))return this;q=q||.001;for(var _=this.abs(),m=_.toContinued(),L=1;L<m.length;L++){for(var g=b(m[L-1],1),v=L-2;v>=0;v--)g=g.inverse().add(m[v]);if(Math.abs(g.sub(_).valueOf())<q)return g.mul(this.s)}return this},divisible:function(q,_){return i(q,_),!(!(o.n*this.d)||this.n*o.d%(o.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(q){var _,m="",L=this.n,g=this.d;return this.s<0&&(m+="-"),g===1?m+=L:(q&&(_=Math.floor(L/g))>0&&(m+=_,m+=" ",L%=g),m+=L,m+="/",m+=g),m},toLatex:function(q){var _,m="",L=this.n,g=this.d;return this.s<0&&(m+="-"),g===1?m+=L:(q&&(_=Math.floor(L/g))>0&&(m+=_,L%=g),m+="\\frac{",m+=L,m+="}{",m+=g,m+="}"),m},toContinued:function(){var q,_=this.n,m=this.d,L=[];if(isNaN(_)||isNaN(m))return L;do L.push(Math.floor(_/m)),q=_%m,_=m,m=q;while(_!==1);return L},toString:function(q){var _=this.n,m=this.d;if(isNaN(_)||isNaN(m))return"NaN";q=q||15;var L=a(_,m),g=O(_,m,L),v=this.s<0?"-":"";if(v+=_/m|0,_%=m,_*=10,_&&(v+="."),L){for(var y=g;y--;)v+=_/m|0,_%=m,_*=10;v+="(";for(var y=L;y--;)v+=_/m|0,_%=m,_*=10;v+=")"}else for(var y=q;_&&y--;)v+=_/m|0,_%=m,_*=10;return v}},Object.defineProperty(l,"__esModule",{value:!0}),l.default=l,l.Fraction=l,M.exports=l})()})(bs);var Qd=bs.exports,tt=w1(Qd),Zd="Fraction",e5=[],t5=h0(Zd,e5,()=>(Object.defineProperty(tt,"name",{value:"Fraction"}),tt.prototype.constructor=tt,tt.prototype.type="Fraction",tt.prototype.isFraction=!0,tt.prototype.toJSON=function(){return{mathjs:"Fraction",n:this.s*this.n,d:this.d}},tt.fromJSON=function(M){return new tt(M)},tt),{isClass:!0}),r5="Matrix",M5=[],o5=h0(r5,M5,()=>{function M(){if(!(this instanceof M))throw new SyntaxError("Constructor must be called with the new operator")}return M.prototype.type="Matrix",M.prototype.isMatrix=!0,M.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},M.prototype.datatype=function(){throw new Error("Cannot invoke datatype on a Matrix interface")},M.prototype.create=function(e,t){throw new Error("Cannot invoke create on a Matrix interface")},M.prototype.subset=function(e,t,r){throw new Error("Cannot invoke subset on a Matrix interface")},M.prototype.get=function(e){throw new Error("Cannot invoke get on a Matrix interface")},M.prototype.set=function(e,t,r){throw new Error("Cannot invoke set on a Matrix interface")},M.prototype.resize=function(e,t){throw new Error("Cannot invoke resize on a Matrix interface")},M.prototype.reshape=function(e,t){throw new Error("Cannot invoke reshape on a Matrix interface")},M.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},M.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},M.prototype.map=function(e,t){throw new Error("Cannot invoke map on a Matrix interface")},M.prototype.forEach=function(e){throw new Error("Cannot invoke forEach on a Matrix interface")},M.prototype[Symbol.iterator]=function(){throw new Error("Cannot iterate a Matrix interface")},M.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},M.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},M.prototype.format=function(e){throw new Error("Cannot invoke format on a Matrix interface")},M.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},M},{isClass:!0});function ps(M){return Object.keys(M.signatures||{}).reduce(function(e,t){var r=(t.match(/,/g)||[]).length+1;return Math.max(e,r)},-1)}var n5="DenseMatrix",b5=["Matrix"],p5=h0(n5,b5,M=>{var{Matrix:e}=M;function t(a,O){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(O&&!Ee(O))throw new Error("Invalid datatype: "+O);if(F1(a))a.type==="DenseMatrix"?(this._data=_1(a._data),this._size=_1(a._size),this._datatype=O||a._datatype):(this._data=a.toArray(),this._size=a.size(),this._datatype=O||a._datatype);else if(a&&H1(a.data)&&H1(a.size))this._data=a.data,this._size=a.size,Tc(this._data,this._size),this._datatype=O||a.datatype;else if(H1(a))this._data=s(a),this._size=M2(this._data),Tc(this._data,this._size),this._datatype=O;else{if(a)throw new TypeError("Unsupported type of data ("+qt(a)+")");this._data=[],this._size=[0],this._datatype=O}}t.prototype=new e,t.prototype.createDenseMatrix=function(a,O){return new t(a,O)},Object.defineProperty(t,"name",{value:"DenseMatrix"}),t.prototype.constructor=t,t.prototype.type="DenseMatrix",t.prototype.isDenseMatrix=!0,t.prototype.getDataType=function(){return Ao(this._data,qt)},t.prototype.storage=function(){return"dense"},t.prototype.datatype=function(){return this._datatype},t.prototype.create=function(a,O){return new t(a,O)},t.prototype.subset=function(a,O,u){switch(arguments.length){case 1:return r(this,a);case 2:case 3:return n(this,a,O,u);default:throw new SyntaxError("Wrong number of arguments")}},t.prototype.get=function(a){if(!H1(a))throw new TypeError("Array expected");if(a.length!==this._size.length)throw new A1(a.length,this._size.length);for(var O=0;O<a.length;O++)Y1(a[O],this._size[O]);for(var u=this._data,l=0,d=a.length;l<d;l++){var A=a[l];Y1(A,u.length),u=u[A]}return u},t.prototype.set=function(a,O,u){if(!H1(a))throw new TypeError("Array expected");if(a.length<this._size.length)throw new A1(a.length,this._size.length,"<");var l,d,A,h=a.map(function(_){return _+1});i(this,h,u);var q=this._data;for(l=0,d=a.length-1;l<d;l++)A=a[l],Y1(A,q.length),q=q[A];return A=a[a.length-1],Y1(A,q.length),q[A]=O,this};function r(a,O){if(!xb(O))throw new TypeError("Invalid index");var u=O.isScalar();if(u)return a.get(O.min());var l=O.size();if(l.length!==a._size.length)throw new A1(l.length,a._size.length);for(var d=O.min(),A=O.max(),h=0,q=a._size.length;h<q;h++)Y1(d[h],a._size[h]),Y1(A[h],a._size[h]);return new t(o(a._data,O,l.length,0),a._datatype)}function o(a,O,u,l){var d=l===u-1,A=O.dimension(l);return d?A.map(function(h){return Y1(h,a.length),a[h]}).valueOf():A.map(function(h){Y1(h,a.length);var q=a[h];return o(q,O,u,l+1)}).valueOf()}function n(a,O,u,l){if(!O||O.isIndex!==!0)throw new TypeError("Invalid index");var d=O.size(),A=O.isScalar(),h;if(F1(u)?(h=u.size(),u=u.valueOf()):h=M2(u),A){if(h.length!==0)throw new TypeError("Scalar expected");a.set(O.min(),u,l)}else{if(!Wr(h,d))try{h.length===0?u=Pc([u],d):u=Pc(u,d),h=M2(u)}catch{}if(d.length<a._size.length)throw new A1(d.length,a._size.length,"<");if(h.length<d.length){for(var q=0,_=0;d[q]===1&&h[q]===1;)q++;for(;d[q]===1;)_++,q++;u=xc(u,d.length,_,h)}if(!Wr(d,h))throw new A1(d,h,">");var m=O.max().map(function(v){return v+1});i(a,m,l);var L=d.length,g=0;b(a._data,O,u,L,g)}return a}function b(a,O,u,l,d){var A=d===l-1,h=O.dimension(d);A?h.forEach(function(q,_){Y1(q),a[q]=u[_[0]]}):h.forEach(function(q,_){Y1(q),b(a[q],O,u[_[0]],l,d+1)})}t.prototype.resize=function(a,O,u){if(!aM(a))throw new TypeError("Array or Matrix expected");var l=a.valueOf().map(A=>Array.isArray(A)&&A.length===1?A[0]:A),d=u?this.clone():this;return z(d,l,O)};function z(a,O,u){if(O.length===0){for(var l=a._data;H1(l);)l=l[0];return l}return a._size=O.slice(0),a._data=kb(a._data,a._size,u),a}t.prototype.reshape=function(a,O){var u=O?this.clone():this;u._data=Ub(u._data,a);var l=u._size.reduce((d,A)=>d*A);return u._size=jb(a,l),u};function i(a,O,u){for(var l=a._size.slice(0),d=!1;l.length<O.length;)l.push(0),d=!0;for(var A=0,h=O.length;A<h;A++)O[A]>l[A]&&(l[A]=O[A],d=!0);d&&z(a,l,u)}t.prototype.clone=function(){var a=new t({data:_1(this._data),size:_1(this._size),datatype:this._datatype});return a},t.prototype.size=function(){return this._size.slice(0)},t.prototype.map=function(a){var O=this,u=ps(a),l=function h(q,_){return H1(q)?q.map(function(m,L){return h(m,_.concat(L))}):u===1?a(q):u===2?a(q,_):a(q,_,O)},d=l(this._data,[]),A=this._datatype!==void 0?Ao(d,qt):void 0;return new t(d,A)},t.prototype.forEach=function(a){var O=this,u=function l(d,A){H1(d)?d.forEach(function(h,q){l(h,A.concat(q))}):a(d,A,O)};u(this._data,[])},t.prototype[Symbol.iterator]=function*(){var a=function*O(u,l){if(H1(u))for(var d=0;d<u.length;d++)yield*O(u[d],l.concat(d));else yield{value:u,index:l}};yield*a(this._data,[])},t.prototype.rows=function(){var a=[],O=this.size();if(O.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");var u=this._data;for(var l of u)a.push(new t([l],this._datatype));return a},t.prototype.columns=function(){var a=this,O=[],u=this.size();if(u.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");for(var l=this._data,d=function(q){var _=l.map(m=>[m[q]]);O.push(new t(_,a._datatype))},A=0;A<u[1];A++)d(A);return O},t.prototype.toArray=function(){return _1(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.format=function(a){return N1(this._data,a)},t.prototype.toString=function(){return N1(this._data)},t.prototype.toJSON=function(){return{mathjs:"DenseMatrix",data:this._data,size:this._size,datatype:this._datatype}},t.prototype.diagonal=function(a){if(a){if(Q1(a)&&(a=a.toNumber()),!X1(a)||!$1(a))throw new TypeError("The parameter k must be an integer number")}else a=0;for(var O=a>0?a:0,u=a<0?-a:0,l=this._size[0],d=this._size[1],A=Math.min(l-u,d-O),h=[],q=0;q<A;q++)h[q]=this._data[q+u][q+O];return new t({data:h,size:[A],datatype:this._datatype})},t.diagonal=function(a,O,u,l){if(!H1(a))throw new TypeError("Array expected, size parameter");if(a.length!==2)throw new Error("Only two dimensions matrix are supported");if(a=a.map(function(y){if(Q1(y)&&(y=y.toNumber()),!X1(y)||!$1(y)||y<1)throw new Error("Size values must be positive integers");return y}),u){if(Q1(u)&&(u=u.toNumber()),!X1(u)||!$1(u))throw new TypeError("The parameter k must be an integer number")}else u=0;var d=u>0?u:0,A=u<0?-u:0,h=a[0],q=a[1],_=Math.min(h-A,q-d),m;if(H1(O)){if(O.length!==_)throw new Error("Invalid value array length");m=function(X){return O[X]}}else if(F1(O)){var L=O.size();if(L.length!==1||L[0]!==_)throw new Error("Invalid matrix length");m=function(X){return O.get([X])}}else m=function(){return O};l||(l=Q1(m(0))?m(0).mul(0):0);var g=[];if(a.length>0){g=kb(g,a,l);for(var v=0;v<_;v++)g[v+A][v+d]=m(v)}return new t({data:g,size:[h,q]})},t.fromJSON=function(a){return new t(a)},t.prototype.swapRows=function(a,O){if(!X1(a)||!$1(a)||!X1(O)||!$1(O))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Y1(a,this._size[0]),Y1(O,this._size[0]),t._swapRows(a,O,this._data),this},t._swapRows=function(a,O,u){var l=u[a];u[a]=u[O],u[O]=l};function s(a){return F1(a)?s(a.valueOf()):H1(a)?a.map(s):a}return t},{isClass:!0});function z5(M){var e=M.length,t=M[0].length,r,o,n=[];for(o=0;o<t;o++){var b=[];for(r=0;r<e;r++)b.push(M[r][o]);n.push(b)}return n}function Lo(M){for(var e=0;e<M.length;e++)if(aM(M[e]))return!0;return!1}function fM(M,e){F1(M)&&(M=M.valueOf());for(var t=0,r=M.length;t<r;t++){var o=M[t];Array.isArray(o)?fM(o,e):e(o)}}function ge(M,e,t){return M&&typeof M.map=="function"?M.map(function(r){return ge(r,e)}):e(M)}function tp(M,e,t){var r=Array.isArray(M)?M2(M):M.size();if(e<0||e>=r.length)throw new dt(e,r.length);return F1(M)?M.create(vo(M.valueOf(),e,t)):vo(M,e,t)}function vo(M,e,t){var r,o,n,b;if(e<=0)if(Array.isArray(M[0])){for(b=z5(M),o=[],r=0;r<b.length;r++)o[r]=vo(b[r],e-1,t);return o}else{for(n=M[0],r=1;r<M.length;r++)n=t(n,M[r]);return n}else{for(o=[],r=0;r<M.length;r++)o[r]=vo(M[r],e-1,t);return o}}var zs="isInteger",i5=["typed"],c5=h0(zs,i5,M=>{var{typed:e}=M;return e(zs,{number:$1,BigNumber:function(r){return r.isInt()},Fraction:function(r){return r.d===1&&isFinite(r.n)},"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),is="number",No="number, number";function cs(M){return Math.abs(M)}cs.signature=is;function ss(M,e){return M+e}ss.signature=No;function Os(M,e){return M-e}Os.signature=No;function as(M,e){return M*e}as.signature=No;function us(M){return-M}us.signature=is;function As(M,e){return M*M<1&&e===1/0||M*M>1&&e===-1/0?0:Math.pow(M,e)}As.signature=No;var fs="number";function ls(M){return M===0}ls.signature=fs;function qs(M){return Number.isNaN(M)}qs.signature=fs;var ds="isNumeric",s5=["typed"],O5=h0(ds,s5,M=>{var{typed:e}=M;return e(ds,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),hs="isZero",a5=["typed"],u5=h0(hs,a5,M=>{var{typed:e}=M;return e(hs,{number:ls,BigNumber:function(r){return r.isZero()},Complex:function(r){return r.re===0&&r.im===0},Fraction:function(r){return r.d===1&&r.n===0},Unit:e.referToSelf(t=>r=>e.find(t,r.valueType())(r.value)),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),Ws="isNaN",A5=["typed"],f5=h0(Ws,A5,M=>{var{typed:e}=M;return e(Ws,{number:qs,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 ge(r,Number.isNaN)}})});function yo(M,e,t){if(t==null)return M.eq(e);if(M.eq(e))return!0;if(M.isNaN()||e.isNaN())return!1;if(M.isFinite()&&e.isFinite()){var r=M.minus(e).abs();if(r.isZero())return!0;var o=M.constructor.max(M.abs(),e.abs());return r.lte(o.times(t))}return!1}function l5(M,e,t){return Ut(M.re,e.re,t)&&Ut(M.im,e.im,t)}var Bo=h0("compareUnits",["typed"],M=>{var{typed:e}=M;return{"Unit, Unit":e.referToSelf(t=>(r,o)=>{if(!r.equalBase(o))throw new Error("Cannot compare units with different base");return e.find(t,[r.valueType(),o.valueType()])(r.value,o.value)})}}),wo="equalScalar",q5=["typed","config"],d5=h0(wo,q5,M=>{var{typed:e,config:t}=M,r=Bo({typed:e});return e(wo,{"boolean, boolean":function(n,b){return n===b},"number, number":function(n,b){return Ut(n,b,t.epsilon)},"BigNumber, BigNumber":function(n,b){return n.eq(b)||yo(n,b,t.epsilon)},"Fraction, Fraction":function(n,b){return n.equals(b)},"Complex, Complex":function(n,b){return l5(n,b,t.epsilon)}},r)});h0(wo,["typed","config"],M=>{var{typed:e,config:t}=M;return e(wo,{"number, number":function(o,n){return Ut(o,n,t.epsilon)}})});var h5="SparseMatrix",W5=["typed","equalScalar","Matrix"],_5=h0(h5,W5,M=>{var{typed:e,equalScalar:t,Matrix:r}=M;function o(A,h){if(!(this instanceof o))throw new SyntaxError("Constructor must be called with the new operator");if(h&&!Ee(h))throw new Error("Invalid datatype: "+h);if(F1(A))n(this,A,h);else if(A&&H1(A.index)&&H1(A.ptr)&&H1(A.size))this._values=A.values,this._index=A.index,this._ptr=A.ptr,this._size=A.size,this._datatype=h||A.datatype;else if(H1(A))b(this,A,h);else{if(A)throw new TypeError("Unsupported type of data ("+qt(A)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=h}}function n(A,h,q){h.type==="SparseMatrix"?(A._values=h._values?_1(h._values):void 0,A._index=_1(h._index),A._ptr=_1(h._ptr),A._size=_1(h._size),A._datatype=q||h._datatype):b(A,h.valueOf(),q||h._datatype)}function b(A,h,q){A._values=[],A._index=[],A._ptr=[],A._datatype=q;var _=h.length,m=0,L=t,g=0;if(Ee(q)&&(L=e.find(t,[q,q])||t,g=e.convert(0,q)),_>0){var v=0;do{A._ptr.push(A._index.length);for(var y=0;y<_;y++){var X=h[y];if(H1(X)){if(v===0&&m<X.length&&(m=X.length),v<X.length){var T=X[v];L(T,g)||(A._values.push(T),A._index.push(y))}}else v===0&&m<1&&(m=1),L(X,g)||(A._values.push(X),A._index.push(y))}v++}while(v<m)}A._ptr.push(A._index.length),A._size=[_,m]}o.prototype=new r,o.prototype.createSparseMatrix=function(A,h){return new o(A,h)},Object.defineProperty(o,"name",{value:"SparseMatrix"}),o.prototype.constructor=o,o.prototype.type="SparseMatrix",o.prototype.isSparseMatrix=!0,o.prototype.getDataType=function(){return Ao(this._values,qt)},o.prototype.storage=function(){return"sparse"},o.prototype.datatype=function(){return this._datatype},o.prototype.create=function(A,h){return new o(A,h)},o.prototype.density=function(){var A=this._size[0],h=this._size[1];return A!==0&&h!==0?this._index.length/(A*h):0},o.prototype.subset=function(A,h,q){if(!this._values)throw new Error("Cannot invoke subset on a Pattern only matrix");switch(arguments.length){case 1:return z(this,A);case 2:case 3:return i(this,A,h,q);default:throw new SyntaxError("Wrong number of arguments")}};function z(A,h){if(!xb(h))throw new TypeError("Invalid index");var q=h.isScalar();if(q)return A.get(h.min());var _=h.size();if(_.length!==A._size.length)throw new A1(_.length,A._size.length);var m,L,g,v,y=h.min(),X=h.max();for(m=0,L=A._size.length;m<L;m++)Y1(y[m],A._size[m]),Y1(X[m],A._size[m]);var T=A._values,N=A._index,D=A._ptr,C=h.dimension(0),P=h.dimension(1),H=[],G=[];C.forEach(function(z0,a0){G[z0]=a0[0],H[z0]=!0});var k=T?[]:void 0,J=[],o0=[];return P.forEach(function(z0){for(o0.push(J.length),g=D[z0],v=D[z0+1];g<v;g++)m=N[g],H[m]===!0&&(J.push(G[m]),k&&k.push(T[g]))}),o0.push(J.length),new o({values:k,index:J,ptr:o0,size:_,datatype:A._datatype})}function i(A,h,q,_){if(!h||h.isIndex!==!0)throw new TypeError("Invalid index");var m=h.size(),L=h.isScalar(),g;if(F1(q)?(g=q.size(),q=q.toArray()):g=M2(q),L){if(g.length!==0)throw new TypeError("Scalar expected");A.set(h.min(),q,_)}else{if(m.length!==1&&m.length!==2)throw new A1(m.length,A._size.length,"<");if(g.length<m.length){for(var v=0,y=0;m[v]===1&&g[v]===1;)v++;for(;m[v]===1;)y++,v++;q=xc(q,m.length,y,g)}if(!Wr(m,g))throw new A1(m,g,">");if(m.length===1){var X=h.dimension(0);X.forEach(function(D,C){Y1(D),A.set([D,0],q[C[0]],_)})}else{var T=h.dimension(0),N=h.dimension(1);T.forEach(function(D,C){Y1(D),N.forEach(function(P,H){Y1(P),A.set([D,P],q[C[0]][H[0]],_)})})}}return A}o.prototype.get=function(A){if(!H1(A))throw new TypeError("Array expected");if(A.length!==this._size.length)throw new A1(A.length,this._size.length);if(!this._values)throw new Error("Cannot invoke get on a Pattern only matrix");var h=A[0],q=A[1];Y1(h,this._size[0]),Y1(q,this._size[1]);var _=s(h,this._ptr[q],this._ptr[q+1],this._index);return _<this._ptr[q+1]&&this._index[_]===h?this._values[_]:0},o.prototype.set=function(A,h,q){if(!H1(A))throw new TypeError("Array expected");if(A.length!==this._size.length)throw new A1(A.length,this._size.length);if(!this._values)throw new Error("Cannot invoke set on a Pattern only matrix");var _=A[0],m=A[1],L=this._size[0],g=this._size[1],v=t,y=0;Ee(this._datatype)&&(v=e.find(t,[this._datatype,this._datatype])||t,y=e.convert(0,this._datatype)),(_>L-1||m>g-1)&&(u(this,Math.max(_+1,L),Math.max(m+1,g),q),L=this._size[0],g=this._size[1]),Y1(_,L),Y1(m,g);var X=s(_,this._ptr[m],this._ptr[m+1],this._index);return X<this._ptr[m+1]&&this._index[X]===_?v(h,y)?a(X,m,this._values,this._index,this._ptr):this._values[X]=h:v(h,y)||O(X,_,m,h,this._values,this._index,this._ptr),this};function s(A,h,q,_){if(q-h===0)return q;for(var m=h;m<q;m++)if(_[m]===A)return m;return h}function a(A,h,q,_,m){q.splice(A,1),_.splice(A,1);for(var L=h+1;L<m.length;L++)m[L]--}function O(A,h,q,_,m,L,g){m.splice(A,0,_),L.splice(A,0,h);for(var v=q+1;v<g.length;v++)g[v]++}o.prototype.resize=function(A,h,q){if(!aM(A))throw new TypeError("Array or Matrix expected");var _=A.valueOf().map(L=>Array.isArray(L)&&L.length===1?L[0]:L);if(_.length!==2)throw new Error("Only two dimensions matrix are supported");_.forEach(function(L){if(!X1(L)||!$1(L)||L<0)throw new TypeError("Invalid size, must contain positive integers (size: "+N1(_)+")")});var m=q?this.clone():this;return u(m,_[0],_[1],h)};function u(A,h,q,_){var m=_||0,L=t,g=0;Ee(A._datatype)&&(L=e.find(t,[A._datatype,A._datatype])||t,g=e.convert(0,A._datatype),m=e.convert(m,A._datatype));var v=!L(m,g),y=A._size[0],X=A._size[1],T,N,D;if(q>X){for(N=X;N<q;N++)if(A._ptr[N]=A._values.length,v)for(T=0;T<y;T++)A._values.push(m),A._index.push(T);A._ptr[q]=A._values.length}else q<X&&(A._ptr.splice(q+1,X-q),A._values.splice(A._ptr[q],A._values.length),A._index.splice(A._ptr[q],A._index.length));if(X=q,h>y){if(v){var C=0;for(N=0;N<X;N++){A._ptr[N]=A._ptr[N]+C,D=A._ptr[N+1]+C;var P=0;for(T=y;T<h;T++,P++)A._values.splice(D+P,0,m),A._index.splice(D+P,0,T),C++}A._ptr[X]=A._values.length}}else if(h<y){var H=0;for(N=0;N<X;N++){A._ptr[N]=A._ptr[N]-H;var G=A._ptr[N],k=A._ptr[N+1]-H;for(D=G;D<k;D++)T=A._index[D],T>h-1&&(A._values.splice(D,1),A._index.splice(D,1),H++)}A._ptr[N]=A._values.length}return A._size[0]=h,A._size[1]=q,A}o.prototype.reshape=function(A,h){if(!H1(A))throw new TypeError("Array expected");if(A.length!==2)throw new Error("Sparse matrices can only be reshaped in two dimensions");A.forEach(function(z0){if(!X1(z0)||!$1(z0)||z0<=-2||z0===0)throw new TypeError("Invalid size, must contain positive integers or -1 (size: "+N1(A)+")")});var q=this._size[0]*this._size[1];A=jb(A,q);var _=A[0]*A[1];if(q!==_)throw new Error("Reshaping sparse matrix will result in the wrong number of elements");var m=h?this.clone():this;if(this._size[0]===A[0]&&this._size[1]===A[1])return m;for(var L=[],g=0;g<m._ptr.length;g++)for(var v=0;v<m._ptr[g+1]-m._ptr[g];v++)L.push(g);for(var y=m._values.slice(),X=m._index.slice(),T=0;T<m._index.length;T++){var N=X[T],D=L[T],C=N*m._size[1]+D;L[T]=C%A[1],X[T]=Math.floor(C/A[1])}m._values.length=0,m._index.length=0,m._ptr.length=A[1]+1,m._size=A.slice();for(var P=0;P<m._ptr.length;P++)m._ptr[P]=0;for(var H=0;H<y.length;H++){var G=X[H],k=L[H],J=y[H],o0=s(G,m._ptr[k],m._ptr[k+1],m._index);O(o0,G,k,J,m._values,m._index,m._ptr)}return m},o.prototype.clone=function(){var A=new o({values:this._values?_1(this._values):void 0,index:_1(this._index),ptr:_1(this._ptr),size:_1(this._size),datatype:this._datatype});return A},o.prototype.size=function(){return this._size.slice(0)},o.prototype.map=function(A,h){if(!this._values)throw new Error("Cannot invoke map on a Pattern only matrix");var q=this,_=this._size[0],m=this._size[1],L=ps(A),g=function(y,X,T){return L===1?A(y):L===2?A(y,[X,T]):A(y,[X,T],q)};return l(this,0,_-1,0,m-1,g,h)};function l(A,h,q,_,m,L,g){var v=[],y=[],X=[],T=t,N=0;Ee(A._datatype)&&(T=e.find(t,[A._datatype,A._datatype])||t,N=e.convert(0,A._datatype));for(var D=function(u0,I0,S0){u0=L(u0,I0,S0),T(u0,N)||(v.push(u0),y.push(I0))},C=_;C<=m;C++){X.push(v.length);var P=A._ptr[C],H=A._ptr[C+1];if(g)for(var G=P;G<H;G++){var k=A._index[G];k>=h&&k<=q&&D(A._values[G],k-h,C-_)}else{for(var J={},o0=P;o0<H;o0++){var z0=A._index[o0];J[z0]=A._values[o0]}for(var a0=h;a0<=q;a0++){var v0=a0 in J?J[a0]:0;D(v0,a0-h,C-_)}}}return X.push(v.length),new o({values:v,index:y,ptr:X,size:[q-h+1,m-_+1]})}o.prototype.forEach=function(A,h){if(!this._values)throw new Error("Cannot invoke forEach on a Pattern only matrix");for(var q=this,_=this._size[0],m=this._size[1],L=0;L<m;L++){var g=this._ptr[L],v=this._ptr[L+1];if(h)for(var y=g;y<v;y++){var X=this._index[y];A(this._values[y],[X,L],q)}else{for(var T={},N=g;N<v;N++){var D=this._index[N];T[D]=this._values[N]}for(var C=0;C<_;C++){var P=C in T?T[C]:0;A(P,[C,L],q)}}}},o.prototype[Symbol.iterator]=function*(){if(!this._values)throw new Error("Cannot iterate a Pattern only matrix");for(var A=this._size[1],h=0;h<A;h++)for(var q=this._ptr[h],_=this._ptr[h+1],m=q;m<_;m++){var L=this._index[m];yield{value:this._values[m],index:[L,h]}}},o.prototype.toArray=function(){return d(this._values,this._index,this._ptr,this._size,!0)},o.prototype.valueOf=function(){return d(this._values,this._index,this._ptr,this._size,!1)};function d(A,h,q,_,m){var L=_[0],g=_[1],v=[],y,X;for(y=0;y<L;y++)for(v[y]=[],X=0;X<g;X++)v[y][X]=0;for(X=0;X<g;X++)for(var T=q[X],N=q[X+1],D=T;D<N;D++)y=h[D],v[y][X]=A?m?_1(A[D]):A[D]:1;return v}return o.prototype.format=function(A){for(var h=this._size[0],q=this._size[1],_=this.density(),m="Sparse Matrix ["+N1(h,A)+" x "+N1(q,A)+"] density: "+N1(_,A)+`
|
67
67
|
`,L=0;L<q;L++)for(var g=this._ptr[L],v=this._ptr[L+1],y=g;y<v;y++){var X=this._index[y];m+=`
|
68
|
-
(`+N1(X,A)+", "+N1(L,A)+") ==> "+(this._values?N1(this._values[y],A):"X")}return m},o.prototype.toString=function(){return N1(this.toArray())},o.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},o.prototype.diagonal=function(A){if(A){if(Q1(A)&&(A=A.toNumber()),!X1(A)||!$1(A))throw new TypeError("The parameter k must be an integer number")}else A=0;var h=A>0?A:0,q=A<0?-A:0,_=this._size[0],m=this._size[1],L=Math.min(_-q,m-h),g=[],v=[],y=[];y[0]=0;for(var X=h;X<m&&g.length<L;X++)for(var T=this._ptr[X],N=this._ptr[X+1],D=T;D<N;D++){var C=this._index[D];if(C===X-h+q){g.push(this._values[D]),v[g.length-1]=C-q;break}}return y.push(g.length),new o({values:g,index:v,ptr:y,size:[L,1]})},o.fromJSON=function(A){return new o(A)},o.diagonal=function(A,h,q,_,m){if(!H1(A))throw new TypeError("Array expected, size parameter");if(A.length!==2)throw new Error("Only two dimensions matrix are supported");if(A=A.map(function(z0){if(Q1(z0)&&(z0=z0.toNumber()),!X1(z0)||!$1(z0)||z0<1)throw new Error("Size values must be positive integers");return z0}),q){if(Q1(q)&&(q=q.toNumber()),!X1(q)||!$1(q))throw new TypeError("The parameter k must be an integer number")}else q=0;var L=t,g=0;Ee(m)&&(L=e.find(t,[m,m])||t,g=e.convert(0,m));var v=q>0?q:0,y=q<0?-q:0,X=A[0],T=A[1],N=Math.min(X-y,T-v),D;if(H1(h)){if(h.length!==N)throw new Error("Invalid value array length");D=function(a0){return h[a0]}}else if(F1(h)){var C=h.size();if(C.length!==1||C[0]!==N)throw new Error("Invalid matrix length");D=function(a0){return h.get([a0])}}else D=function(){return h};for(var P=[],H=[],G=[],k=0;k<T;k++){G.push(P.length);var J=k-v;if(J>=0&&J<N){var o0=D(J);L(o0,g)||(H.push(J+y),P.push(o0))}}return G.push(P.length),new o({values:P,index:H,ptr:G,size:[X,T]})},o.prototype.swapRows=function(A,h){if(!X1(A)||!$1(A)||!X1(h)||!$1(h))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Y1(A,this._size[0]),Y1(h,this._size[0]),o._swapRows(A,h,this._size[1],this._values,this._index,this._ptr),this},o._forEachRow=function(A,h,q,_,m){for(var L=_[A],g=_[A+1],v=L;v<g;v++)m(q[v],h[v])},o._swapRows=function(A,h,q,_,m,L){for(var g=0;g<q;g++){var v=L[g],y=L[g+1],X=s(A,v,y,m),T=s(h,v,y,m);if(X<y&&T<y&&m[X]===A&&m[T]===h){if(_){var N=_[X];_[X]=_[T],_[T]=N}continue}if(X<y&&m[X]===A&&(T>=y||m[T]!==h)){var D=_?_[X]:void 0;m.splice(T,0,h),_&&_.splice(T,0,D),m.splice(T<=X?X+1:X,1),_&&_.splice(T<=X?X+1:X,1);continue}if(T<y&&m[T]===h&&(X>=y||m[X]!==A)){var C=_?_[T]:void 0;m.splice(X,0,A),_&&_.splice(X,0,C),m.splice(X<=T?T+1:T,1),_&&_.splice(X<=T?T+1:T,1)}}},o},{isClass:!0}),m5="number",g5=["typed"];function R5(M){var e=M.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(e){var t={"0b":2,"0o":8,"0x":16}[e[1]],r=e[2],o=e[3];return{input:M,radix:t,integerPart:r,fractionalPart:o}}else return null}function L5(M){for(var e=parseInt(M.integerPart,M.radix),t=0,r=0;r<M.fractionalPart.length;r++){var o=parseInt(M.fractionalPart[r],M.radix);t+=o/Math.pow(M.radix,r+1)}var n=e+t;if(isNaN(n))throw new SyntaxError('String "'+M.input+'" is not a valid number');return n}var v5=h0(m5,g5,M=>{var{typed:e}=M,t=e("number",{"":function(){return 0},number:function(o){return o},string:function(o){if(o==="NaN")return NaN;var n=R5(o);if(n)return L5(n);var b=0,z=o.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);z&&(b=Number(z[2]),o=z[1]);var i=Number(o);if(isNaN(i))throw new SyntaxError('String "'+o+'" is not a valid number');if(z){if(i>2**b-1)throw new SyntaxError('String "'.concat(o,'" is out of range'));i>=2**(b-1)&&(i=i-2**b)}return i},BigNumber:function(o){return o.toNumber()},Fraction:function(o){return o.valueOf()},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),null:function(o){return 0},"Unit, string | Unit":function(o,n){return o.toNumber(n)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),N5="bignumber",y5=["typed","BigNumber"],B5=h0(N5,y5,M=>{var{typed:e,BigNumber:t}=M;return e("bignumber",{"":function(){return new t(0)},number:function(o){return new t(o+"")},string:function(o){var n=o.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(n){var b=n[2],z=t(n[1]),i=new t(2).pow(Number(b));if(z.gt(i.sub(1)))throw new SyntaxError('String "'.concat(o,'" is out of range'));var s=new t(2).pow(Number(b)-1);return z.gte(s)?z.sub(i):z}return new t(o)},BigNumber:function(o){return o},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),Fraction:function(o){return new t(o.n).div(o.d).times(o.s)},null:function(o){return new t(0)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))})}),w5="fraction",D5=["typed","Fraction"],X5=h0(w5,D5,M=>{var{typed:e,Fraction:t}=M;return e("fraction",{number:function(o){if(!isFinite(o)||isNaN(o))throw new Error(o+" cannot be represented as a fraction");return new t(o)},string:function(o){return new t(o)},"number, number":function(o,n){return new t(o,n)},null:function(o){return new t(0)},BigNumber:function(o){return new t(o.toString())},Fraction:function(o){return o},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),Object:function(o){return new t(o)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))})}),_s="matrix",E5=["typed","Matrix","DenseMatrix","SparseMatrix"],T5=h0(_s,E5,M=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:o}=M;return e(_s,{"":function(){return n([])},string:function(z){return n([],z)},"string, string":function(z,i){return n([],z,i)},Array:function(z){return n(z)},Matrix:function(z){return n(z,z.storage())},"Array | Matrix, string":n,"Array | Matrix, string, string":n});function n(b,z,i){if(z==="dense"||z==="default"||z===void 0)return new r(b,i);if(z==="sparse")return new o(b,i);throw new TypeError("Unknown matrix type "+JSON.stringify(z)+".")}}),ms="unaryMinus",C5=["typed"],x5=h0(ms,C5,M=>{var{typed:e}=M;return e(ms,{number:us,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var o=r.clone();return o.value=e.find(t,o.valueType())(r.value),o}),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),gs="abs",S5=["typed"],F5=h0(gs,S5,M=>{var{typed:e}=M;return e(gs,{number:cs,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),Rs="addScalar",I5=["typed"],P5=h0(Rs,I5,M=>{var{typed:e}=M;return e(Rs,{"number, number":ss,"Complex, Complex":function(r,o){return r.add(o)},"BigNumber, BigNumber":function(r,o){return r.plus(o)},"Fraction, Fraction":function(r,o){return r.add(o)},"Unit, Unit":e.referToSelf(t=>(r,o)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(o.value===null||o.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(o))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),o.valueType()])(n.value,o.value),n.fixPrefix=!1,n})})}),Ls="subtractScalar",k5=["typed"],$5=h0(Ls,k5,M=>{var{typed:e}=M;return e(Ls,{"number, number":Os,"Complex, Complex":function(r,o){return r.sub(o)},"BigNumber, BigNumber":function(r,o){return r.minus(o)},"Fraction, Fraction":function(r,o){return r.sub(o)},"Unit, Unit":e.referToSelf(t=>(r,o)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(o.value===null||o.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(o))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),o.valueType()])(n.value,o.value),n.fixPrefix=!1,n})})}),U5="matAlgo11xS0s",j5=["typed","equalScalar"],rp=h0(U5,j5,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=t,q=0,_=b;typeof u=="string"&&(A=u,h=e.find(t,[A,A]),q=e.convert(0,A),n=e.convert(n,A),_=e.find(b,[A,A]));for(var m=[],L=[],g=[],v=0;v<d;v++){g[v]=L.length;for(var y=a[v],X=a[v+1],T=y;T<X;T++){var N=s[T],D=z?_(n,i[T]):_(i[T],n);h(D,q)||(L.push(N),m.push(D))}}return g[d]=L.length,o.createSparseMatrix({values:m,index:L,ptr:g,size:[l,d],datatype:A})}}),H5="matAlgo12xSfs",Y5=["typed","DenseMatrix"],vr=h0(H5,Y5,M=>{var{typed:e,DenseMatrix:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var q=[],_=[],m=[],L=0;L<d;L++){for(var g=L+1,v=a[L],y=a[L+1],X=v;X<y;X++){var T=s[X];_[T]=i[X],m[T]=g}for(var N=0;N<l;N++)L===0&&(q[N]=[]),m[N]===g?q[N][L]=z?h(n,_[N]):h(_[N],n):q[N][L]=z?h(n,0):h(0,n)}return new t({data:q,size:[l,d],datatype:A})}}),G5="matAlgo14xDs",V5=["typed"],Mp=h0(G5,V5,M=>{var{typed:e}=M;return function(o,n,b,z){var i=o._data,s=o._size,a=o._datatype,O,u=b;typeof a=="string"&&(O=a,n=e.convert(n,O),u=e.find(b,[O,O]));var l=s.length>0?t(u,0,s,s[0],i,n,z):[];return o.createDenseMatrix({data:l,size:_1(s),datatype:O})};function t(r,o,n,b,z,i,s){var a=[];if(o===n.length-1)for(var O=0;O<b;O++)a[O]=s?r(i,z[O]):r(z[O],i);else for(var u=0;u<b;u++)a[u]=t(r,o+1,n,n[o+1],z[u],i,s);return a}}),K5="matAlgo02xDS0",J5=["typed","equalScalar"],Q5=h0(K5,J5,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b,z){var i=o._data,s=o._size,a=o._datatype||o.getDataType(),O=n._values,u=n._index,l=n._ptr,d=n._size,A=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(s.length!==d.length)throw new A1(s.length,d.length);if(s[0]!==d[0]||s[1]!==d[1])throw new RangeError("Dimension mismatch. Matrix A ("+s+") must match Matrix B ("+d+")");if(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var h=s[0],q=s[1],_,m=t,L=0,g=b;typeof a=="string"&&a===A&&a!=="mixed"&&(_=a,m=e.find(t,[_,_]),L=e.convert(0,_),g=e.find(b,[_,_]));for(var v=[],y=[],X=[],T=0;T<q;T++){X[T]=y.length;for(var N=l[T],D=l[T+1],C=N;C<D;C++){var P=u[C],H=z?g(O[C],i[P][T]):g(i[P][T],O[C]);m(H,L)||(y.push(P),v.push(H))}}return X[q]=y.length,n.createSparseMatrix({values:v,index:y,ptr:X,size:[h,q],datatype:a===o._datatype&&A===n._datatype?_:void 0})}}),Z5="matAlgo03xDSf",eh=["typed"],Nr=h0(Z5,eh,M=>{var{typed:e}=M;return function(r,o,n,b){var z=r._data,i=r._size,s=r._datatype||r.getDataType(),a=o._values,O=o._index,u=o._ptr,l=o._size,d=o._datatype||o._data===void 0?o._datatype:o.getDataType();if(i.length!==l.length)throw new A1(i.length,l.length);if(i[0]!==l[0]||i[1]!==l[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+l+")");if(!a)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],q,_=0,m=n;typeof s=="string"&&s===d&&s!=="mixed"&&(q=s,_=e.convert(0,q),m=e.find(n,[q,q]));for(var L=[],g=0;g<A;g++)L[g]=[];for(var v=[],y=[],X=0;X<h;X++){for(var T=X+1,N=u[X],D=u[X+1],C=N;C<D;C++){var P=O[C];v[P]=b?m(a[C],z[P][X]):m(z[P][X],a[C]),y[P]=T}for(var H=0;H<A;H++)y[H]===T?L[H][X]=v[H]:L[H][X]=b?m(_,z[H][X]):m(z[H][X],_)}return r.createDenseMatrix({data:L,size:[A,h],datatype:s===r._datatype&&d===o._datatype?q:void 0})}}),th="matAlgo05xSfSf",rh=["typed","equalScalar"],vs=h0(th,rh,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b){var z=o._values,i=o._index,s=o._ptr,a=o._size,O=o._datatype||o._data===void 0?o._datatype:o.getDataType(),u=n._values,l=n._index,d=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(a.length!==A.length)throw new A1(a.length,A.length);if(a[0]!==A[0]||a[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+a+") must match Matrix B ("+A+")");var q=a[0],_=a[1],m,L=t,g=0,v=b;typeof O=="string"&&O===h&&O!=="mixed"&&(m=O,L=e.find(t,[m,m]),g=e.convert(0,m),v=e.find(b,[m,m]));var y=z&&u?[]:void 0,X=[],T=[],N=y?[]:void 0,D=y?[]:void 0,C=[],P=[],H,G,k,J;for(G=0;G<_;G++){T[G]=X.length;var o0=G+1;for(k=s[G],J=s[G+1];k<J;k++)H=i[k],X.push(H),C[H]=o0,N&&(N[H]=z[k]);for(k=d[G],J=d[G+1];k<J;k++)H=l[k],C[H]!==o0&&X.push(H),P[H]=o0,D&&(D[H]=u[k]);if(y)for(k=T[G];k<X.length;){H=X[k];var z0=C[H],a0=P[H];if(z0===o0||a0===o0){var v0=z0===o0?N[H]:g,w0=a0===o0?D[H]:g,u0=v(v0,w0);L(u0,g)?X.splice(k,1):(y.push(u0),k++)}}}return T[_]=X.length,o.createSparseMatrix({values:y,index:X,ptr:T,size:[q,_],datatype:O===o._datatype&&h===n._datatype?m:void 0})}}),Mh="matAlgo13xDD",oh=["typed"],nh=h0(Mh,oh,M=>{var{typed:e}=M;return function(o,n,b){var z=o._data,i=o._size,s=o._datatype,a=n._data,O=n._size,u=n._datatype,l=[];if(i.length!==O.length)throw new A1(i.length,O.length);for(var d=0;d<i.length;d++){if(i[d]!==O[d])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+O+")");l[d]=i[d]}var A,h=b;typeof s=="string"&&s===u&&(A=s,h=e.find(b,[A,A]));var q=l.length>0?t(h,0,l,l[0],z,a):[];return o.createDenseMatrix({data:q,size:l,datatype:A})};function t(r,o,n,b,z,i){var s=[];if(o===n.length-1)for(var a=0;a<b;a++)s[a]=r(z[a],i[a]);else for(var O=0;O<b;O++)s[O]=t(r,o+1,n,n[o+1],z[O],i[O]);return s}}),bh="broadcast",ph=["concat"],zh=h0(bh,ph,M=>{var{concat:e}=M;return function(o,n){var b=Math.max(o._size.length,n._size.length);if(o._size.length===n._size.length&&o._size.every((d,A)=>d===n._size[A]))return[o,n];for(var z=t(o._size,b,0),i=t(n._size,b,0),s=[],a=0;a<b;a++)s[a]=Math.max(z[a],i[a]);fo(z,s),fo(i,s);var O=o.clone(),u=n.clone();O._size.length<b?O.reshape(t(O._size,b,1)):u._size.length<b&&u.reshape(t(u._size,b,1));for(var l=0;l<b;l++)O._size[l]<s[l]&&(O=r(O,s[l],l)),u._size[l]<s[l]&&(u=r(u,s[l],l));return[O,u]};function t(o,n,b){return[...Array(n-o.length).fill(b),...o]}function r(o,n,b){return e(...Array(n).fill(o),b)}}),ih="matrixAlgorithmSuite",ch=["typed","matrix","concat"],jt=h0(ih,ch,M=>{var{typed:e,matrix:t,concat:r}=M,o=nh({typed:e}),n=Mp({typed:e}),b=zh({concat:r});return function(i){var s=i.elop,a=i.SD||i.DS,O;s?(O={"DenseMatrix, DenseMatrix":(A,h)=>o(...b(A,h),s),"Array, Array":(A,h)=>o(...b(t(A),t(h)),s).valueOf(),"Array, DenseMatrix":(A,h)=>o(...b(t(A),h),s),"DenseMatrix, Array":(A,h)=>o(...b(A,t(h)),s)},i.SS&&(O["SparseMatrix, SparseMatrix"]=(A,h)=>i.SS(...b(A,h),s,!1)),i.DS&&(O["DenseMatrix, SparseMatrix"]=(A,h)=>i.DS(...b(A,h),s,!1),O["Array, SparseMatrix"]=(A,h)=>i.DS(...b(t(A),h),s,!1)),a&&(O["SparseMatrix, DenseMatrix"]=(A,h)=>a(...b(h,A),s,!0),O["SparseMatrix, Array"]=(A,h)=>a(...b(t(h),A),s,!0))):(O={"DenseMatrix, DenseMatrix":e.referToSelf(A=>(h,q)=>o(...b(h,q),A)),"Array, Array":e.referToSelf(A=>(h,q)=>o(...b(t(h),t(q)),A).valueOf()),"Array, DenseMatrix":e.referToSelf(A=>(h,q)=>o(...b(t(h),q),A)),"DenseMatrix, Array":e.referToSelf(A=>(h,q)=>o(...b(h,t(q)),A))},i.SS&&(O["SparseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.SS(...b(h,q),A,!1))),i.DS&&(O["DenseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.DS(...b(h,q),A,!1)),O["Array, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.DS(...b(t(h),q),A,!1))),a&&(O["SparseMatrix, DenseMatrix"]=e.referToSelf(A=>(h,q)=>a(...b(q,h),A,!0)),O["SparseMatrix, Array"]=e.referToSelf(A=>(h,q)=>a(...b(t(q),h),A,!0))));var u=i.scalar||"any",l=i.Ds||i.Ss;l&&(s?(O["DenseMatrix,"+u]=(A,h)=>n(A,h,s,!1),O[u+", DenseMatrix"]=(A,h)=>n(h,A,s,!0),O["Array,"+u]=(A,h)=>n(t(A),h,s,!1).valueOf(),O[u+", Array"]=(A,h)=>n(t(h),A,s,!0).valueOf()):(O["DenseMatrix,"+u]=e.referToSelf(A=>(h,q)=>n(h,q,A,!1)),O[u+", DenseMatrix"]=e.referToSelf(A=>(h,q)=>n(q,h,A,!0)),O["Array,"+u]=e.referToSelf(A=>(h,q)=>n(t(h),q,A,!1).valueOf()),O[u+", Array"]=e.referToSelf(A=>(h,q)=>n(t(q),h,A,!0).valueOf())));var d=i.sS!==void 0?i.sS:i.Ss;return s?(i.Ss&&(O["SparseMatrix,"+u]=(A,h)=>i.Ss(A,h,s,!1)),d&&(O[u+", SparseMatrix"]=(A,h)=>d(h,A,s,!0))):(i.Ss&&(O["SparseMatrix,"+u]=e.referToSelf(A=>(h,q)=>i.Ss(h,q,A,!1))),d&&(O[u+", SparseMatrix"]=e.referToSelf(A=>(h,q)=>d(q,h,A,!0)))),s&&s.signatures&&hc(O,s.signatures),O}}),sh="matAlgo01xDSid",Oh=["typed"],Ns=h0(sh,Oh,M=>{var{typed:e}=M;return function(r,o,n,b){var z=r._data,i=r._size,s=r._datatype||r.getDataType(),a=o._values,O=o._index,u=o._ptr,l=o._size,d=o._datatype||o._data===void 0?o._datatype:o.getDataType();if(i.length!==l.length)throw new A1(i.length,l.length);if(i[0]!==l[0]||i[1]!==l[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+l+")");if(!a)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],q=typeof s=="string"&&s!=="mixed"&&s===d?s:void 0,_=q?e.find(n,[q,q]):n,m,L,g=[];for(m=0;m<A;m++)g[m]=[];var v=[],y=[];for(L=0;L<h;L++){for(var X=L+1,T=u[L],N=u[L+1],D=T;D<N;D++)m=O[D],v[m]=b?_(a[D],z[m][L]):_(z[m][L],a[D]),y[m]=X;for(m=0;m<A;m++)y[m]===X?g[m][L]=v[m]:g[m][L]=z[m][L]}return r.createDenseMatrix({data:g,size:[A,h],datatype:s===r._datatype&&d===o._datatype?q:void 0})}}),ah="matAlgo04xSidSid",uh=["typed","equalScalar"],Ah=h0(ah,uh,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b){var z=o._values,i=o._index,s=o._ptr,a=o._size,O=o._datatype||o._data===void 0?o._datatype:o.getDataType(),u=n._values,l=n._index,d=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(a.length!==A.length)throw new A1(a.length,A.length);if(a[0]!==A[0]||a[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+a+") must match Matrix B ("+A+")");var q=a[0],_=a[1],m,L=t,g=0,v=b;typeof O=="string"&&O===h&&O!=="mixed"&&(m=O,L=e.find(t,[m,m]),g=e.convert(0,m),v=e.find(b,[m,m]));var y=z&&u?[]:void 0,X=[],T=[],N=z&&u?[]:void 0,D=z&&u?[]:void 0,C=[],P=[],H,G,k,J,o0;for(G=0;G<_;G++){T[G]=X.length;var z0=G+1;for(J=s[G],o0=s[G+1],k=J;k<o0;k++)H=i[k],X.push(H),C[H]=z0,N&&(N[H]=z[k]);for(J=d[G],o0=d[G+1],k=J;k<o0;k++)if(H=l[k],C[H]===z0){if(N){var a0=v(N[H],u[k]);L(a0,g)?C[H]=null:N[H]=a0}}else X.push(H),P[H]=z0,D&&(D[H]=u[k]);if(N&&D)for(k=T[G];k<X.length;)H=X[k],C[H]===z0?(y[k]=N[H],k++):P[H]===z0?(y[k]=D[H],k++):X.splice(k,1)}return T[_]=X.length,o.createSparseMatrix({values:y,index:X,ptr:T,size:[q,_],datatype:O===o._datatype&&h===n._datatype?m:void 0})}}),fh="matAlgo10xSids",lh=["typed","DenseMatrix"],ys=h0(fh,lh,M=>{var{typed:e,DenseMatrix:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var q=[],_=[],m=[],L=0;L<d;L++){for(var g=L+1,v=a[L],y=a[L+1],X=v;X<y;X++){var T=s[X];_[T]=i[X],m[T]=g}for(var N=0;N<l;N++)L===0&&(q[N]=[]),m[N]===g?q[N][L]=z?h(n,_[N]):h(_[N],n):q[N][L]=n}return new t({data:q,size:[l,d],datatype:A})}}),qh="multiplyScalar",dh=["typed"],hh=h0(qh,dh,M=>{var{typed:e}=M;return e("multiplyScalar",{"number, number":as,"Complex, Complex":function(r,o){return r.mul(o)},"BigNumber, BigNumber":function(r,o){return r.times(o)},"Fraction, Fraction":function(r,o){return r.mul(o)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Bs="multiply",Wh=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],_h=h0(Bs,Wh,M=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:o,equalScalar:n,dot:b}=M,z=rp({typed:e,equalScalar:n}),i=Mp({typed:e});function s(g,v){switch(g.length){case 1:switch(v.length){case 1:if(g[0]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(g[0]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+g[0]+") must match Matrix rows ("+v[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+v.length+" dimensions)")}break;case 2:switch(v.length){case 1:if(g[1]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+g[1]+") must match Vector length ("+v[0]+")");break;case 2:if(g[1]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+g[1]+") must match Matrix B rows ("+v[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+v.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+g.length+" dimensions)")}}function a(g,v,y){if(y===0)throw new Error("Cannot multiply two empty vectors");return b(g,v)}function O(g,v){if(v.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return u(g,v)}function u(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._size,C=v._datatype||v.getDataType(),P=X[0],H=D[1],G,k=r,J=o;T&&C&&T===C&&typeof T=="string"&&T!=="mixed"&&(G=T,k=e.find(r,[G,G]),J=e.find(o,[G,G]));for(var o0=[],z0=0;z0<H;z0++){for(var a0=J(y[0],N[0][z0]),v0=1;v0<P;v0++)a0=k(a0,J(y[v0],N[v0][z0]));o0[z0]=a0}return g.createDenseMatrix({data:o0,size:[H],datatype:T===g._datatype&&C===v._datatype?G:void 0})}var l=e("_multiplyMatrixVector",{"DenseMatrix, any":A,"SparseMatrix, any":_}),d=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":h,"DenseMatrix, SparseMatrix":q,"SparseMatrix, DenseMatrix":m,"SparseMatrix, SparseMatrix":L});function A(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._datatype||v.getDataType(),C=X[0],P=X[1],H,G=r,k=o;T&&D&&T===D&&typeof T=="string"&&T!=="mixed"&&(H=T,G=e.find(r,[H,H]),k=e.find(o,[H,H]));for(var J=[],o0=0;o0<C;o0++){for(var z0=y[o0],a0=k(z0[0],N[0]),v0=1;v0<P;v0++)a0=G(a0,k(z0[v0],N[v0]));J[o0]=a0}return g.createDenseMatrix({data:J,size:[C],datatype:T===g._datatype&&D===v._datatype?H:void 0})}function h(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._size,C=v._datatype||v.getDataType(),P=X[0],H=X[1],G=D[1],k,J=r,o0=o;T&&C&&T===C&&typeof T=="string"&&T!=="mixed"&&T!=="mixed"&&(k=T,J=e.find(r,[k,k]),o0=e.find(o,[k,k]));for(var z0=[],a0=0;a0<P;a0++){var v0=y[a0];z0[a0]=[];for(var w0=0;w0<G;w0++){for(var u0=o0(v0[0],N[0][w0]),I0=1;I0<H;I0++)u0=J(u0,o0(v0[I0],N[I0][w0]));z0[a0][w0]=u0}}return g.createDenseMatrix({data:z0,size:[P,G],datatype:T===g._datatype&&C===v._datatype?k:void 0})}function q(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._values,D=v._index,C=v._ptr,P=v._size,H=v._datatype||v._data===void 0?v._datatype:v.getDataType();if(!N)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var G=X[0],k=P[1],J,o0=r,z0=o,a0=n,v0=0;T&&H&&T===H&&typeof T=="string"&&T!=="mixed"&&(J=T,o0=e.find(r,[J,J]),z0=e.find(o,[J,J]),a0=e.find(n,[J,J]),v0=e.convert(0,J));for(var w0=[],u0=[],I0=[],S0=v.createSparseMatrix({values:w0,index:u0,ptr:I0,size:[G,k],datatype:T===g._datatype&&H===v._datatype?J:void 0}),F0=0;F0<k;F0++){I0[F0]=u0.length;var W0=C[F0],b1=C[F0+1];if(b1>W0)for(var J0=0,p1=0;p1<G;p1++){for(var Z1=p1+1,d1=void 0,F=W0;F<b1;F++){var K=D[F];J0!==Z1?(d1=z0(y[p1][K],N[F]),J0=Z1):d1=o0(d1,z0(y[p1][K],N[F]))}J0===Z1&&!a0(d1,v0)&&(u0.push(p1),w0.push(d1))}}return I0[k]=u0.length,S0}function _(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType();if(!y)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var D=v._data,C=v._datatype||v.getDataType(),P=g._size[0],H=v._size[0],G=[],k=[],J=[],o0,z0=r,a0=o,v0=n,w0=0;N&&C&&N===C&&typeof N=="string"&&N!=="mixed"&&(o0=N,z0=e.find(r,[o0,o0]),a0=e.find(o,[o0,o0]),v0=e.find(n,[o0,o0]),w0=e.convert(0,o0));var u0=[],I0=[];J[0]=0;for(var S0=0;S0<H;S0++){var F0=D[S0];if(!v0(F0,w0))for(var W0=T[S0],b1=T[S0+1],J0=W0;J0<b1;J0++){var p1=X[J0];I0[p1]?u0[p1]=z0(u0[p1],a0(F0,y[J0])):(I0[p1]=!0,k.push(p1),u0[p1]=a0(F0,y[J0]))}}for(var Z1=k.length,d1=0;d1<Z1;d1++){var F=k[d1];G[d1]=u0[F]}return J[1]=k.length,g.createSparseMatrix({values:G,index:k,ptr:J,size:[P,1],datatype:N===g._datatype&&C===v._datatype?o0:void 0})}function m(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType();if(!y)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var D=v._data,C=v._datatype||v.getDataType(),P=g._size[0],H=v._size[0],G=v._size[1],k,J=r,o0=o,z0=n,a0=0;N&&C&&N===C&&typeof N=="string"&&N!=="mixed"&&(k=N,J=e.find(r,[k,k]),o0=e.find(o,[k,k]),z0=e.find(n,[k,k]),a0=e.convert(0,k));for(var v0=[],w0=[],u0=[],I0=g.createSparseMatrix({values:v0,index:w0,ptr:u0,size:[P,G],datatype:N===g._datatype&&C===v._datatype?k:void 0}),S0=[],F0=[],W0=0;W0<G;W0++){u0[W0]=w0.length;for(var b1=W0+1,J0=0;J0<H;J0++){var p1=D[J0][W0];if(!z0(p1,a0))for(var Z1=T[J0],d1=T[J0+1],F=Z1;F<d1;F++){var K=X[F];F0[K]!==b1?(F0[K]=b1,w0.push(K),S0[K]=o0(p1,y[F])):S0[K]=J(S0[K],o0(p1,y[F]))}}for(var Z=u0[W0],O0=w0.length,R0=Z;R0<O0;R0++){var j0=w0[R0];v0[R0]=S0[j0]}}return u0[G]=w0.length,I0}function L(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType(),D=v._values,C=v._index,P=v._ptr,H=v._datatype||v._data===void 0?v._datatype:v.getDataType(),G=g._size[0],k=v._size[1],J=y&&D,o0,z0=r,a0=o;N&&H&&N===H&&typeof N=="string"&&N!=="mixed"&&(o0=N,z0=e.find(r,[o0,o0]),a0=e.find(o,[o0,o0]));for(var v0=J?[]:void 0,w0=[],u0=[],I0=g.createSparseMatrix({values:v0,index:w0,ptr:u0,size:[G,k],datatype:N===g._datatype&&H===v._datatype?o0:void 0}),S0=J?[]:void 0,F0=[],W0,b1,J0,p1,Z1,d1,F,K,Z=0;Z<k;Z++){u0[Z]=w0.length;var O0=Z+1;for(Z1=P[Z],d1=P[Z+1],p1=Z1;p1<d1;p1++)if(K=C[p1],J)for(b1=T[K],J0=T[K+1],W0=b1;W0<J0;W0++)F=X[W0],F0[F]!==O0?(F0[F]=O0,w0.push(F),S0[F]=a0(D[p1],y[W0])):S0[F]=z0(S0[F],a0(D[p1],y[W0]));else for(b1=T[K],J0=T[K+1],W0=b1;W0<J0;W0++)F=X[W0],F0[F]!==O0&&(F0[F]=O0,w0.push(F));if(J)for(var R0=u0[Z],j0=w0.length,g1=R0;g1<j0;g1++){var V0=w0[g1];v0[g1]=S0[V0]}}return u0[k]=w0.length,I0}return e(Bs,o,{"Array, Array":e.referTo("Matrix, Matrix",g=>(v,y)=>{s(M2(v),M2(y));var X=g(t(v),t(y));return F1(X)?X.valueOf():X}),"Matrix, Matrix":function(v,y){var X=v.size(),T=y.size();return s(X,T),X.length===1?T.length===1?a(v,y,X[0]):O(v,y):T.length===1?l(v,y):d(v,y)},"Matrix, Array":e.referTo("Matrix,Matrix",g=>(v,y)=>g(v,t(y))),"Array, Matrix":e.referToSelf(g=>(v,y)=>g(t(v,y.storage()),y)),"SparseMatrix, any":function(v,y){return z(v,y,o,!1)},"DenseMatrix, any":function(v,y){return i(v,y,o,!1)},"any, SparseMatrix":function(v,y){return z(y,v,o,!0)},"any, DenseMatrix":function(v,y){return i(y,v,o,!0)},"Array, any":function(v,y){return i(t(v),y,o,!1).valueOf()},"any, Array":function(v,y){return i(t(y),v,o,!0).valueOf()},"any, any":o,"any, any, ...any":e.referToSelf(g=>(v,y,X)=>{for(var T=g(v,y),N=0;N<X.length;N++)T=g(T,X[N]);return T})})}),ws="subtract",mh=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],gh=h0(ws,mh,M=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:o,unaryMinus:n,DenseMatrix:b,concat:z}=M,i=Ns({typed:e}),s=Nr({typed:e}),a=vs({typed:e,equalScalar:r}),O=ys({typed:e,DenseMatrix:b}),u=vr({typed:e,DenseMatrix:b}),l=jt({typed:e,matrix:t,concat:z});return e(ws,{"any, any":o},l({elop:o,SS:a,DS:i,SD:s,Ss:u,sS:O}))}),Rh="matAlgo07xSSf",Lh=["typed","DenseMatrix"],Do=h0(Rh,Lh,M=>{var{typed:e,DenseMatrix:t}=M;return function(n,b,z){var i=n._size,s=n._datatype||n._data===void 0?n._datatype:n.getDataType(),a=b._size,O=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(i.length!==a.length)throw new A1(i.length,a.length);if(i[0]!==a[0]||i[1]!==a[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+a+")");var u=i[0],l=i[1],d,A=0,h=z;typeof s=="string"&&s===O&&s!=="mixed"&&(d=s,A=e.convert(0,d),h=e.find(z,[d,d]));var q,_,m=[];for(q=0;q<u;q++)m[q]=[];var L=[],g=[],v=[],y=[];for(_=0;_<l;_++){var X=_+1;for(r(n,_,v,L,X),r(b,_,y,g,X),q=0;q<u;q++){var T=v[q]===X?L[q]:A,N=y[q]===X?g[q]:A;m[q][_]=h(T,N)}}return new t({data:m,size:[u,l],datatype:s===n._datatype&&O===b._datatype?d:void 0})};function r(o,n,b,z,i){for(var s=o._values,a=o._index,O=o._ptr,u=O[n],l=O[n+1];u<l;u++){var d=a[u];b[d]=i,z[d]=s[u]}}}),Ds="conj",vh=["typed"],Nh=h0(Ds,vh,M=>{var{typed:e}=M;return e(Ds,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),Xs="concat",yh=["typed","matrix","isInteger"],Bh=h0(Xs,yh,M=>{var{typed:e,matrix:t,isInteger:r}=M;return e(Xs,{"...Array | Matrix | number | BigNumber":function(n){var b,z=n.length,i=-1,s,a=!1,O=[];for(b=0;b<z;b++){var u=n[b];if(F1(u)&&(a=!0),X1(u)||Q1(u)){if(b!==z-1)throw new Error("Dimension must be specified as last argument");if(s=i,i=u.valueOf(),!r(i))throw new TypeError("Integer number expected for dimension");if(i<0||b>0&&i>s)throw new dt(i,s+1)}else{var l=_1(u).valueOf(),d=M2(l);if(O[b]=l,s=i,i=d.length-1,b>0&&i!==s)throw new A1(s+1,i+1)}}if(O.length===0)throw new SyntaxError("At least one matrix expected");for(var A=O.shift();O.length;)A=Ic(A,O.shift(),i);return a?t(A):A},"...string":function(n){return n.join("")}})}),Es="count",wh=["typed","size","prod"],Dh=h0(Es,wh,M=>{var{typed:e,size:t,prod:r}=M;return e(Es,{string:function(n){return n.length},"Matrix | Array":function(n){return r(t(n))}})}),Ts="identity",Xh=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Eh=h0(Ts,Xh,M=>{var{typed:e,config:t,matrix:r,BigNumber:o,DenseMatrix:n,SparseMatrix:b}=M;return e(Ts,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(a){return r(a)},"number | BigNumber":function(a){return i(a,a,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(a,O){return i(a,a,O)},"number | BigNumber, number | BigNumber":function(a,O){return i(a,O,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(a,O,u){return i(a,O,u)},Array:function(a){return z(a)},"Array, string":function(a,O){return z(a,O)},Matrix:function(a){return z(a.valueOf(),a.storage())},"Matrix, string":function(a,O){return z(a.valueOf(),O)}});function z(s,a){switch(s.length){case 0:return a?r(a):[];case 1:return i(s[0],s[0],a);case 2:return i(s[0],s[1],a);default:throw new Error("Vector containing two values expected")}}function i(s,a,O){var u=Q1(s)||Q1(a)?o:null;if(Q1(s)&&(s=s.toNumber()),Q1(a)&&(a=a.toNumber()),!$1(s)||s<1)throw new Error("Parameters in function identity must be positive integers");if(!$1(a)||a<1)throw new Error("Parameters in function identity must be positive integers");var l=u?new o(1):1,d=u?new u(0):0,A=[s,a];if(O){if(O==="sparse")return b.diagonal(A,l,0,d);if(O==="dense")return n.diagonal(A,l,0,d);throw new TypeError('Unknown matrix type "'.concat(O,'"'))}for(var h=kb([],A,d),q=s<a?s:a,_=0;_<q;_++)h[_][_]=l;return h}}),Cs="kron",Th=["typed","matrix","multiplyScalar"],Ch=h0(Cs,Th,M=>{var{typed:e,matrix:t,multiplyScalar:r}=M;return e(Cs,{"Matrix, Matrix":function(b,z){return t(o(b.toArray(),z.toArray()))},"Matrix, Array":function(b,z){return t(o(b.toArray(),z))},"Array, Matrix":function(b,z){return t(o(b,z.toArray()))},"Array, Array":o});function o(n,b){if(M2(n).length===1&&(n=[n]),M2(b).length===1&&(b=[b]),M2(n).length>2||M2(b).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(n.length)+", y = "+JSON.stringify(b.length)+")");var z=[],i=[];return n.map(function(s){return b.map(function(a){return i=[],z.push(i),s.map(function(O){return a.map(function(u){return i.push(r(O,u))})})})})&&z}});function xh(){throw new Error('No "bignumber" implementation available')}function Sh(){throw new Error('No "fraction" implementation available')}function Fh(){throw new Error('No "matrix" implementation available')}var xs="reshape",Ih=["typed","isInteger","matrix"],Ph=h0(xs,Ih,M=>{var{typed:e,isInteger:t}=M;return e(xs,{"Matrix, Array":function(o,n){return o.reshape(n,!0)},"Array, Array":function(o,n){return n.forEach(function(b){if(!t(b))throw new TypeError("Invalid size for dimension: "+b)}),Ub(o,n)}})}),Ss="size",kh=["typed","config","?matrix"],$h=h0(Ss,kh,M=>{var{typed:e,config:t,matrix:r}=M;return e(Ss,{Matrix:function(n){return n.create(n.size())},Array:M2,string:function(n){return t.matrix==="Array"?[n.length]:r([n.length])},"number | Complex | BigNumber | Unit | boolean | null":function(n){return t.matrix==="Array"?[]:r?r([]):Fh()}})}),Fs="transpose",Uh=["typed","matrix"],jh=h0(Fs,Uh,M=>{var{typed:e,matrix:t}=M;return e(Fs,{Array:b=>r(t(b)).valueOf(),Matrix:r,any:_1});function r(b){var z=b.size(),i;switch(z.length){case 1:i=b.clone();break;case 2:{var s=z[0],a=z[1];if(a===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+N1(z)+")");switch(b.storage()){case"dense":i=o(b,s,a);break;case"sparse":i=n(b,s,a);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+N1(z)+")")}return i}function o(b,z,i){for(var s=b._data,a=[],O,u=0;u<i;u++){O=a[u]=[];for(var l=0;l<z;l++)O[l]=_1(s[l][u])}return b.createDenseMatrix({data:a,size:[i,z],datatype:b._datatype})}function n(b,z,i){for(var s=b._values,a=b._index,O=b._ptr,u=s?[]:void 0,l=[],d=[],A=[],h=0;h<z;h++)A[h]=0;var q,_,m;for(q=0,_=a.length;q<_;q++)A[a[q]]++;for(var L=0,g=0;g<z;g++)d.push(L),L+=A[g],A[g]=d[g];for(d.push(L),m=0;m<i;m++)for(var v=O[m],y=O[m+1],X=v;X<y;X++){var T=A[a[X]]++;l[T]=m,s&&(u[T]=_1(s[X]))}return b.createSparseMatrix({values:u,index:l,ptr:d,size:[i,z],datatype:b._datatype})}}),Is="ctranspose",Hh=["typed","transpose","conj"],Yh=h0(Is,Hh,M=>{var{typed:e,transpose:t,conj:r}=M;return e(Is,{any:function(n){return r(t(n))}})}),Ps="mode",Gh=["typed","isNaN","isNumeric"],Vh=h0(Ps,Gh,M=>{var{typed:e,isNaN:t,isNumeric:r}=M;return e(Ps,{"Array | Matrix":o,"...":function(b){return o(b)}});function o(n){n=Hb(n.valueOf());var b=n.length;if(b===0)throw new Error("Cannot calculate mode of an empty array");for(var z={},i=[],s=0,a=0;a<n.length;a++){var O=n[a];if(r(O)&&t(O))throw new Error("Cannot calculate mode of an array containing NaN values");O in z||(z[O]=0),z[O]++,z[O]===s?i.push(O):z[O]>s&&(s=z[O],i=[O])}return i}});function gt(M,e,t){var r;return String(M).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+qt(t)+", value: "+JSON.stringify(t)+")":" (type: "+M.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(M).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+qt(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):M}var ks="prod",Kh=["typed","config","multiplyScalar","numeric"],Jh=h0(ks,Kh,M=>{var{typed:e,config:t,multiplyScalar:r,numeric:o}=M;return e(ks,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":function(z,i){throw new Error("prod(A, dim) is not yet supported")},"...":function(z){return n(z)}});function n(b){var z;if(fM(b,function(i){try{z=z===void 0?i:r(z,i)}catch(s){throw gt(s,"prod",i)}}),typeof z=="string"&&(z=o(z,t.number)),z===void 0)throw new Error("Cannot calculate prod of an empty array");return z}}),Qh="numeric",Zh=["number","?bignumber","?fraction"],eW=h0(Qh,Zh,M=>{var{number:e,bignumber:t,fraction:r}=M,o={string:!0,number:!0,BigNumber:!0,Fraction:!0},n={number:b=>e(b),BigNumber:t?b=>t(b):xh,Fraction:r?b=>r(b):Sh};return function(z){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",s=arguments.length>2?arguments[2]:void 0;if(s!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var a=qt(z);if(!(a in o))throw new TypeError("Cannot convert "+z+' of type "'+a+'"; valid input types are '+Object.keys(o).join(", "));if(!(i in n))throw new TypeError("Cannot convert "+z+' to type "'+i+'"; valid output types are '+Object.keys(n).join(", "));return i===a?z:n[i](z)}}),$s="divideScalar",tW=["typed","numeric"],rW=h0($s,tW,M=>{var{typed:e,numeric:t}=M;return e($s,{"number, number":function(o,n){return o/n},"Complex, Complex":function(o,n){return o.div(n)},"BigNumber, BigNumber":function(o,n){return o.div(n)},"Fraction, Fraction":function(o,n){return o.div(n)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,o)=>r.divide(o),"number | Fraction | Complex | BigNumber, Unit":(r,o)=>o.divideInto(r)})}),Us="pow",MW=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],oW=h0(Us,MW,M=>{var{typed:e,config:t,identity:r,multiply:o,matrix:n,inv:b,number:z,fraction:i,Complex:s}=M;return e(Us,{"number, number":a,"Complex, Complex":function(d,A){return d.pow(A)},"BigNumber, BigNumber":function(d,A){return A.isInteger()||d>=0||t.predictable?d.pow(A):new s(d.toNumber(),0).pow(A.toNumber(),0)},"Fraction, Fraction":function(d,A){var h=d.pow(A);if(h!=null)return h;if(t.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return a(d.valueOf(),A.valueOf())},"Array, number":O,"Array, BigNumber":function(d,A){return O(d,A.toNumber())},"Matrix, number":u,"Matrix, BigNumber":function(d,A){return u(d,A.toNumber())},"Unit, number | BigNumber":function(d,A){return d.pow(A)}});function a(l,d){if(t.predictable&&!$1(d)&&l<0)try{var A=i(d),h=z(A);if((d===h||Math.abs((d-h)/d)<1e-14)&&A.d%2===1)return(A.n%2===0?1:-1)*Math.pow(-l,d)}catch{}return t.predictable&&(l<-1&&d===1/0||l>-1&&l<0&&d===-1/0)?NaN:$1(d)||l>=0||t.predictable?As(l,d):l*l<1&&d===1/0||l*l>1&&d===-1/0?0:new s(l,0).pow(d,0)}function O(l,d){if(!$1(d))throw new TypeError("For A^b, b must be an integer (value is "+d+")");var A=M2(l);if(A.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+A.length+" dimensions)");if(A[0]!==A[1])throw new Error("For A^b, A must be square (size is "+A[0]+"x"+A[1]+")");if(d<0)try{return O(b(l),-d)}catch(_){throw _.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 "+d+")"):_}for(var h=r(A[0]).valueOf(),q=l;d>=1;)(d&1)===1&&(h=o(q,h)),d>>=1,q=o(q,q);return h}function u(l,d){return n(O(l.valueOf(),d))}}),js="dotDivide",nW=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],bW=h0(js,nW,M=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:o,DenseMatrix:n,concat:b}=M,z=Q5({typed:e,equalScalar:r}),i=Nr({typed:e}),s=Do({typed:e,DenseMatrix:n}),a=rp({typed:e,equalScalar:r}),O=vr({typed:e,DenseMatrix:n}),u=jt({typed:e,matrix:t,concat:b});return e(js,u({elop:o,SS:s,DS:i,SD:z,Ss:a,sS:O}))}),Xo="compare",pW=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],zW=h0(Xo,pW,M=>{var{typed:e,config:t,equalScalar:r,matrix:o,BigNumber:n,Fraction:b,DenseMatrix:z,concat:i}=M,s=Nr({typed:e}),a=vs({typed:e,equalScalar:r}),O=vr({typed:e,DenseMatrix:z}),u=jt({typed:e,matrix:o,concat:i}),l=Bo({typed:e});return e(Xo,iW({typed:e,config:t}),{"boolean, boolean":function(A,h){return A===h?0:A>h?1:-1},"BigNumber, BigNumber":function(A,h){return yo(A,h,t.epsilon)?new n(0):new n(A.cmp(h))},"Fraction, Fraction":function(A,h){return new b(A.compare(h))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},l,u({SS:a,DS:s,Ss:O}))}),iW=h0(Xo,["typed","config"],M=>{var{typed:e,config:t}=M;return e(Xo,{"number, number":function(o,n){return Ut(o,n,t.epsilon)?0:o>n?1:-1}})}),Eo="equal",cW=["typed","matrix","equalScalar","DenseMatrix","concat"],sW=h0(Eo,cW,M=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:t,concat:n});return e(Eo,OW({typed:e,equalScalar:r}),s({elop:r,SS:z,DS:b,Ss:i}))}),OW=h0(Eo,["typed","equalScalar"],M=>{var{typed:e,equalScalar:t}=M;return e(Eo,{"any, any":function(o,n){return o===null?n===null:n===null?o===null:o===void 0?n===void 0:n===void 0?o===void 0:t(o,n)}})}),To="smaller",aW=["typed","config","matrix","DenseMatrix","concat"],uW=h0(To,aW,M=>{var{typed:e,config:t,matrix:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:r,concat:n}),a=Bo({typed:e});return e(To,AW({typed:e,config:t}),{"boolean, boolean":(O,u)=>O<u,"BigNumber, BigNumber":function(u,l){return u.lt(l)&&!yo(u,l,t.epsilon)},"Fraction, Fraction":(O,u)=>O.compare(u)===-1,"Complex, Complex":function(u,l){throw new TypeError("No ordering relation is defined for complex numbers")}},a,s({SS:z,DS:b,Ss:i}))}),AW=h0(To,["typed","config"],M=>{var{typed:e,config:t}=M;return e(To,{"number, number":function(o,n){return o<n&&!Ut(o,n,t.epsilon)}})}),Co="larger",fW=["typed","config","matrix","DenseMatrix","concat"],lW=h0(Co,fW,M=>{var{typed:e,config:t,matrix:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:r,concat:n}),a=Bo({typed:e});return e(Co,qW({typed:e,config:t}),{"boolean, boolean":(O,u)=>O>u,"BigNumber, BigNumber":function(u,l){return u.gt(l)&&!yo(u,l,t.epsilon)},"Fraction, Fraction":(O,u)=>O.compare(u)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},a,s({SS:z,DS:b,Ss:i}))}),qW=h0(Co,["typed","config"],M=>{var{typed:e,config:t}=M;return e(Co,{"number, number":function(o,n){return o>n&&!Ut(o,n,t.epsilon)}})}),Hs="deepEqual",dW=["typed","equal"],hW=h0(Hs,dW,M=>{var{typed:e,equal:t}=M;return e(Hs,{"any, any":function(n,b){return r(n.valueOf(),b.valueOf())}});function r(o,n){if(Array.isArray(o))if(Array.isArray(n)){var b=o.length;if(b!==n.length)return!1;for(var z=0;z<b;z++)if(!r(o[z],n[z]))return!1;return!0}else return!1;else return Array.isArray(n)?!1:t(o,n)}}),Ys="partitionSelect",WW=["typed","isNumeric","isNaN","compare"],_W=h0(Ys,WW,M=>{var{typed:e,isNumeric:t,isNaN:r,compare:o}=M,n=o,b=(s,a)=>-o(s,a);return e(Ys,{"Array | Matrix, number":function(a,O){return z(a,O,n)},"Array | Matrix, number, string":function(a,O,u){if(u==="asc")return z(a,O,n);if(u==="desc")return z(a,O,b);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":z});function z(s,a,O){if(!$1(a)||a<0)throw new Error("k must be a non-negative integer");if(F1(s)){var u=s.size();if(u.length>1)throw new Error("Only one dimensional matrices supported");return i(s.valueOf(),a,O)}if(Array.isArray(s))return i(s,a,O)}function i(s,a,O){if(a>=s.length)throw new Error("k out of bounds");for(var u=0;u<s.length;u++)if(t(s[u])&&r(s[u]))return s[u];for(var l=0,d=s.length-1;l<d;){for(var A=l,h=d,q=s[Math.floor(Math.random()*(d-l+1))+l];A<h;)if(O(s[A],q)>=0){var _=s[h];s[h]=s[A],s[A]=_,--h}else++A;O(s[A],q)>0&&--A,a<=A?d=A:l=A+1}return s[a]}}),Gs="max",mW=["typed","config","numeric","larger"],gW=h0(Gs,mW,M=>{var{typed:e,config:t,numeric:r,larger:o}=M;return e(Gs,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,s){return tp(i,s.valueOf(),n)},"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function max");return b(i)}});function n(z,i){try{return o(z,i)?z:i}catch(s){throw gt(s,"max",i)}}function b(z){var i;if(fM(z,function(s){try{isNaN(s)&&typeof s=="number"?i=NaN:(i===void 0||o(s,i))&&(i=s)}catch(a){throw gt(a,"max",s)}}),i===void 0)throw new Error("Cannot calculate max of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),Vs="min",RW=["typed","config","numeric","smaller"],LW=h0(Vs,RW,M=>{var{typed:e,config:t,numeric:r,smaller:o}=M;return e(Vs,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,s){return tp(i,s.valueOf(),n)},"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function min");return b(i)}});function n(z,i){try{return o(z,i)?z:i}catch(s){throw gt(s,"min",i)}}function b(z){var i;if(fM(z,function(s){try{isNaN(s)&&typeof s=="number"?i=NaN:(i===void 0||o(s,i))&&(i=s)}catch(a){throw gt(a,"min",s)}}),i===void 0)throw new Error("Cannot calculate min of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),Ks="add",vW=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],NW=h0(Ks,vW,M=>{var{typed:e,matrix:t,addScalar:r,equalScalar:o,DenseMatrix:n,SparseMatrix:b,concat:z}=M,i=Ns({typed:e}),s=Ah({typed:e,equalScalar:o}),a=ys({typed:e,DenseMatrix:n}),O=jt({typed:e,matrix:t,concat:z});return e(Ks,{"any, any":r,"any, any, ...any":e.referToSelf(u=>(l,d,A)=>{for(var h=u(l,d),q=0;q<A.length;q++)h=u(h,A[q]);return h})},O({elop:r,DS:i,SS:s,Ss:a}))}),Js="dot",yW=["typed","addScalar","multiplyScalar","conj","size"],BW=h0(Js,yW,M=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:o,size:n}=M;return e(Js,{"Array | DenseMatrix, Array | DenseMatrix":z,"SparseMatrix, SparseMatrix":i});function b(a,O){var u=s(a),l=s(O),d,A;if(u.length===1)d=u[0];else if(u.length===2&&u[1]===1)d=u[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+u.join(", ")+")");if(l.length===1)A=l[0];else if(l.length===2&&l[1]===1)A=l[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+l.join(", ")+")");if(d!==A)throw new RangeError("Vectors must have equal length ("+d+" != "+A+")");if(d===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return d}function z(a,O){var u=b(a,O),l=F1(a)?a._data:a,d=F1(a)?a._datatype||a.getDataType():void 0,A=F1(O)?O._data:O,h=F1(O)?O._datatype||O.getDataType():void 0,q=s(a).length===2,_=s(O).length===2,m=t,L=r;if(d&&h&&d===h&&typeof d=="string"&&d!=="mixed"){var g=d;m=e.find(t,[g,g]),L=e.find(r,[g,g])}if(!q&&!_){for(var v=L(o(l[0]),A[0]),y=1;y<u;y++)v=m(v,L(o(l[y]),A[y]));return v}if(!q&&_){for(var X=L(o(l[0]),A[0][0]),T=1;T<u;T++)X=m(X,L(o(l[T]),A[T][0]));return X}if(q&&!_){for(var N=L(o(l[0][0]),A[0]),D=1;D<u;D++)N=m(N,L(o(l[D][0]),A[D]));return N}if(q&&_){for(var C=L(o(l[0][0]),A[0][0]),P=1;P<u;P++)C=m(C,L(o(l[P][0]),A[P][0]));return C}}function i(a,O){b(a,O);for(var u=a._index,l=a._values,d=O._index,A=O._values,h=0,q=t,_=r,m=0,L=0;m<u.length&&L<d.length;){var g=u[m],v=d[L];if(g<v){m++;continue}if(g>v){L++;continue}g===v&&(h=q(h,_(l[m],A[L])),m++,L++)}return h}function s(a){return F1(a)?a.size():n(a)}}),wW="trace",DW=["typed","matrix","add"],XW=h0(wW,DW,M=>{var{typed:e,matrix:t,add:r}=M;return e("trace",{Array:function(z){return o(t(z))},SparseMatrix:n,DenseMatrix:o,any:_1});function o(b){var z=b._size,i=b._data;switch(z.length){case 1:if(z[0]===1)return _1(i[0]);throw new RangeError("Matrix must be square (size: "+N1(z)+")");case 2:{var s=z[0],a=z[1];if(s===a){for(var O=0,u=0;u<s;u++)O=r(O,i[u][u]);return O}else throw new RangeError("Matrix must be square (size: "+N1(z)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(z)+")")}}function n(b){var z=b._values,i=b._index,s=b._ptr,a=b._size,O=a[0],u=a[1];if(O===u){var l=0;if(z.length>0)for(var d=0;d<u;d++)for(var A=s[d],h=s[d+1],q=A;q<h;q++){var _=i[q];if(_===d){l=r(l,z[q]);break}if(_>d)break}return l}throw new RangeError("Matrix must be square (size: "+N1(a)+")")}}),Qs="det",EW=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],TW=h0(Qs,EW,M=>{var{typed:e,matrix:t,subtractScalar:r,multiply:o,divideScalar:n,isZero:b,unaryMinus:z}=M;return e(Qs,{any:function(a){return _1(a)},"Array | Matrix":function(a){var O;switch(F1(a)?O=a.size():Array.isArray(a)?(a=t(a),O=a.size()):O=[],O.length){case 0:return _1(a);case 1:if(O[0]===1)return _1(a.valueOf()[0]);if(O[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+N1(O)+")");case 2:{var u=O[0],l=O[1];if(u===l)return i(a.clone().valueOf(),u);if(l===0)return 1;throw new RangeError("Matrix must be square (size: "+N1(O)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(O)+")")}}});function i(s,a,O){if(a===1)return _1(s[0][0]);if(a===2)return r(o(s[0][0],s[1][1]),o(s[1][0],s[0][1]));for(var u=!1,l=new Array(a).fill(0).map((y,X)=>X),d=0;d<a;d++){var A=l[d];if(b(s[A][d])){var h=void 0;for(h=d+1;h<a;h++)if(!b(s[l[h]][d])){A=l[h],l[h]=l[d],l[d]=A,u=!u;break}if(h===a)return s[A][d]}for(var q=s[A][d],_=d===0?1:s[l[d-1]][d-1],m=d+1;m<a;m++)for(var L=l[m],g=d+1;g<a;g++)s[L][g]=n(r(o(s[L][g],q),o(s[L][d],s[A][g])),_)}var v=s[l[a-1]][a-1];return u?z(v):v}}),Zs="inv",CW=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],xW=h0(Zs,CW,M=>{var{typed:e,matrix:t,divideScalar:r,addScalar:o,multiply:n,unaryMinus:b,det:z,identity:i,abs:s}=M;return e(Zs,{"Array | Matrix":function(u){var l=F1(u)?u.size():M2(u);switch(l.length){case 1:if(l[0]===1)return F1(u)?t([r(1,u.valueOf()[0])]):[r(1,u[0])];throw new RangeError("Matrix must be square (size: "+N1(l)+")");case 2:{var d=l[0],A=l[1];if(d===A)return F1(u)?t(a(u.valueOf(),d,A),u.storage()):a(u,d,A);throw new RangeError("Matrix must be square (size: "+N1(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(l)+")")}},any:function(u){return r(1,u)}});function a(O,u,l){var d,A,h,q,_;if(u===1){if(q=O[0][0],q===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,q)]]}else if(u===2){var m=z(O);if(m===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(O[1][1],m),r(b(O[0][1]),m)],[r(b(O[1][0]),m),r(O[0][0],m)]]}else{var L=O.concat();for(d=0;d<u;d++)L[d]=L[d].concat();for(var g=i(u).valueOf(),v=0;v<l;v++){var y=s(L[v][v]),X=v;for(d=v+1;d<u;)s(L[d][v])>y&&(y=s(L[d][v]),X=d),d++;if(y===0)throw Error("Cannot calculate inverse, determinant is zero");d=X,d!==v&&(_=L[v],L[v]=L[d],L[d]=_,_=g[v],g[v]=g[d],g[d]=_);var T=L[v],N=g[v];for(d=0;d<u;d++){var D=L[d],C=g[d];if(d!==v){if(D[v]!==0){for(h=r(b(D[v]),T[v]),A=v;A<l;A++)D[A]=o(D[A],n(h,T[A]));for(A=0;A<l;A++)C[A]=o(C[A],n(h,N[A]))}}else{for(h=T[v],A=v;A<l;A++)D[A]=r(D[A],h);for(A=0;A<l;A++)C[A]=r(C[A],h)}}}return g}}}),e3="pinv",SW=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],FW=h0(e3,SW,M=>{var{typed:e,matrix:t,inv:r,deepEqual:o,equal:n,dotDivide:b,dot:z,ctranspose:i,divideScalar:s,multiply:a,add:O,Complex:u}=M;return e(e3,{"Array | Matrix":function(m){var L=F1(m)?m.size():M2(m);switch(L.length){case 1:return q(m)?i(m):L[0]===1?r(m):b(i(m),z(m,m));case 2:{if(q(m))return i(m);var g=L[0],v=L[1];if(g===v)try{return r(m)}catch(y){if(!(y instanceof Error&&y.message.match(/Cannot calculate inverse, determinant is zero/)))throw y}return F1(m)?t(l(m.valueOf(),g,v),m.storage()):l(m,g,v)}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(L)+")")}},any:function(m){return n(m,0)?_1(m):s(1,m)}});function l(_,m,L){var{C:g,F:v}=A(_,m,L),y=a(r(a(i(g),g)),i(g)),X=a(i(v),r(a(v,i(v))));return a(X,y)}function d(_,m,L){for(var g=_1(_),v=0,y=0;y<m;y++){if(L<=v)return g;for(var X=y;h(g[X][v]);)if(X++,m===X&&(X=y,v++,L===v))return g;[g[X],g[y]]=[g[y],g[X]];for(var T=g[y][v],N=0;N<L;N++)g[y][N]=b(g[y][N],T);for(var D=0;D<m;D++)if(D!==y){T=g[D][v];for(var C=0;C<L;C++)g[D][C]=O(g[D][C],a(-1,a(T,g[y][C])))}v++}return g}function A(_,m,L){var g=d(_,m,L),v=_.map((X,T)=>X.filter((N,D)=>D<m&&!h(z(g[D],g[D])))),y=g.filter((X,T)=>!h(z(g[T],g[T])));return{C:v,F:y}}function h(_){return n(O(_,u(1,1)),O(0,u(1,1)))}function q(_){return o(O(_,u(1,1)),O(a(_,0),u(1,1)))}}),IW="divide",PW=["typed","matrix","multiply","equalScalar","divideScalar","inv"],kW=h0(IW,PW,M=>{var{typed:e,matrix:t,multiply:r,equalScalar:o,divideScalar:n,inv:b}=M,z=rp({typed:e,equalScalar:o}),i=Mp({typed:e});return e("divide",hc({"Array | Matrix, Array | Matrix":function(a,O){return r(a,b(O))},"DenseMatrix, any":function(a,O){return i(a,O,n,!1)},"SparseMatrix, any":function(a,O){return z(a,O,n,!1)},"Array, any":function(a,O){return i(t(a),O,n,!1).valueOf()},"any, Array | Matrix":function(a,O){return r(a,b(O))}},n.signatures))}),t3="sum",$W=["typed","config","add","numeric"],UW=h0(t3,$W,M=>{var{typed:e,config:t,add:r,numeric:o}=M;return e(t3,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":b,"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function sum");return n(i)}});function n(z){var i;return fM(z,function(s){try{i=i===void 0?s:r(i,s)}catch(a){throw gt(a,"sum",s)}}),i===void 0&&(i=o(0,t.number)),typeof i=="string"&&(i=o(i,t.number)),i}function b(z,i){try{var s=tp(z,i,r);return s}catch(a){throw gt(a,"sum")}}}),r3="median",jW=["typed","add","divide","compare","partitionSelect"],HW=h0(r3,jW,M=>{var{typed:e,add:t,divide:r,compare:o,partitionSelect:n}=M;function b(s){try{s=Hb(s.valueOf());var a=s.length;if(a===0)throw new Error("Cannot calculate median of an empty array");if(a%2===0){for(var O=a/2-1,u=n(s,O+1),l=s[O],d=0;d<O;++d)o(s[d],l)>0&&(l=s[d]);return i(l,u)}else{var A=n(s,(a-1)/2);return z(A)}}catch(h){throw gt(h,"median")}}var z=e({"number | BigNumber | Complex | Unit":function(a){return a}}),i=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(a,O){return r(t(a,O),2)}});return e(r3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(a,O){throw new Error("median(A, dim) is not yet supported")},"...":function(a){if(Lo(a))throw new TypeError("Scalar values expected in function median");return b(a)}})}),xo=Yd({config:U2}),op=Jd({}),np=t5({}),bp=o5({}),Ce=p5({Matrix:bp}),C0=Kq({BigNumber:xo,Complex:op,DenseMatrix:Ce,Fraction:np}),YW=F5({typed:C0}),So=P5({typed:C0}),GW=B5({BigNumber:xo,typed:C0}),M3=Nh({typed:C0}),Rt=d5({config:U2,typed:C0}),Fo=c5({typed:C0}),VW=u5({typed:C0}),Io=hh({typed:C0}),o3=v5({typed:C0}),pp=_5({Matrix:bp,equalScalar:Rt,typed:C0}),n3=$5({typed:C0}),b3=f5({typed:C0}),zp=x5({typed:C0}),p3=X5({Fraction:np,typed:C0}),z3=O5({typed:C0}),o2=T5({DenseMatrix:Ce,Matrix:bp,SparseMatrix:pp,typed:C0}),i3=Vh({isNaN:b3,isNumeric:z3,typed:C0}),lM=eW({bignumber:GW,fraction:p3,number:o3}),KW=Jh({config:U2,multiplyScalar:Io,numeric:lM,typed:C0}),JW=Ph({isInteger:Fo,matrix:o2,typed:C0}),c3=$h({matrix:o2,config:U2,typed:C0}),s3=jh({matrix:o2,typed:C0}),Ht=Bh({isInteger:Fo,matrix:o2,typed:C0}),QW=Dh({prod:KW,size:c3,typed:C0}),ZW=Yh({conj:M3,transpose:s3,typed:C0}),qM=rW({numeric:lM,typed:C0}),e6=bW({DenseMatrix:Ce,concat:Ht,divideScalar:qM,equalScalar:Rt,matrix:o2,typed:C0}),O3=sW({DenseMatrix:Ce,concat:Ht,equalScalar:Rt,matrix:o2,typed:C0}),a3=Eh({BigNumber:xo,DenseMatrix:Ce,SparseMatrix:pp,config:U2,matrix:o2,typed:C0}),t6=Ch({matrix:o2,multiplyScalar:Io,typed:C0}),r6=uW({DenseMatrix:Ce,concat:Ht,config:U2,matrix:o2,typed:C0}),M6=gh({DenseMatrix:Ce,concat:Ht,equalScalar:Rt,matrix:o2,subtractScalar:n3,typed:C0,unaryMinus:zp}),dM=NW({DenseMatrix:Ce,SparseMatrix:pp,addScalar:So,concat:Ht,equalScalar:Rt,matrix:o2,typed:C0}),u3=zW({BigNumber:xo,DenseMatrix:Ce,Fraction:np,concat:Ht,config:U2,equalScalar:Rt,matrix:o2,typed:C0}),o6=hW({equal:O3,typed:C0}),A3=BW({addScalar:So,conj:M3,multiplyScalar:Io,size:c3,typed:C0}),n6=lW({DenseMatrix:Ce,concat:Ht,config:U2,matrix:o2,typed:C0}),ip=LW({config:U2,numeric:lM,smaller:r6,typed:C0}),yr=_h({addScalar:So,dot:A3,equalScalar:Rt,matrix:o2,multiplyScalar:Io,typed:C0}),b6=_W({compare:u3,isNaN:b3,isNumeric:z3,typed:C0}),p6=UW({add:dM,config:U2,numeric:lM,typed:C0}),z6=XW({add:dM,matrix:o2,typed:C0}),f3=TW({divideScalar:qM,isZero:VW,matrix:o2,multiply:yr,subtractScalar:n3,typed:C0,unaryMinus:zp}),i6=gW({config:U2,larger:n6,numeric:lM,typed:C0}),Po=xW({abs:YW,addScalar:So,det:f3,divideScalar:qM,identity:a3,matrix:o2,multiply:yr,typed:C0,unaryMinus:zp}),c6=FW({Complex:op,add:dM,ctranspose:ZW,deepEqual:o6,divideScalar:qM,dot:A3,dotDivide:e6,equal:O3,inv:Po,matrix:o2,multiply:yr,typed:C0}),s6=oW({Complex:op,config:U2,fraction:p3,identity:a3,inv:Po,matrix:o2,multiply:yr,number:o3,typed:C0}),O6=kW({divideScalar:qM,equalScalar:Rt,inv:Po,matrix:o2,multiply:yr,typed:C0}),l3=HW({add:dM,compare:u3,divide:O6,partitionSelect:b6,typed:C0});class a6{constructor(e,t,r){E(this,"_cacheData");E(this,"_variables");E(this,"_math");E(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}alma({series:e,length:t,offset:r,sigma:o,floor:n,isSeriesLen:b},z){if(t===void 0||r===void 0||o===void 0)return;const i=this._cacheDataList(e,t,`alma_${z}`,b);if(i===void 0)return;let s=r*(t-1);n&&(s=Math.floor(s));const a=t/o;let O=0,u=0;for(let l=0;l<=t-1;l++){const d=Math.exp(-1*Math.pow(l-s,2)/(2*Math.pow(a,2)));O+=d,u+=i[i.length-1-(t-l-1)]*d}return u/O}sma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const b=this._cacheDataList(e,t,`sma_${o}`,r);if(b===void 0)return;const z=b.slice(-t);return n=p6(...z)/t,n}rma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`rma_${o}`);if(n)return n==null?void 0:n.sum;const{sum:b}=this._getCacheData(`rma_${o}`),z=1/t,i=this.sma({source:e,length:t,isSeriesLen:r},o),s=b===void 0?i:z*e+(1-z)*(b||0);return this._cacheDataHandle(`rma_${o}`,{sum:s}),s}atr({length:e,isSeriesLen:t},r){const o=this._verifyCacheData(`atr_${r}`);if(o)return o==null?void 0:o.value;const{high:n,close:b}=this._getCacheData(`atr_${r}`),{high:z,close:i,low:s}=this._variables,a=n===void 0?z-s:Math.max(Math.max(z-s,Math.abs(z-b)),Math.abs(s-b)),O=this.rma({source:a,length:e,isSeriesLen:t},r);return this._cacheDataHandle(`atr_${r}`,{high:z,close:i,value:O}),O}barssince({condition:e},t){const r=this._verifyCacheData(`barssince_${t}`);if(r)return r==null?void 0:r.count;let{count:o}=this._getCacheData(`barssince_${t}`);if(e)o=0;else{if(o===void 0)return;o+=1}return this._cacheDataHandle(`barssince_${t}`,{count:o}),o}stdev({source:e,length:t,biased:r=!0,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0)return;const b=this._cacheDataList(e,t,`stdev_${n}`,o),z=this.sma({source:e,length:t,isSeriesLen:o},n);if(b===void 0)return;let i=0;for(let s=0;s<t;s++){const a=this._sum(b[b.length-1-s],-(z||0));i+=a*a}return r||t<=1?Math.sqrt(i/t):Math.sqrt(i/(t-1))}_sum(e,t){let o=e+t;return Math.abs(o)<=1e-10&&(o=0),o}bb({series:e,length:t,mult:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this.stdev({source:e,length:t,isSeriesLen:o},n);if(b===void 0||z===void 0)return[];const i=r*z;return[b,b+i,b-i]}bbw({series:e,length:t,mult:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this.stdev({source:e,length:t,isSeriesLen:o},n);if(b===void 0||z===void 0)return;const i=r*z;return(b+i-(b-i))/b}cci({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},o),b=this.dev({source:e,length:t,isSeriesLen:r},o);if(!(n===void 0||b===void 0))return(e-n)/(.015*b)}change({source:e,length:t=1,isSeriesLen:r},o){const n=this._cacheDataList(e,t,`change_${o}`,r);if(n===void 0)return;const b=n[n.length-1-t];if(!(e===void 0||isNaN(e)))return b===void 0?b:typeof e=="boolean"?b!==e:e-b}cmo({series:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const o=this.change({source:e},r);if(o===void 0)return;const n=this._math.sum({source:o>=0?o:0,length:t},`sm1_${r}`),b=this._math.sum({source:o>=0?0:-o,length:t},`sm2_${r}`);if(!(n===void 0||b===void 0))return 100*(n-b)/(n+b)}cog({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${o}`,r),b=this._math.sum({source:e,length:t},o);if(b===void 0||n===void 0)return;let z=0;for(let i=0;i<t;i++){const s=n[n.length-1-i];z+=s*(i+1)}return-z/b}correlation({source1:e,source2:t,length:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||isNaN(t)||r===void 0)return;const b=this._cacheDataList([e,t],r,`correlation_${n}`,o),z=this.sma({source:e,length:r,isSeriesLen:o},`sma1_${n}`),i=this.sma({source:t,length:r,isSeriesLen:o},`sma2_${n}`);if(z===void 0||i===void 0||b===void 0)return;let s=0,a=0,O=0;for(let l=0;l<r;l++){const[d,A]=b[b.length-1-l],h=d-z,q=A-i;s+=h*q,a+=h*h,O+=q*q}return isNaN(a)||isNaN(s)||isNaN(O)?void 0:s/Math.sqrt(a*O)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`cross_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`cross_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n>=b&&e<t||n<=b&&e>t,this._cacheDataHandle(`cross_${r}`,{source1:e,source2:t,value:z}),z}crossover({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`crossover_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`crossover_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n<=b&&e>t,this._cacheDataHandle(`crossover_${r}`,{source1:e,source2:t,value:z}),z}crossunder({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`crossunder_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`crossunder_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n>=b&&e<t,this._cacheDataHandle(`crossunder_${r}`,{source1:e,source2:t,value:z}),z}cum({source:e=0},t){const r=this._verifyCacheData(`cum_${t}`);if(r)return r==null?void 0:r.sum;e=isNaN(e)?0:e;let{sum:o}=this._getCacheData(`cum_${t}`);return o=o||0,o+=e,this._cacheDataHandle(`cum_${t}`,{sum:o}),o}dev({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},o);let b=0;const z=this._cacheDataList(e,t,`dev_${o}`,r);if(!(!z||n===void 0)){for(let i=0;i<t;i++){const s=z[z.length-1-i];b+=Math.abs(s-n)}return b/t}}dmi({diLength:e,adxSmoothing:t},r){if(e===void 0||t===void 0)return[void 0,void 0,void 0];const o=`dmi_${r}`,n=this._verifyCacheData(o);if(n)return n==null?void 0:n.value;const{low:b,high:z,close:i,PDMS:s,NDMS:a,TRS:O,ADX:u,count:l=0}=this._getCacheData(o),{low:d,high:A,close:h}=this._variables;if(b===void 0||z===void 0||i===void 0)return this._cacheData[o]={low:d,high:A,close:h,PDMS:s,NDMS:a,TRS:A-d,count:1},[void 0,void 0,void 0];let q=A-z,_=b-d;q=q>_&&q>0?q:0,_=_>q&&_>0?_:0,q===_&&(q=_=0);const m=Math.max(A-d,Math.abs(A-i),Math.abs(d-i));let L={};if(l<e)L={low:d,high:A,close:h,PDMS:(s||0)+q,NDMS:(a||0)+_,TRS:(O||0)+m,count:l+1,value:[void 0,void 0,void 0]};else{const g=s-s/e+q,v=a-a/e+_,y=O-O/e+m,X=g/y*100,T=v/y*100,N=Math.abs((X-T)/(X+T))*100;let D=N,C=[X,T,void 0];if(l+1-e<t){const P=l+1-e;D=((u||0)*(P-1)+N)/P}else D=(u*(t-1)+N)/t,C=[X,T,D];L={low:d,high:A,close:h,PDMS:g,NDMS:v,TRS:y,ADX:D,count:l+1,value:C}}return this._cacheDataHandle(o,L),L.value}ema({source:e,length:t,isSeriesLen:r},o){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`ema_${o}`);if(n)return n==null?void 0:n.sum;let{sum:b,count:z=1}=this._getCacheData(`ema_${o}`);const i=this.sma({source:e,length:t,isSeriesLen:r},o);if(z>t){const s=2/(t+1);b=b===void 0?e:s*e+(1-s)*(b||0)}else b=i;return z+=1,this._cacheDataHandle(`ema_${o}`,{sum:b,count:z}),b}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const o=this._verifyCacheData(`falling_${r}`);if(o)return o==null?void 0:o.value;const{source:n,fallings:b=[]}=this._getCacheData(`falling_${r}`);b.push(n>e);const z=b.slice(-t);let i=!1;return z.length<t?i=!1:i=z.every(s=>s),this._cacheDataHandle(`falling_${r}`,{source:e,fallings:z,value:i}),i}rising({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const o=this._verifyCacheData(`rising_${r}`);if(o)return o==null?void 0:o.value;const{source:n,risings:b=[]}=this._getCacheData(`rising_${r}`);b.push(n<e);const z=b.slice(-t);let i=!1;return z.length<t?i=!1:i=z.every(s=>s),this._cacheDataHandle(`rising_${r}`,{source:e,risings:z,value:i}),i}highest({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highest_${o}`,r);if(b)return Math.max(...b.slice(-t))}highestbars({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highestbars_${o}`,r);return b?b.slice(-t).reduce((i,s,a,O)=>s>=O[i]?a:i,0)-t+1:void 0}wma({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${o}`,r);if(!n)return;let b=0,z=0;for(let i=0;i<t;i++){const s=(t-i)*t;b+=s,z+=n[n.length-1-i]*s}return z/b}hma({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t,isSeriesLen:r},o),b=this.wma({source:e,length:Math.round(t/2),isSeriesLen:r},`half_${o}`);return n===void 0||b===void 0?void 0:this.wma({source:2*b-n,length:Math.floor(Math.sqrt(t)),isSeriesLen:r},`hma_${o}`)}kc({series:e,length:t,mult:r,useTrueRange:o=!0,isSeriesLen:n},b){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[void 0,void 0,void 0];const z=this.ema({source:e,length:t,isSeriesLen:n},b),{ta:i,high:s,low:a}=this._variables,O=o?i.tr:s-a,u=this.ema({source:O,length:t,isSeriesLen:n},`range_${b}`);return[z,z+u*r,z-u*r]}kcw({series:e,length:t,mult:r,useTrueRange:o=!0,isSeriesLen:n},b){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const z=this.ema({source:e,length:t,isSeriesLen:n},b),{ta:i,high:s,low:a}=this._variables,O=o?i.tr:s-a,u=this.ema({source:O,length:t,isSeriesLen:n},`range_${b}`);return(z+u*r-(z-u*r))/z}linreg({source:e,length:t,offset:r,isSeriesLen:o},n){if(t===void 0||r===void 0)return;const b=this._cacheDataList(e,t,`dev_${n}`,o);if(!b)return;const z=b.slice(-t).filter(d=>d!==void 0);let i=0,s=0,a=0,O=0;for(const[d,A]of z.entries())i+=d,s+=A,a+=d*A,O+=d*d;const u=(t*a-i*s)/(t*O-i*i);return(s-u*i)/t+u*(t-1-r)}lowest({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowest_${o}`,r);if(b)return Math.min(...b.slice(-t))}lowestbars({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowestbars_${o}`,r);return b?b.slice(-t).reduce((i,s,a,O)=>s<=O[i]?a:i,0)-t+1:void 0}macd({source:e,fastlen:t,slowlen:r,siglen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0||o===void 0)return[void 0,void 0,void 0];const b=this.ema({source:e,length:t},`ema1_${n}`),z=this.ema({source:e,length:r},`ema2_${n}`);if(b===void 0||z===void 0)return[void 0,void 0,void 0];const i=b-z,s=this.ema({source:i,length:o},`macd_${n}`);if(s===void 0)return[i,s,void 0];const a=i-s;return[i,s,a]}max({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`max_${t}`]||0;return e>r&&(r=e),this._cacheData[`max_${t}`]=r,r}min({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`min_${t}`]||1/0;return e<r&&(r=e),this._cacheData[`min_${t}`]=r,r}median({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${o}`,r);if(n)return l3(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:o}=this._variables,n=this.change({source:e},r),b=this._math.sum({source:o*(n>=0?0:e),length:t},`lower_${r}`),z=this._math.sum({source:o*(n<=0?0:e),length:t},`upper_${r}`);if(!(z===void 0||b===void 0))return 100-100/(1+z/b)}mode({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${o}`,r);if(n)return ip(i3(n.slice(-t)))}mom({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=`mom_${o}`,b=this._cacheDataList(e,t,n,r);if(!b||b.length<=t||e===void 0||isNaN(e))return;let z=b.length-t-1,i;for(;i===void 0&&z>=0;)i=b[z],z--;return i===void 0?i:e-i}percentile_linear_interpolation({source:e,length:t,percentage:r,isSeriesLen:o},n){if(t===void 0||r===void 0||t<0||r<0||r>100)return;const b=this._cacheDataList(e,t+1,`percentile_linear_interpolation_${n}`,o);if(!b)return;const z=this._sort(b.slice(-(t+1))),i=z.length;r/=100;const s=1/(i*2);if(r<=s)return z[0];if(r>=1-1/(i*2))return z[i-1];for(const[a,O]of z.entries()){const u=z[a-1];if(r<(a+.5)/i)return u===void 0||O===void 0?void 0:u+(O-u)*(r-(a-.5)/i)/(1/i)}}percentile_nearest_rank({source:e,length:t,percentage:r,isSeriesLen:o},n){if(t===void 0||r===void 0||e===void 0||isNaN(e)||t<0||r<0||r>100)return;const b=this._cacheDataList(e,t,`percentile_nearest_rank_${n}`,o);if(!b)return;const z=this._sort(b.slice(-t)),i=r/100*z.length,s=Math.ceil(i)-1;return z[s>=z.length?z.length-1:s]}percentrank({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${o}`,r);if(!n)return;const b=n.slice(-(t+1)),z=e;if(z===void 0)return;let i=0;for(let s=0;s<b.length;s++)b[s]!==void 0&&(b[s]<z||b[s]===z&&s<t)&&i++;return i/(b.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},o){const n=new n1;let{close:b,open:z,low:i,high:s}=this._variables;const a=`pivot_point_levels_${o}`,O=this._verifyCacheData(a);if(O)return n._value=(O==null?void 0:O.result)||[],n;const{close:u,low:l,high:d,open:A,result:h}=this._getCacheData(a);if(!t&&(d&&l&&(s=Math.max(d,s),i=Math.min(l,i)),this._cacheDataHandle(a,{close:b,open:z,low:i,high:s,result:h}),!r))return n._value=h||[],n;const q={close:b,open:z,low:i,high:s};t===!0&&!r&&(b=u,z=A,i=l,s=d);const _=this._getPivotPointLevels(s,i,b,z,r,e);return this._cacheDataHandle(a,{...q,result:_}),n._value=_,n}_getPivotPointLevels(e,t,r,o,n,b){if(r===void 0||o===void 0||t===void 0||e===void 0)return[];switch(b){case Ft.traditional:return this._traditional(e,t,r);case Ft.fibonacci:return this._fibonacci(e,t,r);case Ft.woodie:return n?[]:this._woodie(e,t);case Ft.classic:return this._classic(e,t,r);case Ft.dm:return this._DM(e,t,r,o);case Ft.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const o=(e+t+r)/3,n=o*2-t,b=o+(e-t),z=o*2+(e-2*t),i=o*3+(e-3*t),s=o*4+(e-4*t),a=o*2-e,O=o-(e-t),u=o*2-(2*e-t),l=o*3-(3*e-t),d=o*4-(4*e-t);return[o,n,a,b,O,z,u,i,l,s,d]}_fibonacci(e,t,r){const o=(e+t+r)/3,n=o+.382*(e-t),b=o-.382*(e-t),z=o+.618*(e-t),i=o-.618*(e-t),s=o+(e-t),a=o-(e-t);return[o,n,b,z,i,s,a]}_woodie(e,t){const{open:r}=this._variables,o=(e+t+2*r)/4,n=2*o-t,b=2*o-e,z=o+(e-t),i=o-(e-t),s=e+2*(o-t),a=t-2*(e-o),O=s+(e-t),u=a-(e-t);return[o,n,b,z,i,s,a,O,u]}_classic(e,t,r){const o=(e+t+r)/3,n=2*o-t,b=2*o-e,z=o+(e-t),i=o-(e-t),s=o+2*(e-t),a=o-2*(e-t),O=o+3*(e-t),u=o-3*(e-t);return[o,n,b,z,i,s,a,O,u]}_DM(e,t,r,o){let n;o===r?n=e+t+2*r:r>o?n=2*e+t+r:n=2*t+e+r;const b=n/4,z=n/2-t,i=n/2-e;return[b,z,i]}_camarilla(e,t,r){const o=(e+t+r)/3,n=r+1.1*(e-t)/12,b=r-1.1*(e-t)/12,z=r+1.1*(e-t)/6,i=r-1.1*(e-t)/6,s=r+1.1*(e-t)/4,a=r-1.1*(e-t)/4,O=r+1.1*(e-t)/2,u=r-1.1*(e-t)/2,l=e/t*r,d=r-(l-r);return[o,n,b,z,i,s,a,O,u,l,d]}pivothigh(e,t){const{leftbars:r,rightbars:o}=e;if(r===void 0||o===void 0||r<0||o<0)return;let n=this._variables.high;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+o+1,`pivothigh_${t}`);if(!b)return;const z=b.slice(-(r+o+1)),i=z[r],s=z.splice(0,r+1),a=Math.max(...z),O=Math.max(...s);return i>=O&&i>a?i:void 0}pivotlow(e,t){const{leftbars:r,rightbars:o}=e;if(r===void 0||o===void 0||r<0||o<0)return;let n=this._variables.low;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+o+1,`pivotlow_${t}`);if(!b)return;const z=b.slice(-(r+o+1)),i=z[r],s=z.splice(0,r+1),a=Math.min(...z),O=Math.min(...s);return i<=O&&i<a?i:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const o=this._cacheDataList(e,t,`range_${r}`,!0);if(!o)return;const n=o.filter(i=>i!==void 0).slice(-t),b=Math.max(...n),z=Math.min(...n);return b-z}roc({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${o}`,r),b=this.change({source:e,length:t,isSeriesLen:r},o);if(n)return 100*b/n[n.length-1-t]}rsi({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._verifyCacheData(`rsi_${o}`);if(n)return n==null?void 0:n.value;const{source:b}=this._getCacheData(`rsi_${o}`),z=Math.max(e-b,0),i=Math.max(b-e,0),s=this.rma({source:z,length:t,isSeriesLen:r},`rma1_${o}`),a=this.rma({source:i,length:t,isSeriesLen:r},`rma2_${o}`),O=s===void 0||a===void 0?void 0:100-100/(1+s/a);return this._cacheDataHandle(`rsi_${o}`,{source:e,value:O}),O}sar({start:e,inc:t,max:r},o){if(e===void 0||t===void 0||r===void 0)return;const n=this._verifyCacheData(`sar_${o}`);if(n)return n==null?void 0:n.result;const{close:b,low:z,high:i,preLow:s,preHigh:a,data:O={}}=this._getCacheData(`sar_${o}`);let{result:u,maxMin:l,acceleration:d,isBelow:A}=O,h=!1;const{close:q,low:_,high:m,bar_index:L}=this._variables;return L===1&&(q>b?(A=!0,l=m,u=z):(A=!1,l=_,u=i),h=!0,d=e),u=u+d*(l-u),A?u>_&&(h=!0,A=!1,u=Math.max(m,l||0),l=_,d=e):u<m&&(h=!0,A=!0,u=Math.min(_,l||0),l=m,d=e),h||(A?m>(l||0)&&(l=m,d=Math.min((d||0)+t,r)):_<(l||0)&&(l=_,d=Math.min((d||0)+t,r))),A?(u=Math.min(u,z),L>1&&(u=Math.min(u,s))):(u=Math.max(u,i),L>1&&(u=Math.max(u,a))),this._cacheDataHandle(`sar_${o}`,{high:m,close:q,low:_,preLow:z,preHigh:i,data:Object.assign(O,{result:u,maxMin:l,acceleration:d,isBelow:A})}),u}stoch({source:e,high:t,low:r,length:o,isSeriesLen:n},b){if(o===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||o<0)return;const z=this.lowest({source:r,length:o,isSeriesLen:n},b),i=this.highest({source:t,length:o,isSeriesLen:n},b);if(!(z===void 0||i===void 0))return 100*(e-z)/(i-z)}supertrend({factor:e,atrPeriod:t},r){if(e===void 0||t===void 0)return[void 0,void 0];const o=`supertrend_${r}`,n=this._verifyCacheData(o);if(n)return n==null?void 0:n.value;let b=1;const{hl2:z,close:i}=this._variables,{upperBand:s,lowerBand:a,superTrend:O,atr:u,close:l}=this._getCacheData(o),d=this.atr({length:t},r);if(d===void 0)return this._cacheDataHandle(o,{close:i,value:[void 0,b]}),[void 0,b];let A=z+e*d,h=z-e*d;const q=s||0,_=a||0;h=h>_||l<_?h:_,A=A<q||l>q?A:q,u===void 0?b=1:O===q?b=i>A?-1:1:b=i<h?1:-1;const m=b===-1?h:A;return this._cacheDataHandle(o,{upperBand:A,lowerBand:h,superTrend:m,atr:d,close:i,value:[m,b]}),[m,b]}swma({source:e},t){const r=this._verifyCacheData(`swma_${t}`);if(r)return r==null?void 0:r.value;let{list:o}=this._getCacheData(`swma_${t}`);o||(o=[]),o.push(e),o=o.slice(-4);const n=o.filter(b=>b!==void 0).length<4?void 0:o[3]*1/6+o[2]*2/6+o[1]*2/6+o[0]*1/6;return this._cacheDataHandle(`swma_${t}`,{list:o,value:n}),n}tr({handle_na:e=!1},t){const{close:r,low:o,high:n}=this._variables,b=this._verifyCacheData(`tr_${t}`);if(b)return b==null?void 0:b.value;const{close:z}=this._getCacheData(`tr_${t}`);let i;return z===void 0?i=e?n-o:void 0:i=Math.max(n-o,Math.abs(n-z),Math.abs(o-z)),this._cacheDataHandle(`tr_${t}`,{close:r,value:i}),i}tsi({source:e,short_length:t,long_length:r},o){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const n=this.change({source:e},o);if(n===void 0)return;const b=this._doubleSmooth(n,r,t,o),z=this._doubleSmooth(Math.abs(n),r,t,`abs_${o}`);if(!(z===void 0||b===void 0))return b/z}_doubleSmooth(e,t,r,o){const n=this.ema({source:e,length:t},`ema1_${o}`);return this.ema({source:n,length:r},`ema2_${o}`)}valuewhen({condition:e,source:t,occurrence:r},o){if(r===void 0||r<0)return;let{list:n}=this._getCacheData(`valuewhen_${o}`);n||(n=[]),e&&n.push(t);const b=n[n.length-1-r];return this._cacheDataHandle(`valuewhen_${o}`,{list:n,value:b}),b}variance({source:e,length:t,biased:r=!0,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this._cacheDataList(e,t,`variance_${n}`,!0);if(!z||b===void 0)return;const i=z.filter(a=>a!==void 0&&!isNaN(a)).slice(-t);if(i.length<t)return;const s=i.reduce((a,O)=>a+Math.pow(O-b,2),0);if(s!==void 0)return r||t<=1?s/t:s/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},o){if(e===void 0)return;const n=`vwap_${o}`,b=this._verifyCacheData(n);if(b)return b==null?void 0:b.value;t=t===void 0?this._timeframe.change({timeframe:"1D"},o):t;const{volume:z}=this._variables;let{sum:i=0,sumV:s=0,count:a=0,isReset:O,sumS:u=0}=this._getCacheData(n);if(t&&(i=s=a=u=0,O=!0),!O)return r!==void 0?[]:void 0;const l=e*z+i,d=z+s,A=l/d;if(a++,r!==void 0){u=z*Math.pow(e,2)+u;const h=this._computeBands(u,d,r,A);return this._cacheDataHandle(n,{sum:l,sumV:d,count:a,isReset:O,sumS:u,value:h}),h}return this._cacheDataHandle(n,{sum:l,sumV:d,count:a,isReset:O,value:A}),A}_computeBands(e,t,r,o){let n=e/t-Math.pow(o,2);n=n<0?0:n;const b=Math.sqrt(n),z=b!==void 0&&!isNaN(b)?o+r*b:void 0,i=b!==void 0&&!isNaN(b)?o-r*b:void 0;return[o,z,i]}vwma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0||t<=0)return;const{volume:n}=this._variables,b=this.sma({source:e*n,length:t,isSeriesLen:r},`sma1_${o}`),z=this.sma({source:n,length:t,isSeriesLen:r},`sma2_${o}`);if(!(b===void 0||z===void 0))return b/z}wpr({length:e,isSeriesLen:t},r){if(e===void 0||e<=0)return;const o=this.highest({length:e,isSeriesLen:t},r),n=this.lowest({length:e,isSeriesLen:t},r),{close:b}=this._variables;if(!(o===void 0||n===void 0))return(o-b)/(o-n)*-100}_sort(e){const t=e.length;for(let r=0;r<t;r++){let o={};for(let n=0;n<t-r;n++){const{currentVal:b,currentIndex:z}=o,i=e[n];if(i!==void 0){if(b!==void 0&&i<b){e.splice(n,1),e.splice(z,0,i),o={currentIndex:z+1,currentVal:b};continue}o={currentIndex:n,currentVal:i}}}}return e}_cacheDataList(e,t,r,o=!1){const n=this._cacheData[r]||{barIndex:-1,list:[],length:t},{bar_index:b}=this._variables;if(n.length<t&&(n.length=t),n.barIndex<=b){const z=n.list.length;if(n.barIndex===b)n.list[z-1]=e;else{let i=b-n.barIndex-1;if(n.barIndex!==-1&&i>0){const s=n.list[z-1];for(;i>0;)n.list.push(s),i--}n.list.push(e)}n.barIndex=b,n.list.length>n.length+5&&!o&&n.list.shift(),this._cacheData[r]=n}if(!(n.list.length<t))return n.list}_getCacheData(e){const{bar_index:t}=this._variables,r=this._cacheData[e]||{};return r.barIndex===t?r.preCacheData||{}:r}_cacheDataHandle(e,t){const{bar_index:r,_isRealTimeBar:o,_isRepeated:n}=this._variables;if(!o&&!n){let b=this._cacheData[e]||{};b.barIndex===r&&(b=b.preCacheData),this._cacheData[e]=Object.assign(t,{barIndex:r,preCacheData:{...b,preCacheData:void 0}})}}_verifyCacheData(e){const{bar_index:t,_isRepeated:r}=this._variables,o=this._cacheData[e]||{},{barIndex:n}=o;if(n===t&&r)return o}}class u6{constructor(e,t,r){E(this,"_cacheData");E(this,"_variables");E(this,"_errorListener");E(this,"_historyInputs");E(this,"_name");this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(e){if(!(e!=null&&e.length)){self.workerStorage.delete(this._name),this._cacheData={};return}for(const t of e){const r=t.id,o=this._historyInputs[r];(!(t!=null&&t.sourceTypeName)&&(o==null?void 0:o.defval)!==t.defval||o!=null&&o.sourceTypeName&&t.sourceTypeName!==(o==null?void 0:o.sourceTypeName))&&(this._cacheData[r]=Object.assign(this._cacheData[r]||{},{...t,isModify:!0}))}}input(e,t){return this._cacheHandle(e,t)}int(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,v2.INT)}bool(e,t){return this._cacheHandle(e,t,v2.BOOL)}color(e,t){return this._cacheHandle(e,t,v2.COLOR)}time(e,t){return this._cacheHandle(e,t,v2.TIME)}float(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,v2.FLOAT)}price(e,t){return this._cacheHandle(e,t,v2.PRICE)}source(e,t){return this._cacheHandle(e,t,v2.SOURCE)}string(e,t){return this._cacheHandle(e,t,v2.STRING)}symbol(e,t){return this._cacheHandle(e,t,v2.SYMBOL)}session(e,t){return this._cacheHandle(e,t,v2.SESSION)}text_area(e,t){return this._cacheHandle(e,t,v2.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,v2.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,v2.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const o=`${r||"input"}_${t}`,n=this._cacheData[o];if(e.defval===void 0&&this._errorListener.addError(l1.inputDefvalErr,t,$0.Error),self.workerStorage.setValue(this._name,o,{...e}),n)if(!n.isModify)Object.assign(this._cacheData[o],e);else{const b=this._historyInputs[o];!(e.sourceTypeName||b!=null&&b.sourceTypeName)&&e.defval===(b==null?void 0:b.defval)||e.sourceTypeName&&(b==null?void 0:b.sourceTypeName)===e.sourceTypeName?n.sourceTypeName&&(this._cacheData[o].defval=this._variables[n.sourceTypeName]):Object.assign(this._cacheData[o],e)}else{const{defval:b,display:z}=e;if(this._displayVerify(t,z),e={inputType:r,...e},this._cacheData[o]=e,(r||e.inputType)===v2.SOURCE)this._cacheData[o].options=Nu;else if(e.options)if(!e.options.includes(b))this._errorListener.addError(r2(l1.inputOptErr,{defval:String(b),args:e.options.toString()}),t,$0.Error,6+((r==null?void 0:r.length)||-1));else{const i=new Map;for(const s of e.options){if(i.has(s)){this._errorListener.addError(r2(l1.optionsRepeatErr,{option:String(s)}),t,$0.Error,6+((r==null?void 0:r.length)||-1));break}i.set(s,s)}}}return this._cacheData[o].defval}_displayVerify(e,t){!t||!t.length||t.includes(A2.dataWindow)||t.includes(A2.statusLine)||this._errorListener.addError(r2(l1.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,$0.Error)}_verifyMaxOrMin(e,t){const{defval:r,maxval:o,minval:n}=e;typeof r=="number"&&(o!==void 0&&r>o||n!==void 0&&r<n)&&this._errorListener.addError(l1.minOrMaxErr,t,$0.Error)}getInputs(){const e=Object.keys(this._cacheData),t=[];for(const r of e){const o=this._cacheData[r];o.id=r,t.push(o)}return t.sort((r,o)=>(r.index||0)-(o.index||0))}}class A6{color({x:e}){return e===void 0?null:e}new({color:e,transp:t=100}){d0(t)&&(t=100);let r=(100-t)/100;r=r<0?0:r>1?1:r;const{r:o,g:n,b}=this._parseColor(e||"");return`rgba(${Math.round(o)}, ${Math.round(n)}, ${Math.round(b)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:o=0}){return d0(o)&&(o=0),d0(e)&&(e=0),d0(t)&&(t=0),d0(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-o)/100})`}g({color:e}){return e?this._parseColor(e).g:0}r({color:e}){return e?this._parseColor(e).r:0}b({color:e}){return e?this._parseColor(e).b:0}t({color:e}){return e?100-Math.round(this._parseColor(e).a*100):0}from_gradient({value:e,bottom_value:t,top_value:r,bottom_color:o,top_color:n}){if(d0(e)||d0(t)||d0(r)||r===t)return"rgba(0,0,0,1)";const b=(e-t)/(r-t),z=Math.min(Math.max(b,0),1),{r:i,g:s,b:a,a:O}=this._parseColor(o||"rgba(0,0,0,0)"),{r:u,g:l,b:d,a:A}=this._parseColor(n||"rgba(0,0,0,0)"),h=i+z*(u-i),q=s+z*(l-s),_=a+z*(d-a),m=O+z*(A-O);return`rgba(${Math.round(h)}, ${Math.round(q)}, ${Math.round(_)}, ${m.toFixed(2)})`}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3],n=n===void 0?1:n}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/[\d.]+/g))==null?void 0:t.map(Number))||[]}}var Z0={};const f6=Object.prototype.toString;function hM(M){const e=f6.call(M);return e.endsWith("Array]")&&!e.includes("Big")}var l6=Object.freeze({__proto__:null,isAnyArray:hM}),q6=V1(l6);function d6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!hM(M))throw new TypeError("input must be an array");if(M.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,o=e.toIndex,n=o===void 0?M.length:o;if(r<0||r>=M.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>M.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=M[r],z=r+1;z<n;z++)M[z]>b&&(b=M[z]);return b}function h6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!hM(M))throw new TypeError("input must be an array");if(M.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,o=e.toIndex,n=o===void 0?M.length:o;if(r<0||r>=M.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>M.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=M[r],z=r+1;z<n;z++)M[z]<b&&(b=M[z]);return b}function W6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(hM(M)){if(M.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var t;if(e.output!==void 0){if(!hM(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(M.length);var r=h6(M),o=d6(M);if(r===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=e.min,b=n===void 0?e.autoMinMax?r:0:n,z=e.max,i=z===void 0?e.autoMinMax?o:1:z;if(b>=i)throw new RangeError("min option must be smaller than max option");for(var s=(i-b)/(o-r),a=0;a<M.length;a++)t[a]=(M[a]-r)*s+b;return t}var _6=Object.freeze({__proto__:null,default:W6}),m6=V1(_6);Object.defineProperty(Z0,"__esModule",{value:!0});var C2=q6,q3=m6;const ko=" ".repeat(2),d3=" ".repeat(4);function g6(){return h3(this)}function h3(M,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:o=8,padMinus:n="auto"}=e;return`${M.constructor.name} {
|
68
|
+
(`+N1(X,A)+", "+N1(L,A)+") ==> "+(this._values?N1(this._values[y],A):"X")}return m},o.prototype.toString=function(){return N1(this.toArray())},o.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},o.prototype.diagonal=function(A){if(A){if(Q1(A)&&(A=A.toNumber()),!X1(A)||!$1(A))throw new TypeError("The parameter k must be an integer number")}else A=0;var h=A>0?A:0,q=A<0?-A:0,_=this._size[0],m=this._size[1],L=Math.min(_-q,m-h),g=[],v=[],y=[];y[0]=0;for(var X=h;X<m&&g.length<L;X++)for(var T=this._ptr[X],N=this._ptr[X+1],D=T;D<N;D++){var C=this._index[D];if(C===X-h+q){g.push(this._values[D]),v[g.length-1]=C-q;break}}return y.push(g.length),new o({values:g,index:v,ptr:y,size:[L,1]})},o.fromJSON=function(A){return new o(A)},o.diagonal=function(A,h,q,_,m){if(!H1(A))throw new TypeError("Array expected, size parameter");if(A.length!==2)throw new Error("Only two dimensions matrix are supported");if(A=A.map(function(z0){if(Q1(z0)&&(z0=z0.toNumber()),!X1(z0)||!$1(z0)||z0<1)throw new Error("Size values must be positive integers");return z0}),q){if(Q1(q)&&(q=q.toNumber()),!X1(q)||!$1(q))throw new TypeError("The parameter k must be an integer number")}else q=0;var L=t,g=0;Ee(m)&&(L=e.find(t,[m,m])||t,g=e.convert(0,m));var v=q>0?q:0,y=q<0?-q:0,X=A[0],T=A[1],N=Math.min(X-y,T-v),D;if(H1(h)){if(h.length!==N)throw new Error("Invalid value array length");D=function(a0){return h[a0]}}else if(F1(h)){var C=h.size();if(C.length!==1||C[0]!==N)throw new Error("Invalid matrix length");D=function(a0){return h.get([a0])}}else D=function(){return h};for(var P=[],H=[],G=[],k=0;k<T;k++){G.push(P.length);var J=k-v;if(J>=0&&J<N){var o0=D(J);L(o0,g)||(H.push(J+y),P.push(o0))}}return G.push(P.length),new o({values:P,index:H,ptr:G,size:[X,T]})},o.prototype.swapRows=function(A,h){if(!X1(A)||!$1(A)||!X1(h)||!$1(h))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return Y1(A,this._size[0]),Y1(h,this._size[0]),o._swapRows(A,h,this._size[1],this._values,this._index,this._ptr),this},o._forEachRow=function(A,h,q,_,m){for(var L=_[A],g=_[A+1],v=L;v<g;v++)m(q[v],h[v])},o._swapRows=function(A,h,q,_,m,L){for(var g=0;g<q;g++){var v=L[g],y=L[g+1],X=s(A,v,y,m),T=s(h,v,y,m);if(X<y&&T<y&&m[X]===A&&m[T]===h){if(_){var N=_[X];_[X]=_[T],_[T]=N}continue}if(X<y&&m[X]===A&&(T>=y||m[T]!==h)){var D=_?_[X]:void 0;m.splice(T,0,h),_&&_.splice(T,0,D),m.splice(T<=X?X+1:X,1),_&&_.splice(T<=X?X+1:X,1);continue}if(T<y&&m[T]===h&&(X>=y||m[X]!==A)){var C=_?_[T]:void 0;m.splice(X,0,A),_&&_.splice(X,0,C),m.splice(X<=T?T+1:T,1),_&&_.splice(X<=T?T+1:T,1)}}},o},{isClass:!0}),m5="number",g5=["typed"];function R5(M){var e=M.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(e){var t={"0b":2,"0o":8,"0x":16}[e[1]],r=e[2],o=e[3];return{input:M,radix:t,integerPart:r,fractionalPart:o}}else return null}function L5(M){for(var e=parseInt(M.integerPart,M.radix),t=0,r=0;r<M.fractionalPart.length;r++){var o=parseInt(M.fractionalPart[r],M.radix);t+=o/Math.pow(M.radix,r+1)}var n=e+t;if(isNaN(n))throw new SyntaxError('String "'+M.input+'" is not a valid number');return n}var v5=h0(m5,g5,M=>{var{typed:e}=M,t=e("number",{"":function(){return 0},number:function(o){return o},string:function(o){if(o==="NaN")return NaN;var n=R5(o);if(n)return L5(n);var b=0,z=o.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);z&&(b=Number(z[2]),o=z[1]);var i=Number(o);if(isNaN(i))throw new SyntaxError('String "'+o+'" is not a valid number');if(z){if(i>2**b-1)throw new SyntaxError('String "'.concat(o,'" is out of range'));i>=2**(b-1)&&(i=i-2**b)}return i},BigNumber:function(o){return o.toNumber()},Fraction:function(o){return o.valueOf()},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),null:function(o){return 0},"Unit, string | Unit":function(o,n){return o.toNumber(n)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),N5="bignumber",y5=["typed","BigNumber"],B5=h0(N5,y5,M=>{var{typed:e,BigNumber:t}=M;return e("bignumber",{"":function(){return new t(0)},number:function(o){return new t(o+"")},string:function(o){var n=o.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(n){var b=n[2],z=t(n[1]),i=new t(2).pow(Number(b));if(z.gt(i.sub(1)))throw new SyntaxError('String "'.concat(o,'" is out of range'));var s=new t(2).pow(Number(b)-1);return z.gte(s)?z.sub(i):z}return new t(o)},BigNumber:function(o){return o},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),Fraction:function(o){return new t(o.n).div(o.d).times(o.s)},null:function(o){return new t(0)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))})}),w5="fraction",D5=["typed","Fraction"],X5=h0(w5,D5,M=>{var{typed:e,Fraction:t}=M;return e("fraction",{number:function(o){if(!isFinite(o)||isNaN(o))throw new Error(o+" cannot be represented as a fraction");return new t(o)},string:function(o){return new t(o)},"number, number":function(o,n){return new t(o,n)},null:function(o){return new t(0)},BigNumber:function(o){return new t(o.toString())},Fraction:function(o){return o},Unit:e.referToSelf(r=>o=>{var n=o.clone();return n.value=r(o.value),n}),Object:function(o){return new t(o)},"Array | Matrix":e.referToSelf(r=>o=>ge(o,r))})}),_s="matrix",E5=["typed","Matrix","DenseMatrix","SparseMatrix"],T5=h0(_s,E5,M=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:o}=M;return e(_s,{"":function(){return n([])},string:function(z){return n([],z)},"string, string":function(z,i){return n([],z,i)},Array:function(z){return n(z)},Matrix:function(z){return n(z,z.storage())},"Array | Matrix, string":n,"Array | Matrix, string, string":n});function n(b,z,i){if(z==="dense"||z==="default"||z===void 0)return new r(b,i);if(z==="sparse")return new o(b,i);throw new TypeError("Unknown matrix type "+JSON.stringify(z)+".")}}),ms="unaryMinus",C5=["typed"],x5=h0(ms,C5,M=>{var{typed:e}=M;return e(ms,{number:us,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var o=r.clone();return o.value=e.find(t,o.valueType())(r.value),o}),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),gs="abs",S5=["typed"],F5=h0(gs,S5,M=>{var{typed:e}=M;return e(gs,{number:cs,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),Rs="addScalar",I5=["typed"],P5=h0(Rs,I5,M=>{var{typed:e}=M;return e(Rs,{"number, number":ss,"Complex, Complex":function(r,o){return r.add(o)},"BigNumber, BigNumber":function(r,o){return r.plus(o)},"Fraction, Fraction":function(r,o){return r.add(o)},"Unit, Unit":e.referToSelf(t=>(r,o)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(o.value===null||o.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(o))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),o.valueType()])(n.value,o.value),n.fixPrefix=!1,n})})}),Ls="subtractScalar",k5=["typed"],$5=h0(Ls,k5,M=>{var{typed:e}=M;return e(Ls,{"number, number":Os,"Complex, Complex":function(r,o){return r.sub(o)},"BigNumber, BigNumber":function(r,o){return r.minus(o)},"Fraction, Fraction":function(r,o){return r.sub(o)},"Unit, Unit":e.referToSelf(t=>(r,o)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(o.value===null||o.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(o))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),o.valueType()])(n.value,o.value),n.fixPrefix=!1,n})})}),U5="matAlgo11xS0s",j5=["typed","equalScalar"],rp=h0(U5,j5,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=t,q=0,_=b;typeof u=="string"&&(A=u,h=e.find(t,[A,A]),q=e.convert(0,A),n=e.convert(n,A),_=e.find(b,[A,A]));for(var m=[],L=[],g=[],v=0;v<d;v++){g[v]=L.length;for(var y=a[v],X=a[v+1],T=y;T<X;T++){var N=s[T],D=z?_(n,i[T]):_(i[T],n);h(D,q)||(L.push(N),m.push(D))}}return g[d]=L.length,o.createSparseMatrix({values:m,index:L,ptr:g,size:[l,d],datatype:A})}}),H5="matAlgo12xSfs",Y5=["typed","DenseMatrix"],vr=h0(H5,Y5,M=>{var{typed:e,DenseMatrix:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var q=[],_=[],m=[],L=0;L<d;L++){for(var g=L+1,v=a[L],y=a[L+1],X=v;X<y;X++){var T=s[X];_[T]=i[X],m[T]=g}for(var N=0;N<l;N++)L===0&&(q[N]=[]),m[N]===g?q[N][L]=z?h(n,_[N]):h(_[N],n):q[N][L]=z?h(n,0):h(0,n)}return new t({data:q,size:[l,d],datatype:A})}}),G5="matAlgo14xDs",V5=["typed"],Mp=h0(G5,V5,M=>{var{typed:e}=M;return function(o,n,b,z){var i=o._data,s=o._size,a=o._datatype,O,u=b;typeof a=="string"&&(O=a,n=e.convert(n,O),u=e.find(b,[O,O]));var l=s.length>0?t(u,0,s,s[0],i,n,z):[];return o.createDenseMatrix({data:l,size:_1(s),datatype:O})};function t(r,o,n,b,z,i,s){var a=[];if(o===n.length-1)for(var O=0;O<b;O++)a[O]=s?r(i,z[O]):r(z[O],i);else for(var u=0;u<b;u++)a[u]=t(r,o+1,n,n[o+1],z[u],i,s);return a}}),K5="matAlgo02xDS0",J5=["typed","equalScalar"],Q5=h0(K5,J5,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b,z){var i=o._data,s=o._size,a=o._datatype||o.getDataType(),O=n._values,u=n._index,l=n._ptr,d=n._size,A=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(s.length!==d.length)throw new A1(s.length,d.length);if(s[0]!==d[0]||s[1]!==d[1])throw new RangeError("Dimension mismatch. Matrix A ("+s+") must match Matrix B ("+d+")");if(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var h=s[0],q=s[1],_,m=t,L=0,g=b;typeof a=="string"&&a===A&&a!=="mixed"&&(_=a,m=e.find(t,[_,_]),L=e.convert(0,_),g=e.find(b,[_,_]));for(var v=[],y=[],X=[],T=0;T<q;T++){X[T]=y.length;for(var N=l[T],D=l[T+1],C=N;C<D;C++){var P=u[C],H=z?g(O[C],i[P][T]):g(i[P][T],O[C]);m(H,L)||(y.push(P),v.push(H))}}return X[q]=y.length,n.createSparseMatrix({values:v,index:y,ptr:X,size:[h,q],datatype:a===o._datatype&&A===n._datatype?_:void 0})}}),Z5="matAlgo03xDSf",eh=["typed"],Nr=h0(Z5,eh,M=>{var{typed:e}=M;return function(r,o,n,b){var z=r._data,i=r._size,s=r._datatype||r.getDataType(),a=o._values,O=o._index,u=o._ptr,l=o._size,d=o._datatype||o._data===void 0?o._datatype:o.getDataType();if(i.length!==l.length)throw new A1(i.length,l.length);if(i[0]!==l[0]||i[1]!==l[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+l+")");if(!a)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],q,_=0,m=n;typeof s=="string"&&s===d&&s!=="mixed"&&(q=s,_=e.convert(0,q),m=e.find(n,[q,q]));for(var L=[],g=0;g<A;g++)L[g]=[];for(var v=[],y=[],X=0;X<h;X++){for(var T=X+1,N=u[X],D=u[X+1],C=N;C<D;C++){var P=O[C];v[P]=b?m(a[C],z[P][X]):m(z[P][X],a[C]),y[P]=T}for(var H=0;H<A;H++)y[H]===T?L[H][X]=v[H]:L[H][X]=b?m(_,z[H][X]):m(z[H][X],_)}return r.createDenseMatrix({data:L,size:[A,h],datatype:s===r._datatype&&d===o._datatype?q:void 0})}}),th="matAlgo05xSfSf",rh=["typed","equalScalar"],vs=h0(th,rh,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b){var z=o._values,i=o._index,s=o._ptr,a=o._size,O=o._datatype||o._data===void 0?o._datatype:o.getDataType(),u=n._values,l=n._index,d=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(a.length!==A.length)throw new A1(a.length,A.length);if(a[0]!==A[0]||a[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+a+") must match Matrix B ("+A+")");var q=a[0],_=a[1],m,L=t,g=0,v=b;typeof O=="string"&&O===h&&O!=="mixed"&&(m=O,L=e.find(t,[m,m]),g=e.convert(0,m),v=e.find(b,[m,m]));var y=z&&u?[]:void 0,X=[],T=[],N=y?[]:void 0,D=y?[]:void 0,C=[],P=[],H,G,k,J;for(G=0;G<_;G++){T[G]=X.length;var o0=G+1;for(k=s[G],J=s[G+1];k<J;k++)H=i[k],X.push(H),C[H]=o0,N&&(N[H]=z[k]);for(k=d[G],J=d[G+1];k<J;k++)H=l[k],C[H]!==o0&&X.push(H),P[H]=o0,D&&(D[H]=u[k]);if(y)for(k=T[G];k<X.length;){H=X[k];var z0=C[H],a0=P[H];if(z0===o0||a0===o0){var v0=z0===o0?N[H]:g,w0=a0===o0?D[H]:g,u0=v(v0,w0);L(u0,g)?X.splice(k,1):(y.push(u0),k++)}}}return T[_]=X.length,o.createSparseMatrix({values:y,index:X,ptr:T,size:[q,_],datatype:O===o._datatype&&h===n._datatype?m:void 0})}}),Mh="matAlgo13xDD",oh=["typed"],nh=h0(Mh,oh,M=>{var{typed:e}=M;return function(o,n,b){var z=o._data,i=o._size,s=o._datatype,a=n._data,O=n._size,u=n._datatype,l=[];if(i.length!==O.length)throw new A1(i.length,O.length);for(var d=0;d<i.length;d++){if(i[d]!==O[d])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+O+")");l[d]=i[d]}var A,h=b;typeof s=="string"&&s===u&&(A=s,h=e.find(b,[A,A]));var q=l.length>0?t(h,0,l,l[0],z,a):[];return o.createDenseMatrix({data:q,size:l,datatype:A})};function t(r,o,n,b,z,i){var s=[];if(o===n.length-1)for(var a=0;a<b;a++)s[a]=r(z[a],i[a]);else for(var O=0;O<b;O++)s[O]=t(r,o+1,n,n[o+1],z[O],i[O]);return s}}),bh="broadcast",ph=["concat"],zh=h0(bh,ph,M=>{var{concat:e}=M;return function(o,n){var b=Math.max(o._size.length,n._size.length);if(o._size.length===n._size.length&&o._size.every((d,A)=>d===n._size[A]))return[o,n];for(var z=t(o._size,b,0),i=t(n._size,b,0),s=[],a=0;a<b;a++)s[a]=Math.max(z[a],i[a]);fo(z,s),fo(i,s);var O=o.clone(),u=n.clone();O._size.length<b?O.reshape(t(O._size,b,1)):u._size.length<b&&u.reshape(t(u._size,b,1));for(var l=0;l<b;l++)O._size[l]<s[l]&&(O=r(O,s[l],l)),u._size[l]<s[l]&&(u=r(u,s[l],l));return[O,u]};function t(o,n,b){return[...Array(n-o.length).fill(b),...o]}function r(o,n,b){return e(...Array(n).fill(o),b)}}),ih="matrixAlgorithmSuite",ch=["typed","matrix","concat"],jt=h0(ih,ch,M=>{var{typed:e,matrix:t,concat:r}=M,o=nh({typed:e}),n=Mp({typed:e}),b=zh({concat:r});return function(i){var s=i.elop,a=i.SD||i.DS,O;s?(O={"DenseMatrix, DenseMatrix":(A,h)=>o(...b(A,h),s),"Array, Array":(A,h)=>o(...b(t(A),t(h)),s).valueOf(),"Array, DenseMatrix":(A,h)=>o(...b(t(A),h),s),"DenseMatrix, Array":(A,h)=>o(...b(A,t(h)),s)},i.SS&&(O["SparseMatrix, SparseMatrix"]=(A,h)=>i.SS(...b(A,h),s,!1)),i.DS&&(O["DenseMatrix, SparseMatrix"]=(A,h)=>i.DS(...b(A,h),s,!1),O["Array, SparseMatrix"]=(A,h)=>i.DS(...b(t(A),h),s,!1)),a&&(O["SparseMatrix, DenseMatrix"]=(A,h)=>a(...b(h,A),s,!0),O["SparseMatrix, Array"]=(A,h)=>a(...b(t(h),A),s,!0))):(O={"DenseMatrix, DenseMatrix":e.referToSelf(A=>(h,q)=>o(...b(h,q),A)),"Array, Array":e.referToSelf(A=>(h,q)=>o(...b(t(h),t(q)),A).valueOf()),"Array, DenseMatrix":e.referToSelf(A=>(h,q)=>o(...b(t(h),q),A)),"DenseMatrix, Array":e.referToSelf(A=>(h,q)=>o(...b(h,t(q)),A))},i.SS&&(O["SparseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.SS(...b(h,q),A,!1))),i.DS&&(O["DenseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.DS(...b(h,q),A,!1)),O["Array, SparseMatrix"]=e.referToSelf(A=>(h,q)=>i.DS(...b(t(h),q),A,!1))),a&&(O["SparseMatrix, DenseMatrix"]=e.referToSelf(A=>(h,q)=>a(...b(q,h),A,!0)),O["SparseMatrix, Array"]=e.referToSelf(A=>(h,q)=>a(...b(t(q),h),A,!0))));var u=i.scalar||"any",l=i.Ds||i.Ss;l&&(s?(O["DenseMatrix,"+u]=(A,h)=>n(A,h,s,!1),O[u+", DenseMatrix"]=(A,h)=>n(h,A,s,!0),O["Array,"+u]=(A,h)=>n(t(A),h,s,!1).valueOf(),O[u+", Array"]=(A,h)=>n(t(h),A,s,!0).valueOf()):(O["DenseMatrix,"+u]=e.referToSelf(A=>(h,q)=>n(h,q,A,!1)),O[u+", DenseMatrix"]=e.referToSelf(A=>(h,q)=>n(q,h,A,!0)),O["Array,"+u]=e.referToSelf(A=>(h,q)=>n(t(h),q,A,!1).valueOf()),O[u+", Array"]=e.referToSelf(A=>(h,q)=>n(t(q),h,A,!0).valueOf())));var d=i.sS!==void 0?i.sS:i.Ss;return s?(i.Ss&&(O["SparseMatrix,"+u]=(A,h)=>i.Ss(A,h,s,!1)),d&&(O[u+", SparseMatrix"]=(A,h)=>d(h,A,s,!0))):(i.Ss&&(O["SparseMatrix,"+u]=e.referToSelf(A=>(h,q)=>i.Ss(h,q,A,!1))),d&&(O[u+", SparseMatrix"]=e.referToSelf(A=>(h,q)=>d(q,h,A,!0)))),s&&s.signatures&&hc(O,s.signatures),O}}),sh="matAlgo01xDSid",Oh=["typed"],Ns=h0(sh,Oh,M=>{var{typed:e}=M;return function(r,o,n,b){var z=r._data,i=r._size,s=r._datatype||r.getDataType(),a=o._values,O=o._index,u=o._ptr,l=o._size,d=o._datatype||o._data===void 0?o._datatype:o.getDataType();if(i.length!==l.length)throw new A1(i.length,l.length);if(i[0]!==l[0]||i[1]!==l[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+l+")");if(!a)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],q=typeof s=="string"&&s!=="mixed"&&s===d?s:void 0,_=q?e.find(n,[q,q]):n,m,L,g=[];for(m=0;m<A;m++)g[m]=[];var v=[],y=[];for(L=0;L<h;L++){for(var X=L+1,T=u[L],N=u[L+1],D=T;D<N;D++)m=O[D],v[m]=b?_(a[D],z[m][L]):_(z[m][L],a[D]),y[m]=X;for(m=0;m<A;m++)y[m]===X?g[m][L]=v[m]:g[m][L]=z[m][L]}return r.createDenseMatrix({data:g,size:[A,h],datatype:s===r._datatype&&d===o._datatype?q:void 0})}}),ah="matAlgo04xSidSid",uh=["typed","equalScalar"],Ah=h0(ah,uh,M=>{var{typed:e,equalScalar:t}=M;return function(o,n,b){var z=o._values,i=o._index,s=o._ptr,a=o._size,O=o._datatype||o._data===void 0?o._datatype:o.getDataType(),u=n._values,l=n._index,d=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(a.length!==A.length)throw new A1(a.length,A.length);if(a[0]!==A[0]||a[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+a+") must match Matrix B ("+A+")");var q=a[0],_=a[1],m,L=t,g=0,v=b;typeof O=="string"&&O===h&&O!=="mixed"&&(m=O,L=e.find(t,[m,m]),g=e.convert(0,m),v=e.find(b,[m,m]));var y=z&&u?[]:void 0,X=[],T=[],N=z&&u?[]:void 0,D=z&&u?[]:void 0,C=[],P=[],H,G,k,J,o0;for(G=0;G<_;G++){T[G]=X.length;var z0=G+1;for(J=s[G],o0=s[G+1],k=J;k<o0;k++)H=i[k],X.push(H),C[H]=z0,N&&(N[H]=z[k]);for(J=d[G],o0=d[G+1],k=J;k<o0;k++)if(H=l[k],C[H]===z0){if(N){var a0=v(N[H],u[k]);L(a0,g)?C[H]=null:N[H]=a0}}else X.push(H),P[H]=z0,D&&(D[H]=u[k]);if(N&&D)for(k=T[G];k<X.length;)H=X[k],C[H]===z0?(y[k]=N[H],k++):P[H]===z0?(y[k]=D[H],k++):X.splice(k,1)}return T[_]=X.length,o.createSparseMatrix({values:y,index:X,ptr:T,size:[q,_],datatype:O===o._datatype&&h===n._datatype?m:void 0})}}),fh="matAlgo10xSids",lh=["typed","DenseMatrix"],ys=h0(fh,lh,M=>{var{typed:e,DenseMatrix:t}=M;return function(o,n,b,z){var i=o._values,s=o._index,a=o._ptr,O=o._size,u=o._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=O[0],d=O[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var q=[],_=[],m=[],L=0;L<d;L++){for(var g=L+1,v=a[L],y=a[L+1],X=v;X<y;X++){var T=s[X];_[T]=i[X],m[T]=g}for(var N=0;N<l;N++)L===0&&(q[N]=[]),m[N]===g?q[N][L]=z?h(n,_[N]):h(_[N],n):q[N][L]=n}return new t({data:q,size:[l,d],datatype:A})}}),qh="multiplyScalar",dh=["typed"],hh=h0(qh,dh,M=>{var{typed:e}=M;return e("multiplyScalar",{"number, number":as,"Complex, Complex":function(r,o){return r.mul(o)},"BigNumber, BigNumber":function(r,o){return r.times(o)},"Fraction, Fraction":function(r,o){return r.mul(o)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Bs="multiply",Wh=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],_h=h0(Bs,Wh,M=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:o,equalScalar:n,dot:b}=M,z=rp({typed:e,equalScalar:n}),i=Mp({typed:e});function s(g,v){switch(g.length){case 1:switch(v.length){case 1:if(g[0]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(g[0]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+g[0]+") must match Matrix rows ("+v[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+v.length+" dimensions)")}break;case 2:switch(v.length){case 1:if(g[1]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+g[1]+") must match Vector length ("+v[0]+")");break;case 2:if(g[1]!==v[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+g[1]+") must match Matrix B rows ("+v[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+v.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+g.length+" dimensions)")}}function a(g,v,y){if(y===0)throw new Error("Cannot multiply two empty vectors");return b(g,v)}function O(g,v){if(v.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return u(g,v)}function u(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._size,C=v._datatype||v.getDataType(),P=X[0],H=D[1],G,k=r,J=o;T&&C&&T===C&&typeof T=="string"&&T!=="mixed"&&(G=T,k=e.find(r,[G,G]),J=e.find(o,[G,G]));for(var o0=[],z0=0;z0<H;z0++){for(var a0=J(y[0],N[0][z0]),v0=1;v0<P;v0++)a0=k(a0,J(y[v0],N[v0][z0]));o0[z0]=a0}return g.createDenseMatrix({data:o0,size:[H],datatype:T===g._datatype&&C===v._datatype?G:void 0})}var l=e("_multiplyMatrixVector",{"DenseMatrix, any":A,"SparseMatrix, any":_}),d=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":h,"DenseMatrix, SparseMatrix":q,"SparseMatrix, DenseMatrix":m,"SparseMatrix, SparseMatrix":L});function A(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._datatype||v.getDataType(),C=X[0],P=X[1],H,G=r,k=o;T&&D&&T===D&&typeof T=="string"&&T!=="mixed"&&(H=T,G=e.find(r,[H,H]),k=e.find(o,[H,H]));for(var J=[],o0=0;o0<C;o0++){for(var z0=y[o0],a0=k(z0[0],N[0]),v0=1;v0<P;v0++)a0=G(a0,k(z0[v0],N[v0]));J[o0]=a0}return g.createDenseMatrix({data:J,size:[C],datatype:T===g._datatype&&D===v._datatype?H:void 0})}function h(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._data,D=v._size,C=v._datatype||v.getDataType(),P=X[0],H=X[1],G=D[1],k,J=r,o0=o;T&&C&&T===C&&typeof T=="string"&&T!=="mixed"&&T!=="mixed"&&(k=T,J=e.find(r,[k,k]),o0=e.find(o,[k,k]));for(var z0=[],a0=0;a0<P;a0++){var v0=y[a0];z0[a0]=[];for(var w0=0;w0<G;w0++){for(var u0=o0(v0[0],N[0][w0]),I0=1;I0<H;I0++)u0=J(u0,o0(v0[I0],N[I0][w0]));z0[a0][w0]=u0}}return g.createDenseMatrix({data:z0,size:[P,G],datatype:T===g._datatype&&C===v._datatype?k:void 0})}function q(g,v){var y=g._data,X=g._size,T=g._datatype||g.getDataType(),N=v._values,D=v._index,C=v._ptr,P=v._size,H=v._datatype||v._data===void 0?v._datatype:v.getDataType();if(!N)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var G=X[0],k=P[1],J,o0=r,z0=o,a0=n,v0=0;T&&H&&T===H&&typeof T=="string"&&T!=="mixed"&&(J=T,o0=e.find(r,[J,J]),z0=e.find(o,[J,J]),a0=e.find(n,[J,J]),v0=e.convert(0,J));for(var w0=[],u0=[],I0=[],S0=v.createSparseMatrix({values:w0,index:u0,ptr:I0,size:[G,k],datatype:T===g._datatype&&H===v._datatype?J:void 0}),F0=0;F0<k;F0++){I0[F0]=u0.length;var W0=C[F0],b1=C[F0+1];if(b1>W0)for(var J0=0,p1=0;p1<G;p1++){for(var Z1=p1+1,d1=void 0,F=W0;F<b1;F++){var K=D[F];J0!==Z1?(d1=z0(y[p1][K],N[F]),J0=Z1):d1=o0(d1,z0(y[p1][K],N[F]))}J0===Z1&&!a0(d1,v0)&&(u0.push(p1),w0.push(d1))}}return I0[k]=u0.length,S0}function _(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType();if(!y)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var D=v._data,C=v._datatype||v.getDataType(),P=g._size[0],H=v._size[0],G=[],k=[],J=[],o0,z0=r,a0=o,v0=n,w0=0;N&&C&&N===C&&typeof N=="string"&&N!=="mixed"&&(o0=N,z0=e.find(r,[o0,o0]),a0=e.find(o,[o0,o0]),v0=e.find(n,[o0,o0]),w0=e.convert(0,o0));var u0=[],I0=[];J[0]=0;for(var S0=0;S0<H;S0++){var F0=D[S0];if(!v0(F0,w0))for(var W0=T[S0],b1=T[S0+1],J0=W0;J0<b1;J0++){var p1=X[J0];I0[p1]?u0[p1]=z0(u0[p1],a0(F0,y[J0])):(I0[p1]=!0,k.push(p1),u0[p1]=a0(F0,y[J0]))}}for(var Z1=k.length,d1=0;d1<Z1;d1++){var F=k[d1];G[d1]=u0[F]}return J[1]=k.length,g.createSparseMatrix({values:G,index:k,ptr:J,size:[P,1],datatype:N===g._datatype&&C===v._datatype?o0:void 0})}function m(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType();if(!y)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var D=v._data,C=v._datatype||v.getDataType(),P=g._size[0],H=v._size[0],G=v._size[1],k,J=r,o0=o,z0=n,a0=0;N&&C&&N===C&&typeof N=="string"&&N!=="mixed"&&(k=N,J=e.find(r,[k,k]),o0=e.find(o,[k,k]),z0=e.find(n,[k,k]),a0=e.convert(0,k));for(var v0=[],w0=[],u0=[],I0=g.createSparseMatrix({values:v0,index:w0,ptr:u0,size:[P,G],datatype:N===g._datatype&&C===v._datatype?k:void 0}),S0=[],F0=[],W0=0;W0<G;W0++){u0[W0]=w0.length;for(var b1=W0+1,J0=0;J0<H;J0++){var p1=D[J0][W0];if(!z0(p1,a0))for(var Z1=T[J0],d1=T[J0+1],F=Z1;F<d1;F++){var K=X[F];F0[K]!==b1?(F0[K]=b1,w0.push(K),S0[K]=o0(p1,y[F])):S0[K]=J(S0[K],o0(p1,y[F]))}}for(var Z=u0[W0],O0=w0.length,R0=Z;R0<O0;R0++){var j0=w0[R0];v0[R0]=S0[j0]}}return u0[G]=w0.length,I0}function L(g,v){var y=g._values,X=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType(),D=v._values,C=v._index,P=v._ptr,H=v._datatype||v._data===void 0?v._datatype:v.getDataType(),G=g._size[0],k=v._size[1],J=y&&D,o0,z0=r,a0=o;N&&H&&N===H&&typeof N=="string"&&N!=="mixed"&&(o0=N,z0=e.find(r,[o0,o0]),a0=e.find(o,[o0,o0]));for(var v0=J?[]:void 0,w0=[],u0=[],I0=g.createSparseMatrix({values:v0,index:w0,ptr:u0,size:[G,k],datatype:N===g._datatype&&H===v._datatype?o0:void 0}),S0=J?[]:void 0,F0=[],W0,b1,J0,p1,Z1,d1,F,K,Z=0;Z<k;Z++){u0[Z]=w0.length;var O0=Z+1;for(Z1=P[Z],d1=P[Z+1],p1=Z1;p1<d1;p1++)if(K=C[p1],J)for(b1=T[K],J0=T[K+1],W0=b1;W0<J0;W0++)F=X[W0],F0[F]!==O0?(F0[F]=O0,w0.push(F),S0[F]=a0(D[p1],y[W0])):S0[F]=z0(S0[F],a0(D[p1],y[W0]));else for(b1=T[K],J0=T[K+1],W0=b1;W0<J0;W0++)F=X[W0],F0[F]!==O0&&(F0[F]=O0,w0.push(F));if(J)for(var R0=u0[Z],j0=w0.length,g1=R0;g1<j0;g1++){var V0=w0[g1];v0[g1]=S0[V0]}}return u0[k]=w0.length,I0}return e(Bs,o,{"Array, Array":e.referTo("Matrix, Matrix",g=>(v,y)=>{s(M2(v),M2(y));var X=g(t(v),t(y));return F1(X)?X.valueOf():X}),"Matrix, Matrix":function(v,y){var X=v.size(),T=y.size();return s(X,T),X.length===1?T.length===1?a(v,y,X[0]):O(v,y):T.length===1?l(v,y):d(v,y)},"Matrix, Array":e.referTo("Matrix,Matrix",g=>(v,y)=>g(v,t(y))),"Array, Matrix":e.referToSelf(g=>(v,y)=>g(t(v,y.storage()),y)),"SparseMatrix, any":function(v,y){return z(v,y,o,!1)},"DenseMatrix, any":function(v,y){return i(v,y,o,!1)},"any, SparseMatrix":function(v,y){return z(y,v,o,!0)},"any, DenseMatrix":function(v,y){return i(y,v,o,!0)},"Array, any":function(v,y){return i(t(v),y,o,!1).valueOf()},"any, Array":function(v,y){return i(t(y),v,o,!0).valueOf()},"any, any":o,"any, any, ...any":e.referToSelf(g=>(v,y,X)=>{for(var T=g(v,y),N=0;N<X.length;N++)T=g(T,X[N]);return T})})}),ws="subtract",mh=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],gh=h0(ws,mh,M=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:o,unaryMinus:n,DenseMatrix:b,concat:z}=M,i=Ns({typed:e}),s=Nr({typed:e}),a=vs({typed:e,equalScalar:r}),O=ys({typed:e,DenseMatrix:b}),u=vr({typed:e,DenseMatrix:b}),l=jt({typed:e,matrix:t,concat:z});return e(ws,{"any, any":o},l({elop:o,SS:a,DS:i,SD:s,Ss:u,sS:O}))}),Rh="matAlgo07xSSf",Lh=["typed","DenseMatrix"],Do=h0(Rh,Lh,M=>{var{typed:e,DenseMatrix:t}=M;return function(n,b,z){var i=n._size,s=n._datatype||n._data===void 0?n._datatype:n.getDataType(),a=b._size,O=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(i.length!==a.length)throw new A1(i.length,a.length);if(i[0]!==a[0]||i[1]!==a[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+a+")");var u=i[0],l=i[1],d,A=0,h=z;typeof s=="string"&&s===O&&s!=="mixed"&&(d=s,A=e.convert(0,d),h=e.find(z,[d,d]));var q,_,m=[];for(q=0;q<u;q++)m[q]=[];var L=[],g=[],v=[],y=[];for(_=0;_<l;_++){var X=_+1;for(r(n,_,v,L,X),r(b,_,y,g,X),q=0;q<u;q++){var T=v[q]===X?L[q]:A,N=y[q]===X?g[q]:A;m[q][_]=h(T,N)}}return new t({data:m,size:[u,l],datatype:s===n._datatype&&O===b._datatype?d:void 0})};function r(o,n,b,z,i){for(var s=o._values,a=o._index,O=o._ptr,u=O[n],l=O[n+1];u<l;u++){var d=a[u];b[d]=i,z[d]=s[u]}}}),Ds="conj",vh=["typed"],Nh=h0(Ds,vh,M=>{var{typed:e}=M;return e(Ds,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>ge(r,t))})}),Xs="concat",yh=["typed","matrix","isInteger"],Bh=h0(Xs,yh,M=>{var{typed:e,matrix:t,isInteger:r}=M;return e(Xs,{"...Array | Matrix | number | BigNumber":function(n){var b,z=n.length,i=-1,s,a=!1,O=[];for(b=0;b<z;b++){var u=n[b];if(F1(u)&&(a=!0),X1(u)||Q1(u)){if(b!==z-1)throw new Error("Dimension must be specified as last argument");if(s=i,i=u.valueOf(),!r(i))throw new TypeError("Integer number expected for dimension");if(i<0||b>0&&i>s)throw new dt(i,s+1)}else{var l=_1(u).valueOf(),d=M2(l);if(O[b]=l,s=i,i=d.length-1,b>0&&i!==s)throw new A1(s+1,i+1)}}if(O.length===0)throw new SyntaxError("At least one matrix expected");for(var A=O.shift();O.length;)A=Ic(A,O.shift(),i);return a?t(A):A},"...string":function(n){return n.join("")}})}),Es="count",wh=["typed","size","prod"],Dh=h0(Es,wh,M=>{var{typed:e,size:t,prod:r}=M;return e(Es,{string:function(n){return n.length},"Matrix | Array":function(n){return r(t(n))}})}),Ts="identity",Xh=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Eh=h0(Ts,Xh,M=>{var{typed:e,config:t,matrix:r,BigNumber:o,DenseMatrix:n,SparseMatrix:b}=M;return e(Ts,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(a){return r(a)},"number | BigNumber":function(a){return i(a,a,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(a,O){return i(a,a,O)},"number | BigNumber, number | BigNumber":function(a,O){return i(a,O,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(a,O,u){return i(a,O,u)},Array:function(a){return z(a)},"Array, string":function(a,O){return z(a,O)},Matrix:function(a){return z(a.valueOf(),a.storage())},"Matrix, string":function(a,O){return z(a.valueOf(),O)}});function z(s,a){switch(s.length){case 0:return a?r(a):[];case 1:return i(s[0],s[0],a);case 2:return i(s[0],s[1],a);default:throw new Error("Vector containing two values expected")}}function i(s,a,O){var u=Q1(s)||Q1(a)?o:null;if(Q1(s)&&(s=s.toNumber()),Q1(a)&&(a=a.toNumber()),!$1(s)||s<1)throw new Error("Parameters in function identity must be positive integers");if(!$1(a)||a<1)throw new Error("Parameters in function identity must be positive integers");var l=u?new o(1):1,d=u?new u(0):0,A=[s,a];if(O){if(O==="sparse")return b.diagonal(A,l,0,d);if(O==="dense")return n.diagonal(A,l,0,d);throw new TypeError('Unknown matrix type "'.concat(O,'"'))}for(var h=kb([],A,d),q=s<a?s:a,_=0;_<q;_++)h[_][_]=l;return h}}),Cs="kron",Th=["typed","matrix","multiplyScalar"],Ch=h0(Cs,Th,M=>{var{typed:e,matrix:t,multiplyScalar:r}=M;return e(Cs,{"Matrix, Matrix":function(b,z){return t(o(b.toArray(),z.toArray()))},"Matrix, Array":function(b,z){return t(o(b.toArray(),z))},"Array, Matrix":function(b,z){return t(o(b,z.toArray()))},"Array, Array":o});function o(n,b){if(M2(n).length===1&&(n=[n]),M2(b).length===1&&(b=[b]),M2(n).length>2||M2(b).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(n.length)+", y = "+JSON.stringify(b.length)+")");var z=[],i=[];return n.map(function(s){return b.map(function(a){return i=[],z.push(i),s.map(function(O){return a.map(function(u){return i.push(r(O,u))})})})})&&z}});function xh(){throw new Error('No "bignumber" implementation available')}function Sh(){throw new Error('No "fraction" implementation available')}function Fh(){throw new Error('No "matrix" implementation available')}var xs="reshape",Ih=["typed","isInteger","matrix"],Ph=h0(xs,Ih,M=>{var{typed:e,isInteger:t}=M;return e(xs,{"Matrix, Array":function(o,n){return o.reshape(n,!0)},"Array, Array":function(o,n){return n.forEach(function(b){if(!t(b))throw new TypeError("Invalid size for dimension: "+b)}),Ub(o,n)}})}),Ss="size",kh=["typed","config","?matrix"],$h=h0(Ss,kh,M=>{var{typed:e,config:t,matrix:r}=M;return e(Ss,{Matrix:function(n){return n.create(n.size())},Array:M2,string:function(n){return t.matrix==="Array"?[n.length]:r([n.length])},"number | Complex | BigNumber | Unit | boolean | null":function(n){return t.matrix==="Array"?[]:r?r([]):Fh()}})}),Fs="transpose",Uh=["typed","matrix"],jh=h0(Fs,Uh,M=>{var{typed:e,matrix:t}=M;return e(Fs,{Array:b=>r(t(b)).valueOf(),Matrix:r,any:_1});function r(b){var z=b.size(),i;switch(z.length){case 1:i=b.clone();break;case 2:{var s=z[0],a=z[1];if(a===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+N1(z)+")");switch(b.storage()){case"dense":i=o(b,s,a);break;case"sparse":i=n(b,s,a);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+N1(z)+")")}return i}function o(b,z,i){for(var s=b._data,a=[],O,u=0;u<i;u++){O=a[u]=[];for(var l=0;l<z;l++)O[l]=_1(s[l][u])}return b.createDenseMatrix({data:a,size:[i,z],datatype:b._datatype})}function n(b,z,i){for(var s=b._values,a=b._index,O=b._ptr,u=s?[]:void 0,l=[],d=[],A=[],h=0;h<z;h++)A[h]=0;var q,_,m;for(q=0,_=a.length;q<_;q++)A[a[q]]++;for(var L=0,g=0;g<z;g++)d.push(L),L+=A[g],A[g]=d[g];for(d.push(L),m=0;m<i;m++)for(var v=O[m],y=O[m+1],X=v;X<y;X++){var T=A[a[X]]++;l[T]=m,s&&(u[T]=_1(s[X]))}return b.createSparseMatrix({values:u,index:l,ptr:d,size:[i,z],datatype:b._datatype})}}),Is="ctranspose",Hh=["typed","transpose","conj"],Yh=h0(Is,Hh,M=>{var{typed:e,transpose:t,conj:r}=M;return e(Is,{any:function(n){return r(t(n))}})}),Ps="mode",Gh=["typed","isNaN","isNumeric"],Vh=h0(Ps,Gh,M=>{var{typed:e,isNaN:t,isNumeric:r}=M;return e(Ps,{"Array | Matrix":o,"...":function(b){return o(b)}});function o(n){n=Hb(n.valueOf());var b=n.length;if(b===0)throw new Error("Cannot calculate mode of an empty array");for(var z={},i=[],s=0,a=0;a<n.length;a++){var O=n[a];if(r(O)&&t(O))throw new Error("Cannot calculate mode of an array containing NaN values");O in z||(z[O]=0),z[O]++,z[O]===s?i.push(O):z[O]>s&&(s=z[O],i=[O])}return i}});function gt(M,e,t){var r;return String(M).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+qt(t)+", value: "+JSON.stringify(t)+")":" (type: "+M.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(M).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+qt(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):M}var ks="prod",Kh=["typed","config","multiplyScalar","numeric"],Jh=h0(ks,Kh,M=>{var{typed:e,config:t,multiplyScalar:r,numeric:o}=M;return e(ks,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":function(z,i){throw new Error("prod(A, dim) is not yet supported")},"...":function(z){return n(z)}});function n(b){var z;if(fM(b,function(i){try{z=z===void 0?i:r(z,i)}catch(s){throw gt(s,"prod",i)}}),typeof z=="string"&&(z=o(z,t.number)),z===void 0)throw new Error("Cannot calculate prod of an empty array");return z}}),Qh="numeric",Zh=["number","?bignumber","?fraction"],eW=h0(Qh,Zh,M=>{var{number:e,bignumber:t,fraction:r}=M,o={string:!0,number:!0,BigNumber:!0,Fraction:!0},n={number:b=>e(b),BigNumber:t?b=>t(b):xh,Fraction:r?b=>r(b):Sh};return function(z){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",s=arguments.length>2?arguments[2]:void 0;if(s!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var a=qt(z);if(!(a in o))throw new TypeError("Cannot convert "+z+' of type "'+a+'"; valid input types are '+Object.keys(o).join(", "));if(!(i in n))throw new TypeError("Cannot convert "+z+' to type "'+i+'"; valid output types are '+Object.keys(n).join(", "));return i===a?z:n[i](z)}}),$s="divideScalar",tW=["typed","numeric"],rW=h0($s,tW,M=>{var{typed:e,numeric:t}=M;return e($s,{"number, number":function(o,n){return o/n},"Complex, Complex":function(o,n){return o.div(n)},"BigNumber, BigNumber":function(o,n){return o.div(n)},"Fraction, Fraction":function(o,n){return o.div(n)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,o)=>r.divide(o),"number | Fraction | Complex | BigNumber, Unit":(r,o)=>o.divideInto(r)})}),Us="pow",MW=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],oW=h0(Us,MW,M=>{var{typed:e,config:t,identity:r,multiply:o,matrix:n,inv:b,number:z,fraction:i,Complex:s}=M;return e(Us,{"number, number":a,"Complex, Complex":function(d,A){return d.pow(A)},"BigNumber, BigNumber":function(d,A){return A.isInteger()||d>=0||t.predictable?d.pow(A):new s(d.toNumber(),0).pow(A.toNumber(),0)},"Fraction, Fraction":function(d,A){var h=d.pow(A);if(h!=null)return h;if(t.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return a(d.valueOf(),A.valueOf())},"Array, number":O,"Array, BigNumber":function(d,A){return O(d,A.toNumber())},"Matrix, number":u,"Matrix, BigNumber":function(d,A){return u(d,A.toNumber())},"Unit, number | BigNumber":function(d,A){return d.pow(A)}});function a(l,d){if(t.predictable&&!$1(d)&&l<0)try{var A=i(d),h=z(A);if((d===h||Math.abs((d-h)/d)<1e-14)&&A.d%2===1)return(A.n%2===0?1:-1)*Math.pow(-l,d)}catch{}return t.predictable&&(l<-1&&d===1/0||l>-1&&l<0&&d===-1/0)?NaN:$1(d)||l>=0||t.predictable?As(l,d):l*l<1&&d===1/0||l*l>1&&d===-1/0?0:new s(l,0).pow(d,0)}function O(l,d){if(!$1(d))throw new TypeError("For A^b, b must be an integer (value is "+d+")");var A=M2(l);if(A.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+A.length+" dimensions)");if(A[0]!==A[1])throw new Error("For A^b, A must be square (size is "+A[0]+"x"+A[1]+")");if(d<0)try{return O(b(l),-d)}catch(_){throw _.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 "+d+")"):_}for(var h=r(A[0]).valueOf(),q=l;d>=1;)(d&1)===1&&(h=o(q,h)),d>>=1,q=o(q,q);return h}function u(l,d){return n(O(l.valueOf(),d))}}),js="dotDivide",nW=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],bW=h0(js,nW,M=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:o,DenseMatrix:n,concat:b}=M,z=Q5({typed:e,equalScalar:r}),i=Nr({typed:e}),s=Do({typed:e,DenseMatrix:n}),a=rp({typed:e,equalScalar:r}),O=vr({typed:e,DenseMatrix:n}),u=jt({typed:e,matrix:t,concat:b});return e(js,u({elop:o,SS:s,DS:i,SD:z,Ss:a,sS:O}))}),Xo="compare",pW=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],zW=h0(Xo,pW,M=>{var{typed:e,config:t,equalScalar:r,matrix:o,BigNumber:n,Fraction:b,DenseMatrix:z,concat:i}=M,s=Nr({typed:e}),a=vs({typed:e,equalScalar:r}),O=vr({typed:e,DenseMatrix:z}),u=jt({typed:e,matrix:o,concat:i}),l=Bo({typed:e});return e(Xo,iW({typed:e,config:t}),{"boolean, boolean":function(A,h){return A===h?0:A>h?1:-1},"BigNumber, BigNumber":function(A,h){return yo(A,h,t.epsilon)?new n(0):new n(A.cmp(h))},"Fraction, Fraction":function(A,h){return new b(A.compare(h))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},l,u({SS:a,DS:s,Ss:O}))}),iW=h0(Xo,["typed","config"],M=>{var{typed:e,config:t}=M;return e(Xo,{"number, number":function(o,n){return Ut(o,n,t.epsilon)?0:o>n?1:-1}})}),Eo="equal",cW=["typed","matrix","equalScalar","DenseMatrix","concat"],sW=h0(Eo,cW,M=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:t,concat:n});return e(Eo,OW({typed:e,equalScalar:r}),s({elop:r,SS:z,DS:b,Ss:i}))}),OW=h0(Eo,["typed","equalScalar"],M=>{var{typed:e,equalScalar:t}=M;return e(Eo,{"any, any":function(o,n){return o===null?n===null:n===null?o===null:o===void 0?n===void 0:n===void 0?o===void 0:t(o,n)}})}),To="smaller",aW=["typed","config","matrix","DenseMatrix","concat"],uW=h0(To,aW,M=>{var{typed:e,config:t,matrix:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:r,concat:n}),a=Bo({typed:e});return e(To,AW({typed:e,config:t}),{"boolean, boolean":(O,u)=>O<u,"BigNumber, BigNumber":function(u,l){return u.lt(l)&&!yo(u,l,t.epsilon)},"Fraction, Fraction":(O,u)=>O.compare(u)===-1,"Complex, Complex":function(u,l){throw new TypeError("No ordering relation is defined for complex numbers")}},a,s({SS:z,DS:b,Ss:i}))}),AW=h0(To,["typed","config"],M=>{var{typed:e,config:t}=M;return e(To,{"number, number":function(o,n){return o<n&&!Ut(o,n,t.epsilon)}})}),Co="larger",fW=["typed","config","matrix","DenseMatrix","concat"],lW=h0(Co,fW,M=>{var{typed:e,config:t,matrix:r,DenseMatrix:o,concat:n}=M,b=Nr({typed:e}),z=Do({typed:e,DenseMatrix:o}),i=vr({typed:e,DenseMatrix:o}),s=jt({typed:e,matrix:r,concat:n}),a=Bo({typed:e});return e(Co,qW({typed:e,config:t}),{"boolean, boolean":(O,u)=>O>u,"BigNumber, BigNumber":function(u,l){return u.gt(l)&&!yo(u,l,t.epsilon)},"Fraction, Fraction":(O,u)=>O.compare(u)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},a,s({SS:z,DS:b,Ss:i}))}),qW=h0(Co,["typed","config"],M=>{var{typed:e,config:t}=M;return e(Co,{"number, number":function(o,n){return o>n&&!Ut(o,n,t.epsilon)}})}),Hs="deepEqual",dW=["typed","equal"],hW=h0(Hs,dW,M=>{var{typed:e,equal:t}=M;return e(Hs,{"any, any":function(n,b){return r(n.valueOf(),b.valueOf())}});function r(o,n){if(Array.isArray(o))if(Array.isArray(n)){var b=o.length;if(b!==n.length)return!1;for(var z=0;z<b;z++)if(!r(o[z],n[z]))return!1;return!0}else return!1;else return Array.isArray(n)?!1:t(o,n)}}),Ys="partitionSelect",WW=["typed","isNumeric","isNaN","compare"],_W=h0(Ys,WW,M=>{var{typed:e,isNumeric:t,isNaN:r,compare:o}=M,n=o,b=(s,a)=>-o(s,a);return e(Ys,{"Array | Matrix, number":function(a,O){return z(a,O,n)},"Array | Matrix, number, string":function(a,O,u){if(u==="asc")return z(a,O,n);if(u==="desc")return z(a,O,b);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":z});function z(s,a,O){if(!$1(a)||a<0)throw new Error("k must be a non-negative integer");if(F1(s)){var u=s.size();if(u.length>1)throw new Error("Only one dimensional matrices supported");return i(s.valueOf(),a,O)}if(Array.isArray(s))return i(s,a,O)}function i(s,a,O){if(a>=s.length)throw new Error("k out of bounds");for(var u=0;u<s.length;u++)if(t(s[u])&&r(s[u]))return s[u];for(var l=0,d=s.length-1;l<d;){for(var A=l,h=d,q=s[Math.floor(Math.random()*(d-l+1))+l];A<h;)if(O(s[A],q)>=0){var _=s[h];s[h]=s[A],s[A]=_,--h}else++A;O(s[A],q)>0&&--A,a<=A?d=A:l=A+1}return s[a]}}),Gs="max",mW=["typed","config","numeric","larger"],gW=h0(Gs,mW,M=>{var{typed:e,config:t,numeric:r,larger:o}=M;return e(Gs,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,s){return tp(i,s.valueOf(),n)},"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function max");return b(i)}});function n(z,i){try{return o(z,i)?z:i}catch(s){throw gt(s,"max",i)}}function b(z){var i;if(fM(z,function(s){try{isNaN(s)&&typeof s=="number"?i=NaN:(i===void 0||o(s,i))&&(i=s)}catch(a){throw gt(a,"max",s)}}),i===void 0)throw new Error("Cannot calculate max of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),Vs="min",RW=["typed","config","numeric","smaller"],LW=h0(Vs,RW,M=>{var{typed:e,config:t,numeric:r,smaller:o}=M;return e(Vs,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,s){return tp(i,s.valueOf(),n)},"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function min");return b(i)}});function n(z,i){try{return o(z,i)?z:i}catch(s){throw gt(s,"min",i)}}function b(z){var i;if(fM(z,function(s){try{isNaN(s)&&typeof s=="number"?i=NaN:(i===void 0||o(s,i))&&(i=s)}catch(a){throw gt(a,"min",s)}}),i===void 0)throw new Error("Cannot calculate min of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),Ks="add",vW=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],NW=h0(Ks,vW,M=>{var{typed:e,matrix:t,addScalar:r,equalScalar:o,DenseMatrix:n,SparseMatrix:b,concat:z}=M,i=Ns({typed:e}),s=Ah({typed:e,equalScalar:o}),a=ys({typed:e,DenseMatrix:n}),O=jt({typed:e,matrix:t,concat:z});return e(Ks,{"any, any":r,"any, any, ...any":e.referToSelf(u=>(l,d,A)=>{for(var h=u(l,d),q=0;q<A.length;q++)h=u(h,A[q]);return h})},O({elop:r,DS:i,SS:s,Ss:a}))}),Js="dot",yW=["typed","addScalar","multiplyScalar","conj","size"],BW=h0(Js,yW,M=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:o,size:n}=M;return e(Js,{"Array | DenseMatrix, Array | DenseMatrix":z,"SparseMatrix, SparseMatrix":i});function b(a,O){var u=s(a),l=s(O),d,A;if(u.length===1)d=u[0];else if(u.length===2&&u[1]===1)d=u[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+u.join(", ")+")");if(l.length===1)A=l[0];else if(l.length===2&&l[1]===1)A=l[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+l.join(", ")+")");if(d!==A)throw new RangeError("Vectors must have equal length ("+d+" != "+A+")");if(d===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return d}function z(a,O){var u=b(a,O),l=F1(a)?a._data:a,d=F1(a)?a._datatype||a.getDataType():void 0,A=F1(O)?O._data:O,h=F1(O)?O._datatype||O.getDataType():void 0,q=s(a).length===2,_=s(O).length===2,m=t,L=r;if(d&&h&&d===h&&typeof d=="string"&&d!=="mixed"){var g=d;m=e.find(t,[g,g]),L=e.find(r,[g,g])}if(!q&&!_){for(var v=L(o(l[0]),A[0]),y=1;y<u;y++)v=m(v,L(o(l[y]),A[y]));return v}if(!q&&_){for(var X=L(o(l[0]),A[0][0]),T=1;T<u;T++)X=m(X,L(o(l[T]),A[T][0]));return X}if(q&&!_){for(var N=L(o(l[0][0]),A[0]),D=1;D<u;D++)N=m(N,L(o(l[D][0]),A[D]));return N}if(q&&_){for(var C=L(o(l[0][0]),A[0][0]),P=1;P<u;P++)C=m(C,L(o(l[P][0]),A[P][0]));return C}}function i(a,O){b(a,O);for(var u=a._index,l=a._values,d=O._index,A=O._values,h=0,q=t,_=r,m=0,L=0;m<u.length&&L<d.length;){var g=u[m],v=d[L];if(g<v){m++;continue}if(g>v){L++;continue}g===v&&(h=q(h,_(l[m],A[L])),m++,L++)}return h}function s(a){return F1(a)?a.size():n(a)}}),wW="trace",DW=["typed","matrix","add"],XW=h0(wW,DW,M=>{var{typed:e,matrix:t,add:r}=M;return e("trace",{Array:function(z){return o(t(z))},SparseMatrix:n,DenseMatrix:o,any:_1});function o(b){var z=b._size,i=b._data;switch(z.length){case 1:if(z[0]===1)return _1(i[0]);throw new RangeError("Matrix must be square (size: "+N1(z)+")");case 2:{var s=z[0],a=z[1];if(s===a){for(var O=0,u=0;u<s;u++)O=r(O,i[u][u]);return O}else throw new RangeError("Matrix must be square (size: "+N1(z)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(z)+")")}}function n(b){var z=b._values,i=b._index,s=b._ptr,a=b._size,O=a[0],u=a[1];if(O===u){var l=0;if(z.length>0)for(var d=0;d<u;d++)for(var A=s[d],h=s[d+1],q=A;q<h;q++){var _=i[q];if(_===d){l=r(l,z[q]);break}if(_>d)break}return l}throw new RangeError("Matrix must be square (size: "+N1(a)+")")}}),Qs="det",EW=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],TW=h0(Qs,EW,M=>{var{typed:e,matrix:t,subtractScalar:r,multiply:o,divideScalar:n,isZero:b,unaryMinus:z}=M;return e(Qs,{any:function(a){return _1(a)},"Array | Matrix":function(a){var O;switch(F1(a)?O=a.size():Array.isArray(a)?(a=t(a),O=a.size()):O=[],O.length){case 0:return _1(a);case 1:if(O[0]===1)return _1(a.valueOf()[0]);if(O[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+N1(O)+")");case 2:{var u=O[0],l=O[1];if(u===l)return i(a.clone().valueOf(),u);if(l===0)return 1;throw new RangeError("Matrix must be square (size: "+N1(O)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(O)+")")}}});function i(s,a,O){if(a===1)return _1(s[0][0]);if(a===2)return r(o(s[0][0],s[1][1]),o(s[1][0],s[0][1]));for(var u=!1,l=new Array(a).fill(0).map((y,X)=>X),d=0;d<a;d++){var A=l[d];if(b(s[A][d])){var h=void 0;for(h=d+1;h<a;h++)if(!b(s[l[h]][d])){A=l[h],l[h]=l[d],l[d]=A,u=!u;break}if(h===a)return s[A][d]}for(var q=s[A][d],_=d===0?1:s[l[d-1]][d-1],m=d+1;m<a;m++)for(var L=l[m],g=d+1;g<a;g++)s[L][g]=n(r(o(s[L][g],q),o(s[L][d],s[A][g])),_)}var v=s[l[a-1]][a-1];return u?z(v):v}}),Zs="inv",CW=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],xW=h0(Zs,CW,M=>{var{typed:e,matrix:t,divideScalar:r,addScalar:o,multiply:n,unaryMinus:b,det:z,identity:i,abs:s}=M;return e(Zs,{"Array | Matrix":function(u){var l=F1(u)?u.size():M2(u);switch(l.length){case 1:if(l[0]===1)return F1(u)?t([r(1,u.valueOf()[0])]):[r(1,u[0])];throw new RangeError("Matrix must be square (size: "+N1(l)+")");case 2:{var d=l[0],A=l[1];if(d===A)return F1(u)?t(a(u.valueOf(),d,A),u.storage()):a(u,d,A);throw new RangeError("Matrix must be square (size: "+N1(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(l)+")")}},any:function(u){return r(1,u)}});function a(O,u,l){var d,A,h,q,_;if(u===1){if(q=O[0][0],q===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,q)]]}else if(u===2){var m=z(O);if(m===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(O[1][1],m),r(b(O[0][1]),m)],[r(b(O[1][0]),m),r(O[0][0],m)]]}else{var L=O.concat();for(d=0;d<u;d++)L[d]=L[d].concat();for(var g=i(u).valueOf(),v=0;v<l;v++){var y=s(L[v][v]),X=v;for(d=v+1;d<u;)s(L[d][v])>y&&(y=s(L[d][v]),X=d),d++;if(y===0)throw Error("Cannot calculate inverse, determinant is zero");d=X,d!==v&&(_=L[v],L[v]=L[d],L[d]=_,_=g[v],g[v]=g[d],g[d]=_);var T=L[v],N=g[v];for(d=0;d<u;d++){var D=L[d],C=g[d];if(d!==v){if(D[v]!==0){for(h=r(b(D[v]),T[v]),A=v;A<l;A++)D[A]=o(D[A],n(h,T[A]));for(A=0;A<l;A++)C[A]=o(C[A],n(h,N[A]))}}else{for(h=T[v],A=v;A<l;A++)D[A]=r(D[A],h);for(A=0;A<l;A++)C[A]=r(C[A],h)}}}return g}}}),e3="pinv",SW=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],FW=h0(e3,SW,M=>{var{typed:e,matrix:t,inv:r,deepEqual:o,equal:n,dotDivide:b,dot:z,ctranspose:i,divideScalar:s,multiply:a,add:O,Complex:u}=M;return e(e3,{"Array | Matrix":function(m){var L=F1(m)?m.size():M2(m);switch(L.length){case 1:return q(m)?i(m):L[0]===1?r(m):b(i(m),z(m,m));case 2:{if(q(m))return i(m);var g=L[0],v=L[1];if(g===v)try{return r(m)}catch(y){if(!(y instanceof Error&&y.message.match(/Cannot calculate inverse, determinant is zero/)))throw y}return F1(m)?t(l(m.valueOf(),g,v),m.storage()):l(m,g,v)}default:throw new RangeError("Matrix must be two dimensional (size: "+N1(L)+")")}},any:function(m){return n(m,0)?_1(m):s(1,m)}});function l(_,m,L){var{C:g,F:v}=A(_,m,L),y=a(r(a(i(g),g)),i(g)),X=a(i(v),r(a(v,i(v))));return a(X,y)}function d(_,m,L){for(var g=_1(_),v=0,y=0;y<m;y++){if(L<=v)return g;for(var X=y;h(g[X][v]);)if(X++,m===X&&(X=y,v++,L===v))return g;[g[X],g[y]]=[g[y],g[X]];for(var T=g[y][v],N=0;N<L;N++)g[y][N]=b(g[y][N],T);for(var D=0;D<m;D++)if(D!==y){T=g[D][v];for(var C=0;C<L;C++)g[D][C]=O(g[D][C],a(-1,a(T,g[y][C])))}v++}return g}function A(_,m,L){var g=d(_,m,L),v=_.map((X,T)=>X.filter((N,D)=>D<m&&!h(z(g[D],g[D])))),y=g.filter((X,T)=>!h(z(g[T],g[T])));return{C:v,F:y}}function h(_){return n(O(_,u(1,1)),O(0,u(1,1)))}function q(_){return o(O(_,u(1,1)),O(a(_,0),u(1,1)))}}),IW="divide",PW=["typed","matrix","multiply","equalScalar","divideScalar","inv"],kW=h0(IW,PW,M=>{var{typed:e,matrix:t,multiply:r,equalScalar:o,divideScalar:n,inv:b}=M,z=rp({typed:e,equalScalar:o}),i=Mp({typed:e});return e("divide",hc({"Array | Matrix, Array | Matrix":function(a,O){return r(a,b(O))},"DenseMatrix, any":function(a,O){return i(a,O,n,!1)},"SparseMatrix, any":function(a,O){return z(a,O,n,!1)},"Array, any":function(a,O){return i(t(a),O,n,!1).valueOf()},"any, Array | Matrix":function(a,O){return r(a,b(O))}},n.signatures))}),t3="sum",$W=["typed","config","add","numeric"],UW=h0(t3,$W,M=>{var{typed:e,config:t,add:r,numeric:o}=M;return e(t3,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":b,"...":function(i){if(Lo(i))throw new TypeError("Scalar values expected in function sum");return n(i)}});function n(z){var i;return fM(z,function(s){try{i=i===void 0?s:r(i,s)}catch(a){throw gt(a,"sum",s)}}),i===void 0&&(i=o(0,t.number)),typeof i=="string"&&(i=o(i,t.number)),i}function b(z,i){try{var s=tp(z,i,r);return s}catch(a){throw gt(a,"sum")}}}),r3="median",jW=["typed","add","divide","compare","partitionSelect"],HW=h0(r3,jW,M=>{var{typed:e,add:t,divide:r,compare:o,partitionSelect:n}=M;function b(s){try{s=Hb(s.valueOf());var a=s.length;if(a===0)throw new Error("Cannot calculate median of an empty array");if(a%2===0){for(var O=a/2-1,u=n(s,O+1),l=s[O],d=0;d<O;++d)o(s[d],l)>0&&(l=s[d]);return i(l,u)}else{var A=n(s,(a-1)/2);return z(A)}}catch(h){throw gt(h,"median")}}var z=e({"number | BigNumber | Complex | Unit":function(a){return a}}),i=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(a,O){return r(t(a,O),2)}});return e(r3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(a,O){throw new Error("median(A, dim) is not yet supported")},"...":function(a){if(Lo(a))throw new TypeError("Scalar values expected in function median");return b(a)}})}),xo=Yd({config:U2}),op=Jd({}),np=t5({}),bp=o5({}),Ce=p5({Matrix:bp}),C0=Kq({BigNumber:xo,Complex:op,DenseMatrix:Ce,Fraction:np}),YW=F5({typed:C0}),So=P5({typed:C0}),GW=B5({BigNumber:xo,typed:C0}),M3=Nh({typed:C0}),Rt=d5({config:U2,typed:C0}),Fo=c5({typed:C0}),VW=u5({typed:C0}),Io=hh({typed:C0}),o3=v5({typed:C0}),pp=_5({Matrix:bp,equalScalar:Rt,typed:C0}),n3=$5({typed:C0}),b3=f5({typed:C0}),zp=x5({typed:C0}),p3=X5({Fraction:np,typed:C0}),z3=O5({typed:C0}),o2=T5({DenseMatrix:Ce,Matrix:bp,SparseMatrix:pp,typed:C0}),i3=Vh({isNaN:b3,isNumeric:z3,typed:C0}),lM=eW({bignumber:GW,fraction:p3,number:o3}),KW=Jh({config:U2,multiplyScalar:Io,numeric:lM,typed:C0}),JW=Ph({isInteger:Fo,matrix:o2,typed:C0}),c3=$h({matrix:o2,config:U2,typed:C0}),s3=jh({matrix:o2,typed:C0}),Ht=Bh({isInteger:Fo,matrix:o2,typed:C0}),QW=Dh({prod:KW,size:c3,typed:C0}),ZW=Yh({conj:M3,transpose:s3,typed:C0}),qM=rW({numeric:lM,typed:C0}),e6=bW({DenseMatrix:Ce,concat:Ht,divideScalar:qM,equalScalar:Rt,matrix:o2,typed:C0}),O3=sW({DenseMatrix:Ce,concat:Ht,equalScalar:Rt,matrix:o2,typed:C0}),a3=Eh({BigNumber:xo,DenseMatrix:Ce,SparseMatrix:pp,config:U2,matrix:o2,typed:C0}),t6=Ch({matrix:o2,multiplyScalar:Io,typed:C0}),r6=uW({DenseMatrix:Ce,concat:Ht,config:U2,matrix:o2,typed:C0}),M6=gh({DenseMatrix:Ce,concat:Ht,equalScalar:Rt,matrix:o2,subtractScalar:n3,typed:C0,unaryMinus:zp}),dM=NW({DenseMatrix:Ce,SparseMatrix:pp,addScalar:So,concat:Ht,equalScalar:Rt,matrix:o2,typed:C0}),u3=zW({BigNumber:xo,DenseMatrix:Ce,Fraction:np,concat:Ht,config:U2,equalScalar:Rt,matrix:o2,typed:C0}),o6=hW({equal:O3,typed:C0}),A3=BW({addScalar:So,conj:M3,multiplyScalar:Io,size:c3,typed:C0}),n6=lW({DenseMatrix:Ce,concat:Ht,config:U2,matrix:o2,typed:C0}),ip=LW({config:U2,numeric:lM,smaller:r6,typed:C0}),yr=_h({addScalar:So,dot:A3,equalScalar:Rt,matrix:o2,multiplyScalar:Io,typed:C0}),b6=_W({compare:u3,isNaN:b3,isNumeric:z3,typed:C0}),p6=UW({add:dM,config:U2,numeric:lM,typed:C0}),z6=XW({add:dM,matrix:o2,typed:C0}),f3=TW({divideScalar:qM,isZero:VW,matrix:o2,multiply:yr,subtractScalar:n3,typed:C0,unaryMinus:zp}),i6=gW({config:U2,larger:n6,numeric:lM,typed:C0}),Po=xW({abs:YW,addScalar:So,det:f3,divideScalar:qM,identity:a3,matrix:o2,multiply:yr,typed:C0,unaryMinus:zp}),c6=FW({Complex:op,add:dM,ctranspose:ZW,deepEqual:o6,divideScalar:qM,dot:A3,dotDivide:e6,equal:O3,inv:Po,matrix:o2,multiply:yr,typed:C0}),s6=oW({Complex:op,config:U2,fraction:p3,identity:a3,inv:Po,matrix:o2,multiply:yr,number:o3,typed:C0}),O6=kW({divideScalar:qM,equalScalar:Rt,inv:Po,matrix:o2,multiply:yr,typed:C0}),l3=HW({add:dM,compare:u3,divide:O6,partitionSelect:b6,typed:C0});class a6{constructor(e,t,r){E(this,"_cacheData");E(this,"_variables");E(this,"_math");E(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}alma({series:e,length:t,offset:r,sigma:o,floor:n,isSeriesLen:b},z){if(t===void 0||r===void 0||o===void 0)return;const i=this._cacheDataList(e,t,`alma_${z}`,b);if(i===void 0)return;let s=r*(t-1);n&&(s=Math.floor(s));const a=t/o;let O=0,u=0;for(let l=0;l<=t-1;l++){const d=Math.exp(-1*Math.pow(l-s,2)/(2*Math.pow(a,2)));O+=d,u+=i[i.length-1-(t-l-1)]*d}return u/O}sma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const b=this._cacheDataList(e,t,`sma_${o}`,r);if(b===void 0)return;const z=b.slice(-t);return n=p6(...z)/t,n}rma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`rma_${o}`);if(n)return n==null?void 0:n.sum;const{sum:b}=this._getCacheData(`rma_${o}`),z=1/t,i=this.sma({source:e,length:t,isSeriesLen:r},o),s=b===void 0?i:z*e+(1-z)*(b||0);return this._cacheDataHandle(`rma_${o}`,{sum:s}),s}atr({length:e,isSeriesLen:t},r){const o=this._verifyCacheData(`atr_${r}`);if(o)return o==null?void 0:o.value;const{high:n,close:b}=this._getCacheData(`atr_${r}`),{high:z,close:i,low:s}=this._variables,a=n===void 0?z-s:Math.max(Math.max(z-s,Math.abs(z-b)),Math.abs(s-b)),O=this.rma({source:a,length:e,isSeriesLen:t},r);return this._cacheDataHandle(`atr_${r}`,{high:z,close:i,value:O}),O}barssince({condition:e},t){const r=this._verifyCacheData(`barssince_${t}`);if(r)return r==null?void 0:r.count;let{count:o}=this._getCacheData(`barssince_${t}`);if(e)o=0;else{if(o===void 0)return;o+=1}return this._cacheDataHandle(`barssince_${t}`,{count:o}),o}stdev({source:e,length:t,biased:r=!0,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0)return;const b=this._cacheDataList(e,t,`stdev_${n}`,o),z=this.sma({source:e,length:t,isSeriesLen:o},n);if(b===void 0)return;let i=0;for(let s=0;s<t;s++){const a=this._sum(b[b.length-1-s],-(z||0));i+=a*a}return r||t<=1?Math.sqrt(i/t):Math.sqrt(i/(t-1))}_sum(e,t){let o=e+t;return Math.abs(o)<=1e-10&&(o=0),o}bb({series:e,length:t,mult:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this.stdev({source:e,length:t,isSeriesLen:o},n);if(b===void 0||z===void 0)return[];const i=r*z;return[b,b+i,b-i]}bbw({series:e,length:t,mult:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this.stdev({source:e,length:t,isSeriesLen:o},n);if(b===void 0||z===void 0)return;const i=r*z;return(b+i-(b-i))/b}cci({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},o),b=this.dev({source:e,length:t,isSeriesLen:r},o);if(!(n===void 0||b===void 0))return(e-n)/(.015*b)}change({source:e,length:t=1,isSeriesLen:r},o){const n=this._cacheDataList(e,t,`change_${o}`,r);if(n===void 0)return;const b=n[n.length-1-t];if(!(e===void 0||isNaN(e)))return b===void 0?b:typeof e=="boolean"?b!==e:e-b}cmo({series:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return;const o=this.change({source:e},r);if(o===void 0)return;const n=this._math.sum({source:o>=0?o:0,length:t},`sm1_${r}`),b=this._math.sum({source:o>=0?0:-o,length:t},`sm2_${r}`);if(!(n===void 0||b===void 0))return 100*(n-b)/(n+b)}cog({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${o}`,r),b=this._math.sum({source:e,length:t},o);if(b===void 0||n===void 0)return;let z=0;for(let i=0;i<t;i++){const s=n[n.length-1-i];z+=s*(i+1)}return-z/b}correlation({source1:e,source2:t,length:r,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||isNaN(t)||r===void 0)return;const b=this._cacheDataList([e,t],r,`correlation_${n}`,o),z=this.sma({source:e,length:r,isSeriesLen:o},`sma1_${n}`),i=this.sma({source:t,length:r,isSeriesLen:o},`sma2_${n}`);if(z===void 0||i===void 0||b===void 0)return;let s=0,a=0,O=0;for(let l=0;l<r;l++){const[d,A]=b[b.length-1-l],h=d-z,q=A-i;s+=h*q,a+=h*h,O+=q*q}return isNaN(a)||isNaN(s)||isNaN(O)?void 0:s/Math.sqrt(a*O)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`cross_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`cross_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n>=b&&e<t||n<=b&&e>t,this._cacheDataHandle(`cross_${r}`,{source1:e,source2:t,value:z}),z}crossover({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`crossover_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`crossover_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n<=b&&e>t,this._cacheDataHandle(`crossover_${r}`,{source1:e,source2:t,value:z}),z}crossunder({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const o=this._verifyCacheData(`crossunder_${r}`);if(o)return o==null?void 0:o.value;const{source1:n,source2:b}=this._getCacheData(`crossunder_${r}`);let z=!1;return n===void 0||b===void 0?z=!1:z=n>=b&&e<t,this._cacheDataHandle(`crossunder_${r}`,{source1:e,source2:t,value:z}),z}cum({source:e=0},t){const r=this._verifyCacheData(`cum_${t}`);if(r)return r==null?void 0:r.sum;e=isNaN(e)?0:e;let{sum:o}=this._getCacheData(`cum_${t}`);return o=o||0,o+=e,this._cacheDataHandle(`cum_${t}`,{sum:o}),o}dev({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},o);let b=0;const z=this._cacheDataList(e,t,`dev_${o}`,r);if(!(!z||n===void 0)){for(let i=0;i<t;i++){const s=z[z.length-1-i];b+=Math.abs(s-n)}return b/t}}dmi({diLength:e,adxSmoothing:t},r){if(e===void 0||t===void 0)return[void 0,void 0,void 0];const o=`dmi_${r}`,n=this._verifyCacheData(o);if(n)return n==null?void 0:n.value;const{low:b,high:z,close:i,PDMS:s,NDMS:a,TRS:O,ADX:u,count:l=0}=this._getCacheData(o),{low:d,high:A,close:h}=this._variables;if(b===void 0||z===void 0||i===void 0)return this._cacheData[o]={low:d,high:A,close:h,PDMS:s,NDMS:a,TRS:A-d,count:1},[void 0,void 0,void 0];let q=A-z,_=b-d;q=q>_&&q>0?q:0,_=_>q&&_>0?_:0,q===_&&(q=_=0);const m=Math.max(A-d,Math.abs(A-i),Math.abs(d-i));let L={};if(l<e)L={low:d,high:A,close:h,PDMS:(s||0)+q,NDMS:(a||0)+_,TRS:(O||0)+m,count:l+1,value:[void 0,void 0,void 0]};else{const g=s-s/e+q,v=a-a/e+_,y=O-O/e+m,X=g/y*100,T=v/y*100,N=Math.abs((X-T)/(X+T))*100;let D=N,C=[X,T,void 0];if(l+1-e<t){const P=l+1-e;D=((u||0)*(P-1)+N)/P}else D=(u*(t-1)+N)/t,C=[X,T,D];L={low:d,high:A,close:h,PDMS:g,NDMS:v,TRS:y,ADX:D,count:l+1,value:C}}return this._cacheDataHandle(o,L),L.value}ema({source:e,length:t,isSeriesLen:r},o){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`ema_${o}`);if(n)return n==null?void 0:n.sum;let{sum:b,count:z=1}=this._getCacheData(`ema_${o}`);const i=this.sma({source:e,length:t,isSeriesLen:r},o);if(z>t){const s=2/(t+1);b=b===void 0?e:s*e+(1-s)*(b||0)}else b=i;return z+=1,this._cacheDataHandle(`ema_${o}`,{sum:b,count:z}),b}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const o=this._verifyCacheData(`falling_${r}`);if(o)return o==null?void 0:o.value;const{source:n,fallings:b=[]}=this._getCacheData(`falling_${r}`);b.push(n>e);const z=b.slice(-t);let i=!1;return z.length<t?i=!1:i=z.every(s=>s),this._cacheDataHandle(`falling_${r}`,{source:e,fallings:z,value:i}),i}rising({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const o=this._verifyCacheData(`rising_${r}`);if(o)return o==null?void 0:o.value;const{source:n,risings:b=[]}=this._getCacheData(`rising_${r}`);b.push(n<e);const z=b.slice(-t);let i=!1;return z.length<t?i=!1:i=z.every(s=>s),this._cacheDataHandle(`rising_${r}`,{source:e,risings:z,value:i}),i}highest({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highest_${o}`,r,!1);if(b)return Math.max(...b.slice(-t))}highestbars({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highestbars_${o}`,r);return b?b.slice(-t).reduce((i,s,a,O)=>s>=O[i]?a:i,0)-t+1:void 0}wma({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${o}`,r);if(!n)return;let b=0,z=0;for(let i=0;i<t;i++){const s=(t-i)*t;b+=s,z+=n[n.length-1-i]*s}return z/b}hma({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t,isSeriesLen:r},o),b=this.wma({source:e,length:Math.round(t/2),isSeriesLen:r},`half_${o}`);return n===void 0||b===void 0?void 0:this.wma({source:2*b-n,length:Math.floor(Math.sqrt(t)),isSeriesLen:r},`hma_${o}`)}kc({series:e,length:t,mult:r,useTrueRange:o=!0,isSeriesLen:n},b){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[void 0,void 0,void 0];const z=this.ema({source:e,length:t,isSeriesLen:n},b),{ta:i,high:s,low:a}=this._variables,O=o?i.tr:s-a,u=this.ema({source:O,length:t,isSeriesLen:n},`range_${b}`);return[z,z+u*r,z-u*r]}kcw({series:e,length:t,mult:r,useTrueRange:o=!0,isSeriesLen:n},b){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const z=this.ema({source:e,length:t,isSeriesLen:n},b),{ta:i,high:s,low:a}=this._variables,O=o?i.tr:s-a,u=this.ema({source:O,length:t,isSeriesLen:n},`range_${b}`);return(z+u*r-(z-u*r))/z}linreg({source:e,length:t,offset:r,isSeriesLen:o},n){if(t===void 0||r===void 0)return;const b=this._cacheDataList(e,t,`dev_${n}`,o);if(!b)return;const z=b.slice(-t).filter(d=>d!==void 0);let i=0,s=0,a=0,O=0;for(const[d,A]of z.entries())i+=d,s+=A,a+=d*A,O+=d*d;const u=(t*a-i*s)/(t*O-i*i);return(s-u*i)/t+u*(t-1-r)}lowest({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowest_${o}`,r,!1);if(b)return Math.min(...b.slice(-t))}lowestbars({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowestbars_${o}`,r);return b?b.slice(-t).reduce((i,s,a,O)=>s<=O[i]?a:i,0)-t+1:void 0}macd({source:e,fastlen:t,slowlen:r,siglen:o},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0||o===void 0)return[void 0,void 0,void 0];const b=this.ema({source:e,length:t},`ema1_${n}`),z=this.ema({source:e,length:r},`ema2_${n}`);if(b===void 0||z===void 0)return[void 0,void 0,void 0];const i=b-z,s=this.ema({source:i,length:o},`macd_${n}`);if(s===void 0)return[i,s,void 0];const a=i-s;return[i,s,a]}max({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`max_${t}`]||0;return e>r&&(r=e),this._cacheData[`max_${t}`]=r,r}min({source:e},t){if(e===void 0||isNaN(e))return;let r=this._cacheData[`min_${t}`]||1/0;return e<r&&(r=e),this._cacheData[`min_${t}`]=r,r}median({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${o}`,r);if(n)return l3(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:o}=this._variables,n=this.change({source:e},r),b=this._math.sum({source:o*(n>=0?0:e),length:t},`lower_${r}`),z=this._math.sum({source:o*(n<=0?0:e),length:t},`upper_${r}`);if(!(z===void 0||b===void 0))return 100-100/(1+z/b)}mode({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${o}`,r);if(n)return ip(i3(n.slice(-t)))}mom({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=`mom_${o}`,b=this._cacheDataList(e,t,n,r);if(!b||b.length<=t||e===void 0||isNaN(e))return;let z=b.length-t-1,i;for(;i===void 0&&z>=0;)i=b[z],z--;return i===void 0?i:e-i}percentile_linear_interpolation({source:e,length:t,percentage:r,isSeriesLen:o},n){if(t===void 0||r===void 0||t<0||r<0||r>100)return;const b=this._cacheDataList(e,t,`percentile_linear_interpolation_${n}`,o);if(!b)return;const z=this._sort(b.slice(-t)),i=z.length;r/=100;const s=1/(i*2);if(r<=s)return z[0];if(r>=1-1/(i*2))return z[i-1];for(const[a,O]of z.entries()){const u=z[a-1];if(r<(a+.5)/i)return u===void 0||O===void 0?void 0:u+(O-u)*(r-(a-.5)/i)/(1/i)}}percentile_nearest_rank({source:e,length:t,percentage:r,isSeriesLen:o},n){if(t===void 0||r===void 0||e===void 0||isNaN(e)||t<0||r<0||r>100)return;const b=this._cacheDataList(e,t,`percentile_nearest_rank_${n}`,o);if(!b)return;const z=this._sort(b.slice(-t)),i=r/100*z.length,s=Math.ceil(i)-1;return z[s>=z.length?z.length-1:s]}percentrank({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${o}`,r);if(!n)return;const b=n.slice(-(t+1)),z=e;if(z===void 0)return;let i=0;for(let s=0;s<b.length;s++)b[s]!==void 0&&(b[s]<z||b[s]===z&&s<t)&&i++;return i/(b.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},o){const n=new n1;let{close:b,open:z,low:i,high:s}=this._variables;const a=`pivot_point_levels_${o}`,O=this._verifyCacheData(a);if(O)return n._value=(O==null?void 0:O.result)||[],n;const{close:u,low:l,high:d,open:A,result:h}=this._getCacheData(a);if(!t&&(d&&l&&(s=Math.max(d,s),i=Math.min(l,i)),this._cacheDataHandle(a,{close:b,open:z,low:i,high:s,result:h}),!r))return n._value=h||[],n;const q={close:b,open:z,low:i,high:s};t===!0&&!r&&(b=u,z=A,i=l,s=d);const _=this._getPivotPointLevels(s,i,b,z,r,e);return this._cacheDataHandle(a,{...q,result:_}),n._value=_,n}_getPivotPointLevels(e,t,r,o,n,b){if(r===void 0||o===void 0||t===void 0||e===void 0)return[];switch(b){case Ft.traditional:return this._traditional(e,t,r);case Ft.fibonacci:return this._fibonacci(e,t,r);case Ft.woodie:return n?[]:this._woodie(e,t);case Ft.classic:return this._classic(e,t,r);case Ft.dm:return this._DM(e,t,r,o);case Ft.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const o=(e+t+r)/3,n=o*2-t,b=o+(e-t),z=o*2+(e-2*t),i=o*3+(e-3*t),s=o*4+(e-4*t),a=o*2-e,O=o-(e-t),u=o*2-(2*e-t),l=o*3-(3*e-t),d=o*4-(4*e-t);return[o,n,a,b,O,z,u,i,l,s,d]}_fibonacci(e,t,r){const o=(e+t+r)/3,n=o+.382*(e-t),b=o-.382*(e-t),z=o+.618*(e-t),i=o-.618*(e-t),s=o+(e-t),a=o-(e-t);return[o,n,b,z,i,s,a]}_woodie(e,t){const{open:r}=this._variables,o=(e+t+2*r)/4,n=2*o-t,b=2*o-e,z=o+(e-t),i=o-(e-t),s=e+2*(o-t),a=t-2*(e-o),O=s+(e-t),u=a-(e-t);return[o,n,b,z,i,s,a,O,u]}_classic(e,t,r){const o=(e+t+r)/3,n=2*o-t,b=2*o-e,z=o+(e-t),i=o-(e-t),s=o+2*(e-t),a=o-2*(e-t),O=o+3*(e-t),u=o-3*(e-t);return[o,n,b,z,i,s,a,O,u]}_DM(e,t,r,o){let n;o===r?n=e+t+2*r:r>o?n=2*e+t+r:n=2*t+e+r;const b=n/4,z=n/2-t,i=n/2-e;return[b,z,i]}_camarilla(e,t,r){const o=(e+t+r)/3,n=r+1.1*(e-t)/12,b=r-1.1*(e-t)/12,z=r+1.1*(e-t)/6,i=r-1.1*(e-t)/6,s=r+1.1*(e-t)/4,a=r-1.1*(e-t)/4,O=r+1.1*(e-t)/2,u=r-1.1*(e-t)/2,l=e/t*r,d=r-(l-r);return[o,n,b,z,i,s,a,O,u,l,d]}pivothigh(e,t){const{leftbars:r,rightbars:o}=e;if(r===void 0||o===void 0||r<0||o<0)return;let n=this._variables.high;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+o+1,`pivothigh_${t}`);if(!b)return;const z=b.slice(-(r+o+1)),i=z[r],s=z.splice(0,r+1),a=Math.max(...z),O=Math.max(...s);return i>=O&&i>a?i:void 0}pivotlow(e,t){const{leftbars:r,rightbars:o}=e;if(r===void 0||o===void 0||r<0||o<0)return;let n=this._variables.low;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+o+1,`pivotlow_${t}`);if(!b)return;const z=b.slice(-(r+o+1)),i=z[r],s=z.splice(0,r+1),a=Math.min(...z),O=Math.min(...s);return i<=O&&i<a?i:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const o=this._cacheDataList(e,t,`range_${r}`,!0);if(!o)return;const n=o.filter(i=>i!==void 0).slice(-t),b=Math.max(...n),z=Math.min(...n);return b-z}roc({source:e,length:t,isSeriesLen:r},o){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${o}`,r),b=this.change({source:e,length:t,isSeriesLen:r},o);if(n)return 100*b/n[n.length-1-t]}rsi({source:e,length:t,isSeriesLen:r},o){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._verifyCacheData(`rsi_${o}`);if(n)return n==null?void 0:n.value;const{source:b}=this._getCacheData(`rsi_${o}`),z=Math.max(e-b,0),i=Math.max(b-e,0),s=this.rma({source:z,length:t,isSeriesLen:r},`rma1_${o}`),a=this.rma({source:i,length:t,isSeriesLen:r},`rma2_${o}`),O=s===void 0||a===void 0?void 0:100-100/(1+s/a);return this._cacheDataHandle(`rsi_${o}`,{source:e,value:O}),O}sar({start:e,inc:t,max:r},o){if(e===void 0||t===void 0||r===void 0)return;const n=this._verifyCacheData(`sar_${o}`);if(n)return n==null?void 0:n.result;const{close:b,low:z,high:i,preLow:s,preHigh:a,data:O={}}=this._getCacheData(`sar_${o}`);let{result:u,maxMin:l,acceleration:d,isBelow:A}=O,h=!1;const{close:q,low:_,high:m,bar_index:L}=this._variables;return L===1&&(q>b?(A=!0,l=m,u=z):(A=!1,l=_,u=i),h=!0,d=e),u=u+d*(l-u),A?u>_&&(h=!0,A=!1,u=Math.max(m,l||0),l=_,d=e):u<m&&(h=!0,A=!0,u=Math.min(_,l||0),l=m,d=e),h||(A?m>(l||0)&&(l=m,d=Math.min((d||0)+t,r)):_<(l||0)&&(l=_,d=Math.min((d||0)+t,r))),A?(u=Math.min(u,z),L>1&&(u=Math.min(u,s))):(u=Math.max(u,i),L>1&&(u=Math.max(u,a))),this._cacheDataHandle(`sar_${o}`,{high:m,close:q,low:_,preLow:z,preHigh:i,data:Object.assign(O,{result:u,maxMin:l,acceleration:d,isBelow:A})}),u}stoch({source:e,high:t,low:r,length:o,isSeriesLen:n},b){if(o===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||o<0)return;const z=this.lowest({source:r,length:o,isSeriesLen:n},b),i=this.highest({source:t,length:o,isSeriesLen:n},b);if(!(z===void 0||i===void 0))return 100*(e-z)/(i-z)}supertrend({factor:e,atrPeriod:t},r){if(e===void 0||t===void 0)return[void 0,void 0];const o=`supertrend_${r}`,n=this._verifyCacheData(o);if(n)return n==null?void 0:n.value;let b=1;const{hl2:z,close:i}=this._variables,{upperBand:s,lowerBand:a,superTrend:O,atr:u,close:l}=this._getCacheData(o),d=this.atr({length:t},r);if(d===void 0)return this._cacheDataHandle(o,{close:i,value:[void 0,b]}),[void 0,b];let A=z+e*d,h=z-e*d;const q=s||0,_=a||0;h=h>_||l<_?h:_,A=A<q||l>q?A:q,u===void 0?b=1:O===q?b=i>A?-1:1:b=i<h?1:-1;const m=b===-1?h:A;return this._cacheDataHandle(o,{upperBand:A,lowerBand:h,superTrend:m,atr:d,close:i,value:[m,b]}),[m,b]}swma({source:e},t){const r=this._verifyCacheData(`swma_${t}`);if(r)return r==null?void 0:r.value;let{list:o}=this._getCacheData(`swma_${t}`);o||(o=[]),o.push(e),o=o.slice(-4);const n=o.filter(b=>b!==void 0).length<4?void 0:o[3]*1/6+o[2]*2/6+o[1]*2/6+o[0]*1/6;return this._cacheDataHandle(`swma_${t}`,{list:o,value:n}),n}tr({handle_na:e=!1},t){const{close:r,low:o,high:n}=this._variables,b=this._verifyCacheData(`tr_${t}`);if(b)return b==null?void 0:b.value;const{close:z}=this._getCacheData(`tr_${t}`);let i;return z===void 0?i=e?n-o:void 0:i=Math.max(n-o,Math.abs(n-z),Math.abs(o-z)),this._cacheDataHandle(`tr_${t}`,{close:r,value:i}),i}tsi({source:e,short_length:t,long_length:r},o){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const n=this.change({source:e},o);if(n===void 0)return;const b=this._doubleSmooth(n,r,t,o),z=this._doubleSmooth(Math.abs(n),r,t,`abs_${o}`);if(!(z===void 0||b===void 0))return b/z}_doubleSmooth(e,t,r,o){const n=this.ema({source:e,length:t},`ema1_${o}`);return this.ema({source:n,length:r},`ema2_${o}`)}valuewhen({condition:e,source:t,occurrence:r},o){if(r===void 0||r<0)return;let{list:n}=this._getCacheData(`valuewhen_${o}`);n||(n=[]),e&&n.push(t);const b=n[n.length-1-r];return this._cacheDataHandle(`valuewhen_${o}`,{list:n,value:b}),b}variance({source:e,length:t,biased:r=!0,isSeriesLen:o},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const b=this.sma({source:e,length:t,isSeriesLen:o},n),z=this._cacheDataList(e,t,`variance_${n}`,!0);if(!z||b===void 0)return;const i=z.filter(a=>a!==void 0&&!isNaN(a)).slice(-t);if(i.length<t)return;const s=i.reduce((a,O)=>a+Math.pow(O-b,2),0);if(s!==void 0)return r||t<=1?s/t:s/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},o){if(e===void 0)return;const n=`vwap_${o}`,b=this._verifyCacheData(n);if(b)return b==null?void 0:b.value;t=t===void 0?this._timeframe.change({timeframe:"1D"},o):t;const{volume:z}=this._variables;let{sum:i=0,sumV:s=0,count:a=0,isReset:O,sumS:u=0}=this._getCacheData(n);if(t&&(i=s=a=u=0,O=!0),!O)return r!==void 0?[]:void 0;const l=e*z+i,d=z+s,A=l/d;if(a++,r!==void 0){u=z*Math.pow(e,2)+u;const h=this._computeBands(u,d,r,A);return this._cacheDataHandle(n,{sum:l,sumV:d,count:a,isReset:O,sumS:u,value:h}),h}return this._cacheDataHandle(n,{sum:l,sumV:d,count:a,isReset:O,value:A}),A}_computeBands(e,t,r,o){let n=e/t-Math.pow(o,2);n=n<0?0:n;const b=Math.sqrt(n),z=b!==void 0&&!isNaN(b)?o+r*b:void 0,i=b!==void 0&&!isNaN(b)?o-r*b:void 0;return[o,z,i]}vwma({source:e,length:t,isSeriesLen:r},o){if(e===void 0||isNaN(e)||t===void 0||t<=0)return;const{volume:n}=this._variables,b=this.sma({source:e*n,length:t,isSeriesLen:r},`sma1_${o}`),z=this.sma({source:n,length:t,isSeriesLen:r},`sma2_${o}`);if(!(b===void 0||z===void 0))return b/z}wpr({length:e,isSeriesLen:t},r){if(e===void 0||e<=0)return;const o=this.highest({length:e,isSeriesLen:t},r),n=this.lowest({length:e,isSeriesLen:t},r),{close:b}=this._variables;if(!(o===void 0||n===void 0))return(o-b)/(o-n)*-100}_sort(e){const t=e.length;for(let r=0;r<t;r++){let o={};for(let n=0;n<t-r;n++){const{currentVal:b,currentIndex:z}=o,i=e[n];if(i!==void 0){if(b!==void 0&&i<b){e.splice(n,1),e.splice(z,0,i),o={currentIndex:z+1,currentVal:b};continue}o={currentIndex:n,currentVal:i}}}}return e}_cacheDataList(e,t,r,o=!1,n=!0){const b=this._cacheData[r]||{barIndex:-1,list:[],length:t},{bar_index:z}=this._variables;if(b.length<t&&(b.length=t),b.barIndex<=z){const i=b.list.length;if(b.barIndex===z)b.list[i-1]=e;else{let s=z-b.barIndex-1;if(b.barIndex!==-1&&s>0){const a=b.list[i-1];for(;s>0;)b.list.push(a),s--}b.list.push(e)}b.barIndex=z,b.list.length>b.length+5&&!o&&b.list.shift(),this._cacheData[r]=b}if(!(b.list.length<t&&n))return b.list}_getCacheData(e){const{bar_index:t}=this._variables,r=this._cacheData[e]||{};return r.barIndex===t?r.preCacheData||{}:r}_cacheDataHandle(e,t){const{bar_index:r,_isRealTimeBar:o,_isRepeated:n}=this._variables;if(!o&&!n){let b=this._cacheData[e]||{};b.barIndex===r&&(b=b.preCacheData),this._cacheData[e]=Object.assign(t,{barIndex:r,preCacheData:{...b,preCacheData:void 0}})}}_verifyCacheData(e){const{bar_index:t,_isRepeated:r}=this._variables,o=this._cacheData[e]||{},{barIndex:n}=o;if(n===t&&r)return o}}class u6{constructor(e,t,r){E(this,"_cacheData");E(this,"_variables");E(this,"_errorListener");E(this,"_historyInputs");E(this,"_name");this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(e){if(!(e!=null&&e.length)){self.workerStorage.delete(this._name),this._cacheData={};return}for(const t of e){const r=t.id,o=this._historyInputs[r];(!(t!=null&&t.sourceTypeName)&&(o==null?void 0:o.defval)!==t.defval||o!=null&&o.sourceTypeName&&t.sourceTypeName!==(o==null?void 0:o.sourceTypeName))&&(this._cacheData[r]=Object.assign(this._cacheData[r]||{},{...t,isModify:!0}))}}input(e,t){return this._cacheHandle(e,t)}int(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,v2.INT)}bool(e,t){return this._cacheHandle(e,t,v2.BOOL)}color(e,t){return this._cacheHandle(e,t,v2.COLOR)}time(e,t){return this._cacheHandle(e,t,v2.TIME)}float(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,v2.FLOAT)}price(e,t){return this._cacheHandle(e,t,v2.PRICE)}source(e,t){return this._cacheHandle(e,t,v2.SOURCE)}string(e,t){return this._cacheHandle(e,t,v2.STRING)}symbol(e,t){return this._cacheHandle(e,t,v2.SYMBOL)}session(e,t){return this._cacheHandle(e,t,v2.SESSION)}text_area(e,t){return this._cacheHandle(e,t,v2.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,v2.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,v2.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const o=`${r||"input"}_${t}`,n=this._cacheData[o];if(e.defval===void 0&&this._errorListener.addError(l1.inputDefvalErr,t,$0.Error),self.workerStorage.setValue(this._name,o,{...e}),n)if(!n.isModify)Object.assign(this._cacheData[o],e);else{const b=this._historyInputs[o];!(e.sourceTypeName||b!=null&&b.sourceTypeName)&&e.defval===(b==null?void 0:b.defval)||e.sourceTypeName&&(b==null?void 0:b.sourceTypeName)===e.sourceTypeName?n.sourceTypeName&&(this._cacheData[o].defval=this._variables[n.sourceTypeName]):Object.assign(this._cacheData[o],e)}else{const{defval:b,display:z}=e;if(this._displayVerify(t,z),e={inputType:r,...e},this._cacheData[o]=e,(r||e.inputType)===v2.SOURCE)this._cacheData[o].options=Nu;else if(e.options)if(!e.options.includes(b))this._errorListener.addError(r2(l1.inputOptErr,{defval:String(b),args:e.options.toString()}),t,$0.Error,6+((r==null?void 0:r.length)||-1));else{const i=new Map;for(const s of e.options){if(i.has(s)){this._errorListener.addError(r2(l1.optionsRepeatErr,{option:String(s)}),t,$0.Error,6+((r==null?void 0:r.length)||-1));break}i.set(s,s)}}}return this._cacheData[o].defval}_displayVerify(e,t){!t||!t.length||t.includes(A2.dataWindow)||t.includes(A2.statusLine)||this._errorListener.addError(r2(l1.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,$0.Error)}_verifyMaxOrMin(e,t){const{defval:r,maxval:o,minval:n}=e;typeof r=="number"&&(o!==void 0&&r>o||n!==void 0&&r<n)&&this._errorListener.addError(l1.minOrMaxErr,t,$0.Error)}getInputs(){const e=Object.keys(this._cacheData),t=[];for(const r of e){const o=this._cacheData[r];o.id=r,t.push(o)}return t.sort((r,o)=>(r.index||0)-(o.index||0))}}class A6{color({x:e}){return e===void 0?null:e}new({color:e,transp:t=100}){d0(t)&&(t=100);let r=(100-t)/100;r=r<0?0:r>1?1:r;const{r:o,g:n,b}=this._parseColor(e||"");return`rgba(${Math.round(o)}, ${Math.round(n)}, ${Math.round(b)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:o=0}){return d0(o)&&(o=0),d0(e)&&(e=0),d0(t)&&(t=0),d0(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-o)/100})`}g({color:e}){return e?this._parseColor(e).g:0}r({color:e}){return e?this._parseColor(e).r:0}b({color:e}){return e?this._parseColor(e).b:0}t({color:e}){return e?100-Math.round(this._parseColor(e).a*100):0}from_gradient({value:e,bottom_value:t,top_value:r,bottom_color:o,top_color:n}){if(d0(e)||d0(t)||d0(r)||r===t)return"rgba(0,0,0,1)";const b=(e-t)/(r-t),z=Math.min(Math.max(b,0),1),{r:i,g:s,b:a,a:O}=this._parseColor(o||"rgba(0,0,0,0)"),{r:u,g:l,b:d,a:A}=this._parseColor(n||"rgba(0,0,0,0)"),h=i+z*(u-i),q=s+z*(l-s),_=a+z*(d-a),m=O+z*(A-O);return`rgba(${Math.round(h)}, ${Math.round(q)}, ${Math.round(_)}, ${m.toFixed(2)})`}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3],n=n===void 0?1:n}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/[\d.]+/g))==null?void 0:t.map(Number))||[]}}var Z0={};const f6=Object.prototype.toString;function hM(M){const e=f6.call(M);return e.endsWith("Array]")&&!e.includes("Big")}var l6=Object.freeze({__proto__:null,isAnyArray:hM}),q6=V1(l6);function d6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!hM(M))throw new TypeError("input must be an array");if(M.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,o=e.toIndex,n=o===void 0?M.length:o;if(r<0||r>=M.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>M.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=M[r],z=r+1;z<n;z++)M[z]>b&&(b=M[z]);return b}function h6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!hM(M))throw new TypeError("input must be an array");if(M.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,o=e.toIndex,n=o===void 0?M.length:o;if(r<0||r>=M.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>M.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=M[r],z=r+1;z<n;z++)M[z]<b&&(b=M[z]);return b}function W6(M){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(hM(M)){if(M.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var t;if(e.output!==void 0){if(!hM(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(M.length);var r=h6(M),o=d6(M);if(r===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=e.min,b=n===void 0?e.autoMinMax?r:0:n,z=e.max,i=z===void 0?e.autoMinMax?o:1:z;if(b>=i)throw new RangeError("min option must be smaller than max option");for(var s=(i-b)/(o-r),a=0;a<M.length;a++)t[a]=(M[a]-r)*s+b;return t}var _6=Object.freeze({__proto__:null,default:W6}),m6=V1(_6);Object.defineProperty(Z0,"__esModule",{value:!0});var C2=q6,q3=m6;const ko=" ".repeat(2),d3=" ".repeat(4);function g6(){return h3(this)}function h3(M,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:o=8,padMinus:n="auto"}=e;return`${M.constructor.name} {
|
69
69
|
${ko}[
|
70
70
|
${d3}${R6(M,t,r,o,n)}
|
71
71
|
${ko}]
|
@@ -73,7 +73,7 @@ ${ko}rows: ${M.rows}
|
|
73
73
|
${ko}columns: ${M.columns}
|
74
74
|
}`}function R6(M,e,t,r,o){const{rows:n,columns:b}=M,z=Math.min(n,e),i=Math.min(b,t),s=[];if(o==="auto"){o=!1;e:for(let a=0;a<z;a++)for(let O=0;O<i;O++)if(M.get(a,O)<0){o=!0;break e}}for(let a=0;a<z;a++){let O=[];for(let u=0;u<i;u++)O.push(L6(M.get(a,u),r,o));s.push(`${O.join(" ")}`)}return i!==b&&(s[s.length-1]+=` ... ${b-t} more columns`),z!==n&&s.push(`... ${n-e} more rows`),s.join(`
|
75
75
|
${d3}`)}function L6(M,e,t){return(M>=0&&t?` ${W3(M,e-1)}`:W3(M,e)).padEnd(e)}function W3(M,e){let t=M.toString();if(t.length<=e)return t;let r=M.toFixed(e);if(r.length>e&&(r=M.toFixed(Math.max(0,e-(r.length-e)))),r.length<=e&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let o=M.toExponential(e);return o.length>e&&(o=M.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function v6(M,e){M.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},M.prototype.addS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)+r);return this},M.prototype.addM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)+r.get(o,n));return this},M.add=function(r,o){return new e(r).add(o)},M.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},M.prototype.subS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)-r);return this},M.prototype.subM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)-r.get(o,n));return this},M.sub=function(r,o){return new e(r).sub(o)},M.prototype.subtract=M.prototype.sub,M.prototype.subtractS=M.prototype.subS,M.prototype.subtractM=M.prototype.subM,M.subtract=M.sub,M.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},M.prototype.mulS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)*r);return this},M.prototype.mulM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)*r.get(o,n));return this},M.mul=function(r,o){return new e(r).mul(o)},M.prototype.multiply=M.prototype.mul,M.prototype.multiplyS=M.prototype.mulS,M.prototype.multiplyM=M.prototype.mulM,M.multiply=M.mul,M.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},M.prototype.divS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)/r);return this},M.prototype.divM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)/r.get(o,n));return this},M.div=function(r,o){return new e(r).div(o)},M.prototype.divide=M.prototype.div,M.prototype.divideS=M.prototype.divS,M.prototype.divideM=M.prototype.divM,M.divide=M.div,M.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},M.prototype.modS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)%r);return this},M.prototype.modM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)%r.get(o,n));return this},M.mod=function(r,o){return new e(r).mod(o)},M.prototype.modulus=M.prototype.mod,M.prototype.modulusS=M.prototype.modS,M.prototype.modulusM=M.prototype.modM,M.modulus=M.mod,M.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},M.prototype.andS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)&r);return this},M.prototype.andM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)&r.get(o,n));return this},M.and=function(r,o){return new e(r).and(o)},M.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},M.prototype.orS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)|r);return this},M.prototype.orM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)|r.get(o,n));return this},M.or=function(r,o){return new e(r).or(o)},M.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},M.prototype.xorS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)^r);return this},M.prototype.xorM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)^r.get(o,n));return this},M.xor=function(r,o){return new e(r).xor(o)},M.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},M.prototype.leftShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)<<r);return this},M.prototype.leftShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)<<r.get(o,n));return this},M.leftShift=function(r,o){return new e(r).leftShift(o)},M.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},M.prototype.signPropagatingRightShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>r);return this},M.prototype.signPropagatingRightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>r.get(o,n));return this},M.signPropagatingRightShift=function(r,o){return new e(r).signPropagatingRightShift(o)},M.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},M.prototype.rightShiftS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>>r);return this},M.prototype.rightShiftM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,this.get(o,n)>>>r.get(o,n));return this},M.rightShift=function(r,o){return new e(r).rightShift(o)},M.prototype.zeroFillRightShift=M.prototype.rightShift,M.prototype.zeroFillRightShiftS=M.prototype.rightShiftS,M.prototype.zeroFillRightShiftM=M.prototype.rightShiftM,M.zeroFillRightShift=M.rightShift,M.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,~this.get(r,o));return this},M.not=function(r){return new e(r).not()},M.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.abs(this.get(r,o)));return this},M.abs=function(r){return new e(r).abs()},M.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.acos(this.get(r,o)));return this},M.acos=function(r){return new e(r).acos()},M.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.acosh(this.get(r,o)));return this},M.acosh=function(r){return new e(r).acosh()},M.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.asin(this.get(r,o)));return this},M.asin=function(r){return new e(r).asin()},M.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.asinh(this.get(r,o)));return this},M.asinh=function(r){return new e(r).asinh()},M.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.atan(this.get(r,o)));return this},M.atan=function(r){return new e(r).atan()},M.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.atanh(this.get(r,o)));return this},M.atanh=function(r){return new e(r).atanh()},M.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cbrt(this.get(r,o)));return this},M.cbrt=function(r){return new e(r).cbrt()},M.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.ceil(this.get(r,o)));return this},M.ceil=function(r){return new e(r).ceil()},M.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.clz32(this.get(r,o)));return this},M.clz32=function(r){return new e(r).clz32()},M.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cos(this.get(r,o)));return this},M.cos=function(r){return new e(r).cos()},M.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.cosh(this.get(r,o)));return this},M.cosh=function(r){return new e(r).cosh()},M.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.exp(this.get(r,o)));return this},M.exp=function(r){return new e(r).exp()},M.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.expm1(this.get(r,o)));return this},M.expm1=function(r){return new e(r).expm1()},M.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.floor(this.get(r,o)));return this},M.floor=function(r){return new e(r).floor()},M.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.fround(this.get(r,o)));return this},M.fround=function(r){return new e(r).fround()},M.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log(this.get(r,o)));return this},M.log=function(r){return new e(r).log()},M.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log1p(this.get(r,o)));return this},M.log1p=function(r){return new e(r).log1p()},M.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log10(this.get(r,o)));return this},M.log10=function(r){return new e(r).log10()},M.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.log2(this.get(r,o)));return this},M.log2=function(r){return new e(r).log2()},M.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.round(this.get(r,o)));return this},M.round=function(r){return new e(r).round()},M.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sign(this.get(r,o)));return this},M.sign=function(r){return new e(r).sign()},M.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sin(this.get(r,o)));return this},M.sin=function(r){return new e(r).sin()},M.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sinh(this.get(r,o)));return this},M.sinh=function(r){return new e(r).sinh()},M.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.sqrt(this.get(r,o)));return this},M.sqrt=function(r){return new e(r).sqrt()},M.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.tan(this.get(r,o)));return this},M.tan=function(r){return new e(r).tan()},M.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.tanh(this.get(r,o)));return this},M.tanh=function(r){return new e(r).tanh()},M.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.set(r,o,Math.trunc(this.get(r,o)));return this},M.trunc=function(r){return new e(r).trunc()},M.pow=function(r,o){return new e(r).pow(o)},M.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},M.prototype.powS=function(r){for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,Math.pow(this.get(o,n),r));return this},M.prototype.powM=function(r){if(r=e.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let o=0;o<this.rows;o++)for(let n=0;n<this.columns;n++)this.set(o,n,Math.pow(this.get(o,n),r.get(o,n)));return this}}function ne(M,e,t){let r=t?M.rows:M.rows-1;if(e<0||e>r)throw new RangeError("Row index out of range")}function be(M,e,t){let r=t?M.columns:M.columns-1;if(e<0||e>r)throw new RangeError("Column index out of range")}function Br(M,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==M.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function wr(M,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==M.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function cp(M,e){if(!C2.isAnyArray(e))throw new TypeError("row indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=M.rows)throw new RangeError("row indices are out of range")}function sp(M,e){if(!C2.isAnyArray(e))throw new TypeError("column indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=M.columns)throw new RangeError("column indices are out of range")}function Op(M,e,t,r,o){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Uo("startRow",e),Uo("endRow",t),Uo("startColumn",r),Uo("endColumn",o),e>t||r>o||e<0||e>=M.rows||t<0||t>=M.rows||r<0||r>=M.columns||o<0||o>=M.columns)throw new RangeError("Submatrix indices are out of range")}function $o(M,e=0){let t=[];for(let r=0;r<M;r++)t.push(e);return t}function Uo(M,e){if(typeof e!="number")throw new TypeError(`${M} must be a number`)}function Dr(M){if(M.isEmpty())throw new Error("Empty matrix has no elements to index")}function N6(M){let e=$o(M.rows);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[t]+=M.get(t,r);return e}function y6(M){let e=$o(M.columns);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[r]+=M.get(t,r);return e}function B6(M){let e=0;for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)e+=M.get(t,r);return e}function w6(M){let e=$o(M.rows,1);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[t]*=M.get(t,r);return e}function D6(M){let e=$o(M.columns,1);for(let t=0;t<M.rows;++t)for(let r=0;r<M.columns;++r)e[r]*=M.get(t,r);return e}function X6(M){let e=1;for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)e*=M.get(t,r);return e}function E6(M,e,t){const r=M.rows,o=M.columns,n=[];for(let b=0;b<r;b++){let z=0,i=0,s=0;for(let a=0;a<o;a++)s=M.get(b,a)-t[b],z+=s,i+=s*s;e?n.push((i-z*z/o)/(o-1)):n.push((i-z*z/o)/o)}return n}function T6(M,e,t){const r=M.rows,o=M.columns,n=[];for(let b=0;b<o;b++){let z=0,i=0,s=0;for(let a=0;a<r;a++)s=M.get(a,b)-t[b],z+=s,i+=s*s;e?n.push((i-z*z/r)/(r-1)):n.push((i-z*z/r)/r)}return n}function C6(M,e,t){const r=M.rows,o=M.columns,n=r*o;let b=0,z=0,i=0;for(let s=0;s<r;s++)for(let a=0;a<o;a++)i=M.get(s,a)-t,b+=i,z+=i*i;return e?(z-b*b/n)/(n-1):(z-b*b/n)/n}function x6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e[t])}function S6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e[r])}function F6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)-e)}function I6(M){const e=[];for(let t=0;t<M.rows;t++){let r=0;for(let o=0;o<M.columns;o++)r+=Math.pow(M.get(t,o),2)/(M.columns-1);e.push(Math.sqrt(r))}return e}function P6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e[t])}function k6(M){const e=[];for(let t=0;t<M.columns;t++){let r=0;for(let o=0;o<M.rows;o++)r+=Math.pow(M.get(o,t),2)/(M.rows-1);e.push(Math.sqrt(r))}return e}function $6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e[r])}function U6(M){const e=M.size-1;let t=0;for(let r=0;r<M.columns;r++)for(let o=0;o<M.rows;o++)t+=Math.pow(M.get(o,r),2)/e;return Math.sqrt(t)}function j6(M,e){for(let t=0;t<M.rows;t++)for(let r=0;r<M.columns;r++)M.set(t,r,M.get(t,r)/e)}class U0{static from1DArray(e,t,r){if(e*t!==r.length)throw new RangeError("data length does not match given dimensions");let n=new l0(e,t);for(let b=0;b<e;b++)for(let z=0;z<t;z++)n.set(b,z,r[b*t+z]);return n}static rowVector(e){let t=new l0(1,e.length);for(let r=0;r<e.length;r++)t.set(0,r,e[r]);return t}static columnVector(e){let t=new l0(e.length,1);for(let r=0;r<e.length;r++)t.set(r,0,e[r]);return t}static zeros(e,t){return new l0(e,t)}static ones(e,t){return new l0(e,t).fill(1)}static rand(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:o=Math.random}=r;let n=new l0(e,t);for(let b=0;b<e;b++)for(let z=0;z<t;z++)n.set(b,z,o());return n}static randInt(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:o=0,max:n=1e3,random:b=Math.random}=r;if(!Number.isInteger(o))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(o>=n)throw new RangeError("min must be smaller than max");let z=n-o,i=new l0(e,t);for(let s=0;s<e;s++)for(let a=0;a<t;a++){let O=o+Math.round(b()*z);i.set(s,a,O)}return i}static eye(e,t,r){t===void 0&&(t=e),r===void 0&&(r=1);let o=Math.min(e,t),n=this.zeros(e,t);for(let b=0;b<o;b++)n.set(b,b,r);return n}static diag(e,t,r){let o=e.length;t===void 0&&(t=o),r===void 0&&(r=t);let n=Math.min(o,t,r),b=this.zeros(t,r);for(let z=0;z<n;z++)b.set(z,z,e[z]);return b}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,o=e.columns,n=new l0(r,o);for(let b=0;b<r;b++)for(let z=0;z<o;z++)n.set(b,z,Math.min(e.get(b,z),t.get(b,z)));return n}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,o=e.columns,n=new this(r,o);for(let b=0;b<r;b++)for(let z=0;z<o;z++)n.set(b,z,Math.max(e.get(b,z),t.get(b,z)));return n}static checkMatrix(e){return U0.isMatrix(e)?e:new l0(e)}static isMatrix(e){return e!=null&&e.klass==="Matrix"}get size(){return this.rows*this.columns}apply(e){if(typeof e!="function")throw new TypeError("callback must be a function");for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.call(this,t,r);return this}to1DArray(){let e=[];for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}to2DArray(){let e=[];for(let t=0;t<this.rows;t++){e.push([]);for(let r=0;r<this.columns;r++)e[t].push(this.get(t,r))}return e}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let e=0;e<this.rows;e++)for(let t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let e=0;e<this.rows;e++)if(this.get(e,e)!==0)return!1;return!0}isEchelonForm(){let e=0,t=0,r=-1,o=!0,n=!1;for(;e<this.rows&&o;){for(t=0,n=!1;t<this.columns&&n===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(n=!0,r=t):(o=!1,n=!0);e++}return o}isReducedEchelonForm(){let e=0,t=0,r=-1,o=!0,n=!1;for(;e<this.rows&&o;){for(t=0,n=!1;t<this.columns&&n===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(n=!0,r=t):(o=!1,n=!0);for(let b=t+1;b<this.rows;b++)this.get(e,b)!==0&&(o=!1);e++}return o}echelonForm(){let e=this.clone(),t=0,r=0;for(;t<e.rows&&r<e.columns;){let o=t;for(let n=t;n<e.rows;n++)e.get(n,r)>e.get(o,r)&&(o=n);if(e.get(o,r)===0)r++;else{e.swapRows(t,o);let n=e.get(t,r);for(let b=r;b<e.columns;b++)e.set(t,b,e.get(t,b)/n);for(let b=t+1;b<e.rows;b++){let z=e.get(b,r)/e.get(t,r);e.set(b,r,0);for(let i=r+1;i<e.columns;i++)e.set(b,i,e.get(b,i)-e.get(t,i)*z)}t++,r++}}return e}reducedEchelonForm(){let e=this.echelonForm(),t=e.columns,r=e.rows,o=r-1;for(;o>=0;)if(e.maxRow(o)===0)o--;else{let n=0,b=!1;for(;n<r&&b===!1;)e.get(o,n)===1?b=!0:n++;for(let z=0;z<o;z++){let i=e.get(z,n);for(let s=n;s<t;s++){let a=e.get(z,s)-i*e.get(o,s);e.set(z,s,a)}}o--}return e}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{rows:t=1,columns:r=1}=e;if(!Number.isInteger(t)||t<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let o=new l0(this.rows*t,this.columns*r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)o.setSubMatrix(this,this.rows*n,this.columns*b);return o}fill(e){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,e);return this}neg(){return this.mulS(-1)}getRow(e){ne(this,e);let t=[];for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}getRowVector(e){return l0.rowVector(this.getRow(e))}setRow(e,t){ne(this,e),t=Br(this,t);for(let r=0;r<this.columns;r++)this.set(e,r,t[r]);return this}swapRows(e,t){ne(this,e),ne(this,t);for(let r=0;r<this.columns;r++){let o=this.get(e,r);this.set(e,r,this.get(t,r)),this.set(t,r,o)}return this}getColumn(e){be(this,e);let t=[];for(let r=0;r<this.rows;r++)t.push(this.get(r,e));return t}getColumnVector(e){return l0.columnVector(this.getColumn(e))}setColumn(e,t){be(this,e),t=wr(this,t);for(let r=0;r<this.rows;r++)this.set(r,e,t[r]);return this}swapColumns(e,t){be(this,e),be(this,t);for(let r=0;r<this.rows;r++){let o=this.get(r,e);this.set(r,e,this.get(r,t)),this.set(r,t,o)}return this}addRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[r]);return this}subRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[r]);return this}mulRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[r]);return this}divRowVector(e){e=Br(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[r]);return this}addColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[t]);return this}subColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[t]);return this}mulColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[t]);return this}divColumnVector(e){e=wr(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[t]);return this}mulRow(e,t){ne(this,e);for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this}mulColumn(e,t){be(this,e);for(let r=0;r<this.rows;r++)this.set(r,e,this.get(r,e)*t);return this}max(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t[r]&&(t[r]=this.get(r,o));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t[o]&&(t[o]=this.get(r,o));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>t&&(t=this.get(r,o));return t}default:throw new Error(`invalid option: ${e}`)}}maxIndex(){Dr(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)>e&&(e=this.get(r,o),t[0]=r,t[1]=o);return t}min(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t[r]&&(t[r]=this.get(r,o));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t[o]&&(t[o]=this.get(r,o));return t}case void 0:{let t=this.get(0,0);for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<t&&(t=this.get(r,o));return t}default:throw new Error(`invalid option: ${e}`)}}minIndex(){Dr(this);let e=this.get(0,0),t=[0,0];for(let r=0;r<this.rows;r++)for(let o=0;o<this.columns;o++)this.get(r,o)<e&&(e=this.get(r,o),t[0]=r,t[1]=o);return t}maxRow(e){if(ne(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxRowIndex(e){ne(this,e),Dr(this);let t=this.get(e,0),r=[e,0];for(let o=1;o<this.columns;o++)this.get(e,o)>t&&(t=this.get(e,o),r[1]=o);return r}minRow(e){if(ne(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minRowIndex(e){ne(this,e),Dr(this);let t=this.get(e,0),r=[e,0];for(let o=1;o<this.columns;o++)this.get(e,o)<t&&(t=this.get(e,o),r[1]=o);return r}maxColumn(e){if(be(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)>t&&(t=this.get(r,e));return t}maxColumnIndex(e){be(this,e),Dr(this);let t=this.get(0,e),r=[0,e];for(let o=1;o<this.rows;o++)this.get(o,e)>t&&(t=this.get(o,e),r[0]=o);return r}minColumn(e){if(be(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)<t&&(t=this.get(r,e));return t}minColumnIndex(e){be(this,e),Dr(this);let t=this.get(0,e),r=[0,e];for(let o=1;o<this.rows;o++)this.get(o,e)<t&&(t=this.get(o,e),r[0]=o);return r}diag(){let e=Math.min(this.rows,this.columns),t=[];for(let r=0;r<e;r++)t.push(this.get(r,r));return t}norm(e="frobenius"){switch(e){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${e}`)}}cumulativeSum(){let e=0;for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r),this.set(t,r,e);return this}dot(e){U0.isMatrix(e)&&(e=e.to1DArray());let t=this.to1DArray();if(t.length!==e.length)throw new RangeError("vectors do not have the same size");let r=0;for(let o=0;o<t.length;o++)r+=t[o]*e[o];return r}mmul(e){e=l0.checkMatrix(e);let t=this.rows,r=this.columns,o=e.columns,n=new l0(t,o),b=new Float64Array(r);for(let z=0;z<o;z++){for(let i=0;i<r;i++)b[i]=e.get(i,z);for(let i=0;i<t;i++){let s=0;for(let a=0;a<r;a++)s+=this.get(i,a)*b[a];n.set(i,z,s)}}return n}strassen2x2(e){e=l0.checkMatrix(e);let t=new l0(2,2);const r=this.get(0,0),o=e.get(0,0),n=this.get(0,1),b=e.get(0,1),z=this.get(1,0),i=e.get(1,0),s=this.get(1,1),a=e.get(1,1),O=(r+s)*(o+a),u=(z+s)*o,l=r*(b-a),d=s*(i-o),A=(r+n)*a,h=(z-r)*(o+b),q=(n-s)*(i+a),_=O+d-A+q,m=l+A,L=u+d,g=O-u+l+h;return t.set(0,0,_),t.set(0,1,m),t.set(1,0,L),t.set(1,1,g),t}strassen3x3(e){e=l0.checkMatrix(e);let t=new l0(3,3);const r=this.get(0,0),o=this.get(0,1),n=this.get(0,2),b=this.get(1,0),z=this.get(1,1),i=this.get(1,2),s=this.get(2,0),a=this.get(2,1),O=this.get(2,2),u=e.get(0,0),l=e.get(0,1),d=e.get(0,2),A=e.get(1,0),h=e.get(1,1),q=e.get(1,2),_=e.get(2,0),m=e.get(2,1),L=e.get(2,2),g=(r+o+n-b-z-a-O)*h,v=(r-b)*(-l+h),y=z*(-u+l+A-h-q-_+L),X=(-r+b+z)*(u-l+h),T=(b+z)*(-u+l),N=r*u,D=(-r+s+a)*(u-d+q),C=(-r+s)*(d-q),P=(s+a)*(-u+d),H=(r+o+n-z-i-s-a)*q,G=a*(-u+d+A-h-q-_+m),k=(-n+a+O)*(h+_-m),J=(n-O)*(h-m),o0=n*_,z0=(a+O)*(-_+m),a0=(-n+z+i)*(q+_-L),v0=(n-i)*(q-L),w0=(z+i)*(-_+L),u0=o*A,I0=i*m,S0=b*d,F0=s*l,W0=O*L,b1=N+o0+u0,J0=g+X+T+N+k+o0+z0,p1=N+D+P+H+o0+a0+w0,Z1=v+y+X+N+o0+a0+v0,d1=v+X+T+N+I0,F=o0+a0+v0+w0+S0,K=N+D+C+G+k+J+o0,Z=k+J+o0+z0+F0,O0=N+D+C+P+W0;return t.set(0,0,b1),t.set(0,1,J0),t.set(0,2,p1),t.set(1,0,Z1),t.set(1,1,d1),t.set(1,2,F),t.set(2,0,K),t.set(2,1,Z),t.set(2,2,O0),t}mmulStrassen(e){e=l0.checkMatrix(e);let t=this.clone(),r=t.rows,o=t.columns,n=e.rows,b=e.columns;o!==n&&console.warn(`Multiplying ${r} x ${o} and ${n} x ${b} matrix: dimensions do not match.`);function z(O,u,l){let d=O.rows,A=O.columns;if(d===u&&A===l)return O;{let h=U0.zeros(u,l);return h=h.setSubMatrix(O,0,0),h}}let i=Math.max(r,n),s=Math.max(o,b);t=z(t,i,s),e=z(e,i,s);function a(O,u,l,d){if(l<=512||d<=512)return O.mmul(u);l%2===1&&d%2===1?(O=z(O,l+1,d+1),u=z(u,l+1,d+1)):l%2===1?(O=z(O,l+1,d),u=z(u,l+1,d)):d%2===1&&(O=z(O,l,d+1),u=z(u,l,d+1));let A=parseInt(O.rows/2,10),h=parseInt(O.columns/2,10),q=O.subMatrix(0,A-1,0,h-1),_=u.subMatrix(0,A-1,0,h-1),m=O.subMatrix(0,A-1,h,O.columns-1),L=u.subMatrix(0,A-1,h,u.columns-1),g=O.subMatrix(A,O.rows-1,0,h-1),v=u.subMatrix(A,u.rows-1,0,h-1),y=O.subMatrix(A,O.rows-1,h,O.columns-1),X=u.subMatrix(A,u.rows-1,h,u.columns-1),T=a(U0.add(q,y),U0.add(_,X),A,h),N=a(U0.add(g,y),_,A,h),D=a(q,U0.sub(L,X),A,h),C=a(y,U0.sub(v,_),A,h),P=a(U0.add(q,m),X,A,h),H=a(U0.sub(g,q),U0.add(_,L),A,h),G=a(U0.sub(m,y),U0.add(v,X),A,h),k=U0.add(T,C);k.sub(P),k.add(G);let J=U0.add(D,P),o0=U0.add(N,C),z0=U0.sub(T,N);z0.add(D),z0.add(H);let a0=U0.zeros(2*k.rows,2*k.columns);return a0=a0.setSubMatrix(k,0,0),a0=a0.setSubMatrix(J,k.rows,0),a0=a0.setSubMatrix(o0,0,k.columns),a0=a0.setSubMatrix(z0,k.rows,k.columns),a0.subMatrix(0,l-1,0,d-1)}return a(t,e,i,s)}scaleRows(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let o=new l0(this.rows,this.columns);for(let n=0;n<this.rows;n++){const b=this.getRow(n);b.length>0&&q3(b,{min:t,max:r,output:b}),o.setRow(n,b)}return o}scaleColumns(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let o=new l0(this.rows,this.columns);for(let n=0;n<this.columns;n++){const b=this.getColumn(n);b.length&&q3(b,{min:t,max:r,output:b}),o.setColumn(n,b)}return o}flipRows(){const e=Math.ceil(this.columns/2);for(let t=0;t<this.rows;t++)for(let r=0;r<e;r++){let o=this.get(t,r),n=this.get(t,this.columns-1-r);this.set(t,r,n),this.set(t,this.columns-1-r,o)}return this}flipColumns(){const e=Math.ceil(this.rows/2);for(let t=0;t<this.columns;t++)for(let r=0;r<e;r++){let o=this.get(r,t),n=this.get(this.rows-1-r,t);this.set(r,t,n),this.set(this.rows-1-r,t,o)}return this}kroneckerProduct(e){e=l0.checkMatrix(e);let t=this.rows,r=this.columns,o=e.rows,n=e.columns,b=new l0(t*o,r*n);for(let z=0;z<t;z++)for(let i=0;i<r;i++)for(let s=0;s<o;s++)for(let a=0;a<n;a++)b.set(o*z+s,n*i+a,this.get(z,i)*e.get(s,a));return b}kroneckerSum(e){if(e=l0.checkMatrix(e),!this.isSquare()||!e.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let t=this.rows,r=e.rows,o=this.kroneckerProduct(l0.eye(r,r)),n=l0.eye(t,t).kroneckerProduct(e);return o.add(n)}transpose(){let e=new l0(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.set(r,t,this.get(t,r));return e}sortRows(e=_3){for(let t=0;t<this.rows;t++)this.setRow(t,this.getRow(t).sort(e));return this}sortColumns(e=_3){for(let t=0;t<this.columns;t++)this.setColumn(t,this.getColumn(t).sort(e));return this}subMatrix(e,t,r,o){Op(this,e,t,r,o);let n=new l0(t-e+1,o-r+1);for(let b=e;b<=t;b++)for(let z=r;z<=o;z++)n.set(b-e,z-r,this.get(b,z));return n}subMatrixRow(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.columns-1),t>r||t<0||t>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let o=new l0(e.length,r-t+1);for(let n=0;n<e.length;n++)for(let b=t;b<=r;b++){if(e[n]<0||e[n]>=this.rows)throw new RangeError(`Row index out of range: ${e[n]}`);o.set(n,b-t,this.get(e[n],b))}return o}subMatrixColumn(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.rows-1),t>r||t<0||t>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let o=new l0(r-t+1,e.length);for(let n=0;n<e.length;n++)for(let b=t;b<=r;b++){if(e[n]<0||e[n]>=this.columns)throw new RangeError(`Column index out of range: ${e[n]}`);o.set(b-t,n,this.get(b,e[n]))}return o}setSubMatrix(e,t,r){if(e=l0.checkMatrix(e),e.isEmpty())return this;let o=t+e.rows-1,n=r+e.columns-1;Op(this,t,o,r,n);for(let b=0;b<e.rows;b++)for(let z=0;z<e.columns;z++)this.set(t+b,r+z,e.get(b,z));return this}selection(e,t){cp(this,e),sp(this,t);let r=new l0(e.length,t.length);for(let o=0;o<e.length;o++){let n=e[o];for(let b=0;b<t.length;b++){let z=t[b];r.set(o,b,this.get(n,z))}}return r}trace(){let e=Math.min(this.rows,this.columns),t=0;for(let r=0;r<e;r++)t+=this.get(r,r);return t}clone(){return this.constructor.copy(this,new l0(this.rows,this.columns))}static copy(e,t){for(const[r,o,n]of e.entries())t.set(r,o,n);return t}sum(e){switch(e){case"row":return N6(this);case"column":return y6(this);case void 0:return B6(this);default:throw new Error(`invalid option: ${e}`)}}product(e){switch(e){case"row":return w6(this);case"column":return D6(this);case void 0:return X6(this);default:throw new Error(`invalid option: ${e}`)}}mean(e){const t=this.sum(e);switch(e){case"row":{for(let r=0;r<this.rows;r++)t[r]/=this.columns;return t}case"column":{for(let r=0;r<this.columns;r++)t[r]/=this.rows;return t}case void 0:return t/this.size;default:throw new Error(`invalid option: ${e}`)}}variance(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:o=this.mean(e)}=t;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(e){case"row":{if(!C2.isAnyArray(o))throw new TypeError("mean must be an array");return E6(this,r,o)}case"column":{if(!C2.isAnyArray(o))throw new TypeError("mean must be an array");return T6(this,r,o)}case void 0:{if(typeof o!="number")throw new TypeError("mean must be a number");return C6(this,r,o)}default:throw new Error(`invalid option: ${e}`)}}standardDeviation(e,t){typeof e=="object"&&(t=e,e=void 0);const r=this.variance(e,t);if(e===void 0)return Math.sqrt(r);for(let o=0;o<r.length;o++)r[o]=Math.sqrt(r[o]);return r}center(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{center:r=this.mean(e)}=t;switch(e){case"row":{if(!C2.isAnyArray(r))throw new TypeError("center must be an array");return x6(this,r),this}case"column":{if(!C2.isAnyArray(r))throw new TypeError("center must be an array");return S6(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return F6(this,r),this}default:throw new Error(`invalid option: ${e}`)}}scale(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");let r=t.scale;switch(e){case"row":{if(r===void 0)r=I6(this);else if(!C2.isAnyArray(r))throw new TypeError("scale must be an array");return P6(this,r),this}case"column":{if(r===void 0)r=k6(this);else if(!C2.isAnyArray(r))throw new TypeError("scale must be an array");return $6(this,r),this}case void 0:{if(r===void 0)r=U6(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return j6(this,r),this}default:throw new Error(`invalid option: ${e}`)}}toString(e){return h3(this,e)}[Symbol.iterator](){return this.entries()}*entries(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield[e,t,this.get(e,t)]}*values(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield this.get(e,t)}}U0.prototype.klass="Matrix",typeof Symbol<"u"&&(U0.prototype[Symbol.for("nodejs.util.inspect.custom")]=g6);function _3(M,e){return M-e}function H6(M){return M.every(e=>typeof e=="number")}U0.random=U0.rand,U0.randomInt=U0.randInt,U0.diagonal=U0.diag,U0.prototype.diagonal=U0.prototype.diag,U0.identity=U0.eye,U0.prototype.negate=U0.prototype.neg,U0.prototype.tensorProduct=U0.prototype.kroneckerProduct;let l0=(Sr=class extends U0{constructor(t,r){super();ni(this,mM);E(this,"data");if(Sr.isMatrix(t))bi(this,mM,pi).call(this,t.rows,t.columns),Sr.copy(t,this);else if(Number.isInteger(t)&&t>=0)bi(this,mM,pi).call(this,t,r);else if(C2.isAnyArray(t)){const o=t;if(t=o.length,r=t?o[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(o[n].length!==r)throw new RangeError("Inconsistent array dimensions");if(!H6(o[n]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(o[n]))}this.rows=t,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(t,r,o){return this.data[t][r]=o,this}get(t,r){return this.data[t][r]}removeRow(t){return ne(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,r){return r===void 0&&(r=t,t=this.rows),ne(this,t,!0),r=Float64Array.from(Br(this,r)),this.data.splice(t,0,r),this.rows+=1,this}removeColumn(t){be(this,t);for(let r=0;r<this.rows;r++){const o=new Float64Array(this.columns-1);for(let n=0;n<t;n++)o[n]=this.data[r][n];for(let n=t+1;n<this.columns;n++)o[n-1]=this.data[r][n];this.data[r]=o}return this.columns-=1,this}addColumn(t,r){typeof r>"u"&&(r=t,t=this.columns),be(this,t,!0),r=wr(this,r);for(let o=0;o<this.rows;o++){const n=new Float64Array(this.columns+1);let b=0;for(;b<t;b++)n[b]=this.data[o][b];for(n[b++]=r[o];b<this.columns+1;b++)n[b]=this.data[o][b-1];this.data[o]=n}return this.columns+=1,this}},mM=new WeakSet,pi=function(t,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let o=0;o<t;o++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=t,this.columns=r},Sr);v6(U0,l0);const On=class On extends U0{constructor(t){super();ni(this,_2,void 0);if(l0.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");Mb(this,_2,l0.copy(t,new l0(t.rows,t.rows)))}else if(Number.isInteger(t)&&t>=0)Mb(this,_2,new l0(t,t));else if(Mb(this,_2,new l0(t)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return ye(this,_2).size}get rows(){return ye(this,_2).rows}get columns(){return ye(this,_2).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return l0.isMatrix(t)&&t.klassType==="SymmetricMatrix"}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}clone(){const t=new On(this.diagonalSize);for(const[r,o,n]of this.upperRightEntries())t.set(r,o,n);return t}toMatrix(){return new l0(this)}get(t,r){return ye(this,_2).get(t,r)}set(t,r,o){return ye(this,_2).set(t,r,o),ye(this,_2).set(r,t,o),this}removeCross(t){return ye(this,_2).removeRow(t),ye(this,_2).removeColumn(t),this}addCross(t,r){r===void 0&&(r=t,t=this.diagonalSize);const o=r.slice();return o.splice(t,1),ye(this,_2).addRow(t,o),ye(this,_2).addColumn(t,r),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[o,n]of t.entries())n||r.push(o);r.reverse();for(const o of r)this.removeCross(o);return this}toCompact(){const{diagonalSize:t}=this,r=new Array(t*(t+1)/2);for(let o=0,n=0,b=0;b<r.length;b++)r[b]=this.get(n,o),++o>=t&&(o=++n);return r}static fromCompact(t){const r=t.length,o=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(o))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const n=new On(o);for(let b=0,z=0,i=0;i<r;i++)n.set(b,z,t[i]),++b>=o&&(b=++z);return n}*upperRightEntries(){for(let t=0,r=0;t<this.diagonalSize;void 0){const o=this.get(t,r);yield[t,r,o],++r>=this.diagonalSize&&(r=++t)}}*upperRightValues(){for(let t=0,r=0;t<this.diagonalSize;void 0)yield this.get(t,r),++r>=this.diagonalSize&&(r=++t)}};_2=new WeakMap;let Yt=On;Yt.prototype.klassType="SymmetricMatrix";class jo extends Yt{static isDistanceMatrix(e){return Yt.isSymmetricMatrix(e)&&e.klassSubType==="DistanceMatrix"}constructor(e){if(super(e),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(e,t,r){return e===t&&(r=0),super.set(e,t,r)}addCross(e,t){return t===void 0&&(t=e,e=this.diagonalSize),t=t.slice(),t[e]=0,super.addCross(e,t)}toSymmetricMatrix(){return new Yt(this)}clone(){const e=new jo(this.diagonalSize);for(const[t,r,o]of this.upperRightEntries())t!==r&&e.set(t,r,o);return e}toCompact(){const{diagonalSize:e}=this,t=(e-1)*e/2,r=new Array(t);for(let o=1,n=0,b=0;b<r.length;b++)r[b]=this.get(n,o),++o>=e&&(o=++n+1);return r}static fromCompact(e){const t=e.length,r=(Math.sqrt(8*t+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(e)}`);const o=new this(r);for(let n=1,b=0,z=0;z<t;z++)o.set(n,b,e[z]),++n>=r&&(n=++b+1);return o}}jo.prototype.klassSubType="DistanceMatrix";class rt extends U0{constructor(e,t,r){super(),this.matrix=e,this.rows=t,this.columns=r}}class Y6 extends rt{constructor(e,t){be(e,t),super(e,e.rows,1),this.column=t}set(e,t,r){return this.matrix.set(e,this.column,r),this}get(e){return this.matrix.get(e,this.column)}}class G6 extends rt{constructor(e,t){sp(e,t),super(e,e.rows,t.length),this.columnIndices=t}set(e,t,r){return this.matrix.set(e,this.columnIndices[t],r),this}get(e,t){return this.matrix.get(e,this.columnIndices[t])}}class V6 extends rt{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(e,this.columns-t-1,r),this}get(e,t){return this.matrix.get(e,this.columns-t-1)}}class K6 extends rt{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(this.rows-e-1,t,r),this}get(e,t){return this.matrix.get(this.rows-e-1,t)}}class J6 extends rt{constructor(e,t){ne(e,t),super(e,1,e.columns),this.row=t}set(e,t,r){return this.matrix.set(this.row,t,r),this}get(e,t){return this.matrix.get(this.row,t)}}class Q6 extends rt{constructor(e,t){cp(e,t),super(e,t.length,e.columns),this.rowIndices=t}set(e,t,r){return this.matrix.set(this.rowIndices[e],t,r),this}get(e,t){return this.matrix.get(this.rowIndices[e],t)}}class Ho extends rt{constructor(e,t,r){cp(e,t),sp(e,r),super(e,t.length,r.length),this.rowIndices=t,this.columnIndices=r}set(e,t,r){return this.matrix.set(this.rowIndices[e],this.columnIndices[t],r),this}get(e,t){return this.matrix.get(this.rowIndices[e],this.columnIndices[t])}}class Z6 extends rt{constructor(e,t,r,o,n){Op(e,t,r,o,n),super(e,r-t+1,n-o+1),this.startRow=t,this.startColumn=o}set(e,t,r){return this.matrix.set(this.startRow+e,this.startColumn+t,r),this}get(e,t){return this.matrix.get(this.startRow+e,this.startColumn+t)}}class e_ extends rt{constructor(e){super(e,e.columns,e.rows)}set(e,t,r){return this.matrix.set(t,e,r),this}get(e,t){return this.matrix.get(t,e)}}class m3 extends U0{constructor(e,t={}){const{rows:r=1}=t;if(e.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=e.length/r,this.data=e}set(e,t,r){let o=this._calculateIndex(e,t);return this.data[o]=r,this}get(e,t){let r=this._calculateIndex(e,t);return this.data[r]}_calculateIndex(e,t){return e*this.columns+t}}class j2 extends U0{constructor(e){super(),this.data=e,this.rows=e.length,this.columns=e[0].length}set(e,t,r){return this.data[e][t]=r,this}get(e,t){return this.data[e][t]}}function t_(M,e){if(C2.isAnyArray(M))return M[0]&&C2.isAnyArray(M[0])?new j2(M):new m3(M,e);throw new Error("the argument is not an array")}class Yo{constructor(e){e=j2.checkMatrix(e);let t=e.clone(),r=t.rows,o=t.columns,n=new Float64Array(r),b=1,z,i,s,a,O,u,l,d,A;for(z=0;z<r;z++)n[z]=z;for(d=new Float64Array(r),i=0;i<o;i++){for(z=0;z<r;z++)d[z]=t.get(z,i);for(z=0;z<r;z++){for(A=Math.min(z,i),O=0,s=0;s<A;s++)O+=t.get(z,s)*d[s];d[z]-=O,t.set(z,i,d[z])}for(a=i,z=i+1;z<r;z++)Math.abs(d[z])>Math.abs(d[a])&&(a=z);if(a!==i){for(s=0;s<o;s++)u=t.get(a,s),t.set(a,s,t.get(i,s)),t.set(i,s,u);l=n[a],n[a]=n[i],n[i]=l,b=-b}if(i<r&&t.get(i,i)!==0)for(z=i+1;z<r;z++)t.set(z,i,t.get(z,i)/t.get(i,i))}this.LU=t,this.pivotVector=n,this.pivotSign=b}isSingular(){let e=this.LU,t=e.columns;for(let r=0;r<t;r++)if(e.get(r,r)===0)return!0;return!1}solve(e){e=l0.checkMatrix(e);let t=this.LU;if(t.rows!==e.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let o=e.columns,n=e.subMatrixRow(this.pivotVector,0,o-1),b=t.columns,z,i,s;for(s=0;s<b;s++)for(z=s+1;z<b;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s));for(s=b-1;s>=0;s--){for(i=0;i<o;i++)n.set(s,i,n.get(s,i)/t.get(s,s));for(z=0;z<s;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s))}return n}get determinant(){let e=this.LU;if(!e.isSquare())throw new Error("Matrix must be square");let t=this.pivotSign,r=e.columns;for(let o=0;o<r;o++)t*=e.get(o,o);return t}get lowerTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,o=new l0(t,r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)n>b?o.set(n,b,e.get(n,b)):n===b?o.set(n,b,1):o.set(n,b,0);return o}get upperTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,o=new l0(t,r);for(let n=0;n<t;n++)for(let b=0;b<r;b++)n<=b?o.set(n,b,e.get(n,b)):o.set(n,b,0);return o}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Mt(M,e){let t=0;return Math.abs(M)>Math.abs(e)?(t=e/M,Math.abs(M)*Math.sqrt(1+t*t)):e!==0?(t=M/e,Math.abs(e)*Math.sqrt(1+t*t)):0}class ap{constructor(e){e=j2.checkMatrix(e);let t=e.clone(),r=e.rows,o=e.columns,n=new Float64Array(o),b,z,i,s;for(i=0;i<o;i++){let a=0;for(b=i;b<r;b++)a=Mt(a,t.get(b,i));if(a!==0){for(t.get(i,i)<0&&(a=-a),b=i;b<r;b++)t.set(b,i,t.get(b,i)/a);for(t.set(i,i,t.get(i,i)+1),z=i+1;z<o;z++){for(s=0,b=i;b<r;b++)s+=t.get(b,i)*t.get(b,z);for(s=-s/t.get(i,i),b=i;b<r;b++)t.set(b,z,t.get(b,z)+s*t.get(b,i))}}n[i]=-a}this.QR=t,this.Rdiag=n}solve(e){e=l0.checkMatrix(e);let t=this.QR,r=t.rows;if(e.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let o=e.columns,n=e.clone(),b=t.columns,z,i,s,a;for(s=0;s<b;s++)for(i=0;i<o;i++){for(a=0,z=s;z<r;z++)a+=t.get(z,s)*n.get(z,i);for(a=-a/t.get(s,s),z=s;z<r;z++)n.set(z,i,n.get(z,i)+a*t.get(z,s))}for(s=b-1;s>=0;s--){for(i=0;i<o;i++)n.set(s,i,n.get(s,i)/this.Rdiag[s]);for(z=0;z<s;z++)for(i=0;i<o;i++)n.set(z,i,n.get(z,i)-n.get(s,i)*t.get(z,s))}return n.subMatrix(0,b-1,0,o-1)}isFullRank(){let e=this.QR.columns;for(let t=0;t<e;t++)if(this.Rdiag[t]===0)return!1;return!0}get upperTriangularMatrix(){let e=this.QR,t=e.columns,r=new l0(t,t),o,n;for(o=0;o<t;o++)for(n=0;n<t;n++)o<n?r.set(o,n,e.get(o,n)):o===n?r.set(o,n,this.Rdiag[o]):r.set(o,n,0);return r}get orthogonalMatrix(){let e=this.QR,t=e.rows,r=e.columns,o=new l0(t,r),n,b,z,i;for(z=r-1;z>=0;z--){for(n=0;n<t;n++)o.set(n,z,0);for(o.set(z,z,1),b=z;b<r;b++)if(e.get(z,z)!==0){for(i=0,n=z;n<t;n++)i+=e.get(n,z)*o.get(n,b);for(i=-i/e.get(z,z),n=z;n<t;n++)o.set(n,b,o.get(n,b)+i*e.get(n,z))}}return o}}class Xr{constructor(e,t={}){if(e=j2.checkMatrix(e),e.isEmpty())throw new Error("Matrix must be non-empty");let r=e.rows,o=e.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:b=!0,autoTranspose:z=!1}=t;let i=!!n,s=!!b,a=!1,O;if(r<o)if(!z)O=e.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{O=e.transpose(),r=O.rows,o=O.columns,a=!0;let N=i;i=s,s=N}else O=e.clone();let u=Math.min(r,o),l=Math.min(r+1,o),d=new Float64Array(l),A=new l0(r,u),h=new l0(o,o),q=new Float64Array(o),_=new Float64Array(r),m=new Float64Array(l);for(let N=0;N<l;N++)m[N]=N;let L=Math.min(r-1,o),g=Math.max(0,Math.min(o-2,r)),v=Math.max(L,g);for(let N=0;N<v;N++){if(N<L){d[N]=0;for(let D=N;D<r;D++)d[N]=Mt(d[N],O.get(D,N));if(d[N]!==0){O.get(N,N)<0&&(d[N]=-d[N]);for(let D=N;D<r;D++)O.set(D,N,O.get(D,N)/d[N]);O.set(N,N,O.get(N,N)+1)}d[N]=-d[N]}for(let D=N+1;D<o;D++){if(N<L&&d[N]!==0){let C=0;for(let P=N;P<r;P++)C+=O.get(P,N)*O.get(P,D);C=-C/O.get(N,N);for(let P=N;P<r;P++)O.set(P,D,O.get(P,D)+C*O.get(P,N))}q[D]=O.get(N,D)}if(i&&N<L)for(let D=N;D<r;D++)A.set(D,N,O.get(D,N));if(N<g){q[N]=0;for(let D=N+1;D<o;D++)q[N]=Mt(q[N],q[D]);if(q[N]!==0){q[N+1]<0&&(q[N]=0-q[N]);for(let D=N+1;D<o;D++)q[D]/=q[N];q[N+1]+=1}if(q[N]=-q[N],N+1<r&&q[N]!==0){for(let D=N+1;D<r;D++)_[D]=0;for(let D=N+1;D<r;D++)for(let C=N+1;C<o;C++)_[D]+=q[C]*O.get(D,C);for(let D=N+1;D<o;D++){let C=-q[D]/q[N+1];for(let P=N+1;P<r;P++)O.set(P,D,O.get(P,D)+C*_[P])}}if(s)for(let D=N+1;D<o;D++)h.set(D,N,q[D])}}let y=Math.min(o,r+1);if(L<o&&(d[L]=O.get(L,L)),r<y&&(d[y-1]=0),g+1<y&&(q[g]=O.get(g,y-1)),q[y-1]=0,i){for(let N=L;N<u;N++){for(let D=0;D<r;D++)A.set(D,N,0);A.set(N,N,1)}for(let N=L-1;N>=0;N--)if(d[N]!==0){for(let D=N+1;D<u;D++){let C=0;for(let P=N;P<r;P++)C+=A.get(P,N)*A.get(P,D);C=-C/A.get(N,N);for(let P=N;P<r;P++)A.set(P,D,A.get(P,D)+C*A.get(P,N))}for(let D=N;D<r;D++)A.set(D,N,-A.get(D,N));A.set(N,N,1+A.get(N,N));for(let D=0;D<N-1;D++)A.set(D,N,0)}else{for(let D=0;D<r;D++)A.set(D,N,0);A.set(N,N,1)}}if(s)for(let N=o-1;N>=0;N--){if(N<g&&q[N]!==0)for(let D=N+1;D<o;D++){let C=0;for(let P=N+1;P<o;P++)C+=h.get(P,N)*h.get(P,D);C=-C/h.get(N+1,N);for(let P=N+1;P<o;P++)h.set(P,D,h.get(P,D)+C*h.get(P,N))}for(let D=0;D<o;D++)h.set(D,N,0);h.set(N,N,1)}let X=y-1,T=Number.EPSILON;for(;y>0;){let N,D;for(N=y-2;N>=-1&&N!==-1;N--){const C=Number.MIN_VALUE+T*Math.abs(d[N]+Math.abs(d[N+1]));if(Math.abs(q[N])<=C||Number.isNaN(q[N])){q[N]=0;break}}if(N===y-2)D=4;else{let C;for(C=y-1;C>=N&&C!==N;C--){let P=(C!==y?Math.abs(q[C]):0)+(C!==N+1?Math.abs(q[C-1]):0);if(Math.abs(d[C])<=T*P){d[C]=0;break}}C===N?D=3:C===y-1?D=1:(D=2,N=C)}switch(N++,D){case 1:{let C=q[y-2];q[y-2]=0;for(let P=y-2;P>=N;P--){let H=Mt(d[P],C),G=d[P]/H,k=C/H;if(d[P]=H,P!==N&&(C=-k*q[P-1],q[P-1]=G*q[P-1]),s)for(let J=0;J<o;J++)H=G*h.get(J,P)+k*h.get(J,y-1),h.set(J,y-1,-k*h.get(J,P)+G*h.get(J,y-1)),h.set(J,P,H)}break}case 2:{let C=q[N-1];q[N-1]=0;for(let P=N;P<y;P++){let H=Mt(d[P],C),G=d[P]/H,k=C/H;if(d[P]=H,C=-k*q[P],q[P]=G*q[P],i)for(let J=0;J<r;J++)H=G*A.get(J,P)+k*A.get(J,N-1),A.set(J,N-1,-k*A.get(J,P)+G*A.get(J,N-1)),A.set(J,P,H)}break}case 3:{const C=Math.max(Math.abs(d[y-1]),Math.abs(d[y-2]),Math.abs(q[y-2]),Math.abs(d[N]),Math.abs(q[N])),P=d[y-1]/C,H=d[y-2]/C,G=q[y-2]/C,k=d[N]/C,J=q[N]/C,o0=((H+P)*(H-P)+G*G)/2,z0=P*G*(P*G);let a0=0;(o0!==0||z0!==0)&&(o0<0?a0=0-Math.sqrt(o0*o0+z0):a0=Math.sqrt(o0*o0+z0),a0=z0/(o0+a0));let v0=(k+P)*(k-P)+a0,w0=k*J;for(let u0=N;u0<y-1;u0++){let I0=Mt(v0,w0);I0===0&&(I0=Number.MIN_VALUE);let S0=v0/I0,F0=w0/I0;if(u0!==N&&(q[u0-1]=I0),v0=S0*d[u0]+F0*q[u0],q[u0]=S0*q[u0]-F0*d[u0],w0=F0*d[u0+1],d[u0+1]=S0*d[u0+1],s)for(let W0=0;W0<o;W0++)I0=S0*h.get(W0,u0)+F0*h.get(W0,u0+1),h.set(W0,u0+1,-F0*h.get(W0,u0)+S0*h.get(W0,u0+1)),h.set(W0,u0,I0);if(I0=Mt(v0,w0),I0===0&&(I0=Number.MIN_VALUE),S0=v0/I0,F0=w0/I0,d[u0]=I0,v0=S0*q[u0]+F0*d[u0+1],d[u0+1]=-F0*q[u0]+S0*d[u0+1],w0=F0*q[u0+1],q[u0+1]=S0*q[u0+1],i&&u0<r-1)for(let W0=0;W0<r;W0++)I0=S0*A.get(W0,u0)+F0*A.get(W0,u0+1),A.set(W0,u0+1,-F0*A.get(W0,u0)+S0*A.get(W0,u0+1)),A.set(W0,u0,I0)}q[y-2]=v0;break}case 4:{if(d[N]<=0&&(d[N]=d[N]<0?-d[N]:0,s))for(let C=0;C<=X;C++)h.set(C,N,-h.get(C,N));for(;N<X&&!(d[N]>=d[N+1]);){let C=d[N];if(d[N]=d[N+1],d[N+1]=C,s&&N<o-1)for(let P=0;P<o;P++)C=h.get(P,N+1),h.set(P,N+1,h.get(P,N)),h.set(P,N,C);if(i&&N<r-1)for(let P=0;P<r;P++)C=A.get(P,N+1),A.set(P,N+1,A.get(P,N)),A.set(P,N,C);N++}y--;break}}}if(a){let N=h;h=A,A=N}this.m=r,this.n=o,this.s=d,this.U=A,this.V=h}solve(e){let t=e,r=this.threshold,o=this.s.length,n=l0.zeros(o,o);for(let u=0;u<o;u++)Math.abs(this.s[u])<=r?n.set(u,u,0):n.set(u,u,1/this.s[u]);let b=this.U,z=this.rightSingularVectors,i=z.mmul(n),s=z.rows,a=b.rows,O=l0.zeros(s,a);for(let u=0;u<s;u++)for(let l=0;l<a;l++){let d=0;for(let A=0;A<o;A++)d+=i.get(u,A)*b.get(l,A);O.set(u,l,d)}return O.mmul(t)}solveForDiagonal(e){return this.solve(l0.diag(e))}inverse(){let e=this.V,t=this.threshold,r=e.rows,o=e.columns,n=new l0(r,this.s.length);for(let a=0;a<r;a++)for(let O=0;O<o;O++)Math.abs(this.s[O])>t&&n.set(a,O,e.get(a,O)/this.s[O]);let b=this.U,z=b.rows,i=b.columns,s=new l0(r,z);for(let a=0;a<r;a++)for(let O=0;O<z;O++){let u=0;for(let l=0;l<i;l++)u+=n.get(a,l)*b.get(O,l);s.set(a,O,u)}return s}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let e=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,t=0,r=this.s;for(let o=0,n=r.length;o<n;o++)r[o]>e&&t++;return t}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return l0.diag(this.s)}}function r_(M,e=!1){return M=j2.checkMatrix(M),e?new Xr(M).inverse():g3(M,l0.eye(M.rows))}function g3(M,e,t=!1){return M=j2.checkMatrix(M),e=j2.checkMatrix(e),t?new Xr(M).solve(e):M.isSquare()?new Yo(M).solve(e):new ap(M).solve(e)}function Go(M){if(M=l0.checkMatrix(M),M.isSquare()){if(M.columns===0)return 1;let e,t,r,o;if(M.columns===2)return e=M.get(0,0),t=M.get(0,1),r=M.get(1,0),o=M.get(1,1),e*o-t*r;if(M.columns===3){let n,b,z;return n=new Ho(M,[1,2],[1,2]),b=new Ho(M,[1,2],[0,2]),z=new Ho(M,[1,2],[0,1]),e=M.get(0,0),t=M.get(0,1),r=M.get(0,2),e*Go(n)-t*Go(b)+r*Go(z)}else return new Yo(M).determinant}else throw Error("determinant can only be calculated for a square matrix")}function M_(M,e){let t=[];for(let r=0;r<M;r++)r!==e&&t.push(r);return t}function o_(M,e,t,r=1e-9,o=1e-9){if(M>o)return new Array(e.rows+1).fill(0);{let n=e.addRow(t,[0]);for(let b=0;b<n.rows;b++)Math.abs(n.get(b,0))<r&&n.set(b,0,0);return n.to1DArray()}}function n_(M,e={}){const{thresholdValue:t=1e-9,thresholdError:r=1e-9}=e;M=l0.checkMatrix(M);let o=M.rows,n=new l0(o,o);for(let b=0;b<o;b++){let z=l0.columnVector(M.getRow(b)),i=M.subMatrixRow(M_(o,b)).transpose(),a=new Xr(i).solve(z),O=l0.sub(z,i.mmul(a)).abs().max();n.setRow(b,o_(O,a,b,t,r))}return n}function b_(M,e=Number.EPSILON){if(M=l0.checkMatrix(M),M.isEmpty())return M.transpose();let t=new Xr(M,{autoTranspose:!0}),r=t.leftSingularVectors,o=t.rightSingularVectors,n=t.diagonal;for(let b=0;b<n.length;b++)Math.abs(n[b])>e?n[b]=1/n[b]:n[b]=0;return o.mmul(l0.diag(n).mmul(r.transpose()))}function p_(M,e=M,t={}){M=new l0(M);let r=!1;if(typeof e=="object"&&!l0.isMatrix(e)&&!C2.isAnyArray(e)?(t=e,e=M,r=!0):e=new l0(e),M.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0}=t;o&&(M=M.center("column"),r||(e=e.center("column")));const n=M.transpose().mmul(e);for(let b=0;b<n.rows;b++)for(let z=0;z<n.columns;z++)n.set(b,z,n.get(b,z)*(1/(M.rows-1)));return n}function z_(M,e=M,t={}){M=new l0(M);let r=!1;if(typeof e=="object"&&!l0.isMatrix(e)&&!C2.isAnyArray(e)?(t=e,e=M,r=!0):e=new l0(e),M.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0,scale:n=!0}=t;o&&(M.center("column"),r||e.center("column")),n&&(M.scale("column"),r||e.scale("column"));const b=M.standardDeviation("column",{unbiased:!0}),z=r?b:e.standardDeviation("column",{unbiased:!0}),i=M.transpose().mmul(e);for(let s=0;s<i.rows;s++)for(let a=0;a<i.columns;a++)i.set(s,a,i.get(s,a)*(1/(b[s]*z[a]))*(1/(M.rows-1)));return i}let R3=class{constructor(e,t={}){const{assumeSymmetric:r=!1}=t;if(e=j2.checkMatrix(e),!e.isSquare())throw new Error("Matrix is not a square matrix");if(e.isEmpty())throw new Error("Matrix must be non-empty");let o=e.columns,n=new l0(o,o),b=new Float64Array(o),z=new Float64Array(o),i=e,s,a,O=!1;if(r?O=!0:O=e.isSymmetric(),O){for(s=0;s<o;s++)for(a=0;a<o;a++)n.set(s,a,i.get(s,a));i_(o,z,b,n),c_(o,z,b,n)}else{let u=new l0(o,o),l=new Float64Array(o);for(a=0;a<o;a++)for(s=0;s<o;s++)u.set(s,a,i.get(s,a));s_(o,u,l,n),O_(o,z,b,n,u)}this.n=o,this.e=z,this.d=b,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let e=this.n,t=this.e,r=this.d,o=new l0(e,e),n,b;for(n=0;n<e;n++){for(b=0;b<e;b++)o.set(n,b,0);o.set(n,n,r[n]),t[n]>0?o.set(n,n+1,t[n]):t[n]<0&&o.set(n,n-1,t[n])}return o}};function i_(M,e,t,r){let o,n,b,z,i,s,a,O;for(i=0;i<M;i++)t[i]=r.get(M-1,i);for(z=M-1;z>0;z--){for(O=0,b=0,s=0;s<z;s++)O=O+Math.abs(t[s]);if(O===0)for(e[z]=t[z-1],i=0;i<z;i++)t[i]=r.get(z-1,i),r.set(z,i,0),r.set(i,z,0);else{for(s=0;s<z;s++)t[s]/=O,b+=t[s]*t[s];for(o=t[z-1],n=Math.sqrt(b),o>0&&(n=-n),e[z]=O*n,b=b-o*n,t[z-1]=o-n,i=0;i<z;i++)e[i]=0;for(i=0;i<z;i++){for(o=t[i],r.set(i,z,o),n=e[i]+r.get(i,i)*o,s=i+1;s<=z-1;s++)n+=r.get(s,i)*t[s],e[s]+=r.get(s,i)*o;e[i]=n}for(o=0,i=0;i<z;i++)e[i]/=b,o+=e[i]*t[i];for(a=o/(b+b),i=0;i<z;i++)e[i]-=a*t[i];for(i=0;i<z;i++){for(o=t[i],n=e[i],s=i;s<=z-1;s++)r.set(s,i,r.get(s,i)-(o*e[s]+n*t[s]));t[i]=r.get(z-1,i),r.set(z,i,0)}}t[z]=b}for(z=0;z<M-1;z++){if(r.set(M-1,z,r.get(z,z)),r.set(z,z,1),b=t[z+1],b!==0){for(s=0;s<=z;s++)t[s]=r.get(s,z+1)/b;for(i=0;i<=z;i++){for(n=0,s=0;s<=z;s++)n+=r.get(s,z+1)*r.get(s,i);for(s=0;s<=z;s++)r.set(s,i,r.get(s,i)-n*t[s])}}for(s=0;s<=z;s++)r.set(s,z+1,0)}for(i=0;i<M;i++)t[i]=r.get(M-1,i),r.set(M-1,i,0);r.set(M-1,M-1,1),e[0]=0}function c_(M,e,t,r){let o,n,b,z,i,s,a,O,u,l,d,A,h,q,_,m;for(b=1;b<M;b++)e[b-1]=e[b];e[M-1]=0;let L=0,g=0,v=Number.EPSILON;for(s=0;s<M;s++){for(g=Math.max(g,Math.abs(t[s])+Math.abs(e[s])),a=s;a<M&&!(Math.abs(e[a])<=v*g);)a++;if(a>s)do{for(o=t[s],O=(t[s+1]-o)/(2*e[s]),u=Mt(O,1),O<0&&(u=-u),t[s]=e[s]/(O+u),t[s+1]=e[s]*(O+u),l=t[s+1],n=o-t[s],b=s+2;b<M;b++)t[b]-=n;for(L=L+n,O=t[a],d=1,A=d,h=d,q=e[s+1],_=0,m=0,b=a-1;b>=s;b--)for(h=A,A=d,m=_,o=d*e[b],n=d*O,u=Mt(O,e[b]),e[b+1]=_*u,_=e[b]/u,d=O/u,O=d*t[b]-_*o,t[b+1]=n+_*(d*o+_*t[b]),i=0;i<M;i++)n=r.get(i,b+1),r.set(i,b+1,_*r.get(i,b)+d*n),r.set(i,b,d*r.get(i,b)-_*n);O=-_*m*h*q*e[s]/l,e[s]=_*O,t[s]=d*O}while(Math.abs(e[s])>v*g);t[s]=t[s]+L,e[s]=0}for(b=0;b<M-1;b++){for(i=b,O=t[b],z=b+1;z<M;z++)t[z]<O&&(i=z,O=t[z]);if(i!==b)for(t[i]=t[b],t[b]=O,z=0;z<M;z++)O=r.get(z,b),r.set(z,b,r.get(z,i)),r.set(z,i,O)}}function s_(M,e,t,r){let o=0,n=M-1,b,z,i,s,a,O,u;for(O=o+1;O<=n-1;O++){for(u=0,s=O;s<=n;s++)u=u+Math.abs(e.get(s,O-1));if(u!==0){for(i=0,s=n;s>=O;s--)t[s]=e.get(s,O-1)/u,i+=t[s]*t[s];for(z=Math.sqrt(i),t[O]>0&&(z=-z),i=i-t[O]*z,t[O]=t[O]-z,a=O;a<M;a++){for(b=0,s=n;s>=O;s--)b+=t[s]*e.get(s,a);for(b=b/i,s=O;s<=n;s++)e.set(s,a,e.get(s,a)-b*t[s])}for(s=0;s<=n;s++){for(b=0,a=n;a>=O;a--)b+=t[a]*e.get(s,a);for(b=b/i,a=O;a<=n;a++)e.set(s,a,e.get(s,a)-b*t[a])}t[O]=u*t[O],e.set(O,O-1,u*z)}}for(s=0;s<M;s++)for(a=0;a<M;a++)r.set(s,a,s===a?1:0);for(O=n-1;O>=o+1;O--)if(e.get(O,O-1)!==0){for(s=O+1;s<=n;s++)t[s]=e.get(s,O-1);for(a=O;a<=n;a++){for(z=0,s=O;s<=n;s++)z+=t[s]*r.get(s,a);for(z=z/t[O]/e.get(O,O-1),s=O;s<=n;s++)r.set(s,a,r.get(s,a)+z*t[s])}}}function O_(M,e,t,r,o){let n=M-1,b=0,z=M-1,i=Number.EPSILON,s=0,a=0,O=0,u=0,l=0,d=0,A=0,h=0,q,_,m,L,g,v,y,X,T,N,D,C,P,H,G;for(q=0;q<M;q++)for((q<b||q>z)&&(t[q]=o.get(q,q),e[q]=0),_=Math.max(q-1,0);_<M;_++)a=a+Math.abs(o.get(q,_));for(;n>=b;){for(L=n;L>b&&(d=Math.abs(o.get(L-1,L-1))+Math.abs(o.get(L,L)),d===0&&(d=a),!(Math.abs(o.get(L,L-1))<i*d));)L--;if(L===n)o.set(n,n,o.get(n,n)+s),t[n]=o.get(n,n),e[n]=0,n--,h=0;else if(L===n-1){if(y=o.get(n,n-1)*o.get(n-1,n),O=(o.get(n-1,n-1)-o.get(n,n))/2,u=O*O+y,A=Math.sqrt(Math.abs(u)),o.set(n,n,o.get(n,n)+s),o.set(n-1,n-1,o.get(n-1,n-1)+s),X=o.get(n,n),u>=0){for(A=O>=0?O+A:O-A,t[n-1]=X+A,t[n]=t[n-1],A!==0&&(t[n]=X-y/A),e[n-1]=0,e[n]=0,X=o.get(n,n-1),d=Math.abs(X)+Math.abs(A),O=X/d,u=A/d,l=Math.sqrt(O*O+u*u),O=O/l,u=u/l,_=n-1;_<M;_++)A=o.get(n-1,_),o.set(n-1,_,u*A+O*o.get(n,_)),o.set(n,_,u*o.get(n,_)-O*A);for(q=0;q<=n;q++)A=o.get(q,n-1),o.set(q,n-1,u*A+O*o.get(q,n)),o.set(q,n,u*o.get(q,n)-O*A);for(q=b;q<=z;q++)A=r.get(q,n-1),r.set(q,n-1,u*A+O*r.get(q,n)),r.set(q,n,u*r.get(q,n)-O*A)}else t[n-1]=X+O,t[n]=X+O,e[n-1]=A,e[n]=-A;n=n-2,h=0}else{if(X=o.get(n,n),T=0,y=0,L<n&&(T=o.get(n-1,n-1),y=o.get(n,n-1)*o.get(n-1,n)),h===10){for(s+=X,q=b;q<=n;q++)o.set(q,q,o.get(q,q)-X);d=Math.abs(o.get(n,n-1))+Math.abs(o.get(n-1,n-2)),X=T=.75*d,y=-.4375*d*d}if(h===30&&(d=(T-X)/2,d=d*d+y,d>0)){for(d=Math.sqrt(d),T<X&&(d=-d),d=X-y/((T-X)/2+d),q=b;q<=n;q++)o.set(q,q,o.get(q,q)-d);s+=d,X=T=y=.964}for(h=h+1,g=n-2;g>=L&&(A=o.get(g,g),l=X-A,d=T-A,O=(l*d-y)/o.get(g+1,g)+o.get(g,g+1),u=o.get(g+1,g+1)-A-l-d,l=o.get(g+2,g+1),d=Math.abs(O)+Math.abs(u)+Math.abs(l),O=O/d,u=u/d,l=l/d,!(g===L||Math.abs(o.get(g,g-1))*(Math.abs(u)+Math.abs(l))<i*(Math.abs(O)*(Math.abs(o.get(g-1,g-1))+Math.abs(A)+Math.abs(o.get(g+1,g+1))))));)g--;for(q=g+2;q<=n;q++)o.set(q,q-2,0),q>g+2&&o.set(q,q-3,0);for(m=g;m<=n-1&&(H=m!==n-1,m!==g&&(O=o.get(m,m-1),u=o.get(m+1,m-1),l=H?o.get(m+2,m-1):0,X=Math.abs(O)+Math.abs(u)+Math.abs(l),X!==0&&(O=O/X,u=u/X,l=l/X)),X!==0);m++)if(d=Math.sqrt(O*O+u*u+l*l),O<0&&(d=-d),d!==0){for(m!==g?o.set(m,m-1,-d*X):L!==g&&o.set(m,m-1,-o.get(m,m-1)),O=O+d,X=O/d,T=u/d,A=l/d,u=u/O,l=l/O,_=m;_<M;_++)O=o.get(m,_)+u*o.get(m+1,_),H&&(O=O+l*o.get(m+2,_),o.set(m+2,_,o.get(m+2,_)-O*A)),o.set(m,_,o.get(m,_)-O*X),o.set(m+1,_,o.get(m+1,_)-O*T);for(q=0;q<=Math.min(n,m+3);q++)O=X*o.get(q,m)+T*o.get(q,m+1),H&&(O=O+A*o.get(q,m+2),o.set(q,m+2,o.get(q,m+2)-O*l)),o.set(q,m,o.get(q,m)-O),o.set(q,m+1,o.get(q,m+1)-O*u);for(q=b;q<=z;q++)O=X*r.get(q,m)+T*r.get(q,m+1),H&&(O=O+A*r.get(q,m+2),r.set(q,m+2,r.get(q,m+2)-O*l)),r.set(q,m,r.get(q,m)-O),r.set(q,m+1,r.get(q,m+1)-O*u)}}}if(a!==0){for(n=M-1;n>=0;n--)if(O=t[n],u=e[n],u===0)for(L=n,o.set(n,n,1),q=n-1;q>=0;q--){for(y=o.get(q,q)-O,l=0,_=L;_<=n;_++)l=l+o.get(q,_)*o.get(_,n);if(e[q]<0)A=y,d=l;else if(L=q,e[q]===0?o.set(q,n,y!==0?-l/y:-l/(i*a)):(X=o.get(q,q+1),T=o.get(q+1,q),u=(t[q]-O)*(t[q]-O)+e[q]*e[q],v=(X*d-A*l)/u,o.set(q,n,v),o.set(q+1,n,Math.abs(X)>Math.abs(A)?(-l-y*v)/X:(-d-T*v)/A)),v=Math.abs(o.get(q,n)),i*v*v>1)for(_=q;_<=n;_++)o.set(_,n,o.get(_,n)/v)}else if(u<0)for(L=n-1,Math.abs(o.get(n,n-1))>Math.abs(o.get(n-1,n))?(o.set(n-1,n-1,u/o.get(n,n-1)),o.set(n-1,n,-(o.get(n,n)-O)/o.get(n,n-1))):(G=Vo(0,-o.get(n-1,n),o.get(n-1,n-1)-O,u),o.set(n-1,n-1,G[0]),o.set(n-1,n,G[1])),o.set(n,n-1,0),o.set(n,n,1),q=n-2;q>=0;q--){for(N=0,D=0,_=L;_<=n;_++)N=N+o.get(q,_)*o.get(_,n-1),D=D+o.get(q,_)*o.get(_,n);if(y=o.get(q,q)-O,e[q]<0)A=y,l=N,d=D;else if(L=q,e[q]===0?(G=Vo(-N,-D,y,u),o.set(q,n-1,G[0]),o.set(q,n,G[1])):(X=o.get(q,q+1),T=o.get(q+1,q),C=(t[q]-O)*(t[q]-O)+e[q]*e[q]-u*u,P=(t[q]-O)*2*u,C===0&&P===0&&(C=i*a*(Math.abs(y)+Math.abs(u)+Math.abs(X)+Math.abs(T)+Math.abs(A))),G=Vo(X*l-A*N+u*D,X*d-A*D-u*N,C,P),o.set(q,n-1,G[0]),o.set(q,n,G[1]),Math.abs(X)>Math.abs(A)+Math.abs(u)?(o.set(q+1,n-1,(-N-y*o.get(q,n-1)+u*o.get(q,n))/X),o.set(q+1,n,(-D-y*o.get(q,n)-u*o.get(q,n-1))/X)):(G=Vo(-l-T*o.get(q,n-1),-d-T*o.get(q,n),A,u),o.set(q+1,n-1,G[0]),o.set(q+1,n,G[1]))),v=Math.max(Math.abs(o.get(q,n-1)),Math.abs(o.get(q,n))),i*v*v>1)for(_=q;_<=n;_++)o.set(_,n-1,o.get(_,n-1)/v),o.set(_,n,o.get(_,n)/v)}for(q=0;q<M;q++)if(q<b||q>z)for(_=q;_<M;_++)r.set(q,_,o.get(q,_));for(_=M-1;_>=b;_--)for(q=b;q<=z;q++){for(A=0,m=b;m<=Math.min(_,z);m++)A=A+r.get(q,m)*o.get(m,_);r.set(q,_,A)}}}function Vo(M,e,t,r){let o,n;return Math.abs(t)>Math.abs(r)?(o=r/t,n=t+o*r,[(M+o*e)/n,(e-o*M)/n]):(o=t/r,n=r+o*t,[(o*M+e)/n,(o*e-M)/n])}class L3{constructor(e){if(e=j2.checkMatrix(e),!e.isSymmetric())throw new Error("Matrix is not symmetric");let t=e,r=t.rows,o=new l0(r,r),n=!0,b,z,i;for(z=0;z<r;z++){let s=0;for(i=0;i<z;i++){let a=0;for(b=0;b<i;b++)a+=o.get(i,b)*o.get(z,b);a=(t.get(z,i)-a)/o.get(i,i),o.set(z,i,a),s=s+a*a}for(s=t.get(z,z)-s,n&=s>0,o.set(z,z,Math.sqrt(Math.max(s,0))),i=z+1;i<r;i++)o.set(z,i,0)}this.L=o,this.positiveDefinite=!!n}isPositiveDefinite(){return this.positiveDefinite}solve(e){e=j2.checkMatrix(e);let t=this.L,r=t.rows;if(e.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let o=e.columns,n=e.clone(),b,z,i;for(i=0;i<r;i++)for(z=0;z<o;z++){for(b=0;b<i;b++)n.set(i,z,n.get(i,z)-n.get(b,z)*t.get(i,b));n.set(i,z,n.get(i,z)/t.get(i,i))}for(i=r-1;i>=0;i--)for(z=0;z<o;z++){for(b=i+1;b<r;b++)n.set(i,z,n.get(i,z)-n.get(b,z)*t.get(b,i));n.set(i,z,n.get(i,z)/t.get(i,i))}return n}get lowerTriangularMatrix(){return this.L}}class v3{constructor(e,t={}){e=j2.checkMatrix(e);let{Y:r}=t;const{scaleScores:o=!1,maxIterations:n=1e3,terminationCriteria:b=1e-10}=t;let z;if(r){if(C2.isAnyArray(r)&&typeof r[0]=="number"?r=l0.columnVector(r):r=j2.checkMatrix(r),r.rows!==e.rows)throw new Error("Y should have the same number of rows as X");z=r.getColumnVector(0)}else z=e.getColumnVector(0);let i=1,s,a,O,u;for(let l=0;l<n&&i>b;l++)O=e.transpose().mmul(z).div(z.transpose().mmul(z).get(0,0)),O=O.div(O.norm()),s=e.mmul(O).div(O.transpose().mmul(O).get(0,0)),l>0&&(i=s.clone().sub(u).pow(2).sum()),u=s.clone(),r?(a=r.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0)),a=a.div(a.norm()),z=r.mmul(a).div(a.transpose().mmul(a).get(0,0))):z=s;if(r){let l=e.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0));l=l.div(l.norm());let d=e.clone().sub(s.clone().mmul(l.transpose())),A=z.transpose().mmul(s).div(s.transpose().mmul(s).get(0,0)),h=r.clone().sub(s.clone().mulS(A.get(0,0)).mmul(a.transpose()));this.t=s,this.p=l.transpose(),this.w=O.transpose(),this.q=a,this.u=z,this.s=s.transpose().mmul(s),this.xResidual=d,this.yResidual=h,this.betas=A}else this.w=O.transpose(),this.s=s.transpose().mmul(s).sqrt(),o?this.t=s.clone().div(this.s.get(0,0)):this.t=s,this.xResidual=e.sub(s.mmul(O.transpose()))}}Z0.AbstractMatrix=U0,Z0.CHO=L3,Z0.CholeskyDecomposition=L3,Z0.DistanceMatrix=jo,Z0.EVD=R3;var a_=Z0.EigenvalueDecomposition=R3;Z0.LU=Yo,Z0.LuDecomposition=Yo;var N3=Z0.Matrix=l0;Z0.MatrixColumnSelectionView=G6,Z0.MatrixColumnView=Y6,Z0.MatrixFlipColumnView=V6,Z0.MatrixFlipRowView=K6,Z0.MatrixRowSelectionView=Q6,Z0.MatrixRowView=J6,Z0.MatrixSelectionView=Ho,Z0.MatrixSubView=Z6,Z0.MatrixTransposeView=e_,Z0.NIPALS=v3,Z0.Nipals=v3,Z0.QR=ap,Z0.QrDecomposition=ap,Z0.SVD=Xr,Z0.SingularValueDecomposition=Xr,Z0.SymmetricMatrix=Yt,Z0.WrapperMatrix1D=m3,Z0.WrapperMatrix2D=j2,Z0.correlation=z_,Z0.covariance=p_;var y3=Z0.default=l0;Z0.determinant=Go,Z0.inverse=r_,Z0.linearDependencies=n_,Z0.pseudoInverse=b_,Z0.solve=g3,Z0.wrap=t_;const B3=a_,w3=N3;y3.Matrix&&y3.Matrix;class u_{constructor(e){E(this,"_errorListener");this._errorListener=e}new({rows:e,columns:t,initial_value:r}={}){return new up(e,t,r,this._errorListener)}avg({id:e}){return e==null?void 0:e.avg()}col({id:e,column:t}){return e==null?void 0:e.col({column:t})}det({id:e}){return e==null?void 0:e.det()}get({id:e,row:t,column:r}){return e==null?void 0:e.get({row:t,column:r})}inv({id:e}){return e==null?void 0:e.inv()}max({id:e}){return e==null?void 0:e.max()}min({id:e}){return e==null?void 0:e.min()}pow({id:e,power:t}){return e==null?void 0:e.pow({power:t})}row({id:e,row:t}){return e==null?void 0:e.row({row:t})}set({id:e,row:t,column:r,value:o}){e==null||e.set({row:t,column:r,value:o})}sum({id1:e,id2:t}){return e==null?void 0:e.sum({id2:t})}copy({id:e}){return e==null?void 0:e.copy()}diff({id1:e,id2:t}){return e==null?void 0:e.diff({id2:t})}rows({id:e}){return e==null?void 0:e.rows()}columns({id:e}){return e==null?void 0:e.columns()}fill({id:e,value:t,from_row:r,to_row:o,from_column:n,to_column:b}){e==null||e.fill({value:t,from_row:r,to_row:o,from_column:n,to_column:b})}kron({id1:e,id2:t}){return e==null?void 0:e.kron({id2:t})}mode({id:e}){return e==null?void 0:e.mode()}mult({id1:e,id2:t}){return e==null?void 0:e.mult({id2:t})}pinv({id:e}){return e==null?void 0:e.pinv()}rank({id:e}){return e==null?void 0:e.rank()}sort({id:e,column:t,order:r}){e==null||e.sort({column:t,order:r})}trace({id:e}){return e==null?void 0:e.trace()}concat({id1:e,id2:t}){return e==null?void 0:e.concat({id2:t})}median({id:e}){return e==null?void 0:e.median()}add_col({id:e,column:t,array_id:r}){e==null||e.add_col({column:t,array_id:r})}add_row({id:e,row:t,array_id:r}){e==null||e.add_row({row:t,array_id:r})}is_zero({id:e}){return e==null?void 0:e.is_zero()}reshape({id:e,rows:t,columns:r},o){return e==null?void 0:e.reshape({rows:t,columns:r},o)}reverse({id:e}){e==null||e.reverse()}is_binary({id:e}){return e==null?void 0:e.is_binary()}is_square({id:e}){return e==null?void 0:e.is_square()}submatrix({id:e,from_row:t,to_row:r,from_column:o,to_column:n}){return e==null?void 0:e.submatrix({from_row:t,to_row:r,from_column:o,to_column:n})}swap_rows({id:e,row1:t,row2:r}){e==null||e.swap_rows({row1:t,row2:r})}transpose({id:e}){return e==null?void 0:e.transpose()}remove_col({id:e,column:t}){return e==null?void 0:e.remove_col({column:t})}remove_row({id:e,row:t}){return e==null?void 0:e.remove_row({row:t})}eigenvalues({id:e}){return e==null?void 0:e.eigenvalues()}is_diagonal({id:e}){return e==null?void 0:e.is_diagonal()}is_identity({id:e}){return e==null?void 0:e.is_identity()}eigenvectors({id:e}){return e==null?void 0:e.eigenvectors()}is_symmetric({id:e}){return e==null?void 0:e.is_symmetric()}swap_columns({id:e,column1:t,column2:r}){e==null||e.swap_columns({column1:t,column2:r})}is_stochastic({id:e}){return e==null?void 0:e.is_stochastic()}is_triangular({id:e}){return e==null?void 0:e.is_triangular()}elements_count({id:e}){return e==null?void 0:e.elements_count()}is_antidiagonal({id:e}){return e==null?void 0:e.is_antidiagonal()}is_antisymmetric({id:e}){return e==null?void 0:e.is_antisymmetric()}}class up{constructor(e=0,t=0,r=void 0,o){E(this,"_matrixInstance");E(this,"_errorListener");this._matrixInstance=this._createMatrix(e,t,r),this._errorListener=o}get _matrixArray(){return this._matrixInstance.map(e=>[...e._value])}get _value(){return this._matrixInstance}set _value(e){this._matrixInstance=e}get isMatrix(){return!0}_createMatrix(e,t,r){return Array.from(new Array(e),()=>new n1(t,r,this._errorListener))}avg(){let e=0,t=0;for(const o of this._matrixInstance)for(const n of o._value)e+=d0(n)?0:n,t+=1;return e/t}col({column:e}){const t=[],r=new n1(0,void 0,this._errorListener);if(d0(e))return r;for(const o of this._matrixInstance)t.push(o._value[e]);return r._value=t,r}det(){return f3(this._matrixArray)}get({row:e,column:t}){var r,o;if(!(d0(e)||d0(t)))return(o=(r=this._matrixInstance[e])==null?void 0:r._value)==null?void 0:o[t]}inv(){const e=Po(this._matrixArray);return this._newMatrix(e)}max(){return i6(this._matrixArray)}min(){return ip(this._matrixArray)}pow({power:e}){const t=d0(e)?this._matrixArray:s6(this._matrixArray,e);return this._newMatrix(t)}row({row:e}){return d0(e)?new n1(0,void 0,this._errorListener):this._matrixInstance[e]}set({row:e,column:t,value:r}){d0(e)||d0(t)||this._matrixInstance[e].set({index:t,value:r})}sum({id2:e}){const t=dM(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:e}){const t=M6(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:e,from_row:t,to_row:r,from_column:o,to_column:n}={}){d0(t)&&(t=0),d0(r)&&(r=this.rows()),d0(o)&&(o=0),d0(n)&&(n=this.columns());let b=t||0;for(;b<(r||0);){let z=this._matrixInstance[b];z||(z=new n1(0,e,this._errorListener),this._matrixInstance[b]=z),z.fill({value:e,index_from:o,index_to:n}),b++}}kron({id2:e}){const t=t6(this._matrixArray,e._matrixArray);return this._newMatrix(t)}mode(){return ip(i3(this._matrixArray))}mult({id2:e}){const t=typeof e=="number"?e:e._matrixArray?e._matrixArray:e._value,r=yr(this._matrixArray,t);return this._newMatrix(r)}pinv(){const e=c6(this._matrixArray);return this._newMatrix(e)}rank(){return this._matrixRank(this._matrixArray)}sort({column:e,order:t=$e.ascending}={}){d0(e)&&(e=0),this._matrixInstance.sort((r,o)=>{const n=r._value[e],b=o._value[e];return t!==$e.descending?n-b:b-n})}trace(){return z6(this._matrixArray)}concat({id2:e}){for(const t of e._value)this._matrixInstance.push(t);return this}median(){return l3(this._matrixArray)}add_col({column:e,array_id:t}={}){d0(e)&&(e=this.columns());for(const[r,o]of this._matrixInstance.entries())o.insert({index:e,value:t?t._value[r]:void 0})}add_row({row:e,array_id:t}){d0(e)&&(e=this.rows()),this._matrixInstance.splice(e,0,t||new n1(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(e=>e.every(t=>t===0))}reshape({rows:e=0,columns:t=0},r){if(e*t!==this.columns()*this.rows()){this._errorListener.addError(l1.matrixRehapeErr,r,$0.Error);return}const o=JW(this._matrixArray,[e,t]);this._matrixInstance=o.map(n=>{const b=new n1(0,void 0,this._errorListener);return b._value=[...n],b})}reverse(){this._matrixInstance.reverse();for(const e of this._matrixInstance)e.reverse()}is_binary(){return this._matrixArray.every(e=>e.every(t=>t===0||t===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:e,to_row:t,from_column:r,to_column:o}={}){d0(e)&&(e=0),d0(t)&&(t=this.rows()),d0(r)&&(r=0),d0(o)&&(o=this.columns());const n=this._matrixArray.splice(e,t),b=[];for(const z of n)b.push(z.splice(r,o));return this._newMatrix(b)}swap_rows({row1:e,row2:t}){if(d0(e)||d0(t))return;const r=this._matrixInstance[e],o=this._matrixInstance[t];this._matrixInstance[e]=o,this._matrixInstance[t]=r}transpose(){const e=s3(this._matrixArray);return this._newMatrix(e)}remove_col({column:e}={}){d0(e)&&(e=this.columns());const t=[];for(const o of this._matrixInstance){const n=o._value.splice(e,1);t.push(n[0])}const r=new n1(0,void 0,this._errorListener);return r._value=t,r}remove_row({row:e}={}){return d0(e)&&(e=this.rows()),this._matrixInstance.splice(e,1)[0]}eigenvalues(){const e=new B3(new w3(this._matrixArray)),t=new n1(0,void 0,this._errorListener);return t._value=e.realEigenvalues,t}is_diagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<t;n++)if(o!==n&&r[o][n]!==0)return!1;return!0}is_identity(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<t;n++)if(o!==n&&r[o][n]!==0||o===n&&r[o][n]!==1)return!1;return!0}eigenvectors(){const e=new B3(new w3(this._matrixArray));return this._newMatrix(e.eigenvectorMatrix.to2DArray())}is_symmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=o+1;n<t;n++)if(r[o][n]!==r[n][o])return!1;return!0}swap_columns({column1:e,column2:t}){if(!(d0(e)||d0(t)))for(const r of this._matrixInstance){const o=r._value[e],n=r._value[t];r.set({index:e,value:n}),r.set({index:t,value:o})}}is_stochastic(){const e=this._matrixArray;for(let t=0;t<e.length;t++){let r=0;for(let o=0;o<e[t].length;o++){if(e[t][o]<0)return!1;r+=e[t][o]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const e=this.rows(),t=this.columns();return e!==t?!1:this._isUpperTriangular(e)||this._isLowerTriangular(e)}elements_count(){return QW(this._matrixArray)}is_antidiagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<e;n++)if(o+n!==e-1&&r[o][n]!==0)return!1;return!0}is_antisymmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let o=0;o<e;o++)for(let n=0;n<e;n++)if(o!==n&&r[o][n]!==-r[n][o])return!1;return!0}_isUpperTriangular(e){const t=this._matrixArray;for(let r=1;r<e;r++)for(let o=0;o<r;o++)if(t[r][o]!==0)return!1;return!0}_isLowerTriangular(e){const t=this._matrixArray;for(let r=0;r<e-1;r++)for(let o=r+1;o<e;o++)if(t[r][o]!==0)return!1;return!0}_newMatrix(e){const t=new up(0,0,void 0,this._errorListener);return t._value=e.map(r=>{const o=new n1(0,void 0,this._errorListener);return o._value=[...r],o}),t}_matrixRank(e){let t=0;const r=e.length,o=e[0].length,n=[...e].map(b=>[...b]);for(let b=0;b<r&&!(b>=o);b++){let z=b;for(;z<r&&n[z][b]===0;)z++;if(z===r)continue;if(z!==b){const s=n[z];n[z]=n[b],n[b]=s}const i=n[b][b];for(let s=0;s<o;s++)n[b][s]/=i;for(let s=b+1;s<r;s++){const a=n[s][b];n[s]=n[s].map((O,u)=>O-a*n[b][u]),n[s][b]=0}}for(let b=0;b<r;b++)n[b].some(z=>Number(z.toFixed(8))!==0)&&t++;return t}}class A_{constructor(e){E(this,"_variables");E(this,"_cacheData");this._variables=e,this._cacheData={}}change({timeframe:e},t){if(!e)return!0;const{time:r,__period:o}=this._variables,n=N2(e,r),b=N2(o,r);if(n<b)return!0;const z=`change_${t}`,i=this._cacheData[z],s=this._variables.time;if(i){if(i.offset){if(i.currentTime+i.offset<=s)return this._cacheData[z]={currentTime:s,offset:0},!0}else if(i.currentTime+n*1e3<=s)return this._cacheData[z]={currentTime:s,offset:0},!0}else{const a=this._calcTimeOffset(s,e);return this._cacheData[z]={currentTime:s,offset:a},!1}return!1}in_seconds({timeframe:e}={}){const{time:t,__period:r}=this._variables;return N2(e||r,t)}from_seconds({seconds:e=0}){const t=e*1e3,r=D1.duration(t);if(r.years())return"12M";const n=r.asMonths();if(Fo(n))return`${n}M`;const b=r.asWeeks();if(Fo(b))return`${b}M`;const z=r.asDays();if(z>=1)return`${Math.ceil(z)}D`;const i=r.asMinutes();if(i>=1)return`${Math.ceil(i)}`;const s=r.asSeconds();return s<=1?"1S":s<=5?"5S":s<=10?"10S":s<=15?"15S":s<=30?"30S":"1"}_calcTimeOffset(e,t){let r=0;if(t.includes("W")){const z=D1(e).day();t="1D",z!==1&&(r=(8-z)*60*60*24*1e3)}else if(t.includes("M")){const z=D1(e).date();t="1D";const i=D1(e).daysInMonth();z!==1&&(r=(i-z+1)*60*60*24*1e3)}const o=this._variables.getTimeTradingday(e,t),n=N2(t,e)*1e3,b=e-o-Math.floor((e-o)/n)*n;return r?r-b:b}}class f_{constructor(e,t){E(this,"_errorListener");E(this,"_intlNumberFormatter");E(this,"_precision");E(this,"_intlFormat");this._errorListener=e,this._precision=t,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:3}),this._intlFormat=new Intl.NumberFormat("en-US")}pos({source:e="",str:t=""}){return e==null?void 0:e.indexOf(t)}trim({source:e=""}){return e==null?void 0:e.trim()}lower({source:e=""}){return e==null?void 0:e.toLocaleLowerCase()}match({source:e="",regex:t=""}){const r=e==null?void 0:e.match(new RegExp(t));return r?r[0]:""}split({string:e="",separator:t=""}){const r=e==null?void 0:e.split(t),o=new n1;return o._value=r||[],o}upper({source:e=""}){return e==null?void 0:e.toLocaleUpperCase()}format({formatString:e=""},t){return this._strFormat(e,t)}length({string:e=""}){return e==null?void 0:e.length}repeat({source:e="",repeat:t,separator:r=""},o){if(d0(t)){this._errorListener.addError(l1.arrLenErr,o,$0.Error);return}return Array.from(new Array(t),()=>e).join(r)}replace({source:e="",target:t="",replacement:r="",occurrence:o}){d0(o)&&(o=0);let n=-1;for(let b=0;b<o+1&&(n=e.indexOf(t,n+1),n!==-1);b++);return n!==-1?e.substring(0,n)+r+e.substring(n+t.length):e}contains({source:e="",str:t=""}){return e==null?void 0:e.includes(t)}endswith({source:e="",str:t=""}){return e==null?void 0:e.endsWith(t)}tonumber({string:e=""}){if(/[^\d.]/.test(e))return;const t=parseFloat(e);return isNaN(t)?void 0:t}tostring({value:e,format:t}){if(e===void 0)return"NaN";if(typeof e=="object"){if(e.isArray)return this._arrToStr(e._value,t);if(e.isMatrix){const r=[];for(const o of e._matrixArray)r.push(this._arrToStr(o,t));return r.join(`
|
76
|
-
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t==null?void 0:t.replace(/0/g,"#")))}_arrToStr(e,t){return`[${e.map(o=>typeof o=="number"?this._toStringFormat(o,t):o).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return d0(t)&&(t=0),d0(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return d0(e)&&(e=0),$2(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e==null?void 0:e.toFixed(10));switch(t){case O1.mintick:return e==null?void 0:e.toFixed(this._precision);case O1.percent:return`${Number(e.toFixed(2))}%`;case O1.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var z;let[r,o]=t.split(".");t.split("%").length===2&&(e=e*100);let[n,b=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const i=r.split(","),s=((z=i[i.length-1])==null?void 0:z.replace(/[^#]/g,"").length)||0;s&&(n=n.replace(new RegExp(`\\B(?=(\\d{${s}})+(?!\\d))`,"g"),",")),r=i.join("")}n=r.replace(/#/,n).replace(/#/g,"")}else n=`${r}${n}`;if(o&&o.includes("#")){const i=o.split("#").length-1,s=+`${n}.${b}`;if(!isNaN(s))return+`${s.toFixed(i)}${o.replace(/#/g,"")}`;b=`${b.substring(0,i)}${o.replace(/#/g,"")}`}else b=o||"";return b?+`${n}.${b}`:n}_formatNumber(e,t){if(!t)return Number(e==null?void 0:e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}strformat({formatString:e=""},t,r){return this._strFormat(e,t,r)}_strFormat(e,t,r){return e.replace(/{[^{}]+}/g,o=>{if(!o)return o;const n=o.replace(/[{}]/g,"").split(","),b=Number(n[0]);if(isNaN(b)||t.length<=b)return o;const z=t[b];if(n.length===1)return typeof z=="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):z===void 0?"":z;if(n.length===2){const i=n[1].trim();return i==="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):i==="date"?D1(z).format("LL"):o}else{const i=n[1].trim(),s=n[2].trim();if(i==="number")return this._formatNumber(z,s);if(i==="date"){let a="YYYY-MM-DD";switch(s){case"long":a="LL";break;case"short":a="L";break;default:s&&(a=s)}return D1(z).format(a)}return o}})}}class l_{constructor(e){E(this,"_errorListener");this._errorListener=e}new(){return new Ap(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class Ap{constructor(e){E(this,"_errorListener");E(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}get _value(){return this._mapInstance}_copyMap(e){const t=new Ap(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class q_{constructor(e){E(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Er(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Er(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Er(e,t)}from_time({price:e,time:t}){return new Er(e,void 0,t)}}class Er{constructor(e,t,r){E(this,"_index");E(this,"_price");E(this,"_time");this._index=t&&Math.round(t),this._price=e,this._time=r}get index(){return this._index}set index(e){this._index=e&&Math.round(e)}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}copy(){return new Er(this._price,this._index,this._time)}}class d_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLabel",{text:"",xloc:P1.bar_index,yloc:le.price,size:L2.normal,style:T1.styleLabelDown,textalign:t1.alignCenter});this._variables=e,this._errorListener=t}new(e,t){B0(this._errorListener,"label.new",this._variables.__requestName,t);const{time:r,high:o,low:n,bar_index:b}=this._variables,z=`label_${t}_${b}`;S1(e,["color","textcolor"]);const i={...this._defaultLabel,...e,id:z,time:r,high:o,low:n,bar_index:b};e.x&&(i.x=e.x&&Math.round(e.x)),e.point&&(i.x=i.xloc===P1.bar_index?e.point.index:e.point.time,i.y=e.point.price),i.yloc===le.abovebar?i.y=o:i.yloc===le.belowbar&&(i.y=n),this._verfiyArgs(e,t);const s=new Ko(z,this._variables,this._errorListener,i);return t.startsWith("export")||this._variables.label.add(z,i,s),s}_verfiyArgs(e,t){const{xloc:r,yloc:o,style:n,size:b,textalign:z,text_font_family:i}=e,s="label.new";this._paramVerfiy(n,t,s,Object.values(T1),"style"),this._paramVerfiy(r,t,s,Object.values(P1),"xloc"),this._paramVerfiy(o,t,s,Object.values(le),"yloc"),this._paramVerfiy(b,t,s,Object.values(L2),"size"),this._paramVerfiy(z,t,s,[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign"),this._paramVerfiy(i,t,s,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}label(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e},t){e==null||e.delete(t)}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Ko{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get type(){return Q0.LABEL}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.label.get(this._id)||this._data}copy(e){B0(this._errorListener,"label.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`label_${e}_${t}`,o=this._getLabel(e),n={...o||{},id:r,bar_index:t},b=new Ko(r,this._variables,this._errorListener,n);return o&&this._variables.label.add(r,n,b),b}get_x(e){var t;return B0(this._errorListener,"label.get_x",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return B0(this._errorListener,"label.get_y",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){B0(this._errorListener,"label.set_x",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=e&&Math.round(e))}set_y({y:e},t){B0(this._errorListener,"label.set_y",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.y=e)}delete(e){B0(this._errorListener,"label.delete",this._variables.__requestName,e),this._variables.label.delete(this._id,this._variables.bar_index,this._data.id)}set_xy({x:e,y:t},r){B0(this._errorListener,"label.set_xy",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.y=t)}get_text(e){var t;return B0(this._errorListener,"label.get_text",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){B0(this._errorListener,"label.set_size",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(L2),"size")}set_text({text:e},t){B0(this._errorListener,"label.set_text",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){B0(this._errorListener,"label.set_xloc",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(P1),"xloc"))}set_yloc({yloc:e},t){B0(this._errorListener,"label.set_yloc",this._variables.__requestName,t);const r=this._getLabel(t),{high:o,low:n}=this._variables;r&&(r.yloc=e,e===le.abovebar?r.y=o:e===le.belowbar&&(r.y=n),this._paramVerfiy(e,t,"label.set_yloc",Object.values(le),"yloc"))}set_color(e,t){B0(this._errorListener,"label.set_color",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){B0(this._errorListener,"label.set_point",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=r.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){B0(this._errorListener,"label.set_style",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(T1),"style")}set_tooltip({tooltip:e},t){B0(this._errorListener,"label.set_tooltip",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){B0(this._errorListener,"label.set_textalign",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign")}set_textcolor(e,t){B0(this._errorListener,"label.set_textcolor",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"label.set_text_font_family",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLabel(e){const t=this._variables.label.get(this._id)||this._data;return t||console.log(`错误${e}: label 不存在`),t}}const h_={freq_all:Ae.freqAll,freq_once_per_bar:Ae.freqOncePerBar,freq_once_per_bar_close:Ae.freqOncePerBarClose},W_={gaps_off:Pe.gapsOff,gaps_on:Pe.gapsOn,lookahead_off:Pe.lookaheadOff,lookahead_on:Pe.lookaheadOn},Tr={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"},D3={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"},__={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},X3={all:[A2.dataWindow,A2.pane,A2.priceScale,A2.statusLine],data_window:[A2.dataWindow],none:[],pane:[A2.pane],price_scale:[A2.priceScale],status_line:[A2.statusLine]},m_={both:fe.both,left:fe.left,none:fe.none,right:fe.right},g_={inherit:O1.inherit,mintick:O1.mintick,percent:O1.percent,price:O1.price,volume:O1.volume},R_={style_solid:kM.styleSolid,style_dashed:kM.styleDashed,style_dotted:kM.styleDotted},L_={style_arrowdown:T1.styleArrowdown,style_arrowup:T1.styleArrowup,style_circle:T1.styleCircle,style_cross:T1.styleCross,style_diamond:T1.styleDiamond,style_flag:T1.styleFlag,style_label_center:T1.styleLabelCenter,style_label_down:T1.styleLabelDown,style_label_left:T1.styleLabelLeft,style_label_lower_left:T1.styleLabelLowerLeft,style_label_lower_right:T1.styleLabelLowerRight,style_label_right:T1.styleLabelRight,style_label_up:T1.styleLabelUp,style_label_upper_left:T1.styleLabelUpperLeft,style_label_upper_right:T1.styleLabelUpperRight,style_none:T1.styleNone,style_square:T1.styleSquare,style_text_outline:T1.styleTextOutline,style_triangledown:T1.styleTriangledown,style_triangleup:T1.styleTriangleup,style_xcross:T1.styleXcross},v_={style_arrow_both:n2.styleArrowBoth,style_arrow_left:n2.styleArrowLeft,style_arrow_right:n2.styleArrowRight,style_dashed:n2.styleDashed,style_dotted:n2.styleDotted,style_solid:n2.styleSolid},N_={abovebar:ke.abovebar,absolute:ke.absolute,belowbar:ke.belowbar,bottom:ke.bottom,top:ke.top},y_={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},B_={style_area:ee.styleArea,style_areabr:ee.styleAreabr,style_circles:ee.styleCircles,style_columns:ee.styleColumns,style_cross:ee.styleCross,style_histogram:ee.styleHistogram,style_line:ee.styleLine,style_linebr:ee.styleLinebr,style_stepline:ee.styleStepline,style_stepline_diamond:ee.styleSteplineDiamond,style_steplinebr:ee.styleSteplinebr},w_={bottom_center:P2.bottomCenter,bottom_left:P2.bottomLeft,bottom_right:P2.bottomRight,middle_center:P2.middleCenter,middle_left:P2.middleLeft,middle_right:P2.middleRight,top_center:P2.topCenter,top_left:P2.topLeft,top_right:P2.topRight},D_={left:$M.left,none:$M.none,right:$M.right},X_={arrowdown:X2.arrowdown,arrowup:X2.arrowup,circle:X2.circle,cross:X2.cross,diamond:X2.diamond,flag:X2.flag,labeldown:X2.labeldown,labelup:X2.labelup,square:X2.square,triangledown:X2.triangledown,triangleup:X2.triangleup,xcross:X2.xcross},E_={auto:L2.auto,huge:L2.huge,large:L2.large,normal:L2.normal,small:L2.small,tiny:L2.tiny},T_={cash:b2.cash,fixed:b2.fixed,percent_of_equity:b2.percentOfEquity,commission:{cash_per_contract:O2.cashPerContract,cash_per_order:O2.cashPerOrder,percent:O2.percent},direction:{all:i1.all,long:i1.long,short:i1.short},oca:{cancel:Ue.cancel,none:Ue.none,reduce:Ue.reduce}},C_={align_bottom:t1.alignBottom,align_center:t1.alignCenter,align_left:t1.alignLeft,align_right:t1.alignRight,align_top:t1.alignTop,wrap_auto:t1.wrapAuto,wrap_none:t1.wrapNone},x_={bar_index:P1.bar_index,bar_time:P1.bar_time},S_={abovebar:le.abovebar,belowbar:le.belowbar,price:le.price},F_={actual:UM.actual,estimate:UM.estimate,standardized:UM.standardized};class fp{constructor(){E(this,"adjustment",{dividends:PM.dividends,none:PM.none,splits:PM.splits});E(this,"alert",h_);E(this,"barmerge",W_);E(this,"color",Tr);E(this,"currency",D3);E(this,"dayofweek",__);E(this,"earnings",F_);E(this,"display",X3);E(this,"extend",m_);E(this,"font",{family_default:St.familyDefault,family_monospace:St.familyMonospace});E(this,"format",g_);E(this,"hline",R_);E(this,"label",L_);E(this,"line",v_);E(this,"location",N_);E(this,"math",y_);E(this,"order",{ascending:$e.ascending,descending:$e.descending});E(this,"plot",B_);E(this,"position",w_);E(this,"scale",D_);E(this,"session",{extended:ut.extended,regular:ut.regular});E(this,"shape",X_);E(this,"size",E_);E(this,"splits",{denominator:"denominator",numerator:"numerator"});E(this,"strategy",T_);E(this,"text",C_);E(this,"xloc",x_);E(this,"yloc",S_)}updateData(){}}class I_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:P1.bar_index,line_color:Tr.blue,line_style:n2.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var z;B0(this._errorListener,"polyline.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`polyline_${t}_${r}`,n=Object.assign({},this._defaultPolyline,e,{id:o,bar_index:r,points:(z=e.points)==null?void 0:z._value.map(i=>({time:i.time,index:i.index,price:i.price}))});S1(n,["line_color","fill_color"]);const b=new E3(o,this._variables,n);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(o,n,b),b}_verfiyArgs(e,t){const{line_style:r,xloc:o}=e,n="polyline.new";this._paramVerfiy(r,t,n,Object.values(n2),"line_style"),this._paramVerfiy(o,t,n,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}delete({id:e}){e&&e.delete()}}class E3{constructor(e,t,r){E(this,"_id");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=t,this._id=e,this._data=r}get type(){return Q0.POLYLINE}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.polyline.get(this._id)||this._data}delete(){this._variables.polyline.delete(this._id,this._variables.bar_index,this._data.id)}}class P_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLine",{xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},o){B0(this._errorListener,"line.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`line_${o}_${n}`;S1(r,["color"]);const z={...this._defaultLine,...r,id:b,bar_index:n},{x1:i,x2:s}=z;if(i&&(z.x1=i&&Math.round(i)),s&&(z.x2=s&&Math.round(s)),e&&t){const O=z.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,u=z.xloc===P1.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(z,{x1:O,y1:e==null?void 0:e.price,x2:u,y2:t==null?void 0:t.price})}this._verfiyArgs(r,o);const a=new Jo(b,this._variables,this._errorListener,z);return o.startsWith("export")||this._variables.line.add(b,z,a),a}_verfiyArgs(e,t){const{extend:r,xloc:o,style:n}=e,b="line.new";this._paramVerfiy(n,t,b,Object.values(n2),"style"),this._paramVerfiy(r,t,b,Object.values(fe),"extend"),this._paramVerfiy(o,t,b,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}line(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class Jo{constructor(e,t,r,o){E(this,"_variables");E(this,"_id");E(this,"_suffix","");E(this,"_errorListener");E(this,"_fillKeys",[]);E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get id(){return this._id}get __fillKeys(){return this._fillKeys}__setFillKeys(e){this._fillKeys.includes(e)||this._fillKeys.push(e)}__updateFillKeys(e,t){const r=this._fillKeys.findIndex(o=>o===e);r!==-1?this._fillKeys.splice(r,1,t):this._fillKeys.push(t)}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get type(){return Q0.LINE}set data(e){this._data=e}get data(){return this._variables.line.get(this._id)||this._data}get originData(){return this._data}copy(e){const{bar_index:t}=this._variables,r=`line_${e}_${t}`,o=this._getLine(e,"copy"),n={...o,id:r,bar_index:t,isVar:void 0},b=new Jo(r,this._variables,this._errorListener,n);return o&&this._variables.line.add(r,n,b),b}delete(e){B0(this._errorListener,"line.delete",this._variables.__requestName,e);for(const t of this._fillKeys)this._variables.linefill.delete(t,this._variables.bar_index);this._variables.line.delete(this._id,this._variables.bar_index,this._data.id)}get_price({x:e},t){const r=this._getLine(t,"get_price");if(e===void 0)return e;if(r&&r.xloc===P1.bar_index){const{x1:o,y1:n,x2:b,y2:z}=r;return o===void 0||b===void 0||n===void 0||z===void 0?void 0:(z-n)/(b-o)*(e-o)+n}}get_x1(e){var t;return(t=this._getLine(e,"get_x1"))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e,"get_x2"))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e,"get_y1"))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e,"get_y2"))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t,"set_x1");r&&(r.x1=e&&Math.round(e))}set_x2({x:e},t){const r=this._getLine(t,"set_x2");r&&(r.x2=e&&Math.round(e))}set_y1({y:e},t){const r=this._getLine(t,"set_y1");r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t,"set_y2");r&&(r.y2=e)}set_xy1({x:e,y:t},r){const o=this._getLine(r,"set_xy1");o&&(o.x1=e&&Math.round(e),o.y1=t)}set_xy2({x:e,y:t},r){const o=this._getLine(r,"set_xy2");o&&(o.x2=e&&Math.round(e),o.y2=t)}set_xloc({xloc:e,x1:t,x2:r},o){const n=this._getLine(o,"set_xloc");n&&(n.xloc=e,n.x1=t&&Math.round(t),n.x2=r&&Math.round(r),this._paramVerfiy(e,o,"line.set_xloc",Object.values(P1),"xloc"))}set_color(e,t){const r=this._getLine(t,"set_color");r&&(S1(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t,"set_style");r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(n2),"style"))}set_width({width:e},t){const r=this._getLine(t,"set_width");r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t,"set_extend");r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(fe),"extend"))}set_first_point({point:e},t){const r=this._getLine(t,"set_first_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x1=z),i&&(r.y1=i)}}set_second_point({point:e},t){const r=this._getLine(t,"set_second_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x2=z),i&&(r.y2=i)}}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLine(e,t){B0(this._errorListener,`line.${t}`,this._variables.__requestName,e);const r=this._variables.line.get(this._id)||this._data;return r||console.log(`${e}: line 不存在`),r}}class k_{constructor(e){E(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:o}=e,{bar_index:n}=this._variables,b=`linefill_${t}_${n}`,z=r==null?void 0:r.data,i=o==null?void 0:o.data;z&&(z.linefills=z.linefills||[],z.linefills.push(b)),i&&(i.linefills=i.linefills||[],i.linefills.push(b)),S1(e,["color"]),r==null||r.__setFillKeys(b),o==null||o.__setFillKeys(b);const s={line1:z,line2:i,color:e.color,id:b,bar_index:n},a=new T3(this._variables,b,s,r,o);return t.startsWith("export")||(z||i)&&this._variables.linefill.add(b,s,a),a}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class T3{constructor(e,t,r,o,n){E(this,"_id");E(this,"_line1");E(this,"_line2");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._line1=o,this._line2=n,this._data=r}get type(){return Q0.LINEFILL}get id(){return this._id}get preId(){return this._preId}updateId(){var o,n;const{bar_index:e,_isRealTimeBar:t}=this._variables,r=this._id;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const b=this._id.split("_");b.pop(),this._id=`${b.join("_")}_${e}`}return(o=this._line1)==null||o.__updateFillKeys(r,this._id),(n=this._line2)==null||n.__updateFillKeys(r,this._id),t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.linefill.get(this._id)||this._data}linefill(e){return e.x}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:o,line2:n}=e;o&&(o.linefills=(t=o.linefills)==null?void 0:t.filter(b=>b!==this._id)),n&&(n.linefills=(r=n.linefills)==null?void 0:r.filter(b=>b!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id,this._variables.bar_index,this._data.id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(e){const t=this._variables.linefill.get(this._id);t&&(S1(e,["color"]),t.color=e.color)}}class $_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultBox",{border_color:Tr.blue,border_width:1,bgcolor:Tr.blue,xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid,text:"",text_size:L2.auto,text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_wrap:t1.wrapNone});this._variables=e,this._errorListener=t}box({x:e}){return e}new({top_left:e,bottom_right:t,...r},o){B0(this._errorListener,"box.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`box_${o}_${n}`,z={...this._defaultBox,...r,id:b,bar_index:n};S1(z,["border_color","bgcolor","text_color"]);const{left:i,right:s}=z;if(i&&(z.left=i&&Math.round(i)),s&&(z.right=s&&Math.round(s)),e){const{price:O,time:u,index:l}=e;z.top=O,z.left=z.xloc===P1.bar_index?l:u}if(t){const{price:O,time:u,index:l}=t;z.bottom=O,z.right=z.xloc===P1.bar_index?l:u}this._verfiyArgs(r,o);const a=new Qo(this._variables,b,this._errorListener,z);return o.startsWith("export")||this._variables.box.add(b,z,a),a}_verfiyArgs(e,t){const{border_style:r,extend:o,xloc:n,text_size:b,text_halign:z,text_valign:i,text_wrap:s,text_font_family:a}=e,O="box.new";this._paramVerfiy(r,t,O,[n2.styleDashed,n2.styleDotted,n2.styleSolid],"border_style"),this._paramVerfiy(o,t,O,Object.values(fe),"extend"),this._paramVerfiy(n,t,O,Object.values(P1),"xloc"),this._paramVerfiy(b,t,O,Object.values(L2),"text_size"),this._paramVerfiy(z,t,O,[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"),this._paramVerfiy(i,t,O,[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"),this._paramVerfiy(s,t,O,[t1.wrapAuto,t1.wrapNone],"text_wrap"),this._paramVerfiy(a,t,O,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_top({id:e},t){return e==null?void 0:e.get_top(t)}get_bottom({id:e},t){return e==null?void 0:e.get_bottom(t)}get_left({id:e},t){return e==null?void 0:e.get_left(t)}get_right({id:e},t){return e==null?void 0:e.get_right(t)}set_top({id:e,...t},r){e==null||e.set_top(t,r)}set_bottom({id:e,...t},r){e==null||e.set_bottom(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_left({id:e,...t},r){e==null||e.set_left(t,r)}set_right({id:e,...t},r){e==null||e.set_right(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({id:e,...t},r){e==null||e.set_border_width(t,r)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t},r){e==null||e.set_lefttop(t,r)}set_rightbottom({id:e,...t},r){e==null||e.set_rightbottom(t,r)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t},r){e==null||e.set_text_color(t,r)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t},r){e==null||e.set_top_left_point(t,r)}set_bottom_right_point({id:e,...t},r){e==null||e.set_bottom_right_point(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Qo{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.BOX}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.box.get(this._id)||this._data}copy(e){B0(this._errorListener,"box.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`box_${e}_${t}`,o=this._getBox(),n={...o,id:r,bar_index:t},b=new Qo(this._variables,r,this._errorListener,n);return o&&this._variables.box.add(r,n,b),b}delete(e){B0(this._errorListener,"box.delete",this._variables.__requestName,e),this._variables.box.delete(this._id,this._variables.bar_index,this._data.id)}get_top(e){B0(this._errorListener,"box.get_top",this._variables.__requestName,e);const t=this._getBox();return t&&t.top}set_top({top:e},t){B0(this._errorListener,"box.set_top",this._variables.__requestName,t);const r=this._getBox();r&&(r.top=e)}get_left(e){B0(this._errorListener,"box.get_left",this._variables.__requestName,e);const t=this._getBox();return t&&t.left}set_left({left:e},t){B0(this._errorListener,"box.set_left",this._variables.__requestName,t);const r=this._getBox();r&&(r.left=e&&Math.round(e))}set_text({text:e},t){B0(this._errorListener,"box.set_text",this._variables.__requestName,t);const r=this._getBox();r&&(r.text=e)}get_right(e){B0(this._errorListener,"box.get_right",this._variables.__requestName,e);const t=this._getBox();return t&&t.right}set_right({right:e},t){B0(this._errorListener,"box.set_right",this._variables.__requestName,t);const r=this._getBox();r&&(r.right=e&&Math.round(e))}get_bottom(e){B0(this._errorListener,"box.get_bottom",this._variables.__requestName,e);const t=this._getBox();return t&&t.bottom}set_bottom({bottom:e},t){B0(this._errorListener,"box.set_bottom",this._variables.__requestName,t);const r=this._getBox();r&&(r.bottom=e)}set_extend({extend:e},t){B0(this._errorListener,"box.set_extend",this._variables.__requestName,t);const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(fe),"extend"))}set_bgcolor({color:e},t){B0(this._errorListener,"box.set_bgcolor",this._variables.__requestName,t);const r=this._getBox();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_lefttop({left:e,top:t},r){B0(this._errorListener,"box.set_lefttop",this._variables.__requestName,r);const o=this._getBox();o&&(o.left=e&&Math.round(e),o.top=t)}set_text_size({text_size:e},t){B0(this._errorListener,"box.set_text_size",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(L2),"text_size"))}set_text_wrap({text_wrap:e},t){B0(this._errorListener,"box.set_text_wrap",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[t1.wrapAuto,t1.wrapNone],"text_wrap"))}set_text_color({text_color:e},t){B0(this._errorListener,"box.set_text_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_color=e,S1(r,["text_color"]))}set_rightbottom({right:e,bottom:t},r){B0(this._errorListener,"box.set_rightbottom",this._variables.__requestName,r);const o=this._getBox();o&&(o.right=e&&Math.round(e),o.bottom=t)}set_text_halign({text_halign:e},t){B0(this._errorListener,"box.set_text_halign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){B0(this._errorListener,"box.set_text_valign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"))}set_top_left_point({point:e},t){B0(this._errorListener,"box.set_top_left_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.top=n,r.left=r.xloc===P1.bar_index?o:b}}set_border_color({color:e},t){B0(this._errorListener,"box.set_border_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_style({style:e},t){B0(this._errorListener,"box.set_border_style",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[n2.styleDashed,n2.styleDotted,n2.styleSolid],"style"))}set_border_width({width:e},t){B0(this._errorListener,"box.set_border_width",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_width=e)}set_bottom_right_point({point:e},t){B0(this._errorListener,"box.set_bottom_right_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.bottom=n,r.right=r.xloc===P1.bar_index?o:b}}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"box.set_text_font_family",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(St),"text_font_family"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getBox(){return this._variables.box.get(this._id)||this._data}}class U_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultTable",{position:P2.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e}){return e}new(e,t){B0(this._errorListener,"table.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`table_${t}_${r}`,{rows:n}=e;S1(e,["text_color","bgcolor","border_color"]);const b=Array.from(Array(n),()=>[]),z=t.split("_"),i=z.pop(),s=z.pop(),a={...this._defaultTable,...e,cell:b,id:o,bar_index:r,line:s,col:i},O=new C3(this._variables,o,this._errorListener,a);return this._paramVerfiy(e.position,t,"table.new",Object.values(P2),"position"),t.startsWith("export")||this._variables.table.add(o,a,O),O}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}cell({table_id:e,...t},r){e==null||e.cell(t,r)}cell_set_bgcolor({table_id:e,...t},r){e==null||e.cell_set_bgcolor(t,r)}cell_set_height({table_id:e,...t},r){e==null||e.cell_set_height(t,r)}cell_set_text({table_id:e,...t},r){e==null||e.cell_set_text(t,r)}cell_set_text_color({table_id:e,...t},r){e==null||e.cell_set_text_color(t,r)}cell_set_text_font_family({table_id:e,...t},r){e==null||e.cell_set_text_font_family(t,r)}cell_set_text_halign({table_id:e,...t},r){e==null||e.cell_set_text_halign(t,r)}cell_set_text_valign({table_id:e,...t},r){e==null||e.cell_set_text_valign(t,r)}cell_set_text_size({table_id:e,...t},r){e==null||e.cell_set_text_size(t,r)}cell_set_tooltip({table_id:e,...t},r){e==null||e.cell_set_tooltip(t,r)}cell_set_width({table_id:e,...t},r){e==null||e.cell_set_width(t,r)}clear({table_id:e,...t},r){e==null||e.clear(t,r)}delete({table_id:e},t){e==null||e.delete(t)}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({table_id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({table_id:e,...t},r){e==null||e.set_border_width(t,r)}set_frame_color({table_id:e,...t},r){e==null||e.set_frame_color(t,r)}set_frame_width({table_id:e,...t},r){e==null||e.set_frame_width(t,r)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class C3{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_defaultCell",{column:0,row:0,text:"",text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_size:L2.normal});E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.TABLE}get id(){return this._id}get preId(){return this._preId}set data(e){this._data=e}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get data(){return this._variables.table.get(this._id)||this._data}cell(e,t){this._verfiyRequestFunc(t,"cell");const r={...this._defaultCell,...e},{column:o=0,row:n=0}=r,b=this._getTable();if(b){const z=b.cell||[],i=z[n]||[];i[o]=r,z[n]=i,b.cell=z}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r},o){this._verfiyRequestFunc(o,"cell_set_bgcolor");const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r},o){this._verfiyRequestFunc(o,"cell_set_height");const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r},o){this._verfiyRequestFunc(o,"cell_set_text");const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r},o){this._verfiyRequestFunc(o,"cell_set_text_color");const n=this._getTableItem(e,t);n&&(n.text_color=r,S1(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r},o){this._verfiyRequestFunc(o,"cell_set_text_font_family");const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r},o){this._verfiyRequestFunc(o,"cell_set_text_halign");const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r},o){this._verfiyRequestFunc(o,"cell_set_text_valign");const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r},o){this._verfiyRequestFunc(o,"cell_set_text_size");const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r},o){this._verfiyRequestFunc(o,"cell_set_tooltip");const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r},o){this._verfiyRequestFunc(o,"cell_set_width");const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){this._verfiyRequestFunc(n,"clear");const b=this._getTable();if(b){const z=b.cell;if(z)for(let i=t;i<=o;i++)for(let s=e;s<=r;s++){const a=z[i];a&&(a[s]=void 0)}}}delete(e){this._verfiyRequestFunc(e,"delete"),this._variables.table.delete(this._id,this._variables.bar_index,this._data.id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){if(this._verfiyRequestFunc(n,"merge_cells"),e>r||t>o){this._errorListener.addError(l1.mergeCellErr,n,$0.Error);return}const b=this._getTable();if(!b)return;const z=b.merge_cells||[];z.push({start_column:e,start_row:t,end_column:r,end_row:o}),b.merge_cells=z}set_bgcolor({bgcolor:e},t){this._verfiyRequestFunc(t,"set_bgcolor");const r=this._getTable();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_border_color({border_color:e},t){this._verfiyRequestFunc(t,"set_border_color");const r=this._getTable();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_width({border_width:e},t){this._verfiyRequestFunc(t,"set_border_width");const r=this._getTable();r&&(r.border_width=e)}set_frame_color({frame_color:e},t){this._verfiyRequestFunc(t,"set_frame_color");const r=this._getTable();r&&(r.frame_color=e)}set_frame_width({frame_width:e},t){this._verfiyRequestFunc(t,"set_frame_width");const r=this._getTable();r&&(r.frame_width=e)}set_position({position:e},t){this._verfiyRequestFunc(t,"set_position");const r=this._getTable();r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(P2),"position"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getTableItem(e,t){const r=this._getTable();if(r){const o=r.cell;return o?o[t][e]:void 0}}_getTable(){return this._variables.table.get(this._id)||this._data}_verfiyRequestFunc(e,t){B0(this._errorListener,`table.${t}`,this._variables.__requestName,e)}}class j_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){return this._verifyTradeNum(e,t)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.historyOrders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.historyOrders[e];return o||r}exit_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{out_qty:r=0,direction:o}=this._strategy.historyOrders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.closedtrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.historyOrders.length;return!(e>=r)}}class H_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,original_qty:o=0,commission:n=0}=this._strategy.orders[e];return n*r/o}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.orders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.orders[e];return o||r}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,direction:o}=this._strategy.orders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.opentrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.orders.length;return!(e>=r)}}class Y_{constructor(e,t){E(this,"_strategy");E(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(i1),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}}var G_=20,V_=1,Gt=1e6,x3=1e6,K_=-7,J_=21,Q_=!1,WM="[big.js] ",Vt=WM+"Invalid ",Zo=Vt+"decimal places",Z_=Vt+"rounding mode",S3=WM+"Division by zero",m1={},xe=void 0,em=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function F3(){function M(e){var t=this;if(!(t instanceof M))return e===xe?F3():new M(e);if(e instanceof M)t.s=e.s,t.e=e.e,t.c=e.c.slice();else{if(typeof e!="string"){if(M.strict===!0&&typeof e!="bigint")throw TypeError(Vt+"value");e=e===0&&1/e<0?"-0":String(e)}tm(t,e)}t.constructor=M}return M.prototype=m1,M.DP=G_,M.RM=V_,M.NE=K_,M.PE=J_,M.strict=Q_,M.roundDown=0,M.roundHalfUp=1,M.roundHalfEven=2,M.roundUp=3,M}function tm(M,e){var t,r,o;if(!em.test(e))throw Error(Vt+"number");for(M.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),o=e.length,r=0;r<o&&e.charAt(r)=="0";)++r;if(r==o)M.c=[M.e=0];else{for(;o>0&&e.charAt(--o)=="0";);for(M.e=t-r-1,M.c=[],t=0;r<=o;)M.c[t++]=+e.charAt(r++)}return M}function Kt(M,e,t,r){var o=M.c;if(t===xe&&(t=M.constructor.RM),t!==0&&t!==1&&t!==2&&t!==3)throw Error(Z_);if(e<1)r=t===3&&(r||!!o[0])||e===0&&(t===1&&o[0]>=5||t===2&&(o[0]>5||o[0]===5&&(r||o[1]!==xe))),o.length=1,r?(M.e=M.e-e+1,o[0]=1):o[0]=M.e=0;else if(e<o.length){if(r=t===1&&o[e]>=5||t===2&&(o[e]>5||o[e]===5&&(r||o[e+1]!==xe||o[e-1]&1))||t===3&&(r||!!o[0]),o.length=e,r){for(;++o[--e]>9;)if(o[e]=0,e===0){++M.e,o.unshift(1);break}}for(e=o.length;!o[--e];)o.pop()}return M}function Jt(M,e,t){var r=M.e,o=M.c.join(""),n=o.length;if(e)o=o.charAt(0)+(n>1?"."+o.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)o="0"+o;o="0."+o}else if(r>0)if(++r>n)for(r-=n;r--;)o+="0";else r<n&&(o=o.slice(0,r)+"."+o.slice(r));else n>1&&(o=o.charAt(0)+"."+o.slice(1));return M.s<0&&t?"-"+o:o}m1.abs=function(){var M=new this.constructor(this);return M.s=1,M},m1.cmp=function(M){var e,t=this,r=t.c,o=(M=new t.constructor(M)).c,n=t.s,b=M.s,z=t.e,i=M.e;if(!r[0]||!o[0])return r[0]?n:o[0]?-b:0;if(n!=b)return n;if(e=n<0,z!=i)return z>i^e?1:-1;for(b=(z=r.length)<(i=o.length)?z:i,n=-1;++n<b;)if(r[n]!=o[n])return r[n]>o[n]^e?1:-1;return z==i?0:z>i^e?1:-1},m1.div=function(M){var e=this,t=e.constructor,r=e.c,o=(M=new t(M)).c,n=e.s==M.s?1:-1,b=t.DP;if(b!==~~b||b<0||b>Gt)throw Error(Zo);if(!o[0])throw Error(S3);if(!r[0])return M.s=n,M.c=[M.e=0],M;var z,i,s,a,O,u=o.slice(),l=z=o.length,d=r.length,A=r.slice(0,z),h=A.length,q=M,_=q.c=[],m=0,L=b+(q.e=e.e-M.e)+1;for(q.s=n,n=L<0?0:L,u.unshift(0);h++<z;)A.push(0);do{for(s=0;s<10;s++){if(z!=(h=A.length))a=z>h?1:-1;else for(O=-1,a=0;++O<z;)if(o[O]!=A[O]){a=o[O]>A[O]?1:-1;break}if(a<0){for(i=h==z?o:u;h;){if(A[--h]<i[h]){for(O=h;O&&!A[--O];)A[O]=9;--A[O],A[h]+=10}A[h]-=i[h]}for(;!A[0];)A.shift()}else break}_[m++]=a?s:++s,A[0]&&a?A[h]=r[l]||0:A=[r[l]]}while((l++<d||A[0]!==xe)&&n--);return!_[0]&&m!=1&&(_.shift(),q.e--,L--),m>L&&Kt(q,L,t.RM,A[0]!==xe),q},m1.eq=function(M){return this.cmp(M)===0},m1.gt=function(M){return this.cmp(M)>0},m1.gte=function(M){return this.cmp(M)>-1},m1.lt=function(M){return this.cmp(M)<0},m1.lte=function(M){return this.cmp(M)<1},m1.minus=m1.sub=function(M){var e,t,r,o,n=this,b=n.constructor,z=n.s,i=(M=new b(M)).s;if(z!=i)return M.s=-i,n.plus(M);var s=n.c.slice(),a=n.e,O=M.c,u=M.e;if(!s[0]||!O[0])return O[0]?M.s=-i:s[0]?M=new b(n):M.s=1,M;if(z=a-u){for((o=z<0)?(z=-z,r=s):(u=a,r=O),r.reverse(),i=z;i--;)r.push(0);r.reverse()}else for(t=((o=s.length<O.length)?s:O).length,z=i=0;i<t;i++)if(s[i]!=O[i]){o=s[i]<O[i];break}if(o&&(r=s,s=O,O=r,M.s=-M.s),(i=(t=O.length)-(e=s.length))>0)for(;i--;)s[e++]=0;for(i=e;t>z;){if(s[--t]<O[t]){for(e=t;e&&!s[--e];)s[e]=9;--s[e],s[t]+=10}s[t]-=O[t]}for(;s[--i]===0;)s.pop();for(;s[0]===0;)s.shift(),--u;return s[0]||(M.s=1,s=[u=0]),M.c=s,M.e=u,M},m1.mod=function(M){var e,t=this,r=t.constructor,o=t.s,n=(M=new r(M)).s;if(!M.c[0])throw Error(S3);return t.s=M.s=1,e=M.cmp(t)==1,t.s=o,M.s=n,e?new r(t):(o=r.DP,n=r.RM,r.DP=r.RM=0,t=t.div(M),r.DP=o,r.RM=n,this.minus(t.times(M)))},m1.neg=function(){var M=new this.constructor(this);return M.s=-M.s,M},m1.plus=m1.add=function(M){var e,t,r,o=this,n=o.constructor;if(M=new n(M),o.s!=M.s)return M.s=-M.s,o.minus(M);var b=o.e,z=o.c,i=M.e,s=M.c;if(!z[0]||!s[0])return s[0]||(z[0]?M=new n(o):M.s=o.s),M;if(z=z.slice(),e=b-i){for(e>0?(i=b,r=s):(e=-e,r=z),r.reverse();e--;)r.push(0);r.reverse()}for(z.length-s.length<0&&(r=s,s=z,z=r),e=s.length,t=0;e;z[e]%=10)t=(z[--e]=z[e]+s[e]+t)/10|0;for(t&&(z.unshift(t),++i),e=z.length;z[--e]===0;)z.pop();return M.c=z,M.e=i,M},m1.pow=function(M){var e=this,t=new e.constructor("1"),r=t,o=M<0;if(M!==~~M||M<-x3||M>x3)throw Error(Vt+"exponent");for(o&&(M=-M);M&1&&(r=r.times(e)),M>>=1,!!M;)e=e.times(e);return o?t.div(r):r},m1.prec=function(M,e){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");return Kt(new this.constructor(this),M,e)},m1.round=function(M,e){if(M===xe)M=0;else if(M!==~~M||M<-Gt||M>Gt)throw Error(Zo);return Kt(new this.constructor(this),M+this.e+1,e)},m1.sqrt=function(){var M,e,t,r=this,o=r.constructor,n=r.s,b=r.e,z=new o("0.5");if(!r.c[0])return new o(r);if(n<0)throw Error(WM+"No square root");n=Math.sqrt(+Jt(r,!0,!0)),n===0||n===1/0?(e=r.c.join(""),e.length+b&1||(e+="0"),n=Math.sqrt(e),b=((b+1)/2|0)-(b<0||b&1),M=new o((n==1/0?"5e":(n=n.toExponential()).slice(0,n.indexOf("e")+1))+b)):M=new o(n+""),b=M.e+(o.DP+=4);do t=M,M=z.times(t.plus(r.div(t)));while(t.c.slice(0,b).join("")!==M.c.slice(0,b).join(""));return Kt(M,(o.DP-=4)+M.e+1,o.RM)},m1.times=m1.mul=function(M){var e,t=this,r=t.constructor,o=t.c,n=(M=new r(M)).c,b=o.length,z=n.length,i=t.e,s=M.e;if(M.s=t.s==M.s?1:-1,!o[0]||!n[0])return M.c=[M.e=0],M;for(M.e=i+s,b<z&&(e=o,o=n,n=e,s=b,b=z,z=s),e=new Array(s=b+z);s--;)e[s]=0;for(i=z;i--;){for(z=0,s=b+i;s>i;)z=e[s]+n[i]*o[s-i-1]+z,e[s--]=z%10,z=z/10|0;e[s]=z}for(z?++M.e:e.shift(),i=e.length;!e[--i];)e.pop();return M.c=e,M},m1.toExponential=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),++M,e);t.c.length<M;)t.c.push(0)}return Jt(t,!0,!!r)},m1.toFixed=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),M+t.e+1,e),M=M+t.e+1;t.c.length<M;)t.c.push(0)}return Jt(t,!1,!!r)},m1[Symbol.for("nodejs.util.inspect.custom")]=m1.toJSON=m1.toString=function(){var M=this,e=M.constructor;return Jt(M,M.e<=e.NE||M.e>=e.PE,!!M.c[0])},m1.toNumber=function(){var M=+Jt(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(M.toString()))throw Error(WM+"Imprecise conversion");return M},m1.toPrecision=function(M,e){var t=this,r=t.constructor,o=t.c[0];if(M!==xe){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");for(t=Kt(new r(t),M,e);t.c.length<M;)t.c.push(0)}return Jt(t,M<=t.e||t.e<=r.NE||t.e>=r.PE,!!o)},m1.valueOf=function(){var M=this,e=M.constructor;if(e.strict===!0)throw Error(WM+"valueOf disallowed");return Jt(M,M.e<=e.NE||M.e>=e.PE,!0)};var en=F3();function I3(M,e){return en(M).plus(e).toNumber()}function tn(M,e){return en(M).minus(e).toNumber()}function Qt(M,e){return en(M).mul(e).toNumber()}function rn(M,e=5){return Number(M&&en(M).toFixed(e))}let rm=class{constructor(e,t,r,o,n){E(this,"_variables");E(this,"_options");E(this,"_totalChangeCapital");E(this,"_historyOrder");E(this,"_orders");E(this,"_exitOrders");E(this,"_pendingOrders");E(this,"_mintick");E(this,"_funcOptions");E(this,"_pendingCloseOrders");E(this,"_errorListener");E(this,"_risk");E(this,"_opentrades");E(this,"_closedtrades");E(this,"_riskNamespace");E(this,"_updateOptions",{});E(this,"_id");E(this,"_maxDrawdownVerifyIndex",0);E(this,"calcOnOrderFillsData",{index:-1});this._variables=e,this._errorListener=o,this._options={overlay:!1,format:O1.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:b2.fixed,default_qty_value:1,initial_capital:1e6,currency:D3.NONE,slippage:0,commission_type:O2.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._exitOrders=[],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 H_(this),this._closedtrades=new j_(this),this._riskNamespace=new Y_(this,o),this._id=`strategy_${n}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}get isCalcOnEveryTick(){return this._options.calc_on_every_tick}updateOptions(e){this._updateOptions=e||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._ordersHandle(),this._pendingOrderHandle(),this._exitOrdersHandle(),this._maxIntradayFilledOrdersVerify(),this._maxDrawdownVerify();const{open:e,high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,o=this._variables.close;this._variables.strategy.update(this.calcOnOrderFillsData.currentData||{open:e,close:o,high:t,low:r}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._ordersHandle(),this._pendingOrderHandle(),this._calcProfitAndLoss()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var l;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{time_tradingday:o,time:n,strategy:{netprofit:b,initial_capital:z}}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:a=0}=this._risk;n===o&&(a=b,this._risk.preNetprofit=b,this._risk.isTemporaryBan=!1);let O=a-b;O+=this._orders.reduce((d,A)=>{const{in_price:h,direction:q,qty:_=0,commission:m=0,original_qty:L=0}=A,g=q===i1.long?1:-1,v=(i-h)*_,y=(s-h)*_,X=g===1?y:-v;return d+X+_/L*m},0);let u=!1;switch(t){case b2.cash:u=e<O;break;case b2.percentOfEquity:const d=O/(z+b)*100;u=e<d;break}if(u){this._risk.isTemporaryBan=!0;const d=(l=this._orders[0])==null?void 0:l.direction;this._closeOrders(this._orders,d===i1.long?s:i,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:o,time_tradingday:n}=this._variables,{open:b}=this.calcOnOrderFillsData.data||this._variables;o===n&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,b,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:o=0}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:b,strategy:z}=this._variables,{open:i}=this.calcOnOrderFillsData.data||this._variables;let s=t;if(n===b){const a=z.netprofit+z.openprofit;a<o?s=0:s++,Object.assign(this._risk,{lossDays:s,totalProfit:a})}e<=s&&this._riskTouchOff(i,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:o}=this._variables,{open:n}=this.calcOnOrderFillsData.data||this._variables;if(e!==void 0&&t&&this._maxDrawdownVerifyIndex===o){const{initial_capital:b}=this._options,i=this._orders.reduce((a,O)=>{const{in_price:u,commission:l=0,qty:d=0,original_qty:A=0,direction:h}=O,q=h===i1.long?1:-1,_=(n-u)*q*d;return a+_+l*d/A},0)+this._totalChangeCapital;let s=!1;switch(t){case b2.percentOfEquity:s=i/b*100<=-e;break;case b2.cash:s=i<=-e;break}s&&this._riskTouchOff(n,"Close Position (Max Drawdown)")}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,e,t,"close"),this._pendingOrders=[]}strategy(e,t){if(!this._variables.bar_index){this._paramVerfiy(e.format,t,"strategy",[O1.inherit,O1.price,O1.percent,O1.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(b2),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(O2),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),o={...this._updateOptions};if(r)for(const n of Object.keys({...r,...e}))e[n]!==r[n]&&delete o[n];this._variables.max_bars_back=e.max_bars_back||0,self==null||self.workerStorage.set(this._id,e),Object.assign(this._options,e,o),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:o,scriptType:"strategy"})}}order(e,t){this._verfiyRequestFunc(t,"order"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(Ue),"oca_type"),this._orderHandle(e))}entry(e,t){this._verfiyRequestFunc(t,"entry"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(Ue),"oca_type"),this._entryHandle(e))}close(e,t){if(this._verfiyRequestFunc(t,"close"),!this._getCloseOrders(e.id).length)return;const{immediately:o}=e;if(o||this._options.process_orders_on_close){const n=this._pendingCloseOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingCloseOrders.push({...e,place_order_type:"close"})}else{const n=this._pendingOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingOrders.push({...e,place_order_type:"close"})}}close_all(e,t){if(this._verfiyRequestFunc(t,"close_all"),typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:r}=e;r||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e},t){this._verfiyRequestFunc(t,"cancel"),this._pendingOrders=this._pendingOrders.filter(r=>!(r.id===e&&r.place_order_type!=="close"))}cancel_all(e){this._verfiyRequestFunc(e,"cancel_all"),this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(e,t){this._verfiyRequestFunc(t,"exit"),this._exit(e,t)}convert_to_account({value:e},t){return this._verfiyRequestFunc(t,"convert_to_account"),e}convert_to_symbol({value:e},t){return this._verfiyRequestFunc(t,"convert_to_symbol"),e}default_entry_qty({fill_price:e},t){return this._verfiyRequestFunc(t,"default_entry_qty"),e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=b2.fixed,default_qty_value:r=1,initial_capital:o,commission_value:n}=this._options;let b=r;switch(t){case b2.cash:b=r/e;break;case b2.percentOfEquity:const z=this._getOrderProfit(e),i=o+z+this._totalChangeCapital;n?b=this._getCommQty(i,e):b=i*r/100/e;break}return sc(b,this._getLen())}_calcExitQty(e){if(!String(e).includes("."))return e;const t=this._getLen();return Math.ceil(Qt(e,Math.pow(10,t)))}_getCommQty(e,t){const{commission_type:r,commission_value:o=0,default_qty_value:n=0}=this._options;let b=0;switch(r){case O2.percent:b=e*n/(100*t+o*t);break;case O2.cashPerContract:b=e*n/(100*t+o);break;case O2.cashPerOrder:b=(e-o)*n/100/t}return b}_getLen(){const e=5-(this._variables.precision||5);return e<0?0:e}_getCapital(e,t){const{margin_long:r=0,margin_short:o=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:o<=100&&o>0&&e===-1&&(t=t*100/o),t}_calcProfitAndLoss(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;for(const t of this._orders){const{in_price:r,qty:o=0,direction:n}=t,b=n===i1.long?1:-1,z=(e-r)*b*o,[i,s]=this._calcProfitAndLossHandle(r,o,b);this._calcOrderPercent(t,z,i,s)}}_calcProfitAndLossHandle(e,t,r,o){const{high:n,low:b}=this.calcOnOrderFillsData.data||this._variables,z=((o||n)-e)*t,i=((o||b)-e)*t;let s=r===1?z:-i,a=r===1?i:-z;return[s,a]}_calcOrderPercent(e,t,r,o){const{commission_value:n}=this._options,{close:b}=this.calcOnOrderFillsData.data||this._variables,{original_qty:z=0,qty:i=0,in_price:s,max_profit:a=0,trading_loss:O=0}=e;let{commission:u=0}=e,l=s*i;if(n){const d=this._getCommission(b,i);u=u*i/z,r-=u,o-=u,l+=u,t=t-d-u}r=Math.max(r,a,0),o=Math.min(o,O,0),Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:o,profit_percent:t/l*100,max_profit_percent:r/l*100,trading_loss_percent:o/l*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:e}=this._variables,{high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:o,margin_long:n=0,margin_short:b=0}=this._options,z=this._orders[0].direction===i1.long?1:-1;let i=z===1?r:t;if(z===1&&n===100)return;const s=(z===1?n:b)/100;if(s<=0)return;let a=!1;const[O,u]=this._orders.reduce((h,q)=>{let[_,m]=h;const{in_price:L,qty:g=0,in_time:v}=q;v===e&&(a=!0);const y=L*g,X=i*g;return _+=y,m+=X,[_,m]},[0,0]);let l=0,d=0;const A=o+this._totalChangeCapital;if(a&&(l=A-O*s,l<0&&(i=this._orders[0].in_price,d=Math.abs(Math.trunc(l/s/i)*4),d=Math.max(d,1))),l>=0){const h=z*(u-O);if(l=A+h-u*s,l>=0)return;d=Math.abs(Math.trunc(l/s/i)*4)}d<=0||this._marginCallOrders(i,d,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:o="FIFO"}=this._options;if(o==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r,!0);return}for(const n of this.orders)n.position_close_type=n.place_order_type,n.isTiggerClose=!0,this._processOrder(n,e,t,r,r,!0);this._orders=this._orders.filter(n=>!n.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e),s=e.direction===i1.long?1:-1;if(o<=0)return;let a=o;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"order"});return}this._judgeCapitalEnough(o,b,s)&&this._addPendingOrders(e,b,a,r,z)}_orderOnCloseHandle(e){const t=this._orders.filter(_=>_.direction!==e.direction),{slippage:r=0}=this._options;let{direction:o,qty:n=0,id:b,comment:z,oca_type:i,oca_name:s,in_price:a}=e;const O=o===i1.long?1:-1;if(t.length){const _=this._processOrders(t,a,n,b,z,!1,"order");if(_<=0)return;n=_}const u=a-O*r*this._mintick;if(!this._judgeCapitalEnough(n,u,O))return;this._ocaGroupVerify(n,s,i);const{bar_index:d,time:A}=this._variables,{high:h,low:q}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...e,in_price:u,in_high:h,in_low:q,in_index:d,in_time:A,qty:n,place_order_type:"order"})}_judgeCapitalEnough(e,t,r){let o=this._freezeCapital;if(this._orders.some(a=>(a.direction===i1.long?1:-1)!==r)&&(o=0),e<=0)return!1;const{margin_long:n=0,margin_short:b=0}=this._options;if(n===0&&r===1||b===0&&r===-1)return!0;const z=this._getOrderProfit(t),s=this._getCapital(r,this._options.initial_capital+z+this._totalChangeCapital)-o;return e*t<=s}_getOrderProfit(e){return this._orders.reduce((t,r)=>{const{in_price:o,qty:n=0,direction:b}=r,z=b===i1.long?1:-1;return t+(e-o)*n*z},0)}_ocaGroupVerify(e,t,r){if(!t||!r||r===Ue.none)return!1;let o=!1;switch(r){case Ue.cancel:this._pendingOrders=this._pendingOrders.filter(n=>{if(n.oca_name===t)n.isCancel=!0,o=!0;else return!0});break;case Ue.reduce:this._pendingOrders=this._pendingOrders.filter(n=>{const{qty:b=0,oca_name:z}=n;if(t===z){const i=b-e;return o=!0,i<=0?(n.isCancel=!0,!1):(n.qty=i,!0)}else return!0});break}return o}_processOrders(e,t,r,o,n,b=!1,z,i){if(!e.length)return r;let s=r;for(const a of e)if(a.position_close_type=z||a.place_order_type,a.immediately=i,a.isTiggerClose=b||a.position_close_type==="close",s=this._processOrder(a,t,s,o,n,b),s<=0)break;return this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),s}_addPendingOrders(e,t,r,o,n){const b=this._pendingOrders.find(z=>z.id===e.id&&!z.isMarketPrice);if(b)Object.assign(b,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const z={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"order"};this._pendingOrders.push(z)}}_orderArgsParse(e){var q,_;const{direction:t,qty:r,stop:o}=e;let n=e.limit||0,{close:b}=this.calcOnOrderFillsData.data||this._variables;(_=(q=this.calcOnOrderFillsData)==null?void 0:q.tradeData)!=null&&_.open&&(b=this.calcOnOrderFillsData.tradeData.open);let z=b,i=!1,s;const a=t===i1.long?1:-1,O=o&&(o-b)*a>=0,{backtest_fill_limits_assumption:u=0}=this._options;u>0&&n&&(n-=u*this._mintick*a);const l=n&&(n-b)*a<=0;let d=!1;O&&l?(o!==b&&(s=o),z=n):O?(z=o,d=o===b):l?(z=n,d=n===b):i=!0;const A=r!==void 0?sc(r,this._getLen()):this._calcDefaultQty(z);return{orders:this._orders.filter(m=>m.direction!==t),isMarketPrice:i,activePrice:s,quantities:A,close:b,price:z,isTouch:d}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e);if(o<=0)return;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"entry"});return}this._judgeCapitalEnough(o,n,e.direction===i1.long?1:-1)&&this._addPendingEntry(e,b,o,r,z)}_entryOnCloseHandle(e){const{direction:t,in_price:r,qty:o=0}=e,n=this._orders.filter(b=>b.direction!==t);this._entryOrder(n,r,o,e)}_entryOrder(e,t,r,o){const{time:n,bar_index:b}=this._variables,{high:z,low:i}=this.calcOnOrderFillsData.data||this._variables,{slippage:s=0}=this._options,{oca_name:a,oca_type:O,direction:u,comment:l,id:d}=o,A=u===i1.long?1:-1;if(r=this._getAvailablePositionSize(r,u),r<=0)return;const h=t;if(t=t+s*this._mintick*A,!this._judgeCapitalEnough(r,t,A))return;this._closeOrders(e,h,d,l,"entry",void 0,!0);const _={...o,in_price:t,qty:r,in_index:b,in_high:z,in_low:i,in_time:n,place_order_type:"entry"},{orders:m}=this._getEntryOrders(u),L=m.length;L&&L>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,a,O),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:o}=this._risk;if(o&&o!==i1.all&&o!==t)return 0;if(r===void 0)return e;const n=this._orders.reduce((b,z)=>b+(z.qty||0),0);return n?n+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(o=>["entry","order"].includes(o.place_order_type)&&o.direction===e),r=this._orders.filter(o=>o.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,o,n){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:b}=this._getEntryOrders(e.direction),z=b.find(i=>i.id===e.id&&i.place_order_type==="entry");if(z)Object.assign(z,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const i={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"entry"};this._pendingOrders.push(i)}}_closeAllOrders(e,t){const{comment:r,immediately:o}=e,{bar_index:n}=this._variables,b=this._orders.filter(z=>z.in_index!==n);b.length&&(this._closeOrders(b,t,"Close position order",r,"close",o),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,o,n,b,z){if(e.length){for(const i of e)i.position_close_type=n,i.immediately=b,i.isTiggerClose=!0,this._closeOrder(i,t,r,o,z);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}}_closeOrder(e,t,r,o,n){const{time:b,bar_index:z}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables,{slippage:a=0}=this._options,{in_price:O,qty:u=0,direction:l}=e,d=l===i1.long?1:-1;t=t-d*a*this._mintick,e.isDeal=!0;const A=(t-O)*d*u,h={...e,out_price:t,out_id:r,out_index:z,out_high:i,out_low:s,out_time:b,out_comment:o,out_qty:u,profit:A};this._calcPercent(h,n)}_exitOrdersHandle(){if(!this._exitOrders.length)return;let{open:e,low:t,high:r,close:o}=this.calcOnOrderFillsData.data||this._variables;const n=[],b=Math.abs(r-e),z=Math.abs(t-e),i=[],s=this._variables.precision;e=Number(e.toFixed(s)),t=Number(t.toFixed(s)),r=Number(r.toFixed(s)),o=Number(o.toFixed(s));for(const a of this._exitOrders){const{directionNum:O,id:u,comment:l,qty:d,comment_loss:A,comment_profit:h,comment_trailing:q,order:_}=a;if(_.isTiggerClose)continue;let m=b<z||b===z&&O===1;if(_.in_time===this._variables.time&&!this._variables._isRepeated){const{in_price:D}=_;m?D<r&&D>=e?e=D:D<=r&&D>=o?r=D:r=o:D<=e&&D>t?e=D:D<=o&&D>=t?t=D:t=o,e=D}const L=[],[g,v]=this._getLimitPrice(a,e,t,r,m);g&&L.push({order:_,price:g,index:v,isHighFront:m,exitInfo:{id:u,comment:h||l,qty:d}});const[y,X]=this._getStopPrice(a,e,t,r,m);y&&L.push({order:_,price:y,index:X,isHighFront:m,exitInfo:{id:u,comment:A||l,qty:d}});const[T,N]=this._getTrailStopPrice(a,e,t,r,o,m);if(T&&L.push({order:_,price:T,index:N,isHighFront:m,exitInfo:{id:u,comment:q||l,qty:d}}),L.length){this._executesSort(L),n.push(L[0]);continue}i.push(a)}this._exitOrders=i,this._executesSort(n);for(const a of n){const{order:O,price:u,exitInfo:l,isHighFront:d,index:A}=a;d?(r=A===1?u:r,t=A===1?e:u):(r=A===1?e:u,t=A===1?u:t),this._variables.strategy.update({open:u,high:r,low:t,close:o}),this._processExitOnClose(O,u,l)}}_executesSort(e){return e.sort(({price:t,index:r,isHighFront:o},{price:n,index:b})=>r!==b?r-b:o?r===1?t-n:n-t:r===1?n-t:t-n),e}_getLimitPrice(e,t,r,o,n){const{limit:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z>=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getStopPrice(e,t,r,o,n){const{stop:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z<=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getTrailStopPrice(e,t,r,o,n,b){const{trail_stop_price:z,directionNum:i,active_price:s,trail_offset:a=0}=e;let O=z,u,l=1;if(O)if((O-t)*i>=0)u=t,l=1;else{const[d,A,h]=this._calcTrailStopPrice(O,o,r,n,a,i,b);u=A,l=h||1,e.trail_stop_price=d}if(s&&!u&&s<=o&&s>=r)if(a===0)u=s,b&&s>t||!b&&s<t?l=1:l=2;else{O=tn(s,Qt(a*i,this._mintick));let d=o,A=r;b?s>=t&&s<=o?(d=o,l=1):(b=!1,d=n,l=2):s<t&&s>=r?(A=r,l=1):(b=!0,A=n,l=2);const[h,q,_=1]=this._calcTrailStopPrice(O,d,A,n,a,i,b);delete e.active_price,l<_&&(l=_),e.trail_stop_price=h,u=q}return[u,l]}_ordersHandle(e){const t=this._orders.filter(b=>b.isMarketPriceLimit||b.isMarketPriceStop);if(!t.length)return;const{open:r,close:o}=this.calcOnOrderFillsData.data||this._variables,n=e?o:r;for(const b of t){const{out_comment:z,out_qty:i,out_id:s}=b;this._processExitOnClose(b,n,{id:s,comment:z,qty:i})}}_calcTrailStopPrice(e,t,r,o,n,b,z){let i=e,s;const a=tn(b===1?t:r,Qt(n*b,this._mintick));let O=1;return b===1?z?(i<a&&(i=a),i>=r&&(O=2,s=i)):i>=r?(O=1,s=i):a>i&&(i=a,a>=o&&(O=3,s=a)):z?i<=t?(O=1,s=i):a<i&&(i=a,a<=o&&(O=3,s=a)):(a<i&&(i=a),i<=t&&(O=2,s=i)),[i,s,O]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(z=>z.place_order_type==="exit");let r=[];for(const z of this._pendingOrders){const{isCancel:i,place_order_type:s,isMarketPrice:a}=z;if(i)continue;let O;switch(s){case"entry":if(!a){r.push(z);continue}this._entryOrderHandle(z);break;case"order":if(!a){r.push(z);continue}this._orderOrderHandle(z);break;case"close":O=this._closeOrderHandle(z);break;case"close_all":const{open:u}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(z,u);break}O&&e.push(O)}const o=this._options.pyramiding||1,n=this._orders.filter(z=>z.direction===i1.long).length<o,b=this._orders.filter(z=>z.direction===i1.short).length<o;r=r.filter(z=>z.direction===i1.long&&n||z.direction===i1.short&&b);for(const z of this._pendingOrderSort(r)){const{place_order_type:i}=z;let s;switch(i){case"entry":s=this._entryOrderHandle(z);break;case"order":s=this._orderOrderHandle(z);break}s&&e.push(s)}for(const z of t){const i=this._exitOrderHandle(z);i&&e.push(i)}this._pendingOrders=e}_pendingOrderSort(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,n=Math.abs(o-t)<=Math.abs(r-t);return e.sort(({in_price:b},{in_price:z})=>{let i=0,s=0;return n?(b>=t&&b<=o?i=1:i=2,z>=t&&z<=o?s=1:s=2):(b<=t&&b>=r?i=1:i=2,z<=t&&z>=r?s=1:s=2),i!==s?i-s:n?i===1?b-z:z-b:i===1?z-b:b-z}),e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const{close:e}=this.calcOnOrderFillsData.data||this._variables,t=[];for(const r of this._pendingCloseOrders)switch(r.place_order_type){case"close":const o=this._closeOrderHandle(r,!0);o&&t.push(o);break;case"close_all":this._closeAllOrders(r,e);break;case"entry":this._entryOnCloseHandle(r);break;case"order":this._orderOnCloseHandle(r);break}this._pendingCloseOrders=t,this._ordersHandle(!0)}_entryOrderHandle(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:n,qty:b=0,in_price:z,direction:i,active_price:s}=e;if(s&&o>=s&&r<=s)return delete e.active_price,e;let a=z;if(n)a=t;else{let{stop:O,limit:u}=e;const l=i===i1.long?1:-1,d=O&&(O-t)*l>=0,{backtest_fill_limits_assumption:A=0}=this._options;A>0&&u&&(u-=A*this._mintick*l);const h=u&&(u-t)*l<=0;d&&h||(O&&!d||u&&!h)&&(a=t)}if(a<=o&&a>=r){const O=this._orders.filter(u=>u.direction!==i);this._entryOrder(O,a,b,e)}else return e}_orderOrderHandle(e){const{time:t,bar_index:r}=this._variables,{open:o,low:n,high:b}=this.calcOnOrderFillsData.data||this._variables,{slippage:z=0}=this._options,{isMarketPrice:i,qty:s=0,in_price:a,direction:O,comment:u,oca_name:l,oca_type:d,active_price:A,id:h}=e;if(A&&b>=A&&n<=A)return delete e.active_price,e;let q=a,_=s;if(i&&(q=o),q<=b&&q>=n){const m=this._orders.filter(g=>g.direction!==O);if(m.length&&(_=this._processOrders(m,q,s,h,u,!1,"order"),_<=0))return;const L=O===i1.long?1:-1;this._ocaGroupVerify(_,l,d),this._calcCurrentOrder({...e,in_price:q-L*z*this._mintick,in_index:r,in_time:t,in_high:b,in_low:n,qty:_});return}else return e}_getCloseOrders(e){const{close_entries_rule:t="FIFO"}=this._options;let r=[];return t==="FIFO"?r=this._orders.filter(o=>o.id===e):r=this._orders.filter(o=>o.id===e&&!o.close_qty),r}_closeOrderHandle(e,t){const{id:r,qty:o,qty_percent:n=100,comment:b,immediately:z}=e,{close_entries_rule:i="FIFO"}=this._options,s=this._getCloseOrders(r);if(!s.length)return;let a=0;if(o?a=o:(a=s.reduce((l,d)=>l+(d.qty||0),a),a=n/100*a),a<=0)return;const{open:O,close:u}=this.calcOnOrderFillsData.data||this._variables;if(i==="FIFO")this._processOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,!1,"close",z);else if(this._processCloseOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,z))return e}_processCloseOrders(e,t,r,o,n,b){let z=!1;for(const i of e)i.close_qty=r,(i.qty||0)>r&&(z=!0),i.immediately=b,i.position_close_type="close",i.isTiggerClose=!0,this._processOrder(i,t,r,o,n);return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_exitOrderHandle(e){const{from_entry:t,id:r}=e,o=this._orders.filter(n=>{var b;return(!t||t===n.id)&&!((b=n.exitIds)!=null&&b.includes(r))});if(!(o.length&&!this._ordersToExit(o,e,!0)))return e}_exit(e,t){if(!e.hasOwnProperty("profit")&&!e.hasOwnProperty("loss")&&!e.hasOwnProperty("stop")&&!e.hasOwnProperty("limit")&&(!e.hasOwnProperty("trail_offset")||!e.hasOwnProperty("trail_price")&&!e.hasOwnProperty("trail_points"))){this._errorListener.addError(l1.strategyExitErr,t,$0.Error);return}const{profit:r,loss:o,stop:n,limit:b,trail_offset:z,trail_price:i,trail_points:s,from_entry:a="",id:O}=e;if(this._isNaN(r)&&this._isNaN(o)&&this._isNaN(n)&&this._isNaN(b)&&(this._isNaN(z)||this._isNaN(s)&&this._isNaN(i)))return;const u={...e,place_order_type:"exit"},l=this._orders.filter(q=>{var _;return(!a||a===q.id)&&!((_=q.exitIds)!=null&&_.includes(O))}),d=this._updateExitOrders(u),A=this._pendingOrders.filter(q=>(!a||a===q.id)&&["order","entry"].includes(q.place_order_type||""));if(l.length){if(!this._ordersToExit(l,u,!1))return}else if(!A.length||d)return;const h=this._pendingOrders.find(q=>q.id===O&&q.place_order_type==="exit");h?Object.assign(h,{...e}):this._pendingOrders.push(u)}_updateExitOrders(e){let t=!1;e.qty&&(e.qty=this._calcExitQty(e.qty));const r=this._exitOrders.filter(o=>o.id===e.id&&(o.from_entry===e.from_entry||!e.from_entry));for(const o of r){const{directionNum:n,order:b,qty:z}=o;if(b.isTiggerClose){o.isClose=!0;continue}t=!0;const i={qty:z,...e},s=!0;if(this._stopProfit(b,n,i,s)){o.isClose=!0;continue}if(this._stopLoss(b,n,i,s)){o.isClose=!0;continue}if(this._trailStopLoss(b,n,i,s)){o.isClose=!0;continue}Object.assign(o,i)}return this._exitOrders=this._exitOrders.filter(o=>!o.isClose),t}_ordersToExit(e,t,r){var q;const{qty:o,qty_percent:n=100,id:b,comment:z}=t;let i=o,s=!1;t.comment=z||b;const a=e[0],O={...t},{qty:u=0}=a,l=a.direction===i1.long?1:-1;return i=o?o>=u?u:o:n/100*u,O.qty=this._calcExitQty(i),i<u&&(s=!0),this._stopProfit(a,l,O,r)||this._stopLoss(a,l,O,r)||this._trailStopLoss(a,l,O,r)||(this._exitOrders.push({...O,directionNum:l,order:a}),a.exitIds?(q=a.exitIds)==null||q.push(b):a.exitIds=[b]),s}_addExitPendingCloseOrders(e){const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r,o){var A,h;const{limit:n,profit:b,comment_profit:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=I3(u,Qt(b*t,this._mintick))),r.limit=t===1?ac(O,this._variables.precision):uc(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t<=0)return e.isMarketPriceLimit=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r,o){var A,h;const{stop:n,loss:b,comment_loss:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=tn(u,Qt(b*t,this._mintick))),r.stop=t===1?uc(O,this._variables.precision):ac(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t>=0)return e.isMarketPriceStop=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r,o){var u,l;const{trail_offset:n,trail_price:b,trail_points:z,comment_trailing:i,comment:s,id:a,qty:O}=r;if(!this._isNaN(n)){const{in_price:d}=e,{process_orders_on_close:A}=this._options;let h;if(this._isNaN(b)?this._isNaN(z)||(h=I3(d,Qt(z*t,this._mintick))):h=b,r.active_price=h,o)return;let{close:q}=this.calcOnOrderFillsData.data||this._variables;if((l=(u=this.calcOnOrderFillsData)==null?void 0:u.tradeData)!=null&&l.open&&(q=this.calcOnOrderFillsData.tradeData.open),h!==void 0&&(h-q)*t<=0){const _=tn(q,Qt(n*t,this._mintick));if((_-q)*t>=0)return e.isMarketPriceStop=!0,r.comment=i||s,Object.assign(e,{out_comment:r.comment,out_id:a,out_qty:O}),A&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=_}}}_processExitOnClose(e,t,r){const{qty:o=0,comment:n,id:b}=r,{close_entries_rule:z="FIFO"}=this._options;if(o)if(e.isTiggerClose=!0,z==="FIFO")this._processExitOrders(this._orders,t,o,b,n);else{if(e.isDeal)return;this._processOrders([e],t,o,b,n,!1,"exit")}}_processExitOrders(e,t,r,o,n){let b=r,z;for(const i of e)if(z=i,i.position_close_type="exit",b=this._processOrder(i,t,b,o,n),b<=0)break;return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_processOrder(e,t,r,o,n,b=!1){const{time:z,bar_index:i}=this._variables,{low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:O=0}=this._options,{in_price:u,qty:l=0,max_profit:d,trading_loss:A,direction:h,commission:q=0,original_qty:_=0}=e,m=h===i1.long?1:-1;if(t=t-m*O*this._mintick,r<l){const L=l-r,g=(t-u)*m*r,v=d!==void 0?d/l*r:void 0,y=A!==void 0?A/l*r:void 0,X=q*L/_;this._calcPercent({...e,out_price:t,last_commission:X,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,profit:g,out_qty:r,max_profit:v,trading_loss:y});const T=(t-u)*m*L-X;Object.assign(e,{qty:L,profit:T,max_profit:d!==void 0?d-(v||0):void 0,trading_loss:A!==void 0?A-(y||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{e.isDeal=!0;const L=(t-u)*m*l;this._calcPercent({...e,out_price:t,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,out_qty:l,profit:L}),r-=l}return b&&(m===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(e,t){const{commission_value:r,process_orders_on_close:o}=this._options,{in_price:n,out_qty:b=0,out_price:z=0,original_qty:i=0,direction:s,last_commission:a=0,immediately:O}=e;let{profit:u=0,max_profit:l,trading_loss:d,commission:A=0}=e,h=n*b,q=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=u,r){const g=this._getCommission(z,b);this._totalChangeCapital-=g;let v=A*b/i;h+=v,v+=g,u=u-v,Object.assign(e,{commission:v});const y=this._orders.reduce((X,T)=>{const{qty:N=0,original_qty:D=0,commission:C=0}=T;return X+C*N/D},0);q+=y-a}const _=s===i1.long?1:-1;let[m,L]=this._calcProfitAndLossHandle(n,b,_,z);if(r){const g=A*b/i;m-=g,L-=g}l=Math.max(m,l||0),d=Math.min(L,d||0),u=parseFloat(String(u)),Object.assign(e,{max_profit:l,profit:u,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:u/q*100,profit_percent:u/h*100,max_profit_percent:l/h*100,trading_loss_percent:d/h*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(o?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(e),!t&&this._calcOrderFillsHandle(z,s,O)}_getCommission(e,t){const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:o=0,max_profit:n=0,trading_loss:b=0,direction:z,immediately:i}=e;let{profit:s=0}=e,a=r*o;const O=this._totalChangeCapital+this._options.initial_capital;if(t){const u=this._getCommission(r,o);this._totalChangeCapital-=u,s=s-u,a+=u,Object.assign(e,{commission:u,total_profit:this._totalChangeCapital})}s=parseFloat(String(s)),Object.assign(e,{original_qty:o,profit:s,total_profit_percent:s/O*100,profit_percent:s/a*100,max_profit_percent:n/a*100,trading_loss_percent:b/a*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders),t&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,z,i)}_calcOrderFillsHandle(e,t,r=!1){const{calc_on_order_fills:o,process_orders_on_close:n,slippage:b=0}=this._options;if(o){const{open:z,high:i,low:s,close:a}=this._variables,O=t===i1.long?1:-1,u=a-O*b*this._mintick;if((r||n)&&e===u)return;const l=z-O*b*this._mintick;let d={open:z,high:i,low:s,close:a},A={open:z,high:i,low:s,close:a},h=this.calcOnOrderFillsData.index;const q=Math.abs(i-z)<=Math.abs(s-z);switch(h){case-1:e===l?(h=0,A={open:z,high:z,low:z,close:z}):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 0:e===l?(h=1,q?(A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a})):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 1:h=2,q?(A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a});break;case 2:h=-1,d=void 0;break}this.calcOnOrderFillsData={tradeData:d,index:h,currentData:A}}}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_verfiyRequestFunc(e,t){B0(this._errorListener,`strategy.${t}`,this._variables.__requestName,e)}};class lp{constructor(e,t,r){E(this,"array");E(this,"color");E(this,"math");E(this,"str");E(this,"map");E(this,"matrix");E(this,"timeframe");E(this,"ta");E(this,"input");E(this,"_variables");E(this,"_cacheData");E(this,"_options");E(this,"_errorListener");E(this,"_plots");E(this,"_plotshapes");E(this,"_plotbars");E(this,"_plotchars");E(this,"_plotarrows");E(this,"_plotcandles");E(this,"_alerts");E(this,"_bgColors");E(this,"_hlines");E(this,"_fills");E(this,"chart");E(this,"line");E(this,"label");E(this,"polyline");E(this,"box");E(this,"table");E(this,"linefill");E(this,"log");E(this,"runtime");E(this,"strategy");E(this,"request");E(this,"syminfo");E(this,"_count",0);var n;const o=((n=e.toString().split(".")[1])==null?void 0:n.length)||5;this._variables=t,this._errorListener=new pm,this.array=new $4(this._errorListener),this.math=new U4(o),this.color=new A6,this.str=new f_(this._errorListener,o),this.map=new l_(this._errorListener),this.timeframe=new A_(t),this.matrix=new u_(this._errorListener),this.ta=new a6(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new u6(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new q_(t)},this.line=new P_(t,this._errorListener),this.label=new d_(t,this._errorListener),this.polyline=new I_(t,this._errorListener),this.box=new $_(t,this._errorListener),this.table=new U_(t,this._errorListener),this.linefill=new k_(t),this.log=new nm(t,this.str),this.runtime=new bm(this._errorListener),this.strategy=new rm(this._variables,this._options,e,this._errorListener,r),this.request=new Mm(this._variables,r,this,this._errorListener),this.syminfo=new om}get errors(){return this._errorListener.errors}get scriptType(){return this._options.scriptType}clearErrors(){this._errorListener.clear()}addErrors(e,t){this._errorListener.setErrors(e,t)}options(e,t){if(!t)return e.length?this._getDataOfBarindex(e):this._options;const r=this.input.getInputs(),o=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let b;if(n.length){b={};for(const _ of n)b[_]=[...this._bgColors[_].values()]}const z=this._hlines.size?[...this._hlines.values()]:void 0,i=this._fills.size?[...this._fills.values()]:void 0,s=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,strategySummary:this._variables.strategy.summaryData});const a=this._plots.size>0?[...this._plots.values()]:void 0,O=this._plotbars.size>0?[...this._plotbars.values()]:void 0,u=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,l=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,d=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,A=this._plotchars.size>0?[...this._plotchars.values()]:void 0,h=this._getDraws(),q=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{inputs:r,plots:a,draws:h,alerts:o,colors:b,hlines:z,fills:i,logs:s,plotshapes:u,plotarrows:l,plotcandles:d,plotchars:A,plotbars:O,isUseBgColor:q})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let o;if(r.length){o={};for(const q of r)o[q]=[...this._bgColors[q].values()].map(_=>{const m=[];for(const L of e){const g=_.data[L];g&&m.push(g)}return _.data=m,_})}const n=this._hlines.size?[...this._hlines.values()]:void 0,b=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,z=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 i=this._getDataFromBarindex(e,[...this._plots.values()]),s=this._plotbars.size>0?this._getDataFromBarindex(e,[...this._plotbars.values()]):void 0,a=this._plotarrows.size>0?this._getDataFromBarindex(e,[...this._plotarrows.values()]):void 0,O=this._plotcandles.size>0?this._getDataFromBarindex(e,[...this._plotcandles.values()]):void 0,u=this._plotchars.size>0?this._getDataFromBarindex(e,[...this._plotchars.values()]):void 0,l=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,d=this._getDrawDeletes(e),A=this._getDrawsFromBarindex(e),h=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{plots:i,plotarrows:a,plotcandles:O,plotchars:u,plotbars:s,draws:A,drawDeletes:d,alerts:t,colors:o,hlines:n,fills:b,logs:z,plotshapes:l,isUseBgColor:h})}_getDataFromBarindex(e,t){return t.map(r=>{const o=[];for(const n of e){const b=r.data[n];b&&o.push(b)}return r.data=o,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:o,polyline:n,label:b}=this._variables,z={};return e.size&&(z.lines=e.data),t.size&&(z.linefills=t.data),r.size&&(z.tables=r.data),o.size&&(z.boxes=o.data),n.size&&(z.polylines=n.data),b.size&&(z.labels=b.data),Object.keys(z).length?z:void 0}_getDrawsFromBarindex(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={};return t.size&&(i.lines=t.getValOfBarIndex(e)),r.size&&(i.linefills=r.getValOfBarIndex(e)),o.size&&(i.tables=o.getValOfBarIndex(e)),n.size&&(i.boxes=n.getValOfBarIndex(e)),b.size&&(i.polylines=b.getValOfBarIndex(e)),z.size&&(i.labels=z.getValOfBarIndex(e)),Object.keys(i).length?i:void 0}_getDrawDeletes(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={},s=t.getDeleteIds(e),a=r.getDeleteIds(e),O=o.getDeleteIds(e),u=n.getDeleteIds(e),l=b.getDeleteIds(e),d=z.getDeleteIds(e);return s.length&&(i.lines=s),a.length&&(i.linefills=a),O.length&&(i.tables=O),u.length&&(i.boxes=u),l.length&&(i.polylines=l),d.length&&(i.labels=d),i}updateOptions(e){var o;const{inputs:t,strategy:r}=e;this.input.update(t),r&&((o=this.strategy)==null||o.updateOptions(r))}update(e){const{barIndex:t}=e;this.strategy.update(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:o}=e;r.test(o)?(Bu.includes(o)||yu.includes(o))&&this._errorListener.addError(r2(l1.libraryTitleIsKeywordErr,{name:o}),t,$0.Error):this._errorListener.addError(l1.libraryTitleErr,t,$0.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r,max_bars_back:o=0}=e;this._variables.max_bars_back=o,this._paramVerfiy(r,t,"indicator",[O1.inherit,O1.percent,O1.price,O1.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,o,n="format"){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(vu.lineWidthWarning,t,$0.Warning),e.linewidth=1)}plot(e,t){const r=["color"];S1(e,r);const{series:o,color:n,...b}=e,{bar_index:z,time:i}=this._variables,s=`plot_${t}`,a=this._plots.get(s),O=(a==null?void 0:a.data)||[],u=o!==void 0&&isNaN(o)?void 0:o;if(O[z]={value:[i,u],barIndex:z,itemStyle:{color:n}},this._seriesColorHandle(e,r,a),!a){this._count++,this._lineWidthVerify(b,t),this._paramVerfiy(e.format,t,"plot",[O1.percent,O1.price,O1.volume]);const l=n?[n]:void 0;this._plots.set(s,{editable:!0,...b,colors:l,data:O,id:s,zIndex:this._count})}return{type:"plot",offset:e.offset||0,key:s}}plotbar(e,t){const r=["color"];S1(e,r);const{open:o,close:n,low:b,high:z,color:i,...s}=e,{bar_index:a,time:O}=this._variables,u=`plotbar_${t}`,l=this._plotbars.get(u),d=(l==null?void 0:l.data)||[],A=n!==void 0&&isNaN(n)?void 0:n,h=o!==void 0&&isNaN(o)?void 0:o,q=b!==void 0&&isNaN(b)?void 0:b,_=z!==void 0&&isNaN(z)?void 0:z,m=[O,h,A,q,_];if(d[a]={value:m,barIndex:a,itemStyle:{color:i}},this._seriesColorHandle(e,r,l),!l){this._count++,this._paramVerfiy(e.format,t,"plotbar",[O1.percent,O1.price,O1.volume]);const L=i?[i]:void 0;this._plotbars.set(u,{editable:!0,...s,colors:L,data:d,id:u,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:o,format:n,location:b,style:z}=e;this._paramVerfiy(z,r,t,Object.values(X2),"style"),this._paramVerfiy(b,r,t,Object.values(ke),"location"),this._paramVerfiy(o,r,t,Object.values(L2),"size"),this._paramVerfiy(n,r,t,[O1.percent,O1.price,O1.volume],"format")}plotchar(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,high:O,low:u}=this._variables,l=`plotchar_${t}`,d=this._plotchars.get(l),A=(d==null?void 0:d.data)||[],h={value:[a,o],barIndex:s,itemStyle:{color:n,textcolor:b},low:u,high:O};A[s]=h,this._seriesColorHandle(e,r,d),d||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(l,{editable:!0,...i,location:z,data:A,id:l,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];S1(e,r);const{series:o,colorup:n,colordown:b,...z}=e,{bar_index:i,time:s,low:a,high:O}=this._variables,u=`plotarrow_${t}`,l=this._plotarrows.get(u),d=(l==null?void 0:l.data)||[];d[i]={value:[s,o!==void 0&&isNaN(o)?void 0:o],barIndex:i,itemStyle:{colorup:n,colordown:b},low:a,high:O},this._seriesColorHandle(e,r,l),l||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[O1.percent,O1.price,O1.volume]),this._plotarrows.set(u,{editable:!0,...z,data:d,id:u,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,low:O,high:u}=this._variables,l=`plotshape_${t}`,d=this._plotshapes.get(l),A=(d==null?void 0:d.data)||[],h={value:o,barIndex:s,color:n,textcolor:b,time:a,low:O,high:u};if(A[s]=h,this._seriesColorHandle(e,r,d),!d){this._count++;const q=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(l,{editable:!0,...i,data:A,location:z,id:l,colors:q,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];S1(e,r);const{wickcolor:o,bordercolor:n,color:b,close:z,open:i,low:s,high:a,...O}=e,{bar_index:u,time:l}=this._variables,d=`plotcandle_${t}`,A=this._plotcandles.get(d),h=(A==null?void 0:A.data)||[],q=z!==void 0&&isNaN(z)?void 0:z,_=i!==void 0&&isNaN(i)?void 0:i,m=s!==void 0&&isNaN(s)?void 0:s,L=a!==void 0&&isNaN(a)?void 0:a,g=[l,_,q,m,L];h[u]={value:g,barIndex:u,wickcolor:o,bordercolor:n,color:b},this._seriesColorHandle(e,r,A),A||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[O1.percent,O1.price,O1.volume]),this._plotcandles.set(d,{editable:!0,...O,data:h,id:d,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;S1(e,["color"]),this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?A2.none:A2.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var X,T,N,D,C,P,H,G;const r=["color","top_color","bottom_color"];S1(e,r);const{color:o,top_color:n,bottom_color:b,seriesColors:z,hline1:i,hline2:s,plot1:a,plot2:O,top_value:u,bottom_value:l,...d}=e,{bar_index:A,time:h}=this._variables,q=`fill_${t}`,_=this._fills.get(q),m=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const L=e.display&&!e.display.length?A2.none:A2.all;let g,v,y="plot";if(i&&s)g=(X=this._hlines.get(i==null?void 0:i.key))==null?void 0:X.price,v=(T=this._hlines.get(s==null?void 0:s.key))==null?void 0:T.price,y="hline";else{const k=this._plots.get(a==null?void 0:a.key),J=this._plots.get(O==null?void 0:O.key),o0=(k==null?void 0:k.data)||[],z0=(J==null?void 0:J.data)||[];if(g=(D=(N=o0[A])==null?void 0:N.value)==null?void 0:D[1],v=(P=(C=z0[A])==null?void 0:C.value)==null?void 0:P[1],!A){const a0=(k==null?void 0:k.force_overlay)&&(J==null?void 0:J.force_overlay);(k!=null&&k.force_overlay||J!=null&&J.force_overlay)&&!a0?this._errorListener.addError(l1.plotFillForceOverlayErr,t,$0.Error):d.force_overlay=a0}}if(m[A]={time:h,color:o,top_color:n,bottom_color:b,barIndex:A,plot1:g,plot2:v,top_value:u,bottom_value:l},this._seriesColorHandle(e,r,_),!_){this._count++;const k=((H=this._options.indicator)==null?void 0:H.explicit_plot_zorder)||((G=this._options.strategy)==null?void 0:G.explicit_plot_zorder),J=o?[o]:void 0,o0=n?[n]:void 0,z0=b?[b]:void 0;this._fills.set(q,{id:q,colors:J,top_colors:o0,bottom_colors:z0,display:L,data:m,type:y,editable:!0,fillgaps:!1,hline1:i,hline2:s,plot1:a,plot2:O,...d,zIndex:k?this._count:void 0})}}alert({message:e,freq:t=Ae.freqOncePerBar},r){const{bar_index:o,_isRealTimeBar:n,last_bar_index:b}=this._variables,z=`alert_${r}`,i=this._cacheData[z]||{},s=i.barIndex;if(this._paramVerfiy(t,r,"alert",[Ae.freqAll,Ae.freqOncePerBar,Ae.freqOncePerBarClose]),t===Ae.freqOncePerBar&&o===s){this._alerts.delete(z);return}this._cacheData[z]=i;const a={message:e,freq:t,id:z,type:"alert"};if(n){t!==Ae.freqOncePerBarClose&&this._alerts.set(z,a),i.barIndex=o;return}if(!n&&t===Ae.freqOncePerBarClose&&o===s&&b===o-1){this._alerts.set(z,a),i.barIndex=o;return}this._alerts.delete(z)}alertcondition({condition:e,message:t,title:r},o){const{_isRealTimeBar:n}=this._variables,b=`alertcondition_${o}`;n&&e?this._alerts.set(b,{message:t,title:r,id:b,type:"alertcondition"}):this._alerts.delete(b)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=X3.all,t,r){e.length&&e.length<4&&this._errorListener.addError(r2(l1.displayErr,{func:t,values:"[display.none, display.all]"}),r,$0.Error)}_setColors(e,t,r){S1(e,["color"]);const{color:n,...b}=e;this._verifyDisplay(b.display,t,r);const z=e.display&&!e.display.length?A2.none:A2.all,{bar_index:i,time:s}=this._variables,a=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const O=this._bgColors[t].get(a),u=(O==null?void 0:O.data)||[],l=(O==null?void 0:O.setColors)||[];n&&!l.includes(n)&&l.push(n),u[i]={color:n,time:s,barIndex:i},O||this._bgColors[t].set(a,{...b,display:z,data:u,setColors:l,id:a})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||typeof e=="number"&&isNaN(e))}fixnan({source:e},t){return e===void 0||typeof e=="number"&&isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!(typeof e=="number"&&isNaN(e))?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o)}time_close({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o,!0)}timestamp(e){const{dateString:t,timezone:r,year:o,month:n,day:b,hour:z=0,minute:i=0,second:s=0}=e;if(t)return D1(t).utc(!/GMT|UTC/.test(t)).valueOf();let a=n-1,O=o;if(a<0){const u=Math.ceil(Math.abs(a/12));a=12*u+a,O=o-u}return $2({year:O,month:a,day:b,hour:z,minute:i,second:s},r).valueOf()}weekofyear({time:e,timezone:t}){return $2(e,t).week()}year({time:e,timezone:t}){return $2(e,t).year()}second({time:e,timezone:t}){return $2(e,t).second()}month({time:e,timezone:t}){return $2(e,t).month()+1}minute({time:e,timezone:t}){return $2(e,t).minute()}hour({time:e,timezone:t}){return $2(e,t).hour()}dayofweek({time:e,timezone:t}){return $2(e,t).day()+1}dayofmonth({time:e,timezone:t}){return $2(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,this._variables.timeframe.period),o=N2(t,e)*1e3;return e-r-Math.floor((e-r)/o)*o}_timeHandle(e,t,r="",o,n,b=0,z=!1){const i=r||this._variables.__period,s=N2(i,e),a=N2(this._variables.__period,e);let O;if(s<=a)O=e,z&&(O+=a*1e3);else{const u=`time_${t}`,l=this._cacheData[u];if(l)l.currentTime+s*1e3-l.offset<=e?(O=e,this._cacheData[u]={currentTime:e,offset:0}):O=l.currentTime;else{const d=this._calcTimeOffset(e,i);this._cacheData[u]={currentTime:e,offset:d},O=e}z&&(O+=s*1e3)}if(o&&o!==ut.regular&&o!==ut.extended){const{timePeriods:u,weeks:l}=this._parserSession(o,t),d=$2(e,n),A=d.format("YYYY-MM-DD HH:mm"),h=d.format("YYYY-MM-DD"),q=O,_=$2(O,n).format("YYYY-MM-DD HH:mm");O=void 0;for(const L of u){const[g,v]=L;let y;if((g===v||Number(g==null?void 0:g.replace(":",""))>Number(v==null?void 0:v.replace(":","")))&&(y=d.add(1,"day").format("YYYY-MM-DD")),D1(A).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")){D1(_).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")?O=q:O=$2(`${h} ${g}`,n).valueOf();break}}const m=this._variables.dayofweek;O&&!l.includes(m)&&(O=void 0)}return O&&O-b*a*1e3}_seriesColorHandle(e,t,r){var o;if(r&&t!=null&&t.length)for(const n of t){if((o=r.gradientColorKeys)!=null&&o.includes(n))continue;const b=e[n];if(!b)continue;const z=r[`${n}s`]||[];z.includes(b)||(z.push(b),r[`${n}s`]=z,z.length>5&&(r[`${n}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(n)))}}_parserSession(e,t){const r=e.split(":"),o=r[0],b=(r[1]||"1234567").split("").map(i=>{const s=parseInt(i,10);if(s<1||s>7){this._errorListener.addError(`Invalid day of week: ${i}`,t,$0.Error);return}return s});return{timePeriods:o.split(",").map(i=>{i===""||i===ut.regular?i="0930-1500":i===ut.extended&&(i="1500-1830");const s=i.split("-");return s.length!==2?[]:[this._processTime(s[0],t),this._processTime(s[1],t)]}),weeks:b}}_processTime(e,t){const r=e.slice(0,2),o=e.slice(2),n=parseInt(r,10),b=parseInt(o,10);if(!(n>=0&&n<=23)&&b>=0&&b<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,$0.Error);return}return`${r}:${o}`}}let Mm=class{constructor(e,t,r,o){E(this,"_variables");E(this,"_scriptId");E(this,"_cacheData");E(this,"_funcs");E(this,"_errorListener");this._variables=e,this._scriptId=t,this._cacheData=new Map,this._funcs=r,this._errorListener=o}security(e,t){var d;const r=self.workerStorage.get(`request_${this._scriptId}`),{__requestName:o,__period:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||n;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${o}${t}_${s}`,O=this._getRequestData(e,a);if(r!=null&&r.has(a))return(d=O==null?void 0:O.result)==null?void 0:d[a];const u=this._parseExprCode(e),l=this._runScriptHandle(u,a,i,O,!0);return r==null||r.set(a,{id:a,isRun:!1,strJs:u,dataId:s,interval:z,symbol:b,paramsExpr:i}),l}security_lower_tf(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{__period:o,__requestName:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||o;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${n}${t}_${s}`,O=r==null?void 0:r.get(a),u=this._getRequestLowerTfData(e,t,a,O==null?void 0:O.defaultResult),l=new n1(0,void 0,this._errorListener);if(O!=null&&O.strJs)return O!=null&&O.defaultResult?u!=null&&u.length?u.map(q=>{const _=new n1(0,void 0,this._errorListener);return _._value=q,_}):O==null?void 0:O.defaultResult:u&&(l._value=u,l);const d=this._parseExprCode(e),A={id:a,strJs:d,isRun:!1,dataId:s,interval:z,symbol:b,paramsExpr:i,defaultResult:void 0};r==null||r.set(a,A);const h=this._runScriptHandle(d,a,i,u,!0);return Array.isArray(h)?(A.defaultResult=h.map(()=>new n1(0,void 0,this._errorListener)),A.defaultResult):l}_symbolTransform(e){if(!e)return this._variables.syminfo.tickerid;let[t,r]=e.split(":");return r?t=Du[t]||t:(t="FX",r=t),`${t}:${r}`}_runScriptHandle(e,t,r,o,n){const{result:b,logs:z,errors:i}=this._runScripts(e,t,n,r,o);return this._funcs.log.mergeLogs(z),this._funcs.addErrors(i,t),b}_getCurrentData(e){let{symbol:t,timeframe:r}=e;const{__period:o,syminfo:{ticker:n,tickerid:b}}=this._variables;if(r=hr(r),(o===r||r==="")&&(t===n||t===b||!t)){const{close:z,open:i,high:s,low:a,bar_index:O,last_bar_index:u,last_bar_time:l,_isRealTimeBar:d,volume:A,time:h,time_tradingday:q,mintick:_,nextBarTime:m}=this._variables;return{barIndex:O,c:z,o:i,h:s,l:a,volume:A,lastBarIndex:u,lastBarTime:l/1e3,nextBarTime:m?m/1e3:void 0,isrealtime:d,time_tradingday:q,time:h/1e3,interval:o,mintick:_}}}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,o=[];t=cc(t);const n=JSON.parse(t),b=n.pop();let z=(b==null?void 0:b.memberCodes)||{},i=(b==null?void 0:b.depends)||[];if(!i.length)return`return ${b==null?void 0:b.code}`;let s=[],a=[],O=[];if(this._getDependCodes(i,n,o,s,a,O),this._getStmtFuncs(o,n,O,s,a),a.length){const h=r.length;for(let q=h-1;q>=0;q--){const _=r[q];let m=JSON.parse(cc(_));const L=[];m=m.map(y=>{const{scope:X,code:T,varNames:N,dependSelf:D}=y;return X===2&&!L.includes(N)&&!D&&(y.code=`let ${T}`),N&&L.push(...N.split(", ")),y.memberCodes&&Object.assign(z,{...y.memberCodes}),y});const g=[];let v=a.map(y=>({...y,isArg:!1,isPreArg:!0}));a=[],this._getDependCodes(v,m,o,s,a,g),this._getStmtFuncs(o,m,g,s,a)}}const u=o.filter(h=>!!h).map((h,q)=>{let _=h.join(`
|
76
|
+
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t==null?void 0:t.replace(/0/g,"#")))}_arrToStr(e,t){return`[${e.map(o=>typeof o=="number"?this._toStringFormat(o,t):o).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return d0(t)&&(t=0),d0(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return d0(e)&&(e=0),$2(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e==null?void 0:e.toFixed(10));switch(t){case O1.mintick:return e==null?void 0:e.toFixed(this._precision);case O1.percent:return`${Number(e.toFixed(2))}%`;case O1.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var z;let[r,o]=t.split(".");t.split("%").length===2&&(e=e*100);let[n,b=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const i=r.split(","),s=((z=i[i.length-1])==null?void 0:z.replace(/[^#]/g,"").length)||0;s&&(n=n.replace(new RegExp(`\\B(?=(\\d{${s}})+(?!\\d))`,"g"),",")),r=i.join("")}n=r.replace(/#/,n).replace(/#/g,"")}else n=`${r}${n}`;if(o&&o.includes("#")){const i=o.split("#").length-1,s=+`${n}.${b}`;if(!isNaN(s))return+`${s.toFixed(i)}${o.replace(/#/g,"")}`;b=`${b.substring(0,i)}${o.replace(/#/g,"")}`}else b=o||"";return b?+`${n}.${b}`:n}_formatNumber(e,t){if(!t)return Number(e==null?void 0:e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}strformat({formatString:e=""},t,r){return this._strFormat(e,t,r)}_strFormat(e,t,r){return e.replace(/{[^{}]+}/g,o=>{if(!o)return o;const n=o.replace(/[{}]/g,"").split(","),b=Number(n[0]);if(isNaN(b)||t.length<=b)return o;const z=t[b];if(n.length===1)return typeof z=="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):z===void 0?"":z;if(n.length===2){const i=n[1].trim();return i==="number"?r?this._intlFormat.format(z):Number(z.toFixed(this._precision)):i==="date"?D1(z).format("LL"):o}else{const i=n[1].trim(),s=n[2].trim();if(i==="number")return this._formatNumber(z,s);if(i==="date"){let a="YYYY-MM-DD";switch(s){case"long":a="LL";break;case"short":a="L";break;default:s&&(a=s)}return D1(z).format(a)}return o}})}}class l_{constructor(e){E(this,"_errorListener");this._errorListener=e}new(){return new Ap(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class Ap{constructor(e){E(this,"_errorListener");E(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}get _value(){return this._mapInstance}_copyMap(e){const t=new Ap(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new n1(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class q_{constructor(e){E(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Er(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Er(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Er(e,t)}from_time({price:e,time:t}){return new Er(e,void 0,t)}}class Er{constructor(e,t,r){E(this,"_index");E(this,"_price");E(this,"_time");this._index=t&&Math.round(t),this._price=e,this._time=r}get index(){return this._index}set index(e){this._index=e&&Math.round(e)}get price(){return this._price}set price(e){this._price=e}get time(){return this._time}set time(e){this._time=e}copy(){return new Er(this._price,this._index,this._time)}}class d_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLabel",{text:"",xloc:P1.bar_index,yloc:le.price,size:L2.normal,style:T1.styleLabelDown,textalign:t1.alignCenter});this._variables=e,this._errorListener=t}new(e,t){B0(this._errorListener,"label.new",this._variables.__requestName,t);const{time:r,high:o,low:n,bar_index:b}=this._variables,z=`label_${t}_${b}`;S1(e,["color","textcolor"]);const i={...this._defaultLabel,...e,id:z,time:r,high:o,low:n,bar_index:b};e.x&&(i.x=e.x&&Math.round(e.x)),e.point&&(i.x=i.xloc===P1.bar_index?e.point.index:e.point.time,i.y=e.point.price),i.yloc===le.abovebar?i.y=o:i.yloc===le.belowbar&&(i.y=n),this._verfiyArgs(e,t);const s=new Ko(z,this._variables,this._errorListener,i);return t.startsWith("export")||this._variables.label.add(z,i,s),s}_verfiyArgs(e,t){const{xloc:r,yloc:o,style:n,size:b,textalign:z,text_font_family:i}=e,s="label.new";this._paramVerfiy(n,t,s,Object.values(T1),"style"),this._paramVerfiy(r,t,s,Object.values(P1),"xloc"),this._paramVerfiy(o,t,s,Object.values(le),"yloc"),this._paramVerfiy(b,t,s,Object.values(L2),"size"),this._paramVerfiy(z,t,s,[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign"),this._paramVerfiy(i,t,s,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}label(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e},t){e==null||e.delete(t)}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Ko{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get type(){return Q0.LABEL}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.label.get(this._id)||this._data}copy(e){B0(this._errorListener,"label.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`label_${e}_${t}`,o=this._getLabel(e),n={...o||{},id:r,bar_index:t},b=new Ko(r,this._variables,this._errorListener,n);return o&&this._variables.label.add(r,n,b),b}get_x(e){var t;return B0(this._errorListener,"label.get_x",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return B0(this._errorListener,"label.get_y",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){B0(this._errorListener,"label.set_x",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=e&&Math.round(e))}set_y({y:e},t){B0(this._errorListener,"label.set_y",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.y=e)}delete(e){B0(this._errorListener,"label.delete",this._variables.__requestName,e),this._variables.label.delete(this._id,this._variables.bar_index,this._data.id)}set_xy({x:e,y:t},r){B0(this._errorListener,"label.set_xy",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.y=t)}get_text(e){var t;return B0(this._errorListener,"label.get_text",this._variables.__requestName,e),(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){B0(this._errorListener,"label.set_size",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(L2),"size")}set_text({text:e},t){B0(this._errorListener,"label.set_text",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){B0(this._errorListener,"label.set_xloc",this._variables.__requestName,r);const o=this._getLabel(r);o&&(o.x=e&&Math.round(e),o.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(P1),"xloc"))}set_yloc({yloc:e},t){B0(this._errorListener,"label.set_yloc",this._variables.__requestName,t);const r=this._getLabel(t),{high:o,low:n}=this._variables;r&&(r.yloc=e,e===le.abovebar?r.y=o:e===le.belowbar&&(r.y=n),this._paramVerfiy(e,t,"label.set_yloc",Object.values(le),"yloc"))}set_color(e,t){B0(this._errorListener,"label.set_color",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){B0(this._errorListener,"label.set_point",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.x=r.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){B0(this._errorListener,"label.set_style",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(T1),"style")}set_tooltip({tooltip:e},t){B0(this._errorListener,"label.set_tooltip",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){B0(this._errorListener,"label.set_textalign",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"textalign")}set_textcolor(e,t){B0(this._errorListener,"label.set_textcolor",this._variables.__requestName,t);const r=this._getLabel(t);S1(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"label.set_text_font_family",this._variables.__requestName,t);const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLabel(e){const t=this._variables.label.get(this._id)||this._data;return t||console.log(`错误${e}: label 不存在`),t}}const h_={freq_all:Ae.freqAll,freq_once_per_bar:Ae.freqOncePerBar,freq_once_per_bar_close:Ae.freqOncePerBarClose},W_={gaps_off:Pe.gapsOff,gaps_on:Pe.gapsOn,lookahead_off:Pe.lookaheadOff,lookahead_on:Pe.lookaheadOn},Tr={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"},D3={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"},__={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},X3={all:[A2.dataWindow,A2.pane,A2.priceScale,A2.statusLine],data_window:[A2.dataWindow],none:[],pane:[A2.pane],price_scale:[A2.priceScale],status_line:[A2.statusLine]},m_={both:fe.both,left:fe.left,none:fe.none,right:fe.right},g_={inherit:O1.inherit,mintick:O1.mintick,percent:O1.percent,price:O1.price,volume:O1.volume},R_={style_solid:kM.styleSolid,style_dashed:kM.styleDashed,style_dotted:kM.styleDotted},L_={style_arrowdown:T1.styleArrowdown,style_arrowup:T1.styleArrowup,style_circle:T1.styleCircle,style_cross:T1.styleCross,style_diamond:T1.styleDiamond,style_flag:T1.styleFlag,style_label_center:T1.styleLabelCenter,style_label_down:T1.styleLabelDown,style_label_left:T1.styleLabelLeft,style_label_lower_left:T1.styleLabelLowerLeft,style_label_lower_right:T1.styleLabelLowerRight,style_label_right:T1.styleLabelRight,style_label_up:T1.styleLabelUp,style_label_upper_left:T1.styleLabelUpperLeft,style_label_upper_right:T1.styleLabelUpperRight,style_none:T1.styleNone,style_square:T1.styleSquare,style_text_outline:T1.styleTextOutline,style_triangledown:T1.styleTriangledown,style_triangleup:T1.styleTriangleup,style_xcross:T1.styleXcross},v_={style_arrow_both:n2.styleArrowBoth,style_arrow_left:n2.styleArrowLeft,style_arrow_right:n2.styleArrowRight,style_dashed:n2.styleDashed,style_dotted:n2.styleDotted,style_solid:n2.styleSolid},N_={abovebar:ke.abovebar,absolute:ke.absolute,belowbar:ke.belowbar,bottom:ke.bottom,top:ke.top},y_={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},B_={style_area:ee.styleArea,style_areabr:ee.styleAreabr,style_circles:ee.styleCircles,style_columns:ee.styleColumns,style_cross:ee.styleCross,style_histogram:ee.styleHistogram,style_line:ee.styleLine,style_linebr:ee.styleLinebr,style_stepline:ee.styleStepline,style_stepline_diamond:ee.styleSteplineDiamond,style_steplinebr:ee.styleSteplinebr},w_={bottom_center:P2.bottomCenter,bottom_left:P2.bottomLeft,bottom_right:P2.bottomRight,middle_center:P2.middleCenter,middle_left:P2.middleLeft,middle_right:P2.middleRight,top_center:P2.topCenter,top_left:P2.topLeft,top_right:P2.topRight},D_={left:$M.left,none:$M.none,right:$M.right},X_={arrowdown:X2.arrowdown,arrowup:X2.arrowup,circle:X2.circle,cross:X2.cross,diamond:X2.diamond,flag:X2.flag,labeldown:X2.labeldown,labelup:X2.labelup,square:X2.square,triangledown:X2.triangledown,triangleup:X2.triangleup,xcross:X2.xcross},E_={auto:L2.auto,huge:L2.huge,large:L2.large,normal:L2.normal,small:L2.small,tiny:L2.tiny},T_={cash:b2.cash,fixed:b2.fixed,percent_of_equity:b2.percentOfEquity,commission:{cash_per_contract:O2.cashPerContract,cash_per_order:O2.cashPerOrder,percent:O2.percent},direction:{all:i1.all,long:i1.long,short:i1.short},oca:{cancel:Ue.cancel,none:Ue.none,reduce:Ue.reduce}},C_={align_bottom:t1.alignBottom,align_center:t1.alignCenter,align_left:t1.alignLeft,align_right:t1.alignRight,align_top:t1.alignTop,wrap_auto:t1.wrapAuto,wrap_none:t1.wrapNone},x_={bar_index:P1.bar_index,bar_time:P1.bar_time},S_={abovebar:le.abovebar,belowbar:le.belowbar,price:le.price},F_={actual:UM.actual,estimate:UM.estimate,standardized:UM.standardized};class fp{constructor(){E(this,"adjustment",{dividends:PM.dividends,none:PM.none,splits:PM.splits});E(this,"alert",h_);E(this,"barmerge",W_);E(this,"color",Tr);E(this,"currency",D3);E(this,"dayofweek",__);E(this,"earnings",F_);E(this,"display",X3);E(this,"extend",m_);E(this,"font",{family_default:St.familyDefault,family_monospace:St.familyMonospace});E(this,"format",g_);E(this,"hline",R_);E(this,"label",L_);E(this,"line",v_);E(this,"location",N_);E(this,"math",y_);E(this,"order",{ascending:$e.ascending,descending:$e.descending});E(this,"plot",B_);E(this,"position",w_);E(this,"scale",D_);E(this,"session",{extended:ut.extended,regular:ut.regular});E(this,"shape",X_);E(this,"size",E_);E(this,"splits",{denominator:"denominator",numerator:"numerator"});E(this,"strategy",T_);E(this,"text",C_);E(this,"xloc",x_);E(this,"yloc",S_)}updateData(){}}class I_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:P1.bar_index,line_color:Tr.blue,line_style:n2.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var z;B0(this._errorListener,"polyline.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`polyline_${t}_${r}`,n=Object.assign({},this._defaultPolyline,e,{id:o,bar_index:r,points:(z=e.points)==null?void 0:z._value.map(i=>({time:i.time,index:i.index,price:i.price}))});S1(n,["line_color","fill_color"]);const b=new E3(o,this._variables,n);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(o,n,b),b}_verfiyArgs(e,t){const{line_style:r,xloc:o}=e,n="polyline.new";this._paramVerfiy(r,t,n,Object.values(n2),"line_style"),this._paramVerfiy(o,t,n,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}delete({id:e}){e&&e.delete()}}class E3{constructor(e,t,r){E(this,"_id");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=t,this._id=e,this._data=r}get type(){return Q0.POLYLINE}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.polyline.get(this._id)||this._data}delete(){this._variables.polyline.delete(this._id,this._variables.bar_index,this._data.id)}}class P_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultLine",{xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},o){B0(this._errorListener,"line.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`line_${o}_${n}`;S1(r,["color"]);const z={...this._defaultLine,...r,id:b,bar_index:n},{x1:i,x2:s}=z;if(i&&(z.x1=i&&Math.round(i)),s&&(z.x2=s&&Math.round(s)),e&&t){const O=z.xloc===P1.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,u=z.xloc===P1.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(z,{x1:O,y1:e==null?void 0:e.price,x2:u,y2:t==null?void 0:t.price})}this._verfiyArgs(r,o);const a=new Jo(b,this._variables,this._errorListener,z);return o.startsWith("export")||this._variables.line.add(b,z,a),a}_verfiyArgs(e,t){const{extend:r,xloc:o,style:n}=e,b="line.new";this._paramVerfiy(n,t,b,Object.values(n2),"style"),this._paramVerfiy(r,t,b,Object.values(fe),"extend"),this._paramVerfiy(o,t,b,Object.values(P1),"xloc")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}line(e){return e.x}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class Jo{constructor(e,t,r,o){E(this,"_variables");E(this,"_id");E(this,"_suffix","");E(this,"_errorListener");E(this,"_fillKeys",[]);E(this,"_preId","");E(this,"_data");this._id=e,this._variables=t,this._errorListener=r,this._data=o}get id(){return this._id}get __fillKeys(){return this._fillKeys}__setFillKeys(e){this._fillKeys.includes(e)||this._fillKeys.push(e)}__updateFillKeys(e,t){const r=this._fillKeys.findIndex(o=>o===e);r!==-1?this._fillKeys.splice(r,1,t):this._fillKeys.push(t)}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get type(){return Q0.LINE}set data(e){this._data=e}get data(){return this._variables.line.get(this._id)||this._data}get originData(){return this._data}copy(e){const{bar_index:t}=this._variables,r=`line_${e}_${t}`,o=this._getLine(e,"copy"),n={...o,id:r,bar_index:t,isVar:void 0},b=new Jo(r,this._variables,this._errorListener,n);return o&&this._variables.line.add(r,n,b),b}delete(e){B0(this._errorListener,"line.delete",this._variables.__requestName,e);for(const t of this._fillKeys)this._variables.linefill.delete(t,this._variables.bar_index);this._variables.line.delete(this._id,this._variables.bar_index,this._data.id)}get_price({x:e},t){const r=this._getLine(t,"get_price");if(e===void 0)return e;if(r&&r.xloc===P1.bar_index){const{x1:o,y1:n,x2:b,y2:z}=r;return o===void 0||b===void 0||n===void 0||z===void 0?void 0:(z-n)/(b-o)*(e-o)+n}}get_x1(e){var t;return(t=this._getLine(e,"get_x1"))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e,"get_x2"))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e,"get_y1"))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e,"get_y2"))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t,"set_x1");r&&(r.x1=e&&Math.round(e))}set_x2({x:e},t){const r=this._getLine(t,"set_x2");r&&(r.x2=e&&Math.round(e))}set_y1({y:e},t){const r=this._getLine(t,"set_y1");r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t,"set_y2");r&&(r.y2=e)}set_xy1({x:e,y:t},r){const o=this._getLine(r,"set_xy1");o&&(o.x1=e&&Math.round(e),o.y1=t)}set_xy2({x:e,y:t},r){const o=this._getLine(r,"set_xy2");o&&(o.x2=e&&Math.round(e),o.y2=t)}set_xloc({xloc:e,x1:t,x2:r},o){const n=this._getLine(o,"set_xloc");n&&(n.xloc=e,n.x1=t&&Math.round(t),n.x2=r&&Math.round(r),this._paramVerfiy(e,o,"line.set_xloc",Object.values(P1),"xloc"))}set_color(e,t){const r=this._getLine(t,"set_color");r&&(S1(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t,"set_style");r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(n2),"style"))}set_width({width:e},t){const r=this._getLine(t,"set_width");r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t,"set_extend");r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(fe),"extend"))}set_first_point({point:e},t){const r=this._getLine(t,"set_first_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x1=z),i&&(r.y1=i)}}set_second_point({point:e},t){const r=this._getLine(t,"set_second_point");if(r){const{index:o,time:n,price:b}=e||{},z=r.xloc===P1.bar_index?o:n,i=b;z&&(r.x2=z),i&&(r.y2=i)}}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getLine(e,t){B0(this._errorListener,`line.${t}`,this._variables.__requestName,e);const r=this._variables.line.get(this._id)||this._data;return r||console.log(`${e}: line 不存在`),r}}class k_{constructor(e){E(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:o}=e,{bar_index:n}=this._variables,b=`linefill_${t}_${n}`,z=r==null?void 0:r.data,i=o==null?void 0:o.data;z&&(z.linefills=z.linefills||[],z.linefills.push(b)),i&&(i.linefills=i.linefills||[],i.linefills.push(b)),S1(e,["color"]),r==null||r.__setFillKeys(b),o==null||o.__setFillKeys(b);const s={line1:z,line2:i,color:e.color,id:b,bar_index:n},a=new T3(this._variables,b,s,r,o);return t.startsWith("export")||(z||i)&&this._variables.linefill.add(b,s,a),a}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class T3{constructor(e,t,r,o,n){E(this,"_id");E(this,"_line1");E(this,"_line2");E(this,"_variables");E(this,"_suffix");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._line1=o,this._line2=n,this._data=r}get type(){return Q0.LINEFILL}get id(){return this._id}get preId(){return this._preId}updateId(){var o,n;const{bar_index:e,_isRealTimeBar:t}=this._variables,r=this._id;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const b=this._id.split("_");b.pop(),this._id=`${b.join("_")}_${e}`}return(o=this._line1)==null||o.__updateFillKeys(r,this._id),(n=this._line2)==null||n.__updateFillKeys(r,this._id),t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.linefill.get(this._id)||this._data}linefill(e){return e.x}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:o,line2:n}=e;o&&(o.linefills=(t=o.linefills)==null?void 0:t.filter(b=>b!==this._id)),n&&(n.linefills=(r=n.linefills)==null?void 0:r.filter(b=>b!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id,this._variables.bar_index,this._data.id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(e){const t=this._variables.linefill.get(this._id);t&&(S1(e,["color"]),t.color=e.color)}}class $_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultBox",{border_color:Tr.blue,border_width:1,bgcolor:Tr.blue,xloc:P1.bar_index,extend:fe.none,style:n2.styleSolid,text:"",text_size:L2.auto,text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_wrap:t1.wrapNone});this._variables=e,this._errorListener=t}box({x:e}){return e}new({top_left:e,bottom_right:t,...r},o){B0(this._errorListener,"box.new",this._variables.__requestName,o);const{bar_index:n}=this._variables,b=`box_${o}_${n}`,z={...this._defaultBox,...r,id:b,bar_index:n};S1(z,["border_color","bgcolor","text_color"]);const{left:i,right:s}=z;if(i&&(z.left=i&&Math.round(i)),s&&(z.right=s&&Math.round(s)),e){const{price:O,time:u,index:l}=e;z.top=O,z.left=z.xloc===P1.bar_index?l:u}if(t){const{price:O,time:u,index:l}=t;z.bottom=O,z.right=z.xloc===P1.bar_index?l:u}this._verfiyArgs(r,o);const a=new Qo(this._variables,b,this._errorListener,z);return o.startsWith("export")||this._variables.box.add(b,z,a),a}_verfiyArgs(e,t){const{border_style:r,extend:o,xloc:n,text_size:b,text_halign:z,text_valign:i,text_wrap:s,text_font_family:a}=e,O="box.new";this._paramVerfiy(r,t,O,[n2.styleDashed,n2.styleDotted,n2.styleSolid],"border_style"),this._paramVerfiy(o,t,O,Object.values(fe),"extend"),this._paramVerfiy(n,t,O,Object.values(P1),"xloc"),this._paramVerfiy(b,t,O,Object.values(L2),"text_size"),this._paramVerfiy(z,t,O,[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"),this._paramVerfiy(i,t,O,[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"),this._paramVerfiy(s,t,O,[t1.wrapAuto,t1.wrapNone],"text_wrap"),this._paramVerfiy(a,t,O,Object.values(St),"text_font_family")}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e},t){e==null||e.delete(t)}get_top({id:e},t){return e==null?void 0:e.get_top(t)}get_bottom({id:e},t){return e==null?void 0:e.get_bottom(t)}get_left({id:e},t){return e==null?void 0:e.get_left(t)}get_right({id:e},t){return e==null?void 0:e.get_right(t)}set_top({id:e,...t},r){e==null||e.set_top(t,r)}set_bottom({id:e,...t},r){e==null||e.set_bottom(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_left({id:e,...t},r){e==null||e.set_left(t,r)}set_right({id:e,...t},r){e==null||e.set_right(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({id:e,...t},r){e==null||e.set_border_width(t,r)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t},r){e==null||e.set_lefttop(t,r)}set_rightbottom({id:e,...t},r){e==null||e.set_rightbottom(t,r)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t},r){e==null||e.set_text_color(t,r)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t},r){e==null||e.set_top_left_point(t,r)}set_bottom_right_point({id:e,...t},r){e==null||e.set_bottom_right_point(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class Qo{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.BOX}get id(){return this._id}get preId(){return this._preId}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}set data(e){this._data=e}get data(){return this._variables.box.get(this._id)||this._data}copy(e){B0(this._errorListener,"box.copy",this._variables.__requestName,e);const{bar_index:t}=this._variables,r=`box_${e}_${t}`,o=this._getBox(),n={...o,id:r,bar_index:t},b=new Qo(this._variables,r,this._errorListener,n);return o&&this._variables.box.add(r,n,b),b}delete(e){B0(this._errorListener,"box.delete",this._variables.__requestName,e),this._variables.box.delete(this._id,this._variables.bar_index,this._data.id)}get_top(e){B0(this._errorListener,"box.get_top",this._variables.__requestName,e);const t=this._getBox();return t&&t.top}set_top({top:e},t){B0(this._errorListener,"box.set_top",this._variables.__requestName,t);const r=this._getBox();r&&(r.top=e)}get_left(e){B0(this._errorListener,"box.get_left",this._variables.__requestName,e);const t=this._getBox();return t&&t.left}set_left({left:e},t){B0(this._errorListener,"box.set_left",this._variables.__requestName,t);const r=this._getBox();r&&(r.left=e&&Math.round(e))}set_text({text:e},t){B0(this._errorListener,"box.set_text",this._variables.__requestName,t);const r=this._getBox();r&&(r.text=e)}get_right(e){B0(this._errorListener,"box.get_right",this._variables.__requestName,e);const t=this._getBox();return t&&t.right}set_right({right:e},t){B0(this._errorListener,"box.set_right",this._variables.__requestName,t);const r=this._getBox();r&&(r.right=e&&Math.round(e))}get_bottom(e){B0(this._errorListener,"box.get_bottom",this._variables.__requestName,e);const t=this._getBox();return t&&t.bottom}set_bottom({bottom:e},t){B0(this._errorListener,"box.set_bottom",this._variables.__requestName,t);const r=this._getBox();r&&(r.bottom=e)}set_extend({extend:e},t){B0(this._errorListener,"box.set_extend",this._variables.__requestName,t);const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(fe),"extend"))}set_bgcolor({color:e},t){B0(this._errorListener,"box.set_bgcolor",this._variables.__requestName,t);const r=this._getBox();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_lefttop({left:e,top:t},r){B0(this._errorListener,"box.set_lefttop",this._variables.__requestName,r);const o=this._getBox();o&&(o.left=e&&Math.round(e),o.top=t)}set_text_size({text_size:e},t){B0(this._errorListener,"box.set_text_size",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(L2),"text_size"))}set_text_wrap({text_wrap:e},t){B0(this._errorListener,"box.set_text_wrap",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[t1.wrapAuto,t1.wrapNone],"text_wrap"))}set_text_color({text_color:e},t){B0(this._errorListener,"box.set_text_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_color=e,S1(r,["text_color"]))}set_rightbottom({right:e,bottom:t},r){B0(this._errorListener,"box.set_rightbottom",this._variables.__requestName,r);const o=this._getBox();o&&(o.right=e&&Math.round(e),o.bottom=t)}set_text_halign({text_halign:e},t){B0(this._errorListener,"box.set_text_halign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[t1.alignLeft,t1.alignCenter,t1.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){B0(this._errorListener,"box.set_text_valign",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[t1.alignBottom,t1.alignCenter,t1.alignTop],"text_valign"))}set_top_left_point({point:e},t){B0(this._errorListener,"box.set_top_left_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.top=n,r.left=r.xloc===P1.bar_index?o:b}}set_border_color({color:e},t){B0(this._errorListener,"box.set_border_color",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_style({style:e},t){B0(this._errorListener,"box.set_border_style",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[n2.styleDashed,n2.styleDotted,n2.styleSolid],"style"))}set_border_width({width:e},t){B0(this._errorListener,"box.set_border_width",this._variables.__requestName,t);const r=this._getBox();r&&(r.border_width=e)}set_bottom_right_point({point:e},t){B0(this._errorListener,"box.set_bottom_right_point",this._variables.__requestName,t);const r=this._getBox();if(r){const{index:o,price:n,time:b}=e||{};r.bottom=n,r.right=r.xloc===P1.bar_index?o:b}}set_text_font_family({text_font_family:e},t){B0(this._errorListener,"box.set_text_font_family",this._variables.__requestName,t);const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(St),"text_font_family"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getBox(){return this._variables.box.get(this._id)||this._data}}class U_{constructor(e,t){E(this,"_variables");E(this,"_errorListener");E(this,"_defaultTable",{position:P2.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e}){return e}new(e,t){B0(this._errorListener,"table.new",this._variables.__requestName,t);const{bar_index:r}=this._variables,o=`table_${t}_${r}`,{rows:n}=e;S1(e,["text_color","bgcolor","border_color"]);const b=Array.from(Array(n),()=>[]),z=t.split("_"),i=z.pop(),s=z.pop(),a={...this._defaultTable,...e,cell:b,id:o,bar_index:r,line:s,col:i},O=new C3(this._variables,o,this._errorListener,a);return this._paramVerfiy(e.position,t,"table.new",Object.values(P2),"position"),t.startsWith("export")||this._variables.table.add(o,a,O),O}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}cell({table_id:e,...t},r){e==null||e.cell(t,r)}cell_set_bgcolor({table_id:e,...t},r){e==null||e.cell_set_bgcolor(t,r)}cell_set_height({table_id:e,...t},r){e==null||e.cell_set_height(t,r)}cell_set_text({table_id:e,...t},r){e==null||e.cell_set_text(t,r)}cell_set_text_color({table_id:e,...t},r){e==null||e.cell_set_text_color(t,r)}cell_set_text_font_family({table_id:e,...t},r){e==null||e.cell_set_text_font_family(t,r)}cell_set_text_halign({table_id:e,...t},r){e==null||e.cell_set_text_halign(t,r)}cell_set_text_valign({table_id:e,...t},r){e==null||e.cell_set_text_valign(t,r)}cell_set_text_size({table_id:e,...t},r){e==null||e.cell_set_text_size(t,r)}cell_set_tooltip({table_id:e,...t},r){e==null||e.cell_set_tooltip(t,r)}cell_set_width({table_id:e,...t},r){e==null||e.cell_set_width(t,r)}clear({table_id:e,...t},r){e==null||e.clear(t,r)}delete({table_id:e},t){e==null||e.delete(t)}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t},r){e==null||e.set_bgcolor(t,r)}set_border_color({table_id:e,...t},r){e==null||e.set_border_color(t,r)}set_border_width({table_id:e,...t},r){e==null||e.set_border_width(t,r)}set_frame_color({table_id:e,...t},r){e==null||e.set_frame_color(t,r)}set_frame_width({table_id:e,...t},r){e==null||e.set_frame_width(t,r)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class C3{constructor(e,t,r,o){E(this,"_id");E(this,"_variables");E(this,"_errorListener");E(this,"_suffix","");E(this,"_preId","");E(this,"_defaultCell",{column:0,row:0,text:"",text_color:Tr.black,text_halign:t1.alignCenter,text_valign:t1.alignCenter,text_size:L2.normal});E(this,"_data");this._variables=e,this._id=t,this._errorListener=r,this._data=o}get type(){return Q0.TABLE}get id(){return this._id}get preId(){return this._preId}set data(e){this._data=e}updateId(){const{bar_index:e,_isRealTimeBar:t}=this._variables;if(!this._suffix)this._suffix=`_${e}`,this._id=`${this._id}${this._suffix}`;else{const r=this._id.split("_");r.pop(),this._id=`${r.join("_")}_${e}`}return t||(this._preId=this._id),this._id}get data(){return this._variables.table.get(this._id)||this._data}cell(e,t){this._verfiyRequestFunc(t,"cell");const r={...this._defaultCell,...e},{column:o=0,row:n=0}=r,b=this._getTable();if(b){const z=b.cell||[],i=z[n]||[];i[o]=r,z[n]=i,b.cell=z}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r},o){this._verfiyRequestFunc(o,"cell_set_bgcolor");const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r},o){this._verfiyRequestFunc(o,"cell_set_height");const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r},o){this._verfiyRequestFunc(o,"cell_set_text");const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r},o){this._verfiyRequestFunc(o,"cell_set_text_color");const n=this._getTableItem(e,t);n&&(n.text_color=r,S1(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r},o){this._verfiyRequestFunc(o,"cell_set_text_font_family");const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r},o){this._verfiyRequestFunc(o,"cell_set_text_halign");const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r},o){this._verfiyRequestFunc(o,"cell_set_text_valign");const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r},o){this._verfiyRequestFunc(o,"cell_set_text_size");const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r},o){this._verfiyRequestFunc(o,"cell_set_tooltip");const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r},o){this._verfiyRequestFunc(o,"cell_set_width");const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){this._verfiyRequestFunc(n,"clear");const b=this._getTable();if(b){const z=b.cell;if(z)for(let i=t;i<=o;i++)for(let s=e;s<=r;s++){const a=z[i];a&&(a[s]=void 0)}}}delete(e){this._verfiyRequestFunc(e,"delete"),this._variables.table.delete(this._id,this._variables.bar_index,this._data.id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:o=0},n){if(this._verfiyRequestFunc(n,"merge_cells"),e>r||t>o){this._errorListener.addError(l1.mergeCellErr,n,$0.Error);return}const b=this._getTable();if(!b)return;const z=b.merge_cells||[];z.push({start_column:e,start_row:t,end_column:r,end_row:o}),b.merge_cells=z}set_bgcolor({bgcolor:e},t){this._verfiyRequestFunc(t,"set_bgcolor");const r=this._getTable();r&&(r.bgcolor=e,S1(r,["bgcolor"]))}set_border_color({border_color:e},t){this._verfiyRequestFunc(t,"set_border_color");const r=this._getTable();r&&(r.border_color=e,S1(r,["border_color"]))}set_border_width({border_width:e},t){this._verfiyRequestFunc(t,"set_border_width");const r=this._getTable();r&&(r.border_width=e)}set_frame_color({frame_color:e},t){this._verfiyRequestFunc(t,"set_frame_color");const r=this._getTable();r&&(r.frame_color=e)}set_frame_width({frame_width:e},t){this._verfiyRequestFunc(t,"set_frame_width");const r=this._getTable();r&&(r.frame_width=e)}set_position({position:e},t){this._verfiyRequestFunc(t,"set_position");const r=this._getTable();r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(P2),"position"))}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_getTableItem(e,t){const r=this._getTable();if(r){const o=r.cell;return o?o[t][e]:void 0}}_getTable(){return this._variables.table.get(this._id)||this._data}_verfiyRequestFunc(e,t){B0(this._errorListener,`table.${t}`,this._variables.__requestName,e)}}class j_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){return this._verifyTradeNum(e,t)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.historyOrders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.historyOrders[e];return o||r}exit_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{out_qty:r=0,direction:o}=this._strategy.historyOrders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.closedtrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.historyOrders.length;return!(e>=r)}}class H_{constructor(e){E(this,"_strategy");this._strategy=e}commission({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,original_qty:o=0,commission:n=0}=this._strategy.orders[e];return n*r/o}entry_bar_index({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_index}entry_comment({trade_num:e},t){if(!this._verifyTradeNum(e,t))return"";const{comment:r,id:o}=this._strategy.orders[e];return r||o}entry_id({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].id:""}entry_price({trade_num:e},t){if(this._verifyTradeNum(e,t))return this._strategy.orders[e].in_price}entry_time({trade_num:e},t){if(!this._verifyTradeNum(e,t))return;const{in_time:r,entry_time:o}=this._strategy.orders[e];return o||r}max_drawdown({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e},t){return this._verifyTradeNum(e,t)?this._strategy.orders[e].profit_percent:0}size({trade_num:e},t){if(!this._verifyTradeNum(e,t))return 0;const{qty:r=0,direction:o}=this._strategy.orders[e];return o===i1.long?r:-r}_verifyTradeNum(e,t){if(this._strategy._verfiyRequestFunc(t,"strategy.opentrades.*"),typeof e!="number"||e<0)return!1;const r=this._strategy.orders.length;return!(e>=r)}}class Y_{constructor(e,t){E(this,"_strategy");E(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(i1),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._strategy._verfiyRequestFunc(r,"strategy.risk.*"),this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[b2.percentOfEquity,b2.cash],"type"),t===b2.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e},t){this._strategy._verfiyRequestFunc(t,"strategy.risk.*"),this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}}var G_=20,V_=1,Gt=1e6,x3=1e6,K_=-7,J_=21,Q_=!1,WM="[big.js] ",Vt=WM+"Invalid ",Zo=Vt+"decimal places",Z_=Vt+"rounding mode",S3=WM+"Division by zero",m1={},xe=void 0,em=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;function F3(){function M(e){var t=this;if(!(t instanceof M))return e===xe?F3():new M(e);if(e instanceof M)t.s=e.s,t.e=e.e,t.c=e.c.slice();else{if(typeof e!="string"){if(M.strict===!0&&typeof e!="bigint")throw TypeError(Vt+"value");e=e===0&&1/e<0?"-0":String(e)}tm(t,e)}t.constructor=M}return M.prototype=m1,M.DP=G_,M.RM=V_,M.NE=K_,M.PE=J_,M.strict=Q_,M.roundDown=0,M.roundHalfUp=1,M.roundHalfEven=2,M.roundUp=3,M}function tm(M,e){var t,r,o;if(!em.test(e))throw Error(Vt+"number");for(M.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1,(t=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(t<0&&(t=r),t+=+e.slice(r+1),e=e.substring(0,r)):t<0&&(t=e.length),o=e.length,r=0;r<o&&e.charAt(r)=="0";)++r;if(r==o)M.c=[M.e=0];else{for(;o>0&&e.charAt(--o)=="0";);for(M.e=t-r-1,M.c=[],t=0;r<=o;)M.c[t++]=+e.charAt(r++)}return M}function Kt(M,e,t,r){var o=M.c;if(t===xe&&(t=M.constructor.RM),t!==0&&t!==1&&t!==2&&t!==3)throw Error(Z_);if(e<1)r=t===3&&(r||!!o[0])||e===0&&(t===1&&o[0]>=5||t===2&&(o[0]>5||o[0]===5&&(r||o[1]!==xe))),o.length=1,r?(M.e=M.e-e+1,o[0]=1):o[0]=M.e=0;else if(e<o.length){if(r=t===1&&o[e]>=5||t===2&&(o[e]>5||o[e]===5&&(r||o[e+1]!==xe||o[e-1]&1))||t===3&&(r||!!o[0]),o.length=e,r){for(;++o[--e]>9;)if(o[e]=0,e===0){++M.e,o.unshift(1);break}}for(e=o.length;!o[--e];)o.pop()}return M}function Jt(M,e,t){var r=M.e,o=M.c.join(""),n=o.length;if(e)o=o.charAt(0)+(n>1?"."+o.slice(1):"")+(r<0?"e":"e+")+r;else if(r<0){for(;++r;)o="0"+o;o="0."+o}else if(r>0)if(++r>n)for(r-=n;r--;)o+="0";else r<n&&(o=o.slice(0,r)+"."+o.slice(r));else n>1&&(o=o.charAt(0)+"."+o.slice(1));return M.s<0&&t?"-"+o:o}m1.abs=function(){var M=new this.constructor(this);return M.s=1,M},m1.cmp=function(M){var e,t=this,r=t.c,o=(M=new t.constructor(M)).c,n=t.s,b=M.s,z=t.e,i=M.e;if(!r[0]||!o[0])return r[0]?n:o[0]?-b:0;if(n!=b)return n;if(e=n<0,z!=i)return z>i^e?1:-1;for(b=(z=r.length)<(i=o.length)?z:i,n=-1;++n<b;)if(r[n]!=o[n])return r[n]>o[n]^e?1:-1;return z==i?0:z>i^e?1:-1},m1.div=function(M){var e=this,t=e.constructor,r=e.c,o=(M=new t(M)).c,n=e.s==M.s?1:-1,b=t.DP;if(b!==~~b||b<0||b>Gt)throw Error(Zo);if(!o[0])throw Error(S3);if(!r[0])return M.s=n,M.c=[M.e=0],M;var z,i,s,a,O,u=o.slice(),l=z=o.length,d=r.length,A=r.slice(0,z),h=A.length,q=M,_=q.c=[],m=0,L=b+(q.e=e.e-M.e)+1;for(q.s=n,n=L<0?0:L,u.unshift(0);h++<z;)A.push(0);do{for(s=0;s<10;s++){if(z!=(h=A.length))a=z>h?1:-1;else for(O=-1,a=0;++O<z;)if(o[O]!=A[O]){a=o[O]>A[O]?1:-1;break}if(a<0){for(i=h==z?o:u;h;){if(A[--h]<i[h]){for(O=h;O&&!A[--O];)A[O]=9;--A[O],A[h]+=10}A[h]-=i[h]}for(;!A[0];)A.shift()}else break}_[m++]=a?s:++s,A[0]&&a?A[h]=r[l]||0:A=[r[l]]}while((l++<d||A[0]!==xe)&&n--);return!_[0]&&m!=1&&(_.shift(),q.e--,L--),m>L&&Kt(q,L,t.RM,A[0]!==xe),q},m1.eq=function(M){return this.cmp(M)===0},m1.gt=function(M){return this.cmp(M)>0},m1.gte=function(M){return this.cmp(M)>-1},m1.lt=function(M){return this.cmp(M)<0},m1.lte=function(M){return this.cmp(M)<1},m1.minus=m1.sub=function(M){var e,t,r,o,n=this,b=n.constructor,z=n.s,i=(M=new b(M)).s;if(z!=i)return M.s=-i,n.plus(M);var s=n.c.slice(),a=n.e,O=M.c,u=M.e;if(!s[0]||!O[0])return O[0]?M.s=-i:s[0]?M=new b(n):M.s=1,M;if(z=a-u){for((o=z<0)?(z=-z,r=s):(u=a,r=O),r.reverse(),i=z;i--;)r.push(0);r.reverse()}else for(t=((o=s.length<O.length)?s:O).length,z=i=0;i<t;i++)if(s[i]!=O[i]){o=s[i]<O[i];break}if(o&&(r=s,s=O,O=r,M.s=-M.s),(i=(t=O.length)-(e=s.length))>0)for(;i--;)s[e++]=0;for(i=e;t>z;){if(s[--t]<O[t]){for(e=t;e&&!s[--e];)s[e]=9;--s[e],s[t]+=10}s[t]-=O[t]}for(;s[--i]===0;)s.pop();for(;s[0]===0;)s.shift(),--u;return s[0]||(M.s=1,s=[u=0]),M.c=s,M.e=u,M},m1.mod=function(M){var e,t=this,r=t.constructor,o=t.s,n=(M=new r(M)).s;if(!M.c[0])throw Error(S3);return t.s=M.s=1,e=M.cmp(t)==1,t.s=o,M.s=n,e?new r(t):(o=r.DP,n=r.RM,r.DP=r.RM=0,t=t.div(M),r.DP=o,r.RM=n,this.minus(t.times(M)))},m1.neg=function(){var M=new this.constructor(this);return M.s=-M.s,M},m1.plus=m1.add=function(M){var e,t,r,o=this,n=o.constructor;if(M=new n(M),o.s!=M.s)return M.s=-M.s,o.minus(M);var b=o.e,z=o.c,i=M.e,s=M.c;if(!z[0]||!s[0])return s[0]||(z[0]?M=new n(o):M.s=o.s),M;if(z=z.slice(),e=b-i){for(e>0?(i=b,r=s):(e=-e,r=z),r.reverse();e--;)r.push(0);r.reverse()}for(z.length-s.length<0&&(r=s,s=z,z=r),e=s.length,t=0;e;z[e]%=10)t=(z[--e]=z[e]+s[e]+t)/10|0;for(t&&(z.unshift(t),++i),e=z.length;z[--e]===0;)z.pop();return M.c=z,M.e=i,M},m1.pow=function(M){var e=this,t=new e.constructor("1"),r=t,o=M<0;if(M!==~~M||M<-x3||M>x3)throw Error(Vt+"exponent");for(o&&(M=-M);M&1&&(r=r.times(e)),M>>=1,!!M;)e=e.times(e);return o?t.div(r):r},m1.prec=function(M,e){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");return Kt(new this.constructor(this),M,e)},m1.round=function(M,e){if(M===xe)M=0;else if(M!==~~M||M<-Gt||M>Gt)throw Error(Zo);return Kt(new this.constructor(this),M+this.e+1,e)},m1.sqrt=function(){var M,e,t,r=this,o=r.constructor,n=r.s,b=r.e,z=new o("0.5");if(!r.c[0])return new o(r);if(n<0)throw Error(WM+"No square root");n=Math.sqrt(+Jt(r,!0,!0)),n===0||n===1/0?(e=r.c.join(""),e.length+b&1||(e+="0"),n=Math.sqrt(e),b=((b+1)/2|0)-(b<0||b&1),M=new o((n==1/0?"5e":(n=n.toExponential()).slice(0,n.indexOf("e")+1))+b)):M=new o(n+""),b=M.e+(o.DP+=4);do t=M,M=z.times(t.plus(r.div(t)));while(t.c.slice(0,b).join("")!==M.c.slice(0,b).join(""));return Kt(M,(o.DP-=4)+M.e+1,o.RM)},m1.times=m1.mul=function(M){var e,t=this,r=t.constructor,o=t.c,n=(M=new r(M)).c,b=o.length,z=n.length,i=t.e,s=M.e;if(M.s=t.s==M.s?1:-1,!o[0]||!n[0])return M.c=[M.e=0],M;for(M.e=i+s,b<z&&(e=o,o=n,n=e,s=b,b=z,z=s),e=new Array(s=b+z);s--;)e[s]=0;for(i=z;i--;){for(z=0,s=b+i;s>i;)z=e[s]+n[i]*o[s-i-1]+z,e[s--]=z%10,z=z/10|0;e[s]=z}for(z?++M.e:e.shift(),i=e.length;!e[--i];)e.pop();return M.c=e,M},m1.toExponential=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),++M,e);t.c.length<M;)t.c.push(0)}return Jt(t,!0,!!r)},m1.toFixed=function(M,e){var t=this,r=t.c[0];if(M!==xe){if(M!==~~M||M<0||M>Gt)throw Error(Zo);for(t=Kt(new t.constructor(t),M+t.e+1,e),M=M+t.e+1;t.c.length<M;)t.c.push(0)}return Jt(t,!1,!!r)},m1[Symbol.for("nodejs.util.inspect.custom")]=m1.toJSON=m1.toString=function(){var M=this,e=M.constructor;return Jt(M,M.e<=e.NE||M.e>=e.PE,!!M.c[0])},m1.toNumber=function(){var M=+Jt(this,!0,!0);if(this.constructor.strict===!0&&!this.eq(M.toString()))throw Error(WM+"Imprecise conversion");return M},m1.toPrecision=function(M,e){var t=this,r=t.constructor,o=t.c[0];if(M!==xe){if(M!==~~M||M<1||M>Gt)throw Error(Vt+"precision");for(t=Kt(new r(t),M,e);t.c.length<M;)t.c.push(0)}return Jt(t,M<=t.e||t.e<=r.NE||t.e>=r.PE,!!o)},m1.valueOf=function(){var M=this,e=M.constructor;if(e.strict===!0)throw Error(WM+"valueOf disallowed");return Jt(M,M.e<=e.NE||M.e>=e.PE,!0)};var en=F3();function I3(M,e){return en(M).plus(e).toNumber()}function tn(M,e){return en(M).minus(e).toNumber()}function Qt(M,e){return en(M).mul(e).toNumber()}function rn(M,e=5){return Number(M&&en(M).toFixed(e))}let rm=class{constructor(e,t,r,o,n){E(this,"_variables");E(this,"_options");E(this,"_totalChangeCapital");E(this,"_historyOrder");E(this,"_orders");E(this,"_exitOrders");E(this,"_pendingOrders");E(this,"_mintick");E(this,"_funcOptions");E(this,"_pendingCloseOrders");E(this,"_errorListener");E(this,"_risk");E(this,"_opentrades");E(this,"_closedtrades");E(this,"_riskNamespace");E(this,"_updateOptions",{});E(this,"_id");E(this,"_maxDrawdownVerifyIndex",0);E(this,"calcOnOrderFillsData",{index:-1});this._variables=e,this._errorListener=o,this._options={overlay:!1,format:O1.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:b2.fixed,default_qty_value:1,initial_capital:1e6,currency:D3.NONE,slippage:0,commission_type:O2.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._exitOrders=[],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 H_(this),this._closedtrades=new j_(this),this._riskNamespace=new Y_(this,o),this._id=`strategy_${n}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}get isCalcOnEveryTick(){return this._options.calc_on_every_tick}updateOptions(e){this._updateOptions=e||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._ordersHandle(),this._pendingOrderHandle(),this._exitOrdersHandle(),this._maxIntradayFilledOrdersVerify(),this._maxDrawdownVerify();const{open:e,high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,o=this._variables.close;this._variables.strategy.update(this.calcOnOrderFillsData.currentData||{open:e,close:o,high:t,low:r}),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}calcCurrentOrder(){this._ordersHandle(),this._pendingOrderHandle(),this._calcProfitAndLoss()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var l;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{time_tradingday:o,time:n,strategy:{netprofit:b,initial_capital:z}}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables;let{preNetprofit:a=0}=this._risk;n===o&&(a=b,this._risk.preNetprofit=b,this._risk.isTemporaryBan=!1);let O=a-b;O+=this._orders.reduce((d,A)=>{const{in_price:h,direction:q,qty:_=0,commission:m=0,original_qty:L=0}=A,g=q===i1.long?1:-1,v=(i-h)*_,y=(s-h)*_,X=g===1?y:-v;return d+X+_/L*m},0);let u=!1;switch(t){case b2.cash:u=e<O;break;case b2.percentOfEquity:const d=O/(z+b)*100;u=e<d;break}if(u){this._risk.isTemporaryBan=!0;const d=(l=this._orders[0])==null?void 0:l.direction;this._closeOrders(this._orders,d===i1.long?s:i,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:o,time_tradingday:n}=this._variables,{open:b}=this.calcOnOrderFillsData.data||this._variables;o===n&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,b,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:o=0}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:b,strategy:z}=this._variables,{open:i}=this.calcOnOrderFillsData.data||this._variables;let s=t;if(n===b){const a=z.netprofit+z.openprofit;a<o?s=0:s++,Object.assign(this._risk,{lossDays:s,totalProfit:a})}e<=s&&this._riskTouchOff(i,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:o}=this._variables,{open:n}=this.calcOnOrderFillsData.data||this._variables;if(e!==void 0&&t&&this._maxDrawdownVerifyIndex===o){const{initial_capital:b}=this._options,i=this._orders.reduce((a,O)=>{const{in_price:u,commission:l=0,qty:d=0,original_qty:A=0,direction:h}=O,q=h===i1.long?1:-1,_=(n-u)*q*d;return a+_+l*d/A},0)+this._totalChangeCapital;let s=!1;switch(t){case b2.percentOfEquity:s=i/b*100<=-e;break;case b2.cash:s=i<=-e;break}s&&this._riskTouchOff(n,"Close Position (Max Drawdown)")}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,e,t,"close"),this._pendingOrders=[]}strategy(e,t){if(!this._variables.bar_index){this._paramVerfiy(e.format,t,"strategy",[O1.inherit,O1.price,O1.percent,O1.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(b2),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(O2),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),o={...this._updateOptions};if(r)for(const n of Object.keys({...r,...e}))e[n]!==r[n]&&delete o[n];this._variables.max_bars_back=e.max_bars_back||0,self==null||self.workerStorage.set(this._id,e),Object.assign(this._options,e,o),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:o,scriptType:"strategy"})}}order(e,t){this._verfiyRequestFunc(t,"order"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(Ue),"oca_type"),this._orderHandle(e))}entry(e,t){this._verfiyRequestFunc(t,"entry"),!this._risk.isDisabledOpen&&(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(Ue),"oca_type"),this._entryHandle(e))}close(e,t){if(this._verfiyRequestFunc(t,"close"),!this._getCloseOrders(e.id).length)return;const{immediately:o}=e;if(o||this._options.process_orders_on_close){const n=this._pendingCloseOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingCloseOrders.push({...e,place_order_type:"close"})}else{const n=this._pendingOrders.find(b=>b.id===e.id&&b.place_order_type==="close");if(n){Object.assign(n,e);return}this._pendingOrders.push({...e,place_order_type:"close"})}}close_all(e,t){if(this._verfiyRequestFunc(t,"close_all"),typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:r}=e;r||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e},t){this._verfiyRequestFunc(t,"cancel"),this._pendingOrders=this._pendingOrders.filter(r=>!(r.id===e&&r.place_order_type!=="close"))}cancel_all(e){this._verfiyRequestFunc(e,"cancel_all"),this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(e,t){this._verfiyRequestFunc(t,"exit"),this._exit(e,t)}convert_to_account({value:e},t){return this._verfiyRequestFunc(t,"convert_to_account"),e}convert_to_symbol({value:e},t){return this._verfiyRequestFunc(t,"convert_to_symbol"),e}default_entry_qty({fill_price:e},t){return this._verfiyRequestFunc(t,"default_entry_qty"),e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=b2.fixed,default_qty_value:r=1,initial_capital:o,commission_value:n}=this._options;let b=r;switch(t){case b2.cash:b=r/e;break;case b2.percentOfEquity:const z=this._getOrderProfit(e),i=o+z+this._totalChangeCapital;n?b=this._getCommQty(i,e):b=i*r/100/e;break}return sc(b,this._getLen())}_calcExitQty(e){if(!String(e).includes("."))return e;const t=this._getLen();return Math.ceil(Qt(e,Math.pow(10,t)))}_getCommQty(e,t){const{commission_type:r,commission_value:o=0,default_qty_value:n=0}=this._options;let b=0;switch(r){case O2.percent:b=e*n/(100*t+o*t);break;case O2.cashPerContract:b=e*n/(100*t+o);break;case O2.cashPerOrder:b=(e-o)*n/100/t}return b}_getLen(){const e=5-(this._variables.precision||5);return e<0?0:e}_getCapital(e,t){const{margin_long:r=0,margin_short:o=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:o<=100&&o>0&&e===-1&&(t=t*100/o),t}_calcProfitAndLoss(){const{close:e}=this.calcOnOrderFillsData.data||this._variables;for(const t of this._orders){const{in_price:r,qty:o=0,direction:n}=t,b=n===i1.long?1:-1,z=(e-r)*b*o,[i,s]=this._calcProfitAndLossHandle(r,o,b);this._calcOrderPercent(t,z,i,s)}}_calcProfitAndLossHandle(e,t,r,o){const{high:n,low:b}=this.calcOnOrderFillsData.data||this._variables,z=((o||n)-e)*t,i=((o||b)-e)*t;let s=r===1?z:-i,a=r===1?i:-z;return[s,a]}_calcOrderPercent(e,t,r,o){const{commission_value:n}=this._options,{close:b}=this.calcOnOrderFillsData.data||this._variables,{original_qty:z=0,qty:i=0,in_price:s,max_profit:a=0,trading_loss:O=0}=e;let{commission:u=0}=e,l=s*i;if(n){const d=this._getCommission(b,i);u=u*i/z,r-=u,o-=u,l+=u,t=t-d-u}r=Math.max(r,a,0),o=Math.min(o,O,0),Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:o,profit_percent:t/l*100,max_profit_percent:r/l*100,trading_loss_percent:o/l*100})}_calcLiquidate(){if(!this._orders.length)return;const{time:e}=this._variables,{high:t,low:r}=this.calcOnOrderFillsData.data||this._variables,{initial_capital:o,margin_long:n=0,margin_short:b=0}=this._options,z=this._orders[0].direction===i1.long?1:-1;let i=z===1?r:t;if(z===1&&n===100)return;const s=(z===1?n:b)/100;if(s<=0)return;let a=!1;const[O,u]=this._orders.reduce((h,q)=>{let[_,m]=h;const{in_price:L,qty:g=0,in_time:v}=q;v===e&&(a=!0);const y=L*g,X=i*g;return _+=y,m+=X,[_,m]},[0,0]);let l=0,d=0;const A=o+this._totalChangeCapital;if(a&&(l=A-O*s,l<0&&(i=this._orders[0].in_price,d=Math.abs(Math.trunc(l/s/i)*4),d=Math.max(d,1))),l>=0){const h=z*(u-O);if(l=A+h-u*s,l>=0)return;d=Math.abs(Math.trunc(l/s/i)*4)}d<=0||this._marginCallOrders(i,d,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:o="FIFO"}=this._options;if(o==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r,!0);return}for(const n of this.orders)n.position_close_type=n.place_order_type,n.isTiggerClose=!0,this._processOrder(n,e,t,r,r,!0);this._orders=this._orders.filter(n=>!n.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e),s=e.direction===i1.long?1:-1;if(o<=0)return;let a=o;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"order"});return}this._judgeCapitalEnough(o,b,s)&&this._addPendingOrders(e,b,a,r,z)}_orderOnCloseHandle(e){const t=this._orders.filter(_=>_.direction!==e.direction),{slippage:r=0}=this._options;let{direction:o,qty:n=0,id:b,comment:z,oca_type:i,oca_name:s,in_price:a}=e;const O=o===i1.long?1:-1;if(t.length){const _=this._processOrders(t,a,n,b,z,!1,"order");if(_<=0)return;n=_}const u=a-O*r*this._mintick;if(!this._judgeCapitalEnough(n,u,O))return;this._ocaGroupVerify(n,s,i);const{bar_index:d,time:A}=this._variables,{high:h,low:q}=this.calcOnOrderFillsData.data||this._variables;this._calcCurrentOrder({...e,in_price:u,in_high:h,in_low:q,in_index:d,in_time:A,qty:n,place_order_type:"order"})}_judgeCapitalEnough(e,t,r){let o=this._freezeCapital;if(this._orders.some(a=>(a.direction===i1.long?1:-1)!==r)&&(o=0),e<=0)return!1;const{margin_long:n=0,margin_short:b=0}=this._options;if(n===0&&r===1||b===0&&r===-1)return!0;const z=this._getOrderProfit(t),s=this._getCapital(r,this._options.initial_capital+z+this._totalChangeCapital)-o;return e*t<=s}_getOrderProfit(e){return this._orders.reduce((t,r)=>{const{in_price:o,qty:n=0,direction:b}=r,z=b===i1.long?1:-1;return t+(e-o)*n*z},0)}_ocaGroupVerify(e,t,r){if(!t||!r||r===Ue.none)return!1;let o=!1;switch(r){case Ue.cancel:this._pendingOrders=this._pendingOrders.filter(n=>{if(n.oca_name===t)n.isCancel=!0,o=!0;else return!0});break;case Ue.reduce:this._pendingOrders=this._pendingOrders.filter(n=>{const{qty:b=0,oca_name:z}=n;if(t===z){const i=b-e;return o=!0,i<=0?(n.isCancel=!0,!1):(n.qty=i,!0)}else return!0});break}return o}_processOrders(e,t,r,o,n,b=!1,z,i){if(!e.length)return r;let s=r;for(const a of e)if(a.position_close_type=z||a.place_order_type,a.immediately=i,a.isTiggerClose=b||a.position_close_type==="close",s=this._processOrder(a,t,s,o,n,b),s<=0)break;return this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),s}_addPendingOrders(e,t,r,o,n){const b=this._pendingOrders.find(z=>z.id===e.id&&!z.isMarketPrice);if(b)Object.assign(b,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const z={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"order"};this._pendingOrders.push(z)}}_orderArgsParse(e){var q,_;const{direction:t,qty:r,stop:o}=e;let n=e.limit||0,{close:b}=this.calcOnOrderFillsData.data||this._variables;(_=(q=this.calcOnOrderFillsData)==null?void 0:q.tradeData)!=null&&_.open&&(b=this.calcOnOrderFillsData.tradeData.open);let z=b,i=!1,s;const a=t===i1.long?1:-1,O=o&&(o-b)*a>=0,{backtest_fill_limits_assumption:u=0}=this._options;u>0&&n&&(n-=u*this._mintick*a);const l=n&&(n-b)*a<=0;let d=!1;O&&l?(o!==b&&(s=o),z=n):O?(z=o,d=o===b):l?(z=n,d=n===b):i=!0;const A=r!==void 0?sc(r,this._getLen()):this._calcDefaultQty(z);return{orders:this._orders.filter(m=>m.direction!==t),isMarketPrice:i,activePrice:s,quantities:A,close:b,price:z,isTouch:d}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{isMarketPrice:r,quantities:o,close:n,price:b,activePrice:z,isTouch:i}=this._orderArgsParse(e);if(o<=0)return;if((r||i)&&t){this._pendingCloseOrders.push({...e,in_price:n,qty:o,place_order_type:"entry"});return}this._judgeCapitalEnough(o,n,e.direction===i1.long?1:-1)&&this._addPendingEntry(e,b,o,r,z)}_entryOnCloseHandle(e){const{direction:t,in_price:r,qty:o=0}=e,n=this._orders.filter(b=>b.direction!==t);this._entryOrder(n,r,o,e)}_entryOrder(e,t,r,o){const{time:n,bar_index:b}=this._variables,{high:z,low:i}=this.calcOnOrderFillsData.data||this._variables,{slippage:s=0}=this._options,{oca_name:a,oca_type:O,direction:u,comment:l,id:d}=o,A=u===i1.long?1:-1;if(r=this._getAvailablePositionSize(r,u),r<=0)return;const h=t;if(t=t+s*this._mintick*A,!this._judgeCapitalEnough(r,t,A))return;this._closeOrders(e,h,d,l,"entry",void 0,!0);const _={...o,in_price:t,qty:r,in_index:b,in_high:z,in_low:i,in_time:n,place_order_type:"entry"},{orders:m}=this._getEntryOrders(u),L=m.length;L&&L>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,a,O),this._calcCurrentOrder(_))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:o}=this._risk;if(o&&o!==i1.all&&o!==t)return 0;if(r===void 0)return e;const n=this._orders.reduce((b,z)=>b+(z.qty||0),0);return n?n+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(o=>["entry","order"].includes(o.place_order_type)&&o.direction===e),r=this._orders.filter(o=>o.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,o,n){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:b}=this._getEntryOrders(e.direction),z=b.find(i=>i.id===e.id&&i.place_order_type==="entry");if(z)Object.assign(z,{...e,in_price:t,isMarketPrice:o,qty:r,active_price:n});else{const i={...e,in_price:t,isMarketPrice:o,qty:r,active_price:n,entry_time:this._variables.time,place_order_type:"entry"};this._pendingOrders.push(i)}}_closeAllOrders(e,t){const{comment:r,immediately:o}=e,{bar_index:n}=this._variables,b=this._orders.filter(z=>z.in_index!==n);b.length&&(this._closeOrders(b,t,"Close position order",r,"close",o),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,o,n,b,z){if(e.length){for(const i of e)i.position_close_type=n,i.immediately=b,i.isTiggerClose=!0,this._closeOrder(i,t,r,o,z);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}}_closeOrder(e,t,r,o,n){const{time:b,bar_index:z}=this._variables,{high:i,low:s}=this.calcOnOrderFillsData.data||this._variables,{slippage:a=0}=this._options,{in_price:O,qty:u=0,direction:l}=e,d=l===i1.long?1:-1;t=t-d*a*this._mintick,e.isDeal=!0;const A=(t-O)*d*u,h={...e,out_price:t,out_id:r,out_index:z,out_high:i,out_low:s,out_time:b,out_comment:o,out_qty:u,profit:A};this._calcPercent(h,n)}_exitOrdersHandle(){if(!this._exitOrders.length)return;let{open:e,low:t,high:r,close:o}=this.calcOnOrderFillsData.data||this._variables;const n=[],b=Math.abs(r-e),z=Math.abs(t-e),i=[],s=this._variables.precision;e=Number(e.toFixed(s)),t=Number(t.toFixed(s)),r=Number(r.toFixed(s)),o=Number(o.toFixed(s));for(const a of this._exitOrders){const{directionNum:O,id:u,comment:l,qty:d,comment_loss:A,comment_profit:h,comment_trailing:q,order:_}=a;if(_.isTiggerClose)continue;let m=b<z||b===z&&O===1;if(_.in_time===this._variables.time&&!this._variables._isRepeated){const{in_price:D}=_;m?D<r&&D>=e?e=D:D<=r&&D>=o?r=D:r=o:D<=e&&D>t?e=D:D<=o&&D>=t?t=D:t=o,e=D}const L=[],[g,v]=this._getLimitPrice(a,e,t,r,m);g&&L.push({order:_,price:g,index:v,isHighFront:m,exitInfo:{id:u,comment:h||l,qty:d}});const[y,X]=this._getStopPrice(a,e,t,r,m);y&&L.push({order:_,price:y,index:X,isHighFront:m,exitInfo:{id:u,comment:A||l,qty:d}});const[T,N]=this._getTrailStopPrice(a,e,t,r,o,m);if(T&&L.push({order:_,price:T,index:N,isHighFront:m,exitInfo:{id:u,comment:q||l,qty:d}}),L.length){this._executesSort(L),n.push(L[0]);continue}i.push(a)}this._exitOrders=i,this._executesSort(n);for(const a of n){const{order:O,price:u,exitInfo:l,isHighFront:d,index:A}=a;d?(r=A===1?u:r,t=A===1?e:u):(r=A===1?e:u,t=A===1?u:t),this._variables.strategy.update({open:u,high:r,low:t,close:o}),this._processExitOnClose(O,u,l)}}_executesSort(e){return e.sort(({price:t,index:r,isHighFront:o},{price:n,index:b})=>r!==b?r-b:o?r===1?t-n:n-t:r===1?n-t:t-n),e}_getLimitPrice(e,t,r,o,n){const{limit:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z>=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getStopPrice(e,t,r,o,n){const{stop:b,directionNum:z}=e;let i,s=1;return b&&((t-b)*z<=0?(i=t,s=1):r<=b&&o>=b&&(i=b,n&&b>t||!n&&b<t?s=1:s=2)),[i,s]}_getTrailStopPrice(e,t,r,o,n,b){const{trail_stop_price:z,directionNum:i,active_price:s,trail_offset:a=0}=e;let O=z,u,l=1;if(O)if((O-t)*i>=0)u=t,l=1;else{const[d,A,h]=this._calcTrailStopPrice(O,o,r,n,a,i,b);u=A,l=h||1,e.trail_stop_price=d}if(s&&!u&&s<=o&&s>=r)if(a===0)u=s,b&&s>t||!b&&s<t?l=1:l=2;else{O=tn(s,Qt(a*i,this._mintick));let d=o,A=r;b?s>=t&&s<=o?(d=o,l=1):(b=!1,d=n,l=2):s<t&&s>=r?(A=r,l=1):(b=!0,A=n,l=2);const[h,q,_=1]=this._calcTrailStopPrice(O,d,A,n,a,i,b);delete e.active_price,l<_&&(l=_),e.trail_stop_price=h,u=q}return[u,l]}_ordersHandle(e){const t=this._orders.filter(b=>b.isMarketPriceLimit||b.isMarketPriceStop);if(!t.length)return;const{open:r,close:o}=this.calcOnOrderFillsData.data||this._variables,n=e?o:r;for(const b of t){const{out_comment:z,out_qty:i,out_id:s}=b;this._processExitOnClose(b,n,{id:s,comment:z,qty:i})}}_calcTrailStopPrice(e,t,r,o,n,b,z){let i=e,s;const a=tn(b===1?t:r,Qt(n*b,this._mintick));let O=1;return b===1?z?(i<a&&(i=a),i>=r&&(O=2,s=i)):i>=r?(O=1,s=i):a>i&&(i=a,a>=o&&(O=3,s=a)):z?i<=t?(O=1,s=i):a<i&&(i=a,a<=o&&(O=3,s=a)):(a<i&&(i=a),i<=t&&(O=2,s=i)),[i,s,O]}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(z=>z.place_order_type==="exit");let r=[];for(const z of this._pendingOrders){const{isCancel:i,place_order_type:s,isMarketPrice:a}=z;if(i)continue;let O;switch(s){case"entry":if(!a){r.push(z);continue}this._entryOrderHandle(z);break;case"order":if(!a){r.push(z);continue}this._orderOrderHandle(z);break;case"close":O=this._closeOrderHandle(z);break;case"close_all":const{open:u}=this.calcOnOrderFillsData.data||this._variables;this._closeAllOrders(z,u);break}O&&e.push(O)}const o=this._options.pyramiding||1,n=this._orders.filter(z=>z.direction===i1.long).length<o,b=this._orders.filter(z=>z.direction===i1.short).length<o;r=r.filter(z=>z.direction===i1.long&&n||z.direction===i1.short&&b);for(const z of this._pendingOrderSort(r)){const{place_order_type:i}=z;let s;switch(i){case"entry":s=this._entryOrderHandle(z);break;case"order":s=this._orderOrderHandle(z);break}s&&e.push(s)}for(const z of t){const i=this._exitOrderHandle(z);i&&e.push(i)}this._pendingOrders=e}_pendingOrderSort(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,n=Math.abs(o-t)<=Math.abs(r-t);return e.sort(({in_price:b},{in_price:z})=>{let i=0,s=0;return n?(b>=t&&b<=o?i=1:i=2,z>=t&&z<=o?s=1:s=2):(b<=t&&b>=r?i=1:i=2,z<=t&&z>=r?s=1:s=2),i!==s?i-s:n?i===1?b-z:z-b:i===1?z-b:b-z}),e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const{close:e}=this.calcOnOrderFillsData.data||this._variables,t=[];for(const r of this._pendingCloseOrders)switch(r.place_order_type){case"close":const o=this._closeOrderHandle(r,!0);o&&t.push(o);break;case"close_all":this._closeAllOrders(r,e);break;case"entry":this._entryOnCloseHandle(r);break;case"order":this._orderOnCloseHandle(r);break}this._pendingCloseOrders=t,this._ordersHandle(!0)}_entryOrderHandle(e){const{open:t,low:r,high:o}=this.calcOnOrderFillsData.data||this._variables,{isMarketPrice:n,qty:b=0,in_price:z,direction:i,active_price:s}=e;if(s&&o>=s&&r<=s)return delete e.active_price,e;let a=z;if(n)a=t;else{let{stop:O,limit:u}=e;const l=i===i1.long?1:-1,d=O&&(O-t)*l>=0,{backtest_fill_limits_assumption:A=0}=this._options;A>0&&u&&(u-=A*this._mintick*l);const h=u&&(u-t)*l<=0;d&&h||(O&&!d||u&&!h)&&(a=t)}if(a<=o&&a>=r){const O=this._orders.filter(u=>u.direction!==i);this._entryOrder(O,a,b,e)}else return e}_orderOrderHandle(e){const{time:t,bar_index:r}=this._variables,{open:o,low:n,high:b}=this.calcOnOrderFillsData.data||this._variables,{slippage:z=0}=this._options,{isMarketPrice:i,qty:s=0,in_price:a,direction:O,comment:u,oca_name:l,oca_type:d,active_price:A,id:h}=e;if(A&&b>=A&&n<=A)return delete e.active_price,e;let q=a,_=s;if(i&&(q=o),q<=b&&q>=n){const m=this._orders.filter(g=>g.direction!==O);if(m.length&&(_=this._processOrders(m,q,s,h,u,!1,"order"),_<=0))return;const L=O===i1.long?1:-1;this._ocaGroupVerify(_,l,d),this._calcCurrentOrder({...e,in_price:q-L*z*this._mintick,in_index:r,in_time:t,in_high:b,in_low:n,qty:_});return}else return e}_getCloseOrders(e){const{close_entries_rule:t="FIFO"}=this._options;let r=[];return t==="FIFO"?r=this._orders.filter(o=>o.id===e):r=this._orders.filter(o=>o.id===e&&!o.close_qty),r}_closeOrderHandle(e,t){const{id:r,qty:o,qty_percent:n=100,comment:b,immediately:z}=e,{close_entries_rule:i="FIFO"}=this._options,s=this._getCloseOrders(r);if(!s.length)return;let a=0;if(o?a=o:(a=s.reduce((l,d)=>l+(d.qty||0),a),a=n/100*a),a<=0)return;const{open:O,close:u}=this.calcOnOrderFillsData.data||this._variables;if(i==="FIFO")this._processOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,!1,"close",z);else if(this._processCloseOrders(s,t?u:O,a,`Close entry(s) order ${r}`,b,z))return e}_processCloseOrders(e,t,r,o,n,b){let z=!1;for(const i of e)i.close_qty=r,(i.qty||0)>r&&(z=!0),i.immediately=b,i.position_close_type="close",i.isTiggerClose=!0,this._processOrder(i,t,r,o,n);return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_exitOrderHandle(e){const{from_entry:t,id:r}=e,o=this._orders.filter(n=>{var b;return(!t||t===n.id)&&!((b=n.exitIds)!=null&&b.includes(r))});if(!(o.length&&!this._ordersToExit(o,e,!0)))return e}_exit(e,t){if(!e.hasOwnProperty("profit")&&!e.hasOwnProperty("loss")&&!e.hasOwnProperty("stop")&&!e.hasOwnProperty("limit")&&(!e.hasOwnProperty("trail_offset")||!e.hasOwnProperty("trail_price")&&!e.hasOwnProperty("trail_points"))){this._errorListener.addError(l1.strategyExitErr,t,$0.Error);return}const{profit:r,loss:o,stop:n,limit:b,trail_offset:z,trail_price:i,trail_points:s,from_entry:a="",id:O}=e;if(this._isNaN(r)&&this._isNaN(o)&&this._isNaN(n)&&this._isNaN(b)&&(this._isNaN(z)||this._isNaN(s)&&this._isNaN(i)))return;const u={...e,place_order_type:"exit"},l=this._orders.filter(q=>{var _;return(!a||a===q.id)&&!((_=q.exitIds)!=null&&_.includes(O))}),d=this._updateExitOrders(u),A=this._pendingOrders.filter(q=>(!a||a===q.id)&&["order","entry"].includes(q.place_order_type||""));if(l.length){if(!this._ordersToExit(l,u,!1))return}else if(!A.length||d)return;const h=this._pendingOrders.find(q=>q.id===O&&q.place_order_type==="exit");h?Object.assign(h,{...e}):this._pendingOrders.push(u)}_updateExitOrders(e){let t=!1;e.qty&&(e.qty=this._calcExitQty(e.qty));const r=this._exitOrders.filter(o=>o.id===e.id&&(o.from_entry===e.from_entry||!e.from_entry));for(const o of r){const{directionNum:n,order:b,qty:z}=o;if(b.isTiggerClose){o.isClose=!0;continue}t=!0;const i={qty:z,...e},s=!0;if(this._stopProfit(b,n,i,s)){o.isClose=!0;continue}if(this._stopLoss(b,n,i,s)){o.isClose=!0;continue}if(this._trailStopLoss(b,n,i,s)){o.isClose=!0;continue}Object.assign(o,i)}return this._exitOrders=this._exitOrders.filter(o=>!o.isClose),t}_ordersToExit(e,t,r){var q;const{qty:o,qty_percent:n=100,id:b,comment:z}=t;let i=o,s=!1;t.comment=z||b;const a=e[0],O={...t},{qty:u=0}=a,l=a.direction===i1.long?1:-1;return i=o?o>=u?u:o:n/100*u,O.qty=this._calcExitQty(i),i<u&&(s=!0),this._stopProfit(a,l,O,r)||this._stopLoss(a,l,O,r)||this._trailStopLoss(a,l,O,r)||(this._exitOrders.push({...O,directionNum:l,order:a}),a.exitIds?(q=a.exitIds)==null||q.push(b):a.exitIds=[b]),s}_addExitPendingCloseOrders(e){const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r,o){var A,h;const{limit:n,profit:b,comment_profit:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=I3(u,Qt(b*t,this._mintick))),r.limit=t===1?ac(O,this._variables.precision):uc(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t<=0)return e.isMarketPriceLimit=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r,o){var A,h;const{stop:n,loss:b,comment_loss:z,comment:i,id:s,qty:a}=r;let O=n;const{in_price:u}=e,{process_orders_on_close:l}=this._options;if(!this._isNaN(b)&&this._isNaN(n)&&(O=tn(u,Qt(b*t,this._mintick))),r.stop=t===1?uc(O,this._variables.precision):ac(O,this._variables.precision),o)return;let{close:d}=this.calcOnOrderFillsData.data||this._variables;if((h=(A=this.calcOnOrderFillsData)==null?void 0:A.tradeData)!=null&&h.open&&(d=this.calcOnOrderFillsData.tradeData.open),O!==void 0&&(O-d)*t>=0)return e.isMarketPriceStop=!0,r.comment=z||i,Object.assign(e,{out_comment:r.comment,out_id:s,out_qty:a}),l&&this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r,o){var u,l;const{trail_offset:n,trail_price:b,trail_points:z,comment_trailing:i,comment:s,id:a,qty:O}=r;if(!this._isNaN(n)){const{in_price:d}=e,{process_orders_on_close:A}=this._options;let h;if(this._isNaN(b)?this._isNaN(z)||(h=I3(d,Qt(z*t,this._mintick))):h=b,r.active_price=h,o)return;let{close:q}=this.calcOnOrderFillsData.data||this._variables;if((l=(u=this.calcOnOrderFillsData)==null?void 0:u.tradeData)!=null&&l.open&&(q=this.calcOnOrderFillsData.tradeData.open),h!==void 0&&(h-q)*t<=0){const _=tn(q,Qt(n*t,this._mintick));if((_-q)*t>=0)return e.isMarketPriceStop=!0,r.comment=i||s,Object.assign(e,{out_comment:r.comment,out_id:a,out_qty:O}),A&&this._addExitPendingCloseOrders(r),!0;r.trail_stop_price=_}}}_processExitOnClose(e,t,r){const{qty:o=0,comment:n,id:b}=r,{close_entries_rule:z="FIFO"}=this._options;if(o)if(e.isTiggerClose=!0,z==="FIFO")this._processExitOrders(this._orders,t,o,b,n);else{if(e.isDeal)return;this._processOrders([e],t,o,b,n,!1,"exit")}}_processExitOrders(e,t,r,o,n){let b=r,z;for(const i of e)if(z=i,i.position_close_type="exit",b=this._processOrder(i,t,b,o,n),b<=0)break;return this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),z}_processOrder(e,t,r,o,n,b=!1){const{time:z,bar_index:i}=this._variables,{low:s,high:a}=this.calcOnOrderFillsData.data||this._variables,{slippage:O=0}=this._options,{in_price:u,qty:l=0,max_profit:d,trading_loss:A,direction:h,commission:q=0,original_qty:_=0}=e,m=h===i1.long?1:-1;if(t=t-m*O*this._mintick,r<l){const L=l-r,g=(t-u)*m*r,v=d!==void 0?d/l*r:void 0,y=A!==void 0?A/l*r:void 0,X=q*L/_;this._calcPercent({...e,out_price:t,last_commission:X,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,profit:g,out_qty:r,max_profit:v,trading_loss:y});const T=(t-u)*m*L-X;Object.assign(e,{qty:L,profit:T,max_profit:d!==void 0?d-(v||0):void 0,trading_loss:A!==void 0?A-(y||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{e.isDeal=!0;const L=(t-u)*m*l;this._calcPercent({...e,out_price:t,out_id:o,out_index:i,out_high:a,out_low:s,out_time:z,out_comment:n,out_qty:l,profit:L}),r-=l}return b&&(m===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(e,t){const{commission_value:r,process_orders_on_close:o}=this._options,{in_price:n,out_qty:b=0,out_price:z=0,original_qty:i=0,direction:s,last_commission:a=0,immediately:O}=e;let{profit:u=0,max_profit:l,trading_loss:d,commission:A=0}=e,h=n*b,q=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=u,r){const g=this._getCommission(z,b);this._totalChangeCapital-=g;let v=A*b/i;h+=v,v+=g,u=u-v,Object.assign(e,{commission:v});const y=this._orders.reduce((X,T)=>{const{qty:N=0,original_qty:D=0,commission:C=0}=T;return X+C*N/D},0);q+=y-a}const _=s===i1.long?1:-1;let[m,L]=this._calcProfitAndLossHandle(n,b,_,z);if(r){const g=A*b/i;m-=g,L-=g}l=Math.max(m,l||0),d=Math.min(L,d||0),u=parseFloat(String(u)),Object.assign(e,{max_profit:l,profit:u,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:u/q*100,profit_percent:u/h*100,max_profit_percent:l/h*100,trading_loss_percent:d/h*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(o?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(e),!t&&this._calcOrderFillsHandle(z,s,O)}_getCommission(e,t){const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:o=0,max_profit:n=0,trading_loss:b=0,direction:z,immediately:i}=e;let{profit:s=0}=e,a=r*o;const O=this._totalChangeCapital+this._options.initial_capital;if(t){const u=this._getCommission(r,o);this._totalChangeCapital-=u,s=s-u,a+=u,Object.assign(e,{commission:u,total_profit:this._totalChangeCapital})}s=parseFloat(String(s)),Object.assign(e,{original_qty:o,profit:s,total_profit_percent:s/O*100,profit_percent:s/a*100,max_profit_percent:n/a*100,trading_loss_percent:b/a*100,stop:void 0,limit:void 0}),this._risk.intradayOrders+=1,this._orders.push(e),this._variables.strategy.updateOrders(this._orders),t&&this._variables.strategy.updateHistoryOrders(this._historyOrder),this._calcOrderFillsHandle(r,z,i)}_calcOrderFillsHandle(e,t,r=!1){const{calc_on_order_fills:o,process_orders_on_close:n,slippage:b=0}=this._options;if(o){const{open:z,high:i,low:s,close:a}=this._variables,O=t===i1.long?1:-1,u=a-O*b*this._mintick;if((r||n)&&e===u)return;const l=z-O*b*this._mintick;let d={open:z,high:i,low:s,close:a},A={open:z,high:i,low:s,close:a},h=this.calcOnOrderFillsData.index;const q=Math.abs(i-z)<=Math.abs(s-z);switch(h){case-1:e===l?(h=0,A={open:z,high:z,low:z,close:z}):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 0:e===l?(h=1,q?(A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a})):e>l?q?(h=1,A={open:z,high:i,low:z,close:i},d={open:i,high:i,low:s,close:a}):(h=2,A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a}):q?(h=2,A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(h=1,A={open:z,high:z,low:s,close:s},d={open:s,high:i,low:s,close:a});break;case 1:h=2,q?(A={open:z,high:i,low:s,close:s},d={open:s,high:a,low:s,close:a}):(A={open:z,high:i,low:s,close:i},d={open:i,high:i,low:a,close:a});break;case 2:h=-1,d=void 0;break}this.calcOnOrderFillsData={tradeData:d,index:h,currentData:A}}}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,o,n){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_verfiyRequestFunc(e,t){B0(this._errorListener,`strategy.${t}`,this._variables.__requestName,e)}};class lp{constructor(e,t,r){E(this,"array");E(this,"color");E(this,"math");E(this,"str");E(this,"map");E(this,"matrix");E(this,"timeframe");E(this,"ta");E(this,"input");E(this,"_variables");E(this,"_cacheData");E(this,"_options");E(this,"_errorListener");E(this,"_plots");E(this,"_plotshapes");E(this,"_plotbars");E(this,"_plotchars");E(this,"_plotarrows");E(this,"_plotcandles");E(this,"_alerts");E(this,"_bgColors");E(this,"_hlines");E(this,"_fills");E(this,"chart");E(this,"line");E(this,"label");E(this,"polyline");E(this,"box");E(this,"table");E(this,"linefill");E(this,"log");E(this,"runtime");E(this,"strategy");E(this,"request");E(this,"syminfo");E(this,"_count",0);var n;const o=((n=e.toString().split(".")[1])==null?void 0:n.length)||5;this._variables=t,this._errorListener=new pm,this.array=new $4(this._errorListener),this.math=new U4(o),this.color=new A6,this.str=new f_(this._errorListener,o),this.map=new l_(this._errorListener),this.timeframe=new A_(t),this.matrix=new u_(this._errorListener),this.ta=new a6(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new u6(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new q_(t)},this.line=new P_(t,this._errorListener),this.label=new d_(t,this._errorListener),this.polyline=new I_(t,this._errorListener),this.box=new $_(t,this._errorListener),this.table=new U_(t,this._errorListener),this.linefill=new k_(t),this.log=new nm(t,this.str),this.runtime=new bm(this._errorListener),this.strategy=new rm(this._variables,this._options,e,this._errorListener,r),this.request=new Mm(this._variables,r,this,this._errorListener),this.syminfo=new om}get errors(){return this._errorListener.errors}get scriptType(){return this._options.scriptType}clearErrors(){this._errorListener.clear()}addErrors(e,t){this._errorListener.setErrors(e,t)}options(e,t){if(!t)return e.length?this._getDataOfBarindex(e):this._options;const r=this.input.getInputs(),o=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let b;if(n.length){b={};for(const _ of n)b[_]=[...this._bgColors[_].values()]}const z=this._hlines.size?[...this._hlines.values()]:void 0,i=this._fills.size?[...this._fills.values()]:void 0,s=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,strategySummary:this._variables.strategy.summaryData});const a=this._plots.size>0?[...this._plots.values()]:void 0,O=this._plotbars.size>0?[...this._plotbars.values()]:void 0,u=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,l=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,d=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,A=this._plotchars.size>0?[...this._plotchars.values()]:void 0,h=this._getDraws(),q=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{inputs:r,plots:a,draws:h,alerts:o,colors:b,hlines:z,fills:i,logs:s,plotshapes:u,plotarrows:l,plotcandles:d,plotchars:A,plotbars:O,isUseBgColor:q})}_getDataOfBarindex(e){const t=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let o;if(r.length){o={};for(const q of r)o[q]=[...this._bgColors[q].values()].map(_=>{const m=[];for(const L of e){const g=_.data[L];g&&m.push(g)}return _.data=m,_})}const n=this._hlines.size?[...this._hlines.values()]:void 0,b=this._fills.size?this._getDataFromBarindex(e,[...this._fills.values()]):void 0,z=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 i=this._getDataFromBarindex(e,[...this._plots.values()]),s=this._plotbars.size>0?this._getDataFromBarindex(e,[...this._plotbars.values()]):void 0,a=this._plotarrows.size>0?this._getDataFromBarindex(e,[...this._plotarrows.values()]):void 0,O=this._plotcandles.size>0?this._getDataFromBarindex(e,[...this._plotcandles.values()]):void 0,u=this._plotchars.size>0?this._getDataFromBarindex(e,[...this._plotchars.values()]):void 0,l=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,d=this._getDrawDeletes(e),A=this._getDrawsFromBarindex(e),h=this._variables.chart.isUseBgColor;return Object.assign({},this._options,{plots:i,plotarrows:a,plotcandles:O,plotchars:u,plotbars:s,draws:A,drawDeletes:d,alerts:t,colors:o,hlines:n,fills:b,logs:z,plotshapes:l,isUseBgColor:h})}_getDataFromBarindex(e,t){return t.map(r=>{const o=[];for(const n of e){const b=r.data[n];b&&o.push(b)}return r.data=o,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:o,polyline:n,label:b}=this._variables,z={};return e.size&&(z.lines=e.data),t.size&&(z.linefills=t.data),r.size&&(z.tables=r.data),o.size&&(z.boxes=o.data),n.size&&(z.polylines=n.data),b.size&&(z.labels=b.data),Object.keys(z).length?z:void 0}_getDrawsFromBarindex(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={};return t.size&&(i.lines=t.getValOfBarIndex(e)||[]),r.size&&(i.linefills=r.getValOfBarIndex(e)),o.size&&(i.tables=o.getValOfBarIndex(e)),n.size&&(i.boxes=n.getValOfBarIndex(e)),b.size&&(i.polylines=b.getValOfBarIndex(e)),z.size&&(i.labels=z.getValOfBarIndex(e)),Object.keys(i).length?i:void 0}_getDrawDeletes(e){const{line:t,linefill:r,table:o,box:n,polyline:b,label:z}=this._variables,i={},s=t.getDeleteIds(e),a=r.getDeleteIds(e),O=o.getDeleteIds(e),u=n.getDeleteIds(e),l=b.getDeleteIds(e),d=z.getDeleteIds(e);return s.length&&(i.lines=s),a.length&&(i.linefills=a),O.length&&(i.tables=O),u.length&&(i.boxes=u),l.length&&(i.polylines=l),d.length&&(i.labels=d),i}updateOptions(e){var o;const{inputs:t,strategy:r}=e;this.input.update(t),r&&((o=this.strategy)==null||o.updateOptions(r))}update(e){const{barIndex:t}=e;this.strategy.update(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:o}=e;r.test(o)?(Bu.includes(o)||yu.includes(o))&&this._errorListener.addError(r2(l1.libraryTitleIsKeywordErr,{name:o}),t,$0.Error):this._errorListener.addError(l1.libraryTitleErr,t,$0.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r,max_bars_back:o=0}=e;this._variables.max_bars_back=o,this._paramVerfiy(r,t,"indicator",[O1.inherit,O1.percent,O1.price,O1.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,o,n="format"){e&&!o.includes(e)&&this._errorListener.addError(r2(l1.paramsErr,{value:e,func:r,param:n,targetVal:`[${o.join(", ")}]`}),t,$0.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(vu.lineWidthWarning,t,$0.Warning),e.linewidth=1)}plot(e,t){const r=["color"];S1(e,r);const{series:o,color:n,...b}=e,{bar_index:z,time:i}=this._variables,s=`plot_${t}`,a=this._plots.get(s),O=(a==null?void 0:a.data)||[],u=o!==void 0&&isNaN(o)?void 0:o;if(O[z]={value:[i,u],barIndex:z,itemStyle:{color:n}},this._seriesColorHandle(e,r,a),!a){this._count++,this._lineWidthVerify(b,t),this._paramVerfiy(e.format,t,"plot",[O1.percent,O1.price,O1.volume]);const l=n?[n]:void 0;this._plots.set(s,{editable:!0,...b,colors:l,data:O,id:s,zIndex:this._count})}return{type:"plot",offset:e.offset||0,key:s}}plotbar(e,t){const r=["color"];S1(e,r);const{open:o,close:n,low:b,high:z,color:i,...s}=e,{bar_index:a,time:O}=this._variables,u=`plotbar_${t}`,l=this._plotbars.get(u),d=(l==null?void 0:l.data)||[],A=n!==void 0&&isNaN(n)?void 0:n,h=o!==void 0&&isNaN(o)?void 0:o,q=b!==void 0&&isNaN(b)?void 0:b,_=z!==void 0&&isNaN(z)?void 0:z,m=[O,h,A,q,_];if(d[a]={value:m,barIndex:a,itemStyle:{color:i}},this._seriesColorHandle(e,r,l),!l){this._count++,this._paramVerfiy(e.format,t,"plotbar",[O1.percent,O1.price,O1.volume]);const L=i?[i]:void 0;this._plotbars.set(u,{editable:!0,...s,colors:L,data:d,id:u,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:o,format:n,location:b,style:z}=e;this._paramVerfiy(z,r,t,Object.values(X2),"style"),this._paramVerfiy(b,r,t,Object.values(ke),"location"),this._paramVerfiy(o,r,t,Object.values(L2),"size"),this._paramVerfiy(n,r,t,[O1.percent,O1.price,O1.volume],"format")}plotchar(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,high:O,low:u}=this._variables,l=`plotchar_${t}`,d=this._plotchars.get(l),A=(d==null?void 0:d.data)||[],h={value:[a,o],barIndex:s,itemStyle:{color:n,textcolor:b},low:u,high:O};A[s]=h,this._seriesColorHandle(e,r,d),d||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(l,{editable:!0,...i,location:z,data:A,id:l,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];S1(e,r);const{series:o,colorup:n,colordown:b,...z}=e,{bar_index:i,time:s,low:a,high:O}=this._variables,u=`plotarrow_${t}`,l=this._plotarrows.get(u),d=(l==null?void 0:l.data)||[];d[i]={value:[s,o!==void 0&&isNaN(o)?void 0:o],barIndex:i,itemStyle:{colorup:n,colordown:b},low:a,high:O},this._seriesColorHandle(e,r,l),l||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[O1.percent,O1.price,O1.volume]),this._plotarrows.set(u,{editable:!0,...z,data:d,id:u,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];S1(e,r);const{series:o,color:n,textcolor:b,location:z=ke.abovebar,...i}=e,{bar_index:s,time:a,low:O,high:u}=this._variables,l=`plotshape_${t}`,d=this._plotshapes.get(l),A=(d==null?void 0:d.data)||[],h={value:o,barIndex:s,color:n,textcolor:b,time:a,low:O,high:u};if(A[s]=h,this._seriesColorHandle(e,r,d),!d){this._count++;const q=n?[n]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(l,{editable:!0,...i,data:A,location:z,id:l,colors:q,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];S1(e,r);const{wickcolor:o,bordercolor:n,color:b,close:z,open:i,low:s,high:a,...O}=e,{bar_index:u,time:l}=this._variables,d=`plotcandle_${t}`,A=this._plotcandles.get(d),h=(A==null?void 0:A.data)||[],q=z!==void 0&&isNaN(z)?void 0:z,_=i!==void 0&&isNaN(i)?void 0:i,m=s!==void 0&&isNaN(s)?void 0:s,L=a!==void 0&&isNaN(a)?void 0:a,g=[l,_,q,m,L];h[u]={value:g,barIndex:u,wickcolor:o,bordercolor:n,color:b},this._seriesColorHandle(e,r,A),A||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[O1.percent,O1.price,O1.volume]),this._plotcandles.set(d,{editable:!0,...O,data:h,id:d,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;S1(e,["color"]),this._verifyDisplay(e.display,"hline",t);const n=e.display&&!e.display.length?A2.none:A2.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:n,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var X,T,N,D,C,P,H,G;const r=["color","top_color","bottom_color"];S1(e,r);const{color:o,top_color:n,bottom_color:b,seriesColors:z,hline1:i,hline2:s,plot1:a,plot2:O,top_value:u,bottom_value:l,...d}=e,{bar_index:A,time:h}=this._variables,q=`fill_${t}`,_=this._fills.get(q),m=(_==null?void 0:_.data)||[];this._verifyDisplay(e.display,"fill",t);const L=e.display&&!e.display.length?A2.none:A2.all;let g,v,y="plot";if(i&&s)g=(X=this._hlines.get(i==null?void 0:i.key))==null?void 0:X.price,v=(T=this._hlines.get(s==null?void 0:s.key))==null?void 0:T.price,y="hline";else{const k=this._plots.get(a==null?void 0:a.key),J=this._plots.get(O==null?void 0:O.key),o0=(k==null?void 0:k.data)||[],z0=(J==null?void 0:J.data)||[];if(g=(D=(N=o0[A])==null?void 0:N.value)==null?void 0:D[1],v=(P=(C=z0[A])==null?void 0:C.value)==null?void 0:P[1],!A){const a0=(k==null?void 0:k.force_overlay)&&(J==null?void 0:J.force_overlay);(k!=null&&k.force_overlay||J!=null&&J.force_overlay)&&!a0?this._errorListener.addError(l1.plotFillForceOverlayErr,t,$0.Error):d.force_overlay=a0}}if(m[A]={time:h,color:o,top_color:n,bottom_color:b,barIndex:A,plot1:g,plot2:v,top_value:u,bottom_value:l},this._seriesColorHandle(e,r,_),!_){this._count++;const k=((H=this._options.indicator)==null?void 0:H.explicit_plot_zorder)||((G=this._options.strategy)==null?void 0:G.explicit_plot_zorder),J=o?[o]:void 0,o0=n?[n]:void 0,z0=b?[b]:void 0;this._fills.set(q,{id:q,colors:J,top_colors:o0,bottom_colors:z0,display:L,data:m,type:y,editable:!0,fillgaps:!1,hline1:i,hline2:s,plot1:a,plot2:O,...d,zIndex:k?this._count:void 0})}}alert({message:e,freq:t=Ae.freqOncePerBar},r){const{bar_index:o,_isRealTimeBar:n,last_bar_index:b}=this._variables,z=`alert_${r}`,i=this._cacheData[z]||{},s=i.barIndex;if(this._paramVerfiy(t,r,"alert",[Ae.freqAll,Ae.freqOncePerBar,Ae.freqOncePerBarClose]),t===Ae.freqOncePerBar&&o===s){this._alerts.delete(z);return}this._cacheData[z]=i;const a={message:e,freq:t,id:z,type:"alert"};if(n){t!==Ae.freqOncePerBarClose&&this._alerts.set(z,a),i.barIndex=o;return}if(!n&&t===Ae.freqOncePerBarClose&&o===s&&b===o-1){this._alerts.set(z,a),i.barIndex=o;return}this._alerts.delete(z)}alertcondition({condition:e,message:t,title:r},o){const{_isRealTimeBar:n}=this._variables,b=`alertcondition_${o}`;n&&e?this._alerts.set(b,{message:t,title:r,id:b,type:"alertcondition"}):this._alerts.delete(b)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=X3.all,t,r){e.length&&e.length<4&&this._errorListener.addError(r2(l1.displayErr,{func:t,values:"[display.none, display.all]"}),r,$0.Error)}_setColors(e,t,r){S1(e,["color"]);const{color:n,...b}=e;this._verifyDisplay(b.display,t,r);const z=e.display&&!e.display.length?A2.none:A2.all,{bar_index:i,time:s}=this._variables,a=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const O=this._bgColors[t].get(a),u=(O==null?void 0:O.data)||[],l=(O==null?void 0:O.setColors)||[];n&&!l.includes(n)&&l.push(n),u[i]={color:n,time:s,barIndex:i},O||this._bgColors[t].set(a,{...b,display:z,data:u,setColors:l,id:a})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||typeof e=="number"&&isNaN(e))}fixnan({source:e},t){return e===void 0||typeof e=="number"&&isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!(typeof e=="number"&&isNaN(e))?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o)}time_close({timeframe:e="",session:t,timezone:r,bars_back:o=0},n){return this._timeHandle(this._variables.time,n,e,t,r,o,!0)}timestamp(e){const{dateString:t,timezone:r,year:o,month:n,day:b,hour:z=0,minute:i=0,second:s=0}=e;if(t)return D1(t).utc(!/GMT|UTC/.test(t)).valueOf();let a=n-1,O=o;if(a<0){const u=Math.ceil(Math.abs(a/12));a=12*u+a,O=o-u}return $2({year:O,month:a,day:b,hour:z,minute:i,second:s},r).valueOf()}weekofyear({time:e,timezone:t}){return $2(e,t).week()}year({time:e,timezone:t}){return $2(e,t).year()}second({time:e,timezone:t}){return $2(e,t).second()}month({time:e,timezone:t}){return $2(e,t).month()+1}minute({time:e,timezone:t}){return $2(e,t).minute()}hour({time:e,timezone:t}){return $2(e,t).hour()}dayofweek({time:e,timezone:t}){return $2(e,t).day()+1}dayofmonth({time:e,timezone:t}){return $2(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,this._variables.timeframe.period),o=N2(t,e)*1e3;return e-r-Math.floor((e-r)/o)*o}_timeHandle(e,t,r="",o,n,b=0,z=!1){const i=r||this._variables.__period,s=N2(i,e),a=N2(this._variables.__period,e);let O;if(s<=a)O=e,z&&(O+=a*1e3);else{const u=`time_${t}`,l=this._cacheData[u];if(l)l.currentTime+s*1e3-l.offset<=e?(O=e,this._cacheData[u]={currentTime:e,offset:0}):O=l.currentTime;else{const d=this._calcTimeOffset(e,i);this._cacheData[u]={currentTime:e,offset:d},O=e}z&&(O+=s*1e3)}if(o&&o!==ut.regular&&o!==ut.extended){const{timePeriods:u,weeks:l}=this._parserSession(o,t),d=$2(e,n),A=d.format("YYYY-MM-DD HH:mm"),h=d.format("YYYY-MM-DD"),q=O,_=$2(O,n).format("YYYY-MM-DD HH:mm");O=void 0;for(const L of u){const[g,v]=L;let y;if((g===v||Number(g==null?void 0:g.replace(":",""))>Number(v==null?void 0:v.replace(":","")))&&(y=d.add(1,"day").format("YYYY-MM-DD")),D1(A).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")){D1(_).isBetween(`${h} ${g}`,`${y||h} ${v}`,"hour","[)")?O=q:O=$2(`${h} ${g}`,n).valueOf();break}}const m=this._variables.dayofweek;O&&!l.includes(m)&&(O=void 0)}return O&&O-b*a*1e3}_seriesColorHandle(e,t,r){var o;if(r&&t!=null&&t.length)for(const n of t){if((o=r.gradientColorKeys)!=null&&o.includes(n))continue;const b=e[n];if(!b)continue;const z=r[`${n}s`]||[];z.includes(b)||(z.push(b),r[`${n}s`]=z,z.length>5&&(r[`${n}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(n)))}}_parserSession(e,t){const r=e.split(":"),o=r[0],b=(r[1]||"1234567").split("").map(i=>{const s=parseInt(i,10);if(s<1||s>7){this._errorListener.addError(`Invalid day of week: ${i}`,t,$0.Error);return}return s});return{timePeriods:o.split(",").map(i=>{i===""||i===ut.regular?i="0930-1500":i===ut.extended&&(i="1500-1830");const s=i.split("-");return s.length!==2?[]:[this._processTime(s[0],t),this._processTime(s[1],t)]}),weeks:b}}_processTime(e,t){const r=e.slice(0,2),o=e.slice(2),n=parseInt(r,10),b=parseInt(o,10);if(!(n>=0&&n<=23)&&b>=0&&b<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",t,$0.Error);return}return`${r}:${o}`}}let Mm=class{constructor(e,t,r,o){E(this,"_variables");E(this,"_scriptId");E(this,"_cacheData");E(this,"_funcs");E(this,"_errorListener");this._variables=e,this._scriptId=t,this._cacheData=new Map,this._funcs=r,this._errorListener=o}security(e,t){var d;const r=self.workerStorage.get(`request_${this._scriptId}`),{__requestName:o,__period:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||n;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${o}${t}_${s}`,O=this._getRequestData(e,a);if(r!=null&&r.has(a))return(d=O==null?void 0:O.result)==null?void 0:d[a];const u=this._parseExprCode(e),l=this._runScriptHandle(u,a,i,O,!0);return r==null||r.set(a,{id:a,isRun:!1,strJs:u,dataId:s,interval:z,symbol:b,paramsExpr:i}),l}security_lower_tf(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{__period:o,__requestName:n}=this._variables;e.symbol=this._symbolTransform(e.symbol),e.timeframe=e.timeframe||o;let{symbol:b,timeframe:z,paramsExpr:i=[]}=e;z=hr(z);const s=`${b}--${z}`,a=`${n}${t}_${s}`,O=r==null?void 0:r.get(a),u=this._getRequestLowerTfData(e,t,a,O==null?void 0:O.defaultResult),l=new n1(0,void 0,this._errorListener);if(O!=null&&O.strJs)return O!=null&&O.defaultResult?u!=null&&u.length?u.map(q=>{const _=new n1(0,void 0,this._errorListener);return _._value=q,_}):O==null?void 0:O.defaultResult:u&&(l._value=u,l);const d=this._parseExprCode(e),A={id:a,strJs:d,isRun:!1,dataId:s,interval:z,symbol:b,paramsExpr:i,defaultResult:void 0};r==null||r.set(a,A);const h=this._runScriptHandle(d,a,i,u,!0);return Array.isArray(h)?(A.defaultResult=h.map(()=>new n1(0,void 0,this._errorListener)),A.defaultResult):l}_symbolTransform(e){if(!e)return this._variables.syminfo.tickerid;let[t,r]=e.split(":");return r?t=Du[t]||t:(t="FX",r=t),`${t}:${r}`}_runScriptHandle(e,t,r,o,n){const{result:b,logs:z,errors:i}=this._runScripts(e,t,n,r,o);return this._funcs.log.mergeLogs(z),this._funcs.addErrors(i,t),b}_getCurrentData(e){let{symbol:t,timeframe:r}=e;const{__period:o,syminfo:{ticker:n,tickerid:b}}=this._variables;if(r=hr(r),(o===r||r==="")&&(t===n||t===b||!t)){const{close:z,open:i,high:s,low:a,bar_index:O,last_bar_index:u,last_bar_time:l,_isRealTimeBar:d,volume:A,time:h,time_tradingday:q,mintick:_,nextBarTime:m}=this._variables;return{barIndex:O,c:z,o:i,h:s,l:a,volume:A,lastBarIndex:u,lastBarTime:l/1e3,nextBarTime:m?m/1e3:void 0,isrealtime:d,time_tradingday:q,time:h/1e3,interval:o,mintick:_}}}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,o=[];t=cc(t);const n=JSON.parse(t),b=n.pop();let z=(b==null?void 0:b.memberCodes)||{},i=(b==null?void 0:b.depends)||[];if(!i.length)return`return ${b==null?void 0:b.code}`;let s=[],a=[],O=[];if(this._getDependCodes(i,n,o,s,a,O),this._getStmtFuncs(o,n,O,s,a),a.length){const h=r.length;for(let q=h-1;q>=0;q--){const _=r[q];let m=JSON.parse(cc(_));const L=[];m=m.map(y=>{const{scope:X,code:T,varNames:N,dependSelf:D}=y;return X===2&&!L.includes(N)&&!D&&(y.code=`let ${T}`),N&&L.push(...N.split(", ")),y.memberCodes&&Object.assign(z,{...y.memberCodes}),y});const g=[];let v=a.map(y=>({...y,isArg:!1,isPreArg:!0}));a=[],this._getDependCodes(v,m,o,s,a,g),this._getStmtFuncs(o,m,g,s,a)}}const u=o.filter(h=>!!h).map((h,q)=>{let _=h.join(`
|
77
77
|
`);return q===0&&(_=`${_}
|
78
78
|
${s.join(`
|
79
79
|
`)}`),_});let l=u.join(`
|
@@ -82,7 +82,7 @@ ${O.join(`
|
|
82
82
|
`)}
|
83
83
|
return ${b==null?void 0:b.code}`;d>1;)l=`${l}}`,d--;const A=[];for(const h of Object.keys(z))l.includes(`$_var.getCacheData("${h}"`)&&A.push(z[h]);return A.length&&(l=`${A.join(`
|
84
84
|
`)}
|
85
|
-
${l}`),l}_getRequestLowerTfData(e,t,r,o){var L;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:s}=e;const{__period:a,time:O,_isRealTimeBar:u}=this._variables;b=hr(b);let l=N2(b,O)*1e3;const d=N2(a,O)*1e3;if(l>d)return!s&&this._errorListener.addError(r2(l1.requestLowerTfPeriodErr,{period:b}),t,$0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),q=self.workerStorage.get(`request_${this._scriptId}_list`),_=self.workerStorage.get(`request_${this._scriptId}_tmp`),m={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:ii[b]||ic(b)};if(h!=null&&h.has(A)){_==null||_.delete(A);const{index:g=0,periodStamp:v=d}=this._cacheData.get(r)||{},y=h==null?void 0:h.get(A);if(!y.length)return[];if(y.length-1<0)return[];const T=y.slice(g);let N=O,D=v+N;const C=[];for(const[P,H]of T.entries()){let{time:G}=H;G=G*1e3;let k=g+P;if(G>=D)return!u&&this._cacheData.set(r,{index:k,periodStamp:v}),C;if(N<=G&&G<D){const J=(L=H==null?void 0:H.result)==null?void 0:L[r];if(Array.isArray(J))for(const[o0,z0]of J.entries())C[o0]||(C[o0]=[]),C[o0].push(z0);else o||C.push(J)}}return!u&&this._cacheData.set(r,{index:y.length,periodStamp:v}),C}else(q==null?void 0:q.get(A))||_==null||_.set(A,m);q==null||q.set(A,m)}_getRequestData(e,t){var _,m,L,g,v;let{symbol:r,timeframe:o,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:s,mintick:a,time:O,nextBarTime:u}=this._variables;o=hr(o),r=r;const l=`${r}--${o}`,d=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),q={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:o,timeframe:ii[o]||ic(o)};if(d!=null&&d.has(l)){let y=N2(o,O)*1e3;const X=N2(s,O)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=X}=this._cacheData.get(t)||{},D=d==null?void 0:d.get(l);if(!D.length)return;const C=D.slice(T);let P=O,H=N+P;const G=D.length-1;if(G<0)return;const k={lastBarIndex:D[G].barindex||G,lastBarTime:D[G].time,interval:o,mintick:a};if(y>N){let J;if(z===Pe.lookaheadOn?J=this._lookaheadOnHandle(C,o,H,y,k,T,N,t,P,b):J=this._lookaheadOffHandle(C,o,H,y,k,T,N,t,P,u||H,b),J)return J;if(J===null)return}else if(z===Pe.lookaheadOn)for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((_=C[J+1])==null?void 0:_.time)*1e3||z0+y;let w0=T+J;if(z0>=H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<=P&&v0>P){const u0=T+J;return this._cacheData.set(t,{index:u0,periodStamp:N}),{...o0,barIndex:a0||u0,nextBarTime:(m=C[J+1])==null?void 0:m.time,...k}}}else for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((L=C[J+1])==null?void 0:L.time)*1e3||z0+y;let w0=T+J;if(z0>H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<H&&H<=v0)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(g=C[J+1])==null?void 0:g.time,...k};if(z0>=P&&z0<=H&&(a0||w0)===k.lastBarIndex)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(v=C[J+1])==null?void 0:v.time,...k}}this._cacheData.set(t,{index:D.length,periodStamp:N});return}else(A==null?void 0:A.get(l))||h==null||h.set(l,q);A==null||A.set(l,q)}_lookaheadOnHandle(e,t,r,o,n,b,z,i,s,a){var O;for(const[u,l]of e.entries()){let{time:d,barindex:A}=l;d=d*1e3,t.includes("M")&&(o=N2(t,d)*1e3-(D1(d).date()-1)*864e5);const h=d,q=o+h;let _=b+u;if(r<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),null;let m={...l,barIndex:A||_,nextBarTime:(O=e[u+1])==null?void 0:O.time,...n};if(a===Pe.gapsOn){if(r>h&&s<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}else{if(r>q)continue;if(r>h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}}}_lookaheadOffHandle(e,t,r,o,n,b,z,i,s,a,O){var u,l;for(const[d,A]of e.entries()){let{time:h,barindex:q}=A;h=h*1e3,t.includes("M")&&(o=N2(t,h)*1e3-(D1(h).date()-1)*864e5);const _=h,m=o+_,L=b+d;if(r<_)return this._cacheData.set(i,{index:L,periodStamp:z}),null;const g={...A,barIndex:q||L,nextBarTime:(u=e[d+1])==null?void 0:u.time,...n};if(r>=m&&s<m||r<m&&a>=m)return O===Pe.gapsOn?(this._cacheData.set(i,{index:L,periodStamp:z}),g):(this._cacheData.set(i,{index:L,data:g,periodStamp:z}),g);if(!(s>m)&&s>=_){let v=(l=this._cacheData.get(i))==null?void 0:l.data;if(!v){const y=e[L-1];if(!y)return null;v={...y,barIndex:y.barindex||L-1,nextBarTime:g.time,...n},this._cacheData.set(i,{index:L,data:v,periodStamp:z})}return v}}}_getDependCodes(e,t,r,o,n,b){for(const z of e){if(!z.isArg){const i=t.filter(a=>{var O;return(O=a==null?void 0:a.depends)==null?void 0:O.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const a of i){const{code:O,depends:u,scope:l,funcName:d}=a;r[l]=r[l]||[];const A=r[l];let h=l===0&&d;if(!A.includes(O)){if(h){if(o.includes(O))continue;o.unshift(O)}else A.unshift(O);if(u!=null&&u.length){for(const q of u)q.memberCode&&!h&&b.push(q.memberCode);this._getDependCodes(u,t,r,o,n,b)}}}const s=t.find(a=>{var O;return((O=a.varNames)==null?void 0:O.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&a.methodName===z.functionName)||a.funcName===z.name});if(s){const{code:a,depends:O,scope:u}=s;r[u]=r[u]||[];const l=r[u],d=l.findIndex(A=>A===a);if(d!==-1){if(z.isFunc)continue;l.splice(d,1)}if(l.unshift(a),O!=null&&O.length){for(const A of O)A.memberCode&&b.push(A.memberCode);this._getDependCodes(O,t,r,o,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,o,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:s,scope:a=0}=z;e[a]=e[a]||[];const O=e[a];if(!O.includes(i)&&(O.push(i),s!=null&&s.length)){for(const u of s)u.memberCode&&r.push(u.memberCode);this._getDependCodes(s.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,o,n,r)}}}runScripts(e,t,r,o,n,b){var u;const z=`${this._scriptId}_${t}`;let{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O}=self.workerStorage.get(z)||{};if(r&&(i=new qp(z),s=new fp,a=new lp(this._variables.mintick||1e-5,i,this._scriptId),O=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e),i.__requestName=t,self.workerStorage.set(z,{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O})),o&&o.length){const l=o.length-1,{interval:d,symbol:A=""}=n,{mintick:h,syminfo:q}=this._variables,[_,m]=A.split(":");i.updateOptions({interval:d,mintick:h,syminfo:{...q.__syminfo,tickerid:A||q.tickerid,ticker:m||_||q.ticker}});for(const[v,y]of o.entries()){const{barindex:X}=y,T=Object.assign(y,{barIndex:X||v,lastBarIndex:o[l].barindex||l,lastBarTime:o[l].time,nextBarTime:(u=o[v+1])==null?void 0:u.time});if(i.updateData(T),a.update({barIndex:(T==null?void 0:T.barindex)||0}),y.result=Object.assign(y.result||{},{[t]:O(i,s,a,b||[],t)}),a.endExecution(),a.errors.length&&a.errors.some(N=>N.type===$0.Error))return{logs:[],errors:a.errors}}const L=a.log.logs,g=a.errors;return a.log.clearLogs(),a.clearErrors(),{logs:L,errors:g}}}_runScripts(e,t,r,o,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a}=self.workerStorage.get(b)||{};const{interval:O,...u}=n||{};if(r){z=new qp(b),i=new fp,s=new lp(this._variables.mintick||1e-5,z,this._scriptId),a=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:q}=this._variables;z.updateOptions({interval:O,mintick:h||1e-5,syminfo:{...q.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a})}z.updateData(u),s.update({barIndex:(u==null?void 0:u.barindex)||0});const l=a(z,i,s,o||[],t),d=s.log.logs,A=s.errors;return s.log.clearLogs(),s.clearErrors(),s.endExecution(),{result:l,logs:d,errors:A}}},om=class{constructor(){}prefix(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[0])||""}ticker(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[1])||""}};class nm{constructor(e,t){E(this,"_logs");E(this,"_variables");E(this,"_str");E(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get logs(){return this._logs}clearLogForIndex(e){this._logs=this._logs.filter(t=>t.barIndex!==e)}clearLogs(){this._logs=[]}info(e,t,r){this._addLog(e,t,"info",r)}error(e,t,r){this._addLog(e,t,"error",r)}warning(e,t,r){this._addLog(e,t,"warning",r)}mergeLogs(e){this._logs=this._logs.concat(e)}_addLog(e,t,r,o){if(typeof t=="string"&&(o=t),o.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:s,__isReqRepeated:a}=this._variables;let O=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>(typeof A=="object"&&(A.isArray?A=JSON.stringify(A._value):A=A.toString()),A!==void 0?A:"na")),O=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:s});const d=Date.now();O!==void 0&&this._logs.push({message:`[${D1(u&&!a?d:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${O}`,time:z,id:I4(6),barIndex:i,type:r})}}class bm{constructor(e){E(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,$0.Error)}}class pm{constructor(){E(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return D2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,o=0){const[n,b]=t.split("_").slice(-2),z=this._errors.get(t),i={message:e,endLineNumber:Number(n),startColumn:Number(b)+1,endColumn:Number(b)+o+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class zm{constructor(){E(this,"_isMarketOpen");E(this,"_currentBarIndex");E(this,"_totalBarIndex");E(this,"_isRealTimeBar");E(this,"_preBarIndex");E(this,"_preIsRealTimeBar");E(this,"_isFirstRun",!1);this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0,this._preIsRealTimeBar=!1}update(e,t,r,o){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=o}set isFirstRun(e){this._isFirstRun=e}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex||!this._isFirstRun}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar||this._isFirstRun}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1&&!this._preIsRealTimeBar||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class im{constructor(e){E(this,"_variables");this._variables=e}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{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class cm{constructor(e){E(this,"_orders");E(this,"_historyOrders");E(this,"_options");E(this,"_max_contracts_held_all",0);E(this,"_max_contracts_held_long",0);E(this,"_max_contracts_held_short",0);E(this,"_max_drawdown",0);E(this,"_max_runup",0);E(this,"_max_runup_percent",0);E(this,"_max_drawdown_percent",0);E(this,"_variables");E(this,"_netprofit",0);E(this,"_eventrades",0);E(this,"_avg_trade_percent");E(this,"_avg_losing_trade_percent");E(this,"_avg_winning_trade_percent");E(this,"_closedtrades",0);E(this,"_losstrades",0);E(this,"_grossloss",0);E(this,"_grossprofit",0);E(this,"_wintrades",0);E(this,"_opentrades_capital_held",0);E(this,"_position_avg_price",0);E(this,"_position_size",0);E(this,"_openprofit",0);E(this,"_preMaxNetValue",0);E(this,"_preMinNetValue",0);E(this,"marginCallLong",0);E(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=e}update(e){this._calcMaxDrawdownAndMaxRunup(e)}_calcMaxDrawdownAndMaxRunup(e){if(!this._orders.length&&!this._historyOrders.length)return;let t=0,r=0;const{high:o,low:n,close:b}=e;let z=0;for(const[a,O]of this._orders.entries()){const{in_price:u,qty:l=0,direction:d,commission:A,original_qty:h=1}=O,q=d===i1.long?1:-1,_=(o-u)*l,m=(n-u)*l,L=q===1?_:-m,g=q===1?-m:_;z+=(b-u)*q*l,t+=g,a>0&&A&&(r-=A*l/h),r+=L}this._openprofit=z;const i=this.initial_capital,s=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-s+Math.max(t,0),r=s-this._preMinNetValue+r,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(e){this._orders=e,this._calcMaxContracts()}_calcMaxContracts(){const e=this._orders.length;if(!e){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,o,n,b,z,i]=this._orders.reduce(([s,a,O,u,l,d,A],h)=>{const{direction:q,qty:_=0,in_price:m,commission:L=0}=h;return q===i1.long?(s+=_,a+=_,d+=_):(s+=_,O+=_,d-=_),u+=_*m,l+=m,A+=L,[s,a,O,u,l,d,A]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-i,this._grossloss=i),this._position_size=z,this._position_avg_price=b/e,this._opentrades_capital_held=n,this._max_contracts_held_all=Math.max(t,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(o,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,o,n,b,z,i,s,a]=this._historyOrders.reduce((l,d)=>{let[A,h,q,_,m,L,g,v]=l;const{profit:y=0,profit_percent:X=0}=d;return A+=y,h+=X,y<0?(q+=y,_+=X,g+=1):y>0&&(m+=y,L+=X,v+=1),[A,h,q,_,m,L,g,v]},[0,0,0,0,0,0,0,0]),O=this._orders.reduce((l,d)=>{const{commission:A=0,qty:h=0,original_qty:q=0}=d,_=A*h/q;return l+_},0);this._avg_trade_percent=t?o/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/s:void 0,this._avg_winning_trade_percent=t?i/a:void 0,this._netprofit=r-O;const u=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,u),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,u),this._grossloss=Math.abs(n-O),this._grossprofit=z,this._eventrades=t-s-a,this._losstrades=s,this._wintrades=a}updateStrategyOptions(e){this._options=e}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 e=this._losstrades;return e?Math.abs(this._grossloss/e):void 0}get avg_losing_trade_percent(){return this._avg_losing_trade_percent}get avg_trade(){if(this._closedtrades)return 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._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const e=this._wintrades;return e?Math.abs(this._grossprofit/e):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var e;return((e=this._options)==null?void 0:e.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:e,margin_long:t=0,margin_short:r=0,commission_type:o,commission_value:n=0}=this._options,b=this._orders[0].direction===i1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[s,a]=this._orders.reduce((O,u)=>{let[l,d]=O;const{in_price:A,qty:h=0,original_qty:q=0}=u,_=A*h;if(l+=_,n){let m=0;switch(o){case O2.percent:m=(_+h*i)*n/100;break;case O2.cashPerContract:m=h*n*2;break;case O2.cashPerOrder:m=h/q*n+n;break}d+=m}return[l,d]},[0,0]);return(s-(e+this._netprofit-a))*b/this._position_size/(1-b*z)}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}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(e,t){if(!this._options)return 0;const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class sm{constructor(e){E(this,"_preAccdist");E(this,"_preNvi");E(this,"_prePvi");E(this,"_preObv");E(this,"_prePvt");E(this,"_preWad");E(this,"_preVwap");E(this,"_preValue");E(this,"_currentData");E(this,"_preData");E(this,"_id");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={},this._id=e}update(e){this._preValue={},e.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...e}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:e,low:t,high:r,volume:o}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*o+this._preAccdist;return!this.isRealTime&&(this._preAccdist=n),this._preValue.accdist=n,n}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:e,low:t,high:r,volume:o}=this._currentData,n=(2*e-r-t)/((r-t)*o);return this._preValue.iii=n,n}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:e,low:t,high:r,volume:o,open:n}=this._currentData,b=(e-n)/(r-t)*o;return this._preValue.wvad=b,b}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const o=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=o),this._preValue.obv=o,o}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:e,high:t}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const o=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=o,o}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const o=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=o),this._preValue.pvt=o,o}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:o}=this._preData;if(o===void 0)return this._preWad=0,0;const n=Math.max(t,o),b=Math.min(r,o),z=e-o,s=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=s),this._preValue.wad=s,s}get vwap(){var a,O;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:o=0,isReset:n}=this._preVwap;if(((O=(a=self.workerStorage)==null?void 0:a.get(this._id))==null?void 0:O.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=o=0),!n)return;const z=e*t+r,i=t+o;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const s=z/i;return this._preValue.vwap=s,s}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n<r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._preNvi=b),this._preValue.nvi=b,b}_getPvi(){const e=this._prePvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n>r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Om{constructor(){E(this,"_period");E(this,"_multiplier");E(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=OM(e);this._multiplier=t,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}}class am{constructor(){E(this,"_bgColor");E(this,"_fgColor");E(this,"isUseBgColor",!1)}updateOptions(e){e!=null&&e.bg_color&&(this._bgColor=e.bg_color,this._fgColor=this._contrastColor(e.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){}get right_visible_bar_time(){}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3]||1}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}_contrastColor(e){const{r:t,g:r,b:o}=this._parseColor(e);return(299*t+587*r+114*o)/1e3>128?"#000000":"#ffffff"}}class um{constructor(){E(this,"_syminfo",{})}update(e){this._syminfo=e}get __syminfo(){return this._syminfo}get basecurrency(){return this._syminfo.basecurrency||""}get country(){return this._syminfo.country}get currency(){return this._syminfo.currency||"USD"}get description(){return this._syminfo.description||""}get employees(){return this._syminfo.employees||100}get expiration_date(){return this._syminfo.expiration_date}get industry(){return this._syminfo.industry}get minmove(){return this._syminfo.minmove&&Number(this._syminfo.minmove)}get mintick(){return this._syminfo.mintick}get pointvalue(){return this._syminfo.pointvalue&&Number(this._syminfo.pointvalue)}get prefix(){return this.tickerid.replace(`:${this.ticker}`,"")}get pricescale(){return this._syminfo.pricescale&&Number(this._syminfo.pricescale)}get recommendations_buy(){return this._syminfo.recommendations_buy}get recommendations_buy_strong(){return this._syminfo.recommendations_buy_strong}get recommendations_date(){return this._syminfo.recommendations_date}get recommendations_hold(){return this._syminfo.recommendations_hold}get recommendations_sell(){return this._syminfo.recommendations_sell}get recommendations_sell_strong(){return this._syminfo.recommendations_sell_strong}get recommendations_total(){return this._syminfo.recommendations_total}get root(){return this._syminfo.root||""}get sector(){return this._syminfo.sector}get session(){return this._syminfo.session||ut.regular}get shareholders(){return this._syminfo.shareholders}get shares_outstanding_float(){return this._syminfo.shares_outstanding_float}get shares_outstanding_total(){return this._syminfo.shares_outstanding_total}get target_price_average(){return this._syminfo.target_price_average}get target_price_date(){return this._syminfo.target_price_date}get target_price_estimates(){return this._syminfo.pricescale}get target_price_high(){return this._syminfo.target_price_high}get target_price_low(){return this._syminfo.target_price_low}get target_price_median(){return this._syminfo.target_price_median}get ticker(){return this._syminfo.ticker||""}get tickerid(){return this._syminfo.tickerid||""}get timezone(){return this._syminfo.timezone||"UTC+8"}get type(){return this._syminfo.type||"forex"}get volumetype(){return this._syminfo.volumetype||"n/a"}}class Am{constructor(e){E(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class fm{constructor(e){E(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class qp{constructor(e){E(this,"_cacheData");E(this,"_barIndex");E(this,"_isRealTimeBar");E(this,"_barstate");E(this,"_priceVariables");E(this,"_lastBarIndex");E(this,"_currentBarTime");E(this,"_lastBarTime");E(this,"_period");E(this,"_offsetTime");E(this,"_timeframe");E(this,"_ta");E(this,"_polyline");E(this,"_label");E(this,"_line");E(this,"_linefill");E(this,"_box");E(this,"_table");E(this,"_strategy");E(this,"_session");E(this,"syminfo");E(this,"chart");E(this,"earnings");E(this,"dividends");E(this,"_timeTradingday");E(this,"_mintick");E(this,"_cacheSpace");E(this,"_precision");E(this,"_nextBarTime");E(this,"_isRepeated");E(this,"_preCacheData");E(this,"__requestName","");E(this,"__isFirstRun",!1);E(this,"_maxBarsBack",0);E(this,"__isReqRepeated");E(this,"_newCacheData",{});this._cacheData={varData:{},varipData:{}},this._preCacheData={varData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zm,this._timeframe=new Om,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new sm(e),this._polyline=new Cr(this),this._label=new Cr(this),this._line=new Cr(this,Q0.LINE),this._linefill=new Cr(this,Q0.LINEFILL),this._box=new Cr(this),this._table=new Cr(this),this._strategy=new cm(this),this._session=new im(this),this.syminfo=new um,this.chart=new am,this.earnings=new fm(this),this.dividends=new Am(this),this._cacheSpace=new Map}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:e,open:t,high:r,low:o}=this._priceVariables;return(e+t+r+o)/4}get hl2(){const{high:e,low:t}=this._priceVariables;return(e+t)/2}get hlc3(){const{close:e,high:t,low:r}=this._priceVariables;return(e+t+r)/3}get hlcc4(){const{close:e,high:t,low:r}=this._priceVariables;return(e*2+t+r)/4}get hour(){return D1(this._currentBarTime).hour()}get minute(){return D1(this._currentBarTime).minute()}get second(){return D1(this._currentBarTime).second()}get month(){return D1(this._currentBarTime).month()+1}get year(){return D1(this._currentBarTime).year()}get dayofweek(){return D1(this._currentBarTime).day()}get dayofmonth(){return D1(this._currentBarTime).date()}get weekofyear(){return D1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=OM(this._period);return D1(this._currentBarTime).add(e,t).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}get nextBarTime(){return this._nextBarTime}set max_bars_back(e){this._maxBarsBack=e}updateMaxLength(e){const{max_lines_count:t,max_labels_count:r,max_boxes_count:o,max_polylines_count:n}=e;o&&this._box.setMaxLen(o),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,o]=OM(t),n=D1(e);return["M","w","y","d"].includes(o)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(e){var s;const{interval:t="1D",offsetTime:r=5,mintick:o,chart:n,syminfo:b}=e,z=((s=o.toString().split(".")[1])==null?void 0:s.length)||5;this._precision=z;const i=Ac(t);this._period=i,this._mintick=o,this._offsetTime=r,this._timeframe.update(i),this.chart.updateOptions(n),this.syminfo.update(b),this._barstate.isFirstRun=this.__isFirstRun}updateData(e,t){const{barIndex:r,c:o,o:n,h:b,l:z,volume:i,time:s,lastBarIndex:a,lastBarTime:O,isrealtime:u,time_tradingday:l,nextBarTime:d}=e;if(this._priceVariables={close:rn(o,this._precision),open:rn(n,this._precision),high:rn(b,this._precision),low:rn(z,this._precision),volume:Number(i)},this._isRealTimeBar=u,this._newCacheData={},r>this._barIndex){const{varData:A,varipData:h}=this._cacheData;this._preCacheData={varData:{},varipData:{}},u?(this._deepCopy(A,this._preCacheData.varData),this._deepCopy(h,this._preCacheData.varipData)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=s*1e3,this._lastBarIndex=a,this._barIndex=r,this._lastBarTime=O*1e3,this._nextBarTime=d*1e3,this._barstate.update(r,a,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){const o=this.setCacheData(e,r),n=this._cacheSpace.get(e)||0;return t=Math.floor(t),n<t&&this._cacheSpace.set(e,t),o[o.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const o=this._cacheSpace.get(e)||0;return o&&r.data.length>(this._maxBarsBack||o+50)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}getTypeInstance(e,t){return new Lu(e,t)}verifyVarAndVarip(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(o))return this._upadteChartDraws(n.varData[o]),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(o)?(this._upadteChartDraws(b[o]),!0):!1}getVarValue(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[o]=this._preCacheData.varData[o],this.__isReqRepeated&&(this._cacheData.varipData[o]=this._preCacheData.varipData[o]));const n=this._cacheData;if(r==="var"){if(this._isRealTimeBar){if(this._newCacheData.hasOwnProperty(o))return this._newCacheData[o];const b=n.varData[o];return typeof b!="object"||b!=null&&b.type?b:b!=null&&b.copy?b.copy():Object.assign({},b)}return n.varData[o]}return this._cacheData.varipData[o]}setVarValue(e,t,r,o){var z;const n=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;let b;switch(typeof r=="object"&&((z=r==null?void 0:r.varipKeys)!=null&&z.length)&&o!=="varip"&&(o="var",b=r.varipKeys),o){case"var":if(this._isRealTimeBar){if(b&&b.length)for(const i of b)this._cacheData.varData[n][i]=r[i];this._newCacheData[n]=r}else this._chartDrawsHandle(r,this._cacheData.varData[n]),this._cacheData.varData[n]=r;break;case"varip":this._chartDrawsHandle(r,this._cacheData.varipData[n]),this._cacheData.varipData[n]=r;break}return r}_upadteChartDraws(e){const t=this._isRealTimeBar?e==null?void 0:e.preId:e==null?void 0:e.id;if(t)switch(e==null?void 0:e.type){case Q0.BOX:this._setChartDraw(t,this._box);break;case Q0.LINE:this._setChartDraw(t,this._line);break;case Q0.POLYLINE:this._setChartDraw(t,this._polyline);break;case Q0.LABEL:this._setChartDraw(t,this._label);break;case Q0.LINEFILL:this._setChartDraw(t,this._linefill);break;case Q0.TABLE:this._setChartDraw(t,this._table);break}}_deepCopy(e,t){for(const r of Object.keys(e)){const o=e[r];typeof o!="object"||o!=null&&o.type?t[r]=o:o!=null&&o.copy?t[r]=o.copy():(t[r]={},this._deepCopy(o,t[r]))}}_setChartDraw(e,t){const r=t.getInstance(e);let o=t.get(e);if(!o||!r)return;const n=r.updateId()||e;n===e&&!this._isRealTimeBar||(o=JSON.parse(JSON.stringify(o)),r.data=o,t.deleteHandle(e,!1),t.set(n,o,r))}_chartDrawsHandle(e,t){const r=t==null?void 0:t.id;let o=e==null?void 0:e.id;o&&e.data&&(e.data.isVar=!0),r!==o&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?D2.uniq([...e,...t]):typeof e=="number"||typeof t=="number"?Number(e)+Number(t):(e||"")+(t||"")}sub(e,t){return Array.isArray(e)&&Array.isArray(t)?e.filter(r=>!t.includes(r)):Number(e)-Number(t)}div(e,t){if(t)return e/t}equal(e,t,r,o){if(e!==void 0&&t!==void 0)return e==t;if(!(r.endsWith(Q0.BOOL)&&e===void 0))return(r.endsWith(Q0.FLOAT)||r.endsWith(Q0.INT)||o.endsWith(Q0.FLOAT)||o.endsWith(Q0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(Q0.STRING)&&e===""&&t===void 0||o.endsWith(Q0.STRING)&&t===""&&e===void 0?!0:r.endsWith(Q0.NA)&&o.endsWith(Q0.NA)?!1:e==t}compareDataHandle(e){if(typeof e!="number"||!e)return e;const t=String(e);if(!t.includes(".")&&!/[eE]/.test(t))return e;const[r,o]=e.toFixed(11).split(".");return+`${r}.${o.slice(0,10)}`}againAssignParse(e,t){var o;if(t)return;const r=(o=e==null?void 0:e.constructor)==null?void 0:o.name;if(r)switch(r){case Ko.name:case E3.name:case Qo.name:case C3.name:case Jo.name:case T3.name:e==null||e.delete();break}}}class Cr{constructor(e,t,r=50){E(this,"_all");E(this,"_allInstance");E(this,"_pseudoArrayAll");E(this,"_maxLength");E(this,"_deleteIds");E(this,"_variables");E(this,"_preDeleteIds");E(this,"_againAddItems");E(this,"_tmpData");E(this,"_tmpInstance");E(this,"_type");E(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new n1,this._maxLength=r,this._deleteIds=new Map,this._variables=e,this._preDeleteIds=new Map,this._againAddItems=[],this._tmpData=new Map,this._tmpInstance=new Map,this._type=t}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get data(){const e=[],t=D2.flatMap([...this._deleteIds.values()]),r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=[];for(const n of r)if(!t.some(b=>b.key===n)){const b=this._tmpData.get(n)||this._all.get(n),z=b==null?void 0:b.id;b&&!o.includes(z)&&(o.push(z),e.push(b))}return this._variables._isRealTimeBar&&this._preDeleteIds.set(this._variables.last_bar_index,this._deleteIds.get(this._variables.last_bar_index)||[]),this._tmpDataHandle(),this._type===Q0.LINEFILL?e:e.slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values(),...this._tmpInstance.values()],this._pseudoArrayAll}add(e,t,r){if(this.set(e,t,r),!this._variables._isRealTimeBar&&this._type!==Q0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:o}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:s}=b;if(s===o)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=D2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(o.some(s=>s.key===z))continue;const i=this._tmpData.get(z)||this._all.get(z);i&&t.push(i)}}return this._againAddItems.length&&(t=this._againAddItems.concat(t),this._againAddItems=[]),this._tmpDataHandle(),t.length?this._type===Q0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:o}=this._variables,n=[];for(const b of e){let z=[...this._deleteIds.get(b)||[]];const i=this._preDeleteIds.get(b)||[];if(b===r&&o){let s=[];for(const a of i){const O=z.findIndex(u=>u.id===a.id);if(O===-1){const u=this._all.get(a.key);u&&n.push(u)}else s.push(a),z.splice(O,1)}this._preDeleteIds.set(r,D2.uniqBy([...z,...s],"id"))}else{const s=[],a=[...this._all.values(),...this._tmpData.values()];for(const O of this._tmpIds)a.some(u=>u.id===O.id)||s.push(O);for(const O of z)i.some(u=>u.id===O.id)||s.push(O);z=s,this._preDeleteIds.delete(b)}t=t.concat(z)}return this._againAddItems=n,D2.uniq(t.map(b=>b.id))}set(e,t,r){this._variables._isRealTimeBar?(this._tmpData.set(e,t),this._tmpInstance.set(e,r)):(this._all.set(e,t),this._allInstance.set(e,r))}get(e){const t=this._all.get(e);let r=this._tmpData.get(e);return this._variables._isRealTimeBar?(r||(r=t?{...t}:void 0,r&&this._tmpData.set(e,r)),r):(this._tmpData.clear(),this._tmpInstance.clear(),t)}getInstance(e){return this._allInstance.get(e)}deleteHandle(e,t=!0){var r;if(this._type===Q0.LINE&&t){const o=(r=this._allInstance.get(e))==null?void 0:r.__fillKeys;if(o&&o.length)for(const n of o)this._variables.linefill.deleteHandle(n)}this._variables._isRealTimeBar?(this._tmpData.delete(e),this._tmpInstance.delete(e)):(this._all.delete(e),this._allInstance.delete(e))}delete(e,t,r){const o=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(o==null?void 0:o.id)||r}),this._deleteIds.set(t,n)}}_tmpDataHandle(){var e;this._tmpIds=[];for(const[t]of this._tmpInstance){const r=(e=this._tmpData.get(t))==null?void 0:e.id;r&&this._tmpIds.push({id:r,key:t})}this._tmpData.clear(),this._tmpInstance.clear(),this._deleteIds.clear()}}/**
|
85
|
+
${l}`),l}_getRequestLowerTfData(e,t,r,o){var L;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:s}=e;const{__period:a,time:O,_isRealTimeBar:u}=this._variables;b=hr(b);let l=N2(b,O)*1e3;const d=N2(a,O)*1e3;if(l>d)return!s&&this._errorListener.addError(r2(l1.requestLowerTfPeriodErr,{period:b}),t,$0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),q=self.workerStorage.get(`request_${this._scriptId}_list`),_=self.workerStorage.get(`request_${this._scriptId}_tmp`),m={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:ii[b]||ic(b)};if(h!=null&&h.has(A)){_==null||_.delete(A);const{index:g=0,periodStamp:v=d}=this._cacheData.get(r)||{},y=h==null?void 0:h.get(A);if(!y.length)return[];if(y.length-1<0)return[];const T=y.slice(g);let N=O,D=v+N;const C=[];for(const[P,H]of T.entries()){let{time:G}=H;G=G*1e3;let k=g+P;if(G>=D)return!u&&this._cacheData.set(r,{index:k,periodStamp:v}),C;if(N<=G&&G<D){const J=(L=H==null?void 0:H.result)==null?void 0:L[r];if(Array.isArray(J))for(const[o0,z0]of J.entries())C[o0]||(C[o0]=[]),C[o0].push(z0);else o||C.push(J)}}return!u&&this._cacheData.set(r,{index:y.length,periodStamp:v}),C}else(q==null?void 0:q.get(A))||_==null||_.set(A,m);q==null||q.set(A,m)}_getRequestData(e,t){var _,m,L,g,v;let{symbol:r,timeframe:o,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:s,mintick:a,time:O,nextBarTime:u}=this._variables;o=hr(o),r=r;const l=`${r}--${o}`,d=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),q={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:o,timeframe:ii[o]||ic(o)};if(d!=null&&d.has(l)){let y=N2(o,O)*1e3;const X=N2(s,O)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=X}=this._cacheData.get(t)||{},D=d==null?void 0:d.get(l);if(!D.length)return;const C=D.slice(T);let P=O,H=N+P;const G=D.length-1;if(G<0)return;const k={lastBarIndex:D[G].barindex||G,lastBarTime:D[G].time,interval:o,mintick:a};if(y>N){let J;if(z===Pe.lookaheadOn?J=this._lookaheadOnHandle(C,o,H,y,k,T,N,t,P,b):J=this._lookaheadOffHandle(C,o,H,y,k,T,N,t,P,u||H,b),J)return J;if(J===null)return}else if(z===Pe.lookaheadOn)for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((_=C[J+1])==null?void 0:_.time)*1e3||z0+y;let w0=T+J;if(z0>=H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<=P&&v0>P){const u0=T+J;return this._cacheData.set(t,{index:u0,periodStamp:N}),{...o0,barIndex:a0||u0,nextBarTime:(m=C[J+1])==null?void 0:m.time,...k}}}else for(const[J,o0]of C.entries()){let{time:z0,barindex:a0}=o0;z0=z0*1e3;const v0=((L=C[J+1])==null?void 0:L.time)*1e3||z0+y;let w0=T+J;if(z0>H){this._cacheData.set(t,{index:w0,periodStamp:N});return}if(z0<H&&H<=v0)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(g=C[J+1])==null?void 0:g.time,...k};if(z0>=P&&z0<=H&&(a0||w0)===k.lastBarIndex)return this._cacheData.set(t,{index:w0,periodStamp:N}),{...o0,barIndex:a0||w0,nextBarTime:(v=C[J+1])==null?void 0:v.time,...k}}this._cacheData.set(t,{index:D.length,periodStamp:N});return}else(A==null?void 0:A.get(l))||h==null||h.set(l,q);A==null||A.set(l,q)}_lookaheadOnHandle(e,t,r,o,n,b,z,i,s,a){var O;for(const[u,l]of e.entries()){let{time:d,barindex:A}=l;d=d*1e3,t.includes("M")&&(o=N2(t,d)*1e3-(D1(d).date()-1)*864e5);const h=d,q=o+h;let _=b+u;if(r<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),null;let m={...l,barIndex:A||_,nextBarTime:(O=e[u+1])==null?void 0:O.time,...n};if(a===Pe.gapsOn){if(r>h&&s<=h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}else{if(r>q)continue;if(r>h)return this._cacheData.set(i,{index:_,periodStamp:z}),m}}}_lookaheadOffHandle(e,t,r,o,n,b,z,i,s,a,O){var u,l;for(const[d,A]of e.entries()){let{time:h,barindex:q}=A;h=h*1e3,t.includes("M")&&(o=N2(t,h)*1e3-(D1(h).date()-1)*864e5);const _=h,m=o+_,L=b+d;if(r<_)return this._cacheData.set(i,{index:L,periodStamp:z}),null;const g={...A,barIndex:q||L,nextBarTime:(u=e[d+1])==null?void 0:u.time,...n};if(r>=m&&s<m||r<m&&a>=m)return O===Pe.gapsOn?(this._cacheData.set(i,{index:L,periodStamp:z}),g):(this._cacheData.set(i,{index:L,data:g,periodStamp:z}),g);if(!(s>m)&&s>=_){let v=(l=this._cacheData.get(i))==null?void 0:l.data;if(!v){const y=e[L-1];if(!y)return null;v={...y,barIndex:y.barindex||L-1,nextBarTime:g.time,...n},this._cacheData.set(i,{index:L,data:v,periodStamp:z})}return v}}}_getDependCodes(e,t,r,o,n,b){for(const z of e){if(!z.isArg){const i=t.filter(a=>{var O;return(O=a==null?void 0:a.depends)==null?void 0:O.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const a of i){const{code:O,depends:u,scope:l,funcName:d}=a;r[l]=r[l]||[];const A=r[l];let h=l===0&&d;if(!A.includes(O)){if(h){if(o.includes(O))continue;o.unshift(O)}else A.unshift(O);if(u!=null&&u.length){for(const q of u)q.memberCode&&!h&&b.push(q.memberCode);this._getDependCodes(u,t,r,o,n,b)}}}const s=t.find(a=>{var O;return((O=a.varNames)==null?void 0:O.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&a.methodName===z.functionName)||a.funcName===z.name});if(s){const{code:a,depends:O,scope:u}=s;r[u]=r[u]||[];const l=r[u],d=l.findIndex(A=>A===a);if(d!==-1){if(z.isFunc)continue;l.splice(d,1)}if(l.unshift(a),O!=null&&O.length){for(const A of O)A.memberCode&&b.push(A.memberCode);this._getDependCodes(O,t,r,o,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,o,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:s,scope:a=0}=z;e[a]=e[a]||[];const O=e[a];if(!O.includes(i)&&(O.push(i),s!=null&&s.length)){for(const u of s)u.memberCode&&r.push(u.memberCode);this._getDependCodes(s.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,o,n,r)}}}runScripts(e,t,r,o,n,b){var u;const z=`${this._scriptId}_${t}`;let{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O}=self.workerStorage.get(z)||{};if(r&&(i=new qp(z),s=new fp,a=new lp(this._variables.mintick||1e-5,i,this._scriptId),O=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e),i.__requestName=t,self.workerStorage.set(z,{builtInGather:i,buildinConstants:s,buildInFunctions:a,tradingvueFunc:O})),o&&o.length){const l=o.length-1,{interval:d,symbol:A=""}=n,{mintick:h,syminfo:q}=this._variables,[_,m]=A.split(":");i.updateOptions({interval:d,mintick:h,syminfo:{...q.__syminfo,tickerid:A||q.tickerid,ticker:m||_||q.ticker}});for(const[v,y]of o.entries()){const{barindex:X}=y,T=Object.assign(y,{barIndex:X||v,lastBarIndex:o[l].barindex||l,lastBarTime:o[l].time,nextBarTime:(u=o[v+1])==null?void 0:u.time});if(i.updateData(T),a.update({barIndex:(T==null?void 0:T.barindex)||0}),y.result=Object.assign(y.result||{},{[t]:O(i,s,a,b||[],t)}),a.endExecution(),a.errors.length&&a.errors.some(N=>N.type===$0.Error))return{logs:[],errors:a.errors}}const L=a.log.logs,g=a.errors;return a.log.clearLogs(),a.clearErrors(),{logs:L,errors:g}}}_runScripts(e,t,r,o,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a}=self.workerStorage.get(b)||{};const{interval:O,...u}=n||{};if(r){z=new qp(b),i=new fp,s=new lp(this._variables.mintick||1e-5,z,this._scriptId),a=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:q}=this._variables;z.updateOptions({interval:O,mintick:h||1e-5,syminfo:{...q.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:s,tradingvueFunc:a})}z.updateData(u),s.update({barIndex:(u==null?void 0:u.barindex)||0});const l=a(z,i,s,o||[],t),d=s.log.logs,A=s.errors;return s.log.clearLogs(),s.clearErrors(),s.endExecution(),{result:l,logs:d,errors:A}}},om=class{constructor(){}prefix(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[0])||""}ticker(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[1])||""}};class nm{constructor(e,t){E(this,"_logs");E(this,"_variables");E(this,"_str");E(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get logs(){return this._logs}clearLogForIndex(e){this._logs=this._logs.filter(t=>t.barIndex!==e)}clearLogs(){this._logs=[]}info(e,t,r){this._addLog(e,t,"info",r)}error(e,t,r){this._addLog(e,t,"error",r)}warning(e,t,r){this._addLog(e,t,"warning",r)}mergeLogs(e){this._logs=this._logs.concat(e)}_addLog(e,t,r,o){if(typeof t=="string"&&(o=t),o.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:s,__isReqRepeated:a}=this._variables;let O=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>(typeof A=="object"&&(A.isArray?A=JSON.stringify(A._value):A=A.toString()),A!==void 0?A:"na")),O=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:s});const d=Date.now();O!==void 0&&this._logs.push({message:`[${D1(u&&!a?d:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${O}`,time:z,id:I4(6),barIndex:i,type:r})}}class bm{constructor(e){E(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,$0.Error)}}class pm{constructor(){E(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return D2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,o=0){const[n,b]=t.split("_").slice(-2),z=this._errors.get(t),i={message:e,endLineNumber:Number(n),startColumn:Number(b)+1,endColumn:Number(b)+o+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class zm{constructor(){E(this,"_isMarketOpen");E(this,"_currentBarIndex");E(this,"_totalBarIndex");E(this,"_isRealTimeBar");E(this,"_preBarIndex");E(this,"_preIsRealTimeBar");E(this,"_isFirstRun",!1);this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0,this._preIsRealTimeBar=!1}update(e,t,r,o){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=o}set isFirstRun(e){this._isFirstRun=e}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex||!this._isFirstRun}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar||this._isFirstRun}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1&&!this._preIsRealTimeBar||this._currentBarIndex===this._totalBarIndex&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class im{constructor(e){E(this,"_variables");this._variables=e}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{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const{time:e,__period:t}=this._variables,r=N2(t,e);return this._variables.time+r===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class cm{constructor(e){E(this,"_orders");E(this,"_historyOrders");E(this,"_options");E(this,"_max_contracts_held_all",0);E(this,"_max_contracts_held_long",0);E(this,"_max_contracts_held_short",0);E(this,"_max_drawdown",0);E(this,"_max_runup",0);E(this,"_max_runup_percent",0);E(this,"_max_drawdown_percent",0);E(this,"_variables");E(this,"_netprofit",0);E(this,"_eventrades",0);E(this,"_avg_trade_percent");E(this,"_avg_losing_trade_percent");E(this,"_avg_winning_trade_percent");E(this,"_closedtrades",0);E(this,"_losstrades",0);E(this,"_grossloss",0);E(this,"_grossprofit",0);E(this,"_wintrades",0);E(this,"_opentrades_capital_held",0);E(this,"_position_avg_price",0);E(this,"_position_size",0);E(this,"_openprofit",0);E(this,"_preMaxNetValue",0);E(this,"_preMinNetValue",0);E(this,"marginCallLong",0);E(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=e}update(e){this._calcMaxDrawdownAndMaxRunup(e)}_calcMaxDrawdownAndMaxRunup(e){if(!this._orders.length&&!this._historyOrders.length)return;let t=0,r=0;const{high:o,low:n,close:b}=e;let z=0;for(const[a,O]of this._orders.entries()){const{in_price:u,qty:l=0,direction:d,commission:A,original_qty:h=1}=O,q=d===i1.long?1:-1,_=(o-u)*l,m=(n-u)*l,L=q===1?_:-m,g=q===1?-m:_;z+=(b-u)*q*l,t+=g,a>0&&A&&(r-=A*l/h),r+=L}this._openprofit=z;const i=this.initial_capital,s=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-s+Math.max(t,0),r=s-this._preMinNetValue+r,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/this._preMaxNetValue*100),r>this._max_runup&&(this._max_runup=r,this._max_runup_percent=r/(this._preMinNetValue+r)*100)}updateOrders(e){this._orders=e,this._calcMaxContracts()}_calcMaxContracts(){const e=this._orders.length;if(!e){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,o,n,b,z,i]=this._orders.reduce(([s,a,O,u,l,d,A],h)=>{const{direction:q,qty:_=0,in_price:m,commission:L=0}=h;return q===i1.long?(s+=_,a+=_,d+=_):(s+=_,O+=_,d-=_),u+=_*m,l+=m,A+=L,[s,a,O,u,l,d,A]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-i,this._grossloss=i),this._position_size=z,this._position_avg_price=b/e,this._opentrades_capital_held=n,this._max_contracts_held_all=Math.max(t,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(o,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,o,n,b,z,i,s,a]=this._historyOrders.reduce((l,d)=>{let[A,h,q,_,m,L,g,v]=l;const{profit:y=0,profit_percent:X=0}=d;return A+=y,h+=X,y<0?(q+=y,_+=X,g+=1):y>0&&(m+=y,L+=X,v+=1),[A,h,q,_,m,L,g,v]},[0,0,0,0,0,0,0,0]),O=this._orders.reduce((l,d)=>{const{commission:A=0,qty:h=0,original_qty:q=0}=d,_=A*h/q;return l+_},0);this._avg_trade_percent=t?o/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/s:void 0,this._avg_winning_trade_percent=t?i/a:void 0,this._netprofit=r-O;const u=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,u),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,u),this._grossloss=Math.abs(n-O),this._grossprofit=z,this._eventrades=t-s-a,this._losstrades=s,this._wintrades=a}updateStrategyOptions(e){this._options=e}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 e=this._losstrades;return e?Math.abs(this._grossloss/e):void 0}get avg_losing_trade_percent(){return this._avg_losing_trade_percent}get avg_trade(){if(this._closedtrades)return 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._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const e=this._wintrades;return e?Math.abs(this._grossprofit/e):void 0}get avg_winning_trade_percent(){return this._avg_winning_trade_percent}get initial_capital(){var e;return((e=this._options)==null?void 0:e.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:e,margin_long:t=0,margin_short:r=0,commission_type:o,commission_value:n=0}=this._options,b=this._orders[0].direction===i1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[s,a]=this._orders.reduce((O,u)=>{let[l,d]=O;const{in_price:A,qty:h=0,original_qty:q=0}=u,_=A*h;if(l+=_,n){let m=0;switch(o){case O2.percent:m=(_+h*i)*n/100;break;case O2.cashPerContract:m=h*n*2;break;case O2.cashPerOrder:m=h/q*n+n;break}d+=m}return[l,d]},[0,0]);return(s-(e+this._netprofit-a))*b/this._position_size/(1-b*z)}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}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(e,t){if(!this._options)return 0;const{commission_value:r=0,commission_type:o}=this._options,n=e*t;let b=0;switch(o){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class sm{constructor(e){E(this,"_preAccdist");E(this,"_preNvi");E(this,"_prePvi");E(this,"_preObv");E(this,"_prePvt");E(this,"_preWad");E(this,"_preVwap");E(this,"_preValue");E(this,"_currentData");E(this,"_preData");E(this,"_id");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={},this._id=e}update(e){this._preValue={},e.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...e}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:e,low:t,high:r,volume:o}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*o+this._preAccdist;return!this.isRealTime&&(this._preAccdist=n),this._preValue.accdist=n,n}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:e,low:t,high:r,volume:o}=this._currentData,n=(2*e-r-t)/((r-t)*o);return this._preValue.iii=n,n}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:e,low:t,high:r,volume:o,open:n}=this._currentData,b=(e-n)/(r-t)*o;return this._preValue.wvad=b,b}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const o=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=o),this._preValue.obv=o,o}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:e,high:t}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const o=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=o,o}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const o=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=o),this._preValue.pvt=o,o}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:o}=this._preData;if(o===void 0)return this._preWad=0,0;const n=Math.max(t,o),b=Math.min(r,o),z=e-o,s=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=s),this._preValue.wad=s,s}get vwap(){var a,O;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:o=0,isReset:n}=this._preVwap;if(((O=(a=self.workerStorage)==null?void 0:a.get(this._id))==null?void 0:O.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=o=0),!n)return;const z=e*t+r,i=t+o;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const s=z/i;return this._preValue.vwap=s,s}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n<r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._preNvi=b),this._preValue.nvi=b,b}_getPvi(){const e=this._prePvi||1,{close:t=0,volume:r=0}=this._preData,{close:o,volume:n}=this._currentData;let b=1;const z=e||1;return o&&t?b=n>r?z+(o-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Om{constructor(){E(this,"_period");E(this,"_multiplier");E(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=OM(e);this._multiplier=t,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}}class am{constructor(){E(this,"_bgColor");E(this,"_fgColor");E(this,"isUseBgColor",!1)}updateOptions(e){e!=null&&e.bg_color&&(this._bgColor=e.bg_color,this._fgColor=this._contrastColor(e.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){}get right_visible_bar_time(){}_parseColor(e){let t,r,o,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),o=parseInt(e.substring(5,7),16);const b=e.substring(7);b?n=parseInt(b,16)/255:n=1}else{const b=this._parserRgbColor(e);t=b[0]||0,r=b[1]||0,o=b[2]||0,n=b[3]||1}return{r:t,g:r,b:o,a:n}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}_contrastColor(e){const{r:t,g:r,b:o}=this._parseColor(e);return(299*t+587*r+114*o)/1e3>128?"#000000":"#ffffff"}}class um{constructor(){E(this,"_syminfo",{})}update(e){this._syminfo=e}get __syminfo(){return this._syminfo}get basecurrency(){return this._syminfo.basecurrency||""}get country(){return this._syminfo.country}get currency(){return this._syminfo.currency||"USD"}get description(){return this._syminfo.description||""}get employees(){return this._syminfo.employees||100}get expiration_date(){return this._syminfo.expiration_date}get industry(){return this._syminfo.industry}get minmove(){return this._syminfo.minmove&&Number(this._syminfo.minmove)}get mintick(){return this._syminfo.mintick}get pointvalue(){return this._syminfo.pointvalue&&Number(this._syminfo.pointvalue)}get prefix(){return this.tickerid.replace(`:${this.ticker}`,"")}get pricescale(){return this._syminfo.pricescale&&Number(this._syminfo.pricescale)}get recommendations_buy(){return this._syminfo.recommendations_buy}get recommendations_buy_strong(){return this._syminfo.recommendations_buy_strong}get recommendations_date(){return this._syminfo.recommendations_date}get recommendations_hold(){return this._syminfo.recommendations_hold}get recommendations_sell(){return this._syminfo.recommendations_sell}get recommendations_sell_strong(){return this._syminfo.recommendations_sell_strong}get recommendations_total(){return this._syminfo.recommendations_total}get root(){return this._syminfo.root||""}get sector(){return this._syminfo.sector}get session(){return this._syminfo.session||ut.regular}get shareholders(){return this._syminfo.shareholders}get shares_outstanding_float(){return this._syminfo.shares_outstanding_float}get shares_outstanding_total(){return this._syminfo.shares_outstanding_total}get target_price_average(){return this._syminfo.target_price_average}get target_price_date(){return this._syminfo.target_price_date}get target_price_estimates(){return this._syminfo.pricescale}get target_price_high(){return this._syminfo.target_price_high}get target_price_low(){return this._syminfo.target_price_low}get target_price_median(){return this._syminfo.target_price_median}get ticker(){return this._syminfo.ticker||""}get tickerid(){return this._syminfo.tickerid||""}get timezone(){return this._syminfo.timezone||"UTC+8"}get type(){return this._syminfo.type||"forex"}get volumetype(){return this._syminfo.volumetype||"n/a"}}class Am{constructor(e){E(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class fm{constructor(e){E(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class qp{constructor(e){E(this,"_cacheData");E(this,"_barIndex");E(this,"_isRealTimeBar");E(this,"_barstate");E(this,"_priceVariables");E(this,"_lastBarIndex");E(this,"_currentBarTime");E(this,"_lastBarTime");E(this,"_period");E(this,"_offsetTime");E(this,"_timeframe");E(this,"_ta");E(this,"_polyline");E(this,"_label");E(this,"_line");E(this,"_linefill");E(this,"_box");E(this,"_table");E(this,"_strategy");E(this,"_session");E(this,"syminfo");E(this,"chart");E(this,"earnings");E(this,"dividends");E(this,"_timeTradingday");E(this,"_mintick");E(this,"_cacheSpace");E(this,"_precision");E(this,"_nextBarTime");E(this,"_isRepeated");E(this,"_preCacheData");E(this,"__requestName","");E(this,"__isFirstRun",!1);E(this,"_maxBarsBack",0);E(this,"__isReqRepeated");E(this,"_newCacheData",{});this._cacheData={varData:{},varipData:{}},this._preCacheData={varData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new zm,this._timeframe=new Om,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new sm(e),this._polyline=new Cr(this),this._label=new Cr(this),this._line=new Cr(this,Q0.LINE),this._linefill=new Cr(this,Q0.LINEFILL),this._box=new Cr(this),this._table=new Cr(this),this._strategy=new cm(this),this._session=new im(this),this.syminfo=new um,this.chart=new am,this.earnings=new fm(this),this.dividends=new Am(this),this._cacheSpace=new Map}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:e,open:t,high:r,low:o}=this._priceVariables;return(e+t+r+o)/4}get hl2(){const{high:e,low:t}=this._priceVariables;return(e+t)/2}get hlc3(){const{close:e,high:t,low:r}=this._priceVariables;return(e+t+r)/3}get hlcc4(){const{close:e,high:t,low:r}=this._priceVariables;return(e*2+t+r)/4}get hour(){return D1(this._currentBarTime).hour()}get minute(){return D1(this._currentBarTime).minute()}get second(){return D1(this._currentBarTime).second()}get month(){return D1(this._currentBarTime).month()+1}get year(){return D1(this._currentBarTime).year()}get dayofweek(){return D1(this._currentBarTime).day()}get dayofmonth(){return D1(this._currentBarTime).date()}get weekofyear(){return D1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=OM(this._period);return D1(this._currentBarTime).add(e,t).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}get precision(){return this._precision}get nextBarTime(){return this._nextBarTime}set max_bars_back(e){this._maxBarsBack=e}updateMaxLength(e){const{max_lines_count:t,max_labels_count:r,max_boxes_count:o,max_polylines_count:n}=e;o&&this._box.setMaxLen(o),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,o]=OM(t),n=D1(e);return["M","w","y","d"].includes(o)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(e){var s;const{interval:t="1D",offsetTime:r=5,mintick:o,chart:n,syminfo:b}=e,z=((s=o.toString().split(".")[1])==null?void 0:s.length)||5;this._precision=z;const i=Ac(t);this._period=i,this._mintick=o,this._offsetTime=r,this._timeframe.update(i),this.chart.updateOptions(n),this.syminfo.update(b),this._barstate.isFirstRun=this.__isFirstRun}updateData(e,t){const{barIndex:r,c:o,o:n,h:b,l:z,volume:i,time:s,lastBarIndex:a,lastBarTime:O,isrealtime:u,time_tradingday:l,nextBarTime:d}=e;if(this._priceVariables={close:rn(o,this._precision),open:rn(n,this._precision),high:rn(b,this._precision),low:rn(z,this._precision),volume:Number(i)},this._isRealTimeBar=u,this._newCacheData={},r>this._barIndex){const{varData:A,varipData:h}=this._cacheData;this._preCacheData={varData:{},varipData:{}},u?(this._deepCopy(A,this._preCacheData.varData),this._deepCopy(h,this._preCacheData.varipData)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=s*1e3,this._lastBarIndex=a,this._barIndex=r,this._lastBarTime=O*1e3,this._nextBarTime=d*1e3,this._barstate.update(r,a,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){const o=this.setCacheData(e,r),n=this._cacheSpace.get(e)||0;return t=Math.floor(t),n<t&&this._cacheSpace.set(e,t),o[o.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const o=this._cacheSpace.get(e)||0;return o&&r.data.length>(this._maxBarsBack||o+50)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}getTypeInstance(e,t){return new Lu(e,t)}verifyVarAndVarip(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(o))return this._upadteChartDraws(n.varData[o]),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(o)?(this._upadteChartDraws(b[o]),!0):!1}getVarValue(e,t,r){const o=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[o]=this._preCacheData.varData[o],this.__isReqRepeated&&(this._cacheData.varipData[o]=this._preCacheData.varipData[o]));const n=this._cacheData;if(r==="var"){if(this._isRealTimeBar){if(this._newCacheData.hasOwnProperty(o))return this._newCacheData[o];const b=n.varData[o];return typeof b!="object"||b!=null&&b.type?b:b!=null&&b.copy?b.copy():Object.assign({},b)}return n.varData[o]}return this._cacheData.varipData[o]}setVarValue(e,t,r,o){var z;const n=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;let b;switch(typeof r=="object"&&((z=r==null?void 0:r.varipKeys)!=null&&z.length)&&o!=="varip"&&(o="var",b=r.varipKeys),o){case"var":if(this._isRealTimeBar){if(b&&b.length)for(const i of b)this._cacheData.varData[n][i]=r[i];this._newCacheData[n]=r}else this._chartDrawsHandle(r,this._cacheData.varData[n]),this._cacheData.varData[n]=r;break;case"varip":this._chartDrawsHandle(r,this._cacheData.varipData[n]),this._cacheData.varipData[n]=r;break}return r}_upadteChartDraws(e){const t=this._isRealTimeBar?e==null?void 0:e.preId:e==null?void 0:e.id;if(t)switch(e==null?void 0:e.type){case Q0.BOX:this._setChartDraw(t,this._box);break;case Q0.LINE:this._setChartDraw(t,this._line);break;case Q0.POLYLINE:this._setChartDraw(t,this._polyline);break;case Q0.LABEL:this._setChartDraw(t,this._label);break;case Q0.LINEFILL:this._setChartDraw(t,this._linefill);break;case Q0.TABLE:this._setChartDraw(t,this._table);break}}_deepCopy(e,t){for(const r of Object.keys(e)){const o=e[r];typeof o!="object"||o!=null&&o.type?t[r]=o:o!=null&&o.copy?t[r]=o.copy():(t[r]={},this._deepCopy(o,t[r]))}}_setChartDraw(e,t){const r=t.getInstance(e);let o=t.get(e);if(!o||!r)return;const n=r.updateId()||e;n===e&&!this._isRealTimeBar||(o=JSON.parse(JSON.stringify(o)),r.data=o,t.deleteHandle(e,!1),t.set(n,o,r))}_chartDrawsHandle(e,t){const r=t==null?void 0:t.id;let o=e==null?void 0:e.id;o&&e.data&&(e.data.isVar=!0),r!==o&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?D2.uniq([...e,...t]):typeof e=="number"||typeof t=="number"?Number(e)+Number(t):(e||"")+(t||"")}sub(e,t){return Array.isArray(e)&&Array.isArray(t)?e.filter(r=>!t.includes(r)):Number(e)-Number(t)}div(e,t){if(t)return e/t}equal(e,t,r,o){if(e!==void 0&&t!==void 0)return e==t;if(!(r.endsWith(Q0.BOOL)&&e===void 0))return(r.endsWith(Q0.FLOAT)||r.endsWith(Q0.INT)||o.endsWith(Q0.FLOAT)||o.endsWith(Q0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(Q0.STRING)&&e===""&&t===void 0||o.endsWith(Q0.STRING)&&t===""&&e===void 0?!0:r.endsWith(Q0.NA)&&o.endsWith(Q0.NA)?!1:e==t}compareDataHandle(e){if(typeof e!="number"||!e)return e;const t=String(e);if(!t.includes(".")&&!/[eE]/.test(t))return e;const[r,o]=e.toFixed(11).split(".");return+`${r}.${o.slice(0,10)}`}againAssignParse(e,t){var o;if(t)return;const r=(o=e==null?void 0:e.constructor)==null?void 0:o.name;if(r)switch(r){case Ko.name:case E3.name:case Qo.name:case C3.name:case Jo.name:case T3.name:e==null||e.delete();break}}}class Cr{constructor(e,t,r=50){E(this,"_all");E(this,"_allInstance");E(this,"_pseudoArrayAll");E(this,"_maxLength");E(this,"_deleteIds");E(this,"_variables");E(this,"_preDeleteIds");E(this,"_againAddItems");E(this,"_tmpData");E(this,"_tmpInstance");E(this,"_type");E(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new n1,this._maxLength=r,this._deleteIds=new Map,this._variables=e,this._preDeleteIds=new Map,this._againAddItems=[],this._tmpData=new Map,this._tmpInstance=new Map,this._type=t}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get data(){const e=[],t=D2.flatMap([...this._deleteIds.values()]),r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=[];for(const n of r)if(!t.some(b=>b.key===n)){const b=this._tmpData.get(n)||this._all.get(n),z=b==null?void 0:b.id;b&&!o.includes(z)&&(o.push(z),e.push(b))}return this._variables._isRealTimeBar&&this._preDeleteIds.set(this._variables.last_bar_index,this._deleteIds.get(this._variables.last_bar_index)||[]),this._tmpDataHandle(),this._type===Q0.LINEFILL?e:e.slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values(),...this._tmpInstance.values()],this._pseudoArrayAll}add(e,t,r){if(this.set(e,t,r),!this._variables._isRealTimeBar&&this._type!==Q0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:o}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:s}=b;if(s===o)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=D2.uniq([...this._all.keys(),...this._tmpData.keys()]),o=D2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(o.some(s=>s.key===z))continue;const i=this._tmpData.get(z)||this._all.get(z);i&&t.push(i)}}return this._againAddItems.length&&(t=this._againAddItems.concat(t),this._againAddItems=[]),this._tmpDataHandle(),t.length?this._type===Q0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:o}=this._variables,n=[];for(const z of e){let i=[...this._deleteIds.get(z)||[]];const s=this._preDeleteIds.get(z)||[];if(z===r&&o){let a=[];for(const O of s){const u=i.findIndex(l=>l.id===O.id);if(u===-1){const l=this._all.get(O.key);l&&n.push(l)}else a.push(O),i.splice(u,1)}this._preDeleteIds.set(r,D2.uniqBy([...i,...a],"id"))}else{const a=[];for(const O of i)s.some(u=>u.id===O.id)||a.push(O);i=a,this._preDeleteIds.delete(z)}t=t.concat(i)}const b=[...this._all.values(),...this._tmpData.values()];for(const z of this._tmpIds)b.some(i=>i.id===z.id)||t.push(z);return this._againAddItems=n,D2.uniq(t.map(z=>z.id))}set(e,t,r){this._variables._isRealTimeBar?(this._tmpData.set(e,t),this._tmpInstance.set(e,r)):(this._all.set(e,t),this._allInstance.set(e,r))}get(e){const t=this._all.get(e);let r=this._tmpData.get(e);return this._variables._isRealTimeBar?(r||(r=t?{...t}:void 0,r&&this._tmpData.set(e,r)),r):(this._tmpData.clear(),this._tmpInstance.clear(),t)}getInstance(e){return this._allInstance.get(e)}deleteHandle(e,t=!0){var r;if(this._type===Q0.LINE&&t){const o=(r=this._allInstance.get(e))==null?void 0:r.__fillKeys;if(o&&o.length)for(const n of o)this._variables.linefill.deleteHandle(n)}this._variables._isRealTimeBar?(this._tmpData.delete(e),this._tmpInstance.delete(e)):(this._all.delete(e),this._allInstance.delete(e))}delete(e,t,r){const o=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(o==null?void 0:o.id)||r}),this._deleteIds.set(t,n)}}_tmpDataHandle(){var e;this._tmpIds=[];for(const[t]of this._tmpInstance){const r=(e=this._tmpData.get(t))==null?void 0:e.id;r&&this._tmpIds.push({id:r,key:t})}this._tmpData.clear(),this._tmpInstance.clear(),this._deleteIds.clear()}}/**
|
86
86
|
* @license
|
87
87
|
* Copyright 2019 Google LLC
|
88
88
|
* SPDX-License-Identifier: Apache-2.0
|