@guihz/trading-vue-editor-tes 0.0.202 → 0.0.203

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,10 +59,10 @@ ${Qs}rows: ${s.rows}
59
59
  ${Qs}columns: ${s.columns}
60
60
  }`}function O1(s,t,e,r,n){const{rows:i,columns:a}=s,l=Math.min(i,t),c=Math.min(a,e),h=[];if(n==="auto"){n=!1;t:for(let p=0;p<l;p++)for(let f=0;f<c;f++)if(s.get(p,f)<0){n=!0;break t}}for(let p=0;p<l;p++){let f=[];for(let d=0;d<c;d++)f.push(I1(s.get(p,d),r,n));h.push(`${f.join(" ")}`)}return c!==a&&(h[h.length-1]+=` ... ${a-e} more columns`),l!==i&&h.push(`... ${i-t} more rows`),h.join(`
61
61
  ${zf}`)}function I1(s,t,e){return(s>=0&&e?` ${qf(s,t-1)}`:qf(s,t)).padEnd(t)}function qf(s,t){let e=s.toString();if(e.length<=t)return e;let r=s.toFixed(t);if(r.length>t&&(r=s.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=s.toExponential(t);return n.length>t&&(n=s.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function T1(s,t){s.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},s.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+r);return this},s.prototype.addM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)+r.get(n,i));return this},s.add=function(r,n){return new t(r).add(n)},s.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},s.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-r);return this},s.prototype.subM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)-r.get(n,i));return this},s.sub=function(r,n){return new t(r).sub(n)},s.prototype.subtract=s.prototype.sub,s.prototype.subtractS=s.prototype.subS,s.prototype.subtractM=s.prototype.subM,s.subtract=s.sub,s.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},s.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*r);return this},s.prototype.mulM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)*r.get(n,i));return this},s.mul=function(r,n){return new t(r).mul(n)},s.prototype.multiply=s.prototype.mul,s.prototype.multiplyS=s.prototype.mulS,s.prototype.multiplyM=s.prototype.mulM,s.multiply=s.mul,s.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},s.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/r);return this},s.prototype.divM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)/r.get(n,i));return this},s.div=function(r,n){return new t(r).div(n)},s.prototype.divide=s.prototype.div,s.prototype.divideS=s.prototype.divS,s.prototype.divideM=s.prototype.divM,s.divide=s.div,s.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},s.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%r);return this},s.prototype.modM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)%r.get(n,i));return this},s.mod=function(r,n){return new t(r).mod(n)},s.prototype.modulus=s.prototype.mod,s.prototype.modulusS=s.prototype.modS,s.prototype.modulusM=s.prototype.modM,s.modulus=s.mod,s.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},s.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&r);return this},s.prototype.andM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)&r.get(n,i));return this},s.and=function(r,n){return new t(r).and(n)},s.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},s.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|r);return this},s.prototype.orM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)|r.get(n,i));return this},s.or=function(r,n){return new t(r).or(n)},s.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},s.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^r);return this},s.prototype.xorM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)^r.get(n,i));return this},s.xor=function(r,n){return new t(r).xor(n)},s.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},s.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<r);return this},s.prototype.leftShiftM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)<<r.get(n,i));return this},s.leftShift=function(r,n){return new t(r).leftShift(n)},s.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},s.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>r);return this},s.prototype.signPropagatingRightShiftM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>r.get(n,i));return this},s.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},s.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},s.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>r);return this},s.prototype.rightShiftM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,this.get(n,i)>>>r.get(n,i));return this},s.rightShift=function(r,n){return new t(r).rightShift(n)},s.prototype.zeroFillRightShift=s.prototype.rightShift,s.prototype.zeroFillRightShiftS=s.prototype.rightShiftS,s.prototype.zeroFillRightShiftM=s.prototype.rightShiftM,s.zeroFillRightShift=s.rightShift,s.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},s.not=function(r){return new t(r).not()},s.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},s.abs=function(r){return new t(r).abs()},s.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},s.acos=function(r){return new t(r).acos()},s.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},s.acosh=function(r){return new t(r).acosh()},s.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},s.asin=function(r){return new t(r).asin()},s.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},s.asinh=function(r){return new t(r).asinh()},s.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},s.atan=function(r){return new t(r).atan()},s.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},s.atanh=function(r){return new t(r).atanh()},s.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},s.cbrt=function(r){return new t(r).cbrt()},s.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},s.ceil=function(r){return new t(r).ceil()},s.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},s.clz32=function(r){return new t(r).clz32()},s.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},s.cos=function(r){return new t(r).cos()},s.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},s.cosh=function(r){return new t(r).cosh()},s.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},s.exp=function(r){return new t(r).exp()},s.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},s.expm1=function(r){return new t(r).expm1()},s.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},s.floor=function(r){return new t(r).floor()},s.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},s.fround=function(r){return new t(r).fround()},s.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},s.log=function(r){return new t(r).log()},s.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},s.log1p=function(r){return new t(r).log1p()},s.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},s.log10=function(r){return new t(r).log10()},s.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},s.log2=function(r){return new t(r).log2()},s.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},s.round=function(r){return new t(r).round()},s.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},s.sign=function(r){return new t(r).sign()},s.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},s.sin=function(r){return new t(r).sin()},s.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},s.sinh=function(r){return new t(r).sinh()},s.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},s.sqrt=function(r){return new t(r).sqrt()},s.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},s.tan=function(r){return new t(r).tan()},s.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},s.tanh=function(r){return new t(r).tanh()},s.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},s.trunc=function(r){return new t(r).trunc()},s.pow=function(r,n){return new t(r).pow(n)},s.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},s.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let i=0;i<this.columns;i++)this.set(n,i,Math.pow(this.get(n,i),r));return this},s.prototype.powM=function(r){if(r=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 i=0;i<this.columns;i++)this.set(n,i,Math.pow(this.get(n,i),r.get(n,i)));return this}}function Sr(s,t,e){let r=e?s.rows:s.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function Br(s,t,e){let r=e?s.columns:s.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function Di(s,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==s.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function bi(s,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==s.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function La(s,t){if(!cr.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]>=s.rows)throw new RangeError("row indices are out of range")}function Ra(s,t){if(!cr.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]>=s.columns)throw new RangeError("column indices are out of range")}function Pa(s,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(eo("startRow",t),eo("endRow",e),eo("startColumn",r),eo("endColumn",n),t>e||r>n||t<0||t>=s.rows||e<0||e>=s.rows||r<0||r>=s.columns||n<0||n>=s.columns)throw new RangeError("Submatrix indices are out of range")}function to(s,t=0){let e=[];for(let r=0;r<s;r++)e.push(t);return e}function eo(s,t){if(typeof t!="number")throw new TypeError(`${s} must be a number`)}function xi(s){if(s.isEmpty())throw new Error("Empty matrix has no elements to index")}function $1(s){let t=to(s.rows);for(let e=0;e<s.rows;++e)for(let r=0;r<s.columns;++r)t[e]+=s.get(e,r);return t}function L1(s){let t=to(s.columns);for(let e=0;e<s.rows;++e)for(let r=0;r<s.columns;++r)t[r]+=s.get(e,r);return t}function R1(s){let t=0;for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)t+=s.get(e,r);return t}function P1(s){let t=to(s.rows,1);for(let e=0;e<s.rows;++e)for(let r=0;r<s.columns;++r)t[e]*=s.get(e,r);return t}function z1(s){let t=to(s.columns,1);for(let e=0;e<s.rows;++e)for(let r=0;r<s.columns;++r)t[r]*=s.get(e,r);return t}function k1(s){let t=1;for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)t*=s.get(e,r);return t}function q1(s,t,e){const r=s.rows,n=s.columns,i=[];for(let a=0;a<r;a++){let l=0,c=0,h=0;for(let p=0;p<n;p++)h=s.get(a,p)-e[a],l+=h,c+=h*h;t?i.push((c-l*l/n)/(n-1)):i.push((c-l*l/n)/n)}return i}function U1(s,t,e){const r=s.rows,n=s.columns,i=[];for(let a=0;a<n;a++){let l=0,c=0,h=0;for(let p=0;p<r;p++)h=s.get(p,a)-e[a],l+=h,c+=h*h;t?i.push((c-l*l/r)/(r-1)):i.push((c-l*l/r)/r)}return i}function W1(s,t,e){const r=s.rows,n=s.columns,i=r*n;let a=0,l=0,c=0;for(let h=0;h<r;h++)for(let p=0;p<n;p++)c=s.get(h,p)-e,a+=c,l+=c*c;return t?(l-a*a/i)/(i-1):(l-a*a/i)/i}function j1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)-t[e])}function V1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)-t[r])}function Y1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)-t)}function Z1(s){const t=[];for(let e=0;e<s.rows;e++){let r=0;for(let n=0;n<s.columns;n++)r+=Math.pow(s.get(e,n),2)/(s.columns-1);t.push(Math.sqrt(r))}return t}function K1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)/t[e])}function G1(s){const t=[];for(let e=0;e<s.columns;e++){let r=0;for(let n=0;n<s.rows;n++)r+=Math.pow(s.get(n,e),2)/(s.rows-1);t.push(Math.sqrt(r))}return t}function H1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.get(e,r)/t[r])}function J1(s){const t=s.size-1;let e=0;for(let r=0;r<s.columns;r++)for(let n=0;n<s.rows;n++)e+=Math.pow(s.get(n,r),2)/t;return Math.sqrt(e)}function X1(s,t){for(let e=0;e<s.rows;e++)for(let r=0;r<s.columns;r++)s.set(e,r,s.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 i=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)i.set(a,l,r[a*e+l]);return i}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 i=new pt(t,e);for(let a=0;a<t;a++)for(let l=0;l<e;l++)i.set(a,l,n());return i}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:i=1e3,random:a=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(i))throw new TypeError("max must be an integer");if(n>=i)throw new RangeError("min must be smaller than max");let l=i-n,c=new pt(t,e);for(let h=0;h<t;h++)for(let p=0;p<e;p++){let f=n+Math.round(a()*l);c.set(h,p,f)}return c}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),i=this.zeros(t,e);for(let a=0;a<n;a++)i.set(a,a,r);return i}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let i=Math.min(n,e,r),a=this.zeros(e,r);for(let l=0;l<i;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,i=new pt(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)i.set(a,l,Math.min(t.get(a,l),e.get(a,l)));return i}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,i=new this(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)i.set(a,l,Math.max(t.get(a,l),e.get(a,l)));return i}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,i=!1;for(;t<this.rows&&n;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(i=!0,r=e):(n=!1,i=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,i=!1;for(;t<this.rows&&n;){for(e=0,i=!1;e<this.columns&&i===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(i=!0,r=e):(n=!1,i=!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 i=e;i<t.rows;i++)t.get(i,r)>t.get(n,r)&&(n=i);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let i=t.get(e,r);for(let a=r;a<t.columns;a++)t.set(e,a,t.get(e,a)/i);for(let a=e+1;a<t.rows;a++){let l=t.get(a,r)/t.get(e,r);t.set(a,r,0);for(let c=r+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(e,c)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let i=0,a=!1;for(;i<r&&a===!1;)t.get(n,i)===1?a=!0:i++;for(let l=0;l<n;l++){let c=t.get(l,i);for(let h=i;h<e;h++){let p=t.get(l,h)-c*t.get(n,h);t.set(l,h,p)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new pt(this.rows*e,this.columns*r);for(let i=0;i<e;i++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*i,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){Sr(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){Sr(this,t),e=Di(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Sr(this,t),Sr(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){Br(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return pt.columnVector(this.getColumn(t))}setColumn(t,e){Br(this,t),e=bi(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){Br(this,t),Br(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=Di(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=Di(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=Di(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=Di(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=bi(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=bi(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=bi(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=bi(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){Sr(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){Br(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){xi(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(){xi(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(Sr(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){Sr(this,t),xi(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(Sr(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){Sr(this,t),xi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(Br(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){Br(this,t),xi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(Br(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){Br(this,t),xi(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,i=new pt(e,n),a=new Float64Array(r);for(let l=0;l<n;l++){for(let c=0;c<r;c++)a[c]=t.get(c,l);for(let c=0;c<e;c++){let h=0;for(let p=0;p<r;p++)h+=this.get(c,p)*a[p];i.set(c,l,h)}}return i}strassen2x2(t){t=pt.checkMatrix(t);let e=new pt(2,2);const r=this.get(0,0),n=t.get(0,0),i=this.get(0,1),a=t.get(0,1),l=this.get(1,0),c=t.get(1,0),h=this.get(1,1),p=t.get(1,1),f=(r+h)*(n+p),d=(l+h)*n,g=r*(a-p),y=h*(c-n),m=(r+i)*p,w=(l-r)*(n+a),v=(i-h)*(c+p),x=f+y-m+v,b=g+m,N=d+y,E=f-d+g+w;return e.set(0,0,x),e.set(0,1,b),e.set(1,0,N),e.set(1,1,E),e}strassen3x3(t){t=pt.checkMatrix(t);let e=new pt(3,3);const r=this.get(0,0),n=this.get(0,1),i=this.get(0,2),a=this.get(1,0),l=this.get(1,1),c=this.get(1,2),h=this.get(2,0),p=this.get(2,1),f=this.get(2,2),d=t.get(0,0),g=t.get(0,1),y=t.get(0,2),m=t.get(1,0),w=t.get(1,1),v=t.get(1,2),x=t.get(2,0),b=t.get(2,1),N=t.get(2,2),E=(r+n+i-a-l-p-f)*w,A=(r-a)*(-g+w),M=l*(-d+g+m-w-v-x+N),S=(-r+a+l)*(d-g+w),T=(a+l)*(-d+g),F=r*d,O=(-r+h+p)*(d-y+v),R=(-r+h)*(y-v),U=(h+p)*(-d+y),q=(r+n+i-l-c-h-p)*v,W=p*(-d+y+m-w-v-x+b),z=(-i+p+f)*(w+x-b),K=(i-f)*(w-b),Z=i*x,X=(p+f)*(-x+b),Q=(-i+l+c)*(v+x-N),ct=(i-c)*(v-N),vt=(l+c)*(-x+N),lt=n*m,wt=c*b,bt=a*y,Bt=h*g,xt=f*N,oe=F+Z+lt,It=E+S+T+F+z+Z+X,Nt=F+O+U+q+Z+Q+vt,ce=A+M+S+F+Z+Q+ct,re=A+S+T+F+wt,qt=Z+Q+ct+vt+bt,Jt=F+O+R+W+z+K+Z,$e=z+K+Z+X+Bt,vr=F+O+R+U+xt;return e.set(0,0,oe),e.set(0,1,It),e.set(0,2,Nt),e.set(1,0,ce),e.set(1,1,re),e.set(1,2,qt),e.set(2,0,Jt),e.set(2,1,$e),e.set(2,2,vr),e}mmulStrassen(t){t=pt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,i=t.rows,a=t.columns;n!==i&&console.warn(`Multiplying ${r} x ${n} and ${i} x ${a} matrix: dimensions do not match.`);function l(f,d,g){let y=f.rows,m=f.columns;if(y===d&&m===g)return f;{let w=$t.zeros(d,g);return w=w.setSubMatrix(f,0,0),w}}let c=Math.max(r,i),h=Math.max(n,a);e=l(e,c,h),t=l(t,c,h);function p(f,d,g,y){if(g<=512||y<=512)return f.mmul(d);g%2===1&&y%2===1?(f=l(f,g+1,y+1),d=l(d,g+1,y+1)):g%2===1?(f=l(f,g+1,y),d=l(d,g+1,y)):y%2===1&&(f=l(f,g,y+1),d=l(d,g,y+1));let m=parseInt(f.rows/2,10),w=parseInt(f.columns/2,10),v=f.subMatrix(0,m-1,0,w-1),x=d.subMatrix(0,m-1,0,w-1),b=f.subMatrix(0,m-1,w,f.columns-1),N=d.subMatrix(0,m-1,w,d.columns-1),E=f.subMatrix(m,f.rows-1,0,w-1),A=d.subMatrix(m,d.rows-1,0,w-1),M=f.subMatrix(m,f.rows-1,w,f.columns-1),S=d.subMatrix(m,d.rows-1,w,d.columns-1),T=p($t.add(v,M),$t.add(x,S),m,w),F=p($t.add(E,M),x,m,w),O=p(v,$t.sub(N,S),m,w),R=p(M,$t.sub(A,x),m,w),U=p($t.add(v,b),S,m,w),q=p($t.sub(E,v),$t.add(x,N),m,w),W=p($t.sub(b,M),$t.add(A,S),m,w),z=$t.add(T,R);z.sub(U),z.add(W);let K=$t.add(O,U),Z=$t.add(F,R),X=$t.sub(T,F);X.add(O),X.add(q);let Q=$t.zeros(2*z.rows,2*z.columns);return Q=Q.setSubMatrix(z,0,0),Q=Q.setSubMatrix(K,z.rows,0),Q=Q.setSubMatrix(Z,0,z.columns),Q=Q.setSubMatrix(X,z.rows,z.columns),Q.subMatrix(0,g-1,0,y-1)}return p(e,t,c,h)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let i=0;i<this.rows;i++){const a=this.getRow(i);a.length>0&&Pf(a,{min:e,max:r,output:a}),n.setRow(i,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 i=0;i<this.columns;i++){const a=this.getColumn(i);a.length&&Pf(a,{min:e,max:r,output:a}),n.setColumn(i,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),i=this.get(e,this.columns-1-r);this.set(e,r,i),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),i=this.get(this.rows-1-r,e);this.set(r,e,i),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,i=t.columns,a=new pt(e*n,r*i);for(let l=0;l<e;l++)for(let c=0;c<r;c++)for(let h=0;h<n;h++)for(let p=0;p<i;p++)a.set(n*l+h,i*c+p,this.get(l,c)*t.get(h,p));return a}kroneckerSum(t){if(t=pt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(pt.eye(r,r)),i=pt.eye(e,e).kroneckerProduct(t);return n.add(i)}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=Uf){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=Uf){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Pa(this,t,e,r,n);let i=new pt(e-t+1,n-r+1);for(let a=t;a<=e;a++)for(let l=r;l<=n;l++)i.set(a-t,l-r,this.get(a,l));return i}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 i=0;i<t.length;i++)for(let a=e;a<=r;a++){if(t[i]<0||t[i]>=this.rows)throw new RangeError(`Row index out of range: ${t[i]}`);n.set(i,a-e,this.get(t[i],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 i=0;i<t.length;i++)for(let a=e;a<=r;a++){if(t[i]<0||t[i]>=this.columns)throw new RangeError(`Column index out of range: ${t[i]}`);n.set(a-e,i,this.get(a,t[i]))}return n}setSubMatrix(t,e,r){if(t=pt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,i=r+t.columns-1;Pa(this,e,n,r,i);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){La(this,t),Ra(this,e);let r=new pt(t.length,e.length);for(let n=0;n<t.length;n++){let i=t[n];for(let a=0;a<e.length;a++){let l=e[a];r.set(n,a,this.get(i,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,i]of t.entries())e.set(r,n,i);return e}sum(t){switch(t){case"row":return $1(this);case"column":return L1(this);case void 0:return R1(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return P1(this);case"column":return z1(this);case void 0:return k1(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(!cr.isAnyArray(n))throw new TypeError("mean must be an array");return q1(this,r,n)}case"column":{if(!cr.isAnyArray(n))throw new TypeError("mean must be an array");return U1(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return W1(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(!cr.isAnyArray(r))throw new TypeError("center must be an array");return j1(this,r),this}case"column":{if(!cr.isAnyArray(r))throw new TypeError("center must be an array");return V1(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return Y1(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=Z1(this);else if(!cr.isAnyArray(r))throw new TypeError("scale must be an array");return K1(this,r),this}case"column":{if(r===void 0)r=G1(this);else if(!cr.isAnyArray(r))throw new TypeError("scale must be an array");return H1(this,r),this}case void 0:{if(r===void 0)r=J1(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return X1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return kf(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")]=B1);function Uf(s,t){return s-t}function Q1(s){return s.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=(Ni=class extends $t{constructor(e,r){super();Al(this,es);$(this,"data");if(Ni.isMatrix(e))Cl(this,es,Fl).call(this,e.rows,e.columns),Ni.copy(e,this);else if(Number.isInteger(e)&&e>=0)Cl(this,es,Fl).call(this,e,r);else if(cr.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 i=0;i<e;i++){if(n[i].length!==r)throw new RangeError("Inconsistent array dimensions");if(!Q1(n[i]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[i]))}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 Sr(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),Sr(this,e,!0),r=Float64Array.from(Di(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){Br(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let i=0;i<e;i++)n[i]=this.data[r][i];for(let i=e+1;i<this.columns;i++)n[i-1]=this.data[r][i];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),Br(this,e,!0),r=bi(this,r);for(let n=0;n<this.rows;n++){const i=new Float64Array(this.columns+1);let a=0;for(;a<e;a++)i[a]=this.data[n][a];for(i[a++]=r[n];a<this.columns+1;a++)i[a]=this.data[n][a-1];this.data[n]=i}return this.columns+=1,this}},es=new WeakSet,Fl=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},Ni);T1($t,pt);const go=class go extends $t{constructor(e){super();Al(this,Xe,void 0);if(pt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");ua(this,Xe,pt.copy(e,new pt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)ua(this,Xe,new pt(e,e));else if(ua(this,Xe,new pt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Jr(this,Xe).size}get rows(){return Jr(this,Xe).rows}get columns(){return Jr(this,Xe).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 go(this.diagonalSize);for(const[r,n,i]of this.upperRightEntries())e.set(r,n,i);return e}toMatrix(){return new pt(this)}get(e,r){return Jr(this,Xe).get(e,r)}set(e,r,n){return Jr(this,Xe).set(e,r,n),Jr(this,Xe).set(r,e,n),this}removeCross(e){return Jr(this,Xe).removeRow(e),Jr(this,Xe).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Jr(this,Xe).addRow(e,n),Jr(this,Xe).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,i]of e.entries())i||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,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=e&&(n=++i);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 i=new go(n);for(let a=0,l=0,c=0;c<r;c++)i.set(a,l,e[c]),++a>=n&&(a=++l);return i}*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)}};Xe=new WeakMap;let Xn=go;Xn.prototype.klassType="SymmetricMatrix";class ro extends Xn{static isDistanceMatrix(t){return Xn.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 Xn(this)}clone(){const t=new ro(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,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=t&&(n=++i+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 i=1,a=0,l=0;l<e;l++)n.set(i,a,t[l]),++i>=r&&(i=++a+1);return n}}ro.prototype.klassSubType="DistanceMatrix";class fn extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class ty extends fn{constructor(t,e){Br(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class ey extends fn{constructor(t,e){Ra(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 ry extends fn{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 ny extends fn{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 iy extends fn{constructor(t,e){Sr(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 sy extends fn{constructor(t,e){La(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 no extends fn{constructor(t,e,r){La(t,e),Ra(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 oy extends fn{constructor(t,e,r,n,i){Pa(t,e,r,n,i),super(t,r-e+1,i-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 ay extends fn{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 Wf 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 gr 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 uy(s,t){if(cr.isAnyArray(s))return s[0]&&cr.isAnyArray(s[0])?new gr(s):new Wf(s,t);throw new Error("the argument is not an array")}class io{constructor(t){t=gr.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,i=new Float64Array(r),a=1,l,c,h,p,f,d,g,y,m;for(l=0;l<r;l++)i[l]=l;for(y=new Float64Array(r),c=0;c<n;c++){for(l=0;l<r;l++)y[l]=e.get(l,c);for(l=0;l<r;l++){for(m=Math.min(l,c),f=0,h=0;h<m;h++)f+=e.get(l,h)*y[h];y[l]-=f,e.set(l,c,y[l])}for(p=c,l=c+1;l<r;l++)Math.abs(y[l])>Math.abs(y[p])&&(p=l);if(p!==c){for(h=0;h<n;h++)d=e.get(p,h),e.set(p,h,e.get(c,h)),e.set(c,h,d);g=i[p],i[p]=i[c],i[c]=g,a=-a}if(c<r&&e.get(c,c)!==0)for(l=c+1;l<r;l++)e.set(l,c,e.get(l,c)/e.get(c,c))}this.LU=e,this.pivotVector=i,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,i=t.subMatrixRow(this.pivotVector,0,n-1),a=e.columns,l,c,h;for(h=0;h<a;h++)for(l=h+1;l<a;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(h,c)*e.get(l,h));for(h=a-1;h>=0;h--){for(c=0;c<n;c++)i.set(h,c,i.get(h,c)/e.get(h,h));for(l=0;l<h;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(h,c)*e.get(l,h))}return i}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 i=0;i<e;i++)for(let a=0;a<r;a++)i>a?n.set(i,a,t.get(i,a)):i===a?n.set(i,a,1):n.set(i,a,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let i=0;i<e;i++)for(let a=0;a<r;a++)i<=a?n.set(i,a,t.get(i,a)):n.set(i,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function hn(s,t){let e=0;return Math.abs(s)>Math.abs(t)?(e=t/s,Math.abs(s)*Math.sqrt(1+e*e)):t!==0?(e=s/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class za{constructor(t){t=gr.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,i=new Float64Array(n),a,l,c,h;for(c=0;c<n;c++){let p=0;for(a=c;a<r;a++)p=hn(p,e.get(a,c));if(p!==0){for(e.get(c,c)<0&&(p=-p),a=c;a<r;a++)e.set(a,c,e.get(a,c)/p);for(e.set(c,c,e.get(c,c)+1),l=c+1;l<n;l++){for(h=0,a=c;a<r;a++)h+=e.get(a,c)*e.get(a,l);for(h=-h/e.get(c,c),a=c;a<r;a++)e.set(a,l,e.get(a,l)+h*e.get(a,c))}}i[c]=-p}this.QR=e,this.Rdiag=i}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,i=t.clone(),a=e.columns,l,c,h,p;for(h=0;h<a;h++)for(c=0;c<n;c++){for(p=0,l=h;l<r;l++)p+=e.get(l,h)*i.get(l,c);for(p=-p/e.get(h,h),l=h;l<r;l++)i.set(l,c,i.get(l,c)+p*e.get(l,h))}for(h=a-1;h>=0;h--){for(c=0;c<n;c++)i.set(h,c,i.get(h,c)/this.Rdiag[h]);for(l=0;l<h;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(h,c)*e.get(l,h))}return i.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,i;for(n=0;n<e;n++)for(i=0;i<e;i++)n<i?r.set(n,i,t.get(n,i)):n===i?r.set(n,i,this.Rdiag[n]):r.set(n,i,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new pt(e,r),i,a,l,c;for(l=r-1;l>=0;l--){for(i=0;i<e;i++)n.set(i,l,0);for(n.set(l,l,1),a=l;a<r;a++)if(t.get(l,l)!==0){for(c=0,i=l;i<e;i++)c+=t.get(i,l)*n.get(i,a);for(c=-c/t.get(l,l),i=l;i<e;i++)n.set(i,a,n.get(i,a)+c*t.get(i,l))}}return n}}class Ei{constructor(t,e={}){if(t=gr.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:a=!0,autoTranspose:l=!1}=e;let c=!!i,h=!!a,p=!1,f;if(r<n)if(!l)f=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{f=t.transpose(),r=f.rows,n=f.columns,p=!0;let F=c;c=h,h=F}else f=t.clone();let d=Math.min(r,n),g=Math.min(r+1,n),y=new Float64Array(g),m=new pt(r,d),w=new pt(n,n),v=new Float64Array(n),x=new Float64Array(r),b=new Float64Array(g);for(let F=0;F<g;F++)b[F]=F;let N=Math.min(r-1,n),E=Math.max(0,Math.min(n-2,r)),A=Math.max(N,E);for(let F=0;F<A;F++){if(F<N){y[F]=0;for(let O=F;O<r;O++)y[F]=hn(y[F],f.get(O,F));if(y[F]!==0){f.get(F,F)<0&&(y[F]=-y[F]);for(let O=F;O<r;O++)f.set(O,F,f.get(O,F)/y[F]);f.set(F,F,f.get(F,F)+1)}y[F]=-y[F]}for(let O=F+1;O<n;O++){if(F<N&&y[F]!==0){let R=0;for(let U=F;U<r;U++)R+=f.get(U,F)*f.get(U,O);R=-R/f.get(F,F);for(let U=F;U<r;U++)f.set(U,O,f.get(U,O)+R*f.get(U,F))}v[O]=f.get(F,O)}if(c&&F<N)for(let O=F;O<r;O++)m.set(O,F,f.get(O,F));if(F<E){v[F]=0;for(let O=F+1;O<n;O++)v[F]=hn(v[F],v[O]);if(v[F]!==0){v[F+1]<0&&(v[F]=0-v[F]);for(let O=F+1;O<n;O++)v[O]/=v[F];v[F+1]+=1}if(v[F]=-v[F],F+1<r&&v[F]!==0){for(let O=F+1;O<r;O++)x[O]=0;for(let O=F+1;O<r;O++)for(let R=F+1;R<n;R++)x[O]+=v[R]*f.get(O,R);for(let O=F+1;O<n;O++){let R=-v[O]/v[F+1];for(let U=F+1;U<r;U++)f.set(U,O,f.get(U,O)+R*x[U])}}if(h)for(let O=F+1;O<n;O++)w.set(O,F,v[O])}}let M=Math.min(n,r+1);if(N<n&&(y[N]=f.get(N,N)),r<M&&(y[M-1]=0),E+1<M&&(v[E]=f.get(E,M-1)),v[M-1]=0,c){for(let F=N;F<d;F++){for(let O=0;O<r;O++)m.set(O,F,0);m.set(F,F,1)}for(let F=N-1;F>=0;F--)if(y[F]!==0){for(let O=F+1;O<d;O++){let R=0;for(let U=F;U<r;U++)R+=m.get(U,F)*m.get(U,O);R=-R/m.get(F,F);for(let U=F;U<r;U++)m.set(U,O,m.get(U,O)+R*m.get(U,F))}for(let O=F;O<r;O++)m.set(O,F,-m.get(O,F));m.set(F,F,1+m.get(F,F));for(let O=0;O<F-1;O++)m.set(O,F,0)}else{for(let O=0;O<r;O++)m.set(O,F,0);m.set(F,F,1)}}if(h)for(let F=n-1;F>=0;F--){if(F<E&&v[F]!==0)for(let O=F+1;O<n;O++){let R=0;for(let U=F+1;U<n;U++)R+=w.get(U,F)*w.get(U,O);R=-R/w.get(F+1,F);for(let U=F+1;U<n;U++)w.set(U,O,w.get(U,O)+R*w.get(U,F))}for(let O=0;O<n;O++)w.set(O,F,0);w.set(F,F,1)}let S=M-1,T=Number.EPSILON;for(;M>0;){let F,O;for(F=M-2;F>=-1&&F!==-1;F--){const R=Number.MIN_VALUE+T*Math.abs(y[F]+Math.abs(y[F+1]));if(Math.abs(v[F])<=R||Number.isNaN(v[F])){v[F]=0;break}}if(F===M-2)O=4;else{let R;for(R=M-1;R>=F&&R!==F;R--){let U=(R!==M?Math.abs(v[R]):0)+(R!==F+1?Math.abs(v[R-1]):0);if(Math.abs(y[R])<=T*U){y[R]=0;break}}R===F?O=3:R===M-1?O=1:(O=2,F=R)}switch(F++,O){case 1:{let R=v[M-2];v[M-2]=0;for(let U=M-2;U>=F;U--){let q=hn(y[U],R),W=y[U]/q,z=R/q;if(y[U]=q,U!==F&&(R=-z*v[U-1],v[U-1]=W*v[U-1]),h)for(let K=0;K<n;K++)q=W*w.get(K,U)+z*w.get(K,M-1),w.set(K,M-1,-z*w.get(K,U)+W*w.get(K,M-1)),w.set(K,U,q)}break}case 2:{let R=v[F-1];v[F-1]=0;for(let U=F;U<M;U++){let q=hn(y[U],R),W=y[U]/q,z=R/q;if(y[U]=q,R=-z*v[U],v[U]=W*v[U],c)for(let K=0;K<r;K++)q=W*m.get(K,U)+z*m.get(K,F-1),m.set(K,F-1,-z*m.get(K,U)+W*m.get(K,F-1)),m.set(K,U,q)}break}case 3:{const R=Math.max(Math.abs(y[M-1]),Math.abs(y[M-2]),Math.abs(v[M-2]),Math.abs(y[F]),Math.abs(v[F])),U=y[M-1]/R,q=y[M-2]/R,W=v[M-2]/R,z=y[F]/R,K=v[F]/R,Z=((q+U)*(q-U)+W*W)/2,X=U*W*(U*W);let Q=0;(Z!==0||X!==0)&&(Z<0?Q=0-Math.sqrt(Z*Z+X):Q=Math.sqrt(Z*Z+X),Q=X/(Z+Q));let ct=(z+U)*(z-U)+Q,vt=z*K;for(let lt=F;lt<M-1;lt++){let wt=hn(ct,vt);wt===0&&(wt=Number.MIN_VALUE);let bt=ct/wt,Bt=vt/wt;if(lt!==F&&(v[lt-1]=wt),ct=bt*y[lt]+Bt*v[lt],v[lt]=bt*v[lt]-Bt*y[lt],vt=Bt*y[lt+1],y[lt+1]=bt*y[lt+1],h)for(let xt=0;xt<n;xt++)wt=bt*w.get(xt,lt)+Bt*w.get(xt,lt+1),w.set(xt,lt+1,-Bt*w.get(xt,lt)+bt*w.get(xt,lt+1)),w.set(xt,lt,wt);if(wt=hn(ct,vt),wt===0&&(wt=Number.MIN_VALUE),bt=ct/wt,Bt=vt/wt,y[lt]=wt,ct=bt*v[lt]+Bt*y[lt+1],y[lt+1]=-Bt*v[lt]+bt*y[lt+1],vt=Bt*v[lt+1],v[lt+1]=bt*v[lt+1],c&&lt<r-1)for(let xt=0;xt<r;xt++)wt=bt*m.get(xt,lt)+Bt*m.get(xt,lt+1),m.set(xt,lt+1,-Bt*m.get(xt,lt)+bt*m.get(xt,lt+1)),m.set(xt,lt,wt)}v[M-2]=ct;break}case 4:{if(y[F]<=0&&(y[F]=y[F]<0?-y[F]:0,h))for(let R=0;R<=S;R++)w.set(R,F,-w.get(R,F));for(;F<S&&!(y[F]>=y[F+1]);){let R=y[F];if(y[F]=y[F+1],y[F+1]=R,h&&F<n-1)for(let U=0;U<n;U++)R=w.get(U,F+1),w.set(U,F+1,w.get(U,F)),w.set(U,F,R);if(c&&F<r-1)for(let U=0;U<r;U++)R=m.get(U,F+1),m.set(U,F+1,m.get(U,F)),m.set(U,F,R);F++}M--;break}}}if(p){let F=w;w=m,m=F}this.m=r,this.n=n,this.s=y,this.U=m,this.V=w}solve(t){let e=t,r=this.threshold,n=this.s.length,i=pt.zeros(n,n);for(let d=0;d<n;d++)Math.abs(this.s[d])<=r?i.set(d,d,0):i.set(d,d,1/this.s[d]);let a=this.U,l=this.rightSingularVectors,c=l.mmul(i),h=l.rows,p=a.rows,f=pt.zeros(h,p);for(let d=0;d<h;d++)for(let g=0;g<p;g++){let y=0;for(let m=0;m<n;m++)y+=c.get(d,m)*a.get(g,m);f.set(d,g,y)}return f.mmul(e)}solveForDiagonal(t){return this.solve(pt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,i=new pt(r,this.s.length);for(let p=0;p<r;p++)for(let f=0;f<n;f++)Math.abs(this.s[f])>e&&i.set(p,f,t.get(p,f)/this.s[f]);let a=this.U,l=a.rows,c=a.columns,h=new pt(r,l);for(let p=0;p<r;p++)for(let f=0;f<l;f++){let d=0;for(let g=0;g<c;g++)d+=i.get(p,g)*a.get(f,g);h.set(p,f,d)}return h}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,i=r.length;n<i;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 ly(s,t=!1){return s=gr.checkMatrix(s),t?new Ei(s).inverse():jf(s,pt.eye(s.rows))}function jf(s,t,e=!1){return s=gr.checkMatrix(s),t=gr.checkMatrix(t),e?new Ei(s).solve(t):s.isSquare()?new io(s).solve(t):new za(s).solve(t)}function so(s){if(s=pt.checkMatrix(s),s.isSquare()){if(s.columns===0)return 1;let t,e,r,n;if(s.columns===2)return t=s.get(0,0),e=s.get(0,1),r=s.get(1,0),n=s.get(1,1),t*n-e*r;if(s.columns===3){let i,a,l;return i=new no(s,[1,2],[1,2]),a=new no(s,[1,2],[0,2]),l=new no(s,[1,2],[0,1]),t=s.get(0,0),e=s.get(0,1),r=s.get(0,2),t*so(i)-e*so(a)+r*so(l)}else return new io(s).determinant}else throw Error("determinant can only be calculated for a square matrix")}function cy(s,t){let e=[];for(let r=0;r<s;r++)r!==t&&e.push(r);return e}function fy(s,t,e,r=1e-9,n=1e-9){if(s>n)return new Array(t.rows+1).fill(0);{let i=t.addRow(e,[0]);for(let a=0;a<i.rows;a++)Math.abs(i.get(a,0))<r&&i.set(a,0,0);return i.to1DArray()}}function hy(s,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;s=pt.checkMatrix(s);let n=s.rows,i=new pt(n,n);for(let a=0;a<n;a++){let l=pt.columnVector(s.getRow(a)),c=s.subMatrixRow(cy(n,a)).transpose(),p=new Ei(c).solve(l),f=pt.sub(l,c.mmul(p)).abs().max();i.setRow(a,fy(f,p,a,e,r))}return i}function py(s,t=Number.EPSILON){if(s=pt.checkMatrix(s),s.isEmpty())return s.transpose();let e=new Ei(s,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,i=e.diagonal;for(let a=0;a<i.length;a++)Math.abs(i[a])>t?i[a]=1/i[a]:i[a]=0;return n.mmul(pt.diag(i).mmul(r.transpose()))}function dy(s,t=s,e={}){s=new pt(s);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!cr.isAnyArray(t)?(e=t,t=s,r=!0):t=new pt(t),s.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(s=s.center("column"),r||(t=t.center("column")));const i=s.transpose().mmul(t);for(let a=0;a<i.rows;a++)for(let l=0;l<i.columns;l++)i.set(a,l,i.get(a,l)*(1/(s.rows-1)));return i}function _y(s,t=s,e={}){s=new pt(s);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!cr.isAnyArray(t)?(e=t,t=s,r=!0):t=new pt(t),s.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=e;n&&(s.center("column"),r||t.center("column")),i&&(s.scale("column"),r||t.scale("column"));const a=s.standardDeviation("column",{unbiased:!0}),l=r?a:t.standardDeviation("column",{unbiased:!0}),c=s.transpose().mmul(t);for(let h=0;h<c.rows;h++)for(let p=0;p<c.columns;p++)c.set(h,p,c.get(h,p)*(1/(a[h]*l[p]))*(1/(s.rows-1)));return c}let Vf=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=gr.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,i=new pt(n,n),a=new Float64Array(n),l=new Float64Array(n),c=t,h,p,f=!1;if(r?f=!0:f=t.isSymmetric(),f){for(h=0;h<n;h++)for(p=0;p<n;p++)i.set(h,p,c.get(h,p));my(n,l,a,i),gy(n,l,a,i)}else{let d=new pt(n,n),g=new Float64Array(n);for(p=0;p<n;p++)for(h=0;h<n;h++)d.set(h,p,c.get(h,p));vy(n,d,g,i),yy(n,l,a,i,d)}this.n=n,this.e=l,this.d=a,this.V=i}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new pt(t,t),i,a;for(i=0;i<t;i++){for(a=0;a<t;a++)n.set(i,a,0);n.set(i,i,r[i]),e[i]>0?n.set(i,i+1,e[i]):e[i]<0&&n.set(i,i-1,e[i])}return n}};function my(s,t,e,r){let n,i,a,l,c,h,p,f;for(c=0;c<s;c++)e[c]=r.get(s-1,c);for(l=s-1;l>0;l--){for(f=0,a=0,h=0;h<l;h++)f=f+Math.abs(e[h]);if(f===0)for(t[l]=e[l-1],c=0;c<l;c++)e[c]=r.get(l-1,c),r.set(l,c,0),r.set(c,l,0);else{for(h=0;h<l;h++)e[h]/=f,a+=e[h]*e[h];for(n=e[l-1],i=Math.sqrt(a),n>0&&(i=-i),t[l]=f*i,a=a-n*i,e[l-1]=n-i,c=0;c<l;c++)t[c]=0;for(c=0;c<l;c++){for(n=e[c],r.set(c,l,n),i=t[c]+r.get(c,c)*n,h=c+1;h<=l-1;h++)i+=r.get(h,c)*e[h],t[h]+=r.get(h,c)*n;t[c]=i}for(n=0,c=0;c<l;c++)t[c]/=a,n+=t[c]*e[c];for(p=n/(a+a),c=0;c<l;c++)t[c]-=p*e[c];for(c=0;c<l;c++){for(n=e[c],i=t[c],h=c;h<=l-1;h++)r.set(h,c,r.get(h,c)-(n*t[h]+i*e[h]));e[c]=r.get(l-1,c),r.set(l,c,0)}}e[l]=a}for(l=0;l<s-1;l++){if(r.set(s-1,l,r.get(l,l)),r.set(l,l,1),a=e[l+1],a!==0){for(h=0;h<=l;h++)e[h]=r.get(h,l+1)/a;for(c=0;c<=l;c++){for(i=0,h=0;h<=l;h++)i+=r.get(h,l+1)*r.get(h,c);for(h=0;h<=l;h++)r.set(h,c,r.get(h,c)-i*e[h])}}for(h=0;h<=l;h++)r.set(h,l+1,0)}for(c=0;c<s;c++)e[c]=r.get(s-1,c),r.set(s-1,c,0);r.set(s-1,s-1,1),t[0]=0}function gy(s,t,e,r){let n,i,a,l,c,h,p,f,d,g,y,m,w,v,x,b;for(a=1;a<s;a++)t[a-1]=t[a];t[s-1]=0;let N=0,E=0,A=Number.EPSILON;for(h=0;h<s;h++){for(E=Math.max(E,Math.abs(e[h])+Math.abs(t[h])),p=h;p<s&&!(Math.abs(t[p])<=A*E);)p++;if(p>h)do{for(n=e[h],f=(e[h+1]-n)/(2*t[h]),d=hn(f,1),f<0&&(d=-d),e[h]=t[h]/(f+d),e[h+1]=t[h]*(f+d),g=e[h+1],i=n-e[h],a=h+2;a<s;a++)e[a]-=i;for(N=N+i,f=e[p],y=1,m=y,w=y,v=t[h+1],x=0,b=0,a=p-1;a>=h;a--)for(w=m,m=y,b=x,n=y*t[a],i=y*f,d=hn(f,t[a]),t[a+1]=x*d,x=t[a]/d,y=f/d,f=y*e[a]-x*n,e[a+1]=i+x*(y*n+x*e[a]),c=0;c<s;c++)i=r.get(c,a+1),r.set(c,a+1,x*r.get(c,a)+y*i),r.set(c,a,y*r.get(c,a)-x*i);f=-x*b*w*v*t[h]/g,t[h]=x*f,e[h]=y*f}while(Math.abs(t[h])>A*E);e[h]=e[h]+N,t[h]=0}for(a=0;a<s-1;a++){for(c=a,f=e[a],l=a+1;l<s;l++)e[l]<f&&(c=l,f=e[l]);if(c!==a)for(e[c]=e[a],e[a]=f,l=0;l<s;l++)f=r.get(l,a),r.set(l,a,r.get(l,c)),r.set(l,c,f)}}function vy(s,t,e,r){let n=0,i=s-1,a,l,c,h,p,f,d;for(f=n+1;f<=i-1;f++){for(d=0,h=f;h<=i;h++)d=d+Math.abs(t.get(h,f-1));if(d!==0){for(c=0,h=i;h>=f;h--)e[h]=t.get(h,f-1)/d,c+=e[h]*e[h];for(l=Math.sqrt(c),e[f]>0&&(l=-l),c=c-e[f]*l,e[f]=e[f]-l,p=f;p<s;p++){for(a=0,h=i;h>=f;h--)a+=e[h]*t.get(h,p);for(a=a/c,h=f;h<=i;h++)t.set(h,p,t.get(h,p)-a*e[h])}for(h=0;h<=i;h++){for(a=0,p=i;p>=f;p--)a+=e[p]*t.get(h,p);for(a=a/c,p=f;p<=i;p++)t.set(h,p,t.get(h,p)-a*e[p])}e[f]=d*e[f],t.set(f,f-1,d*l)}}for(h=0;h<s;h++)for(p=0;p<s;p++)r.set(h,p,h===p?1:0);for(f=i-1;f>=n+1;f--)if(t.get(f,f-1)!==0){for(h=f+1;h<=i;h++)e[h]=t.get(h,f-1);for(p=f;p<=i;p++){for(l=0,h=f;h<=i;h++)l+=e[h]*r.get(h,p);for(l=l/e[f]/t.get(f,f-1),h=f;h<=i;h++)r.set(h,p,r.get(h,p)+l*e[h])}}}function yy(s,t,e,r,n){let i=s-1,a=0,l=s-1,c=Number.EPSILON,h=0,p=0,f=0,d=0,g=0,y=0,m=0,w=0,v,x,b,N,E,A,M,S,T,F,O,R,U,q,W;for(v=0;v<s;v++)for((v<a||v>l)&&(e[v]=n.get(v,v),t[v]=0),x=Math.max(v-1,0);x<s;x++)p=p+Math.abs(n.get(v,x));for(;i>=a;){for(N=i;N>a&&(y=Math.abs(n.get(N-1,N-1))+Math.abs(n.get(N,N)),y===0&&(y=p),!(Math.abs(n.get(N,N-1))<c*y));)N--;if(N===i)n.set(i,i,n.get(i,i)+h),e[i]=n.get(i,i),t[i]=0,i--,w=0;else if(N===i-1){if(M=n.get(i,i-1)*n.get(i-1,i),f=(n.get(i-1,i-1)-n.get(i,i))/2,d=f*f+M,m=Math.sqrt(Math.abs(d)),n.set(i,i,n.get(i,i)+h),n.set(i-1,i-1,n.get(i-1,i-1)+h),S=n.get(i,i),d>=0){for(m=f>=0?f+m:f-m,e[i-1]=S+m,e[i]=e[i-1],m!==0&&(e[i]=S-M/m),t[i-1]=0,t[i]=0,S=n.get(i,i-1),y=Math.abs(S)+Math.abs(m),f=S/y,d=m/y,g=Math.sqrt(f*f+d*d),f=f/g,d=d/g,x=i-1;x<s;x++)m=n.get(i-1,x),n.set(i-1,x,d*m+f*n.get(i,x)),n.set(i,x,d*n.get(i,x)-f*m);for(v=0;v<=i;v++)m=n.get(v,i-1),n.set(v,i-1,d*m+f*n.get(v,i)),n.set(v,i,d*n.get(v,i)-f*m);for(v=a;v<=l;v++)m=r.get(v,i-1),r.set(v,i-1,d*m+f*r.get(v,i)),r.set(v,i,d*r.get(v,i)-f*m)}else e[i-1]=S+f,e[i]=S+f,t[i-1]=m,t[i]=-m;i=i-2,w=0}else{if(S=n.get(i,i),T=0,M=0,N<i&&(T=n.get(i-1,i-1),M=n.get(i,i-1)*n.get(i-1,i)),w===10){for(h+=S,v=a;v<=i;v++)n.set(v,v,n.get(v,v)-S);y=Math.abs(n.get(i,i-1))+Math.abs(n.get(i-1,i-2)),S=T=.75*y,M=-.4375*y*y}if(w===30&&(y=(T-S)/2,y=y*y+M,y>0)){for(y=Math.sqrt(y),T<S&&(y=-y),y=S-M/((T-S)/2+y),v=a;v<=i;v++)n.set(v,v,n.get(v,v)-y);h+=y,S=T=M=.964}for(w=w+1,E=i-2;E>=N&&(m=n.get(E,E),g=S-m,y=T-m,f=(g*y-M)/n.get(E+1,E)+n.get(E,E+1),d=n.get(E+1,E+1)-m-g-y,g=n.get(E+2,E+1),y=Math.abs(f)+Math.abs(d)+Math.abs(g),f=f/y,d=d/y,g=g/y,!(E===N||Math.abs(n.get(E,E-1))*(Math.abs(d)+Math.abs(g))<c*(Math.abs(f)*(Math.abs(n.get(E-1,E-1))+Math.abs(m)+Math.abs(n.get(E+1,E+1))))));)E--;for(v=E+2;v<=i;v++)n.set(v,v-2,0),v>E+2&&n.set(v,v-3,0);for(b=E;b<=i-1&&(q=b!==i-1,b!==E&&(f=n.get(b,b-1),d=n.get(b+1,b-1),g=q?n.get(b+2,b-1):0,S=Math.abs(f)+Math.abs(d)+Math.abs(g),S!==0&&(f=f/S,d=d/S,g=g/S)),S!==0);b++)if(y=Math.sqrt(f*f+d*d+g*g),f<0&&(y=-y),y!==0){for(b!==E?n.set(b,b-1,-y*S):N!==E&&n.set(b,b-1,-n.get(b,b-1)),f=f+y,S=f/y,T=d/y,m=g/y,d=d/f,g=g/f,x=b;x<s;x++)f=n.get(b,x)+d*n.get(b+1,x),q&&(f=f+g*n.get(b+2,x),n.set(b+2,x,n.get(b+2,x)-f*m)),n.set(b,x,n.get(b,x)-f*S),n.set(b+1,x,n.get(b+1,x)-f*T);for(v=0;v<=Math.min(i,b+3);v++)f=S*n.get(v,b)+T*n.get(v,b+1),q&&(f=f+m*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-f*g)),n.set(v,b,n.get(v,b)-f),n.set(v,b+1,n.get(v,b+1)-f*d);for(v=a;v<=l;v++)f=S*r.get(v,b)+T*r.get(v,b+1),q&&(f=f+m*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-f*g)),r.set(v,b,r.get(v,b)-f),r.set(v,b+1,r.get(v,b+1)-f*d)}}}if(p!==0){for(i=s-1;i>=0;i--)if(f=e[i],d=t[i],d===0)for(N=i,n.set(i,i,1),v=i-1;v>=0;v--){for(M=n.get(v,v)-f,g=0,x=N;x<=i;x++)g=g+n.get(v,x)*n.get(x,i);if(t[v]<0)m=M,y=g;else if(N=v,t[v]===0?n.set(v,i,M!==0?-g/M:-g/(c*p)):(S=n.get(v,v+1),T=n.get(v+1,v),d=(e[v]-f)*(e[v]-f)+t[v]*t[v],A=(S*y-m*g)/d,n.set(v,i,A),n.set(v+1,i,Math.abs(S)>Math.abs(m)?(-g-M*A)/S:(-y-T*A)/m)),A=Math.abs(n.get(v,i)),c*A*A>1)for(x=v;x<=i;x++)n.set(x,i,n.get(x,i)/A)}else if(d<0)for(N=i-1,Math.abs(n.get(i,i-1))>Math.abs(n.get(i-1,i))?(n.set(i-1,i-1,d/n.get(i,i-1)),n.set(i-1,i,-(n.get(i,i)-f)/n.get(i,i-1))):(W=oo(0,-n.get(i-1,i),n.get(i-1,i-1)-f,d),n.set(i-1,i-1,W[0]),n.set(i-1,i,W[1])),n.set(i,i-1,0),n.set(i,i,1),v=i-2;v>=0;v--){for(F=0,O=0,x=N;x<=i;x++)F=F+n.get(v,x)*n.get(x,i-1),O=O+n.get(v,x)*n.get(x,i);if(M=n.get(v,v)-f,t[v]<0)m=M,g=F,y=O;else if(N=v,t[v]===0?(W=oo(-F,-O,M,d),n.set(v,i-1,W[0]),n.set(v,i,W[1])):(S=n.get(v,v+1),T=n.get(v+1,v),R=(e[v]-f)*(e[v]-f)+t[v]*t[v]-d*d,U=(e[v]-f)*2*d,R===0&&U===0&&(R=c*p*(Math.abs(M)+Math.abs(d)+Math.abs(S)+Math.abs(T)+Math.abs(m))),W=oo(S*g-m*F+d*O,S*y-m*O-d*F,R,U),n.set(v,i-1,W[0]),n.set(v,i,W[1]),Math.abs(S)>Math.abs(m)+Math.abs(d)?(n.set(v+1,i-1,(-F-M*n.get(v,i-1)+d*n.get(v,i))/S),n.set(v+1,i,(-O-M*n.get(v,i)-d*n.get(v,i-1))/S)):(W=oo(-g-T*n.get(v,i-1),-y-T*n.get(v,i),m,d),n.set(v+1,i-1,W[0]),n.set(v+1,i,W[1]))),A=Math.max(Math.abs(n.get(v,i-1)),Math.abs(n.get(v,i))),c*A*A>1)for(x=v;x<=i;x++)n.set(x,i-1,n.get(x,i-1)/A),n.set(x,i,n.get(x,i)/A)}for(v=0;v<s;v++)if(v<a||v>l)for(x=v;x<s;x++)r.set(v,x,n.get(v,x));for(x=s-1;x>=a;x--)for(v=a;v<=l;v++){for(m=0,b=a;b<=Math.min(x,l);b++)m=m+r.get(v,b)*n.get(b,x);r.set(v,x,m)}}}function oo(s,t,e,r){let n,i;return Math.abs(e)>Math.abs(r)?(n=r/e,i=e+n*r,[(s+n*t)/i,(t-n*s)/i]):(n=e/r,i=r+n*e,[(n*s+t)/i,(n*t-s)/i])}class Yf{constructor(t){if(t=gr.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new pt(r,r),i=!0,a,l,c;for(l=0;l<r;l++){let h=0;for(c=0;c<l;c++){let p=0;for(a=0;a<c;a++)p+=n.get(c,a)*n.get(l,a);p=(e.get(l,c)-p)/n.get(c,c),n.set(l,c,p),h=h+p*p}for(h=e.get(l,l)-h,i&=h>0,n.set(l,l,Math.sqrt(Math.max(h,0))),c=l+1;c<r;c++)n.set(l,c,0)}this.L=n,this.positiveDefinite=!!i}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=gr.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,i=t.clone(),a,l,c;for(c=0;c<r;c++)for(l=0;l<n;l++){for(a=0;a<c;a++)i.set(c,l,i.get(c,l)-i.get(a,l)*e.get(c,a));i.set(c,l,i.get(c,l)/e.get(c,c))}for(c=r-1;c>=0;c--)for(l=0;l<n;l++){for(a=c+1;a<r;a++)i.set(c,l,i.get(c,l)-i.get(a,l)*e.get(a,c));i.set(c,l,i.get(c,l)/e.get(c,c))}return i}get lowerTriangularMatrix(){return this.L}}class Zf{constructor(t,e={}){t=gr.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:i=1e3,terminationCriteria:a=1e-10}=e;let l;if(r){if(cr.isAnyArray(r)&&typeof r[0]=="number"?r=pt.columnVector(r):r=gr.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let c=1,h,p,f,d;for(let g=0;g<i&&c>a;g++)f=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),f=f.div(f.norm()),h=t.mmul(f).div(f.transpose().mmul(f).get(0,0)),g>0&&(c=h.clone().sub(d).pow(2).sum()),d=h.clone(),r?(p=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),p=p.div(p.norm()),l=r.mmul(p).div(p.transpose().mmul(p).get(0,0))):l=h;if(r){let g=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));g=g.div(g.norm());let y=t.clone().sub(h.clone().mmul(g.transpose())),m=l.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),w=r.clone().sub(h.clone().mulS(m.get(0,0)).mmul(p.transpose()));this.t=h,this.p=g.transpose(),this.w=f.transpose(),this.q=p,this.u=l,this.s=h.transpose().mmul(h),this.xResidual=y,this.yResidual=w,this.betas=m}else this.w=f.transpose(),this.s=h.transpose().mmul(h).sqrt(),n?this.t=h.clone().div(this.s.get(0,0)):this.t=h,this.xResidual=t.sub(h.mmul(f.transpose()))}}kt.AbstractMatrix=$t,kt.CHO=Yf,kt.CholeskyDecomposition=Yf,kt.DistanceMatrix=ro,kt.EVD=Vf;var wy=kt.EigenvalueDecomposition=Vf;kt.LU=io,kt.LuDecomposition=io;var Kf=kt.Matrix=pt;kt.MatrixColumnSelectionView=ey,kt.MatrixColumnView=ty,kt.MatrixFlipColumnView=ry,kt.MatrixFlipRowView=ny,kt.MatrixRowSelectionView=sy,kt.MatrixRowView=iy,kt.MatrixSelectionView=no,kt.MatrixSubView=oy,kt.MatrixTransposeView=ay,kt.NIPALS=Zf,kt.Nipals=Zf,kt.QR=za,kt.QrDecomposition=za,kt.SVD=Ei,kt.SingularValueDecomposition=Ei,kt.SymmetricMatrix=Xn,kt.WrapperMatrix1D=Wf,kt.WrapperMatrix2D=gr,kt.correlation=_y,kt.covariance=dy;var Gf=kt.default=pt;kt.determinant=so,kt.inverse=ly,kt.linearDependencies=hy,kt.pseudoInverse=py,kt.solve=jf,kt.wrap=uy;const Hf=wy,Jf=Kf;Gf.Matrix&&Gf.Matrix;class Dy{constructor(t){$(this,"_errorListener");this._errorListener=t}new({rows:t,columns:e,initial_value:r}={}){return new ka(t,e,r,this._errorListener)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id1:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id1:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:i,to_column:a}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:i,to_column:a})}kron({id1:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id1:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id1:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r},n){return t==null?void 0:t.reshape({rows:e,columns:r},n)}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:i}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:i})}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 ka{constructor(t=0,e=0,r=void 0,n){$(this,"_matrixInstance");$(this,"_errorListener");this._matrixInstance=this._createMatrix(t,e,r),this._errorListener=n}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Qt(e,r,this._errorListener))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const i of n._value)t+=_t(i)?0:i,e+=1;return t/e}col({column:t}){const e=[],r=new Qt(0,void 0,this._errorListener);if(_t(t))return r;for(const n of this._matrixInstance)e.push(n._value[t]);return r._value=e,r}det(){return Lf(this._matrixArray)}get({row:t,column:e}){var r,n;if(!(_t(t)||_t(e)))return(n=(r=this._matrixInstance[t])==null?void 0:r._value)==null?void 0:n[e]}inv(){const t=Xs(this._matrixArray);return this._newMatrix(t)}max(){return m1(this._matrixArray)}min(){return $a(this._matrixArray)}pow({power:t}){const e=_t(t)?this._matrixArray:v1(this._matrixArray,t);return this._newMatrix(e)}row({row:t}){return _t(t)?new Qt(0,void 0,this._errorListener):this._matrixInstance[t]}set({row:t,column:e,value:r}){_t(t)||_t(e)||this._matrixInstance[t].set({index:e,value:r})}sum({id2:t}){const e=Qi(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=c1(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e,to_row:r,from_column:n,to_column:i}={}){_t(e)&&(e=0),_t(r)&&(r=this.rows()),_t(n)&&(n=0),_t(i)&&(i=this.columns());for(const[a,l]of this._matrixInstance.entries())for(const[c]of l._value.entries())a<r&&a>=e&&c>=n&&c<i&&l.set({index:c,value:t})}kron({id2:t}){const e=u1(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return $a(Nf(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=wi(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=g1(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t,order:e=Yn.ascending}={}){_t(t)&&(t=0),this._matrixInstance.sort((r,n)=>{const i=r._value[t],a=n._value[t];return e!==Yn.descending?i-a:a-i})}trace(){return _1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Rf(this._matrixArray)}add_col({column:t,array_id:e}={}){_t(t)&&(t=this.columns());for(const[r,n]of this._matrixInstance.entries())n.insert({index:t,value:e?e._value[r]:void 0})}add_row({row:t,array_id:e}){_t(t)&&(t=this.rows()),this._matrixInstance.splice(t,0,e||new Qt(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t=0,columns:e=0},r){if(t*e!==this.columns()*this.rows()){this._errorListener.addError(le.matrixRehapeErr,r,zt.Error);return}const n=i1(this._matrixArray,[t,e]);this._matrixInstance=n.map(i=>{const a=new Qt(0,void 0,this._errorListener);return a._value=[...i],a})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t,to_row:e,from_column:r,to_column:n}={}){_t(t)&&(t=0),_t(e)&&(e=this.rows()),_t(r)&&(r=0),_t(n)&&(n=this.columns());const i=this._matrixArray.splice(t,e),a=[];for(const l of i)a.push(l.splice(r,n));return this._newMatrix(a)}swap_rows({row1:t,row2:e}){if(_t(t)||_t(e))return;const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Bf(this._matrixArray);return this._newMatrix(t)}remove_col({column:t}={}){_t(t)&&(t=this.columns());const e=[];for(const n of this._matrixInstance){const i=n._value.splice(t,1);e.push(i[0])}const r=new Qt(0,void 0,this._errorListener);return r._value=e,r}remove_row({row:t}={}){return _t(t)&&(t=this.rows()),this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new Hf(new Jf(this._matrixArray)),e=new Qt(0,void 0,this._errorListener);return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let i=0;i<e;i++)if(n!==i&&r[n][i]!==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 i=0;i<e;i++)if(n!==i&&r[n][i]!==0||n===i&&r[n][i]!==1)return!1;return!0}eigenvectors(){const t=new Hf(new Jf(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 i=n+1;i<e;i++)if(r[n][i]!==r[i][n])return!1;return!0}swap_columns({column1:t,column2:e}){if(!(_t(t)||_t(e)))for(const r of this._matrixInstance){const n=r._value[t],i=r._value[e];r.set({index:t,value:i}),r.set({index:e,value:n})}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return s1(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 i=0;i<t;i++)if(n+i!==t-1&&r[n][i]!==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 i=0;i<t;i++)if(n!==i&&r[n][i]!==-r[i][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 ka(0,0,void 0,this._errorListener);return e._value=t.map(r=>{const n=new Qt(0,void 0,this._errorListener);return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,i=[...t].map(a=>[...a]);for(let a=0;a<r&&!(a>=n);a++){let l=a;for(;l<r&&i[l][a]===0;)l++;if(l===r)continue;if(l!==a){const h=i[l];i[l]=i[a],i[a]=h}const c=i[a][a];for(let h=0;h<n;h++)i[a][h]/=c;for(let h=a+1;h<r;h++){const p=i[h][a];i[h]=i[h].map((f,d)=>f-p*i[a][d]),i[h][a]=0}}for(let a=0;a<r;a++)i[a].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class by{constructor(t){$(this,"_variables");$(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){if(!t)return!0;const r=Qr(t),n=Qr(this._variables.timeframe.period);if(r<n)return!0;const i=`change_${e}`,a=this._cacheData[i],l=this._variables.time;if(a){if(a.offset){if(a.currentTime+a.offset<=l)return this._cacheData[i]={currentTime:l,offset:0},!0}else if(a.currentTime+r*1e3<=l)return this._cacheData[i]={currentTime:l,offset:0},!0}else{const c=this._calcTimeOffset(l,t);return this._cacheData[i]={currentTime:l,offset:c},!1}return!1}in_seconds({timeframe:t}={}){return Qr(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=ee.duration(e);if(r.years())return"12M";const i=r.asMonths();if(Hs(i))return`${i}M`;const a=r.asWeeks();if(Hs(a))return`${a}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const c=r.asMinutes();if(c>=1)return`${Math.ceil(c)}`;const h=r.asSeconds();return h<=1?"1S":h<=5?"5S":h<=10?"10S":h<=15?"15S":h<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=ee(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=ee(t).date();e="1D";const c=ee(t).daysInMonth();l!==1&&(r=(c-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),i=Qr(e)*1e3,a=t-n-Math.floor((t-n)/i)*i;return r?r-a:a}}class xy{constructor(t,e){$(this,"_errorListener");$(this,"_intlNumberFormatter");$(this,"_precision");this._errorListener=t,this._precision=e,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact"})}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 Qt;return n._value=r||[],n}upper({source:t=""}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t=""},e){return this._strFormat(t,e)}length({string:t=""}){return t==null?void 0:t.length}repeat({source:t="",repeat:e,separator:r=""},n){if(_t(e)){this._errorListener.addError(le.arrLenErr,n,zt.Error);return}return Array.from(new Array(e),()=>t).join(r)}replace({source:t="",target:e="",replacement:r="",occurrence:n}){_t(n)&&(n=0);let i=-1;for(let a=0;a<n+1&&(i=t.indexOf(e,i+1),i!==-1);a++);return i!==-1?t.substring(0,i)+r+t.substring(i+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 String(this._toStringFormat(t,e))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),kr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Kt.mintick:return t.toFixed(this._precision);case Kt.percent:return`${t}%`;case Kt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var l;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[i,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),h=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;h&&(i=i.replace(new RegExp(`\\B(?=(\\d{${h}})+(?!\\d))`,"g"),",")),r=c.join("")}i=r.replace(/#/,i).replace(/#/g,"")}else i=`${r}${i}`;if(n&&n.includes("#")){const c=n.split("#").length-1;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${i}.${a}`:i}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}_strFormat(t,e){let r=t;for(const[n,i]of e.entries()){if(i===void 0||typeof i=="number"&&isNaN(i)){r="NaN";continue}if(typeof i=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(i,c)))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),String(i))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),i)}return r}}class Ey{constructor(t){$(this,"_errorListener");this._errorListener=t}new(){return new qa(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class qa{constructor(t){$(this,"_errorListener");$(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new qa(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class Ay{constructor(t){$(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Ai(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Ai(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Ai(t,e)}from_time({price:t,time:e}){return new Ai(t,void 0,e)}}class Ai{constructor(t,e,r){$(this,"_index");$(this,"_price");$(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 Ai(this._price,this._index,this._time)}}class Cy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLabel",{text:"",xloc:we.bar_index,yloc:Wr.price,size:rr.normal,style:ge.styleLabelDown,textalign:Wt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:i,bar_index:a}=this._variables,l=`label_${e}_${a}`;me(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:l,time:r,high:n,low:i,bar_index:a};t.point&&(c.x=c.xloc===we.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===Wr.abovebar?c.y=n:c.yloc===Wr.belowbar&&(c.y=i),this._verfiyArgs(t,e);const h=new ao(l,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(l,c,h),h}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:i,size:a,textalign:l,text_font_family:c}=t,h="label.new";this._paramVerfiy(i,e,h,Object.values(ge),"style"),this._paramVerfiy(r,e,h,Object.values(we),"xloc"),this._paramVerfiy(n,e,h,Object.values(Wr),"yloc"),this._paramVerfiy(a,e,h,Object.values(rr),"size"),this._paramVerfiy(l,e,h,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign"),this._paramVerfiy(c,e,h,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}label(t){return t.x}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 ao{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get type(){return Fe.LABEL}get id(){return this._id}get data(){return this._variables.label.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`label_${t}_${e}`,n=this._getLabel(t),i=new ao(r,this._variables,this._errorListener);if(n){const a={...n,id:r,bar_index:e};this._variables.label.add(r,a,i)}return i}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),this._paramVerfiy(t,e,"label.set_size",Object.values(rr),"size")}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,this._paramVerfiy(e,r,"label.set_xloc",Object.values(we),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:i}=this._variables;r&&(r.yloc=t,t===Wr.abovebar?r.y=n:t===Wr.belowbar&&(r.y=i),this._paramVerfiy(t,e,"label.set_yloc",Object.values(Wr),"yloc"))}set_color(t,e){const r=this._getLabel(e);me(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===we.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),this._paramVerfiy(t,e,"label.set_style",Object.values(ge),"style")}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),this._paramVerfiy(t,e,"label.set_textalign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);me(t,["textcolor"]),r&&(r.textcolor=t.textcolor)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t),this._paramVerfiy(t,e,"label.set_text_font_family",Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const Fy={freq_all:qr.freqAll,freq_once_per_bar:qr.freqOncePerBar,freq_once_per_bar_close:qr.freqOncePerBarClose},My={gaps_off:Yi.gapsOff,gaps_on:Yi.gapsOn,lookahead_off:Yi.lookaheadOff,lookahead_on:Yi.lookaheadOn},Ci={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"},Xf={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"},Ny={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Qf={all:[Ye.dataWindow,Ye.pane,Ye.priceScale,Ye.statusLine],data_window:[Ye.dataWindow],none:[],pane:[Ye.pane],price_scale:[Ye.priceScale],status_line:[Ye.statusLine]},Sy={both:Ur.both,left:Ur.left,none:Ur.none,right:Ur.right},By={inherit:Kt.inherit,mintick:Kt.mintick,percent:Kt.percent,price:Kt.price,volume:Kt.volume},Oy={style_solid:Ds.styleSolid,style_dashed:Ds.styleDashed,style_dotted:Ds.styleDotted},Iy={style_arrowdown:ge.styleArrowdown,style_arrowup:ge.styleArrowup,style_circle:ge.styleCircle,style_cross:ge.styleCross,style_diamond:ge.styleDiamond,style_flag:ge.styleFlag,style_label_center:ge.styleLabelCenter,style_label_down:ge.styleLabelDown,style_label_left:ge.styleLabelLeft,style_label_lower_left:ge.styleLabelLowerLeft,style_label_lower_right:ge.styleLabelLowerRight,style_label_right:ge.styleLabelRight,style_label_up:ge.styleLabelUp,style_label_upper_left:ge.styleLabelUpperLeft,style_label_upper_right:ge.styleLabelUpperRight,style_none:ge.styleNone,style_square:ge.styleSquare,style_text_outline:ge.styleTextOutline,style_triangledown:ge.styleTriangledown,style_triangleup:ge.styleTriangleup,style_xcross:ge.styleXcross},Ty={style_arrow_both:Le.styleArrowBoth,style_arrow_left:Le.styleArrowLeft,style_arrow_right:Le.styleArrowRight,style_dashed:Le.styleDashed,style_dotted:Le.styleDotted,style_solid:Le.styleSolid},$y={abovebar:an.abovebar,absolute:an.absolute,belowbar:an.belowbar,bottom:an.bottom,top:an.top},Ly={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Ry={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},Py={bottom_center:_r.bottomCenter,bottom_left:_r.bottomLeft,bottom_right:_r.bottomRight,middle_center:_r.middleCenter,middle_left:_r.middleLeft,middle_right:_r.middleRight,top_center:_r.topCenter,top_left:_r.topLeft,top_right:_r.topRight},zy={left:bs.left,none:bs.none,right:bs.right},ky={arrowdown:ur.arrowdown,arrowup:ur.arrowup,circle:ur.circle,cross:ur.cross,diamond:ur.diamond,flag:ur.flag,labeldown:ur.labeldown,labelup:ur.labelup,square:ur.square,triangledown:ur.triangledown,triangleup:ur.triangleup,xcross:ur.xcross},qy={auto:rr.auto,huge:rr.huge,large:rr.large,normal:rr.normal,small:rr.small,tiny:rr.tiny},Uy={cash:Re.cash,fixed:Re.fixed,percent_of_equity:Re.percentOfEquity,commission:{cash_per_contract:nr.cashPerContract,cash_per_order:nr.cashPerOrder,percent:nr.percent},direction:{all:ue.all,long:ue.long,short:ue.short},oca:{cancel:un.cancel,none:un.none,reduce:un.reduce}},Wy={align_bottom:Wt.alignBottom,align_center:Wt.alignCenter,align_left:Wt.alignLeft,align_right:Wt.alignRight,align_top:Wt.alignTop,wrap_auto:Wt.wrapAuto,wrap_none:Wt.wrapNone},jy={bar_index:we.bar_index,bar_time:we.bar_time},Vy={abovebar:Wr.abovebar,belowbar:Wr.belowbar,price:Wr.price},Yy={actual:xs.actual,estimate:xs.estimate,standardized:xs.standardized};class th{constructor(){$(this,"adjustment",{dividends:ws.dividends,none:ws.none,splits:ws.splits});$(this,"alert",Fy);$(this,"barmerge",My);$(this,"color",Ci);$(this,"currency",Xf);$(this,"dayofweek",Ny);$(this,"earnings",Yy);$(this,"display",Qf);$(this,"extend",Sy);$(this,"font",{family_default:Zn.familyDefault,family_monospace:Zn.familyMonospace});$(this,"format",By);$(this,"hline",Oy);$(this,"label",Iy);$(this,"line",Ty);$(this,"location",$y);$(this,"math",Ly);$(this,"order",{ascending:Yn.ascending,descending:Yn.descending});$(this,"plot",Ry);$(this,"position",Py);$(this,"scale",zy);$(this,"session",{extended:fi.extended,regular:fi.regular});$(this,"shape",ky);$(this,"size",qy);$(this,"splits",{denominator:"denominator",numerator:"numerator"});$(this,"strategy",Uy);$(this,"text",Wy);$(this,"xloc",jy);$(this,"yloc",Vy)}updateData(){}}class Zy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:we.bar_index,line_color:Ci.blue,line_style:Le.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var l;const{bar_index:r}=this._variables,n=`polyline_${e}_${r}`,i=Object.assign({},this._defaultPolyline,t,{id:n,bar_index:r,points:(l=t.points)==null?void 0:l._value.map(c=>({time:c.time,index:c.index,price:c.price}))});me(i,["line_color","fill_color"]);const a=new eh(n,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(n,i,a),a}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,i="polyline.new";this._paramVerfiy(r,e,i,Object.values(Le),"line_style"),this._paramVerfiy(n,e,i,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}delete({id:t}){t&&t.delete()}}class eh{constructor(t,e){$(this,"_id");$(this,"_variables");this._variables=e,this._id=t}get type(){return Fe.POLYLINE}get id(){return this._id}get data(){return this._variables.polyline.get(this._id)}delete(){this._variables.polyline.delete(this._id)}}class Ky{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLine",{xloc:we.bar_index,extend:Ur.none,style:Le.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const{bar_index:i}=this._variables,a=`line_${n}_${i}`;me(r,["color"]);const l={...this._defaultLine,...r,id:a,bar_index:i};if(t&&e){const h=l.xloc===we.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,p=l.xloc===we.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(l,{x1:h,y1:t==null?void 0:t.price,x2:p,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const c=new uo(a,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(a,l,c),c}_verfiyArgs(t,e){const{extend:r,xloc:n,style:i}=t,a="line.new";this._paramVerfiy(i,e,a,Object.values(Le),"style"),this._paramVerfiy(r,e,a,Object.values(Ur),"extend"),this._paramVerfiy(n,e,a,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}line(t){return t.x}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 uo{constructor(t,e,r){$(this,"_variables");$(this,"_id");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get id(){return this._id}get type(){return Fe.LINE}get data(){return this._variables.line.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`line_${t}_${e}`,n=this._getLine(t),i=new uo(r,this._variables,this._errorListener);return n&&this._variables.line.add(r,{...n,id:r,bar_index:e},i),i}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===we.bar_index){const{x1:n,y1:i,x2:a,y2:l}=r;return n===void 0||a===void 0||i===void 0||l===void 0?void 0:(l-i)/(a-n)*(t-n)+i}}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 i=this._getLine(n);i&&(i.xloc=t,i.x1=e,i.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(we),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(me(t,["color"]),r.color=t.color)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t,this._paramVerfiy(t,e,"line.set_style",Object.values(Le),"style"))}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,this._paramVerfiy(t,e,"line.set_extend",Object.values(Ur),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Gy{constructor(t){$(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,{bar_index:i}=this._variables,a=`linefill_${e}_${i}`,l=r==null?void 0:r.data,c=n==null?void 0:n.data;l&&(l.linefills=l.linefills||[],l.linefills.push(a)),c&&(c.linefills=c.linefills||[],c.linefills.push(a)),me(t,["color"]);const h=new lo(this._variables,a,r,n);return e.startsWith("export")||(l||c)&&this._variables.linefill.add(a,{line1:l,line2:c,color:t.color,id:a,bar_index:i},h),h}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 lo{constructor(t,e,r,n){$(this,"_id");$(this,"_line1");$(this,"_line2");$(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}get type(){return Fe.LINEFILL}get id(){return this._id}get data(){return this._variables.linefill.get(this._id)}linefill(t,e){return t.x?t.x:new lo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:i}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),i&&(i.linefills=(r=i.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(me(t,["color"]),e.color=t.color)}}class Hy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultBox",{border_color:Ci.blue,border_width:1,bgcolor:Ci.blue,xloc:we.bar_index,extend:Ur.none,style:Le.styleSolid,text:"",text_size:rr.auto,text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_wrap:Wt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const{bar_index:i}=this._variables,a=`box_${n}_${i}`,l={...this._defaultBox,...r,id:a,bar_index:i};if(me(l,["border_color","bgcolor","text_color"]),t){const{price:h,time:p,index:f}=t;l.top=h,l.left=l.xloc===we.bar_index?f:p}if(e){const{price:h,time:p,index:f}=e;l.bottom=h,l.right=l.xloc===we.bar_index?f:p}this._verfiyArgs(r,n);const c=new co(this._variables,a,this._errorListener);return n.startsWith("export")||this._variables.box.add(a,l,c),c}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:l,text_valign:c,text_wrap:h,text_font_family:p}=t,f="box.new";this._paramVerfiy(r,e,f,[Le.styleDashed,Le.styleDotted,Le.styleSolid],"border_style"),this._paramVerfiy(n,e,f,Object.values(Ur),"extend"),this._paramVerfiy(i,e,f,Object.values(we),"xloc"),this._paramVerfiy(a,e,f,Object.values(rr),"text_size"),this._paramVerfiy(l,e,f,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"),this._paramVerfiy(c,e,f,[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"),this._paramVerfiy(h,e,f,[Wt.wrapAuto,Wt.wrapNone],"text_wrap"),this._paramVerfiy(p,e,f,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}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},r){t==null||t.set_extend(e,r)}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},r){t==null||t.set_border_style(e,r)}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},r){t==null||t.set_text_size(e,r)}set_text_wrap({id:t,...e},r){t==null||t.set_text_wrap(e,r)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e},r){t==null||t.set_text_halign(e,r)}set_text_valign({id:t,...e},r){t==null||t.set_text_valign(e,r)}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},r){t==null||t.set_text_font_family(e,r)}}class co{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");this._variables=t,this._id=e,this._errorListener=r}get type(){return Fe.BOX}get id(){return this._id}get data(){return this._variables.box.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`box_${t}_${e}`,n=this._getBox(),i=new co(this._variables,r,this._errorListener);return n&&this._variables.box.add(r,{...n,id:r,bar_index:e},i),i}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},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(Ur),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,me(e,["bgcolor"]))}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t},e){const r=this._getBox();r&&(r.text_size=t,this._paramVerfiy(t,e,"box.set_text_size",Object.values(rr),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[Wt.wrapAuto,Wt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,me(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:i}=t||{};e.top=n,e.left=e.xloc===we.bar_index?r:i}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,me(e,["border_color"]))}set_border_style({style:t},e){const r=this._getBox();r&&(r.border_style=t,this._paramVerfiy(t,e,"box.set_border_style",[Le.styleDashed,Le.styleDotted,Le.styleSolid],"style"))}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:i}=t||{};e.bottom=n,e.right=e.xloc===we.bar_index?r:i}}set_text_font_family({text_font_family:t},e){const r=this._getBox();r&&(r.text_font_family=t,this._paramVerfiy(t,e,"box.set_text_font_family",Object.values(Zn),"text_font_family"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getBox(){return this._variables.box.get(this._id)}}class Jy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultTable",{position:_r.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t,this._errorListener=e}table({x:t}){return t}new(t,e){const{bar_index:r}=this._variables,n=`table_${e}_${r}`,{columns:i,rows:a}=t;me(t,["text_color","bgcolor","border_color"]);const l=Array.from(Array(a),()=>Array.from(Array(i),()=>{})),c={...this._defaultTable,...t,cell:l,id:n,bar_index:r},h=new rh(this._variables,n,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(_r),"position"),e.startsWith("export")||this._variables.table.add(n,c,h),h}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}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},r){t==null||t.set_position(e,r)}}class rh{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_size:rr.normal});this._variables=t,this._id=e,this._errorListener=r}get type(){return Fe.TABLE}get id(){return this._id}get data(){return this._variables.table.get(this._id)}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],l=a[n]||[];l[r]=e,a[n]=l,i.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,me(n,["text_color"]))}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 i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},i){if(t>r||e>n){this._errorListener.addError(le.mergeCellErr,i,zt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,me(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,me(e,["border_color"]))}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},e){const r=this._variables.table.get(this._id);r&&(r.position=t,this._paramVerfiy(t,e,"table.set_position",Object.values(_r),"position"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_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 Xy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===ue.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class Qy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===ue.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class tw{constructor(t,e){$(this,"_strategy");$(this,"_errorListener");this._strategy=t,this._errorListener=e}allow_entry_in({value:t},e){this._paramVerfiy(t,e,"strategy.risk.allow_entry_in",Object.values(ue),"value"),this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_drawdown",[Re.percentOfEquity,Re.cash],"type"),e===Re.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_intraday_loss",[Re.percentOfEquity,Re.cash],"type"),e===Re.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}}let ew=class{constructor(t,e,r,n,i){$(this,"_variables");$(this,"_options");$(this,"_totalChangeCapital");$(this,"_historyOrder");$(this,"_orders");$(this,"_pendingOrders");$(this,"_mintick");$(this,"_funcOptions");$(this,"_pendingCloseOrders");$(this,"_errorListener");$(this,"_risk");$(this,"_opentrades");$(this,"_closedtrades");$(this,"_riskNamespace");$(this,"_updateOptions",{});$(this,"_id");$(this,"_maxDrawdownVerifyIndex",0);this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Kt.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Re.fixed,default_qty_value:1,initial_capital:1e6,currency:Xf.NONE,slippage:0,commission_type:nr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new Qy(this),this._closedtrades=new Xy(this),this._riskNamespace=new tw(this,n),this._id=`strategy_${i}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:t}=this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(t){this._updateOptions=t||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),this._maxDrawdownVerify(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._calcProfitAndLoss(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._variables.strategy.update(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{high:n,low:i,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:h}}=this._variables;let{preNetprofit:p=0}=this._risk;l===a&&(p=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=p-c;f+=this._orders.reduce((y,m)=>{const{in_price:w,direction:v,qty:x=0,commission:b=0,original_qty:N=0}=m,E=v===ue.long?1:-1,A=(n-w)*x,M=(i-w)*x,S=E===1?M:-A;return y+S+x/N*b},0);let d=!1;switch(e){case Re.cash:d=t<f;break;case Re.percentOfEquity:const y=f/(h+c)*100;d=t<y;break}if(d){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===ue.long?i:n,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:i,time_tradingday:a,strategy:l,open:c}=this._variables;let h=e;if(i===a){const p=l.netprofit+l.openprofit;p<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:p})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:n,open:i}=this._variables;if(t!==void 0&&e&&this._maxDrawdownVerifyIndex===n){const{initial_capital:a}=this._options,c=this._orders.reduce((p,f)=>{const{in_price:d,commission:g=0,qty:y=0,original_qty:m=0,direction:w}=f,v=w===ue.long?1:-1,x=(i-d)*v*y;return p+x+g*y/m},0)+this._totalChangeCapital;let h=!1;switch(e){case Re.percentOfEquity:h=c/a*100<=-t;break;case Re.cash:h=c<=-t;break}h&&this._riskTouchOff(i,"Close Position (Max Drawdown)")}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,t,e,"close"),this._pendingOrders=[]}strategy(t,e){if(!this._variables.bar_index){this._paramVerfiy(t.format,e,"strategy",[Kt.inherit,Kt.price,Kt.percent,Kt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Re),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(nr),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),n={...this._updateOptions};if(r)for(const i of Object.keys({...r,...t}))t[i]!==r[i]&&delete n[i];self==null||self.workerStorage.set(this._id,t),Object.assign(this._options,t,n),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:n,scriptType:"strategy"})}}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(un),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(un),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.length)return;const{immediately:e}=t;if(e||this._options.process_orders_on_close){const r=this._pendingCloseOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingCloseOrders.push({...t,place_order_type:"close"})}else{const r=this._pendingOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingOrders.push({...t,place_order_type:"close"})}}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Re.fixed,default_qty_value:r=1,initial_capital:n}=this._options;let i=r;switch(e){case Re.cash:i=r/t;break;case Re.percentOfEquity:const a=this._getOrderProfit(t);i=(n+a+this._totalChangeCapital)*r/100/t;break}return Tl(i,this._getLen(t))}_getLen(t){const e=String(Math.floor(t)).length-2;return e<0?0:e}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{close:t}=this._variables;for(const e of this._orders){const{in_price:r,qty:n=0,direction:i}=e,a=i===ue.long?1:-1,l=(t-r)*a*n,[c,h]=this._calcProfitAndLossHandle(r,n,a);this._calcOrderPercent(e,l,c,h)}}_calcProfitAndLossHandle(t,e,r){const{high:n,low:i}=this._variables,a=(n-t)*e,l=(i-t)*e;let c=r===1?a:-l,h=r===1?l:-a;return[c,h]}_calcOrderPercent(t,e,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:p=0,trading_loss:f=0}=t;let{commission:d=0}=t,g=h*c;if(i){const y=this._getCommission(a,c);d=d*c/l,r-=d,n-=d,g+=d,e=e-y-d}r=Math.max(r,p,0),n=Math.min(n,f,0),Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:t,low:e,time:r}=this._variables,{initial_capital:n,margin_long:i=0,margin_short:a=0}=this._options,l=this._orders[0].direction===ue.long?1:-1;let c=l===1?e:t;if(l===1&&i===100)return;const h=(l===1?i:a)/100;if(h<=0)return;let p=!1;const[f,d]=this._orders.reduce((w,v)=>{let[x,b]=w;const{in_price:N,qty:E=0,in_time:A}=v;A===r&&(p=!0);const M=N*E,S=c*E;return x+=M,b+=S,[x,b]},[0,0]);let g=0,y=0;const m=n+this._totalChangeCapital;if(p&&(g=m-f*h,g<0&&(c=this._orders[0].in_price,y=Math.abs(Math.trunc(g/h/c)*4),y=Math.max(y,1))),g>=0){const w=l*(d-f);if(g=m+w-d*h,g>=0)return;y=Math.abs(Math.trunc(g/h/c)*4)}y<=0||this._marginCallOrders(c,y,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r,!0);return}for(const i of this.orders)i.position_close_type=i.place_order_type,this._processOrder(i,t,e,r,r,!0);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:l,price:c,activePrice:h}=this._orderArgsParse(t),p=t.direction===ue.long?1:-1;if(a<=0)return;let f=a;if(i&&e){if(n.length){const b=this._processOrders(n,l,f,t.id,t.comment,!1,"order");if(b<=0)return;f=b}const g=l+p*r*this._mintick;if(!this._judgeCapitalEnough(f,g,p))return;this._ocaGroupVerify(f,t.oca_name,t.oca_type);const{bar_index:m,time:w,high:v,low:x}=this._variables;this._calcCurrentOrder({...t,in_price:g,in_high:v,in_low:x,in_index:m,in_time:w,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,p)&&this._addPendingOrders(t,c,f,i,h)}_judgeCapitalEnough(t,e,r){let n=this._freezeCapital;if(this._orders.some(p=>(p.direction===ue.long?1:-1)!==r)&&(n=0),t<=0)return!1;const{margin_long:i=0,margin_short:a=0}=this._options;if(i===0&&r===1||a===0&&r===-1)return!0;const l=this._getOrderProfit(e),h=this._getCapital(r,this._options.initial_capital+l+this._totalChangeCapital)-n;return t*e<=h}_getOrderProfit(t){return this._orders.reduce((e,r)=>{const{in_price:n,qty:i=0,direction:a}=r,l=a===ue.long?1:-1;return e+(t-n)*i*l},0)}_ocaGroupVerify(t,e,r){if(!e||!r||r===un.none)return!1;let n=!1;switch(r){case un.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===e)i.isCancel=!0,n=!0;else return!0});break;case un.reduce:this._pendingOrders=this._pendingOrders.filter(i=>{const{qty:a=0,oca_name:l}=i;if(e===l){const c=a-t;return n=!0,c<=0?(i.isCancel=!0,!1):(i.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,i,a=!1,l){let c=r;for(const h of t)if(h.position_close_type=l||h.place_order_type,c=this._processOrder(h,e,c,n,i,a),c<=0)break;return this._orders=this._orders.filter(h=>!h.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),c}_addPendingOrders(t,e,r,n,i){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let i=t.limit||0;const{close:a}=this._variables;let l=a,c=!1,h;const p=e===ue.long?1:-1,f=n&&(n-a)*p>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&i&&(i-=d*this._mintick*p);const g=i&&(i-a)*p<0;f&&g?(h=n,l=i):f?l=n:g?l=i:c=!0;const y=r!==void 0?Tl(r,this._getLen(l)):this._calcDefaultQty(l);return{orders:this._orders.filter(w=>w.direction!==e),isMarketPrice:c,activePrice:h,quantities:y,close:a,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:l,activePrice:c}=this._orderArgsParse(t);if(i<=0)return;if(r.length&&n&&e){this._entryOrder(r,a,i,t);return}this._judgeCapitalEnough(i,a,t.direction===ue.long?1:-1)&&this._addPendingEntry(t,l,i,n,c)}_entryOrder(t,e,r,n){const{time:i,bar_index:a,high:l,low:c}=this._variables,{slippage:h=0}=this._options,{oca_name:p,oca_type:f,direction:d,comment:g,isMarketPrice:y,id:m}=n,w=d===ue.long?1:-1;if(r=this._getAvailablePositionSize(r,d),r<=0||(e=e+h*this._mintick*w,!this._judgeCapitalEnough(r,e,w)))return;this._closeOrders(t,e,m,g,"entry");const x={...n,in_price:e,qty:r,in_index:a,in_high:l,in_low:c,in_time:i,place_order_type:"entry"};if(y){this._calcCurrentOrder(x);return}const{pendingOrders:b,orders:N}=this._getEntryOrders(d),E=b.length+N.length;E&&E>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,p,f),this._calcCurrentOrder(x))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==ue.all&&n!==e)return 0;if(r===void 0)return t;const i=this._orders.reduce((a,l)=>a+(l.qty||0),0);return i?i+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,i){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(p=>p.id===t.id&&p.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else if(!c||c<(this._options.pyramiding||1)){const p={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(p)}}_closeAllOrders(t,e){const{comment:r}=t,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,e,"Close position order",r,"close"),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n,i){for(const a of t)a.position_close_type=i,this._closeOrder(a,e,r,n);this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_closeOrder(t,e,r,n){const{time:i,bar_index:a,high:l,low:c}=this._variables,{slippage:h=0}=this._options,{in_price:p,qty:f=0,direction:d}=t,g=d===ue.long?1:-1;e=e-g*h*this._mintick,t.isDeal=!0;const y=(e-p)*g*f,m={...t,out_price:e,out_id:r,out_index:a,out_high:l,out_low:c,out_time:i,out_comment:n,out_qty:f,profit:y};this._calcPercent(m)}_ordersHandle(){const t=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!t.length)return;const{open:e,low:r,high:n,close:i}=this._variables;for(const a of t){const{stop:l,limit:c,trail_stop_price:h,isMarketPriceLimit:p,isMarketPriceStop:f,direction:d,id:g,out_comment:y,active_price:m,trail_offset:w=0,out_qty:v,comment_loss:x,comment_profit:b,comment_trailing:N}=a;let E=h;const A=d===ue.long?1:-1;let M,S=y;if(p||f?M=e:(c&&r<=c&&n>=c&&(S=b||y,M=c),l&&r<=l&&n>=l&&(M=E?(l-E)*A>0?l:E:l,S=(E===M?N:x)||y)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let T=!1;if(m&&m<=n&&m>=r&&(E=m-w*A*this._mintick,(E-i)*A>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=E)),T=!0,a.trail_stop_price=E),E)if((E-e)*A>=0&&!T)M=E;else{const F=(A===1?n:r)-w*A*this._mintick;A===1?E<e&&E>=r&&F>E&&F<i?M=E:F>E?(E=F,F>=i&&(M=F)):E<=n&&r<=E&&(M=E):E>e&&E<=n&&F<E&&F>i?M=E:F<E?(E=F,F<=i&&(M=F)):E<=n&&r<=E&&(M=E),a.trail_stop_price=E}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||y,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of this._pendingOrders){const{isCancel:i,place_order_type:a}=n;if(i)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of r)switch(n.place_order_type){case"close":const i=this._closeOrderHandle(n);i&&t.push(i);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of e){const i=this._exitOrderHandle(n);i&&t.push(i)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),e=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;this._pendingCloseOrders=[];for(const n of e)switch(n.place_order_type){case"close":const i=this._closeOrderHandle(n,!0);i&&this._pendingCloseOrders.push(i);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of t){const{from_entry:i}=n,a=this._orders.filter(l=>!i||l.id===i&&(l.isMarketPriceLimit||l.isMarketPriceStop));for(const l of a)this._processExitOnClose(l,l.limit||l.stop||l.trail_stop_price||r,n)}}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let p=l;if(i&&(p=e),p<=n&&p>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,p,a,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:p,direction:f,comment:d,oca_name:g,oca_type:y,active_price:m,id:w}=t;if(m&&n>=m&&r<=m)return delete t.active_price,t;let v=p,x=h;if(c&&(v=e),v<=n&&v>=r){const b=this._orders.filter(E=>E.direction!==f);if(b.length&&(x=this._processOrders(b,v,h,w,d,!1,"order"),x<=0))return;const N=f===ue.long?1:-1;this._ocaGroupVerify(x,g,y),this._calcCurrentOrder({...t,in_price:v+N*l*this._mintick,in_index:a,in_time:i,in_high:n,in_low:r,qty:x});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:i=100,comment:a}=t,{close_entries_rule:l="FIFO"}=this._options;let c=[];if(l==="FIFO"?c=this._orders.filter(d=>d.id===r):c=this._orders.filter(d=>d.id===r&&!d.close_qty),!c.length)return t;let h=0;if(n?h=n:(h=c.reduce((d,g)=>d+(g.qty||0),h),h=i/100*h),h<=0)return;const{open:p,close:f}=this._variables;if(l==="FIFO")this._processOrders(c,e?f:p,h,`Close entry(s) order ${r}`,a,!1,"close");else if(this._processCloseOrders(c,e?f:p,h,`Close entry(s) order ${r}`,a))return t}_processCloseOrders(t,e,r,n,i){let a=!1;for(const l of t)l.close_qty=r,(l.qty||0)>r&&(a=!0),l.position_close_type="close",this._processOrder(l,e,r,n,i);return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),a}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t)))return t}_exit(t,e){const{profit:r,loss:n,stop:i,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:p="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c))){this._errorListener.addError(le.strategyExitErr,e,zt.Error);return}const d={...t,place_order_type:"exit"},g=this._orders.filter(w=>(!p||p===w.id)&&!w.hasExit),y=this._pendingOrders.filter(w=>!p||p===w.id);if(g.length){if(!this._ordersToExit(g,d))return}else if(!y.length)return;const m=this._pendingOrders.find(w=>w.id===f&&w.place_order_type==="exit");m?Object.assign(m,{...t}):this._pendingOrders.push(d)}_ordersToExit(t,e){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:l,comment_profit:c,comment_trailing:h}=e;let p=r,f=!1;e.comment=a||i;for(const d of t){const{qty:g=0}=d,y=d.direction===ue.long?1:-1;p=r?r>=g?g:r:n/100*g,d.out_qty=p,p<g&&(f=!0),Object.assign(d,{out_comment:a||i,comment_loss:l,comment_profit:c,comment_trailing:h}),!(this._stopProfit(d,y,{...e,qty:p})||this._stopLoss(d,y,{...e,qty:p})||this._trailStopLoss(d,y,{...e,qty:p}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(t){t.place_order_type="exit";const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r){const{limit:n,profit:i,comment_profit:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=p+e*i*this._mintick),t.limit=c,c!==void 0&&(c-h)*e<=0&&(t.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,t.limit=c,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r){const{stop:n,loss:i,comment_loss:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=p-e*i*this._mintick),t.stop=c,c!==void 0&&(c-h)*e>=0&&(t.isMarketPriceStop=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,t.stop=c,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(i)?this._isNaN(a)||(d=p+a*e*this._mintick):d=i,t.trail_offset=n,d!==void 0&&(d-h)*e<=0){const g=h-n*e*this._mintick;if((g-h)*e>=0&&(t.trail_stop_price=h,t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;t.trail_stop_price=g}t.active_price=d}}_processExitOnClose(t,e,r){const{qty:n=0,comment:i,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO"){const c=this._processExitOrders(this._orders,e,n,a,i);c&&!c.hasExit?(c.hasExit=!0,Object.assign(t,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,a,i,!1,"exit")}_processExitOrders(t,e,r,n,i){let a=r,l;for(const c of t)if(l=c,c.position_close_type="exit",a=this._processOrder(c,e,a,n,i),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_processOrder(t,e,r,n,i,a=!1){const{time:l,bar_index:c,high:h,low:p}=this._variables,{slippage:f=0}=this._options,{in_price:d,qty:g=0,max_profit:y,trading_loss:m,direction:w,commission:v=0,original_qty:x=0}=t,b=w===ue.long?1:-1;if(e=e-b*f*this._mintick,r<g){const N=g-r,E=(e-d)*b*r,A=y!==void 0?y/g*r:void 0,M=m!==void 0?m/g*r:void 0,S=v*N/x;this._calcPercent({...t,out_price:e,last_commission:S,out_id:n,out_index:c,out_high:h,out_low:p,out_time:l,out_comment:i,profit:E,out_qty:r,max_profit:A,trading_loss:M});const T=(e-d)*b*N-S;Object.assign(t,{qty:N,profit:T,max_profit:y!==void 0?y-(A||0):void 0,trading_loss:m!==void 0?m-(M||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{t.isDeal=!0;const N=(e-d)*b*g;this._calcPercent({...t,out_price:e,out_id:n,out_index:c,out_high:h,out_low:p,out_time:l,out_comment:i,out_qty:g,profit:N}),r-=g}return a&&(b===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(t){const{commission_value:e,process_orders_on_close:r}=this._options,{in_price:n,out_qty:i=0,out_price:a=0,original_qty:l=0,direction:c,last_commission:h=0}=t;let{profit:p=0,max_profit:f,trading_loss:d,commission:g=0}=t,y=n*i,m=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=p,e){const w=this._getCommission(a,i);this._totalChangeCapital-=w;let v=g*i/l;y+=v,v+=w,p=p-v,Object.assign(t,{commission:v,profit:p});const x=this._orders.reduce((b,N)=>{const{qty:E=0,original_qty:A=0,commission:M=0}=N;return b+M*E/A},0);m+=x-h}if(f===void 0||d===void 0){const w=c===ue.long?1:-1,v=this._calcProfitAndLossHandle(n,i,w);if(f=v[0],d=v[1],e){const x=g*i/l;f-=x,d-=x}f=Math.max(0,f),d=Math.min(0,d)}Object.assign(t,{max_profit:f,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:p/m*100,profit_percent:p/y*100,max_profit_percent:f/y*100,trading_loss_percent:d/y*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(r?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(t)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,i=t*e;let a=0;switch(n){case nr.percent:a=i*r/100;break;case nr.cashPerContract:a=e*r;break;case nr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=t;let{profit:l=0}=t,c=r*n;const h=this._totalChangeCapital+this._options.initial_capital;if(e){const p=this._getCommission(r,n);this._totalChangeCapital-=p,l=l-p,c+=p,Object.assign(t,{commission:p,profit:l,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,total_profit_percent:l/h*100,profit_percent:l/c*100,max_profit_percent:i/c*100,trading_loss_percent:a/c*100}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders),e&&this._variables.strategy.updateHistoryOrders(this._historyOrder)}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}};var nh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){return function(e,r,n){r.prototype.isBetween=function(i,a,l,c){var h=n(i),p=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(nh);var rw=nh.exports,nw=Gt(rw),ih={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){return function(e,r,n){var i=r.prototype,a=function(d){var g,y=d.date,m=d.utc,w={};if(!((g=y)===null||g instanceof Date||g instanceof Array||i.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(y).length)return new Date;var v=m?n.utc():n();Object.keys(y).forEach(function(T){var F,O;w[F=T,O=i.$utils().p(F),O==="date"?"day":O]=y[T]});var x=w.day||(w.year||w.month>=0?1:v.date()),b=w.year||v.year(),N=w.month>=0?w.month:w.year||w.day?0:v.month(),E=w.hour||0,A=w.minute||0,M=w.second||0,S=w.millisecond||0;return m?new Date(Date.UTC(b,N,x,E,A,M,S)):new Date(b,N,x,E,A,M,S)}return y},l=i.parse;i.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=i.set,h=i.add,p=i.subtract,f=function(d,g,y,m){m===void 0&&(m=1);var w=Object.keys(g),v=this;return w.forEach(function(x){v=d.bind(v)(g[x]*m,x)}),v};i.set=function(d,g){return g=g===void 0?d:g,d.constructor.name==="Object"?f.bind(this)(function(y,m){return c.bind(this)(m,y)},g,d):c.bind(this)(d,g)},i.add=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g):h.bind(this)(d,g)},i.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g,-1):p.bind(this)(d,g)}}})})(ih);var iw=ih.exports,sw=Gt(iw),sh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){var e,r,n=1e3,i=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,p=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},g=function(A){return A instanceof N},y=function(A,M,S){return new N(A,S,M.$l)},m=function(A){return r.p(A)+"s"},w=function(A){return A<0},v=function(A){return w(A)?Math.ceil(A):Math.floor(A)},x=function(A){return Math.abs(A)},b=function(A,M){return A?w(A)?{negative:!0,format:""+x(A)+M}:{negative:!1,format:""+A+M}:{negative:!1,format:""}},N=function(){function A(S,T,F){var O=this;if(this.$d={},this.$l=F,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),T)return y(S*d[m(T)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){O.$d[m(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var R=S.match(f);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=A.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(T,F){return T+(S.$d[F]||0)*d[F]},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/i),S%=i,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),T=b(this.$d.months,"M"),F=+this.$d.days||0;this.$d.weeks&&(F+=7*this.$d.weeks);var O=b(F,"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 W=b(q,"S"),z=S.negative||T.negative||O.negative||R.negative||U.negative||W.negative,K=R.format||U.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+T.format+O.format+K+R.format+U.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},M.toJSON=function(){return this.toISOString()},M.format=function(S){var T=S||"YYYY-MM-DDTHH:mm:ss",F={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 T.replace(c,function(O,R){return R||String(F[O])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var T=this.$ms,F=m(S);return F==="milliseconds"?T%=1e3:T=F==="weeks"?v(T/d[F]):this.$d[F],T||0},M.add=function(S,T,F){var O;return O=T?S*d[m(T)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+O*(F?-1:1),this)},M.subtract=function(S,T){return this.add(S,T,!0)},M.locale=function(S){var T=this.clone();return T.$l=S,T},M.clone=function(){return y(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")},A}(),E=function(A,M,S){return A.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(A,M,S){e=S,r=S().$utils(),S.duration=function(O,R){var U=S.locale();return y(O,{$l:U},R)},S.isDuration=g;var T=M.prototype.add,F=M.prototype.subtract;M.prototype.add=function(O,R){return g(O)?E(this,O,1):T.bind(this)(O,R)},M.prototype.subtract=function(O,R){return g(O)?E(this,O,-1):F.bind(this)(O,R)}}})})(sh);var ow=sh.exports,aw=Gt(ow);ee.extend(Sl),ee.extend(nw),ee.extend(sw),ee.extend(aw);class oh{constructor(t,e,r){$(this,"array");$(this,"color");$(this,"math");$(this,"str");$(this,"map");$(this,"matrix");$(this,"timeframe");$(this,"ta");$(this,"input");$(this,"_variables");$(this,"_cacheData");$(this,"_options");$(this,"_errorListener");$(this,"_plots");$(this,"_plotshapes");$(this,"_plotbars");$(this,"_plotchars");$(this,"_plotarrows");$(this,"_plotcandles");$(this,"_alerts");$(this,"_bgColors");$(this,"_hlines");$(this,"_fills");$(this,"chart");$(this,"line");$(this,"label");$(this,"polyline");$(this,"box");$(this,"table");$(this,"linefill");$(this,"log");$(this,"runtime");$(this,"strategy");$(this,"request");$(this,"syminfo");$(this,"_count",0);var i;const n=((i=t.toString().split(".")[1])==null?void 0:i.length)||5;this._variables=e,this._errorListener=new hw,this.array=new Hp(this._errorListener),this.math=new Jp(n,this._errorListener),this.color=new b1,this.str=new xy(this._errorListener,n),this.map=new Ey(this._errorListener),this.timeframe=new by(e),this.matrix=new Dy(this._errorListener),this.ta=new w1(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new D1(e,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Ay(e)},this.line=new Ky(e,this._errorListener),this.label=new Cy(e,this._errorListener),this.polyline=new Zy(e,this._errorListener),this.box=new Hy(e,this._errorListener),this.table=new Jy(e,this._errorListener),this.linefill=new Gy(e),this.log=new cw(e),this.runtime=new fw(this._errorListener),this.strategy=new ew(this._variables,this._options,t,this._errorListener,r),this.request=new uw(this._variables,r),this.syminfo=new lw}get errors(){return this._errorListener.errors}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let i;if(n.length){i={};for(const v of n)i[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,l=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders,strategySummary:this._variables.strategy.summaryData});const h=this._plots.size>0?[...this._plots.values()]:void 0,p=this._plotbars.size>0?[...this._plotbars.values()]:void 0,f=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,d=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,g=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,y=this._plotchars.size>0?[...this._plotchars.values()]:void 0,m=this._getDraws(),w=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:h,draws:m,alerts:r,colors:i,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:d,plotcandles:g,plotchars:y,plotbars:p,isUseBgColor:w})}_getDataOfBarindex(t){const e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const d of r)n[d]=[...this._bgColors[d].values()].map(g=>{const y=[];for(const m of t){const w=g.colors[m];w&&y.push(w)}return g.colors=y,g})}const i=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,l=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),h=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,p=this._getDrawsFromBarindex(t),f=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,draws:p,alerts:e,colors:n,hlines:i,fills:a,logs:l,plotshapes:h,isUseBgColor:f})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const i of t){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:i,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),i.data.length&&(l.polylines=i.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:i,polyline:a,label:l}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),i.data.length&&(c.boxes=i.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),l.data.length&&(c.labels=l.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}updateOptions(t){const{inputs:e,strategy:r}=t;this.input.update(e),r&&this.strategy.updateOptions(r)}update(t){const{barIndex:e}=t;this.strategy.update(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)?(Gp.includes(n)||Kp.includes(n))&&this._errorListener.addError(Ve(le.libraryTitleIsKeywordErr,{name:n}),e,zt.Error):this._errorListener.addError(le.libraryTitleErr,e,zt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Kt.inherit,Kt.percent,Kt.price,Kt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,i="format"){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(Yp.lineWidthWarning,e,zt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];me(t,r);const{series:n,color:i,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,p=this._plots.get(h),f=(p==null?void 0:p.data)||[],d=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,d],itemStyle:{color:i}},this._seriesColorHandle(t,r,p),!p){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Kt.percent,Kt.price,Kt.volume]);const g=i?[i]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h,zIndex:this._count})}return{type:"plot",key:h}}plotbar(t,e){const r=["color"];me(t,r);const{open:n,close:i,low:a,high:l,color:c,...h}=t,{bar_index:p,time:f}=this._variables,d=`plotbar_${e}`,g=this._plotbars.get(d),y=(g==null?void 0:g.data)||[],m=i!==void 0&&isNaN(i)?void 0:i,w=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,x=l!==void 0&&isNaN(l)?void 0:l,b=[f,w,m,v,x];if(y[p]={value:b,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Kt.percent,Kt.price,Kt.volume]);const N=c?[c]:void 0;this._plotbars.set(d,{editable:!0,...h,colors:N,data:y,id:d,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:i,location:a,style:l}=t;this._paramVerfiy(l,r,e,Object.values(ur),"style"),this._paramVerfiy(a,r,e,Object.values(an),"location"),this._paramVerfiy(n,r,e,Object.values(rr),"size"),this._paramVerfiy(i,r,e,[Kt.percent,Kt.price,Kt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];me(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:h,time:p,high:f,low:d}=this._variables,g=`plotchar_${e}`,y=this._plotchars.get(g),m=(y==null?void 0:y.data)||[],w={value:[p,n],itemStyle:{color:i,textcolor:a},low:d,high:f};m[h]=w,this._seriesColorHandle(t,r,y),y||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];me(t,r);const{series:n,colorup:i,colordown:a,...l}=t,{bar_index:c,time:h}=this._variables,p=`plotarrow_${e}`,f=this._plotarrows.get(p),d=(f==null?void 0:f.data)||[];d[c]={value:[h,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:i,colordown:a}},this._seriesColorHandle(t,r,f),f||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Kt.percent,Kt.price,Kt.volume]),this._plotarrows.set(p,{editable:!0,...l,data:d,id:p,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];me(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:h,time:p,low:f,high:d}=this._variables,g=`plotshape_${e}`,y=this._plotshapes.get(g),m=(y==null?void 0:y.data)||[],w={value:n,color:i,textcolor:a,time:p,low:f,high:d};if(m[h]=w,this._seriesColorHandle(t,r,y),!y){this._count++;const v=i?[i]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];me(t,r);const{wickcolor:n,bordercolor:i,color:a,close:l,open:c,low:h,high:p,...f}=t,{bar_index:d,time:g}=this._variables,y=`plotcandle_${e}`,m=this._plotcandles.get(y),w=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,x=c!==void 0&&isNaN(c)?void 0:c,b=h!==void 0&&isNaN(h)?void 0:h,N=p!==void 0&&isNaN(p)?void 0:p,E=[g,x,v,b,N];w[d]={value:E,wickcolor:n,bordercolor:i,color:a},this._seriesColorHandle(t,r,m),m||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Kt.percent,Kt.price,Kt.volume]),this._plotcandles.set(y,{editable:!0,...f,data:w,id:y,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;me(t,["color"]),this._verifyDisplay(t.display,"hline",e);const i=t.display&&!t.display.length?Ye.none:Ye.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:i,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,T,F,O,R,U,q,W,z,K;const r=["color","top_color","bottom_color"];me(t,r);const{color:n,top_color:i,bottom_color:a,seriesColors:l,hline1:c,hline2:h,plot1:p,plot2:f,top_value:d,bottom_value:g,...y}=t,{bar_index:m,time:w}=this._variables,v=`fill_${e}`,x=this._fills.get(v),b=(x==null?void 0:x.data)||[];this._verifyDisplay(t.display,"fill",e);const N=t.display&&!t.display.length?Ye.none:Ye.all;let E,A,M="plot";if(c&&h)E=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,A=(T=this._hlines.get(h==null?void 0:h.key))==null?void 0:T.price,M="hline";else{const Z=((F=this._plots.get(p==null?void 0:p.key))==null?void 0:F.data)||[],X=((O=this._plots.get(f==null?void 0:f.key))==null?void 0:O.data)||[];E=(U=(R=Z[m])==null?void 0:R.value)==null?void 0:U[1],A=(W=(q=X[m])==null?void 0:q.value)==null?void 0:W[1]}if(b[m]={time:w,color:n,top_color:i,bottom_color:a,plot1:E,plot2:A,top_value:d,bottom_value:g},this._seriesColorHandle(t,r,x),!x){this._count++;const Z=((z=this._options.indicator)==null?void 0:z.explicit_plot_zorder)||((K=this._options.strategy)==null?void 0:K.explicit_plot_zorder),X=n?[n]:void 0,Q=i?[i]:void 0,ct=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ct,display:N,data:b,type:M,editable:!0,fillgaps:!1,hline1:c,hline2:h,plot1:p,plot2:f,...y,zIndex:Z?this._count:void 0})}}alert({message:t,freq:e=qr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},h=c.barIndex;if(this._paramVerfiy(e,r,"alert",[qr.freqAll,qr.freqOncePerBar,qr.freqOncePerBarClose]),e===qr.freqOncePerBar&&n===h){this._alerts.delete(l);return}this._cacheData[l]=c;const p={message:t,freq:e,id:l,type:"alert"};if(i){e!==qr.freqOncePerBarClose&&this._alerts.set(l,p),c.barIndex=n;return}if(!i&&e===qr.freqOncePerBarClose&&n===h&&a===n-1){this._alerts.set(l,p),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t,e){this._setColors(t,"barcolor",e)}bgcolor(t,e){this._setColors(t,"bgcolor",e)}_verifyDisplay(t=Qf.all,e,r){t.length&&t.length<4&&this._errorListener.addError(Ve(le.displayErr,{func:e,values:"[display.none, display.all]"}),r,zt.Error)}_setColors(t,e,r){me(t,["color"]);const{color:i,...a}=t;this._verifyDisplay(a.display,e,r);const l=t.display&&!t.display.length?Ye.none:Ye.all,{bar_index:c,time:h}=this._variables,p=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const f=this._bgColors[e].get(p),d=(f==null?void 0:f.colors)||[],g=(f==null?void 0:f.setColors)||[];i&&!g.includes(i)&&g.push(i),d[c]={color:i,time:h},f||this._bgColors[e].set(p,{...a,display:l,colors:d,setColors:g,id:p})}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||typeof t=="number"&&isNaN(t))}fixnan({source:t},e){return t===void 0||typeof t=="number"&&isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!(typeof t=="number"&&isNaN(t))?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,t,e,r,n)}timestamp(t){const{dateString:e,timezone:r,year:n,month:i,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return ee(e).utc(!/GMT|UTC/.test(e)).valueOf();let p=i-1,f=n;if(p<0){const g=Math.ceil(Math.abs(p/12));p=12*g+p,f=n-g}let d=ee({year:f,month:p,day:a,hour:l,minute:c,second:h});return r&&(d=kr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:t,timezone:e}){return kr(t,e).week()}year({time:t,timezone:e}){return kr(t,e).year()}second({time:t,timezone:e}){return kr(t,e).second()}month({time:t,timezone:e}){return kr(t,e).month()+1}minute({time:t,timezone:e}){return kr(t,e).minute()}hour({time:t,timezone:e}){return kr(t,e).hour()}dayofweek({time:t,timezone:e}){return kr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return kr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Qr(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,i,a=0){const l=r||this._variables.timeframe.period,c=Qr(l),h=Qr(this._variables.timeframe.period);let p;if(c<=h)p=t;else{const f=`time_${e}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=t?(p=t,this._cacheData[f]={currentTime:t,offset:0}):p=d;else{const g=this._calcTimeOffset(t,l);this._cacheData[f]={currentTime:t,offset:g},p=t}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,e),g=ee(t).format("YYYY-MM-DD"),y=p;p=void 0;for(const w of f){const[v,x]=w;if(ee(t).isBetween(`${g} ${v}`,`${g} ${x}`,"hour")){ee(y).isBetween(`${g} ${v}`,`${g} ${x}`,"hour")?p=y:p=ee(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;p&&!d.includes(m)&&(p=void 0)}return i&&(p=p&&kr(p,i).valueOf()),p&&p-a*h*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const i of e){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=t[i];if(!a)continue;const l=r[`${i}s`]||[];l.includes(a)||(l.push(a),r[`${i}s`]=l,l.length>5&&(r[`${i}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(i)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,zt.Error);return}return h});return{timePeriods:n.split(",").map(c=>{c===""||c===fi.regular?c="0930-1500":c===fi.extended&&(c="1500-1830");const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,zt.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",e,zt.Error);return}return`${r}:${n}`}}class uw{constructor(t,e){$(this,"_variables");$(this,"_scriptId");$(this,"_cacheData");this._variables=t,this._scriptId=e,this._cacheData=new Map}security(t,e){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=t,i=this._getRequestData(t,e);if(r!=null&&r.has(e)){const c=r.get(e);return this._runScripts(c,e,!1,n,i)}const a=this._parseExprCode(t),l=this._runScripts(a,e,!0,n,i);return r==null||r.set(e,a),l}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],i=1;e=Il(e);const a=JSON.parse(e),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},h=(l==null?void 0:l.depends)||[];if(!h.length)return`return ${l==null?void 0:l.code}`;let p=[],f=[];const d=[];if(this._getDependCodes(h,a,n,p,f,d),f.length){const m=r.length;let w=[];for(let v=m-1;v>=0;v--){const x=r[v];let b=JSON.parse(Il(x));const N=[];i!==0&&f.length&&(w.unshift("{"),i++),b=b.map(S=>{const{scope:T,code:F,varNames:O,dependSelf:R}=S;return T===2&&!N.includes(O)&&!R&&(S.code=`let ${F}`),O&&N.push(...O.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const E=[],A=[];let M=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(M,b,A,p,f,E),w.unshift(...A,...E),n=w.concat(n),w=[]}}for(n.push(`return ${l==null?void 0:l.code}`);i>1;)n.push("}"),i--;n=p.concat(n),n.push(...d);let g=n.join(`
62
+ `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return String(this._toStringFormat(t,e))}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._toStringFormat(n,e):n).toString()}]`}substring({source:t="",begin_pos:e=0,end_pos:r}){return _t(e)&&(e=0),_t(r)&&(r=void 0),t==null?void 0:t.substring(e,r)}startswith({source:t="",str:e=""}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _t(t)&&(t=0),kr(t,r).format(e)}replace_all({source:t="",target:e="",replacement:r=""}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_toStringFormat(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case Kt.mintick:return t.toFixed(this._precision);case Kt.percent:return`${t}%`;case Kt.volume:return this._intlNumberFormatter.format(Math.round(t));default:return this._formatOthers(t,e)}}_formatOthers(t,e){var l;let[r,n]=e.split(".");e.split("%").length===2&&(t=t*100);let[i,a=""]=String(t).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),h=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;h&&(i=i.replace(new RegExp(`\\B(?=(\\d{${h}})+(?!\\d))`,"g"),",")),r=c.join("")}i=r.replace(/#/,i).replace(/#/g,"")}else i=`${r}${i}`;if(n&&n.includes("#")){const c=n.split("#").length-1;a=`${a.substring(0,c)}${n.replace(/#/g,"")}`}else a=n||"";return a?`${i}.${a}`:i}_formatNumber(t,e){if(!e)return Number(t.toFixed(this._precision));switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:return this._formatOthers(t,e)}}_strFormat(t,e){let r=t;for(const[n,i]of e.entries()){if(i===void 0||typeof i=="number"&&isNaN(i)){r="NaN";continue}if(typeof i=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(a));if(l){const c=l[1];r=r.replace(new RegExp(a,"g"),String(this._formatNumber(i,c)))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),String(i))}else r=r.replace(new RegExp(`\\{${n}\\}`,"g"),i)}return r}}class Ey{constructor(t){$(this,"_errorListener");this._errorListener=t}new(){return new qa(this._errorListener)}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class qa{constructor(t){$(this,"_errorListener");$(this,"_mapInstance");this._errorListener=t,this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new qa(this._errorListener);return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Qt(0,void 0,this._errorListener);return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class Ay{constructor(t){$(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Ai(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Ai(t,r,e)}copy({id:t}){return t==null?void 0:t.copy()}from_index({price:t,index:e}){return new Ai(t,e)}from_time({price:t,time:e}){return new Ai(t,void 0,e)}}class Ai{constructor(t,e,r){$(this,"_index");$(this,"_price");$(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 Ai(this._price,this._index,this._time)}}class Cy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLabel",{text:"",xloc:we.bar_index,yloc:Wr.price,size:rr.normal,style:ge.styleLabelDown,textalign:Wt.alignCenter});this._variables=t,this._errorListener=e}new(t,e){const{time:r,high:n,low:i,bar_index:a}=this._variables,l=`label_${e}_${a}`;me(t,["color","textcolor"]);const c={...this._defaultLabel,...t,id:l,time:r,high:n,low:i,bar_index:a};t.point&&(c.x=c.xloc===we.bar_index?t.point.index:t.point.time,c.y=t.point.price),c.yloc===Wr.abovebar?c.y=n:c.yloc===Wr.belowbar&&(c.y=i),this._verfiyArgs(t,e);const h=new ao(l,this._variables,this._errorListener);return e.startsWith("export")||this._variables.label.add(l,c,h),h}_verfiyArgs(t,e){const{xloc:r,yloc:n,style:i,size:a,textalign:l,text_font_family:c}=t,h="label.new";this._paramVerfiy(i,e,h,Object.values(ge),"style"),this._paramVerfiy(r,e,h,Object.values(we),"xloc"),this._paramVerfiy(n,e,h,Object.values(Wr),"yloc"),this._paramVerfiy(a,e,h,Object.values(rr),"size"),this._paramVerfiy(l,e,h,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign"),this._paramVerfiy(c,e,h,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}label(t){return t.x}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 ao{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get type(){return Fe.LABEL}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get data(){return this._variables.label.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`label_${t}_${e}`,n=this._getLabel(t),i=new ao(r,this._variables,this._errorListener);if(n){const a={...n,id:r,bar_index:e};this._variables.label.add(r,a,i)}return i}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),this._paramVerfiy(t,e,"label.set_size",Object.values(rr),"size")}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,this._paramVerfiy(e,r,"label.set_xloc",Object.values(we),"xloc"))}set_yloc({yloc:t},e){const r=this._getLabel(e),{high:n,low:i}=this._variables;r&&(r.yloc=t,t===Wr.abovebar?r.y=n:t===Wr.belowbar&&(r.y=i),this._paramVerfiy(t,e,"label.set_yloc",Object.values(Wr),"yloc"))}set_color(t,e){const r=this._getLabel(e);me(t,["color"]),r&&(r.color=t.color)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===we.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),this._paramVerfiy(t,e,"label.set_style",Object.values(ge),"style")}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),this._paramVerfiy(t,e,"label.set_textalign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"textalign")}set_textcolor(t,e){const r=this._getLabel(e);me(t,["textcolor"]),r&&(r.textcolor=t.textcolor)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t),this._paramVerfiy(t,e,"label.set_text_font_family",Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const Fy={freq_all:qr.freqAll,freq_once_per_bar:qr.freqOncePerBar,freq_once_per_bar_close:qr.freqOncePerBarClose},My={gaps_off:Yi.gapsOff,gaps_on:Yi.gapsOn,lookahead_off:Yi.lookaheadOff,lookahead_on:Yi.lookaheadOn},Ci={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"},Xf={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"},Ny={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Qf={all:[Ye.dataWindow,Ye.pane,Ye.priceScale,Ye.statusLine],data_window:[Ye.dataWindow],none:[],pane:[Ye.pane],price_scale:[Ye.priceScale],status_line:[Ye.statusLine]},Sy={both:Ur.both,left:Ur.left,none:Ur.none,right:Ur.right},By={inherit:Kt.inherit,mintick:Kt.mintick,percent:Kt.percent,price:Kt.price,volume:Kt.volume},Oy={style_solid:Ds.styleSolid,style_dashed:Ds.styleDashed,style_dotted:Ds.styleDotted},Iy={style_arrowdown:ge.styleArrowdown,style_arrowup:ge.styleArrowup,style_circle:ge.styleCircle,style_cross:ge.styleCross,style_diamond:ge.styleDiamond,style_flag:ge.styleFlag,style_label_center:ge.styleLabelCenter,style_label_down:ge.styleLabelDown,style_label_left:ge.styleLabelLeft,style_label_lower_left:ge.styleLabelLowerLeft,style_label_lower_right:ge.styleLabelLowerRight,style_label_right:ge.styleLabelRight,style_label_up:ge.styleLabelUp,style_label_upper_left:ge.styleLabelUpperLeft,style_label_upper_right:ge.styleLabelUpperRight,style_none:ge.styleNone,style_square:ge.styleSquare,style_text_outline:ge.styleTextOutline,style_triangledown:ge.styleTriangledown,style_triangleup:ge.styleTriangleup,style_xcross:ge.styleXcross},Ty={style_arrow_both:Le.styleArrowBoth,style_arrow_left:Le.styleArrowLeft,style_arrow_right:Le.styleArrowRight,style_dashed:Le.styleDashed,style_dotted:Le.styleDotted,style_solid:Le.styleSolid},$y={abovebar:an.abovebar,absolute:an.absolute,belowbar:an.belowbar,bottom:an.bottom,top:an.top},Ly={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Ry={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},Py={bottom_center:_r.bottomCenter,bottom_left:_r.bottomLeft,bottom_right:_r.bottomRight,middle_center:_r.middleCenter,middle_left:_r.middleLeft,middle_right:_r.middleRight,top_center:_r.topCenter,top_left:_r.topLeft,top_right:_r.topRight},zy={left:bs.left,none:bs.none,right:bs.right},ky={arrowdown:ur.arrowdown,arrowup:ur.arrowup,circle:ur.circle,cross:ur.cross,diamond:ur.diamond,flag:ur.flag,labeldown:ur.labeldown,labelup:ur.labelup,square:ur.square,triangledown:ur.triangledown,triangleup:ur.triangleup,xcross:ur.xcross},qy={auto:rr.auto,huge:rr.huge,large:rr.large,normal:rr.normal,small:rr.small,tiny:rr.tiny},Uy={cash:Re.cash,fixed:Re.fixed,percent_of_equity:Re.percentOfEquity,commission:{cash_per_contract:nr.cashPerContract,cash_per_order:nr.cashPerOrder,percent:nr.percent},direction:{all:ue.all,long:ue.long,short:ue.short},oca:{cancel:un.cancel,none:un.none,reduce:un.reduce}},Wy={align_bottom:Wt.alignBottom,align_center:Wt.alignCenter,align_left:Wt.alignLeft,align_right:Wt.alignRight,align_top:Wt.alignTop,wrap_auto:Wt.wrapAuto,wrap_none:Wt.wrapNone},jy={bar_index:we.bar_index,bar_time:we.bar_time},Vy={abovebar:Wr.abovebar,belowbar:Wr.belowbar,price:Wr.price},Yy={actual:xs.actual,estimate:xs.estimate,standardized:xs.standardized};class th{constructor(){$(this,"adjustment",{dividends:ws.dividends,none:ws.none,splits:ws.splits});$(this,"alert",Fy);$(this,"barmerge",My);$(this,"color",Ci);$(this,"currency",Xf);$(this,"dayofweek",Ny);$(this,"earnings",Yy);$(this,"display",Qf);$(this,"extend",Sy);$(this,"font",{family_default:Zn.familyDefault,family_monospace:Zn.familyMonospace});$(this,"format",By);$(this,"hline",Oy);$(this,"label",Iy);$(this,"line",Ty);$(this,"location",$y);$(this,"math",Ly);$(this,"order",{ascending:Yn.ascending,descending:Yn.descending});$(this,"plot",Ry);$(this,"position",Py);$(this,"scale",zy);$(this,"session",{extended:fi.extended,regular:fi.regular});$(this,"shape",ky);$(this,"size",qy);$(this,"splits",{denominator:"denominator",numerator:"numerator"});$(this,"strategy",Uy);$(this,"text",Wy);$(this,"xloc",jy);$(this,"yloc",Vy)}updateData(){}}class Zy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:we.bar_index,line_color:Ci.blue,line_style:Le.styleSolid,line_width:1});this._variables=t,this._errorListener=e}new(t,e){var l;const{bar_index:r}=this._variables,n=`polyline_${e}_${r}`,i=Object.assign({},this._defaultPolyline,t,{id:n,bar_index:r,points:(l=t.points)==null?void 0:l._value.map(c=>({time:c.time,index:c.index,price:c.price}))});me(i,["line_color","fill_color"]);const a=new eh(n,this._variables);return this._verfiyArgs(t,e),e.startsWith("export")||this._variables.polyline.add(n,i,a),a}_verfiyArgs(t,e){const{line_style:r,xloc:n}=t,i="polyline.new";this._paramVerfiy(r,e,i,Object.values(Le),"line_style"),this._paramVerfiy(n,e,i,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}delete({id:t}){t&&t.delete()}}class eh{constructor(t,e){$(this,"_id");$(this,"_variables");this._variables=e,this._id=t}get type(){return Fe.POLYLINE}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get data(){return this._variables.polyline.get(this._id)}delete(){this._variables.polyline.delete(this._id)}}class Ky{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultLine",{xloc:we.bar_index,extend:Ur.none,style:Le.styleSolid});this._variables=t,this._errorListener=e}new({first_point:t,second_point:e,...r},n){const{bar_index:i}=this._variables,a=`line_${n}_${i}`;me(r,["color"]);const l={...this._defaultLine,...r,id:a,bar_index:i};if(t&&e){const h=l.xloc===we.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,p=l.xloc===we.bar_index?e==null?void 0:e.index:e==null?void 0:e.time;Object.assign(l,{x1:h,y1:t==null?void 0:t.price,x2:p,y2:e==null?void 0:e.price})}this._verfiyArgs(r,n);const c=new uo(a,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(a,l,c),c}_verfiyArgs(t,e){const{extend:r,xloc:n,style:i}=t,a="line.new";this._paramVerfiy(i,e,a,Object.values(Le),"style"),this._paramVerfiy(r,e,a,Object.values(Ur),"extend"),this._paramVerfiy(n,e,a,Object.values(we),"xloc")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}line(t){return t.x}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 uo{constructor(t,e,r){$(this,"_variables");$(this,"_id");$(this,"_errorListener");this._id=t,this._variables=e,this._errorListener=r}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get type(){return Fe.LINE}get data(){return this._variables.line.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`line_${t}_${e}`,n=this._getLine(t),i=new uo(r,this._variables,this._errorListener);return n&&this._variables.line.add(r,{...n,id:r,bar_index:e},i),i}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===we.bar_index){const{x1:n,y1:i,x2:a,y2:l}=r;return n===void 0||a===void 0||i===void 0||l===void 0?void 0:(l-i)/(a-n)*(t-n)+i}}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 i=this._getLine(n);i&&(i.xloc=t,i.x1=e,i.x2=r,this._paramVerfiy(t,n,"line.set_xloc",Object.values(we),"xloc"))}set_color(t,e){const r=this._getLine(e);r&&(me(t,["color"]),r.color=t.color)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t,this._paramVerfiy(t,e,"line.set_style",Object.values(Le),"style"))}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,this._paramVerfiy(t,e,"line.set_extend",Object.values(Ur),"extend"))}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:i,price:a}=t||{},l=r.xloc===we.bar_index?n:i,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Gy{constructor(t){$(this,"_variables");this._variables=t}new(t,e){const{line1:r,line2:n}=t,{bar_index:i}=this._variables,a=`linefill_${e}_${i}`,l=r==null?void 0:r.data,c=n==null?void 0:n.data;l&&(l.linefills=l.linefills||[],l.linefills.push(a)),c&&(c.linefills=c.linefills||[],c.linefills.push(a)),me(t,["color"]);const h=new lo(this._variables,a,r,n);return e.startsWith("export")||(l||c)&&this._variables.linefill.add(a,{line1:l,line2:c,color:t.color,id:a,bar_index:i},h),h}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 lo{constructor(t,e,r,n){$(this,"_id");$(this,"_line1");$(this,"_line2");$(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}get type(){return Fe.LINEFILL}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get data(){return this._variables.linefill.get(this._id)}linefill(t,e){return t.x?t.x:new lo(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:i}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(a=>a!==this._id)),i&&(i.linefills=(r=i.linefills)==null?void 0:r.filter(a=>a!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color(t){const e=this._variables.linefill.get(this._id);e&&(me(t,["color"]),e.color=t.color)}}class Hy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultBox",{border_color:Ci.blue,border_width:1,bgcolor:Ci.blue,xloc:we.bar_index,extend:Ur.none,style:Le.styleSolid,text:"",text_size:rr.auto,text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_wrap:Wt.wrapNone});this._variables=t,this._errorListener=e}box({x:t}){return t}new({top_left:t,bottom_right:e,...r},n){const{bar_index:i}=this._variables,a=`box_${n}_${i}`,l={...this._defaultBox,...r,id:a,bar_index:i};if(me(l,["border_color","bgcolor","text_color"]),t){const{price:h,time:p,index:f}=t;l.top=h,l.left=l.xloc===we.bar_index?f:p}if(e){const{price:h,time:p,index:f}=e;l.bottom=h,l.right=l.xloc===we.bar_index?f:p}this._verfiyArgs(r,n);const c=new co(this._variables,a,this._errorListener);return n.startsWith("export")||this._variables.box.add(a,l,c),c}_verfiyArgs(t,e){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:l,text_valign:c,text_wrap:h,text_font_family:p}=t,f="box.new";this._paramVerfiy(r,e,f,[Le.styleDashed,Le.styleDotted,Le.styleSolid],"border_style"),this._paramVerfiy(n,e,f,Object.values(Ur),"extend"),this._paramVerfiy(i,e,f,Object.values(we),"xloc"),this._paramVerfiy(a,e,f,Object.values(rr),"text_size"),this._paramVerfiy(l,e,f,[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"),this._paramVerfiy(c,e,f,[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"),this._paramVerfiy(h,e,f,[Wt.wrapAuto,Wt.wrapNone],"text_wrap"),this._paramVerfiy(p,e,f,Object.values(Zn),"text_font_family")}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}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},r){t==null||t.set_extend(e,r)}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},r){t==null||t.set_border_style(e,r)}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},r){t==null||t.set_text_size(e,r)}set_text_wrap({id:t,...e},r){t==null||t.set_text_wrap(e,r)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e},r){t==null||t.set_text_halign(e,r)}set_text_valign({id:t,...e},r){t==null||t.set_text_valign(e,r)}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},r){t==null||t.set_text_font_family(e,r)}}class co{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");this._variables=t,this._id=e,this._errorListener=r}get type(){return Fe.BOX}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get data(){return this._variables.box.get(this._id)}copy(t){const{bar_index:e}=this._variables,r=`box_${t}_${e}`,n=this._getBox(),i=new co(this._variables,r,this._errorListener);return n&&this._variables.box.add(r,{...n,id:r,bar_index:e},i),i}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},e){const r=this._getBox();r&&(r.extend=t,this._paramVerfiy(t,e,"box.set_extend",Object.values(Ur),"extend"))}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t,me(e,["bgcolor"]))}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t},e){const r=this._getBox();r&&(r.text_size=t,this._paramVerfiy(t,e,"box.set_text_size",Object.values(rr),"text_size"))}set_text_wrap({text_wrap:t},e){const r=this._getBox();r&&(r.text_wrap=t,this._paramVerfiy(t,e,"box.set_text_wrap",[Wt.wrapAuto,Wt.wrapNone],"text_wrap"))}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t,me(e,["text_color"]))}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t},e){const r=this._getBox();r&&(r.text_halign=t,this._paramVerfiy(t,e,"box.set_text_halign",[Wt.alignLeft,Wt.alignCenter,Wt.alignRight],"text_halign"))}set_text_valign({text_valign:t},e){const r=this._getBox();r&&(r.text_valign=t,this._paramVerfiy(t,e,"box.set_text_valign",[Wt.alignBottom,Wt.alignCenter,Wt.alignTop],"text_valign"))}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:i}=t||{};e.top=n,e.left=e.xloc===we.bar_index?r:i}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t,me(e,["border_color"]))}set_border_style({style:t},e){const r=this._getBox();r&&(r.border_style=t,this._paramVerfiy(t,e,"box.set_border_style",[Le.styleDashed,Le.styleDotted,Le.styleSolid],"style"))}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:i}=t||{};e.bottom=n,e.right=e.xloc===we.bar_index?r:i}}set_text_font_family({text_font_family:t},e){const r=this._getBox();r&&(r.text_font_family=t,this._paramVerfiy(t,e,"box.set_text_font_family",Object.values(Zn),"text_font_family"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_getBox(){return this._variables.box.get(this._id)}}class Jy{constructor(t,e){$(this,"_variables");$(this,"_errorListener");$(this,"_defaultTable",{position:_r.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t,this._errorListener=e}table({x:t}){return t}new(t,e){const{bar_index:r}=this._variables,n=`table_${e}_${r}`,{rows:i}=t;me(t,["text_color","bgcolor","border_color"]);const a=Array.from(Array(i),()=>[]),l=e.split("_"),c=l.pop(),h=l.pop(),p={...this._defaultTable,...t,cell:a,id:n,bar_index:r,line:h,col:c},f=new rh(this._variables,n,this._errorListener);return this._paramVerfiy(t.position,e,"table.new",Object.values(_r),"position"),e.startsWith("export")||this._variables.table.add(n,p,f),f}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}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},r){t==null||t.set_position(e,r)}}class rh{constructor(t,e,r){$(this,"_id");$(this,"_variables");$(this,"_errorListener");$(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ci.black,text_halign:Wt.alignCenter,text_valign:Wt.alignCenter,text_size:rr.normal});this._variables=t,this._id=e,this._errorListener=r}get type(){return Fe.TABLE}get id(){return this._id}updateId(){const t=this._id.split("_");return t.pop(),this._id=`${t.join("_")}_${this._variables.bar_index}`,this._id}get data(){return this._variables.table.get(this._id)}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],l=a[n]||[];l[r]=e,a[n]=l,i.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,me(n,["text_color"]))}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 i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let l=e;l<=n;l++)for(let c=t;c<=r;c++){const h=a[l];h&&(h[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},i){if(t>r||e>n){this._errorListener.addError(le.mergeCellErr,i,zt.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:t,start_row:e,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t,me(e,["bgcolor"]))}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t,me(e,["border_color"]))}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},e){const r=this._variables.table.get(this._id);r&&(r.position=t,this._paramVerfiy(t,e,"table.set_position",Object.values(_r),"position"))}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_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 Xy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){return this._verifyTradeNum(t)&&this._strategy.historyOrders[t].commission||0}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.historyOrders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].in_time}exit_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_index}exit_comment({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_comment:""}exit_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].out_id:""}exit_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_price}exit_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.historyOrders[t].out_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.historyOrders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{out_qty:e=0,direction:r}=this._strategy.historyOrders[t];return r===ue.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.historyOrders.length;return!(t>=e)}}class Qy{constructor(t){$(this,"_strategy");this._strategy=t}commission({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,original_qty:r=0,commission:n=0}=this._strategy.orders[t];return n*e/r}entry_bar_index({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_index}entry_comment({trade_num:t}){if(!this._verifyTradeNum(t))return"";const{comment:e,id:r}=this._strategy.orders[t];return e||r}entry_id({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].id:""}entry_price({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_price}entry_time({trade_num:t}){if(this._verifyTradeNum(t))return this._strategy.orders[t].in_time}max_drawdown({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss:0}max_drawdown_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].trading_loss_percent:0}max_runup({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit:0}max_runup_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].max_profit_percent:0}profit({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit:0}profit_percent({trade_num:t}){return this._verifyTradeNum(t)?this._strategy.orders[t].profit_percent:0}size({trade_num:t}){if(!this._verifyTradeNum(t))return 0;const{qty:e=0,direction:r}=this._strategy.orders[t];return r===ue.long?e:-e}_verifyTradeNum(t){if(typeof t!="number"||t<0)return!1;const e=this._strategy.orders.length;return!(t>=e)}}class tw{constructor(t,e){$(this,"_strategy");$(this,"_errorListener");this._strategy=t,this._errorListener=e}allow_entry_in({value:t},e){this._paramVerfiy(t,e,"strategy.risk.allow_entry_in",Object.values(ue),"value"),this._strategy.updateRisk({allow_entry_in:t})}max_cons_loss_days({count:t}){this._strategy.updateRisk({max_cons_loss_days:t})}max_drawdown({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_drawdown",[Re.percentOfEquity,Re.cash],"type"),e===Re.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_drawdown:t,max_drawdown_type:e})}max_intraday_filled_orders({count:t}){this._strategy.updateRisk({max_intraday_filled_orders:t})}max_intraday_loss({value:t,type:e},r){this._paramVerfiy(e,r,"strategy.risk.max_intraday_loss",[Re.percentOfEquity,Re.cash],"type"),e===Re.percentOfEquity&&(t=t>100?100:t),this._strategy.updateRisk({max_intraday_loss:t,max_intraday_loss_type:e})}max_position_size({contracts:t}){this._strategy.updateRisk({max_position_size:t})}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}}let ew=class{constructor(t,e,r,n,i){$(this,"_variables");$(this,"_options");$(this,"_totalChangeCapital");$(this,"_historyOrder");$(this,"_orders");$(this,"_pendingOrders");$(this,"_mintick");$(this,"_funcOptions");$(this,"_pendingCloseOrders");$(this,"_errorListener");$(this,"_risk");$(this,"_opentrades");$(this,"_closedtrades");$(this,"_riskNamespace");$(this,"_updateOptions",{});$(this,"_id");$(this,"_maxDrawdownVerifyIndex",0);this._variables=t,this._errorListener=n,this._options={overlay:!1,format:Kt.inherit,pyramiding:1,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Re.fixed,default_qty_value:1,initial_capital:1e6,currency:Xf.NONE,slippage:0,commission_type:nr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._pendingCloseOrders=[],this._mintick=r,this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),this._variables.strategy.updateStrategyOptions(this._options),this._risk={intradayOrders:0},this._opentrades=new Qy(this),this._closedtrades=new Xy(this),this._riskNamespace=new tw(this,n),this._id=`strategy_${i}`}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _freezeCapital(){const{close:t}=this._variables;return this._orders.reduce((e,r)=>e+t*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(t){this._updateOptions=t||{},Object.assign(this._options,this._updateOptions)}update(){this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),this._maxDrawdownVerify(),this._variables.strategy.update(),!this._options.process_orders_on_close&&this._calcLiquidate(),this._calcProfitAndLoss()}updateRisk(t){Object.assign(this._risk,t)}endExecution(){this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:t,max_intraday_loss_type:e,isDisabledOpen:r}=this._risk;if(t===void 0||!e||r)return;const{high:n,low:i,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:h}}=this._variables;let{preNetprofit:p=0}=this._risk;l===a&&(p=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=p-c;f+=this._orders.reduce((y,m)=>{const{in_price:w,direction:v,qty:x=0,commission:b=0,original_qty:N=0}=m,E=v===ue.long?1:-1,A=(n-w)*x,M=(i-w)*x,S=E===1?M:-A;return y+S+x/N*b},0);let d=!1;switch(e){case Re.cash:d=t<f;break;case Re.percentOfEquity:const y=f/(h+c)*100;d=t<y;break}if(d){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===ue.long?i:n,"Close Position (Max intraday Loss)",void 0,"close"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:t,intradayOrders:e=0,isDisabledOpen:r}=this._risk;if(t===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),t<=e&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)",void 0,"close"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:t,lossDays:e=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(t===void 0||r)return;const{time:i,time_tradingday:a,strategy:l,open:c}=this._variables;let h=e;if(i===a){const p=l.netprofit+l.openprofit;p<n?h=0:h++,Object.assign(this._risk,{lossDays:h,totalProfit:p})}t<=h&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){const{max_drawdown:t,max_drawdown_type:e,isDisabledOpen:r}=this._risk;if(r)return;const{bar_index:n,open:i}=this._variables;if(t!==void 0&&e&&this._maxDrawdownVerifyIndex===n){const{initial_capital:a}=this._options,c=this._orders.reduce((p,f)=>{const{in_price:d,commission:g=0,qty:y=0,original_qty:m=0,direction:w}=f,v=w===ue.long?1:-1,x=(i-d)*v*y;return p+x+g*y/m},0)+this._totalChangeCapital;let h=!1;switch(e){case Re.percentOfEquity:h=c/a*100<=-t;break;case Re.cash:h=c<=-t;break}h&&this._riskTouchOff(i,"Close Position (Max Drawdown)")}}_riskTouchOff(t,e){this._risk.isDisabledOpen=!0,this._orders.length&&this._closeOrders(this._orders,t,e,"close"),this._pendingOrders=[]}strategy(t,e){if(!this._variables.bar_index){this._paramVerfiy(t.format,e,"strategy",[Kt.inherit,Kt.price,Kt.percent,Kt.volume],"format"),this._paramVerfiy(t.default_qty_type,e,"strategy",Object.values(Re),"default_qty_type"),this._paramVerfiy(t.commission_type,e,"strategy",Object.values(nr),"commission_type");const r=self==null?void 0:self.workerStorage.get(this._id),n={...this._updateOptions};if(r)for(const i of Object.keys({...r,...t}))t[i]!==r[i]&&delete n[i];self==null||self.workerStorage.set(this._id,t),Object.assign(this._options,t,n),this._variables.updateMaxLength(t),Object.assign(this._funcOptions,{strategy:this._options,userSetStrategyConfig:n,scriptType:"strategy"})}}order(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.order",Object.values(un),"oca_type"),this._orderHandle(t))}entry(t,e){this._risk.isDisabledOpen||(this._paramVerfiy(t.oca_type,e,"strategy.entry",Object.values(un),"oca_type"),this._entryHandle(t))}close(t){if(!this._orders.filter(r=>!this._options.process_orders_on_close||r.in_index!==this._variables.bar_index).length)return;const{immediately:e}=t;if(e||this._options.process_orders_on_close){const r=this._pendingCloseOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingCloseOrders.push({...t,place_order_type:"close"})}else{const r=this._pendingOrders.find(n=>n.id===t.id&&n.place_order_type==="close");if(r){Object.assign(r,t);return}this._pendingOrders.push({...t,place_order_type:"close"})}}close_all(t){if(typeof t=="string"&&(t={}),!this._orders.length)return;const{immediately:e}=t;e||this._options.process_orders_on_close?this._pendingCloseOrders.push({...t,place_order_type:"close_all"}):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>!(e.id===t&&e.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(t=>t.place_order_type==="close_all")}exit(t,e){this._exit(t,e)}convert_to_account({value:t}){return t}convert_to_symbol({value:t}){return t}default_entry_qty({fill_price:t}){return t?this._calcDefaultQty(t):0}_calcDefaultQty(t){const{default_qty_type:e=Re.fixed,default_qty_value:r=1,initial_capital:n}=this._options;let i=r;switch(e){case Re.cash:i=r/t;break;case Re.percentOfEquity:const a=this._getOrderProfit(t);i=(n+a+this._totalChangeCapital)*r/100/t;break}return Tl(i,this._getLen(t))}_getLen(t){const e=String(Math.floor(t)).length-2;return e<0?0:e}_getCapital(t,e){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&t===1?e=e*100/r:n<=100&&n>0&&t===-1&&(e=e*100/n),e}_calcProfitAndLoss(){const{close:t}=this._variables;for(const e of this._orders){const{in_price:r,qty:n=0,direction:i}=e,a=i===ue.long?1:-1,l=(t-r)*a*n,[c,h]=this._calcProfitAndLossHandle(r,n,a);this._calcOrderPercent(e,l,c,h)}}_calcProfitAndLossHandle(t,e,r){const{high:n,low:i}=this._variables,a=(n-t)*e,l=(i-t)*e;let c=r===1?a:-l,h=r===1?l:-a;return[c,h]}_calcOrderPercent(t,e,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:h,max_profit:p=0,trading_loss:f=0}=t;let{commission:d=0}=t,g=h*c;if(i){const y=this._getCommission(a,c);d=d*c/l,r-=d,n-=d,g+=d,e=e-y-d}r=Math.max(r,p,0),n=Math.min(n,f,0),Object.assign(t,{profit:e,total_profit:this._totalChangeCapital+e,total_profit_percent:e/(this._options.initial_capital+this._totalChangeCapital)*100,max_profit:r,trading_loss:n,profit_percent:e/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:t,low:e,time:r}=this._variables,{initial_capital:n,margin_long:i=0,margin_short:a=0}=this._options,l=this._orders[0].direction===ue.long?1:-1;let c=l===1?e:t;if(l===1&&i===100)return;const h=(l===1?i:a)/100;if(h<=0)return;let p=!1;const[f,d]=this._orders.reduce((w,v)=>{let[x,b]=w;const{in_price:N,qty:E=0,in_time:A}=v;A===r&&(p=!0);const M=N*E,S=c*E;return x+=M,b+=S,[x,b]},[0,0]);let g=0,y=0;const m=n+this._totalChangeCapital;if(p&&(g=m-f*h,g<0&&(c=this._orders[0].in_price,y=Math.abs(Math.trunc(g/h/c)*4),y=Math.max(y,1))),g>=0){const w=l*(d-f);if(g=m+w-d*h,g>=0)return;y=Math.abs(Math.trunc(g/h/c)*4)}y<=0||this._marginCallOrders(c,y,"Margin Call")}_marginCallOrders(t,e,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,t,e*this._orders.length,r,r,!0);return}for(const i of this.orders)i.position_close_type=i.place_order_type,this._processOrder(i,t,e,r,r,!0);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:l,price:c,activePrice:h}=this._orderArgsParse(t),p=t.direction===ue.long?1:-1;if(a<=0)return;let f=a;if(i&&e){if(n.length){const b=this._processOrders(n,l,f,t.id,t.comment,!1,"order");if(b<=0)return;f=b}const g=l+p*r*this._mintick;if(!this._judgeCapitalEnough(f,g,p))return;this._ocaGroupVerify(f,t.oca_name,t.oca_type);const{bar_index:m,time:w,high:v,low:x}=this._variables;this._calcCurrentOrder({...t,in_price:g,in_high:v,in_low:x,in_index:m,in_time:w,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,p)&&this._addPendingOrders(t,c,f,i,h)}_judgeCapitalEnough(t,e,r){let n=this._freezeCapital;if(this._orders.some(p=>(p.direction===ue.long?1:-1)!==r)&&(n=0),t<=0)return!1;const{margin_long:i=0,margin_short:a=0}=this._options;if(i===0&&r===1||a===0&&r===-1)return!0;const l=this._getOrderProfit(e),h=this._getCapital(r,this._options.initial_capital+l+this._totalChangeCapital)-n;return t*e<=h}_getOrderProfit(t){return this._orders.reduce((e,r)=>{const{in_price:n,qty:i=0,direction:a}=r,l=a===ue.long?1:-1;return e+(t-n)*i*l},0)}_ocaGroupVerify(t,e,r){if(!e||!r||r===un.none)return!1;let n=!1;switch(r){case un.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===e)i.isCancel=!0,n=!0;else return!0});break;case un.reduce:this._pendingOrders=this._pendingOrders.filter(i=>{const{qty:a=0,oca_name:l}=i;if(e===l){const c=a-t;return n=!0,c<=0?(i.isCancel=!0,!1):(i.qty=c,!0)}else return!0});break}return n}_processOrders(t,e,r,n,i,a=!1,l){let c=r;for(const h of t)if(h.position_close_type=l||h.place_order_type,c=this._processOrder(h,e,c,n,i,a),c<=0)break;return this._orders=this._orders.filter(h=>!h.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),c}_addPendingOrders(t,e,r,n,i){const a=this._pendingOrders.find(l=>l.id===t.id&&!l.isMarketPrice);if(a)Object.assign(a,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else{const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let i=t.limit||0;const{close:a}=this._variables;let l=a,c=!1,h;const p=e===ue.long?1:-1,f=n&&(n-a)*p>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&i&&(i-=d*this._mintick*p);const g=i&&(i-a)*p<0;f&&g?(h=n,l=i):f?l=n:g?l=i:c=!0;const y=r!==void 0?Tl(r,this._getLen(l)):this._calcDefaultQty(l);return{orders:this._orders.filter(w=>w.direction!==e),isMarketPrice:c,activePrice:h,quantities:y,close:a,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:l,activePrice:c}=this._orderArgsParse(t);if(i<=0)return;if(r.length&&n&&e){this._entryOrder(r,a,i,t);return}this._judgeCapitalEnough(i,a,t.direction===ue.long?1:-1)&&this._addPendingEntry(t,l,i,n,c)}_entryOrder(t,e,r,n){const{time:i,bar_index:a,high:l,low:c}=this._variables,{slippage:h=0}=this._options,{oca_name:p,oca_type:f,direction:d,comment:g,isMarketPrice:y,id:m}=n,w=d===ue.long?1:-1;if(r=this._getAvailablePositionSize(r,d),r<=0||(e=e+h*this._mintick*w,!this._judgeCapitalEnough(r,e,w)))return;this._closeOrders(t,e,m,g,"entry");const x={...n,in_price:e,qty:r,in_index:a,in_high:l,in_low:c,in_time:i,place_order_type:"entry"};if(y){this._calcCurrentOrder(x);return}const{pendingOrders:b,orders:N}=this._getEntryOrders(d),E=b.length+N.length;E&&E>=(this._options.pyramiding||1)||(this._ocaGroupVerify(r,p,f),this._calcCurrentOrder(x))}_getAvailablePositionSize(t,e){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==ue.all&&n!==e)return 0;if(r===void 0)return t;const i=this._orders.reduce((a,l)=>a+(l.qty||0),0);return i?i+t>r?0:t:t>r?t-r:0}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===t),r=this._orders.filter(n=>n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,i){if(r=this._getAvailablePositionSize(r,t.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(t.direction),c=a.length+l.length,h=a.find(p=>p.id===t.id&&p.place_order_type==="entry");if(h)Object.assign(h,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:i});else if(!c||c<(this._options.pyramiding||1)){const p={...t,in_price:e,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(p)}}_closeAllOrders(t,e){const{comment:r}=t,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,e,"Close position order",r,"close"),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(t,e,r,n,i){for(const a of t)a.position_close_type=i,this._closeOrder(a,e,r,n);this._orders=this._orders.filter(a=>!a.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_closeOrder(t,e,r,n){const{time:i,bar_index:a,high:l,low:c}=this._variables,{slippage:h=0}=this._options,{in_price:p,qty:f=0,direction:d}=t,g=d===ue.long?1:-1;e=e-g*h*this._mintick,t.isDeal=!0;const y=(e-p)*g*f,m={...t,out_price:e,out_id:r,out_index:a,out_high:l,out_low:c,out_time:i,out_comment:n,out_qty:f,profit:y};this._calcPercent(m)}_ordersHandle(){const t=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!t.length)return;const{open:e,low:r,high:n,close:i}=this._variables;for(const a of t){const{stop:l,limit:c,trail_stop_price:h,isMarketPriceLimit:p,isMarketPriceStop:f,direction:d,id:g,out_comment:y,active_price:m,trail_offset:w=0,out_qty:v,comment_loss:x,comment_profit:b,comment_trailing:N}=a;let E=h;const A=d===ue.long?1:-1;let M,S=y;if(p||f?M=e:(c&&r<=c&&n>=c&&(S=b||y,M=c),l&&r<=l&&n>=l&&(M=E?(l-E)*A>0?l:E:l,S=(E===M?N:x)||y)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let T=!1;if(m&&m<=n&&m>=r&&(E=m-w*A*this._mintick,(E-i)*A>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=E)),T=!0,a.trail_stop_price=E),E)if((E-e)*A>=0&&!T)M=E;else{const F=(A===1?n:r)-w*A*this._mintick;A===1?E<e&&E>=r&&F>E&&F<i?M=E:F>E?(E=F,F>=i&&(M=F)):E<=n&&r<=E&&(M=E):E>e&&E<=n&&F<E&&F>i?M=E:F<E?(E=F,F<=i&&(M=F)):E<=n&&r<=E&&(M=E),a.trail_stop_price=E}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||y,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[],e=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of this._pendingOrders){const{isCancel:i,place_order_type:a}=n;if(i)continue;let l;switch(a){case"entry":l=this._entryOrderHandle(n);break;case"order":l=this._orderOrderHandle(n);break}l&&t.push(l)}for(const n of r)switch(n.place_order_type){case"close":const i=this._closeOrderHandle(n);i&&t.push(i);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of e){const i=this._exitOrderHandle(n);i&&t.push(i)}this._pendingOrders=t}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const t=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),e=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;this._pendingCloseOrders=[];for(const n of e)switch(n.place_order_type){case"close":const i=this._closeOrderHandle(n,!0);i&&this._pendingCloseOrders.push(i);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of t){const{from_entry:i}=n,a=this._orders.filter(l=>!i||l.id===i&&(l.isMarketPriceLimit||l.isMarketPriceStop));for(const l of a)this._processExitOnClose(l,l.limit||l.stop||l.trail_stop_price||r,n)}}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:l,direction:c,active_price:h}=t;if(h&&n>=h&&r<=h)return delete t.active_price,t;let p=l;if(i&&(p=e),p<=n&&p>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,p,a,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:h=0,in_price:p,direction:f,comment:d,oca_name:g,oca_type:y,active_price:m,id:w}=t;if(m&&n>=m&&r<=m)return delete t.active_price,t;let v=p,x=h;if(c&&(v=e),v<=n&&v>=r){const b=this._orders.filter(E=>E.direction!==f);if(b.length&&(x=this._processOrders(b,v,h,w,d,!1,"order"),x<=0))return;const N=f===ue.long?1:-1;this._ocaGroupVerify(x,g,y),this._calcCurrentOrder({...t,in_price:v+N*l*this._mintick,in_index:a,in_time:i,in_high:n,in_low:r,qty:x});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:i=100,comment:a}=t,{close_entries_rule:l="FIFO"}=this._options;let c=[];if(l==="FIFO"?c=this._orders.filter(d=>d.id===r):c=this._orders.filter(d=>d.id===r&&!d.close_qty),!c.length)return t;let h=0;if(n?h=n:(h=c.reduce((d,g)=>d+(g.qty||0),h),h=i/100*h),h<=0)return;const{open:p,close:f}=this._variables;if(l==="FIFO")this._processOrders(c,e?f:p,h,`Close entry(s) order ${r}`,a,!1,"close");else if(this._processCloseOrders(c,e?f:p,h,`Close entry(s) order ${r}`,a))return t}_processCloseOrders(t,e,r,n,i){let a=!1;for(const l of t)l.close_qty=r,(l.qty||0)>r&&(a=!0),l.position_close_type="close",this._processOrder(l,e,r,n,i);return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),a}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,t)))return t}_exit(t,e){const{profit:r,loss:n,stop:i,limit:a,trail_offset:l,trail_price:c,trail_points:h,from_entry:p="",id:f}=t;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(h)&&this._isNaN(c))){this._errorListener.addError(le.strategyExitErr,e,zt.Error);return}const d={...t,place_order_type:"exit"},g=this._orders.filter(w=>(!p||p===w.id)&&!w.hasExit),y=this._pendingOrders.filter(w=>!p||p===w.id);if(g.length){if(!this._ordersToExit(g,d))return}else if(!y.length)return;const m=this._pendingOrders.find(w=>w.id===f&&w.place_order_type==="exit");m?Object.assign(m,{...t}):this._pendingOrders.push(d)}_ordersToExit(t,e){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:l,comment_profit:c,comment_trailing:h}=e;let p=r,f=!1;e.comment=a||i;for(const d of t){const{qty:g=0}=d,y=d.direction===ue.long?1:-1;p=r?r>=g?g:r:n/100*g,d.out_qty=p,p<g&&(f=!0),Object.assign(d,{out_comment:a||i,comment_loss:l,comment_profit:c,comment_trailing:h}),!(this._stopProfit(d,y,{...e,qty:p})||this._stopLoss(d,y,{...e,qty:p})||this._trailStopLoss(d,y,{...e,qty:p}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(t){t.place_order_type="exit";const e=this._pendingCloseOrders.find(r=>r.id===t.id);e?Object.assign(e,{...t}):this._pendingCloseOrders.push(t)}_stopProfit(t,e,r){const{limit:n,profit:i,comment_profit:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=p+e*i*this._mintick),t.limit=c,c!==void 0&&(c-h)*e<=0&&(t.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,t.limit=c,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(t,e,r){const{stop:n,loss:i,comment_loss:a,comment:l}=r;let c=n;const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=p-e*i*this._mintick),t.stop=c,c!==void 0&&(c-h)*e>=0&&(t.isMarketPriceStop=!0,r.comment=a||l,Object.assign(t,{out_comment:r.comment}),c=h,t.stop=c,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:h}=this._variables,{in_price:p}=t,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(i)?this._isNaN(a)||(d=p+a*e*this._mintick):d=i,t.trail_offset=n,d!==void 0&&(d-h)*e<=0){const g=h-n*e*this._mintick;if((g-h)*e>=0&&(t.trail_stop_price=h,t.isMarketPriceStop=!0,r.comment=l||c,Object.assign(t,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;t.trail_stop_price=g}t.active_price=d}}_processExitOnClose(t,e,r){const{qty:n=0,comment:i,id:a}=r,{close_entries_rule:l="FIFO"}=this._options;if(l==="FIFO"){const c=this._processExitOrders(this._orders,e,n,a,i);c&&!c.hasExit?(c.hasExit=!0,Object.assign(t,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,a,i,!1,"exit")}_processExitOrders(t,e,r,n,i){let a=r,l;for(const c of t)if(l=c,c.position_close_type="exit",a=this._processOrder(c,e,a,n,i),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),this._variables.strategy.updateHistoryOrders(this._historyOrder),l}_processOrder(t,e,r,n,i,a=!1){const{time:l,bar_index:c,high:h,low:p}=this._variables,{slippage:f=0}=this._options,{in_price:d,qty:g=0,max_profit:y,trading_loss:m,direction:w,commission:v=0,original_qty:x=0}=t,b=w===ue.long?1:-1;if(e=e-b*f*this._mintick,r<g){const N=g-r,E=(e-d)*b*r,A=y!==void 0?y/g*r:void 0,M=m!==void 0?m/g*r:void 0,S=v*N/x;this._calcPercent({...t,out_price:e,last_commission:S,out_id:n,out_index:c,out_high:h,out_low:p,out_time:l,out_comment:i,profit:E,out_qty:r,max_profit:A,trading_loss:M});const T=(e-d)*b*N-S;Object.assign(t,{qty:N,profit:T,max_profit:y!==void 0?y-(A||0):void 0,trading_loss:m!==void 0?m-(M||0):void 0,total_profit:this._totalChangeCapital+T}),r=0}else{t.isDeal=!0;const N=(e-d)*b*g;this._calcPercent({...t,out_price:e,out_id:n,out_index:c,out_high:h,out_low:p,out_time:l,out_comment:i,out_qty:g,profit:N}),r-=g}return a&&(b===1?this._variables.strategy.marginCallLong++:this._variables.strategy.marginCallShort++),r}_calcPercent(t){const{commission_value:e,process_orders_on_close:r}=this._options,{in_price:n,out_qty:i=0,out_price:a=0,original_qty:l=0,direction:c,last_commission:h=0}=t;let{profit:p=0,max_profit:f,trading_loss:d,commission:g=0}=t,y=n*i,m=this._totalChangeCapital+this._options.initial_capital;if(this._totalChangeCapital+=p,e){const w=this._getCommission(a,i);this._totalChangeCapital-=w;let v=g*i/l;y+=v,v+=w,p=p-v,Object.assign(t,{commission:v,profit:p});const x=this._orders.reduce((b,N)=>{const{qty:E=0,original_qty:A=0,commission:M=0}=N;return b+M*E/A},0);m+=x-h}if(f===void 0||d===void 0){const w=c===ue.long?1:-1,v=this._calcProfitAndLossHandle(n,i,w);if(f=v[0],d=v[1],e){const x=g*i/l;f-=x,d-=x}f=Math.max(0,f),d=Math.min(0,d)}Object.assign(t,{max_profit:f,trading_loss:d,total_profit:this._totalChangeCapital,total_profit_percent:p/m*100,profit_percent:p/y*100,max_profit_percent:f/y*100,trading_loss_percent:d/y*100}),this._maxDrawdownVerifyIndex=this._variables.bar_index+(r?1:0),this._risk.intradayOrders+=1,this._historyOrder.push(t)}_getCommission(t,e){const{commission_value:r=0,commission_type:n}=this._options,i=t*e;let a=0;switch(n){case nr.percent:a=i*r/100;break;case nr.cashPerContract:a=e*r;break;case nr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(t){const{commission_value:e}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=t;let{profit:l=0}=t,c=r*n;const h=this._totalChangeCapital+this._options.initial_capital;if(e){const p=this._getCommission(r,n);this._totalChangeCapital-=p,l=l-p,c+=p,Object.assign(t,{commission:p,profit:l,total_profit:this._totalChangeCapital})}Object.assign(t,{original_qty:n,total_profit_percent:l/h*100,profit_percent:l/c*100,max_profit_percent:i/c*100,trading_loss_percent:a/c*100}),this._risk.intradayOrders+=1,this._orders.push(t),this._variables.strategy.updateOrders(this._orders),e&&this._variables.strategy.updateHistoryOrders(this._historyOrder)}_isNaN(t){return t===void 0||isNaN(t)}_paramVerfiy(t="",e,r,n,i){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}};var nh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){return function(e,r,n){r.prototype.isBetween=function(i,a,l,c){var h=n(i),p=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(h,l):!this.isBefore(h,l))&&(d?this.isBefore(p,l):!this.isAfter(p,l))||(f?this.isBefore(h,l):!this.isAfter(h,l))&&(d?this.isAfter(p,l):!this.isBefore(p,l))}}})})(nh);var rw=nh.exports,nw=Gt(rw),ih={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){return function(e,r,n){var i=r.prototype,a=function(d){var g,y=d.date,m=d.utc,w={};if(!((g=y)===null||g instanceof Date||g instanceof Array||i.$utils().u(g)||g.constructor.name!=="Object")){if(!Object.keys(y).length)return new Date;var v=m?n.utc():n();Object.keys(y).forEach(function(T){var F,O;w[F=T,O=i.$utils().p(F),O==="date"?"day":O]=y[T]});var x=w.day||(w.year||w.month>=0?1:v.date()),b=w.year||v.year(),N=w.month>=0?w.month:w.year||w.day?0:v.month(),E=w.hour||0,A=w.minute||0,M=w.second||0,S=w.millisecond||0;return m?new Date(Date.UTC(b,N,x,E,A,M,S)):new Date(b,N,x,E,A,M,S)}return y},l=i.parse;i.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=i.set,h=i.add,p=i.subtract,f=function(d,g,y,m){m===void 0&&(m=1);var w=Object.keys(g),v=this;return w.forEach(function(x){v=d.bind(v)(g[x]*m,x)}),v};i.set=function(d,g){return g=g===void 0?d:g,d.constructor.name==="Object"?f.bind(this)(function(y,m){return c.bind(this)(m,y)},g,d):c.bind(this)(d,g)},i.add=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g):h.bind(this)(d,g)},i.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(h,d,g,-1):p.bind(this)(d,g)}}})})(ih);var iw=ih.exports,sw=Gt(iw),sh={exports:{}};(function(s,t){(function(e,r){s.exports=r()})(Yt,function(){var e,r,n=1e3,i=6e4,a=36e5,l=864e5,c=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,h=31536e6,p=2628e6,f=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,d={years:h,months:p,days:l,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},g=function(A){return A instanceof N},y=function(A,M,S){return new N(A,S,M.$l)},m=function(A){return r.p(A)+"s"},w=function(A){return A<0},v=function(A){return w(A)?Math.ceil(A):Math.floor(A)},x=function(A){return Math.abs(A)},b=function(A,M){return A?w(A)?{negative:!0,format:""+x(A)+M}:{negative:!1,format:""+A+M}:{negative:!1,format:""}},N=function(){function A(S,T,F){var O=this;if(this.$d={},this.$l=F,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),T)return y(S*d[m(T)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){O.$d[m(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var R=S.match(f);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=A.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(T,F){return T+(S.$d[F]||0)*d[F]},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/i),S%=i,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),T=b(this.$d.months,"M"),F=+this.$d.days||0;this.$d.weeks&&(F+=7*this.$d.weeks);var O=b(F,"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 W=b(q,"S"),z=S.negative||T.negative||O.negative||R.negative||U.negative||W.negative,K=R.format||U.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+T.format+O.format+K+R.format+U.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},M.toJSON=function(){return this.toISOString()},M.format=function(S){var T=S||"YYYY-MM-DDTHH:mm:ss",F={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 T.replace(c,function(O,R){return R||String(F[O])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var T=this.$ms,F=m(S);return F==="milliseconds"?T%=1e3:T=F==="weeks"?v(T/d[F]):this.$d[F],T||0},M.add=function(S,T,F){var O;return O=T?S*d[m(T)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+O*(F?-1:1),this)},M.subtract=function(S,T){return this.add(S,T,!0)},M.locale=function(S){var T=this.clone();return T.$l=S,T},M.clone=function(){return y(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")},A}(),E=function(A,M,S){return A.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(A,M,S){e=S,r=S().$utils(),S.duration=function(O,R){var U=S.locale();return y(O,{$l:U},R)},S.isDuration=g;var T=M.prototype.add,F=M.prototype.subtract;M.prototype.add=function(O,R){return g(O)?E(this,O,1):T.bind(this)(O,R)},M.prototype.subtract=function(O,R){return g(O)?E(this,O,-1):F.bind(this)(O,R)}}})})(sh);var ow=sh.exports,aw=Gt(ow);ee.extend(Sl),ee.extend(nw),ee.extend(sw),ee.extend(aw);class oh{constructor(t,e,r){$(this,"array");$(this,"color");$(this,"math");$(this,"str");$(this,"map");$(this,"matrix");$(this,"timeframe");$(this,"ta");$(this,"input");$(this,"_variables");$(this,"_cacheData");$(this,"_options");$(this,"_errorListener");$(this,"_plots");$(this,"_plotshapes");$(this,"_plotbars");$(this,"_plotchars");$(this,"_plotarrows");$(this,"_plotcandles");$(this,"_alerts");$(this,"_bgColors");$(this,"_hlines");$(this,"_fills");$(this,"chart");$(this,"line");$(this,"label");$(this,"polyline");$(this,"box");$(this,"table");$(this,"linefill");$(this,"log");$(this,"runtime");$(this,"strategy");$(this,"request");$(this,"syminfo");$(this,"_count",0);var i;const n=((i=t.toString().split(".")[1])==null?void 0:i.length)||5;this._variables=e,this._errorListener=new hw,this.array=new Hp(this._errorListener),this.math=new Jp(n,this._errorListener),this.color=new b1,this.str=new xy(this._errorListener,n),this.map=new Ey(this._errorListener),this.timeframe=new by(e),this.matrix=new Dy(this._errorListener),this.ta=new w1(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new D1(e,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new Ay(e)},this.line=new Ky(e,this._errorListener),this.label=new Cy(e,this._errorListener),this.polyline=new Zy(e,this._errorListener),this.box=new Hy(e,this._errorListener),this.table=new Jy(e,this._errorListener),this.linefill=new Gy(e),this.log=new cw(e),this.runtime=new fw(this._errorListener),this.strategy=new ew(this._variables,this._options,t,this._errorListener,r),this.request=new uw(this._variables,r),this.syminfo=new lw}get errors(){return this._errorListener.errors}options(t){if(t.length)return this._getDataOfBarindex(t);const e=this.input.getInputs(),r=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const n=Object.keys(this._bgColors);let i;if(n.length){i={};for(const v of n)i[v]=[...this._bgColors[v].values()]}const a=this._hlines.size?[...this._hlines.values()]:void 0,l=this._fills.size?[...this._fills.values()]:void 0,c=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders,strategySummary:this._variables.strategy.summaryData});const h=this._plots.size>0?[...this._plots.values()]:void 0,p=this._plotbars.size>0?[...this._plotbars.values()]:void 0,f=this._plotshapes.size>0?[...this._plotshapes.values()]:void 0,d=this._plotarrows.size>0?[...this._plotarrows.values()]:void 0,g=this._plotcandles.size>0?[...this._plotcandles.values()]:void 0,y=this._plotchars.size>0?[...this._plotchars.values()]:void 0,m=this._getDraws(),w=this._variables.chart.isUseBgColor;return Object.assign(this._options,{inputs:e,plots:h,draws:m,alerts:r,colors:i,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:d,plotcandles:g,plotchars:y,plotbars:p,isUseBgColor:w})}_getDataOfBarindex(t){const e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors);let n;if(r.length){n={};for(const d of r)n[d]=[...this._bgColors[d].values()].map(g=>{const y=[];for(const m of t){const w=g.colors[m];w&&y.push(w)}return g.colors=y,g})}const i=this._hlines.size?[...this._hlines.values()]:void 0,a=this._fills.size?this._getDataFromBarindex(t,[...this._fills.values()]):void 0,l=this.log.logs.length?this.log.logs:void 0;this.log.clearLogs(),this._options.scriptType==="strategy"&&Object.assign(this._options,{orders:this.strategy.orders,historyOrders:this.strategy.historyOrders});const c=this._getDataFromBarindex(t,[...this._plots.values()]),h=this._plotshapes.size>0?this._getDataFromBarindex(t,[...this._plotshapes.values()]):void 0,p=this._getDrawsFromBarindex(t),f=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,draws:p,alerts:e,colors:n,hlines:i,fills:a,logs:l,plotshapes:h,isUseBgColor:f})}_getDataFromBarindex(t,e){return e.map(r=>{const n=[];for(const i of t){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:i,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),i.data.length&&(l.polylines=i.data),a.data.length&&(l.labels=a.data),Object.keys(l).length?l:void 0}_getDrawsFromBarindex(t){const{line:e,linefill:r,table:n,box:i,polyline:a,label:l}=this._variables,c={};return e.data.length&&(c.lines=e.getValOfBarIndex(t)),r.data.length&&(c.linefills=r.getValOfBarIndex(t)),n.data.length&&(c.tables=n.getValOfBarIndex(t)),i.data.length&&(c.boxes=i.getValOfBarIndex(t)),a.data.length&&(c.polylines=a.getValOfBarIndex(t)),l.data.length&&(c.labels=l.getValOfBarIndex(t)),Object.keys(c).length?c:void 0}updateOptions(t){const{inputs:e,strategy:r}=t;this.input.update(e),r&&this.strategy.updateOptions(r)}update(t){const{barIndex:e}=t;this.strategy.update(),this.math.update(e)}endExecution(){this.strategy.endExecution()}library(t,e){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=t;r.test(n)?(Gp.includes(n)||Kp.includes(n))&&this._errorListener.addError(Ve(le.libraryTitleIsKeywordErr,{name:n}),e,zt.Error):this._errorListener.addError(le.libraryTitleErr,e,zt.Error),this._options.scriptType="library",this._options.library=t}}indicator(t,e){if(!this._variables.bar_index){const{format:r}=t;this._paramVerfiy(r,e,"indicator",[Kt.inherit,Kt.percent,Kt.price,Kt.volume]),this._variables.updateMaxLength(t),this._options.scriptType="indicator",this._options.indicator=t}}_paramVerfiy(t="",e,r,n,i="format"){t&&!n.includes(t)&&this._errorListener.addError(Ve(le.paramsErr,{value:t,func:r,param:i,targetVal:`[${n.join(", ")}]`}),e,zt.Error)}_lineWidthVerify(t,e){const{linewidth:r=1}=t;r<1&&(this._errorListener.addError(Yp.lineWidthWarning,e,zt.Warning),t.linewidth=1)}plot(t,e){const r=["color"];me(t,r);const{series:n,color:i,...a}=t,{bar_index:l,time:c}=this._variables,h=`plot_${e}`,p=this._plots.get(h),f=(p==null?void 0:p.data)||[],d=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,d],itemStyle:{color:i}},this._seriesColorHandle(t,r,p),!p){this._count++,this._lineWidthVerify(a,e),this._paramVerfiy(t.format,e,"plot",[Kt.percent,Kt.price,Kt.volume]);const g=i?[i]:void 0;this._plots.set(h,{editable:!0,...a,colors:g,data:f,id:h,zIndex:this._count})}return{type:"plot",key:h}}plotbar(t,e){const r=["color"];me(t,r);const{open:n,close:i,low:a,high:l,color:c,...h}=t,{bar_index:p,time:f}=this._variables,d=`plotbar_${e}`,g=this._plotbars.get(d),y=(g==null?void 0:g.data)||[],m=i!==void 0&&isNaN(i)?void 0:i,w=n!==void 0&&isNaN(n)?void 0:n,v=a!==void 0&&isNaN(a)?void 0:a,x=l!==void 0&&isNaN(l)?void 0:l,b=[f,w,m,v,x];if(y[p]={value:b,itemStyle:{color:c}},this._seriesColorHandle(t,r,g),!g){this._count++,this._paramVerfiy(t.format,e,"plotbar",[Kt.percent,Kt.price,Kt.volume]);const N=c?[c]:void 0;this._plotbars.set(d,{editable:!0,...h,colors:N,data:y,id:d,zIndex:this._count})}}_verfiyArgs(t,e,r){const{size:n,format:i,location:a,style:l}=t;this._paramVerfiy(l,r,e,Object.values(ur),"style"),this._paramVerfiy(a,r,e,Object.values(an),"location"),this._paramVerfiy(n,r,e,Object.values(rr),"size"),this._paramVerfiy(i,r,e,[Kt.percent,Kt.price,Kt.volume],"format")}plotchar(t,e){const r=["color","textcolor"];me(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:h,time:p,high:f,low:d}=this._variables,g=`plotchar_${e}`,y=this._plotchars.get(g),m=(y==null?void 0:y.data)||[],w={value:[p,n],itemStyle:{color:i,textcolor:a},low:d,high:f};m[h]=w,this._seriesColorHandle(t,r,y),y||(this._count++,this._verfiyArgs(t,"plotchar",e),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(t,e){const r=["colorup","colordown"];me(t,r);const{series:n,colorup:i,colordown:a,...l}=t,{bar_index:c,time:h}=this._variables,p=`plotarrow_${e}`,f=this._plotarrows.get(p),d=(f==null?void 0:f.data)||[];d[c]={value:[h,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:i,colordown:a}},this._seriesColorHandle(t,r,f),f||(this._count++,this._paramVerfiy(t.format,e,"plotarrow",[Kt.percent,Kt.price,Kt.volume]),this._plotarrows.set(p,{editable:!0,...l,data:d,id:p,zIndex:this._count}))}plotshape(t,e){const r=["color","textcolor"];me(t,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=t,{bar_index:h,time:p,low:f,high:d}=this._variables,g=`plotshape_${e}`,y=this._plotshapes.get(g),m=(y==null?void 0:y.data)||[],w={value:n,color:i,textcolor:a,time:p,low:f,high:d};if(m[h]=w,this._seriesColorHandle(t,r,y),!y){this._count++;const v=i?[i]:void 0;this._verfiyArgs(t,"plotshape",e),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(t,e){const r=["wickcolor","bordercolor","color"];me(t,r);const{wickcolor:n,bordercolor:i,color:a,close:l,open:c,low:h,high:p,...f}=t,{bar_index:d,time:g}=this._variables,y=`plotcandle_${e}`,m=this._plotcandles.get(y),w=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,x=c!==void 0&&isNaN(c)?void 0:c,b=h!==void 0&&isNaN(h)?void 0:h,N=p!==void 0&&isNaN(p)?void 0:p,E=[g,x,v,b,N];w[d]={value:E,wickcolor:n,bordercolor:i,color:a},this._seriesColorHandle(t,r,m),m||(this._count++,this._paramVerfiy(t.format,e,"plotcandle",[Kt.percent,Kt.price,Kt.volume]),this._plotcandles.set(y,{editable:!0,...f,data:w,id:y,zIndex:this._count}))}hline(t,e){const r=`hline_${e}`;me(t,["color"]),this._verifyDisplay(t.display,"hline",e);const i=t.display&&!t.display.length?Ye.none:Ye.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(t,e),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:i,...t,zIndex:this._count})),{type:"hline",key:r}}fill(t,e){var S,T,F,O,R,U,q,W,z,K;const r=["color","top_color","bottom_color"];me(t,r);const{color:n,top_color:i,bottom_color:a,seriesColors:l,hline1:c,hline2:h,plot1:p,plot2:f,top_value:d,bottom_value:g,...y}=t,{bar_index:m,time:w}=this._variables,v=`fill_${e}`,x=this._fills.get(v),b=(x==null?void 0:x.data)||[];this._verifyDisplay(t.display,"fill",e);const N=t.display&&!t.display.length?Ye.none:Ye.all;let E,A,M="plot";if(c&&h)E=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,A=(T=this._hlines.get(h==null?void 0:h.key))==null?void 0:T.price,M="hline";else{const Z=((F=this._plots.get(p==null?void 0:p.key))==null?void 0:F.data)||[],X=((O=this._plots.get(f==null?void 0:f.key))==null?void 0:O.data)||[];E=(U=(R=Z[m])==null?void 0:R.value)==null?void 0:U[1],A=(W=(q=X[m])==null?void 0:q.value)==null?void 0:W[1]}if(b[m]={time:w,color:n,top_color:i,bottom_color:a,plot1:E,plot2:A,top_value:d,bottom_value:g},this._seriesColorHandle(t,r,x),!x){this._count++;const Z=((z=this._options.indicator)==null?void 0:z.explicit_plot_zorder)||((K=this._options.strategy)==null?void 0:K.explicit_plot_zorder),X=n?[n]:void 0,Q=i?[i]:void 0,ct=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ct,display:N,data:b,type:M,editable:!0,fillgaps:!1,hline1:c,hline2:h,plot1:p,plot2:f,...y,zIndex:Z?this._count:void 0})}}alert({message:t,freq:e=qr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},h=c.barIndex;if(this._paramVerfiy(e,r,"alert",[qr.freqAll,qr.freqOncePerBar,qr.freqOncePerBarClose]),e===qr.freqOncePerBar&&n===h){this._alerts.delete(l);return}this._cacheData[l]=c;const p={message:t,freq:e,id:l,type:"alert"};if(i){e!==qr.freqOncePerBarClose&&this._alerts.set(l,p),c.barIndex=n;return}if(!i&&e===qr.freqOncePerBarClose&&n===h&&a===n-1){this._alerts.set(l,p),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&t?this._alerts.set(a,{message:e,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(t,e){this._setColors(t,"barcolor",e)}bgcolor(t,e){this._setColors(t,"bgcolor",e)}_verifyDisplay(t=Qf.all,e,r){t.length&&t.length<4&&this._errorListener.addError(Ve(le.displayErr,{func:e,values:"[display.none, display.all]"}),r,zt.Error)}_setColors(t,e,r){me(t,["color"]);const{color:i,...a}=t;this._verifyDisplay(a.display,e,r);const l=t.display&&!t.display.length?Ye.none:Ye.all,{bar_index:c,time:h}=this._variables,p=`${e}_${r}`;this._bgColors[e]||(this._bgColors[e]=new Map);const f=this._bgColors[e].get(p),d=(f==null?void 0:f.colors)||[],g=(f==null?void 0:f.setColors)||[];i&&!g.includes(i)&&g.push(i),d[c]={color:i,time:h},f||this._bgColors[e].set(p,{...a,display:l,colors:d,setColors:g,id:p})}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||typeof t=="number"&&isNaN(t))}fixnan({source:t},e){return t===void 0||typeof t=="number"&&isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!(typeof t=="number"&&isNaN(t))?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,t,e,r,n)}timestamp(t){const{dateString:e,timezone:r,year:n,month:i,day:a,hour:l=0,minute:c=0,second:h=0}=t;if(e)return ee(e).utc(!/GMT|UTC/.test(e)).valueOf();let p=i-1,f=n;if(p<0){const g=Math.ceil(Math.abs(p/12));p=12*g+p,f=n-g}let d=ee({year:f,month:p,day:a,hour:l,minute:c,second:h});return r&&(d=kr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:t,timezone:e}){return kr(t,e).week()}year({time:t,timezone:e}){return kr(t,e).year()}second({time:t,timezone:e}){return kr(t,e).second()}month({time:t,timezone:e}){return kr(t,e).month()+1}minute({time:t,timezone:e}){return kr(t,e).minute()}hour({time:t,timezone:e}){return kr(t,e).hour()}dayofweek({time:t,timezone:e}){return kr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return kr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Qr(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,i,a=0){const l=r||this._variables.timeframe.period,c=Qr(l),h=Qr(this._variables.timeframe.period);let p;if(c<=h)p=t;else{const f=`time_${e}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=t?(p=t,this._cacheData[f]={currentTime:t,offset:0}):p=d;else{const g=this._calcTimeOffset(t,l);this._cacheData[f]={currentTime:t,offset:g},p=t}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,e),g=ee(t).format("YYYY-MM-DD"),y=p;p=void 0;for(const w of f){const[v,x]=w;if(ee(t).isBetween(`${g} ${v}`,`${g} ${x}`,"hour")){ee(y).isBetween(`${g} ${v}`,`${g} ${x}`,"hour")?p=y:p=ee(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;p&&!d.includes(m)&&(p=void 0)}return i&&(p=p&&kr(p,i).valueOf()),p&&p-a*h*1e3}_seriesColorHandle(t,e,r){var n;if(r&&e!=null&&e.length)for(const i of e){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=t[i];if(!a)continue;const l=r[`${i}s`]||[];l.includes(a)||(l.push(a),r[`${i}s`]=l,l.length>5&&(r[`${i}s`]=[],r.gradientColorKeys=r.gradientColorKeys||[],r.gradientColorKeys.push(i)))}}_parserSession(t,e){const r=t.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const h=parseInt(c,10);if(h<1||h>7){this._errorListener.addError(`Invalid day of week: ${c}`,e,zt.Error);return}return h});return{timePeriods:n.split(",").map(c=>{c===""||c===fi.regular?c="0930-1500":c===fi.extended&&(c="1500-1830");const h=c.split("-");return h.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,e,zt.Error),[]):[this._processTime(h[0],e),this._processTime(h[1],e)]}),weeks:a}}_processTime(t,e){const r=parseInt(t.slice(0,2),10),n=parseInt(t.slice(2),10);if(!(r>=0&&r<=23)&&n>=0&&n<=59){this._errorListener.addError("Invalid time: Time must be within 00:00 to 23:59",e,zt.Error);return}return`${r}:${n}`}}class uw{constructor(t,e){$(this,"_variables");$(this,"_scriptId");$(this,"_cacheData");this._variables=t,this._scriptId=e,this._cacheData=new Map}security(t,e){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=t,i=this._getRequestData(t,e);if(r!=null&&r.has(e)){const c=r.get(e);return this._runScripts(c,e,!1,n,i)}const a=this._parseExprCode(t),l=this._runScripts(a,e,!0,n,i);return r==null||r.set(e,a),l}_parseExprCode(t){let{expression:e,paramsExpr:r=[]}=t,n=[],i=1;e=Il(e);const a=JSON.parse(e),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},h=(l==null?void 0:l.depends)||[];if(!h.length)return`return ${l==null?void 0:l.code}`;let p=[],f=[];const d=[];if(this._getDependCodes(h,a,n,p,f,d),f.length){const m=r.length;let w=[];for(let v=m-1;v>=0;v--){const x=r[v];let b=JSON.parse(Il(x));const N=[];i!==0&&f.length&&(w.unshift("{"),i++),b=b.map(S=>{const{scope:T,code:F,varNames:O,dependSelf:R}=S;return T===2&&!N.includes(O)&&!R&&(S.code=`let ${F}`),O&&N.push(...O.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const E=[],A=[];let M=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(M,b,A,p,f,E),w.unshift(...A,...E),n=w.concat(n),w=[]}}for(n.push(`return ${l==null?void 0:l.code}`);i>1;)n.push("}"),i--;n=p.concat(n),n.push(...d);let g=n.join(`
63
63
  `);const y=[];for(const m of Object.keys(c))g.includes(`$_var.getCacheData("${m}"`)&&y.push(c[m]);return y.length&&(g=`${y.join(`
64
64
  `)}
65
- ${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:i}=t;const{__period:a,syminfo:{ticker:l,tickerid:c},mintick:h}=this._variables;if((n===a||n==="")&&(r===l||r===c)){const{close:g,open:y,high:m,low:w,bar_index:v,last_bar_index:x,last_bar_time:b,_isRealTimeBar:N,volume:E,time:A,time_tradingday:M}=this._variables;return{barIndex:v,c:g,o:y,h:m,l:w,volume:E,lastBarIndex:x,lastBarTime:b/1e3,isrealtime:N,time_tradingday:M,time:A/1e3,interval:a,mintick:h}}const p=`${r}--${n||a}`,f=self.workerStorage.get(`request_${this._scriptId}_data`),d=self.workerStorage.get(`request_${this._scriptId}_list`);if(f!=null&&f.has(p)){d==null||d.delete(p);const{index:g=0,periodStamp:y=Qr(this._variables.__period)*1e3}=this._cacheData.get(e)||{},m=(f.get(p)||[]).slice(g),w=this._variables.time,v=y+w,x=m.length-1,b={lastBarIndex:m[x].barindex||x,lastBarTime:m[x].time,interval:a,mintick:h};for(const[N,E]of m.entries()){let{time:A,barindex:M}=E;if(A=A*1e3,A>=v){this._cacheData.set(e,{index:N,periodStamp:y});return}if(A>=w)return this._cacheData.set(e,{index:N+1,periodStamp:y}),{...E,barIndex:M||N,...b}}this._cacheData.set(e,{index:m.length,periodStamp:y})}else(d==null?void 0:d.get(p))||d==null||d.set(p,{id:p,calc_bars_count:i,symbol:r,timeframe:n||a})}_getDependCodes(t,e,r,n,i,a){for(const l of t){if(!l.isArg){const c=e.filter(p=>{var f;return(f=p==null?void 0:p.depends)==null?void 0:f.some(d=>d.name===l.name&&d.scope===l.scope&&d.isAgainAssign)});for(const p of c){const{code:f,depends:d}=p;if(!r.includes(f)&&(r.unshift(f),d!=null&&d.length)){for(const g of d)g.memberCode&&a.push(g.memberCode);this._getDependCodes(d,e,r,n,i,a)}}const h=e.find(p=>{var f;return((f=p.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&p.methodName===l.functionName)||p.funcName===l.name});if(h){const{code:p,depends:f}=h,d=r.findIndex(g=>g===p);if(d!==-1&&r.splice(d,1),r.unshift(p),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,i,a)}continue}}i.some(c=>c.name===l.name)||i.push(l)}}_runScripts(t,e,r,n,i){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:p}=self.workerStorage.get(a)||{};const{interval:f,mintick:d,...g}=i||{};r&&(l=new ah(a),c=new th,h=new oh(this._variables.mintick||1e-5,l,this._scriptId),p=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),l.updateOptions({interval:f,mintick:d||1e-5}),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:p})),l.updateData(g),h.update({barIndex:(g==null?void 0:g.barindex)||0});const y=p(l,c,h,n||[],e);return h.endExecution(),y}}let lw=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class cw{constructor(t){$(this,"_logs");$(this,"_variables");$(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:i,formatString:a}=t,{time:l,bar_index:c}=this._variables;let h=i;a&&Array.isArray(e)&&e.length&&(h=a.replace(/{(\d+)}/g,(p,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(3)))),typeof d=="object"&&(d.isArray?d=JSON.stringify(d._value):d=d.toString()),d!==void 0?d:p})),h&&this._logs.push({message:`[${ee(l).format()}]: ${h}`,time:l,barIndex:c,type:r})}}class fw{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,zt.Error)}}class hw{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Xr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[i,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(i),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(i),type:r};l?l.push(c):this._errors.set(e,[c])}}class pw{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(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 dw{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class _w{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossloss_percent",0);$(this,"_grossprofit",0);$(this,"_grossprofit_percent",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){if(!this._orders.length)return;let t=0,e=0;const{high:r,low:n,close:i}=this._variables;let a=0;for(const h of this._orders){const{in_price:p,qty:f=0,commission:d=0,original_qty:g=0,direction:y,profit:m=0}=h,w=y===ue.long?1:-1,v=(r-p)*f,x=(n-p)*f,b=this._getCommission(i,f),N=d*f/g,E=w===1?v:-x,A=w===1?-x:v;a+=m+N+b,t+=A,e+=E}this._openprofit=a;const l=this.initial_capital,c=l+this._netprofit;this._preMinNetValue=this._preMinNetValue||l,this._preMaxNetValue=this._preMaxNetValue||l,t=this._preMaxNetValue-c+Math.max(t,0),e=c-this._preMinNetValue+e,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/l*100),e>this._max_runup&&(this._max_runup=e,this._max_runup_percent=e/c*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,i,a,l,c]=this._orders.reduce(([h,p,f,d,g,y,m],w)=>{const{direction:v,qty:x=0,in_price:b,commission:N=0}=w;return v===ue.long?(h+=x,p+=x,y+=x):(h+=x,f+=x,y-=x),d+=x*b,g+=b,m+=N,[h,p,f,d,g,y,m]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=-c),this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=i,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,i,a]=this._historyOrders.reduce((h,p)=>{let[f,d,g,y]=h;const{profit:m=0,profit_percent:w=0}=p;return f+=m,d+=w,m<0?g+=m:y+=m,[f,d,g,y]},[0,0,0,0]),l=this._orders.reduce((h,p)=>{const{commission:f=0,qty:d=0,original_qty:g=0}=p,y=f*d/g;return h+y},0);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r-l;const c=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,c),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,c),this._grossloss=i-l,this._grossprofit=a,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){const t=this._losstrades;return t?Math.abs(this._grossloss_percent/t):void 0}get avg_trade(){if(this._closedtrades)return this._netprofit/this._closedtrades}get equity(){return this.initial_capital+this._netprofit+this._openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this._wintrades;return t?Math.abs(this._grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:i=0}=this._options,a=this._orders[0].direction===ue.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,p]=this._orders.reduce((f,d)=>{let[g,y]=f;const{in_price:m,qty:w=0,original_qty:v=0}=d,x=m*w;if(g+=x,i){let b=0;switch(n){case nr.percent:b=(x+w*c)*i/100;break;case nr.cashPerContract:b=w*i*2;break;case nr.cashPerOrder:b=w/v*i+i;break}y+=b}return[g,y]},[0,0]);return(h-(t+this._netprofit-p))*a/this._position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,i=t*e;let a=0;switch(n){case nr.percent:a=i*r/100;break;case nr.cashPerContract:a=e*r;break;case nr.cashPerOrder:a=r;break}return a}}class mw{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}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 i=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=i),this._preValue.accdist=i,i}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,i=(2*t-r-e)/((r-e)*n);return this._preValue.iii=i,i}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:i}=this._currentData,a=(t-i)/(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 i=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-i:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){var p,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:i}=this._preVwap;if(((f=(p=self.workerStorage)==null?void 0:p.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(i=!0,r=n=0),!i)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:i});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i<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:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class gw{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=ys(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 vw{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,i;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?i=parseInt(a,16)/255:i=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:e,g:r,b:n,a:i}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class yw{constructor(t){$(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return fi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){return""}get tickerid(){return""}get timezone(){}get type(){}get volumetype(){return"n/a"}}class ww{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Dw{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(jp),ee.extend(Sl),ee.extend(Up);class ah{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");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 pw,this._timeframe=new gw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new mw(t),this._polyline=new Fi,this._label=new Fi,this._line=new Fi,this._linefill=new Fi,this._box=new Fi,this._table=new Fi(1),this._strategy=new _w(this),this._session=new dw(this),this.syminfo=new yw(this),this.chart=new vw(this),this.earnings=new Dw(this),this.dividends=new ww(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close: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 ee(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()+1}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=ys(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:i}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),i&&this._polyline.setMaxLen(i)}getTimeTradingday(t,e){const[r,n]=ys(e),i=ee(t);return["M","w","y","d"].includes(n)?i.valueOf():(i.subtract(this._offsetTime,"h"),i.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){const{interval:e="1D",offsetTime:r=5,mintick:n,chart:i}=t;this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(i)}updateData(t){const{barIndex:e,c:r,o:n,h:i,l:a,volume:l,time:c,lastBarIndex:h,lastBarTime:p,isrealtime:f,time_tradingday:d}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(i),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._timeTradingday=d,this._currentBarTime=c*1e3,this._lastBarIndex=h,this._barIndex=e,this._lastBarTime=p*1e3,this._barstate.update(e,h,f,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return(this._cacheSpace.get(t)||0)<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new Pp(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`;return r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var l;const i=`${t}_${e}`;let a;switch(typeof r=="object"&&((l=r==null?void 0:r.varipKeys)!=null&&l.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[i]||this._cacheData.varipData[i]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[i]=r,a&&a.length)for(const c of a)this._cacheData.varData[i][c]=r[c]}else this._cacheData.varData[i]=r;break;case"varip":this._cacheData.varipData[i]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case Fe.BOX:this._setChartDraw(e,this._box);break;case Fe.LINE:this._setChartDraw(e,this._line);break;case Fe.POLYLINE:this._setChartDraw(e,this._polyline);break;case Fe.LABEL:this._setChartDraw(e,this._label);break;case Fe.LINEFILL:this._setChartDraw(e,this._linefill);break;case Fe.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t);e.delete(t),e.set(t,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Xr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case ao.name:case eh.name:case co.name:case rh.name:case uo.name:case lo.name:t==null||t.delete();break}}}class Fi{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[i,a]of this._all){const{isVar:l,id:c,bar_index:h}=a;if(h===n)break;if(l)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const i=r.filter(a=>a.endsWith(`_${n}`));for(const a of i){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
65
+ ${g}`),g}_getRequestData(t,e){let{symbol:r,timeframe:n,calc_bars_count:i}=t;const{__period:a,syminfo:{ticker:l,tickerid:c},mintick:h}=this._variables;if((n===a||n==="")&&(r===l||r===c)){const{close:g,open:y,high:m,low:w,bar_index:v,last_bar_index:x,last_bar_time:b,_isRealTimeBar:N,volume:E,time:A,time_tradingday:M}=this._variables;return{barIndex:v,c:g,o:y,h:m,l:w,volume:E,lastBarIndex:x,lastBarTime:b/1e3,isrealtime:N,time_tradingday:M,time:A/1e3,interval:a,mintick:h}}const p=`${r}--${n||a}`,f=self.workerStorage.get(`request_${this._scriptId}_data`),d=self.workerStorage.get(`request_${this._scriptId}_list`);if(f!=null&&f.has(p)){d==null||d.delete(p);const{index:g=0,periodStamp:y=Qr(this._variables.__period)*1e3}=this._cacheData.get(e)||{},m=(f.get(p)||[]).slice(g),w=this._variables.time,v=y+w,x=m.length-1,b={lastBarIndex:m[x].barindex||x,lastBarTime:m[x].time,interval:a,mintick:h};for(const[N,E]of m.entries()){let{time:A,barindex:M}=E;if(A=A*1e3,A>=v){this._cacheData.set(e,{index:N,periodStamp:y});return}if(A>=w)return this._cacheData.set(e,{index:N+1,periodStamp:y}),{...E,barIndex:M||N,...b}}this._cacheData.set(e,{index:m.length,periodStamp:y})}else(d==null?void 0:d.get(p))||d==null||d.set(p,{id:p,calc_bars_count:i,symbol:r,timeframe:n||a})}_getDependCodes(t,e,r,n,i,a){for(const l of t){if(!l.isArg){const c=e.filter(p=>{var f;return(f=p==null?void 0:p.depends)==null?void 0:f.some(d=>d.name===l.name&&d.scope===l.scope&&d.isAgainAssign)});for(const p of c){const{code:f,depends:d}=p;if(!r.includes(f)&&(r.unshift(f),d!=null&&d.length)){for(const g of d)g.memberCode&&a.push(g.memberCode);this._getDependCodes(d,e,r,n,i,a)}}const h=e.find(p=>{var f;return((f=p.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&p.methodName===l.functionName)||p.funcName===l.name});if(h){const{code:p,depends:f}=h,d=r.findIndex(g=>g===p);if(d!==-1&&r.splice(d,1),r.unshift(p),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,e,r,n,i,a)}continue}}i.some(c=>c.name===l.name)||i.push(l)}}_runScripts(t,e,r,n,i){const a=`${this._scriptId}_${e}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:p}=self.workerStorage.get(a)||{};const{interval:f,mintick:d,...g}=i||{};r&&(l=new ah(a),c=new th,h=new oh(this._variables.mintick||1e-5,l,this._scriptId),p=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",t),l.updateOptions({interval:f,mintick:d||1e-5}),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:h,tradingvueFunc:p})),l.updateData(g),h.update({barIndex:(g==null?void 0:g.barindex)||0});const y=p(l,c,h,n||[],e);return h.endExecution(),y}}let lw=class{constructor(){}prefix(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[0])||""}ticker(t){var r;const{symbol:e}=t;return((r=e==null?void 0:e.split("."))==null?void 0:r[1])||""}};class cw{constructor(t){$(this,"_logs");$(this,"_variables");$(this,"_intlFormat");this._variables=t,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e,r){this._addLog(t,e,"info",r)}error(t,e,r){this._addLog(t,e,"error",r)}warning(t,e,r){this._addLog(t,e,"warning",r)}_addLog(t,e,r,n){if(typeof e=="string"&&(n=e),n.startsWith("export"))return;const{message:i,formatString:a}=t,{time:l,bar_index:c}=this._variables;let h=i;a&&Array.isArray(e)&&e.length&&(h=a.replace(/{(\d+)}/g,(p,f)=>{let d=e[f];return typeof d=="number"&&(d=this._intlFormat.format(parseFloat(d.toFixed(3)))),typeof d=="object"&&(d.isArray?d=JSON.stringify(d._value):d=d.toString()),d!==void 0?d:p})),h&&this._logs.push({message:`[${ee(l).format()}]: ${h}`,time:l,barIndex:c,type:r})}}class fw{constructor(t){$(this,"_errorListener");this._errorListener=t}error({message:t},e){e.startsWith("export")||this._errorListener.addError(t,e,zt.Error)}}class hw{constructor(){$(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Xr.flatMap([...this._errors.values()])}addError(t,e,r,n=0){const[i,a]=e.split("_").slice(-2),l=this._errors.get(e),c={message:t,endLineNumber:Number(i),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(i),type:r};l?l.push(c):this._errors.set(e,[c])}}class pw{constructor(){$(this,"_isMarketOpen");$(this,"_currentBarIndex");$(this,"_totalBarIndex");$(this,"_isRealTimeBar");$(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&&!this._isRealTimeBar:this._currentBarIndex===this._totalBarIndex}}class dw{constructor(t){$(this,"_variables");this._variables=t}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const t=Qr(this._variables.timeframe.period);return this._variables.time+t===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class _w{constructor(t){$(this,"_orders");$(this,"_historyOrders");$(this,"_options");$(this,"_max_contracts_held_all",0);$(this,"_max_contracts_held_long",0);$(this,"_max_contracts_held_short",0);$(this,"_max_drawdown",0);$(this,"_max_runup",0);$(this,"_max_runup_percent",0);$(this,"_max_drawdown_percent",0);$(this,"_variables");$(this,"_netprofit",0);$(this,"_eventrades",0);$(this,"_avg_trade_percent");$(this,"_closedtrades",0);$(this,"_losstrades",0);$(this,"_grossloss",0);$(this,"_grossloss_percent",0);$(this,"_grossprofit",0);$(this,"_grossprofit_percent",0);$(this,"_wintrades",0);$(this,"_opentrades_capital_held",0);$(this,"_position_avg_price",0);$(this,"_position_size",0);$(this,"_openprofit",0);$(this,"_preMaxNetValue",0);$(this,"_preMinNetValue",0);$(this,"marginCallLong",0);$(this,"marginCallShort",0);this._orders=[],this._historyOrders=[],this._variables=t}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){if(!this._orders.length)return;let t=0,e=0;const{high:r,low:n,close:i}=this._variables;let a=0;for(const h of this._orders){const{in_price:p,qty:f=0,commission:d=0,original_qty:g=0,direction:y,profit:m=0}=h,w=y===ue.long?1:-1,v=(r-p)*f,x=(n-p)*f,b=this._getCommission(i,f),N=d*f/g,E=w===1?v:-x,A=w===1?-x:v;a+=m+N+b,t+=A,e+=E}this._openprofit=a;const l=this.initial_capital,c=l+this._netprofit;this._preMinNetValue=this._preMinNetValue||l,this._preMaxNetValue=this._preMaxNetValue||l,t=this._preMaxNetValue-c+Math.max(t,0),e=c-this._preMinNetValue+e,this._max_drawdown<t&&(this._max_drawdown=t,this._max_drawdown_percent=t/l*100),e>this._max_runup&&(this._max_runup=e,this._max_runup_percent=e/c*100)}updateOrders(t){this._orders=t,this._calcMaxContracts()}_calcMaxContracts(){const t=this._orders.length;if(!t){this._position_size=0,this._position_avg_price=void 0,this._opentrades_capital_held=0;return}const[e,r,n,i,a,l,c]=this._orders.reduce(([h,p,f,d,g,y,m],w)=>{const{direction:v,qty:x=0,in_price:b,commission:N=0}=w;return v===ue.long?(h+=x,p+=x,y+=x):(h+=x,f+=x,y-=x),d+=x*b,g+=b,m+=N,[h,p,f,d,g,y,m]},[0,0,0,0,0,0,0]);this._historyOrders.length||(this._netprofit=-c,this._grossloss=-c),this._position_size=l,this._position_avg_price=a/t,this._opentrades_capital_held=i,this._max_contracts_held_all=Math.max(e,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(t){this._historyOrders=t;const e=this._historyOrders.length;this._closedtrades=e;const[r,n,i,a]=this._historyOrders.reduce((h,p)=>{let[f,d,g,y]=h;const{profit:m=0,profit_percent:w=0}=p;return f+=m,d+=w,m<0?g+=m:y+=m,[f,d,g,y]},[0,0,0,0]),l=this._orders.reduce((h,p)=>{const{commission:f=0,qty:d=0,original_qty:g=0}=p,y=f*d/g;return h+y},0);this._avg_trade_percent=e?n/e:void 0,this._netprofit=r-l;const c=this.initial_capital+this._netprofit;this._preMaxNetValue=Math.max(this._preMaxNetValue||this.initial_capital,c),this._preMinNetValue=Math.min(this._preMinNetValue||this.initial_capital,c),this._grossloss=i-l,this._grossprofit=a,this._eventrades=this._historyOrders.filter(h=>h.profit===0).length,this._losstrades=this._historyOrders.filter(h=>(h.profit||0)<0).length,this._wintrades=this._historyOrders.filter(h=>(h.profit||0)>0).length}updateStrategyOptions(t){this._options=t}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const t=this._losstrades;return t?Math.abs(this._grossloss/t):void 0}get avg_losing_trade_percent(){const t=this._losstrades;return t?Math.abs(this._grossloss_percent/t):void 0}get avg_trade(){if(this._closedtrades)return this._netprofit/this._closedtrades}get equity(){return this.initial_capital+this._netprofit+this._openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._openprofit}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const t=this._wintrades;return t?Math.abs(this._grossprofit/t):void 0}get avg_winning_trade_percent(){const t=this._wintrades;return t?Math.abs(this._grossprofit_percent/t):void 0}get initial_capital(){var t;return((t=this._options)==null?void 0:t.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss/this.initial_capital*100}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit/this.initial_capital*100}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:t,margin_long:e=0,margin_short:r=0,commission_type:n,commission_value:i=0}=this._options,a=this._orders[0].direction===ue.long?1:-1,l=(a===1?e:r)/100;if(l<=0)return;const{close:c}=this._variables,[h,p]=this._orders.reduce((f,d)=>{let[g,y]=f;const{in_price:m,qty:w=0,original_qty:v=0}=d,x=m*w;if(g+=x,i){let b=0;switch(n){case nr.percent:b=(x+w*c)*i/100;break;case nr.cashPerContract:b=w*i*2;break;case nr.cashPerOrder:b=w/v*i+i;break}y+=b}return[g,y]},[0,0]);return(h-(t+this._netprofit-p))*a/this._position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this._netprofit/this.initial_capital*100}get openprofit_percent(){return this._openprofit/(this.initial_capital+this._netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}get summaryData(){return{position_size:this.position_size,position_avg_price:this.position_avg_price,position_entry_name:this.position_entry_name,openprofit_percent:this.openprofit_percent,netprofit_percent:this.netprofit_percent,max_drawdown_percent:this.max_drawdown_percent,max_runup_percent:this.max_runup_percent,max_drawdown:this.max_drawdown,max_runup:this.max_runup,max_contracts_held_long:this.max_contracts_held_long,max_contracts_held_short:this.max_contracts_held_short,max_contracts_held_all:this.max_contracts_held_all,avg_winning_trade_percent:this.avg_winning_trade_percent,avg_winning_trade:this.avg_winning_trade,avg_trade_percent:this.avg_trade_percent,avg_trade:this.avg_trade,avg_losing_trade:this.avg_losing_trade,avg_losing_trade_percent:this.avg_losing_trade_percent,wintrades:this.wintrades,losstrades:this.losstrades,eventrades:this.eventrades,grossprofit:this.grossprofit,grossprofit_percent:this.grossprofit_percent,grossloss:this.grossloss,grossloss_percent:this.grossloss_percent,openprofit:this.openprofit,initial_capital:this.initial_capital,netprofit:this.netprofit,closedtrades:this.closedtrades,opentrades:this.opentrades,equity:this.equity,margin_call_long:this.marginCallLong,margin_call_short:this.marginCallShort}}_getCommission(t,e){if(!this._options)return 0;const{commission_value:r=0,commission_type:n}=this._options,i=t*e;let a=0;switch(n){case nr.percent:a=i*r/100;break;case nr.cashPerContract:a=e*r;break;case nr.cashPerOrder:a=r;break}return a}}class mw{constructor(t){$(this,"_preAccdist");$(this,"_preNvi");$(this,"_prePvi");$(this,"_preObv");$(this,"_prePvt");$(this,"_preWad");$(this,"_preVwap");$(this,"_preValue");$(this,"_currentData");$(this,"_preData");$(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=t}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 i=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=i),this._preValue.accdist=i,i}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,i=(2*t-r-e)/((r-e)*n);return this._preValue.iii=i,i}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:i}=this._currentData,a=(t-i)/(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 i=Math.max(e,n),a=Math.min(r,n),l=t-n,h=(l>0?t-a:l<0?t-i:0)+this._preWad;return!this.isRealTime&&(this._preWad=h),this._preValue.wad=h,h}get vwap(){var p,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:i}=this._preVwap;if(((f=(p=self.workerStorage)==null?void 0:p.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(i=!0,r=n=0),!i)return;const l=t*e+r,c=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:i});const h=l/c;return this._preValue.vwap=h,h}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i<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:i}=this._currentData;let a=1;const l=t||1;return n&&e?a=i>r?l+(n-e)/e*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class gw{constructor(){$(this,"_period");$(this,"_multiplier");$(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=ys(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 vw{constructor(t){$(this,"_variables");$(this,"_bgColor");$(this,"_fgColor");$(this,"isUseBgColor",!1);this._variables=t}updateOptions(t){t!=null&&t.bg_color&&(this._bgColor=t.bg_color,this._fgColor=this._contrastColor(t.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(t){let e,r,n,i;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const a=t.substring(7);a?i=parseInt(a,16)/255:i=1}else{const a=this._parserRgbColor(t);e=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:e,g:r,b:n,a:i}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}_contrastColor(t){const{r:e,g:r,b:n}=this._parseColor(t);return(299*e+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class yw{constructor(t){$(this,"_variables");this._variables=t}get basecurrency(){return""}get country(){}get currency(){return"CNY"}get description(){return""}get employees(){return 100}get expiration_date(){}get industry(){}get minmove(){}get mintick(){return this._variables.mintick}get pointvalue(){}get prefix(){}get pricescale(){}get recommendations_buy(){}get recommendations_buy_strong(){}get recommendations_date(){}get recommendations_hold(){}get recommendations_sell(){}get recommendations_sell_strong(){}get recommendations_total(){}get root(){return""}get sector(){}get session(){return fi.regular}get shareholders(){}get shares_outstanding_float(){}get shares_outstanding_total(){}get target_price_average(){}get target_price_date(){}get target_price_estimates(){}get target_price_high(){}get target_price_low(){}get target_price_median(){}get ticker(){return""}get tickerid(){return""}get timezone(){}get type(){}get volumetype(){return"n/a"}}class ww{constructor(t){$(this,"_variables");this._variables=t}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class Dw{constructor(t){$(this,"_variables");this._variables=t}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}ee.extend(jp),ee.extend(Sl),ee.extend(Up);class ah{constructor(t){$(this,"_cacheData");$(this,"_barIndex");$(this,"_isRealTimeBar");$(this,"_barstate");$(this,"_priceVariables");$(this,"_lastBarIndex");$(this,"_currentBarTime");$(this,"_lastBarTime");$(this,"_period");$(this,"_offsetTime");$(this,"_timeframe");$(this,"_ta");$(this,"_polyline");$(this,"_label");$(this,"_line");$(this,"_linefill");$(this,"_box");$(this,"_table");$(this,"_strategy");$(this,"_session");$(this,"syminfo");$(this,"chart");$(this,"earnings");$(this,"dividends");$(this,"_timeTradingday");$(this,"_mintick");$(this,"_cacheSpace");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 pw,this._timeframe=new gw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new mw(t),this._polyline=new Fi,this._label=new Fi,this._line=new Fi,this._linefill=new Fi,this._box=new Fi,this._table=new Fi,this._strategy=new _w(this),this._session=new dw(this),this.syminfo=new yw(this),this.chart=new vw(this),this.earnings=new Dw(this),this.dividends=new ww(this),this._cacheSpace=new Map}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close: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 ee(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ee(this._currentBarTime).minute()}get second(){return ee(this._currentBarTime).second()}get month(){return ee(this._currentBarTime).month()+1}get year(){return ee(this._currentBarTime).year()}get dayofweek(){return ee(this._currentBarTime).day()+1}get dayofmonth(){return ee(this._currentBarTime).date()}get weekofyear(){return ee(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=ys(this._period);return this._isRealTimeBar?void 0:ee(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}updateMaxLength(t){const{max_lines_count:e,max_labels_count:r,max_boxes_count:n,max_polylines_count:i}=t;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),e&&this._line.setMaxLen(e),i&&this._polyline.setMaxLen(i)}getTimeTradingday(t,e){const[r,n]=ys(e),i=ee(t);return["M","w","y","d"].includes(n)?i.valueOf():(i.subtract(this._offsetTime,"h"),i.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(t){const{interval:e="1D",offsetTime:r=5,mintick:n,chart:i}=t;this._period=e,this._mintick=n,this._offsetTime=r,this._timeframe.update(e),this.chart.updateOptions(i)}updateData(t){const{barIndex:e,c:r,o:n,h:i,l:a,volume:l,time:c,lastBarIndex:h,lastBarTime:p,isrealtime:f,time_tradingday:d}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(i),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varNewData={}),this._timeTradingday=d,this._currentBarTime=c*1e3,this._lastBarIndex=h,this._barIndex=e,this._lastBarTime=p*1e3,this._barstate.update(e,h,f,!0),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){const n=this.setCacheData(t,r);return(this._cacheSpace.get(t)||0)<e&&this._cacheSpace.set(t,e),n[n.length-1-e]}setCacheData(t,e){let r=this._cacheData[t]||{barIndex:-1,data:[]};if(r.barIndex>this._barIndex)return r.data;r.barIndex===this._barIndex?r.data[r.data.length-1]=e:r.data.push(e);const n=this._cacheSpace.get(t);return n&&r.data.length>n+5&&r.data.shift(),r.barIndex=this._barIndex,this._cacheData[t]=r,r.data}getTypeInstance(t,e){return new Pp(t,e)}verifyVarAndVarip(t,e,r){const n=`${t}_${e}`;return r==="var"&&this._cacheData.varData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varData[n]),!0):r==="varip"&&this._cacheData.varipData.hasOwnProperty(n)?(this._upadteChartDraws(this._cacheData.varipData[n]),!0):!1}getVarValue(t,e,r){const n=`${t}_${e}`;return r==="var"?this._isRealTimeBar&&this._cacheData.varNewData.hasOwnProperty(n)?this._cacheData.varNewData[n]:this._cacheData.varData[n]:this._cacheData.varipData[n]}setVarValue(t,e,r,n){var l;const i=`${t}_${e}`;let a;switch(typeof r=="object"&&((l=r==null?void 0:r.varipKeys)!=null&&l.length)&&(n="var",a=r.varipKeys),this._chartDrawsHandle(r,this._cacheData.varData[i]||this._cacheData.varipData[i]),n){case"var":if(this._isRealTimeBar){if(this._cacheData.varNewData[i]=r,a&&a.length)for(const c of a)this._cacheData.varData[i][c]=r[c]}else this._cacheData.varData[i]=r;break;case"varip":this._cacheData.varipData[i]=r;break}return r}_upadteChartDraws(t){const e=t==null?void 0:t.id;if(e)switch(t==null?void 0:t.type){case Fe.BOX:this._setChartDraw(e,this._box);break;case Fe.LINE:this._setChartDraw(e,this._line);break;case Fe.POLYLINE:this._setChartDraw(e,this._polyline);break;case Fe.LABEL:this._setChartDraw(e,this._label);break;case Fe.LINEFILL:this._setChartDraw(e,this._linefill);break;case Fe.TABLE:this._setChartDraw(e,this._table);break}}_setChartDraw(t,e){const r=e.getInstance(t),n=e.get(t),i=(r==null?void 0:r.updateId())||t;e.delete(t),e.set(i,n,r)}_chartDrawsHandle(t,e){const r=e==null?void 0:e.id;let n=t==null?void 0:t.id;r!==n&&(n&&t.data&&(t.data.isVar=!0),r&&e.data&&(e.data.isVar=!1))}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Xr.uniq([...t,...e]):typeof t=="number"||typeof e=="number"?Number(t)+Number(e):t+e}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case ao.name:case eh.name:case co.name:case rh.name:case uo.name:case lo.name:t==null||t.delete();break}}}class Fi{constructor(t=50){$(this,"_all");$(this,"_allInstance");$(this,"_pseudoArrayAll");$(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()].slice(-this._maxLength)}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){if(this.set(t,e,r),this._all.size>this._maxLength){const{bar_index:n}=e;for(const[i,a]of this._all){const{isVar:l,id:c,bar_index:h}=a;if(h===n)break;if(l)continue;this.delete(c);break}}}getValOfBarIndex(t){let e=[];const r=[...this._all.keys()];for(const n of t){const i=r.filter(a=>a.endsWith(`_${n}`));for(const a of i){const l=this._all.get(a);l&&e.push(l)}}return e.length?e:void 0}set(t,e,r){this._all.set(t,e),this._allInstance.set(t,r)}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}/**
66
66
  * @license
67
67
  * Copyright 2019 Google LLC
68
68
  * SPDX-License-Identifier: Apache-2.0
@@ -75,6 +75,7 @@ export declare class Box {
75
75
  constructor(variables: BuiltInVariables, key: string, errorListener: TccErrorListener);
76
76
  get type(): VType;
77
77
  get id(): string;
78
+ updateId(): string;
78
79
  get data(): IBoxArgs | undefined;
79
80
  copy(posStr: string): Box;
80
81
  delete(): void;
@@ -59,6 +59,7 @@ export declare class Label {
59
59
  constructor(key: string, variables: BuiltInVariables, errorListener: TccErrorListener);
60
60
  get type(): VType;
61
61
  get id(): string;
62
+ updateId(): string;
62
63
  get data(): Partial<ILabelArgs> | undefined;
63
64
  copy(posStr: string): Label;
64
65
  get_x(posStr: string): number | undefined;
@@ -61,6 +61,7 @@ export declare class Line {
61
61
  private _errorListener;
62
62
  constructor(key: string, variables: BuiltInVariables, errorListener: TccErrorListener);
63
63
  get id(): string;
64
+ updateId(): string;
64
65
  get type(): VType;
65
66
  get data(): ILineArgs | undefined;
66
67
  copy(posStr: string): Line;
@@ -30,6 +30,7 @@ export declare class Linefill {
30
30
  constructor(variables: BuiltInVariables, key: string, line1?: Line, line2?: Line);
31
31
  get type(): VType;
32
32
  get id(): string;
33
+ updateId(): string;
33
34
  get data(): TLinefill | undefined;
34
35
  linefill(args: {
35
36
  x?: Linefill;
@@ -31,6 +31,7 @@ export declare class Polyline {
31
31
  constructor(key: string, variables: BuiltInVariables);
32
32
  get type(): VType;
33
33
  get id(): string;
34
+ updateId(): string;
34
35
  get data(): IPolyline | undefined;
35
36
  delete(): void;
36
37
  }
@@ -82,6 +82,7 @@ export declare class Table {
82
82
  constructor(variables: BuiltInVariables, key: string, errorListener: TccErrorListener);
83
83
  get type(): VType;
84
84
  get id(): string;
85
+ updateId(): string;
85
86
  get data(): ITableArgs | undefined;
86
87
  cell(args: ITableCellArgs): void;
87
88
  cell_set_bgcolor({ column, row, bgcolor }: ITableCellArgs): void;
@@ -67593,7 +67593,7 @@ function nr(a, n, r) {
67593
67593
  function ih() {
67594
67594
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
67595
67595
  }
67596
- const Pp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-DhG0a5Az.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
67596
+ const Pp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-Bn8CAGnd.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
67597
67597
  Pp.onerror = (a) => {
67598
67598
  console.error(a);
67599
67599
  };
@@ -141,7 +141,7 @@ function print() { __p += __j.call(arguments, '') }
141
141
  * @license
142
142
  * Copyright 2019 Google LLC
143
143
  * SPDX-License-Identifier: Apache-2.0
144
- */const yo=Symbol("Comlink.proxy"),tm=Symbol("Comlink.endpoint"),rm=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),_o=a=>typeof a=="object"&&a!==null||typeof a=="function",sm={canHandle:a=>_o(a)&&a[yo],serialize(a){const{port1:n,port2:s}=new MessageChannel;return go(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},am={canHandle:a=>_o(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},fo=new Map([["proxy",sm],["throw",am]]);function nm(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function go(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!nm(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(br);let b;try{const h=y.slice(0,-1).reduce((N,B)=>N[B],a),T=y.reduce((N,B)=>N[B],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=br(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:B}=new MessageChannel;go(a,B),b=pm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),bo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function im(a){return a.constructor.name==="MessagePort"}function bo(a){im(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function xo(a){return Lr(a,{type:"RELEASE"}).then(()=>{bo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&xo(a)});function om(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function lm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===rm)return()=>{lm(c),xo(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Lr(a,{type:"GET",path:n.map(f=>f.toString())}).then(br);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Lr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(br)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===tm)return Lr(a,{type:"ENDPOINT"}).then(br);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=ho(y);return Lr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(br)},construct(l,m){Qs(o);const[y,f]=ho(m);return Lr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(br)}});return om(c,a),c}function cm(a){return Array.prototype.concat.apply([],a)}function ho(a){const n=a.map(ea);return[n.map(s=>s[0]),cm(n.map(s=>s[1]))]}const wo=new WeakMap;function pm(a,n){return wo.set(a,n),a}function gn(a){return Object.assign(a,{[yo]:!0})}function ea(a){for(const[n,s]of fo)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},wo.get(a)||[]]}function br(a){switch(a.type){case"HANDLER":return fo.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Lr(a,n,s){return new Promise(o=>{const c=dm();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function dm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const vo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-DhG0a5Az.js").href:new URL("assets/scriptsRunWorker-DhG0a5Az.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});vo.onerror=a=>{console.error(a)};async function To(a){return await Gs.setInlayHints(a)}const Do=_n(vo),ko=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-jsFIW02M.js").href:new URL("assets/parserTccWorker-jsFIW02M.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function Io(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=lt;return await ko.parseTcc(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function mm(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=lt;return await ko.parseLibraryCode(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function um(a,n,s=!0){return await Do.runScript(a,n,s)}async function ym(a){return await Do.removeScript(a)}function _m(a){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:a==null?void 0:a.name})}self.MonacoEnvironment={getWorker(){return new _m({name:"Editor Worker"})}},sn.config({paths:{vs:"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onCursorPositionChange:T,onActionTrigger:N,onEditorDidMount:B}=a,E=O.useRef(null),F=O.useRef(null),H=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(q){var R;(R=E.current)==null||R.setOriginalScript(q)},setScript(q){var R;(R=E.current)==null||R.setValue(q)},gotoLine(){var q;(q=E.current)==null||q.gotoLine()},getEditorLayout(){var q;return(q=E.current)==null?void 0:q.getEditorLayout()},setPosition(q,R){var V;(V=E.current)==null||V.setPosition({column:q,lineNumber:R})},setModelMarkers(q){var R;(R=E.current)==null||R.setModelMarkers(q)},focus(){var q;(q=E.current)==null||q.focus()}})),O.useEffect(()=>{var q,R;m?(R=E.current)==null||R.addDiffDecorations():(q=E.current)==null||q.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var q;(q=E.current)==null||q.updateActionTrigger(N)},[N]),O.useEffect(()=>{var q;h&&((q=E.current)==null||q.addLinkOpenFunc(h))},[h]);function Y(q,R){var re,ie;zt.initBuiltinsTrees(),Gs.setEditor(q),E.current=new em(q,R,N),h&&((re=E.current)==null||re.addLinkOpenFunc(h)),m&&((ie=E.current)==null||ie.addDiffDecorations()),kd(q),requestAnimationFrame(A);const V=q.getValue();E.current.onChangeCursorPosition(T),b&&b(V),!y&&G(V),B&&B()}const G=O.useCallback(async q=>{var ht;const R=Date.now();H.current=!1;const{errors:V,functions:re,methods:ie,types:xt,variables:St,overloadsFuncs:Ue,imports:Ke,enums:Z}=await Io(q),be=new Map(Object.entries(re)),Ee=new Map(Object.entries(ie)),Me=new Map(Object.entries(xt)),ct=new Map(Object.entries(St)),Et=new Map(Object.entries(Ke)),se=new Map(Object.entries(Z));gr.setUserDefined({functions:be,methods:Ee,types:Me,variables:ct,imports:Et,enums:se},Ue),zt.setUserDefind(be,Me,ct,Ee,se);const he=V.map($e=>({...$e,severity:$e.type||ke.MarkerSeverity.Error}));if(y)return;!H.current&&((ht=E.current)==null||ht.setModelMarkers(he));const Re=Date.now();console.log((Re-R)/1e3)},[y]),K=O.useMemo(()=>qd.debounce(G,1500),[G]);function U(q){var R;if(y){G(q||"");return}H.current=!0,Gs.clearInlayHints(),(R=E.current)==null||R.setModelMarkers([]),q!==void 0&&(b&&b(q),K(q))}const A=O.useCallback(()=>{var R,V;const q=(R=F.current)==null?void 0:R.getBoundingClientRect();(V=E.current)==null||V.setEditorLayout((q==null?void 0:q.height)||0,q==null?void 0:q.width)},[]);return O.useEffect(()=>{const q=()=>{window.requestAnimationFrame(A)},R=new ResizeObserver(q);return F.current&&R.observe(F.current),()=>{var V;F.current&&R.unobserve(F.current),R.disconnect(),(V=E.current)==null||V.dispose()}},[]),M.jsx("div",{ref:F,children:M.jsx(yd,{height:s,width:o||"100%",defaultLanguage:Se,defaultValue:f||`indicator("我的脚本")
144
+ */const yo=Symbol("Comlink.proxy"),tm=Symbol("Comlink.endpoint"),rm=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),_o=a=>typeof a=="object"&&a!==null||typeof a=="function",sm={canHandle:a=>_o(a)&&a[yo],serialize(a){const{port1:n,port2:s}=new MessageChannel;return go(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},am={canHandle:a=>_o(a)&&Ys in a,serialize({value:a}){let n;return a instanceof Error?n={isError:!0,value:{message:a.message,name:a.name,stack:a.stack}}:n={isError:!1,value:a},[n,[]]},deserialize(a){throw a.isError?Object.assign(new Error(a.value.message),a.value):a.value}},fo=new Map([["proxy",sm],["throw",am]]);function nm(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function go(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!nm(s,c.origin)){console.warn(`Invalid origin '${c.origin}' for comlink proxy`);return}const{id:l,type:m,path:y}=Object.assign({path:[]},c.data),f=(c.data.argumentList||[]).map(br);let b;try{const h=y.slice(0,-1).reduce((N,B)=>N[B],a),T=y.reduce((N,B)=>N[B],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=br(c.data.value),b=!0;break;case"APPLY":b=T.apply(h,f);break;case"CONSTRUCT":{const N=new T(...f);b=gn(N)}break;case"ENDPOINT":{const{port1:N,port2:B}=new MessageChannel;go(a,B),b=pm(N,[N])}break;case"RELEASE":b=void 0;break;default:return}}catch(h){b={value:h,[Ys]:0}}Promise.resolve(b).catch(h=>({value:h,[Ys]:0})).then(h=>{const[T,N]=ea(h);n.postMessage(Object.assign(Object.assign({},T),{id:l}),N),m==="RELEASE"&&(n.removeEventListener("message",o),bo(n),yn in a&&typeof a[yn]=="function"&&a[yn]())}).catch(h=>{const[T,N]=ea({value:new TypeError("Unserializable return value"),[Ys]:0});n.postMessage(Object.assign(Object.assign({},T),{id:l}),N)})}),n.start&&n.start()}function im(a){return a.constructor.name==="MessagePort"}function bo(a){im(a)&&a.close()}function _n(a,n){return fn(a,[],n)}function Qs(a){if(a)throw new Error("Proxy has been released and is not useable")}function xo(a){return Lr(a,{type:"RELEASE"}).then(()=>{bo(a)})}const Zs=new WeakMap,Js="FinalizationRegistry"in globalThis&&new FinalizationRegistry(a=>{const n=(Zs.get(a)||0)-1;Zs.set(a,n),n===0&&xo(a)});function om(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function lm(a){Js&&Js.unregister(a)}function fn(a,n=[],s=function(){}){let o=!1;const c=new Proxy(s,{get(l,m){if(Qs(o),m===rm)return()=>{lm(c),xo(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Lr(a,{type:"GET",path:n.map(f=>f.toString())}).then(br);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Lr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(br)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===tm)return Lr(a,{type:"ENDPOINT"}).then(br);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=ho(y);return Lr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(br)},construct(l,m){Qs(o);const[y,f]=ho(m);return Lr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(br)}});return om(c,a),c}function cm(a){return Array.prototype.concat.apply([],a)}function ho(a){const n=a.map(ea);return[n.map(s=>s[0]),cm(n.map(s=>s[1]))]}const wo=new WeakMap;function pm(a,n){return wo.set(a,n),a}function gn(a){return Object.assign(a,{[yo]:!0})}function ea(a){for(const[n,s]of fo)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},wo.get(a)||[]]}function br(a){switch(a.type){case"HANDLER":return fo.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Lr(a,n,s){return new Promise(o=>{const c=dm();a.addEventListener("message",function l(m){!m.data||!m.data.id||m.data.id!==c||(a.removeEventListener("message",l),o(m.data))}),a.start&&a.start(),a.postMessage(Object.assign({id:c},n),s)})}function dm(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const vo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-Bn8CAGnd.js").href:new URL("assets/scriptsRunWorker-Bn8CAGnd.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});vo.onerror=a=>{console.error(a)};async function To(a){return await Gs.setInlayHints(a)}const Do=_n(vo),ko=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-jsFIW02M.js").href:new URL("assets/parserTccWorker-jsFIW02M.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Us&&Us.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function Io(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=lt;return await ko.parseTcc(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function mm(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=lt;return await ko.parseLibraryCode(a,n,gn(To),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function um(a,n,s=!0){return await Do.runScript(a,n,s)}async function ym(a){return await Do.removeScript(a)}function _m(a){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:a==null?void 0:a.name})}self.MonacoEnvironment={getWorker(){return new _m({name:"Editor Worker"})}},sn.config({paths:{vs:"https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs"},"vs/nls":{availableLanguages:{"*":"zh-cn"}}});const fm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onCursorPositionChange:T,onActionTrigger:N,onEditorDidMount:B}=a,E=O.useRef(null),F=O.useRef(null),H=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(q){var R;(R=E.current)==null||R.setOriginalScript(q)},setScript(q){var R;(R=E.current)==null||R.setValue(q)},gotoLine(){var q;(q=E.current)==null||q.gotoLine()},getEditorLayout(){var q;return(q=E.current)==null?void 0:q.getEditorLayout()},setPosition(q,R){var V;(V=E.current)==null||V.setPosition({column:q,lineNumber:R})},setModelMarkers(q){var R;(R=E.current)==null||R.setModelMarkers(q)},focus(){var q;(q=E.current)==null||q.focus()}})),O.useEffect(()=>{var q,R;m?(R=E.current)==null||R.addDiffDecorations():(q=E.current)==null||q.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var q;(q=E.current)==null||q.updateActionTrigger(N)},[N]),O.useEffect(()=>{var q;h&&((q=E.current)==null||q.addLinkOpenFunc(h))},[h]);function Y(q,R){var re,ie;zt.initBuiltinsTrees(),Gs.setEditor(q),E.current=new em(q,R,N),h&&((re=E.current)==null||re.addLinkOpenFunc(h)),m&&((ie=E.current)==null||ie.addDiffDecorations()),kd(q),requestAnimationFrame(A);const V=q.getValue();E.current.onChangeCursorPosition(T),b&&b(V),!y&&G(V),B&&B()}const G=O.useCallback(async q=>{var ht;const R=Date.now();H.current=!1;const{errors:V,functions:re,methods:ie,types:xt,variables:St,overloadsFuncs:Ue,imports:Ke,enums:Z}=await Io(q),be=new Map(Object.entries(re)),Ee=new Map(Object.entries(ie)),Me=new Map(Object.entries(xt)),ct=new Map(Object.entries(St)),Et=new Map(Object.entries(Ke)),se=new Map(Object.entries(Z));gr.setUserDefined({functions:be,methods:Ee,types:Me,variables:ct,imports:Et,enums:se},Ue),zt.setUserDefind(be,Me,ct,Ee,se);const he=V.map($e=>({...$e,severity:$e.type||ke.MarkerSeverity.Error}));if(y)return;!H.current&&((ht=E.current)==null||ht.setModelMarkers(he));const Re=Date.now();console.log((Re-R)/1e3)},[y]),K=O.useMemo(()=>qd.debounce(G,1500),[G]);function U(q){var R;if(y){G(q||"");return}H.current=!0,Gs.clearInlayHints(),(R=E.current)==null||R.setModelMarkers([]),q!==void 0&&(b&&b(q),K(q))}const A=O.useCallback(()=>{var R,V;const q=(R=F.current)==null?void 0:R.getBoundingClientRect();(V=E.current)==null||V.setEditorLayout((q==null?void 0:q.height)||0,q==null?void 0:q.width)},[]);return O.useEffect(()=>{const q=()=>{window.requestAnimationFrame(A)},R=new ResizeObserver(q);return F.current&&R.observe(F.current),()=>{var V;F.current&&R.unobserve(F.current),R.disconnect(),(V=E.current)==null||V.dispose()}},[]),M.jsx("div",{ref:F,children:M.jsx(yd,{height:s,width:o||"100%",defaultLanguage:Se,defaultValue:f||`indicator("我的脚本")
145
145
  plot(close)
146
146
  `,theme:c||"vs-dark",className:`tvue-script ${c||"vs-dark"}`,options:{colorDecorators:!0,useShadowDOM:!1,matchOnWordStartOnly:!0,automaticLayout:!1,unicodeHighlight:{allowedCharacters:{" ":!0}},suggest:{filterGraceful:!0},fontSize:13,...y?Ld:{},readOnlyMessage:{value:"该脚本是只读的。它无法被编辑。"},...l},onMount:Y,onChange:U})})},gm=O.forwardRef(fm),bm=a=>{const{theme:n,modified:s,original:o,height:c,width:l,renderSideBySide:m=!0}=a,y=O.useCallback((f,b)=>{b.languages.register({id:Se}),b.editor.defineTheme("vs-dark",cn),b.editor.defineTheme("vs",ln),b.languages.setMonarchTokensProvider(Se,Nr),b.languages.setLanguageConfiguration(Se,on)},[]);return M.jsx(cd,{height:c||"90vh",width:l||"100%",theme:n||"vs-dark",options:{readOnly:!0,renderSideBySide:m,scrollBeyondLastLine:!1},language:Se,modified:s,original:o,onMount:y})};I.VMarkerSeverity=void 0,function(a){a[a.Hint=1]="Hint",a[a.Info=2]="Info",a[a.Warning=4]="Warning",a[a.Error=8]="Error"}(I.VMarkerSeverity||(I.VMarkerSeverity={}));var ta={},xm=function(){var a=document.getSelection();if(!a.rangeCount)return function(){};for(var n=document.activeElement,s=[],o=0;o<a.rangeCount;o++)s.push(a.getRangeAt(o));switch(n.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":n.blur();break;default:n=null;break}return a.removeAllRanges(),function(){a.type==="Caret"&&a.removeAllRanges(),a.rangeCount||s.forEach(function(c){a.addRange(c)}),n&&n.focus()}},hm=xm,Ao={"text/plain":"Text","text/html":"Url",default:"Text"},wm="Copy to clipboard: #{key}, Enter";function vm(a){var n=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return a.replace(/#{\s*key\s*}/g,n)}function Tm(a,n){var s,o,c,l,m,y,f=!1;n||(n={}),s=n.debug||!1;try{c=hm(),l=document.createRange(),m=document.getSelection(),y=document.createElement("span"),y.textContent=a,y.ariaHidden="true",y.style.all="unset",y.style.position="fixed",y.style.top=0,y.style.clip="rect(0, 0, 0, 0)",y.style.whiteSpace="pre",y.style.webkitUserSelect="text",y.style.MozUserSelect="text",y.style.msUserSelect="text",y.style.userSelect="text",y.addEventListener("copy",function(h){if(h.stopPropagation(),n.format)if(h.preventDefault(),typeof h.clipboardData>"u"){s&&console.warn("unable to use e.clipboardData"),s&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var T=Ao[n.format]||Ao.default;window.clipboardData.setData(T,a)}else h.clipboardData.clearData(),h.clipboardData.setData(n.format,a);n.onCopy&&(h.preventDefault(),n.onCopy(h.clipboardData))}),document.body.appendChild(y),l.selectNodeContents(y),m.addRange(l);var b=document.execCommand("copy");if(!b)throw new Error("copy command was unsuccessful");f=!0}catch(h){s&&console.error("unable to copy using execCommand: ",h),s&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(n.format||"text",a),n.onCopy&&n.onCopy(window.clipboardData),f=!0}catch(T){s&&console.error("unable to copy using clipboardData: ",T),s&&console.error("falling back to prompt"),o=vm("message"in n?n.message:wm),window.prompt(o,a)}}finally{m&&(typeof m.removeRange=="function"?m.removeRange(l):m.removeAllRanges()),y&&document.body.removeChild(y),c()}return f}var Dm=Tm;function bn(a){"@babel/helpers - typeof";return bn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},bn(a)}Object.defineProperty(ta,"__esModule",{value:!0}),ta.CopyToClipboard=void 0;var ra=qo(O),km=qo(Dm),Im=["text","onCopy","options","children"];function qo(a){return a&&a.__esModule?a:{default:a}}function Co(a,n){var s=Object.keys(a);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(a);n&&(o=o.filter(function(c){return Object.getOwnPropertyDescriptor(a,c).enumerable})),s.push.apply(s,o)}return s}function zo(a){for(var n=1;n<arguments.length;n++){var s=arguments[n]!=null?arguments[n]:{};n%2?Co(Object(s),!0).forEach(function(o){hn(a,o,s[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(s)):Co(Object(s)).forEach(function(o){Object.defineProperty(a,o,Object.getOwnPropertyDescriptor(s,o))})}return a}function Am(a,n){if(a==null)return{};var s=qm(a,n),o,c;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(a);for(c=0;c<l.length;c++)o=l[c],!(n.indexOf(o)>=0)&&Object.prototype.propertyIsEnumerable.call(a,o)&&(s[o]=a[o])}return s}function qm(a,n){if(a==null)return{};var s={},o=Object.keys(a),c,l;for(l=0;l<o.length;l++)c=o[l],!(n.indexOf(c)>=0)&&(s[c]=a[c]);return s}function Cm(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function So(a,n){for(var s=0;s<n.length;s++){var o=n[s];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(a,o.key,o)}}function zm(a,n,s){return n&&So(a.prototype,n),s&&So(a,s),Object.defineProperty(a,"prototype",{writable:!1}),a}function Sm(a,n){if(typeof n!="function"&&n!==null)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(n&&n.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),n&&xn(a,n)}function xn(a,n){return xn=Object.setPrototypeOf||function(o,c){return o.__proto__=c,o},xn(a,n)}function Em(a){var n=Lm();return function(){var o=sa(a),c;if(n){var l=sa(this).constructor;c=Reflect.construct(o,arguments,l)}else c=o.apply(this,arguments);return Nm(this,c)}}function Nm(a,n){if(n&&(bn(n)==="object"||typeof n=="function"))return n;if(n!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Eo(a)}function Eo(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Lm(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function sa(a){return sa=Object.setPrototypeOf?Object.getPrototypeOf:function(s){return s.__proto__||Object.getPrototypeOf(s)},sa(a)}function hn(a,n,s){return n in a?Object.defineProperty(a,n,{value:s,enumerable:!0,configurable:!0,writable:!0}):a[n]=s,a}var No=function(a){Sm(s,a);var n=Em(s);function s(){var o;Cm(this,s);for(var c=arguments.length,l=new Array(c),m=0;m<c;m++)l[m]=arguments[m];return o=n.call.apply(n,[this].concat(l)),hn(Eo(o),"onClick",function(y){var f=o.props,b=f.text,h=f.onCopy,T=f.children,N=f.options,B=ra.default.Children.only(T),E=(0,km.default)(b,N);h&&h(b,E),B&&B.props&&typeof B.props.onClick=="function"&&B.props.onClick(y)}),o}return zm(s,[{key:"render",value:function(){var c=this.props;c.text,c.onCopy,c.options;var l=c.children,m=Am(c,Im),y=ra.default.Children.only(l);return ra.default.cloneElement(y,zo(zo({},m),{},{onClick:this.onClick}))}}]),s}(ra.default.PureComponent);ta.CopyToClipboard=No,hn(No,"defaultProps",{onCopy:void 0,options:void 0});var Mm=ta,wn=Mm.CopyToClipboard;wn.CopyToClipboard=wn;var Pm=wn;const vn=ip(Pm);async function Om(a,n=0){const s=a[n];if(!s)return;const{name:o,args:c,type:l,desc:m,examples:y,remarks:f,seeAlso:b,syntax:h,detailedDesc:T,fields:N,returns:B}=s,E={name:o};if(a.length>1&&(E.overloads=`${a.length} overloads`),l&&(E.type=l),c&&(E.name=`${o}()`,E.args=c.map(F=>{const{name:H,desc:Y,displayType:G}=F;return{label:`${H} (${G})`,desc:Y&&xr(Y)}})),m&&(E.desc=m.map(F=>xr(F))),y&&(E.originalExample=y.join(`
147
147
  `),E.examples=await ke.editor.colorize(E.originalExample,Se,{tabSize:4})),T){E.detailedDesc=[];for(const F of T){const{desc:H,examples:Y}=F;let G=H.map(A=>xr(A)),K,U;Y&&(U=Y.join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guihz/trading-vue-editor-tes",
3
- "version": "0.0.202",
3
+ "version": "0.0.203",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"