@guihz/trading-vue-editor-tes 0.0.288 → 0.0.290
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assets/{parserTccWorker-DMNGR4iS.js → parserTccWorker-CG4IgAww.js} +4 -4
- package/lib/assets/{scriptsRunWorker-BmSQ0ITR.js → scriptsRunWorker-Bj5i72x4.js} +2 -2
- package/lib/trading-vue-editor.es.packages.js +2 -2
- package/lib/trading-vue-editor.umd.packages.mjs +1 -1
- package/package.json +1 -1
@@ -65,7 +65,7 @@ Example:
|
|
65
65
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
66
66
|
**/(function(o,e){(function(t){var r=2e3,M={s:1,n:0,d:1};function n(d,m){if(isNaN(d=parseInt(d,10)))throw A();return d*m}function b(d,m){if(m===0)throw q();var _=Object.create(l.prototype);_.s=d<0?-1:1,d=d<0?-d:d;var R=u(d,m);return _.n=d/R,_.d=m/R,_}function z(d){for(var m={},_=d,R=2,g=4;g<=_;){for(;_%R===0;)_/=R,m[R]=(m[R]||0)+1;g+=1+2*R++}return _!==d?_>1&&(m[_]=(m[_]||0)+1):m[d]=(m[d]||0)+1,m}var i=function(d,m){var _=0,R=1,g=1,L=0,y=0,D=0,T=1,N=1,w=0,E=1,P=1,H=1,Y=1e7,k;if(d!=null)if(m!==void 0){if(_=d,R=m,g=_*R,_%1!==0||R%1!==0)throw h()}else switch(typeof d){case"object":{if("d"in d&&"n"in d)_=d.n,R=d.d,"s"in d&&(_*=d.s);else if(0 in d)_=d[0],1 in d&&(R=d[1]);else throw A();g=_*R;break}case"number":{if(d<0&&(g=d,d=-d),d%1===0)_=d;else if(d>0){for(d>=1&&(N=Math.pow(10,Math.floor(1+Math.log(d)/Math.LN10)),d/=N);E<=Y&&H<=Y;)if(k=(w+P)/(E+H),d===k){E+H<=Y?(_=w+P,R=E+H):H>E?(_=P,R=H):(_=w,R=E);break}else d>k?(w+=P,E+=H):(P+=w,H+=E),E>Y?(_=P,R=H):(_=w,R=E);_*=N}else(isNaN(d)||isNaN(m))&&(R=_=NaN);break}case"string":{if(E=d.match(/\d+|./g),E===null)throw A();if(E[w]==="-"?(g=-1,w++):E[w]==="+"&&w++,E.length===w+1?y=n(E[w++],g):E[w+1]==="."||E[w]==="."?(E[w]!=="."&&(L=n(E[w++],g)),w++,(w+1===E.length||E[w+1]==="("&&E[w+3]===")"||E[w+1]==="'"&&E[w+3]==="'")&&(y=n(E[w],g),T=Math.pow(10,E[w].length),w++),(E[w]==="("&&E[w+2]===")"||E[w]==="'"&&E[w+2]==="'")&&(D=n(E[w+1],g),N=Math.pow(10,E[w+1].length)-1,w+=3)):E[w+1]==="/"||E[w+1]===":"?(y=n(E[w],g),T=n(E[w+2],1),w+=3):E[w+3]==="/"&&E[w+1]===" "&&(L=n(E[w],g),y=n(E[w+2],g),T=n(E[w+4],1),w+=5),E.length<=w){R=T*N,g=_=D+R*L+N*y;break}}default:throw A()}if(R===0)throw q();M.s=g<0?-1:1,M.n=Math.abs(_),M.d=Math.abs(R)};function c(d,m,_){for(var R=1;m>0;d=d*d%_,m>>=1)m&1&&(R=R*d%_);return R}function O(d,m){for(;m%2===0;m/=2);for(;m%5===0;m/=5);if(m===1)return 0;for(var _=10%m,R=1;_!==1;R++)if(_=_*10%m,R>r)return 0;return R}function s(d,m,_){for(var R=1,g=c(10,_,m),L=0;L<300;L++){if(R===g)return L;R=R*10%m,g=g*10%m}return 0}function u(d,m){if(!d)return m;if(!m)return d;for(;;){if(d%=m,!d)return m;if(m%=d,!m)return d}}function l(d,m){if(i(d,m),this instanceof l)d=u(M.d,M.n),this.s=M.s,this.n=M.n/d,this.d=M.d/d;else return b(M.s*M.n,M.d)}var q=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(d,m){return i(d,m),b(this.s*this.n*M.d+M.s*this.d*M.n,this.d*M.d)},sub:function(d,m){return i(d,m),b(this.s*this.n*M.d-M.s*this.d*M.n,this.d*M.d)},mul:function(d,m){return i(d,m),b(this.s*M.s*this.n*M.n,this.d*M.d)},div:function(d,m){return i(d,m),b(this.s*M.s*this.n*M.d,this.d*M.n)},clone:function(){return b(this.s*this.n,this.d)},mod:function(d,m){if(isNaN(this.n)||isNaN(this.d))return new l(NaN);if(d===void 0)return b(this.s*this.n%this.d,1);if(i(d,m),M.n===0&&this.d===0)throw q();return b(this.s*(M.d*this.n)%(M.n*this.d),M.d*this.d)},gcd:function(d,m){return i(d,m),b(u(M.n,this.n)*u(M.d,this.d),M.d*this.d)},lcm:function(d,m){return i(d,m),M.n===0&&this.n===0?b(0,1):b(M.n*this.n,u(M.n,this.n)*u(M.d,this.d))},ceil:function(d){return d=Math.pow(10,d||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.ceil(d*this.s*this.n/this.d),d)},floor:function(d){return d=Math.pow(10,d||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.floor(d*this.s*this.n/this.d),d)},round:function(d){return d=Math.pow(10,d||0),isNaN(this.n)||isNaN(this.d)?new l(NaN):b(Math.round(d*this.s*this.n/this.d),d)},inverse:function(){return b(this.s*this.d,this.n)},pow:function(d,m){if(i(d,m),M.d===1)return M.s<0?b(Math.pow(this.s*this.d,M.n),Math.pow(this.n,M.n)):b(Math.pow(this.s*this.n,M.n),Math.pow(this.d,M.n));if(this.s<0)return null;var _=z(this.n),R=z(this.d),g=1,L=1;for(var y in _)if(y!=="1"){if(y==="0"){g=0;break}if(_[y]*=M.n,_[y]%M.d===0)_[y]/=M.d;else return null;g*=Math.pow(y,_[y])}for(var y in R)if(y!=="1"){if(R[y]*=M.n,R[y]%M.d===0)R[y]/=M.d;else return null;L*=Math.pow(y,R[y])}return M.s<0?b(L,g):b(g,L)},equals:function(d,m){return i(d,m),this.s*this.n*M.d===M.s*M.n*this.d},compare:function(d,m){i(d,m);var _=this.s*this.n*M.d-M.s*M.n*this.d;return(0<_)-(_<0)},simplify:function(d){if(isNaN(this.n)||isNaN(this.d))return this;d=d||.001;for(var m=this.abs(),_=m.toContinued(),R=1;R<_.length;R++){for(var g=b(_[R-1],1),L=R-2;L>=0;L--)g=g.inverse().add(_[L]);if(Math.abs(g.sub(m).valueOf())<d)return g.mul(this.s)}return this},divisible:function(d,m){return i(d,m),!(!(M.n*this.d)||this.n*M.d%(M.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(d){var m,_="",R=this.n,g=this.d;return this.s<0&&(_+="-"),g===1?_+=R:(d&&(m=Math.floor(R/g))>0&&(_+=m,_+=" ",R%=g),_+=R,_+="/",_+=g),_},toLatex:function(d){var m,_="",R=this.n,g=this.d;return this.s<0&&(_+="-"),g===1?_+=R:(d&&(m=Math.floor(R/g))>0&&(_+=m,R%=g),_+="\\frac{",_+=R,_+="}{",_+=g,_+="}"),_},toContinued:function(){var d,m=this.n,_=this.d,R=[];if(isNaN(m)||isNaN(_))return R;do R.push(Math.floor(m/_)),d=m%_,m=_,_=d;while(m!==1);return R},toString:function(d){var m=this.n,_=this.d;if(isNaN(m)||isNaN(_))return"NaN";d=d||15;var R=O(m,_),g=s(m,_,R),L=this.s<0?"-":"";if(L+=m/_|0,m%=_,m*=10,m&&(L+="."),R){for(var y=g;y--;)L+=m/_|0,m%=_,m*=10;L+="(";for(var y=R;y--;)L+=m/_|0,m%=_,m*=10;L+=")"}else for(var y=d;m&&y--;)L+=m/_|0,m%=_,m*=10;return L}},Object.defineProperty(l,"__esModule",{value:!0}),l.default=l,l.Fraction=l,o.exports=l})()})(Aa);var R5=Aa.exports,rt=B1(R5),v5="Fraction",L5=[],N5=h0(v5,L5,()=>(Object.defineProperty(rt,"name",{value:"Fraction"}),rt.prototype.constructor=rt,rt.prototype.type="Fraction",rt.prototype.isFraction=!0,rt.prototype.toJSON=function(){return{mathjs:"Fraction",n:this.s*this.n,d:this.d}},rt.fromJSON=function(o){return new rt(o)},rt),{isClass:!0}),y5="Matrix",B5=[],w5=h0(y5,B5,()=>{function o(){if(!(this instanceof o))throw new SyntaxError("Constructor must be called with the new operator")}return o.prototype.type="Matrix",o.prototype.isMatrix=!0,o.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},o.prototype.datatype=function(){throw new Error("Cannot invoke datatype on a Matrix interface")},o.prototype.create=function(e,t){throw new Error("Cannot invoke create on a Matrix interface")},o.prototype.subset=function(e,t,r){throw new Error("Cannot invoke subset on a Matrix interface")},o.prototype.get=function(e){throw new Error("Cannot invoke get on a Matrix interface")},o.prototype.set=function(e,t,r){throw new Error("Cannot invoke set on a Matrix interface")},o.prototype.resize=function(e,t){throw new Error("Cannot invoke resize on a Matrix interface")},o.prototype.reshape=function(e,t){throw new Error("Cannot invoke reshape on a Matrix interface")},o.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},o.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},o.prototype.map=function(e,t){throw new Error("Cannot invoke map on a Matrix interface")},o.prototype.forEach=function(e){throw new Error("Cannot invoke forEach on a Matrix interface")},o.prototype[Symbol.iterator]=function(){throw new Error("Cannot iterate a Matrix interface")},o.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},o.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},o.prototype.format=function(e){throw new Error("Cannot invoke format on a Matrix interface")},o.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},o},{isClass:!0});function fa(o){return Object.keys(o.signatures||{}).reduce(function(e,t){var r=(t.match(/,/g)||[]).length+1;return Math.max(e,r)},-1)}var D5="DenseMatrix",X5=["Matrix"],E5=h0(D5,X5,o=>{var{Matrix:e}=o;function t(O,s){if(!(this instanceof t))throw new SyntaxError("Constructor must be called with the new operator");if(s&&!Te(s))throw new Error("Invalid datatype: "+s);if(P1(O))O.type==="DenseMatrix"?(this._data=g1(O._data),this._size=g1(O._size),this._datatype=s||O._datatype):(this._data=O.toArray(),this._size=O.size(),this._datatype=s||O._datatype);else if(O&&V1(O.data)&&V1(O.size))this._data=O.data,this._size=O.size,Uc(this._data,this._size),this._datatype=s||O.datatype;else if(V1(O))this._data=c(O),this._size=o2(this._data),Uc(this._data,this._size),this._datatype=s;else{if(O)throw new TypeError("Unsupported type of data ("+Wt(O)+")");this._data=[],this._size=[0],this._datatype=s}}t.prototype=new e,t.prototype.createDenseMatrix=function(O,s){return new t(O,s)},Object.defineProperty(t,"name",{value:"DenseMatrix"}),t.prototype.constructor=t,t.prototype.type="DenseMatrix",t.prototype.isDenseMatrix=!0,t.prototype.getDataType=function(){return ho(this._data,Wt)},t.prototype.storage=function(){return"dense"},t.prototype.datatype=function(){return this._datatype},t.prototype.create=function(O,s){return new t(O,s)},t.prototype.subset=function(O,s,u){switch(arguments.length){case 1:return r(this,O);case 2:case 3:return n(this,O,s,u);default:throw new SyntaxError("Wrong number of arguments")}},t.prototype.get=function(O){if(!V1(O))throw new TypeError("Array expected");if(O.length!==this._size.length)throw new d1(O.length,this._size.length);for(var s=0;s<O.length;s++)K1(O[s],this._size[s]);for(var u=this._data,l=0,q=O.length;l<q;l++){var A=O[l];K1(A,u.length),u=u[A]}return u},t.prototype.set=function(O,s,u){if(!V1(O))throw new TypeError("Array expected");if(O.length<this._size.length)throw new d1(O.length,this._size.length,"<");var l,q,A,h=O.map(function(m){return m+1});i(this,h,u);var d=this._data;for(l=0,q=O.length-1;l<q;l++)A=O[l],K1(A,d.length),d=d[A];return A=O[O.length-1],K1(A,d.length),d[A]=s,this};function r(O,s){if(!$b(s))throw new TypeError("Invalid index");var u=s.isScalar();if(u)return O.get(s.min());var l=s.size();if(l.length!==O._size.length)throw new d1(l.length,O._size.length);for(var q=s.min(),A=s.max(),h=0,d=O._size.length;h<d;h++)K1(q[h],O._size[h]),K1(A[h],O._size[h]);return new t(M(O._data,s,l.length,0),O._datatype)}function M(O,s,u,l){var q=l===u-1,A=s.dimension(l);return q?A.map(function(h){return K1(h,O.length),O[h]}).valueOf():A.map(function(h){K1(h,O.length);var d=O[h];return M(d,s,u,l+1)}).valueOf()}function n(O,s,u,l){if(!s||s.isIndex!==!0)throw new TypeError("Invalid index");var q=s.size(),A=s.isScalar(),h;if(P1(u)?(h=u.size(),u=u.valueOf()):h=o2(u),A){if(h.length!==0)throw new TypeError("Scalar expected");O.set(s.min(),u,l)}else{if(!gr(h,q))try{h.length===0?u=Kc([u],q):u=Kc(u,q),h=o2(u)}catch{}if(q.length<O._size.length)throw new d1(q.length,O._size.length,"<");if(h.length<q.length){for(var d=0,m=0;q[d]===1&&h[d]===1;)d++;for(;q[d]===1;)m++,d++;u=Hc(u,q.length,m,h)}if(!gr(q,h))throw new d1(q,h,">");var _=s.max().map(function(L){return L+1});i(O,_,l);var R=q.length,g=0;b(O._data,s,u,R,g)}return O}function b(O,s,u,l,q){var A=q===l-1,h=s.dimension(q);A?h.forEach(function(d,m){K1(d),O[d]=u[m[0]]}):h.forEach(function(d,m){K1(d),b(O[d],s,u[m[0]],l,q+1)})}t.prototype.resize=function(O,s,u){if(!AM(O))throw new TypeError("Array or Matrix expected");var l=O.valueOf().map(A=>Array.isArray(A)&&A.length===1?A[0]:A),q=u?this.clone():this;return z(q,l,s)};function z(O,s,u){if(s.length===0){for(var l=O._data;V1(l);)l=l[0];return l}return O._size=s.slice(0),O._data=Gb(O._data,O._size,u),O}t.prototype.reshape=function(O,s){var u=s?this.clone():this;u._data=Kb(u._data,O);var l=u._size.reduce((q,A)=>q*A);return u._size=Jb(O,l),u};function i(O,s,u){for(var l=O._size.slice(0),q=!1;l.length<s.length;)l.push(0),q=!0;for(var A=0,h=s.length;A<h;A++)s[A]>l[A]&&(l[A]=s[A],q=!0);q&&z(O,l,u)}t.prototype.clone=function(){var O=new t({data:g1(this._data),size:g1(this._size),datatype:this._datatype});return O},t.prototype.size=function(){return this._size.slice(0)},t.prototype.map=function(O){var s=this,u=fa(O),l=function h(d,m){return V1(d)?d.map(function(_,R){return h(_,m.concat(R))}):u===1?O(d):u===2?O(d,m):O(d,m,s)},q=l(this._data,[]),A=this._datatype!==void 0?ho(q,Wt):void 0;return new t(q,A)},t.prototype.forEach=function(O){var s=this,u=function l(q,A){V1(q)?q.forEach(function(h,d){l(h,A.concat(d))}):O(q,A,s)};u(this._data,[])},t.prototype[Symbol.iterator]=function*(){var O=function*s(u,l){if(V1(u))for(var q=0;q<u.length;q++)yield*s(u[q],l.concat(q));else yield{value:u,index:l}};yield*O(this._data,[])},t.prototype.rows=function(){var O=[],s=this.size();if(s.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");var u=this._data;for(var l of u)O.push(new t([l],this._datatype));return O},t.prototype.columns=function(){var O=this,s=[],u=this.size();if(u.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");for(var l=this._data,q=function(d){var m=l.map(_=>[_[d]]);s.push(new t(m,O._datatype))},A=0;A<u[1];A++)q(A);return s},t.prototype.toArray=function(){return g1(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.format=function(O){return D1(this._data,O)},t.prototype.toString=function(){return D1(this._data)},t.prototype.toJSON=function(){return{mathjs:"DenseMatrix",data:this._data,size:this._size,datatype:this._datatype}},t.prototype.diagonal=function(O){if(O){if(e2(O)&&(O=O.toNumber()),!C1(O)||!U1(O))throw new TypeError("The parameter k must be an integer number")}else O=0;for(var s=O>0?O:0,u=O<0?-O:0,l=this._size[0],q=this._size[1],A=Math.min(l-u,q-s),h=[],d=0;d<A;d++)h[d]=this._data[d+u][d+s];return new t({data:h,size:[A],datatype:this._datatype})},t.diagonal=function(O,s,u,l){if(!V1(O))throw new TypeError("Array expected, size parameter");if(O.length!==2)throw new Error("Only two dimensions matrix are supported");if(O=O.map(function(y){if(e2(y)&&(y=y.toNumber()),!C1(y)||!U1(y)||y<1)throw new Error("Size values must be positive integers");return y}),u){if(e2(u)&&(u=u.toNumber()),!C1(u)||!U1(u))throw new TypeError("The parameter k must be an integer number")}else u=0;var q=u>0?u:0,A=u<0?-u:0,h=O[0],d=O[1],m=Math.min(h-A,d-q),_;if(V1(s)){if(s.length!==m)throw new Error("Invalid value array length");_=function(D){return s[D]}}else if(P1(s)){var R=s.size();if(R.length!==1||R[0]!==m)throw new Error("Invalid matrix length");_=function(D){return s.get([D])}}else _=function(){return s};l||(l=e2(_(0))?_(0).mul(0):0);var g=[];if(O.length>0){g=Gb(g,O,l);for(var L=0;L<m;L++)g[L+A][L+q]=_(L)}return new t({data:g,size:[h,d]})},t.fromJSON=function(O){return new t(O)},t.prototype.swapRows=function(O,s){if(!C1(O)||!U1(O)||!C1(s)||!U1(s))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return K1(O,this._size[0]),K1(s,this._size[0]),t._swapRows(O,s,this._data),this},t._swapRows=function(O,s,u){var l=u[O];u[O]=u[s],u[s]=l};function c(O){return P1(O)?c(O.valueOf()):V1(O)?O.map(c):O}return t},{isClass:!0});function T5(o){var e=o.length,t=o[0].length,r,M,n=[];for(M=0;M<t;M++){var b=[];for(r=0;r<e;r++)b.push(o[r][M]);n.push(b)}return n}function Bo(o){for(var e=0;e<o.length;e++)if(AM(o[e]))return!0;return!1}function dM(o,e){P1(o)&&(o=o.valueOf());for(var t=0,r=o.length;t<r;t++){var M=o[t];Array.isArray(M)?dM(M,e):e(M)}}function Re(o,e,t){return o&&typeof o.map=="function"?o.map(function(r){return Re(r,e)}):e(o)}function pp(o,e,t){var r=Array.isArray(o)?o2(o):o.size();if(e<0||e>=r.length)throw new _t(e,r.length);return P1(o)?o.create(wo(o.valueOf(),e,t)):wo(o,e,t)}function wo(o,e,t){var r,M,n,b;if(e<=0)if(Array.isArray(o[0])){for(b=T5(o),M=[],r=0;r<b.length;r++)M[r]=wo(b[r],e-1,t);return M}else{for(n=o[0],r=1;r<o.length;r++)n=t(n,o[r]);return n}else{for(M=[],r=0;r<o.length;r++)M[r]=wo(o[r],e-1,t);return M}}var la="isInteger",C5=["typed"],x5=h0(la,C5,o=>{var{typed:e}=o;return e(la,{number:U1,BigNumber:function(r){return r.isInt()},Fraction:function(r){return r.d===1&&isFinite(r.n)},"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),da="number",Do="number, number";function qa(o){return Math.abs(o)}qa.signature=da;function ha(o,e){return o+e}ha.signature=Do;function Wa(o,e){return o-e}Wa.signature=Do;function _a(o,e){return o*e}_a.signature=Do;function ma(o){return-o}ma.signature=da;function ga(o,e){return o*o<1&&e===1/0||o*o>1&&e===-1/0?0:Math.pow(o,e)}ga.signature=Do;var Ra="number";function va(o){return o===0}va.signature=Ra;function La(o){return Number.isNaN(o)}La.signature=Ra;var Na="isNumeric",S5=["typed"],F5=h0(Na,S5,o=>{var{typed:e}=o;return e(Na,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),ya="isZero",I5=["typed"],P5=h0(ya,I5,o=>{var{typed:e}=o;return e(ya,{number:va,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=>Re(r,t))})}),Ba="isNaN",k5=["typed"],$5=h0(Ba,k5,o=>{var{typed:e}=o;return e(Ba,{number:La,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 Re(r,Number.isNaN)}})});function Xo(o,e,t){if(t==null)return o.eq(e);if(o.eq(e))return!0;if(o.isNaN()||e.isNaN())return!1;if(o.isFinite()&&e.isFinite()){var r=o.minus(e).abs();if(r.isZero())return!0;var M=o.constructor.max(o.abs(),e.abs());return r.lte(M.times(t))}return!1}function U5(o,e,t){return Yt(o.re,e.re,t)&&Yt(o.im,e.im,t)}var Eo=h0("compareUnits",["typed"],o=>{var{typed:e}=o;return{"Unit, Unit":e.referToSelf(t=>(r,M)=>{if(!r.equalBase(M))throw new Error("Cannot compare units with different base");return e.find(t,[r.valueType(),M.valueType()])(r.value,M.value)})}}),To="equalScalar",j5=["typed","config"],H5=h0(To,j5,o=>{var{typed:e,config:t}=o,r=Eo({typed:e});return e(To,{"boolean, boolean":function(n,b){return n===b},"number, number":function(n,b){return Yt(n,b,t.epsilon)},"BigNumber, BigNumber":function(n,b){return n.eq(b)||Xo(n,b,t.epsilon)},"Fraction, Fraction":function(n,b){return n.equals(b)},"Complex, Complex":function(n,b){return U5(n,b,t.epsilon)}},r)});h0(To,["typed","config"],o=>{var{typed:e,config:t}=o;return e(To,{"number, number":function(M,n){return Yt(M,n,t.epsilon)}})});var Y5="SparseMatrix",G5=["typed","equalScalar","Matrix"],V5=h0(Y5,G5,o=>{var{typed:e,equalScalar:t,Matrix:r}=o;function M(A,h){if(!(this instanceof M))throw new SyntaxError("Constructor must be called with the new operator");if(h&&!Te(h))throw new Error("Invalid datatype: "+h);if(P1(A))n(this,A,h);else if(A&&V1(A.index)&&V1(A.ptr)&&V1(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(V1(A))b(this,A,h);else{if(A)throw new TypeError("Unsupported type of data ("+Wt(A)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=h}}function n(A,h,d){h.type==="SparseMatrix"?(A._values=h._values?g1(h._values):void 0,A._index=g1(h._index),A._ptr=g1(h._ptr),A._size=g1(h._size),A._datatype=d||h._datatype):b(A,h.valueOf(),d||h._datatype)}function b(A,h,d){A._values=[],A._index=[],A._ptr=[],A._datatype=d;var m=h.length,_=0,R=t,g=0;if(Te(d)&&(R=e.find(t,[d,d])||t,g=e.convert(0,d)),m>0){var L=0;do{A._ptr.push(A._index.length);for(var y=0;y<m;y++){var D=h[y];if(V1(D)){if(L===0&&_<D.length&&(_=D.length),L<D.length){var T=D[L];R(T,g)||(A._values.push(T),A._index.push(y))}}else L===0&&_<1&&(_=1),R(D,g)||(A._values.push(D),A._index.push(y))}L++}while(L<_)}A._ptr.push(A._index.length),A._size=[m,_]}M.prototype=new r,M.prototype.createSparseMatrix=function(A,h){return new M(A,h)},Object.defineProperty(M,"name",{value:"SparseMatrix"}),M.prototype.constructor=M,M.prototype.type="SparseMatrix",M.prototype.isSparseMatrix=!0,M.prototype.getDataType=function(){return ho(this._values,Wt)},M.prototype.storage=function(){return"sparse"},M.prototype.datatype=function(){return this._datatype},M.prototype.create=function(A,h){return new M(A,h)},M.prototype.density=function(){var A=this._size[0],h=this._size[1];return A!==0&&h!==0?this._index.length/(A*h):0},M.prototype.subset=function(A,h,d){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,d);default:throw new SyntaxError("Wrong number of arguments")}};function z(A,h){if(!$b(h))throw new TypeError("Invalid index");var d=h.isScalar();if(d)return A.get(h.min());var m=h.size();if(m.length!==A._size.length)throw new d1(m.length,A._size.length);var _,R,g,L,y=h.min(),D=h.max();for(_=0,R=A._size.length;_<R;_++)K1(y[_],A._size[_]),K1(D[_],A._size[_]);var T=A._values,N=A._index,w=A._ptr,E=h.dimension(0),P=h.dimension(1),H=[],Y=[];E.forEach(function(b0,O0){Y[b0]=O0[0],H[b0]=!0});var k=T?[]:void 0,K=[],e0=[];return P.forEach(function(b0){for(e0.push(K.length),g=w[b0],L=w[b0+1];g<L;g++)_=N[g],H[_]===!0&&(K.push(Y[_]),k&&k.push(T[g]))}),e0.push(K.length),new M({values:k,index:K,ptr:e0,size:m,datatype:A._datatype})}function i(A,h,d,m){if(!h||h.isIndex!==!0)throw new TypeError("Invalid index");var _=h.size(),R=h.isScalar(),g;if(P1(d)?(g=d.size(),d=d.toArray()):g=o2(d),R){if(g.length!==0)throw new TypeError("Scalar expected");A.set(h.min(),d,m)}else{if(_.length!==1&&_.length!==2)throw new d1(_.length,A._size.length,"<");if(g.length<_.length){for(var L=0,y=0;_[L]===1&&g[L]===1;)L++;for(;_[L]===1;)y++,L++;d=Hc(d,_.length,y,g)}if(!gr(_,g))throw new d1(_,g,">");if(_.length===1){var D=h.dimension(0);D.forEach(function(w,E){K1(w),A.set([w,0],d[E[0]],m)})}else{var T=h.dimension(0),N=h.dimension(1);T.forEach(function(w,E){K1(w),N.forEach(function(P,H){K1(P),A.set([w,P],d[E[0]][H[0]],m)})})}}return A}M.prototype.get=function(A){if(!V1(A))throw new TypeError("Array expected");if(A.length!==this._size.length)throw new d1(A.length,this._size.length);if(!this._values)throw new Error("Cannot invoke get on a Pattern only matrix");var h=A[0],d=A[1];K1(h,this._size[0]),K1(d,this._size[1]);var m=c(h,this._ptr[d],this._ptr[d+1],this._index);return m<this._ptr[d+1]&&this._index[m]===h?this._values[m]:0},M.prototype.set=function(A,h,d){if(!V1(A))throw new TypeError("Array expected");if(A.length!==this._size.length)throw new d1(A.length,this._size.length);if(!this._values)throw new Error("Cannot invoke set on a Pattern only matrix");var m=A[0],_=A[1],R=this._size[0],g=this._size[1],L=t,y=0;Te(this._datatype)&&(L=e.find(t,[this._datatype,this._datatype])||t,y=e.convert(0,this._datatype)),(m>R-1||_>g-1)&&(u(this,Math.max(m+1,R),Math.max(_+1,g),d),R=this._size[0],g=this._size[1]),K1(m,R),K1(_,g);var D=c(m,this._ptr[_],this._ptr[_+1],this._index);return D<this._ptr[_+1]&&this._index[D]===m?L(h,y)?O(D,_,this._values,this._index,this._ptr):this._values[D]=h:L(h,y)||s(D,m,_,h,this._values,this._index,this._ptr),this};function c(A,h,d,m){if(d-h===0)return d;for(var _=h;_<d;_++)if(m[_]===A)return _;return h}function O(A,h,d,m,_){d.splice(A,1),m.splice(A,1);for(var R=h+1;R<_.length;R++)_[R]--}function s(A,h,d,m,_,R,g){_.splice(A,0,m),R.splice(A,0,h);for(var L=d+1;L<g.length;L++)g[L]++}M.prototype.resize=function(A,h,d){if(!AM(A))throw new TypeError("Array or Matrix expected");var m=A.valueOf().map(R=>Array.isArray(R)&&R.length===1?R[0]:R);if(m.length!==2)throw new Error("Only two dimensions matrix are supported");m.forEach(function(R){if(!C1(R)||!U1(R)||R<0)throw new TypeError("Invalid size, must contain positive integers (size: "+D1(m)+")")});var _=d?this.clone():this;return u(_,m[0],m[1],h)};function u(A,h,d,m){var _=m||0,R=t,g=0;Te(A._datatype)&&(R=e.find(t,[A._datatype,A._datatype])||t,g=e.convert(0,A._datatype),_=e.convert(_,A._datatype));var L=!R(_,g),y=A._size[0],D=A._size[1],T,N,w;if(d>D){for(N=D;N<d;N++)if(A._ptr[N]=A._values.length,L)for(T=0;T<y;T++)A._values.push(_),A._index.push(T);A._ptr[d]=A._values.length}else d<D&&(A._ptr.splice(d+1,D-d),A._values.splice(A._ptr[d],A._values.length),A._index.splice(A._ptr[d],A._index.length));if(D=d,h>y){if(L){var E=0;for(N=0;N<D;N++){A._ptr[N]=A._ptr[N]+E,w=A._ptr[N+1]+E;var P=0;for(T=y;T<h;T++,P++)A._values.splice(w+P,0,_),A._index.splice(w+P,0,T),E++}A._ptr[D]=A._values.length}}else if(h<y){var H=0;for(N=0;N<D;N++){A._ptr[N]=A._ptr[N]-H;var Y=A._ptr[N],k=A._ptr[N+1]-H;for(w=Y;w<k;w++)T=A._index[w],T>h-1&&(A._values.splice(w,1),A._index.splice(w,1),H++)}A._ptr[N]=A._values.length}return A._size[0]=h,A._size[1]=d,A}M.prototype.reshape=function(A,h){if(!V1(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(b0){if(!C1(b0)||!U1(b0)||b0<=-2||b0===0)throw new TypeError("Invalid size, must contain positive integers or -1 (size: "+D1(A)+")")});var d=this._size[0]*this._size[1];A=Jb(A,d);var m=A[0]*A[1];if(d!==m)throw new Error("Reshaping sparse matrix will result in the wrong number of elements");var _=h?this.clone():this;if(this._size[0]===A[0]&&this._size[1]===A[1])return _;for(var R=[],g=0;g<_._ptr.length;g++)for(var L=0;L<_._ptr[g+1]-_._ptr[g];L++)R.push(g);for(var y=_._values.slice(),D=_._index.slice(),T=0;T<_._index.length;T++){var N=D[T],w=R[T],E=N*_._size[1]+w;R[T]=E%A[1],D[T]=Math.floor(E/A[1])}_._values.length=0,_._index.length=0,_._ptr.length=A[1]+1,_._size=A.slice();for(var P=0;P<_._ptr.length;P++)_._ptr[P]=0;for(var H=0;H<y.length;H++){var Y=D[H],k=R[H],K=y[H],e0=c(Y,_._ptr[k],_._ptr[k+1],_._index);s(e0,Y,k,K,_._values,_._index,_._ptr)}return _},M.prototype.clone=function(){var A=new M({values:this._values?g1(this._values):void 0,index:g1(this._index),ptr:g1(this._ptr),size:g1(this._size),datatype:this._datatype});return A},M.prototype.size=function(){return this._size.slice(0)},M.prototype.map=function(A,h){if(!this._values)throw new Error("Cannot invoke map on a Pattern only matrix");var d=this,m=this._size[0],_=this._size[1],R=fa(A),g=function(y,D,T){return R===1?A(y):R===2?A(y,[D,T]):A(y,[D,T],d)};return l(this,0,m-1,0,_-1,g,h)};function l(A,h,d,m,_,R,g){var L=[],y=[],D=[],T=t,N=0;Te(A._datatype)&&(T=e.find(t,[A._datatype,A._datatype])||t,N=e.convert(0,A._datatype));for(var w=function(A0,k0,I0){A0=R(A0,k0,I0),T(A0,N)||(L.push(A0),y.push(k0))},E=m;E<=_;E++){D.push(L.length);var P=A._ptr[E],H=A._ptr[E+1];if(g)for(var Y=P;Y<H;Y++){var k=A._index[Y];k>=h&&k<=d&&w(A._values[Y],k-h,E-m)}else{for(var K={},e0=P;e0<H;e0++){var b0=A._index[e0];K[b0]=A._values[e0]}for(var O0=h;O0<=d;O0++){var v0=O0 in K?K[O0]:0;w(v0,O0-h,E-m)}}}return D.push(L.length),new M({values:L,index:y,ptr:D,size:[d-h+1,_-m+1]})}M.prototype.forEach=function(A,h){if(!this._values)throw new Error("Cannot invoke forEach on a Pattern only matrix");for(var d=this,m=this._size[0],_=this._size[1],R=0;R<_;R++){var g=this._ptr[R],L=this._ptr[R+1];if(h)for(var y=g;y<L;y++){var D=this._index[y];A(this._values[y],[D,R],d)}else{for(var T={},N=g;N<L;N++){var w=this._index[N];T[w]=this._values[N]}for(var E=0;E<m;E++){var P=E in T?T[E]:0;A(P,[E,R],d)}}}},M.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 d=this._ptr[h],m=this._ptr[h+1],_=d;_<m;_++){var R=this._index[_];yield{value:this._values[_],index:[R,h]}}},M.prototype.toArray=function(){return q(this._values,this._index,this._ptr,this._size,!0)},M.prototype.valueOf=function(){return q(this._values,this._index,this._ptr,this._size,!1)};function q(A,h,d,m,_){var R=m[0],g=m[1],L=[],y,D;for(y=0;y<R;y++)for(L[y]=[],D=0;D<g;D++)L[y][D]=0;for(D=0;D<g;D++)for(var T=d[D],N=d[D+1],w=T;w<N;w++)y=h[w],L[y][D]=A?_?g1(A[w]):A[w]:1;return L}return M.prototype.format=function(A){for(var h=this._size[0],d=this._size[1],m=this.density(),_="Sparse Matrix ["+D1(h,A)+" x "+D1(d,A)+"] density: "+D1(m,A)+`
|
67
67
|
`,R=0;R<d;R++)for(var g=this._ptr[R],L=this._ptr[R+1],y=g;y<L;y++){var D=this._index[y];_+=`
|
68
|
-
(`+D1(D,A)+", "+D1(R,A)+") ==> "+(this._values?D1(this._values[y],A):"X")}return _},M.prototype.toString=function(){return D1(this.toArray())},M.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},M.prototype.diagonal=function(A){if(A){if(e2(A)&&(A=A.toNumber()),!C1(A)||!U1(A))throw new TypeError("The parameter k must be an integer number")}else A=0;var h=A>0?A:0,d=A<0?-A:0,m=this._size[0],_=this._size[1],R=Math.min(m-d,_-h),g=[],L=[],y=[];y[0]=0;for(var D=h;D<_&&g.length<R;D++)for(var T=this._ptr[D],N=this._ptr[D+1],w=T;w<N;w++){var E=this._index[w];if(E===D-h+d){g.push(this._values[w]),L[g.length-1]=E-d;break}}return y.push(g.length),new M({values:g,index:L,ptr:y,size:[R,1]})},M.fromJSON=function(A){return new M(A)},M.diagonal=function(A,h,d,m,_){if(!V1(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(b0){if(e2(b0)&&(b0=b0.toNumber()),!C1(b0)||!U1(b0)||b0<1)throw new Error("Size values must be positive integers");return b0}),d){if(e2(d)&&(d=d.toNumber()),!C1(d)||!U1(d))throw new TypeError("The parameter k must be an integer number")}else d=0;var R=t,g=0;Te(_)&&(R=e.find(t,[_,_])||t,g=e.convert(0,_));var L=d>0?d:0,y=d<0?-d:0,D=A[0],T=A[1],N=Math.min(D-y,T-L),w;if(V1(h)){if(h.length!==N)throw new Error("Invalid value array length");w=function(O0){return h[O0]}}else if(P1(h)){var E=h.size();if(E.length!==1||E[0]!==N)throw new Error("Invalid matrix length");w=function(O0){return h.get([O0])}}else w=function(){return h};for(var P=[],H=[],Y=[],k=0;k<T;k++){Y.push(P.length);var K=k-L;if(K>=0&&K<N){var e0=w(K);R(e0,g)||(H.push(K+y),P.push(e0))}}return Y.push(P.length),new M({values:P,index:H,ptr:Y,size:[D,T]})},M.prototype.swapRows=function(A,h){if(!C1(A)||!U1(A)||!C1(h)||!U1(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 K1(A,this._size[0]),K1(h,this._size[0]),M._swapRows(A,h,this._size[1],this._values,this._index,this._ptr),this},M._forEachRow=function(A,h,d,m,_){for(var R=m[A],g=m[A+1],L=R;L<g;L++)_(d[L],h[L])},M._swapRows=function(A,h,d,m,_,R){for(var g=0;g<d;g++){var L=R[g],y=R[g+1],D=c(A,L,y,_),T=c(h,L,y,_);if(D<y&&T<y&&_[D]===A&&_[T]===h){if(m){var N=m[D];m[D]=m[T],m[T]=N}continue}if(D<y&&_[D]===A&&(T>=y||_[T]!==h)){var w=m?m[D]:void 0;_.splice(T,0,h),m&&m.splice(T,0,w),_.splice(T<=D?D+1:D,1),m&&m.splice(T<=D?D+1:D,1);continue}if(T<y&&_[T]===h&&(D>=y||_[D]!==A)){var E=m?m[T]:void 0;_.splice(D,0,A),m&&m.splice(D,0,E),_.splice(D<=T?T+1:T,1),m&&m.splice(D<=T?T+1:T,1)}}},M},{isClass:!0}),K5="number",J5=["typed"];function Q5(o){var e=o.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],M=e[3];return{input:o,radix:t,integerPart:r,fractionalPart:M}}else return null}function Z5(o){for(var e=parseInt(o.integerPart,o.radix),t=0,r=0;r<o.fractionalPart.length;r++){var M=parseInt(o.fractionalPart[r],o.radix);t+=M/Math.pow(o.radix,r+1)}var n=e+t;if(isNaN(n))throw new SyntaxError('String "'+o.input+'" is not a valid number');return n}var eh=h0(K5,J5,o=>{var{typed:e}=o,t=e("number",{"":function(){return 0},number:function(M){return M},string:function(M){if(M==="NaN")return NaN;var n=Q5(M);if(n)return Z5(n);var b=0,z=M.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);z&&(b=Number(z[2]),M=z[1]);var i=Number(M);if(isNaN(i))throw new SyntaxError('String "'+M+'" is not a valid number');if(z){if(i>2**b-1)throw new SyntaxError('String "'.concat(M,'" is out of range'));i>=2**(b-1)&&(i=i-2**b)}return i},BigNumber:function(M){return M.toNumber()},Fraction:function(M){return M.valueOf()},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),null:function(M){return 0},"Unit, string | Unit":function(M,n){return M.toNumber(n)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),th="bignumber",rh=["typed","BigNumber"],Mh=h0(th,rh,o=>{var{typed:e,BigNumber:t}=o;return e("bignumber",{"":function(){return new t(0)},number:function(M){return new t(M+"")},string:function(M){var n=M.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(M,'" is out of range'));var c=new t(2).pow(Number(b)-1);return z.gte(c)?z.sub(i):z}return new t(M)},BigNumber:function(M){return M},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),Fraction:function(M){return new t(M.n).div(M.d).times(M.s)},null:function(M){return new t(0)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))})}),oh="fraction",nh=["typed","Fraction"],bh=h0(oh,nh,o=>{var{typed:e,Fraction:t}=o;return e("fraction",{number:function(M){if(!isFinite(M)||isNaN(M))throw new Error(M+" cannot be represented as a fraction");return new t(M)},string:function(M){return new t(M)},"number, number":function(M,n){return new t(M,n)},null:function(M){return new t(0)},BigNumber:function(M){return new t(M.toString())},Fraction:function(M){return M},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),Object:function(M){return new t(M)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))})}),wa="matrix",ph=["typed","Matrix","DenseMatrix","SparseMatrix"],zh=h0(wa,ph,o=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:M}=o;return e(wa,{"":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 M(b,i);throw new TypeError("Unknown matrix type "+JSON.stringify(z)+".")}}),Da="unaryMinus",ih=["typed"],ch=h0(Da,ih,o=>{var{typed:e}=o;return e(Da,{number:ma,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var M=r.clone();return M.value=e.find(t,M.valueType())(r.value),M}),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),Xa="abs",ah=["typed"],sh=h0(Xa,ah,o=>{var{typed:e}=o;return e(Xa,{number:qa,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),Ea="addScalar",Oh=["typed"],uh=h0(Ea,Oh,o=>{var{typed:e}=o;return e(Ea,{"number, number":ha,"Complex, Complex":function(r,M){return r.add(M)},"BigNumber, BigNumber":function(r,M){return r.plus(M)},"Fraction, Fraction":function(r,M){return r.add(M)},"Unit, Unit":e.referToSelf(t=>(r,M)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(M.value===null||M.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(M))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),M.valueType()])(n.value,M.value),n.fixPrefix=!1,n})})}),Ta="subtractScalar",Ah=["typed"],fh=h0(Ta,Ah,o=>{var{typed:e}=o;return e(Ta,{"number, number":Wa,"Complex, Complex":function(r,M){return r.sub(M)},"BigNumber, BigNumber":function(r,M){return r.minus(M)},"Fraction, Fraction":function(r,M){return r.sub(M)},"Unit, Unit":e.referToSelf(t=>(r,M)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(M.value===null||M.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(M))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),M.valueType()])(n.value,M.value),n.fixPrefix=!1,n})})}),lh="matAlgo11xS0s",dh=["typed","equalScalar"],zp=h0(lh,dh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=t,d=0,m=b;typeof u=="string"&&(A=u,h=e.find(t,[A,A]),d=e.convert(0,A),n=e.convert(n,A),m=e.find(b,[A,A]));for(var _=[],R=[],g=[],L=0;L<q;L++){g[L]=R.length;for(var y=O[L],D=O[L+1],T=y;T<D;T++){var N=c[T],w=z?m(n,i[T]):m(i[T],n);h(w,d)||(R.push(N),_.push(w))}}return g[q]=R.length,M.createSparseMatrix({values:_,index:R,ptr:g,size:[l,q],datatype:A})}}),qh="matAlgo12xSfs",hh=["typed","DenseMatrix"],Br=h0(qh,hh,o=>{var{typed:e,DenseMatrix:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var d=[],m=[],_=[],R=0;R<q;R++){for(var g=R+1,L=O[R],y=O[R+1],D=L;D<y;D++){var T=c[D];m[T]=i[D],_[T]=g}for(var N=0;N<l;N++)R===0&&(d[N]=[]),_[N]===g?d[N][R]=z?h(n,m[N]):h(m[N],n):d[N][R]=z?h(n,0):h(0,n)}return new t({data:d,size:[l,q],datatype:A})}}),Wh="matAlgo14xDs",_h=["typed"],ip=h0(Wh,_h,o=>{var{typed:e}=o;return function(M,n,b,z){var i=M._data,c=M._size,O=M._datatype,s,u=b;typeof O=="string"&&(s=O,n=e.convert(n,s),u=e.find(b,[s,s]));var l=c.length>0?t(u,0,c,c[0],i,n,z):[];return M.createDenseMatrix({data:l,size:g1(c),datatype:s})};function t(r,M,n,b,z,i,c){var O=[];if(M===n.length-1)for(var s=0;s<b;s++)O[s]=c?r(i,z[s]):r(z[s],i);else for(var u=0;u<b;u++)O[u]=t(r,M+1,n,n[M+1],z[u],i,c);return O}}),mh="matAlgo02xDS0",gh=["typed","equalScalar"],Rh=h0(mh,gh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b,z){var i=M._data,c=M._size,O=M._datatype||M.getDataType(),s=n._values,u=n._index,l=n._ptr,q=n._size,A=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==q.length)throw new d1(c.length,q.length);if(c[0]!==q[0]||c[1]!==q[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+q+")");if(!s)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var h=c[0],d=c[1],m,_=t,R=0,g=b;typeof O=="string"&&O===A&&O!=="mixed"&&(m=O,_=e.find(t,[m,m]),R=e.convert(0,m),g=e.find(b,[m,m]));for(var L=[],y=[],D=[],T=0;T<d;T++){D[T]=y.length;for(var N=l[T],w=l[T+1],E=N;E<w;E++){var P=u[E],H=z?g(s[E],i[P][T]):g(i[P][T],s[E]);_(H,R)||(y.push(P),L.push(H))}}return D[d]=y.length,n.createSparseMatrix({values:L,index:y,ptr:D,size:[h,d],datatype:O===M._datatype&&A===n._datatype?m:void 0})}}),vh="matAlgo03xDSf",Lh=["typed"],wr=h0(vh,Lh,o=>{var{typed:e}=o;return function(r,M,n,b){var z=r._data,i=r._size,c=r._datatype||r.getDataType(),O=M._values,s=M._index,u=M._ptr,l=M._size,q=M._datatype||M._data===void 0?M._datatype:M.getDataType();if(i.length!==l.length)throw new d1(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(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],d,m=0,_=n;typeof c=="string"&&c===q&&c!=="mixed"&&(d=c,m=e.convert(0,d),_=e.find(n,[d,d]));for(var R=[],g=0;g<A;g++)R[g]=[];for(var L=[],y=[],D=0;D<h;D++){for(var T=D+1,N=u[D],w=u[D+1],E=N;E<w;E++){var P=s[E];L[P]=b?_(O[E],z[P][D]):_(z[P][D],O[E]),y[P]=T}for(var H=0;H<A;H++)y[H]===T?R[H][D]=L[H]:R[H][D]=b?_(m,z[H][D]):_(z[H][D],m)}return r.createDenseMatrix({data:R,size:[A,h],datatype:c===r._datatype&&q===M._datatype?d:void 0})}}),Nh="matAlgo05xSfSf",yh=["typed","equalScalar"],Ca=h0(Nh,yh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b){var z=M._values,i=M._index,c=M._ptr,O=M._size,s=M._datatype||M._data===void 0?M._datatype:M.getDataType(),u=n._values,l=n._index,q=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(O.length!==A.length)throw new d1(O.length,A.length);if(O[0]!==A[0]||O[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+O+") must match Matrix B ("+A+")");var d=O[0],m=O[1],_,R=t,g=0,L=b;typeof s=="string"&&s===h&&s!=="mixed"&&(_=s,R=e.find(t,[_,_]),g=e.convert(0,_),L=e.find(b,[_,_]));var y=z&&u?[]:void 0,D=[],T=[],N=y?[]:void 0,w=y?[]:void 0,E=[],P=[],H,Y,k,K;for(Y=0;Y<m;Y++){T[Y]=D.length;var e0=Y+1;for(k=c[Y],K=c[Y+1];k<K;k++)H=i[k],D.push(H),E[H]=e0,N&&(N[H]=z[k]);for(k=q[Y],K=q[Y+1];k<K;k++)H=l[k],E[H]!==e0&&D.push(H),P[H]=e0,w&&(w[H]=u[k]);if(y)for(k=T[Y];k<D.length;){H=D[k];var b0=E[H],O0=P[H];if(b0===e0||O0===e0){var v0=b0===e0?N[H]:g,B0=O0===e0?w[H]:g,A0=L(v0,B0);R(A0,g)?D.splice(k,1):(y.push(A0),k++)}}}return T[m]=D.length,M.createSparseMatrix({values:y,index:D,ptr:T,size:[d,m],datatype:s===M._datatype&&h===n._datatype?_:void 0})}}),Bh="matAlgo13xDD",wh=["typed"],Dh=h0(Bh,wh,o=>{var{typed:e}=o;return function(M,n,b){var z=M._data,i=M._size,c=M._datatype,O=n._data,s=n._size,u=n._datatype,l=[];if(i.length!==s.length)throw new d1(i.length,s.length);for(var q=0;q<i.length;q++){if(i[q]!==s[q])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+s+")");l[q]=i[q]}var A,h=b;typeof c=="string"&&c===u&&(A=c,h=e.find(b,[A,A]));var d=l.length>0?t(h,0,l,l[0],z,O):[];return M.createDenseMatrix({data:d,size:l,datatype:A})};function t(r,M,n,b,z,i){var c=[];if(M===n.length-1)for(var O=0;O<b;O++)c[O]=r(z[O],i[O]);else for(var s=0;s<b;s++)c[s]=t(r,M+1,n,n[M+1],z[s],i[s]);return c}}),Xh="broadcast",Eh=["concat"],Th=h0(Xh,Eh,o=>{var{concat:e}=o;return function(M,n){var b=Math.max(M._size.length,n._size.length);if(M._size.length===n._size.length&&M._size.every((q,A)=>q===n._size[A]))return[M,n];for(var z=t(M._size,b,0),i=t(n._size,b,0),c=[],O=0;O<b;O++)c[O]=Math.max(z[O],i[O]);Wo(z,c),Wo(i,c);var s=M.clone(),u=n.clone();s._size.length<b?s.reshape(t(s._size,b,1)):u._size.length<b&&u.reshape(t(u._size,b,1));for(var l=0;l<b;l++)s._size[l]<c[l]&&(s=r(s,c[l],l)),u._size[l]<c[l]&&(u=r(u,c[l],l));return[s,u]};function t(M,n,b){return[...Array(n-M.length).fill(b),...M]}function r(M,n,b){return e(...Array(n).fill(M),b)}}),Ch="matrixAlgorithmSuite",xh=["typed","matrix","concat"],Gt=h0(Ch,xh,o=>{var{typed:e,matrix:t,concat:r}=o,M=Dh({typed:e}),n=ip({typed:e}),b=Th({concat:r});return function(i){var c=i.elop,O=i.SD||i.DS,s;c?(s={"DenseMatrix, DenseMatrix":(A,h)=>M(...b(A,h),c),"Array, Array":(A,h)=>M(...b(t(A),t(h)),c).valueOf(),"Array, DenseMatrix":(A,h)=>M(...b(t(A),h),c),"DenseMatrix, Array":(A,h)=>M(...b(A,t(h)),c)},i.SS&&(s["SparseMatrix, SparseMatrix"]=(A,h)=>i.SS(...b(A,h),c,!1)),i.DS&&(s["DenseMatrix, SparseMatrix"]=(A,h)=>i.DS(...b(A,h),c,!1),s["Array, SparseMatrix"]=(A,h)=>i.DS(...b(t(A),h),c,!1)),O&&(s["SparseMatrix, DenseMatrix"]=(A,h)=>O(...b(h,A),c,!0),s["SparseMatrix, Array"]=(A,h)=>O(...b(t(h),A),c,!0))):(s={"DenseMatrix, DenseMatrix":e.referToSelf(A=>(h,d)=>M(...b(h,d),A)),"Array, Array":e.referToSelf(A=>(h,d)=>M(...b(t(h),t(d)),A).valueOf()),"Array, DenseMatrix":e.referToSelf(A=>(h,d)=>M(...b(t(h),d),A)),"DenseMatrix, Array":e.referToSelf(A=>(h,d)=>M(...b(h,t(d)),A))},i.SS&&(s["SparseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.SS(...b(h,d),A,!1))),i.DS&&(s["DenseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.DS(...b(h,d),A,!1)),s["Array, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.DS(...b(t(h),d),A,!1))),O&&(s["SparseMatrix, DenseMatrix"]=e.referToSelf(A=>(h,d)=>O(...b(d,h),A,!0)),s["SparseMatrix, Array"]=e.referToSelf(A=>(h,d)=>O(...b(t(d),h),A,!0))));var u=i.scalar||"any",l=i.Ds||i.Ss;l&&(c?(s["DenseMatrix,"+u]=(A,h)=>n(A,h,c,!1),s[u+", DenseMatrix"]=(A,h)=>n(h,A,c,!0),s["Array,"+u]=(A,h)=>n(t(A),h,c,!1).valueOf(),s[u+", Array"]=(A,h)=>n(t(h),A,c,!0).valueOf()):(s["DenseMatrix,"+u]=e.referToSelf(A=>(h,d)=>n(h,d,A,!1)),s[u+", DenseMatrix"]=e.referToSelf(A=>(h,d)=>n(d,h,A,!0)),s["Array,"+u]=e.referToSelf(A=>(h,d)=>n(t(h),d,A,!1).valueOf()),s[u+", Array"]=e.referToSelf(A=>(h,d)=>n(t(d),h,A,!0).valueOf())));var q=i.sS!==void 0?i.sS:i.Ss;return c?(i.Ss&&(s["SparseMatrix,"+u]=(A,h)=>i.Ss(A,h,c,!1)),q&&(s[u+", SparseMatrix"]=(A,h)=>q(h,A,c,!0))):(i.Ss&&(s["SparseMatrix,"+u]=e.referToSelf(A=>(h,d)=>i.Ss(h,d,A,!1))),q&&(s[u+", SparseMatrix"]=e.referToSelf(A=>(h,d)=>q(d,h,A,!0)))),c&&c.signatures&&yc(s,c.signatures),s}}),Sh="matAlgo01xDSid",Fh=["typed"],xa=h0(Sh,Fh,o=>{var{typed:e}=o;return function(r,M,n,b){var z=r._data,i=r._size,c=r._datatype||r.getDataType(),O=M._values,s=M._index,u=M._ptr,l=M._size,q=M._datatype||M._data===void 0?M._datatype:M.getDataType();if(i.length!==l.length)throw new d1(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(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],d=typeof c=="string"&&c!=="mixed"&&c===q?c:void 0,m=d?e.find(n,[d,d]):n,_,R,g=[];for(_=0;_<A;_++)g[_]=[];var L=[],y=[];for(R=0;R<h;R++){for(var D=R+1,T=u[R],N=u[R+1],w=T;w<N;w++)_=s[w],L[_]=b?m(O[w],z[_][R]):m(z[_][R],O[w]),y[_]=D;for(_=0;_<A;_++)y[_]===D?g[_][R]=L[_]:g[_][R]=z[_][R]}return r.createDenseMatrix({data:g,size:[A,h],datatype:c===r._datatype&&q===M._datatype?d:void 0})}}),Ih="matAlgo04xSidSid",Ph=["typed","equalScalar"],kh=h0(Ih,Ph,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b){var z=M._values,i=M._index,c=M._ptr,O=M._size,s=M._datatype||M._data===void 0?M._datatype:M.getDataType(),u=n._values,l=n._index,q=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(O.length!==A.length)throw new d1(O.length,A.length);if(O[0]!==A[0]||O[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+O+") must match Matrix B ("+A+")");var d=O[0],m=O[1],_,R=t,g=0,L=b;typeof s=="string"&&s===h&&s!=="mixed"&&(_=s,R=e.find(t,[_,_]),g=e.convert(0,_),L=e.find(b,[_,_]));var y=z&&u?[]:void 0,D=[],T=[],N=z&&u?[]:void 0,w=z&&u?[]:void 0,E=[],P=[],H,Y,k,K,e0;for(Y=0;Y<m;Y++){T[Y]=D.length;var b0=Y+1;for(K=c[Y],e0=c[Y+1],k=K;k<e0;k++)H=i[k],D.push(H),E[H]=b0,N&&(N[H]=z[k]);for(K=q[Y],e0=q[Y+1],k=K;k<e0;k++)if(H=l[k],E[H]===b0){if(N){var O0=L(N[H],u[k]);R(O0,g)?E[H]=null:N[H]=O0}}else D.push(H),P[H]=b0,w&&(w[H]=u[k]);if(N&&w)for(k=T[Y];k<D.length;)H=D[k],E[H]===b0?(y[k]=N[H],k++):P[H]===b0?(y[k]=w[H],k++):D.splice(k,1)}return T[m]=D.length,M.createSparseMatrix({values:y,index:D,ptr:T,size:[d,m],datatype:s===M._datatype&&h===n._datatype?_:void 0})}}),$h="matAlgo10xSids",Uh=["typed","DenseMatrix"],Sa=h0($h,Uh,o=>{var{typed:e,DenseMatrix:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var d=[],m=[],_=[],R=0;R<q;R++){for(var g=R+1,L=O[R],y=O[R+1],D=L;D<y;D++){var T=c[D];m[T]=i[D],_[T]=g}for(var N=0;N<l;N++)R===0&&(d[N]=[]),_[N]===g?d[N][R]=z?h(n,m[N]):h(m[N],n):d[N][R]=n}return new t({data:d,size:[l,q],datatype:A})}}),jh="multiplyScalar",Hh=["typed"],Yh=h0(jh,Hh,o=>{var{typed:e}=o;return e("multiplyScalar",{"number, number":_a,"Complex, Complex":function(r,M){return r.mul(M)},"BigNumber, BigNumber":function(r,M){return r.times(M)},"Fraction, Fraction":function(r,M){return r.mul(M)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Fa="multiply",Gh=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],Vh=h0(Fa,Gh,o=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:M,equalScalar:n,dot:b}=o,z=zp({typed:e,equalScalar:n}),i=ip({typed:e});function c(g,L){switch(g.length){case 1:switch(L.length){case 1:if(g[0]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(g[0]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+g[0]+") must match Matrix rows ("+L[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+L.length+" dimensions)")}break;case 2:switch(L.length){case 1:if(g[1]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+g[1]+") must match Vector length ("+L[0]+")");break;case 2:if(g[1]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+g[1]+") must match Matrix B rows ("+L[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+L.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+g.length+" dimensions)")}}function O(g,L,y){if(y===0)throw new Error("Cannot multiply two empty vectors");return b(g,L)}function s(g,L){if(L.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return u(g,L)}function u(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._size,E=L._datatype||L.getDataType(),P=D[0],H=w[1],Y,k=r,K=M;T&&E&&T===E&&typeof T=="string"&&T!=="mixed"&&(Y=T,k=e.find(r,[Y,Y]),K=e.find(M,[Y,Y]));for(var e0=[],b0=0;b0<H;b0++){for(var O0=K(y[0],N[0][b0]),v0=1;v0<P;v0++)O0=k(O0,K(y[v0],N[v0][b0]));e0[b0]=O0}return g.createDenseMatrix({data:e0,size:[H],datatype:T===g._datatype&&E===L._datatype?Y:void 0})}var l=e("_multiplyMatrixVector",{"DenseMatrix, any":A,"SparseMatrix, any":m}),q=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":h,"DenseMatrix, SparseMatrix":d,"SparseMatrix, DenseMatrix":_,"SparseMatrix, SparseMatrix":R});function A(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._datatype||L.getDataType(),E=D[0],P=D[1],H,Y=r,k=M;T&&w&&T===w&&typeof T=="string"&&T!=="mixed"&&(H=T,Y=e.find(r,[H,H]),k=e.find(M,[H,H]));for(var K=[],e0=0;e0<E;e0++){for(var b0=y[e0],O0=k(b0[0],N[0]),v0=1;v0<P;v0++)O0=Y(O0,k(b0[v0],N[v0]));K[e0]=O0}return g.createDenseMatrix({data:K,size:[E],datatype:T===g._datatype&&w===L._datatype?H:void 0})}function h(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._size,E=L._datatype||L.getDataType(),P=D[0],H=D[1],Y=w[1],k,K=r,e0=M;T&&E&&T===E&&typeof T=="string"&&T!=="mixed"&&T!=="mixed"&&(k=T,K=e.find(r,[k,k]),e0=e.find(M,[k,k]));for(var b0=[],O0=0;O0<P;O0++){var v0=y[O0];b0[O0]=[];for(var B0=0;B0<Y;B0++){for(var A0=e0(v0[0],N[0][B0]),k0=1;k0<H;k0++)A0=K(A0,e0(v0[k0],N[k0][B0]));b0[O0][B0]=A0}}return g.createDenseMatrix({data:b0,size:[P,Y],datatype:T===g._datatype&&E===L._datatype?k:void 0})}function d(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._values,w=L._index,E=L._ptr,P=L._size,H=L._datatype||L._data===void 0?L._datatype:L.getDataType();if(!N)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var Y=D[0],k=P[1],K,e0=r,b0=M,O0=n,v0=0;T&&H&&T===H&&typeof T=="string"&&T!=="mixed"&&(K=T,e0=e.find(r,[K,K]),b0=e.find(M,[K,K]),O0=e.find(n,[K,K]),v0=e.convert(0,K));for(var B0=[],A0=[],k0=[],I0=L.createSparseMatrix({values:B0,index:A0,ptr:k0,size:[Y,k],datatype:T===g._datatype&&H===L._datatype?K:void 0}),P0=0;P0<k;P0++){k0[P0]=A0.length;var W0=E[P0],z1=E[P0+1];if(z1>W0)for(var Z0=0,i1=0;i1<Y;i1++){for(var t2=i1+1,W1=void 0,F=W0;F<z1;F++){var J=w[F];Z0!==t2?(W1=b0(y[i1][J],N[F]),Z0=t2):W1=e0(W1,b0(y[i1][J],N[F]))}Z0===t2&&!O0(W1,v0)&&(A0.push(i1),B0.push(W1))}}return k0[k]=A0.length,I0}function m(g,L){var y=g._values,D=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 w=L._data,E=L._datatype||L.getDataType(),P=g._size[0],H=L._size[0],Y=[],k=[],K=[],e0,b0=r,O0=M,v0=n,B0=0;N&&E&&N===E&&typeof N=="string"&&N!=="mixed"&&(e0=N,b0=e.find(r,[e0,e0]),O0=e.find(M,[e0,e0]),v0=e.find(n,[e0,e0]),B0=e.convert(0,e0));var A0=[],k0=[];K[0]=0;for(var I0=0;I0<H;I0++){var P0=w[I0];if(!v0(P0,B0))for(var W0=T[I0],z1=T[I0+1],Z0=W0;Z0<z1;Z0++){var i1=D[Z0];k0[i1]?A0[i1]=b0(A0[i1],O0(P0,y[Z0])):(k0[i1]=!0,k.push(i1),A0[i1]=O0(P0,y[Z0]))}}for(var t2=k.length,W1=0;W1<t2;W1++){var F=k[W1];Y[W1]=A0[F]}return K[1]=k.length,g.createSparseMatrix({values:Y,index:k,ptr:K,size:[P,1],datatype:N===g._datatype&&E===L._datatype?e0:void 0})}function _(g,L){var y=g._values,D=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 w=L._data,E=L._datatype||L.getDataType(),P=g._size[0],H=L._size[0],Y=L._size[1],k,K=r,e0=M,b0=n,O0=0;N&&E&&N===E&&typeof N=="string"&&N!=="mixed"&&(k=N,K=e.find(r,[k,k]),e0=e.find(M,[k,k]),b0=e.find(n,[k,k]),O0=e.convert(0,k));for(var v0=[],B0=[],A0=[],k0=g.createSparseMatrix({values:v0,index:B0,ptr:A0,size:[P,Y],datatype:N===g._datatype&&E===L._datatype?k:void 0}),I0=[],P0=[],W0=0;W0<Y;W0++){A0[W0]=B0.length;for(var z1=W0+1,Z0=0;Z0<H;Z0++){var i1=w[Z0][W0];if(!b0(i1,O0))for(var t2=T[Z0],W1=T[Z0+1],F=t2;F<W1;F++){var J=D[F];P0[J]!==z1?(P0[J]=z1,B0.push(J),I0[J]=e0(i1,y[F])):I0[J]=K(I0[J],e0(i1,y[F]))}}for(var Z=A0[W0],s0=B0.length,R0=Z;R0<s0;R0++){var H0=B0[R0];v0[R0]=I0[H0]}}return A0[Y]=B0.length,k0}function R(g,L){var y=g._values,D=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType(),w=L._values,E=L._index,P=L._ptr,H=L._datatype||L._data===void 0?L._datatype:L.getDataType(),Y=g._size[0],k=L._size[1],K=y&&w,e0,b0=r,O0=M;N&&H&&N===H&&typeof N=="string"&&N!=="mixed"&&(e0=N,b0=e.find(r,[e0,e0]),O0=e.find(M,[e0,e0]));for(var v0=K?[]:void 0,B0=[],A0=[],k0=g.createSparseMatrix({values:v0,index:B0,ptr:A0,size:[Y,k],datatype:N===g._datatype&&H===L._datatype?e0:void 0}),I0=K?[]:void 0,P0=[],W0,z1,Z0,i1,t2,W1,F,J,Z=0;Z<k;Z++){A0[Z]=B0.length;var s0=Z+1;for(t2=P[Z],W1=P[Z+1],i1=t2;i1<W1;i1++)if(J=E[i1],K)for(z1=T[J],Z0=T[J+1],W0=z1;W0<Z0;W0++)F=D[W0],P0[F]!==s0?(P0[F]=s0,B0.push(F),I0[F]=O0(w[i1],y[W0])):I0[F]=b0(I0[F],O0(w[i1],y[W0]));else for(z1=T[J],Z0=T[J+1],W0=z1;W0<Z0;W0++)F=D[W0],P0[F]!==s0&&(P0[F]=s0,B0.push(F));if(K)for(var R0=A0[Z],H0=B0.length,v1=R0;v1<H0;v1++){var J0=B0[v1];v0[v1]=I0[J0]}}return A0[k]=B0.length,k0}return e(Fa,M,{"Array, Array":e.referTo("Matrix, Matrix",g=>(L,y)=>{c(o2(L),o2(y));var D=g(t(L),t(y));return P1(D)?D.valueOf():D}),"Matrix, Matrix":function(L,y){var D=L.size(),T=y.size();return c(D,T),D.length===1?T.length===1?O(L,y,D[0]):s(L,y):T.length===1?l(L,y):q(L,y)},"Matrix, Array":e.referTo("Matrix,Matrix",g=>(L,y)=>g(L,t(y))),"Array, Matrix":e.referToSelf(g=>(L,y)=>g(t(L,y.storage()),y)),"SparseMatrix, any":function(L,y){return z(L,y,M,!1)},"DenseMatrix, any":function(L,y){return i(L,y,M,!1)},"any, SparseMatrix":function(L,y){return z(y,L,M,!0)},"any, DenseMatrix":function(L,y){return i(y,L,M,!0)},"Array, any":function(L,y){return i(t(L),y,M,!1).valueOf()},"any, Array":function(L,y){return i(t(y),L,M,!0).valueOf()},"any, any":M,"any, any, ...any":e.referToSelf(g=>(L,y,D)=>{for(var T=g(L,y),N=0;N<D.length;N++)T=g(T,D[N]);return T})})}),Ia="subtract",Kh=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],Jh=h0(Ia,Kh,o=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:M,unaryMinus:n,DenseMatrix:b,concat:z}=o,i=xa({typed:e}),c=wr({typed:e}),O=Ca({typed:e,equalScalar:r}),s=Sa({typed:e,DenseMatrix:b}),u=Br({typed:e,DenseMatrix:b}),l=Gt({typed:e,matrix:t,concat:z});return e(Ia,{"any, any":M},l({elop:M,SS:O,DS:i,SD:c,Ss:u,sS:s}))}),Qh="matAlgo07xSSf",Zh=["typed","DenseMatrix"],Co=h0(Qh,Zh,o=>{var{typed:e,DenseMatrix:t}=o;return function(n,b,z){var i=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),O=b._size,s=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(i.length!==O.length)throw new d1(i.length,O.length);if(i[0]!==O[0]||i[1]!==O[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+O+")");var u=i[0],l=i[1],q,A=0,h=z;typeof c=="string"&&c===s&&c!=="mixed"&&(q=c,A=e.convert(0,q),h=e.find(z,[q,q]));var d,m,_=[];for(d=0;d<u;d++)_[d]=[];var R=[],g=[],L=[],y=[];for(m=0;m<l;m++){var D=m+1;for(r(n,m,L,R,D),r(b,m,y,g,D),d=0;d<u;d++){var T=L[d]===D?R[d]:A,N=y[d]===D?g[d]:A;_[d][m]=h(T,N)}}return new t({data:_,size:[u,l],datatype:c===n._datatype&&s===b._datatype?q:void 0})};function r(M,n,b,z,i){for(var c=M._values,O=M._index,s=M._ptr,u=s[n],l=s[n+1];u<l;u++){var q=O[u];b[q]=i,z[q]=c[u]}}}),Pa="conj",eW=["typed"],tW=h0(Pa,eW,o=>{var{typed:e}=o;return e(Pa,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),ka="concat",rW=["typed","matrix","isInteger"],MW=h0(ka,rW,o=>{var{typed:e,matrix:t,isInteger:r}=o;return e(ka,{"...Array | Matrix | number | BigNumber":function(n){var b,z=n.length,i=-1,c,O=!1,s=[];for(b=0;b<z;b++){var u=n[b];if(P1(u)&&(O=!0),C1(u)||e2(u)){if(b!==z-1)throw new Error("Dimension must be specified as last argument");if(c=i,i=u.valueOf(),!r(i))throw new TypeError("Integer number expected for dimension");if(i<0||b>0&&i>c)throw new _t(i,c+1)}else{var l=g1(u).valueOf(),q=o2(l);if(s[b]=l,c=i,i=q.length-1,b>0&&i!==c)throw new d1(c+1,i+1)}}if(s.length===0)throw new SyntaxError("At least one matrix expected");for(var A=s.shift();s.length;)A=Vc(A,s.shift(),i);return O?t(A):A},"...string":function(n){return n.join("")}})}),$a="count",oW=["typed","size","prod"],nW=h0($a,oW,o=>{var{typed:e,size:t,prod:r}=o;return e($a,{string:function(n){return n.length},"Matrix | Array":function(n){return r(t(n))}})}),Ua="identity",bW=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],pW=h0(Ua,bW,o=>{var{typed:e,config:t,matrix:r,BigNumber:M,DenseMatrix:n,SparseMatrix:b}=o;return e(Ua,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(O){return r(O)},"number | BigNumber":function(O){return i(O,O,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(O,s){return i(O,O,s)},"number | BigNumber, number | BigNumber":function(O,s){return i(O,s,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(O,s,u){return i(O,s,u)},Array:function(O){return z(O)},"Array, string":function(O,s){return z(O,s)},Matrix:function(O){return z(O.valueOf(),O.storage())},"Matrix, string":function(O,s){return z(O.valueOf(),s)}});function z(c,O){switch(c.length){case 0:return O?r(O):[];case 1:return i(c[0],c[0],O);case 2:return i(c[0],c[1],O);default:throw new Error("Vector containing two values expected")}}function i(c,O,s){var u=e2(c)||e2(O)?M:null;if(e2(c)&&(c=c.toNumber()),e2(O)&&(O=O.toNumber()),!U1(c)||c<1)throw new Error("Parameters in function identity must be positive integers");if(!U1(O)||O<1)throw new Error("Parameters in function identity must be positive integers");var l=u?new M(1):1,q=u?new u(0):0,A=[c,O];if(s){if(s==="sparse")return b.diagonal(A,l,0,q);if(s==="dense")return n.diagonal(A,l,0,q);throw new TypeError('Unknown matrix type "'.concat(s,'"'))}for(var h=Gb([],A,q),d=c<O?c:O,m=0;m<d;m++)h[m][m]=l;return h}}),ja="kron",zW=["typed","matrix","multiplyScalar"],iW=h0(ja,zW,o=>{var{typed:e,matrix:t,multiplyScalar:r}=o;return e(ja,{"Matrix, Matrix":function(b,z){return t(M(b.toArray(),z.toArray()))},"Matrix, Array":function(b,z){return t(M(b.toArray(),z))},"Array, Matrix":function(b,z){return t(M(b,z.toArray()))},"Array, Array":M});function M(n,b){if(o2(n).length===1&&(n=[n]),o2(b).length===1&&(b=[b]),o2(n).length>2||o2(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(c){return b.map(function(O){return i=[],z.push(i),c.map(function(s){return O.map(function(u){return i.push(r(s,u))})})})})&&z}});function cW(){throw new Error('No "bignumber" implementation available')}function aW(){throw new Error('No "fraction" implementation available')}function sW(){throw new Error('No "matrix" implementation available')}var Ha="reshape",OW=["typed","isInteger","matrix"],uW=h0(Ha,OW,o=>{var{typed:e,isInteger:t}=o;return e(Ha,{"Matrix, Array":function(M,n){return M.reshape(n,!0)},"Array, Array":function(M,n){return n.forEach(function(b){if(!t(b))throw new TypeError("Invalid size for dimension: "+b)}),Kb(M,n)}})}),Ya="size",AW=["typed","config","?matrix"],fW=h0(Ya,AW,o=>{var{typed:e,config:t,matrix:r}=o;return e(Ya,{Matrix:function(n){return n.create(n.size())},Array:o2,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([]):sW()}})}),Ga="transpose",lW=["typed","matrix"],dW=h0(Ga,lW,o=>{var{typed:e,matrix:t}=o;return e(Ga,{Array:b=>r(t(b)).valueOf(),Matrix:r,any:g1});function r(b){var z=b.size(),i;switch(z.length){case 1:i=b.clone();break;case 2:{var c=z[0],O=z[1];if(O===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+D1(z)+")");switch(b.storage()){case"dense":i=M(b,c,O);break;case"sparse":i=n(b,c,O);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+D1(z)+")")}return i}function M(b,z,i){for(var c=b._data,O=[],s,u=0;u<i;u++){s=O[u]=[];for(var l=0;l<z;l++)s[l]=g1(c[l][u])}return b.createDenseMatrix({data:O,size:[i,z],datatype:b._datatype})}function n(b,z,i){for(var c=b._values,O=b._index,s=b._ptr,u=c?[]:void 0,l=[],q=[],A=[],h=0;h<z;h++)A[h]=0;var d,m,_;for(d=0,m=O.length;d<m;d++)A[O[d]]++;for(var R=0,g=0;g<z;g++)q.push(R),R+=A[g],A[g]=q[g];for(q.push(R),_=0;_<i;_++)for(var L=s[_],y=s[_+1],D=L;D<y;D++){var T=A[O[D]]++;l[T]=_,c&&(u[T]=g1(c[D]))}return b.createSparseMatrix({values:u,index:l,ptr:q,size:[i,z],datatype:b._datatype})}}),Va="ctranspose",qW=["typed","transpose","conj"],hW=h0(Va,qW,o=>{var{typed:e,transpose:t,conj:r}=o;return e(Va,{any:function(n){return r(t(n))}})}),Ka="mode",WW=["typed","isNaN","isNumeric"],_W=h0(Ka,WW,o=>{var{typed:e,isNaN:t,isNumeric:r}=o;return e(Ka,{"Array | Matrix":M,"...":function(b){return M(b)}});function M(n){n=Qb(n.valueOf());var b=n.length;if(b===0)throw new Error("Cannot calculate mode of an empty array");for(var z={},i=[],c=0,O=0;O<n.length;O++){var s=n[O];if(r(s)&&t(s))throw new Error("Cannot calculate mode of an array containing NaN values");s in z||(z[s]=0),z[s]++,z[s]===c?i.push(s):z[s]>c&&(c=z[s],i=[s])}return i}});function Lt(o,e,t){var r;return String(o).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+Wt(t)+", value: "+JSON.stringify(t)+")":" (type: "+o.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(o).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+Wt(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):o}var Ja="prod",mW=["typed","config","multiplyScalar","numeric"],gW=h0(Ja,mW,o=>{var{typed:e,config:t,multiplyScalar:r,numeric:M}=o;return e(Ja,{"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(dM(b,function(i){try{z=z===void 0?i:r(z,i)}catch(c){throw Lt(c,"prod",i)}}),typeof z=="string"&&(z=M(z,t.number)),z===void 0)throw new Error("Cannot calculate prod of an empty array");return z}}),RW="numeric",vW=["number","?bignumber","?fraction"],LW=h0(RW,vW,o=>{var{number:e,bignumber:t,fraction:r}=o,M={string:!0,number:!0,BigNumber:!0,Fraction:!0},n={number:b=>e(b),BigNumber:t?b=>t(b):cW,Fraction:r?b=>r(b):aW};return function(z){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",c=arguments.length>2?arguments[2]:void 0;if(c!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var O=Wt(z);if(!(O in M))throw new TypeError("Cannot convert "+z+' of type "'+O+'"; valid input types are '+Object.keys(M).join(", "));if(!(i in n))throw new TypeError("Cannot convert "+z+' to type "'+i+'"; valid output types are '+Object.keys(n).join(", "));return i===O?z:n[i](z)}}),Qa="divideScalar",NW=["typed","numeric"],yW=h0(Qa,NW,o=>{var{typed:e,numeric:t}=o;return e(Qa,{"number, number":function(M,n){return M/n},"Complex, Complex":function(M,n){return M.div(n)},"BigNumber, BigNumber":function(M,n){return M.div(n)},"Fraction, Fraction":function(M,n){return M.div(n)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,M)=>r.divide(M),"number | Fraction | Complex | BigNumber, Unit":(r,M)=>M.divideInto(r)})}),Za="pow",BW=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],wW=h0(Za,BW,o=>{var{typed:e,config:t,identity:r,multiply:M,matrix:n,inv:b,number:z,fraction:i,Complex:c}=o;return e(Za,{"number, number":O,"Complex, Complex":function(q,A){return q.pow(A)},"BigNumber, BigNumber":function(q,A){return A.isInteger()||q>=0||t.predictable?q.pow(A):new c(q.toNumber(),0).pow(A.toNumber(),0)},"Fraction, Fraction":function(q,A){var h=q.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 O(q.valueOf(),A.valueOf())},"Array, number":s,"Array, BigNumber":function(q,A){return s(q,A.toNumber())},"Matrix, number":u,"Matrix, BigNumber":function(q,A){return u(q,A.toNumber())},"Unit, number | BigNumber":function(q,A){return q.pow(A)}});function O(l,q){if(t.predictable&&!U1(q)&&l<0)try{var A=i(q),h=z(A);if((q===h||Math.abs((q-h)/q)<1e-14)&&A.d%2===1)return(A.n%2===0?1:-1)*Math.pow(-l,q)}catch{}return t.predictable&&(l<-1&&q===1/0||l>-1&&l<0&&q===-1/0)?NaN:U1(q)||l>=0||t.predictable?ga(l,q):l*l<1&&q===1/0||l*l>1&&q===-1/0?0:new c(l,0).pow(q,0)}function s(l,q){if(!U1(q))throw new TypeError("For A^b, b must be an integer (value is "+q+")");var A=o2(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(q<0)try{return s(b(l),-q)}catch(m){throw m.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 "+q+")"):m}for(var h=r(A[0]).valueOf(),d=l;q>=1;)(q&1)===1&&(h=M(d,h)),q>>=1,d=M(d,d);return h}function u(l,q){return n(s(l.valueOf(),q))}}),e3="dotDivide",DW=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],XW=h0(e3,DW,o=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:M,DenseMatrix:n,concat:b}=o,z=Rh({typed:e,equalScalar:r}),i=wr({typed:e}),c=Co({typed:e,DenseMatrix:n}),O=zp({typed:e,equalScalar:r}),s=Br({typed:e,DenseMatrix:n}),u=Gt({typed:e,matrix:t,concat:b});return e(e3,u({elop:M,SS:c,DS:i,SD:z,Ss:O,sS:s}))}),xo="compare",EW=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],TW=h0(xo,EW,o=>{var{typed:e,config:t,equalScalar:r,matrix:M,BigNumber:n,Fraction:b,DenseMatrix:z,concat:i}=o,c=wr({typed:e}),O=Ca({typed:e,equalScalar:r}),s=Br({typed:e,DenseMatrix:z}),u=Gt({typed:e,matrix:M,concat:i}),l=Eo({typed:e});return e(xo,CW({typed:e,config:t}),{"boolean, boolean":function(A,h){return A===h?0:A>h?1:-1},"BigNumber, BigNumber":function(A,h){return Xo(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:O,DS:c,Ss:s}))}),CW=h0(xo,["typed","config"],o=>{var{typed:e,config:t}=o;return e(xo,{"number, number":function(M,n){return Yt(M,n,t.epsilon)?0:M>n?1:-1}})}),So="equal",xW=["typed","matrix","equalScalar","DenseMatrix","concat"],SW=h0(So,xW,o=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:t,concat:n});return e(So,FW({typed:e,equalScalar:r}),c({elop:r,SS:z,DS:b,Ss:i}))}),FW=h0(So,["typed","equalScalar"],o=>{var{typed:e,equalScalar:t}=o;return e(So,{"any, any":function(M,n){return M===null?n===null:n===null?M===null:M===void 0?n===void 0:n===void 0?M===void 0:t(M,n)}})}),Fo="smaller",IW=["typed","config","matrix","DenseMatrix","concat"],PW=h0(Fo,IW,o=>{var{typed:e,config:t,matrix:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:r,concat:n}),O=Eo({typed:e});return e(Fo,kW({typed:e,config:t}),{"boolean, boolean":(s,u)=>s<u,"BigNumber, BigNumber":function(u,l){return u.lt(l)&&!Xo(u,l,t.epsilon)},"Fraction, Fraction":(s,u)=>s.compare(u)===-1,"Complex, Complex":function(u,l){throw new TypeError("No ordering relation is defined for complex numbers")}},O,c({SS:z,DS:b,Ss:i}))}),kW=h0(Fo,["typed","config"],o=>{var{typed:e,config:t}=o;return e(Fo,{"number, number":function(M,n){return M<n&&!Yt(M,n,t.epsilon)}})}),Io="larger",$W=["typed","config","matrix","DenseMatrix","concat"],UW=h0(Io,$W,o=>{var{typed:e,config:t,matrix:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:r,concat:n}),O=Eo({typed:e});return e(Io,jW({typed:e,config:t}),{"boolean, boolean":(s,u)=>s>u,"BigNumber, BigNumber":function(u,l){return u.gt(l)&&!Xo(u,l,t.epsilon)},"Fraction, Fraction":(s,u)=>s.compare(u)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},O,c({SS:z,DS:b,Ss:i}))}),jW=h0(Io,["typed","config"],o=>{var{typed:e,config:t}=o;return e(Io,{"number, number":function(M,n){return M>n&&!Yt(M,n,t.epsilon)}})}),t3="deepEqual",HW=["typed","equal"],YW=h0(t3,HW,o=>{var{typed:e,equal:t}=o;return e(t3,{"any, any":function(n,b){return r(n.valueOf(),b.valueOf())}});function r(M,n){if(Array.isArray(M))if(Array.isArray(n)){var b=M.length;if(b!==n.length)return!1;for(var z=0;z<b;z++)if(!r(M[z],n[z]))return!1;return!0}else return!1;else return Array.isArray(n)?!1:t(M,n)}}),r3="partitionSelect",GW=["typed","isNumeric","isNaN","compare"],VW=h0(r3,GW,o=>{var{typed:e,isNumeric:t,isNaN:r,compare:M}=o,n=M,b=(c,O)=>-M(c,O);return e(r3,{"Array | Matrix, number":function(O,s){return z(O,s,n)},"Array | Matrix, number, string":function(O,s,u){if(u==="asc")return z(O,s,n);if(u==="desc")return z(O,s,b);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":z});function z(c,O,s){if(!U1(O)||O<0)throw new Error("k must be a non-negative integer");if(P1(c)){var u=c.size();if(u.length>1)throw new Error("Only one dimensional matrices supported");return i(c.valueOf(),O,s)}if(Array.isArray(c))return i(c,O,s)}function i(c,O,s){if(O>=c.length)throw new Error("k out of bounds");for(var u=0;u<c.length;u++)if(t(c[u])&&r(c[u]))return c[u];for(var l=0,q=c.length-1;l<q;){for(var A=l,h=q,d=c[Math.floor(Math.random()*(q-l+1))+l];A<h;)if(s(c[A],d)>=0){var m=c[h];c[h]=c[A],c[A]=m,--h}else++A;s(c[A],d)>0&&--A,O<=A?q=A:l=A+1}return c[O]}}),M3="max",KW=["typed","config","numeric","larger"],JW=h0(M3,KW,o=>{var{typed:e,config:t,numeric:r,larger:M}=o;return e(M3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,c){return pp(i,c.valueOf(),n)},"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function max");return b(i)}});function n(z,i){try{return M(z,i)?z:i}catch(c){throw Lt(c,"max",i)}}function b(z){var i;if(dM(z,function(c){try{isNaN(c)&&typeof c=="number"?i=NaN:(i===void 0||M(c,i))&&(i=c)}catch(O){throw Lt(O,"max",c)}}),i===void 0)throw new Error("Cannot calculate max of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),o3="min",QW=["typed","config","numeric","smaller"],ZW=h0(o3,QW,o=>{var{typed:e,config:t,numeric:r,smaller:M}=o;return e(o3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,c){return pp(i,c.valueOf(),n)},"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function min");return b(i)}});function n(z,i){try{return M(z,i)?z:i}catch(c){throw Lt(c,"min",i)}}function b(z){var i;if(dM(z,function(c){try{isNaN(c)&&typeof c=="number"?i=NaN:(i===void 0||M(c,i))&&(i=c)}catch(O){throw Lt(O,"min",c)}}),i===void 0)throw new Error("Cannot calculate min of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),n3="add",e6=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],t6=h0(n3,e6,o=>{var{typed:e,matrix:t,addScalar:r,equalScalar:M,DenseMatrix:n,SparseMatrix:b,concat:z}=o,i=xa({typed:e}),c=kh({typed:e,equalScalar:M}),O=Sa({typed:e,DenseMatrix:n}),s=Gt({typed:e,matrix:t,concat:z});return e(n3,{"any, any":r,"any, any, ...any":e.referToSelf(u=>(l,q,A)=>{for(var h=u(l,q),d=0;d<A.length;d++)h=u(h,A[d]);return h})},s({elop:r,DS:i,SS:c,Ss:O}))}),b3="dot",r6=["typed","addScalar","multiplyScalar","conj","size"],M6=h0(b3,r6,o=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:M,size:n}=o;return e(b3,{"Array | DenseMatrix, Array | DenseMatrix":z,"SparseMatrix, SparseMatrix":i});function b(O,s){var u=c(O),l=c(s),q,A;if(u.length===1)q=u[0];else if(u.length===2&&u[1]===1)q=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(q!==A)throw new RangeError("Vectors must have equal length ("+q+" != "+A+")");if(q===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return q}function z(O,s){var u=b(O,s),l=P1(O)?O._data:O,q=P1(O)?O._datatype||O.getDataType():void 0,A=P1(s)?s._data:s,h=P1(s)?s._datatype||s.getDataType():void 0,d=c(O).length===2,m=c(s).length===2,_=t,R=r;if(q&&h&&q===h&&typeof q=="string"&&q!=="mixed"){var g=q;_=e.find(t,[g,g]),R=e.find(r,[g,g])}if(!d&&!m){for(var L=R(M(l[0]),A[0]),y=1;y<u;y++)L=_(L,R(M(l[y]),A[y]));return L}if(!d&&m){for(var D=R(M(l[0]),A[0][0]),T=1;T<u;T++)D=_(D,R(M(l[T]),A[T][0]));return D}if(d&&!m){for(var N=R(M(l[0][0]),A[0]),w=1;w<u;w++)N=_(N,R(M(l[w][0]),A[w]));return N}if(d&&m){for(var E=R(M(l[0][0]),A[0][0]),P=1;P<u;P++)E=_(E,R(M(l[P][0]),A[P][0]));return E}}function i(O,s){b(O,s);for(var u=O._index,l=O._values,q=s._index,A=s._values,h=0,d=t,m=r,_=0,R=0;_<u.length&&R<q.length;){var g=u[_],L=q[R];if(g<L){_++;continue}if(g>L){R++;continue}g===L&&(h=d(h,m(l[_],A[R])),_++,R++)}return h}function c(O){return P1(O)?O.size():n(O)}}),o6="trace",n6=["typed","matrix","add"],b6=h0(o6,n6,o=>{var{typed:e,matrix:t,add:r}=o;return e("trace",{Array:function(z){return M(t(z))},SparseMatrix:n,DenseMatrix:M,any:g1});function M(b){var z=b._size,i=b._data;switch(z.length){case 1:if(z[0]===1)return g1(i[0]);throw new RangeError("Matrix must be square (size: "+D1(z)+")");case 2:{var c=z[0],O=z[1];if(c===O){for(var s=0,u=0;u<c;u++)s=r(s,i[u][u]);return s}else throw new RangeError("Matrix must be square (size: "+D1(z)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(z)+")")}}function n(b){var z=b._values,i=b._index,c=b._ptr,O=b._size,s=O[0],u=O[1];if(s===u){var l=0;if(z.length>0)for(var q=0;q<u;q++)for(var A=c[q],h=c[q+1],d=A;d<h;d++){var m=i[d];if(m===q){l=r(l,z[d]);break}if(m>q)break}return l}throw new RangeError("Matrix must be square (size: "+D1(O)+")")}}),p3="det",p6=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],z6=h0(p3,p6,o=>{var{typed:e,matrix:t,subtractScalar:r,multiply:M,divideScalar:n,isZero:b,unaryMinus:z}=o;return e(p3,{any:function(O){return g1(O)},"Array | Matrix":function(O){var s;switch(P1(O)?s=O.size():Array.isArray(O)?(O=t(O),s=O.size()):s=[],s.length){case 0:return g1(O);case 1:if(s[0]===1)return g1(O.valueOf()[0]);if(s[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+D1(s)+")");case 2:{var u=s[0],l=s[1];if(u===l)return i(O.clone().valueOf(),u);if(l===0)return 1;throw new RangeError("Matrix must be square (size: "+D1(s)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(s)+")")}}});function i(c,O,s){if(O===1)return g1(c[0][0]);if(O===2)return r(M(c[0][0],c[1][1]),M(c[1][0],c[0][1]));for(var u=!1,l=new Array(O).fill(0).map((y,D)=>D),q=0;q<O;q++){var A=l[q];if(b(c[A][q])){var h=void 0;for(h=q+1;h<O;h++)if(!b(c[l[h]][q])){A=l[h],l[h]=l[q],l[q]=A,u=!u;break}if(h===O)return c[A][q]}for(var d=c[A][q],m=q===0?1:c[l[q-1]][q-1],_=q+1;_<O;_++)for(var R=l[_],g=q+1;g<O;g++)c[R][g]=n(r(M(c[R][g],d),M(c[R][q],c[A][g])),m)}var L=c[l[O-1]][O-1];return u?z(L):L}}),z3="inv",i6=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],c6=h0(z3,i6,o=>{var{typed:e,matrix:t,divideScalar:r,addScalar:M,multiply:n,unaryMinus:b,det:z,identity:i,abs:c}=o;return e(z3,{"Array | Matrix":function(u){var l=P1(u)?u.size():o2(u);switch(l.length){case 1:if(l[0]===1)return P1(u)?t([r(1,u.valueOf()[0])]):[r(1,u[0])];throw new RangeError("Matrix must be square (size: "+D1(l)+")");case 2:{var q=l[0],A=l[1];if(q===A)return P1(u)?t(O(u.valueOf(),q,A),u.storage()):O(u,q,A);throw new RangeError("Matrix must be square (size: "+D1(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(l)+")")}},any:function(u){return r(1,u)}});function O(s,u,l){var q,A,h,d,m;if(u===1){if(d=s[0][0],d===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,d)]]}else if(u===2){var _=z(s);if(_===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(s[1][1],_),r(b(s[0][1]),_)],[r(b(s[1][0]),_),r(s[0][0],_)]]}else{var R=s.concat();for(q=0;q<u;q++)R[q]=R[q].concat();for(var g=i(u).valueOf(),L=0;L<l;L++){var y=c(R[L][L]),D=L;for(q=L+1;q<u;)c(R[q][L])>y&&(y=c(R[q][L]),D=q),q++;if(y===0)throw Error("Cannot calculate inverse, determinant is zero");q=D,q!==L&&(m=R[L],R[L]=R[q],R[q]=m,m=g[L],g[L]=g[q],g[q]=m);var T=R[L],N=g[L];for(q=0;q<u;q++){var w=R[q],E=g[q];if(q!==L){if(w[L]!==0){for(h=r(b(w[L]),T[L]),A=L;A<l;A++)w[A]=M(w[A],n(h,T[A]));for(A=0;A<l;A++)E[A]=M(E[A],n(h,N[A]))}}else{for(h=T[L],A=L;A<l;A++)w[A]=r(w[A],h);for(A=0;A<l;A++)E[A]=r(E[A],h)}}}return g}}}),i3="pinv",a6=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],s6=h0(i3,a6,o=>{var{typed:e,matrix:t,inv:r,deepEqual:M,equal:n,dotDivide:b,dot:z,ctranspose:i,divideScalar:c,multiply:O,add:s,Complex:u}=o;return e(i3,{"Array | Matrix":function(_){var R=P1(_)?_.size():o2(_);switch(R.length){case 1:return d(_)?i(_):R[0]===1?r(_):b(i(_),z(_,_));case 2:{if(d(_))return i(_);var g=R[0],L=R[1];if(g===L)try{return r(_)}catch(y){if(!(y instanceof Error&&y.message.match(/Cannot calculate inverse, determinant is zero/)))throw y}return P1(_)?t(l(_.valueOf(),g,L),_.storage()):l(_,g,L)}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(R)+")")}},any:function(_){return n(_,0)?g1(_):c(1,_)}});function l(m,_,R){var{C:g,F:L}=A(m,_,R),y=O(r(O(i(g),g)),i(g)),D=O(i(L),r(O(L,i(L))));return O(D,y)}function q(m,_,R){for(var g=g1(m),L=0,y=0;y<_;y++){if(R<=L)return g;for(var D=y;h(g[D][L]);)if(D++,_===D&&(D=y,L++,R===L))return g;[g[D],g[y]]=[g[y],g[D]];for(var T=g[y][L],N=0;N<R;N++)g[y][N]=b(g[y][N],T);for(var w=0;w<_;w++)if(w!==y){T=g[w][L];for(var E=0;E<R;E++)g[w][E]=s(g[w][E],O(-1,O(T,g[y][E])))}L++}return g}function A(m,_,R){var g=q(m,_,R),L=m.map((D,T)=>D.filter((N,w)=>w<_&&!h(z(g[w],g[w])))),y=g.filter((D,T)=>!h(z(g[T],g[T])));return{C:L,F:y}}function h(m){return n(s(m,u(1,1)),s(0,u(1,1)))}function d(m){return M(s(m,u(1,1)),s(O(m,0),u(1,1)))}}),O6="divide",u6=["typed","matrix","multiply","equalScalar","divideScalar","inv"],A6=h0(O6,u6,o=>{var{typed:e,matrix:t,multiply:r,equalScalar:M,divideScalar:n,inv:b}=o,z=zp({typed:e,equalScalar:M}),i=ip({typed:e});return e("divide",yc({"Array | Matrix, Array | Matrix":function(O,s){return r(O,b(s))},"DenseMatrix, any":function(O,s){return i(O,s,n,!1)},"SparseMatrix, any":function(O,s){return z(O,s,n,!1)},"Array, any":function(O,s){return i(t(O),s,n,!1).valueOf()},"any, Array | Matrix":function(O,s){return r(O,b(s))}},n.signatures))}),c3="sum",f6=["typed","config","add","numeric"],l6=h0(c3,f6,o=>{var{typed:e,config:t,add:r,numeric:M}=o;return e(c3,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":b,"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function sum");return n(i)}});function n(z){var i;return dM(z,function(c){try{i=i===void 0?c:r(i,c)}catch(O){throw Lt(O,"sum",c)}}),i===void 0&&(i=M(0,t.number)),typeof i=="string"&&(i=M(i,t.number)),i}function b(z,i){try{var c=pp(z,i,r);return c}catch(O){throw Lt(O,"sum")}}}),a3="median",d6=["typed","add","divide","compare","partitionSelect"],q6=h0(a3,d6,o=>{var{typed:e,add:t,divide:r,compare:M,partitionSelect:n}=o;function b(c){try{c=Qb(c.valueOf());var O=c.length;if(O===0)throw new Error("Cannot calculate median of an empty array");if(O%2===0){for(var s=O/2-1,u=n(c,s+1),l=c[s],q=0;q<s;++q)M(c[q],l)>0&&(l=c[q]);return i(l,u)}else{var A=n(c,(O-1)/2);return z(A)}}catch(h){throw Lt(h,"median")}}var z=e({"number | BigNumber | Complex | Unit":function(O){return O}}),i=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(O,s){return r(t(O,s),2)}});return e(a3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(O,s){throw new Error("median(A, dim) is not yet supported")},"...":function(O){if(Bo(O))throw new TypeError("Scalar values expected in function median");return b(O)}})}),Po=h5({config:U2}),cp=g5({}),ap=N5({}),sp=w5({}),xe=E5({Matrix:sp}),x0=mq({BigNumber:Po,Complex:cp,DenseMatrix:xe,Fraction:ap}),h6=sh({typed:x0}),ko=uh({typed:x0}),W6=Mh({BigNumber:Po,typed:x0}),s3=tW({typed:x0}),Nt=H5({config:U2,typed:x0}),$o=x5({typed:x0}),_6=P5({typed:x0}),Uo=Yh({typed:x0}),O3=eh({typed:x0}),Op=V5({Matrix:sp,equalScalar:Nt,typed:x0}),u3=fh({typed:x0}),A3=$5({typed:x0}),up=ch({typed:x0}),f3=bh({Fraction:ap,typed:x0}),l3=F5({typed:x0}),n2=zh({DenseMatrix:xe,Matrix:sp,SparseMatrix:Op,typed:x0}),d3=_W({isNaN:A3,isNumeric:l3,typed:x0}),qM=LW({bignumber:W6,fraction:f3,number:O3}),m6=gW({config:U2,multiplyScalar:Uo,numeric:qM,typed:x0}),g6=uW({isInteger:$o,matrix:n2,typed:x0}),q3=fW({matrix:n2,config:U2,typed:x0}),h3=dW({matrix:n2,typed:x0}),Vt=MW({isInteger:$o,matrix:n2,typed:x0}),R6=nW({prod:m6,size:q3,typed:x0}),v6=hW({conj:s3,transpose:h3,typed:x0}),hM=yW({numeric:qM,typed:x0}),L6=XW({DenseMatrix:xe,concat:Vt,divideScalar:hM,equalScalar:Nt,matrix:n2,typed:x0}),W3=SW({DenseMatrix:xe,concat:Vt,equalScalar:Nt,matrix:n2,typed:x0}),_3=pW({BigNumber:Po,DenseMatrix:xe,SparseMatrix:Op,config:U2,matrix:n2,typed:x0}),N6=iW({matrix:n2,multiplyScalar:Uo,typed:x0}),y6=PW({DenseMatrix:xe,concat:Vt,config:U2,matrix:n2,typed:x0}),B6=Jh({DenseMatrix:xe,concat:Vt,equalScalar:Nt,matrix:n2,subtractScalar:u3,typed:x0,unaryMinus:up}),WM=t6({DenseMatrix:xe,SparseMatrix:Op,addScalar:ko,concat:Vt,equalScalar:Nt,matrix:n2,typed:x0}),m3=TW({BigNumber:Po,DenseMatrix:xe,Fraction:ap,concat:Vt,config:U2,equalScalar:Nt,matrix:n2,typed:x0}),w6=YW({equal:W3,typed:x0}),g3=M6({addScalar:ko,conj:s3,multiplyScalar:Uo,size:q3,typed:x0}),D6=UW({DenseMatrix:xe,concat:Vt,config:U2,matrix:n2,typed:x0}),Ap=ZW({config:U2,numeric:qM,smaller:y6,typed:x0}),Dr=Vh({addScalar:ko,dot:g3,equalScalar:Nt,matrix:n2,multiplyScalar:Uo,typed:x0}),X6=VW({compare:m3,isNaN:A3,isNumeric:l3,typed:x0}),E6=l6({add:WM,config:U2,numeric:qM,typed:x0}),T6=b6({add:WM,matrix:n2,typed:x0}),R3=z6({divideScalar:hM,isZero:_6,matrix:n2,multiply:Dr,subtractScalar:u3,typed:x0,unaryMinus:up}),C6=JW({config:U2,larger:D6,numeric:qM,typed:x0}),jo=c6({abs:h6,addScalar:ko,det:R3,divideScalar:hM,identity:_3,matrix:n2,multiply:Dr,typed:x0,unaryMinus:up}),x6=s6({Complex:cp,add:WM,ctranspose:v6,deepEqual:w6,divideScalar:hM,dot:g3,dotDivide:L6,equal:W3,inv:jo,matrix:n2,multiply:Dr,typed:x0}),S6=wW({Complex:cp,config:U2,fraction:f3,identity:_3,inv:jo,matrix:n2,multiply:Dr,number:O3,typed:x0}),F6=A6({divideScalar:hM,equalScalar:Nt,inv:jo,matrix:n2,multiply:Dr,typed:x0}),v3=q6({add:WM,compare:m3,divide:F6,partitionSelect:X6,typed:x0});class I6{constructor(e,t,r){C(this,"_cacheData");C(this,"_variables");C(this,"_math");C(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}get _taCacheData(){return this._cacheData}set _taCacheData(e){this._cacheData=e}alma({series:e,length:t,offset:r,sigma:M,floor:n,isSeriesLen:b},z){if(t===void 0||r===void 0||M===void 0)return;const i=this._cacheDataList(e,t,`alma_${z}`,b);if(i===void 0)return;let c=r*(t-1);n&&(c=Math.floor(c));const O=t/M;let s=0,u=0;for(let l=0;l<=t-1;l++){const q=Math.exp(-1*Math.pow(l-c,2)/(2*Math.pow(O,2)));s+=q,u+=i[i.length-1-(t-l-1)]*q}return u/s}sma({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const b=this._cacheDataList(e,t,`sma_${M}`,r);if(b===void 0)return;const z=b.slice(-t);return n=E6(...z)/t,n}rma({source:e,length:t,isSeriesLen:r},M){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`rma_${M}`);if(n)return n==null?void 0:n.sum;const{sum:b}=this._getCacheData(`rma_${M}`),z=1/t,i=this.sma({source:e,length:t,isSeriesLen:r},M),c=b===void 0?i:z*e+(1-z)*(b||0);return this._cacheDataHandle(`rma_${M}`,{sum:c}),c}atr({length:e,isSeriesLen:t},r){const M=this._verifyCacheData(`atr_${r}`);if(M)return M==null?void 0:M.value;const{high:n,close:b}=this._getCacheData(`atr_${r}`),{high:z,close:i,low:c}=this._variables,O=n===void 0?z-c:Math.max(Math.max(z-c,Math.abs(z-b)),Math.abs(c-b)),s=this.rma({source:O,length:e,isSeriesLen:t},r);return this._cacheDataHandle(`atr_${r}`,{high:z,close:i,value:s}),s}barssince({condition:e},t){const r=this._verifyCacheData(`barssince_${t}`);if(r)return r==null?void 0:r.count;let{count:M}=this._getCacheData(`barssince_${t}`);if(e)M=0;else{if(M===void 0)return;M+=1}return this._cacheDataHandle(`barssince_${t}`,{count:M}),M}stdev({source:e,length:t,biased:r=!0,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0)return;const b=this._cacheDataList(e,t,`stdev_${n}`,M),z=this.sma({source:e,length:t,isSeriesLen:M},n);if(b===void 0)return;let i=0;for(let c=0;c<t;c++){const O=this._sum(b[b.length-1-c],-(z||0));i+=O*O}return r||t<=1?Math.sqrt(i/t):Math.sqrt(i/(t-1))}_sum(e,t){let M=e+t;return Math.abs(M)<=1e-10&&(M=0),M}bb({series:e,length:t,mult:r,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this.stdev({source:e,length:t,isSeriesLen:M},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:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this.stdev({source:e,length:t,isSeriesLen:M},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},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},M),b=this.dev({source:e,length:t,isSeriesLen:r},M);if(!(n===void 0||b===void 0))return(e-n)/(.015*b)}change({source:e,length:t=1,isSeriesLen:r},M){const n=this._cacheDataList(e,t,`change_${M}`,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 M=this.change({source:e},r);if(M===void 0)return;const n=this._math.sum({source:M>=0?M:0,length:t},`sm1_${r}`),b=this._math.sum({source:M>=0?0:-M,length:t},`sm2_${r}`);if(!(n===void 0||b===void 0))return 100*(n-b)/(n+b)}cog({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${M}`,r),b=this._math.sum({source:e,length:t},M);if(b===void 0||n===void 0)return;let z=0;for(let i=0;i<t;i++){const c=n[n.length-1-i];z+=c*(i+1)}return-z/b}correlation({source1:e,source2:t,length:r,isSeriesLen:M},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}`,M),z=this.sma({source:e,length:r,isSeriesLen:M},`sma1_${n}`),i=this.sma({source:t,length:r,isSeriesLen:M},`sma2_${n}`);if(z===void 0||i===void 0||b===void 0)return;let c=0,O=0,s=0;for(let l=0;l<r;l++){const[q,A]=b[b.length-1-l],h=q-z,d=A-i;c+=h*d,O+=h*h,s+=d*d}return isNaN(O)||isNaN(c)||isNaN(s)?void 0:c/Math.sqrt(O*s)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const M=this._verifyCacheData(`cross_${r}`);if(M)return M==null?void 0:M.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 M=this._verifyCacheData(`crossover_${r}`);if(M)return M==null?void 0:M.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 M=this._verifyCacheData(`crossunder_${r}`);if(M)return M==null?void 0:M.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:M}=this._getCacheData(`cum_${t}`);return M=M||0,M+=e,this._cacheDataHandle(`cum_${t}`,{sum:M}),M}dev({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},M);let b=0;const z=this._cacheDataList(e,t,`dev_${M}`,r);if(!(!z||n===void 0)){for(let i=0;i<t;i++){const c=z[z.length-1-i];b+=Math.abs(c-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 M=`dmi_${r}`,n=this._verifyCacheData(M);if(n)return n==null?void 0:n.value;const{low:b,high:z,close:i,PDMS:c,NDMS:O,TRS:s,ADX:u,count:l=0}=this._getCacheData(M),{low:q,high:A,close:h}=this._variables;if(b===void 0||z===void 0||i===void 0)return this._cacheData[M]={low:q,high:A,close:h,PDMS:c,NDMS:O,TRS:A-q,count:1},[void 0,void 0,void 0];let d=A-z,m=b-q;d=d>m&&d>0?d:0,m=m>d&&m>0?m:0,d===m&&(d=m=0);const _=Math.max(A-q,Math.abs(A-i),Math.abs(q-i));let R={};if(l<e)R={low:q,high:A,close:h,PDMS:(c||0)+d,NDMS:(O||0)+m,TRS:(s||0)+_,count:l+1,value:[void 0,void 0,void 0]};else{const g=c-c/e+d,L=O-O/e+m,y=s-s/e+_,D=g/y*100,T=L/y*100,N=Math.abs((D-T)/(D+T))*100;let w=N,E=[D,T,void 0];if(l+1-e<t){const P=l+1-e;w=((u||0)*(P-1)+N)/P}else w=(u*(t-1)+N)/t,E=[D,T,w];R={low:q,high:A,close:h,PDMS:g,NDMS:L,TRS:y,ADX:w,count:l+1,value:E}}return this._cacheDataHandle(M,R),R.value}ema({source:e,length:t,isSeriesLen:r},M){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`ema_${M}`);if(n)return n==null?void 0:n.sum;let{sum:b,count:z=1}=this._getCacheData(`ema_${M}`);const i=this.sma({source:e,length:t,isSeriesLen:r},M);if(z>t){const c=2/(t+1);b=b===void 0?e:c*e+(1-c)*(b||0)}else b=i;return z+=1,this._cacheDataHandle(`ema_${M}`,{sum:b,count:z}),b}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const M=this._verifyCacheData(`falling_${r}`);if(M)return M==null?void 0:M.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(c=>c),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 M=this._verifyCacheData(`rising_${r}`);if(M)return M==null?void 0:M.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(c=>c),this._cacheDataHandle(`rising_${r}`,{source:e,risings:z,value:i}),i}highest({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highest_${M}`,r,!1,!0);if(b!=null&&b.length)return Math.max(...b.slice(-t))}highestbars({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highestbars_${M}`,r);return b?b.slice(-t).reduce((i,c,O,s)=>c>=s[i]?O:i,0)-t+1:void 0}wma({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${M}`,r);if(!n)return;let b=0,z=0;for(let i=0;i<t;i++){const c=(t-i)*t;b+=c,z+=n[n.length-1-i]*c}return z/b}hma({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t,isSeriesLen:r},M),b=this.wma({source:e,length:Math.round(t/2),isSeriesLen:r},`half_${M}`);return n===void 0||b===void 0?void 0:this.wma({source:2*b-n,length:Math.floor(Math.sqrt(t)),isSeriesLen:r},`hma_${M}`)}kc({series:e,length:t,mult:r,useTrueRange:M=!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:c,low:O}=this._variables,s=M?i.tr:c-O,u=this.ema({source:s,length:t,isSeriesLen:n},`range_${b}`);return[z,z+u*r,z-u*r]}kcw({series:e,length:t,mult:r,useTrueRange:M=!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:c,low:O}=this._variables,s=M?i.tr:c-O,u=this.ema({source:s,length:t,isSeriesLen:n},`range_${b}`);return(z+u*r-(z-u*r))/z}linreg({source:e,length:t,offset:r,isSeriesLen:M},n){if(t===void 0||r===void 0)return;const b=this._cacheDataList(e,t,`dev_${n}`,M);if(!b)return;const z=b.slice(-t).filter(q=>q!==void 0);let i=0,c=0,O=0,s=0;for(const[q,A]of z.entries())i+=q,c+=A,O+=q*A,s+=q*q;const u=(t*O-i*c)/(t*s-i*i);return(c-u*i)/t+u*(t-1-r)}lowest({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowest_${M}`,r,!1,!0);if(b!=null&&b.length)return Math.min(...b.slice(-t))}lowestbars({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowestbars_${M}`,r);return b?b.slice(-t).reduce((i,c,O,s)=>c<=s[i]?O:i,0)-t+1:void 0}macd({source:e,fastlen:t,slowlen:r,siglen:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0||M===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,c=this.ema({source:i,length:M},`macd_${n}`);if(c===void 0)return[i,c,void 0];const O=i-c;return[i,c,O]}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},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${M}`,r);if(n)return v3(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:M}=this._variables,n=this.change({source:e},r),b=this._math.sum({source:M*(n>=0?0:e),length:t},`lower_${r}`),z=this._math.sum({source:M*(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},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${M}`,r);if(n)return Ap(d3(n.slice(-t)))}mom({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<0)return;const n=`mom_${M}`,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:M},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}`,M);if(!b)return;const z=this._sort(b.slice(-t)),i=z.length;r/=100;const c=1/(i*2);if(r<=c)return z[0];if(r>=1-1/(i*2))return z[i-1];for(const[O,s]of z.entries()){const u=z[O-1];if(r<(O+.5)/i)return u===void 0||s===void 0?void 0:u+(s-u)*(r-(O-.5)/i)/(1/i)}}percentile_nearest_rank({source:e,length:t,percentage:r,isSeriesLen:M},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}`,M);if(!b)return;const z=this._sort(b.slice(-t)),i=r/100*z.length,c=Math.ceil(i)-1;return z[c>=z.length?z.length-1:c]}percentrank({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${M}`,r);if(!n)return;const b=n.slice(-(t+1)),z=e;if(z===void 0)return;let i=0;for(let c=0;c<b.length;c++)b[c]!==void 0&&(b[c]<z||b[c]===z&&c<t)&&i++;return i/(b.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},M){const n=p1(0,void 0,N0.FLOAT);let{close:b,open:z,low:i,high:c}=this._variables;const O=`pivot_point_levels_${M}`,s=this._verifyCacheData(O);if(s)return n._value=(s==null?void 0:s.result)||[],n;const{close:u,low:l,high:q,open:A,result:h}=this._getCacheData(O);if(!t&&(q&&l&&(c=Math.max(q,c),i=Math.min(l,i)),this._cacheDataHandle(O,{close:b,open:z,low:i,high:c,result:h}),!r))return n._value=h||[],n;const d={close:b,open:z,low:i,high:c};t===!0&&!r&&(b=u,z=A,i=l,c=q);const m=this._getPivotPointLevels(c,i,b,z,r,e);return this._cacheDataHandle(O,{...d,result:m}),n._value=m,n}_getPivotPointLevels(e,t,r,M,n,b){if(r===void 0||M===void 0||t===void 0||e===void 0)return[];switch(b){case Pt.traditional:return this._traditional(e,t,r);case Pt.fibonacci:return this._fibonacci(e,t,r);case Pt.woodie:return n?[]:this._woodie(e,t);case Pt.classic:return this._classic(e,t,r);case Pt.dm:return this._DM(e,t,r,M);case Pt.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const M=(e+t+r)/3,n=M*2-t,b=M+(e-t),z=M*2+(e-2*t),i=M*3+(e-3*t),c=M*4+(e-4*t),O=M*2-e,s=M-(e-t),u=M*2-(2*e-t),l=M*3-(3*e-t),q=M*4-(4*e-t);return[M,n,O,b,s,z,u,i,l,c,q]}_fibonacci(e,t,r){const M=(e+t+r)/3,n=M+.382*(e-t),b=M-.382*(e-t),z=M+.618*(e-t),i=M-.618*(e-t),c=M+(e-t),O=M-(e-t);return[M,n,b,z,i,c,O]}_woodie(e,t){const{open:r}=this._variables,M=(e+t+2*r)/4,n=2*M-t,b=2*M-e,z=M+(e-t),i=M-(e-t),c=e+2*(M-t),O=t-2*(e-M),s=c+(e-t),u=O-(e-t);return[M,n,b,z,i,c,O,s,u]}_classic(e,t,r){const M=(e+t+r)/3,n=2*M-t,b=2*M-e,z=M+(e-t),i=M-(e-t),c=M+2*(e-t),O=M-2*(e-t),s=M+3*(e-t),u=M-3*(e-t);return[M,n,b,z,i,c,O,s,u]}_DM(e,t,r,M){let n;M===r?n=e+t+2*r:r>M?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 M=(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,c=r+1.1*(e-t)/4,O=r-1.1*(e-t)/4,s=r+1.1*(e-t)/2,u=r-1.1*(e-t)/2,l=e/t*r,q=r-(l-r);return[M,n,b,z,i,c,O,s,u,l,q]}pivothigh(e,t){const{leftbars:r,rightbars:M}=e;if(r===void 0||M===void 0||r<0||M<0)return;let n=this._variables.high;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+M+1,`pivothigh_${t}`);if(!b)return;const z=b.slice(-(r+M+1)),i=z[r],c=z.splice(0,r+1),O=Math.max(...z),s=Math.max(...c);return i>=s&&i>O?i:void 0}pivotlow(e,t){const{leftbars:r,rightbars:M}=e;if(r===void 0||M===void 0||r<0||M<0)return;let n=this._variables.low;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+M+1,`pivotlow_${t}`);if(!b)return;const z=b.slice(-(r+M+1)),i=z[r],c=z.splice(0,r+1),O=Math.min(...z),s=Math.min(...c);return i<=s&&i<O?i:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const M=this._cacheDataList(e,t,`range_${r}`,!0);if(!M)return;const n=M.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},M){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${M}`,r),b=this.change({source:e,length:t,isSeriesLen:r},M);if(n)return 100*b/n[n.length-1-t]}rsi({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._verifyCacheData(`rsi_${M}`);if(n)return n==null?void 0:n.value;const{source:b}=this._getCacheData(`rsi_${M}`),z=Math.max(e-b,0),i=Math.max(b-e,0),c=this.rma({source:z,length:t,isSeriesLen:r},`rma1_${M}`),O=this.rma({source:i,length:t,isSeriesLen:r},`rma2_${M}`),s=c===void 0||O===void 0?void 0:100-100/(1+c/O);return this._cacheDataHandle(`rsi_${M}`,{source:e,value:s}),s}sar({start:e,inc:t,max:r},M){if(e===void 0||t===void 0||r===void 0)return;const n=this._verifyCacheData(`sar_${M}`);if(n)return n==null?void 0:n.result;const{close:b,low:z,high:i,preLow:c,preHigh:O,data:s={}}=this._getCacheData(`sar_${M}`);let{result:u,maxMin:l,acceleration:q,isBelow:A}=s,h=!1;const{close:d,low:m,high:_,bar_index:R}=this._variables;return R===1&&(d>b?(A=!0,l=_,u=z):(A=!1,l=m,u=i),h=!0,q=e),u=u+q*(l-u),A?u>m&&(h=!0,A=!1,u=Math.max(_,l||0),l=m,q=e):u<_&&(h=!0,A=!0,u=Math.min(m,l||0),l=_,q=e),h||(A?_>(l||0)&&(l=_,q=Math.min((q||0)+t,r)):m<(l||0)&&(l=m,q=Math.min((q||0)+t,r))),A?(u=Math.min(u,z),R>1&&(u=Math.min(u,c))):(u=Math.max(u,i),R>1&&(u=Math.max(u,O))),this._cacheDataHandle(`sar_${M}`,{high:_,close:d,low:m,preLow:z,preHigh:i,data:Object.assign(s,{result:u,maxMin:l,acceleration:q,isBelow:A})}),u}stoch({source:e,high:t,low:r,length:M,isSeriesLen:n},b){if(M===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||M<0)return;const z=this.lowest({source:r,length:M,isSeriesLen:n},b),i=this.highest({source:t,length:M,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 M=`supertrend_${r}`,n=this._verifyCacheData(M);if(n)return n==null?void 0:n.value;let b=1;const{hl2:z,close:i}=this._variables,{upperBand:c,lowerBand:O,superTrend:s,atr:u,close:l}=this._getCacheData(M),q=this.atr({length:t},r);if(q===void 0)return this._cacheDataHandle(M,{close:i,value:[void 0,b]}),[void 0,b];let A=z+e*q,h=z-e*q;const d=c||0,m=O||0;h=h>m||l<m?h:m,A=A<d||l>d?A:d,u===void 0?b=1:s===d?b=i>A?-1:1:b=i<h?1:-1;const _=b===-1?h:A;return this._cacheDataHandle(M,{upperBand:A,lowerBand:h,superTrend:_,atr:q,close:i,value:[_,b]}),[_,b]}swma({source:e},t){const r=this._verifyCacheData(`swma_${t}`);if(r)return r==null?void 0:r.value;let{list:M}=this._getCacheData(`swma_${t}`);M||(M=[]),M.push(e),M=M.slice(-4);const n=M.filter(b=>b!==void 0).length<4?void 0:M[3]*1/6+M[2]*2/6+M[1]*2/6+M[0]*1/6;return this._cacheDataHandle(`swma_${t}`,{list:M,value:n}),n}tr({handle_na:e=!1},t){const{close:r,low:M,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-M:void 0:i=Math.max(n-M,Math.abs(n-z),Math.abs(M-z)),this._cacheDataHandle(`tr_${t}`,{close:r,value:i}),i}tsi({source:e,short_length:t,long_length:r},M){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const n=this.change({source:e},M);if(n===void 0)return;const b=this._doubleSmooth(n,r,t,M),z=this._doubleSmooth(Math.abs(n),r,t,`abs_${M}`);if(!(z===void 0||b===void 0))return b/z}_doubleSmooth(e,t,r,M){const n=this.ema({source:e,length:t},`ema1_${M}`);return this.ema({source:n,length:r},`ema2_${M}`)}valuewhen({condition:e,source:t,occurrence:r},M){if(r===void 0||r<0)return;let{list:n}=this._getCacheData(`valuewhen_${M}`);n||(n=[]),e&&n.push(t);const b=n[n.length-1-r];return this._cacheDataHandle(`valuewhen_${M}`,{list:n,value:b}),b}variance({source:e,length:t,biased:r=!0,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this._cacheDataList(e,t,`variance_${n}`,!0);if(!z||b===void 0)return;const i=z.filter(O=>O!==void 0&&!isNaN(O)).slice(-t);if(i.length<t)return;const c=i.reduce((O,s)=>O+Math.pow(s-b,2),0);if(c!==void 0)return r||t<=1?c/t:c/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},M){if(e===void 0)return;const n=`vwap_${M}`,b=this._verifyCacheData(n);if(b)return b==null?void 0:b.value;t=t===void 0?this._timeframe.change({timeframe:"1D"},M):t;const{volume:z}=this._variables;let{sum:i=0,sumV:c=0,count:O=0,isReset:s,sumS:u=0}=this._getCacheData(n);if(t&&(i=c=O=u=0,s=!0),!s)return r!==void 0?[]:void 0;const l=e*z+i,q=z+c,A=l/q;if(O++,r!==void 0){u=z*Math.pow(e,2)+u;const h=this._computeBands(u,q,r,A);return this._cacheDataHandle(n,{sum:l,sumV:q,count:O,isReset:s,sumS:u,value:h}),h}return this._cacheDataHandle(n,{sum:l,sumV:q,count:O,isReset:s,value:A}),A}_computeBands(e,t,r,M){let n=e/t-Math.pow(M,2);n=n<0?0:n;const b=Math.sqrt(n),z=b!==void 0&&!isNaN(b)?M+r*b:void 0,i=b!==void 0&&!isNaN(b)?M-r*b:void 0;return[M,z,i]}vwma({source:e,length:t,isSeriesLen:r},M){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_${M}`),z=this.sma({source:n,length:t,isSeriesLen:r},`sma2_${M}`);if(!(b===void 0||z===void 0))return b/z}wpr({length:e,isSeriesLen:t},r){if(e===void 0||e<=0)return;const M=this.highest({length:e,isSeriesLen:t},r),n=this.lowest({length:e,isSeriesLen:t},r),{close:b}=this._variables;if(!(M===void 0||n===void 0))return(M-b)/(M-n)*-100}_sort(e){const t=[];for(const r of e){if(typeof r=="number")break;t.push(r)}return e.sort((r,M)=>r-M),t.concat(e)}_cacheDataList(e,t,r,M=!1,n=!0,b=!1){const z=this._cacheData[r]||{barIndex:-1,list:[],length:t},{bar_index:i}=this._variables;if(z.length<t&&(z.length=t),z.barIndex<=i&&!(isNaN(e)&&b)){const c=z.list.length;if(z.barIndex===i)z.list[c-1]=e;else{let O=i-z.barIndex-1;if(z.barIndex!==-1&&O>0){const s=z.list[c-1];for(;O>0;)z.list.push(s),O--}z.list.push(e)}z.barIndex=i,z.list.length>z.length+5&&!M&&z.list.shift(),this._cacheData[r]=z}if(!(z.list.length<t&&n))return z.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:M,_isRepeated:n}=this._variables;if(!M&&!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,M=this._cacheData[e]||{},{barIndex:n}=M;if(n===t&&r)return M}}class P6{constructor(e,t,r){C(this,"_cacheData");C(this,"_variables");C(this,"_errorListener");C(this,"_historyInputs");C(this,"_name");C(this,"_newCacheData",{});this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}get _inputCacheData(){return this._cacheData}set _inputCacheData(e){this._cacheData=e}update(e){if(!(e!=null&&e.length)){self.workerStorage.delete(this._name),this._cacheData={};return}for(const t of e){const r=t.id,M=this._historyInputs[r];(!(t!=null&&t.sourceTypeName)&&(M==null?void 0:M.defval)!==t.defval||M!=null&&M.sourceTypeName&&t.sourceTypeName!==(M==null?void 0:M.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,N2.INT)}bool(e,t){return this._cacheHandle(e,t,N2.BOOL)}color(e,t){return this._cacheHandle(e,t,N2.COLOR)}time(e,t){return this._cacheHandle(e,t,N2.TIME)}float(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,N2.FLOAT)}price(e,t){return this._cacheHandle(e,t,N2.PRICE)}source(e,t){return this._cacheHandle(e,t,N2.SOURCE)}string(e,t){return this._cacheHandle(e,t,N2.STRING)}symbol(e,t){return this._cacheHandle(e,t,N2.SYMBOL)}session(e,t){return this._cacheHandle(e,t,N2.SESSION)}text_area(e,t){return this._cacheHandle(e,t,N2.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,N2.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,N2.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const M=`${r||"input"}_${t}`,n=this._newCacheData[M]||this._cacheData[M];if(this._variables.bar_index)return n.sourceTypeName&&(n.defval=this._variables[n.sourceTypeName]),n.defval;if(e.defval===void 0&&this._errorListener.addError(N1.inputDefvalErr,t,K0.Error),n)if(!n.isModify)Object.assign(this._newCacheData[M],e);else{this._newCacheData[M]=n;const b=this._historyInputs[M];!(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._newCacheData[M].defval=this._variables[n.sourceTypeName]):Object.assign(this._newCacheData[M],e)}else{const{defval:b,display:z}=e;if(this._displayVerify(t,z),e={inputType:r,...e},this._newCacheData[M]=e,(r||e.inputType)===N2.SOURCE)this._newCacheData[M].options=ui;else if(e.options)if(!e.options.includes(b))this._errorListener.addError(l2(N1.inputOptErr,{defval:String(b),args:e.options.toString()}),t,K0.Error,6+((r==null?void 0:r.length)||-1));else{const i=new Map;for(const c of e.options){if(i.has(c)){this._errorListener.addError(l2(N1.optionsRepeatErr,{option:String(c)}),t,K0.Error,6+((r==null?void 0:r.length)||-1));break}i.set(c,c)}}}return self.workerStorage.setValue(this._name,M,{...e}),this._newCacheData[M].defval}_displayVerify(e,t){!t||!t.length||t.includes(le.dataWindow)||t.includes(le.statusLine)||this._errorListener.addError(l2(N1.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,K0.Error)}_verifyMaxOrMin(e,t){const{defval:r,maxval:M,minval:n}=e;typeof r=="number"&&(M!==void 0&&r>M||n!==void 0&&r<n)&&this._errorListener.addError(N1.minOrMaxErr,t,K0.Error)}getInputs(){const e=Object.keys(this._newCacheData),t=[];for(const r of e){const M=this._newCacheData[r];M.id=r,t.push(M)}return this._cacheData=this._newCacheData,t.sort((r,M)=>(r.index||0)-(M.index||0))}}class k6{color({x:e}){return e===void 0?null:e}new({color:e,transp:t=100}){u0(t)&&(t=100);let r=(100-t)/100;r=r<0?0:r>1?1:r;const{r:M,g:n,b}=this._parseColor(e||"");return`rgba(${Math.round(M)}, ${Math.round(n)}, ${Math.round(b)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:M=0}){return u0(M)&&(M=0),u0(e)&&(e=0),u0(t)&&(t=0),u0(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-M)/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:M,top_color:n}){if(u0(e)||u0(t)||u0(r)||r===t)return"rgba(0,0,0,1)";const b=(e-t)/(r-t),z=Math.min(Math.max(b,0),1);if(!M&&!n)return"rgba(0,0,0,0)";let{r:i,g:c,b:O,a:s}=M?this._parseColor(M):{},{r:u,g:l,b:q,a:A}=n?this._parseColor(n):{};M?n||(u=i,l=c,q=O,A=0):(i=u,c=l,O=q,s=0);const h=i+z*(u-i),d=c+z*(l-c),m=O+z*(q-O),_=s+z*(A-s);return`rgba(${Math.round(h)}, ${Math.round(d)}, ${Math.round(m)}, ${_.toFixed(2)})`}_parseColor(e){let t,r,M,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),M=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,M=b[2]||0,n=b[3],n=n===void 0?1:n}return{r:t,g:r,b:M,a:n}}_parserRgbColor(e){var t;return((t=e.match(/[\d.]+/g))==null?void 0:t.map(Number))||[]}}var t1={};const $6=Object.prototype.toString;function _M(o){const e=$6.call(o);return e.endsWith("Array]")&&!e.includes("Big")}var U6=Object.freeze({__proto__:null,isAnyArray:_M}),j6=Y1(U6);function H6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!_M(o))throw new TypeError("input must be an array");if(o.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,M=e.toIndex,n=M===void 0?o.length:M;if(r<0||r>=o.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>o.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=o[r],z=r+1;z<n;z++)o[z]>b&&(b=o[z]);return b}function Y6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!_M(o))throw new TypeError("input must be an array");if(o.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,M=e.toIndex,n=M===void 0?o.length:M;if(r<0||r>=o.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>o.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=o[r],z=r+1;z<n;z++)o[z]<b&&(b=o[z]);return b}function G6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_M(o)){if(o.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(!_M(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(o.length);var r=Y6(o),M=H6(o);if(r===M)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?M:1:z;if(b>=i)throw new RangeError("min option must be smaller than max option");for(var c=(i-b)/(M-r),O=0;O<o.length;O++)t[O]=(o[O]-r)*c+b;return t}var V6=Object.freeze({__proto__:null,default:G6}),K6=Y1(V6);Object.defineProperty(t1,"__esModule",{value:!0});var C2=j6,L3=K6;const Ho=" ".repeat(2),N3=" ".repeat(4);function J6(){return y3(this)}function y3(o,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:M=8,padMinus:n="auto"}=e;return`${o.constructor.name} {
|
68
|
+
(`+D1(D,A)+", "+D1(R,A)+") ==> "+(this._values?D1(this._values[y],A):"X")}return _},M.prototype.toString=function(){return D1(this.toArray())},M.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},M.prototype.diagonal=function(A){if(A){if(e2(A)&&(A=A.toNumber()),!C1(A)||!U1(A))throw new TypeError("The parameter k must be an integer number")}else A=0;var h=A>0?A:0,d=A<0?-A:0,m=this._size[0],_=this._size[1],R=Math.min(m-d,_-h),g=[],L=[],y=[];y[0]=0;for(var D=h;D<_&&g.length<R;D++)for(var T=this._ptr[D],N=this._ptr[D+1],w=T;w<N;w++){var E=this._index[w];if(E===D-h+d){g.push(this._values[w]),L[g.length-1]=E-d;break}}return y.push(g.length),new M({values:g,index:L,ptr:y,size:[R,1]})},M.fromJSON=function(A){return new M(A)},M.diagonal=function(A,h,d,m,_){if(!V1(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(b0){if(e2(b0)&&(b0=b0.toNumber()),!C1(b0)||!U1(b0)||b0<1)throw new Error("Size values must be positive integers");return b0}),d){if(e2(d)&&(d=d.toNumber()),!C1(d)||!U1(d))throw new TypeError("The parameter k must be an integer number")}else d=0;var R=t,g=0;Te(_)&&(R=e.find(t,[_,_])||t,g=e.convert(0,_));var L=d>0?d:0,y=d<0?-d:0,D=A[0],T=A[1],N=Math.min(D-y,T-L),w;if(V1(h)){if(h.length!==N)throw new Error("Invalid value array length");w=function(O0){return h[O0]}}else if(P1(h)){var E=h.size();if(E.length!==1||E[0]!==N)throw new Error("Invalid matrix length");w=function(O0){return h.get([O0])}}else w=function(){return h};for(var P=[],H=[],Y=[],k=0;k<T;k++){Y.push(P.length);var K=k-L;if(K>=0&&K<N){var e0=w(K);R(e0,g)||(H.push(K+y),P.push(e0))}}return Y.push(P.length),new M({values:P,index:H,ptr:Y,size:[D,T]})},M.prototype.swapRows=function(A,h){if(!C1(A)||!U1(A)||!C1(h)||!U1(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 K1(A,this._size[0]),K1(h,this._size[0]),M._swapRows(A,h,this._size[1],this._values,this._index,this._ptr),this},M._forEachRow=function(A,h,d,m,_){for(var R=m[A],g=m[A+1],L=R;L<g;L++)_(d[L],h[L])},M._swapRows=function(A,h,d,m,_,R){for(var g=0;g<d;g++){var L=R[g],y=R[g+1],D=c(A,L,y,_),T=c(h,L,y,_);if(D<y&&T<y&&_[D]===A&&_[T]===h){if(m){var N=m[D];m[D]=m[T],m[T]=N}continue}if(D<y&&_[D]===A&&(T>=y||_[T]!==h)){var w=m?m[D]:void 0;_.splice(T,0,h),m&&m.splice(T,0,w),_.splice(T<=D?D+1:D,1),m&&m.splice(T<=D?D+1:D,1);continue}if(T<y&&_[T]===h&&(D>=y||_[D]!==A)){var E=m?m[T]:void 0;_.splice(D,0,A),m&&m.splice(D,0,E),_.splice(D<=T?T+1:T,1),m&&m.splice(D<=T?T+1:T,1)}}},M},{isClass:!0}),K5="number",J5=["typed"];function Q5(o){var e=o.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],M=e[3];return{input:o,radix:t,integerPart:r,fractionalPart:M}}else return null}function Z5(o){for(var e=parseInt(o.integerPart,o.radix),t=0,r=0;r<o.fractionalPart.length;r++){var M=parseInt(o.fractionalPart[r],o.radix);t+=M/Math.pow(o.radix,r+1)}var n=e+t;if(isNaN(n))throw new SyntaxError('String "'+o.input+'" is not a valid number');return n}var eh=h0(K5,J5,o=>{var{typed:e}=o,t=e("number",{"":function(){return 0},number:function(M){return M},string:function(M){if(M==="NaN")return NaN;var n=Q5(M);if(n)return Z5(n);var b=0,z=M.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);z&&(b=Number(z[2]),M=z[1]);var i=Number(M);if(isNaN(i))throw new SyntaxError('String "'+M+'" is not a valid number');if(z){if(i>2**b-1)throw new SyntaxError('String "'.concat(M,'" is out of range'));i>=2**(b-1)&&(i=i-2**b)}return i},BigNumber:function(M){return M.toNumber()},Fraction:function(M){return M.valueOf()},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),null:function(M){return 0},"Unit, string | Unit":function(M,n){return M.toNumber(n)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))});return t.fromJSON=function(r){return parseFloat(r.value)},t}),th="bignumber",rh=["typed","BigNumber"],Mh=h0(th,rh,o=>{var{typed:e,BigNumber:t}=o;return e("bignumber",{"":function(){return new t(0)},number:function(M){return new t(M+"")},string:function(M){var n=M.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(M,'" is out of range'));var c=new t(2).pow(Number(b)-1);return z.gte(c)?z.sub(i):z}return new t(M)},BigNumber:function(M){return M},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),Fraction:function(M){return new t(M.n).div(M.d).times(M.s)},null:function(M){return new t(0)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))})}),oh="fraction",nh=["typed","Fraction"],bh=h0(oh,nh,o=>{var{typed:e,Fraction:t}=o;return e("fraction",{number:function(M){if(!isFinite(M)||isNaN(M))throw new Error(M+" cannot be represented as a fraction");return new t(M)},string:function(M){return new t(M)},"number, number":function(M,n){return new t(M,n)},null:function(M){return new t(0)},BigNumber:function(M){return new t(M.toString())},Fraction:function(M){return M},Unit:e.referToSelf(r=>M=>{var n=M.clone();return n.value=r(M.value),n}),Object:function(M){return new t(M)},"Array | Matrix":e.referToSelf(r=>M=>Re(M,r))})}),wa="matrix",ph=["typed","Matrix","DenseMatrix","SparseMatrix"],zh=h0(wa,ph,o=>{var{typed:e,Matrix:t,DenseMatrix:r,SparseMatrix:M}=o;return e(wa,{"":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 M(b,i);throw new TypeError("Unknown matrix type "+JSON.stringify(z)+".")}}),Da="unaryMinus",ih=["typed"],ch=h0(Da,ih,o=>{var{typed:e}=o;return e(Da,{number:ma,"Complex | BigNumber | Fraction":t=>t.neg(),Unit:e.referToSelf(t=>r=>{var M=r.clone();return M.value=e.find(t,M.valueType())(r.value),M}),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),Xa="abs",ah=["typed"],sh=h0(Xa,ah,o=>{var{typed:e}=o;return e(Xa,{number:qa,"Complex | BigNumber | Fraction | Unit":t=>t.abs(),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),Ea="addScalar",Oh=["typed"],uh=h0(Ea,Oh,o=>{var{typed:e}=o;return e(Ea,{"number, number":ha,"Complex, Complex":function(r,M){return r.add(M)},"BigNumber, BigNumber":function(r,M){return r.plus(M)},"Fraction, Fraction":function(r,M){return r.add(M)},"Unit, Unit":e.referToSelf(t=>(r,M)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(M.value===null||M.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(M))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),M.valueType()])(n.value,M.value),n.fixPrefix=!1,n})})}),Ta="subtractScalar",Ah=["typed"],fh=h0(Ta,Ah,o=>{var{typed:e}=o;return e(Ta,{"number, number":Wa,"Complex, Complex":function(r,M){return r.sub(M)},"BigNumber, BigNumber":function(r,M){return r.minus(M)},"Fraction, Fraction":function(r,M){return r.sub(M)},"Unit, Unit":e.referToSelf(t=>(r,M)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(M.value===null||M.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(M))throw new Error("Units do not match");var n=r.clone();return n.value=e.find(t,[n.valueType(),M.valueType()])(n.value,M.value),n.fixPrefix=!1,n})})}),lh="matAlgo11xS0s",dh=["typed","equalScalar"],zp=h0(lh,dh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=t,d=0,m=b;typeof u=="string"&&(A=u,h=e.find(t,[A,A]),d=e.convert(0,A),n=e.convert(n,A),m=e.find(b,[A,A]));for(var _=[],R=[],g=[],L=0;L<q;L++){g[L]=R.length;for(var y=O[L],D=O[L+1],T=y;T<D;T++){var N=c[T],w=z?m(n,i[T]):m(i[T],n);h(w,d)||(R.push(N),_.push(w))}}return g[q]=R.length,M.createSparseMatrix({values:_,index:R,ptr:g,size:[l,q],datatype:A})}}),qh="matAlgo12xSfs",hh=["typed","DenseMatrix"],Br=h0(qh,hh,o=>{var{typed:e,DenseMatrix:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var d=[],m=[],_=[],R=0;R<q;R++){for(var g=R+1,L=O[R],y=O[R+1],D=L;D<y;D++){var T=c[D];m[T]=i[D],_[T]=g}for(var N=0;N<l;N++)R===0&&(d[N]=[]),_[N]===g?d[N][R]=z?h(n,m[N]):h(m[N],n):d[N][R]=z?h(n,0):h(0,n)}return new t({data:d,size:[l,q],datatype:A})}}),Wh="matAlgo14xDs",_h=["typed"],ip=h0(Wh,_h,o=>{var{typed:e}=o;return function(M,n,b,z){var i=M._data,c=M._size,O=M._datatype,s,u=b;typeof O=="string"&&(s=O,n=e.convert(n,s),u=e.find(b,[s,s]));var l=c.length>0?t(u,0,c,c[0],i,n,z):[];return M.createDenseMatrix({data:l,size:g1(c),datatype:s})};function t(r,M,n,b,z,i,c){var O=[];if(M===n.length-1)for(var s=0;s<b;s++)O[s]=c?r(i,z[s]):r(z[s],i);else for(var u=0;u<b;u++)O[u]=t(r,M+1,n,n[M+1],z[u],i,c);return O}}),mh="matAlgo02xDS0",gh=["typed","equalScalar"],Rh=h0(mh,gh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b,z){var i=M._data,c=M._size,O=M._datatype||M.getDataType(),s=n._values,u=n._index,l=n._ptr,q=n._size,A=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(c.length!==q.length)throw new d1(c.length,q.length);if(c[0]!==q[0]||c[1]!==q[1])throw new RangeError("Dimension mismatch. Matrix A ("+c+") must match Matrix B ("+q+")");if(!s)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var h=c[0],d=c[1],m,_=t,R=0,g=b;typeof O=="string"&&O===A&&O!=="mixed"&&(m=O,_=e.find(t,[m,m]),R=e.convert(0,m),g=e.find(b,[m,m]));for(var L=[],y=[],D=[],T=0;T<d;T++){D[T]=y.length;for(var N=l[T],w=l[T+1],E=N;E<w;E++){var P=u[E],H=z?g(s[E],i[P][T]):g(i[P][T],s[E]);_(H,R)||(y.push(P),L.push(H))}}return D[d]=y.length,n.createSparseMatrix({values:L,index:y,ptr:D,size:[h,d],datatype:O===M._datatype&&A===n._datatype?m:void 0})}}),vh="matAlgo03xDSf",Lh=["typed"],wr=h0(vh,Lh,o=>{var{typed:e}=o;return function(r,M,n,b){var z=r._data,i=r._size,c=r._datatype||r.getDataType(),O=M._values,s=M._index,u=M._ptr,l=M._size,q=M._datatype||M._data===void 0?M._datatype:M.getDataType();if(i.length!==l.length)throw new d1(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(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],d,m=0,_=n;typeof c=="string"&&c===q&&c!=="mixed"&&(d=c,m=e.convert(0,d),_=e.find(n,[d,d]));for(var R=[],g=0;g<A;g++)R[g]=[];for(var L=[],y=[],D=0;D<h;D++){for(var T=D+1,N=u[D],w=u[D+1],E=N;E<w;E++){var P=s[E];L[P]=b?_(O[E],z[P][D]):_(z[P][D],O[E]),y[P]=T}for(var H=0;H<A;H++)y[H]===T?R[H][D]=L[H]:R[H][D]=b?_(m,z[H][D]):_(z[H][D],m)}return r.createDenseMatrix({data:R,size:[A,h],datatype:c===r._datatype&&q===M._datatype?d:void 0})}}),Nh="matAlgo05xSfSf",yh=["typed","equalScalar"],Ca=h0(Nh,yh,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b){var z=M._values,i=M._index,c=M._ptr,O=M._size,s=M._datatype||M._data===void 0?M._datatype:M.getDataType(),u=n._values,l=n._index,q=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(O.length!==A.length)throw new d1(O.length,A.length);if(O[0]!==A[0]||O[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+O+") must match Matrix B ("+A+")");var d=O[0],m=O[1],_,R=t,g=0,L=b;typeof s=="string"&&s===h&&s!=="mixed"&&(_=s,R=e.find(t,[_,_]),g=e.convert(0,_),L=e.find(b,[_,_]));var y=z&&u?[]:void 0,D=[],T=[],N=y?[]:void 0,w=y?[]:void 0,E=[],P=[],H,Y,k,K;for(Y=0;Y<m;Y++){T[Y]=D.length;var e0=Y+1;for(k=c[Y],K=c[Y+1];k<K;k++)H=i[k],D.push(H),E[H]=e0,N&&(N[H]=z[k]);for(k=q[Y],K=q[Y+1];k<K;k++)H=l[k],E[H]!==e0&&D.push(H),P[H]=e0,w&&(w[H]=u[k]);if(y)for(k=T[Y];k<D.length;){H=D[k];var b0=E[H],O0=P[H];if(b0===e0||O0===e0){var v0=b0===e0?N[H]:g,B0=O0===e0?w[H]:g,A0=L(v0,B0);R(A0,g)?D.splice(k,1):(y.push(A0),k++)}}}return T[m]=D.length,M.createSparseMatrix({values:y,index:D,ptr:T,size:[d,m],datatype:s===M._datatype&&h===n._datatype?_:void 0})}}),Bh="matAlgo13xDD",wh=["typed"],Dh=h0(Bh,wh,o=>{var{typed:e}=o;return function(M,n,b){var z=M._data,i=M._size,c=M._datatype,O=n._data,s=n._size,u=n._datatype,l=[];if(i.length!==s.length)throw new d1(i.length,s.length);for(var q=0;q<i.length;q++){if(i[q]!==s[q])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+s+")");l[q]=i[q]}var A,h=b;typeof c=="string"&&c===u&&(A=c,h=e.find(b,[A,A]));var d=l.length>0?t(h,0,l,l[0],z,O):[];return M.createDenseMatrix({data:d,size:l,datatype:A})};function t(r,M,n,b,z,i){var c=[];if(M===n.length-1)for(var O=0;O<b;O++)c[O]=r(z[O],i[O]);else for(var s=0;s<b;s++)c[s]=t(r,M+1,n,n[M+1],z[s],i[s]);return c}}),Xh="broadcast",Eh=["concat"],Th=h0(Xh,Eh,o=>{var{concat:e}=o;return function(M,n){var b=Math.max(M._size.length,n._size.length);if(M._size.length===n._size.length&&M._size.every((q,A)=>q===n._size[A]))return[M,n];for(var z=t(M._size,b,0),i=t(n._size,b,0),c=[],O=0;O<b;O++)c[O]=Math.max(z[O],i[O]);Wo(z,c),Wo(i,c);var s=M.clone(),u=n.clone();s._size.length<b?s.reshape(t(s._size,b,1)):u._size.length<b&&u.reshape(t(u._size,b,1));for(var l=0;l<b;l++)s._size[l]<c[l]&&(s=r(s,c[l],l)),u._size[l]<c[l]&&(u=r(u,c[l],l));return[s,u]};function t(M,n,b){return[...Array(n-M.length).fill(b),...M]}function r(M,n,b){return e(...Array(n).fill(M),b)}}),Ch="matrixAlgorithmSuite",xh=["typed","matrix","concat"],Gt=h0(Ch,xh,o=>{var{typed:e,matrix:t,concat:r}=o,M=Dh({typed:e}),n=ip({typed:e}),b=Th({concat:r});return function(i){var c=i.elop,O=i.SD||i.DS,s;c?(s={"DenseMatrix, DenseMatrix":(A,h)=>M(...b(A,h),c),"Array, Array":(A,h)=>M(...b(t(A),t(h)),c).valueOf(),"Array, DenseMatrix":(A,h)=>M(...b(t(A),h),c),"DenseMatrix, Array":(A,h)=>M(...b(A,t(h)),c)},i.SS&&(s["SparseMatrix, SparseMatrix"]=(A,h)=>i.SS(...b(A,h),c,!1)),i.DS&&(s["DenseMatrix, SparseMatrix"]=(A,h)=>i.DS(...b(A,h),c,!1),s["Array, SparseMatrix"]=(A,h)=>i.DS(...b(t(A),h),c,!1)),O&&(s["SparseMatrix, DenseMatrix"]=(A,h)=>O(...b(h,A),c,!0),s["SparseMatrix, Array"]=(A,h)=>O(...b(t(h),A),c,!0))):(s={"DenseMatrix, DenseMatrix":e.referToSelf(A=>(h,d)=>M(...b(h,d),A)),"Array, Array":e.referToSelf(A=>(h,d)=>M(...b(t(h),t(d)),A).valueOf()),"Array, DenseMatrix":e.referToSelf(A=>(h,d)=>M(...b(t(h),d),A)),"DenseMatrix, Array":e.referToSelf(A=>(h,d)=>M(...b(h,t(d)),A))},i.SS&&(s["SparseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.SS(...b(h,d),A,!1))),i.DS&&(s["DenseMatrix, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.DS(...b(h,d),A,!1)),s["Array, SparseMatrix"]=e.referToSelf(A=>(h,d)=>i.DS(...b(t(h),d),A,!1))),O&&(s["SparseMatrix, DenseMatrix"]=e.referToSelf(A=>(h,d)=>O(...b(d,h),A,!0)),s["SparseMatrix, Array"]=e.referToSelf(A=>(h,d)=>O(...b(t(d),h),A,!0))));var u=i.scalar||"any",l=i.Ds||i.Ss;l&&(c?(s["DenseMatrix,"+u]=(A,h)=>n(A,h,c,!1),s[u+", DenseMatrix"]=(A,h)=>n(h,A,c,!0),s["Array,"+u]=(A,h)=>n(t(A),h,c,!1).valueOf(),s[u+", Array"]=(A,h)=>n(t(h),A,c,!0).valueOf()):(s["DenseMatrix,"+u]=e.referToSelf(A=>(h,d)=>n(h,d,A,!1)),s[u+", DenseMatrix"]=e.referToSelf(A=>(h,d)=>n(d,h,A,!0)),s["Array,"+u]=e.referToSelf(A=>(h,d)=>n(t(h),d,A,!1).valueOf()),s[u+", Array"]=e.referToSelf(A=>(h,d)=>n(t(d),h,A,!0).valueOf())));var q=i.sS!==void 0?i.sS:i.Ss;return c?(i.Ss&&(s["SparseMatrix,"+u]=(A,h)=>i.Ss(A,h,c,!1)),q&&(s[u+", SparseMatrix"]=(A,h)=>q(h,A,c,!0))):(i.Ss&&(s["SparseMatrix,"+u]=e.referToSelf(A=>(h,d)=>i.Ss(h,d,A,!1))),q&&(s[u+", SparseMatrix"]=e.referToSelf(A=>(h,d)=>q(d,h,A,!0)))),c&&c.signatures&&yc(s,c.signatures),s}}),Sh="matAlgo01xDSid",Fh=["typed"],xa=h0(Sh,Fh,o=>{var{typed:e}=o;return function(r,M,n,b){var z=r._data,i=r._size,c=r._datatype||r.getDataType(),O=M._values,s=M._index,u=M._ptr,l=M._size,q=M._datatype||M._data===void 0?M._datatype:M.getDataType();if(i.length!==l.length)throw new d1(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(!O)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var A=i[0],h=i[1],d=typeof c=="string"&&c!=="mixed"&&c===q?c:void 0,m=d?e.find(n,[d,d]):n,_,R,g=[];for(_=0;_<A;_++)g[_]=[];var L=[],y=[];for(R=0;R<h;R++){for(var D=R+1,T=u[R],N=u[R+1],w=T;w<N;w++)_=s[w],L[_]=b?m(O[w],z[_][R]):m(z[_][R],O[w]),y[_]=D;for(_=0;_<A;_++)y[_]===D?g[_][R]=L[_]:g[_][R]=z[_][R]}return r.createDenseMatrix({data:g,size:[A,h],datatype:c===r._datatype&&q===M._datatype?d:void 0})}}),Ih="matAlgo04xSidSid",Ph=["typed","equalScalar"],kh=h0(Ih,Ph,o=>{var{typed:e,equalScalar:t}=o;return function(M,n,b){var z=M._values,i=M._index,c=M._ptr,O=M._size,s=M._datatype||M._data===void 0?M._datatype:M.getDataType(),u=n._values,l=n._index,q=n._ptr,A=n._size,h=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(O.length!==A.length)throw new d1(O.length,A.length);if(O[0]!==A[0]||O[1]!==A[1])throw new RangeError("Dimension mismatch. Matrix A ("+O+") must match Matrix B ("+A+")");var d=O[0],m=O[1],_,R=t,g=0,L=b;typeof s=="string"&&s===h&&s!=="mixed"&&(_=s,R=e.find(t,[_,_]),g=e.convert(0,_),L=e.find(b,[_,_]));var y=z&&u?[]:void 0,D=[],T=[],N=z&&u?[]:void 0,w=z&&u?[]:void 0,E=[],P=[],H,Y,k,K,e0;for(Y=0;Y<m;Y++){T[Y]=D.length;var b0=Y+1;for(K=c[Y],e0=c[Y+1],k=K;k<e0;k++)H=i[k],D.push(H),E[H]=b0,N&&(N[H]=z[k]);for(K=q[Y],e0=q[Y+1],k=K;k<e0;k++)if(H=l[k],E[H]===b0){if(N){var O0=L(N[H],u[k]);R(O0,g)?E[H]=null:N[H]=O0}}else D.push(H),P[H]=b0,w&&(w[H]=u[k]);if(N&&w)for(k=T[Y];k<D.length;)H=D[k],E[H]===b0?(y[k]=N[H],k++):P[H]===b0?(y[k]=w[H],k++):D.splice(k,1)}return T[m]=D.length,M.createSparseMatrix({values:y,index:D,ptr:T,size:[d,m],datatype:s===M._datatype&&h===n._datatype?_:void 0})}}),$h="matAlgo10xSids",Uh=["typed","DenseMatrix"],Sa=h0($h,Uh,o=>{var{typed:e,DenseMatrix:t}=o;return function(M,n,b,z){var i=M._values,c=M._index,O=M._ptr,s=M._size,u=M._datatype;if(!i)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var l=s[0],q=s[1],A,h=b;typeof u=="string"&&(A=u,n=e.convert(n,A),h=e.find(b,[A,A]));for(var d=[],m=[],_=[],R=0;R<q;R++){for(var g=R+1,L=O[R],y=O[R+1],D=L;D<y;D++){var T=c[D];m[T]=i[D],_[T]=g}for(var N=0;N<l;N++)R===0&&(d[N]=[]),_[N]===g?d[N][R]=z?h(n,m[N]):h(m[N],n):d[N][R]=n}return new t({data:d,size:[l,q],datatype:A})}}),jh="multiplyScalar",Hh=["typed"],Yh=h0(jh,Hh,o=>{var{typed:e}=o;return e("multiplyScalar",{"number, number":_a,"Complex, Complex":function(r,M){return r.mul(M)},"BigNumber, BigNumber":function(r,M){return r.times(M)},"Fraction, Fraction":function(r,M){return r.mul(M)},"number | Fraction | BigNumber | Complex, Unit":(t,r)=>r.multiply(t),"Unit, number | Fraction | BigNumber | Complex | Unit":(t,r)=>t.multiply(r)})}),Fa="multiply",Gh=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],Vh=h0(Fa,Gh,o=>{var{typed:e,matrix:t,addScalar:r,multiplyScalar:M,equalScalar:n,dot:b}=o,z=zp({typed:e,equalScalar:n}),i=ip({typed:e});function c(g,L){switch(g.length){case 1:switch(L.length){case 1:if(g[0]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(g[0]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+g[0]+") must match Matrix rows ("+L[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+L.length+" dimensions)")}break;case 2:switch(L.length){case 1:if(g[1]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+g[1]+") must match Vector length ("+L[0]+")");break;case 2:if(g[1]!==L[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+g[1]+") must match Matrix B rows ("+L[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+L.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+g.length+" dimensions)")}}function O(g,L,y){if(y===0)throw new Error("Cannot multiply two empty vectors");return b(g,L)}function s(g,L){if(L.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return u(g,L)}function u(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._size,E=L._datatype||L.getDataType(),P=D[0],H=w[1],Y,k=r,K=M;T&&E&&T===E&&typeof T=="string"&&T!=="mixed"&&(Y=T,k=e.find(r,[Y,Y]),K=e.find(M,[Y,Y]));for(var e0=[],b0=0;b0<H;b0++){for(var O0=K(y[0],N[0][b0]),v0=1;v0<P;v0++)O0=k(O0,K(y[v0],N[v0][b0]));e0[b0]=O0}return g.createDenseMatrix({data:e0,size:[H],datatype:T===g._datatype&&E===L._datatype?Y:void 0})}var l=e("_multiplyMatrixVector",{"DenseMatrix, any":A,"SparseMatrix, any":m}),q=e("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":h,"DenseMatrix, SparseMatrix":d,"SparseMatrix, DenseMatrix":_,"SparseMatrix, SparseMatrix":R});function A(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._datatype||L.getDataType(),E=D[0],P=D[1],H,Y=r,k=M;T&&w&&T===w&&typeof T=="string"&&T!=="mixed"&&(H=T,Y=e.find(r,[H,H]),k=e.find(M,[H,H]));for(var K=[],e0=0;e0<E;e0++){for(var b0=y[e0],O0=k(b0[0],N[0]),v0=1;v0<P;v0++)O0=Y(O0,k(b0[v0],N[v0]));K[e0]=O0}return g.createDenseMatrix({data:K,size:[E],datatype:T===g._datatype&&w===L._datatype?H:void 0})}function h(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._data,w=L._size,E=L._datatype||L.getDataType(),P=D[0],H=D[1],Y=w[1],k,K=r,e0=M;T&&E&&T===E&&typeof T=="string"&&T!=="mixed"&&T!=="mixed"&&(k=T,K=e.find(r,[k,k]),e0=e.find(M,[k,k]));for(var b0=[],O0=0;O0<P;O0++){var v0=y[O0];b0[O0]=[];for(var B0=0;B0<Y;B0++){for(var A0=e0(v0[0],N[0][B0]),k0=1;k0<H;k0++)A0=K(A0,e0(v0[k0],N[k0][B0]));b0[O0][B0]=A0}}return g.createDenseMatrix({data:b0,size:[P,Y],datatype:T===g._datatype&&E===L._datatype?k:void 0})}function d(g,L){var y=g._data,D=g._size,T=g._datatype||g.getDataType(),N=L._values,w=L._index,E=L._ptr,P=L._size,H=L._datatype||L._data===void 0?L._datatype:L.getDataType();if(!N)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var Y=D[0],k=P[1],K,e0=r,b0=M,O0=n,v0=0;T&&H&&T===H&&typeof T=="string"&&T!=="mixed"&&(K=T,e0=e.find(r,[K,K]),b0=e.find(M,[K,K]),O0=e.find(n,[K,K]),v0=e.convert(0,K));for(var B0=[],A0=[],k0=[],I0=L.createSparseMatrix({values:B0,index:A0,ptr:k0,size:[Y,k],datatype:T===g._datatype&&H===L._datatype?K:void 0}),P0=0;P0<k;P0++){k0[P0]=A0.length;var W0=E[P0],z1=E[P0+1];if(z1>W0)for(var Z0=0,i1=0;i1<Y;i1++){for(var t2=i1+1,W1=void 0,F=W0;F<z1;F++){var J=w[F];Z0!==t2?(W1=b0(y[i1][J],N[F]),Z0=t2):W1=e0(W1,b0(y[i1][J],N[F]))}Z0===t2&&!O0(W1,v0)&&(A0.push(i1),B0.push(W1))}}return k0[k]=A0.length,I0}function m(g,L){var y=g._values,D=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 w=L._data,E=L._datatype||L.getDataType(),P=g._size[0],H=L._size[0],Y=[],k=[],K=[],e0,b0=r,O0=M,v0=n,B0=0;N&&E&&N===E&&typeof N=="string"&&N!=="mixed"&&(e0=N,b0=e.find(r,[e0,e0]),O0=e.find(M,[e0,e0]),v0=e.find(n,[e0,e0]),B0=e.convert(0,e0));var A0=[],k0=[];K[0]=0;for(var I0=0;I0<H;I0++){var P0=w[I0];if(!v0(P0,B0))for(var W0=T[I0],z1=T[I0+1],Z0=W0;Z0<z1;Z0++){var i1=D[Z0];k0[i1]?A0[i1]=b0(A0[i1],O0(P0,y[Z0])):(k0[i1]=!0,k.push(i1),A0[i1]=O0(P0,y[Z0]))}}for(var t2=k.length,W1=0;W1<t2;W1++){var F=k[W1];Y[W1]=A0[F]}return K[1]=k.length,g.createSparseMatrix({values:Y,index:k,ptr:K,size:[P,1],datatype:N===g._datatype&&E===L._datatype?e0:void 0})}function _(g,L){var y=g._values,D=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 w=L._data,E=L._datatype||L.getDataType(),P=g._size[0],H=L._size[0],Y=L._size[1],k,K=r,e0=M,b0=n,O0=0;N&&E&&N===E&&typeof N=="string"&&N!=="mixed"&&(k=N,K=e.find(r,[k,k]),e0=e.find(M,[k,k]),b0=e.find(n,[k,k]),O0=e.convert(0,k));for(var v0=[],B0=[],A0=[],k0=g.createSparseMatrix({values:v0,index:B0,ptr:A0,size:[P,Y],datatype:N===g._datatype&&E===L._datatype?k:void 0}),I0=[],P0=[],W0=0;W0<Y;W0++){A0[W0]=B0.length;for(var z1=W0+1,Z0=0;Z0<H;Z0++){var i1=w[Z0][W0];if(!b0(i1,O0))for(var t2=T[Z0],W1=T[Z0+1],F=t2;F<W1;F++){var J=D[F];P0[J]!==z1?(P0[J]=z1,B0.push(J),I0[J]=e0(i1,y[F])):I0[J]=K(I0[J],e0(i1,y[F]))}}for(var Z=A0[W0],s0=B0.length,R0=Z;R0<s0;R0++){var H0=B0[R0];v0[R0]=I0[H0]}}return A0[Y]=B0.length,k0}function R(g,L){var y=g._values,D=g._index,T=g._ptr,N=g._datatype||g._data===void 0?g._datatype:g.getDataType(),w=L._values,E=L._index,P=L._ptr,H=L._datatype||L._data===void 0?L._datatype:L.getDataType(),Y=g._size[0],k=L._size[1],K=y&&w,e0,b0=r,O0=M;N&&H&&N===H&&typeof N=="string"&&N!=="mixed"&&(e0=N,b0=e.find(r,[e0,e0]),O0=e.find(M,[e0,e0]));for(var v0=K?[]:void 0,B0=[],A0=[],k0=g.createSparseMatrix({values:v0,index:B0,ptr:A0,size:[Y,k],datatype:N===g._datatype&&H===L._datatype?e0:void 0}),I0=K?[]:void 0,P0=[],W0,z1,Z0,i1,t2,W1,F,J,Z=0;Z<k;Z++){A0[Z]=B0.length;var s0=Z+1;for(t2=P[Z],W1=P[Z+1],i1=t2;i1<W1;i1++)if(J=E[i1],K)for(z1=T[J],Z0=T[J+1],W0=z1;W0<Z0;W0++)F=D[W0],P0[F]!==s0?(P0[F]=s0,B0.push(F),I0[F]=O0(w[i1],y[W0])):I0[F]=b0(I0[F],O0(w[i1],y[W0]));else for(z1=T[J],Z0=T[J+1],W0=z1;W0<Z0;W0++)F=D[W0],P0[F]!==s0&&(P0[F]=s0,B0.push(F));if(K)for(var R0=A0[Z],H0=B0.length,v1=R0;v1<H0;v1++){var J0=B0[v1];v0[v1]=I0[J0]}}return A0[k]=B0.length,k0}return e(Fa,M,{"Array, Array":e.referTo("Matrix, Matrix",g=>(L,y)=>{c(o2(L),o2(y));var D=g(t(L),t(y));return P1(D)?D.valueOf():D}),"Matrix, Matrix":function(L,y){var D=L.size(),T=y.size();return c(D,T),D.length===1?T.length===1?O(L,y,D[0]):s(L,y):T.length===1?l(L,y):q(L,y)},"Matrix, Array":e.referTo("Matrix,Matrix",g=>(L,y)=>g(L,t(y))),"Array, Matrix":e.referToSelf(g=>(L,y)=>g(t(L,y.storage()),y)),"SparseMatrix, any":function(L,y){return z(L,y,M,!1)},"DenseMatrix, any":function(L,y){return i(L,y,M,!1)},"any, SparseMatrix":function(L,y){return z(y,L,M,!0)},"any, DenseMatrix":function(L,y){return i(y,L,M,!0)},"Array, any":function(L,y){return i(t(L),y,M,!1).valueOf()},"any, Array":function(L,y){return i(t(y),L,M,!0).valueOf()},"any, any":M,"any, any, ...any":e.referToSelf(g=>(L,y,D)=>{for(var T=g(L,y),N=0;N<D.length;N++)T=g(T,D[N]);return T})})}),Ia="subtract",Kh=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],Jh=h0(Ia,Kh,o=>{var{typed:e,matrix:t,equalScalar:r,subtractScalar:M,unaryMinus:n,DenseMatrix:b,concat:z}=o,i=xa({typed:e}),c=wr({typed:e}),O=Ca({typed:e,equalScalar:r}),s=Sa({typed:e,DenseMatrix:b}),u=Br({typed:e,DenseMatrix:b}),l=Gt({typed:e,matrix:t,concat:z});return e(Ia,{"any, any":M},l({elop:M,SS:O,DS:i,SD:c,Ss:u,sS:s}))}),Qh="matAlgo07xSSf",Zh=["typed","DenseMatrix"],Co=h0(Qh,Zh,o=>{var{typed:e,DenseMatrix:t}=o;return function(n,b,z){var i=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),O=b._size,s=b._datatype||b._data===void 0?b._datatype:b.getDataType();if(i.length!==O.length)throw new d1(i.length,O.length);if(i[0]!==O[0]||i[1]!==O[1])throw new RangeError("Dimension mismatch. Matrix A ("+i+") must match Matrix B ("+O+")");var u=i[0],l=i[1],q,A=0,h=z;typeof c=="string"&&c===s&&c!=="mixed"&&(q=c,A=e.convert(0,q),h=e.find(z,[q,q]));var d,m,_=[];for(d=0;d<u;d++)_[d]=[];var R=[],g=[],L=[],y=[];for(m=0;m<l;m++){var D=m+1;for(r(n,m,L,R,D),r(b,m,y,g,D),d=0;d<u;d++){var T=L[d]===D?R[d]:A,N=y[d]===D?g[d]:A;_[d][m]=h(T,N)}}return new t({data:_,size:[u,l],datatype:c===n._datatype&&s===b._datatype?q:void 0})};function r(M,n,b,z,i){for(var c=M._values,O=M._index,s=M._ptr,u=s[n],l=s[n+1];u<l;u++){var q=O[u];b[q]=i,z[q]=c[u]}}}),Pa="conj",eW=["typed"],tW=h0(Pa,eW,o=>{var{typed:e}=o;return e(Pa,{"number | BigNumber | Fraction":t=>t,Complex:t=>t.conjugate(),"Array | Matrix":e.referToSelf(t=>r=>Re(r,t))})}),ka="concat",rW=["typed","matrix","isInteger"],MW=h0(ka,rW,o=>{var{typed:e,matrix:t,isInteger:r}=o;return e(ka,{"...Array | Matrix | number | BigNumber":function(n){var b,z=n.length,i=-1,c,O=!1,s=[];for(b=0;b<z;b++){var u=n[b];if(P1(u)&&(O=!0),C1(u)||e2(u)){if(b!==z-1)throw new Error("Dimension must be specified as last argument");if(c=i,i=u.valueOf(),!r(i))throw new TypeError("Integer number expected for dimension");if(i<0||b>0&&i>c)throw new _t(i,c+1)}else{var l=g1(u).valueOf(),q=o2(l);if(s[b]=l,c=i,i=q.length-1,b>0&&i!==c)throw new d1(c+1,i+1)}}if(s.length===0)throw new SyntaxError("At least one matrix expected");for(var A=s.shift();s.length;)A=Vc(A,s.shift(),i);return O?t(A):A},"...string":function(n){return n.join("")}})}),$a="count",oW=["typed","size","prod"],nW=h0($a,oW,o=>{var{typed:e,size:t,prod:r}=o;return e($a,{string:function(n){return n.length},"Matrix | Array":function(n){return r(t(n))}})}),Ua="identity",bW=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],pW=h0(Ua,bW,o=>{var{typed:e,config:t,matrix:r,BigNumber:M,DenseMatrix:n,SparseMatrix:b}=o;return e(Ua,{"":function(){return t.matrix==="Matrix"?r([]):[]},string:function(O){return r(O)},"number | BigNumber":function(O){return i(O,O,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(O,s){return i(O,O,s)},"number | BigNumber, number | BigNumber":function(O,s){return i(O,s,t.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(O,s,u){return i(O,s,u)},Array:function(O){return z(O)},"Array, string":function(O,s){return z(O,s)},Matrix:function(O){return z(O.valueOf(),O.storage())},"Matrix, string":function(O,s){return z(O.valueOf(),s)}});function z(c,O){switch(c.length){case 0:return O?r(O):[];case 1:return i(c[0],c[0],O);case 2:return i(c[0],c[1],O);default:throw new Error("Vector containing two values expected")}}function i(c,O,s){var u=e2(c)||e2(O)?M:null;if(e2(c)&&(c=c.toNumber()),e2(O)&&(O=O.toNumber()),!U1(c)||c<1)throw new Error("Parameters in function identity must be positive integers");if(!U1(O)||O<1)throw new Error("Parameters in function identity must be positive integers");var l=u?new M(1):1,q=u?new u(0):0,A=[c,O];if(s){if(s==="sparse")return b.diagonal(A,l,0,q);if(s==="dense")return n.diagonal(A,l,0,q);throw new TypeError('Unknown matrix type "'.concat(s,'"'))}for(var h=Gb([],A,q),d=c<O?c:O,m=0;m<d;m++)h[m][m]=l;return h}}),ja="kron",zW=["typed","matrix","multiplyScalar"],iW=h0(ja,zW,o=>{var{typed:e,matrix:t,multiplyScalar:r}=o;return e(ja,{"Matrix, Matrix":function(b,z){return t(M(b.toArray(),z.toArray()))},"Matrix, Array":function(b,z){return t(M(b.toArray(),z))},"Array, Matrix":function(b,z){return t(M(b,z.toArray()))},"Array, Array":M});function M(n,b){if(o2(n).length===1&&(n=[n]),o2(b).length===1&&(b=[b]),o2(n).length>2||o2(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(c){return b.map(function(O){return i=[],z.push(i),c.map(function(s){return O.map(function(u){return i.push(r(s,u))})})})})&&z}});function cW(){throw new Error('No "bignumber" implementation available')}function aW(){throw new Error('No "fraction" implementation available')}function sW(){throw new Error('No "matrix" implementation available')}var Ha="reshape",OW=["typed","isInteger","matrix"],uW=h0(Ha,OW,o=>{var{typed:e,isInteger:t}=o;return e(Ha,{"Matrix, Array":function(M,n){return M.reshape(n,!0)},"Array, Array":function(M,n){return n.forEach(function(b){if(!t(b))throw new TypeError("Invalid size for dimension: "+b)}),Kb(M,n)}})}),Ya="size",AW=["typed","config","?matrix"],fW=h0(Ya,AW,o=>{var{typed:e,config:t,matrix:r}=o;return e(Ya,{Matrix:function(n){return n.create(n.size())},Array:o2,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([]):sW()}})}),Ga="transpose",lW=["typed","matrix"],dW=h0(Ga,lW,o=>{var{typed:e,matrix:t}=o;return e(Ga,{Array:b=>r(t(b)).valueOf(),Matrix:r,any:g1});function r(b){var z=b.size(),i;switch(z.length){case 1:i=b.clone();break;case 2:{var c=z[0],O=z[1];if(O===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+D1(z)+")");switch(b.storage()){case"dense":i=M(b,c,O);break;case"sparse":i=n(b,c,O);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+D1(z)+")")}return i}function M(b,z,i){for(var c=b._data,O=[],s,u=0;u<i;u++){s=O[u]=[];for(var l=0;l<z;l++)s[l]=g1(c[l][u])}return b.createDenseMatrix({data:O,size:[i,z],datatype:b._datatype})}function n(b,z,i){for(var c=b._values,O=b._index,s=b._ptr,u=c?[]:void 0,l=[],q=[],A=[],h=0;h<z;h++)A[h]=0;var d,m,_;for(d=0,m=O.length;d<m;d++)A[O[d]]++;for(var R=0,g=0;g<z;g++)q.push(R),R+=A[g],A[g]=q[g];for(q.push(R),_=0;_<i;_++)for(var L=s[_],y=s[_+1],D=L;D<y;D++){var T=A[O[D]]++;l[T]=_,c&&(u[T]=g1(c[D]))}return b.createSparseMatrix({values:u,index:l,ptr:q,size:[i,z],datatype:b._datatype})}}),Va="ctranspose",qW=["typed","transpose","conj"],hW=h0(Va,qW,o=>{var{typed:e,transpose:t,conj:r}=o;return e(Va,{any:function(n){return r(t(n))}})}),Ka="mode",WW=["typed","isNaN","isNumeric"],_W=h0(Ka,WW,o=>{var{typed:e,isNaN:t,isNumeric:r}=o;return e(Ka,{"Array | Matrix":M,"...":function(b){return M(b)}});function M(n){n=Qb(n.valueOf());var b=n.length;if(b===0)throw new Error("Cannot calculate mode of an empty array");for(var z={},i=[],c=0,O=0;O<n.length;O++){var s=n[O];if(r(s)&&t(s))throw new Error("Cannot calculate mode of an array containing NaN values");s in z||(z[s]=0),z[s]++,z[s]===c?i.push(s):z[s]>c&&(c=z[s],i=[s])}return i}});function Lt(o,e,t){var r;return String(o).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+Wt(t)+", value: "+JSON.stringify(t)+")":" (type: "+o.data.actual+")",new TypeError("Cannot calculate "+e+", unexpected type of argument"+r)):String(o).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+Wt(t)+", value: "+JSON.stringify(t)+")":"",new TypeError("Cannot calculate "+e+", no ordering relation is defined for complex numbers"+r)):o}var Ja="prod",mW=["typed","config","multiplyScalar","numeric"],gW=h0(Ja,mW,o=>{var{typed:e,config:t,multiplyScalar:r,numeric:M}=o;return e(Ja,{"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(dM(b,function(i){try{z=z===void 0?i:r(z,i)}catch(c){throw Lt(c,"prod",i)}}),typeof z=="string"&&(z=M(z,t.number)),z===void 0)throw new Error("Cannot calculate prod of an empty array");return z}}),RW="numeric",vW=["number","?bignumber","?fraction"],LW=h0(RW,vW,o=>{var{number:e,bignumber:t,fraction:r}=o,M={string:!0,number:!0,BigNumber:!0,Fraction:!0},n={number:b=>e(b),BigNumber:t?b=>t(b):cW,Fraction:r?b=>r(b):aW};return function(z){var i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",c=arguments.length>2?arguments[2]:void 0;if(c!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var O=Wt(z);if(!(O in M))throw new TypeError("Cannot convert "+z+' of type "'+O+'"; valid input types are '+Object.keys(M).join(", "));if(!(i in n))throw new TypeError("Cannot convert "+z+' to type "'+i+'"; valid output types are '+Object.keys(n).join(", "));return i===O?z:n[i](z)}}),Qa="divideScalar",NW=["typed","numeric"],yW=h0(Qa,NW,o=>{var{typed:e,numeric:t}=o;return e(Qa,{"number, number":function(M,n){return M/n},"Complex, Complex":function(M,n){return M.div(n)},"BigNumber, BigNumber":function(M,n){return M.div(n)},"Fraction, Fraction":function(M,n){return M.div(n)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,M)=>r.divide(M),"number | Fraction | Complex | BigNumber, Unit":(r,M)=>M.divideInto(r)})}),Za="pow",BW=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],wW=h0(Za,BW,o=>{var{typed:e,config:t,identity:r,multiply:M,matrix:n,inv:b,number:z,fraction:i,Complex:c}=o;return e(Za,{"number, number":O,"Complex, Complex":function(q,A){return q.pow(A)},"BigNumber, BigNumber":function(q,A){return A.isInteger()||q>=0||t.predictable?q.pow(A):new c(q.toNumber(),0).pow(A.toNumber(),0)},"Fraction, Fraction":function(q,A){var h=q.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 O(q.valueOf(),A.valueOf())},"Array, number":s,"Array, BigNumber":function(q,A){return s(q,A.toNumber())},"Matrix, number":u,"Matrix, BigNumber":function(q,A){return u(q,A.toNumber())},"Unit, number | BigNumber":function(q,A){return q.pow(A)}});function O(l,q){if(t.predictable&&!U1(q)&&l<0)try{var A=i(q),h=z(A);if((q===h||Math.abs((q-h)/q)<1e-14)&&A.d%2===1)return(A.n%2===0?1:-1)*Math.pow(-l,q)}catch{}return t.predictable&&(l<-1&&q===1/0||l>-1&&l<0&&q===-1/0)?NaN:U1(q)||l>=0||t.predictable?ga(l,q):l*l<1&&q===1/0||l*l>1&&q===-1/0?0:new c(l,0).pow(q,0)}function s(l,q){if(!U1(q))throw new TypeError("For A^b, b must be an integer (value is "+q+")");var A=o2(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(q<0)try{return s(b(l),-q)}catch(m){throw m.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 "+q+")"):m}for(var h=r(A[0]).valueOf(),d=l;q>=1;)(q&1)===1&&(h=M(d,h)),q>>=1,d=M(d,d);return h}function u(l,q){return n(s(l.valueOf(),q))}}),e3="dotDivide",DW=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],XW=h0(e3,DW,o=>{var{typed:e,matrix:t,equalScalar:r,divideScalar:M,DenseMatrix:n,concat:b}=o,z=Rh({typed:e,equalScalar:r}),i=wr({typed:e}),c=Co({typed:e,DenseMatrix:n}),O=zp({typed:e,equalScalar:r}),s=Br({typed:e,DenseMatrix:n}),u=Gt({typed:e,matrix:t,concat:b});return e(e3,u({elop:M,SS:c,DS:i,SD:z,Ss:O,sS:s}))}),xo="compare",EW=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],TW=h0(xo,EW,o=>{var{typed:e,config:t,equalScalar:r,matrix:M,BigNumber:n,Fraction:b,DenseMatrix:z,concat:i}=o,c=wr({typed:e}),O=Ca({typed:e,equalScalar:r}),s=Br({typed:e,DenseMatrix:z}),u=Gt({typed:e,matrix:M,concat:i}),l=Eo({typed:e});return e(xo,CW({typed:e,config:t}),{"boolean, boolean":function(A,h){return A===h?0:A>h?1:-1},"BigNumber, BigNumber":function(A,h){return Xo(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:O,DS:c,Ss:s}))}),CW=h0(xo,["typed","config"],o=>{var{typed:e,config:t}=o;return e(xo,{"number, number":function(M,n){return Yt(M,n,t.epsilon)?0:M>n?1:-1}})}),So="equal",xW=["typed","matrix","equalScalar","DenseMatrix","concat"],SW=h0(So,xW,o=>{var{typed:e,matrix:t,equalScalar:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:t,concat:n});return e(So,FW({typed:e,equalScalar:r}),c({elop:r,SS:z,DS:b,Ss:i}))}),FW=h0(So,["typed","equalScalar"],o=>{var{typed:e,equalScalar:t}=o;return e(So,{"any, any":function(M,n){return M===null?n===null:n===null?M===null:M===void 0?n===void 0:n===void 0?M===void 0:t(M,n)}})}),Fo="smaller",IW=["typed","config","matrix","DenseMatrix","concat"],PW=h0(Fo,IW,o=>{var{typed:e,config:t,matrix:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:r,concat:n}),O=Eo({typed:e});return e(Fo,kW({typed:e,config:t}),{"boolean, boolean":(s,u)=>s<u,"BigNumber, BigNumber":function(u,l){return u.lt(l)&&!Xo(u,l,t.epsilon)},"Fraction, Fraction":(s,u)=>s.compare(u)===-1,"Complex, Complex":function(u,l){throw new TypeError("No ordering relation is defined for complex numbers")}},O,c({SS:z,DS:b,Ss:i}))}),kW=h0(Fo,["typed","config"],o=>{var{typed:e,config:t}=o;return e(Fo,{"number, number":function(M,n){return M<n&&!Yt(M,n,t.epsilon)}})}),Io="larger",$W=["typed","config","matrix","DenseMatrix","concat"],UW=h0(Io,$W,o=>{var{typed:e,config:t,matrix:r,DenseMatrix:M,concat:n}=o,b=wr({typed:e}),z=Co({typed:e,DenseMatrix:M}),i=Br({typed:e,DenseMatrix:M}),c=Gt({typed:e,matrix:r,concat:n}),O=Eo({typed:e});return e(Io,jW({typed:e,config:t}),{"boolean, boolean":(s,u)=>s>u,"BigNumber, BigNumber":function(u,l){return u.gt(l)&&!Xo(u,l,t.epsilon)},"Fraction, Fraction":(s,u)=>s.compare(u)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},O,c({SS:z,DS:b,Ss:i}))}),jW=h0(Io,["typed","config"],o=>{var{typed:e,config:t}=o;return e(Io,{"number, number":function(M,n){return M>n&&!Yt(M,n,t.epsilon)}})}),t3="deepEqual",HW=["typed","equal"],YW=h0(t3,HW,o=>{var{typed:e,equal:t}=o;return e(t3,{"any, any":function(n,b){return r(n.valueOf(),b.valueOf())}});function r(M,n){if(Array.isArray(M))if(Array.isArray(n)){var b=M.length;if(b!==n.length)return!1;for(var z=0;z<b;z++)if(!r(M[z],n[z]))return!1;return!0}else return!1;else return Array.isArray(n)?!1:t(M,n)}}),r3="partitionSelect",GW=["typed","isNumeric","isNaN","compare"],VW=h0(r3,GW,o=>{var{typed:e,isNumeric:t,isNaN:r,compare:M}=o,n=M,b=(c,O)=>-M(c,O);return e(r3,{"Array | Matrix, number":function(O,s){return z(O,s,n)},"Array | Matrix, number, string":function(O,s,u){if(u==="asc")return z(O,s,n);if(u==="desc")return z(O,s,b);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":z});function z(c,O,s){if(!U1(O)||O<0)throw new Error("k must be a non-negative integer");if(P1(c)){var u=c.size();if(u.length>1)throw new Error("Only one dimensional matrices supported");return i(c.valueOf(),O,s)}if(Array.isArray(c))return i(c,O,s)}function i(c,O,s){if(O>=c.length)throw new Error("k out of bounds");for(var u=0;u<c.length;u++)if(t(c[u])&&r(c[u]))return c[u];for(var l=0,q=c.length-1;l<q;){for(var A=l,h=q,d=c[Math.floor(Math.random()*(q-l+1))+l];A<h;)if(s(c[A],d)>=0){var m=c[h];c[h]=c[A],c[A]=m,--h}else++A;s(c[A],d)>0&&--A,O<=A?q=A:l=A+1}return c[O]}}),M3="max",KW=["typed","config","numeric","larger"],JW=h0(M3,KW,o=>{var{typed:e,config:t,numeric:r,larger:M}=o;return e(M3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,c){return pp(i,c.valueOf(),n)},"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function max");return b(i)}});function n(z,i){try{return M(z,i)?z:i}catch(c){throw Lt(c,"max",i)}}function b(z){var i;if(dM(z,function(c){try{isNaN(c)&&typeof c=="number"?i=NaN:(i===void 0||M(c,i))&&(i=c)}catch(O){throw Lt(O,"max",c)}}),i===void 0)throw new Error("Cannot calculate max of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),o3="min",QW=["typed","config","numeric","smaller"],ZW=h0(o3,QW,o=>{var{typed:e,config:t,numeric:r,smaller:M}=o;return e(o3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(i,c){return pp(i,c.valueOf(),n)},"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function min");return b(i)}});function n(z,i){try{return M(z,i)?z:i}catch(c){throw Lt(c,"min",i)}}function b(z){var i;if(dM(z,function(c){try{isNaN(c)&&typeof c=="number"?i=NaN:(i===void 0||M(c,i))&&(i=c)}catch(O){throw Lt(O,"min",c)}}),i===void 0)throw new Error("Cannot calculate min of an empty array");return typeof i=="string"&&(i=r(i,t.number)),i}}),n3="add",e6=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],t6=h0(n3,e6,o=>{var{typed:e,matrix:t,addScalar:r,equalScalar:M,DenseMatrix:n,SparseMatrix:b,concat:z}=o,i=xa({typed:e}),c=kh({typed:e,equalScalar:M}),O=Sa({typed:e,DenseMatrix:n}),s=Gt({typed:e,matrix:t,concat:z});return e(n3,{"any, any":r,"any, any, ...any":e.referToSelf(u=>(l,q,A)=>{for(var h=u(l,q),d=0;d<A.length;d++)h=u(h,A[d]);return h})},s({elop:r,DS:i,SS:c,Ss:O}))}),b3="dot",r6=["typed","addScalar","multiplyScalar","conj","size"],M6=h0(b3,r6,o=>{var{typed:e,addScalar:t,multiplyScalar:r,conj:M,size:n}=o;return e(b3,{"Array | DenseMatrix, Array | DenseMatrix":z,"SparseMatrix, SparseMatrix":i});function b(O,s){var u=c(O),l=c(s),q,A;if(u.length===1)q=u[0];else if(u.length===2&&u[1]===1)q=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(q!==A)throw new RangeError("Vectors must have equal length ("+q+" != "+A+")");if(q===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return q}function z(O,s){var u=b(O,s),l=P1(O)?O._data:O,q=P1(O)?O._datatype||O.getDataType():void 0,A=P1(s)?s._data:s,h=P1(s)?s._datatype||s.getDataType():void 0,d=c(O).length===2,m=c(s).length===2,_=t,R=r;if(q&&h&&q===h&&typeof q=="string"&&q!=="mixed"){var g=q;_=e.find(t,[g,g]),R=e.find(r,[g,g])}if(!d&&!m){for(var L=R(M(l[0]),A[0]),y=1;y<u;y++)L=_(L,R(M(l[y]),A[y]));return L}if(!d&&m){for(var D=R(M(l[0]),A[0][0]),T=1;T<u;T++)D=_(D,R(M(l[T]),A[T][0]));return D}if(d&&!m){for(var N=R(M(l[0][0]),A[0]),w=1;w<u;w++)N=_(N,R(M(l[w][0]),A[w]));return N}if(d&&m){for(var E=R(M(l[0][0]),A[0][0]),P=1;P<u;P++)E=_(E,R(M(l[P][0]),A[P][0]));return E}}function i(O,s){b(O,s);for(var u=O._index,l=O._values,q=s._index,A=s._values,h=0,d=t,m=r,_=0,R=0;_<u.length&&R<q.length;){var g=u[_],L=q[R];if(g<L){_++;continue}if(g>L){R++;continue}g===L&&(h=d(h,m(l[_],A[R])),_++,R++)}return h}function c(O){return P1(O)?O.size():n(O)}}),o6="trace",n6=["typed","matrix","add"],b6=h0(o6,n6,o=>{var{typed:e,matrix:t,add:r}=o;return e("trace",{Array:function(z){return M(t(z))},SparseMatrix:n,DenseMatrix:M,any:g1});function M(b){var z=b._size,i=b._data;switch(z.length){case 1:if(z[0]===1)return g1(i[0]);throw new RangeError("Matrix must be square (size: "+D1(z)+")");case 2:{var c=z[0],O=z[1];if(c===O){for(var s=0,u=0;u<c;u++)s=r(s,i[u][u]);return s}else throw new RangeError("Matrix must be square (size: "+D1(z)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(z)+")")}}function n(b){var z=b._values,i=b._index,c=b._ptr,O=b._size,s=O[0],u=O[1];if(s===u){var l=0;if(z.length>0)for(var q=0;q<u;q++)for(var A=c[q],h=c[q+1],d=A;d<h;d++){var m=i[d];if(m===q){l=r(l,z[d]);break}if(m>q)break}return l}throw new RangeError("Matrix must be square (size: "+D1(O)+")")}}),p3="det",p6=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],z6=h0(p3,p6,o=>{var{typed:e,matrix:t,subtractScalar:r,multiply:M,divideScalar:n,isZero:b,unaryMinus:z}=o;return e(p3,{any:function(O){return g1(O)},"Array | Matrix":function(O){var s;switch(P1(O)?s=O.size():Array.isArray(O)?(O=t(O),s=O.size()):s=[],s.length){case 0:return g1(O);case 1:if(s[0]===1)return g1(O.valueOf()[0]);if(s[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+D1(s)+")");case 2:{var u=s[0],l=s[1];if(u===l)return i(O.clone().valueOf(),u);if(l===0)return 1;throw new RangeError("Matrix must be square (size: "+D1(s)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(s)+")")}}});function i(c,O,s){if(O===1)return g1(c[0][0]);if(O===2)return r(M(c[0][0],c[1][1]),M(c[1][0],c[0][1]));for(var u=!1,l=new Array(O).fill(0).map((y,D)=>D),q=0;q<O;q++){var A=l[q];if(b(c[A][q])){var h=void 0;for(h=q+1;h<O;h++)if(!b(c[l[h]][q])){A=l[h],l[h]=l[q],l[q]=A,u=!u;break}if(h===O)return c[A][q]}for(var d=c[A][q],m=q===0?1:c[l[q-1]][q-1],_=q+1;_<O;_++)for(var R=l[_],g=q+1;g<O;g++)c[R][g]=n(r(M(c[R][g],d),M(c[R][q],c[A][g])),m)}var L=c[l[O-1]][O-1];return u?z(L):L}}),z3="inv",i6=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],c6=h0(z3,i6,o=>{var{typed:e,matrix:t,divideScalar:r,addScalar:M,multiply:n,unaryMinus:b,det:z,identity:i,abs:c}=o;return e(z3,{"Array | Matrix":function(u){var l=P1(u)?u.size():o2(u);switch(l.length){case 1:if(l[0]===1)return P1(u)?t([r(1,u.valueOf()[0])]):[r(1,u[0])];throw new RangeError("Matrix must be square (size: "+D1(l)+")");case 2:{var q=l[0],A=l[1];if(q===A)return P1(u)?t(O(u.valueOf(),q,A),u.storage()):O(u,q,A);throw new RangeError("Matrix must be square (size: "+D1(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(l)+")")}},any:function(u){return r(1,u)}});function O(s,u,l){var q,A,h,d,m;if(u===1){if(d=s[0][0],d===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,d)]]}else if(u===2){var _=z(s);if(_===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(s[1][1],_),r(b(s[0][1]),_)],[r(b(s[1][0]),_),r(s[0][0],_)]]}else{var R=s.concat();for(q=0;q<u;q++)R[q]=R[q].concat();for(var g=i(u).valueOf(),L=0;L<l;L++){var y=c(R[L][L]),D=L;for(q=L+1;q<u;)c(R[q][L])>y&&(y=c(R[q][L]),D=q),q++;if(y===0)throw Error("Cannot calculate inverse, determinant is zero");q=D,q!==L&&(m=R[L],R[L]=R[q],R[q]=m,m=g[L],g[L]=g[q],g[q]=m);var T=R[L],N=g[L];for(q=0;q<u;q++){var w=R[q],E=g[q];if(q!==L){if(w[L]!==0){for(h=r(b(w[L]),T[L]),A=L;A<l;A++)w[A]=M(w[A],n(h,T[A]));for(A=0;A<l;A++)E[A]=M(E[A],n(h,N[A]))}}else{for(h=T[L],A=L;A<l;A++)w[A]=r(w[A],h);for(A=0;A<l;A++)E[A]=r(E[A],h)}}}return g}}}),i3="pinv",a6=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],s6=h0(i3,a6,o=>{var{typed:e,matrix:t,inv:r,deepEqual:M,equal:n,dotDivide:b,dot:z,ctranspose:i,divideScalar:c,multiply:O,add:s,Complex:u}=o;return e(i3,{"Array | Matrix":function(_){var R=P1(_)?_.size():o2(_);switch(R.length){case 1:return d(_)?i(_):R[0]===1?r(_):b(i(_),z(_,_));case 2:{if(d(_))return i(_);var g=R[0],L=R[1];if(g===L)try{return r(_)}catch(y){if(!(y instanceof Error&&y.message.match(/Cannot calculate inverse, determinant is zero/)))throw y}return P1(_)?t(l(_.valueOf(),g,L),_.storage()):l(_,g,L)}default:throw new RangeError("Matrix must be two dimensional (size: "+D1(R)+")")}},any:function(_){return n(_,0)?g1(_):c(1,_)}});function l(m,_,R){var{C:g,F:L}=A(m,_,R),y=O(r(O(i(g),g)),i(g)),D=O(i(L),r(O(L,i(L))));return O(D,y)}function q(m,_,R){for(var g=g1(m),L=0,y=0;y<_;y++){if(R<=L)return g;for(var D=y;h(g[D][L]);)if(D++,_===D&&(D=y,L++,R===L))return g;[g[D],g[y]]=[g[y],g[D]];for(var T=g[y][L],N=0;N<R;N++)g[y][N]=b(g[y][N],T);for(var w=0;w<_;w++)if(w!==y){T=g[w][L];for(var E=0;E<R;E++)g[w][E]=s(g[w][E],O(-1,O(T,g[y][E])))}L++}return g}function A(m,_,R){var g=q(m,_,R),L=m.map((D,T)=>D.filter((N,w)=>w<_&&!h(z(g[w],g[w])))),y=g.filter((D,T)=>!h(z(g[T],g[T])));return{C:L,F:y}}function h(m){return n(s(m,u(1,1)),s(0,u(1,1)))}function d(m){return M(s(m,u(1,1)),s(O(m,0),u(1,1)))}}),O6="divide",u6=["typed","matrix","multiply","equalScalar","divideScalar","inv"],A6=h0(O6,u6,o=>{var{typed:e,matrix:t,multiply:r,equalScalar:M,divideScalar:n,inv:b}=o,z=zp({typed:e,equalScalar:M}),i=ip({typed:e});return e("divide",yc({"Array | Matrix, Array | Matrix":function(O,s){return r(O,b(s))},"DenseMatrix, any":function(O,s){return i(O,s,n,!1)},"SparseMatrix, any":function(O,s){return z(O,s,n,!1)},"Array, any":function(O,s){return i(t(O),s,n,!1).valueOf()},"any, Array | Matrix":function(O,s){return r(O,b(s))}},n.signatures))}),c3="sum",f6=["typed","config","add","numeric"],l6=h0(c3,f6,o=>{var{typed:e,config:t,add:r,numeric:M}=o;return e(c3,{"Array | Matrix":n,"Array | Matrix, number | BigNumber":b,"...":function(i){if(Bo(i))throw new TypeError("Scalar values expected in function sum");return n(i)}});function n(z){var i;return dM(z,function(c){try{i=i===void 0?c:r(i,c)}catch(O){throw Lt(O,"sum",c)}}),i===void 0&&(i=M(0,t.number)),typeof i=="string"&&(i=M(i,t.number)),i}function b(z,i){try{var c=pp(z,i,r);return c}catch(O){throw Lt(O,"sum")}}}),a3="median",d6=["typed","add","divide","compare","partitionSelect"],q6=h0(a3,d6,o=>{var{typed:e,add:t,divide:r,compare:M,partitionSelect:n}=o;function b(c){try{c=Qb(c.valueOf());var O=c.length;if(O===0)throw new Error("Cannot calculate median of an empty array");if(O%2===0){for(var s=O/2-1,u=n(c,s+1),l=c[s],q=0;q<s;++q)M(c[q],l)>0&&(l=c[q]);return i(l,u)}else{var A=n(c,(O-1)/2);return z(A)}}catch(h){throw Lt(h,"median")}}var z=e({"number | BigNumber | Complex | Unit":function(O){return O}}),i=e({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(O,s){return r(t(O,s),2)}});return e(a3,{"Array | Matrix":b,"Array | Matrix, number | BigNumber":function(O,s){throw new Error("median(A, dim) is not yet supported")},"...":function(O){if(Bo(O))throw new TypeError("Scalar values expected in function median");return b(O)}})}),Po=h5({config:U2}),cp=g5({}),ap=N5({}),sp=w5({}),xe=E5({Matrix:sp}),x0=mq({BigNumber:Po,Complex:cp,DenseMatrix:xe,Fraction:ap}),h6=sh({typed:x0}),ko=uh({typed:x0}),W6=Mh({BigNumber:Po,typed:x0}),s3=tW({typed:x0}),Nt=H5({config:U2,typed:x0}),$o=x5({typed:x0}),_6=P5({typed:x0}),Uo=Yh({typed:x0}),O3=eh({typed:x0}),Op=V5({Matrix:sp,equalScalar:Nt,typed:x0}),u3=fh({typed:x0}),A3=$5({typed:x0}),up=ch({typed:x0}),f3=bh({Fraction:ap,typed:x0}),l3=F5({typed:x0}),n2=zh({DenseMatrix:xe,Matrix:sp,SparseMatrix:Op,typed:x0}),d3=_W({isNaN:A3,isNumeric:l3,typed:x0}),qM=LW({bignumber:W6,fraction:f3,number:O3}),m6=gW({config:U2,multiplyScalar:Uo,numeric:qM,typed:x0}),g6=uW({isInteger:$o,matrix:n2,typed:x0}),q3=fW({matrix:n2,config:U2,typed:x0}),h3=dW({matrix:n2,typed:x0}),Vt=MW({isInteger:$o,matrix:n2,typed:x0}),R6=nW({prod:m6,size:q3,typed:x0}),v6=hW({conj:s3,transpose:h3,typed:x0}),hM=yW({numeric:qM,typed:x0}),L6=XW({DenseMatrix:xe,concat:Vt,divideScalar:hM,equalScalar:Nt,matrix:n2,typed:x0}),W3=SW({DenseMatrix:xe,concat:Vt,equalScalar:Nt,matrix:n2,typed:x0}),_3=pW({BigNumber:Po,DenseMatrix:xe,SparseMatrix:Op,config:U2,matrix:n2,typed:x0}),N6=iW({matrix:n2,multiplyScalar:Uo,typed:x0}),y6=PW({DenseMatrix:xe,concat:Vt,config:U2,matrix:n2,typed:x0}),B6=Jh({DenseMatrix:xe,concat:Vt,equalScalar:Nt,matrix:n2,subtractScalar:u3,typed:x0,unaryMinus:up}),WM=t6({DenseMatrix:xe,SparseMatrix:Op,addScalar:ko,concat:Vt,equalScalar:Nt,matrix:n2,typed:x0}),m3=TW({BigNumber:Po,DenseMatrix:xe,Fraction:ap,concat:Vt,config:U2,equalScalar:Nt,matrix:n2,typed:x0}),w6=YW({equal:W3,typed:x0}),g3=M6({addScalar:ko,conj:s3,multiplyScalar:Uo,size:q3,typed:x0}),D6=UW({DenseMatrix:xe,concat:Vt,config:U2,matrix:n2,typed:x0}),Ap=ZW({config:U2,numeric:qM,smaller:y6,typed:x0}),Dr=Vh({addScalar:ko,dot:g3,equalScalar:Nt,matrix:n2,multiplyScalar:Uo,typed:x0}),X6=VW({compare:m3,isNaN:A3,isNumeric:l3,typed:x0}),E6=l6({add:WM,config:U2,numeric:qM,typed:x0}),T6=b6({add:WM,matrix:n2,typed:x0}),R3=z6({divideScalar:hM,isZero:_6,matrix:n2,multiply:Dr,subtractScalar:u3,typed:x0,unaryMinus:up}),C6=JW({config:U2,larger:D6,numeric:qM,typed:x0}),jo=c6({abs:h6,addScalar:ko,det:R3,divideScalar:hM,identity:_3,matrix:n2,multiply:Dr,typed:x0,unaryMinus:up}),x6=s6({Complex:cp,add:WM,ctranspose:v6,deepEqual:w6,divideScalar:hM,dot:g3,dotDivide:L6,equal:W3,inv:jo,matrix:n2,multiply:Dr,typed:x0}),S6=wW({Complex:cp,config:U2,fraction:f3,identity:_3,inv:jo,matrix:n2,multiply:Dr,number:O3,typed:x0}),F6=A6({divideScalar:hM,equalScalar:Nt,inv:jo,matrix:n2,multiply:Dr,typed:x0}),v3=q6({add:WM,compare:m3,divide:F6,partitionSelect:X6,typed:x0});class I6{constructor(e,t,r){C(this,"_cacheData");C(this,"_variables");C(this,"_math");C(this,"_timeframe");this._cacheData={},this._variables=e,this._math=t,this._timeframe=r}get _taCacheData(){return this._cacheData}set _taCacheData(e){this._cacheData=e}alma({series:e,length:t,offset:r,sigma:M,floor:n,isSeriesLen:b},z){if(t===void 0||r===void 0||M===void 0)return;const i=this._cacheDataList(e,t,`alma_${z}`,b);if(i===void 0)return;let c=r*(t-1);n&&(c=Math.floor(c));const O=t/M;let s=0,u=0;for(let l=0;l<=t-1;l++){const q=Math.exp(-1*Math.pow(l-c,2)/(2*Math.pow(O,2)));s+=q,u+=i[i.length-1-(t-l-1)]*q}return u/s}sma({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;let n=0;const b=this._cacheDataList(e,t,`sma_${M}`,r);if(b===void 0)return;const z=b.slice(-t);return n=E6(...z)/t,n}rma({source:e,length:t,isSeriesLen:r},M){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`rma_${M}`);if(n)return n==null?void 0:n.sum;const{sum:b}=this._getCacheData(`rma_${M}`),z=1/t,i=this.sma({source:e,length:t,isSeriesLen:r},M),c=b===void 0?i:z*e+(1-z)*(b||0);return this._cacheDataHandle(`rma_${M}`,{sum:c}),c}atr({length:e,isSeriesLen:t},r){const M=this._verifyCacheData(`atr_${r}`);if(M)return M==null?void 0:M.value;const{high:n,close:b}=this._getCacheData(`atr_${r}`),{high:z,close:i,low:c}=this._variables,O=n===void 0?z-c:Math.max(Math.max(z-c,Math.abs(z-b)),Math.abs(c-b)),s=this.rma({source:O,length:e,isSeriesLen:t},r);return this._cacheDataHandle(`atr_${r}`,{high:z,close:i,value:s}),s}barssince({condition:e},t){const r=this._verifyCacheData(`barssince_${t}`);if(r)return r==null?void 0:r.count;let{count:M}=this._getCacheData(`barssince_${t}`);if(e)M=0;else{if(M===void 0)return;M+=1}return this._cacheDataHandle(`barssince_${t}`,{count:M}),M}stdev({source:e,length:t,biased:r=!0,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0)return;const b=this._cacheDataList(e,t,`stdev_${n}`,M),z=this.sma({source:e,length:t,isSeriesLen:M},n);if(b===void 0)return;let i=0;for(let c=0;c<t;c++){const O=this._sum(b[b.length-1-c],-(z||0));i+=O*O}return r||t<=1?Math.sqrt(i/t):Math.sqrt(i/(t-1))}_sum(e,t){let M=e+t;return Math.abs(M)<=1e-10&&(M=0),M}bb({series:e,length:t,mult:r,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return[];const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this.stdev({source:e,length:t,isSeriesLen:M},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:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this.stdev({source:e,length:t,isSeriesLen:M},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},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},M),b=this.dev({source:e,length:t,isSeriesLen:r},M);if(!(n===void 0||b===void 0))return(e-n)/(.015*b)}change({source:e,length:t=1,isSeriesLen:r},M){const n=this._cacheDataList(e,t,`change_${M}`,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 M=this.change({source:e},r);if(M===void 0)return;const n=this._math.sum({source:M>=0?M:0,length:t},`sm1_${r}`),b=this._math.sum({source:M>=0?0:-M,length:t},`sm2_${r}`);if(!(n===void 0||b===void 0))return 100*(n-b)/(n+b)}cog({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this._cacheDataList(e,t,`cog_${M}`,r),b=this._math.sum({source:e,length:t},M);if(b===void 0||n===void 0)return;let z=0;for(let i=0;i<t;i++){const c=n[n.length-1-i];z+=c*(i+1)}return-z/b}correlation({source1:e,source2:t,length:r,isSeriesLen:M},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}`,M),z=this.sma({source:e,length:r,isSeriesLen:M},`sma1_${n}`),i=this.sma({source:t,length:r,isSeriesLen:M},`sma2_${n}`);if(z===void 0||i===void 0||b===void 0)return;let c=0,O=0,s=0;for(let l=0;l<r;l++){const[q,A]=b[b.length-1-l],h=q-z,d=A-i;c+=h*d,O+=h*h,s+=d*d}return isNaN(O)||isNaN(c)||isNaN(s)?void 0:c/Math.sqrt(O*s)}cross({source1:e,source2:t},r){if(e===void 0||t===void 0)return!1;const M=this._verifyCacheData(`cross_${r}`);if(M)return M==null?void 0:M.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 M=this._verifyCacheData(`crossover_${r}`);if(M)return M==null?void 0:M.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 M=this._verifyCacheData(`crossunder_${r}`);if(M)return M==null?void 0:M.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:M}=this._getCacheData(`cum_${t}`);return M=M||0,M+=e,this._cacheDataHandle(`cum_${t}`,{sum:M}),M}dev({source:e,length:t,isSeriesLen:r},M){if(e===void 0||isNaN(e)||t===void 0)return;const n=this.sma({source:e,length:t,isSeriesLen:r},M);let b=0;const z=this._cacheDataList(e,t,`dev_${M}`,r);if(!(!z||n===void 0)){for(let i=0;i<t;i++){const c=z[z.length-1-i];b+=Math.abs(c-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 M=`dmi_${r}`,n=this._verifyCacheData(M);if(n)return n==null?void 0:n.value;const{low:b,high:z,close:i,PDMS:c,NDMS:O,TRS:s,ADX:u,count:l=0}=this._getCacheData(M),{low:q,high:A,close:h}=this._variables;if(b===void 0||z===void 0||i===void 0)return this._cacheData[M]={low:q,high:A,close:h,PDMS:c,NDMS:O,TRS:A-q,count:1},[void 0,void 0,void 0];let d=A-z,m=b-q;d=d>m&&d>0?d:0,m=m>d&&m>0?m:0,d===m&&(d=m=0);const _=Math.max(A-q,Math.abs(A-i),Math.abs(q-i));let R={};if(l<e)R={low:q,high:A,close:h,PDMS:(c||0)+d,NDMS:(O||0)+m,TRS:(s||0)+_,count:l+1,value:[void 0,void 0,void 0]};else{const g=c-c/e+d,L=O-O/e+m,y=s-s/e+_,D=g/y*100,T=L/y*100,N=Math.abs((D-T)/(D+T))*100;let w=N,E=[D,T,void 0];if(l+1-e<t){const P=l+1-e;w=((u||0)*(P-1)+N)/P}else w=(u*(t-1)+N)/t,E=[D,T,w];R={low:q,high:A,close:h,PDMS:g,NDMS:L,TRS:y,ADX:w,count:l+1,value:E}}return this._cacheDataHandle(M,R),R.value}ema({source:e,length:t,isSeriesLen:r},M){if(e===void 0||t===void 0||isNaN(e))return;const n=this._verifyCacheData(`ema_${M}`);if(n)return n==null?void 0:n.sum;let{sum:b,count:z=1}=this._getCacheData(`ema_${M}`);const i=this.sma({source:e,length:t,isSeriesLen:r},M);if(z>t){const c=2/(t+1);b=b===void 0?e:c*e+(1-c)*(b||0)}else b=i;return z+=1,this._cacheDataHandle(`ema_${M}`,{sum:b,count:z}),b}falling({source:e,length:t},r){if(e===void 0||isNaN(e)||t===void 0)return!1;const M=this._verifyCacheData(`falling_${r}`);if(M)return M==null?void 0:M.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(c=>c),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 M=this._verifyCacheData(`rising_${r}`);if(M)return M==null?void 0:M.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(c=>c),this._cacheDataHandle(`rising_${r}`,{source:e,risings:z,value:i}),i}highest({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highest_${M}`,r,!1,!0);if(b!=null&&b.length)return Math.max(...b.slice(-t))}highestbars({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{high:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`highestbars_${M}`,r);return b?b.slice(-t).reduce((i,c,O,s)=>c>=s[i]?O:i,0)-t+1:void 0}wma({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`wma_${M}`,r);if(!n)return;let b=0,z=0;for(let i=0;i<t;i++){const c=(t-i)*t;b+=c,z+=n[n.length-1-i]*c}return z/b}hma({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this.wma({source:e,length:t,isSeriesLen:r},M),b=this.wma({source:e,length:Math.round(t/2),isSeriesLen:r},`half_${M}`);return n===void 0||b===void 0?void 0:this.wma({source:2*b-n,length:Math.floor(Math.sqrt(t)),isSeriesLen:r},`hma_${M}`)}kc({series:e,length:t,mult:r,useTrueRange:M=!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:c,low:O}=this._variables,s=M?i.tr:c-O,u=this.ema({source:s,length:t,isSeriesLen:n},`range_${b}`);return[z,z+u*r,z-u*r]}kcw({series:e,length:t,mult:r,useTrueRange:M=!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:c,low:O}=this._variables,s=M?i.tr:c-O,u=this.ema({source:s,length:t,isSeriesLen:n},`range_${b}`);return(z+u*r-(z-u*r))/z}linreg({source:e,length:t,offset:r,isSeriesLen:M},n){if(t===void 0||r===void 0)return;const b=this._cacheDataList(e,t,`dev_${n}`,M);if(!b)return;const z=b.slice(-t).filter(q=>q!==void 0);let i=0,c=0,O=0,s=0;for(const[q,A]of z.entries())i+=q,c+=A,O+=q*A,s+=q*q;const u=(t*O-i*c)/(t*s-i*i);return(c-u*i)/t+u*(t-1-r)}lowest({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowest_${M}`,r,!1,!0);if(b!=null&&b.length)return Math.min(...b.slice(-t))}lowestbars({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<=0)return;const{low:n}=this._variables,b=this._cacheDataList(typeof e!="number"?n:e,t,`lowestbars_${M}`,r);return b?b.slice(-t).reduce((i,c,O,s)=>c<=s[i]?O:i,0)-t+1:void 0}macd({source:e,fastlen:t,slowlen:r,siglen:M},n){if(e===void 0||isNaN(e)||t===void 0||r===void 0||M===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,c=this.ema({source:i,length:M},`macd_${n}`);if(c===void 0)return[i,c,void 0];const O=i-c;return[i,c,O]}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},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`dev_${M}`,r);if(n)return v3(n.slice(-t))}mfi({series:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const{volume:M}=this._variables,n=this.change({source:e},r),b=this._math.sum({source:M*(n>=0?0:e),length:t},`lower_${r}`),z=this._math.sum({source:M*(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},M){if(t===void 0||e===void 0||isNaN(e)||t<=0)return;const n=this._cacheDataList(e,t,`mode_${M}`,r);if(n)return Ap(d3(n.slice(-t)))}mom({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<0)return;const n=`mom_${M}`,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:M},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}`,M);if(!b)return;const z=this._sort(b.slice(-t)),i=z.length;r/=100;const c=1/(i*2);if(r<=c)return z[0];if(r>=1-1/(i*2))return z[i-1];for(const[O,s]of z.entries()){const u=z[O-1];if(r<(O+.5)/i)return u===void 0||s===void 0?void 0:u+(s-u)*(r-(O-.5)/i)/(1/i)}}percentile_nearest_rank({source:e,length:t,percentage:r,isSeriesLen:M},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}`,M);if(!b)return;const z=this._sort(b.slice(-t)),i=r/100*z.length,c=Math.ceil(i)-1;return z[c>=z.length?z.length-1:c]}percentrank({source:e,length:t,isSeriesLen:r},M){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`percentile_nearest_rank_${M}`,r);if(!n)return;const b=n.slice(-(t+1)),z=e;if(z===void 0)return;let i=0;for(let c=0;c<b.length;c++)b[c]!==void 0&&(b[c]<z||b[c]===z&&c<t)&&i++;return i/(b.length-1)*100}pivot_point_levels({type:e,anchor:t,developing:r},M){const n=p1(0,void 0,N0.FLOAT);let{close:b,open:z,low:i,high:c}=this._variables;const O=`pivot_point_levels_${M}`,s=this._verifyCacheData(O);if(s)return n._value=(s==null?void 0:s.result)||[],n;const{close:u,low:l,high:q,open:A,result:h}=this._getCacheData(O);if(!t&&(q&&l&&(c=Math.max(q,c),i=Math.min(l,i)),this._cacheDataHandle(O,{close:b,open:z,low:i,high:c,result:h}),!r))return n._value=h||[],n;const d={close:b,open:z,low:i,high:c};t===!0&&!r&&(b=u,z=A,i=l,c=q);const m=this._getPivotPointLevels(c,i,b,z,r,e);return this._cacheDataHandle(O,{...d,result:m}),n._value=m,n}_getPivotPointLevels(e,t,r,M,n,b){if(r===void 0||M===void 0||t===void 0||e===void 0)return[];switch(b){case Pt.traditional:return this._traditional(e,t,r);case Pt.fibonacci:return this._fibonacci(e,t,r);case Pt.woodie:return n?[]:this._woodie(e,t);case Pt.classic:return this._classic(e,t,r);case Pt.dm:return this._DM(e,t,r,M);case Pt.camarilla:return this._camarilla(e,t,r);default:return[]}}_traditional(e,t,r){const M=(e+t+r)/3,n=M*2-t,b=M+(e-t),z=M*2+(e-2*t),i=M*3+(e-3*t),c=M*4+(e-4*t),O=M*2-e,s=M-(e-t),u=M*2-(2*e-t),l=M*3-(3*e-t),q=M*4-(4*e-t);return[M,n,O,b,s,z,u,i,l,c,q]}_fibonacci(e,t,r){const M=(e+t+r)/3,n=M+.382*(e-t),b=M-.382*(e-t),z=M+.618*(e-t),i=M-.618*(e-t),c=M+(e-t),O=M-(e-t);return[M,n,b,z,i,c,O]}_woodie(e,t){const{open:r}=this._variables,M=(e+t+2*r)/4,n=2*M-t,b=2*M-e,z=M+(e-t),i=M-(e-t),c=e+2*(M-t),O=t-2*(e-M),s=c+(e-t),u=O-(e-t);return[M,n,b,z,i,c,O,s,u]}_classic(e,t,r){const M=(e+t+r)/3,n=2*M-t,b=2*M-e,z=M+(e-t),i=M-(e-t),c=M+2*(e-t),O=M-2*(e-t),s=M+3*(e-t),u=M-3*(e-t);return[M,n,b,z,i,c,O,s,u]}_DM(e,t,r,M){let n;M===r?n=e+t+2*r:r>M?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 M=(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,c=r+1.1*(e-t)/4,O=r-1.1*(e-t)/4,s=r+1.1*(e-t)/2,u=r-1.1*(e-t)/2,l=e/t*r,q=r-(l-r);return[M,n,b,z,i,c,O,s,u,l,q]}pivothigh(e,t){const{leftbars:r,rightbars:M}=e;if(r===void 0||M===void 0||r<0||M<0)return;let n=this._variables.high;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+M+1,`pivothigh_${t}`);if(!b)return;const z=b.slice(-(r+M+1)),i=z[r],c=z.splice(0,r+1),O=Math.max(...z),s=Math.max(...c);return i>=s&&i>O?i:void 0}pivotlow(e,t){const{leftbars:r,rightbars:M}=e;if(r===void 0||M===void 0||r<0||M<0)return;let n=this._variables.low;e.hasOwnProperty("source")&&(n=e.source);const b=this._cacheDataList(n,r+M+1,`pivotlow_${t}`);if(!b)return;const z=b.slice(-(r+M+1)),i=z[r],c=z.splice(0,r+1),O=Math.min(...z),s=Math.min(...c);return i<=s&&i<O?i:void 0}range({source:e,length:t},r){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const M=this._cacheDataList(e,t,`range_${r}`,!0);if(!M)return;const n=M.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},M){if(t===void 0||t<0)return;const n=this._cacheDataList(e,t+1,`roc_${M}`,r),b=this.change({source:e,length:t,isSeriesLen:r},M);if(n)return 100*b/n[n.length-1-t]}rsi({source:e,length:t,isSeriesLen:r},M){if(t===void 0||e===void 0||isNaN(e)||t<0)return;const n=this._verifyCacheData(`rsi_${M}`);if(n)return n==null?void 0:n.value;const{source:b}=this._getCacheData(`rsi_${M}`),z=Math.max(e-b,0),i=Math.max(b-e,0),c=this.rma({source:z,length:t,isSeriesLen:r},`rma1_${M}`),O=this.rma({source:i,length:t,isSeriesLen:r},`rma2_${M}`),s=c===void 0||O===void 0?void 0:100-100/(1+c/O);return this._cacheDataHandle(`rsi_${M}`,{source:e,value:s}),s}sar({start:e,inc:t,max:r},M){if(e===void 0||t===void 0||r===void 0)return;const n=this._verifyCacheData(`sar_${M}`);if(n)return n==null?void 0:n.result;const{close:b,low:z,high:i,preLow:c,preHigh:O,data:s={}}=this._getCacheData(`sar_${M}`);let{result:u,maxMin:l,acceleration:q,isBelow:A}=s,h=!1;const{close:d,low:m,high:_,bar_index:R}=this._variables;return R===1&&(d>b?(A=!0,l=_,u=z):(A=!1,l=m,u=i),h=!0,q=e),u=u+q*(l-u),A?u>m&&(h=!0,A=!1,u=Math.max(_,l||0),l=m,q=e):u<_&&(h=!0,A=!0,u=Math.min(m,l||0),l=_,q=e),h||(A?_>(l||0)&&(l=_,q=Math.min((q||0)+t,r)):m<(l||0)&&(l=m,q=Math.min((q||0)+t,r))),A?(u=Math.min(u,z),R>1&&(u=Math.min(u,c))):(u=Math.max(u,i),R>1&&(u=Math.max(u,O))),this._cacheDataHandle(`sar_${M}`,{high:_,close:d,low:m,preLow:z,preHigh:i,data:Object.assign(s,{result:u,maxMin:l,acceleration:q,isBelow:A})}),u}stoch({source:e,high:t,low:r,length:M,isSeriesLen:n},b){if(M===void 0||t===void 0||r===void 0||e===void 0||isNaN(e)||M<0)return;const z=this.lowest({source:r,length:M,isSeriesLen:n},b),i=this.highest({source:t,length:M,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 M=`supertrend_${r}`,n=this._verifyCacheData(M);if(n)return n==null?void 0:n.value;let b=1;const{hl2:z,close:i}=this._variables,{upperBand:c,lowerBand:O,superTrend:s,atr:u,close:l}=this._getCacheData(M),q=this.atr({length:t},r);if(q===void 0)return this._cacheDataHandle(M,{close:i,value:[void 0,b]}),[void 0,b];let A=z+e*q,h=z-e*q;const d=c||0,m=O||0;h=h>m||l<m?h:m,A=A<d||l>d?A:d,u===void 0?b=1:s===d?b=i>A?-1:1:b=i<h?1:-1;const _=b===-1?h:A;return this._cacheDataHandle(M,{upperBand:A,lowerBand:h,superTrend:_,atr:q,close:i,value:[_,b]}),[_,b]}swma({source:e},t){const r=this._verifyCacheData(`swma_${t}`);if(r)return r==null?void 0:r.value;let{list:M}=this._getCacheData(`swma_${t}`);M||(M=[]),M.push(e),M=M.slice(-4);const n=M.filter(b=>b!==void 0).length<4?void 0:M[3]*1/6+M[2]*2/6+M[1]*2/6+M[0]*1/6;return this._cacheDataHandle(`swma_${t}`,{list:M,value:n}),n}tr({handle_na:e=!1},t){const{close:r,low:M,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-M:void 0:i=Math.max(n-M,Math.abs(n-z),Math.abs(M-z)),this._cacheDataHandle(`tr_${t}`,{close:r,value:i}),i}tsi({source:e,short_length:t,long_length:r},M){if(e===void 0||isNaN(e)||t===void 0||r===void 0)return;const n=this.change({source:e},M);if(n===void 0)return;const b=this._doubleSmooth(n,r,t,M),z=this._doubleSmooth(Math.abs(n),r,t,`abs_${M}`);if(!(z===void 0||b===void 0))return b/z}_doubleSmooth(e,t,r,M){const n=this.ema({source:e,length:t},`ema1_${M}`);return this.ema({source:n,length:r},`ema2_${M}`)}valuewhen({condition:e,source:t,occurrence:r},M){if(r===void 0||r<0)return;let{list:n}=this._getCacheData(`valuewhen_${M}`);n||(n=[]),e&&n.push(t);const b=n[n.length-1-r];return this._cacheDataHandle(`valuewhen_${M}`,{list:n,value:b}),b}variance({source:e,length:t,biased:r=!0,isSeriesLen:M},n){if(e===void 0||isNaN(e)||t===void 0||t<0)return;const b=this.sma({source:e,length:t,isSeriesLen:M},n),z=this._cacheDataList(e,t,`variance_${n}`,!0);if(!z||b===void 0)return;const i=z.filter(O=>O!==void 0&&!isNaN(O)).slice(-t);if(i.length<t)return;const c=i.reduce((O,s)=>O+Math.pow(s-b,2),0);if(c!==void 0)return r||t<=1?c/t:c/(t-1)}vwap({source:e,anchor:t,stdev_mult:r},M){if(e===void 0)return;const n=`vwap_${M}`,b=this._verifyCacheData(n);if(b)return b==null?void 0:b.value;t=t===void 0?this._timeframe.change({timeframe:"1D"},M):t;const{volume:z}=this._variables;let{sum:i=0,sumV:c=0,count:O=0,isReset:s,sumS:u=0}=this._getCacheData(n);if(t&&(i=c=O=u=0,s=!0),!s)return r!==void 0?[]:void 0;const l=e*z+i,q=z+c,A=l/q;if(O++,r!==void 0){u=z*Math.pow(e,2)+u;const h=this._computeBands(u,q,r,A);return this._cacheDataHandle(n,{sum:l,sumV:q,count:O,isReset:s,sumS:u,value:h}),h}return this._cacheDataHandle(n,{sum:l,sumV:q,count:O,isReset:s,value:A}),A}_computeBands(e,t,r,M){let n=e/t-Math.pow(M,2);n=n<0?0:n;const b=Math.sqrt(n),z=b!==void 0&&!isNaN(b)?M+r*b:void 0,i=b!==void 0&&!isNaN(b)?M-r*b:void 0;return[M,z,i]}vwma({source:e,length:t,isSeriesLen:r},M){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_${M}`),z=this.sma({source:n,length:t,isSeriesLen:r},`sma2_${M}`);if(!(b===void 0||z===void 0))return b/z}wpr({length:e,isSeriesLen:t},r){if(e===void 0||e<=0)return;const M=this.highest({length:e,isSeriesLen:t},r),n=this.lowest({length:e,isSeriesLen:t},r),{close:b}=this._variables;if(!(M===void 0||n===void 0))return(M-b)/(M-n)*-100}_sort(e){const t=[];for(const r of e){if(typeof r=="number")break;t.push(r)}return e.sort((r,M)=>r-M),t.concat(e)}_cacheDataList(e,t,r,M=!1,n=!0,b=!1){const z=this._cacheData[r]||{barIndex:-1,list:[],length:t},{bar_index:i}=this._variables;if(z.length<t&&(z.length=t),z.barIndex<=i&&!(isNaN(e)&&b)){const c=z.list.length;if(z.barIndex===i)z.list[c-1]=e;else{let O=i-z.barIndex-1;if(z.barIndex!==-1&&O>0){const s=z.list[c-1];for(;O>0;)z.list.push(s),O--}z.list.push(e)}z.barIndex=i,z.list.length>z.length+5&&!M&&z.list.shift(),this._cacheData[r]=z}if(!(z.list.length<t&&n))return z.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:M,_isRepeated:n}=this._variables;if(!M&&!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,M=this._cacheData[e]||{},{barIndex:n}=M;if(n===t&&r)return M}}class P6{constructor(e,t,r){C(this,"_cacheData");C(this,"_variables");C(this,"_errorListener");C(this,"_historyInputs");C(this,"_name");C(this,"_newCacheData",{});this._cacheData={},this._variables=e,this._errorListener=t,this._name=`inputs_${r}`,this._historyInputs=self.workerStorage.get(this._name)||{}}get _inputCacheData(){return this._cacheData}set _inputCacheData(e){this._cacheData=e}update(e){if(!(e!=null&&e.length)){self.workerStorage.delete(this._name),this._cacheData={};return}for(const t of e){const r=t.id,M=this._historyInputs[r];(!(t!=null&&t.sourceTypeName)&&(M==null?void 0:M.defval)!==t.defval||M!=null&&M.sourceTypeName&&t.sourceTypeName!==(M==null?void 0:M.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,N2.INT)}bool(e,t){return this._cacheHandle(e,t,N2.BOOL)}color(e,t){return this._cacheHandle(e,t,N2.COLOR)}time(e,t){return this._cacheHandle(e,t,N2.TIME)}float(e,t){return this._verifyMaxOrMin(e,t),this._cacheHandle(e,t,N2.FLOAT)}price(e,t){return this._cacheHandle(e,t,N2.PRICE)}source(e,t){return this._cacheHandle(e,t,N2.SOURCE)}string(e,t){return this._cacheHandle(e,t,N2.STRING)}symbol(e,t){return this._cacheHandle(e,t,N2.SYMBOL)}session(e,t){return this._cacheHandle(e,t,N2.SESSION)}text_area(e,t){return this._cacheHandle(e,t,N2.TEXT_AREA)}timeframe(e,t){return this._cacheHandle(e,t,N2.TIMEFRAME)}enum(e,t){return this._cacheHandle(e,t,N2.ENUM)}_cacheHandle(e,t,r){if(t.startsWith("export"))return e.defval;const M=`${r||"input"}_${t}`,n=this._newCacheData[M]||this._cacheData[M];if(this._variables.bar_index&&n)return n.sourceTypeName&&(n.defval=this._variables[n.sourceTypeName]),n.defval;if(e.defval===void 0&&this._errorListener.addError(N1.inputDefvalErr,t,K0.Error),n)if(!n.isModify)Object.assign(this._newCacheData[M],e);else{this._newCacheData[M]=n;const b=this._historyInputs[M];!(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._newCacheData[M].defval=this._variables[n.sourceTypeName]):Object.assign(this._newCacheData[M],e)}else{const{defval:b,display:z}=e;if(this._displayVerify(t,z),e={inputType:r,...e},this._newCacheData[M]=e,(r||e.inputType)===N2.SOURCE)this._newCacheData[M].options=ui;else if(e.options)if(!e.options.includes(b))this._errorListener.addError(l2(N1.inputOptErr,{defval:String(b),args:e.options.toString()}),t,K0.Error,6+((r==null?void 0:r.length)||-1));else{const i=new Map;for(const c of e.options){if(i.has(c)){this._errorListener.addError(l2(N1.optionsRepeatErr,{option:String(c)}),t,K0.Error,6+((r==null?void 0:r.length)||-1));break}i.set(c,c)}}}return self.workerStorage.setValue(this._name,M,{...e}),this._newCacheData[M].defval}_displayVerify(e,t){!t||!t.length||t.includes(le.dataWindow)||t.includes(le.statusLine)||this._errorListener.addError(l2(N1.displayErr,{func:"input",values:"[display.none, display.data_window, display.status_line, display.all]"}),e,K0.Error)}_verifyMaxOrMin(e,t){const{defval:r,maxval:M,minval:n}=e;typeof r=="number"&&(M!==void 0&&r>M||n!==void 0&&r<n)&&this._errorListener.addError(N1.minOrMaxErr,t,K0.Error)}getInputs(){const e=Object.keys(this._newCacheData),t=[];for(const r of e){const M=this._newCacheData[r];M.id=r,t.push(M)}return this._cacheData=this._newCacheData,t.sort((r,M)=>(r.index||0)-(M.index||0))}}class k6{color({x:e}){return e===void 0?null:e}new({color:e,transp:t=100}){u0(t)&&(t=100);let r=(100-t)/100;r=r<0?0:r>1?1:r;const{r:M,g:n,b}=this._parseColor(e||"");return`rgba(${Math.round(M)}, ${Math.round(n)}, ${Math.round(b)}, ${r})`}rgb({red:e=0,green:t=0,blue:r=0,transp:M=0}){return u0(M)&&(M=0),u0(e)&&(e=0),u0(t)&&(t=0),u0(r)&&(r=0),`rgba(${e}, ${t}, ${r}, ${(100-M)/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:M,top_color:n}){if(u0(e)||u0(t)||u0(r)||r===t)return"rgba(0,0,0,1)";const b=(e-t)/(r-t),z=Math.min(Math.max(b,0),1);if(!M&&!n)return"rgba(0,0,0,0)";let{r:i,g:c,b:O,a:s}=M?this._parseColor(M):{},{r:u,g:l,b:q,a:A}=n?this._parseColor(n):{};M?n||(u=i,l=c,q=O,A=0):(i=u,c=l,O=q,s=0);const h=i+z*(u-i),d=c+z*(l-c),m=O+z*(q-O),_=s+z*(A-s);return`rgba(${Math.round(h)}, ${Math.round(d)}, ${Math.round(m)}, ${_.toFixed(2)})`}_parseColor(e){let t,r,M,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),M=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,M=b[2]||0,n=b[3],n=n===void 0?1:n}return{r:t,g:r,b:M,a:n}}_parserRgbColor(e){var t;return((t=e.match(/[\d.]+/g))==null?void 0:t.map(Number))||[]}}var t1={};const $6=Object.prototype.toString;function _M(o){const e=$6.call(o);return e.endsWith("Array]")&&!e.includes("Big")}var U6=Object.freeze({__proto__:null,isAnyArray:_M}),j6=Y1(U6);function H6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!_M(o))throw new TypeError("input must be an array");if(o.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,M=e.toIndex,n=M===void 0?o.length:M;if(r<0||r>=o.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>o.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=o[r],z=r+1;z<n;z++)o[z]>b&&(b=o[z]);return b}function Y6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!_M(o))throw new TypeError("input must be an array");if(o.length===0)throw new TypeError("input must not be empty");var t=e.fromIndex,r=t===void 0?0:t,M=e.toIndex,n=M===void 0?o.length:M;if(r<0||r>=o.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=r||n>o.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var b=o[r],z=r+1;z<n;z++)o[z]<b&&(b=o[z]);return b}function G6(o){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(_M(o)){if(o.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(!_M(e.output))throw new TypeError("output option must be an array if specified");t=e.output}else t=new Array(o.length);var r=Y6(o),M=H6(o);if(r===M)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?M:1:z;if(b>=i)throw new RangeError("min option must be smaller than max option");for(var c=(i-b)/(M-r),O=0;O<o.length;O++)t[O]=(o[O]-r)*c+b;return t}var V6=Object.freeze({__proto__:null,default:G6}),K6=Y1(V6);Object.defineProperty(t1,"__esModule",{value:!0});var C2=j6,L3=K6;const Ho=" ".repeat(2),N3=" ".repeat(4);function J6(){return y3(this)}function y3(o,e={}){const{maxRows:t=15,maxColumns:r=10,maxNumSize:M=8,padMinus:n="auto"}=e;return`${o.constructor.name} {
|
69
69
|
${Ho}[
|
70
70
|
${N3}${Q6(o,t,r,M,n)}
|
71
71
|
${Ho}]
|
@@ -82,7 +82,7 @@ ${s.join(`
|
|
82
82
|
`)}
|
83
83
|
return ${b==null?void 0:b.code}`;q>1;)l=`${l}}`,q--;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,M){var R;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:c}=e;const{__period:O,time:s,_isRealTimeBar:u}=this._variables;b=uM(b);let l=y2(b,s)*1e3;const q=y2(O,s)*1e3;if(l>q)return!c&&this._errorListener.addError(l2(N1.requestLowerTfPeriodErr,{period:b}),t,K0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),d=self.workerStorage.get(`request_${this._scriptId}_list`),m=self.workerStorage.get(`request_${this._scriptId}_tmp`),_={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:Ai[b]||Ac(b)};if(h!=null&&h.has(A)){m==null||m.delete(A);const{index:g=0,periodStamp:L=q}=this._cacheData[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=s,w=L+N;const E=[];for(const[P,H]of T.entries()){let{time:Y}=H;Y=Y*1e3;let k=g+P;if(Y>=w)return!u&&(this._cacheData[r]={index:k,periodStamp:L}),E;if(N<=Y&&Y<w){const K=(R=H==null?void 0:H.result)==null?void 0:R[r];if(Array.isArray(K))for(const[e0,b0]of K.entries())E[e0]||(E[e0]=[]),E[e0].push(b0);else M||E.push(K)}}return!u&&(this._cacheData[r]={index:y.length,periodStamp:L}),E}else(d==null?void 0:d.get(A))||m==null||m.set(A,_);d==null||d.set(A,_)}_getRequestData(e,t){var m,_,R,g,L;let{symbol:r,timeframe:M,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:c,mintick:O,time:s,nextBarTime:u}=this._variables;M=uM(M),r=r;const l=`${r}--${M}`,q=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),d={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:M,timeframe:Ai[M]||Ac(M)};if(q!=null&&q.has(l)){let y=y2(M,s)*1e3;const D=y2(c,s)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=D}=this._cacheData[t]||{},w=q==null?void 0:q.get(l);if(!w.length)return;const E=w.slice(T);let P=s,H=N+P;const Y=w.length-1;if(Y<0)return;const k={lastBarIndex:w[Y].barindex||Y,lastBarTime:w[Y].time,interval:M,mintick:O};if(y>N){let K;if(z===ke.lookaheadOn?K=this._lookaheadOnHandle(E,M,H,y,k,T,N,t,P,b):K=this._lookaheadOffHandle(E,M,H,y,k,T,N,t,P,u||H,b),K)return K;if(K===null)return}else if(z===ke.lookaheadOn)for(const[K,e0]of E.entries()){let{time:b0,barindex:O0}=e0;b0=b0*1e3;const v0=((m=E[K+1])==null?void 0:m.time)*1e3||b0+y;let B0=T+K;if(b0>=H){this._cacheData[t]={index:B0,periodStamp:N};return}if(b0<=P&&v0>P){const A0=T+K;return this._cacheData[t]={index:A0,periodStamp:N},{...e0,barIndex:O0||A0,nextBarTime:(_=E[K+1])==null?void 0:_.time,...k}}}else for(const[K,e0]of E.entries()){let{time:b0,barindex:O0}=e0;b0=b0*1e3;const v0=((R=E[K+1])==null?void 0:R.time)*1e3||b0+y;let B0=T+K;if(b0>H){this._cacheData[t]={index:B0,periodStamp:N};return}if(b0<H&&H<=v0)return this._cacheData[t]={index:B0,periodStamp:N},{...e0,barIndex:O0||B0,nextBarTime:(g=E[K+1])==null?void 0:g.time,...k};if(b0>=P&&b0<=H&&(O0||B0)===k.lastBarIndex)return this._cacheData[t]={index:B0,periodStamp:N},{...e0,barIndex:O0||B0,nextBarTime:(L=E[K+1])==null?void 0:L.time,...k}}this._cacheData[t]={index:w.length,periodStamp:N};return}else(A==null?void 0:A.get(l))||h==null||h.set(l,d);A==null||A.set(l,d)}_lookaheadOnHandle(e,t,r,M,n,b,z,i,c,O){var s;for(const[u,l]of e.entries()){let{time:q,barindex:A}=l;q=q*1e3,t.includes("M")&&(M=y2(t,q)*1e3-(O1(q).date()-1)*864e5);const h=q,d=M+h;let m=b+u;if(r<=h)return this._cacheData[i]={index:m,periodStamp:z},null;let _={...l,barIndex:A||m,nextBarTime:(s=e[u+1])==null?void 0:s.time,...n};if(O===ke.gapsOn){if(r>h&&c<=h)return this._cacheData[i]={index:m,periodStamp:z},_}else{if(r>d)continue;if(r>h)return this._cacheData[i]={index:m,periodStamp:z},_}}}_lookaheadOffHandle(e,t,r,M,n,b,z,i,c,O,s){var u,l;for(const[q,A]of e.entries()){let{time:h,barindex:d}=A;h=h*1e3,t.includes("M")&&(M=y2(t,h)*1e3-(O1(h).date()-1)*864e5);const m=h,_=M+m,R=b+q;if(r<m)return this._cacheData[i]={index:R,periodStamp:z},null;const g={...A,barIndex:d||R,nextBarTime:(u=e[q+1])==null?void 0:u.time,...n};if(r>=_&&c<_||r<_&&O>=_)return s===ke.gapsOn?(this._cacheData[i]={index:R,periodStamp:z},g):(this._cacheData[i]={index:R,data:g,periodStamp:z},g);if(!(c>_)&&c>=m){let L=(l=this._cacheData[i])==null?void 0:l.data;if(!L){const y=e[R-1];if(!y)return null;L={...y,barIndex:y.barindex||R-1,nextBarTime:g.time,...n},this._cacheData[i]={index:R,data:L,periodStamp:z}}return L}}}_getDependCodes(e,t,r,M,n,b){for(const z of e){if(!z.isArg){const i=t.filter(O=>{var s;return(s=O==null?void 0:O.depends)==null?void 0:s.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const O of i){const{code:s,depends:u,scope:l,funcName:q}=O;r[l]=r[l]||[];const A=r[l];let h=l===0&&q;if(!A.includes(s)){if(h){if(M.includes(s))continue;M.unshift(s)}else A.unshift(s);if(u!=null&&u.length){for(const d of u)d.memberCode&&!h&&b.push(d.memberCode);this._getDependCodes(u,t,r,M,n,b)}}}const c=t.find(O=>{var s;return((s=O.varNames)==null?void 0:s.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&O.methodName===z.functionName)||O.funcName===z.name});if(c){const{code:O,depends:s,scope:u}=c;r[u]=r[u]||[];const l=r[u],q=l.findIndex(A=>A===O);if(q!==-1){if(z.isFunc)continue;l.splice(q,1)}if(l.unshift(O),s!=null&&s.length){for(const A of s)A.memberCode&&b.push(A.memberCode);this._getDependCodes(s,t,r,M,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,M,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:c,scope:O=0}=z;e[O]=e[O]||[];const s=e[O];if(!s.includes(i)&&(s.push(i),c!=null&&c.length)){for(const u of c)u.memberCode&&r.push(u.memberCode);this._getDependCodes(c.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,M,n,r)}}}runScripts(e,t,r,M,n,b){var u,l;const z=`${this._scriptId}_${t}`,i=new _p(z),c=new hp,O=new Wp(this._variables.mintick||1e-5,i,this._scriptId),s=new Function("_$_var","_$_const","_$_func","$paramsExpr","$posStr",e);if(!r){const{varCacheData:q,funcCacheData:A}=n;i.setVarCacheData(q),O.setFuncCacheData(A)}if(i.__requestName=t,M&&M.length){const q=M.length-1,{interval:A,symbol:h=""}=n;let{mintick:d,syminfo:m}=this._variables;const[_,R]=h.split(":");d||(d=Math.pow(10,-(((u=String(M[0].o).split(".")[1])==null?void 0:u.length)||0))),i.updateOptions({interval:A,mintick:d,syminfo:{...m.__syminfo,mintick:d,tickerid:h||m.tickerid,ticker:R||_||m.ticker}});for(const[y,D]of M.entries()){const{barindex:T}=D,N=Object.assign(D,{barIndex:T||y,lastBarIndex:M[q].barindex||q,lastBarTime:M[q].time,nextBarTime:(l=M[y+1])==null?void 0:l.time});if(i.updateData(N),O.update({barIndex:(N==null?void 0:N.barindex)||0}),D.result=Object.assign(D.result||{},{[t]:s(i,c,O,b||[],t)}),O.endExecution(),O.errors.length&&O.errors.some(w=>w.type===K0.Error))return{logs:[],errors:O.errors}}const g=O.log.logs,L=O.errors;return O.log.clearLogs(),O.clearErrors(),{logs:g,errors:L,cacheData:{varCacheData:i.getVarCacheData(),funcCacheData:O.getFuncCacheData()}}}}_runScripts(e,t,r,M,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:c,tradingvueFunc:O}=self.workerStorage.get(b)||{};const{interval:s,...u}=n||{};if(r){z=new _p(b),i=new hp,c=new Wp(this._variables.mintick||1e-5,z,this._scriptId),O=new Function("_$_var","_$_const","_$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:d}=this._variables;z.updateOptions({interval:s,mintick:h||1e-5,syminfo:{...d.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:c,tradingvueFunc:O})}z.updateData(u),c.update({barIndex:(u==null?void 0:u.barindex)||0});const l=O(z,i,c,M||[],t),q=c.log.logs,A=c.errors;return c.log.clearLogs(),c.clearErrors(),c.endExecution(),{result:l,logs:q,errors:A}}},Fm=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 Im{constructor(e,t){C(this,"_logs");C(this,"_variables");C(this,"_str");C(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get _logCacheData(){return this._preBar}set _logCacheData(e){this._preBar=e}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,M){if(typeof t=="string"&&(M=t),M.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:c,__isReqRepeated:O}=this._variables;let s=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>{if(typeof A=="object"){if(A===null)return"null";A!=null&&A.isArray?A=`[${A._value.toString()}]`:A=A.toString()}return A!==void 0?A:"na"}),s=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:c});const q=Date.now();s!==void 0&&this._logs.push({message:`[${O1(u&&!O?q:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${s}`,time:z,id:K4(6),barIndex:i,type:r})}}class Pm{constructor(e){C(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,K0.Error)}}class km{constructor(){C(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return b2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,M=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)+M+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class $m{constructor(){C(this,"_isMarketOpen");C(this,"_currentBarIndex");C(this,"_totalBarIndex");C(this,"_isRealTimeBar");C(this,"_preBarIndex");C(this,"_preIsRealTimeBar");C(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,M){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=M}get _barstateCacheData(){return{currentBarIndex:this._currentBarIndex,isRealTimeBar:this._isRealTimeBar}}set _barstateCacheData(e){this._currentBarIndex=e.currentBarIndex,this._isRealTimeBar=e.isRealTimeBar}set isFirstRun(e){this._isFirstRun=e}get isnew(){return 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 Um{constructor(e){C(this,"_variables");this._variables=e}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday||this._variables.bar_index===0}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=y2(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=y2(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 jm{constructor(e){C(this,"_orders");C(this,"_historyOrders");C(this,"_options");C(this,"_max_contracts_held_all",0);C(this,"_max_contracts_held_long",0);C(this,"_max_contracts_held_short",0);C(this,"_max_drawdown",0);C(this,"_max_runup",0);C(this,"_max_runup_percent",0);C(this,"_max_drawdown_percent",0);C(this,"_variables");C(this,"_netprofit",0);C(this,"_eventrades",0);C(this,"_avg_trade_percent");C(this,"_avg_losing_trade_percent");C(this,"_avg_winning_trade_percent");C(this,"_closedtrades",0);C(this,"_losstrades",0);C(this,"_grossloss",0);C(this,"_grossprofit",0);C(this,"_wintrades",0);C(this,"_opentrades_capital_held",0);C(this,"_position_avg_price",0);C(this,"_position_size",0);C(this,"_openprofit",0);C(this,"_preMaxNetValue",0);C(this,"_preMinNetValue",0);C(this,"marginCallLong",0);C(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:M,low:n,close:b}=e;let z=0;for(const[O,s]of this._orders.entries()){const{in_price:u,qty:l=0,direction:q,commission:A,original_qty:h=1}=s,d=q===a1.long?1:-1,m=(M-u)*l,_=(n-u)*l,R=d===1?m:-_,g=d===1?-_:m;z+=(b-u)*d*l,t+=g,O>0&&A&&(r-=A*l/h),r+=R}this._openprofit=z;const i=this.initial_capital,c=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-c+Math.max(t,0),r=c-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(){if(!this._orders.length){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,M,n,b,z]=this._orders.reduce(([i,c,O,s,u,l],q)=>{const{direction:A,qty:h=0,in_price:d,commission:m=0}=q;return A===a1.long?(i+=h,c+=h,u+=h):(i+=h,O+=h,u-=h),s+=h*d,l+=m,[i,c,O,s,u,l]},[0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-z,this._grossloss=z),this._position_size=b,this._position_avg_price=n/t,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(M,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,M,n,b,z,i,c,O]=this._historyOrders.reduce((l,q)=>{let[A,h,d,m,_,R,g,L]=l;const{profit:y=0,profit_percent:D=0}=q;return A+=y,h+=D,y<0?(d+=y,m+=D,g+=1):y>0&&(_+=y,R+=D,L+=1),[A,h,d,m,_,R,g,L]},[0,0,0,0,0,0,0,0]),s=this._orders.reduce((l,q)=>{const{commission:A=0,qty:h=0,original_qty:d=0}=q,m=A*h/d;return l+m},0);this._avg_trade_percent=t?M/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/c:void 0,this._avg_winning_trade_percent=t?i/O:void 0,this._netprofit=r-s;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-s),this._grossprofit=z,this._eventrades=t-c-O,this._losstrades=c,this._wintrades=O}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:M,commission_value:n=0}=this._options,b=this._orders[0].direction===a1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[c,O]=this._orders.reduce((s,u)=>{let[l,q]=s;const{in_price:A,qty:h=0,original_qty:d=0}=u,m=A*h;if(l+=m,n){let _=0;switch(M){case O2.percent:_=(m+h*i)*n/100;break;case O2.cashPerContract:_=h*n*2;break;case O2.cashPerOrder:_=h/d*n+n;break}q+=_}return[l,q]},[0,0]);return(c-(e+this._netprofit-O))*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:M}=this._options,n=e*t;let b=0;switch(M){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class Hm{constructor(e){C(this,"_preAccdist");C(this,"_preNvi");C(this,"_prePvi");C(this,"_preObv");C(this,"_prePvt");C(this,"_preWad");C(this,"_preVwap");C(this,"_preValue");C(this,"_currentData");C(this,"_preData");C(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}get _varTaCacheData(){return{preAccdist:this._preAccdist,preNvi:this._preNvi,prePvi:this._prePvi,preObv:this._preObv,prePvt:this._prePvt,preWad:this._preWad,preVwap:this._preVwap,currentData:this._currentData,preData:this._preData}}set _varTaCacheData(e){const{preAccdist:t,preNvi:r,prePvi:M,preObv:n,prePvt:b,preWad:z,preVwap:i,currentData:c,preData:O}=e;this._preAccdist=t,this._preNvi=r,this._prePvi=M,this._preObv=n,this._prePvt=b,this._preWad=z,this._preVwap=i,this._currentData=c,this._preData=O}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:M}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*M+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:M}=this._currentData,n=(2*e-r-t)/((r-t)*M);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:M,open:n}=this._currentData,b=(e-n)/(r-t)*M;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 M=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=M),this._preValue.obv=M,M}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 M=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=M,M}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 M=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=M),this._preValue.pvt=M,M}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:M}=this._preData;if(M===void 0)return this._preWad=0,0;const n=Math.max(t,M),b=Math.min(r,M),z=e-M,c=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=c),this._preValue.wad=c,c}get vwap(){var O,s;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:M=0,isReset:n}=this._preVwap;if(((s=(O=self.workerStorage)==null?void 0:O.get(this._id))==null?void 0:s.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=M=0),!n)return;const z=e*t+r,i=t+M;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const c=z/i;return this._preValue.vwap=c,c}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:M,volume:n}=this._currentData;let b=1;const z=e||1;return M&&t?b=n<r?z+(M-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:M,volume:n}=this._currentData;let b=1;const z=e||1;return M&&t?b=n>r?z+(M-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Ym{constructor(){C(this,"_period");C(this,"_multiplier");C(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=ht(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 Gm{constructor(){C(this,"_bgColor");C(this,"_fgColor");C(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,M,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),M=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,M=b[2]||0,n=b[3]||1}return{r:t,g:r,b:M,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:M}=this._parseColor(e);return(299*t+587*r+114*M)/1e3>128?"#000000":"#ffffff"}}class Vm{constructor(){C(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||ft.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 Km{constructor(e){C(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Jm{constructor(e){C(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class _p{constructor(e){C(this,"_cacheData");C(this,"_barIndex");C(this,"_isRealTimeBar");C(this,"_barstate");C(this,"_priceVariables");C(this,"_lastBarIndex");C(this,"_currentBarTime");C(this,"_lastBarTime");C(this,"_period");C(this,"_offsetTime");C(this,"_timeframe");C(this,"_ta");C(this,"_polyline");C(this,"_label");C(this,"_line");C(this,"_linefill");C(this,"_box");C(this,"_table");C(this,"_strategy");C(this,"_session");C(this,"syminfo");C(this,"chart");C(this,"earnings");C(this,"dividends");C(this,"_timeTradingday");C(this,"_mintick");C(this,"_cacheSpace");C(this,"_precision");C(this,"_nextBarTime");C(this,"_isRepeated");C(this,"_preCacheData");C(this,"__requestName","");C(this,"__isFirstRun",!1);C(this,"_maxBarsBack",0);C(this,"_maxBarsBackOfKey");C(this,"__isReqRepeated");C(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 $m,this._timeframe=new Ym,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Hm(e),this._polyline=new Sr(this,N0.POLYLINE),this._label=new Sr(this,N0.LABEL),this._line=new Sr(this,N0.LINE),this._linefill=new Sr(this,N0.LINEFILL),this._box=new Sr(this,N0.BOX),this._table=new Sr(this,N0.TABLE),this._strategy=new jm(this),this._session=new Um(this),this.syminfo=new Vm,this.chart=new Gm,this.earnings=new Jm(this),this.dividends=new Km(this),this._cacheSpace=Object.create(null),this._maxBarsBackOfKey=Object.create(null)}getVarCacheData(){return{cacheData:this._cacheData,preCacheData:this._preCacheData,cacheSpace:this._cacheSpace,taCacheData:this._ta._varTaCacheData,polylineCacheData:this._polyline._cacheData,labelCacheData:this._label._cacheData,lineCacheData:this._line._cacheData,linefillCacheData:this._linefill._cacheData,boxCacheData:this._box._cacheData,tableCacheData:this._table._cacheData,barstateCacheData:this.barstate._barstateCacheData}}setVarCacheData(e){if(!e)return;const{cacheData:t,preCacheData:r,cacheSpace:M,taCacheData:n,polylineCacheData:b,labelCacheData:z,lineCacheData:i,linefillCacheData:c,boxCacheData:O,tableCacheData:s,barstateCacheData:u}=e;this._cacheData=t,this._preCacheData=r,this._cacheSpace=M,this._ta._varTaCacheData=n,this._polyline._cacheData=b,this._label._cacheData=z,this._line._cacheData=i,this._linefill._cacheData=c,this._box._cacheData=O,this._table._cacheData=s,this.barstate._barstateCacheData=u}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:M}=this._priceVariables;return(e+t+r+M)/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 O1(this._currentBarTime).hour()}get minute(){return O1(this._currentBarTime).minute()}get second(){return O1(this._currentBarTime).second()}get month(){return O1(this._currentBarTime).month()+1}get year(){return O1(this._currentBarTime).year()}get dayofweek(){return O1(this.time_tradingday).weekday()}get dayofmonth(){return O1(this.time_tradingday).date()}get weekofyear(){return O1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=ht(this._period);return O1(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:M,max_polylines_count:n}=e;M&&this._box.setMaxLen(M),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,M]=ht(t),n=O1(e);return["M","w","y","d"].includes(M)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}_getTimeTradingday(e,t){const[r,M]=ht(t),n=O1(e).utc(!0);return["M","w","y","d"].includes(M)?n.valueOf():n.startOf("d").valueOf()}updateOptions(e){var c;const{interval:t="1D",offsetTime:r=5,mintick:M,chart:n,syminfo:b}=e,z=((c=M.toString().split(".")[1])==null?void 0:c.length)||5;this._precision=z;const i=Q4(t);this._period=i,this._mintick=M,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:M,o:n,h:b,l:z,volume:i,time:c,lastBarIndex:O,lastBarTime:s,isrealtime:u,time_tradingday:l,nextBarTime:q}=e;if(this._priceVariables={close:rn(M,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._preCacheData.varData=b2.cloneDeep(A),this._preCacheData.varipData=b2.cloneDeep(h)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=c*1e3,this._lastBarIndex=O,this._barIndex=r,this._lastBarTime=s*1e3,this._nextBarTime=q*1e3,this._barstate.update(r,O,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){const M=this.setCacheData(e,r),n=this._cacheSpace[e]||0;return t=Math.floor(t),n<t&&(this._cacheSpace[e]=t),M[M.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;t=this._cacheCopy(t),r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const M=this._cacheSpace[e]||0,n=ui.includes(e)?500:50;return M&&r.data.length>(this._maxBarsBackOfKey[e]||this._maxBarsBack||M+n)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}__setBarsBackOfKey(e,t){this._maxBarsBackOfKey[e]=t}__getBarsBackOfKey(e){return this._maxBarsBackOfKey[e]}getTypeInstance(e,t,r){return new Oi(e,t,r)}verifyVarAndVarip(e,t,r){const M=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(M))return this._upadteChartDraws(n.varData,M),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(M)?(this._upadteChartDraws(b,M),!0):!1}getVarValue(e,t,r){const M=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[M]=this._preCacheData.varData[M],this.__isReqRepeated&&(this._cacheData.varipData[M]=this._preCacheData.varipData[M]));const n=this._cacheData;if(r==="var"){const b=n.varData[M];return this._isRealTimeBar?this._newCacheData.hasOwnProperty(M)?this._newCacheData[M]:this._cacheCopy(b):b}return this._cacheData.varipData[M]}setVarValue(e,t,r,M){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)&&M!=="varip"&&(M="var",b=r.varipKeys),M){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,t){const r=e[t],M=this._isRealTimeBar?r==null?void 0:r.preId:r==null?void 0:r.id;if(!M)return;let n;switch(r==null?void 0:r.type){case N0.BOX:n=this._setChartDraw(M,this._box);break;case N0.LINE:n=this._setChartDraw(M,this._line);break;case N0.POLYLINE:n=this._setChartDraw(M,this._polyline);break;case N0.LABEL:n=this._setChartDraw(M,this._label);break;case N0.LINEFILL:n=this._setChartDraw(M,this._linefill);break;case N0.TABLE:n=this._setChartDraw(M,this._table);break}n&&(e[t]=n)}_cacheCopy(e){return typeof e!="object"||!e||e.isDraw?e:b2.cloneDeep(e)}_updateId(e){const{bar_index:t,_isRealTimeBar:r}=this,M=e.id;if(!e._suffix)e._suffix=`_${t}`,e.id=`${e.id}${e._suffix}`;else{const n=e.id.split("_");n.pop(),e.id=`${n.join("_")}_${t}`}return e.line1&&nt.__updateFillKeys(e.line1,M,e.id),e.line2&&nt.__updateFillKeys(e.line2,M,e.id),r||(e.preId=e.id),e.id}_setChartDraw(e,t){const r=t.getInstance(e);let M=t.get(e);if(!M||!r)return;const n=this._updateId(r)||e;return n===e&&!this._isRealTimeBar||(M=JSON.parse(JSON.stringify(M)),this._isRealTimeBar||(r.data=M),t.deleteHandle(e,!1),t.set(n,M,r)),r}_chartDrawsHandle(e,t){if(typeof e!="object")return;const r=t==null?void 0:t.id;let M=e==null?void 0:e.id;M&&e.data&&(e.data.isVar=!0),r!==M&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?b2.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}notEqual(e,t,r,M){return e===void 0&&typeof t=="number"||t===void 0&&typeof e=="number"?!1:!this.equal(e,t,r,M)}equal(e,t,r,M){if(typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t))return!0;if(e!==void 0&&t!==void 0)return e==t;if(e===void 0&&typeof t=="number"||t===void 0&&typeof e=="number")return!1;if(!(r.endsWith(N0.BOOL)&&e===void 0))return(r.endsWith(N0.FLOAT)||r.endsWith(N0.INT)||M.endsWith(N0.FLOAT)||M.endsWith(N0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(N0.STRING)&&e===""&&t===void 0||M.endsWith(N0.STRING)&&t===""&&e===void 0?!0:r.endsWith(N0.NA)&&M.endsWith(N0.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,M]=e.toFixed(11).split(".");return+`${r}.${M.slice(0,10)}`}}class Sr{constructor(e,t,r=50){C(this,"_all");C(this,"_allInstance");C(this,"_pseudoArrayAll");C(this,"_maxLength");C(this,"_deleteIds");C(this,"_variables");C(this,"_preDeleteIds");C(this,"_againAddItems");C(this,"_tmpData");C(this,"_tmpInstance");C(this,"_type");C(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=p1(0,void 0,t),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}get _cacheData(){return{allInstance:Array.from(this._allInstance),tmpIds:this._tmpIds,preDeleteIds:Array.from(this._preDeleteIds)}}set _cacheData(e){this._allInstance=new Map(e.allInstance),this._all=new Map(e.allInstance.map(([t,r])=>[t,r.data])),this._tmpIds=e.tmpIds,this._preDeleteIds=new Map(e.preDeleteIds)}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get __allInstance(){return this._allInstance}get data(){const e=[],t=b2.flatMap([...this._deleteIds.values()]),r=b2.uniq([...this._tmpData.keys(),...this._all.keys()]),M=[];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&&!M.includes(z)&&(M.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===N0.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!==N0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:M}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:c}=b;if(c===M)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=b2.uniq([...this._all.keys(),...this._tmpData.keys()]),M=b2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(M.some(c=>c.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===N0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:M}=this._variables,n=[];for(const z of e){let i=[...this._deleteIds.get(z)||[]];const c=this._preDeleteIds.get(z)||[];if(z===r&&M){let O=[];for(const s of c){const u=i.findIndex(l=>l.id===s.id);if(u===-1){const l=this._all.get(s.key);l&&n.push(l)}else O.push(s),i.splice(u,1)}this._preDeleteIds.set(r,b2.uniqBy([...i,...O],"id"))}else{const O=[];for(const s of i)c.some(u=>u.id===s.id)||O.push(s);i=O,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,b2.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,r=!1){var M;if(this._type===N0.LINE&&t){const n=(M=this._allInstance.get(e))==null?void 0:M.fillKeys;if(n&&n.length)for(const b of n)this._variables.linefill.deleteHandle(b)}if(this._variables._isRealTimeBar){if(r){const n=this._tmpInstance.get(e);n&&(n.data=void 0)}this._tmpData.delete(e),this._tmpInstance.delete(e)}else{if(r){const n=this._allInstance.get(e);n&&(n.data=void 0)}this._all.delete(e),this._allInstance.delete(e)}}delete(e,t,r){const M=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e,!1,!0),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(M==null?void 0:M.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,M){var R;let{symbol:n,timeframe:b,calc_bars_count:z,ignore_invalid_symbol:i,ignore_invalid_timeframe:c}=e;const{__period:O,time:s,_isRealTimeBar:u}=this._variables;b=uM(b);let l=y2(b,s)*1e3;const q=y2(O,s)*1e3;if(l>q)return!c&&this._errorListener.addError(l2(N1.requestLowerTfPeriodErr,{period:b}),t,K0.Error,25),[];const A=`${n}--${b}`,h=self.workerStorage.get(`request_${this._scriptId}_data`),d=self.workerStorage.get(`request_${this._scriptId}_list`),m=self.workerStorage.get(`request_${this._scriptId}_tmp`),_={id:A,calc_bars_count:z,ignore_invalid_symbol:i,symbol:n,originTimeframe:b,timeframe:Ai[b]||Ac(b)};if(h!=null&&h.has(A)){m==null||m.delete(A);const{index:g=0,periodStamp:L=q}=this._cacheData[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=s,w=L+N;const E=[];for(const[P,H]of T.entries()){let{time:Y}=H;Y=Y*1e3;let k=g+P;if(Y>=w)return!u&&(this._cacheData[r]={index:k,periodStamp:L}),E;if(N<=Y&&Y<w){const K=(R=H==null?void 0:H.result)==null?void 0:R[r];if(Array.isArray(K))for(const[e0,b0]of K.entries())E[e0]||(E[e0]=[]),E[e0].push(b0);else M||E.push(K)}}return!u&&(this._cacheData[r]={index:y.length,periodStamp:L}),E}else(d==null?void 0:d.get(A))||m==null||m.set(A,_);d==null||d.set(A,_)}_getRequestData(e,t){var m,_,R,g,L;let{symbol:r,timeframe:M,calc_bars_count:n,gaps:b,lookahead:z,ignore_invalid_symbol:i}=e;const{__period:c,mintick:O,time:s,nextBarTime:u}=this._variables;M=uM(M),r=r;const l=`${r}--${M}`,q=self.workerStorage.get(`request_${this._scriptId}_data`),A=self.workerStorage.get(`request_${this._scriptId}_list`),h=self.workerStorage.get(`request_${this._scriptId}_tmp`),d={id:l,calc_bars_count:n,ignore_invalid_symbol:i,symbol:r,originTimeframe:M,timeframe:Ai[M]||Ac(M)};if(q!=null&&q.has(l)){let y=y2(M,s)*1e3;const D=y2(c,s)*1e3;h==null||h.delete(l);const{index:T=0,periodStamp:N=D}=this._cacheData[t]||{},w=q==null?void 0:q.get(l);if(!w.length)return;const E=w.slice(T);let P=s,H=N+P;const Y=w.length-1;if(Y<0)return;const k={lastBarIndex:w[Y].barindex||Y,lastBarTime:w[Y].time,interval:M,mintick:O};if(y>N){let K;if(z===ke.lookaheadOn?K=this._lookaheadOnHandle(E,M,H,y,k,T,N,t,P,b):K=this._lookaheadOffHandle(E,M,H,y,k,T,N,t,P,u||H,b),K)return K;if(K===null)return}else if(z===ke.lookaheadOn)for(const[K,e0]of E.entries()){let{time:b0,barindex:O0}=e0;b0=b0*1e3;const v0=((m=E[K+1])==null?void 0:m.time)*1e3||b0+y;let B0=T+K;if(b0>=H){this._cacheData[t]={index:B0,periodStamp:N};return}if(b0<=P&&v0>P){const A0=T+K;return this._cacheData[t]={index:A0,periodStamp:N},{...e0,barIndex:O0||A0,nextBarTime:(_=E[K+1])==null?void 0:_.time,...k}}}else for(const[K,e0]of E.entries()){let{time:b0,barindex:O0}=e0;b0=b0*1e3;const v0=((R=E[K+1])==null?void 0:R.time)*1e3||b0+y;let B0=T+K;if(b0>H){this._cacheData[t]={index:B0,periodStamp:N};return}if(b0<H&&H<=v0)return this._cacheData[t]={index:B0,periodStamp:N},{...e0,barIndex:O0||B0,nextBarTime:(g=E[K+1])==null?void 0:g.time,...k};if(b0>=P&&b0<=H&&(O0||B0)===k.lastBarIndex)return this._cacheData[t]={index:B0,periodStamp:N},{...e0,barIndex:O0||B0,nextBarTime:(L=E[K+1])==null?void 0:L.time,...k}}this._cacheData[t]={index:w.length,periodStamp:N};return}else(A==null?void 0:A.get(l))||h==null||h.set(l,d);A==null||A.set(l,d)}_lookaheadOnHandle(e,t,r,M,n,b,z,i,c,O){var s;for(const[u,l]of e.entries()){let{time:q,barindex:A}=l;q=q*1e3,t.includes("M")&&(M=y2(t,q)*1e3-(O1(q).date()-1)*864e5);const h=q,d=M+h;let m=b+u;if(r<=h)return this._cacheData[i]={index:m,periodStamp:z},null;let _={...l,barIndex:A||m,nextBarTime:(s=e[u+1])==null?void 0:s.time,...n};if(O===ke.gapsOn){if(r>h&&c<=h)return this._cacheData[i]={index:m,periodStamp:z},_}else{if(r>d)continue;if(r>h)return this._cacheData[i]={index:m,periodStamp:z},_}}}_lookaheadOffHandle(e,t,r,M,n,b,z,i,c,O,s){var u,l;for(const[q,A]of e.entries()){let{time:h,barindex:d}=A;h=h*1e3,t.includes("M")&&(M=y2(t,h)*1e3-(O1(h).date()-1)*864e5);const m=h,_=M+m,R=b+q;if(r<m)return this._cacheData[i]={index:R,periodStamp:z},null;const g={...A,barIndex:d||R,nextBarTime:(u=e[q+1])==null?void 0:u.time,...n};if(r>=_&&c<_||r<_&&O>=_)return s===ke.gapsOn?(this._cacheData[i]={index:R,periodStamp:z},g):(this._cacheData[i]={index:R,data:g,periodStamp:z},g);if(!(c>_)&&c>=m){let L=(l=this._cacheData[i])==null?void 0:l.data;if(!L){const y=e[R-1];if(!y)return null;L={...y,barIndex:y.barindex||R-1,nextBarTime:g.time,...n},this._cacheData[i]={index:R,data:L,periodStamp:z}}return L}}}_getDependCodes(e,t,r,M,n,b){for(const z of e){if(!z.isArg){const i=t.filter(O=>{var s;return(s=O==null?void 0:O.depends)==null?void 0:s.some(u=>u.name===z.name&&u.scope===z.scope&&u.isAgainAssign!==!1)});for(const O of i){const{code:s,depends:u,scope:l,funcName:q}=O;r[l]=r[l]||[];const A=r[l];let h=l===0&&q;if(!A.includes(s)){if(h){if(M.includes(s))continue;M.unshift(s)}else A.unshift(s);if(u!=null&&u.length){for(const d of u)d.memberCode&&!h&&b.push(d.memberCode);this._getDependCodes(u,t,r,M,n,b)}}}const c=t.find(O=>{var s;return((s=O.varNames)==null?void 0:s.split(", ").includes(z.name))&&(!z.isPreArg||z.isPreArg&&O.methodName===z.functionName)||O.funcName===z.name});if(c){const{code:O,depends:s,scope:u}=c;r[u]=r[u]||[];const l=r[u],q=l.findIndex(A=>A===O);if(q!==-1){if(z.isFunc)continue;l.splice(q,1)}if(l.unshift(O),s!=null&&s.length){for(const A of s)A.memberCode&&b.push(A.memberCode);this._getDependCodes(s,t,r,M,n,b)}continue}}n.some(i=>i.name===z.name)||n.push(z)}}_getStmtFuncs(e,t,r,M,n){const b=t.filter(z=>z.isStmtFunc);for(const z of b){const{code:i,depends:c,scope:O=0}=z;e[O]=e[O]||[];const s=e[O];if(!s.includes(i)&&(s.push(i),c!=null&&c.length)){for(const u of c)u.memberCode&&r.push(u.memberCode);this._getDependCodes(c.filter(u=>!(u.isFunc&&i.startsWith(u.name))),t,e,M,n,r)}}}runScripts(e,t,r,M,n,b){var u,l;const z=`${this._scriptId}_${t}`,i=new _p(z),c=new hp,O=new Wp(this._variables.mintick||1e-5,i,this._scriptId),s=new Function("_$_var","_$_const","_$_func","$paramsExpr","$posStr",e);if(!r){const{varCacheData:q,funcCacheData:A}=n;i.setVarCacheData(q),O.setFuncCacheData(A)}if(i.__requestName=t,M&&M.length){const q=M.length-1,{interval:A,symbol:h=""}=n;let{mintick:d,syminfo:m}=this._variables;const[_,R]=h.split(":");d||(d=Math.pow(10,-(((u=String(M[0].o).split(".")[1])==null?void 0:u.length)||0))),i.updateOptions({interval:A,mintick:d,syminfo:{...m.__syminfo,mintick:d,tickerid:h||m.tickerid,ticker:R||_||m.ticker}});for(const[y,D]of M.entries()){const{barindex:T}=D,N=Object.assign(D,{barIndex:T||y,lastBarIndex:M[q].barindex||q,lastBarTime:M[q].time,nextBarTime:(l=M[y+1])==null?void 0:l.time});if(i.updateData(N),O.update({barIndex:(N==null?void 0:N.barindex)||0}),D.result=Object.assign(D.result||{},{[t]:s(i,c,O,b||[],t)}),O.endExecution(),O.errors.length&&O.errors.some(w=>w.type===K0.Error))return{logs:[],errors:O.errors}}const g=O.log.logs,L=O.errors;return O.log.clearLogs(),O.clearErrors(),{logs:g,errors:L,cacheData:{varCacheData:i.getVarCacheData(),funcCacheData:O.getFuncCacheData()}}}}_runScripts(e,t,r,M,n){const b=`${this._scriptId}_${t}`;let{builtInGather:z,buildinConstants:i,buildInFunctions:c,tradingvueFunc:O}=self.workerStorage.get(b)||{};const{interval:s,...u}=n||{};if(r){z=new _p(b),i=new hp,c=new Wp(this._variables.mintick||1e-5,z,this._scriptId),O=new Function("_$_var","_$_const","_$_func","$paramsExpr","$posStr",e);const{mintick:h,syminfo:d}=this._variables;z.updateOptions({interval:s,mintick:h||1e-5,syminfo:{...d.__syminfo}}),z.__requestName=t,self.workerStorage.set(b,{builtInGather:z,buildinConstants:i,buildInFunctions:c,tradingvueFunc:O})}z.updateData(u),c.update({barIndex:(u==null?void 0:u.barindex)||0});const l=O(z,i,c,M||[],t),q=c.log.logs,A=c.errors;return c.log.clearLogs(),c.clearErrors(),c.endExecution(),{result:l,logs:q,errors:A}}},Fm=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 Im{constructor(e,t){C(this,"_logs");C(this,"_variables");C(this,"_str");C(this,"_preBar",{barIndex:-1,isrealtime:!1});this._variables=e,this._logs=[],this._str=t}get _logCacheData(){return this._preBar}set _logCacheData(e){this._preBar=e}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,M){if(typeof t=="string"&&(M=t),M.startsWith("export"))return;const{message:n,formatString:b}=e,{time:z,bar_index:i,_isRealTimeBar:c,__isReqRepeated:O}=this._variables;let s=n;b&&Array.isArray(t)&&t.length&&(t=t.map(A=>{if(typeof A=="object"){if(A===null)return"null";A!=null&&A.isArray?A=`[${A._value.toString()}]`:A=A.toString()}return A!==void 0?A:"na"}),s=this._str.strformat({formatString:b},t,!0));const{isrealtime:u,barIndex:l}=this._preBar;i!==l&&(this._preBar={barIndex:i,isrealtime:c});const q=Date.now();s!==void 0&&this._logs.push({message:`[${O1(u&&!O?q:z).format("YYYY-MM-DDTHH:mm:ss.SSSZ")}]: ${s}`,time:z,id:K4(6),barIndex:i,type:r})}}class Pm{constructor(e){C(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,K0.Error)}}class km{constructor(){C(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return b2.flatMap([...this._errors.values()])}setErrors(e,t){this._errors.set(t,e)}addError(e,t,r,M=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)+M+1,startLineNumber:Number(n),type:r};z?z.push(i):this._errors.set(t,[i])}}class $m{constructor(){C(this,"_isMarketOpen");C(this,"_currentBarIndex");C(this,"_totalBarIndex");C(this,"_isRealTimeBar");C(this,"_preBarIndex");C(this,"_preIsRealTimeBar");C(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,M){this._preBarIndex=this._currentBarIndex,this._preIsRealTimeBar=this._isRealTimeBar,this._currentBarIndex=e,this._totalBarIndex=t,this._isRealTimeBar=r,this._isMarketOpen=M}get _barstateCacheData(){return{currentBarIndex:this._currentBarIndex,isRealTimeBar:this._isRealTimeBar}}set _barstateCacheData(e){this._currentBarIndex=e.currentBarIndex,this._isRealTimeBar=e.isRealTimeBar}set isFirstRun(e){this._isFirstRun=e}get isnew(){return 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 Um{constructor(e){C(this,"_variables");this._variables=e}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday||this._variables.bar_index===0}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=y2(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=y2(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 jm{constructor(e){C(this,"_orders");C(this,"_historyOrders");C(this,"_options");C(this,"_max_contracts_held_all",0);C(this,"_max_contracts_held_long",0);C(this,"_max_contracts_held_short",0);C(this,"_max_drawdown",0);C(this,"_max_runup",0);C(this,"_max_runup_percent",0);C(this,"_max_drawdown_percent",0);C(this,"_variables");C(this,"_netprofit",0);C(this,"_eventrades",0);C(this,"_avg_trade_percent");C(this,"_avg_losing_trade_percent");C(this,"_avg_winning_trade_percent");C(this,"_closedtrades",0);C(this,"_losstrades",0);C(this,"_grossloss",0);C(this,"_grossprofit",0);C(this,"_wintrades",0);C(this,"_opentrades_capital_held",0);C(this,"_position_avg_price",0);C(this,"_position_size",0);C(this,"_openprofit",0);C(this,"_preMaxNetValue",0);C(this,"_preMinNetValue",0);C(this,"marginCallLong",0);C(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:M,low:n,close:b}=e;let z=0;for(const[O,s]of this._orders.entries()){const{in_price:u,qty:l=0,direction:q,commission:A,original_qty:h=1}=s,d=q===a1.long?1:-1,m=(M-u)*l,_=(n-u)*l,R=d===1?m:-_,g=d===1?-_:m;z+=(b-u)*d*l,t+=g,O>0&&A&&(r-=A*l/h),r+=R}this._openprofit=z;const i=this.initial_capital,c=i+this._netprofit;this._preMinNetValue=this._preMinNetValue||i,this._preMaxNetValue=this._preMaxNetValue||i,t=this._preMaxNetValue-c+Math.max(t,0),r=c-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(){if(!this._orders.length){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[t,r,M,n,b,z]=this._orders.reduce(([i,c,O,s,u,l],q)=>{const{direction:A,qty:h=0,in_price:d,commission:m=0}=q;return A===a1.long?(i+=h,c+=h,u+=h):(i+=h,O+=h,u-=h),s+=h*d,l+=m,[i,c,O,s,u,l]},[0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-z,this._grossloss=z),this._position_size=b,this._position_avg_price=n/t,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(M,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,M,n,b,z,i,c,O]=this._historyOrders.reduce((l,q)=>{let[A,h,d,m,_,R,g,L]=l;const{profit:y=0,profit_percent:D=0}=q;return A+=y,h+=D,y<0?(d+=y,m+=D,g+=1):y>0&&(_+=y,R+=D,L+=1),[A,h,d,m,_,R,g,L]},[0,0,0,0,0,0,0,0]),s=this._orders.reduce((l,q)=>{const{commission:A=0,qty:h=0,original_qty:d=0}=q,m=A*h/d;return l+m},0);this._avg_trade_percent=t?M/t:void 0,this._avg_losing_trade_percent=t?Math.abs(b)/c:void 0,this._avg_winning_trade_percent=t?i/O:void 0,this._netprofit=r-s;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-s),this._grossprofit=z,this._eventrades=t-c-O,this._losstrades=c,this._wintrades=O}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:M,commission_value:n=0}=this._options,b=this._orders[0].direction===a1.long?1:-1,z=(b===1?t:r)/100;if(z<=0)return;const{close:i}=this._variables,[c,O]=this._orders.reduce((s,u)=>{let[l,q]=s;const{in_price:A,qty:h=0,original_qty:d=0}=u,m=A*h;if(l+=m,n){let _=0;switch(M){case O2.percent:_=(m+h*i)*n/100;break;case O2.cashPerContract:_=h*n*2;break;case O2.cashPerOrder:_=h/d*n+n;break}q+=_}return[l,q]},[0,0]);return(c-(e+this._netprofit-O))*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:M}=this._options,n=e*t;let b=0;switch(M){case O2.percent:b=n*r/100;break;case O2.cashPerContract:b=t*r;break;case O2.cashPerOrder:b=r;break}return b}}class Hm{constructor(e){C(this,"_preAccdist");C(this,"_preNvi");C(this,"_prePvi");C(this,"_preObv");C(this,"_prePvt");C(this,"_preWad");C(this,"_preVwap");C(this,"_preValue");C(this,"_currentData");C(this,"_preData");C(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}get _varTaCacheData(){return{preAccdist:this._preAccdist,preNvi:this._preNvi,prePvi:this._prePvi,preObv:this._preObv,prePvt:this._prePvt,preWad:this._preWad,preVwap:this._preVwap,currentData:this._currentData,preData:this._preData}}set _varTaCacheData(e){const{preAccdist:t,preNvi:r,prePvi:M,preObv:n,prePvt:b,preWad:z,preVwap:i,currentData:c,preData:O}=e;this._preAccdist=t,this._preNvi=r,this._prePvi=M,this._preObv=n,this._prePvt=b,this._preWad=z,this._preVwap=i,this._currentData=c,this._preData=O}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:M}=this._currentData;if(r===t)return this._preAccdist;const n=(e-t-(r-e))/(r-t)*M+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:M}=this._currentData,n=(2*e-r-t)/((r-t)*M);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:M,open:n}=this._currentData,b=(e-n)/(r-t)*M;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 M=Math.sign(e-r)*t+this._preObv;return!this.isRealTime&&(this._preObv=M),this._preValue.obv=M,M}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 M=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=M,M}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 M=(e-r)/r*t+this._prePvt;return!this.isRealTime&&(this._prePvt=M),this._preValue.pvt=M,M}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:e,high:t,low:r}=this._currentData,{close:M}=this._preData;if(M===void 0)return this._preWad=0,0;const n=Math.max(t,M),b=Math.min(r,M),z=e-M,c=(z>0?e-b:z<0?e-n:0)+this._preWad;return!this.isRealTime&&(this._preWad=c),this._preValue.wad=c,c}get vwap(){var O,s;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:M=0,isReset:n}=this._preVwap;if(((s=(O=self.workerStorage)==null?void 0:O.get(this._id))==null?void 0:s.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(n=!0,r=M=0),!n)return;const z=e*t+r,i=t+M;!this.isRealTime&&(this._preVwap={sum:z,sumV:i,isReset:n});const c=z/i;return this._preValue.vwap=c,c}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:M,volume:n}=this._currentData;let b=1;const z=e||1;return M&&t?b=n<r?z+(M-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:M,volume:n}=this._currentData;let b=1;const z=e||1;return M&&t?b=n>r?z+(M-t)/t*z:z:b=z,!this.isRealTime&&(this._prePvi=b),this._preValue.pvi=b,b}}class Ym{constructor(){C(this,"_period");C(this,"_multiplier");C(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=ht(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 Gm{constructor(){C(this,"_bgColor");C(this,"_fgColor");C(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,M,n;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),M=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,M=b[2]||0,n=b[3]||1}return{r:t,g:r,b:M,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:M}=this._parseColor(e);return(299*t+587*r+114*M)/1e3>128?"#000000":"#ffffff"}}class Vm{constructor(){C(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||ft.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 Km{constructor(e){C(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Jm{constructor(e){C(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}class _p{constructor(e){C(this,"_cacheData");C(this,"_barIndex");C(this,"_isRealTimeBar");C(this,"_barstate");C(this,"_priceVariables");C(this,"_lastBarIndex");C(this,"_currentBarTime");C(this,"_lastBarTime");C(this,"_period");C(this,"_offsetTime");C(this,"_timeframe");C(this,"_ta");C(this,"_polyline");C(this,"_label");C(this,"_line");C(this,"_linefill");C(this,"_box");C(this,"_table");C(this,"_strategy");C(this,"_session");C(this,"syminfo");C(this,"chart");C(this,"earnings");C(this,"dividends");C(this,"_timeTradingday");C(this,"_mintick");C(this,"_cacheSpace");C(this,"_precision");C(this,"_nextBarTime");C(this,"_isRepeated");C(this,"_preCacheData");C(this,"__requestName","");C(this,"__isFirstRun",!1);C(this,"_maxBarsBack",0);C(this,"_maxBarsBackOfKey");C(this,"__isReqRepeated");C(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 $m,this._timeframe=new Ym,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Hm(e),this._polyline=new Sr(this,N0.POLYLINE),this._label=new Sr(this,N0.LABEL),this._line=new Sr(this,N0.LINE),this._linefill=new Sr(this,N0.LINEFILL),this._box=new Sr(this,N0.BOX),this._table=new Sr(this,N0.TABLE),this._strategy=new jm(this),this._session=new Um(this),this.syminfo=new Vm,this.chart=new Gm,this.earnings=new Jm(this),this.dividends=new Km(this),this._cacheSpace=Object.create(null),this._maxBarsBackOfKey=Object.create(null)}getVarCacheData(){return{cacheData:this._cacheData,preCacheData:this._preCacheData,cacheSpace:this._cacheSpace,taCacheData:this._ta._varTaCacheData,polylineCacheData:this._polyline._cacheData,labelCacheData:this._label._cacheData,lineCacheData:this._line._cacheData,linefillCacheData:this._linefill._cacheData,boxCacheData:this._box._cacheData,tableCacheData:this._table._cacheData,barstateCacheData:this.barstate._barstateCacheData}}setVarCacheData(e){if(!e)return;const{cacheData:t,preCacheData:r,cacheSpace:M,taCacheData:n,polylineCacheData:b,labelCacheData:z,lineCacheData:i,linefillCacheData:c,boxCacheData:O,tableCacheData:s,barstateCacheData:u}=e;this._cacheData=t,this._preCacheData=r,this._cacheSpace=M,this._ta._varTaCacheData=n,this._polyline._cacheData=b,this._label._cacheData=z,this._line._cacheData=i,this._linefill._cacheData=c,this._box._cacheData=O,this._table._cacheData=s,this.barstate._barstateCacheData=u}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:M}=this._priceVariables;return(e+t+r+M)/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 O1(this._currentBarTime).hour()}get minute(){return O1(this._currentBarTime).minute()}get second(){return O1(this._currentBarTime).second()}get month(){return O1(this._currentBarTime).month()+1}get year(){return O1(this._currentBarTime).year()}get dayofweek(){return O1(this.time_tradingday).weekday()}get dayofmonth(){return O1(this.time_tradingday).date()}get weekofyear(){return O1(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=ht(this._period);return O1(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:M,max_polylines_count:n}=e;M&&this._box.setMaxLen(M),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),n&&this._polyline.setMaxLen(n)}getTimeTradingday(e,t){const[r,M]=ht(t),n=O1(e);return["M","w","y","d"].includes(M)?n.valueOf():(n.subtract(this._offsetTime,"h"),n.startOf("d").add(this._offsetTime,"h").valueOf())}_getTimeTradingday(e,t){const[r,M]=ht(t),n=O1(e).utc(!0);return["M","w","y","d"].includes(M)?n.valueOf():n.startOf("d").valueOf()}updateOptions(e){var c;const{interval:t="1D",offsetTime:r=5,mintick:M,chart:n,syminfo:b}=e,z=((c=M.toString().split(".")[1])==null?void 0:c.length)||5;this._precision=z;const i=Q4(t);this._period=i,this._mintick=M,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:M,o:n,h:b,l:z,volume:i,time:c,lastBarIndex:O,lastBarTime:s,isrealtime:u,time_tradingday:l,nextBarTime:q}=e;if(this._priceVariables={close:rn(M,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._preCacheData.varData=b2.cloneDeep(A),this._preCacheData.varipData=b2.cloneDeep(h)):this._preCacheData={varData:{...A},varipData:{...h}}}this._isRepeated=t,this._timeTradingday=l,this._currentBarTime=c*1e3,this._lastBarIndex=O,this._barIndex=r,this._lastBarTime=s*1e3,this._nextBarTime=q*1e3,this._barstate.update(r,O,u,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:r})}getCacheData(e,t,r){var b;let M=(b=this._cacheData[e])==null?void 0:b.data;M||(M=this.setCacheData(e,r));const n=this._cacheSpace[e]||0;return t=Math.floor(t),n<t&&(this._cacheSpace[e]=t),M[M.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;t=this._cacheCopy(t),r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t);const M=this._cacheSpace[e]||0,n=ui.includes(e)?500:50;return M&&r.data.length>(this._maxBarsBackOfKey[e]||this._maxBarsBack||M+n)&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[e]=r,r.data}__setBarsBackOfKey(e,t){this._maxBarsBackOfKey[e]=t}__getBarsBackOfKey(e){return this._maxBarsBackOfKey[e]}getTypeInstance(e,t,r){return new Oi(e,t,r)}verifyVarAndVarip(e,t,r){const M=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`,n=this._isRepeated||this.__isReqRepeated?this._preCacheData:this._cacheData;if(r==="var"&&n.varData.hasOwnProperty(M))return this._upadteChartDraws(n.varData,M),!0;const b=this.__isReqRepeated?this._preCacheData.varipData:this._cacheData.varipData;return r==="varip"&&b.hasOwnProperty(M)?(this._upadteChartDraws(b,M),!0):!1}getVarValue(e,t,r){const M=`${e}_${t.replace(/\$[\d]+_\$/g,"")}`;(this._isRepeated||this.__isReqRepeated)&&(this._cacheData.varData[M]=this._preCacheData.varData[M],this.__isReqRepeated&&(this._cacheData.varipData[M]=this._preCacheData.varipData[M]));const n=this._cacheData;if(r==="var"){const b=n.varData[M];return this._isRealTimeBar?this._newCacheData.hasOwnProperty(M)?this._newCacheData[M]:this._cacheCopy(b):b}return this._cacheData.varipData[M]}setVarValue(e,t,r,M){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)&&M!=="varip"&&(M="var",b=r.varipKeys),M){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,t){const r=e[t],M=this._isRealTimeBar?r==null?void 0:r.preId:r==null?void 0:r.id;if(!M)return;let n;switch(r==null?void 0:r.type){case N0.BOX:n=this._setChartDraw(M,this._box);break;case N0.LINE:n=this._setChartDraw(M,this._line);break;case N0.POLYLINE:n=this._setChartDraw(M,this._polyline);break;case N0.LABEL:n=this._setChartDraw(M,this._label);break;case N0.LINEFILL:n=this._setChartDraw(M,this._linefill);break;case N0.TABLE:n=this._setChartDraw(M,this._table);break}n&&(e[t]=n)}_cacheCopy(e){return typeof e!="object"||!e||e.isDraw?e:b2.cloneDeep(e)}_updateId(e){const{bar_index:t,_isRealTimeBar:r}=this,M=e.id;if(!e._suffix)e._suffix=`_${t}`,e.id=`${e.id}${e._suffix}`;else{const n=e.id.split("_");n.pop(),e.id=`${n.join("_")}_${t}`}return e.line1&&nt.__updateFillKeys(e.line1,M,e.id),e.line2&&nt.__updateFillKeys(e.line2,M,e.id),r||(e.preId=e.id),e.id}_setChartDraw(e,t){const r=t.getInstance(e);let M=t.get(e);if(!M||!r)return;const n=this._updateId(r)||e;return n===e&&!this._isRealTimeBar||(M=JSON.parse(JSON.stringify(M)),this._isRealTimeBar||(r.data=M),t.deleteHandle(e,!1),t.set(n,M,r)),r}_chartDrawsHandle(e,t){if(typeof e!="object")return;const r=t==null?void 0:t.id;let M=e==null?void 0:e.id;M&&e.data&&(e.data.isVar=!0),r!==M&&r&&t.data&&(t.data.isVar=!1)}add(e,t){return Array.isArray(e)&&Array.isArray(t)?b2.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}notEqual(e,t,r,M){return e===void 0&&typeof t=="number"||t===void 0&&typeof e=="number"?!1:!this.equal(e,t,r,M)}equal(e,t,r,M){if(typeof e=="number"&&typeof t=="number"&&isNaN(e)&&isNaN(t))return!0;if(e!==void 0&&t!==void 0)return e==t;if(e===void 0&&typeof t=="number"||t===void 0&&typeof e=="number")return!1;if(!(r.endsWith(N0.BOOL)&&e===void 0))return(r.endsWith(N0.FLOAT)||r.endsWith(N0.INT)||M.endsWith(N0.FLOAT)||M.endsWith(N0.INT))&&e===void 0&&t===void 0?!1:r.endsWith(N0.STRING)&&e===""&&t===void 0||M.endsWith(N0.STRING)&&t===""&&e===void 0?!0:r.endsWith(N0.NA)&&M.endsWith(N0.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,M]=e.toFixed(11).split(".");return+`${r}.${M.slice(0,10)}`}}class Sr{constructor(e,t,r=50){C(this,"_all");C(this,"_allInstance");C(this,"_pseudoArrayAll");C(this,"_maxLength");C(this,"_deleteIds");C(this,"_variables");C(this,"_preDeleteIds");C(this,"_againAddItems");C(this,"_tmpData");C(this,"_tmpInstance");C(this,"_type");C(this,"_tmpIds",[]);this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=p1(0,void 0,t),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}get _cacheData(){return{allInstance:Array.from(this._allInstance),tmpIds:this._tmpIds,preDeleteIds:Array.from(this._preDeleteIds)}}set _cacheData(e){this._allInstance=new Map(e.allInstance),this._all=new Map(e.allInstance.map(([t,r])=>[t,r.data])),this._tmpIds=e.tmpIds,this._preDeleteIds=new Map(e.preDeleteIds)}setMaxLen(e){this._maxLength=e}get size(){return this._all.size+this._tmpData.size}get __allInstance(){return this._allInstance}get data(){const e=[],t=b2.flatMap([...this._deleteIds.values()]),r=b2.uniq([...this._tmpData.keys(),...this._all.keys()]),M=[];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&&!M.includes(z)&&(M.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===N0.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!==N0.LINEFILL&&this._all.size>this._maxLength){const{bar_index:M}=t;for(const[n,b]of this._all){const{isVar:z,id:i,bar_index:c}=b;if(c===M)break;if(z)continue;this.deleteHandle(i);break}}}getValOfBarIndex(e){let t=[];const r=b2.uniq([...this._all.keys(),...this._tmpData.keys()]),M=b2.flatMap([...this._deleteIds.values()]);for(const n of e){const b=r.filter(z=>z.endsWith(`_${n}`));for(const z of b){if(M.some(c=>c.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===N0.LINEFILL?t:t.slice(-this._maxLength):void 0}getDeleteIds(e){let t=[];const{bar_index:r,_isRealTimeBar:M}=this._variables,n=[];for(const z of e){let i=[...this._deleteIds.get(z)||[]];const c=this._preDeleteIds.get(z)||[];if(z===r&&M){let O=[];for(const s of c){const u=i.findIndex(l=>l.id===s.id);if(u===-1){const l=this._all.get(s.key);l&&n.push(l)}else O.push(s),i.splice(u,1)}this._preDeleteIds.set(r,b2.uniqBy([...i,...O],"id"))}else{const O=[];for(const s of i)c.some(u=>u.id===s.id)||O.push(s);i=O,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,b2.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,r=!1){var M;if(this._type===N0.LINE&&t){const n=(M=this._allInstance.get(e))==null?void 0:M.fillKeys;if(n&&n.length)for(const b of n)this._variables.linefill.deleteHandle(b)}if(this._variables._isRealTimeBar){if(r){const n=this._tmpInstance.get(e);n&&(n.data=void 0)}this._tmpData.delete(e),this._tmpInstance.delete(e)}else{if(r){const n=this._allInstance.get(e);n&&(n.data=void 0)}this._all.delete(e),this._allInstance.delete(e)}}delete(e,t,r){const M=this._all.get(e);if(this._variables._isRealTimeBar||this.deleteHandle(e,!1,!0),!(this._variables.__isFirstRun&&!this._variables._isRealTimeBar)&&typeof t=="number"){const n=this._deleteIds.get(t)||[];n.push({key:e,id:(M==null?void 0:M.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
|