@guihz/trading-vue-editor-tes 0.0.178 → 0.0.179
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,7 @@ ${ro}rows: ${s.rows}
|
|
59
59
|
${ro}columns: ${s.columns}
|
60
60
|
}`}function B1(s,e,t,r,n){const{rows:i,columns:a}=s,l=Math.min(i,e),c=Math.min(a,t),p=[];if(n==="auto"){n=!1;e:for(let h=0;h<l;h++)for(let f=0;f<c;f++)if(s.get(h,f)<0){n=!0;break e}}for(let h=0;h<l;h++){let f=[];for(let d=0;d<c;d++)f.push(O1(s.get(h,d),r,n));p.push(`${f.join(" ")}`)}return c!==a&&(p[p.length-1]+=` ... ${a-t} more columns`),l!==i&&p.push(`... ${i-e} more rows`),p.join(`
|
61
61
|
${zf}`)}function O1(s,e,t){return(s>=0&&t?` ${kf(s,e-1)}`:kf(s,e)).padEnd(e)}function kf(s,e){let t=s.toString();if(t.length<=e)return t;let r=s.toFixed(e);if(r.length>e&&(r=s.toFixed(Math.max(0,e-(r.length-e)))),r.length<=e&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=s.toExponential(e);return n.length>e&&(n=s.toExponential(Math.max(0,e-(n.length-e)))),n.slice(0)}function T1(s,e){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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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=e.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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(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 e(r).trunc()},s.pow=function(r,n){return new e(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=e.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 Nr(s,e,t){let r=t?s.rows:s.rows-1;if(e<0||e>r)throw new RangeError("Row index out of range")}function Sr(s,e,t){let r=t?s.columns:s.columns-1;if(e<0||e>r)throw new RangeError("Column index out of range")}function Di(s,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==s.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function bi(s,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==s.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function La(s,e){if(!ur.isAnyArray(e))throw new TypeError("row indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=s.rows)throw new RangeError("row indices are out of range")}function Ra(s,e){if(!ur.isAnyArray(e))throw new TypeError("column indices must be an array");for(let t=0;t<e.length;t++)if(e[t]<0||e[t]>=s.columns)throw new RangeError("column indices are out of range")}function Pa(s,e,t,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(io("startRow",e),io("endRow",t),io("startColumn",r),io("endColumn",n),e>t||r>n||e<0||e>=s.rows||t<0||t>=s.rows||r<0||r>=s.columns||n<0||n>=s.columns)throw new RangeError("Submatrix indices are out of range")}function no(s,e=0){let t=[];for(let r=0;r<s;r++)t.push(e);return t}function io(s,e){if(typeof e!="number")throw new TypeError(`${s} must be a number`)}function Ei(s){if(s.isEmpty())throw new Error("Empty matrix has no elements to index")}function I1(s){let e=no(s.rows);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[t]+=s.get(t,r);return e}function $1(s){let e=no(s.columns);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[r]+=s.get(t,r);return e}function L1(s){let e=0;for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)e+=s.get(t,r);return e}function R1(s){let e=no(s.rows,1);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[t]*=s.get(t,r);return e}function P1(s){let e=no(s.columns,1);for(let t=0;t<s.rows;++t)for(let r=0;r<s.columns;++r)e[r]*=s.get(t,r);return e}function z1(s){let e=1;for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)e*=s.get(t,r);return e}function q1(s,e,t){const r=s.rows,n=s.columns,i=[];for(let a=0;a<r;a++){let l=0,c=0,p=0;for(let h=0;h<n;h++)p=s.get(a,h)-t[a],l+=p,c+=p*p;e?i.push((c-l*l/n)/(n-1)):i.push((c-l*l/n)/n)}return i}function k1(s,e,t){const r=s.rows,n=s.columns,i=[];for(let a=0;a<n;a++){let l=0,c=0,p=0;for(let h=0;h<r;h++)p=s.get(h,a)-t[a],l+=p,c+=p*p;e?i.push((c-l*l/r)/(r-1)):i.push((c-l*l/r)/r)}return i}function U1(s,e,t){const r=s.rows,n=s.columns,i=r*n;let a=0,l=0,c=0;for(let p=0;p<r;p++)for(let h=0;h<n;h++)c=s.get(p,h)-t,a+=c,l+=c*c;return e?(l-a*a/i)/(i-1):(l-a*a/i)/i}function W1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e[t])}function j1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e[r])}function Y1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)-e)}function V1(s){const e=[];for(let t=0;t<s.rows;t++){let r=0;for(let n=0;n<s.columns;n++)r+=Math.pow(s.get(t,n),2)/(s.columns-1);e.push(Math.sqrt(r))}return e}function Z1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e[t])}function K1(s){const e=[];for(let t=0;t<s.columns;t++){let r=0;for(let n=0;n<s.rows;n++)r+=Math.pow(s.get(n,t),2)/(s.rows-1);e.push(Math.sqrt(r))}return e}function G1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e[r])}function H1(s){const e=s.size-1;let t=0;for(let r=0;r<s.columns;r++)for(let n=0;n<s.rows;n++)t+=Math.pow(s.get(n,r),2)/e;return Math.sqrt(t)}function J1(s,e){for(let t=0;t<s.rows;t++)for(let r=0;r<s.columns;r++)s.set(t,r,s.get(t,r)/e)}class $e{static from1DArray(e,t,r){if(e*t!==r.length)throw new RangeError("data length does not match given dimensions");let i=new pe(e,t);for(let a=0;a<e;a++)for(let l=0;l<t;l++)i.set(a,l,r[a*t+l]);return i}static rowVector(e){let t=new pe(1,e.length);for(let r=0;r<e.length;r++)t.set(0,r,e[r]);return t}static columnVector(e){let t=new pe(e.length,1);for(let r=0;r<e.length;r++)t.set(r,0,e[r]);return t}static zeros(e,t){return new pe(e,t)}static ones(e,t){return new pe(e,t).fill(1)}static rand(e,t,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let i=new pe(e,t);for(let a=0;a<e;a++)for(let l=0;l<t;l++)i.set(a,l,n());return i}static randInt(e,t,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 pe(e,t);for(let p=0;p<e;p++)for(let h=0;h<t;h++){let f=n+Math.round(a()*l);c.set(p,h,f)}return c}static eye(e,t,r){t===void 0&&(t=e),r===void 0&&(r=1);let n=Math.min(e,t),i=this.zeros(e,t);for(let a=0;a<n;a++)i.set(a,a,r);return i}static diag(e,t,r){let n=e.length;t===void 0&&(t=n),r===void 0&&(r=t);let i=Math.min(n,t,r),a=this.zeros(t,r);for(let l=0;l<i;l++)a.set(l,l,e[l]);return a}static min(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,n=e.columns,i=new pe(r,n);for(let a=0;a<r;a++)for(let l=0;l<n;l++)i.set(a,l,Math.min(e.get(a,l),t.get(a,l)));return i}static max(e,t){e=this.checkMatrix(e),t=this.checkMatrix(t);let r=e.rows,n=e.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(e.get(a,l),t.get(a,l)));return i}static checkMatrix(e){return $e.isMatrix(e)?e:new pe(e)}static isMatrix(e){return e!=null&&e.klass==="Matrix"}get size(){return this.rows*this.columns}apply(e){if(typeof e!="function")throw new TypeError("callback must be a function");for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.call(this,t,r);return this}to1DArray(){let e=[];for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}to2DArray(){let e=[];for(let t=0;t<this.rows;t++){e.push([]);for(let r=0;r<this.columns;r++)e[t].push(this.get(t,r))}return e}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let e=0;e<this.rows;e++)for(let t=0;t<=e;t++)if(this.get(e,t)!==this.get(t,e))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let e=0;e<this.rows;e++)if(this.get(e,e)!==0)return!1;return!0}isEchelonForm(){let e=0,t=0,r=-1,n=!0,i=!1;for(;e<this.rows&&n;){for(t=0,i=!1;t<this.columns&&i===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(i=!0,r=t):(n=!1,i=!0);e++}return n}isReducedEchelonForm(){let e=0,t=0,r=-1,n=!0,i=!1;for(;e<this.rows&&n;){for(t=0,i=!1;t<this.columns&&i===!1;)this.get(e,t)===0?t++:this.get(e,t)===1&&t>r?(i=!0,r=t):(n=!1,i=!0);for(let a=t+1;a<this.rows;a++)this.get(e,a)!==0&&(n=!1);e++}return n}echelonForm(){let e=this.clone(),t=0,r=0;for(;t<e.rows&&r<e.columns;){let n=t;for(let i=t;i<e.rows;i++)e.get(i,r)>e.get(n,r)&&(n=i);if(e.get(n,r)===0)r++;else{e.swapRows(t,n);let i=e.get(t,r);for(let a=r;a<e.columns;a++)e.set(t,a,e.get(t,a)/i);for(let a=t+1;a<e.rows;a++){let l=e.get(a,r)/e.get(t,r);e.set(a,r,0);for(let c=r+1;c<e.columns;c++)e.set(a,c,e.get(a,c)-e.get(t,c)*l)}t++,r++}}return e}reducedEchelonForm(){let e=this.echelonForm(),t=e.columns,r=e.rows,n=r-1;for(;n>=0;)if(e.maxRow(n)===0)n--;else{let i=0,a=!1;for(;i<r&&a===!1;)e.get(n,i)===1?a=!0:i++;for(let l=0;l<n;l++){let c=e.get(l,i);for(let p=i;p<t;p++){let h=e.get(l,p)-c*e.get(n,p);e.set(l,p,h)}}n--}return e}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{rows:t=1,columns:r=1}=e;if(!Number.isInteger(t)||t<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new pe(this.rows*t,this.columns*r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)n.setSubMatrix(this,this.rows*i,this.columns*a);return n}fill(e){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,e);return this}neg(){return this.mulS(-1)}getRow(e){Nr(this,e);let t=[];for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}getRowVector(e){return pe.rowVector(this.getRow(e))}setRow(e,t){Nr(this,e),t=Di(this,t);for(let r=0;r<this.columns;r++)this.set(e,r,t[r]);return this}swapRows(e,t){Nr(this,e),Nr(this,t);for(let r=0;r<this.columns;r++){let n=this.get(e,r);this.set(e,r,this.get(t,r)),this.set(t,r,n)}return this}getColumn(e){Sr(this,e);let t=[];for(let r=0;r<this.rows;r++)t.push(this.get(r,e));return t}getColumnVector(e){return pe.columnVector(this.getColumn(e))}setColumn(e,t){Sr(this,e),t=bi(this,t);for(let r=0;r<this.rows;r++)this.set(r,e,t[r]);return this}swapColumns(e,t){Sr(this,e),Sr(this,t);for(let r=0;r<this.rows;r++){let n=this.get(r,e);this.set(r,e,this.get(r,t)),this.set(r,t,n)}return this}addRowVector(e){e=Di(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[r]);return this}subRowVector(e){e=Di(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[r]);return this}mulRowVector(e){e=Di(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[r]);return this}divRowVector(e){e=Di(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[r]);return this}addColumnVector(e){e=bi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)+e[t]);return this}subColumnVector(e){e=bi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)-e[t]);return this}mulColumnVector(e){e=bi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e[t]);return this}divColumnVector(e){e=bi(this,e);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)/e[t]);return this}mulRow(e,t){Nr(this,e);for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this}mulColumn(e,t){Sr(this,e);for(let r=0;r<this.rows;r++)this.set(r,e,this.get(r,e)*t);return this}max(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t[r]&&(t[r]=this.get(r,n));return t}case"column":{const t=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)>t[n]&&(t[n]=this.get(r,n));return t}case void 0:{let t=this.get(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));return t}default:throw new Error(`invalid option: ${e}`)}}maxIndex(){Ei(this);let e=this.get(0,0),t=[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),t[0]=r,t[1]=n);return t}min(e){if(this.isEmpty())return NaN;switch(e){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t[r]&&(t[r]=this.get(r,n));return t}case"column":{const t=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)<t[n]&&(t[n]=this.get(r,n));return t}case void 0:{let t=this.get(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));return t}default:throw new Error(`invalid option: ${e}`)}}minIndex(){Ei(this);let e=this.get(0,0),t=[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),t[0]=r,t[1]=n);return t}maxRow(e){if(Nr(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxRowIndex(e){Nr(this,e),Ei(this);let t=this.get(e,0),r=[e,0];for(let n=1;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[1]=n);return r}minRow(e){if(Nr(this,e),this.isEmpty())return NaN;let t=this.get(e,0);for(let r=1;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minRowIndex(e){Nr(this,e),Ei(this);let t=this.get(e,0),r=[e,0];for(let n=1;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[1]=n);return r}maxColumn(e){if(Sr(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)>t&&(t=this.get(r,e));return t}maxColumnIndex(e){Sr(this,e),Ei(this);let t=this.get(0,e),r=[0,e];for(let n=1;n<this.rows;n++)this.get(n,e)>t&&(t=this.get(n,e),r[0]=n);return r}minColumn(e){if(Sr(this,e),this.isEmpty())return NaN;let t=this.get(0,e);for(let r=1;r<this.rows;r++)this.get(r,e)<t&&(t=this.get(r,e));return t}minColumnIndex(e){Sr(this,e),Ei(this);let t=this.get(0,e),r=[0,e];for(let n=1;n<this.rows;n++)this.get(n,e)<t&&(t=this.get(n,e),r[0]=n);return r}diag(){let e=Math.min(this.rows,this.columns),t=[];for(let r=0;r<e;r++)t.push(this.get(r,r));return t}norm(e="frobenius"){switch(e){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${e}`)}}cumulativeSum(){let e=0;for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r),this.set(t,r,e);return this}dot(e){$e.isMatrix(e)&&(e=e.to1DArray());let t=this.to1DArray();if(t.length!==e.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<t.length;n++)r+=t[n]*e[n];return r}mmul(e){e=pe.checkMatrix(e);let t=this.rows,r=this.columns,n=e.columns,i=new pe(t,n),a=new Float64Array(r);for(let l=0;l<n;l++){for(let c=0;c<r;c++)a[c]=e.get(c,l);for(let c=0;c<t;c++){let p=0;for(let h=0;h<r;h++)p+=this.get(c,h)*a[h];i.set(c,l,p)}}return i}strassen2x2(e){e=pe.checkMatrix(e);let t=new pe(2,2);const r=this.get(0,0),n=e.get(0,0),i=this.get(0,1),a=e.get(0,1),l=this.get(1,0),c=e.get(1,0),p=this.get(1,1),h=e.get(1,1),f=(r+p)*(n+h),d=(l+p)*n,g=r*(a-h),y=p*(c-n),m=(r+i)*h,w=(l-r)*(n+a),v=(i-p)*(c+h),E=f+y-m+v,b=g+m,N=d+y,x=f-d+g+w;return t.set(0,0,E),t.set(0,1,b),t.set(1,0,N),t.set(1,1,x),t}strassen3x3(e){e=pe.checkMatrix(e);let t=new pe(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),p=this.get(2,0),h=this.get(2,1),f=this.get(2,2),d=e.get(0,0),g=e.get(0,1),y=e.get(0,2),m=e.get(1,0),w=e.get(1,1),v=e.get(1,2),E=e.get(2,0),b=e.get(2,1),N=e.get(2,2),x=(r+n+i-a-l-h-f)*w,F=(r-a)*(-g+w),M=l*(-d+g+m-w-v-E+N),S=(-r+a+l)*(d-g+w),I=(a+l)*(-d+g),C=r*d,B=(-r+p+h)*(d-y+v),L=(-r+p)*(y-v),U=(p+h)*(-d+y),k=(r+n+i-l-c-p-h)*v,W=h*(-d+y+m-w-v-E+b),z=(-i+h+f)*(w+E-b),K=(i-f)*(w-b),Z=i*E,X=(h+f)*(-E+b),Q=(-i+l+c)*(v+E-N),ce=(i-c)*(v-N),ve=(l+c)*(-E+N),le=n*m,we=c*b,be=a*y,Be=p*g,Ee=f*N,ot=C+Z+le,Te=x+S+I+C+z+Z+X,Ne=C+B+U+k+Z+Q+ve,lt=F+M+S+C+Z+Q+ce,rt=F+S+I+C+we,ke=Z+Q+ce+ve+be,Je=C+B+L+W+z+K+Z,$t=z+K+Z+X+Be,mr=C+B+L+U+Ee;return t.set(0,0,ot),t.set(0,1,Te),t.set(0,2,Ne),t.set(1,0,lt),t.set(1,1,rt),t.set(1,2,ke),t.set(2,0,Je),t.set(2,1,$t),t.set(2,2,mr),t}mmulStrassen(e){e=pe.checkMatrix(e);let t=this.clone(),r=t.rows,n=t.columns,i=e.rows,a=e.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=$e.zeros(d,g);return w=w.setSubMatrix(f,0,0),w}}let c=Math.max(r,i),p=Math.max(n,a);t=l(t,c,p),e=l(e,c,p);function h(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),E=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),x=f.subMatrix(m,f.rows-1,0,w-1),F=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),I=h($e.add(v,M),$e.add(E,S),m,w),C=h($e.add(x,M),E,m,w),B=h(v,$e.sub(N,S),m,w),L=h(M,$e.sub(F,E),m,w),U=h($e.add(v,b),S,m,w),k=h($e.sub(x,v),$e.add(E,N),m,w),W=h($e.sub(b,M),$e.add(F,S),m,w),z=$e.add(I,L);z.sub(U),z.add(W);let K=$e.add(B,U),Z=$e.add(C,L),X=$e.sub(I,C);X.add(B),X.add(k);let Q=$e.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 h(t,e,c,p)}scaleRows(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let n=new pe(this.rows,this.columns);for(let i=0;i<this.rows;i++){const a=this.getRow(i);a.length>0&&Pf(a,{min:t,max:r,output:a}),n.setRow(i,a)}return n}scaleColumns(e={}){if(typeof e!="object")throw new TypeError("options must be an object");const{min:t=0,max:r=1}=e;if(!Number.isFinite(t))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(t>=r)throw new RangeError("min must be smaller than max");let n=new pe(this.rows,this.columns);for(let i=0;i<this.columns;i++){const a=this.getColumn(i);a.length&&Pf(a,{min:t,max:r,output:a}),n.setColumn(i,a)}return n}flipRows(){const e=Math.ceil(this.columns/2);for(let t=0;t<this.rows;t++)for(let r=0;r<e;r++){let n=this.get(t,r),i=this.get(t,this.columns-1-r);this.set(t,r,i),this.set(t,this.columns-1-r,n)}return this}flipColumns(){const e=Math.ceil(this.rows/2);for(let t=0;t<this.columns;t++)for(let r=0;r<e;r++){let n=this.get(r,t),i=this.get(this.rows-1-r,t);this.set(r,t,i),this.set(this.rows-1-r,t,n)}return this}kroneckerProduct(e){e=pe.checkMatrix(e);let t=this.rows,r=this.columns,n=e.rows,i=e.columns,a=new pe(t*n,r*i);for(let l=0;l<t;l++)for(let c=0;c<r;c++)for(let p=0;p<n;p++)for(let h=0;h<i;h++)a.set(n*l+p,i*c+h,this.get(l,c)*e.get(p,h));return a}kroneckerSum(e){if(e=pe.checkMatrix(e),!this.isSquare()||!e.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let t=this.rows,r=e.rows,n=this.kroneckerProduct(pe.eye(r,r)),i=pe.eye(t,t).kroneckerProduct(e);return n.add(i)}transpose(){let e=new pe(this.columns,this.rows);for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e.set(r,t,this.get(t,r));return e}sortRows(e=Uf){for(let t=0;t<this.rows;t++)this.setRow(t,this.getRow(t).sort(e));return this}sortColumns(e=Uf){for(let t=0;t<this.columns;t++)this.setColumn(t,this.getColumn(t).sort(e));return this}subMatrix(e,t,r,n){Pa(this,e,t,r,n);let i=new pe(t-e+1,n-r+1);for(let a=e;a<=t;a++)for(let l=r;l<=n;l++)i.set(a-e,l-r,this.get(a,l));return i}subMatrixRow(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.columns-1),t>r||t<0||t>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new pe(e.length,r-t+1);for(let i=0;i<e.length;i++)for(let a=t;a<=r;a++){if(e[i]<0||e[i]>=this.rows)throw new RangeError(`Row index out of range: ${e[i]}`);n.set(i,a-t,this.get(e[i],a))}return n}subMatrixColumn(e,t,r){if(t===void 0&&(t=0),r===void 0&&(r=this.rows-1),t>r||t<0||t>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new pe(r-t+1,e.length);for(let i=0;i<e.length;i++)for(let a=t;a<=r;a++){if(e[i]<0||e[i]>=this.columns)throw new RangeError(`Column index out of range: ${e[i]}`);n.set(a-t,i,this.get(a,e[i]))}return n}setSubMatrix(e,t,r){if(e=pe.checkMatrix(e),e.isEmpty())return this;let n=t+e.rows-1,i=r+e.columns-1;Pa(this,t,n,r,i);for(let a=0;a<e.rows;a++)for(let l=0;l<e.columns;l++)this.set(t+a,r+l,e.get(a,l));return this}selection(e,t){La(this,e),Ra(this,t);let r=new pe(e.length,t.length);for(let n=0;n<e.length;n++){let i=e[n];for(let a=0;a<t.length;a++){let l=t[a];r.set(n,a,this.get(i,l))}}return r}trace(){let e=Math.min(this.rows,this.columns),t=0;for(let r=0;r<e;r++)t+=this.get(r,r);return t}clone(){return this.constructor.copy(this,new pe(this.rows,this.columns))}static copy(e,t){for(const[r,n,i]of e.entries())t.set(r,n,i);return t}sum(e){switch(e){case"row":return I1(this);case"column":return $1(this);case void 0:return L1(this);default:throw new Error(`invalid option: ${e}`)}}product(e){switch(e){case"row":return R1(this);case"column":return P1(this);case void 0:return z1(this);default:throw new Error(`invalid option: ${e}`)}}mean(e){const t=this.sum(e);switch(e){case"row":{for(let r=0;r<this.rows;r++)t[r]/=this.columns;return t}case"column":{for(let r=0;r<this.columns;r++)t[r]/=this.rows;return t}case void 0:return t/this.size;default:throw new Error(`invalid option: ${e}`)}}variance(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(e)}=t;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(e){case"row":{if(!ur.isAnyArray(n))throw new TypeError("mean must be an array");return q1(this,r,n)}case"column":{if(!ur.isAnyArray(n))throw new TypeError("mean must be an array");return k1(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return U1(this,r,n)}default:throw new Error(`invalid option: ${e}`)}}standardDeviation(e,t){typeof e=="object"&&(t=e,e=void 0);const r=this.variance(e,t);if(e===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");const{center:r=this.mean(e)}=t;switch(e){case"row":{if(!ur.isAnyArray(r))throw new TypeError("center must be an array");return W1(this,r),this}case"column":{if(!ur.isAnyArray(r))throw new TypeError("center must be an array");return j1(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: ${e}`)}}scale(e,t={}){if(typeof e=="object"&&(t=e,e=void 0),typeof t!="object")throw new TypeError("options must be an object");let r=t.scale;switch(e){case"row":{if(r===void 0)r=V1(this);else if(!ur.isAnyArray(r))throw new TypeError("scale must be an array");return Z1(this,r),this}case"column":{if(r===void 0)r=K1(this);else if(!ur.isAnyArray(r))throw new TypeError("scale must be an array");return G1(this,r),this}case void 0:{if(r===void 0)r=H1(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return J1(this,r),this}default:throw new Error(`invalid option: ${e}`)}}toString(e){return qf(this,e)}[Symbol.iterator](){return this.entries()}*entries(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield[e,t,this.get(e,t)]}*values(){for(let e=0;e<this.rows;e++)for(let t=0;t<this.columns;t++)yield this.get(e,t)}}$e.prototype.klass="Matrix",typeof Symbol<"u"&&($e.prototype[Symbol.for("nodejs.util.inspect.custom")]=S1);function Uf(s,e){return s-e}function X1(s){return s.every(e=>typeof e=="number")}$e.random=$e.rand,$e.randomInt=$e.randInt,$e.diagonal=$e.diag,$e.prototype.diagonal=$e.prototype.diag,$e.identity=$e.eye,$e.prototype.negate=$e.prototype.neg,$e.prototype.tensorProduct=$e.prototype.kroneckerProduct;let pe=(Ni=class extends $e{constructor(t,r){super();Cl(this,is);R(this,"data");if(Ni.isMatrix(t))Fl(this,is,Ml).call(this,t.rows,t.columns),Ni.copy(t,this);else if(Number.isInteger(t)&&t>=0)Fl(this,is,Ml).call(this,t,r);else if(ur.isAnyArray(t)){const n=t;if(t=n.length,r=t?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<t;i++){if(n[i].length!==r)throw new RangeError("Inconsistent array dimensions");if(!X1(n[i]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[i]))}this.rows=t,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(t,r,n){return this.data[t][r]=n,this}get(t,r){return this.data[t][r]}removeRow(t){return Nr(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,r){return r===void 0&&(r=t,t=this.rows),Nr(this,t,!0),r=Float64Array.from(Di(this,r)),this.data.splice(t,0,r),this.rows+=1,this}removeColumn(t){Sr(this,t);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let i=0;i<t;i++)n[i]=this.data[r][i];for(let i=t+1;i<this.columns;i++)n[i-1]=this.data[r][i];this.data[r]=n}return this.columns-=1,this}addColumn(t,r){typeof r>"u"&&(r=t,t=this.columns),Sr(this,t,!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<t;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}},is=new WeakSet,Ml=function(t,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<t;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=t,this.columns=r},Ni);T1($e,pe);const go=class go extends $e{constructor(t){super();Cl(this,Jt,void 0);if(pe.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");ua(this,Jt,pe.copy(t,new pe(t.rows,t.rows)))}else if(Number.isInteger(t)&&t>=0)ua(this,Jt,new pe(t,t));else if(ua(this,Jt,new pe(t)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Jr(this,Jt).size}get rows(){return Jr(this,Jt).rows}get columns(){return Jr(this,Jt).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return pe.isMatrix(t)&&t.klassType==="SymmetricMatrix"}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}clone(){const t=new go(this.diagonalSize);for(const[r,n,i]of this.upperRightEntries())t.set(r,n,i);return t}toMatrix(){return new pe(this)}get(t,r){return Jr(this,Jt).get(t,r)}set(t,r,n){return Jr(this,Jt).set(t,r,n),Jr(this,Jt).set(r,t,n),this}removeCross(t){return Jr(this,Jt).removeRow(t),Jr(this,Jt).removeColumn(t),this}addCross(t,r){r===void 0&&(r=t,t=this.diagonalSize);const n=r.slice();return n.splice(t,1),Jr(this,Jt).addRow(t,n),Jr(this,Jt).addColumn(t,r),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,i]of t.entries())i||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:t}=this,r=new Array(t*(t+1)/2);for(let n=0,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=t&&(n=++i);return r}static fromCompact(t){const r=t.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(t)}`);const i=new go(n);for(let a=0,l=0,c=0;c<r;c++)i.set(a,l,t[c]),++a>=n&&(a=++l);return i}*upperRightEntries(){for(let t=0,r=0;t<this.diagonalSize;void 0){const n=this.get(t,r);yield[t,r,n],++r>=this.diagonalSize&&(r=++t)}}*upperRightValues(){for(let t=0,r=0;t<this.diagonalSize;void 0)yield this.get(t,r),++r>=this.diagonalSize&&(r=++t)}};Jt=new WeakMap;let Xn=go;Xn.prototype.klassType="SymmetricMatrix";class so extends Xn{static isDistanceMatrix(e){return Xn.isSymmetricMatrix(e)&&e.klassSubType==="DistanceMatrix"}constructor(e){if(super(e),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(e,t,r){return e===t&&(r=0),super.set(e,t,r)}addCross(e,t){return t===void 0&&(t=e,e=this.diagonalSize),t=t.slice(),t[e]=0,super.addCross(e,t)}toSymmetricMatrix(){return new Xn(this)}clone(){const e=new so(this.diagonalSize);for(const[t,r,n]of this.upperRightEntries())t!==r&&e.set(t,r,n);return e}toCompact(){const{diagonalSize:e}=this,t=(e-1)*e/2,r=new Array(t);for(let n=1,i=0,a=0;a<r.length;a++)r[a]=this.get(i,n),++n>=e&&(n=++i+1);return r}static fromCompact(e){const t=e.length,r=(Math.sqrt(8*t+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(e)}`);const n=new this(r);for(let i=1,a=0,l=0;l<t;l++)n.set(i,a,e[l]),++i>=r&&(i=++a+1);return n}}so.prototype.klassSubType="DistanceMatrix";class fn extends $e{constructor(e,t,r){super(),this.matrix=e,this.rows=t,this.columns=r}}class Q1 extends fn{constructor(e,t){Sr(e,t),super(e,e.rows,1),this.column=t}set(e,t,r){return this.matrix.set(e,this.column,r),this}get(e){return this.matrix.get(e,this.column)}}class ey extends fn{constructor(e,t){Ra(e,t),super(e,e.rows,t.length),this.columnIndices=t}set(e,t,r){return this.matrix.set(e,this.columnIndices[t],r),this}get(e,t){return this.matrix.get(e,this.columnIndices[t])}}class ty extends fn{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(e,this.columns-t-1,r),this}get(e,t){return this.matrix.get(e,this.columns-t-1)}}class ry extends fn{constructor(e){super(e,e.rows,e.columns)}set(e,t,r){return this.matrix.set(this.rows-e-1,t,r),this}get(e,t){return this.matrix.get(this.rows-e-1,t)}}class ny extends fn{constructor(e,t){Nr(e,t),super(e,1,e.columns),this.row=t}set(e,t,r){return this.matrix.set(this.row,t,r),this}get(e,t){return this.matrix.get(this.row,t)}}class iy extends fn{constructor(e,t){La(e,t),super(e,t.length,e.columns),this.rowIndices=t}set(e,t,r){return this.matrix.set(this.rowIndices[e],t,r),this}get(e,t){return this.matrix.get(this.rowIndices[e],t)}}class oo extends fn{constructor(e,t,r){La(e,t),Ra(e,r),super(e,t.length,r.length),this.rowIndices=t,this.columnIndices=r}set(e,t,r){return this.matrix.set(this.rowIndices[e],this.columnIndices[t],r),this}get(e,t){return this.matrix.get(this.rowIndices[e],this.columnIndices[t])}}class sy extends fn{constructor(e,t,r,n,i){Pa(e,t,r,n,i),super(e,r-t+1,i-n+1),this.startRow=t,this.startColumn=n}set(e,t,r){return this.matrix.set(this.startRow+e,this.startColumn+t,r),this}get(e,t){return this.matrix.get(this.startRow+e,this.startColumn+t)}}class oy extends fn{constructor(e){super(e,e.columns,e.rows)}set(e,t,r){return this.matrix.set(t,e,r),this}get(e,t){return this.matrix.get(t,e)}}class Wf extends $e{constructor(e,t={}){const{rows:r=1}=t;if(e.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=e.length/r,this.data=e}set(e,t,r){let n=this._calculateIndex(e,t);return this.data[n]=r,this}get(e,t){let r=this._calculateIndex(e,t);return this.data[r]}_calculateIndex(e,t){return e*this.columns+t}}class _r extends $e{constructor(e){super(),this.data=e,this.rows=e.length,this.columns=e[0].length}set(e,t,r){return this.data[e][t]=r,this}get(e,t){return this.data[e][t]}}function ay(s,e){if(ur.isAnyArray(s))return s[0]&&ur.isAnyArray(s[0])?new _r(s):new Wf(s,e);throw new Error("the argument is not an array")}class ao{constructor(e){e=_r.checkMatrix(e);let t=e.clone(),r=t.rows,n=t.columns,i=new Float64Array(r),a=1,l,c,p,h,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]=t.get(l,c);for(l=0;l<r;l++){for(m=Math.min(l,c),f=0,p=0;p<m;p++)f+=t.get(l,p)*y[p];y[l]-=f,t.set(l,c,y[l])}for(h=c,l=c+1;l<r;l++)Math.abs(y[l])>Math.abs(y[h])&&(h=l);if(h!==c){for(p=0;p<n;p++)d=t.get(h,p),t.set(h,p,t.get(c,p)),t.set(c,p,d);g=i[h],i[h]=i[c],i[c]=g,a=-a}if(c<r&&t.get(c,c)!==0)for(l=c+1;l<r;l++)t.set(l,c,t.get(l,c)/t.get(c,c))}this.LU=t,this.pivotVector=i,this.pivotSign=a}isSingular(){let e=this.LU,t=e.columns;for(let r=0;r<t;r++)if(e.get(r,r)===0)return!0;return!1}solve(e){e=pe.checkMatrix(e);let t=this.LU;if(t.rows!==e.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=e.columns,i=e.subMatrixRow(this.pivotVector,0,n-1),a=t.columns,l,c,p;for(p=0;p<a;p++)for(l=p+1;l<a;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(p,c)*t.get(l,p));for(p=a-1;p>=0;p--){for(c=0;c<n;c++)i.set(p,c,i.get(p,c)/t.get(p,p));for(l=0;l<p;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(p,c)*t.get(l,p))}return i}get determinant(){let e=this.LU;if(!e.isSquare())throw new Error("Matrix must be square");let t=this.pivotSign,r=e.columns;for(let n=0;n<r;n++)t*=e.get(n,n);return t}get lowerTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,n=new pe(t,r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)i>a?n.set(i,a,e.get(i,a)):i===a?n.set(i,a,1):n.set(i,a,0);return n}get upperTriangularMatrix(){let e=this.LU,t=e.rows,r=e.columns,n=new pe(t,r);for(let i=0;i<t;i++)for(let a=0;a<r;a++)i<=a?n.set(i,a,e.get(i,a)):n.set(i,a,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function hn(s,e){let t=0;return Math.abs(s)>Math.abs(e)?(t=e/s,Math.abs(s)*Math.sqrt(1+t*t)):e!==0?(t=s/e,Math.abs(e)*Math.sqrt(1+t*t)):0}class za{constructor(e){e=_r.checkMatrix(e);let t=e.clone(),r=e.rows,n=e.columns,i=new Float64Array(n),a,l,c,p;for(c=0;c<n;c++){let h=0;for(a=c;a<r;a++)h=hn(h,t.get(a,c));if(h!==0){for(t.get(c,c)<0&&(h=-h),a=c;a<r;a++)t.set(a,c,t.get(a,c)/h);for(t.set(c,c,t.get(c,c)+1),l=c+1;l<n;l++){for(p=0,a=c;a<r;a++)p+=t.get(a,c)*t.get(a,l);for(p=-p/t.get(c,c),a=c;a<r;a++)t.set(a,l,t.get(a,l)+p*t.get(a,c))}}i[c]=-h}this.QR=t,this.Rdiag=i}solve(e){e=pe.checkMatrix(e);let t=this.QR,r=t.rows;if(e.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=e.columns,i=e.clone(),a=t.columns,l,c,p,h;for(p=0;p<a;p++)for(c=0;c<n;c++){for(h=0,l=p;l<r;l++)h+=t.get(l,p)*i.get(l,c);for(h=-h/t.get(p,p),l=p;l<r;l++)i.set(l,c,i.get(l,c)+h*t.get(l,p))}for(p=a-1;p>=0;p--){for(c=0;c<n;c++)i.set(p,c,i.get(p,c)/this.Rdiag[p]);for(l=0;l<p;l++)for(c=0;c<n;c++)i.set(l,c,i.get(l,c)-i.get(p,c)*t.get(l,p))}return i.subMatrix(0,a-1,0,n-1)}isFullRank(){let e=this.QR.columns;for(let t=0;t<e;t++)if(this.Rdiag[t]===0)return!1;return!0}get upperTriangularMatrix(){let e=this.QR,t=e.columns,r=new pe(t,t),n,i;for(n=0;n<t;n++)for(i=0;i<t;i++)n<i?r.set(n,i,e.get(n,i)):n===i?r.set(n,i,this.Rdiag[n]):r.set(n,i,0);return r}get orthogonalMatrix(){let e=this.QR,t=e.rows,r=e.columns,n=new pe(t,r),i,a,l,c;for(l=r-1;l>=0;l--){for(i=0;i<t;i++)n.set(i,l,0);for(n.set(l,l,1),a=l;a<r;a++)if(e.get(l,l)!==0){for(c=0,i=l;i<t;i++)c+=e.get(i,l)*n.get(i,a);for(c=-c/e.get(l,l),i=l;i<t;i++)n.set(i,a,n.get(i,a)+c*e.get(i,l))}}return n}}class xi{constructor(e,t={}){if(e=_r.checkMatrix(e),e.isEmpty())throw new Error("Matrix must be non-empty");let r=e.rows,n=e.columns;const{computeLeftSingularVectors:i=!0,computeRightSingularVectors:a=!0,autoTranspose:l=!1}=t;let c=!!i,p=!!a,h=!1,f;if(r<n)if(!l)f=e.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{f=e.transpose(),r=f.rows,n=f.columns,h=!0;let C=c;c=p,p=C}else f=e.clone();let d=Math.min(r,n),g=Math.min(r+1,n),y=new Float64Array(g),m=new pe(r,d),w=new pe(n,n),v=new Float64Array(n),E=new Float64Array(r),b=new Float64Array(g);for(let C=0;C<g;C++)b[C]=C;let N=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),F=Math.max(N,x);for(let C=0;C<F;C++){if(C<N){y[C]=0;for(let B=C;B<r;B++)y[C]=hn(y[C],f.get(B,C));if(y[C]!==0){f.get(C,C)<0&&(y[C]=-y[C]);for(let B=C;B<r;B++)f.set(B,C,f.get(B,C)/y[C]);f.set(C,C,f.get(C,C)+1)}y[C]=-y[C]}for(let B=C+1;B<n;B++){if(C<N&&y[C]!==0){let L=0;for(let U=C;U<r;U++)L+=f.get(U,C)*f.get(U,B);L=-L/f.get(C,C);for(let U=C;U<r;U++)f.set(U,B,f.get(U,B)+L*f.get(U,C))}v[B]=f.get(C,B)}if(c&&C<N)for(let B=C;B<r;B++)m.set(B,C,f.get(B,C));if(C<x){v[C]=0;for(let B=C+1;B<n;B++)v[C]=hn(v[C],v[B]);if(v[C]!==0){v[C+1]<0&&(v[C]=0-v[C]);for(let B=C+1;B<n;B++)v[B]/=v[C];v[C+1]+=1}if(v[C]=-v[C],C+1<r&&v[C]!==0){for(let B=C+1;B<r;B++)E[B]=0;for(let B=C+1;B<r;B++)for(let L=C+1;L<n;L++)E[B]+=v[L]*f.get(B,L);for(let B=C+1;B<n;B++){let L=-v[B]/v[C+1];for(let U=C+1;U<r;U++)f.set(U,B,f.get(U,B)+L*E[U])}}if(p)for(let B=C+1;B<n;B++)w.set(B,C,v[B])}}let M=Math.min(n,r+1);if(N<n&&(y[N]=f.get(N,N)),r<M&&(y[M-1]=0),x+1<M&&(v[x]=f.get(x,M-1)),v[M-1]=0,c){for(let C=N;C<d;C++){for(let B=0;B<r;B++)m.set(B,C,0);m.set(C,C,1)}for(let C=N-1;C>=0;C--)if(y[C]!==0){for(let B=C+1;B<d;B++){let L=0;for(let U=C;U<r;U++)L+=m.get(U,C)*m.get(U,B);L=-L/m.get(C,C);for(let U=C;U<r;U++)m.set(U,B,m.get(U,B)+L*m.get(U,C))}for(let B=C;B<r;B++)m.set(B,C,-m.get(B,C));m.set(C,C,1+m.get(C,C));for(let B=0;B<C-1;B++)m.set(B,C,0)}else{for(let B=0;B<r;B++)m.set(B,C,0);m.set(C,C,1)}}if(p)for(let C=n-1;C>=0;C--){if(C<x&&v[C]!==0)for(let B=C+1;B<n;B++){let L=0;for(let U=C+1;U<n;U++)L+=w.get(U,C)*w.get(U,B);L=-L/w.get(C+1,C);for(let U=C+1;U<n;U++)w.set(U,B,w.get(U,B)+L*w.get(U,C))}for(let B=0;B<n;B++)w.set(B,C,0);w.set(C,C,1)}let S=M-1,I=Number.EPSILON;for(;M>0;){let C,B;for(C=M-2;C>=-1&&C!==-1;C--){const L=Number.MIN_VALUE+I*Math.abs(y[C]+Math.abs(y[C+1]));if(Math.abs(v[C])<=L||Number.isNaN(v[C])){v[C]=0;break}}if(C===M-2)B=4;else{let L;for(L=M-1;L>=C&&L!==C;L--){let U=(L!==M?Math.abs(v[L]):0)+(L!==C+1?Math.abs(v[L-1]):0);if(Math.abs(y[L])<=I*U){y[L]=0;break}}L===C?B=3:L===M-1?B=1:(B=2,C=L)}switch(C++,B){case 1:{let L=v[M-2];v[M-2]=0;for(let U=M-2;U>=C;U--){let k=hn(y[U],L),W=y[U]/k,z=L/k;if(y[U]=k,U!==C&&(L=-z*v[U-1],v[U-1]=W*v[U-1]),p)for(let K=0;K<n;K++)k=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,k)}break}case 2:{let L=v[C-1];v[C-1]=0;for(let U=C;U<M;U++){let k=hn(y[U],L),W=y[U]/k,z=L/k;if(y[U]=k,L=-z*v[U],v[U]=W*v[U],c)for(let K=0;K<r;K++)k=W*m.get(K,U)+z*m.get(K,C-1),m.set(K,C-1,-z*m.get(K,U)+W*m.get(K,C-1)),m.set(K,U,k)}break}case 3:{const L=Math.max(Math.abs(y[M-1]),Math.abs(y[M-2]),Math.abs(v[M-2]),Math.abs(y[C]),Math.abs(v[C])),U=y[M-1]/L,k=y[M-2]/L,W=v[M-2]/L,z=y[C]/L,K=v[C]/L,Z=((k+U)*(k-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 ce=(z+U)*(z-U)+Q,ve=z*K;for(let le=C;le<M-1;le++){let we=hn(ce,ve);we===0&&(we=Number.MIN_VALUE);let be=ce/we,Be=ve/we;if(le!==C&&(v[le-1]=we),ce=be*y[le]+Be*v[le],v[le]=be*v[le]-Be*y[le],ve=Be*y[le+1],y[le+1]=be*y[le+1],p)for(let Ee=0;Ee<n;Ee++)we=be*w.get(Ee,le)+Be*w.get(Ee,le+1),w.set(Ee,le+1,-Be*w.get(Ee,le)+be*w.get(Ee,le+1)),w.set(Ee,le,we);if(we=hn(ce,ve),we===0&&(we=Number.MIN_VALUE),be=ce/we,Be=ve/we,y[le]=we,ce=be*v[le]+Be*y[le+1],y[le+1]=-Be*v[le]+be*y[le+1],ve=Be*v[le+1],v[le+1]=be*v[le+1],c&&le<r-1)for(let Ee=0;Ee<r;Ee++)we=be*m.get(Ee,le)+Be*m.get(Ee,le+1),m.set(Ee,le+1,-Be*m.get(Ee,le)+be*m.get(Ee,le+1)),m.set(Ee,le,we)}v[M-2]=ce;break}case 4:{if(y[C]<=0&&(y[C]=y[C]<0?-y[C]:0,p))for(let L=0;L<=S;L++)w.set(L,C,-w.get(L,C));for(;C<S&&!(y[C]>=y[C+1]);){let L=y[C];if(y[C]=y[C+1],y[C+1]=L,p&&C<n-1)for(let U=0;U<n;U++)L=w.get(U,C+1),w.set(U,C+1,w.get(U,C)),w.set(U,C,L);if(c&&C<r-1)for(let U=0;U<r;U++)L=m.get(U,C+1),m.set(U,C+1,m.get(U,C)),m.set(U,C,L);C++}M--;break}}}if(h){let C=w;w=m,m=C}this.m=r,this.n=n,this.s=y,this.U=m,this.V=w}solve(e){let t=e,r=this.threshold,n=this.s.length,i=pe.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),p=l.rows,h=a.rows,f=pe.zeros(p,h);for(let d=0;d<p;d++)for(let g=0;g<h;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(t)}solveForDiagonal(e){return this.solve(pe.diag(e))}inverse(){let e=this.V,t=this.threshold,r=e.rows,n=e.columns,i=new pe(r,this.s.length);for(let h=0;h<r;h++)for(let f=0;f<n;f++)Math.abs(this.s[f])>t&&i.set(h,f,e.get(h,f)/this.s[f]);let a=this.U,l=a.rows,c=a.columns,p=new pe(r,l);for(let h=0;h<r;h++)for(let f=0;f<l;f++){let d=0;for(let g=0;g<c;g++)d+=i.get(h,g)*a.get(f,g);p.set(h,f,d)}return p}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let e=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,t=0,r=this.s;for(let n=0,i=r.length;n<i;n++)r[n]>e&&t++;return t}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return pe.diag(this.s)}}function uy(s,e=!1){return s=_r.checkMatrix(s),e?new xi(s).inverse():jf(s,pe.eye(s.rows))}function jf(s,e,t=!1){return s=_r.checkMatrix(s),e=_r.checkMatrix(e),t?new xi(s).solve(e):s.isSquare()?new ao(s).solve(e):new za(s).solve(e)}function uo(s){if(s=pe.checkMatrix(s),s.isSquare()){if(s.columns===0)return 1;let e,t,r,n;if(s.columns===2)return e=s.get(0,0),t=s.get(0,1),r=s.get(1,0),n=s.get(1,1),e*n-t*r;if(s.columns===3){let i,a,l;return i=new oo(s,[1,2],[1,2]),a=new oo(s,[1,2],[0,2]),l=new oo(s,[1,2],[0,1]),e=s.get(0,0),t=s.get(0,1),r=s.get(0,2),e*uo(i)-t*uo(a)+r*uo(l)}else return new ao(s).determinant}else throw Error("determinant can only be calculated for a square matrix")}function ly(s,e){let t=[];for(let r=0;r<s;r++)r!==e&&t.push(r);return t}function cy(s,e,t,r=1e-9,n=1e-9){if(s>n)return new Array(e.rows+1).fill(0);{let i=e.addRow(t,[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 fy(s,e={}){const{thresholdValue:t=1e-9,thresholdError:r=1e-9}=e;s=pe.checkMatrix(s);let n=s.rows,i=new pe(n,n);for(let a=0;a<n;a++){let l=pe.columnVector(s.getRow(a)),c=s.subMatrixRow(ly(n,a)).transpose(),h=new xi(c).solve(l),f=pe.sub(l,c.mmul(h)).abs().max();i.setRow(a,cy(f,h,a,t,r))}return i}function hy(s,e=Number.EPSILON){if(s=pe.checkMatrix(s),s.isEmpty())return s.transpose();let t=new xi(s,{autoTranspose:!0}),r=t.leftSingularVectors,n=t.rightSingularVectors,i=t.diagonal;for(let a=0;a<i.length;a++)Math.abs(i[a])>e?i[a]=1/i[a]:i[a]=0;return n.mmul(pe.diag(i).mmul(r.transpose()))}function py(s,e=s,t={}){s=new pe(s);let r=!1;if(typeof e=="object"&&!pe.isMatrix(e)&&!ur.isAnyArray(e)?(t=e,e=s,r=!0):e=new pe(e),s.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=t;n&&(s=s.center("column"),r||(e=e.center("column")));const i=s.transpose().mmul(e);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 dy(s,e=s,t={}){s=new pe(s);let r=!1;if(typeof e=="object"&&!pe.isMatrix(e)&&!ur.isAnyArray(e)?(t=e,e=s,r=!0):e=new pe(e),s.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=t;n&&(s.center("column"),r||e.center("column")),i&&(s.scale("column"),r||e.scale("column"));const a=s.standardDeviation("column",{unbiased:!0}),l=r?a:e.standardDeviation("column",{unbiased:!0}),c=s.transpose().mmul(e);for(let p=0;p<c.rows;p++)for(let h=0;h<c.columns;h++)c.set(p,h,c.get(p,h)*(1/(a[p]*l[h]))*(1/(s.rows-1)));return c}let Yf=class{constructor(e,t={}){const{assumeSymmetric:r=!1}=t;if(e=_r.checkMatrix(e),!e.isSquare())throw new Error("Matrix is not a square matrix");if(e.isEmpty())throw new Error("Matrix must be non-empty");let n=e.columns,i=new pe(n,n),a=new Float64Array(n),l=new Float64Array(n),c=e,p,h,f=!1;if(r?f=!0:f=e.isSymmetric(),f){for(p=0;p<n;p++)for(h=0;h<n;h++)i.set(p,h,c.get(p,h));_y(n,l,a,i),my(n,l,a,i)}else{let d=new pe(n,n),g=new Float64Array(n);for(h=0;h<n;h++)for(p=0;p<n;p++)d.set(p,h,c.get(p,h));gy(n,d,g,i),vy(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 e=this.n,t=this.e,r=this.d,n=new pe(e,e),i,a;for(i=0;i<e;i++){for(a=0;a<e;a++)n.set(i,a,0);n.set(i,i,r[i]),t[i]>0?n.set(i,i+1,t[i]):t[i]<0&&n.set(i,i-1,t[i])}return n}};function _y(s,e,t,r){let n,i,a,l,c,p,h,f;for(c=0;c<s;c++)t[c]=r.get(s-1,c);for(l=s-1;l>0;l--){for(f=0,a=0,p=0;p<l;p++)f=f+Math.abs(t[p]);if(f===0)for(e[l]=t[l-1],c=0;c<l;c++)t[c]=r.get(l-1,c),r.set(l,c,0),r.set(c,l,0);else{for(p=0;p<l;p++)t[p]/=f,a+=t[p]*t[p];for(n=t[l-1],i=Math.sqrt(a),n>0&&(i=-i),e[l]=f*i,a=a-n*i,t[l-1]=n-i,c=0;c<l;c++)e[c]=0;for(c=0;c<l;c++){for(n=t[c],r.set(c,l,n),i=e[c]+r.get(c,c)*n,p=c+1;p<=l-1;p++)i+=r.get(p,c)*t[p],e[p]+=r.get(p,c)*n;e[c]=i}for(n=0,c=0;c<l;c++)e[c]/=a,n+=e[c]*t[c];for(h=n/(a+a),c=0;c<l;c++)e[c]-=h*t[c];for(c=0;c<l;c++){for(n=t[c],i=e[c],p=c;p<=l-1;p++)r.set(p,c,r.get(p,c)-(n*e[p]+i*t[p]));t[c]=r.get(l-1,c),r.set(l,c,0)}}t[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=t[l+1],a!==0){for(p=0;p<=l;p++)t[p]=r.get(p,l+1)/a;for(c=0;c<=l;c++){for(i=0,p=0;p<=l;p++)i+=r.get(p,l+1)*r.get(p,c);for(p=0;p<=l;p++)r.set(p,c,r.get(p,c)-i*t[p])}}for(p=0;p<=l;p++)r.set(p,l+1,0)}for(c=0;c<s;c++)t[c]=r.get(s-1,c),r.set(s-1,c,0);r.set(s-1,s-1,1),e[0]=0}function my(s,e,t,r){let n,i,a,l,c,p,h,f,d,g,y,m,w,v,E,b;for(a=1;a<s;a++)e[a-1]=e[a];e[s-1]=0;let N=0,x=0,F=Number.EPSILON;for(p=0;p<s;p++){for(x=Math.max(x,Math.abs(t[p])+Math.abs(e[p])),h=p;h<s&&!(Math.abs(e[h])<=F*x);)h++;if(h>p)do{for(n=t[p],f=(t[p+1]-n)/(2*e[p]),d=hn(f,1),f<0&&(d=-d),t[p]=e[p]/(f+d),t[p+1]=e[p]*(f+d),g=t[p+1],i=n-t[p],a=p+2;a<s;a++)t[a]-=i;for(N=N+i,f=t[h],y=1,m=y,w=y,v=e[p+1],E=0,b=0,a=h-1;a>=p;a--)for(w=m,m=y,b=E,n=y*e[a],i=y*f,d=hn(f,e[a]),e[a+1]=E*d,E=e[a]/d,y=f/d,f=y*t[a]-E*n,t[a+1]=i+E*(y*n+E*t[a]),c=0;c<s;c++)i=r.get(c,a+1),r.set(c,a+1,E*r.get(c,a)+y*i),r.set(c,a,y*r.get(c,a)-E*i);f=-E*b*w*v*e[p]/g,e[p]=E*f,t[p]=y*f}while(Math.abs(e[p])>F*x);t[p]=t[p]+N,e[p]=0}for(a=0;a<s-1;a++){for(c=a,f=t[a],l=a+1;l<s;l++)t[l]<f&&(c=l,f=t[l]);if(c!==a)for(t[c]=t[a],t[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 gy(s,e,t,r){let n=0,i=s-1,a,l,c,p,h,f,d;for(f=n+1;f<=i-1;f++){for(d=0,p=f;p<=i;p++)d=d+Math.abs(e.get(p,f-1));if(d!==0){for(c=0,p=i;p>=f;p--)t[p]=e.get(p,f-1)/d,c+=t[p]*t[p];for(l=Math.sqrt(c),t[f]>0&&(l=-l),c=c-t[f]*l,t[f]=t[f]-l,h=f;h<s;h++){for(a=0,p=i;p>=f;p--)a+=t[p]*e.get(p,h);for(a=a/c,p=f;p<=i;p++)e.set(p,h,e.get(p,h)-a*t[p])}for(p=0;p<=i;p++){for(a=0,h=i;h>=f;h--)a+=t[h]*e.get(p,h);for(a=a/c,h=f;h<=i;h++)e.set(p,h,e.get(p,h)-a*t[h])}t[f]=d*t[f],e.set(f,f-1,d*l)}}for(p=0;p<s;p++)for(h=0;h<s;h++)r.set(p,h,p===h?1:0);for(f=i-1;f>=n+1;f--)if(e.get(f,f-1)!==0){for(p=f+1;p<=i;p++)t[p]=e.get(p,f-1);for(h=f;h<=i;h++){for(l=0,p=f;p<=i;p++)l+=t[p]*r.get(p,h);for(l=l/t[f]/e.get(f,f-1),p=f;p<=i;p++)r.set(p,h,r.get(p,h)+l*t[p])}}}function vy(s,e,t,r,n){let i=s-1,a=0,l=s-1,c=Number.EPSILON,p=0,h=0,f=0,d=0,g=0,y=0,m=0,w=0,v,E,b,N,x,F,M,S,I,C,B,L,U,k,W;for(v=0;v<s;v++)for((v<a||v>l)&&(t[v]=n.get(v,v),e[v]=0),E=Math.max(v-1,0);E<s;E++)h=h+Math.abs(n.get(v,E));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=h),!(Math.abs(n.get(N,N-1))<c*y));)N--;if(N===i)n.set(i,i,n.get(i,i)+p),t[i]=n.get(i,i),e[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)+p),n.set(i-1,i-1,n.get(i-1,i-1)+p),S=n.get(i,i),d>=0){for(m=f>=0?f+m:f-m,t[i-1]=S+m,t[i]=t[i-1],m!==0&&(t[i]=S-M/m),e[i-1]=0,e[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,E=i-1;E<s;E++)m=n.get(i-1,E),n.set(i-1,E,d*m+f*n.get(i,E)),n.set(i,E,d*n.get(i,E)-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 t[i-1]=S+f,t[i]=S+f,e[i-1]=m,e[i]=-m;i=i-2,w=0}else{if(S=n.get(i,i),I=0,M=0,N<i&&(I=n.get(i-1,i-1),M=n.get(i,i-1)*n.get(i-1,i)),w===10){for(p+=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=I=.75*y,M=-.4375*y*y}if(w===30&&(y=(I-S)/2,y=y*y+M,y>0)){for(y=Math.sqrt(y),I<S&&(y=-y),y=S-M/((I-S)/2+y),v=a;v<=i;v++)n.set(v,v,n.get(v,v)-y);p+=y,S=I=M=.964}for(w=w+1,x=i-2;x>=N&&(m=n.get(x,x),g=S-m,y=I-m,f=(g*y-M)/n.get(x+1,x)+n.get(x,x+1),d=n.get(x+1,x+1)-m-g-y,g=n.get(x+2,x+1),y=Math.abs(f)+Math.abs(d)+Math.abs(g),f=f/y,d=d/y,g=g/y,!(x===N||Math.abs(n.get(x,x-1))*(Math.abs(d)+Math.abs(g))<c*(Math.abs(f)*(Math.abs(n.get(x-1,x-1))+Math.abs(m)+Math.abs(n.get(x+1,x+1))))));)x--;for(v=x+2;v<=i;v++)n.set(v,v-2,0),v>x+2&&n.set(v,v-3,0);for(b=x;b<=i-1&&(k=b!==i-1,b!==x&&(f=n.get(b,b-1),d=n.get(b+1,b-1),g=k?n.get(b+2,b-1):0,S=Math.abs(f)+Math.abs(d)+Math.abs(g),S!==0&&(f=f/S,d=d/S,g=g/S)),S!==0);b++)if(y=Math.sqrt(f*f+d*d+g*g),f<0&&(y=-y),y!==0){for(b!==x?n.set(b,b-1,-y*S):N!==x&&n.set(b,b-1,-n.get(b,b-1)),f=f+y,S=f/y,I=d/y,m=g/y,d=d/f,g=g/f,E=b;E<s;E++)f=n.get(b,E)+d*n.get(b+1,E),k&&(f=f+g*n.get(b+2,E),n.set(b+2,E,n.get(b+2,E)-f*m)),n.set(b,E,n.get(b,E)-f*S),n.set(b+1,E,n.get(b+1,E)-f*I);for(v=0;v<=Math.min(i,b+3);v++)f=S*n.get(v,b)+I*n.get(v,b+1),k&&(f=f+m*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-f*g)),n.set(v,b,n.get(v,b)-f),n.set(v,b+1,n.get(v,b+1)-f*d);for(v=a;v<=l;v++)f=S*r.get(v,b)+I*r.get(v,b+1),k&&(f=f+m*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-f*g)),r.set(v,b,r.get(v,b)-f),r.set(v,b+1,r.get(v,b+1)-f*d)}}}if(h!==0){for(i=s-1;i>=0;i--)if(f=t[i],d=e[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,E=N;E<=i;E++)g=g+n.get(v,E)*n.get(E,i);if(e[v]<0)m=M,y=g;else if(N=v,e[v]===0?n.set(v,i,M!==0?-g/M:-g/(c*h)):(S=n.get(v,v+1),I=n.get(v+1,v),d=(t[v]-f)*(t[v]-f)+e[v]*e[v],F=(S*y-m*g)/d,n.set(v,i,F),n.set(v+1,i,Math.abs(S)>Math.abs(m)?(-g-M*F)/S:(-y-I*F)/m)),F=Math.abs(n.get(v,i)),c*F*F>1)for(E=v;E<=i;E++)n.set(E,i,n.get(E,i)/F)}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=lo(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(C=0,B=0,E=N;E<=i;E++)C=C+n.get(v,E)*n.get(E,i-1),B=B+n.get(v,E)*n.get(E,i);if(M=n.get(v,v)-f,e[v]<0)m=M,g=C,y=B;else if(N=v,e[v]===0?(W=lo(-C,-B,M,d),n.set(v,i-1,W[0]),n.set(v,i,W[1])):(S=n.get(v,v+1),I=n.get(v+1,v),L=(t[v]-f)*(t[v]-f)+e[v]*e[v]-d*d,U=(t[v]-f)*2*d,L===0&&U===0&&(L=c*h*(Math.abs(M)+Math.abs(d)+Math.abs(S)+Math.abs(I)+Math.abs(m))),W=lo(S*g-m*C+d*B,S*y-m*B-d*C,L,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,(-C-M*n.get(v,i-1)+d*n.get(v,i))/S),n.set(v+1,i,(-B-M*n.get(v,i)-d*n.get(v,i-1))/S)):(W=lo(-g-I*n.get(v,i-1),-y-I*n.get(v,i),m,d),n.set(v+1,i-1,W[0]),n.set(v+1,i,W[1]))),F=Math.max(Math.abs(n.get(v,i-1)),Math.abs(n.get(v,i))),c*F*F>1)for(E=v;E<=i;E++)n.set(E,i-1,n.get(E,i-1)/F),n.set(E,i,n.get(E,i)/F)}for(v=0;v<s;v++)if(v<a||v>l)for(E=v;E<s;E++)r.set(v,E,n.get(v,E));for(E=s-1;E>=a;E--)for(v=a;v<=l;v++){for(m=0,b=a;b<=Math.min(E,l);b++)m=m+r.get(v,b)*n.get(b,E);r.set(v,E,m)}}}function lo(s,e,t,r){let n,i;return Math.abs(t)>Math.abs(r)?(n=r/t,i=t+n*r,[(s+n*e)/i,(e-n*s)/i]):(n=t/r,i=r+n*t,[(n*s+e)/i,(n*e-s)/i])}class Vf{constructor(e){if(e=_r.checkMatrix(e),!e.isSymmetric())throw new Error("Matrix is not symmetric");let t=e,r=t.rows,n=new pe(r,r),i=!0,a,l,c;for(l=0;l<r;l++){let p=0;for(c=0;c<l;c++){let h=0;for(a=0;a<c;a++)h+=n.get(c,a)*n.get(l,a);h=(t.get(l,c)-h)/n.get(c,c),n.set(l,c,h),p=p+h*h}for(p=t.get(l,l)-p,i&=p>0,n.set(l,l,Math.sqrt(Math.max(p,0))),c=l+1;c<r;c++)n.set(l,c,0)}this.L=n,this.positiveDefinite=!!i}isPositiveDefinite(){return this.positiveDefinite}solve(e){e=_r.checkMatrix(e);let t=this.L,r=t.rows;if(e.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=e.columns,i=e.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)*t.get(c,a));i.set(c,l,i.get(c,l)/t.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)*t.get(a,c));i.set(c,l,i.get(c,l)/t.get(c,c))}return i}get lowerTriangularMatrix(){return this.L}}class Zf{constructor(e,t={}){e=_r.checkMatrix(e);let{Y:r}=t;const{scaleScores:n=!1,maxIterations:i=1e3,terminationCriteria:a=1e-10}=t;let l;if(r){if(ur.isAnyArray(r)&&typeof r[0]=="number"?r=pe.columnVector(r):r=_r.checkMatrix(r),r.rows!==e.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=e.getColumnVector(0);let c=1,p,h,f,d;for(let g=0;g<i&&c>a;g++)f=e.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),f=f.div(f.norm()),p=e.mmul(f).div(f.transpose().mmul(f).get(0,0)),g>0&&(c=p.clone().sub(d).pow(2).sum()),d=p.clone(),r?(h=r.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),h=h.div(h.norm()),l=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):l=p;if(r){let g=e.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0));g=g.div(g.norm());let y=e.clone().sub(p.clone().mmul(g.transpose())),m=l.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),w=r.clone().sub(p.clone().mulS(m.get(0,0)).mmul(h.transpose()));this.t=p,this.p=g.transpose(),this.w=f.transpose(),this.q=h,this.u=l,this.s=p.transpose().mmul(p),this.xResidual=y,this.yResidual=w,this.betas=m}else this.w=f.transpose(),this.s=p.transpose().mmul(p).sqrt(),n?this.t=p.clone().div(this.s.get(0,0)):this.t=p,this.xResidual=e.sub(p.mmul(f.transpose()))}}qe.AbstractMatrix=$e,qe.CHO=Vf,qe.CholeskyDecomposition=Vf,qe.DistanceMatrix=so,qe.EVD=Yf;var yy=qe.EigenvalueDecomposition=Yf;qe.LU=ao,qe.LuDecomposition=ao;var Kf=qe.Matrix=pe;qe.MatrixColumnSelectionView=ey,qe.MatrixColumnView=Q1,qe.MatrixFlipColumnView=ty,qe.MatrixFlipRowView=ry,qe.MatrixRowSelectionView=iy,qe.MatrixRowView=ny,qe.MatrixSelectionView=oo,qe.MatrixSubView=sy,qe.MatrixTransposeView=oy,qe.NIPALS=Zf,qe.Nipals=Zf,qe.QR=za,qe.QrDecomposition=za,qe.SVD=xi,qe.SingularValueDecomposition=xi,qe.SymmetricMatrix=Xn,qe.WrapperMatrix1D=Wf,qe.WrapperMatrix2D=_r,qe.correlation=dy,qe.covariance=py;var Gf=qe.default=pe;qe.determinant=uo,qe.inverse=uy,qe.linearDependencies=fy,qe.pseudoInverse=hy,qe.solve=jf,qe.wrap=ay;const Hf=yy,Jf=Kf;Gf.Matrix&&Gf.Matrix;class wy{constructor(e){R(this,"_errorListener");this._errorListener=e}new({rows:e,columns:t,initial_value:r}={}){return new qa(e,t,r,this._errorListener)}avg({id:e}){return e==null?void 0:e.avg()}col({id:e,column:t}){return e==null?void 0:e.col({column:t})}det({id:e}){return e==null?void 0:e.det()}get({id:e,row:t,column:r}){return e==null?void 0:e.get({row:t,column:r})}inv({id:e}){return e==null?void 0:e.inv()}max({id:e}){return e==null?void 0:e.max()}min({id:e}){return e==null?void 0:e.min()}pow({id:e,power:t}){return e==null?void 0:e.pow({power:t})}row({id:e,row:t}){return e==null?void 0:e.row({row:t})}set({id:e,row:t,column:r,value:n}){e==null||e.set({row:t,column:r,value:n})}sum({id1:e,id2:t}){return e==null?void 0:e.sum({id2:t})}copy({id:e}){return e==null?void 0:e.copy()}diff({id1:e,id2:t}){return e==null?void 0:e.diff({id2:t})}rows({id:e}){return e==null?void 0:e.rows()}columns({id:e}){return e==null?void 0:e.columns()}fill({id:e,value:t,from_row:r,to_row:n,from_column:i,to_column:a}){e==null||e.fill({value:t,from_row:r,to_row:n,from_column:i,to_column:a})}kron({id1:e,id2:t}){return e==null?void 0:e.kron({id2:t})}mode({id:e}){return e==null?void 0:e.mode()}mult({id1:e,id2:t}){return e==null?void 0:e.mult({id2:t})}pinv({id:e}){return e==null?void 0:e.pinv()}rank({id:e}){return e==null?void 0:e.rank()}sort({id:e,column:t,order:r}){e==null||e.sort({column:t,order:r})}trace({id:e}){return e==null?void 0:e.trace()}concat({id1:e,id2:t}){return e==null?void 0:e.concat({id2:t})}median({id:e}){return e==null?void 0:e.median()}add_col({id:e,column:t,array_id:r}){e==null||e.add_col({column:t,array_id:r})}add_row({id:e,row:t,array_id:r}){e==null||e.add_row({row:t,array_id:r})}is_zero({id:e}){return e==null?void 0:e.is_zero()}reshape({id:e,rows:t,columns:r},n){return e==null?void 0:e.reshape({rows:t,columns:r},n)}reverse({id:e}){e==null||e.reverse()}is_binary({id:e}){return e==null?void 0:e.is_binary()}is_square({id:e}){return e==null?void 0:e.is_square()}submatrix({id:e,from_row:t,to_row:r,from_column:n,to_column:i}){return e==null?void 0:e.submatrix({from_row:t,to_row:r,from_column:n,to_column:i})}swap_rows({id:e,row1:t,row2:r}){e==null||e.swap_rows({row1:t,row2:r})}transpose({id:e}){return e==null?void 0:e.transpose()}remove_col({id:e,column:t}){return e==null?void 0:e.remove_col({column:t})}remove_row({id:e,row:t}){return e==null?void 0:e.remove_row({row:t})}eigenvalues({id:e}){return e==null?void 0:e.eigenvalues()}is_diagonal({id:e}){return e==null?void 0:e.is_diagonal()}is_identity({id:e}){return e==null?void 0:e.is_identity()}eigenvectors({id:e}){return e==null?void 0:e.eigenvectors()}is_symmetric({id:e}){return e==null?void 0:e.is_symmetric()}swap_columns({id:e,column1:t,column2:r}){e==null||e.swap_columns({column1:t,column2:r})}is_stochastic({id:e}){return e==null?void 0:e.is_stochastic()}is_triangular({id:e}){return e==null?void 0:e.is_triangular()}elements_count({id:e}){return e==null?void 0:e.elements_count()}is_antidiagonal({id:e}){return e==null?void 0:e.is_antidiagonal()}is_antisymmetric({id:e}){return e==null?void 0:e.is_antisymmetric()}}class qa{constructor(e=0,t=0,r=void 0,n){R(this,"_matrixInstance");R(this,"_errorListener");this._matrixInstance=this._createMatrix(e,t,r),this._errorListener=n}get _matrixArray(){return this._matrixInstance.map(e=>[...e._value])}get _value(){return this._matrixInstance}set _value(e){this._matrixInstance=e}get isMatrix(){return!0}_createMatrix(e,t,r){return Array.from(new Array(e),()=>new Qe(t,r,this._errorListener))}avg(){let e=0,t=0;for(const n of this._matrixInstance)for(const i of n._value)e+=_e(i)?0:i,t+=1;return e/t}col({column:e}){const t=[],r=new Qe(0,void 0,this._errorListener);if(_e(e))return r;for(const n of this._matrixInstance)t.push(n._value[e]);return r._value=t,r}det(){return Lf(this._matrixArray)}get({row:e,column:t}){var r,n;if(!(_e(e)||_e(t)))return(n=(r=this._matrixInstance[e])==null?void 0:r._value)==null?void 0:n[t]}inv(){const e=to(this._matrixArray);return this._newMatrix(e)}max(){return _1(this._matrixArray)}min(){return $a(this._matrixArray)}pow({power:e}){const t=_e(e)?this._matrixArray:g1(this._matrixArray,e);return this._newMatrix(t)}row({row:e}){return _e(e)?new Qe(0,void 0,this._errorListener):this._matrixInstance[e]}set({row:e,column:t,value:r}){_e(e)||_e(t)||this._matrixInstance[e].set({index:t,value:r})}sum({id2:e}){const t=Qi(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:e}){const t=l1(this._matrixArray,typeof e=="number"?e:e._matrixArray);return this._newMatrix(t)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:e,from_row:t,to_row:r,from_column:n,to_column:i}={}){_e(t)&&(t=0),_e(r)&&(r=this.rows()),_e(n)&&(n=0),_e(i)&&(i=this.columns());for(const[a,l]of this._matrixInstance.entries())for(const[c]of l._value.entries())a<r&&a>=t&&c>=n&&c<i&&l.set({index:c,value:e})}kron({id2:e}){const t=a1(this._matrixArray,e._matrixArray);return this._newMatrix(t)}mode(){return $a(Nf(this._matrixArray))}mult({id2:e}){const t=typeof e=="number"?e:e._matrixArray?e._matrixArray:e._value,r=wi(this._matrixArray,t);return this._newMatrix(r)}pinv(){const e=m1(this._matrixArray);return this._newMatrix(e)}rank(){return this._matrixRank(this._matrixArray)}sort({column:e,order:t=Vn.ascending}={}){_e(e)&&(e=0),this._matrixInstance.sort((r,n)=>{const i=r._value[e],a=n._value[e];return t!==Vn.descending?i-a:a-i})}trace(){return d1(this._matrixArray)}concat({id2:e}){for(const t of e._value)this._matrixInstance.push(t);return this}median(){return Rf(this._matrixArray)}add_col({column:e,array_id:t}={}){_e(e)&&(e=this.columns());for(const[r,n]of this._matrixInstance.entries())n.insert({index:e,value:t?t._value[r]:void 0})}add_row({row:e,array_id:t}){_e(e)&&(e=this.rows()),this._matrixInstance.splice(e,0,t||new Qe(this.columns(),void 0,this._errorListener))}is_zero(){return this._matrixArray.every(e=>e.every(t=>t===0))}reshape({rows:e=0,columns:t=0},r){if(e*t!==this.columns()*this.rows()){this._errorListener.addError(ut.matrixRehapeErr,r,ze.Error);return}const n=n1(this._matrixArray,[e,t]);this._matrixInstance=n.map(i=>{const a=new Qe(0,void 0,this._errorListener);return a._value=[...i],a})}reverse(){this._matrixInstance.reverse();for(const e of this._matrixInstance)e.reverse()}is_binary(){return this._matrixArray.every(e=>e.every(t=>t===0||t===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:e,to_row:t,from_column:r,to_column:n}={}){_e(e)&&(e=0),_e(t)&&(t=this.rows()),_e(r)&&(r=0),_e(n)&&(n=this.columns());const i=this._matrixArray.splice(e,t),a=[];for(const l of i)a.push(l.splice(r,n));return this._newMatrix(a)}swap_rows({row1:e,row2:t}){if(_e(e)||_e(t))return;const r=this._matrixInstance[e],n=this._matrixInstance[t];this._matrixInstance[e]=n,this._matrixInstance[t]=r}transpose(){const e=Bf(this._matrixArray);return this._newMatrix(e)}remove_col({column:e}={}){_e(e)&&(e=this.columns());const t=[];for(const n of this._matrixInstance){const i=n._value.splice(e,1);t.push(i[0])}const r=new Qe(0,void 0,this._errorListener);return r._value=t,r}remove_row({row:e}={}){return _e(e)&&(e=this.rows()),this._matrixInstance.splice(e,1)[0]}eigenvalues(){const e=new Hf(new Jf(this._matrixArray)),t=new Qe(0,void 0,this._errorListener);return t._value=e.realEigenvalues,t}is_diagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<t;i++)if(n!==i&&r[n][i]!==0)return!1;return!0}is_identity(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<t;i++)if(n!==i&&r[n][i]!==0||n===i&&r[n][i]!==1)return!1;return!0}eigenvectors(){const e=new Hf(new Jf(this._matrixArray));return this._newMatrix(e.eigenvectorMatrix.to2DArray())}is_symmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=n+1;i<t;i++)if(r[n][i]!==r[i][n])return!1;return!0}swap_columns({column1:e,column2:t}){if(!(_e(e)||_e(t)))for(const r of this._matrixInstance){const n=r._value[e],i=r._value[t];r.set({index:e,value:i}),r.set({index:t,value:n})}}is_stochastic(){const e=this._matrixArray;for(let t=0;t<e.length;t++){let r=0;for(let n=0;n<e[t].length;n++){if(e[t][n]<0)return!1;r+=e[t][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const e=this.rows(),t=this.columns();return e!==t?!1:this._isUpperTriangular(e)||this._isLowerTriangular(e)}elements_count(){return i1(this._matrixArray)}is_antidiagonal(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<e;i++)if(n+i!==e-1&&r[n][i]!==0)return!1;return!0}is_antisymmetric(){const e=this.rows(),t=this.columns();if(e!==t)return!1;const r=this._matrixArray;for(let n=0;n<e;n++)for(let i=0;i<e;i++)if(n!==i&&r[n][i]!==-r[i][n])return!1;return!0}_isUpperTriangular(e){const t=this._matrixArray;for(let r=1;r<e;r++)for(let n=0;n<r;n++)if(t[r][n]!==0)return!1;return!0}_isLowerTriangular(e){const t=this._matrixArray;for(let r=0;r<e-1;r++)for(let n=r+1;n<e;n++)if(t[r][n]!==0)return!1;return!0}_newMatrix(e){const t=new qa(0,0,void 0,this._errorListener);return t._value=e.map(r=>{const n=new Qe(0,void 0,this._errorListener);return n._value=[...r],n}),t}_matrixRank(e){let t=0;const r=e.length,n=e[0].length,i=[...e].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 p=i[l];i[l]=i[a],i[a]=p}const c=i[a][a];for(let p=0;p<n;p++)i[a][p]/=c;for(let p=a+1;p<r;p++){const h=i[p][a];i[p]=i[p].map((f,d)=>f-h*i[a][d]),i[p][a]=0}}for(let a=0;a<r;a++)i[a].some(l=>Number(l.toFixed(8))!==0)&&t++;return t}}class Dy{constructor(e){R(this,"_variables");R(this,"_cacheData");this._variables=e,this._cacheData={}}change({timeframe:e},t){if(!e)return!0;const r=Xr(e),n=Xr(this._variables.timeframe.period);if(r<n)return!0;const i=`change_${t}`,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,e);return this._cacheData[i]={currentTime:l,offset:c},!1}return!1}in_seconds({timeframe:e}={}){return Xr(e||this._variables.timeframe.period)}from_seconds({seconds:e=0}){const t=e*1e3,r=tt.duration(t);if(r.years())return"12M";const i=r.asMonths();if(Qs(i))return`${i}M`;const a=r.asWeeks();if(Qs(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 p=r.asSeconds();return p<=1?"1S":p<=5?"5S":p<=10?"10S":p<=15?"15S":p<=30?"30S":"1"}_calcTimeOffset(e,t){let r=0;if(t.includes("W")){const l=tt(e).day();t="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(t.includes("M")){const l=tt(e).date();t="1D";const c=tt(e).daysInMonth();l!==1&&(r=(c-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(e,t),i=Xr(t)*1e3,a=e-n-Math.floor((e-n)/i)*i;return r?r-a:a}}class by{constructor(e,t){R(this,"_errorListener");R(this,"_intlNumberFormatter");R(this,"_precision");this._errorListener=e,this._precision=t,this._intlNumberFormatter=new Intl.NumberFormat("en",{notation:"compact"})}pos({source:e="",str:t=""}){return e==null?void 0:e.indexOf(t)}trim({source:e=""}){return e==null?void 0:e.trim()}lower({source:e=""}){return e==null?void 0:e.toLocaleLowerCase()}match({source:e="",regex:t=""}){const r=e==null?void 0:e.match(new RegExp(t));return r?r[0]:""}split({string:e="",separator:t=""}){const r=e==null?void 0:e.split(t),n=new Qe;return n._value=r||[],n}upper({source:e=""}){return e==null?void 0:e.toLocaleUpperCase()}format({formatString:e=""},t){return this._strFormat(e,t)}length({string:e=""}){return e==null?void 0:e.length}repeat({source:e="",repeat:t,separator:r=""},n){if(_e(t)){this._errorListener.addError(ut.arrLenErr,n,ze.Error);return}return Array.from(new Array(t),()=>e).join(r)}replace({source:e="",target:t="",replacement:r="",occurrence:n}){_e(n)&&(n=0);let i=-1;for(let a=0;a<n+1&&(i=e.indexOf(t,i+1),i!==-1);a++);return i!==-1?e.substring(0,i)+r+e.substring(i+t.length):e}contains({source:e="",str:t=""}){return e==null?void 0:e.includes(t)}endswith({source:e="",str:t=""}){return e==null?void 0:e.endsWith(t)}tonumber({string:e=""}){if(/[^\d.]/.test(e))return;const t=parseFloat(e);return isNaN(t)?void 0:t}tostring({value:e,format:t}){if(e===void 0)return"NaN";if(typeof e=="object"){if(e.isArray)return this._arrToStr(e._value,t);if(e.isMatrix){const r=[];for(const n of e._matrixArray)r.push(this._arrToStr(n,t));return r.join(`
|
62
|
-
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t))}_arrToStr(e,t){return`[${e.map(n=>typeof n=="number"?this._toStringFormat(n,t):n).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return _e(t)&&(t=0),_e(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _e(e)&&(e=0),qr(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e.toFixed(this._precision));switch(t){case Ke.mintick:return e.toFixed(this._precision);case Ke.percent:return`${e}%`;case Ke.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var l;let[r,n]=t.split(".");t.split("%").length===2&&(e=e*100);let[i,a=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),p=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;p&&(i=i.replace(new RegExp(`\\B(?=(\\d{${p}})+(?!\\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(e,t){if(!t)return Number(e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}_strFormat(e,t){let r=e;for(const[n,i]of t.entries()){if(i===void 0||isNaN(i)){r="NaN";continue}if(typeof i=="number"){const a=`\\{\\s*${n}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=e.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(e){R(this,"_errorListener");this._errorListener=e}new(){return new ka(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class ka{constructor(e){R(this,"_errorListener");R(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}_copyMap(e){const t=new ka(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new Qe(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new Qe(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class xy{constructor(e){R(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Ai(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Ai(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Ai(e,t)}from_time({price:e,time:t}){return new Ai(e,void 0,t)}}class Ai{constructor(e,t,r){R(this,"_index");R(this,"_price");R(this,"_time");this._index=t,this._price=e,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 Ay{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLabel",{text:"",xloc:wt.bar_index,yloc:Wr.price,size:tr.normal,style:mt.styleLabelDown,textalign:We.alignCenter});this._variables=e,this._errorListener=t}new(e,t){const{time:r,high:n,low:i,bar_index:a}=this._variables,l=`label_${t}_${a}`;_t(e,["color","textcolor"]);const c={...this._defaultLabel,...e,id:l,time:r,high:n,low:i};e.point&&(c.x=c.xloc===wt.bar_index?e.point.index:e.point.time,c.y=e.point.price),c.yloc===Wr.abovebar?c.y=n:c.yloc===Wr.belowbar&&(c.y=i),this._verfiyArgs(e,t);const p=new ts(l,this._variables,this._errorListener);return t.startsWith("export")||this._variables.label.add(l,c,p),p}_verfiyArgs(e,t){const{xloc:r,yloc:n,style:i,size:a,textalign:l,text_font_family:c}=e,p="label.new";this._paramVerfiy(i,t,p,Object.values(mt),"style"),this._paramVerfiy(r,t,p,Object.values(wt),"xloc"),this._paramVerfiy(n,t,p,Object.values(Wr),"yloc"),this._paramVerfiy(a,t,p,Object.values(tr),"size"),this._paramVerfiy(l,t,p,[We.alignLeft,We.alignCenter,We.alignRight],"textalign"),this._paramVerfiy(c,t,p,Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}label(e,t){return e.x?e.x:new ts(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e}){e==null||e.delete()}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ts{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}copy(e){const t=`label_${e}_${this._variables.bar_index}`,r=this._getLabel(e),n=new ts(t,this._variables,this._errorListener);if(r){const i={...r,id:t};this._variables.label.add(t,i,n)}return n}get_x(e){var t;return(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){const r=this._getLabel(t);r&&(r.x=e)}set_y({y:e},t){const r=this._getLabel(t);r&&(r.y=e)}delete(){this._variables.label.delete(this._id)}set_xy({x:e,y:t},r){const n=this._getLabel(r);n&&(n.x=e,n.y=t)}get_text(e){var t;return(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(tr),"size")}set_text({text:e},t){const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){const n=this._getLabel(r);n&&(n.x=e,n.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(wt),"xloc"))}set_yloc({yloc:e},t){const r=this._getLabel(t),{high:n,low:i}=this._variables;r&&(r.yloc=e,e===Wr.abovebar?r.y=n:e===Wr.belowbar&&(r.y=i),this._paramVerfiy(e,t,"label.set_yloc",Object.values(Wr),"yloc"))}set_color(e,t){const r=this._getLabel(t);_t(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){const r=this._getLabel(t);r&&(r.x=r.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(mt),"style")}set_tooltip({tooltip:e},t){const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[We.alignLeft,We.alignCenter,We.alignRight],"textalign")}set_textcolor(e,t){const r=this._getLabel(t);_t(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getLabel(e){const t=this._variables.label.get(this._id);return t||console.log(`错误${e}: label 不存在`),t}}const Cy={freq_all:kr.freqAll,freq_once_per_bar:kr.freqOncePerBar,freq_once_per_bar_close:kr.freqOncePerBarClose},Fy={gaps_off:Vi.gapsOff,gaps_on:Vi.gapsOn,lookahead_off:Vi.lookaheadOff,lookahead_on:Vi.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"},My={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Qf={all:[Yt.dataWindow,Yt.pane,Yt.priceScale,Yt.statusLine],data_window:[Yt.dataWindow],none:[],pane:[Yt.pane],price_scale:[Yt.priceScale],status_line:[Yt.statusLine]},Ny={both:Ur.both,left:Ur.left,none:Ur.none,right:Ur.right},Sy={inherit:Ke.inherit,mintick:Ke.mintick,percent:Ke.percent,price:Ke.price,volume:Ke.volume},By={style_solid:xs.styleSolid,style_dashed:xs.styleDashed,style_dotted:xs.styleDotted},Oy={style_arrowdown:mt.styleArrowdown,style_arrowup:mt.styleArrowup,style_circle:mt.styleCircle,style_cross:mt.styleCross,style_diamond:mt.styleDiamond,style_flag:mt.styleFlag,style_label_center:mt.styleLabelCenter,style_label_down:mt.styleLabelDown,style_label_left:mt.styleLabelLeft,style_label_lower_left:mt.styleLabelLowerLeft,style_label_lower_right:mt.styleLabelLowerRight,style_label_right:mt.styleLabelRight,style_label_up:mt.styleLabelUp,style_label_upper_left:mt.styleLabelUpperLeft,style_label_upper_right:mt.styleLabelUpperRight,style_none:mt.styleNone,style_square:mt.styleSquare,style_text_outline:mt.styleTextOutline,style_triangledown:mt.styleTriangledown,style_triangleup:mt.styleTriangleup,style_xcross:mt.styleXcross},Ty={style_arrow_both:Lt.styleArrowBoth,style_arrow_left:Lt.styleArrowLeft,style_arrow_right:Lt.styleArrowRight,style_dashed:Lt.styleDashed,style_dotted:Lt.styleDotted,style_solid:Lt.styleSolid},Iy={abovebar:an.abovebar,absolute:an.absolute,belowbar:an.belowbar,bottom:an.bottom,top:an.top},$y={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Ly={style_area:Cr.styleArea,style_areabr:Cr.styleAreabr,style_circles:Cr.styleCircles,style_columns:Cr.styleColumns,style_cross:Cr.styleCross,style_histogram:Cr.styleHistogram,style_line:Cr.styleLine,style_linebr:Cr.styleLinebr,style_stepline:Cr.styleStepline,style_stepline_diamond:Cr.styleSteplineDiamond,style_steplinebr:Cr.styleSteplinebr},Ry={bottom_center:pr.bottomCenter,bottom_left:pr.bottomLeft,bottom_right:pr.bottomRight,middle_center:pr.middleCenter,middle_left:pr.middleLeft,middle_right:pr.middleRight,top_center:pr.topCenter,top_left:pr.topLeft,top_right:pr.topRight},Py={left:As.left,none:As.none,right:As.right},zy={arrowdown:or.arrowdown,arrowup:or.arrowup,circle:or.circle,cross:or.cross,diamond:or.diamond,flag:or.flag,labeldown:or.labeldown,labelup:or.labelup,square:or.square,triangledown:or.triangledown,triangleup:or.triangleup,xcross:or.xcross},qy={auto:tr.auto,huge:tr.huge,large:tr.large,normal:tr.normal,small:tr.small,tiny:tr.tiny},ky={cash:Ot.cash,fixed:Ot.fixed,percent_of_equity:Ot.percentOfEquity,commission:{cash_per_contract:Fr.cashPerContract,cash_per_order:Fr.cashPerOrder,percent:Fr.percent},direction:{all:gt.all,long:gt.long,short:gt.short},oca:{cancel:un.cancel,none:un.none,reduce:un.reduce}},Uy={align_bottom:We.alignBottom,align_center:We.alignCenter,align_left:We.alignLeft,align_right:We.alignRight,align_top:We.alignTop,wrap_auto:We.wrapAuto,wrap_none:We.wrapNone},Wy={bar_index:wt.bar_index,bar_time:wt.bar_time},jy={abovebar:Wr.abovebar,belowbar:Wr.belowbar,price:Wr.price},Yy={actual:Cs.actual,estimate:Cs.estimate,standardized:Cs.standardized};class eh{constructor(){R(this,"adjustment",{dividends:Es.dividends,none:Es.none,splits:Es.splits});R(this,"alert",Cy);R(this,"barmerge",Fy);R(this,"color",Ci);R(this,"currency",Xf);R(this,"dayofweek",My);R(this,"earnings",Yy);R(this,"display",Qf);R(this,"extend",Ny);R(this,"font",{family_default:Zn.familyDefault,family_monospace:Zn.familyMonospace});R(this,"format",Sy);R(this,"hline",By);R(this,"label",Oy);R(this,"line",Ty);R(this,"location",Iy);R(this,"math",$y);R(this,"order",{ascending:Vn.ascending,descending:Vn.descending});R(this,"plot",Ly);R(this,"position",Ry);R(this,"scale",Py);R(this,"session",{extended:fi.extended,regular:fi.regular});R(this,"shape",zy);R(this,"size",qy);R(this,"splits",{denominator:"denominator",numerator:"numerator"});R(this,"strategy",ky);R(this,"text",Uy);R(this,"xloc",Wy);R(this,"yloc",jy)}updateData(){}}class Vy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:wt.bar_index,line_color:Ci.blue,line_style:Lt.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var a;const r=`polyline_${t}_${this._variables.bar_index}`,n=Object.assign({},this._defaultPolyline,e,{id:r,points:(a=e.points)==null?void 0:a._value.map(l=>({time:l.time,index:l.index,price:l.price}))});_t(n,["line_color","fill_color"]);const i=new th(r,this._variables);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(r,n,i),i}_verfiyArgs(e,t){const{line_style:r,xloc:n}=e,i="polyline.new";this._paramVerfiy(r,t,i,Object.values(Lt),"line_style"),this._paramVerfiy(n,t,i,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}delete({id:e}){e&&e.delete()}}class th{constructor(e,t){R(this,"_id");R(this,"_variables");this._variables=t,this._id=e}delete(){this._variables.polyline.delete(this._id)}}class Zy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLine",{xloc:wt.bar_index,extend:Ur.none,style:Lt.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},n){const i=`line_${n}_${this._variables.bar_index}`;_t(r,["color"]);const a={...this._defaultLine,...r,id:i};if(e&&t){const c=a.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,p=a.xloc===wt.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(a,{x1:c,y1:e==null?void 0:e.price,x2:p,y2:t==null?void 0:t.price})}this._verfiyArgs(r,n);const l=new rs(i,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(i,a,l),l}_verfiyArgs(e,t){const{extend:r,xloc:n,style:i}=e,a="line.new";this._paramVerfiy(i,t,a,Object.values(Lt),"style"),this._paramVerfiy(r,t,a,Object.values(Ur),"extend"),this._paramVerfiy(n,t,a,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}line(e,t){return e.x?e.x:new rs(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class rs{constructor(e,t,r){R(this,"_variables");R(this,"_id");R(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}get data(){return this._variables.line.get(this._id)}copy(e){const t=`line_${e}_${this._variables.bar_index}`,r=this._getLine(e),n=new rs(t,this._variables,this._errorListener);return r&&this._variables.line.add(t,{...r,id:t},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:e},t){const r=this._getLine(t);if(e===void 0)return e;if(r&&r.xloc===wt.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)*(e-n)+i}}get_x1(e){var t;return(t=this._getLine(e))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t);r&&(r.x1=e)}set_x2({x:e},t){const r=this._getLine(t);r&&(r.x2=e)}set_y1({y:e},t){const r=this._getLine(t);r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t);r&&(r.y2=e)}set_xy1({x:e,y:t},r){const n=this._getLine(r);n&&(n.x1=e,n.y1=t)}set_xy2({x:e,y:t},r){const n=this._getLine(r);n&&(n.x2=e,n.y2=t)}set_xloc({xloc:e,x1:t,x2:r},n){const i=this._getLine(n);i&&(i.xloc=e,i.x1=t,i.x2=r,this._paramVerfiy(e,n,"line.set_xloc",Object.values(wt),"xloc"))}set_color(e,t){const r=this._getLine(t);r&&(_t(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t);r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(Lt),"style"))}set_width({width:e},t){const r=this._getLine(t);r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t);r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(Ur),"extend"))}set_first_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},l=r.xloc===wt.bar_index?n:i,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},l=r.xloc===wt.bar_index?n:i,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getLine(e){const t=this._variables.line.get(this._id);return t||console.log(`${e}: line 不存在`),t}}class Ky{constructor(e){R(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:n}=e,i=`linefill_${t}_${this._variables.bar_index}`,a=r==null?void 0:r.data,l=n==null?void 0:n.data;a&&(a.linefills=a.linefills||[],a.linefills.push(i)),l&&(l.linefills=l.linefills||[],l.linefills.push(i)),_t(e,["color"]);const c=new co(this._variables,i,r,n);return t.startsWith("export")||(a||l)&&this._variables.linefill.add(i,{line1:a,line2:l,color:e.color,id:i},c),c}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class co{constructor(e,t,r,n){R(this,"_id");R(this,"_line1");R(this,"_line2");R(this,"_variables");this._variables=e,this._id=t,this._line1=r,this._line2=n}linefill(e,t){return e.x?e.x:new co(this._variables,t)}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:n,line2:i}=e;n&&(n.linefills=(t=n.linefills)==null?void 0:t.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(e){const t=this._variables.linefill.get(this._id);t&&(_t(e,["color"]),t.color=e.color)}}class Gy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultBox",{border_color:Ci.blue,border_width:1,bgcolor:Ci.blue,xloc:wt.bar_index,extend:Ur.none,style:Lt.styleSolid,text:"",text_size:tr.auto,text_color:Ci.black,text_halign:We.alignCenter,text_valign:We.alignCenter,text_wrap:We.wrapNone});this._variables=e,this._errorListener=t}box({x:e},t){return e===void 0?new ns(this._variables,t,this._errorListener):e}new({top_left:e,bottom_right:t,...r},n){const i=`box_${n}_${this._variables.bar_index}`,a={...this._defaultBox,...r,id:i};if(_t(a,["border_color","bgcolor","text_color"]),e){const{price:c,time:p,index:h}=e;a.top=c,a.left=a.xloc===wt.bar_index?h:p}if(t){const{price:c,time:p,index:h}=t;a.bottom=c,a.right=a.xloc===wt.bar_index?h:p}this._verfiyArgs(r,n);const l=new ns(this._variables,i,this._errorListener);return n.startsWith("export")||this._variables.box.add(i,a,l),l}_verfiyArgs(e,t){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:l,text_valign:c,text_wrap:p,text_font_family:h}=e,f="box.new";this._paramVerfiy(r,t,f,[Lt.styleDashed,Lt.styleDotted,Lt.styleSolid],"border_style"),this._paramVerfiy(n,t,f,Object.values(Ur),"extend"),this._paramVerfiy(i,t,f,Object.values(wt),"xloc"),this._paramVerfiy(a,t,f,Object.values(tr),"text_size"),this._paramVerfiy(l,t,f,[We.alignLeft,We.alignCenter,We.alignRight],"text_halign"),this._paramVerfiy(c,t,f,[We.alignBottom,We.alignCenter,We.alignTop],"text_valign"),this._paramVerfiy(p,t,f,[We.wrapAuto,We.wrapNone],"text_wrap"),this._paramVerfiy(h,t,f,Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_top({id:e}){return e==null?void 0:e.get_top()}get_bottom({id:e}){return e==null?void 0:e.get_bottom()}get_left({id:e}){return e==null?void 0:e.get_left()}get_right({id:e}){return e==null?void 0:e.get_right()}set_top({id:e,...t}){e==null||e.set_top(t)}set_bottom({id:e,...t}){e==null||e.set_bottom(t)}set_left({id:e,...t}){e==null||e.set_left(t)}set_right({id:e,...t}){e==null||e.set_right(t)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({id:e,...t}){e==null||e.set_border_color(t)}set_border_width({id:e,...t}){e==null||e.set_border_width(t)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t}){e==null||e.set_lefttop(t)}set_rightbottom({id:e,...t}){e==null||e.set_rightbottom(t)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t}){e==null||e.set_text_color(t)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t}){e==null||e.set_top_left_point(t)}set_bottom_right_point({id:e,...t}){e==null||e.set_bottom_right_point(t)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ns{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._variables=e,this._id=t,this._errorListener=r}copy(e){const t=`box_${e}_${this._variables.bar_index}`,r=this._getBox(),n=new ns(this._variables,t,this._errorListener);return r&&this._variables.box.add(t,{...r,id:t},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const e=this._getBox();return e&&e.top}set_top({top:e}){const t=this._getBox();t&&(t.top=e)}get_left(){const e=this._getBox();return e&&e.left}set_left({left:e}){const t=this._getBox();t&&(t.left=e)}set_text({text:e}){const t=this._getBox();t&&(t.text=e)}get_right(){const e=this._getBox();return e&&e.right}set_right({right:e}){const t=this._getBox();t&&(t.right=e)}get_bottom(){const e=this._getBox();return e&&e.bottom}set_bottom({bottom:e}){const t=this._getBox();t&&(t.bottom=e)}set_extend({extend:e},t){const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(Ur),"extend"))}set_bgcolor({color:e}){const t=this._getBox();t&&(t.bgcolor=e,_t(t,["bgcolor"]))}set_lefttop({left:e,top:t}){const r=this._getBox();r&&(r.left=e,r.top=t)}set_text_size({text_size:e},t){const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(tr),"text_size"))}set_text_wrap({text_wrap:e},t){const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[We.wrapAuto,We.wrapNone],"text_wrap"))}set_text_color({text_color:e}){const t=this._getBox();t&&(t.text_color=e,_t(t,["text_color"]))}set_rightbottom({right:e,bottom:t}){const r=this._getBox();r&&(r.right=e,r.bottom=t)}set_text_halign({text_halign:e},t){const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[We.alignLeft,We.alignCenter,We.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[We.alignBottom,We.alignCenter,We.alignTop],"text_valign"))}set_top_left_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.top=n,t.left=t.xloc===wt.bar_index?r:i}}set_border_color({color:e}){const t=this._getBox();t&&(t.border_color=e,_t(t,["border_color"]))}set_border_style({style:e},t){const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[Lt.styleDashed,Lt.styleDotted,Lt.styleSolid],"style"))}set_border_width({width:e}){const t=this._getBox();t&&(t.border_width=e)}set_bottom_right_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.bottom=n,t.right=t.xloc===wt.bar_index?r:i}}set_text_font_family({text_font_family:e},t){const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(Zn),"text_font_family"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getBox(){return this._variables.box.get(this._id)}}class Hy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultTable",{position:pr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e},t){return e||new Ua(this._variables,t,this._errorListener)}new(e,t){const r=`table_${t}_${this._variables.bar_index}`,{columns:n,rows:i}=e;_t(e,["text_color","bgcolor","border_color"]);const a=Array.from(Array(i),()=>Array.from(Array(n),()=>{})),l={...this._defaultTable,...e,cell:a,id:r},c=new Ua(this._variables,r,this._errorListener);return this._paramVerfiy(e.position,t,"table.new",Object.values(pr),"position"),t.startsWith("export")||this._variables.table.add(r,l,c),c}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}cell({table_id:e,...t}){e==null||e.cell(t)}cell_set_bgcolor({table_id:e,...t}){e==null||e.cell_set_bgcolor(t)}cell_set_height({table_id:e,...t}){e==null||e.cell_set_height(t)}cell_set_text({table_id:e,...t}){e==null||e.cell_set_text(t)}cell_set_text_color({table_id:e,...t}){e==null||e.cell_set_text_color(t)}cell_set_text_font_family({table_id:e,...t}){e==null||e.cell_set_text_font_family(t)}cell_set_text_halign({table_id:e,...t}){e==null||e.cell_set_text_halign(t)}cell_set_text_valign({table_id:e,...t}){e==null||e.cell_set_text_valign(t)}cell_set_text_size({table_id:e,...t}){e==null||e.cell_set_text_size(t)}cell_set_tooltip({table_id:e,...t}){e==null||e.cell_set_tooltip(t)}cell_set_width({table_id:e,...t}){e==null||e.cell_set_width(t)}clear({table_id:e,...t}){e==null||e.clear(t)}delete({table_id:e}){e==null||e.delete()}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({table_id:e,...t}){e==null||e.set_border_color(t)}set_border_width({table_id:e,...t}){e==null||e.set_border_width(t)}set_frame_color({table_id:e,...t}){e==null||e.set_frame_color(t)}set_frame_width({table_id:e,...t}){e==null||e.set_frame_width(t)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class Ua{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");R(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ci.black,text_halign:We.alignCenter,text_valign:We.alignCenter,text_size:tr.normal});this._variables=e,this._id=t,this._errorListener=r}cell(e){const t={...this._defaultCell,...e},{column:r=0,row:n=0}=t,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],l=a[n]||[];l[r]=t,a[n]=l,i.cell=a}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r}){const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r}){const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r}){const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r}){const n=this._getTableItem(e,t);n&&(n.text_color=r,_t(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r}){const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r}){const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r}){const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r}){const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r}){const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r}){const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0}){const i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let l=t;l<=n;l++)for(let c=e;c<=r;c++){const p=a[l];p&&(p[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0},i){if(e>r||t>n){this._errorListener.addError(ut.mergeCellErr,i,ze.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:e,start_row:t,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:e}){const t=this._variables.table.get(this._id);t&&(t.bgcolor=e,_t(t,["bgcolor"]))}set_border_color({border_color:e}){const t=this._variables.table.get(this._id);t&&(t.border_color=e,_t(t,["border_color"]))}set_border_width({border_width:e}){const t=this._variables.table.get(this._id);t&&(t.border_width=e)}set_frame_color({frame_color:e}){const t=this._variables.table.get(this._id);t&&(t.frame_color=e)}set_frame_width({frame_width:e}){const t=this._variables.table.get(this._id);t&&(t.frame_width=e)}set_position({position:e},t){const r=this._variables.table.get(this._id);r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(pr),"position"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getTableItem(e,t){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[t][e]:void 0}}}class Jy{constructor(e){R(this,"_strategy");this._strategy=e}commission({trade_num:e}){return this._verifyTradeNum(e)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.historyOrders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_time}exit_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{out_qty:t=0,direction:r}=this._strategy.historyOrders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.historyOrders.length;return!(e>=t)}}class Xy{constructor(e){R(this,"_strategy");this._strategy=e}commission({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,original_qty:r=0,commission:n=0}=this._strategy.orders[e];return n*t/r}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.orders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,direction:r}=this._strategy.orders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.orders.length;return!(e>=t)}}class Qy{constructor(e,t){R(this,"_strategy");R(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(gt),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e}){this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[Ot.percentOfEquity,Ot.cash],"type"),t===Ot.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e}){this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[Ot.percentOfEquity,Ot.cash],"type"),t===Ot.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e}){this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}}let ew=class{constructor(e,t,r,n){R(this,"_variables");R(this,"_options");R(this,"_totalChangeCapital");R(this,"_historyOrder");R(this,"_orders");R(this,"_pendingOrders");R(this,"_mintick");R(this,"_funcOptions");R(this,"_pendingCloseOrders");R(this,"_errorListener");R(this,"_risk");R(this,"_opentrades");R(this,"_closedtrades");R(this,"_riskNamespace");this._variables=e,this._errorListener=n,this._options={overlay:!1,format:Ke.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Ot.fixed,default_qty_value:1,initial_capital:1e6,currency:Xf.NONE,slippage:0,commission_type:Fr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._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 Xy(this),this._closedtrades=new Jy(this),this._riskNamespace=new Qy(this,n)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((e,t)=>e+(t.profit||0),0)}get _freezeCapital(){const{close:e}=this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(e){Object.assign(this._options,e),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{high:n,low:i,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:p}}=this._variables;let{preNetprofit:h=0}=this._risk;l===a&&(h=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=h-c;f+=this._orders.reduce((y,m)=>{const{in_price:w,direction:v,qty:E=0,commission:b=0,original_qty:N=0}=m,x=v===gt.long?1:-1,F=(n-w)*E,M=(i-w)*E,S=x===1?-M:F;return y+S+E/N*b},0);let d=!1;switch(t){case Ot.cash:d=e<f;break;case Ot.percentOfEquity:const y=f/(p+c)*100;d=e<y;break}if(d){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===gt.long?i:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(e===void 0||r)return;const{time:i,time_tradingday:a,strategy:l,open:c}=this._variables;let p=t;if(i===a){const h=l.netprofit+l.openprofit;h<n?p=0:p++,Object.assign(this._risk,{lossDays:p,totalProfit:h})}e<=p&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(!r&&e!==void 0&&t){const{max_drawdown:i,max_drawdown_percent:a}=this._variables.strategy;let l=!1;switch(t){case Ot.percentOfEquity:l=a<i;break;case Ot.cash:l=e<i;break}if(l){const{high:c,low:p}=this._variables,h=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(h===gt.long?c:p,"Close Position (Max Drawdown)")}}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,e,t),this._pendingOrders=[]}strategy(e,t){this._variables.bar_index||(this._paramVerfiy(e.format,t,"strategy",[Ke.inherit,Ke.price,Ke.percent,Ke.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(Ot),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(Fr),"commission_type"),Object.assign(this._options,e),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"}))}order(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(un),"oca_type"),this._orderHandle(e))}entry(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(un),"oca_type"),this._entryHandle(e))}close(e){if(!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close"}):this._pendingOrders.push({...e,place_order_type:"close"})}close_all(e){if(typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e}){this._pendingOrders=this._pendingOrders.filter(t=>!(t.id===e&&t.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(e=>e.place_order_type==="close_all")}exit(e,t){this._exit(e,t)}convert_to_account({value:e}){return e}convert_to_symbol({value:e}){return e}default_entry_qty({fill_price:e}){return e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=Ot.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(t){case Ot.fixed:return r;case Ot.cash:return r/e;case Ot.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/e}}_getCapital(e,t){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:n<=100&&n>0&&e===-1&&(t=t*100/n),t}_calcProfitAndLoss(){const{high:e,low:t,close:r}=this._variables;for(const n of this._orders){const{in_price:i,qty:a=0,direction:l}=n,c=l===gt.long?1:-1,p=(r-i)*c*a,h=(e-i)*a,f=(t-i)*a,d=c===1?h:-f,g=c===1?-f:h;this._calcOrderPercent(n,p,d,g)}}_calcOrderPercent(e,t,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:p,max_profit:h=0,trading_loss:f=0}=e;let{commission:d=0}=e;const g=p*c;if(i){const y=this._getCommission(a,c);t=t-y,d=d*c/l,r-=d,n+=d}r=Math.max(r,h),n=Math.min(n,f),t=t-d,Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/this._options.initial_capital*100,max_profit:r,trading_loss:n,profit_percent:t/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:e,low:t}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:i=0,commission_value:a=0}=this._options,l=this._orders[0].direction===gt.long?1:-1,c=l===1?t:e,p=(l===1?n:i)/100;if(p<=0)return;const[h,f,d]=this._orders.reduce((v,E)=>{let[b,N,x]=v;const{in_price:F,qty:M=0,original_qty:S=0,commission:I=0}=E,C=F*M,B=c*M;if(b+=C,N+=B,a){const L=this._getCommission(c,M);x+=L+M/S*I}return[b,N,x]},[0,0,0]),g=l*(f-h),m=r+this._totalChangeCapital+g-d-f*p;if(m>=0)return;const w=Math.trunc(m/p/c)*4;this._marginCallOrders(c,w,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r);return}for(const i of this.orders)this._processOrder(i,e,t,r,r);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(e){const{process_orders_on_close:t,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:l,price:c,activePrice:p}=this._orderArgsParse(e),h=e.direction===gt.long?1:-1;if(a<=0)return;let f=a;if(i&&t){if(n.length){const m=this._processOrders(n,l,f,e.id,e.comment);if(m<=0)return;f=m}const g=l+h*r*this._mintick;if(!this._judgeCapitalEnough(f,g,h))return;this._ocaGroupVerify(f,e.oca_name,e.oca_type),this._calcCurrentOrder({...e,in_price:g,in_index:this._variables.bar_index,in_time:this._variables.time,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,h)&&this._addPendingOrders(e,c,f,i,p)}_judgeCapitalEnough(e,t,r){if(e<=0)return!1;const{margin_long:n=0,margin_short:i=0}=this._options;if((n===0||n===100)&&r===1||i===0&&r===-1)return!0;const l=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return e*t<=l}_ocaGroupVerify(e,t,r){if(!t||!r||r===un.none)return!1;let n=!1;switch(r){case un.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===t)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(t===l){const c=a-e;return n=!0,c<=0?(i.isCancel=!0,!1):(i.qty=c,!0)}else return!0});break}return n}_processOrders(e,t,r,n,i){let a=r;for(const l of e)if(a=this._processOrder(l,t,a,n,i),a<=0)break;return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(e,t,r,n,i){const a=this._pendingOrders.find(l=>l.id===e.id&&!l.isMarketPrice);if(a)Object.assign(a,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else{const l={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(e){const{direction:t,qty:r,stop:n}=e;let i=e.limit||0;const{close:a}=this._variables;let l=a,c=!1,p;const h=t===gt.long?1:-1,f=n&&(n-a)*h>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&i&&(i-=d*this._mintick*h);const g=i&&(i-a)*h<0;f&&g?(p=n,l=i):f?l=n:g?l=i:c=!0;const y=r||this._calcDefaultQty(l)||1;return{orders:this._orders.filter(w=>w.direction!==t),isMarketPrice:c,activePrice:p,quantities:y,close:a,price:l}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:l,activePrice:c}=this._orderArgsParse(e);if(i<=0)return;if(r.length&&n&&t){this._entryOrder(r,a,i,e);return}this._judgeCapitalEnough(i,a,e.direction===gt.long?1:-1)&&this._addPendingEntry(e,l,i,n,c)}_entryOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{oca_name:c,oca_type:p,direction:h,comment:f,isMarketPrice:d,id:g}=n,y=h===gt.long?1:-1;if(this._closeOrders(e,t,g,f),r=this._getAvailablePositionSize(r,h),r<=0)return;t=t+l*this._mintick*y;const m={...n,in_price:t,original_qty:r,qty:r,in_index:a,in_time:i,place_order_type:"entry"};if(d){this._calcCurrentOrder(m);return}const{pendingOrders:w,orders:v}=this._getEntryOrders(h),E=w.length+v.length;E&&E>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,t,y)||(this._ocaGroupVerify(r,c,p),this._calcCurrentOrder(m))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==gt.all&&n!==t)return 0;if(r===void 0)return e;const i=this._orders.reduce((a,l)=>a+(l.qty||0),0);return i?i+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===e),r=this._orders.filter(n=>n.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,n,i){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(e.direction),c=a.length+l.length,p=a.find(h=>h.id===e.id&&h.place_order_type==="entry");if(p)Object.assign(p,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else if(!c||c<(this._options.pyramiding||1)){const h={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(e,t){const{comment:r}=e,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,t,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,n){for(const i of e)this._closeOrder(i,t,r,n);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{in_price:c,qty:p=0,direction:h}=e,f=h===gt.long?1:-1;t=t-f*l*this._mintick,e.isDeal=!0;const d=(t-c)*f*p,g={...e,out_price:t,out_id:r,out_index:a,out_time:i,out_comment:n,out_qty:p,profit:d};this._calcPercent(g),this._risk.intradayOrders+=1,this._historyOrder.push(g),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const e=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!e.length)return;const{open:t,low:r,high:n,close:i}=this._variables;for(const a of e){const{stop:l,limit:c,trail_stop_price:p,isMarketPriceLimit:h,isMarketPriceStop:f,direction:d,id:g,out_comment:y,active_price:m,trail_offset:w=0,out_qty:v,comment_loss:E,comment_profit:b,comment_trailing:N}=a;let x=p;const F=d===gt.long?1:-1;let M,S=y;if(h||f?M=t:(c&&r<=c&&n>=c&&(S=b||y,M=c),l&&r<=l&&n>=l&&(M=x?(l-x)*F>0?l:x:l,S=(x===M?N:E)||y)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let I=!1;if(m&&m<=n&&m>=r&&(x=m-w*F*this._mintick,(x-i)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=x)),I=!0,a.trail_stop_price=x),x)if((x-t)*F>=0&&!I)M=x;else{const C=(F===1?n:r)-w*F*this._mintick;F===1?x<t&&x>=r&&C>x&&C<i?M=x:C>x?(x=C,C>=i&&(M=C)):x<=n&&r<=x&&(M=x):x>t&&x<=n&&C<x&&C>i?M=x:C<x?(x=C,C<=i&&(M=C)):x<=n&&r<=x&&(M=x),a.trail_stop_price=x}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||y,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of r)switch(n.place_order_type){case"close":this._closeOrderHandle(n);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of this._pendingOrders){const{isCancel: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&&e.push(l)}for(const n of t){const i=this._exitOrderHandle(n);i&&e.push(i)}this._pendingOrders=e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const e=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),t=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of t)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of e){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)}this._pendingCloseOrders=[]}_entryOrderHandle(e){const{open:t,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:l,direction:c,active_price:p}=e;if(p&&n>=p&&r<=p)return delete e.active_price,e;let h=l;if(i&&(h=t),h<=n&&h>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,h,a,e)}else return e}_orderOrderHandle(e){const{open:t,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:p=0,in_price:h,direction:f,comment:d,oca_name:g,oca_type:y,active_price:m,id:w}=e;if(m&&n>=m&&r<=m)return delete e.active_price,e;let v=h,E=p;if(c&&(v=t),v<=n&&v>=r){const b=this._orders.filter(x=>x.direction!==f);if(b.length&&(E=this._processOrders(b,v,p,w,d),E<=0))return;const N=f===gt.long?1:-1;this._ocaGroupVerify(E,g,y),this._calcCurrentOrder({...e,in_price:v+N*l*this._mintick,in_index:a,in_time:i,qty:E});return}else return e}_closeOrderHandle(e,t){const{id:r,qty:n,qty_percent:i=100,comment:a}=e,{bar_index:l}=this._variables,c=this._orders.filter(g=>g.id===r&&g.in_index!==l&&(!g.close_qty||g.close_qty<(g.qty||0)));if(!c.length)return;let p=0;if(n?p=n:(p=c.reduce((g,y)=>g+(y.qty||0),p),p=i/100*p),p<=0)return;const{open:h,close:f}=this._variables;let d=p;for(const g of c){const{qty:y=0}=g;d<y?g.close_qty=d:(g.close_qty=y,d-=y)}this._processOrders(this._options.close_entries_rule==="ANY"?c:this._orders,t?f:h,p,`Close entry(s) order ${r}`,a)}_exitOrderHandle(e){const{from_entry:t}=e,r=this._orders.filter(n=>(!t||t===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,e)))return e}_exit(e,t){const{profit:r,loss:n,stop:i,limit:a,trail_offset:l,trail_price:c,trail_points:p,from_entry:h="",id:f}=e;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(p)&&this._isNaN(c))){this._errorListener.addError(ut.strategyExitErr,t,ze.Error);return}const d={...e,place_order_type:"exit"},g=this._orders.filter(w=>(!h||h===w.id)&&!w.hasExit),y=this._pendingOrders.filter(w=>!h||h===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);m?Object.assign(m,{...e}):this._pendingOrders.push(d)}_ordersToExit(e,t){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:l,comment_profit:c,comment_trailing:p}=t;let h=r,f=!1;t.comment=a||i;for(const d of e){const{qty:g=0}=d,y=d.direction===gt.long?1:-1;h=r?r>=g?g:r:n/100*g,d.out_qty=h,h<g&&(f=!0),Object.assign(d,{out_comment:a||i,comment_loss:l,comment_profit:c,comment_trailing:p}),!(this._stopProfit(d,y,{...t,qty:h})||this._stopLoss(d,y,{...t,qty:h})||this._trailStopLoss(d,y,{...t,qty:h}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(e){e.place_order_type="exit";const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r){const{limit:n,profit:i,comment_profit:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h+t*i*this._mintick),e.limit=c,c&&(c-p)*t<=0&&(e.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(e,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r){const{stop:n,loss:i,comment_loss:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h-t*i*this._mintick),e.stop=c,c&&(c-p)*t>=0&&(e.isMarketPriceStop=!0,r.comment=a||l,Object.assign(e,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(i)?this._isNaN(a)||(d=h+a*t*this._mintick):d=i,e.trail_offset=n,d&&(d-p)*t<=0){const g=p-n*t*this._mintick;if((g-p)*t>=0&&(e.trail_stop_price=p,e.isMarketPriceStop=!0,r.comment=l||c,Object.assign(e,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;e.trail_stop_price=g}e.active_price=d}}_processExitOnClose(e,t,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,t,n,a,i);c&&!c.hasExit?(c.hasExit=!0,Object.assign(e,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(e.hasExit=!0)}else e.hasExit=!0,this._processOrders([e],t,n,a,i)}_processExitOrders(e,t,r,n,i){let a=r,l;for(const c of e)if(l=c,a=this._processOrder(c,t,a,n,i),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),l}_processOrder(e,t,r,n,i){const{time:a,bar_index:l}=this._variables,{slippage:c=0}=this._options,{in_price:p,qty:h=0,max_profit:f=0,trading_loss:d=0,direction:g,commission:y=0,original_qty:m=0}=e,w=g===gt.long?1:-1;if(t=t-w*c*this._mintick,r<h){const v=h-r,E=(t-p)*w*r,b=f/h*r,N=d/h*r;this._calcPercent({...e,out_price:t,out_id:n,out_index:l,out_time:a,out_comment:i,profit:E,out_qty:r,max_profit:b,trading_loss:N});const x=(t-p)*w*v-y*v/m;Object.assign(e,{qty:v,profit:x,max_profit:f-b,trading_loss:d-N,total_profit:this._totalChangeCapital+x}),r=0}else{e.isDeal=!0;const v=(t-p)*w*h;this._calcPercent({...e,out_price:t,out_id:n,out_index:l,out_time:a,out_comment:i,out_qty:h,profit:v}),r-=h}return r}_calcPercent(e){const{commission_value:t}=this._options,{in_price:r,out_qty:n=0,out_price:i=0,original_qty:a=0}=e;let{profit:l=0,max_profit:c=0,trading_loss:p=0,commission:h=0}=e;c=c<0?0:c;const f=r*n;if(this._totalChangeCapital+=l,t){const d=this._getCommission(i,n);this._totalChangeCapital-=d,h=h*n/a+d,l=l-h,Object.assign(e,{commission:h,profit:l,max_profit:c})}Object.assign(e,{total_profit:this._totalChangeCapital,total_profit_percent:l/this._options.initial_capital*100,profit_percent:l/f*100,max_profit_percent:c/f*100,trading_loss_percent:p/f*100}),this._risk.intradayOrders+=1,this._historyOrder.push(e),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(e,t){const{commission_value:r=0,commission_type:n}=this._options,i=e*t;let a=0;switch(n){case Fr.percent:a=i*r/100;break;case Fr.cashPerContract:a=t*r;break;case Fr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=e;let{profit:l=0}=e;const c=r*n;if(t){const p=this._getCommission(r,n);this._totalChangeCapital-=p,l=l-p,Object.assign(e,{commission:p,profit:l,total_profit:this._totalChangeCapital})}Object.assign(e,{original_qty:n,total_profit_percent:l/this._options.initial_capital*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(e),this._variables.strategy.updateOrders(this._orders)}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}};var rh={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){return function(t,r,n){r.prototype.isBetween=function(i,a,l,c){var p=n(i),h=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(p,l):!this.isBefore(p,l))&&(d?this.isBefore(h,l):!this.isAfter(h,l))||(f?this.isBefore(p,l):!this.isAfter(p,l))&&(d?this.isAfter(h,l):!this.isBefore(h,l))}}})})(rh);var tw=rh.exports,rw=Ge(tw),nh={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){return function(t,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(I){var C,B;w[C=I,B=i.$utils().p(C),B==="date"?"day":B]=y[I]});var E=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(),x=w.hour||0,F=w.minute||0,M=w.second||0,S=w.millisecond||0;return m?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return y},l=i.parse;i.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=i.set,p=i.add,h=i.subtract,f=function(d,g,y,m){m===void 0&&(m=1);var w=Object.keys(g),v=this;return w.forEach(function(E){v=d.bind(v)(g[E]*m,E)}),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)(p,d,g):p.bind(this)(d,g)},i.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(p,d,g,-1):h.bind(this)(d,g)}}})})(nh);var nw=nh.exports,iw=Ge(nw),ih={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){var t,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,p=31536e6,h=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:p,months:h,days:l,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},g=function(F){return F instanceof N},y=function(F,M,S){return new N(F,S,M.$l)},m=function(F){return r.p(F)+"s"},w=function(F){return F<0},v=function(F){return w(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?w(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,I,C){var B=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return y(S*d[m(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(k){B.$d[m(k)]=S[k]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var U=L.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,C){return I+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/p),S%=p,this.$d.months=v(S/h),S%=h,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"),I=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var B=b(C,"D"),L=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var W=b(k,"S"),z=S.negative||I.negative||B.negative||L.negative||U.negative||W.negative,K=L.format||U.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+I.format+B.format+K+L.format+U.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},M.toJSON=function(){return this.toISOString()},M.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",C={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return I.replace(c,function(B,L){return L||String(C[B])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var I=this.$ms,C=m(S);return C==="milliseconds"?I%=1e3:I=C==="weeks"?v(I/d[C]):this.$d[C],I||0},M.add=function(S,I,C){var B;return B=I?S*d[m(I)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+B*(C?-1:1),this)},M.subtract=function(S,I){return this.add(S,I,!0)},M.locale=function(S){var I=this.clone();return I.$l=S,I},M.clone=function(){return y(this.$ms,this)},M.humanize=function(S){return t().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){t=S,r=S().$utils(),S.duration=function(B,L){var U=S.locale();return y(B,{$l:U},L)},S.isDuration=g;var I=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(B,L){return g(B)?x(this,B,1):I.bind(this)(B,L)},M.prototype.subtract=function(B,L){return g(B)?x(this,B,-1):C.bind(this)(B,L)}}})})(ih);var sw=ih.exports,ow=Ge(sw);tt.extend(Bl),tt.extend(rw),tt.extend(iw),tt.extend(ow);class sh{constructor(e,t,r){R(this,"array");R(this,"color");R(this,"math");R(this,"str");R(this,"map");R(this,"matrix");R(this,"timeframe");R(this,"ta");R(this,"input");R(this,"_variables");R(this,"_cacheData");R(this,"_options");R(this,"_errorListener");R(this,"_plots");R(this,"_plotshapes");R(this,"_plotbars");R(this,"_plotchars");R(this,"_plotarrows");R(this,"_plotcandles");R(this,"_alerts");R(this,"_bgColors");R(this,"_hlines");R(this,"_fills");R(this,"chart");R(this,"line");R(this,"label");R(this,"polyline");R(this,"box");R(this,"table");R(this,"linefill");R(this,"log");R(this,"runtime");R(this,"strategy");R(this,"request");R(this,"syminfo");R(this,"_count",0);var i;const n=((i=e.toString().split(".")[1])==null?void 0:i.length)||5;this._variables=t,this._errorListener=new fw,this.array=new Gp(this._errorListener),this.math=new Hp(n,this._errorListener),this.color=new D1,this.str=new by(this._errorListener,n),this.map=new Ey(this._errorListener),this.timeframe=new Dy(t),this.matrix=new wy(this._errorListener),this.ta=new y1(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new w1(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new xy(t)},this.line=new Zy(t,this._errorListener),this.label=new Ay(t,this._errorListener),this.polyline=new Vy(t,this._errorListener),this.box=new Gy(t,this._errorListener),this.table=new Hy(t,this._errorListener),this.linefill=new Ky(t),this.log=new lw(t),this.runtime=new cw(this._errorListener),this.strategy=new ew(this._variables,this._options,e,this._errorListener),this.request=new aw(this._variables,r),this.syminfo=new uw}get errors(){return this._errorListener.errors}options(e){if(e.length)return this._getDataOfBarindex(e);const t=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});const p=this._plots.size>0?[...this._plots.values()]:void 0,h=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:t,plots:p,draws:m,alerts:r,colors:i,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:d,plotcandles:g,plotchars:y,plotbars:h,isUseBgColor:w})}_getDataOfBarindex(e){const t=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 e){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(e,[...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(e,[...this._plots.values()]),p=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,h=this._getDrawsFromBarindex(e),f=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,draws:h,alerts:t,colors:n,hlines:i,fills:a,logs:l,plotshapes:p,isUseBgColor:f})}_getDataFromBarindex(e,t){return t.map(r=>{const n=[];for(const i of e){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:n,polyline:i,label:a}=this._variables,l={};return e.data.length&&(l.lines=e.data),t.data.length&&(l.linefills=t.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(e){const{line:t,linefill:r,table:n,box:i,polyline:a,label:l}=this._variables,c={};return t.data.length&&(c.lines=t.getValOfBarIndex(e)),r.data.length&&(c.linefills=r.getValOfBarIndex(e)),n.data.length&&(c.tables=n.getValOfBarIndex(e)),i.data.length&&(c.boxes=i.getValOfBarIndex(e)),a.data.length&&(c.polylines=a.getValOfBarIndex(e)),l.data.length&&(c.labels=l.getValOfBarIndex(e)),Object.keys(c).length?c:void 0}updateOptions(e){const{inputs:t}=e;this.input.update(t)}update(e){const{barIndex:t}=e;this.strategy.updateOptions(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=e;r.test(n)?(Kp.includes(n)||Zp.includes(n))&&this._errorListener.addError(jt(ut.libraryTitleIsKeywordErr,{name:n}),t,ze.Error):this._errorListener.addError(ut.libraryTitleErr,t,ze.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r}=e;this._paramVerfiy(r,t,"indicator",[Ke.inherit,Ke.percent,Ke.price,Ke.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,n,i="format"){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(Yp.lineWidthWarning,t,ze.Warning),e.linewidth=1)}plot(e,t){const r=["color"];_t(e,r);const{series:n,color:i,...a}=e,{bar_index:l,time:c}=this._variables,p=`plot_${t}`,h=this._plots.get(p),f=(h==null?void 0:h.data)||[],d=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,d],itemStyle:{color:i}},this._seriesColorHandle(e,r,h),!h){this._count++,this._lineWidthVerify(a,t),this._paramVerfiy(e.format,t,"plot",[Ke.percent,Ke.price,Ke.volume]);const g=i?[i]:void 0;this._plots.set(p,{editable:!0,...a,colors:g,data:f,id:p,zIndex:this._count})}return{type:"plot",key:p}}plotbar(e,t){const r=["color"];_t(e,r);const{open:n,close:i,low:a,high:l,color:c,...p}=e,{bar_index:h,time:f}=this._variables,d=`plotbar_${t}`,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,E=l!==void 0&&isNaN(l)?void 0:l,b=[f,w,m,v,E];if(y[h]={value:b,itemStyle:{color:c}},this._seriesColorHandle(e,r,g),!g){this._count++,this._paramVerfiy(e.format,t,"plotbar",[Ke.percent,Ke.price,Ke.volume]);const N=c?[c]:void 0;this._plotbars.set(d,{editable:!0,...p,colors:N,data:y,id:d,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:n,format:i,location:a,style:l}=e;this._paramVerfiy(l,r,t,Object.values(or),"style"),this._paramVerfiy(a,r,t,Object.values(an),"location"),this._paramVerfiy(n,r,t,Object.values(tr),"size"),this._paramVerfiy(i,r,t,[Ke.percent,Ke.price,Ke.volume],"format")}plotchar(e,t){const r=["color","textcolor"];_t(e,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=e,{bar_index:p,time:h,high:f,low:d}=this._variables,g=`plotchar_${t}`,y=this._plotchars.get(g),m=(y==null?void 0:y.data)||[],w={value:[h,n],itemStyle:{color:i,textcolor:a},low:d,high:f};m[p]=w,this._seriesColorHandle(e,r,y),y||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];_t(e,r);const{series:n,colorup:i,colordown:a,...l}=e,{bar_index:c,time:p}=this._variables,h=`plotarrow_${t}`,f=this._plotarrows.get(h),d=(f==null?void 0:f.data)||[];d[c]={value:[p,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:i,colordown:a}},this._seriesColorHandle(e,r,f),f||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[Ke.percent,Ke.price,Ke.volume]),this._plotarrows.set(h,{editable:!0,...l,data:d,id:h,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];_t(e,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=e,{bar_index:p,time:h,low:f,high:d}=this._variables,g=`plotshape_${t}`,y=this._plotshapes.get(g),m=(y==null?void 0:y.data)||[],w={value:n,color:i,textcolor:a,time:h,low:f,high:d};if(m[p]=w,this._seriesColorHandle(e,r,y),!y){this._count++;const v=i?[i]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];_t(e,r);const{wickcolor:n,bordercolor:i,color:a,close:l,open:c,low:p,high:h,...f}=e,{bar_index:d,time:g}=this._variables,y=`plotcandle_${t}`,m=this._plotcandles.get(y),w=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,E=c!==void 0&&isNaN(c)?void 0:c,b=p!==void 0&&isNaN(p)?void 0:p,N=h!==void 0&&isNaN(h)?void 0:h,x=[g,E,v,b,N];w[d]={value:x,wickcolor:n,bordercolor:i,color:a},this._seriesColorHandle(e,r,m),m||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[Ke.percent,Ke.price,Ke.volume]),this._plotcandles.set(y,{editable:!0,...f,data:w,id:y,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;_t(e,["color"]),this._verifyDisplay(e.display,"hline",t);const i=e.display&&!e.display.length?Yt.none:Yt.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:i,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var S,I,C,B,L,U,k,W,z,K;const r=["color","top_color","bottom_color"];_t(e,r);const{color:n,top_color:i,bottom_color:a,seriesColors:l,hline1:c,hline2:p,plot1:h,plot2:f,top_value:d,bottom_value:g,...y}=e,{bar_index:m,time:w}=this._variables,v=`fill_${t}`,E=this._fills.get(v),b=(E==null?void 0:E.data)||[];this._verifyDisplay(e.display,"fill",t);const N=e.display&&!e.display.length?Yt.none:Yt.all;let x,F,M="plot";if(c&&p)x=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,F=(I=this._hlines.get(p==null?void 0:p.key))==null?void 0:I.price,M="hline";else{const Z=((C=this._plots.get(h==null?void 0:h.key))==null?void 0:C.data)||[],X=((B=this._plots.get(f==null?void 0:f.key))==null?void 0:B.data)||[];x=(U=(L=Z[m])==null?void 0:L.value)==null?void 0:U[1],F=(W=(k=X[m])==null?void 0:k.value)==null?void 0:W[1]}if(b[m]={time:w,color:n,top_color:i,bottom_color:a,plot1:x,plot2:F,top_value:d,bottom_value:g},this._seriesColorHandle(e,r,E),!E){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,ce=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ce,display:N,data:b,type:M,editable:!0,fillgaps:!1,hline1:c,hline2:p,plot1:h,plot2:f,...y,zIndex:Z?this._count:void 0})}}alert({message:e,freq:t=kr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},p=c.barIndex;if(this._paramVerfiy(t,r,"alert",[kr.freqAll,kr.freqOncePerBar,kr.freqOncePerBarClose]),t===kr.freqOncePerBar&&n===p){this._alerts.delete(l);return}this._cacheData[l]=c;const h={message:e,freq:t,id:l,type:"alert"};if(i){t!==kr.freqOncePerBarClose&&this._alerts.set(l,h),c.barIndex=n;return}if(!i&&t===kr.freqOncePerBarClose&&n===p&&a===n-1){this._alerts.set(l,h),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:e,message:t,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&e?this._alerts.set(a,{message:t,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=Qf.all,t,r){e.length&&e.length<4&&this._errorListener.addError(jt(ut.displayErr,{func:t,values:"[display.none, display.all]"}),r,ze.Error)}_setColors(e,t,r){_t(e,["color"]);const{color:i,...a}=e;this._verifyDisplay(a.display,t,r);const l=e.display&&!e.display.length?Yt.none:Yt.all,{bar_index:c,time:p}=this._variables,h=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const f=this._bgColors[t].get(h),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:p},f||this._bgColors[t].set(h,{...a,display:l,colors:d,setColors:g,id:h})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||isNaN(e))}fixnan({source:e},t){return e===void 0||isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!isNaN(e)?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,e,t,r,n)}time_close({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,e,t,r,n)}timestamp(e){const{dateString:t,timezone:r,year:n,month:i,day:a,hour:l=0,minute:c=0,second:p=0}=e;if(t)return tt(t).utc(!/GMT|UTC/.test(t)).valueOf();let h=i-1,f=n;if(h<0){const g=Math.ceil(Math.abs(h/12));h=12*g+h,f=n-g}let d=tt({year:f,month:h,day:a,hour:l,minute:c,second:p});return r&&(d=qr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:e,timezone:t}){return qr(e,t).week()}year({time:e,timezone:t}){return qr(e,t).year()}second({time:e,timezone:t}){return qr(e,t).second()}month({time:e,timezone:t}){return qr(e,t).month()+1}minute({time:e,timezone:t}){return qr(e,t).minute()}hour({time:e,timezone:t}){return qr(e,t).hour()}dayofweek({time:e,timezone:t}){return qr(e,t).day()+1}dayofmonth({time:e,timezone:t}){return qr(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,t),n=Xr(t)*1e3;return e-r-Math.floor((e-r)/n)*n}_timeHandle(e,t,r="",n,i,a=0){const l=r||this._variables.timeframe.period,c=Xr(l),p=Xr(this._variables.timeframe.period);let h;if(c<=p)h=e;else{const f=`time_${t}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=e?(h=e,this._cacheData[f]={currentTime:e,offset:0}):h=d;else{const g=this._calcTimeOffset(e,l);this._cacheData[f]={currentTime:e,offset:g},h=e}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,t),g=tt(e).format("YYYY-MM-DD"),y=h;h=void 0;for(const w of f){const[v,E]=w;if(tt(e).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")){tt(y).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")?h=y:h=tt(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;h&&!d.includes(m)&&(h=void 0)}return i&&(h=h&&qr(h,i).valueOf()),h&&h-a*p*1e3}_seriesColorHandle(e,t,r){var n;if(r&&t!=null&&t.length)for(const i of t){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=e[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(e,t){const r=e.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const p=parseInt(c,10);if(p<1||p>7){this._errorListener.addError(`Invalid day of week: ${c}`,t,ze.Error);return}return p});return{timePeriods:n.split(",").map(c=>{c===""||c===fi.regular?c="0930-1500":c===fi.extended&&(c="1500-1830");const p=c.split("-");return p.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,t,ze.Error),[]):[this._processTime(p[0],t),this._processTime(p[1],t)]}),weeks:a}}_processTime(e,t){const r=parseInt(e.slice(0,2),10),n=parseInt(e.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",t,ze.Error);return}return`${r}:${n}`}}class aw{constructor(e,t){R(this,"_variables");R(this,"_scriptId");R(this,"_cacheData");this._variables=e,this._scriptId=t,this._cacheData=new Map}security(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=e,i=this._getRequestData(e,t);if(r!=null&&r.has(t)){const c=r.get(t);return this._runScripts(c,t,!1,n,i)}const a=this._parseExprCode(e),l=this._runScripts(a,t,!0,n,i);return r==null||r.set(t,a),l}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,n=[],i=1;t=Il(t);const a=JSON.parse(t),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},p=(l==null?void 0:l.depends)||[];if(!p.length)return`return ${l==null?void 0:l.code}`;let h=[],f=[];const d=[];if(this._getDependCodes(p,a,n,h,f,d),f.length){const m=r.length;let w=[];for(let v=m-1;v>=0;v--){const E=r[v];let b=JSON.parse(Il(E));const N=[];i!==0&&f.length&&(w.unshift("{"),i++),b=b.map(S=>{const{scope:I,code:C,varNames:B,dependSelf:L}=S;return I===2&&!N.includes(B)&&!L&&(S.code=`let ${C}`),B&&N.push(...B.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const x=[],F=[];let M=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(M,b,F,h,f,x),w.unshift(...F,...x),n=w.concat(n),w=[]}}for(n.push(`return ${l==null?void 0:l.code}`);i>1;)n.push("}"),i--;n=h.concat(n),n.push(...d);let g=n.join(`
|
62
|
+
`)}}if(typeof e=="string")return e;if(typeof e=="boolean")return String(e);if(typeof e=="number")return String(this._toStringFormat(e,t))}_arrToStr(e,t){return`[${e.map(n=>typeof n=="number"?this._toStringFormat(n,t):n).toString()}]`}substring({source:e="",begin_pos:t=0,end_pos:r}){return _e(t)&&(t=0),_e(r)&&(r=void 0),e==null?void 0:e.substring(t,r)}startswith({source:e="",str:t=""}){return e==null?void 0:e.startsWith(t)}format_time({time:e,format:t="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return _e(e)&&(e=0),qr(e,r).format(t)}replace_all({source:e="",target:t="",replacement:r=""}){return e==null?void 0:e.replace(new RegExp(t,"g"),r)}_toStringFormat(e,t){if(!t)return Number(e.toFixed(this._precision));switch(t){case Ke.mintick:return e.toFixed(this._precision);case Ke.percent:return`${e}%`;case Ke.volume:return this._intlNumberFormatter.format(Math.round(e));default:return this._formatOthers(e,t)}}_formatOthers(e,t){var l;let[r,n]=t.split(".");t.split("%").length===2&&(e=e*100);let[i,a=""]=String(e).split(".");if(r.includes("#")){if(r.includes(",")){const c=r.split(","),p=((l=c[c.length-1])==null?void 0:l.replace(/[^#]/g,"").length)||0;p&&(i=i.replace(new RegExp(`\\B(?=(\\d{${p}})+(?!\\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(e,t){if(!t)return Number(e.toFixed(this._precision));switch(t){case"integer":return String(Math.round(e));case"currency":return`$${e}`;case"percent":return`${e*100}%`;default:return this._formatOthers(e,t)}}_strFormat(e,t){let r=e;for(const[n,i]of t.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=e.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(e){R(this,"_errorListener");this._errorListener=e}new(){return new ka(this._errorListener)}copy({id:e}){return e==null?void 0:e.copy()}get({id:e,key:t}){return e==null?void 0:e.get({key:t})}put({id:e,key:t,value:r}){return e==null?void 0:e.put({key:t,value:r})}keys({id:e}){return e==null?void 0:e.keys()}size({id:e}){return e==null?void 0:e.size()}clear({id:e}){e==null||e.clear()}remove({id:e,key:t}){return e==null?void 0:e.remove({key:t})}values({id:e}){return e==null?void 0:e.values()}put_all({id:e,id2:t}){e==null||e.put_all({id2:t})}contains({id:e,key:t}){return e==null?void 0:e.contains({key:t})}}class ka{constructor(e){R(this,"_errorListener");R(this,"_mapInstance");this._errorListener=e,this._mapInstance=new Map}get isMap(){return!0}_copyMap(e){const t=new ka(this._errorListener);return t._mapInstance=new Map(e.entries()),t}copy(){return this._copyMap(this._mapInstance)}get({key:e}){return this._mapInstance.get(e)}put({key:e,value:t}){return this._mapInstance.set(e,t)}keys(){const e=new Qe(0,void 0,this._errorListener);return e._value=[...this._mapInstance.keys()],e}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:e}){const t=this._mapInstance.get(e);return this._mapInstance.delete(e),t||void 0}values(){const e=new Qe(0,void 0,this._errorListener);return e._value=[...this._mapInstance.values()],e}put_all({id2:e}){this._mapInstance=new Map([...this._mapInstance,...e._mapInstance])}contains({key:e}){return this._mapInstance.has(e)}}class xy{constructor(e){R(this,"_variables");this._variables=e}new({price:e,time:t,index:r}){return new Ai(e,r,t)}now({price:e}){const{time:t,bar_index:r}=this._variables;return new Ai(e,r,t)}copy({id:e}){return e==null?void 0:e.copy()}from_index({price:e,index:t}){return new Ai(e,t)}from_time({price:e,time:t}){return new Ai(e,void 0,t)}}class Ai{constructor(e,t,r){R(this,"_index");R(this,"_price");R(this,"_time");this._index=t,this._price=e,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 Ay{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLabel",{text:"",xloc:wt.bar_index,yloc:Wr.price,size:tr.normal,style:mt.styleLabelDown,textalign:We.alignCenter});this._variables=e,this._errorListener=t}new(e,t){const{time:r,high:n,low:i,bar_index:a}=this._variables,l=`label_${t}_${a}`;_t(e,["color","textcolor"]);const c={...this._defaultLabel,...e,id:l,time:r,high:n,low:i};e.point&&(c.x=c.xloc===wt.bar_index?e.point.index:e.point.time,c.y=e.point.price),c.yloc===Wr.abovebar?c.y=n:c.yloc===Wr.belowbar&&(c.y=i),this._verfiyArgs(e,t);const p=new ts(l,this._variables,this._errorListener);return t.startsWith("export")||this._variables.label.add(l,c,p),p}_verfiyArgs(e,t){const{xloc:r,yloc:n,style:i,size:a,textalign:l,text_font_family:c}=e,p="label.new";this._paramVerfiy(i,t,p,Object.values(mt),"style"),this._paramVerfiy(r,t,p,Object.values(wt),"xloc"),this._paramVerfiy(n,t,p,Object.values(Wr),"yloc"),this._paramVerfiy(a,t,p,Object.values(tr),"size"),this._paramVerfiy(l,t,p,[We.alignLeft,We.alignCenter,We.alignRight],"textalign"),this._paramVerfiy(c,t,p,Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}label(e,t){return e.x?e.x:new ts(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}get_x({id:e},t){return e==null?void 0:e.get_x(t)}get_y({id:e},t){return e==null?void 0:e.get_y(t)}set_x({id:e,...t},r){e==null||e.set_x(t,r)}set_y({id:e,...t},r){e==null||e.set_y(t,r)}delete({id:e}){e==null||e.delete()}get_text({id:e},t){return e==null?void 0:e.get_text(t)}set_xy({id:e,...t},r){e==null||e.set_xy(t,r)}set_size({id:e,...t},r){e==null||e.set_size(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}set_yloc({id:e,...t},r){e==null||e.set_yloc(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_tooltip({id:e,...t},r){e==null||e.set_tooltip(t,r)}set_point({id:e,...t},r){e==null||e.set_point(t,r)}set_text({id:e,...t},r){e==null||e.set_text(t,r)}set_textcolor({id:e,...t},r){e==null||e.set_textcolor(t,r)}set_textalign({id:e,...t},r){e==null||e.set_textalign(t,r)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ts{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}copy(e){const t=`label_${e}_${this._variables.bar_index}`,r=this._getLabel(e),n=new ts(t,this._variables,this._errorListener);if(r){const i={...r,id:t};this._variables.label.add(t,i,n)}return n}get_x(e){var t;return(t=this._getLabel(e))==null?void 0:t.x}get_y(e){var t;return(t=this._getLabel(e))==null?void 0:t.y}set_x({x:e},t){const r=this._getLabel(t);r&&(r.x=e)}set_y({y:e},t){const r=this._getLabel(t);r&&(r.y=e)}delete(){this._variables.label.delete(this._id)}set_xy({x:e,y:t},r){const n=this._getLabel(r);n&&(n.x=e,n.y=t)}get_text(e){var t;return(t=this._getLabel(e))==null?void 0:t.text}set_size({size:e},t){const r=this._getLabel(t);r&&(r.size=e),this._paramVerfiy(e,t,"label.set_size",Object.values(tr),"size")}set_text({text:e},t){const r=this._getLabel(t);r&&(r.text=e)}set_xloc({x:e,xloc:t},r){const n=this._getLabel(r);n&&(n.x=e,n.xloc=t,this._paramVerfiy(t,r,"label.set_xloc",Object.values(wt),"xloc"))}set_yloc({yloc:e},t){const r=this._getLabel(t),{high:n,low:i}=this._variables;r&&(r.yloc=e,e===Wr.abovebar?r.y=n:e===Wr.belowbar&&(r.y=i),this._paramVerfiy(e,t,"label.set_yloc",Object.values(Wr),"yloc"))}set_color(e,t){const r=this._getLabel(t);_t(e,["color"]),r&&(r.color=e.color)}set_point({point:e},t){const r=this._getLabel(t);r&&(r.x=r.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,r.y=e==null?void 0:e.price)}set_style({style:e},t){const r=this._getLabel(t);r&&(r.style=e),this._paramVerfiy(e,t,"label.set_style",Object.values(mt),"style")}set_tooltip({tooltip:e},t){const r=this._getLabel(t);r&&(r.tooltip=e)}set_textalign({textalign:e},t){const r=this._getLabel(t);r&&(r.textalign=e),this._paramVerfiy(e,t,"label.set_textalign",[We.alignLeft,We.alignCenter,We.alignRight],"textalign")}set_textcolor(e,t){const r=this._getLabel(t);_t(e,["textcolor"]),r&&(r.textcolor=e.textcolor)}set_text_font_family({text_font_family:e},t){const r=this._getLabel(t);r&&(r.text_font_family=e),this._paramVerfiy(e,t,"label.set_text_font_family",Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getLabel(e){const t=this._variables.label.get(this._id);return t||console.log(`错误${e}: label 不存在`),t}}const Cy={freq_all:kr.freqAll,freq_once_per_bar:kr.freqOncePerBar,freq_once_per_bar_close:kr.freqOncePerBarClose},Fy={gaps_off:Vi.gapsOff,gaps_on:Vi.gapsOn,lookahead_off:Vi.lookaheadOff,lookahead_on:Vi.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"},My={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},Qf={all:[Yt.dataWindow,Yt.pane,Yt.priceScale,Yt.statusLine],data_window:[Yt.dataWindow],none:[],pane:[Yt.pane],price_scale:[Yt.priceScale],status_line:[Yt.statusLine]},Ny={both:Ur.both,left:Ur.left,none:Ur.none,right:Ur.right},Sy={inherit:Ke.inherit,mintick:Ke.mintick,percent:Ke.percent,price:Ke.price,volume:Ke.volume},By={style_solid:xs.styleSolid,style_dashed:xs.styleDashed,style_dotted:xs.styleDotted},Oy={style_arrowdown:mt.styleArrowdown,style_arrowup:mt.styleArrowup,style_circle:mt.styleCircle,style_cross:mt.styleCross,style_diamond:mt.styleDiamond,style_flag:mt.styleFlag,style_label_center:mt.styleLabelCenter,style_label_down:mt.styleLabelDown,style_label_left:mt.styleLabelLeft,style_label_lower_left:mt.styleLabelLowerLeft,style_label_lower_right:mt.styleLabelLowerRight,style_label_right:mt.styleLabelRight,style_label_up:mt.styleLabelUp,style_label_upper_left:mt.styleLabelUpperLeft,style_label_upper_right:mt.styleLabelUpperRight,style_none:mt.styleNone,style_square:mt.styleSquare,style_text_outline:mt.styleTextOutline,style_triangledown:mt.styleTriangledown,style_triangleup:mt.styleTriangleup,style_xcross:mt.styleXcross},Ty={style_arrow_both:Lt.styleArrowBoth,style_arrow_left:Lt.styleArrowLeft,style_arrow_right:Lt.styleArrowRight,style_dashed:Lt.styleDashed,style_dotted:Lt.styleDotted,style_solid:Lt.styleSolid},Iy={abovebar:an.abovebar,absolute:an.absolute,belowbar:an.belowbar,bottom:an.bottom,top:an.top},$y={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},Ly={style_area:Cr.styleArea,style_areabr:Cr.styleAreabr,style_circles:Cr.styleCircles,style_columns:Cr.styleColumns,style_cross:Cr.styleCross,style_histogram:Cr.styleHistogram,style_line:Cr.styleLine,style_linebr:Cr.styleLinebr,style_stepline:Cr.styleStepline,style_stepline_diamond:Cr.styleSteplineDiamond,style_steplinebr:Cr.styleSteplinebr},Ry={bottom_center:pr.bottomCenter,bottom_left:pr.bottomLeft,bottom_right:pr.bottomRight,middle_center:pr.middleCenter,middle_left:pr.middleLeft,middle_right:pr.middleRight,top_center:pr.topCenter,top_left:pr.topLeft,top_right:pr.topRight},Py={left:As.left,none:As.none,right:As.right},zy={arrowdown:or.arrowdown,arrowup:or.arrowup,circle:or.circle,cross:or.cross,diamond:or.diamond,flag:or.flag,labeldown:or.labeldown,labelup:or.labelup,square:or.square,triangledown:or.triangledown,triangleup:or.triangleup,xcross:or.xcross},qy={auto:tr.auto,huge:tr.huge,large:tr.large,normal:tr.normal,small:tr.small,tiny:tr.tiny},ky={cash:Ot.cash,fixed:Ot.fixed,percent_of_equity:Ot.percentOfEquity,commission:{cash_per_contract:Fr.cashPerContract,cash_per_order:Fr.cashPerOrder,percent:Fr.percent},direction:{all:gt.all,long:gt.long,short:gt.short},oca:{cancel:un.cancel,none:un.none,reduce:un.reduce}},Uy={align_bottom:We.alignBottom,align_center:We.alignCenter,align_left:We.alignLeft,align_right:We.alignRight,align_top:We.alignTop,wrap_auto:We.wrapAuto,wrap_none:We.wrapNone},Wy={bar_index:wt.bar_index,bar_time:wt.bar_time},jy={abovebar:Wr.abovebar,belowbar:Wr.belowbar,price:Wr.price},Yy={actual:Cs.actual,estimate:Cs.estimate,standardized:Cs.standardized};class eh{constructor(){R(this,"adjustment",{dividends:Es.dividends,none:Es.none,splits:Es.splits});R(this,"alert",Cy);R(this,"barmerge",Fy);R(this,"color",Ci);R(this,"currency",Xf);R(this,"dayofweek",My);R(this,"earnings",Yy);R(this,"display",Qf);R(this,"extend",Ny);R(this,"font",{family_default:Zn.familyDefault,family_monospace:Zn.familyMonospace});R(this,"format",Sy);R(this,"hline",By);R(this,"label",Oy);R(this,"line",Ty);R(this,"location",Iy);R(this,"math",$y);R(this,"order",{ascending:Vn.ascending,descending:Vn.descending});R(this,"plot",Ly);R(this,"position",Ry);R(this,"scale",Py);R(this,"session",{extended:fi.extended,regular:fi.regular});R(this,"shape",zy);R(this,"size",qy);R(this,"splits",{denominator:"denominator",numerator:"numerator"});R(this,"strategy",ky);R(this,"text",Uy);R(this,"xloc",Wy);R(this,"yloc",jy)}updateData(){}}class Vy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:wt.bar_index,line_color:Ci.blue,line_style:Lt.styleSolid,line_width:1});this._variables=e,this._errorListener=t}new(e,t){var a;const r=`polyline_${t}_${this._variables.bar_index}`,n=Object.assign({},this._defaultPolyline,e,{id:r,points:(a=e.points)==null?void 0:a._value.map(l=>({time:l.time,index:l.index,price:l.price}))});_t(n,["line_color","fill_color"]);const i=new th(r,this._variables);return this._verfiyArgs(e,t),t.startsWith("export")||this._variables.polyline.add(r,n,i),i}_verfiyArgs(e,t){const{line_style:r,xloc:n}=e,i="polyline.new";this._paramVerfiy(r,t,i,Object.values(Lt),"line_style"),this._paramVerfiy(n,t,i,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}delete({id:e}){e&&e.delete()}}class th{constructor(e,t){R(this,"_id");R(this,"_variables");this._variables=t,this._id=e}delete(){this._variables.polyline.delete(this._id)}}class Zy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultLine",{xloc:wt.bar_index,extend:Ur.none,style:Lt.styleSolid});this._variables=e,this._errorListener=t}new({first_point:e,second_point:t,...r},n){const i=`line_${n}_${this._variables.bar_index}`;_t(r,["color"]);const a={...this._defaultLine,...r,id:i};if(e&&t){const c=a.xloc===wt.bar_index?e==null?void 0:e.index:e==null?void 0:e.time,p=a.xloc===wt.bar_index?t==null?void 0:t.index:t==null?void 0:t.time;Object.assign(a,{x1:c,y1:e==null?void 0:e.price,x2:p,y2:t==null?void 0:t.price})}this._verfiyArgs(r,n);const l=new rs(i,this._variables,this._errorListener);return n.startsWith("export")||this._variables.line.add(i,a,l),l}_verfiyArgs(e,t){const{extend:r,xloc:n,style:i}=e,a="line.new";this._paramVerfiy(i,t,a,Object.values(Lt),"style"),this._paramVerfiy(r,t,a,Object.values(Ur),"extend"),this._paramVerfiy(n,t,a,Object.values(wt),"xloc")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}line(e,t){return e.x?e.x:new rs(t,this._variables,this._errorListener)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_x1({id:e},t){return e==null?void 0:e.get_x1(t)}get_x2({id:e},t){return e==null?void 0:e.get_x2(t)}get_y1({id:e},t){return e==null?void 0:e.get_y1(t)}get_y2({id:e},t){return e==null?void 0:e.get_y2(t)}set_x1({id:e,...t},r){e==null||e.set_x1(t,r)}set_x2({id:e,...t},r){e==null||e.set_x2(t,r)}set_y1({id:e,...t},r){e==null||e.set_y1(t,r)}set_y2({id:e,...t},r){e==null||e.set_y2(t,r)}set_xy1({id:e,...t},r){e==null||e.set_xy1(t,r)}set_xy2({id:e,...t},r){e==null||e.set_xy2(t,r)}set_xloc({id:e,...t},r){e==null||e.set_xloc(t,r)}get_price({id:e,...t},r){return e==null?void 0:e.get_price(t,r)}set_color({id:e,...t},r){e==null||e.set_color(t,r)}set_style({id:e,...t},r){e==null||e.set_style(t,r)}set_width({id:e,...t},r){e==null||e.set_width(t,r)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_first_point({id:e,...t},r){e==null||e.set_first_point(t,r)}set_second_point({id:e,...t},r){e==null||e.set_second_point(t,r)}}class rs{constructor(e,t,r){R(this,"_variables");R(this,"_id");R(this,"_errorListener");this._id=e,this._variables=t,this._errorListener=r}get data(){return this._variables.line.get(this._id)}copy(e){const t=`line_${e}_${this._variables.bar_index}`,r=this._getLine(e),n=new rs(t,this._variables,this._errorListener);return r&&this._variables.line.add(t,{...r,id:t},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:e},t){const r=this._getLine(t);if(e===void 0)return e;if(r&&r.xloc===wt.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)*(e-n)+i}}get_x1(e){var t;return(t=this._getLine(e))==null?void 0:t.x1}get_x2(e){var t;return(t=this._getLine(e))==null?void 0:t.x2}get_y1(e){var t;return(t=this._getLine(e))==null?void 0:t.y1}get_y2(e){var t;return(t=this._getLine(e))==null?void 0:t.y2}set_x1({x:e},t){const r=this._getLine(t);r&&(r.x1=e)}set_x2({x:e},t){const r=this._getLine(t);r&&(r.x2=e)}set_y1({y:e},t){const r=this._getLine(t);r&&(r.y1=e)}set_y2({y:e},t){const r=this._getLine(t);r&&(r.y2=e)}set_xy1({x:e,y:t},r){const n=this._getLine(r);n&&(n.x1=e,n.y1=t)}set_xy2({x:e,y:t},r){const n=this._getLine(r);n&&(n.x2=e,n.y2=t)}set_xloc({xloc:e,x1:t,x2:r},n){const i=this._getLine(n);i&&(i.xloc=e,i.x1=t,i.x2=r,this._paramVerfiy(e,n,"line.set_xloc",Object.values(wt),"xloc"))}set_color(e,t){const r=this._getLine(t);r&&(_t(e,["color"]),r.color=e.color)}set_style({style:e},t){const r=this._getLine(t);r&&(r.style=e,this._paramVerfiy(e,t,"line.set_style",Object.values(Lt),"style"))}set_width({width:e},t){const r=this._getLine(t);r&&(r.width=e)}set_extend({extend:e},t){const r=this._getLine(t);r&&(r.extend=e,this._paramVerfiy(e,t,"line.set_extend",Object.values(Ur),"extend"))}set_first_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},l=r.xloc===wt.bar_index?n:i,c=a;l&&(r.x1=l),c&&(r.y1=c)}}set_second_point({point:e},t){const r=this._getLine(t);if(r){const{index:n,time:i,price:a}=e||{},l=r.xloc===wt.bar_index?n:i,c=a;l&&(r.x2=l),c&&(r.y2=c)}}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getLine(e){const t=this._variables.line.get(this._id);return t||console.log(`${e}: line 不存在`),t}}class Ky{constructor(e){R(this,"_variables");this._variables=e}new(e,t){const{line1:r,line2:n}=e,i=`linefill_${t}_${this._variables.bar_index}`,a=r==null?void 0:r.data,l=n==null?void 0:n.data;a&&(a.linefills=a.linefills||[],a.linefills.push(i)),l&&(l.linefills=l.linefills||[],l.linefills.push(i)),_t(e,["color"]);const c=new co(this._variables,i,r,n);return t.startsWith("export")||(a||l)&&this._variables.linefill.add(i,{line1:a,line2:l,color:e.color,id:i},c),c}delete({id:e}){e==null||e.delete()}get_line1({id:e}){return e==null?void 0:e.get_line1()}get_line2({id:e}){return e==null?void 0:e.get_line2()}set_color({id:e,...t}){e==null||e.set_color(t)}}class co{constructor(e,t,r,n){R(this,"_id");R(this,"_line1");R(this,"_line2");R(this,"_variables");this._variables=e,this._id=t,this._line1=r,this._line2=n}linefill(e,t){return e.x?e.x:new co(this._variables,t)}delete(){var t,r;const e=this._variables.linefill.get(this._id);if(e){const{line1:n,line2:i}=e;n&&(n.linefills=(t=n.linefills)==null?void 0:t.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(e){const t=this._variables.linefill.get(this._id);t&&(_t(e,["color"]),t.color=e.color)}}class Gy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultBox",{border_color:Ci.blue,border_width:1,bgcolor:Ci.blue,xloc:wt.bar_index,extend:Ur.none,style:Lt.styleSolid,text:"",text_size:tr.auto,text_color:Ci.black,text_halign:We.alignCenter,text_valign:We.alignCenter,text_wrap:We.wrapNone});this._variables=e,this._errorListener=t}box({x:e},t){return e===void 0?new ns(this._variables,t,this._errorListener):e}new({top_left:e,bottom_right:t,...r},n){const i=`box_${n}_${this._variables.bar_index}`,a={...this._defaultBox,...r,id:i};if(_t(a,["border_color","bgcolor","text_color"]),e){const{price:c,time:p,index:h}=e;a.top=c,a.left=a.xloc===wt.bar_index?h:p}if(t){const{price:c,time:p,index:h}=t;a.bottom=c,a.right=a.xloc===wt.bar_index?h:p}this._verfiyArgs(r,n);const l=new ns(this._variables,i,this._errorListener);return n.startsWith("export")||this._variables.box.add(i,a,l),l}_verfiyArgs(e,t){const{border_style:r,extend:n,xloc:i,text_size:a,text_halign:l,text_valign:c,text_wrap:p,text_font_family:h}=e,f="box.new";this._paramVerfiy(r,t,f,[Lt.styleDashed,Lt.styleDotted,Lt.styleSolid],"border_style"),this._paramVerfiy(n,t,f,Object.values(Ur),"extend"),this._paramVerfiy(i,t,f,Object.values(wt),"xloc"),this._paramVerfiy(a,t,f,Object.values(tr),"text_size"),this._paramVerfiy(l,t,f,[We.alignLeft,We.alignCenter,We.alignRight],"text_halign"),this._paramVerfiy(c,t,f,[We.alignBottom,We.alignCenter,We.alignTop],"text_valign"),this._paramVerfiy(p,t,f,[We.wrapAuto,We.wrapNone],"text_wrap"),this._paramVerfiy(h,t,f,Object.values(Zn),"text_font_family")}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}copy({id:e},t){return e==null?void 0:e.copy(t)}delete({id:e}){e==null||e.delete()}get_top({id:e}){return e==null?void 0:e.get_top()}get_bottom({id:e}){return e==null?void 0:e.get_bottom()}get_left({id:e}){return e==null?void 0:e.get_left()}get_right({id:e}){return e==null?void 0:e.get_right()}set_top({id:e,...t}){e==null||e.set_top(t)}set_bottom({id:e,...t}){e==null||e.set_bottom(t)}set_left({id:e,...t}){e==null||e.set_left(t)}set_right({id:e,...t}){e==null||e.set_right(t)}set_extend({id:e,...t},r){e==null||e.set_extend(t,r)}set_bgcolor({id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({id:e,...t}){e==null||e.set_border_color(t)}set_border_width({id:e,...t}){e==null||e.set_border_width(t)}set_border_style({id:e,...t},r){e==null||e.set_border_style(t,r)}set_lefttop({id:e,...t}){e==null||e.set_lefttop(t)}set_rightbottom({id:e,...t}){e==null||e.set_rightbottom(t)}set_text_size({id:e,...t},r){e==null||e.set_text_size(t,r)}set_text_wrap({id:e,...t},r){e==null||e.set_text_wrap(t,r)}set_text_color({id:e,...t}){e==null||e.set_text_color(t)}set_text_halign({id:e,...t},r){e==null||e.set_text_halign(t,r)}set_text_valign({id:e,...t},r){e==null||e.set_text_valign(t,r)}set_top_left_point({id:e,...t}){e==null||e.set_top_left_point(t)}set_bottom_right_point({id:e,...t}){e==null||e.set_bottom_right_point(t)}set_text_font_family({id:e,...t},r){e==null||e.set_text_font_family(t,r)}}class ns{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");this._variables=e,this._id=t,this._errorListener=r}copy(e){const t=`box_${e}_${this._variables.bar_index}`,r=this._getBox(),n=new ns(this._variables,t,this._errorListener);return r&&this._variables.box.add(t,{...r,id:t},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const e=this._getBox();return e&&e.top}set_top({top:e}){const t=this._getBox();t&&(t.top=e)}get_left(){const e=this._getBox();return e&&e.left}set_left({left:e}){const t=this._getBox();t&&(t.left=e)}set_text({text:e}){const t=this._getBox();t&&(t.text=e)}get_right(){const e=this._getBox();return e&&e.right}set_right({right:e}){const t=this._getBox();t&&(t.right=e)}get_bottom(){const e=this._getBox();return e&&e.bottom}set_bottom({bottom:e}){const t=this._getBox();t&&(t.bottom=e)}set_extend({extend:e},t){const r=this._getBox();r&&(r.extend=e,this._paramVerfiy(e,t,"box.set_extend",Object.values(Ur),"extend"))}set_bgcolor({color:e}){const t=this._getBox();t&&(t.bgcolor=e,_t(t,["bgcolor"]))}set_lefttop({left:e,top:t}){const r=this._getBox();r&&(r.left=e,r.top=t)}set_text_size({text_size:e},t){const r=this._getBox();r&&(r.text_size=e,this._paramVerfiy(e,t,"box.set_text_size",Object.values(tr),"text_size"))}set_text_wrap({text_wrap:e},t){const r=this._getBox();r&&(r.text_wrap=e,this._paramVerfiy(e,t,"box.set_text_wrap",[We.wrapAuto,We.wrapNone],"text_wrap"))}set_text_color({text_color:e}){const t=this._getBox();t&&(t.text_color=e,_t(t,["text_color"]))}set_rightbottom({right:e,bottom:t}){const r=this._getBox();r&&(r.right=e,r.bottom=t)}set_text_halign({text_halign:e},t){const r=this._getBox();r&&(r.text_halign=e,this._paramVerfiy(e,t,"box.set_text_halign",[We.alignLeft,We.alignCenter,We.alignRight],"text_halign"))}set_text_valign({text_valign:e},t){const r=this._getBox();r&&(r.text_valign=e,this._paramVerfiy(e,t,"box.set_text_valign",[We.alignBottom,We.alignCenter,We.alignTop],"text_valign"))}set_top_left_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.top=n,t.left=t.xloc===wt.bar_index?r:i}}set_border_color({color:e}){const t=this._getBox();t&&(t.border_color=e,_t(t,["border_color"]))}set_border_style({style:e},t){const r=this._getBox();r&&(r.border_style=e,this._paramVerfiy(e,t,"box.set_border_style",[Lt.styleDashed,Lt.styleDotted,Lt.styleSolid],"style"))}set_border_width({width:e}){const t=this._getBox();t&&(t.border_width=e)}set_bottom_right_point({point:e}){const t=this._getBox();if(t){const{index:r,price:n,time:i}=e||{};t.bottom=n,t.right=t.xloc===wt.bar_index?r:i}}set_text_font_family({text_font_family:e},t){const r=this._getBox();r&&(r.text_font_family=e,this._paramVerfiy(e,t,"box.set_text_font_family",Object.values(Zn),"text_font_family"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getBox(){return this._variables.box.get(this._id)}}class Hy{constructor(e,t){R(this,"_variables");R(this,"_errorListener");R(this,"_defaultTable",{position:pr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=e,this._errorListener=t}table({x:e},t){return e||new Ua(this._variables,t,this._errorListener)}new(e,t){const r=`table_${t}_${this._variables.bar_index}`,{columns:n,rows:i}=e;_t(e,["text_color","bgcolor","border_color"]);const a=Array.from(Array(i),()=>Array.from(Array(n),()=>{})),l={...this._defaultTable,...e,cell:a,id:r},c=new Ua(this._variables,r,this._errorListener);return this._paramVerfiy(e.position,t,"table.new",Object.values(pr),"position"),t.startsWith("export")||this._variables.table.add(r,l,c),c}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}cell({table_id:e,...t}){e==null||e.cell(t)}cell_set_bgcolor({table_id:e,...t}){e==null||e.cell_set_bgcolor(t)}cell_set_height({table_id:e,...t}){e==null||e.cell_set_height(t)}cell_set_text({table_id:e,...t}){e==null||e.cell_set_text(t)}cell_set_text_color({table_id:e,...t}){e==null||e.cell_set_text_color(t)}cell_set_text_font_family({table_id:e,...t}){e==null||e.cell_set_text_font_family(t)}cell_set_text_halign({table_id:e,...t}){e==null||e.cell_set_text_halign(t)}cell_set_text_valign({table_id:e,...t}){e==null||e.cell_set_text_valign(t)}cell_set_text_size({table_id:e,...t}){e==null||e.cell_set_text_size(t)}cell_set_tooltip({table_id:e,...t}){e==null||e.cell_set_tooltip(t)}cell_set_width({table_id:e,...t}){e==null||e.cell_set_width(t)}clear({table_id:e,...t}){e==null||e.clear(t)}delete({table_id:e}){e==null||e.delete()}merge_cells({table_id:e,...t},r){e==null||e.merge_cells(t,r)}set_bgcolor({table_id:e,...t}){e==null||e.set_bgcolor(t)}set_border_color({table_id:e,...t}){e==null||e.set_border_color(t)}set_border_width({table_id:e,...t}){e==null||e.set_border_width(t)}set_frame_color({table_id:e,...t}){e==null||e.set_frame_color(t)}set_frame_width({table_id:e,...t}){e==null||e.set_frame_width(t)}set_position({table_id:e,...t},r){e==null||e.set_position(t,r)}}class Ua{constructor(e,t,r){R(this,"_id");R(this,"_variables");R(this,"_errorListener");R(this,"_defaultCell",{column:0,row:0,text:"",text_color:Ci.black,text_halign:We.alignCenter,text_valign:We.alignCenter,text_size:tr.normal});this._variables=e,this._id=t,this._errorListener=r}cell(e){const t={...this._defaultCell,...e},{column:r=0,row:n=0}=t,i=this._variables.table.get(this._id);if(i){const a=i.cell||[],l=a[n]||[];l[r]=t,a[n]=l,i.cell=a}}cell_set_bgcolor({column:e=0,row:t=0,bgcolor:r}){const n=this._getTableItem(e,t);n&&(n.bgcolor=r)}cell_set_height({column:e=0,row:t=0,height:r}){const n=this._getTableItem(e,t);n&&(n.height=r)}cell_set_text({column:e=0,row:t=0,text:r}){const n=this._getTableItem(e,t);n&&(n.text=r)}cell_set_text_color({column:e=0,row:t=0,text_color:r}){const n=this._getTableItem(e,t);n&&(n.text_color=r,_t(n,["text_color"]))}cell_set_text_font_family({column:e=0,row:t=0,text_font_family:r}){const n=this._getTableItem(e,t);n&&(n.text_font_family=r)}cell_set_text_halign({column:e=0,row:t=0,text_halign:r}){const n=this._getTableItem(e,t);n&&(n.text_halign=r)}cell_set_text_valign({column:e=0,row:t=0,text_valign:r}){const n=this._getTableItem(e,t);n&&(n.text_valign=r)}cell_set_text_size({column:e=0,row:t=0,text_size:r}){const n=this._getTableItem(e,t);n&&(n.text_size=r)}cell_set_tooltip({column:e=0,row:t=0,tooltip:r}){const n=this._getTableItem(e,t);n&&(n.tooltip=r)}cell_set_width({column:e=0,row:t=0,width:r}){const n=this._getTableItem(e,t);n&&(n.width=r)}clear({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0}){const i=this._variables.table.get(this._id);if(i){const a=i.cell;if(a)for(let l=t;l<=n;l++)for(let c=e;c<=r;c++){const p=a[l];p&&(p[c]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:e=0,start_row:t=0,end_column:r=0,end_row:n=0},i){if(e>r||t>n){this._errorListener.addError(ut.mergeCellErr,i,ze.Error);return}const a=this._variables.table.get(this._id);if(!a)return;const l=a.merge_cells||[];l.push({start_column:e,start_row:t,end_column:r,end_row:n}),a.merge_cells=l}set_bgcolor({bgcolor:e}){const t=this._variables.table.get(this._id);t&&(t.bgcolor=e,_t(t,["bgcolor"]))}set_border_color({border_color:e}){const t=this._variables.table.get(this._id);t&&(t.border_color=e,_t(t,["border_color"]))}set_border_width({border_width:e}){const t=this._variables.table.get(this._id);t&&(t.border_width=e)}set_frame_color({frame_color:e}){const t=this._variables.table.get(this._id);t&&(t.frame_color=e)}set_frame_width({frame_width:e}){const t=this._variables.table.get(this._id);t&&(t.frame_width=e)}set_position({position:e},t){const r=this._variables.table.get(this._id);r&&(r.position=e,this._paramVerfiy(e,t,"table.set_position",Object.values(pr),"position"))}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_getTableItem(e,t){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[t][e]:void 0}}}class Jy{constructor(e){R(this,"_strategy");this._strategy=e}commission({trade_num:e}){return this._verifyTradeNum(e)&&this._strategy.historyOrders[e].commission||0}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.historyOrders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].in_time}exit_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_index}exit_comment({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_comment:""}exit_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].out_id:""}exit_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_price}exit_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.historyOrders[e].out_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.historyOrders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{out_qty:t=0,direction:r}=this._strategy.historyOrders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.historyOrders.length;return!(e>=t)}}class Xy{constructor(e){R(this,"_strategy");this._strategy=e}commission({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,original_qty:r=0,commission:n=0}=this._strategy.orders[e];return n*t/r}entry_bar_index({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_index}entry_comment({trade_num:e}){if(!this._verifyTradeNum(e))return"";const{comment:t,id:r}=this._strategy.orders[e];return t||r}entry_id({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].id:""}entry_price({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_price}entry_time({trade_num:e}){if(this._verifyTradeNum(e))return this._strategy.orders[e].in_time}max_drawdown({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss:0}max_drawdown_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].trading_loss_percent:0}max_runup({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit:0}max_runup_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].max_profit_percent:0}profit({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit:0}profit_percent({trade_num:e}){return this._verifyTradeNum(e)?this._strategy.orders[e].profit_percent:0}size({trade_num:e}){if(!this._verifyTradeNum(e))return 0;const{qty:t=0,direction:r}=this._strategy.orders[e];return r===gt.long?t:-t}_verifyTradeNum(e){if(typeof e!="number"||e<0)return!1;const t=this._strategy.orders.length;return!(e>=t)}}class Qy{constructor(e,t){R(this,"_strategy");R(this,"_errorListener");this._strategy=e,this._errorListener=t}allow_entry_in({value:e},t){this._paramVerfiy(e,t,"strategy.risk.allow_entry_in",Object.values(gt),"value"),this._strategy.updateRisk({allow_entry_in:e})}max_cons_loss_days({count:e}){this._strategy.updateRisk({max_cons_loss_days:e})}max_drawdown({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_drawdown",[Ot.percentOfEquity,Ot.cash],"type"),t===Ot.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_drawdown:e,max_drawdown_type:t})}max_intraday_filled_orders({count:e}){this._strategy.updateRisk({max_intraday_filled_orders:e})}max_intraday_loss({value:e,type:t},r){this._paramVerfiy(t,r,"strategy.risk.max_intraday_loss",[Ot.percentOfEquity,Ot.cash],"type"),t===Ot.percentOfEquity&&(e=e>100?100:e),this._strategy.updateRisk({max_intraday_loss:e,max_intraday_loss_type:t})}max_position_size({contracts:e}){this._strategy.updateRisk({max_position_size:e})}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}}let ew=class{constructor(e,t,r,n){R(this,"_variables");R(this,"_options");R(this,"_totalChangeCapital");R(this,"_historyOrder");R(this,"_orders");R(this,"_pendingOrders");R(this,"_mintick");R(this,"_funcOptions");R(this,"_pendingCloseOrders");R(this,"_errorListener");R(this,"_risk");R(this,"_opentrades");R(this,"_closedtrades");R(this,"_riskNamespace");this._variables=e,this._errorListener=n,this._options={overlay:!1,format:Ke.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Ot.fixed,default_qty_value:1,initial_capital:1e6,currency:Xf.NONE,slippage:0,commission_type:Fr.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=t,this._totalChangeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._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 Xy(this),this._closedtrades=new Jy(this),this._riskNamespace=new Qy(this,n)}get orders(){return[...this._orders]}get historyOrders(){return[...this._historyOrder]}get _orderProfit(){return this._orders.reduce((e,t)=>e+(t.profit||0),0)}get _freezeCapital(){const{close:e}=this._variables;return this._orders.reduce((t,r)=>t+e*(r.qty||0),0)}get opentrades(){return this._opentrades}get closedtrades(){return this._closedtrades}get risk(){return this._riskNamespace}updateOptions(e){Object.assign(this._options,e),this._maxConsLossDaysVerify(),this._pendingOrderHandle(),this._maxIntradayFilledOrdersVerify(),this._ordersHandle(),!this._options.process_orders_on_close&&this._calcLiquidate()}updateRisk(e){Object.assign(this._risk,e)}endExecution(){this._calcProfitAndLoss(),this._variables.strategy.update(),this._maxDrawdownVerify(),this._maxIntradayLoss(),this._pendingCloseOrderHandle(),this._options.process_orders_on_close&&this._calcLiquidate()}_maxIntradayLoss(){var g;const{max_intraday_loss:e,max_intraday_loss_type:t,isDisabledOpen:r}=this._risk;if(e===void 0||!t||r)return;const{high:n,low:i,time_tradingday:a,time:l,strategy:{netprofit:c,initial_capital:p}}=this._variables;let{preNetprofit:h=0}=this._risk;l===a&&(h=c,this._risk.preNetprofit=c,this._risk.isTemporaryBan=!1);let f=h-c;f+=this._orders.reduce((y,m)=>{const{in_price:w,direction:v,qty:E=0,commission:b=0,original_qty:N=0}=m,x=v===gt.long?1:-1,F=(n-w)*E,M=(i-w)*E,S=x===1?-M:F;return y+S+E/N*b},0);let d=!1;switch(t){case Ot.cash:d=e<f;break;case Ot.percentOfEquity:const y=f/(p+c)*100;d=e<y;break}if(d){this._risk.isTemporaryBan=!0;const y=(g=this._orders[0])==null?void 0:g.direction;this._closeOrders(this._orders,y===gt.long?i:n,"Close Position (Max intraday Loss)"),this._pendingOrders=[]}}_maxIntradayFilledOrdersVerify(){const{max_intraday_filled_orders:e,intradayOrders:t=0,isDisabledOpen:r}=this._risk;if(e===void 0||r)return;const{time:n,time_tradingday:i,open:a}=this._variables;n===i&&(this._risk.intradayOrders=0,this._risk.isTemporaryBan=!1),e<=t&&(this._risk.isTemporaryBan=!0,this._closeOrders(this._orders,a,"Close Position (Max number of filled orders in one day)"),this._pendingOrders=[])}_maxConsLossDaysVerify(){const{max_cons_loss_days:e,lossDays:t=0,isDisabledOpen:r,totalProfit:n=0}=this._risk;if(e===void 0||r)return;const{time:i,time_tradingday:a,strategy:l,open:c}=this._variables;let p=t;if(i===a){const h=l.netprofit+l.openprofit;h<n?p=0:p++,Object.assign(this._risk,{lossDays:p,totalProfit:h})}e<=p&&this._riskTouchOff(c,"Close Position (Max consecutive loss days)")}_maxDrawdownVerify(){var n;const{max_drawdown:e,max_drawdown_type:t,isDisabledOpen:r}=this._risk;if(!r&&e!==void 0&&t){const{max_drawdown:i,max_drawdown_percent:a}=this._variables.strategy;let l=!1;switch(t){case Ot.percentOfEquity:l=a<i;break;case Ot.cash:l=e<i;break}if(l){const{high:c,low:p}=this._variables,h=(n=this._orders[0])==null?void 0:n.direction;this._riskTouchOff(h===gt.long?c:p,"Close Position (Max Drawdown)")}}}_riskTouchOff(e,t){this._risk.isDisabledOpen=!0,this._closeOrders(this._orders,e,t),this._pendingOrders=[]}strategy(e,t){this._variables.bar_index||(this._paramVerfiy(e.format,t,"strategy",[Ke.inherit,Ke.price,Ke.percent,Ke.volume],"format"),this._paramVerfiy(e.default_qty_type,t,"strategy",Object.values(Ot),"default_qty_type"),this._paramVerfiy(e.commission_type,t,"strategy",Object.values(Fr),"commission_type"),Object.assign(this._options,e),this._variables.updateMaxLength(e),Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"}))}order(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.order",Object.values(un),"oca_type"),this._orderHandle(e))}entry(e,t){this._risk.isDisabledOpen||(this._paramVerfiy(e.oca_type,t,"strategy.entry",Object.values(un),"oca_type"),this._entryHandle(e))}close(e){if(!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close"}):this._pendingOrders.push({...e,place_order_type:"close"})}close_all(e){if(typeof e=="string"&&(e={}),!this._orders.length)return;const{immediately:t}=e;t||this._options.process_orders_on_close?this._pendingCloseOrders.push({...e,place_order_type:"close_all"}):this._pendingOrders.push({...e,place_order_type:"close_all"})}cancel({id:e}){this._pendingOrders=this._pendingOrders.filter(t=>!(t.id===e&&t.place_order_type!=="close"))}cancel_all(){this._pendingOrders=this._pendingOrders.filter(e=>e.place_order_type==="close_all")}exit(e,t){this._exit(e,t)}convert_to_account({value:e}){return e}convert_to_symbol({value:e}){return e}default_entry_qty({fill_price:e}){return e?this._calcDefaultQty(e):0}_calcDefaultQty(e){const{default_qty_type:t=Ot.fixed,default_qty_value:r=1,initial_capital:n}=this._options;switch(t){case Ot.fixed:return r;case Ot.cash:return r/e;case Ot.percentOfEquity:return(n+this._orderProfit+this._totalChangeCapital)*r/100/e}}_getCapital(e,t){const{margin_long:r=0,margin_short:n=0}=this._options;return r<100&&r>0&&e===1?t=t*100/r:n<=100&&n>0&&e===-1&&(t=t*100/n),t}_calcProfitAndLoss(){const{high:e,low:t,close:r}=this._variables;for(const n of this._orders){const{in_price:i,qty:a=0,direction:l}=n,c=l===gt.long?1:-1,p=(r-i)*c*a,h=(e-i)*a,f=(t-i)*a,d=c===1?h:-f,g=c===1?-f:h;this._calcOrderPercent(n,p,d,g)}}_calcOrderPercent(e,t,r,n){const{commission_value:i}=this._options,{close:a}=this._variables,{original_qty:l=0,qty:c=0,in_price:p,max_profit:h=0,trading_loss:f=0}=e;let{commission:d=0}=e;const g=p*c;if(i){const y=this._getCommission(a,c);t=t-y,d=d*c/l,r-=d,n+=d}r=Math.max(r,h),n=Math.min(n,f),t=t-d,Object.assign(e,{profit:t,total_profit:this._totalChangeCapital+t,total_profit_percent:t/this._options.initial_capital*100,max_profit:r,trading_loss:n,profit_percent:t/g*100,max_profit_percent:r/g*100,trading_loss_percent:n/g*100})}_calcLiquidate(){if(!this._orders.length)return;const{high:e,low:t}=this._variables,{initial_capital:r,margin_long:n=0,margin_short:i=0,commission_value:a=0}=this._options,l=this._orders[0].direction===gt.long?1:-1,c=l===1?t:e,p=(l===1?n:i)/100;if(p<=0)return;const[h,f,d]=this._orders.reduce((v,E)=>{let[b,N,x]=v;const{in_price:F,qty:M=0,original_qty:S=0,commission:I=0}=E,C=F*M,B=c*M;if(b+=C,N+=B,a){const L=this._getCommission(c,M);x+=L+M/S*I}return[b,N,x]},[0,0,0]),g=l*(f-h),m=r+this._totalChangeCapital+g-d-f*p;if(m>=0)return;const w=Math.trunc(m/p/c)*4;this._marginCallOrders(c,w,"Margin Call")}_marginCallOrders(e,t,r){const{close_entries_rule:n="FIFO"}=this._options;if(n==="FIFO"){this._processOrders(this._orders,e,t*this._orders.length,r,r);return}for(const i of this.orders)this._processOrder(i,e,t,r,r);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_orderHandle(e){const{process_orders_on_close:t,slippage:r=0}=this._options,{orders:n,isMarketPrice:i,quantities:a,close:l,price:c,activePrice:p}=this._orderArgsParse(e),h=e.direction===gt.long?1:-1;if(a<=0)return;let f=a;if(i&&t){if(n.length){const m=this._processOrders(n,l,f,e.id,e.comment);if(m<=0)return;f=m}const g=l+h*r*this._mintick;if(!this._judgeCapitalEnough(f,g,h))return;this._ocaGroupVerify(f,e.oca_name,e.oca_type),this._calcCurrentOrder({...e,in_price:g,in_index:this._variables.bar_index,in_time:this._variables.time,qty:f,place_order_type:"order"});return}this._judgeCapitalEnough(a,c,h)&&this._addPendingOrders(e,c,f,i,p)}_judgeCapitalEnough(e,t,r){if(e<=0)return!1;const{margin_long:n=0,margin_short:i=0}=this._options;if((n===0||n===100)&&r===1||i===0&&r===-1)return!0;const l=this._getCapital(r,this._options.initial_capital+this._orderProfit+this._totalChangeCapital)-this._freezeCapital;return e*t<=l}_ocaGroupVerify(e,t,r){if(!t||!r||r===un.none)return!1;let n=!1;switch(r){case un.cancel:this._pendingOrders=this._pendingOrders.filter(i=>{if(i.oca_name===t)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(t===l){const c=a-e;return n=!0,c<=0?(i.isCancel=!0,!1):(i.qty=c,!0)}else return!0});break}return n}_processOrders(e,t,r,n,i){let a=r;for(const l of e)if(a=this._processOrder(l,t,a,n,i),a<=0)break;return this._orders=this._orders.filter(l=>!l.isDeal),this._variables.strategy.updateOrders(this._orders),a}_addPendingOrders(e,t,r,n,i){const a=this._pendingOrders.find(l=>l.id===e.id&&!l.isMarketPrice);if(a)Object.assign(a,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else{const l={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(e){const{direction:t,qty:r,stop:n}=e;let i=e.limit||0;const{close:a}=this._variables;let l=a,c=!1,p;const h=t===gt.long?1:-1,f=n&&(n-a)*h>0,{backtest_fill_limits_assumption:d=0}=this._options;d>0&&i&&(i-=d*this._mintick*h);const g=i&&(i-a)*h<0;f&&g?(p=n,l=i):f?l=n:g?l=i:c=!0;const y=r||this._calcDefaultQty(l)||1;return{orders:this._orders.filter(w=>w.direction!==t),isMarketPrice:c,activePrice:p,quantities:y,close:a,price:l}}_entryHandle(e){const{process_orders_on_close:t}=this._options,{orders:r,isMarketPrice:n,quantities:i,close:a,price:l,activePrice:c}=this._orderArgsParse(e);if(i<=0)return;if(r.length&&n&&t){this._entryOrder(r,a,i,e);return}this._judgeCapitalEnough(i,a,e.direction===gt.long?1:-1)&&this._addPendingEntry(e,l,i,n,c)}_entryOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{oca_name:c,oca_type:p,direction:h,comment:f,isMarketPrice:d,id:g}=n,y=h===gt.long?1:-1;if(this._closeOrders(e,t,g,f),r=this._getAvailablePositionSize(r,h),r<=0)return;t=t+l*this._mintick*y;const m={...n,in_price:t,original_qty:r,qty:r,in_index:a,in_time:i,place_order_type:"entry"};if(d){this._calcCurrentOrder(m);return}const{pendingOrders:w,orders:v}=this._getEntryOrders(h),E=w.length+v.length;E&&E>=(this._options.pyramiding||0)||!this._judgeCapitalEnough(r,t,y)||(this._ocaGroupVerify(r,c,p),this._calcCurrentOrder(m))}_getAvailablePositionSize(e,t){const{max_position_size:r,allow_entry_in:n}=this._risk;if(n&&n!==gt.all&&n!==t)return 0;if(r===void 0)return e;const i=this._orders.reduce((a,l)=>a+(l.qty||0),0);return i?i+e>r?0:e:e>r?e-r:0}_getEntryOrders(e){const t=this._pendingOrders.filter(n=>["entry","order"].includes(n.place_order_type)&&n.direction===e),r=this._orders.filter(n=>n.direction===e);return{pendingOrders:t,orders:r}}_addPendingEntry(e,t,r,n,i){if(r=this._getAvailablePositionSize(r,e.direction),r<=0)return;const{pendingOrders:a,orders:l}=this._getEntryOrders(e.direction),c=a.length+l.length,p=a.find(h=>h.id===e.id&&h.place_order_type==="entry");if(p)Object.assign(p,{...e,in_price:t,isMarketPrice:n,qty:r,active_price:i});else if(!c||c<(this._options.pyramiding||1)){const h={...e,in_price:t,isMarketPrice:n,qty:r,active_price:i,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(e,t){const{comment:r}=e,{bar_index:n}=this._variables,i=this._orders.filter(a=>a.in_index!==n);i.length&&(this._closeOrders(i,t,"Close position order",r),this._orders=[],this._variables.strategy.updateOrders(this._orders))}_closeOrders(e,t,r,n){for(const i of e)this._closeOrder(i,t,r,n);this._orders=this._orders.filter(i=>!i.isDeal),this._variables.strategy.updateOrders(this._orders)}_closeOrder(e,t,r,n){const{time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{in_price:c,qty:p=0,direction:h}=e,f=h===gt.long?1:-1;t=t-f*l*this._mintick,e.isDeal=!0;const d=(t-c)*f*p,g={...e,out_price:t,out_id:r,out_index:a,out_time:i,out_comment:n,out_qty:p,profit:d};this._calcPercent(g),this._risk.intradayOrders+=1,this._historyOrder.push(g),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_ordersHandle(){const e=this._orders.filter(a=>a.place_order_type==="exit"&&!a.hasExit);if(!e.length)return;const{open:t,low:r,high:n,close:i}=this._variables;for(const a of e){const{stop:l,limit:c,trail_stop_price:p,isMarketPriceLimit:h,isMarketPriceStop:f,direction:d,id:g,out_comment:y,active_price:m,trail_offset:w=0,out_qty:v,comment_loss:E,comment_profit:b,comment_trailing:N}=a;let x=p;const F=d===gt.long?1:-1;let M,S=y;if(h||f?M=t:(c&&r<=c&&n>=c&&(S=b||y,M=c),l&&r<=l&&n>=l&&(M=x?(l-x)*F>0?l:x:l,S=(x===M?N:E)||y)),M)this._processExitOnClose(a,M,{from_entry:g,comment:S,qty:v});else{let I=!1;if(m&&m<=n&&m>=r&&(x=m-w*F*this._mintick,(x-i)*F>=0&&(a.isMarketPriceStop=!0,this._options.process_orders_on_close&&(M=x)),I=!0,a.trail_stop_price=x),x)if((x-t)*F>=0&&!I)M=x;else{const C=(F===1?n:r)-w*F*this._mintick;F===1?x<t&&x>=r&&C>x&&C<i?M=x:C>x?(x=C,C>=i&&(M=C)):x<=n&&r<=x&&(M=x):x>t&&x<=n&&C<x&&C>i?M=x:C<x?(x=C,C<=i&&(M=C)):x<=n&&r<=x&&(M=x),a.trail_stop_price=x}M&&this._processExitOnClose(a,M,{from_entry:g,comment:N||y,qty:v})}}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const e=[],t=this._pendingOrders.filter(n=>n.place_order_type==="exit"),r=this._pendingOrders.filter(n=>["close","close_all"].includes(n.place_order_type||""));for(const n of r)switch(n.place_order_type){case"close":this._closeOrderHandle(n);break;case"close_all":this._closeAllOrders(n,this._variables.open);break}for(const n of this._pendingOrders){const{isCancel: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&&e.push(l)}for(const n of t){const i=this._exitOrderHandle(n);i&&e.push(i)}this._pendingOrders=e}_pendingCloseOrderHandle(){if(!this._pendingCloseOrders.length)return;const e=this._pendingCloseOrders.filter(n=>n.place_order_type==="exit"),t=this._pendingCloseOrders.filter(n=>["close","close_all"].includes(n.place_order_type||"")),{close:r}=this._variables;for(const n of t)switch(n.place_order_type){case"close":this._closeOrderHandle(n,!0);break;case"close_all":this._closeAllOrders(n,r);break}for(const n of e){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)}this._pendingCloseOrders=[]}_entryOrderHandle(e){const{open:t,low:r,high:n}=this._variables,{isMarketPrice:i,qty:a=0,in_price:l,direction:c,active_price:p}=e;if(p&&n>=p&&r<=p)return delete e.active_price,e;let h=l;if(i&&(h=t),h<=n&&h>=r){const f=this._orders.filter(d=>d.direction!==c);this._entryOrder(f,h,a,e)}else return e}_orderOrderHandle(e){const{open:t,low:r,high:n,time:i,bar_index:a}=this._variables,{slippage:l=0}=this._options,{isMarketPrice:c,qty:p=0,in_price:h,direction:f,comment:d,oca_name:g,oca_type:y,active_price:m,id:w}=e;if(m&&n>=m&&r<=m)return delete e.active_price,e;let v=h,E=p;if(c&&(v=t),v<=n&&v>=r){const b=this._orders.filter(x=>x.direction!==f);if(b.length&&(E=this._processOrders(b,v,p,w,d),E<=0))return;const N=f===gt.long?1:-1;this._ocaGroupVerify(E,g,y),this._calcCurrentOrder({...e,in_price:v+N*l*this._mintick,in_index:a,in_time:i,qty:E});return}else return e}_closeOrderHandle(e,t){const{id:r,qty:n,qty_percent:i=100,comment:a}=e,{bar_index:l}=this._variables,c=this._orders.filter(g=>g.id===r&&g.in_index!==l&&(!g.close_qty||g.close_qty<(g.qty||0)));if(!c.length)return;let p=0;if(n?p=n:(p=c.reduce((g,y)=>g+(y.qty||0),p),p=i/100*p),p<=0)return;const{open:h,close:f}=this._variables;let d=p;for(const g of c){const{qty:y=0}=g;d<y?g.close_qty=d:(g.close_qty=y,d-=y)}this._processOrders(this._options.close_entries_rule==="ANY"?c:this._orders,t?f:h,p,`Close entry(s) order ${r}`,a)}_exitOrderHandle(e){const{from_entry:t}=e,r=this._orders.filter(n=>(!t||t===n.id)&&!n.hasExit);if(!(r.length&&!this._ordersToExit(r,e)))return e}_exit(e,t){const{profit:r,loss:n,stop:i,limit:a,trail_offset:l,trail_price:c,trail_points:p,from_entry:h="",id:f}=e;if(this._isNaN(r)&&this._isNaN(n)&&this._isNaN(i)&&this._isNaN(a)&&(this._isNaN(l)||this._isNaN(p)&&this._isNaN(c))){this._errorListener.addError(ut.strategyExitErr,t,ze.Error);return}const d={...e,place_order_type:"exit"},g=this._orders.filter(w=>(!h||h===w.id)&&!w.hasExit),y=this._pendingOrders.filter(w=>!h||h===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);m?Object.assign(m,{...e}):this._pendingOrders.push(d)}_ordersToExit(e,t){const{qty:r,qty_percent:n=100,id:i,comment:a,comment_loss:l,comment_profit:c,comment_trailing:p}=t;let h=r,f=!1;t.comment=a||i;for(const d of e){const{qty:g=0}=d,y=d.direction===gt.long?1:-1;h=r?r>=g?g:r:n/100*g,d.out_qty=h,h<g&&(f=!0),Object.assign(d,{out_comment:a||i,comment_loss:l,comment_profit:c,comment_trailing:p}),!(this._stopProfit(d,y,{...t,qty:h})||this._stopLoss(d,y,{...t,qty:h})||this._trailStopLoss(d,y,{...t,qty:h}))&&(d.place_order_type="exit")}return f}_addExitPendingCloseOrders(e){e.place_order_type="exit";const t=this._pendingCloseOrders.find(r=>r.id===e.id);t?Object.assign(t,{...e}):this._pendingCloseOrders.push(e)}_stopProfit(e,t,r){const{limit:n,profit:i,comment_profit:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h+t*i*this._mintick),e.limit=c,c&&(c-p)*t<=0&&(e.isMarketPriceLimit=!0,r.comment=a||l,Object.assign(e,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_stopLoss(e,t,r){const{stop:n,loss:i,comment_loss:a,comment:l}=r;let c=n;const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;if(!this._isNaN(i)&&this._isNaN(n)&&(c=h-t*i*this._mintick),e.stop=c,c&&(c-p)*t>=0&&(e.isMarketPriceStop=!0,r.comment=a||l,Object.assign(e,{out_comment:r.comment}),c=p,f))return this._addExitPendingCloseOrders(r),!0}_trailStopLoss(e,t,r){const{trail_offset:n,trail_price:i,trail_points:a,comment_trailing:l,comment:c}=r;if(!this._isNaN(n)){const{close:p}=this._variables,{in_price:h}=e,{process_orders_on_close:f}=this._options;let d;if(this._isNaN(i)?this._isNaN(a)||(d=h+a*t*this._mintick):d=i,e.trail_offset=n,d&&(d-p)*t<=0){const g=p-n*t*this._mintick;if((g-p)*t>=0&&(e.trail_stop_price=p,e.isMarketPriceStop=!0,r.comment=l||c,Object.assign(e,{out_comment:r.comment}),f))return this._addExitPendingCloseOrders(r),!0;e.trail_stop_price=g}e.active_price=d}}_processExitOnClose(e,t,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,t,n,a,i);c&&!c.hasExit?(c.hasExit=!0,Object.assign(e,{trail_stop_price:c.trail_stop_price,stop:c.stop,limit:c.limit,trail_offset:c.trail_offset,active_price:c.active_price})):c&&(e.hasExit=!0)}else e.hasExit=!0,this._processOrders([e],t,n,a,i)}_processExitOrders(e,t,r,n,i){let a=r,l;for(const c of e)if(l=c,a=this._processOrder(c,t,a,n,i),a<=0||!c.hasExit)break;return this._orders=this._orders.filter(c=>!c.isDeal),this._variables.strategy.updateOrders(this._orders),l}_processOrder(e,t,r,n,i){const{time:a,bar_index:l}=this._variables,{slippage:c=0}=this._options,{in_price:p,qty:h=0,max_profit:f=0,trading_loss:d=0,direction:g,commission:y=0,original_qty:m=0}=e,w=g===gt.long?1:-1;if(t=t-w*c*this._mintick,r<h){const v=h-r,E=(t-p)*w*r,b=f/h*r,N=d/h*r;this._calcPercent({...e,out_price:t,out_id:n,out_index:l,out_time:a,out_comment:i,profit:E,out_qty:r,max_profit:b,trading_loss:N});const x=(t-p)*w*v-y*v/m;Object.assign(e,{qty:v,profit:x,max_profit:f-b,trading_loss:d-N,total_profit:this._totalChangeCapital+x}),r=0}else{e.isDeal=!0;const v=(t-p)*w*h;this._calcPercent({...e,out_price:t,out_id:n,out_index:l,out_time:a,out_comment:i,out_qty:h,profit:v}),r-=h}return r}_calcPercent(e){const{commission_value:t}=this._options,{in_price:r,out_qty:n=0,out_price:i=0,original_qty:a=0}=e;let{profit:l=0,max_profit:c=0,trading_loss:p=0,commission:h=0}=e;c=c<0?0:c;const f=r*n;if(this._totalChangeCapital+=l,t){const d=this._getCommission(i,n);this._totalChangeCapital-=d,h=h*n/a+d,l=l-h,Object.assign(e,{commission:h,profit:l,max_profit:c})}Object.assign(e,{total_profit:this._totalChangeCapital,total_profit_percent:l/this._options.initial_capital*100,profit_percent:l/f*100,max_profit_percent:c/f*100,trading_loss_percent:p/f*100}),this._risk.intradayOrders+=1,this._historyOrder.push(e),this._variables.strategy.updateHistoryOrders(this._historyOrder)}_getCommission(e,t){const{commission_value:r=0,commission_type:n}=this._options,i=e*t;let a=0;switch(n){case Fr.percent:a=i*r/100;break;case Fr.cashPerContract:a=t*r;break;case Fr.cashPerOrder:a=r;break}return a}_calcCurrentOrder(e){const{commission_value:t}=this._options,{in_price:r,qty:n=0,max_profit:i=0,trading_loss:a=0}=e;let{profit:l=0}=e;const c=r*n;if(t){const p=this._getCommission(r,n);this._totalChangeCapital-=p,l=l-p,Object.assign(e,{commission:p,profit:l,total_profit:this._totalChangeCapital})}Object.assign(e,{original_qty:n,total_profit_percent:l/this._options.initial_capital*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(e),this._variables.strategy.updateOrders(this._orders)}_isNaN(e){return e===void 0||isNaN(e)}_paramVerfiy(e="",t,r,n,i){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}};var rh={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){return function(t,r,n){r.prototype.isBetween=function(i,a,l,c){var p=n(i),h=n(a),f=(c=c||"()")[0]==="(",d=c[1]===")";return(f?this.isAfter(p,l):!this.isBefore(p,l))&&(d?this.isBefore(h,l):!this.isAfter(h,l))||(f?this.isBefore(p,l):!this.isAfter(p,l))&&(d?this.isAfter(h,l):!this.isBefore(h,l))}}})})(rh);var tw=rh.exports,rw=Ge(tw),nh={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){return function(t,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(I){var C,B;w[C=I,B=i.$utils().p(C),B==="date"?"day":B]=y[I]});var E=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(),x=w.hour||0,F=w.minute||0,M=w.second||0,S=w.millisecond||0;return m?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return y},l=i.parse;i.parse=function(d){d.date=a.bind(this)(d),l.bind(this)(d)};var c=i.set,p=i.add,h=i.subtract,f=function(d,g,y,m){m===void 0&&(m=1);var w=Object.keys(g),v=this;return w.forEach(function(E){v=d.bind(v)(g[E]*m,E)}),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)(p,d,g):p.bind(this)(d,g)},i.subtract=function(d,g){return d.constructor.name==="Object"?f.bind(this)(p,d,g,-1):h.bind(this)(d,g)}}})})(nh);var nw=nh.exports,iw=Ge(nw),ih={exports:{}};(function(s,e){(function(t,r){s.exports=r()})(Ve,function(){var t,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,p=31536e6,h=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:p,months:h,days:l,hours:a,minutes:i,seconds:n,milliseconds:1,weeks:6048e5},g=function(F){return F instanceof N},y=function(F,M,S){return new N(F,S,M.$l)},m=function(F){return r.p(F)+"s"},w=function(F){return F<0},v=function(F){return w(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?w(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,I,C){var B=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),I)return y(S*d[m(I)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(k){B.$d[m(k)]=S[k]}),this.calMilliseconds(),this;if(typeof S=="string"){var L=S.match(f);if(L){var U=L.slice(2).map(function(k){return k!=null?Number(k):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(I,C){return I+(S.$d[C]||0)*d[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/p),S%=p,this.$d.months=v(S/h),S%=h,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"),I=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var B=b(C,"D"),L=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),k=this.$d.seconds||0;this.$d.milliseconds&&(k+=this.$d.milliseconds/1e3,k=Math.round(1e3*k)/1e3);var W=b(k,"S"),z=S.negative||I.negative||B.negative||L.negative||U.negative||W.negative,K=L.format||U.format||W.format?"T":"",Z=(z?"-":"")+"P"+S.format+I.format+B.format+K+L.format+U.format+W.format;return Z==="P"||Z==="-P"?"P0D":Z},M.toJSON=function(){return this.toISOString()},M.format=function(S){var I=S||"YYYY-MM-DDTHH:mm:ss",C={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return I.replace(c,function(B,L){return L||String(C[B])})},M.as=function(S){return this.$ms/d[m(S)]},M.get=function(S){var I=this.$ms,C=m(S);return C==="milliseconds"?I%=1e3:I=C==="weeks"?v(I/d[C]):this.$d[C],I||0},M.add=function(S,I,C){var B;return B=I?S*d[m(I)]:g(S)?S.$ms:y(S,this).$ms,y(this.$ms+B*(C?-1:1),this)},M.subtract=function(S,I){return this.add(S,I,!0)},M.locale=function(S){var I=this.clone();return I.$l=S,I},M.clone=function(){return y(this.$ms,this)},M.humanize=function(S){return t().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){t=S,r=S().$utils(),S.duration=function(B,L){var U=S.locale();return y(B,{$l:U},L)},S.isDuration=g;var I=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(B,L){return g(B)?x(this,B,1):I.bind(this)(B,L)},M.prototype.subtract=function(B,L){return g(B)?x(this,B,-1):C.bind(this)(B,L)}}})})(ih);var sw=ih.exports,ow=Ge(sw);tt.extend(Bl),tt.extend(rw),tt.extend(iw),tt.extend(ow);class sh{constructor(e,t,r){R(this,"array");R(this,"color");R(this,"math");R(this,"str");R(this,"map");R(this,"matrix");R(this,"timeframe");R(this,"ta");R(this,"input");R(this,"_variables");R(this,"_cacheData");R(this,"_options");R(this,"_errorListener");R(this,"_plots");R(this,"_plotshapes");R(this,"_plotbars");R(this,"_plotchars");R(this,"_plotarrows");R(this,"_plotcandles");R(this,"_alerts");R(this,"_bgColors");R(this,"_hlines");R(this,"_fills");R(this,"chart");R(this,"line");R(this,"label");R(this,"polyline");R(this,"box");R(this,"table");R(this,"linefill");R(this,"log");R(this,"runtime");R(this,"strategy");R(this,"request");R(this,"syminfo");R(this,"_count",0);var i;const n=((i=e.toString().split(".")[1])==null?void 0:i.length)||5;this._variables=t,this._errorListener=new fw,this.array=new Gp(this._errorListener),this.math=new Hp(n,this._errorListener),this.color=new D1,this.str=new by(this._errorListener,n),this.map=new Ey(this._errorListener),this.timeframe=new Dy(t),this.matrix=new wy(this._errorListener),this.ta=new y1(t,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this.input=new w1(t,this._errorListener,r),this._plots=new Map,this._plotshapes=new Map,this._plotbars=new Map,this._plotcandles=new Map,this._plotchars=new Map,this._plotarrows=new Map,this.chart={point:new xy(t)},this.line=new Zy(t,this._errorListener),this.label=new Ay(t,this._errorListener),this.polyline=new Vy(t,this._errorListener),this.box=new Gy(t,this._errorListener),this.table=new Hy(t,this._errorListener),this.linefill=new Ky(t),this.log=new lw(t),this.runtime=new cw(this._errorListener),this.strategy=new ew(this._variables,this._options,e,this._errorListener),this.request=new aw(this._variables,r),this.syminfo=new uw}get errors(){return this._errorListener.errors}options(e){if(e.length)return this._getDataOfBarindex(e);const t=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});const p=this._plots.size>0?[...this._plots.values()]:void 0,h=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:t,plots:p,draws:m,alerts:r,colors:i,hlines:a,fills:l,logs:c,plotshapes:f,plotarrows:d,plotcandles:g,plotchars:y,plotbars:h,isUseBgColor:w})}_getDataOfBarindex(e){const t=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 e){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(e,[...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(e,[...this._plots.values()]),p=this._plotshapes.size>0?this._getDataFromBarindex(e,[...this._plotshapes.values()]):void 0,h=this._getDrawsFromBarindex(e),f=this._variables.chart.isUseBgColor;return Object.assign(this._options,{plots:c,draws:h,alerts:t,colors:n,hlines:i,fills:a,logs:l,plotshapes:p,isUseBgColor:f})}_getDataFromBarindex(e,t){return t.map(r=>{const n=[];for(const i of e){const a=r.data[i];a&&n.push(a)}return r.data=n,{...r}})}_getDraws(){const{line:e,linefill:t,table:r,box:n,polyline:i,label:a}=this._variables,l={};return e.data.length&&(l.lines=e.data),t.data.length&&(l.linefills=t.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(e){const{line:t,linefill:r,table:n,box:i,polyline:a,label:l}=this._variables,c={};return t.data.length&&(c.lines=t.getValOfBarIndex(e)),r.data.length&&(c.linefills=r.getValOfBarIndex(e)),n.data.length&&(c.tables=n.getValOfBarIndex(e)),i.data.length&&(c.boxes=i.getValOfBarIndex(e)),a.data.length&&(c.polylines=a.getValOfBarIndex(e)),l.data.length&&(c.labels=l.getValOfBarIndex(e)),Object.keys(c).length?c:void 0}updateOptions(e){const{inputs:t}=e;this.input.update(t)}update(e){const{barIndex:t}=e;this.strategy.updateOptions(),this.math.update(t)}endExecution(){this.strategy.endExecution()}library(e,t){if(!this._variables.bar_index){const r=/^[^\W\d\s][^\W\s]*$/,{title:n}=e;r.test(n)?(Kp.includes(n)||Zp.includes(n))&&this._errorListener.addError(jt(ut.libraryTitleIsKeywordErr,{name:n}),t,ze.Error):this._errorListener.addError(ut.libraryTitleErr,t,ze.Error),this._options.scriptType="library",this._options.library=e}}indicator(e,t){if(!this._variables.bar_index){const{format:r}=e;this._paramVerfiy(r,t,"indicator",[Ke.inherit,Ke.percent,Ke.price,Ke.volume]),this._variables.updateMaxLength(e),this._options.scriptType="indicator",this._options.indicator=e}}_paramVerfiy(e="",t,r,n,i="format"){e&&!n.includes(e)&&this._errorListener.addError(jt(ut.paramsErr,{value:e,func:r,param:i,targetVal:`[${n.join(", ")}]`}),t,ze.Error)}_lineWidthVerify(e,t){const{linewidth:r=1}=e;r<1&&(this._errorListener.addError(Yp.lineWidthWarning,t,ze.Warning),e.linewidth=1)}plot(e,t){const r=["color"];_t(e,r);const{series:n,color:i,...a}=e,{bar_index:l,time:c}=this._variables,p=`plot_${t}`,h=this._plots.get(p),f=(h==null?void 0:h.data)||[],d=n!==void 0&&isNaN(n)?void 0:n;if(f[l]={value:[c,d],itemStyle:{color:i}},this._seriesColorHandle(e,r,h),!h){this._count++,this._lineWidthVerify(a,t),this._paramVerfiy(e.format,t,"plot",[Ke.percent,Ke.price,Ke.volume]);const g=i?[i]:void 0;this._plots.set(p,{editable:!0,...a,colors:g,data:f,id:p,zIndex:this._count})}return{type:"plot",key:p}}plotbar(e,t){const r=["color"];_t(e,r);const{open:n,close:i,low:a,high:l,color:c,...p}=e,{bar_index:h,time:f}=this._variables,d=`plotbar_${t}`,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,E=l!==void 0&&isNaN(l)?void 0:l,b=[f,w,m,v,E];if(y[h]={value:b,itemStyle:{color:c}},this._seriesColorHandle(e,r,g),!g){this._count++,this._paramVerfiy(e.format,t,"plotbar",[Ke.percent,Ke.price,Ke.volume]);const N=c?[c]:void 0;this._plotbars.set(d,{editable:!0,...p,colors:N,data:y,id:d,zIndex:this._count})}}_verfiyArgs(e,t,r){const{size:n,format:i,location:a,style:l}=e;this._paramVerfiy(l,r,t,Object.values(or),"style"),this._paramVerfiy(a,r,t,Object.values(an),"location"),this._paramVerfiy(n,r,t,Object.values(tr),"size"),this._paramVerfiy(i,r,t,[Ke.percent,Ke.price,Ke.volume],"format")}plotchar(e,t){const r=["color","textcolor"];_t(e,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=e,{bar_index:p,time:h,high:f,low:d}=this._variables,g=`plotchar_${t}`,y=this._plotchars.get(g),m=(y==null?void 0:y.data)||[],w={value:[h,n],itemStyle:{color:i,textcolor:a},low:d,high:f};m[p]=w,this._seriesColorHandle(e,r,y),y||(this._count++,this._verfiyArgs(e,"plotchar",t),this._plotchars.set(g,{editable:!0,...c,location:l,data:m,id:g,zIndex:this._count}))}plotarrow(e,t){const r=["colorup","colordown"];_t(e,r);const{series:n,colorup:i,colordown:a,...l}=e,{bar_index:c,time:p}=this._variables,h=`plotarrow_${t}`,f=this._plotarrows.get(h),d=(f==null?void 0:f.data)||[];d[c]={value:[p,n!==void 0&&isNaN(n)?void 0:n],itemStyle:{colorup:i,colordown:a}},this._seriesColorHandle(e,r,f),f||(this._count++,this._paramVerfiy(e.format,t,"plotarrow",[Ke.percent,Ke.price,Ke.volume]),this._plotarrows.set(h,{editable:!0,...l,data:d,id:h,zIndex:this._count}))}plotshape(e,t){const r=["color","textcolor"];_t(e,r);const{series:n,color:i,textcolor:a,location:l=an.abovebar,...c}=e,{bar_index:p,time:h,low:f,high:d}=this._variables,g=`plotshape_${t}`,y=this._plotshapes.get(g),m=(y==null?void 0:y.data)||[],w={value:n,color:i,textcolor:a,time:h,low:f,high:d};if(m[p]=w,this._seriesColorHandle(e,r,y),!y){this._count++;const v=i?[i]:void 0;this._verfiyArgs(e,"plotshape",t),this._plotshapes.set(g,{editable:!0,...c,data:m,location:l,id:g,colors:v,zIndex:this._count})}}plotcandle(e,t){const r=["wickcolor","bordercolor","color"];_t(e,r);const{wickcolor:n,bordercolor:i,color:a,close:l,open:c,low:p,high:h,...f}=e,{bar_index:d,time:g}=this._variables,y=`plotcandle_${t}`,m=this._plotcandles.get(y),w=(m==null?void 0:m.data)||[],v=l!==void 0&&isNaN(l)?void 0:l,E=c!==void 0&&isNaN(c)?void 0:c,b=p!==void 0&&isNaN(p)?void 0:p,N=h!==void 0&&isNaN(h)?void 0:h,x=[g,E,v,b,N];w[d]={value:x,wickcolor:n,bordercolor:i,color:a},this._seriesColorHandle(e,r,m),m||(this._count++,this._paramVerfiy(e.format,t,"plotcandle",[Ke.percent,Ke.price,Ke.volume]),this._plotcandles.set(y,{editable:!0,...f,data:w,id:y,zIndex:this._count}))}hline(e,t){const r=`hline_${t}`;_t(e,["color"]),this._verifyDisplay(e.display,"hline",t);const i=e.display&&!e.display.length?Yt.none:Yt.all;return this._hlines.has(r)||(this._count++,this._lineWidthVerify(e,t),this._hlines.set(r,{id:r,linewidth:1,editable:!0,display:i,...e,zIndex:this._count})),{type:"hline",key:r}}fill(e,t){var S,I,C,B,L,U,k,W,z,K;const r=["color","top_color","bottom_color"];_t(e,r);const{color:n,top_color:i,bottom_color:a,seriesColors:l,hline1:c,hline2:p,plot1:h,plot2:f,top_value:d,bottom_value:g,...y}=e,{bar_index:m,time:w}=this._variables,v=`fill_${t}`,E=this._fills.get(v),b=(E==null?void 0:E.data)||[];this._verifyDisplay(e.display,"fill",t);const N=e.display&&!e.display.length?Yt.none:Yt.all;let x,F,M="plot";if(c&&p)x=(S=this._hlines.get(c==null?void 0:c.key))==null?void 0:S.price,F=(I=this._hlines.get(p==null?void 0:p.key))==null?void 0:I.price,M="hline";else{const Z=((C=this._plots.get(h==null?void 0:h.key))==null?void 0:C.data)||[],X=((B=this._plots.get(f==null?void 0:f.key))==null?void 0:B.data)||[];x=(U=(L=Z[m])==null?void 0:L.value)==null?void 0:U[1],F=(W=(k=X[m])==null?void 0:k.value)==null?void 0:W[1]}if(b[m]={time:w,color:n,top_color:i,bottom_color:a,plot1:x,plot2:F,top_value:d,bottom_value:g},this._seriesColorHandle(e,r,E),!E){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,ce=a?[a]:void 0;this._fills.set(v,{id:v,colors:X,top_colors:Q,bottom_colors:ce,display:N,data:b,type:M,editable:!0,fillgaps:!1,hline1:c,hline2:p,plot1:h,plot2:f,...y,zIndex:Z?this._count:void 0})}}alert({message:e,freq:t=kr.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:i,last_bar_index:a}=this._variables,l=`alert_${r}`,c=this._cacheData[l]||{},p=c.barIndex;if(this._paramVerfiy(t,r,"alert",[kr.freqAll,kr.freqOncePerBar,kr.freqOncePerBarClose]),t===kr.freqOncePerBar&&n===p){this._alerts.delete(l);return}this._cacheData[l]=c;const h={message:e,freq:t,id:l,type:"alert"};if(i){t!==kr.freqOncePerBarClose&&this._alerts.set(l,h),c.barIndex=n;return}if(!i&&t===kr.freqOncePerBarClose&&n===p&&a===n-1){this._alerts.set(l,h),c.barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:e,message:t,title:r},n){const{_isRealTimeBar:i}=this._variables,a=`alertcondition_${n}`;i&&e?this._alerts.set(a,{message:t,title:r,id:a,type:"alertcondition"}):this._alerts.delete(a)}barcolor(e,t){this._setColors(e,"barcolor",t)}bgcolor(e,t){this._setColors(e,"bgcolor",t)}_verifyDisplay(e=Qf.all,t,r){e.length&&e.length<4&&this._errorListener.addError(jt(ut.displayErr,{func:t,values:"[display.none, display.all]"}),r,ze.Error)}_setColors(e,t,r){_t(e,["color"]);const{color:i,...a}=e;this._verifyDisplay(a.display,t,r);const l=e.display&&!e.display.length?Yt.none:Yt.all,{bar_index:c,time:p}=this._variables,h=`${t}_${r}`;this._bgColors[t]||(this._bgColors[t]=new Map);const f=this._bgColors[t].get(h),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:p},f||this._bgColors[t].set(h,{...a,display:l,colors:d,setColors:g,id:h})}max_bars_back({var:e,num:t,var_name:r}){console.log(e,t,r)}float({x:e}){return e}bool({x:e}){return e||!1}string({x:e}){return e}int({x:e}){return e&&Math.trunc(e)}na({x:e}){return!!(e===void 0||typeof e=="number"&&isNaN(e))}fixnan({source:e},t){return e===void 0||typeof e=="number"&&isNaN(e)?this._cacheData[`fixnan_${t}`]:(this._cacheData[`fixnan_${t}`]=e,e)}nz({source:e,replacement:t}){return e!==void 0&&!(typeof e=="number"&&isNaN(e))?e:t||0}time({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._timeHandle(this._variables.time,i,e,t,r,n)}time_close({timeframe:e="",session:t,timezone:r,bars_back:n=0},i){return this._variables.time_close&&this._timeHandle(this._variables.time_close,i,e,t,r,n)}timestamp(e){const{dateString:t,timezone:r,year:n,month:i,day:a,hour:l=0,minute:c=0,second:p=0}=e;if(t)return tt(t).utc(!/GMT|UTC/.test(t)).valueOf();let h=i-1,f=n;if(h<0){const g=Math.ceil(Math.abs(h/12));h=12*g+h,f=n-g}let d=tt({year:f,month:h,day:a,hour:l,minute:c,second:p});return r&&(d=qr(d.utc(!0).valueOf(),r)),d.utc(!0).valueOf()}weekofyear({time:e,timezone:t}){return qr(e,t).week()}year({time:e,timezone:t}){return qr(e,t).year()}second({time:e,timezone:t}){return qr(e,t).second()}month({time:e,timezone:t}){return qr(e,t).month()+1}minute({time:e,timezone:t}){return qr(e,t).minute()}hour({time:e,timezone:t}){return qr(e,t).hour()}dayofweek({time:e,timezone:t}){return qr(e,t).day()+1}dayofmonth({time:e,timezone:t}){return qr(e,t).date()}_calcTimeOffset(e,t){const r=this._variables.getTimeTradingday(e,t),n=Xr(t)*1e3;return e-r-Math.floor((e-r)/n)*n}_timeHandle(e,t,r="",n,i,a=0){const l=r||this._variables.timeframe.period,c=Xr(l),p=Xr(this._variables.timeframe.period);let h;if(c<=p)h=e;else{const f=`time_${t}`,d=this._cacheData[f];if(d)d.currentTime+c*1e3-d.offset<=e?(h=e,this._cacheData[f]={currentTime:e,offset:0}):h=d;else{const g=this._calcTimeOffset(e,l);this._cacheData[f]={currentTime:e,offset:g},h=e}}if(n){const{timePeriods:f,weeks:d}=this._parserSession(n,t),g=tt(e).format("YYYY-MM-DD"),y=h;h=void 0;for(const w of f){const[v,E]=w;if(tt(e).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")){tt(y).isBetween(`${g} ${v}`,`${g} ${E}`,"hour")?h=y:h=tt(`${g} ${v}`).valueOf();break}}const m=this._variables.dayofweek;h&&!d.includes(m)&&(h=void 0)}return i&&(h=h&&qr(h,i).valueOf()),h&&h-a*p*1e3}_seriesColorHandle(e,t,r){var n;if(r&&t!=null&&t.length)for(const i of t){if((n=r.gradientColorKeys)!=null&&n.includes(i))continue;const a=e[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(e,t){const r=e.split(":"),n=r[0],a=(r[1]||"1234567").split("").map(c=>{const p=parseInt(c,10);if(p<1||p>7){this._errorListener.addError(`Invalid day of week: ${c}`,t,ze.Error);return}return p});return{timePeriods:n.split(",").map(c=>{c===""||c===fi.regular?c="0930-1500":c===fi.extended&&(c="1500-1830");const p=c.split("-");return p.length!==2?(this._errorListener.addError(`Invalid time period: ${c}`,t,ze.Error),[]):[this._processTime(p[0],t),this._processTime(p[1],t)]}),weeks:a}}_processTime(e,t){const r=parseInt(e.slice(0,2),10),n=parseInt(e.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",t,ze.Error);return}return`${r}:${n}`}}class aw{constructor(e,t){R(this,"_variables");R(this,"_scriptId");R(this,"_cacheData");this._variables=e,this._scriptId=t,this._cacheData=new Map}security(e,t){const r=self.workerStorage.get(`request_${this._scriptId}`),{paramsExpr:n=[]}=e,i=this._getRequestData(e,t);if(r!=null&&r.has(t)){const c=r.get(t);return this._runScripts(c,t,!1,n,i)}const a=this._parseExprCode(e),l=this._runScripts(a,t,!0,n,i);return r==null||r.set(t,a),l}_parseExprCode(e){let{expression:t,paramsExpr:r=[]}=e,n=[],i=1;t=Il(t);const a=JSON.parse(t),l=a.pop();let c=(l==null?void 0:l.memberCodes)||{},p=(l==null?void 0:l.depends)||[];if(!p.length)return`return ${l==null?void 0:l.code}`;let h=[],f=[];const d=[];if(this._getDependCodes(p,a,n,h,f,d),f.length){const m=r.length;let w=[];for(let v=m-1;v>=0;v--){const E=r[v];let b=JSON.parse(Il(E));const N=[];i!==0&&f.length&&(w.unshift("{"),i++),b=b.map(S=>{const{scope:I,code:C,varNames:B,dependSelf:L}=S;return I===2&&!N.includes(B)&&!L&&(S.code=`let ${C}`),B&&N.push(...B.split(", ")),S.memberCodes&&Object.assign(c,{...S.memberCodes}),S});const x=[],F=[];let M=f.map(S=>({...S,isArg:!1,isPreArg:!0}));f=[],this._getDependCodes(M,b,F,h,f,x),w.unshift(...F,...x),n=w.concat(n),w=[]}}for(n.push(`return ${l==null?void 0:l.code}`);i>1;)n.push("}"),i--;n=h.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
65
|
${g}`),g}_getRequestData(e,t){let{symbol:r,timeframe:n,calc_bars_count:i}=e;const a=self.workerStorage.get(`request_${this._scriptId}_data`),l=`${r}--${n}`;if(a!=null&&a.has(l)){const{index:c=0,periodStamp:p=Xr(this._variables.__period)*1e3}=this._cacheData.get(t)||{},h=(a.get(l)||[]).slice(c),f=this._variables.time,d=p+f;for(const[g,y]of h.entries()){const{timestamp:m,close:w,open:v,high:E,low:b,volume:N}=y;let x=m*1e3;if(x>=d){this._cacheData.set(t,{index:g,periodStamp:p});return}if(x>=f)return this._cacheData.set(t,{index:g+1,periodStamp:p}),{close:Number(w),open:Number(v),high:Number(E),low:Number(b),timestamp:m,volume:N}}this._cacheData.set(t,{index:h.length,periodStamp:p})}else{const c=self.workerStorage.get(`request_${this._scriptId}_list`);(c==null?void 0:c.get(l))||c==null||c.set(l,{id:l,calc_bars_count:i,symbol:r,timeframe:n})}}_getDependCodes(e,t,r,n,i,a){for(const l of e){if(!l.isArg){const c=t.filter(h=>{var f;return(f=h==null?void 0:h.depends)==null?void 0:f.some(d=>d.name===l.name&&d.scope===l.scope&&d.isAgainAssign)});for(const h of c){const{code:f,depends:d}=h;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,t,r,n,i,a)}}const p=t.find(h=>{var f;return((f=h.varNames)==null?void 0:f.split(", ").includes(l.name))&&(!l.isPreArg||l.isPreArg&&h.methodName===l.functionName)||h.funcName===l.name});if(p){const{code:h,depends:f}=p,d=r.findIndex(g=>g===h);if(d!==-1&&r.splice(d,1),r.unshift(h),f!=null&&f.length){for(const g of f)g.memberCode&&a.push(g.memberCode);this._getDependCodes(f,t,r,n,i,a)}continue}}i.some(c=>c.name===l.name)||i.push(l)}}_runScripts(e,t,r,n,i){const a=`${this._scriptId}_${t}`;let{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h}=self.workerStorage.get(a)||{};return r&&(l=new oh(a),c=new eh,p=new sh(this._variables.mintick||1e-5,l,this._scriptId),h=new Function("$_var","$_const","$_func","$paramsExpr","$posStr",e),self.workerStorage.set(a,{builtInGather:l,buildinConstants:c,buildInFunctions:p,tradingvueFunc:h})),h(l,c,p,n||[],t)}}let uw=class{constructor(){}prefix(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[0])||""}ticker(e){var r;const{symbol:t}=e;return((r=t==null?void 0:t.split("."))==null?void 0:r[1])||""}};class lw{constructor(e){R(this,"_logs");R(this,"_variables");R(this,"_intlFormat");this._variables=e,this._logs=[],this._intlFormat=new Intl.NumberFormat("en-US")}get logs(){return this._logs}clearLogs(){this._logs=[]}info(e,t,r){this._addLog(e,t,"info",r)}error(e,t,r){this._addLog(e,t,"error",r)}warning(e,t,r){this._addLog(e,t,"warning",r)}_addLog(e,t,r,n){if(typeof t=="string"&&(n=t),n.startsWith("export"))return;const{message:i,formatString:a}=e,{time:l,bar_index:c}=this._variables;let p=i;a&&Array.isArray(t)&&t.length&&(p=a.replace(/{(\d+)}/g,(h,f)=>{let d=t[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:h})),p&&this._logs.push({message:`[${tt(l).format()}]: ${p}`,time:l,barIndex:c,type:r})}}class cw{constructor(e){R(this,"_errorListener");this._errorListener=e}error({message:e},t){t.startsWith("export")||this._errorListener.addError(e,t,ze.Error)}}class fw{constructor(){R(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return zr.flatMap([...this._errors.values()])}addError(e,t,r,n=0){const[i,a]=t.split("_").slice(-2),l=this._errors.get(t),c={message:e,endLineNumber:Number(i),startColumn:Number(a)+1,endColumn:Number(a)+n+1,startLineNumber:Number(i),type:r};l?l.push(c):this._errors.set(t,[c])}}class hw{constructor(){R(this,"_isMarketOpen");R(this,"_currentBarIndex");R(this,"_totalBarIndex");R(this,"_isRealTimeBar");R(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(e,t,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=e,this._totalBarIndex=t,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 pw{constructor(e){R(this,"_variables");this._variables=e}get isfirstbar(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get isfirstbar_regular(){return this._variables.timeframe.isdwm?!0:this._variables.time===this._variables.time_tradingday}get islastbar(){if(this._variables.timeframe.isdwm)return!0;const e=Xr(this._variables.timeframe.period);return this._variables.time+e===this._variables.time_tradingday+24*60*60*1e3}get islastbar_regular(){if(this._variables.timeframe.isdwm)return!0;const e=Xr(this._variables.timeframe.period);return this._variables.time+e===this._variables.time_tradingday+24*60*60*1e3}get ismarket(){return!0}get ispostmarket(){return!1}get ispremarket(){return!1}}class dw{constructor(e){R(this,"_orders");R(this,"_historyOrders");R(this,"_options");R(this,"_max_contracts_held_all",0);R(this,"_max_contracts_held_long",0);R(this,"_max_contracts_held_short",0);R(this,"_max_drawdown",0);R(this,"_max_runup",0);R(this,"_max_runup_percent",0);R(this,"_max_drawdown_percent",0);R(this,"_variables");R(this,"_netprofit",0);R(this,"_eventrades",0);R(this,"_avg_trade_percent");R(this,"_closedtrades",0);R(this,"_losstrades",0);R(this,"_grossloss",0);R(this,"_grossloss_percent",0);R(this,"_grossprofit",0);R(this,"_grossprofit_percent",0);R(this,"_wintrades",0);R(this,"_opentrades_capital_held",0);R(this,"_position_avg_price",0);R(this,"_position_size",0);this._orders=[],this._historyOrders=[],this._variables=e}update(){this._calcMaxDrawdownAndMaxRunup()}_calcMaxDrawdownAndMaxRunup(){let e=0,t=0;const{high:r,low:n}=this._variables;for(const p of this._orders){const{in_price:h,qty:f=0,commission:d=0,original_qty:g=0,direction:y}=p,m=y===gt.long?1:-1,w=(r-h)*f,v=(n-h)*f,E=m===1?w:-v,b=m===1?-v:w;e+=b+d*f/g,t+=E+d*f/g}const[i,a]=this._historyOrders.reduce((p,h)=>{let[f,d]=p;const{profit:g=0,commission:y=0}=h;return f+=g,d+=g-y,[f,d]},[0,0]);e-=i,t+=a;const l=e/(this.initial_capital+this.netprofit)*100;this._max_drawdown<e&&(this._max_drawdown=e),l>this._max_drawdown_percent&&(this._max_drawdown_percent=l);const c=t/(this.initial_capital+this.netprofit)*100;t>this._max_runup&&(this._max_runup=t),c>this._max_runup_percent&&(this._max_runup_percent=c)}updateOrders(e){this._orders=e,this._calcMaxContracts()}_calcMaxContracts(){const e=this._orders.length;if(!e)return;const[t,r,n,i,a,l]=this._orders.reduce(([c,p,h,f,d,g],y)=>{const{direction:m,qty:w=0,in_price:v}=y;return m===gt.long?(c+=w,p+=w,g+=w):(c+=w,h+=w,g-=w),f+=w*v,d+=v,[c,p,h,f,d,g]},[0,0,0,0,0,0]);this._position_size=l,this._position_avg_price=a/e,this._opentrades_capital_held=i,this._max_contracts_held_all=Math.max(t,this._max_contracts_held_all),this._max_contracts_held_long=Math.max(r,this._max_contracts_held_long),this._max_contracts_held_short=Math.max(n,this._max_contracts_held_short)}updateHistoryOrders(e){this._historyOrders=e;const t=this._historyOrders.length;this._closedtrades=t;const[r,n,i,a,l,c]=this._historyOrders.reduce((p,h)=>{let[f,d,g,y,m,w]=p;const{profit:v=0,profit_percent:E=0}=h;return f+=v,d+=E,v<0?(g+=v,y+=E):(m+=v,w+=E),[f,d,g,y,m,w]},[0,0,0,0,0,0]);this._avg_trade_percent=t?n/t:void 0,this._netprofit=r,this._grossloss=i,this._grossloss_percent=a,this._grossprofit=l,this._grossprofit_percent=c,this._eventrades=this._historyOrders.filter(p=>p.profit===0).length,this._losstrades=this._historyOrders.filter(p=>(p.profit||0)<0).length,this._wintrades=this._historyOrders.filter(p=>(p.profit||0)>0).length}updateStrategyOptions(e){this._options=e}get long(){return"long"}get short(){return"short"}get account_currency(){return"USD"}get closedtrades(){return this._closedtrades}get opentrades(){return{opentrades:this._orders.length,capital_held:this._opentrades_capital_held}}get avg_losing_trade(){const e=this.losstrades;return e?Math.abs(this.grossloss/e):void 0}get avg_losing_trade_percent(){const e=this.losstrades;return e?Math.abs(this.grossloss_percent/e):void 0}get avg_trade(){if(this.closedtrades)return Math.abs(this.netprofit/this.closedtrades)}get equity(){return this.initial_capital+this.netprofit+this.openprofit}get netprofit(){return this._netprofit}get eventrades(){return this._eventrades}get openprofit(){return this._orders.reduce((e,t)=>{const{profit:r=0}=t;return e+r},0)}get avg_trade_percent(){return this._avg_trade_percent}get avg_winning_trade(){const e=this.wintrades;return e?Math.abs(this.grossprofit/e):void 0}get avg_winning_trade_percent(){const e=this.wintrades;return e?Math.abs(this.grossprofit_percent/e):void 0}get initial_capital(){var e;return((e=this._options)==null?void 0:e.initial_capital)||0}get losstrades(){return this._losstrades}get grossloss(){return this._grossloss}get grossloss_percent(){return this._grossloss_percent}get grossprofit(){return this._grossprofit}get grossprofit_percent(){return this._grossprofit_percent}get wintrades(){return this._wintrades}get margin_liquidation_price(){if(!this._options)return;const{initial_capital:e,margin_long:t=0,margin_short:r=0,commission_type:n,commission_value:i=0}=this._options,a=this._orders[0].direction===gt.long?1:-1,l=(a===1?t:r)/100;if(l<=0)return;const{close:c}=this._variables,[p,h]=this._orders.reduce((f,d)=>{let[g,y]=f;const{in_price:m,qty:w=0,original_qty:v=0}=d,E=m*w;if(g+=E,i){let b=0;switch(n){case Fr.percent:b=(E+w*c)*i/100;break;case Fr.cashPerContract:b=w*i*2;break;case Fr.cashPerOrder:b=w/v*i+i;break}y+=b}return[g,y]},[0,0]);return(p-(e+this.netprofit-h))*a/this.position_size/(1-a*l)}get max_contracts_held_all(){return this._max_contracts_held_all}get max_contracts_held_long(){return this._max_contracts_held_long}get max_contracts_held_short(){return this._max_contracts_held_short}get max_drawdown(){return this._max_drawdown}get max_runup(){return this._max_runup}get max_runup_percent(){return this._max_runup_percent}get max_drawdown_percent(){return this._max_drawdown_percent}get netprofit_percent(){return this.netprofit/this.initial_capital*100}get openprofit_percent(){return this.openprofit/(this.initial_capital+this.netprofit)*100}get position_avg_price(){return this._position_avg_price}get position_entry_name(){if(this._orders.length)return this._orders[0].id}get position_size(){return this._position_size}}class _w{constructor(e){R(this,"_preAccdist");R(this,"_preNvi");R(this,"_prePvi");R(this,"_preObv");R(this,"_prePvt");R(this,"_preWad");R(this,"_preVwap");R(this,"_preValue");R(this,"_currentData");R(this,"_preData");R(this,"_id");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={},this._id=e}update(e){this._preValue={},e.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...e}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:e,low:t,high:r,volume:n}=this._currentData;if(r===t)return this._preAccdist;const i=(e-t-(r-e))/(r-t)*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:e,low:t,high:r,volume:n}=this._currentData,i=(2*e-r-t)/((r-t)*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:e,low:t,high:r,volume:n,open:i}=this._currentData,a=(e-i)/(r-t)*n;return this._preValue.wvad=a,a}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(e-r)*t+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:e,high:t}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(t-e,Math.abs(t-r),Math.abs(e-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:e,volume:t}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(e-r)/r*t+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:e,high:t,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const i=Math.max(t,n),a=Math.min(r,n),l=e-n,p=(l>0?e-a:l<0?e-i:0)+this._preWad;return!this.isRealTime&&(this._preWad=p),this._preValue.wad=p,p}get vwap(){var h,f;if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:e,volume:t}=this._currentData;let{sum:r=0,sumV:n=0,isReset:i}=this._preVwap;if(((f=(h=self.workerStorage)==null?void 0:h.get(this._id))==null?void 0:f.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin"))&&(i=!0,r=n=0),!i)return;const l=e*t+r,c=t+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:c,isReset:i});const p=l/c;return this._preValue.vwap=p,p}_getNvi(){const e=this._preNvi||1,{close:t=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=e||1;return n&&t?a=i<r?l+(n-t)/t*l:l:a=l,!this.isRealTime&&(this._preNvi=a),this._preValue.nvi=a,a}_getPvi(){const e=this._prePvi||1,{close:t=0,volume:r=0}=this._preData,{close:n,volume:i}=this._currentData;let a=1;const l=e||1;return n&&t?a=i>r?l+(n-t)/t*l:l:a=l,!this.isRealTime&&(this._prePvi=a),this._preValue.pvi=a,a}}class mw{constructor(){R(this,"_period");R(this,"_multiplier");R(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(e){if(!e)return;this._period=e;const[t,r]=bs(e);this._multiplier=t,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class gw{constructor(e){R(this,"_variables");R(this,"_bgColor");R(this,"_fgColor");R(this,"isUseBgColor",!1);this._variables=e}updateOptions(e){e!=null&&e.bg_color&&(this._bgColor=e.bg_color,this._fgColor=this._contrastColor(e.bg_color))}get bg_color(){return this.isUseBgColor=!0,this._bgColor}get fg_color(){return this.isUseBgColor=!0,this._fgColor}get is_heikinashi(){return!1}get is_kagi(){return!1}get is_linebreak(){return!1}get is_pnf(){return!1}get is_range(){return!1}get is_renko(){return!1}get is_standard(){return!0}get left_visible_bar_time(){return this._variables.time}get right_visible_bar_time(){return this._variables.time}_parseColor(e){let t,r,n,i;if(e.startsWith("#")){t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);const a=e.substring(7);a?i=parseInt(a,16)/255:i=1}else{const a=this._parserRgbColor(e);t=a[0]||0,r=a[1]||0,n=a[2]||0,i=a[3]||1}return{r:t,g:r,b:n,a:i}}_parserRgbColor(e){var t;return((t=e.match(/\d+/g))==null?void 0:t.map(Number))||[]}_contrastColor(e){const{r:t,g:r,b:n}=this._parseColor(e);return(299*t+587*r+114*n)/1e3>128?"#000000":"#ffffff"}}class vw{constructor(e){R(this,"_variables");this._variables=e}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(){}get tickerid(){}get timezone(){}get type(){}get volumetype(){return"n/a"}}class yw{constructor(e){R(this,"_variables");this._variables=e}get future_amount(){}get future_ex_date(){}get future_pay_date(){}}class ww{constructor(e){R(this,"_variables");this._variables=e}get future_eps(){}get future_period_end_time(){}get future_revenue(){}get future_time(){}}tt.extend(Wp),tt.extend(Bl),tt.extend(kp);class oh{constructor(e){R(this,"_cacheData");R(this,"_barIndex");R(this,"_isRealTimeBar");R(this,"_barstate");R(this,"_priceVariables");R(this,"_lastBarIndex");R(this,"_currentBarTime");R(this,"_lastBarTime");R(this,"_period");R(this,"_offsetTime");R(this,"_timeframe");R(this,"_ta");R(this,"_polyline");R(this,"_label");R(this,"_line");R(this,"_linefill");R(this,"_box");R(this,"_table");R(this,"_strategy");R(this,"_session");R(this,"syminfo");R(this,"chart");R(this,"earnings");R(this,"dividends");R(this,"_timeTradingday");R(this,"_mintick");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 hw,this._timeframe=new mw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new _w(e),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 dw(this),this._session=new pw(this),this.syminfo=new vw(this),this.chart=new gw(this),this.earnings=new ww(this),this.dividends=new yw(this)}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get strategy(){return this._strategy}get session(){return this._session}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:e,open:t,high:r,low:n}=this._priceVariables;return(e+t+r+n)/4}get hl2(){const{high:e,low:t}=this._priceVariables;return(e+t)/2}get hlc3(){const{close:e,high:t,low:r}=this._priceVariables;return(e+t+r)/3}get hlcc4(){const{close:e,high:t,low:r}=this._priceVariables;return(e*2+t+r)/4}get hour(){return tt(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return tt(this._currentBarTime).minute()}get second(){return tt(this._currentBarTime).second()}get month(){return tt(this._currentBarTime).month()+1}get year(){return tt(this._currentBarTime).year()}get dayofweek(){return tt(this._currentBarTime).day()+1}get dayofmonth(){return tt(this._currentBarTime).date()}get weekofyear(){return tt(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[e,t]=bs(this._period);return this._isRealTimeBar?void 0:tt(this._currentBarTime).add(e,t).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this._timeTradingday||this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}get mintick(){return this._mintick}get __period(){return this._period}updateMaxLength(e){const{max_lines_count:t,max_labels_count:r,max_boxes_count:n,max_polylines_count:i}=e;n&&this._box.setMaxLen(n),r&&this._label.setMaxLen(r),t&&this._line.setMaxLen(t),i&&this._polyline.setMaxLen(i)}getTimeTradingday(e,t){const[r,n]=bs(t),i=tt(e);return["M","w","y","d"].includes(n)?i.valueOf():(i.subtract(this._offsetTime,"h"),i.startOf("d").add(this._offsetTime,"h").valueOf())}updateOptions(e){const{interval:t="1D",offsetTime:r=5,mintick:n,chart:i}=e;this._period=t,this._mintick=n,this._offsetTime=r,this._timeframe.update(t),this.chart.updateOptions(i)}updateData(e){const{barIndex:t,c:r,o:n,h:i,l:a,volume:l,time:c,lastBarIndex:p,lastBarTime:h,complete:f,time_tradingday:d}=e;this._priceVariables={close:Number(r),open:Number(n),high:Number(i),low:Number(a),volume:Number(l)},this._isRealTimeBar=f,t>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._timeTradingday=d,this._currentBarTime=c*1e3,this._lastBarIndex=p,this._barIndex=t,this._lastBarTime=h*1e3,this._barstate.update(t,p,f,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:t})}getCacheData(e,t,r){const n=this.setCacheData(e,r);return n[n.length-1-t]}setCacheData(e,t){let r=this._cacheData[e]||{barIndex:-1,data:[]};return r.barIndex>this._barIndex||(r.barIndex===this._barIndex?r.data[r.data.length-1]=t:r.data.push(t),r.barIndex=this._barIndex,this._cacheData[e]=r),r.data}getTypeInstance(e,t){return new Rp(e,t)}getVarValue(e,t,r){const n=`${e}_${t}`,i=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(i)return i}setVarValue(e,t,r,n){const i=`${e}_${t}`;let a;switch(typeof r=="object"&&r&&(n="var",a=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=zr.cloneDeep(r);if(this._cacheData.varNewData[i]=l,a&&a.length)for(const c of a)this._cacheData.varData[i][c]=l[c]}else this._cacheData.varData[i]=r;break;case"varip":this._cacheData.varipData[i]=r;break}return r}add(e,t){return Array.isArray(e)&&Array.isArray(t)?zr.uniq([...e,...t]):typeof e=="number"||typeof t=="number"?Number(e)+Number(t):e+t}sub(e,t){return Array.isArray(e)&&Array.isArray(t)?e.filter(r=>!t.includes(r)):Number(e)-Number(t)}againAssignParse(e,t){var n;if(t)return;const r=(n=e==null?void 0:e.constructor)==null?void 0:n.name;if(r)switch(r){case ts.name:case th.name:case ns.name:case Ua.name:case rs.name:case co.name:e==null||e.delete();break}}}class Fi{constructor(e=50){R(this,"_all");R(this,"_allInstance");R(this,"_pseudoArrayAll");R(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Qe,this._maxLength=e}setMaxLen(e){this._maxLength=e}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(e,t,r){if(this._all.set(e,t),this._allInstance.set(e,r),this._all.size>this._maxLength){const n=this._all.keys().next().value;n&&this.delete(n)}}getValOfBarIndex(e){let t=[];const r=[...this._all.keys()];for(const n of e){const i=r.filter(a=>a.endsWith(`_${n}`));for(const a of i){const l=this._all.get(a);l&&t.push(l)}}return t.length?t:void 0}get(e){return this._all.get(e)}getInstance(e){return this._allInstance.get(e)}delete(e){this._all.delete(e),this._allInstance.delete(e)}}/**
|
@@ -67593,7 +67593,7 @@ function ir(a, n, r) {
|
|
67593
67593
|
function oh() {
|
67594
67594
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
67595
67595
|
}
|
67596
|
-
const Fp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-
|
67596
|
+
const Fp = new Worker(new URL("" + new URL("assets/scriptsRunWorker-DXhENwBC.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
|
67597
67597
|
Fp.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 _o=Symbol("Comlink.proxy"),sm=Symbol("Comlink.endpoint"),am=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),fo=a=>typeof a=="object"&&a!==null||typeof a=="function",nm={canHandle:a=>fo(a)&&a[_o],serialize(a){const{port1:n,port2:s}=new MessageChannel;return bo(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},im={canHandle:a=>fo(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}},go=new Map([["proxy",nm],["throw",im]]);function om(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function bo(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!om(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(xr);let b;try{const h=y.slice(0,-1).reduce((N,U)=>N[U],a),T=y.reduce((N,U)=>N[U],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=xr(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:U}=new MessageChannel;bo(a,U),b=mm(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),xo(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 lm(a){return a.constructor.name==="MessagePort"}function xo(a){lm(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 ho(a){return Mr(a,{type:"RELEASE"}).then(()=>{xo(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&&ho(a)});function cm(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function pm(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===am)return()=>{pm(c),ho(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Mr(a,{type:"GET",path:n.map(f=>f.toString())}).then(xr);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Mr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(xr)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===sm)return Mr(a,{type:"ENDPOINT"}).then(xr);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=wo(y);return Mr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(xr)},construct(l,m){Qs(o);const[y,f]=wo(m);return Mr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(xr)}});return cm(c,a),c}function dm(a){return Array.prototype.concat.apply([],a)}function wo(a){const n=a.map(ea);return[n.map(s=>s[0]),dm(n.map(s=>s[1]))]}const vo=new WeakMap;function mm(a,n){return vo.set(a,n),a}function gn(a){return Object.assign(a,{[_o]:!0})}function ea(a){for(const[n,s]of go)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},vo.get(a)||[]]}function xr(a){switch(a.type){case"HANDLER":return go.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Mr(a,n,s){return new Promise(o=>{const c=um();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 um(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const To=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-
|
144
|
+
*/const _o=Symbol("Comlink.proxy"),sm=Symbol("Comlink.endpoint"),am=Symbol("Comlink.releaseProxy"),yn=Symbol("Comlink.finalizer"),Ys=Symbol("Comlink.thrown"),fo=a=>typeof a=="object"&&a!==null||typeof a=="function",nm={canHandle:a=>fo(a)&&a[_o],serialize(a){const{port1:n,port2:s}=new MessageChannel;return bo(a,n),[s,[s]]},deserialize(a){return a.start(),_n(a)}},im={canHandle:a=>fo(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}},go=new Map([["proxy",nm],["throw",im]]);function om(a,n){for(const s of a)if(n===s||s==="*"||s instanceof RegExp&&s.test(n))return!0;return!1}function bo(a,n=globalThis,s=["*"]){n.addEventListener("message",function o(c){if(!c||!c.data)return;if(!om(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(xr);let b;try{const h=y.slice(0,-1).reduce((N,U)=>N[U],a),T=y.reduce((N,U)=>N[U],a);switch(m){case"GET":b=T;break;case"SET":h[y.slice(-1)[0]]=xr(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:U}=new MessageChannel;bo(a,U),b=mm(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),xo(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 lm(a){return a.constructor.name==="MessagePort"}function xo(a){lm(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 ho(a){return Mr(a,{type:"RELEASE"}).then(()=>{xo(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&&ho(a)});function cm(a,n){const s=(Zs.get(n)||0)+1;Zs.set(n,s),Js&&Js.register(a,n,a)}function pm(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===am)return()=>{pm(c),ho(a),o=!0};if(m==="then"){if(n.length===0)return{then:()=>c};const y=Mr(a,{type:"GET",path:n.map(f=>f.toString())}).then(xr);return y.then.bind(y)}return fn(a,[...n,m])},set(l,m,y){Qs(o);const[f,b]=ea(y);return Mr(a,{type:"SET",path:[...n,m].map(h=>h.toString()),value:f},b).then(xr)},apply(l,m,y){Qs(o);const f=n[n.length-1];if(f===sm)return Mr(a,{type:"ENDPOINT"}).then(xr);if(f==="bind")return fn(a,n.slice(0,-1));const[b,h]=wo(y);return Mr(a,{type:"APPLY",path:n.map(T=>T.toString()),argumentList:b},h).then(xr)},construct(l,m){Qs(o);const[y,f]=wo(m);return Mr(a,{type:"CONSTRUCT",path:n.map(b=>b.toString()),argumentList:y},f).then(xr)}});return cm(c,a),c}function dm(a){return Array.prototype.concat.apply([],a)}function wo(a){const n=a.map(ea);return[n.map(s=>s[0]),dm(n.map(s=>s[1]))]}const vo=new WeakMap;function mm(a,n){return vo.set(a,n),a}function gn(a){return Object.assign(a,{[_o]:!0})}function ea(a){for(const[n,s]of go)if(s.canHandle(a)){const[o,c]=s.serialize(a);return[{type:"HANDLER",name:n,value:o},c]}return[{type:"RAW",value:a},vo.get(a)||[]]}function xr(a){switch(a.type){case"HANDLER":return go.get(a.name).deserialize(a.value);case"RAW":return a.value}}function Mr(a,n,s){return new Promise(o=>{const c=um();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 um(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const To=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-DXhENwBC.js").href:new URL("assets/scriptsRunWorker-DXhENwBC.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"});To.onerror=a=>{console.error(a)};async function Do(a){return await Gs.setInlayHints(a)}const ko=_n(To),Io=_n(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-Bcz7NTve.js").href:new URL("assets/parserTccWorker-Bcz7NTve.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 Ao(a,n=!1){const{functions:s,types:o,constants:c,variables:l,methods:m}=pt;return await Io.parseTcc(a,n,gn(Do),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function ym(a,n){const{functions:s,types:o,constants:c,variables:l,methods:m}=pt;return await Io.parseLibraryCode(a,n,gn(Do),{functions:Object.fromEntries(s),methods:Object.fromEntries(m),types:Object.fromEntries(o),constants:Object.fromEntries(c),variables:Object.fromEntries(l)})}async function qo(a,n,s=!0){return await ko.runScript(a,n,s)}async function _m(a){return await ko.removeScript(a)}function fm(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 fm({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"}}});let Co={};const gm=(a,n)=>{const{height:s,width:o,theme:c,options:l,hasDiff:m,readOnly:y,defaultValue:f,onChange:b,onLinkOpen:h,onDeclareConfigChange:T,onCursorPositionChange:N,onActionTrigger:U,onEditorDidMount:R}=a,L=O.useRef(null),j=O.useRef(null),V=O.useRef(!1);O.useImperativeHandle(n,()=>({setOriginalScript(z){var W;(W=L.current)==null||W.setOriginalScript(z)},setScript(z){var W;(W=L.current)==null||W.setValue(z)},gotoLine(){var z;(z=L.current)==null||z.gotoLine()},getEditorLayout(){var z;return(z=L.current)==null?void 0:z.getEditorLayout()},setPosition(z,W){var Q;(Q=L.current)==null||Q.setPosition({column:z,lineNumber:W})},setModelMarkers(z){var W;(W=L.current)==null||W.setModelMarkers(z)},focus(){var z;(z=L.current)==null||z.focus()}})),O.useEffect(()=>{var z,W;m?(W=L.current)==null||W.addDiffDecorations():(z=L.current)==null||z.removeDiffDecorations()},[m]),O.useEffect(()=>{c&&ke.editor.setTheme(c)},[c]),O.useEffect(()=>{var z;(z=L.current)==null||z.updateActionTrigger(U)},[U]),O.useEffect(()=>{var z;h&&((z=L.current)==null||z.addLinkOpenFunc(h))},[h]);function Y(z,W){var ie,Ze;St.initBuiltinsTrees(),Gs.setEditor(z),L.current=new rm(z,W,U),h&&((ie=L.current)==null||ie.addLinkOpenFunc(h)),m&&((Ze=L.current)==null||Ze.addDiffDecorations()),qd(z),requestAnimationFrame(H);const Q=z.getValue();L.current.onChangeCursorPosition(N),b&&b(Q),!y&&F(Q),R&&R()}const F=O.useCallback(async z=>{var Lt;const W=Date.now();V.current=!1;const{errors:Q,functions:ie,methods:Ze,types:Et,variables:Ue,overloadsFuncs:Ke,imports:J,preParserCode:be,enums:Le}=await Ao(z),Me=new Map(Object.entries(ie)),dt=new Map(Object.entries(Ze)),wt=new Map(Object.entries(Et)),se=new Map(Object.entries(Ue)),he=new Map(Object.entries(J)),Pe=new Map(Object.entries(Le));br.setUserDefined({functions:Me,methods:dt,types:wt,variables:se,imports:he,enums:Pe},Ke),St.setUserDefind(Me,wt,se,dt,Pe);const Nt=Q.map(He=>({...He,severity:He.type||ke.MarkerSeverity.Error}));if(y)return;try{const He=await qo(be||"",{isPreParser:!0});(!io.isEqual(He,Co)||Q.length)&&(He.errors=He.errors.concat(Q),Co=He,T&&T(He))}catch(He){console.log(He),Q.push({message:He.message,startLineNumber:0,endLineNumber:0,startColumn:0,endColumn:0})}!V.current&&((Lt=L.current)==null||Lt.setModelMarkers(Nt));const je=Date.now();console.log((je-W)/1e3)},[T,y]),B=O.useMemo(()=>io.debounce(F,1500),[F]);function q(z){var W;if(y){F(z||"");return}V.current=!0,Gs.clearInlayHints(),(W=L.current)==null||W.setModelMarkers([]),z!==void 0&&(b&&b(z),B(z))}const H=O.useCallback(()=>{var W,Q;const z=(W=j.current)==null?void 0:W.getBoundingClientRect();(Q=L.current)==null||Q.setEditorLayout((z==null?void 0:z.height)||0,z==null?void 0:z.width)},[]);return O.useEffect(()=>{const z=()=>{window.requestAnimationFrame(H)},W=new ResizeObserver(z);return j.current&&W.observe(j.current),()=>{var Q;j.current&&W.unobserve(j.current),W.disconnect(),(Q=L.current)==null||Q.dispose()}},[]),M.jsx("div",{ref:j,children:M.jsx(gd,{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?Pd:{},readOnlyMessage:{value:"该脚本是只读的。它无法被编辑。"},...l},onMount:Y,onChange:q})})},bm=O.forwardRef(gm),xm=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,Lr),b.languages.setLanguageConfiguration(Se,on)},[]);return M.jsx(md,{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={},hm=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()}},wm=hm,zo={"text/plain":"Text","text/html":"Url",default:"Text"},vm="Copy to clipboard: #{key}, Enter";function Tm(a){var n=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return a.replace(/#{\s*key\s*}/g,n)}function Dm(a,n){var s,o,c,l,m,y,f=!1;n||(n={}),s=n.debug||!1;try{c=wm(),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=zo[n.format]||zo.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=Tm("message"in n?n.message:vm),window.prompt(o,a)}}finally{m&&(typeof m.removeRange=="function"?m.removeRange(l):m.removeAllRanges()),y&&document.body.removeChild(y),c()}return f}var km=Dm;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=So(O),Im=So(km),Am=["text","onCopy","options","children"];function So(a){return a&&a.__esModule?a:{default:a}}function Eo(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 No(a){for(var n=1;n<arguments.length;n++){var s=arguments[n]!=null?arguments[n]:{};n%2?Eo(Object(s),!0).forEach(function(o){hn(a,o,s[o])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(s)):Eo(Object(s)).forEach(function(o){Object.defineProperty(a,o,Object.getOwnPropertyDescriptor(s,o))})}return a}function qm(a,n){if(a==null)return{};var s=Cm(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 Cm(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 zm(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}function Lo(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 Sm(a,n,s){return n&&Lo(a.prototype,n),s&&Lo(a,s),Object.defineProperty(a,"prototype",{writable:!1}),a}function Em(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 Nm(a){var n=Mm();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 Lm(this,c)}}function Lm(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 Mo(a)}function Mo(a){if(a===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function Mm(){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 Po=function(a){Em(s,a);var n=Nm(s);function s(){var o;zm(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(Mo(o),"onClick",function(y){var f=o.props,b=f.text,h=f.onCopy,T=f.children,N=f.options,U=ra.default.Children.only(T),R=(0,Im.default)(b,N);h&&h(b,R),U&&U.props&&typeof U.props.onClick=="function"&&U.props.onClick(y)}),o}return Sm(s,[{key:"render",value:function(){var c=this.props;c.text,c.onCopy,c.options;var l=c.children,m=qm(c,Am),y=ra.default.Children.only(l);return ra.default.cloneElement(y,No(No({},m),{},{onClick:this.onClick}))}}]),s}(ra.default.PureComponent);ta.CopyToClipboard=Po,hn(Po,"defaultProps",{onCopy:void 0,options:void 0});var Pm=ta,wn=Pm.CopyToClipboard;wn.CopyToClipboard=wn;var Om=wn;const vn=cp(Om);async function Rm(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:U}=s,R={name:o};if(a.length>1&&(R.overloads=`${a.length} overloads`),l&&(R.type=l),c&&(R.name=`${o}()`,R.args=c.map(L=>{const{name:j,desc:V,displayType:Y}=L;return{label:`${j} (${Y})`,desc:V&&hr(V)}})),m&&(R.desc=m.map(L=>hr(L))),y&&(R.originalExample=y.join(`
|
147
147
|
`),R.examples=await ke.editor.colorize(R.originalExample,Se,{tabSize:4})),T){R.detailedDesc=[];for(const L of T){const{desc:j,examples:V}=L;let Y=j.map(q=>hr(q)),F,B;V&&(B=V.join(`
|