@guihz/trading-vue-editor-tes 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,7 +59,7 @@ ${Js}rows: ${i.rows}
59
59
  ${Js}columns: ${i.columns}
60
60
  }`}function __(i,t,e,r,n){const{rows:s,columns:a}=i,l=Math.min(s,t),f=Math.min(a,e),h=[];if(n==="auto"){n=!1;t:for(let p=0;p<l;p++)for(let c=0;c<f;c++)if(i.get(p,c)<0){n=!0;break t}}for(let p=0;p<l;p++){let c=[];for(let d=0;d<f;d++)c.push(w_(i.get(p,d),r,n));h.push(`${c.join(" ")}`)}return f!==a&&(h[h.length-1]+=` ... ${a-e} more columns`),l!==s&&h.push(`... ${s-t} more rows`),h.join(`
61
61
  ${Bc}`)}function w_(i,t,e){return(i>=0&&e?` ${Tc(i,t-1)}`:Tc(i,t)).padEnd(t)}function Tc(i,t){let e=i.toString();if(e.length<=t)return e;let r=i.toFixed(t);if(r.length>t&&(r=i.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=i.toExponential(t);return n.length>t&&(n=i.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function D_(i,t){i.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},i.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r);return this},i.prototype.addM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r.get(n,s));return this},i.add=function(r,n){return new t(r).add(n)},i.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},i.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r);return this},i.prototype.subM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r.get(n,s));return this},i.sub=function(r,n){return new t(r).sub(n)},i.prototype.subtract=i.prototype.sub,i.prototype.subtractS=i.prototype.subS,i.prototype.subtractM=i.prototype.subM,i.subtract=i.sub,i.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},i.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r);return this},i.prototype.mulM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r.get(n,s));return this},i.mul=function(r,n){return new t(r).mul(n)},i.prototype.multiply=i.prototype.mul,i.prototype.multiplyS=i.prototype.mulS,i.prototype.multiplyM=i.prototype.mulM,i.multiply=i.mul,i.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},i.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r);return this},i.prototype.divM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r.get(n,s));return this},i.div=function(r,n){return new t(r).div(n)},i.prototype.divide=i.prototype.div,i.prototype.divideS=i.prototype.divS,i.prototype.divideM=i.prototype.divM,i.divide=i.div,i.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},i.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r);return this},i.prototype.modM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r.get(n,s));return this},i.mod=function(r,n){return new t(r).mod(n)},i.prototype.modulus=i.prototype.mod,i.prototype.modulusS=i.prototype.modS,i.prototype.modulusM=i.prototype.modM,i.modulus=i.mod,i.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},i.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r);return this},i.prototype.andM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r.get(n,s));return this},i.and=function(r,n){return new t(r).and(n)},i.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},i.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r);return this},i.prototype.orM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r.get(n,s));return this},i.or=function(r,n){return new t(r).or(n)},i.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},i.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r);return this},i.prototype.xorM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r.get(n,s));return this},i.xor=function(r,n){return new t(r).xor(n)},i.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},i.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r);return this},i.prototype.leftShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r.get(n,s));return this},i.leftShift=function(r,n){return new t(r).leftShift(n)},i.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},i.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r);return this},i.prototype.signPropagatingRightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r.get(n,s));return this},i.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},i.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},i.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r);return this},i.prototype.rightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r.get(n,s));return this},i.rightShift=function(r,n){return new t(r).rightShift(n)},i.prototype.zeroFillRightShift=i.prototype.rightShift,i.prototype.zeroFillRightShiftS=i.prototype.rightShiftS,i.prototype.zeroFillRightShiftM=i.prototype.rightShiftM,i.zeroFillRightShift=i.rightShift,i.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},i.not=function(r){return new t(r).not()},i.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},i.abs=function(r){return new t(r).abs()},i.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},i.acos=function(r){return new t(r).acos()},i.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},i.acosh=function(r){return new t(r).acosh()},i.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},i.asin=function(r){return new t(r).asin()},i.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},i.asinh=function(r){return new t(r).asinh()},i.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},i.atan=function(r){return new t(r).atan()},i.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},i.atanh=function(r){return new t(r).atanh()},i.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},i.cbrt=function(r){return new t(r).cbrt()},i.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},i.ceil=function(r){return new t(r).ceil()},i.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},i.clz32=function(r){return new t(r).clz32()},i.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},i.cos=function(r){return new t(r).cos()},i.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},i.cosh=function(r){return new t(r).cosh()},i.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},i.exp=function(r){return new t(r).exp()},i.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},i.expm1=function(r){return new t(r).expm1()},i.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},i.floor=function(r){return new t(r).floor()},i.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},i.fround=function(r){return new t(r).fround()},i.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},i.log=function(r){return new t(r).log()},i.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},i.log1p=function(r){return new t(r).log1p()},i.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},i.log10=function(r){return new t(r).log10()},i.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},i.log2=function(r){return new t(r).log2()},i.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},i.round=function(r){return new t(r).round()},i.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},i.sign=function(r){return new t(r).sign()},i.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},i.sin=function(r){return new t(r).sin()},i.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},i.sinh=function(r){return new t(r).sinh()},i.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},i.sqrt=function(r){return new t(r).sqrt()},i.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},i.tan=function(r){return new t(r).tan()},i.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},i.tanh=function(r){return new t(r).tanh()},i.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},i.trunc=function(r){return new t(r).trunc()},i.pow=function(r,n){return new t(r).pow(n)},i.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},i.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r));return this},i.prototype.powM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r.get(n,s)));return this}}function gr(i,t,e){let r=e?i.rows:i.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function vr(i,t,e){let r=e?i.columns:i.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function fi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function ci(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function Su(i,t){if(!Je.isAnyArray(t))throw new TypeError("row indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.rows)throw new RangeError("row indices are out of range")}function Bu(i,t){if(!Je.isAnyArray(t))throw new TypeError("column indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.columns)throw new RangeError("column indices are out of range")}function Iu(i,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Hs("startRow",t),Hs("endRow",e),Hs("startColumn",r),Hs("endColumn",n),t>e||r>n||t<0||t>=i.rows||e<0||e>=i.rows||r<0||r>=i.columns||n<0||n>=i.columns)throw new RangeError("Submatrix indices are out of range")}function Xs(i,t=0){let e=[];for(let r=0;r<i;r++)e.push(t);return e}function Hs(i,t){if(typeof t!="number")throw new TypeError(`${i} must be a number`)}function hi(i){if(i.isEmpty())throw new Error("Empty matrix has no elements to index")}function y_(i){let t=Xs(i.rows);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]+=i.get(e,r);return t}function b_(i){let t=Xs(i.columns);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]+=i.get(e,r);return t}function E_(i){let t=0;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t+=i.get(e,r);return t}function A_(i){let t=Xs(i.rows,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]*=i.get(e,r);return t}function x_(i){let t=Xs(i.columns,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]*=i.get(e,r);return t}function C_(i){let t=1;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t*=i.get(e,r);return t}function F_(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<r;a++){let l=0,f=0,h=0;for(let p=0;p<n;p++)h=i.get(a,p)-e[a],l+=h,f+=h*h;t?s.push((f-l*l/n)/(n-1)):s.push((f-l*l/n)/n)}return s}function M_(i,t,e){const r=i.rows,n=i.columns,s=[];for(let a=0;a<n;a++){let l=0,f=0,h=0;for(let p=0;p<r;p++)h=i.get(p,a)-e[a],l+=h,f+=h*h;t?s.push((f-l*l/r)/(r-1)):s.push((f-l*l/r)/r)}return s}function N_(i,t,e){const r=i.rows,n=i.columns,s=r*n;let a=0,l=0,f=0;for(let h=0;h<r;h++)for(let p=0;p<n;p++)f=i.get(h,p)-e,a+=f,l+=f*f;return t?(l-a*a/s)/(s-1):(l-a*a/s)/s}function S_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[e])}function B_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[r])}function I_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t)}function T_(i){const t=[];for(let e=0;e<i.rows;e++){let r=0;for(let n=0;n<i.columns;n++)r+=Math.pow(i.get(e,n),2)/(i.columns-1);t.push(Math.sqrt(r))}return t}function $_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[e])}function O_(i){const t=[];for(let e=0;e<i.columns;e++){let r=0;for(let n=0;n<i.rows;n++)r+=Math.pow(i.get(n,e),2)/(i.rows-1);t.push(Math.sqrt(r))}return t}function R_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[r])}function L_(i){const t=i.size-1;let e=0;for(let r=0;r<i.columns;r++)for(let n=0;n<i.rows;n++)e+=Math.pow(i.get(n,r),2)/t;return Math.sqrt(e)}function P_(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t)}class $t{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,r[a*e+l]);return s}static rowVector(t){let e=new pt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new pt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new pt(t,e)}static ones(t,e){return new pt(t,e).fill(1)}static rand(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)s.set(a,l,n());return s}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:a=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let l=s-n,f=new pt(t,e);for(let h=0;h<t;h++)for(let p=0;p<e;p++){let c=n+Math.round(a()*l);f.set(h,p,c)}return f}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let a=0;a<n;a++)s.set(a,a,r);return s}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let s=Math.min(n,e,r),a=this.zeros(e,r);for(let l=0;l<s;l++)a.set(l,l,t[l]);return a}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new pt(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.min(t.get(a,l),e.get(a,l)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)s.set(a,l,Math.max(t.get(a,l),e.get(a,l)));return s}static checkMatrix(t){return $t.isMatrix(t)?t:new pt(t)}static isMatrix(t){return t!=null&&t.klass==="Matrix"}get size(){return this.rows*this.columns}apply(t){if(typeof t!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(this.get(t,t)!==0)return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let a=e+1;a<this.rows;a++)this.get(t,a)!==0&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let a=r;a<t.columns;a++)t.set(e,a,t.get(e,a)/s);for(let a=e+1;a<t.rows;a++){let l=t.get(a,r)/t.get(e,r);t.set(a,r,0);for(let f=r+1;f<t.columns;f++)t.set(a,f,t.get(a,f)-t.get(e,f)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let s=0,a=!1;for(;s<r&&a===!1;)t.get(n,s)===1?a=!0:s++;for(let l=0;l<n;l++){let f=t.get(l,s);for(let h=s;h<e;h++){let p=t.get(l,h)-f*t.get(n,h);t.set(l,h,p)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new pt(this.rows*e,this.columns*r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*s,this.columns*a);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){gr(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return pt.rowVector(this.getRow(t))}setRow(t,e){gr(this,t),e=fi(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){gr(this,t),gr(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){vr(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return pt.columnVector(this.getColumn(t))}setColumn(t,e){vr(this,t),e=ci(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){vr(this,t),vr(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=fi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=ci(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=ci(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=ci(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=ci(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){gr(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){vr(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){hi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}minIndex(){hi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(gr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){gr(this,t),hi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(gr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){gr(this,t),hi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){vr(this,t),hi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){vr(this,t),hi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){$t.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new pt(e,n),a=new Float64Array(r);for(let l=0;l<n;l++){for(let f=0;f<r;f++)a[f]=t.get(f,l);for(let f=0;f<e;f++){let h=0;for(let p=0;p<r;p++)h+=this.get(f,p)*a[p];s.set(f,l,h)}}return s}strassen2x2(t){t=pt.checkMatrix(t);let e=new pt(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),a=t.get(0,1),l=this.get(1,0),f=t.get(1,0),h=this.get(1,1),p=t.get(1,1),c=(r+h)*(n+p),d=(l+h)*n,_=r*(a-p),D=h*(f-n),g=(r+s)*p,y=(l-r)*(n+a),v=(s-h)*(f+p),E=c+D-g+v,b=_+g,N=d+D,x=c-d+_+y;return e.set(0,0,E),e.set(0,1,b),e.set(1,0,N),e.set(1,1,x),e}strassen3x3(t){t=pt.checkMatrix(t);let e=new pt(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),a=this.get(1,0),l=this.get(1,1),f=this.get(1,2),h=this.get(2,0),p=this.get(2,1),c=this.get(2,2),d=t.get(0,0),_=t.get(0,1),D=t.get(0,2),g=t.get(1,0),y=t.get(1,1),v=t.get(1,2),E=t.get(2,0),b=t.get(2,1),N=t.get(2,2),x=(r+n+s-a-l-p-c)*y,F=(r-a)*(-_+y),M=l*(-d+_+g-y-v-E+N),S=(-r+a+l)*(d-_+y),$=(a+l)*(-d+_),C=r*d,I=(-r+h+p)*(d-D+v),R=(-r+h)*(D-v),U=(h+p)*(-d+D),q=(r+n+s-l-f-h-p)*v,k=p*(-d+D+g-y-v-E+b),P=(-s+p+c)*(y+E-b),K=(s-c)*(y-b),j=s*E,Q=(p+c)*(-E+b),tt=(-s+l+f)*(v+E-N),ft=(s-f)*(v-N),vt=(l+f)*(-E+N),lt=n*g,wt=f*b,yt=a*D,St=h*_,bt=c*N,ee=C+j+lt,It=x+S+$+C+P+j+Q,Mt=C+I+U+q+j+tt+vt,ie=F+M+S+C+j+tt+ft,Ht=F+S+$+C+wt,zt=j+tt+ft+vt+yt,Gt=C+I+R+k+P+K+j,Ce=P+K+j+Q+St,ir=C+I+R+U+bt;return e.set(0,0,ee),e.set(0,1,It),e.set(0,2,Mt),e.set(1,0,ie),e.set(1,1,Ht),e.set(1,2,zt),e.set(2,0,Gt),e.set(2,1,Ce),e.set(2,2,ir),e}mmulStrassen(t){t=pt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,a=t.columns;n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${a} matrix: dimensions do not match.`);function l(c,d,_){let D=c.rows,g=c.columns;if(D===d&&g===_)return c;{let y=$t.zeros(d,_);return y=y.setSubMatrix(c,0,0),y}}let f=Math.max(r,s),h=Math.max(n,a);e=l(e,f,h),t=l(t,f,h);function p(c,d,_,D){if(_<=512||D<=512)return c.mmul(d);_%2===1&&D%2===1?(c=l(c,_+1,D+1),d=l(d,_+1,D+1)):_%2===1?(c=l(c,_+1,D),d=l(d,_+1,D)):D%2===1&&(c=l(c,_,D+1),d=l(d,_,D+1));let g=parseInt(c.rows/2,10),y=parseInt(c.columns/2,10),v=c.subMatrix(0,g-1,0,y-1),E=d.subMatrix(0,g-1,0,y-1),b=c.subMatrix(0,g-1,y,c.columns-1),N=d.subMatrix(0,g-1,y,d.columns-1),x=c.subMatrix(g,c.rows-1,0,y-1),F=d.subMatrix(g,d.rows-1,0,y-1),M=c.subMatrix(g,c.rows-1,y,c.columns-1),S=d.subMatrix(g,d.rows-1,y,d.columns-1),$=p($t.add(v,M),$t.add(E,S),g,y),C=p($t.add(x,M),E,g,y),I=p(v,$t.sub(N,S),g,y),R=p(M,$t.sub(F,E),g,y),U=p($t.add(v,b),S,g,y),q=p($t.sub(x,v),$t.add(E,N),g,y),k=p($t.sub(b,M),$t.add(F,S),g,y),P=$t.add($,R);P.sub(U),P.add(k);let K=$t.add(I,U),j=$t.add(C,R),Q=$t.sub($,C);Q.add(I),Q.add(q);let tt=$t.zeros(2*P.rows,2*P.columns);return tt=tt.setSubMatrix(P,0,0),tt=tt.setSubMatrix(K,P.rows,0),tt=tt.setSubMatrix(j,0,P.columns),tt=tt.setSubMatrix(Q,P.rows,P.columns),tt.subMatrix(0,_-1,0,D-1)}return p(e,t,f,h)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.rows;s++){const a=this.getRow(s);a.length>0&&Sc(a,{min:e,max:r,output:a}),n.setRow(s,a)}return n}scaleColumns(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.columns;s++){const a=this.getColumn(s);a.length&&Sc(a,{min:e,max:r,output:a}),n.setColumn(s,a)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let n=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,n)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let n=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,n)}return this}kroneckerProduct(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,a=new pt(e*n,r*s);for(let l=0;l<e;l++)for(let f=0;f<r;f++)for(let h=0;h<n;h++)for(let p=0;p<s;p++)a.set(n*l+h,s*f+p,this.get(l,f)*t.get(h,p));return a}kroneckerSum(t){if(t=pt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(pt.eye(r,r)),s=pt.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new pt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=$c){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=$c){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Iu(this,t,e,r,n);let s=new pt(e-t+1,n-r+1);for(let a=t;a<=e;a++)for(let l=r;l<=n;l++)s.set(a-t,l-r,this.get(a,l));return s}subMatrixRow(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new pt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,a-e,this.get(t[s],a))}return n}subMatrixColumn(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new pt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let a=e;a<=r;a++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(a-e,s,this.get(a,t[s]))}return n}setSubMatrix(t,e,r){if(t=pt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,s=r+t.columns-1;Iu(this,e,n,r,s);for(let a=0;a<t.rows;a++)for(let l=0;l<t.columns;l++)this.set(e+a,r+l,t.get(a,l));return this}selection(t,e){Su(this,t),Bu(this,e);let r=new pt(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let a=0;a<e.length;a++){let l=e[a];r.set(n,a,this.get(s,l))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new pt(this.rows,this.columns))}static copy(t,e){for(const[r,n,s]of t.entries())e.set(r,n,s);return e}sum(t){switch(t){case"row":return y_(this);case"column":return b_(this);case void 0:return E_(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return A_(this);case"column":return x_(this);case void 0:return C_(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":{for(let r=0;r<this.rows;r++)e[r]/=this.columns;return e}case"column":{for(let r=0;r<this.columns;r++)e[r]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(t){case"row":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return F_(this,r,n)}case"column":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return M_(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return N_(this,r,n)}default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){typeof t=="object"&&(e=t,t=void 0);const r=this.variance(t,e);if(t===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return S_(this,r),this}case"column":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return B_(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return I_(this,r),this}default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":{if(r===void 0)r=T_(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return $_(this,r),this}case"column":{if(r===void 0)r=O_(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return R_(this,r),this}case void 0:{if(r===void 0)r=L_(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return P_(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return Ic(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}$t.prototype.klass="Matrix",typeof Symbol<"u"&&($t.prototype[Symbol.for("nodejs.util.inspect.custom")]=v_);function $c(i,t){return i-t}function z_(i){return i.every(t=>typeof t=="number")}$t.random=$t.rand,$t.randomInt=$t.randInt,$t.diagonal=$t.diag,$t.prototype.diagonal=$t.prototype.diag,$t.identity=$t.eye,$t.prototype.negate=$t.prototype.neg,$t.prototype.tensorProduct=$t.prototype.kroneckerProduct;let pt=(vi=class extends $t{constructor(e,r){super();Dl(this,Gi);G(this,"data");if(vi.isMatrix(e))yl(this,Gi,bl).call(this,e.rows,e.columns),vi.copy(e,this);else if(Number.isInteger(e)&&e>=0)yl(this,Gi,bl).call(this,e,r);else if(Je.isAnyArray(e)){const n=e;if(e=n.length,r=e?n[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<e;s++){if(n[s].length!==r)throw new RangeError("Inconsistent array dimensions");if(!z_(n[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[s]))}this.rows=e,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(e,r,n){return this.data[e][r]=n,this}get(e,r){return this.data[e][r]}removeRow(e){return gr(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),gr(this,e,!0),r=Float64Array.from(fi(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){vr(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let s=0;s<e;s++)n[s]=this.data[r][s];for(let s=e+1;s<this.columns;s++)n[s-1]=this.data[r][s];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),vr(this,e,!0),r=ci(this,r);for(let n=0;n<this.rows;n++){const s=new Float64Array(this.columns+1);let a=0;for(;a<e;a++)s[a]=this.data[n][a];for(s[a++]=r[n];a<this.columns+1;a++)s[a]=this.data[n][a-1];this.data[n]=s}return this.columns+=1,this}},Gi=new WeakSet,bl=function(e,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=r},vi);D_($t,pt);const lo=class lo extends $t{constructor(e){super();Dl(this,qe,void 0);if(pt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");eu(this,qe,pt.copy(e,new pt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)eu(this,qe,new pt(e,e));else if(eu(this,qe,new pt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Rr(this,qe).size}get rows(){return Rr(this,qe).rows}get columns(){return Rr(this,qe).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return pt.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new lo(this.diagonalSize);for(const[r,n,s]of this.upperRightEntries())e.set(r,n,s);return e}toMatrix(){return new pt(this)}get(e,r){return Rr(this,qe).get(e,r)}set(e,r,n){return Rr(this,qe).set(e,r,n),Rr(this,qe).set(r,e,n),this}removeCross(e){return Rr(this,qe).removeRow(e),Rr(this,qe).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Rr(this,qe).addRow(e,n),Rr(this,qe).addColumn(e,r),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,s]of e.entries())s||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,r=new Array(e*(e+1)/2);for(let n=0,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=e&&(n=++s);return r}static fromCompact(e){const r=e.length,n=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(e)}`);const s=new lo(n);for(let a=0,l=0,f=0;f<r;f++)s.set(a,l,e[f]),++a>=n&&(a=++l);return s}*upperRightEntries(){for(let e=0,r=0;e<this.diagonalSize;void 0){const n=this.get(e,r);yield[e,r,n],++r>=this.diagonalSize&&(r=++e)}}*upperRightValues(){for(let e=0,r=0;e<this.diagonalSize;void 0)yield this.get(e,r),++r>=this.diagonalSize&&(r=++e)}};qe=new WeakMap;let Pn=lo;Pn.prototype.klassType="SymmetricMatrix";class Qs extends Pn{static isDistanceMatrix(t){return Pn.isSymmetricMatrix(t)&&t.klassSubType==="DistanceMatrix"}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return e===void 0&&(e=t,t=this.diagonalSize),e=e.slice(),e[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new Pn(this)}clone(){const t=new Qs(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=(t-1)*t/2,r=new Array(e);for(let n=1,s=0,a=0;a<r.length;a++)r[a]=this.get(s,n),++n>=t&&(n=++s+1);return r}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let s=1,a=0,l=0;l<e;l++)n.set(s,a,t[l]),++s>=r&&(s=++a+1);return n}}Qs.prototype.klassSubType="DistanceMatrix";class Kr extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class q_ extends Kr{constructor(t,e){vr(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class U_ extends Kr{constructor(t,e){Bu(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class k_ extends Kr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class W_ extends Kr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class Y_ extends Kr{constructor(t,e){gr(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class Z_ extends Kr{constructor(t,e){Su(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class Vs extends Kr{constructor(t,e,r){Su(t,e),Bu(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class j_ extends Kr{constructor(t,e,r,n,s){Iu(t,e,r,n,s),super(t,r-e+1,s-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class G_ extends Kr{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class Oc extends $t{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class nr extends $t{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function K_(i,t){if(Je.isAnyArray(i))return i[0]&&Je.isAnyArray(i[0])?new nr(i):new Oc(i,t);throw new Error("the argument is not an array")}class to{constructor(t){t=nr.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,s=new Float64Array(r),a=1,l,f,h,p,c,d,_,D,g;for(l=0;l<r;l++)s[l]=l;for(D=new Float64Array(r),f=0;f<n;f++){for(l=0;l<r;l++)D[l]=e.get(l,f);for(l=0;l<r;l++){for(g=Math.min(l,f),c=0,h=0;h<g;h++)c+=e.get(l,h)*D[h];D[l]-=c,e.set(l,f,D[l])}for(p=f,l=f+1;l<r;l++)Math.abs(D[l])>Math.abs(D[p])&&(p=l);if(p!==f){for(h=0;h<n;h++)d=e.get(p,h),e.set(p,h,e.get(f,h)),e.set(f,h,d);_=s[p],s[p]=s[f],s[f]=_,a=-a}if(f<r&&e.get(f,f)!==0)for(l=f+1;l<r;l++)e.set(l,f,e.get(l,f)/e.get(f,f))}this.LU=e,this.pivotVector=s,this.pivotSign=a}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(t.get(r,r)===0)return!0;return!1}solve(t){t=pt.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=t.columns,s=t.subMatrixRow(this.pivotVector,0,n-1),a=e.columns,l,f,h;for(h=0;h<a;h++)for(l=h+1;l<a;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(h,f)*e.get(l,h));for(h=a-1;h>=0;h--){for(f=0;f<n;f++)s.set(h,f,s.get(h,f)/e.get(h,h));for(l=0;l<h;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(h,f)*e.get(l,h))}return s}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s>a?n.set(s,a,t.get(s,a)):s===a?n.set(s,a,1):n.set(s,a,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let a=0;a<r;a++)s<=a?n.set(s,a,t.get(s,a)):n.set(s,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Jr(i,t){let e=0;return Math.abs(i)>Math.abs(t)?(e=t/i,Math.abs(i)*Math.sqrt(1+e*e)):t!==0?(e=i/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class Tu{constructor(t){t=nr.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,s=new Float64Array(n),a,l,f,h;for(f=0;f<n;f++){let p=0;for(a=f;a<r;a++)p=Jr(p,e.get(a,f));if(p!==0){for(e.get(f,f)<0&&(p=-p),a=f;a<r;a++)e.set(a,f,e.get(a,f)/p);for(e.set(f,f,e.get(f,f)+1),l=f+1;l<n;l++){for(h=0,a=f;a<r;a++)h+=e.get(a,f)*e.get(a,l);for(h=-h/e.get(f,f),a=f;a<r;a++)e.set(a,l,e.get(a,l)+h*e.get(a,f))}}s[f]=-p}this.QR=e,this.Rdiag=s}solve(t){t=pt.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=t.columns,s=t.clone(),a=e.columns,l,f,h,p;for(h=0;h<a;h++)for(f=0;f<n;f++){for(p=0,l=h;l<r;l++)p+=e.get(l,h)*s.get(l,f);for(p=-p/e.get(h,h),l=h;l<r;l++)s.set(l,f,s.get(l,f)+p*e.get(l,h))}for(h=a-1;h>=0;h--){for(f=0;f<n;f++)s.set(h,f,s.get(h,f)/this.Rdiag[h]);for(l=0;l<h;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(h,f)*e.get(l,h))}return s.subMatrix(0,a-1,0,n-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let t=this.QR,e=t.columns,r=new pt(e,e),n,s;for(n=0;n<e;n++)for(s=0;s<e;s++)n<s?r.set(n,s,t.get(n,s)):n===s?r.set(n,s,this.Rdiag[n]):r.set(n,s,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new pt(e,r),s,a,l,f;for(l=r-1;l>=0;l--){for(s=0;s<e;s++)n.set(s,l,0);for(n.set(l,l,1),a=l;a<r;a++)if(t.get(l,l)!==0){for(f=0,s=l;s<e;s++)f+=t.get(s,l)*n.get(s,a);for(f=-f/t.get(l,l),s=l;s<e;s++)n.set(s,a,n.get(s,a)+f*t.get(s,l))}}return n}}class pi{constructor(t,e={}){if(t=nr.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:a=!0,autoTranspose:l=!1}=e;let f=!!s,h=!!a,p=!1,c;if(r<n)if(!l)c=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{c=t.transpose(),r=c.rows,n=c.columns,p=!0;let C=f;f=h,h=C}else c=t.clone();let d=Math.min(r,n),_=Math.min(r+1,n),D=new Float64Array(_),g=new pt(r,d),y=new pt(n,n),v=new Float64Array(n),E=new Float64Array(r),b=new Float64Array(_);for(let C=0;C<_;C++)b[C]=C;let N=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),F=Math.max(N,x);for(let C=0;C<F;C++){if(C<N){D[C]=0;for(let I=C;I<r;I++)D[C]=Jr(D[C],c.get(I,C));if(D[C]!==0){c.get(C,C)<0&&(D[C]=-D[C]);for(let I=C;I<r;I++)c.set(I,C,c.get(I,C)/D[C]);c.set(C,C,c.get(C,C)+1)}D[C]=-D[C]}for(let I=C+1;I<n;I++){if(C<N&&D[C]!==0){let R=0;for(let U=C;U<r;U++)R+=c.get(U,C)*c.get(U,I);R=-R/c.get(C,C);for(let U=C;U<r;U++)c.set(U,I,c.get(U,I)+R*c.get(U,C))}v[I]=c.get(C,I)}if(f&&C<N)for(let I=C;I<r;I++)g.set(I,C,c.get(I,C));if(C<x){v[C]=0;for(let I=C+1;I<n;I++)v[C]=Jr(v[C],v[I]);if(v[C]!==0){v[C+1]<0&&(v[C]=0-v[C]);for(let I=C+1;I<n;I++)v[I]/=v[C];v[C+1]+=1}if(v[C]=-v[C],C+1<r&&v[C]!==0){for(let I=C+1;I<r;I++)E[I]=0;for(let I=C+1;I<r;I++)for(let R=C+1;R<n;R++)E[I]+=v[R]*c.get(I,R);for(let I=C+1;I<n;I++){let R=-v[I]/v[C+1];for(let U=C+1;U<r;U++)c.set(U,I,c.get(U,I)+R*E[U])}}if(h)for(let I=C+1;I<n;I++)y.set(I,C,v[I])}}let M=Math.min(n,r+1);if(N<n&&(D[N]=c.get(N,N)),r<M&&(D[M-1]=0),x+1<M&&(v[x]=c.get(x,M-1)),v[M-1]=0,f){for(let C=N;C<d;C++){for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}for(let C=N-1;C>=0;C--)if(D[C]!==0){for(let I=C+1;I<d;I++){let R=0;for(let U=C;U<r;U++)R+=g.get(U,C)*g.get(U,I);R=-R/g.get(C,C);for(let U=C;U<r;U++)g.set(U,I,g.get(U,I)+R*g.get(U,C))}for(let I=C;I<r;I++)g.set(I,C,-g.get(I,C));g.set(C,C,1+g.get(C,C));for(let I=0;I<C-1;I++)g.set(I,C,0)}else{for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}}if(h)for(let C=n-1;C>=0;C--){if(C<x&&v[C]!==0)for(let I=C+1;I<n;I++){let R=0;for(let U=C+1;U<n;U++)R+=y.get(U,C)*y.get(U,I);R=-R/y.get(C+1,C);for(let U=C+1;U<n;U++)y.set(U,I,y.get(U,I)+R*y.get(U,C))}for(let I=0;I<n;I++)y.set(I,C,0);y.set(C,C,1)}let S=M-1,$=Number.EPSILON;for(;M>0;){let C,I;for(C=M-2;C>=-1&&C!==-1;C--){const R=Number.MIN_VALUE+$*Math.abs(D[C]+Math.abs(D[C+1]));if(Math.abs(v[C])<=R||Number.isNaN(v[C])){v[C]=0;break}}if(C===M-2)I=4;else{let R;for(R=M-1;R>=C&&R!==C;R--){let U=(R!==M?Math.abs(v[R]):0)+(R!==C+1?Math.abs(v[R-1]):0);if(Math.abs(D[R])<=$*U){D[R]=0;break}}R===C?I=3:R===M-1?I=1:(I=2,C=R)}switch(C++,I){case 1:{let R=v[M-2];v[M-2]=0;for(let U=M-2;U>=C;U--){let q=Jr(D[U],R),k=D[U]/q,P=R/q;if(D[U]=q,U!==C&&(R=-P*v[U-1],v[U-1]=k*v[U-1]),h)for(let K=0;K<n;K++)q=k*y.get(K,U)+P*y.get(K,M-1),y.set(K,M-1,-P*y.get(K,U)+k*y.get(K,M-1)),y.set(K,U,q)}break}case 2:{let R=v[C-1];v[C-1]=0;for(let U=C;U<M;U++){let q=Jr(D[U],R),k=D[U]/q,P=R/q;if(D[U]=q,R=-P*v[U],v[U]=k*v[U],f)for(let K=0;K<r;K++)q=k*g.get(K,U)+P*g.get(K,C-1),g.set(K,C-1,-P*g.get(K,U)+k*g.get(K,C-1)),g.set(K,U,q)}break}case 3:{const R=Math.max(Math.abs(D[M-1]),Math.abs(D[M-2]),Math.abs(v[M-2]),Math.abs(D[C]),Math.abs(v[C])),U=D[M-1]/R,q=D[M-2]/R,k=v[M-2]/R,P=D[C]/R,K=v[C]/R,j=((q+U)*(q-U)+k*k)/2,Q=U*k*(U*k);let tt=0;(j!==0||Q!==0)&&(j<0?tt=0-Math.sqrt(j*j+Q):tt=Math.sqrt(j*j+Q),tt=Q/(j+tt));let ft=(P+U)*(P-U)+tt,vt=P*K;for(let lt=C;lt<M-1;lt++){let wt=Jr(ft,vt);wt===0&&(wt=Number.MIN_VALUE);let yt=ft/wt,St=vt/wt;if(lt!==C&&(v[lt-1]=wt),ft=yt*D[lt]+St*v[lt],v[lt]=yt*v[lt]-St*D[lt],vt=St*D[lt+1],D[lt+1]=yt*D[lt+1],h)for(let bt=0;bt<n;bt++)wt=yt*y.get(bt,lt)+St*y.get(bt,lt+1),y.set(bt,lt+1,-St*y.get(bt,lt)+yt*y.get(bt,lt+1)),y.set(bt,lt,wt);if(wt=Jr(ft,vt),wt===0&&(wt=Number.MIN_VALUE),yt=ft/wt,St=vt/wt,D[lt]=wt,ft=yt*v[lt]+St*D[lt+1],D[lt+1]=-St*v[lt]+yt*D[lt+1],vt=St*v[lt+1],v[lt+1]=yt*v[lt+1],f&&lt<r-1)for(let bt=0;bt<r;bt++)wt=yt*g.get(bt,lt)+St*g.get(bt,lt+1),g.set(bt,lt+1,-St*g.get(bt,lt)+yt*g.get(bt,lt+1)),g.set(bt,lt,wt)}v[M-2]=ft;break}case 4:{if(D[C]<=0&&(D[C]=D[C]<0?-D[C]:0,h))for(let R=0;R<=S;R++)y.set(R,C,-y.get(R,C));for(;C<S&&!(D[C]>=D[C+1]);){let R=D[C];if(D[C]=D[C+1],D[C+1]=R,h&&C<n-1)for(let U=0;U<n;U++)R=y.get(U,C+1),y.set(U,C+1,y.get(U,C)),y.set(U,C,R);if(f&&C<r-1)for(let U=0;U<r;U++)R=g.get(U,C+1),g.set(U,C+1,g.get(U,C)),g.set(U,C,R);C++}M--;break}}}if(p){let C=y;y=g,g=C}this.m=r,this.n=n,this.s=D,this.U=g,this.V=y}solve(t){let e=t,r=this.threshold,n=this.s.length,s=pt.zeros(n,n);for(let d=0;d<n;d++)Math.abs(this.s[d])<=r?s.set(d,d,0):s.set(d,d,1/this.s[d]);let a=this.U,l=this.rightSingularVectors,f=l.mmul(s),h=l.rows,p=a.rows,c=pt.zeros(h,p);for(let d=0;d<h;d++)for(let _=0;_<p;_++){let D=0;for(let g=0;g<n;g++)D+=f.get(d,g)*a.get(_,g);c.set(d,_,D)}return c.mmul(e)}solveForDiagonal(t){return this.solve(pt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new pt(r,this.s.length);for(let p=0;p<r;p++)for(let c=0;c<n;c++)Math.abs(this.s[c])>e&&s.set(p,c,t.get(p,c)/this.s[c]);let a=this.U,l=a.rows,f=a.columns,h=new pt(r,l);for(let p=0;p<r;p++)for(let c=0;c<l;c++){let d=0;for(let _=0;_<f;_++)d+=s.get(p,_)*a.get(c,_);h.set(p,c,d)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return pt.diag(this.s)}}function J_(i,t=!1){return i=nr.checkMatrix(i),t?new pi(i).inverse():Rc(i,pt.eye(i.rows))}function Rc(i,t,e=!1){return i=nr.checkMatrix(i),t=nr.checkMatrix(t),e?new pi(i).solve(t):i.isSquare()?new to(i).solve(t):new Tu(i).solve(t)}function eo(i){if(i=pt.checkMatrix(i),i.isSquare()){if(i.columns===0)return 1;let t,e,r,n;if(i.columns===2)return t=i.get(0,0),e=i.get(0,1),r=i.get(1,0),n=i.get(1,1),t*n-e*r;if(i.columns===3){let s,a,l;return s=new Vs(i,[1,2],[1,2]),a=new Vs(i,[1,2],[0,2]),l=new Vs(i,[1,2],[0,1]),t=i.get(0,0),e=i.get(0,1),r=i.get(0,2),t*eo(s)-e*eo(a)+r*eo(l)}else return new to(i).determinant}else throw Error("determinant can only be calculated for a square matrix")}function X_(i,t){let e=[];for(let r=0;r<i;r++)r!==t&&e.push(r);return e}function H_(i,t,e,r=1e-9,n=1e-9){if(i>n)return new Array(t.rows+1).fill(0);{let s=t.addRow(e,[0]);for(let a=0;a<s.rows;a++)Math.abs(s.get(a,0))<r&&s.set(a,0,0);return s.to1DArray()}}function Q_(i,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;i=pt.checkMatrix(i);let n=i.rows,s=new pt(n,n);for(let a=0;a<n;a++){let l=pt.columnVector(i.getRow(a)),f=i.subMatrixRow(X_(n,a)).transpose(),p=new pi(f).solve(l),c=pt.sub(l,f.mmul(p)).abs().max();s.setRow(a,H_(c,p,a,e,r))}return s}function V_(i,t=Number.EPSILON){if(i=pt.checkMatrix(i),i.isEmpty())return i.transpose();let e=new pi(i,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,s=e.diagonal;for(let a=0;a<s.length;a++)Math.abs(s[a])>t?s[a]=1/s[a]:s[a]=0;return n.mmul(pt.diag(s).mmul(r.transpose()))}function tw(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(i=i.center("column"),r||(t=t.center("column")));const s=i.transpose().mmul(t);for(let a=0;a<s.rows;a++)for(let l=0;l<s.columns;l++)s.set(a,l,s.get(a,l)*(1/(i.rows-1)));return s}function ew(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=e;n&&(i.center("column"),r||t.center("column")),s&&(i.scale("column"),r||t.scale("column"));const a=i.standardDeviation("column",{unbiased:!0}),l=r?a:t.standardDeviation("column",{unbiased:!0}),f=i.transpose().mmul(t);for(let h=0;h<f.rows;h++)for(let p=0;p<f.columns;p++)f.set(h,p,f.get(h,p)*(1/(a[h]*l[p]))*(1/(i.rows-1)));return f}let Lc=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=nr.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n=t.columns,s=new pt(n,n),a=new Float64Array(n),l=new Float64Array(n),f=t,h,p,c=!1;if(r?c=!0:c=t.isSymmetric(),c){for(h=0;h<n;h++)for(p=0;p<n;p++)s.set(h,p,f.get(h,p));rw(n,l,a,s),nw(n,l,a,s)}else{let d=new pt(n,n),_=new Float64Array(n);for(p=0;p<n;p++)for(h=0;h<n;h++)d.set(h,p,f.get(h,p));iw(n,d,_,s),sw(n,l,a,s,d)}this.n=n,this.e=l,this.d=a,this.V=s}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new pt(t,t),s,a;for(s=0;s<t;s++){for(a=0;a<t;a++)n.set(s,a,0);n.set(s,s,r[s]),e[s]>0?n.set(s,s+1,e[s]):e[s]<0&&n.set(s,s-1,e[s])}return n}};function rw(i,t,e,r){let n,s,a,l,f,h,p,c;for(f=0;f<i;f++)e[f]=r.get(i-1,f);for(l=i-1;l>0;l--){for(c=0,a=0,h=0;h<l;h++)c=c+Math.abs(e[h]);if(c===0)for(t[l]=e[l-1],f=0;f<l;f++)e[f]=r.get(l-1,f),r.set(l,f,0),r.set(f,l,0);else{for(h=0;h<l;h++)e[h]/=c,a+=e[h]*e[h];for(n=e[l-1],s=Math.sqrt(a),n>0&&(s=-s),t[l]=c*s,a=a-n*s,e[l-1]=n-s,f=0;f<l;f++)t[f]=0;for(f=0;f<l;f++){for(n=e[f],r.set(f,l,n),s=t[f]+r.get(f,f)*n,h=f+1;h<=l-1;h++)s+=r.get(h,f)*e[h],t[h]+=r.get(h,f)*n;t[f]=s}for(n=0,f=0;f<l;f++)t[f]/=a,n+=t[f]*e[f];for(p=n/(a+a),f=0;f<l;f++)t[f]-=p*e[f];for(f=0;f<l;f++){for(n=e[f],s=t[f],h=f;h<=l-1;h++)r.set(h,f,r.get(h,f)-(n*t[h]+s*e[h]));e[f]=r.get(l-1,f),r.set(l,f,0)}}e[l]=a}for(l=0;l<i-1;l++){if(r.set(i-1,l,r.get(l,l)),r.set(l,l,1),a=e[l+1],a!==0){for(h=0;h<=l;h++)e[h]=r.get(h,l+1)/a;for(f=0;f<=l;f++){for(s=0,h=0;h<=l;h++)s+=r.get(h,l+1)*r.get(h,f);for(h=0;h<=l;h++)r.set(h,f,r.get(h,f)-s*e[h])}}for(h=0;h<=l;h++)r.set(h,l+1,0)}for(f=0;f<i;f++)e[f]=r.get(i-1,f),r.set(i-1,f,0);r.set(i-1,i-1,1),t[0]=0}function nw(i,t,e,r){let n,s,a,l,f,h,p,c,d,_,D,g,y,v,E,b;for(a=1;a<i;a++)t[a-1]=t[a];t[i-1]=0;let N=0,x=0,F=Number.EPSILON;for(h=0;h<i;h++){for(x=Math.max(x,Math.abs(e[h])+Math.abs(t[h])),p=h;p<i&&!(Math.abs(t[p])<=F*x);)p++;if(p>h)do{for(n=e[h],c=(e[h+1]-n)/(2*t[h]),d=Jr(c,1),c<0&&(d=-d),e[h]=t[h]/(c+d),e[h+1]=t[h]*(c+d),_=e[h+1],s=n-e[h],a=h+2;a<i;a++)e[a]-=s;for(N=N+s,c=e[p],D=1,g=D,y=D,v=t[h+1],E=0,b=0,a=p-1;a>=h;a--)for(y=g,g=D,b=E,n=D*t[a],s=D*c,d=Jr(c,t[a]),t[a+1]=E*d,E=t[a]/d,D=c/d,c=D*e[a]-E*n,e[a+1]=s+E*(D*n+E*e[a]),f=0;f<i;f++)s=r.get(f,a+1),r.set(f,a+1,E*r.get(f,a)+D*s),r.set(f,a,D*r.get(f,a)-E*s);c=-E*b*y*v*t[h]/_,t[h]=E*c,e[h]=D*c}while(Math.abs(t[h])>F*x);e[h]=e[h]+N,t[h]=0}for(a=0;a<i-1;a++){for(f=a,c=e[a],l=a+1;l<i;l++)e[l]<c&&(f=l,c=e[l]);if(f!==a)for(e[f]=e[a],e[a]=c,l=0;l<i;l++)c=r.get(l,a),r.set(l,a,r.get(l,f)),r.set(l,f,c)}}function iw(i,t,e,r){let n=0,s=i-1,a,l,f,h,p,c,d;for(c=n+1;c<=s-1;c++){for(d=0,h=c;h<=s;h++)d=d+Math.abs(t.get(h,c-1));if(d!==0){for(f=0,h=s;h>=c;h--)e[h]=t.get(h,c-1)/d,f+=e[h]*e[h];for(l=Math.sqrt(f),e[c]>0&&(l=-l),f=f-e[c]*l,e[c]=e[c]-l,p=c;p<i;p++){for(a=0,h=s;h>=c;h--)a+=e[h]*t.get(h,p);for(a=a/f,h=c;h<=s;h++)t.set(h,p,t.get(h,p)-a*e[h])}for(h=0;h<=s;h++){for(a=0,p=s;p>=c;p--)a+=e[p]*t.get(h,p);for(a=a/f,p=c;p<=s;p++)t.set(h,p,t.get(h,p)-a*e[p])}e[c]=d*e[c],t.set(c,c-1,d*l)}}for(h=0;h<i;h++)for(p=0;p<i;p++)r.set(h,p,h===p?1:0);for(c=s-1;c>=n+1;c--)if(t.get(c,c-1)!==0){for(h=c+1;h<=s;h++)e[h]=t.get(h,c-1);for(p=c;p<=s;p++){for(l=0,h=c;h<=s;h++)l+=e[h]*r.get(h,p);for(l=l/e[c]/t.get(c,c-1),h=c;h<=s;h++)r.set(h,p,r.get(h,p)+l*e[h])}}}function sw(i,t,e,r,n){let s=i-1,a=0,l=i-1,f=Number.EPSILON,h=0,p=0,c=0,d=0,_=0,D=0,g=0,y=0,v,E,b,N,x,F,M,S,$,C,I,R,U,q,k;for(v=0;v<i;v++)for((v<a||v>l)&&(e[v]=n.get(v,v),t[v]=0),E=Math.max(v-1,0);E<i;E++)p=p+Math.abs(n.get(v,E));for(;s>=a;){for(N=s;N>a&&(D=Math.abs(n.get(N-1,N-1))+Math.abs(n.get(N,N)),D===0&&(D=p),!(Math.abs(n.get(N,N-1))<f*D));)N--;if(N===s)n.set(s,s,n.get(s,s)+h),e[s]=n.get(s,s),t[s]=0,s--,y=0;else if(N===s-1){if(M=n.get(s,s-1)*n.get(s-1,s),c=(n.get(s-1,s-1)-n.get(s,s))/2,d=c*c+M,g=Math.sqrt(Math.abs(d)),n.set(s,s,n.get(s,s)+h),n.set(s-1,s-1,n.get(s-1,s-1)+h),S=n.get(s,s),d>=0){for(g=c>=0?c+g:c-g,e[s-1]=S+g,e[s]=e[s-1],g!==0&&(e[s]=S-M/g),t[s-1]=0,t[s]=0,S=n.get(s,s-1),D=Math.abs(S)+Math.abs(g),c=S/D,d=g/D,_=Math.sqrt(c*c+d*d),c=c/_,d=d/_,E=s-1;E<i;E++)g=n.get(s-1,E),n.set(s-1,E,d*g+c*n.get(s,E)),n.set(s,E,d*n.get(s,E)-c*g);for(v=0;v<=s;v++)g=n.get(v,s-1),n.set(v,s-1,d*g+c*n.get(v,s)),n.set(v,s,d*n.get(v,s)-c*g);for(v=a;v<=l;v++)g=r.get(v,s-1),r.set(v,s-1,d*g+c*r.get(v,s)),r.set(v,s,d*r.get(v,s)-c*g)}else e[s-1]=S+c,e[s]=S+c,t[s-1]=g,t[s]=-g;s=s-2,y=0}else{if(S=n.get(s,s),$=0,M=0,N<s&&($=n.get(s-1,s-1),M=n.get(s,s-1)*n.get(s-1,s)),y===10){for(h+=S,v=a;v<=s;v++)n.set(v,v,n.get(v,v)-S);D=Math.abs(n.get(s,s-1))+Math.abs(n.get(s-1,s-2)),S=$=.75*D,M=-.4375*D*D}if(y===30&&(D=($-S)/2,D=D*D+M,D>0)){for(D=Math.sqrt(D),$<S&&(D=-D),D=S-M/(($-S)/2+D),v=a;v<=s;v++)n.set(v,v,n.get(v,v)-D);h+=D,S=$=M=.964}for(y=y+1,x=s-2;x>=N&&(g=n.get(x,x),_=S-g,D=$-g,c=(_*D-M)/n.get(x+1,x)+n.get(x,x+1),d=n.get(x+1,x+1)-g-_-D,_=n.get(x+2,x+1),D=Math.abs(c)+Math.abs(d)+Math.abs(_),c=c/D,d=d/D,_=_/D,!(x===N||Math.abs(n.get(x,x-1))*(Math.abs(d)+Math.abs(_))<f*(Math.abs(c)*(Math.abs(n.get(x-1,x-1))+Math.abs(g)+Math.abs(n.get(x+1,x+1))))));)x--;for(v=x+2;v<=s;v++)n.set(v,v-2,0),v>x+2&&n.set(v,v-3,0);for(b=x;b<=s-1&&(q=b!==s-1,b!==x&&(c=n.get(b,b-1),d=n.get(b+1,b-1),_=q?n.get(b+2,b-1):0,S=Math.abs(c)+Math.abs(d)+Math.abs(_),S!==0&&(c=c/S,d=d/S,_=_/S)),S!==0);b++)if(D=Math.sqrt(c*c+d*d+_*_),c<0&&(D=-D),D!==0){for(b!==x?n.set(b,b-1,-D*S):N!==x&&n.set(b,b-1,-n.get(b,b-1)),c=c+D,S=c/D,$=d/D,g=_/D,d=d/c,_=_/c,E=b;E<i;E++)c=n.get(b,E)+d*n.get(b+1,E),q&&(c=c+_*n.get(b+2,E),n.set(b+2,E,n.get(b+2,E)-c*g)),n.set(b,E,n.get(b,E)-c*S),n.set(b+1,E,n.get(b+1,E)-c*$);for(v=0;v<=Math.min(s,b+3);v++)c=S*n.get(v,b)+$*n.get(v,b+1),q&&(c=c+g*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-c*_)),n.set(v,b,n.get(v,b)-c),n.set(v,b+1,n.get(v,b+1)-c*d);for(v=a;v<=l;v++)c=S*r.get(v,b)+$*r.get(v,b+1),q&&(c=c+g*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-c*_)),r.set(v,b,r.get(v,b)-c),r.set(v,b+1,r.get(v,b+1)-c*d)}}}if(p!==0){for(s=i-1;s>=0;s--)if(c=e[s],d=t[s],d===0)for(N=s,n.set(s,s,1),v=s-1;v>=0;v--){for(M=n.get(v,v)-c,_=0,E=N;E<=s;E++)_=_+n.get(v,E)*n.get(E,s);if(t[v]<0)g=M,D=_;else if(N=v,t[v]===0?n.set(v,s,M!==0?-_/M:-_/(f*p)):(S=n.get(v,v+1),$=n.get(v+1,v),d=(e[v]-c)*(e[v]-c)+t[v]*t[v],F=(S*D-g*_)/d,n.set(v,s,F),n.set(v+1,s,Math.abs(S)>Math.abs(g)?(-_-M*F)/S:(-D-$*F)/g)),F=Math.abs(n.get(v,s)),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s,n.get(E,s)/F)}else if(d<0)for(N=s-1,Math.abs(n.get(s,s-1))>Math.abs(n.get(s-1,s))?(n.set(s-1,s-1,d/n.get(s,s-1)),n.set(s-1,s,-(n.get(s,s)-c)/n.get(s,s-1))):(k=ro(0,-n.get(s-1,s),n.get(s-1,s-1)-c,d),n.set(s-1,s-1,k[0]),n.set(s-1,s,k[1])),n.set(s,s-1,0),n.set(s,s,1),v=s-2;v>=0;v--){for(C=0,I=0,E=N;E<=s;E++)C=C+n.get(v,E)*n.get(E,s-1),I=I+n.get(v,E)*n.get(E,s);if(M=n.get(v,v)-c,t[v]<0)g=M,_=C,D=I;else if(N=v,t[v]===0?(k=ro(-C,-I,M,d),n.set(v,s-1,k[0]),n.set(v,s,k[1])):(S=n.get(v,v+1),$=n.get(v+1,v),R=(e[v]-c)*(e[v]-c)+t[v]*t[v]-d*d,U=(e[v]-c)*2*d,R===0&&U===0&&(R=f*p*(Math.abs(M)+Math.abs(d)+Math.abs(S)+Math.abs($)+Math.abs(g))),k=ro(S*_-g*C+d*I,S*D-g*I-d*C,R,U),n.set(v,s-1,k[0]),n.set(v,s,k[1]),Math.abs(S)>Math.abs(g)+Math.abs(d)?(n.set(v+1,s-1,(-C-M*n.get(v,s-1)+d*n.get(v,s))/S),n.set(v+1,s,(-I-M*n.get(v,s)-d*n.get(v,s-1))/S)):(k=ro(-_-$*n.get(v,s-1),-D-$*n.get(v,s),g,d),n.set(v+1,s-1,k[0]),n.set(v+1,s,k[1]))),F=Math.max(Math.abs(n.get(v,s-1)),Math.abs(n.get(v,s))),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s-1,n.get(E,s-1)/F),n.set(E,s,n.get(E,s)/F)}for(v=0;v<i;v++)if(v<a||v>l)for(E=v;E<i;E++)r.set(v,E,n.get(v,E));for(E=i-1;E>=a;E--)for(v=a;v<=l;v++){for(g=0,b=a;b<=Math.min(E,l);b++)g=g+r.get(v,b)*n.get(b,E);r.set(v,E,g)}}}function ro(i,t,e,r){let n,s;return Math.abs(e)>Math.abs(r)?(n=r/e,s=e+n*r,[(i+n*t)/s,(t-n*i)/s]):(n=e/r,s=r+n*e,[(n*i+t)/s,(n*t-i)/s])}class Pc{constructor(t){if(t=nr.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new pt(r,r),s=!0,a,l,f;for(l=0;l<r;l++){let h=0;for(f=0;f<l;f++){let p=0;for(a=0;a<f;a++)p+=n.get(f,a)*n.get(l,a);p=(e.get(l,f)-p)/n.get(f,f),n.set(l,f,p),h=h+p*p}for(h=e.get(l,l)-h,s&=h>0,n.set(l,l,Math.sqrt(Math.max(h,0))),f=l+1;f<r;f++)n.set(l,f,0)}this.L=n,this.positiveDefinite=!!s}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=nr.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=t.columns,s=t.clone(),a,l,f;for(f=0;f<r;f++)for(l=0;l<n;l++){for(a=0;a<f;a++)s.set(f,l,s.get(f,l)-s.get(a,l)*e.get(f,a));s.set(f,l,s.get(f,l)/e.get(f,f))}for(f=r-1;f>=0;f--)for(l=0;l<n;l++){for(a=f+1;a<r;a++)s.set(f,l,s.get(f,l)-s.get(a,l)*e.get(a,f));s.set(f,l,s.get(f,l)/e.get(f,f))}return s}get lowerTriangularMatrix(){return this.L}}class zc{constructor(t,e={}){t=nr.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:s=1e3,terminationCriteria:a=1e-10}=e;let l;if(r){if(Je.isAnyArray(r)&&typeof r[0]=="number"?r=pt.columnVector(r):r=nr.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let f=1,h,p,c,d;for(let _=0;_<s&&f>a;_++)c=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),c=c.div(c.norm()),h=t.mmul(c).div(c.transpose().mmul(c).get(0,0)),_>0&&(f=h.clone().sub(d).pow(2).sum()),d=h.clone(),r?(p=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),p=p.div(p.norm()),l=r.mmul(p).div(p.transpose().mmul(p).get(0,0))):l=h;if(r){let _=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));_=_.div(_.norm());let D=t.clone().sub(h.clone().mmul(_.transpose())),g=l.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),y=r.clone().sub(h.clone().mulS(g.get(0,0)).mmul(p.transpose()));this.t=h,this.p=_.transpose(),this.w=c.transpose(),this.q=p,this.u=l,this.s=h.transpose().mmul(h),this.xResidual=D,this.yResidual=y,this.betas=g}else this.w=c.transpose(),this.s=h.transpose().mmul(h).sqrt(),n?this.t=h.clone().div(this.s.get(0,0)):this.t=h,this.xResidual=t.sub(h.mmul(c.transpose()))}}Pt.AbstractMatrix=$t,Pt.CHO=Pc,Pt.CholeskyDecomposition=Pc,Pt.DistanceMatrix=Qs,Pt.EVD=Lc;var ow=Pt.EigenvalueDecomposition=Lc;Pt.LU=to,Pt.LuDecomposition=to;var qc=Pt.Matrix=pt;Pt.MatrixColumnSelectionView=U_,Pt.MatrixColumnView=q_,Pt.MatrixFlipColumnView=k_,Pt.MatrixFlipRowView=W_,Pt.MatrixRowSelectionView=Z_,Pt.MatrixRowView=Y_,Pt.MatrixSelectionView=Vs,Pt.MatrixSubView=j_,Pt.MatrixTransposeView=G_,Pt.NIPALS=zc,Pt.Nipals=zc,Pt.QR=Tu,Pt.QrDecomposition=Tu,Pt.SVD=pi,Pt.SingularValueDecomposition=pi,Pt.SymmetricMatrix=Pn,Pt.WrapperMatrix1D=Oc,Pt.WrapperMatrix2D=nr,Pt.correlation=ew,Pt.covariance=tw;var Uc=Pt.default=pt;Pt.determinant=eo,Pt.inverse=J_,Pt.linearDependencies=Q_,Pt.pseudoInverse=V_,Pt.solve=Rc,Pt.wrap=K_;const kc=ow,Wc=qc;Uc.Matrix&&Uc.Matrix;class uw{new({rows:t,columns:e,initial_value:r}={}){return new $u(t,e,r)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:s,to_column:a}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:s,to_column:a})}kron({id:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r}){return t==null?void 0:t.reshape({rows:e,columns:r})}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:s}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:s})}swap_rows({id:t,row1:e,row2:r}){t==null||t.swap_rows({row1:e,row2:r})}transpose({id:t}){return t==null?void 0:t.transpose()}remove_col({id:t,column:e}){return t==null?void 0:t.remove_col({column:e})}remove_row({id:t,row:e}){return t==null?void 0:t.remove_row({row:e})}eigenvalues({id:t}){return t==null?void 0:t.eigenvalues()}is_diagonal({id:t}){return t==null?void 0:t.is_diagonal()}is_identity({id:t}){return t==null?void 0:t.is_identity()}eigenvectors({id:t}){return t==null?void 0:t.eigenvectors()}is_symmetric({id:t}){return t==null?void 0:t.is_symmetric()}swap_columns({id:t,column1:e,column2:r}){t==null||t.swap_columns({column1:e,column2:r})}is_stochastic({id:t}){return t==null?void 0:t.is_stochastic()}is_triangular({id:t}){return t==null?void 0:t.is_triangular()}elements_count({id:t}){return t==null?void 0:t.elements_count()}is_antidiagonal({id:t}){return t==null?void 0:t.is_antidiagonal()}is_antisymmetric({id:t}){return t==null?void 0:t.is_antisymmetric()}}class $u{constructor(t=0,e=0,r=void 0){G(this,"_matrixInstance");this._matrixInstance=this._createMatrix(t,e,r)}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Xt(e,r))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const s of n._value)t+=s,e+=1;return t/e}col({column:t=0}){const e=[];for(const n of this._matrixInstance)e.push(n._value[t]);const r=new Xt;return r._value=e,r}det(){return Mc(this._matrixArray)}get({row:t,column:e=0}){return this._matrixInstance[t]._value[e]}inv(){const t=Ks(this._matrixArray);return this._newMatrix(t)}max(){return t_(this._matrixArray)}min(){return Nu(this._matrixArray)}pow({power:t}){const e=r_(this._matrixArray,t);return this._newMatrix(e)}row({row:t=0}){return this._matrixInstance[t]}set({row:t,column:e,value:r}){this._matrixInstance[t]._value[e]=r}sum({id2:t}){const e=ki(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=K1(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e=0,to_row:r=this.rows(),from_column:n=0,to_column:s=this.columns()}={}){for(const[a,l]of this._matrixInstance.entries())for(const[f]of l._value.entries())a<r&&a>=e&&f>=n&&f<s&&(l._value[f]=t)}kron({id2:t}){const e=j1(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return Nu(yc(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=ai(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=e_(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t=0,order:e=Tn.ascending}={}){this._matrixInstance.sort((r,n)=>{const s=r._value[t],a=n._value[t];return e!==Tn.descending?s-a:a-s})}trace(){return V1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Nc(this._matrixArray)}add_col({column:t=this.columns(),array_id:e}={}){for(const[r,n]of this._matrixInstance.entries())n._value[t]=e?e._value[r]:void 0}add_row({row:t,array_id:e}){this._matrixInstance.splice(t||this.rows(),0,e||new Xt(this.columns()))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t,columns:e}){const r=k1(this._matrixArray,[t,e]);this._matrixInstance=r.map(n=>{const s=new Xt;return s._value=[...n],s})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t._value.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t=0,to_row:e=this.rows(),from_column:r=0,to_column:n=this.columns()}={}){const s=this._matrixArray.splice(t,e-1),a=[];for(const l of s)a.push(l.splice(r,n-1));return this._newMatrix(a)}swap_rows({row1:t,row2:e}){const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Ec(this._matrixArray);return this._newMatrix(t)}remove_col({column:t=this.columns()}={}){const e=[];for(const n of this._matrixInstance){const s=n._value.splice(t,1);e.push(s[0])}const r=new Xt;return r._value=e,r}remove_row({row:t=this.rows()}={}){return this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new kc(new Wc(this._matrixArray)),e=new Xt;return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0)return!1;return!0}is_identity(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0||n===s&&r[n][s]!==1)return!1;return!0}eigenvectors(){const t=new kc(new Wc(this._matrixArray));return this._newMatrix(t.eigenvectorMatrix.to2DArray())}is_symmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=n+1;s<e;s++)if(r[n][s]!==r[s][n])return!1;return!0}swap_columns({column1:t,column2:e}){for(const r of this._matrixInstance){const n=r._value[t],s=r._value[e];r._value[t]=s,r._value[e]=n}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return W1(this._matrixArray)}is_antidiagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n+s!==t-1&&r[n][s]!==0)return!1;return!0}is_antisymmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n!==s&&r[n][s]!==-r[s][n])return!1;return!0}_isUpperTriangular(t){const e=this._matrixArray;for(let r=1;r<t;r++)for(let n=0;n<r;n++)if(e[r][n]!==0)return!1;return!0}_isLowerTriangular(t){const e=this._matrixArray;for(let r=0;r<t-1;r++)for(let n=r+1;n<t;n++)if(e[r][n]!==0)return!1;return!0}_newMatrix(t){const e=new $u;return e._value=t.map(r=>{const n=new Xt;return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,s=[...t].map(a=>[...a]);for(let a=0;a<r&&!(a>=n);a++){let l=a;for(;l<r&&s[l][a]===0;)l++;if(l===r)continue;if(l!==a){const h=s[l];s[l]=s[a],s[a]=h}const f=s[a][a];for(let h=0;h<n;h++)s[a][h]/=f;for(let h=a+1;h<r;h++){const p=s[h][a];s[h]=s[h].map((c,d)=>c-p*s[a][d]),s[h][a]=0}}for(let a=0;a<r;a++)s[a].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class aw{constructor(t){G(this,"_variables");G(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){const r=Bn(t),n=Bn(this._variables.timeframe.period);if(r<n)return!0;const s=`change_${e}`,a=this._cacheData[s],l=this._variables.time*1e3;if(a){if(a.offset){if(a.currentTime+a.offset<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else if(a.currentTime+r*1e3<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else{const f=this._calcTimeOffset(l,t);return this._cacheData[s]={currentTime:l,offset:f},!1}return!1}in_seconds({timeframe:t}={}){return Bn(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=ne.duration(e);if(r.years())return"12M";const s=r.asMonths();if(js(s))return`${s}M`;const a=r.asWeeks();if(js(a))return`${a}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const f=r.asMinutes();if(f>=1)return`${Math.ceil(f)}`;const h=r.asSeconds();return h<=1?"1S":h<=5?"5S":h<=10?"10S":h<=15?"15S":h<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=ne(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=ne(t).date();e="1D";const f=ne(t).daysInMonth();l!==1&&(r=(f-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),s=Bn(e)*1e3,a=t-n-Math.floor((t-n)/s)*s;return r?r-a:a}}class lw{pos({source:t,str:e}){return t==null?void 0:t.indexOf(e)}trim({source:t}){return t==null?void 0:t.trim()}lower({source:t}){return t==null?void 0:t.toLocaleLowerCase()}match({source:t,regex:e}){const r=t==null?void 0:t.match(new RegExp(e));return r?r[0]:""}split({string:t,separator:e}){const r=t==null?void 0:t.split(e),n=new Xt;return n._value=r||[],n}upper({source:t}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t},e){return this._strFormat(t,e)}length({string:t}){return t==null?void 0:t.length}repeat({source:t,repeat:e=0,separator:r=""}){return Array.from(new Array(e),()=>t).join(r)}replace({source:t,target:e,replacement:r,occurrence:n=0}){let s=-1;for(let a=0;a<n+1&&(s=t.indexOf(e,s+1),s!==-1);a++);return s!==-1?t.substring(0,s)+r+t.substring(s+e.length):t}contains({source:t,str:e}){return t==null?void 0:t.includes(e)}endswith({source:t,str:e}){return t==null?void 0:t.endsWith(e)}tonumber({string:t}){if(/[^\d.]/.test(t))return;const e=parseFloat(t);return isNaN(e)?void 0:e}tostring({value:t,format:e}){if(t===void 0)return"NaN";if(typeof t=="object"){if(t.isArray)return this._arrToStr(t._value,e);if(t.isMatrix){const r=[];for(const n of t._matrixArray)r.push(this._arrToStr(n,e));return r.join(`
62
- `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return this._formatNumber(t,e)}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._formatNumber(n,e):n).toString()}]`}substring({source:t,begin_pos:e=0,end_pos:r}){return t==null?void 0:t.substring(e,r)}startswith({source:t,str:e}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return Fr(t,r).format(e)}replace_all({source:t,target:e,replacement:r}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_formatNumber(t,e){if(!e)return t;switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:const r=e.split(".")[1],n=r?r.length:0;return parseFloat(t.toFixed(n))}}_strFormat(t,e){let r=t;return e.forEach((n,s)=>{if(typeof n=="number"){const a=`\\{\\s*${s}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const f=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,f)))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n)}),r}}class fw{new(){return new Ou}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Ou{constructor(){G(this,"_mapInstance");this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Ou;return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Xt;return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Xt;return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class cw{constructor(t){G(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new zn(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new zn(t,r,e)}copy({id:t}){const{price:e,time:r,index:n}=t||{};return new zn(e,n,r)}from_index({price:t,index:e}){return new zn(t,e)}from_time({price:t,time:e}){return new zn(t,void 0,e)}}class zn{constructor(t,e,r){G(this,"_index");G(this,"_price");G(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new zn(this._price,this._index,this._time)}}class hw{constructor(t){G(this,"_variables");G(this,"_defaultLabel",{text:"",xloc:Ie.bar_index,yloc:Oi.price,size:zr.normal,style:de.styleLabelDown,textalign:Ge.alignCenter});this._variables=t}new(t,e){const r=`label_${e}`,n={...this._defaultLabel,...t,id:r};t.point&&(n.x=n.xloc===Ie.bar_index?t.point.index:t.point.time,n.y=t.point.price);const s=new Yi(r,this._variables);return this._variables.label.add(r,n,s),s}label(t,e){return t.x?t.x:new Yi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class Yi{constructor(t,e){G(this,"_id");G(this,"_variables");this._id=t,this._variables=e}copy(t){const e=`label_${t}`,r=this._getLabel(t),n=new Yi(e,this._variables);return r&&this._variables.label.add(e,{...r,id:e},n),n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t)}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e)}set_yloc({yloc:t},e){const r=this._getLabel(e);r&&(r.yloc=t)}set_color({color:t},e){const r=this._getLabel(e);r&&(r.color=t)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===Ie.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t)}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t)}set_textcolor({textcolor:t},e){const r=this._getLabel(e);r&&(r.textcolor=t)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const pw={freq_all:an.freqAll,freq_once_per_bar:an.freqOncePerBar,freq_once_per_bar_close:an.freqOncePerBarClose},mw={gaps_off:$i.gapsOff,gaps_on:$i.gapsOn,lookahead_off:$i.lookaheadOff,lookahead_on:$i.lookaheadOn},mi={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},dw={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},gw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},vw={all:[tr.dataWindow,tr.pane,tr.priceScale,tr.statusLine],data_window:[tr.dataWindow],none:[],pane:[tr.pane],price_scale:[tr.priceScale],status_line:[tr.statusLine]},_w={both:In.both,left:In.left,none:In.none,right:In.right},ww={inherit:Qn.inherit,mintick:Qn.mintick,percent:Qn.percent,price:Qn.price,volume:Qn.volume},Dw={style_solid:ps.styleSolid,style_dashed:ps.styleDashed,style_dotted:ps.styleDotted},yw={style_arrowdown:de.styleArrowdown,style_arrowup:de.styleArrowup,style_circle:de.styleCircle,style_cross:de.styleCross,style_diamond:de.styleDiamond,style_flag:de.styleFlag,style_label_center:de.styleLabelCenter,style_label_down:de.styleLabelDown,style_label_left:de.styleLabelLeft,style_label_lower_left:de.styleLabelLowerLeft,style_label_lower_right:de.styleLabelLowerRight,style_label_right:de.styleLabelRight,style_label_up:de.styleLabelUp,style_label_upper_left:de.styleLabelUpperLeft,style_label_upper_right:de.styleLabelUpperRight,style_none:de.styleNone,style_square:de.styleSquare,style_text_outline:de.styleTextOutline,style_triangledown:de.styleTriangledown,style_triangleup:de.styleTriangleup,style_xcross:de.styleXcross},bw={style_arrow_both:Pr.styleArrowBoth,style_arrow_left:Pr.styleArrowLeft,style_arrow_right:Pr.styleArrowRight,style_dashed:Pr.styleDashed,style_dotted:Pr.styleDotted,style_solid:Pr.styleSolid},Ew={abovebar:Vn.abovebar,absolute:Vn.absolute,belowbar:Vn.belowbar,bottom:Vn.bottom,top:Vn.top},Aw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},xw={style_area:mr.styleArea,style_areabr:mr.styleAreabr,style_circles:mr.styleCircles,style_columns:mr.styleColumns,style_cross:mr.styleCross,style_histogram:mr.styleHistogram,style_line:mr.styleLine,style_linebr:mr.styleLinebr,style_stepline:mr.styleStepline,style_stepline_diamond:mr.styleSteplineDiamond,style_steplinebr:mr.styleSteplinebr},Cw={bottom_center:Mr.bottomCenter,bottom_left:Mr.bottomLeft,bottom_right:Mr.bottomRight,middle_center:Mr.middleCenter,middle_left:Mr.middleLeft,middle_right:Mr.middleRight,top_center:Mr.topCenter,top_left:Mr.topLeft,top_right:Mr.topRight},Fw={left:ms.left,none:ms.none,right:ms.right},Mw={arrowdown:er.arrowdown,arrowup:er.arrowup,circle:er.circle,cross:er.cross,diamond:er.diamond,flag:er.flag,labeldown:er.labeldown,labelup:er.labelup,square:er.square,triangledown:er.triangledown,triangleup:er.triangleup,xcross:er.xcross},Nw={auto:zr.auto,huge:zr.huge,large:zr.large,normal:zr.normal,small:zr.small,tiny:zr.tiny},Sw={cash:ds.cash,fixed:ds.fixed,percent_of_equity:ds.percentOfEquity,commission:{cash_per_contract:gs.cashPerContract,cash_per_order:gs.cashPerOrder,percent:gs.percent},direction:{all:vs.all,long:vs.long,short:vs.short},oca:{cancel:_s.cancel,none:_s.none,reduce:_s.reduce}},Bw={align_bottom:Ge.alignBottom,align_center:Ge.alignCenter,align_left:Ge.alignLeft,align_right:Ge.alignRight,align_top:Ge.alignTop,wrap_auto:Ge.wrapAuto,wrap_none:Ge.wrapNone},Iw={bar_index:Ie.bar_index,bar_time:Ie.bar_time},Tw={abovebar:Oi.abovebar,belowbar:Oi.belowbar,price:Oi.price},$w={actual:ws.actual,estimate:ws.estimate,standardized:ws.standardized};class Ow{constructor(){G(this,"adjustment",{dividends:hs.dividends,none:hs.none,splits:hs.splits});G(this,"alert",pw);G(this,"barmerge",mw);G(this,"color",mi);G(this,"currency",dw);G(this,"dayofweek",gw);G(this,"earnings",$w);G(this,"display",vw);G(this,"extend",_w);G(this,"font",{family_default:"SimSun",family_monospace:"Monospace"});G(this,"format",ww);G(this,"hline",Dw);G(this,"label",yw);G(this,"line",bw);G(this,"location",Ew);G(this,"math",Aw);G(this,"order",{ascending:Tn.ascending,descending:Tn.descending});G(this,"plot",xw);G(this,"position",Cw);G(this,"scale",Fw);G(this,"session",{extended:ru.extended,regular:ru.regular});G(this,"shape",Mw);G(this,"size",Nw);G(this,"splits",{denominator:"denominator",numerator:"numerator"});G(this,"strategy",Sw);G(this,"text",Bw);G(this,"xloc",Iw);G(this,"yloc",Tw)}updateData(){}}class Rw{constructor(t){G(this,"_variables");G(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:Ie.bar_index,line_color:mi.blue,line_style:Pr.styleSolid,line_width:1});this._variables=t}new(t,e){const r=`polyline_${e}`,n=Object.assign({},this._defaultPolyline,t,{id:r}),s=new Yc(r,this._variables);return this._variables.polyline.add(r,n,s),s}delete({id:t}){t&&t.delete()}}class Yc{constructor(t,e){G(this,"_id");G(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class Lw{constructor(t){G(this,"_variables");G(this,"_defaultLine",{xloc:Ie.bar_index,extend:In.none,style:Pr.styleSolid});this._variables=t}new({first_point:t,second_point:e,...r},n){const s=`line_${n}`,a={...this._defaultLine,...r,id:s};if(t&&e){const f=a.xloc===Ie.bar_index?t.index:t.time,h=a.xloc===Ie.bar_index?e.index:e.time;Object.assign(a,{x1:f,y1:t.price,x2:h,y2:e.price})}const l=new Zi(s,this._variables);return this._variables.line.add(s,a,l),l}line(t,e){return t.x?t.x:new Zi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class Zi{constructor(t,e){G(this,"_variables");G(this,"_id");this._id=t,this._variables=e}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}`,r=this._getLine(t),n=new Zi(e,this._variables);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===Ie.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r)}set_color({color:t},e){const r=this._getLine(e);r&&(r.color=t)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t)}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t)}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===Ie.bar_index?n:s,f=a;l&&(r.x1=l),f&&(r.y1=f)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===Ie.bar_index?n:s,f=a;l&&(r.x2=l),f&&(r.y2=f)}}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Pw{constructor(t){G(this,"_variables");this._variables=t}new({line1:t,line2:e,color:r},n){const s=`linefill_${n}`,a=t==null?void 0:t.data,l=e==null?void 0:e.data;a&&(a.linefills=a.linefills||[],a.linefills.push(s)),l&&(l.linefills=l.linefills||[],l.linefills.push(s));const f=new no(this._variables,s,t,e);return(a||l)&&this._variables.linefill.add(s,{line1:a,line2:l,color:r,id:s},f),f}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class no{constructor(t,e,r,n){G(this,"_id");G(this,"_line1");G(this,"_line2");G(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new no(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color({color:t}){const e=this._variables.linefill.get(this._id);e&&(e.color=t)}}class zw{constructor(t){G(this,"_variables");G(this,"_defaultBox",{border_color:mi.blue,border_width:1,bgcolor:mi.blue,xloc:Ie.bar_index,extend:In.none,style:Pr.styleSolid,text:"",text_size:zr.auto,text_color:mi.black,text_halign:Ge.alignCenter,text_valign:Ge.alignCenter,text_wrap:Ge.wrapNone});this._variables=t}box({x:t},e){return t===void 0?new ji(this._variables,e):t}new({top_left:t,bottom_right:e,...r},n){const s=`box_${n}`,a={...this._defaultBox,...r,id:s};if(t){const{price:f,time:h,index:p}=t;a.top=f,a.left=a.xloc===Ie.bar_index?p:h}if(e){const{price:f,time:h,index:p}=e;a.bottom=f,a.right=a.xloc===Ie.bar_index?p:h}const l=new ji(this._variables,s);return this._variables.box.add(s,a,l),l}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e}){t==null||t.set_extend(e)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e}){t==null||t.set_border_style(e)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e}){t==null||t.set_text_size(e)}set_text_wrap({id:t,...e}){t==null||t.set_text_wrap(e)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e}){t==null||t.set_text_halign(e)}set_text_valign({id:t,...e}){t==null||t.set_text_valign(e)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e}){t==null||t.set_text_font_family(e)}}class ji{constructor(t,e){G(this,"_id");G(this,"_variables");this._variables=t,this._id=e}copy(t){const e=`box_${t}`,r=this._getBox(),n=new ji(this._variables,e);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t}){const e=this._getBox();e&&(e.extend=t)}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t)}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t}){const e=this._getBox();e&&(e.text_size=t)}set_text_wrap({text_wrap:t}){const e=this._getBox();e&&(e.text_wrap=t)}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t)}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t}){const e=this._getBox();e&&(e.text_halign=t)}set_text_valign({text_valign:t}){const e=this._getBox();e&&(e.text_valign=t)}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===Ie.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t)}set_border_style({style:t}){const e=this._getBox();e&&(e.border_style=t)}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===Ie.bar_index?r:s}}set_text_font_family({text_font_family:t}){const e=this._getBox();e&&(e.text_font_family=t)}_getBox(){return this._variables.box.get(this._id)}}class qw{constructor(t){G(this,"_variables");G(this,"_defaultTable",{position:Mr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t}table({x:t},e){return t||new Ru(this._variables,e)}new(t,e){const r=`table_${e}`,n={...this._defaultTable,...t,cell:[],id:r},s=new Ru(this._variables,r);return this._variables.table.add(r,n,s),s}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e}){t==null||t.set_position(e)}}class Ru{constructor(t,e){G(this,"_id");G(this,"_variables");G(this,"_defaultCell",{column:0,row:0,text:"",text_color:mi.black,text_halign:Ge.alignCenter,text_valign:Ge.alignCenter,text_size:zr.normal});this._variables=t,this._id=e}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r)}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let f=t;f<=r;f++){const h=a[l];h&&(h[f]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){console.log(`error ${s}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(t,e);if(!a)return;this.clear({start_column:t,start_row:e,end_column:r,end_row:n});const l=this._variables.table.get(this._id);l.cell[e][t]={...a,isMerge:!0,merge_columns:r-t+1,merge_rows:n-e+1}}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t)}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t)}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t}){const e=this._variables.table.get(this._id);e&&(e.position=t)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Uw{constructor(t){G(this,"_logs");G(this,"_variables");this._variables=t,this._logs=[]}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e){this._addLog(t,e,"info")}error(t,e){this._addLog(t,e,"error")}warning(t,e){this._addLog(t,e,"warning")}_addLog(t,e,r){const{message:n,formatString:s}=t,{time:a,bar_index:l}=this._variables;let f=n;s&&Array.isArray(e)&&e.length&&(f=s.replace(/{(\d+)}/g,(h,p)=>e[p]?String(e[p]):h)),f&&this._logs.push({message:f,time:a,barIndex:l,type:r})}}class kw{constructor(t){G(this,"_errorListener");this._errorListener=t}error({message:t},e){this._errorListener.addError(t,e,li.Error)}}class Ww{constructor(){G(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Cr.flatMap([...this._errors.values()])}addError(t,e,r){const[n,s]=e.split("_").slice(-2),a=this._errors.get(e),l={message:t,endLineNumber:Number(n),startColumn:Number(s),endColumn:Number(s),startLineNumber:Number(n),type:r};a?a.push(l):this._errors.set(e,[l])}}ne.extend(Bp),ne.extend(Fp),ne.extend(Np);class Yw{constructor(){G(this,"_cacheData");G(this,"_barIndex");G(this,"_isRealTimeBar");G(this,"_barstate");G(this,"_priceVariables");G(this,"_lastBarIndex");G(this,"_currentBarTime");G(this,"_lastBarTime");G(this,"_period");G(this,"_offsetTime");G(this,"_timeframe");G(this,"_ta");G(this,"_polyline");G(this,"_label");G(this,"_line");G(this,"_linefill");G(this,"_box");G(this,"_table");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new Zw,this._timeframe=new jw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Gw,this._polyline=new di,this._label=new di,this._line=new di,this._linefill=new di,this._box=new di,this._table=new di}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 na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ne(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ne(this._currentBarTime).minute()}get second(){return ne(this._currentBarTime).second()}get month(){return ne(this._currentBarTime).month()+1}get year(){return ne(this._currentBarTime).year()}get dayofweek(){return ne(this._currentBarTime).day()+1}get dayofmonth(){return ne(this._currentBarTime).date()}get weekofyear(){return ne(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=cs(this._period);return this._isRealTimeBar?void 0:ne(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}getTimeTradingday(t,e){const[r,n]=cs(e),s=ne(t).add(r,n);return["M","w","y"].includes(n)?s.subtract(1,"d").valueOf():s.startOf("d").add(this._offsetTime,"h").valueOf()}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,lastBarIndex:f,time:h,lastBarTime:p,period:c="1D",offsetTime:d=5}=t;this._priceVariables={close:r,open:n,high:s,low:a,volume:l},e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._currentBarTime=h,this._lastBarIndex=f,this._barIndex=e,this._lastBarTime=p,this._period=c,this._offsetTime=d,this._timeframe.update(c),this._barstate.update(e,f,!1,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){let n=this._cacheData[t]||[];n[this._barIndex]=r,n=n.filter(()=>!0);const s=n[n.length-1-e];return this._cacheData[t]=n,s}setCacheData(t,e){const r=this._cacheData[t]||[];r[this._barIndex]=e,this._cacheData[t]=r}getTypeInstance(t,e){return new Ap(t,e)}getVarValue(t,e,r){const n=`${t}_${e}`,s=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(s)return s}setVarValue(t,e,r,n){const s=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=Cr.cloneDeep(r);if(this._cacheData.varNewData[s]=l,a&&a.length)for(const f of a)this._cacheData.varData[s][f]=l[f]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Cr.uniq([...t,...e]):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):t-e}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case Yi.name:case Yc.name:case ji.name:case Ru.name:case Zi.name:case no.name:t==null||t.delete();break}}}class di{constructor(t=50){G(this,"_all");G(this,"_allInstance");G(this,"_pseudoArrayAll");G(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Xt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r);const n=[...this._all.keys()];if(n.length>this._maxLength){const s=n.shift();s&&this.delete(s)}}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}class Zw{constructor(){G(this,"_isMarketOpen");G(this,"_currentBarIndex");G(this,"_totalBarIndex");G(this,"_isRealTimeBar");G(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1:this._currentBarIndex===this._totalBarIndex}}class jw{constructor(){G(this,"_period");G(this,"_multiplier");G(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=cs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class Gw{constructor(){G(this,"_preAccdist");G(this,"_preNvi");G(this,"_prePvi");G(this,"_preObv");G(this,"_prePvt");G(this,"_preWad");G(this,"_preVwap");G(this,"_preValue");G(this,"_currentData");G(this,"_preData");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={}}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(self.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin")&&(s=!0,r=n=0),!s)return;const l=t*e+r,f=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:f,isReset:s});const h=l/f;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}var Zc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,f){var h=n(s),p=n(a),c=(f=f||"()")[0]==="(",d=f[1]===")";return(c?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(c?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(Zc);var Kw=Zc.exports,Jw=Zt(Kw),jc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){var s=r.prototype,a=function(d){var _,D=d.date,g=d.utc,y={};if(!((_=D)===null||_ instanceof Date||_ instanceof Array||s.$utils().u(_)||_.constructor.name!=="Object")){if(!Object.keys(D).length)return new Date;var v=g?n.utc():n();Object.keys(D).forEach(function($){var C,I;y[C=$,I=s.$utils().p(C),I==="date"?"day":I]=D[$]});var E=y.day||(y.year||y.month>=0?1:v.date()),b=y.year||v.year(),N=y.month>=0?y.month:y.year||y.day?0:v.month(),x=y.hour||0,F=y.minute||0,M=y.second||0,S=y.millisecond||0;return g?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return D},l=s.parse;s.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var f=s.set,h=s.add,p=s.subtract,c=function(d,_,D,g){g===void 0&&(g=1);var y=Object.keys(_),v=this;return y.forEach(function(E){v=d.bind(v)(_[E]*g,E)}),v};s.set=function(d,_){return _=_===void 0?d:_,d.constructor.name==="Object"?c.bind(this)(function(D,g){return f.bind(this)(g,D)},_,d):f.bind(this)(d,_)},s.add=function(d,_){return d.constructor.name==="Object"?c.bind(this)(h,d,_):h.bind(this)(d,_)},s.subtract=function(d,_){return d.constructor.name==="Object"?c.bind(this)(h,d,_,-1):p.bind(this)(d,_)}}})})(jc);var Xw=jc.exports,Hw=Zt(Xw),Gc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,p=2628e6,c=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},_=function(F){return F instanceof N},D=function(F,M,S){return new N(F,S,M.$l)},g=function(F){return r.p(F)+"s"},y=function(F){return F<0},v=function(F){return y(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?y(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,$,C){var I=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),$)return D(S*d[g($)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){I.$d[g(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var R=S.match(c);if(R){var U=R.slice(2).map(function(q){return q!=null?Number(q):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function($,C){return $+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/p),S%=p,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),$=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var I=b(C,"D"),R=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),q=this.$d.seconds||0;this.$d.milliseconds&&(q+=this.$d.milliseconds/1e3,q=Math.round(1e3*q)/1e3);var k=b(q,"S"),P=S.negative||$.negative||I.negative||R.negative||U.negative||k.negative,K=R.format||U.format||k.format?"T":"",j=(P?"-":"")+"P"+S.format+$.format+I.format+K+R.format+U.format+k.format;return j==="P"||j==="-P"?"P0D":j},M.toJSON=function(){return this.toISOString()},M.format=function(S){var $=S||"YYYY-MM-DDTHH:mm:ss",C={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return $.replace(f,function(I,R){return R||String(C[I])})},M.as=function(S){return this.$ms/d[g(S)]},M.get=function(S){var $=this.$ms,C=g(S);return C==="milliseconds"?$%=1e3:$=C==="weeks"?v($/d[C]):this.$d[C],$||0},M.add=function(S,$,C){var I;return I=$?S*d[g($)]:_(S)?S.$ms:D(S,this).$ms,D(this.$ms+I*(C?-1:1),this)},M.subtract=function(S,$){return this.add(S,$,!0)},M.locale=function(S){var $=this.clone();return $.$l=S,$},M.clone=function(){return D(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(I,R){var U=S.locale();return D(I,{$l:U},R)},S.isDuration=_;var $=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(I,R){return _(I)?x(this,I,1):$.bind(this)(I,R)},M.prototype.subtract=function(I,R){return _(I)?x(this,I,-1):C.bind(this)(I,R)}}})})(Gc);var Qw=Gc.exports,Vw=Zt(Qw);ne.extend(Jw),ne.extend(Hw),ne.extend(Vw);class tD{constructor(t,e){G(this,"array");G(this,"color");G(this,"math");G(this,"str");G(this,"map");G(this,"matrix");G(this,"timeframe");G(this,"ta");G(this,"input");G(this,"_variables");G(this,"_cacheData");G(this,"_options");G(this,"_errorListener");G(this,"_plots");G(this,"_alerts");G(this,"_bgColors");G(this,"_hlines");G(this,"_fills");G(this,"chart");G(this,"line");G(this,"label");G(this,"polyline");G(this,"box");G(this,"table");G(this,"linefill");G(this,"log");G(this,"runtime");this._variables=e,this.array=new $p,this.math=new Op(t),this.color=new a_,this.str=new lw,this.map=new fw,this.timeframe=new aw(e),this.matrix=new uw,this.ta=new i_(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this._errorListener=new Ww,this.input=new u_(e,this._errorListener),this._plots=new Map,this.chart={point:new cw(e)},this.line=new Lw(e),this.label=new hw(e),this.polyline=new Rw(e),this.box=new zw(e),this.table=new qw(e),this.linefill=new Pw(e),this.log=new Uw(e),this.runtime=new kw(this._errorListener)}get errors(){return this._errorListener.errors}get options(){const t=this.input.getInputs(),e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors).length?{...this._bgColors}:void 0,n=this._hlines.size?[...this._hlines.values()]:void 0,s=this._fills.size?[...this._fills.values()]:void 0,a=this.log.logs.length?this.log.logs:void 0;return this.log.clearLogs(),Object.assign(this._options,{inputGroups:t,plots:[...this._plots.values()],draws:this._getDraws(),alerts:e,colors:r,hlines:n,fills:s,logs:a})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}update(t){const{barIndex:e,inputs:r}=t;r&&r.length&&this.input.update(r),this.math.update(e)}indicator(t){this._variables.bar_index||(this._options.scriptType="indicator",this._options.indicator=t)}plot(t,e){const{series:r,color:n,seriesColors:s,...a}=t,{bar_index:l}=this._variables,f=`plot_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[],c=r!==void 0&&isNaN(r)?void 0:r;if(p[l]=c,s!=null&&s.length&&(this._seriesColorHandle(t,f),p[l]={value:c,itemStyle:{color:n}}),!h){const d=n?[n]:void 0;this._plots.set(f,{editable:!0,...a,colors:d,data:p,id:f})}return{type:"plot",key:f}}_seriesColorHandle(t,e){var s,a;const{seriesColors:r}=t,n=this._plots.get(e);if(n&&r!=null&&r.length)for(const l of r){if((s=n.gradientColorKeys)!=null&&s.includes(l))continue;const f=t[l],h=n[`${l}s`]||[];h.includes(f)||(h.push(f),n[`${l}s`]=h,h.length>5&&(n[`${l}s`]=[],(a=n.gradientColorKeys)==null||a.push(l)))}}plotbar(t,e){const{open:r,close:n,low:s,high:a,color:l,seriesColors:f,...h}=t,{bar_index:p}=this._variables,c=`plotbar_${e}`,d=this._plots.get(c),_=(d==null?void 0:d.data)||[],D=n!==void 0&&isNaN(n)?void 0:n,g=r!==void 0&&isNaN(r)?void 0:r,y=s!==void 0&&isNaN(s)?void 0:s,v=a!==void 0&&isNaN(a)?void 0:a,E=[g,D,y,v];if(_[p]=E,f!=null&&f.length&&(this._seriesColorHandle(t,c),_[p]={value:E,itemStyle:{color:l}}),!d){const b=l?[l]:void 0;this._plots.set(c,{editable:!0,...h,colors:b,data:_,id:c})}}plotchar(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,f=`plotchar_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotarrow(t,e){const{series:r,colorup:n,colordown:s,...a}=t,{bar_index:l}=this._variables,f=`plotarrow_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r!==void 0&&isNaN(r)?void 0:r,colorup:n,colordown:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotshape(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,f=`plotshape_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotcandle(t,e){const{wickcolor:r,bordercolor:n,color:s,close:a,open:l,low:f,high:h,...p}=t,{bar_index:c}=this._variables,d=`plotcandle_${e}`,_=this._plots.get(d),D=(_==null?void 0:_.data)||[],g=a!==void 0&&isNaN(a)?void 0:a,y=l!==void 0&&isNaN(l)?void 0:l,v=f!==void 0&&isNaN(f)?void 0:f,E=h!==void 0&&isNaN(h)?void 0:h,b=[y,g,v,E];D[c]={value:b,wickcolor:r,bordercolor:n,color:s},_||this._plots.set(d,{editable:!0,...p,data:D,id:d})}hline(t,e){const r=`hline_${e}`;return this._hlines.set(r,{linewidth:1,editable:!0,display:tr.all,...t}),{type:"hline",key:r}}fill(t,e){const r=`fill_${e}`;this._fills.set(r,{display:tr.all,editable:!0,fillgaps:!1,...t})}alert({message:t,freq:e=an.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,f=this._cacheData[l].barIndex;if(e===an.freqOncePerBar&&n===f){this._alerts.delete(l);return}const h={message:t,freq:e,id:l,type:"alert"};if(s){e!==an.freqOncePerBarClose&&this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}if(!s&&e===an.freqOncePerBarClose&&n===f&&a===n-1){this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t){this._setColors(t,"barcolor")}bgcolor(t){this._setColors(t,"bgcolor")}_setColors(t,e){var l,f;const{color:r,...n}=t,{bar_index:s}=this._variables,a=((l=this._bgColors[e])==null?void 0:l.colors)||[];if(!a[s]){const h=((f=this._bgColors[e])==null?void 0:f.setColors)||[];h.includes(r)||h.push(r),a[s]=r,this._bgColors[e]={...n,colors:a,setColors:h}}}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return t===void 0}nz({source:t,replacement:e}){return t!==void 0&&!isNaN(t)?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._variables.time_close&&this._timeHandle(this._variables.time_close,s,t,e,r,n)}timestamp({dateString:t,timezone:e,year:r,month:n,day:s,hour:a=0,minute:l=0,second:f=0}){if(t)return ne(t).valueOf();let h=ne({year:r,month:n,day:s,hour:a,minute:l,second:f});return e&&(h=Fr(h.valueOf(),e)),h.valueOf()}weekofyear({time:t,timezone:e}){return Fr(t,e).week()}year({time:t,timezone:e}){return Fr(t,e).year()}second({time:t,timezone:e}){return Fr(t,e).second()}month({time:t,timezone:e}){return Fr(t,e).month()+1}minute({time:t,timezone:e}){return Fr(t,e).minute()}hour({time:t,timezone:e}){return Fr(t,e).hour()}dayofweek({time:t,timezone:e}){return Fr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return Fr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Bn(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0){const l=r||this._variables.timeframe.period,f=Bn(l),h=Bn(this._variables.timeframe.period);let p;if(f<=h)p=t;else{const c=`time_${e}`,d=this._cacheData[c];if(d)d.currentTime+f*1e3-d.offset<=t?(p=t,this._cacheData[c]={currentTime:t,offset:0}):p=d;else{const _=this._calcTimeOffset(t,l);this._cacheData[c]={currentTime:t,offset:_},p=t}}if(n){const{timePeriods:c,weeks:d}=this._parserSession(n),_=ne(t).format("YYYY-MM-DD"),D=p;p=void 0;for(const y of c){const[v,E]=y;if(ne(t).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")){ne(D).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")?p=D:p=ne(`${_} ${v}`).valueOf();break}}const g=this._variables.dayofweek;p&&!d.includes(g)&&(p=void 0)}return s&&(p=p&&Fr(p,s).valueOf()),p&&p-a*h*1e3}_parserSession(t){const e=t.split(":"),r=e[0],s=(e[1]||"1234567").split("").map(l=>{const f=parseInt(l,10);if(f<1||f>7)throw new Error(`Invalid day of week: ${l}`);return f});return{timePeriods:r.split(",").map(l=>{const f=l.split("-");if(f.length!==2)throw new Error(`Invalid time period: ${l}`);return[this._processTime(f[0]),this._processTime(f[1])]}),weeks:s}}_processTime(t){const e=parseInt(t.slice(0,2),10),r=parseInt(t.slice(2),10);if(!(e>=0&&e<=23)&&r>=0&&r<=59)throw new Error("Invalid time: Time must be within 00:00 to 23:59");return`${e}:${r}`}}/**
62
+ `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return this._formatNumber(t,e)}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._formatNumber(n,e):n).toString()}]`}substring({source:t,begin_pos:e=0,end_pos:r}){return t==null?void 0:t.substring(e,r)}startswith({source:t,str:e}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return Fr(t,r).format(e)}replace_all({source:t,target:e,replacement:r}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_formatNumber(t,e){if(!e)return t;switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:const r=e.split(".")[1],n=r?r.length:0;return parseFloat(t.toFixed(n))}}_strFormat(t,e){let r=t;return e.forEach((n,s)=>{if(typeof n=="number"){const a=`\\{\\s*${s}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const f=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(n,f)))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n)}),r}}class fw{new(){return new Ou}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Ou{constructor(){G(this,"_mapInstance");this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Ou;return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Xt;return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Xt;return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class cw{constructor(t){G(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new zn(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new zn(t,r,e)}copy({id:t}){const{price:e,time:r,index:n}=t||{};return new zn(e,n,r)}from_index({price:t,index:e}){return new zn(t,e)}from_time({price:t,time:e}){return new zn(t,void 0,e)}}class zn{constructor(t,e,r){G(this,"_index");G(this,"_price");G(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new zn(this._price,this._index,this._time)}}class hw{constructor(t){G(this,"_variables");G(this,"_defaultLabel",{text:"",xloc:Ie.bar_index,yloc:Oi.price,size:zr.normal,style:de.styleLabelDown,textalign:Ge.alignCenter});this._variables=t}new(t,e){const r=`label_${e}`,n={...this._defaultLabel,...t,id:r};t.point&&(n.x=n.xloc===Ie.bar_index?t.point.index:t.point.time,n.y=t.point.price);const s=new Yi(r,this._variables);return this._variables.label.add(r,n,s),s}label(t,e){return t.x?t.x:new Yi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class Yi{constructor(t,e){G(this,"_id");G(this,"_variables");this._id=t,this._variables=e}copy(t){const e=`label_${t}`,r=this._getLabel(t),n=new Yi(e,this._variables);return r&&this._variables.label.add(e,{...r,id:e},n),n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t)}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e)}set_yloc({yloc:t},e){const r=this._getLabel(e);r&&(r.yloc=t)}set_color({color:t},e){const r=this._getLabel(e);r&&(r.color=t)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===Ie.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t)}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t)}set_textcolor({textcolor:t},e){const r=this._getLabel(e);r&&(r.textcolor=t)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const pw={freq_all:an.freqAll,freq_once_per_bar:an.freqOncePerBar,freq_once_per_bar_close:an.freqOncePerBarClose},mw={gaps_off:$i.gapsOff,gaps_on:$i.gapsOn,lookahead_off:$i.lookaheadOff,lookahead_on:$i.lookaheadOn},mi={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},dw={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},gw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},vw={all:[tr.dataWindow,tr.pane,tr.priceScale,tr.statusLine],data_window:[tr.dataWindow],none:[],pane:[tr.pane],price_scale:[tr.priceScale],status_line:[tr.statusLine]},_w={both:In.both,left:In.left,none:In.none,right:In.right},ww={inherit:Qn.inherit,mintick:Qn.mintick,percent:Qn.percent,price:Qn.price,volume:Qn.volume},Dw={style_solid:ps.styleSolid,style_dashed:ps.styleDashed,style_dotted:ps.styleDotted},yw={style_arrowdown:de.styleArrowdown,style_arrowup:de.styleArrowup,style_circle:de.styleCircle,style_cross:de.styleCross,style_diamond:de.styleDiamond,style_flag:de.styleFlag,style_label_center:de.styleLabelCenter,style_label_down:de.styleLabelDown,style_label_left:de.styleLabelLeft,style_label_lower_left:de.styleLabelLowerLeft,style_label_lower_right:de.styleLabelLowerRight,style_label_right:de.styleLabelRight,style_label_up:de.styleLabelUp,style_label_upper_left:de.styleLabelUpperLeft,style_label_upper_right:de.styleLabelUpperRight,style_none:de.styleNone,style_square:de.styleSquare,style_text_outline:de.styleTextOutline,style_triangledown:de.styleTriangledown,style_triangleup:de.styleTriangleup,style_xcross:de.styleXcross},bw={style_arrow_both:Pr.styleArrowBoth,style_arrow_left:Pr.styleArrowLeft,style_arrow_right:Pr.styleArrowRight,style_dashed:Pr.styleDashed,style_dotted:Pr.styleDotted,style_solid:Pr.styleSolid},Ew={abovebar:Vn.abovebar,absolute:Vn.absolute,belowbar:Vn.belowbar,bottom:Vn.bottom,top:Vn.top},Aw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},xw={style_area:mr.styleArea,style_areabr:mr.styleAreabr,style_circles:mr.styleCircles,style_columns:mr.styleColumns,style_cross:mr.styleCross,style_histogram:mr.styleHistogram,style_line:mr.styleLine,style_linebr:mr.styleLinebr,style_stepline:mr.styleStepline,style_stepline_diamond:mr.styleSteplineDiamond,style_steplinebr:mr.styleSteplinebr},Cw={bottom_center:Mr.bottomCenter,bottom_left:Mr.bottomLeft,bottom_right:Mr.bottomRight,middle_center:Mr.middleCenter,middle_left:Mr.middleLeft,middle_right:Mr.middleRight,top_center:Mr.topCenter,top_left:Mr.topLeft,top_right:Mr.topRight},Fw={left:ms.left,none:ms.none,right:ms.right},Mw={arrowdown:er.arrowdown,arrowup:er.arrowup,circle:er.circle,cross:er.cross,diamond:er.diamond,flag:er.flag,labeldown:er.labeldown,labelup:er.labelup,square:er.square,triangledown:er.triangledown,triangleup:er.triangleup,xcross:er.xcross},Nw={auto:zr.auto,huge:zr.huge,large:zr.large,normal:zr.normal,small:zr.small,tiny:zr.tiny},Sw={cash:ds.cash,fixed:ds.fixed,percent_of_equity:ds.percentOfEquity,commission:{cash_per_contract:gs.cashPerContract,cash_per_order:gs.cashPerOrder,percent:gs.percent},direction:{all:vs.all,long:vs.long,short:vs.short},oca:{cancel:_s.cancel,none:_s.none,reduce:_s.reduce}},Bw={align_bottom:Ge.alignBottom,align_center:Ge.alignCenter,align_left:Ge.alignLeft,align_right:Ge.alignRight,align_top:Ge.alignTop,wrap_auto:Ge.wrapAuto,wrap_none:Ge.wrapNone},Iw={bar_index:Ie.bar_index,bar_time:Ie.bar_time},Tw={abovebar:Oi.abovebar,belowbar:Oi.belowbar,price:Oi.price},$w={actual:ws.actual,estimate:ws.estimate,standardized:ws.standardized};class Ow{constructor(){G(this,"adjustment",{dividends:hs.dividends,none:hs.none,splits:hs.splits});G(this,"alert",pw);G(this,"barmerge",mw);G(this,"color",mi);G(this,"currency",dw);G(this,"dayofweek",gw);G(this,"earnings",$w);G(this,"display",vw);G(this,"extend",_w);G(this,"font",{family_default:"SimSun",family_monospace:"Monospace"});G(this,"format",ww);G(this,"hline",Dw);G(this,"label",yw);G(this,"line",bw);G(this,"location",Ew);G(this,"math",Aw);G(this,"order",{ascending:Tn.ascending,descending:Tn.descending});G(this,"plot",xw);G(this,"position",Cw);G(this,"scale",Fw);G(this,"session",{extended:ru.extended,regular:ru.regular});G(this,"shape",Mw);G(this,"size",Nw);G(this,"splits",{denominator:"denominator",numerator:"numerator"});G(this,"strategy",Sw);G(this,"text",Bw);G(this,"xloc",Iw);G(this,"yloc",Tw)}updateData(){}}class Rw{constructor(t){G(this,"_variables");G(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:Ie.bar_index,line_color:mi.blue,line_style:Pr.styleSolid,line_width:1});this._variables=t}new(t,e){const r=`polyline_${e}`,n=Object.assign({},this._defaultPolyline,t,{id:r}),s=new Yc(r,this._variables);return this._variables.polyline.add(r,n,s),s}delete({id:t}){t&&t.delete()}}class Yc{constructor(t,e){G(this,"_id");G(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class Lw{constructor(t){G(this,"_variables");G(this,"_defaultLine",{xloc:Ie.bar_index,extend:In.none,style:Pr.styleSolid});this._variables=t}new({first_point:t,second_point:e,...r},n){const s=`line_${n}`,a={...this._defaultLine,...r,id:s};if(t&&e){const f=a.xloc===Ie.bar_index?t.index:t.time,h=a.xloc===Ie.bar_index?e.index:e.time;Object.assign(a,{x1:f,y1:t.price,x2:h,y2:e.price})}const l=new Zi(s,this._variables);return this._variables.line.add(s,a,l),l}line(t,e){return t.x?t.x:new Zi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class Zi{constructor(t,e){G(this,"_variables");G(this,"_id");this._id=t,this._variables=e}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}`,r=this._getLine(t),n=new Zi(e,this._variables);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===Ie.bar_index){const{x1:n,y1:s,x2:a,y2:l}=r;return n===void 0||a===void 0||s===void 0||l===void 0?void 0:(l-s)/(a-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r)}set_color({color:t},e){const r=this._getLine(e);r&&(r.color=t)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t)}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t)}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===Ie.bar_index?n:s,f=a;l&&(r.x1=l),f&&(r.y1=f)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:a}=t||{},l=r.xloc===Ie.bar_index?n:s,f=a;l&&(r.x2=l),f&&(r.y2=f)}}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Pw{constructor(t){G(this,"_variables");this._variables=t}new({line1:t,line2:e,color:r},n){const s=`linefill_${n}`,a=t==null?void 0:t.data,l=e==null?void 0:e.data;a&&(a.linefills=a.linefills||[],a.linefills.push(s)),l&&(l.linefills=l.linefills||[],l.linefills.push(s));const f=new no(this._variables,s,t,e);return(a||l)&&this._variables.linefill.add(s,{line1:a,line2:l,color:r,id:s},f),f}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class no{constructor(t,e,r,n){G(this,"_id");G(this,"_line1");G(this,"_line2");G(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new no(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color({color:t}){const e=this._variables.linefill.get(this._id);e&&(e.color=t)}}class zw{constructor(t){G(this,"_variables");G(this,"_defaultBox",{border_color:mi.blue,border_width:1,bgcolor:mi.blue,xloc:Ie.bar_index,extend:In.none,style:Pr.styleSolid,text:"",text_size:zr.auto,text_color:mi.black,text_halign:Ge.alignCenter,text_valign:Ge.alignCenter,text_wrap:Ge.wrapNone});this._variables=t}box({x:t},e){return t===void 0?new ji(this._variables,e):t}new({top_left:t,bottom_right:e,...r},n){const s=`box_${n}`,a={...this._defaultBox,...r,id:s};if(t){const{price:f,time:h,index:p}=t;a.top=f,a.left=a.xloc===Ie.bar_index?p:h}if(e){const{price:f,time:h,index:p}=e;a.bottom=f,a.right=a.xloc===Ie.bar_index?p:h}const l=new ji(this._variables,s);return this._variables.box.add(s,a,l),l}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e}){t==null||t.set_extend(e)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e}){t==null||t.set_border_style(e)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e}){t==null||t.set_text_size(e)}set_text_wrap({id:t,...e}){t==null||t.set_text_wrap(e)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e}){t==null||t.set_text_halign(e)}set_text_valign({id:t,...e}){t==null||t.set_text_valign(e)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e}){t==null||t.set_text_font_family(e)}}class ji{constructor(t,e){G(this,"_id");G(this,"_variables");this._variables=t,this._id=e}copy(t){const e=`box_${t}`,r=this._getBox(),n=new ji(this._variables,e);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t}){const e=this._getBox();e&&(e.extend=t)}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t)}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t}){const e=this._getBox();e&&(e.text_size=t)}set_text_wrap({text_wrap:t}){const e=this._getBox();e&&(e.text_wrap=t)}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t)}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t}){const e=this._getBox();e&&(e.text_halign=t)}set_text_valign({text_valign:t}){const e=this._getBox();e&&(e.text_valign=t)}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===Ie.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t)}set_border_style({style:t}){const e=this._getBox();e&&(e.border_style=t)}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===Ie.bar_index?r:s}}set_text_font_family({text_font_family:t}){const e=this._getBox();e&&(e.text_font_family=t)}_getBox(){return this._variables.box.get(this._id)}}class qw{constructor(t){G(this,"_variables");G(this,"_defaultTable",{position:Mr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t}table({x:t},e){return t||new Ru(this._variables,e)}new(t,e){const r=`table_${e}`,n={...this._defaultTable,...t,cell:[],id:r},s=new Ru(this._variables,r);return this._variables.table.add(r,n,s),s}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e}){t==null||t.set_position(e)}}class Ru{constructor(t,e){G(this,"_id");G(this,"_variables");G(this,"_defaultCell",{column:0,row:0,text:"",text_color:mi.black,text_halign:Ge.alignCenter,text_valign:Ge.alignCenter,text_size:zr.normal});this._variables=t,this._id=e}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const a=s.cell||[],l=a[n]||[];l[r]=e,a[n]=l,s.cell=a}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r)}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const a=s.cell;if(a)for(let l=e;l<=n;l++)for(let f=t;f<=r;f++){const h=a[l];h&&(h[f]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){console.log(`error ${s}: start_column > end_column or start_row > end_row`);return}const a=this._getTableItem(t,e);if(!a)return;this.clear({start_column:t,start_row:e,end_column:r,end_row:n});const l=this._variables.table.get(this._id);l.cell[e][t]={...a,isMerge:!0,merge_columns:r-t+1,merge_rows:n-e+1}}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t)}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t)}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t}){const e=this._variables.table.get(this._id);e&&(e.position=t)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Uw{constructor(t){G(this,"_logs");G(this,"_variables");this._variables=t,this._logs=[]}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e){this._addLog(t,e,"info")}error(t,e){this._addLog(t,e,"error")}warning(t,e){this._addLog(t,e,"warning")}_addLog(t,e,r){const{message:n,formatString:s}=t,{time:a,bar_index:l}=this._variables;let f=n;s&&Array.isArray(e)&&e.length&&(f=s.replace(/{(\d+)}/g,(h,p)=>e[p]?String(e[p]):h)),f&&this._logs.push({message:f,time:a,barIndex:l,type:r})}}class kw{constructor(t){G(this,"_errorListener");this._errorListener=t}error({message:t},e){this._errorListener.addError(t,e,li.Error)}}class Ww{constructor(){G(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Cr.flatMap([...this._errors.values()])}addError(t,e,r){const[n,s]=e.split("_").slice(-2),a=this._errors.get(e),l={message:t,endLineNumber:Number(n),startColumn:Number(s),endColumn:Number(s),startLineNumber:Number(n),type:r};a?a.push(l):this._errors.set(e,[l])}}ne.extend(Bp),ne.extend(Fp),ne.extend(Np);class Yw{constructor(){G(this,"_cacheData");G(this,"_barIndex");G(this,"_isRealTimeBar");G(this,"_barstate");G(this,"_priceVariables");G(this,"_lastBarIndex");G(this,"_currentBarTime");G(this,"_lastBarTime");G(this,"_period");G(this,"_offsetTime");G(this,"_timeframe");G(this,"_ta");G(this,"_polyline");G(this,"_label");G(this,"_line");G(this,"_linefill");G(this,"_box");G(this,"_table");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new Zw,this._timeframe=new jw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Gw,this._polyline=new di,this._label=new di,this._line=new di,this._linefill=new di,this._box=new di,this._table=new di}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 na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ne(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ne(this._currentBarTime).minute()}get second(){return ne(this._currentBarTime).second()}get month(){return ne(this._currentBarTime).month()+1}get year(){return ne(this._currentBarTime).year()}get dayofweek(){return ne(this._currentBarTime).day()+1}get dayofmonth(){return ne(this._currentBarTime).date()}get weekofyear(){return ne(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=cs(this._period);return this._isRealTimeBar?void 0:ne(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}getTimeTradingday(t,e){const[r,n]=cs(e),s=ne(t).add(r,n);return["M","w","y"].includes(n)?s.subtract(1,"d").valueOf():s.startOf("d").add(this._offsetTime,"h").valueOf()}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:a,volume:l,lastBarIndex:f,time:h,lastBarTime:p,period:c="1D",offsetTime:d=5}=t;this._priceVariables={close:r,open:n,high:s,low:a,volume:l},e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._currentBarTime=h,this._lastBarIndex=f,this._barIndex=e,this._lastBarTime=p,this._period=c,this._offsetTime=d,this._timeframe.update(c),this._barstate.update(e,f,!1,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){let n=this._cacheData[t]||[];n[this._barIndex]=r,n=n.filter(()=>!0);const s=n[n.length-1-e];return this._cacheData[t]=n,s}setCacheData(t,e){const r=this._cacheData[t]||[];r[this._barIndex]=e,this._cacheData[t]=r}getTypeInstance(t,e){return new Ap(t,e)}getVarValue(t,e,r){const n=`${t}_${e}`,s=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(s)return s}setVarValue(t,e,r,n){const s=`${t}_${e}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=Cr.cloneDeep(r);if(this._cacheData.varNewData[s]=l,a&&a.length)for(const f of a)this._cacheData.varData[s][f]=l[f]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Cr.uniq([...t,...e]):Number(t)+Number(e)}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case Yi.name:case Yc.name:case ji.name:case Ru.name:case Zi.name:case no.name:t==null||t.delete();break}}}class di{constructor(t=50){G(this,"_all");G(this,"_allInstance");G(this,"_pseudoArrayAll");G(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Xt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r);const n=[...this._all.keys()];if(n.length>this._maxLength){const s=n.shift();s&&this.delete(s)}}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}class Zw{constructor(){G(this,"_isMarketOpen");G(this,"_currentBarIndex");G(this,"_totalBarIndex");G(this,"_isRealTimeBar");G(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1:this._currentBarIndex===this._totalBarIndex}}class jw{constructor(){G(this,"_period");G(this,"_multiplier");G(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=cs(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class Gw{constructor(){G(this,"_preAccdist");G(this,"_preNvi");G(this,"_prePvi");G(this,"_preObv");G(this,"_prePvt");G(this,"_preWad");G(this,"_preVwap");G(this,"_preValue");G(this,"_currentData");G(this,"_preData");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={}}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,a=(t-s)/(r-e)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(self.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin")&&(s=!0,r=n=0),!s)return;const l=t*e+r,f=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:f,isReset:s});const h=l/f;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s<r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let a=1;const l=t||1;return n&&e?a=s>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}var Zc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){r.prototype.isBetween=function(s,a,l,f){var h=n(s),p=n(a),c=(f=f||"()")[0]==="(",d=f[1]===")";return(c?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(c?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(Zc);var Kw=Zc.exports,Jw=Zt(Kw),jc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){var s=r.prototype,a=function(d){var _,D=d.date,g=d.utc,y={};if(!((_=D)===null||_ instanceof Date||_ instanceof Array||s.$utils().u(_)||_.constructor.name!=="Object")){if(!Object.keys(D).length)return new Date;var v=g?n.utc():n();Object.keys(D).forEach(function($){var C,I;y[C=$,I=s.$utils().p(C),I==="date"?"day":I]=D[$]});var E=y.day||(y.year||y.month>=0?1:v.date()),b=y.year||v.year(),N=y.month>=0?y.month:y.year||y.day?0:v.month(),x=y.hour||0,F=y.minute||0,M=y.second||0,S=y.millisecond||0;return g?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return D},l=s.parse;s.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var f=s.set,h=s.add,p=s.subtract,c=function(d,_,D,g){g===void 0&&(g=1);var y=Object.keys(_),v=this;return y.forEach(function(E){v=d.bind(v)(_[E]*g,E)}),v};s.set=function(d,_){return _=_===void 0?d:_,d.constructor.name==="Object"?c.bind(this)(function(D,g){return f.bind(this)(g,D)},_,d):f.bind(this)(d,_)},s.add=function(d,_){return d.constructor.name==="Object"?c.bind(this)(h,d,_):h.bind(this)(d,_)},s.subtract=function(d,_){return d.constructor.name==="Object"?c.bind(this)(h,d,_,-1):p.bind(this)(d,_)}}})})(jc);var Xw=jc.exports,Hw=Zt(Xw),Gc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){var e,r,n=1e3,s=6e4,a=36e5,l=864e5,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,p=2628e6,c=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},_=function(F){return F instanceof N},D=function(F,M,S){return new N(F,S,M.$l)},g=function(F){return r.p(F)+"s"},y=function(F){return F<0},v=function(F){return y(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?y(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,$,C){var I=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),$)return D(S*d[g($)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){I.$d[g(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var R=S.match(c);if(R){var U=R.slice(2).map(function(q){return q!=null?Number(q):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function($,C){return $+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/h),S%=h,this.$d.months=v(S/p),S%=p,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/a),S%=a,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),$=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var I=b(C,"D"),R=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),q=this.$d.seconds||0;this.$d.milliseconds&&(q+=this.$d.milliseconds/1e3,q=Math.round(1e3*q)/1e3);var k=b(q,"S"),P=S.negative||$.negative||I.negative||R.negative||U.negative||k.negative,K=R.format||U.format||k.format?"T":"",j=(P?"-":"")+"P"+S.format+$.format+I.format+K+R.format+U.format+k.format;return j==="P"||j==="-P"?"P0D":j},M.toJSON=function(){return this.toISOString()},M.format=function(S){var $=S||"YYYY-MM-DDTHH:mm:ss",C={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return $.replace(f,function(I,R){return R||String(C[I])})},M.as=function(S){return this.$ms/d[g(S)]},M.get=function(S){var $=this.$ms,C=g(S);return C==="milliseconds"?$%=1e3:$=C==="weeks"?v($/d[C]):this.$d[C],$||0},M.add=function(S,$,C){var I;return I=$?S*d[g($)]:_(S)?S.$ms:D(S,this).$ms,D(this.$ms+I*(C?-1:1),this)},M.subtract=function(S,$){return this.add(S,$,!0)},M.locale=function(S){var $=this.clone();return $.$l=S,$},M.clone=function(){return D(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(I,R){var U=S.locale();return D(I,{$l:U},R)},S.isDuration=_;var $=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(I,R){return _(I)?x(this,I,1):$.bind(this)(I,R)},M.prototype.subtract=function(I,R){return _(I)?x(this,I,-1):C.bind(this)(I,R)}}})})(Gc);var Qw=Gc.exports,Vw=Zt(Qw);ne.extend(Jw),ne.extend(Hw),ne.extend(Vw);class tD{constructor(t,e){G(this,"array");G(this,"color");G(this,"math");G(this,"str");G(this,"map");G(this,"matrix");G(this,"timeframe");G(this,"ta");G(this,"input");G(this,"_variables");G(this,"_cacheData");G(this,"_options");G(this,"_errorListener");G(this,"_plots");G(this,"_alerts");G(this,"_bgColors");G(this,"_hlines");G(this,"_fills");G(this,"chart");G(this,"line");G(this,"label");G(this,"polyline");G(this,"box");G(this,"table");G(this,"linefill");G(this,"log");G(this,"runtime");this._variables=e,this.array=new $p,this.math=new Op(t),this.color=new a_,this.str=new lw,this.map=new fw,this.timeframe=new aw(e),this.matrix=new uw,this.ta=new i_(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this._errorListener=new Ww,this.input=new u_(e,this._errorListener),this._plots=new Map,this.chart={point:new cw(e)},this.line=new Lw(e),this.label=new hw(e),this.polyline=new Rw(e),this.box=new zw(e),this.table=new qw(e),this.linefill=new Pw(e),this.log=new Uw(e),this.runtime=new kw(this._errorListener)}get errors(){return this._errorListener.errors}get options(){const t=this.input.getInputs(),e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors).length?{...this._bgColors}:void 0,n=this._hlines.size?[...this._hlines.values()]:void 0,s=this._fills.size?[...this._fills.values()]:void 0,a=this.log.logs.length?this.log.logs:void 0;return this.log.clearLogs(),Object.assign(this._options,{inputGroups:t,plots:[...this._plots.values()],draws:this._getDraws(),alerts:e,colors:r,hlines:n,fills:s,logs:a})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:a}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}update(t){const{barIndex:e,inputs:r}=t;r&&r.length&&this.input.update(r),this.math.update(e)}indicator(t){this._variables.bar_index||(this._options.scriptType="indicator",this._options.indicator=t)}plot(t,e){const{series:r,color:n,seriesColors:s,...a}=t,{bar_index:l}=this._variables,f=`plot_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[],c=r!==void 0&&isNaN(r)?void 0:r;if(p[l]=c,s!=null&&s.length&&(this._seriesColorHandle(t,f),p[l]={value:c,itemStyle:{color:n}}),!h){const d=n?[n]:void 0;this._plots.set(f,{editable:!0,...a,colors:d,data:p,id:f})}return{type:"plot",key:f}}_seriesColorHandle(t,e){var s,a;const{seriesColors:r}=t,n=this._plots.get(e);if(n&&r!=null&&r.length)for(const l of r){if((s=n.gradientColorKeys)!=null&&s.includes(l))continue;const f=t[l],h=n[`${l}s`]||[];h.includes(f)||(h.push(f),n[`${l}s`]=h,h.length>5&&(n[`${l}s`]=[],(a=n.gradientColorKeys)==null||a.push(l)))}}plotbar(t,e){const{open:r,close:n,low:s,high:a,color:l,seriesColors:f,...h}=t,{bar_index:p}=this._variables,c=`plotbar_${e}`,d=this._plots.get(c),_=(d==null?void 0:d.data)||[],D=n!==void 0&&isNaN(n)?void 0:n,g=r!==void 0&&isNaN(r)?void 0:r,y=s!==void 0&&isNaN(s)?void 0:s,v=a!==void 0&&isNaN(a)?void 0:a,E=[g,D,y,v];if(_[p]=E,f!=null&&f.length&&(this._seriesColorHandle(t,c),_[p]={value:E,itemStyle:{color:l}}),!d){const b=l?[l]:void 0;this._plots.set(c,{editable:!0,...h,colors:b,data:_,id:c})}}plotchar(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,f=`plotchar_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotarrow(t,e){const{series:r,colorup:n,colordown:s,...a}=t,{bar_index:l}=this._variables,f=`plotarrow_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r!==void 0&&isNaN(r)?void 0:r,colorup:n,colordown:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotshape(t,e){const{series:r,color:n,textcolor:s,...a}=t,{bar_index:l}=this._variables,f=`plotshape_${e}`,h=this._plots.get(f),p=(h==null?void 0:h.data)||[];p[l]={value:r,color:n,textcolor:s},h||this._plots.set(f,{editable:!0,...a,data:p,id:f})}plotcandle(t,e){const{wickcolor:r,bordercolor:n,color:s,close:a,open:l,low:f,high:h,...p}=t,{bar_index:c}=this._variables,d=`plotcandle_${e}`,_=this._plots.get(d),D=(_==null?void 0:_.data)||[],g=a!==void 0&&isNaN(a)?void 0:a,y=l!==void 0&&isNaN(l)?void 0:l,v=f!==void 0&&isNaN(f)?void 0:f,E=h!==void 0&&isNaN(h)?void 0:h,b=[y,g,v,E];D[c]={value:b,wickcolor:r,bordercolor:n,color:s},_||this._plots.set(d,{editable:!0,...p,data:D,id:d})}hline(t,e){const r=`hline_${e}`;return this._hlines.set(r,{linewidth:1,editable:!0,display:tr.all,...t}),{type:"hline",key:r}}fill(t,e){const r=`fill_${e}`;this._fills.set(r,{display:tr.all,editable:!0,fillgaps:!1,...t})}alert({message:t,freq:e=an.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:a}=this._variables,l=`alert_${r}`,f=this._cacheData[l].barIndex;if(e===an.freqOncePerBar&&n===f){this._alerts.delete(l);return}const h={message:t,freq:e,id:l,type:"alert"};if(s){e!==an.freqOncePerBarClose&&this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}if(!s&&e===an.freqOncePerBarClose&&n===f&&a===n-1){this._alerts.set(l,h),this._cacheData[l].barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,a=`alertcondition_${n}`;s&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t){this._setColors(t,"barcolor")}bgcolor(t){this._setColors(t,"bgcolor")}_setColors(t,e){var l,f;const{color:r,...n}=t,{bar_index:s}=this._variables,a=((l=this._bgColors[e])==null?void 0:l.colors)||[];if(!a[s]){const h=((f=this._bgColors[e])==null?void 0:f.setColors)||[];h.includes(r)||h.push(r),a[s]=r,this._bgColors[e]={...n,colors:a,setColors:h}}}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return t===void 0}nz({source:t,replacement:e}){return t!==void 0&&!isNaN(t)?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._variables.time_close&&this._timeHandle(this._variables.time_close,s,t,e,r,n)}timestamp({dateString:t,timezone:e,year:r,month:n,day:s,hour:a=0,minute:l=0,second:f=0}){if(t)return ne(t).valueOf();let h=ne({year:r,month:n,day:s,hour:a,minute:l,second:f});return e&&(h=Fr(h.valueOf(),e)),h.valueOf()}weekofyear({time:t,timezone:e}){return Fr(t,e).week()}year({time:t,timezone:e}){return Fr(t,e).year()}second({time:t,timezone:e}){return Fr(t,e).second()}month({time:t,timezone:e}){return Fr(t,e).month()+1}minute({time:t,timezone:e}){return Fr(t,e).minute()}hour({time:t,timezone:e}){return Fr(t,e).hour()}dayofweek({time:t,timezone:e}){return Fr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return Fr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Bn(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,a=0){const l=r||this._variables.timeframe.period,f=Bn(l),h=Bn(this._variables.timeframe.period);let p;if(f<=h)p=t;else{const c=`time_${e}`,d=this._cacheData[c];if(d)d.currentTime+f*1e3-d.offset<=t?(p=t,this._cacheData[c]={currentTime:t,offset:0}):p=d;else{const _=this._calcTimeOffset(t,l);this._cacheData[c]={currentTime:t,offset:_},p=t}}if(n){const{timePeriods:c,weeks:d}=this._parserSession(n),_=ne(t).format("YYYY-MM-DD"),D=p;p=void 0;for(const y of c){const[v,E]=y;if(ne(t).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")){ne(D).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")?p=D:p=ne(`${_} ${v}`).valueOf();break}}const g=this._variables.dayofweek;p&&!d.includes(g)&&(p=void 0)}return s&&(p=p&&Fr(p,s).valueOf()),p&&p-a*h*1e3}_parserSession(t){const e=t.split(":"),r=e[0],s=(e[1]||"1234567").split("").map(l=>{const f=parseInt(l,10);if(f<1||f>7)throw new Error(`Invalid day of week: ${l}`);return f});return{timePeriods:r.split(",").map(l=>{const f=l.split("-");if(f.length!==2)throw new Error(`Invalid time period: ${l}`);return[this._processTime(f[0]),this._processTime(f[1])]}),weeks:s}}_processTime(t){const e=parseInt(t.slice(0,2),10),r=parseInt(t.slice(2),10);if(!(e>=0&&e<=23)&&r>=0&&r<=59)throw new Error("Invalid time: Time must be within 00:00 to 23:59");return`${e}:${r}`}}/**
63
63
  * @license
64
64
  * Copyright 2019 Google LLC
65
65
  * SPDX-License-Identifier: Apache-2.0
@@ -36,14 +36,22 @@ interface IStrategy {
36
36
  interface IOrderArgs {
37
37
  id: string;
38
38
  direction: VDirection;
39
+ from_entry?: string;
39
40
  qty?: number;
40
41
  limit?: number;
42
+ loss?: number;
41
43
  stop?: number;
42
44
  oca_name?: string;
43
45
  oca_type?: VOca;
44
46
  comment?: string;
45
47
  alert_message?: string;
46
48
  disable_alert?: false;
49
+ qty_percent?: number;
50
+ immediately?: boolean;
51
+ trail_price?: number;
52
+ trail_points?: number;
53
+ trail_offset?: number;
54
+ profit?: number;
47
55
  }
48
56
  type CloseEntriesRuleType = 'FIFO' | 'ANY';
49
57
  export default class Strategy {
@@ -53,7 +61,8 @@ export default class Strategy {
53
61
  private _historyOrder;
54
62
  private _orders;
55
63
  private _pendingOrders;
56
- constructor(variables: BuiltInVariables);
64
+ private _mintick;
65
+ constructor(variables: BuiltInVariables, mintick?: number);
57
66
  get options(): {
58
67
  title?: string | undefined;
59
68
  shorttitle?: string | undefined;
@@ -91,5 +100,10 @@ export default class Strategy {
91
100
  strategy(args: IStrategy): void;
92
101
  order(args: IOrderArgs): void;
93
102
  private _longOrderHandle;
103
+ private _shortOrderHandle;
104
+ private _closeOrderHandle;
105
+ private _exitOrderHandle;
106
+ private _exit;
107
+ private _isNaN;
94
108
  }
95
109
  export {};
@@ -65017,7 +65017,7 @@ function Jr(s, i, a) {
65017
65017
  function wb() {
65018
65018
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
65019
65019
  }
65020
- const lu = new Worker(new URL("" + new URL("assets/scriptsRunWorker-Bx4RsHhS.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
65020
+ const lu = new Worker(new URL("" + new URL("assets/scriptsRunWorker-DEh9seQE.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
65021
65021
  lu.onerror = (s) => {
65022
65022
  console.error(s);
65023
65023
  };