@pipsend/charts 2.3.18 → 2.3.19

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.
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @license
3
- * Pipsend Charts v2.3.18-dev+202610170141
3
+ * Pipsend Charts v2.3.19-dev+202610211514
4
4
  * Copyright (c) 2026 Pipsend
5
5
  * Licensed under MIT License
6
6
  * Built on TradingView Lightweight Charts™ (Apache 2.0)
7
7
  */
8
- const t={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var i,s;function n(t,i){const s={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}function e(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(s,i+e),t.lineTo(n,i+e),t.stroke()}function r(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function h(t){if(void 0===t)throw new Error("Value is undefined");return t}function l(t){if(null===t)throw new Error("Value is null");return t}function o(t){return l(h(t))}!function(t){t[t.Simple=0]="Simple",t[t.WithSteps=1]="WithSteps",t[t.Curved=2]="Curved"}(i||(i={})),function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(s||(s={}));class a{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",V:0,I:0,L:0,A:0,B:0},this.O=t}W(){const t=this.M,i=this.$(),s=this.H();return t.P===i&&t.D===s||(t.P=i,t.D=s,t.T=g(i,s),t.A=2.5/12*i,t.V=t.A,t.I=i/12*t.C,t.L=i/12*t.C,t.B=0),t.R=this.N(),t.F=this.U(),this.M}N(){return this.O.W().layout.textColor}U(){return this.O.q()}$(){return this.O.W().layout.fontSize}H(){return this.O.W().layout.fontFamily}}function M(t){return t<0?0:t>255?255:Math.round(t)||0}function y(t){return.199*t[0]+.687*t[1]+.114*t[2]}class S{constructor(t,i){this.j=new Map,this.Y=t,i&&(this.j=i)}X(t,i){if("transparent"===t)return t;const s=this.G(t),n=s[3];return`rgba(${s[0]}, ${s[1]}, ${s[2]}, ${i*n})`}K(t){const i=this.G(t);return{Z:`rgb(${i[0]}, ${i[1]}, ${i[2]})`,J:y(i)>160?"black":"white"}}tt(t){return y(this.G(t))}it(t,i,s){const[n,e,r,h]=this.G(t),[l,o,a,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(o-e)),M(r+s*(a-r)),(c=h+s*(_-h),c<=0||c>1?Math.min(Math.max(c,0),1):Math.round(1e4*c)/1e4)];var c;return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}G(t){const i=this.j.get(t);if(i)return i;const s=function(t){const i=document.createElement("div");i.style.display="none",document.body.appendChild(i),i.style.color=t;const s=window.getComputedStyle(i).color;return document.body.removeChild(i),s}(t),n=s.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/);if(!n){if(this.Y.length)for(const i of this.Y){const s=i(t);if(s)return this.j.set(t,s),s}throw new Error(`Failed to parse color: ${t}`)}const e=[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10),n[4]?parseFloat(n[4]):1];return this.j.set(t,e),e}}class x{constructor(){this.st=[]}nt(t){this.st=t}et(t,i,s){this.st.forEach(n=>{n.et(t,i,s)})}}class C{et(t,i,s){t.useBitmapCoordinateSpace(t=>this.rt(t,i,s))}}class P extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.ht||null===this.ht.ot)return;const n=this.ht.ot,e=this.ht,r=Math.max(1,Math.floor(i))%2/2,h=h=>{t.beginPath();for(let l=n.to-1;l>=n.from;--l){const n=e._t[l],o=Math.round(n.ut*i)+r,a=n.ct*s,_=h*s+r;t.moveTo(o,a),t.arc(o,a,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.Vt(),i=this.Pt.It(),s=this.Ct.Lt(),n=this.O.At();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Bt(s),l=i.Ot();!t&&null!==h&&i.Vt()&&null!==l?(r.wt=h.Et,r.vt=h.vt,r.dt=h.Wt,r._t[0].bt=h.bt,r._t[0].ct=i.$t().zt(h.bt,l.Ht),r.ft=h.Nt??this.O.Ut(r._t[0].ct/i.$t().qt()),r._t[0].gt=s,r._t[0].ut=n.jt(s),r.ot=k):r.ot=null})}}class R extends C{constructor(t){super(),this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;const h=this.Yt.Xt.Vt,l=this.Yt.Gt.Vt;if(!h&&!l)return;const o=Math.round(this.Yt.ut*s),a=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,o,0,i.height)),l&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,a,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",Vt:!1},Gt:{dt:1,Kt:0,R:"",Vt:!1},ut:0,ct:0},this.Jt=new R(this.Zt),this.Qt=t,this.Pt=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.Rt(),this.xt=!1),this.Jt}Rt(){const t=this.Qt.Vt(),i=this.Pt.ti().W().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.Vt=!1,void(s.Xt.Vt=!1);s.Gt.Vt=t&&this.Qt.ii(this.Pt),s.Xt.Vt=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Kt=i.horzLine.style,s.Gt.R=i.horzLine.color,s.Xt.dt=i.vertLine.width,s.Xt.Kt=i.vertLine.style,s.Xt.R=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function V(t,i,s,n,e,r){t.fillRect(i+r,s,n-2*r,r),t.fillRect(i+r,s+e-r,n-2*r,r),t.fillRect(i,s,r,e),t.fillRect(i+n-r,s,r,e)}function I(t,i,s,n,e,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(i,s,n,e),t.restore()}function L(t,i,s,n,e,r){t.beginPath(),t.roundRect?t.roundRect(i,s,n,e,r):(t.lineTo(i+n-r[1],s),0!==r[1]&&t.arcTo(i+n,s,i+n,s+r[1],r[1]),t.lineTo(i+n,s+e-r[2]),0!==r[2]&&t.arcTo(i+n,s+e,i+n-r[2],s+e,r[2]),t.lineTo(i+r[3],s+e),0!==r[3]&&t.arcTo(i,s+e,i,s+e-r[3],r[3]),t.lineTo(i,s+r[0]),0!==r[0]&&t.arcTo(i,s,i+r[0],s,r[0]))}function A(t,i,s,n,e,r,h=0,l=[0,0,0,0],o=""){if(t.save(),!h||!o||o===r)return L(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const a=h/2;var _;L(t,i+a,s+a,n-h,e-h,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==o&&(t.lineWidth=h,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function B(t,i,s,n,e,r,h){t.save(),t.globalCompositeOperation="copy";const l=t.createLinearGradient(0,0,0,e);l.addColorStop(0,r),l.addColorStop(1,h),t.fillStyle=l,t.fillRect(i,s,n,e),t.restore()}class O{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.ri=i}qt(t,i){return this.Yt.Vt?t.P+t.A+t.V:0}et(t,i,s,n){if(!this.Yt.Vt||0===this.Yt.hi.length)return;const e=this.Yt.R,r=this.ri.Z,h=t.useBitmapCoordinateSpace(t=>{const h=t.context;h.font=i.T;const l=this.li(t,i,s,n),o=l.oi;return l.ai?A(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):A(h,o.fi,o.ui,o.ci,o.di,r,o.pi,[0,o.vt,o.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.ai?o.yi-o.pi:0,o.ui,o.pi,o.Si-o.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.ai?"right":"left",t.textBaseline="middle",t.fillStyle=e,t.fillText(this.Yt.hi,s.Ci,(s.ui+s.Si)/2+s.Pi)})}li(t,i,s,n){const{context:e,bitmapSize:r,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.A+this.ri.Di,c=i.V+this.ri.Ri,d=i.I,p=i.L,f=this.Yt.hi,v=i.P,m=s.Fi(e,f),w=Math.ceil(s.Vi(e,f)),g=v+u+c,b=i.S+d+p+w+a,M=Math.max(1,Math.floor(o));let y=Math.round(g*o);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(a*l),P=this.ri.Ii??this.ri.Li,T=Math.round(P*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,V=R?r.width-S:S;let I,L,A;return R?(I=V-x,L=V-C,A=F-a-d-_):(I=V+x,L=V+C,A=F+a+d),{ai:R,oi:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:I,fi:V,gi:L,bi:M,yi:r.width},xi:{ui:k/o,Si:D/o,Ci:A,Pi:m}}}}class E{constructor(t){this.Ai={Li:0,Z:"#000",Ri:0,Di:0},this.Bi={hi:"",Vt:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Oi={hi:"",Vt:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Ei=new(t||O)(this.Bi,this.Ai),this.Wi=new(t||O)(this.Oi,this.Ai)}hi(){return this.zi(),this.Bi.hi}Li(){return this.zi(),this.Ai.Li}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Ei.qt(t,i),this.Wi.qt(t,i))}$i(){return this.Ai.Ii||0}Hi(t){this.Ai.Ii=t}Ni(){return this.zi(),this.Bi.Vt||this.Oi.Vt}Ui(){return this.zi(),this.Bi.Vt}Dt(t){return this.zi(),this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Oi.mi=this.Oi.mi&&t.W().ticksVisible,this.Ei.lt(this.Bi,this.Ai),this.Wi.lt(this.Oi,this.Ai),this.Ei}qi(){return this.zi(),this.Ei.lt(this.Bi,this.Ai),this.Wi.lt(this.Oi,this.Ai),this.Wi}zi(){this.xt&&(this.Bi.mi=!0,this.Oi.mi=!1,this.ji(this.Bi,this.Oi,this.Ai))}}class W extends E{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Xi=s}ji(t,i,s){if(t.Vt=!1,2===this.Qt.W().mode)return;const n=this.Qt.W().horzLine;if(!n.labelVisible)return;const e=this.Yi.Ot();if(!this.Qt.Vt()||this.Yi.Gi()||null===e)return;const r=this.Yi.Ki().K(n.labelBackgroundColor);s.Z=r.Z,t.R=r.J;const h=2/12*this.Yi.P();s.Di=h,s.Ri=h;const l=this.Xi(this.Yi);s.Li=l.Li,t.hi=this.Yi.Zi(l.bt,e),t.Vt=!0}}const z=/[1-9]/g;class ${constructor(){this.Yt=null}lt(t){this.Yt=t}et(t,i){if(null===this.Yt||!1===this.Yt.Vt||0===this.Yt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Vi(t,l(this.Yt).hi,z))));if(s<=0)return;const n=i.Qi,e=s+2*n,r=e/2,h=this.Yt.ts;let o=this.Yt.Li,a=Math.floor(o-r)+.5;a<0?(o+=Math.abs(0-a),a=Math.floor(o-r)+.5):a+e>h&&(o-=Math.abs(h-(a+e)),a=Math.floor(o-r)+.5);const _=a+e,u=Math.ceil(0+i.S+i.C+i.A+i.P+i.V);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(a*s),h=Math.round(0*n),o=Math.round(_*s),c=Math.round(u*n),d=Math.round(2*s);if(t.beginPath(),t.moveTo(r,h),t.lineTo(r,c-d),t.arcTo(r,c,r+d,c,d),t.lineTo(o-d,c),t.arcTo(o,c,o,c-d,d),t.lineTo(o,h),t.fill(),e.mi){const r=Math.round(e.Li*s),l=h,o=Math.round((l+i.C)*n);t.fillStyle=e.R;const a=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,a,o-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.A+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(a+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={Vt:!1,Z:"#4c525e",R:"white",hi:"",ts:0,Li:NaN,mi:!0},this.Ct=t,this.ss=i,this.Xi=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}Rt(){const t=this.Zt;if(t.Vt=!1,2===this.Ct.W().mode)return;const i=this.Ct.W().vertLine;if(!i.labelVisible)return;const s=this.ss.At();if(s.Gi())return;t.ts=s.ts();const n=this.Xi();if(null===n)return;t.Li=n.Li;const e=s.ns(this.Ct.Lt());t.hi=s.es(l(e)),t.Vt=!0;const r=this.ss.Ki().K(i.labelBackgroundColor);t.Z=r.Z,t.R=r.J,t.mi=s.W().ticksVisible}}class N{constructor(){this.rs=null,this.hs=0}ls(){return this.hs}_s(t){this.hs=t}$t(){return this.rs}us(t){this.rs=t}cs(t){return[]}ds(){return[]}Vt(){return!0}}var U;!function(t){t[t.Normal=0]="Normal",t[t.Magnet=1]="Magnet",t[t.Hidden=2]="Hidden",t[t.MagnetOHLC=3]="MagnetOHLC"}(U||(U={}));class q extends N{constructor(t,i){super(),this.Pt=null,this.ps=NaN,this.fs=0,this.vs=!1,this.ws=new Map,this.gs=!1,this.bs=new WeakMap,this.Ms=new WeakMap,this.ys=NaN,this.Ss=NaN,this.xs=NaN,this.Cs=NaN,this.ss=t,this.Ps=i;this.Ts=((t,i)=>s=>{const n=i(),e=t();if(s===l(this.Pt).ks())return{bt:e,Li:n};{const t=l(s.Ot());return{bt:s.Ds(n,t),Li:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.At().Rs(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Li:n}:null})(()=>this.fs,()=>this.ni());this.Fs=new H(this,t,s)}W(){return this.Ps}Vs(t,i){this.xs=t,this.Cs=i}Is(){this.xs=NaN,this.Cs=NaN}Ls(){return this.xs}As(){return this.Cs}Bs(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Os(t,i,s)}Lt(){return this.fs}ni(){return this.ys}ei(){return this.Ss}Vt(){return this.vs}Es(){this.vs=!1,this.Ws(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Pt=null,this.Is(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new F(this,t),this.bs.set(t,i));let s=this.Ms.get(t);return s||(s=new D(this.ss,this,t),this.Ms.set(t,s)),[i,s]}ii(t){return t===this.Pt&&this.Ps.horzLine.visible}si(){return this.Ps.vertLine.visible}Hs(t,i){this.vs&&this.Pt===t||this.ws.clear();const s=[];return this.Pt===t&&s.push(this.Ns(this.ws,i,this.Ts)),s}ds(){return this.vs?[this.Fs]:[]}Us(){return this.Pt}zs(){this.ss.qs().forEach(t=>{this.bs.get(t)?.Tt(),this.Ms.get(t)?.Tt()}),this.ws.forEach(t=>t.Tt()),this.Fs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}Os(t,i,s){this.Ys(t,i,s)&&this.zs()}Ys(t,i,s){const n=this.ys,e=this.Ss,r=this.ps,h=this.fs,l=this.Pt,o=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.At().jt(t),this.Pt=s;const a=null!==o?o.Ot():null;return null!==o&&null!==a?(this.ps=i,this.Ss=o.zt(i,a)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||h!==this.fs||r!==this.ps||l!==this.Pt}Ws(){const t=this.ss.Xs().map(t=>t.Ks().Gs()).filter(v),i=0===t.length?null:Math.max(...t);this.fs=null!==i?i:NaN}Ns(t,i,s){let n=t.get(i);return void 0===n&&(n=new W(this,i,s),t.set(i,n)),n}}function j(t){return"left"===t||"right"===t}class Y{constructor(t){this.Zs=new Map,this.Js=[],this.Qs=t}tn(t,i){const s=function(t,i){return void 0===t?i:{sn:Math.max(t.sn,i.sn),nn:t.nn||i.nn}}(this.Zs.get(t),i);this.Zs.set(t,s)}en(){return this.Qs}rn(t){const i=this.Zs.get(t);return void 0===i?{sn:this.Qs}:{sn:Math.max(this.Qs,i.sn),nn:i.nn}}hn(){this.ln(),this.Js=[{an:0}]}_n(t){this.ln(),this.Js=[{an:1,Ht:t}]}un(t){this.cn(),this.Js.push({an:5,Ht:t})}ln(){this.cn(),this.Js.push({an:6})}dn(){this.ln(),this.Js=[{an:4}]}pn(t){this.ln(),this.Js.push({an:2,Ht:t})}fn(t){this.ln(),this.Js.push({an:3,Ht:t})}vn(){return this.Js}mn(t){for(const i of t.Js)this.wn(i);this.Qs=Math.max(this.Qs,t.Qs),t.Zs.forEach((t,i)=>{this.tn(i,t)})}static gn(){return new Y(2)}static bn(){return new Y(3)}wn(t){switch(t.an){case 0:this.hn();break;case 1:this._n(t.Ht);break;case 2:this.pn(t.Ht);break;case 3:this.fn(t.Ht);break;case 4:this.dn();break;case 5:this.un(t.Ht);break;case 6:this.cn()}}cn(){const t=this.Js.findIndex(t=>5===t.an);-1!==t&&this.Js.splice(t,1)}}class X{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function K(t,i){if(!u(t))return"n/a";if(!c(i))throw new TypeError("invalid length");if(i<0||i>16)throw new TypeError("invalid length");if(0===i)return t.toString();return("0000000000000000"+t.toString()).slice(-i)}class Z extends X{constructor(t,i){if(super(),i||(i=1),u(t)&&c(t)||(t=100),t<0)throw new TypeError("invalid base");this.Yi=t,this.Mn=i,this.yn()}format(t){const i=t<0?"−":"";return t=Math.abs(t),i+this.Sn(t)}yn(){if(this.xn=0,this.Yi>0&&this.Mn>0){let t=this.Yi;for(;t>1;)t/=10,this.xn++}}Sn(t){const i=this.Yi/this.Mn;let s=Math.floor(t),n="";const e=void 0!==this.xn?this.xn:NaN;if(i>1){let r=+(Math.round(t*i)-s*i).toFixed(this.xn);r>=i&&(r-=i,s+=1),n=G+K(+r.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+K(0,e));return s.toFixed(0)+n}}class J extends Z{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Q extends X{constructor(t){super(),this.Cn=t}format(t){let i="";return t<0&&(i="-",t=-t),t<995?i+this.Pn(t):t<999995?i+this.Pn(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),i+this.Pn(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),i+this.Pn(t/1e9)+"B")}Pn(t){let i;const s=Math.pow(10,this.Cn);return i=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.Cn).replace(/\.?0+$/,""):String(t),i.replace(/(\.[1-9]*)0+$/,(t,i)=>i)}}const tt=/[2-9]/g;class it{constructor(t=50){this.Tn=0,this.kn=1,this.Dn=1,this.Rn={},this.Fn=new Map,this.Vn=t}In(){this.Tn=0,this.Fn.clear(),this.kn=1,this.Dn=1,this.Rn={}}Vi(t,i,s){return this.Ln(t,i,s).width}Fi(t,i,s){const n=this.Ln(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}Ln(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Fn.has(e))return h(this.Fn.get(e)).An;if(this.Tn===this.Vn){const t=this.Rn[this.Dn];delete this.Rn[this.Dn],this.Fn.delete(t),this.Dn++,this.Tn--}t.save(),t.textBaseline="middle";const r=t.measureText(e);return t.restore(),0===r.width&&i.length||(this.Fn.set(e,{An:r,Bn:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.On=null,this.M=null,this.En="right",this.Wn=t}zn(t,i,s){this.On=t,this.M=i,this.En=s}et(t){null!==this.M&&null!==this.On&&this.On.et(t,this.M,this.Wn,this.En)}}class nt{constructor(t,i,s){this.$n=t,this.Wn=new it(50),this.Hn=i,this.O=s,this.$=-1,this.Jt=new st(this.Wn)}Dt(){const t=this.O.Nn(this.Hn);if(null===t)return null;const i=t.Un(this.Hn)?t.qn():this.Hn.$t();if(null===i)return null;const s=t.jn(i);if("overlay"===s)return null;const n=this.O.Yn();return n.P!==this.$&&(this.$=n.P,this.Wn.In()),this.Jt.zn(this.$n.qi(),n,s),this.Jt}}class et extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}Xn(t,i){if(!this.Yt?.Vt)return null;const{ct:s,dt:n,Gn:e}=this.Yt;return i>=s-n-7&&i<=s+n+7?{Kn:this.Yt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;if(!1===this.Yt.Vt)return;const h=Math.round(this.Yt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.R,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Kt),e(t,h,0,i.width))}}class rt{constructor(t){this.Zn={ct:0,R:"rgba(0, 0, 0, 0)",dt:1,Kt:0,Vt:!1},this.Jn=new et,this.xt=!0,this.Qn=t,this.te=t.ti(),this.Jn.lt(this.Zn)}Tt(){this.xt=!0}Dt(){return this.Qn.Vt()?(this.xt&&(this.ie(),this.xt=!1),this.Jn):null}}class ht extends rt{constructor(t){super(t)}ie(){this.Zn.Vt=!1;const t=this.Qn.$t(),i=t.se().se;if(2!==i&&3!==i)return;const s=this.Qn.W();if(!s.baseLineVisible||!this.Qn.Vt())return;const n=this.Qn.Ot();null!==n&&(this.Zn.Vt=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.R=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Kt=s.baseLineStyle)}}class lt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ne(){return this.Yt}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.Yt;if(null===n)return;const e=Math.max(1,Math.floor(i)),r=e%2/2,h=Math.round(n.ee.x*i)+r,l=n.ee.y*s;t.fillStyle=n.re,t.beginPath();const o=Math.max(2,1.5*n.he)*i;t.arc(h,l,o,0,2*Math.PI,!1),t.fill(),t.fillStyle=n.le,t.beginPath(),t.arc(h,l,n.vt*i,0,2*Math.PI,!1),t.fill(),t.lineWidth=e,t.strokeStyle=n.oe,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const ot=[{ae:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{ae:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{ae:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class at{constructor(t){this.Jt=new lt,this.xt=!0,this.me=!0,this.we=performance.now(),this.ge=this.we-1,this.be=t}Me(){this.ge=this.we-1,this.Tt()}ye(){if(this.Tt(),2===this.be.W().lastPriceAnimation){const t=performance.now(),i=this.ge-t;if(i>0)return void(i<650&&(this.ge+=2600));this.we=t,this.ge=t+2600}}Tt(){this.xt=!0}Se(){this.me=!0}Vt(){return 0!==this.be.W().lastPriceAnimation}xe(){switch(this.be.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.ge}}Dt(){return this.xt?(this.Rt(),this.xt=!1,this.me=!1):this.me&&(this.Ce(),this.me=!1),this.Jt}Rt(){this.Jt.lt(null);const t=this.be.ti().At(),i=t.Pe(),s=this.be.Ot();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Re))return;const e={x:t.jt(n.Re),y:this.be.$t().zt(n.bt,s.Ht)},r=n.R,h=this.be.W().lineWidth,l=this.Fe(this.Ve(),r);this.Jt.lt({re:r,he:h,le:l.le,oe:l.oe,vt:l.vt,ee:e})}Ce(){const t=this.Jt.ne();if(null!==t){const i=this.Fe(this.Ve(),t.re);t.le=i.le,t.oe=i.oe,t.vt=i.vt}}Ve(){return this.xe()?performance.now()-this.we:2599}Ie(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Ki().X(t,e)}Fe(t,i){const s=t%2600/2600;let n;for(const t of ot)if(s>=t.ae&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.ae)/(n._e-n.ae);return{le:this.Ie(i,e,n.de,n.pe),oe:this.Ie(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,o=n.ce,l+(o-l)*h)};var h,l,o}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.Vt=!1;const i=this.Qn.W();if(!i.priceLineVisible||!this.Qn.Vt())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.Vt=!0,t.ct=s.Li,t.R=this.Qn.Le(s.R),t.dt=i.priceLineWidth,t.Kt=i.priceLineStyle)}}class ut extends E{constructor(t){super(),this.Qt=t}ji(t,i,s){t.Vt=!1,i.Vt=!1;const n=this.Qt;if(!n.Vt())return;const e=n.W(),r=e.lastValueVisible,h=""!==n.Ae(),l=0===e.seriesLastValueMode,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Be(o,r,l),t.Vt=0!==t.hi.length),(h||l)&&(i.hi=this.Oe(o,r,h,l),i.Vt=i.hi.length>0);const a=n.Le(o.R),_=this.Qt.ti().Ki().K(a);s.Z=_.Z,s.Li=o.Li,i.Nt=n.ti().Ut(o.Li/n.$t().qt()),t.Nt=a,t.R=_.J,i.R=_.J}Oe(t,i,s,n){let e="";const r=this.Qt.Ae();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Ee()?t.We:t.ze),e.trim()}Be(t,i,s){return i?s?this.Qt.$t().Ee()?t.ze:t.We:t.hi:""}}function ct(t,i,s,n){const e=Number.isFinite(i),r=Number.isFinite(s);return e&&r?t(i,s):e||r?e?i:s:n}class dt{constructor(t,i){this.$e=t,this.He=i}Ne(t){return null!==t&&(this.$e===t.$e&&this.He===t.He)}Ue(){return new dt(this.$e,this.He)}qe(){return this.$e}je(){return this.He}Ye(){return this.He-this.$e}Gi(){return this.He===this.$e||Number.isNaN(this.He)||Number.isNaN(this.$e)}mn(t){return null===t?this:new dt(ct(Math.min,this.qe(),t.qe(),-1/0),ct(Math.max,this.je(),t.je(),1/0))}Xe(t){if(!u(t))return;if(0===this.He-this.$e)return;const i=.5*(this.He+this.$e);let s=this.He-i,n=this.$e-i;s*=t,n*=t,this.He=i+s,this.$e=i+n}Ge(t){u(t)&&(this.He+=t,this.$e+=t)}Ke(){return{minValue:this.$e,maxValue:this.He}}static Ze(t){return null===t?null:new dt(t.minValue,t.maxValue)}}class pt{constructor(t,i){this.Je=t,this.Qe=i||null}tr(){return this.Je}ir(){return this.Qe}Ke(){return{priceRange:null===this.Je?null:this.Je.Ke(),margins:this.Qe||void 0}}static Ze(t){return null===t?null:new pt(dt.Ze(t.priceRange),t.margins)}}class ft extends rt{constructor(t,i){super(t),this.sr=i}ie(){const t=this.Zn;t.Vt=!1;const i=this.sr.W();if(!this.Qn.Vt()||!i.lineVisible)return;const s=this.sr.nr();null!==s&&(t.Vt=!0,t.ct=s,t.R=i.color,t.dt=i.lineWidth,t.Kt=i.lineStyle,t.Gn=this.sr.W().id)}}class vt extends E{constructor(t,i){super(),this.be=t,this.sr=i}ji(t,i,s){t.Vt=!1,i.Vt=!1;const n=this.sr.W(),e=n.axisLabelVisible,r=""!==n.title,h=this.be;if(!e||!h.Vt())return;const l=this.sr.nr();if(null===l)return;r&&(i.hi=n.title,i.Vt=!0),i.Nt=h.ti().Ut(l/h.$t().qt()),t.hi=this.er(n.price),t.Vt=!0;const o=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.R=a,i.R=a,s.Li=l}er(t){const i=this.be.Ot();return null===i?"":this.be.$t().Zi(t,i.Ht)}}class mt{constructor(t,i){this.be=t,this.Ps=i,this.rr=new ft(t,this),this.$n=new vt(t,this),this.hr=new nt(this.$n,t,t.ti())}lr(t){_(this.Ps,t),this.Tt(),this.be.ti().ar()}W(){return this.Ps}_r(){return this.rr}ur(){return this.hr}cr(){return this.$n}Tt(){this.rr.Tt(),this.$n.Tt()}nr(){const t=this.be,i=t.$t();if(t.ti().At().Gi()||i.Gi())return null;const s=t.Ot();return null===s?null:i.zt(this.Ps.price,s.Ht)}}class wt extends N{constructor(t){super(),this.ss=t}ti(){return this.ss}}const gt={Bar:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=l(t(s,n)),a=o(h.Ht[0])<=o(h.Ht[3]);return{dr:h.R??(a?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,a=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=o(c.Ht[0])<=o(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:a),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}Vr(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Ir=[],this.Lr=new Map,this.Ar=new Map,this.Br=[]}Or(){return this.Er()>0?this.Ir[this.Ir.length-1]:null}Wr(){return this.Er()>0?this.zr(0):null}Gs(){return this.Er()>0?this.zr(this.Ir.length-1):null}Er(){return this.Ir.length}Gi(){return 0===this.Er()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Ir}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Ar.clear(),this.Lr.clear(),this.Ir=t,this.Br=t.map(t=>t.Re)}Yr(){return this.Br}zr(t){return this.Ir[t].Re}Nr(t){return this.Ir[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Ir.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Ir.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Ir.length||t<this.Ir[i].Re?null:i}Zr(t){return yt(this.Ir,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Ir,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Ir[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(o,a,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Lr.get(s);void 0===u&&(u=new Map,this.Lr.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(o);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.ah=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.ah?.rh===t)return this.ah.hh;const i=t.map(t=>new Rt(t));return this.ah={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let Vt=class extends Ft{cs(){return[]}};class It{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new It(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}function At(t){return{hi:t.text(),Li:t.coordinate(),Ii:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),Vt:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Bt{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...At(this.dh)}),this.Jt}}class Ot extends E{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=At(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Li=n.Li,void 0!==n.Ii&&(s.Ii=n.Ii),t.hi=n.hi,t.Vt=n.Vt,t.mi=n.mi}}class Et extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().At(),s=t.map(t=>new Bt(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Ot(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new Lt(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new Lt(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.oh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new at(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().At().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().At().Pe(),e=this.Ot();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Or();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Fh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Vh(l),ze:s.Ih(l,e.Ht),R:o.dr,Li:a,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Lh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Ah()),this.ti().Bh(this),this.ti().Oh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Eh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Bh(this),this.ti().Oh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Bh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Bh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Ot(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.Vt()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Bt(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ol(),Nt:this.al(),Wt:this._l(),Et:this.ul(t)}}Ae(){return this.Ps.title}Vt(){return this.Ps.visible}cl(t){this.kh.push(new Et(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Ot();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.Vt())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=o(n.Ot()),a=3===this.Ps.mode?jt:qt;return t.concat(a.map(t=>e.zt(h.Ht[t],l.Ht)))},[]);if(0===l.length)return n;l.sort((t,i)=>Math.abs(t-h)-Math.abs(i-h));const a=l[0];return n=e.Ds(a,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Vl(),Pl:(this.Pt.ti().At().Vl()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Il:4,Ll:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Ll)+i.Il;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Il)-i.Ll;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.je(),i);return new dt(s,n)}function ai(t){if(null===t)return ti;const i=Math.abs(t.je()-t.qe());if(i>=1||i<1e-15)return ti;const s=Math.ceil(Math.abs(Math.log10(i))),n=ti.Il+s;return{Il:n,Ll:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Al=t,this.Bl=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Al))this.Ol=[2,2.5,2];else{this.Ol=[];for(let t=this.Al;1!==t;){if(t%2==0)this.Ol.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Ol.push(2,2.5),t/=5}if(this.Ol.length>100)throw new Error("something wrong with base")}}}El(t,i,s){const n=0===this.Al?0:1/this.Al;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.Bl[0];for(;;){const t=Gt(e,n,1e-14)&&e>n+1e-14,i=Gt(e,s*h,1e-14),l=Gt(e,1,1e-14);if(!(t&&i&&l))break;e/=h,h=this.Bl[++r%this.Bl.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Ol.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Ol[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Ol[++r%this.Ol.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Al=i,this.zl=s,this.$l=n}El(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Al,[2,2.5,2]),r=new _i(this.Al,[2,2,2.5]),h=new _i(this.Al,[2.5,2,2]),l=[];return l.push(e.El(t,i,n),r.El(t,i,n),h.El(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Ot();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Wl=[]);const _=this.El(o,a);if(this.ql(i,_,o,a,h,l),t.jl()&&this.Yl(_,a,o)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Vl(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.max(1,Math.ceil(this.Ul()*this.Yi.W().tickMarkSpacing))}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.io()&&(i=this.El(c*a,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.so(t,s,e,r),o=this.so(t,n,-r,-e),a=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<a/2&&h.shift(),h.length>0&&o.Tl-h[h.length-1].Tl<a/2&&h.pop(),h.unshift(l),h.push(o)}so(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.El(o,l)),_=this.zl(i+e,t),u=_-_%a,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=o(this.Yi.tr());return this.Yi.io()&&(n=oi(n,this.Yi.no())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.eo=0,this.ro=null,this.Je=null,this.ho=null,this.lo={oo:!1,ao:null},this._o=!1,this.uo=0,this.co=0,this.do=new a,this.po=new a,this.fo=[],this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.Mo=null,this.ll=fi,this.yo=ai(null),this.So=t,this.Ps=i,this.xo=s,this.Co=n,this.Po=e,this.To=new ui(this,100,this.ko.bind(this),this.Do.bind(this))}gl(){return this.So}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.Ro({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Fo(),this.wo=null}void 0!==t.tickMarkSpacing&&(this.wo=null)}Vo(){return this.Ps.autoScale}Io(){return this._o}io(){return 1===this.Ps.mode}Ee(){return 2===this.Ps.mode}Lo(){return 3===this.Ps.mode}no(){return this.yo}se(){return{nn:this.Ps.autoScale,Ao:this.Ps.invertScale,se:this.Ps.mode}}Ro(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.lo.oo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.yo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.yo),null!==s&&this.Bo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Bo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Ee())&&this.bl(),n&&(3===i.se||this.Lo())&&this.bl(),void 0!==t.Ao&&i.Ao!==t.Ao&&(this.Ps.invertScale=t.Ao,this.Oo()),this.po.p(i,this.se())}Eo(){return this.po}P(){return this.xo.fontSize}qt(){return this.eo}Wo(t){this.eo!==t&&(this.eo=t,this.Fo(),this.wo=null)}zo(){if(this.ro)return this.ro;const t=this.qt()-this.$o()-this.Ho();return this.ro=t,t}tr(){return this.No(),this.Je}Bo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.wo=null,this.Je=t)}Uo(t){this.Bo(t),this.qo(null!==t)}Gi(){return this.No(),0===this.eo||!this.Je||this.Je.Gi()}jo(t){return this.Ao()?t:this.qt()-1-t}zt(t,i){return this.Ee()?t=ii(t,i):this.Lo()&&(t=ni(t,i)),this.Do(t,i)}Yo(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.eo-1-o;e.ct=u}}Go(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,o=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),o=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=a?c:this.eo-1-c;e.Ko=p,c=n+_*(l-r),p=a?c:this.eo-1-c,e.Zo=p,c=n+_*(o-r),p=a?c:this.eo-1-c,e.Jo=p,c=n+_*(u-r),p=a?c:this.eo-1-c,e.Qo=p}}Ds(t,i){const s=this.ko(t,i);return this.ta(s,i)}ta(t,i){let s=t;return this.Ee()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Lo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.fo}Ft(){return this.mo||(this.mo=ci(this.fo)),this.mo}ia(t){-1===this.fo.indexOf(t)&&(this.fo.push(t),this.bl(),this.sa())}na(t){const i=this.fo.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.fo.splice(i,1),0===this.fo.length&&(this.Ro({nn:!0}),this.Bo(null)),this.bl(),this.sa()}Ot(){let t=null;for(const i of this.fo){const s=i.Ot();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Ao(){return this.Ps.invertScale}Vl(){const t=null===this.Ot();if(null!==this.wo&&(t||this.wo.ea===t))return this.wo.Vl;this.To.Nl();const i=this.To.Vl();return this.wo={Vl:i,ea:t},this.do.p(),i}ra(){return this.do}ha(t){this.Ee()||this.Lo()||null===this.bo&&null===this.ho&&(this.Gi()||(this.bo=this.eo-t,this.ho=l(this.tr()).Ue()))}la(t){if(this.Ee()||this.Lo())return;if(null===this.bo)return;this.Ro({nn:!1}),(t=this.eo-t)<0&&(t=0);let i=(this.bo+.2*(this.eo-1))/(t+.2*(this.eo-1));const s=l(this.ho).Ue();i=Math.max(i,.1),s.Xe(i),this.Bo(s)}oa(){this.Ee()||this.Lo()||(this.bo=null,this.ho=null)}aa(t){this.Vo()||null===this.Mo&&null===this.ho&&(this.Gi()||(this.Mo=t,this.ho=l(this.tr()).Ue()))}_a(t){if(this.Vo())return;if(null===this.Mo)return;const i=l(this.tr()).Ye()/(this.zo()-1);let s=t-this.Mo;this.Ao()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Bo(e,!0),this.wo=null}ua(){this.Vo()||null!==this.Mo&&(this.Mo=null,this.ho=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.ca(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.da(t);case 3:return this.hl().formatTickmarks(t);default:return this.pa(t)}}Vh(t){return this.er(t,l(this.vo).hl())}Ih(t,i){return t=ii(t,i),this.ca(t,pi)}fa(){return this.fo}va(t){this.lo={ao:t,oo:!1}}zs(){this.fo.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Vo()}Xl(){return this.P()/2}bl(){this.wo=null;let t=1/0;this.vo=null;for(const i of this.fo)i.ls()<t&&(t=i.ls(),this.vo=i);let i=100;null!==this.vo&&(i=Math.round(this.vo.rh())),this.ll=fi,this.Ee()?(this.ll=pi,i=100):this.Lo()?(this.ll=new Z(100,1),i=100):null!==this.vo&&(this.ll=this.vo.hl()),this.To=new ui(this,i,this.ko.bind(this),this.Do.bind(this)),this.To.Nl()}sa(){this.mo=null}ma(){return null===this.vo||this.Ee()||this.Lo()?1:1/this.vo.rh()}Ki(){return this.Po}qo(t){this._o=t}$o(){return this.Ao()?this.Ps.scaleMargins.bottom*this.qt()+this.co:this.Ps.scaleMargins.top*this.qt()+this.uo}Ho(){return this.Ao()?this.Ps.scaleMargins.top*this.qt()+this.uo:this.Ps.scaleMargins.bottom*this.qt()+this.co}No(){this.lo.oo||(this.lo.oo=!0,this.wa())}Fo(){this.ro=null}Do(t,i){if(this.No(),this.Gi())return 0;t=this.io()&&t?ri(t,this.yo):t;const s=l(this.tr()),n=this.Ho()+(this.zo()-1)*(t-s.qe())/s.Ye();return this.jo(n)}ko(t,i){if(this.No(),this.Gi())return 0;const s=this.jo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.Ho())/(this.zo()-1));return this.io()?hi(e,this.yo):e}Oo(){this.wo=null,this.To.Nl()}wa(){if(this.Io()&&!this.Vo())return;const t=this.lo.ao;if(null===t)return;let i=null;const s=this.fa();let n=0,e=0;for(const r of s){if(!r.Vt())continue;const s=r.Ot();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.yo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this.uo&&e===this.co||(this.uo=n,this.co=e,this.wo=null,this.Fo()),null!==i){const t=this.io(),s=t?oi(i,this.yo):i,n=this.Ee()||this.Lo()?0:10*this.ma();if(s.qe()===s.je()||s.Ye()<n){const e=Math.max(5*this.ma(),n/2),r=(s.qe()+s.je())/2,h=new dt(r-e,r+e);i=t?li(h,this.yo):h}if(this.io()){const t=oi(i,this.yo),s=ai(t);if(r=s,h=this.yo,r.Il!==h.Il||r.Ll!==h.Ll){const n=null!==this.ho?oi(this.ho,this.yo):null;this.yo=s,i=li(t,s),null!==n&&(this.ho=li(n,s))}}this.Bo(i)}else null===this.Je&&(this.Bo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Ee()?ii:this.Lo()?ni:this.io()?t=>ri(t,this.yo):null}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}ba(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.ga(t,this.Co.priceFormatter,i)}pa(t,i){const s=this.Co.priceFormatter;return this.ba(t,this.Co.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ca(t,i){return this.ga(t,this.Co.percentageFormatter,i)}da(t,i){const s=this.Co.percentageFormatter;return this.ba(t,this.Co.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.fo=[],this.Ma=new Map,this.eo=0,this.ya=0,this.Sa=1,this.mo=null,this.xa=!1,this.Ca=new a,this.kh=[],this.ph=t,this.ss=i,this.Pa=new Qt(this);const s=i.W();this.Ta=this.ka("left",s.leftPriceScale),this.Da=this.ka("right",s.rightPriceScale),this.Ta.Eo().i(this.Ra.bind(this,this.Ta),this),this.Da.Eo().i(this.Ra.bind(this,this.Da),this),this.Fa(s)}Fa(t){if(t.leftPriceScale&&this.Ta.lr(t.leftPriceScale),t.rightPriceScale&&this.Da.lr(t.rightPriceScale),t.localization&&(this.Ta.bl(),this.Da.bl()),t.overlayPriceScales){const i=Array.from(this.Ma.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Va(t){switch(t){case"left":return this.Ta;case"right":return this.Da}return this.Ma.has(t)?h(this.Ma.get(t))[0].$t():null}m(){this.ti().Ia().u(this),this.Ta.Eo().u(this),this.Da.Eo().u(this),this.fo.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Ca.p()}La(){return this.Sa}Aa(t){this.Sa=t}ti(){return this.ss}ts(){return this.ya}qt(){return this.eo}Ba(t){this.ya=t,this.Oa()}Wo(t){this.eo=t,this.Ta.Wo(t),this.Da.Wo(t),this.fo.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Wo(t)}}),this.Oa()}Ea(t){this.xa=t}Wa(){return this.xa}za(){return this.fo.filter(mi)}yl(){return this.fo}Un(t){const i=t.$t();return null===i||this.Ta!==i&&this.Da!==i}ia(t,i,s){this.$a(t,i,s?t.ls():this.fo.length)}na(t,i){const s=this.fo.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.fo.splice(s,1),i||this.fo.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Ma.has(n)){const i=h(this.Ma.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Ma.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.na(t),this.Ha(e)),this.mo=null}jn(t){return t===this.Ta?"left":t===this.Da?"right":"overlay"}Na(){return this.Ta}Ua(){return this.Da}qa(t,i){t.ha(i)}ja(t,i){t.la(i),this.Oa()}Ya(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Oa()}Ka(t){t.ua()}Oa(){this.fo.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Da.yl().length?t=this.Da:this.ss.W().leftPriceScale.visible&&0!==this.Ta.yl().length?t=this.Ta:0!==this.fo.length&&(t=this.fo[0].$t()),null===t&&(t=this.Da),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Da:this.ss.W().leftPriceScale.visible&&(t=this.Ta),t}Ha(t){null!==t&&t.Vo()&&this.Za(t)}Ja(t){const i=this.ph.Pe();t.Ro({nn:!0}),null!==i&&t.va(i),this.Oa()}Qa(){this.Za(this.Ta),this.Za(this.Da)}t_(){this.Ha(this.Ta),this.Ha(this.Da),this.fo.forEach(t=>{this.Un(t)&&this.Ha(t.$t())}),this.Oa(),this.ss.ar()}Ft(){return null===this.mo&&(this.mo=ci(this.fo)),this.mo}i_(t,i){i=Xt(i,0,this.fo.length-1);const s=this.fo.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.fo.splice(s,1),this.fo.splice(i,0,t),this.fo.forEach((t,i)=>t._s(i)),this.mo=null;for(const t of[this.Ta,this.Da])t.sa(),t.bl();this.ss.ar()}It(){return this.Ft().filter(mi)}s_(){return this.Ca}n_(){return this.Pa}cl(t){this.kh.push(new Vt(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Za(t){const i=t.fa();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.va(i)}t.zs()}$a(t,i,s){let n=this.Va(i);if(null===n&&(n=this.ka(i,this.ss.W().overlayPriceScales)),this.fo.splice(s,0,t),!j(i)){const s=this.Ma.get(i)||[];s.push(t),this.Ma.set(i,s)}t._s(s),n.ia(t),t.us(n),this.Ha(n),this.mo=null}Ra(t,i,s){i.se!==s.se&&this.Za(t)}ka(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Wo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},o_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{a_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,a_:n.a_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.Vn=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.Vn){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,Bn:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(){this.Fn=null}M_(t,i){this.y_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}S_(t,i,s,n,e,r=()=>!0){const h=Math.ceil(i/t);return null!==this.Fn&&this.Fn.x_===h&&e===this.Fn.C_&&s===this.Fn.P_||(this.Fn={C_:e,P_:s,Vl:this.T_(h,s,n,r),x_:h}),this.Fn.Vl}y_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}T_(t,i,s,n){let e=[];const r=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=e;e=[];const l=s.length;let o=0;const a=h(this.m_.get(i)),_=a.length;let u=1/0,c=-1/0;for(let i=0;i<_;i++){const h=a[i];if(!n(h,t))continue;const _=h.index;for(;o<l;){const t=s[o],i=t.index;if(!(i<_&&r(t))){u=i;break}o++,e.push(t),c=i,u=1/0}if(u-_>=t&&_-c>=t&&r(h))e.push(h),c=_;else if(this.w_)return s}for(;o<l;o++)r(s[o])&&e.push(s[o])}return e}}class ki{constructor(t){this.k_=t}D_(){return null===this.k_?null:new Ci(Math.floor(this.k_.qh()),Math.ceil(this.k_.yi()))}R_(){return this.k_}static F_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.ya=0,this.V_=null,this.I_=[],this.Mo=null,this.bo=null,this.L_=new Ti,this.A_=new Map,this.B_=ki.F_(),this.O_=!0,this.E_=new a,this.W_=new a,this.z_=new a,this.H_=null,this.N_=null,this.U_=new Map,this.q_=-1,this.j_=[],this.Ps=i,this.Co=s,this.Y_=i.rightOffset,this.X_=i.barSpacing,this.ss=t,this.G_(i),this.u_=n,this.K_(),this.L_.g_(i.uniformDistribution),this.Z_()}W(){return this.Ps}J_(t){_(this.Co,t),this.Q_(),this.K_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.tu(),this.Ps.fixRightEdge&&this.iu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.G_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.X_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.Z_(),this.Q_(),this.K_(),this.z_.p()}Rs(t){return this.I_[t]?.time??null}ns(t){return this.I_[t]??null}su(t,i){if(this.I_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.I_[this.I_.length-1].time))return i?this.I_.length-1:null;const s=yt(this.I_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.I_[s].time)?i?s:null:s}Gi(){return 0===this.ya||0===this.I_.length||null===this.V_}nu(){return this.I_.length>0}Pe(){return this.eu(),this.B_.D_()}ru(){return this.eu(),this.B_.R_()}hu(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.lu(i)}lu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.ou()),e=l(this.au());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}_u(t){return{from:l(this.su(t.from,!0)),to:l(this.su(t.to,!0))}}ts(){return this.ya}Ba(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.ru(),s=this.ya;if(this.ya=t,this.O_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.X_*t/s;this.X_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.Y_-=Math.round(i/this.X_)+1,this.O_=!0}this.uu(),this.cu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.du()+this.Y_-t;return this.ya-(i+.5)*this.X_-1}pu(t,i){const s=this.du(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.Y_-n,r=this.ya-(e+.5)*this.X_-1;t[i].ut=r}}fu(t,i){const s=Math.ceil(this.vu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.mu(s)?this.wu(s):s}fn(t){this.O_=!0,this.Y_=t,this.cu(),this.ss.gu(),this.ss.ar()}bu(){return this.X_}pn(t){const i=this.X_;if(this.Mu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.Y_*i/this.X_;this.Y_=t}this.cu(),this.ss.gu(),this.ss.ar()}yu(){return this.Y_}Vl(){if(this.Gi())return null;if(null!==this.N_)return this.N_;const t=this.X_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.L_.S_(t,i,this.Ps.ignoreWhitespaceIndices,this.U_,this.q_,(t,i)=>this.u_.allowsTickMark?.(t,i)??!0),o=this.ou()+s,a=this.au()-s,_=this.Su(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.j_.length?(s=this.j_[d],s.coord=this.jt(t.index),s.label=this.xu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.xu(t),weight:t.weight},this.j_.push(s)),this.X_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.j_.length=d,this.N_=this.j_,this.j_}Cu(){let t;this.O_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.bu():this.Ps.rightOffset,this.fn(t)}Pu(t){this.O_=!0,this.V_=t,this.cu(),this.tu()}Tu(t,i){const s=this.vu(t),n=this.bu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.yu()+(s-this.vu(t)))}ha(t){this.Mo&&this.ua(),null===this.bo&&null===this.H_&&(this.Gi()||(this.bo=t,this.ku()))}la(t){if(null===this.H_)return;const i=Xt(this.ya-t,0,this.ya),s=Xt(this.ya-l(this.bo),0,this.ya);0!==i&&0!==s&&this.pn(this.H_.bu*i/s)}oa(){null!==this.bo&&(this.bo=null,this.Du())}aa(t){null===this.Mo&&null===this.H_&&(this.Gi()||(this.Mo=t,this.ku()))}_a(t){if(null===this.Mo)return;const i=(this.Mo-t)/this.bu();this.Y_=l(this.H_).yu+i,this.O_=!0,this.cu()}ua(){null!==this.Mo&&(this.Mo=null,this.Du())}Ru(){this.Fu(this.Ps.rightOffset)}Fu(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.Y_,n=performance.now();this.ss.un({Vu:t=>(t-n)/i>=1,Iu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.O_=!0,this.I_=t,this.L_.M_(t,i),this.cu()}Lu(){return this.E_}Au(){return this.W_}Bu(){return this.z_}du(){return this.V_||0}Ou(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.Mu((this.ya-n)/s),this.Y_=t.yi()-this.du(),i&&(this.Y_=n?n/this.bu():this.Ps.rightOffset),this.cu(),this.O_=!0,this.ss.gu(),this.ss.ar()}Eu(){const t=this.ou(),i=this.au();null!==t&&null!==i&&this.Ou(new Ci(t,i),!0)}Wu(t){const i=new Ci(t.from,t.to);this.Ou(i)}es(t){return void 0!==this.Co.timeFormatter?this.Co.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}Z_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.U_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.U_.set(t,!0);this.q_++}Su(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}ou(){return 0===this.I_.length?null:0}au(){return 0===this.I_.length?null:this.I_.length-1}zu(t){return(this.ya-1-t)/this.X_}vu(t){const i=this.zu(t),s=this.du()+this.Y_-i;return Math.round(1e6*s)/1e6}Mu(t){const i=this.X_;this.X_=t,this.uu(),i!==this.X_&&(this.O_=!0,this.$u())}eu(){if(!this.O_)return;if(this.O_=!1,this.Gi())return void this.Hu(ki.F_());const t=this.du(),i=this.ya/this.X_,s=this.Y_+t,n=new Ci(s-i+1,s);this.Hu(new ki(n))}uu(){const t=Xt(this.X_,this.Nu(),this.Uu());this.X_!==t&&(this.X_=t,this.O_=!0)}Uu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.ya}Nu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.I_.length?this.ya/this.I_.length:this.Ps.minBarSpacing}cu(){const t=this.qu();null!==t&&this.Y_<t&&(this.Y_=t,this.O_=!0);const i=this.ju();this.Y_>i&&(this.Y_=i,this.O_=!0)}qu(){const t=this.ou(),i=this.V_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.ya/this.X_:Math.min(2,this.I_.length))}ju(){return this.Ps.fixRightEdge?0:this.ya/this.X_-Math.min(2,this.I_.length)}ku(){this.H_={bu:this.bu(),yu:this.yu()}}Du(){this.H_=null}xu(t){let i=this.A_.get(t.weight);return void 0===i&&(i=new xi(t=>this.Yu(t),this.u_),this.A_.set(t.weight,i)),i.c_(t)}Yu(t){return this.u_.formatTickmark(t,this.Co)}Hu(t){const i=this.B_;this.B_=t,Pi(i.D_(),this.B_.D_())||this.E_.p(),Pi(i.R_(),this.B_.R_())||this.W_.p(),this.$u()}$u(){this.N_=null}Q_(){this.$u(),this.A_.clear(),this.L_.b_()}K_(){this.u_.updateFormatter(this.Co)}tu(){if(!this.Ps.fixLeftEdge)return;const t=this.ou();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.Y_-s-1;this.fn(t)}this.uu()}iu(){this.cu(),this.uu()}mu(t){return!this.Ps.ignoreWhitespaceIndices||(this.U_.get(t)||!1)}wu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.au();for(;s;){const t=i.next().value;if(this.U_.get(t))return t;if(t<0||t>s)break}return t}G_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.X_);this.ss.fn(i)}}}var Fi,Vi,Ii,Li,Ai;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Bi{constructor(t,i,s){this.Xu=[],this.Gu=[],this.ya=0,this.Ku=null,this.Zu=new a,this.Ju=new a,this.Qu=null,this.tc=t,this.Ps=i,this.u_=s,this.Po=new S(this.Ps.layout.colorParsers),this.sc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.nc=new Yt(i.crosshair),i.addDefaultPane&&(this.ec(0),this.Xu[0].Aa(2)),this.rc=this.hc(0),this.lc=this.hc(1)}Ah(){this.oc(Y.bn())}ar(){this.oc(Y.gn())}Jh(){this.oc(new Y(1))}Bh(t){const i=this.ac(t);this.oc(i)}_c(){return this.Ku}uc(t){if(this.Ku?.r_===t?.r_&&this.Ku?.h_?.Gn===t?.h_?.Gn)return;const i=this.Ku;this.Ku=t,null!==i&&this.Bh(i.r_),null!==t&&t.r_!==i?.r_&&this.Bh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Xu.forEach(i=>i.Fa(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.J_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Zu.p(),this.rc=this.hc(0),this.lc=this.hc(1),this.Ah()}cc(t,i,s=0){const n=this.Xu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fa({leftPriceScale:i}),this.Zu.p(),void this.Ah();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fa({rightPriceScale:i}),this.Zu.p(),void this.Ah();const e=this.dc(t,s);null!==e&&(e.$t.lr(i),this.Zu.p())}dc(t,i){const s=this.Xu[i];if(void 0===s)return null;const n=s.Va(t);return null!==n?{Us:s,$t:n}:null}At(){return this.ph}qs(){return this.Xu}fc(){return this.Ct}vc(){return this.Ju}mc(t,i){t.Wo(i),this.gu()}Ba(t){this.ya=t,this.ph.Ba(this.ya),this.Xu.forEach(i=>i.Ba(t)),this.gu()}wc(t){1!==this.Xu.length&&(r(t>=0&&t<this.Xu.length,"Invalid pane index"),this.Xu.splice(t,1),this.Ah())}gc(t,i){if(this.Xu.length<2)return;r(t>=0&&t<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu.reduce((t,i)=>t+i.La(),0),e=this.Xu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Xu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.Aa(i*l);let a=i-o,_=this.Xu.length-1;for(const t of this.Xu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.Aa(s)}this.Ah()}bc(t,i){r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu[i];this.Xu[t]=n,this.Xu[i]=s,this.Ah()}Mc(t,i){if(r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index"),t===i)return;const[s]=this.Xu.splice(t,1);this.Xu.splice(i,0,s),this.Ah()}qa(t,i,s){t.qa(i,s)}ja(t,i,s){t.ja(i,s),this.Oh(),this.oc(this.yc(t,2))}Ya(t,i){t.Ya(i),this.oc(this.yc(t,2))}Xa(t,i,s){i.Vo()||t.Xa(i,s)}Ga(t,i,s){i.Vo()||(t.Ga(i,s),this.Oh(),this.oc(this.yc(t,2)))}Ka(t,i){i.Vo()||(t.Ka(i),this.oc(this.yc(t,2)))}Ja(t,i){t.Ja(i),this.oc(this.yc(t,2))}Sc(t){this.ph.ha(t)}xc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Tu(t,i),this.gu()}Cc(t){this.Pc(0),this.Tc(t),this.kc()}Dc(t){this.ph.la(t),this.gu()}Rc(){this.ph.oa(),this.ar()}Pc(t){this.ph.aa(t)}Tc(t){this.ph._a(t),this.gu()}kc(){this.ph.ua(),this.ar()}Xs(){return this.Gu}Fc(t,i,s,n,e){this.Ct.Vs(t,i);let r=NaN,h=this.ph.fu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const o=n.ks(),a=o.Ot();if(null!==a&&(r=o.Ds(i,a)),r=this.nc.Ml(r,h,n),this.Ct.Bs(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this.uc(e&&{r_:e.r_,h_:e.h_,o_:e.o_||null}),this.Ju.p(this.Ct.Lt(),{x:t,y:i},s)}}Vc(t,i,s){const n=s.ks(),e=n.Ot(),r=n.zt(t,l(e)),h=this.ph.su(i,!0),o=this.ph.jt(l(h));this.Fc(o,r,null,s,!0)}Ic(t){this.fc().Es(),this.Jh(),t||this.Ju.p(null,null,null)}Oh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Fc(i,s,null,t)}this.Ct.zs()}Lc(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.du(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),o=null!==t&&t>r&&!l,a=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.ph.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.ph.fn(this.ph.yu()-i)}}this.ph.Pu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Xu.find(i=>i.Ft().includes(t));return void 0===i?null:i}gu(){this.Xu.forEach(t=>t.t_()),this.Oh()}m(){this.Xu.forEach(t=>t.m()),this.Xu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Ac(){return this.sc}Yn(){return this.sc.W()}Ia(){return this.Zu}Bc(t,i){const s=this.ec(i);this.Oc(t,s),this.Gu.push(t),1===this.Gu.length?this.Ah():this.ar()}Ec(t){const i=this.Nn(t),s=this.Gu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Gu.splice(s,1),n.na(t),t.m&&t.m(),this.ph.Z_();const e=this.Xu.length;this.Wc(n),this.Xu.length<e&&this.Ah()}Lh(t,i){const s=l(this.Nn(t));s.na(t,!0),s.ia(t,i,!0)}Eu(){const t=Y.gn();t.hn(),this.oc(t)}zc(t){const i=Y.gn();i._n(t),this.oc(i)}dn(){const t=Y.gn();t.dn(),this.oc(t)}pn(t){const i=Y.gn();i.pn(t),this.oc(i)}fn(t){const i=Y.gn();i.fn(t),this.oc(i)}un(t){const i=Y.gn();i.un(t),this.oc(i)}ln(){const t=Y.gn();t.ln(),this.oc(t)}$c(){return this.Ps.rightPriceScale.visible?"right":"left"}Hc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Nc(t))return;const s=l(this.Nn(t));s.na(t);const n=this.ec(i);this.Oc(t,n),0===s.yl().length&&this.Wc(s),this.Ah()}Uc(){return this.lc}q(){return this.rc}Ut(t){const i=this.lc,s=this.rc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Qu||this.Qu.wr!==s||this.Qu.gr!==i)this.Qu={wr:s,gr:i,qc:new Map};else{const i=this.Qu.qc.get(t);if(void 0!==i)return i}const n=this.Po.it(s,i,t/100);return this.Qu.qc.set(t,n),n}jc(t){return this.Xu.indexOf(t)}Ki(){return this.Po}Yc(){return this.Xc()}Xc(t){const i=new wi(this.ph,this);this.Xu.push(i);const s=t??this.Xu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.oc(n),i}ec(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Xu.length,t))<this.Xu.length?this.Xu[t]:this.Xc(t)}Nc(t){return this.Xu.findIndex(i=>i.za().includes(t))}yc(t,i){const s=new Y(i);if(null!==t){const n=this.Xu.indexOf(t);s.tn(n,{sn:i})}return s}ac(t,i){return void 0===i&&(i=2),this.yc(this.Nn(t),i)}oc(t){this.tc&&this.tc(t),this.Xu.forEach(t=>t.n_()._r().Tt())}Oc(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.$c();i.ia(t,n),j(n)||t.lr(t.W())}hc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Wc(t){!t.Wa()&&0===t.yl().length&&this.Xu.length>1&&this.Xu.splice(this.jc(t),1)}}function Oi(t){if(t>=1)return 0;let i=0;for(;i<8;i++){const s=Math.round(t);if(Math.abs(s-t)<1e-8)return i;t*=10}return i}function Ei(t){return!u(t)&&!d(t)}function Wi(t){return u(t)}!function(t){t[t.Disabled=0]="Disabled",t[t.Continuous=1]="Continuous",t[t.OnDataUpdate=2]="OnDataUpdate"}(Vi||(Vi={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Ii||(Ii={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Li||(Li={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Ai||(Ai={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>K(zi(t),4))(t)).replace(/yy/g,(t=>K(zi(t)%100,2))(t)).replace(/MMMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(t,s)).replace(/MMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(t,s)).replace(/MM/g,(t=>K((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>K((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Gc=t,this.Kc=i}c_(t){return $i(t,this.Gc,this.Kc)}}class Ni{constructor(t){this.Zc=t||"%h:%m:%s"}c_(t){return this.Zc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Jc:"yyyy-MM-dd",Qc:"%h:%m:%s",td:" ",sd:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.nd=new Hi(i.Jc,i.sd),this.ed=new Ni(i.Qc),this.rd=i.td}c_(t){return`${this.nd.c_(t)}${this.rd}${this.ed.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{hd:(Gi=1,1e3*Gi),ld:10},{hd:Yi(1),ld:20},{hd:Yi(5),ld:21},{hd:Yi(30),ld:22},{hd:ji(1),ld:30},{hd:ji(3),ld:31},{hd:ji(6),ld:32},{hd:ji(12),ld:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].hd)!==Math.floor(t.getTime()/Xi[s].hd))return Xi[s].ld;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Ei(i))throw new Error("time must be of type BusinessDay");const s=new Date(Date.UTC(i.year,i.month-1,i.day,0,0,0,0));return{od:Math.round(s.getTime()/1e3),ad:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{od:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}function ss(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}class ns{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Ei(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"od"in t?t.od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ad?new Date(1e3*i.od).getTime():new Date(Date.UTC(i.ad.year,i.ad.month-1,i.ad.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Ei(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this._d=new qi({Jc:i,Qc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",td:" ",sd:t.locale}):this._d=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this._d.c_(new Date(1e3*i.od))}allowsTickMark(t,i){const s=this.Ps.timeScale.tickMarkFilter;if(void 0===s)return!0;const n=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible);return s(t.originalTime,n,i)}formatTickmark(t,i){const s=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.ad?new Date(1e3*t.od):new Date(Date.UTC(t.ad.year,t.ad.month-1,t.ad.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.od,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).od);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).od-(s||Zi(i.time).od),s=Zi(i.time).od,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.od-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.od),s)}}(t,i)}static ud(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function es(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function rs(t,i){return t.width===i.width&&t.height===i.height}var hs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var ls=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=es({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return es({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=es(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;rs(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=es(this._transformBitmapSize(t,this._canvasElementClientSize)),n=rs(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&rs(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=os(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new hs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=os(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return es({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):es({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=es({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function os(t){return t.ownerDocument.defaultView}var as=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function _s(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new as(e,s,n)}const us="undefined"!=typeof window;function cs(){return!!us&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ds(){return!!us&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ps(t){return t+t%2}function fs(t){us&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class vs{constructor(t,i,s){this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.gd=null,this.bd=!1,this.Md=null,this.yd=null,this.Sd=!1,this.xd=!1,this.Cd=!1,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Vd=null,this.Id=0,this.Ld=!1,this.Ad=!1,this.Bd=!1,this.Od=0,this.Ed=null,this.Wd=!ds(),this.zd=t=>{this.$d(t)},this.Hd=t=>{if(this.Nd(t)){const i=this.Ud(t);if(++this.vd,this.md&&this.vd>1){const{qd:s}=this.jd(gs(t),this.wd);s<30&&!this.Cd&&this.Yd(i,this.Gd.Xd),this.Kd()}}else{const i=this.Ud(t);if(++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}}},this.tp=t,this.Gd=i,this.Ps=s,this.ip()}m(){null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Fd&&(this.Fd(),this.Fd=null),null!==this.kd&&(this.kd(),this.kd=null),this.sp(),this.Qd()}np(t){this.Dd&&this.Dd();const i=this.ep.bind(this);if(this.Dd=()=>{this.tp.removeEventListener("mousemove",i)},this.tp.addEventListener("mousemove",i),this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.rp),this.Wd=!0}Qd(){null!==this.pd&&clearTimeout(this.pd),this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Kd(){null!==this.md&&clearTimeout(this.md),this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}ep(t){if(this.Bd||null!==this.yd)return;if(this.Nd(t))return;const i=this.Ud(t);this.Zd(i,this.Gd.hp),this.Wd=!0}lp(t){const i=Ms(t.changedTouches,l(this.Ed));if(null===i)return;if(this.Od=bs(t),null!==this.Vd)return;if(this.Ad)return;this.Ld=!0;const s=this.jd(gs(i),l(this.yd)),{op:n,ap:e,qd:r}=s;if(this.Sd||!(r<5)){if(!this.Sd){const t=.5*n,i=e>=t&&!this.Ps._p(),s=t>e&&!this.Ps.up();i||s||(this.Ad=!0),this.Sd=!0,this.Cd=!0,this.sp(),this.Kd()}if(!this.Ad){const s=this.Ud(t,i);this.Yd(s,this.Gd.cp),ws(t)}}}dp(t){if(0!==t.button)return;const i=this.jd(gs(t),l(this.Md)),{qd:s}=i;if(s>=5&&(this.xd=!0,this.Qd()),this.xd){const i=this.Ud(t);this.Zd(i,this.Gd.pp)}}jd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{op:s,ap:n,qd:s+n}}fp(t){let i=Ms(t.changedTouches,l(this.Ed));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ed=null,this.Od=bs(t),this.sp(),this.yd=null,this.Fd&&(this.Fd(),this.Fd=null);const s=this.Ud(t,i);if(this.Yd(s,this.Gd.vp),++this.vd,this.md&&this.vd>1){const{qd:t}=this.jd(gs(i),this.wd);t<30&&!this.Cd&&this.Yd(s,this.Gd.Xd),this.Kd()}else this.Cd||(this.Yd(s,this.Gd.mp),this.Gd.mp&&ws(t));0===this.vd&&ws(t),0===t.touches.length&&this.bd&&(this.bd=!1,ws(t))}$d(t){if(0!==t.button)return;const i=this.Ud(t);if(this.Md=null,this.Bd=!1,this.Rd&&(this.Rd(),this.Rd=null),cs()){this.tp.ownerDocument.documentElement.removeEventListener("mouseleave",this.zd)}if(!this.Nd(t))if(this.Zd(i,this.Gd.wp),++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}else this.xd||this.Zd(i,this.Gd.gp)}sp(){null!==this.gd&&(clearTimeout(this.gd),this.gd=null)}bp(t){if(null!==this.Ed)return;const i=t.changedTouches[0];this.Ed=i.identifier,this.Od=bs(t);const s=this.tp.ownerDocument.documentElement;this.Cd=!1,this.Sd=!1,this.Ad=!1,this.yd=gs(i),this.Fd&&(this.Fd(),this.Fd=null);{const i=this.lp.bind(this),n=this.fp.bind(this);this.Fd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.sp(),this.gd=setTimeout(this.Mp.bind(this,t),240)}const n=this.Ud(t,i);this.Yd(n,this.Gd.yp),this.md||(this.vd=0,this.md=setTimeout(this.Kd.bind(this),500),this.wd=gs(i))}Sp(t){if(0!==t.button)return;const i=this.tp.ownerDocument.documentElement;cs()&&i.addEventListener("mouseleave",this.zd),this.xd=!1,this.Md=gs(t),this.Rd&&(this.Rd(),this.Rd=null);{const t=this.dp.bind(this),s=this.$d.bind(this);this.Rd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Bd=!0,this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.xp),this.pd||(this.dd=0,this.pd=setTimeout(this.Qd.bind(this),500),this.fd=gs(t))}ip(){this.tp.addEventListener("mouseenter",this.np.bind(this)),this.tp.addEventListener("touchcancel",this.sp.bind(this));{const t=this.tp.ownerDocument,i=t=>{this.Gd.Cp&&(t.composed&&this.tp.contains(t.composedPath()[0])||t.target&&this.tp.contains(t.target)||this.Gd.Cp())};this.Td=()=>{t.removeEventListener("touchstart",i)},this.Pd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}ds()&&(this.kd=()=>{this.tp.removeEventListener("dblclick",this.Hd)},this.tp.addEventListener("dblclick",this.Hd)),this.tp.addEventListener("mouseleave",this.Pp.bind(this)),this.tp.addEventListener("touchstart",this.bp.bind(this),{passive:!0}),fs(this.tp),this.tp.addEventListener("mousedown",this.Sp.bind(this)),this.Tp(),this.tp.addEventListener("touchmove",()=>{},{passive:!1})}Tp(){void 0===this.Gd.kp&&void 0===this.Gd.Dp&&void 0===this.Gd.Rp||(this.tp.addEventListener("touchstart",t=>this.Fp(t.touches),{passive:!0}),this.tp.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Vd&&void 0!==this.Gd.Dp){const i=ms(t.touches[0],t.touches[1])/this.Id;this.Gd.Dp(this.Vd,i),ws(t)}},{passive:!1}),this.tp.addEventListener("touchend",t=>{this.Fp(t.touches)}))}Fp(t){1===t.length&&(this.Ld=!1),2!==t.length||this.Ld||this.bd?this.Vp():this.Ip(t)}Ip(t){const i=this.tp.getBoundingClientRect()||{left:0,top:0};this.Vd={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Id=ms(t[0],t[1]),void 0!==this.Gd.kp&&this.Gd.kp(),this.sp()}Vp(){null!==this.Vd&&(this.Vd=null,void 0!==this.Gd.Rp&&this.Gd.Rp())}Pp(t){if(this.Dd&&this.Dd(),this.Nd(t))return;if(!this.Wd)return;const i=this.Ud(t);this.Zd(i,this.Gd.Lp),this.Wd=!ds()}Mp(t){const i=Ms(t.touches,l(this.Ed));if(null===i)return;const s=this.Ud(t,i);this.Yd(s,this.Gd.Ap),this.Cd=!0,this.bd=!0}Nd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:bs(t)<this.Od+500}Yd(t,i){i&&i.call(this.Gd,t)}Zd(t,i){i&&i.call(this.Gd,t)}Ud(t,i){const s=i||t,n=this.tp.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Bp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Op:t.type,Ep:s.target,a_:t.view,Wp:()=>{"touchstart"!==t.type&&ws(t)}}}}function ms(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ws(t){t.cancelable&&t.preventDefault()}function gs(t){return{ut:t.pageX,ct:t.pageY}}function bs(t){return t.timeStamp||performance.now()}function Ms(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class ys{constructor(t,i,s){this.zp=null,this.$p=null,this.Hp=!0,this.Np=null,this.Up=t,this.qp=t.jp()[i],this.Yp=t.jp()[s],this.Xp=document.createElement("tr"),this.Xp.style.height="1px",this.Gp=document.createElement("td"),this.Gp.style.position="relative",this.Gp.style.padding="0",this.Gp.style.margin="0",this.Gp.setAttribute("colspan","3"),this.Kp(),this.Xp.appendChild(this.Gp),this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(this.zp=null,this.$p=null)}m(){null!==this.$p&&this.$p.m()}Jp(){return this.Xp}Qp(){return es({width:this.qp.Qp().width,height:1})}tf(){return es({width:this.qp.tf().width,height:1*window.devicePixelRatio})}if(t,i,s){const n=this.tf();t.fillStyle=this.Up.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Kp(),this.Up.W().layout.panes.enableResize!==this.Hp&&(this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(null!==this.zp&&(this.Gp.removeChild(this.zp.sf),this.Gp.removeChild(this.zp.nf),this.zp=null),null!==this.$p&&(this.$p.m(),this.$p=null)))}Zp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Gp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Gp.appendChild(s);const e={rp:this.ef.bind(this),Lp:this.rf.bind(this),xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),wp:this.af.bind(this),vp:this.af.bind(this)};this.$p=new vs(s,e,{_p:()=>!1,up:()=>!0}),this.zp={nf:s,sf:t}}Kp(){this.Gp.style.background=this.Up.W().layout.panes.separatorColor}ef(t){null!==this.zp&&(this.zp.nf.style.backgroundColor=this.Up.W().layout.panes.separatorHoverColor)}rf(t){null!==this.zp&&null===this.Np&&(this.zp.nf.style.backgroundColor="")}hf(t){if(null===this.zp)return;const i=this.qp._f().La()+this.Yp._f().La(),s=i/(this.qp.Qp().height+this.Yp.Qp().height),n=30*s;i<=2*n||(this.Np={uf:t.pageY,cf:this.qp._f().La(),df:i-n,pf:i,ff:s,vf:n},this.zp.sf.style.display="block")}lf(t){const i=this.Np;if(null===i)return;const s=(t.pageY-i.uf)*i.ff,n=Xt(i.cf+s,i.vf,i.df);this.qp._f().Aa(n),this.Yp._f().Aa(i.pf-n),this.Up.ti().Ah()}af(t){null!==this.Np&&null!==this.zp&&(this.Np=null,this.zp.sf.style.display="none")}}function Ss(t,i){return t.mf-i.mf}function xs(t,i,s){const n=(t.mf-i.mf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class Cs{constructor(t,i,s,n){this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=null,this.Sf=0,this.xf=0,this.Cf=t,this.Pf=i,this.Tf=s,this.Mn=n}kf(t,i){if(null!==this.wf){if(this.wf.gt===i)return void(this.wf.mf=t);if(Math.abs(this.wf.mf-t)<this.Mn)return}this.Mf=this.bf,this.bf=this.gf,this.gf=this.wf,this.wf={gt:i,mf:t}}ae(t,i){if(null===this.wf||null===this.gf)return;if(i-this.wf.gt>50)return;let s=0;const n=xs(this.wf,this.gf,this.Pf),e=Ss(this.wf,this.gf),r=[n],h=[e];if(s+=e,null!==this.bf){const t=xs(this.gf,this.bf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.gf,this.bf);if(r.push(t),h.push(i),s+=i,null!==this.Mf){const t=xs(this.bf,this.Mf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.bf,this.Mf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.Cf||(this.yf={mf:t,gt:i},this.xf=l,this.Sf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Tf))}Iu(t){const i=l(this.yf),s=t-i.gt;return i.mf+this.xf*(Math.pow(this.Tf,s)-1)/Math.log(this.Tf)}Vu(t){return null===this.yf||this.Df(t)===this.Sf}Df(t){const i=t-l(this.yf).gt;return Math.min(i,this.Sf)}}class Ps{constructor(t,i){this.Rf=void 0,this.Ff=void 0,this.Vf=void 0,this.vs=!1,this.If=t,this.Lf=i,this.Af()}Tt(){this.Af()}Bf(){this.Rf&&this.If.removeChild(this.Rf),this.Ff&&this.If.removeChild(this.Ff),this.Rf=void 0,this.Ff=void 0}Of(){return this.vs!==this.Ef()||this.Vf!==this.Wf()}Wf(){return this.Lf.ti().Ki().tt(this.Lf.W().layout.textColor)>160?"dark":"light"}Ef(){return this.Lf.W().layout.attributionLogo}zf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Af(){this.Of()&&(this.Bf(),this.vs=this.Ef(),this.vs&&(this.Vf=this.Wf(),this.Ff=document.createElement("style"),this.Ff.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.Rf=document.createElement("a"),this.Rf.href=`https://pipsend.com${this.zf()}`,this.Rf.title="Powered by Pipsend Charts",this.Rf.id="pipsend-attr-logo",this.Rf.target="_blank",this.Rf.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.Rf.toggleAttribute("data-dark","dark"===this.Vf),this.If.appendChild(this.Ff),this.If.appendChild(this.Rf)))}}function Ts(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new ls(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function ks(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function Ds(t,i,s,n){t.nh&&t.nh(i,s,n)}function Rs(t,i,s,n){t.et(i,s,n)}function Fs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Vs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],o=t[r-1],a=o.qt(n,!1),_=l.$i(),u=o.$i();if(1===i?_>u-a:_<u+a){const n=u-a*i;l.Hi(n);const r=n-i*a/2;if((1===i?r<0:r>s)&&h>0){const n=1===i?-1-r:r-s,l=Math.min(n,h);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);h-=l}}else e=r,h=1===i?u-a-_:_-(u+a)}}class Ls{constructor(t,i,s,n){this.Yi=null,this.$f=null,this.Hf=!1,this.Nf=new it(200),this.Uf=null,this.qf=0,this.jf=!1,this.Yf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Gf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Pt=t,this.Ps=i,this.xo=i.layout,this.sc=s,this.Kf="left"===n,this.Zf=Vs("normal",n),this.Jf=Vs("top",n),this.Qf=Vs("bottom",n),this.Gp=document.createElement("div"),this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.Gp.style.width="25px",this.Gp.style.left="0",this.Gp.style.position="relative",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.iv=Ts(this.Gp,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const r=this.iv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),Cp:this.sv.bind(this),wp:this.af.bind(this),vp:this.af.bind(this),Jd:this.nv.bind(this),Xd:this.nv.bind(this),rp:this.ev.bind(this),Lp:this.rf.bind(this)};this.$p=new vs(this.iv.canvasElement,h,{_p:()=>!this.Ps.handleScroll.vertTouchDrag,up:()=>!0})}m(){this.$p.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Yi&&this.Yi.ra().u(this),this.Yi=null}Jp(){return this.Gp}P(){return this.xo.fontSize}rv(){const t=this.sc.W();return this.Uf!==t.T&&(this.Nf.In(),this.Uf=t.T),t}hv(){if(null===this.Yi)return 0;let t=0;const i=this.rv(),s=l(this.tv.canvasElement.getContext("2d",{colorSpace:this.Pt.Xf().W().layout.colorSpace}));s.save();const n=this.Yi.Vl();s.font=this.lv(),n.length>0&&(t=Math.max(this.Nf.Vi(s,n[0].Jl),this.Nf.Vi(s,n[n.length-1].Jl)));const e=this.ov();for(let i=e.length;i--;){const n=this.Nf.Vi(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Ot();if(null!==r&&null!==this.$f&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.$f.height-2,r);t=Math.max(t,this.Nf.Vi(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Nf.Vi(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ps(Math.ceil(i.S+i.C+i.I+i.L+5+o))}av(t){null!==this.$f&&rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`)}_v(){return l(this.$f).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ra().u(this),this.Yi=t,t.ra().i(this.do.bind(this),this))}$t(){return this.Yi}In(){const t=this.Pt._f();this.Pt.Xf().ti().Ja(t,l(this.$t()))}uv(t){if(null===this.$f)return;const i={colorSpace:this.Pt.Xf().W().layout.colorSpace};if(1!==t){this.cv(),this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)}),this.Pt.fv(t,this.Qf),this.vv(t),this.Pt.fv(t,this.Zf),this.mv(t))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.wv(s),this.Pt.fv(s,this.Jf))}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Vl()}hf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!0,i.qa(s,this.Yi,t.localY)}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f(),n=this.Yi;i.ja(s,n,t.localY)}sv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Xf().ti(),i=this.Pt._f(),s=this.Yi;this.Hf&&(this.Hf=!1,t.Ya(i,s))}af(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!1,i.Ya(s,this.Yi)}nv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.In()}ev(t){if(null===this.Yi)return;!this.Pt.Xf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Ee()||this.Yi.Lo()||this.gv(1)}rf(t){this.gv(0)}ov(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt._f(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt._f().Ft()),t}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt._f().ti(),r=e.q(),h=e.Uc();r===h?I(t,0,0,s,n,r):B(t,0,0,s,n,r,h)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.$f||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.rv().S*s));let e;e=this.Kf?i.width-n:0,t.fillRect(e,0,n,i.height)}vv(t){if(null===this.$f||null===this.Yi)return;const i=this.Yi.Vl(),s=this.Yi.W(),n=this.rv(),e=this.Kf?this.$f.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.lv(),t.fillStyle=s.textColor??this.xo.textColor,t.textAlign=this.Kf?"right":"left",t.textBaseline="middle";const r=this.Kf?Math.round(e-n.I):Math.round(e+n.C+n.I),h=i.map(i=>this.Nf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}cv(){if(null===this.$f||null===this.Yi)return;let t=this.$f.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt._f(),e=this.rv();this.Yi===n.qn()&&this.Pt._f().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.bv(i,e,t)}bv(t,i,s){if(null===this.$f)return;const n=t.filter(t=>t.Li()<=s),e=t.filter(t=>t.Li()>s);n.sort((t,i)=>i.Li()-t.Li()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Li()-i.Li());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Li();n>-t&&n<t&&s.Hi(t),n>this.$f.height-t&&n<this.$f.height+t&&s.Hi(this.$f.height-t)}Is(n,1,this.$f.height,i),Is(e,-1,this.$f.height,i)}mv(t){if(null===this.$f)return;const i=this.ov(),s=this.rv(),n=this.Kf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Nf,n)}})}wv(t){if(null===this.$f||null===this.Yi)return;const i=this.Pt.Xf().ti(),s=[],n=this.Pt._f(),e=i.fc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.rv(),h=this.Kf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Nf,h)})})}gv(t){this.Gp.style.cursor=1===t?"ns-resize":"default"}do(){const t=this.hv();this.qf<t&&this.Pt.Xf().ti().Ah(),this.qf=t}lv(){return g(this.xo.fontSize,this.xo.fontFamily)}}function As(t,i){return t.tl?.(i)??[]}function Bs(t,i){return t.$s?.(i)??[]}function Os(t,i){return t.cs?.(i)??[]}function Es(t,i){return t.Zh?.(i)??[]}class Ws{constructor(t,i){this.$f=es({width:0,height:0}),this.Mv=null,this.yv=null,this.Sv=null,this.xv=null,this.Cv=!1,this.Pv=new a,this.Tv=new a,this.kv=0,this.Dv=!1,this.Rv=null,this.Fv=!1,this.Vv=null,this.Iv=null,this.jf=!1,this.Yf=()=>{this.jf||null===this.Lv||this.ss().ar()},this.Gf=()=>{this.jf||null===this.Lv||this.ss().ar()},this.Lf=t,this.Lv=i,this.Lv.s_().i(this.Av.bind(this),this,!0),this.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Bv.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Ov=document.createElement("td"),this.Ov.style.padding="0",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Bv.appendChild(s),this.tv=Ts(s,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.iv=Ts(s,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const e=this.iv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Xp=document.createElement("tr"),this.Xp.appendChild(this.Ov),this.Xp.appendChild(this.Bv),this.Xp.appendChild(this.Ev),this.Wv(),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>null===this.Rv&&!this.Lf.W().handleScroll.vertTouchDrag,up:()=>null===this.Rv&&!this.Lf.W().handleScroll.horzTouchDrag})}m(){null!==this.Mv&&this.Mv.m(),null!==this.yv&&this.yv.m(),this.Sv=null,this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Lv&&(this.Lv.s_().u(this),this.Lv.m()),this.$p.m()}_f(){return l(this.Lv)}zv(t){null!==this.Lv&&this.Lv.s_().u(this),this.Lv=t,null!==this.Lv&&this.Lv.s_().i(Ws.prototype.Av.bind(this),this,!0),this.Wv(),this.Lf.jp().indexOf(this)===this.Lf.jp().length-1?(this.Sv=this.Sv??new Ps(this.Bv,this.Lf),this.Sv.Tt()):(this.Sv?.Bf(),this.Sv=null)}Xf(){return this.Lf}Jp(){return this.Xp}Wv(){if(null!==this.Lv&&(this.$v(),0!==this.ss().Xs().length)){if(null!==this.Mv){const t=this.Lv.Na();this.Mv.us(l(t))}if(null!==this.yv){const t=this.Lv.Ua();this.yv.us(l(t))}}}Hv(){null!==this.Mv&&this.Mv.Tt(),null!==this.yv&&this.yv.Tt()}La(){return null!==this.Lv?this.Lv.La():0}Aa(t){this.Lv&&this.Lv.Aa(t)}rp(t){if(!this.Lv)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}xp(t){this.Nv(),this.qv(),this.Uv(t.localX,t.localY,t)}hp(t){if(!this.Lv)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}gp(t){null!==this.Lv&&(this.Nv(),this.jv(t))}Jd(t){null!==this.Lv&&this.Yv(this.Tv,t)}Xd(t){this.Jd(t)}pp(t){this.Nv(),this.Xv(t),this.Uv(t.localX,t.localY,t)}wp(t){null!==this.Lv&&(this.Nv(),this.Dv=!1,this.Gv(t))}mp(t){null!==this.Lv&&this.jv(t)}Ap(t){if(this.Dv=!0,null===this.Rv){const i={x:t.localX,y:t.localY};this.Kv(i,i,t)}}Lp(t){null!==this.Lv&&(this.Nv(),this.Lv.ti().uc(null),this.Zv())}Jv(){return this.Pv}Qv(){return this.Tv}kp(){this.kv=1,this.ss().ln()}Dp(t,i){if(!this.Lf.W().handleScale.pinch)return;const s=5*(i-this.kv);this.kv=i,this.ss().xc(t.ut,s)}yp(t){this.Dv=!1,this.Fv=null!==this.Rv,this.qv();const i=this.ss().fc();null!==this.Rv&&i.Vt()&&(this.Vv={x:i.ni(),y:i.ei()},this.Rv={x:t.localX,y:t.localY})}cp(t){if(null===this.Lv)return;const i=t.localX,s=t.localY;if(null!==this.Rv){this.Fv=!1;const n=l(this.Vv),e=n.x+(i-this.Rv.x),r=n.y+(s-this.Rv.y);return void this.Uv(e,r,t)}this.Xv(t)}vp(t){0===this.Xf().W().trackingMode.exitMode&&(this.Fv=!0),this.tm(),this.Gv(t)}Xn(t,i){const s=this.Lv;return null===s?null:Si(s,t,i)}im(t,i){l("left"===i?this.Mv:this.yv).av(es({width:t,height:this.$f.height}))}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Bv.style.width=t.width+"px",this.Bv.style.height=t.height+"px")}sm(){const t=l(this.Lv);t.Ha(t.Na()),t.Ha(t.Ua());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ha(s),i.zs()}for(const i of t.e_())i.zs()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;null!==t&&t.drawImage(n,i,s)}}uv(t){if(0===t)return;if(null===this.Lv)return;t>1&&this.sm(),null!==this.Mv&&this.Mv.uv(t),null!==this.yv&&this.yv.uv(t);const i={colorSpace:this.Lf.W().layout.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t)}),this.Lv&&(this.nm(t,As),this.rm(t),this.nm(t,Bs),this.nm(t,Os)))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.hm(s),this.nm(s,Es),this.nm(s,Os))}lm(){return this.Mv}om(){return this.yv}fv(t,i){this.nm(t,i)}Av(){null!==this.Lv&&this.Lv.s_().u(this),this.Lv=null}jv(t){this.Yv(this.Pv,t)}Yv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().fu(s),{x:s,y:n},i)}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Uc();r===h?I(t,0,0,s,n,h):B(t,0,0,s,n,r,h)}rm(t){const i=l(this.Lv),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}hm(t){this.am(t,Bs,Rs,this.ss().fc())}nm(t,i){const s=l(this.Lv),n=s.Ft(),e=s.e_();for(const s of e)this.am(t,i,Ds,s);for(const s of n)this.am(t,i,Ds,s);for(const s of e)this.am(t,i,Rs,s);for(const s of n)this.am(t,i,Rs,s)}am(t,i,s,n){const e=l(this.Lv),r=e.ti()._c(),h=null!==r&&r.r_===n,o=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Fs(i,i=>s(i,t,h,o),n,e)}$v(){if(null===this.Lv)return;const t=this.Lf,i=this.Lv.Na().W().visible,s=this.Lv.Ua().W().visible;i||null===this.Mv||(this.Ov.removeChild(this.Mv.Jp()),this.Mv.m(),this.Mv=null),s||null===this.yv||(this.Ev.removeChild(this.yv.Jp()),this.yv.m(),this.yv=null);const n=t.ti().Ac();i&&null===this.Mv&&(this.Mv=new Ls(this,t.W(),n,"left"),this.Ov.appendChild(this.Mv.Jp())),s&&null===this.yv&&(this.yv=new Ls(this,t.W(),n,"right"),this.Ev.appendChild(this.yv.Jp()))}_m(t){return t.Bp&&this.Dv||null!==this.Rv}um(t){return Math.max(0,Math.min(t,this.$f.width-1))}dm(t){return Math.max(0,Math.min(t,this.$f.height-1))}Uv(t,i,s){this.ss().Fc(this.um(t),this.dm(i),s,l(this.Lv))}Zv(){this.ss().Ic()}tm(){this.Fv&&(this.Rv=null,this.Zv())}Kv(t,i,s){this.Rv=t,this.Fv=!1,this.Uv(i.x,i.y,s);const n=this.ss().fc();this.Vv={x:n.ni(),y:n.ei()}}ss(){return this.Lf.ti()}Gv(t){if(!this.Cv)return;const i=this.ss(),s=this._f();if(i.Ka(s,s.ks()),this.xv=null,this.Cv=!1,i.kc(),null!==this.Iv){const t=performance.now(),s=i.At();this.Iv.ae(s.yu(),t),this.Iv.Vu(t)||i.un(this.Iv)}}Nv(){this.Rv=null}qv(){if(!this.Lv)return;if(this.ss().ln(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)l(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Lv.ks().Gi()&&this.ss().At().Gi()}Xv(t){if(null===this.Lv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.Lf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Bp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Bp))return;const h=this.Lv.ks(),l=performance.now();if(null!==this.xv||this._m(t)||(this.xv={x:t.clientX,y:t.clientY,od:l,pm:t.localX,fm:t.localY}),null!==this.xv&&!this.Cv&&(this.xv.x!==t.clientX||this.xv.y!==t.clientY)){if(t.Bp&&r.touch||!t.Bp&&r.mouse){const t=s.bu();this.Iv=new Cs(.2/t,7/t,.997,15/t),this.Iv.kf(s.yu(),this.xv.od)}else this.Iv=null;h.Gi()||i.Xa(this.Lv,h,t.localY),i.Pc(t.localX),this.Cv=!0}this.Cv&&(h.Gi()||i.Ga(this.Lv,h,t.localY),i.Tc(t.localX),null!==this.Iv&&this.Iv.kf(s.yu(),l))}}class zs{constructor(t,i,s,n,e){this.xt=!0,this.$f=es({width:0,height:0}),this.Yf=()=>this.uv(3),this.Kf="left"===t,this.sc=s.Ac,this.Ps=i,this.vm=n,this.wm=e,this.Gp=document.createElement("div"),this.Gp.style.width="25px",this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf)}m(){this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Gp}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.tv.resizeCanvasElement(t),this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.xt=!0)}uv(t){if(t<3&&!this.xt)return;if(0===this.$f.width||0===this.$f.height)return;this.xt=!1,this.tv.applySuggestedBitmapSize();const i=_s(this.tv,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)})}tf(){return this.tv.bitmapSize}if(t,i,s){const n=this.tf();n.width>0&&n.height>0&&t.drawImage(this.tv.canvasElement,i,s)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.vm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.sc.W().S*s),r=Math.floor(this.sc.W().S*n),h=this.Kf?i.width-e:0;t.fillRect(h,0,e,r)}dv({context:t,bitmapSize:i}){I(t,0,0,i.width,i.height,this.wm())}}function $s(t){return i=>i.nl?.(t)??[]}const Hs=$s("normal"),Ns=$s("top"),Us=$s("bottom");class qs{constructor(t,i){this.gm=null,this.bm=null,this.M=null,this.Mm=!1,this.$f=es({width:0,height:0}),this.ym=new a,this.Nf=new it(5),this.jf=!1,this.Yf=()=>{this.jf||this.Lf.ti().ar()},this.Gf=()=>{this.jf||this.Lf.ti().ar()},this.Lf=t,this.u_=i,this.Ps=t.W().layout,this.Rf=document.createElement("tr"),this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.xm=document.createElement("td"),this.xm.style.padding="0",this.Gp=document.createElement("td"),this.Gp.style.height="25px",this.Gp.style.padding="0",this.Cm=document.createElement("div"),this.Cm.style.width="100%",this.Cm.style.height="100%",this.Cm.style.position="relative",this.Cm.style.overflow="hidden",this.Gp.appendChild(this.Cm),this.tv=Ts(this.Cm,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const s=this.tv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.iv=Ts(this.Cm,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const n=this.iv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Rf.appendChild(this.Sm),this.Rf.appendChild(this.Gp),this.Rf.appendChild(this.xm),this.Pm(),this.Lf.ti().Ia().i(this.Pm.bind(this),this),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>!0,up:()=>!this.Lf.W().handleScroll.horzTouchDrag})}m(){this.$p.m(),null!==this.gm&&this.gm.m(),null!==this.bm&&this.bm.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Rf}Tm(){return this.gm}km(){return this.bm}xp(t){if(this.Mm)return;this.Mm=!0;const i=this.Lf.ti();!i.At().Gi()&&this.Lf.W().handleScale.axisPressedMouseMove.time&&i.Sc(t.localX)}yp(t){this.xp(t)}Cp(){const t=this.Lf.ti();!t.At().Gi()&&this.Mm&&(this.Mm=!1,this.Lf.W().handleScale.axisPressedMouseMove.time&&t.Rc())}pp(t){const i=this.Lf.ti();!i.At().Gi()&&this.Lf.W().handleScale.axisPressedMouseMove.time&&i.Dc(t.localX)}cp(t){this.pp(t)}wp(){this.Mm=!1;const t=this.Lf.ti();t.At().Gi()&&!this.Lf.W().handleScale.axisPressedMouseMove.time||t.Rc()}vp(){this.wp()}Jd(){this.Lf.W().handleScale.axisDoubleClickReset.time&&this.Lf.ti().dn()}Xd(){this.Jd()}rp(){this.Lf.ti().W().handleScale.axisPressedMouseMove.time&&this.gv(1)}Lp(){this.gv(0)}Qp(){return this.$f}Dm(){return this.ym}Rm(t,i,s){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.ym.p(t)),null!==this.gm&&this.gm.av(es({width:i,height:t.height})),null!==this.bm&&this.bm.av(es({width:s,height:t.height}))}Fm(){const t=this.Vm();return Math.ceil(t.S+t.C+t.P+t.A+t.V+t.Im)}Tt(){this.Lf.ti().At().Vl()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}uv(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const s=_s(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t),this.Lm(s,Us)}),this.vv(s),this.Lm(s,Hs)),null!==this.gm&&this.gm.uv(t),null!==this.bm&&this.bm.uv(t)}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Am([...this.Lf.ti().Xs(),this.Lf.ti().fc()],s),this.Lm(s,Ns))}Lm(t,i){const s=this.Lf.ti().Xs();for(const n of s)Fs(i,i=>Ds(i,t,!1,void 0),n,void 0);for(const n of s)Fs(i,i=>Rs(i,t,!1,void 0),n,void 0)}dv({context:t,bitmapSize:i}){I(t,0,0,i.width,i.height,this.Lf.ti().Uc())}pv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Lf.W().timeScale.borderVisible){t.fillStyle=this.Bm();const n=Math.max(1,Math.floor(this.Vm().S*s));t.fillRect(0,0,i.width,n)}}vv(t){const i=this.Lf.ti().At(),s=i.Vl();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Vm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Bm(),t.fillStyle=this.Bm();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.lv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Lf.W().timeScale.allowBoldLabels&&(t.font=this.Em());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Om(t,i,s){const n=this.Nf.Vi(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.$f.width&&(i-=Math.abs(this.$f.width-(r+n))),i}Am(t,i){const s=this.Vm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Bm(){return this.Lf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}lv(){return g(this.$(),this.Ps.fontFamily)}Em(){return g(this.$(),this.Ps.fontFamily,"bold")}Vm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,V:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Im:0});const t=this.M,i=this.lv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.A=3*s/12,t.V=3*s/12,t.Qi=9*s/12,t.B=0,t.Im=4*s/12,t.Ji.In()}return this.M}gv(t){this.Gp.style.cursor=1===t?"ew-resize":"default"}Pm(){const t=this.Lf.ti(),i=t.W();i.leftPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Jp()),this.gm.m(),this.gm=null),i.rightPriceScale.visible||null===this.bm||(this.xm.removeChild(this.bm.Jp()),this.bm.m(),this.bm=null);const s={Ac:this.Lf.ti().Ac()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Uc();i.leftPriceScale.visible&&null===this.gm&&(this.gm=new zs("left",i,s,n,e),this.Sm.appendChild(this.gm.Jp())),i.rightPriceScale.visible&&null===this.bm&&(this.bm=new zs("right",i,s,n,e),this.xm.appendChild(this.bm.Jp()))}}const js=!!us&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!us&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class Ys{constructor(t,i,s){var n;this.Wm=[],this.zm=[],this.$m=0,this.eo=0,this.ya=0,this.Hm=0,this.Nm=0,this.Um=null,this.qm=!1,this.Pv=new a,this.Tv=new a,this.Ju=new a,this.jm=null,this.Ym=null,this.If=t,this.Ps=i,this.u_=s,this.Rf=document.createElement("div"),this.Rf.classList.add("tv-lightweight-charts"),this.Rf.style.overflow="hidden",this.Rf.style.direction="ltr",this.Rf.style.width="100%",this.Rf.style.height="100%",(n=this.Rf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Xm=document.createElement("table"),this.Xm.setAttribute("cellspacing","0"),this.Rf.appendChild(this.Xm),this.Gm=this.Km.bind(this),Xs(this.Ps)&&this.Zm(!0),this.ss=new Bi(this.tc.bind(this),this.Ps,s),this.ti().vc().i(this.Jm.bind(this),this),this.Qm=new qs(this,this.u_),this.Xm.appendChild(this.Qm.Jp());const e=i.autoSize&&this.tw();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.iw(r,h),this.sw(),t.appendChild(this.Rf),this.nw(),this.ss.At().Bu().i(this.ss.Ah.bind(this.ss),this),this.ss.Ia().i(this.ss.Ah.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}jp(){return this.Wm}ew(){return this.Qm}m(){this.Zm(!1),0!==this.$m&&window.cancelAnimationFrame(this.$m),this.ss.vc().u(this),this.ss.At().Bu().u(this),this.ss.Ia().u(this),this.ss.m();for(const t of this.Wm)this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();this.Wm=[];for(const t of this.zm)this.rw(t);this.zm=[],l(this.Qm).m(),null!==this.Rf.parentElement&&this.Rf.parentElement.removeChild(this.Rf),this.Ju.m(),this.Pv.m(),this.Tv.m(),this.hw()}iw(t,i,s=!1){if(this.eo===i&&this.ya===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return es({width:i-i%2,height:s-s%2})}(es({width:t,height:i}));this.eo=n.height,this.ya=n.width;const e=this.eo+"px",r=this.ya+"px";l(this.Rf).style.height=e,l(this.Rf).style.width=r,this.Xm.style.height=e,this.Xm.style.width=r,s?this.lw(Y.bn(),performance.now()):this.ss.Ah()}uv(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Wm.length;i++)this.Wm[i].uv(t.rn(i).sn);this.Ps.timeScale.visible&&this.Qm.uv(t.en())}lr(t){const i=Xs(this.Ps);this.ss.lr(t);const s=Xs(this.Ps);s!==i&&this.Zm(s),t.layout?.panes&&this.ow(),this.nw(),this.aw(t)}Jv(){return this.Pv}Qv(){return this.Tv}vc(){return this.Ju}_w(t=!1){null!==this.Um&&(this.lw(this.Um,performance.now()),this.Um=null);const i=this.uw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.uw(n,t),s}cw(t){if("left"===t&&!this.dw())return 0;if("right"===t&&!this.pw())return 0;if(0===this.Wm.length)return 0;return l("left"===t?this.Wm[0].lm():this.Wm[0].om())._v()}fw(){return this.Ps.autoSize&&null!==this.jm}nf(){return this.Rf}mw(t){this.Ym=t,this.Ym?this.nf().style.setProperty("cursor",t):this.nf().style.removeProperty("cursor")}ww(){return this.Ym}gw(t){return h(this.Wm[t]).Qp()}ow(){this.zm.forEach(t=>{t.Tt()})}aw(t){(void 0!==t.autoSize||!this.jm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.jm&&this.tw(),!1===t.autoSize&&null!==this.jm&&this.hw(),t.autoSize||void 0===t.width&&void 0===t.height||this.iw(t.width||this.ya,t.height||this.eo))}uw(t,i){let s=0,n=0;const e=this.Wm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Wm.length;r++){const h=this.Wm[r],o=l("left"===s?h.lm():h.om()),a=o.tf();if(null!==t&&o.if(t,n,e,i),e+=a.height,r<this.Wm.length-1){const i=this.zm[r],s=i.tf();null!==t&&i.if(t,n,e),e+=s.height}}};if(this.dw()){r("left",0);s+=l(e.lm()).tf().width}for(let e=0;e<this.Wm.length;e++){const r=this.Wm[e],h=r.tf();if(null!==t&&r.if(t,s,n,i),n+=h.height,e<this.Wm.length-1){const i=this.zm[e],r=i.tf();null!==t&&i.if(t,s,n),n+=r.height}}if(s+=e.tf().width,this.pw()){r("right",s);s+=l(e.om()).tf().width}const h=(i,s,n)=>{l("left"===i?this.Qm.Tm():this.Qm.km()).if(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Qm.tf();if(null!==t){let r=0;this.dw()&&(h("left",r,n),r=l(e.lm()).tf().width),this.Qm.if(t,r,n,i),r+=s.width,this.pw()&&h("right",r,n)}n+=s.height}return es({width:s,height:n})}bw(){let t=0,i=0,s=0;for(const n of this.Wm)this.dw()&&(i=Math.max(i,l(n.lm()).hv(),this.Ps.leftPriceScale.minimumWidth)),this.pw()&&(s=Math.max(s,l(n.om()).hv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.La();i=ps(i),s=ps(s);const n=this.ya,e=this.eo,r=Math.max(n-i-s,0),h=1*this.zm.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Qm.Fm(),this.Ps.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=h+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Wm.length;++t){const n=this.Wm[t];n.zv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Wm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.La()*d*f)/f,e=Math.max(h,2),p+=e,n.av(es({width:r,height:e})),this.dw()&&n.im(i,"left"),this.pw()&&n.im(s,"right"),n._f()&&this.ss.mc(n._f(),e)}this.Qm.Rm(es({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ba(r),this.Hm!==i&&(this.Hm=i),this.Nm!==s&&(this.Nm=s)}Zm(t){t?this.Rf.addEventListener("wheel",this.Gm,{passive:!1}):this.Rf.removeEventListener("wheel",this.Gm)}Mw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return js?1/window.devicePixelRatio:1}Km(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.Mw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.Rf.getBoundingClientRect().left;this.ti().xc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Cc(-80*s)}lw(t,i){const s=t.en();3===s&&this.yw(),3!==s&&2!==s||(this.Sw(t),this.xw(t,i),this.Qm.Tt(),this.Wm.forEach(t=>{t.Hv()}),3===this.Um?.en()&&(this.Um.mn(t),this.yw(),this.Sw(this.Um),this.xw(this.Um,i),t=this.Um,this.Um=null)),this.uv(t)}xw(t,i){for(const s of t.vn())this.wn(s,i)}Sw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qa()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Eu();break;case 1:s.Wu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Cu();break;case 5:t.Ht.Vu(i)||s.fn(t.Ht.Iu(i))}}tc(t){null!==this.Um?this.Um.mn(t):this.Um=t,this.qm||(this.qm=!0,this.$m=window.requestAnimationFrame(t=>{if(this.qm=!1,this.$m=0,null!==this.Um){const i=this.Um;this.Um=null,this.lw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Vu(t)){this.ti().un(s.Ht);break}}}))}yw(){this.sw()}rw(t){this.Xm.removeChild(t.Jp()),t.m()}sw(){const t=this.ss.qs(),i=t.length,s=this.Wm.length;for(let t=i;t<s;t++){const t=h(this.Wm.pop());this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();const i=this.zm.pop();void 0!==i&&this.rw(i)}for(let n=s;n<i;n++){const i=new Ws(this,t[n]);if(i.Jv().i(this.Cw.bind(this,i),this),i.Qv().i(this.Pw.bind(this,i),this),this.Wm.push(i),n>0){const t=new ys(this,n-1,n);this.zm.push(t),this.Xm.insertBefore(t.Jp(),this.Qm.Jp())}this.Xm.insertBefore(i.Jp(),this.Qm.Jp())}for(let s=0;s<i;s++){const i=t[s],n=this.Wm[s];n._f()!==i?n.zv(i):n.Wv()}this.nw(),this.bw()}Tw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.At().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti()._c(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,o=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,a=this.kw(n);return{Dw:r,Re:t??void 0,Rw:i??void 0,Fw:-1!==a?a:void 0,Vw:l,Iw:e,Lw:o,Aw:s??void 0}}kw(t){let i=-1;if(t)i=this.Wm.indexOf(t);else{const t=this.ti().fc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Cw(t,i,s,n){this.Pv.p(()=>this.Tw(i,s,n,t))}Pw(t,i,s,n){this.Tv.p(()=>this.Tw(i,s,n,t))}Jm(t,i,s){this.mw(this.ti()._c()?.o_??null),this.Ju.p(()=>this.Tw(t,i,s))}nw(){const t=this.Ps.timeScale.visible?"":"none";this.Qm.Jp().style.display=t}dw(){return this.Wm[0]._f().Na().W().visible}pw(){return this.Wm[0]._f().Ua().W().visible}tw(){return"ResizeObserver"in window&&(this.jm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.iw(i.contentRect.width,i.contentRect.height)}),this.jm.observe(this.If,{box:"border-box"}),!0)}hw(){null!==this.jm&&this.jm.disconnect(),this.jm=null}}function Xs(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Gs(t){return void 0===t.open&&void 0===t.value}function Ks(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.color&&(r.R=s.color),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Qs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),e}function sn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function nn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),o=Math.min(...r),a=r[r.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,Dw:n,ne:d,R:c}}function en(t){return void 0!==t.Ht}function rn(t,i){return void 0!==i.customValues&&(t.Bw=i.customValues),t}function hn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Gs(t)}(n,h)?rn({gt:i,Re:s,Dw:e},n):rn(t(i,s,n,e,r),n)}function ln(t){return{Candlestick:hn(sn),Bar:hn(tn),Area:hn(Js),Baseline:hn(Qs),Histogram:hn(Zs),Line:hn(Zs),Custom:hn(nn)}[t]}function on(t){return{Re:0,Ow:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Ew:i.key(t[0].gt),Ww:i.key(t[t.length-1].gt)}}function _n(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Dw)}),h(i)}class un{constructor(t){this.zw=new Map,this.$w=new Map,this.Hw=new Map,this.Nw=[],this.u_=t}m(){this.zw.clear(),this.$w.clear(),this.Hw.clear(),this.Nw=[]}Uw(t,i){let s=0!==this.zw.size,n=!1;const e=this.$w.get(t);if(void 0!==e)if(1===this.$w.size)s=!1,n=!0,this.zw.clear();else for(const i of this.Nw)i.pointData.Ow.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=ln(t.Rr()),l=t.pl(),o=t.vl();r=i.map((i,r)=>{const a=e(i.time),_=this.u_.key(a);let u=this.zw.get(_);void 0===u&&(u=on(a),this.zw.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Ow.set(t,c),c})}s&&this.qw(),this.jw(t,r);let h=-1;if(n){const t=[];this.zw.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:_n(i.Ow)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.Yw(t)}return this.Xw(t,h,function(t,i,s){const n=an(t,s),e=an(i,s);if(void 0!==n&&void 0!==e)return{Gw:!1,Eh:n.Ww>=e.Ww&&n.Ew>=e.Ew}}(this.$w.get(t),e,this.u_))}Ec(t){return this.Uw(t,[])}Kw(t,i,s){const n=i;!function(t){void 0===t.Dw&&(t.Dw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.Hw.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.zw.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=on(e),this.zw.set(this.u_.key(e),h));const o=ln(t.Rr()),a=t.pl(),_=t.vl(),u=o(e,h.Re,i,n.Dw,a,_);h.Ow.set(t,u),s?this.Zw(t,u,h.Re):this.Jw(t,u);const c={Eh:en(u),Gw:s};if(!l)return this.Xw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:_n(h.Ow)},p=yt(this.Nw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Nw.splice(p,0,d);for(let t=p;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Nw,p),this.Xw(t,p,c)}Qw(t,i){const s=this.$w.get(t);if(void 0===s||i<=0)return[[],this.tg()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.Hw.delete(t):this.Hw.set(t,s[s.length-1].gt);for(const i of n){const s=this.zw.get(this.u_.key(i.gt));if(s&&(s.Ow.delete(t),0===s.Ow.size)){this.zw.delete(this.u_.key(s.Uh)),this.Nw.splice(s.Re,1);for(let t=s.Re;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t)}}return[n,this.Xw(t,this.Nw.length-1,{Gw:!1,Eh:!1})]}Jw(t,i){let s=this.$w.get(t);void 0===s&&(s=[],this.$w.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?en(i)&&s.push(i):en(i)?s[s.length-1]=i:s.splice(-1,1),this.Hw.set(t,i.gt)}Zw(t,i,s){const n=this.$w.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);en(i)?n[e]=i:n.splice(e,1)}jw(t,i){0!==i.length?(this.$w.set(t,i.filter(en)),this.Hw.set(t,i[i.length-1].gt)):(this.$w.delete(t),this.Hw.delete(t))}qw(){for(const t of this.Nw)0===t.pointData.Ow.size&&this.zw.delete(this.u_.key(t.time))}Yw(t){let i=-1;for(let s=0;s<this.Nw.length&&s<t.length;++s){const n=this.Nw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,cn(e.pointData,s)}if(-1===i&&this.Nw.length!==t.length&&(i=Math.min(this.Nw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)cn(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Nw=t,i}ig(){if(0===this.$w.size)return null;let t=0;return this.$w.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Xw(t,i,s){const n=this.tg();if(-1!==i)this.$w.forEach((i,e)=>{n.za.set(e,{ne:i,sg:e===t?s:void 0})}),this.$w.has(t)||n.za.set(t,{ne:[],sg:s}),n.At.ng=this.Nw,n.At.eg=i;else{const i=this.$w.get(t);n.za.set(t,{ne:i||[],sg:s})}return n}tg(){return{za:new Map,At:{du:this.ig()}}}}function cn(t,i){t.Re=i,t.Ow.forEach(t=>{t.Re=i})}function dn(t,i){return t.gt<i}function pn(t,i){return i<t.gt}function fn(t,i,s){const n=i.qh(),e=i.yi(),r=yt(t,n,dn),h=St(t,e,pn);if(!s)return{from:r,to:h};let l=r,o=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(o=h+1),{from:l,to:o}}class vn{constructor(t,i,s){this.rg=!0,this.hg=!0,this.lg=!0,this.og=[],this.ag=null,this.Qn=t,this.te=i,this._g=s}Tt(t){this.rg=!0,"data"===t&&(this.hg=!0),"options"===t&&(this.lg=!0)}Dt(){return this.Qn.Vt()?(this.ug(),null===this.ag?null:this.cg):null}dg(){const t=this.Qn.Fh();this.og=this.og.map(i=>{const s=t.Vr(i.gt);return null===s?i:{...i,...s}})}pg(){this.ag=null}ug(){this.hg&&(this.fg(),this.hg=!1),this.lg&&(this.dg(),this.lg=!1),this.rg&&(this.vg(),this.rg=!1)}vg(){const t=this.Qn.$t(),i=this.te.At();if(this.pg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Er())return;const n=this.Qn.Ot();null!==n&&(this.ag=fn(this.og,s,this._g),this.mg(t,i,n.Ht),this.wg())}}class mn{constructor(t,i){this.gg=t,this.Yi=i}et(t,i,s){this.gg.draw(t,this.Yi,i,s)}}class wn extends vn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.cg=new mn(this.eh.renderer(),i=>{const s=t.Ot();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),bg:i.ne}))}mg(t,i){i.pu(this.og,m(this.ag))}wg(){this.eh.update({bars:this.og.map(gn),barSpacing:this.te.At().bu(),visibleRange:this.ag},this.Qn.W())}}function gn(t){return{x:t.ut,time:t.gt,originalData:t.bg,barColor:t.dr}}const bn={color:"#2196f3"},Mn=(t,i,s)=>{const n=o(s);return new wn(t,i,n)};function yn(t){const i={value:t.Ht[3],time:t.Dw};return void 0!==t.Bw&&(i.customValues=t.Bw),i}function Sn(t){const i=yn(t);return void 0!==t.R&&(i.color=t.R),i}function xn(t){const i=yn(t);return void 0!==t.wt&&(i.lineColor=t.wt),void 0!==t.wr&&(i.topColor=t.wr),void 0!==t.gr&&(i.bottomColor=t.gr),i}function Cn(t){const i=yn(t);return void 0!==t.br&&(i.topLineColor=t.br),void 0!==t.Mr&&(i.bottomLineColor=t.Mr),void 0!==t.yr&&(i.topFillColor1=t.yr),void 0!==t.Sr&&(i.topFillColor2=t.Sr),void 0!==t.Cr&&(i.bottomFillColor1=t.Cr),void 0!==t.Pr&&(i.bottomFillColor2=t.Pr),i}function Pn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Dw};return void 0!==t.Bw&&(i.customValues=t.Bw),i}function Tn(t){const i=Pn(t);return void 0!==t.R&&(i.color=t.R),i}function kn(t){const i=Pn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function Dn(t){return{Area:xn,Line:Sn,Baseline:Cn,Histogram:Sn,Bar:Tn,Candlestick:kn,Custom:Rn}[t]}function Rn(t){const i=t.Dw;return{...t.ne,time:i}}const Fn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},Vn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},In={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},Ln={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0,ensureEdgeTickMarksVisible:!1,tickMarkSpacing:2.5},An={rightOffset:0,barSpacing:6,minBarSpacing:.5,maxBarSpacing:0,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0,ignoreWhitespaceIndices:!1};function Bn(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:In,crosshair:Fn,grid:Vn,overlayPriceScales:{...Ln},leftPriceScale:{...Ln,visible:!1},rightPriceScale:{...Ln,visible:!0},timeScale:An,localization:{locale:us?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class On{constructor(t,i,s){this.Up=t,this.Mg=i,this.yg=s??0}applyOptions(t){this.Up.ti().cc(this.Mg,t,this.yg)}options(){return this.Yi().W()}width(){return j(this.Mg)?this.Up.cw(this.Mg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Uo(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().io()){const n=this.Yi().ma(),e=Oi(n);s=oi(s,this.Yi().no()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Up.ti().dc(this.Mg,this.yg)).$t}}class En{constructor(t,i,s,n){this.Up=t,this.Pt=s,this.Sg=i,this.xg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Up.ti(),s=i.jc(this.Pt);i.gc(s,t)}getStretchFactor(){return this.Pt.La()}setStretchFactor(t){this.Pt.Aa(t),this.Up.ti().Ah()}paneIndex(){return this.Up.ti().jc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Up.jp().length,"Invalid pane index"),this.Up.ti().Mc(i,t))}getSeries(){return this.Pt.za().map(t=>this.Sg(t))??[]}getHTMLElement(){const t=this.Up.jp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Jp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.xg,requestUpdate:()=>this.Pt.ti().Ah()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Va(t))throw new Error(`Cannot find price scale with id: ${t}`);return new On(this.Up,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Ea(t)}preserveEmptyPane(){return this.Pt.Wa()}addCustomSeries(t,i={},s=0){return this.xg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.xg.addSeries(t,i,this.paneIndex())}}const Wn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class zn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Cg(){return this.sr}}class $n{constructor(t,i,s,n,e,r){this.Pg=new a,this.Qn=t,this.Tg=i,this.kg=s,this.u_=e,this.xg=n,this.Dg=r}m(){this.Pg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.Ot();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Ot();return null===i?null:this.Qn.$t().Ds(t,i.Ht)}barsInLogicalRange(t){if(null===t)return null;const i=new ki(new Ci(t.from,t.to)).D_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(o.from=n.Dw,o.to=e.Dw),o}setData(t){this.u_,this.Qn.Rr(),this.Tg.Rg(this.Qn,t),this.Fg("full")}update(t,i=!1){this.Qn.Rr(),this.Tg.Vg(this.Qn,t,i),this.Fg("update")}pop(t=1){const i=this.Tg.Ig(this.Qn,t);0!==i.length&&this.Fg("update");const s=Dn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return Dn(this.seriesType())(s)}data(){const t=Dn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Pg.i(t)}unsubscribeDataChanged(t){this.Pg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.kg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(Wn),t),s=this.Qn.zh(i);return new zn(s)}removePriceLine(t){this.Qn.$h(t.Cg())}priceLines(){return this.Qn.Hh().map(t=>new zn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.xg,series:this,requestUpdate:()=>this.Qn.ti().Ah(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Ah()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Dg(i)}moveToPane(t){this.Qn.ti().Hc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.za().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Fg(t){this.Pg.v()&&this.Pg.p(t)}}class Hn{constructor(t,i,s){this.Lg=new a,this.W_=new a,this.ym=new a,this.ss=t,this.ph=t.At(),this.Qm=i,this.ph.Lu().i(this.Ag.bind(this)),this.ph.Au().i(this.Bg.bind(this)),this.Qm.Dm().i(this.Og.bind(this)),this.u_=s}m(){this.ph.Lu().u(this),this.ph.Au().u(this),this.Qm.Dm().u(this),this.Lg.m(),this.W_.m(),this.ym.m()}scrollPosition(){return this.ph.yu()}scrollToPosition(t,i){i?this.ph.Fu(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Ru()}getVisibleRange(){const t=this.ph.hu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph._u(i);this.ss.zc(s)}getVisibleLogicalRange(){const t=this.ph.ru();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.zc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Eu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.fu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.su(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.fu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Qm.Qp().width}height(){return this.Qm.Qp().height}subscribeVisibleTimeRangeChange(t){this.Lg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Lg._(t)}subscribeVisibleLogicalRangeChange(t){this.W_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.W_._(t)}subscribeSizeChange(t){this.ym.i(t)}unsubscribeSizeChange(t){this.ym._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.bu()}}Ag(){this.Lg.v()&&this.Lg.p(this.getVisibleRange())}Bg(){this.W_.v()&&this.W_.p(this.getVisibleLogicalRange())}Og(t){this.ym.p(t.width,t.height)}}function Nn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Un{constructor(t,i,s){this.Eg=new Map,this.Wg=new Map,this.zg=new a,this.$g=new a,this.Hg=new a,this.Xu=new WeakMap,this.Ng=new un(i);const n=void 0===s?f(Bn()):_(f(Bn()),Nn(s));this.Ug=i,this.Up=new Ys(t,n,i),this.Up.Jv().i(t=>{this.zg.v()&&this.zg.p(this.qg(t()))},this),this.Up.Qv().i(t=>{this.$g.v()&&this.$g.p(this.qg(t()))},this),this.Up.vc().i(t=>{this.Hg.v()&&this.Hg.p(this.qg(t()))},this);const e=this.Up.ti();this.jg=new Hn(e,this.Up.ew(),this.Ug)}remove(){this.Up.Jv().u(this),this.Up.Qv().u(this),this.Up.vc().u(this),this.jg.m(),this.Up.m(),this.Eg.clear(),this.Wg.clear(),this.zg.m(),this.$g.m(),this.Hg.m(),this.Ng.m()}resize(t,i,s){this.autoSizeActive()||this.Up.iw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...bn,...t.defaultOptions()},Yg:Mn,Xg:t}))(o(t));return this.Gg(n,i,s)}addSeries(t,i={},s=0){return this.Gg(t,i,s)}removeSeries(t){const i=h(this.Eg.get(t)),s=this.Ng.Ec(i);this.Up.ti().Ec(i),this.Kg(s),this.Eg.delete(t),this.Wg.delete(i)}Rg(t,i){this.Kg(this.Ng.Uw(t,i))}Vg(t,i,s){this.Kg(this.Ng.Kw(t,i,s))}Ig(t,i){const[s,n]=this.Ng.Qw(t,i);return 0!==s.length&&this.Kg(n),s}subscribeClick(t){this.zg.i(t)}unsubscribeClick(t){this.zg._(t)}subscribeCrosshairMove(t){this.Hg.i(t)}unsubscribeCrosshairMove(t){this.Hg._(t)}subscribeDblClick(t){this.$g.i(t)}unsubscribeDblClick(t){this.$g._(t)}priceScale(t,i=0){return new On(this.Up,t,i)}timeScale(){return this.jg}applyOptions(t){this.Up.lr(Nn(t))}options(){return this.Up.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Up.ti().W().crosshair.mode,this.Up.lr({crosshair:{mode:2}})),n=this.Up._w(t)}finally{i||void 0===s||this.Up.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Up.ti().Yc();return i.Ea(t),this.Zg(i)}removePane(t){this.Up.ti().wc(t)}swapPanes(t,i){this.Up.ti().bc(t,i)}autoSizeActive(){return this.Up.fw()}chartElement(){return this.Up.nf()}panes(){return this.Up.ti().qs().map(t=>this.Zg(t))}paneSize(t=0){const i=this.Up.gw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Eg.get(s);if(void 0===n)return;const e=this.Up.ti().Nn(n);null!==e&&this.Up.ti().Vc(t,i,e)}clearCrosshairPosition(){this.Up.ti().Ic(!0)}horzBehaviour(){return this.Ug}Gg(i,s={},n=0){r(void 0!==i.Yg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Oi(i.minMove))}(s.priceFormat),"Candlestick"===i.type&&function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(s);const e=_(f(t),f(i.defaultOptions),s),h=i.Yg,l=new Ut(this.Up.ti(),i.type,e,h,i.Xg);this.Up.ti().Bc(l,n);const o=new $n(l,this,this,this,this.Ug,t=>this.Zg(t));return this.Eg.set(o,l),this.Wg.set(l,o),o}Kg(t){const i=this.Up.ti();i.Lc(t.At.du,t.At.ng,t.At.eg),t.za.forEach((t,i)=>i.lt(t.ne,t.sg)),i.At().Z_(),i.gu()}Jg(t){return h(this.Wg.get(t))}qg(t){const i=new Map;t.Iw.forEach((t,s)=>{const n=s.Rr(),e=Dn(n)(t);if("Custom"!==n)r(Ks(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Jg(s),e)});const s=void 0!==t.Vw&&this.Wg.has(t.Vw)?this.Jg(t.Vw):void 0;return{time:t.Dw,logical:t.Re,point:t.Rw,paneIndex:t.Fw,hoveredSeries:s,hoveredObjectId:t.Lw,seriesData:i,sourceEvent:t.Aw}}Zg(t){let i=this.Xu.get(t);return i||(i=new En(this.Up,t=>this.Jg(t),t,this),this.Xu.set(t,i)),i}}function qn(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function jn(t,i,s){const n=qn(t),e=new Un(n,i,s);return i.setOptions(e.options()),e}function Yn(t,i){return jn(t,new ns,ns.ud(i))}function Xn(){return ns}function Gn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Qg:n.time-h.time}}function Kn(t,i,s){const n=t.timeScale(),e=n.coordinateToTime(s);if(null!==e)return e;const r=n.coordinateToLogical(s);if(null===r)return null;const h=Gn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.Qg)}function Zn(t,i,s){if(null==s)return null;const n=t.timeScale(),e=n.timeToCoordinate(s);if(null!==e)return e;if("number"!=typeof s)return null;const r=Gn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.Qg,l=n.logicalToCoordinate(h);return null===l?null:l}class Jn extends vn{constructor(t,i){super(t,i,!0)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Yo(this.og,s,m(this.ag))}tb(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.ib(i.Re,s,t,i)})}}function Qn(t,i,s,n,e,r,h){if(0===i.length||n.from>=i.length||n.to<=0)return;const{context:l,horizontalPixelRatio:o,verticalPixelRatio:a}=t,_=i[n.from];let u=r(t,_),c=_;if(n.to-n.from<2){const i=e/2;l.beginPath();const s={ut:_.ut-i,ct:_.ct},n={ut:_.ut+i,ct:_.ct};l.moveTo(s.ut*o,s.ct*a),l.lineTo(n.ut*o,n.ct*a),h(t,u,s,n)}else{const e=(i,s)=>{h(t,u,c,s),l.beginPath(),u=i,c=s};let d=c;l.beginPath(),l.moveTo(_.ut*o,_.ct*a);for(let h=n.from+1;h<n.to;++h){d=i[h];const n=r(t,d);switch(s){case 0:l.lineTo(d.ut*o,d.ct*a);break;case 1:l.lineTo(d.ut*o,i[h-1].ct*a),n!==u&&(e(n,d),l.lineTo(d.ut*o,i[h-1].ct*a)),l.lineTo(d.ut*o,d.ct*a);break;case 2:{const[t,s]=ne(i,h-1,h);l.bezierCurveTo(t.ut*o,t.ct*a,s.ut*o,s.ct*a,d.ut*o,d.ct*a);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*o,d.ct*a))}(c!==d||c===d&&1===s)&&h(t,u,c,d)}}const te=6;function ie(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function se(t,i){return{ut:t.ut/i,ct:t.ct/i}}function ne(t,i,s){const n=Math.max(0,i-1),e=Math.min(t.length-1,s+1);var r,h;return[(r=t[i],h=se(ie(t[s],t[n]),te),{ut:r.ut+h.ut,ct:r.ct+h.ct}),ie(t[s],se(ie(t[e],t[i]),te))]}function ee(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class re extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,nb:r,dt:h,Kt:l,eb:o}=this.ht;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=h*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.rb.bind(this);void 0!==r&&Qn(t,i,r,s,e,_,ee),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let o=null;const a=Math.max(1,Math.floor(r))%2/2,_=s*h+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(null!==o&&l.fill(),l.beginPath(),l.fillStyle=i,o=i);const s=Math.round(n.ut*r)+a,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class he extends re{rb(t,i){return i.wt}}class le extends Jn{constructor(){super(...arguments),this.cg=new he}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W(),i={_t:this.og,Kt:t.lineStyle,nb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.ag,sb:this.te.At().bu()};this.cg.lt(i)}}const oe={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new le(t,i)};function ae(t,i){return t.weight>i.weight?t:i}function _e(t){return t}class ue{constructor(){this.hb=new a,this.lb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.hb.p(this.ob)),this.ob=0}ab(){return this.hb}m(){this.hb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.lb(),t=>(t>this.ob&&(this.ob=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this._b(t)}formatTickmark(t){return this._b(t.time)}maxTickMarkWeight(t){return t.reduce(ae,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t%120==0?10:t%60==0?9:t%36==0?8:t%12==0?7:t%6==0?6:t%3==0?5:t%1==0?4:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(_e(t[n].time));this.ob=t[t.length-1].time,this.lb()}_b(t){if(this.Ps.localization?.timeFormatter)return this.Ps.localization.timeFormatter(t);if(t<12)return`${t}M`;const i=Math.floor(t/12),s=t%12;return 0===s?`${i}Y`:`${i}Y${s}M`}}const ce={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},de={lastValueVisible:!1,priceLineVisible:!1};class pe extends Un{constructor(t,i){const s=_(ce,i||{}),n=new ue;super(t,n,s),n.setOptions(this.options()),this._initWhitespaceSeries()}addSeries(t,i={},s=0){if(t.isBuiltIn&&!1===["Area","Line"].includes(t.type))throw new Error("Yield curve only support Area and Line series");const n={...de,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(oe);let s;function n(n){const e=function(t,i){return{ae:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),ub:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ub:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ub:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ab().i(n)}}function fe(t,i){const s=qn(t);return new pe(s,i)}function ve(t,i){return t.weight>i.weight?t:i}class me{options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return t=>t}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return t.toFixed(this.Cn())}formatTickmark(t,i){return t.time.toFixed(this.Cn())}maxTickMarkWeight(t){return t.reduce(ve,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t===100*Math.ceil(t/100)?8:t===50*Math.ceil(t/50)?7:t===25*Math.ceil(t/25)?6:t===10*Math.ceil(t/10)?5:t===5*Math.ceil(t/5)?4:t===Math.ceil(t)?3:2*t===Math.ceil(2*t)?1:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(t[n].time)}Cn(){return this.Ps.localization.precision}}function we(t,i){return jn(t,new me,i)}function ge(t,i,s,n,e){const{context:r,horizontalPixelRatio:h,verticalPixelRatio:l}=i;r.lineTo(e.ut*h,t*l),r.lineTo(n.ut*h,t*l),r.closePath(),r.fillStyle=s,r.fill()}class be extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,dt:r,Kt:h,nb:l}=this.ht,o=this.ht.cb??(this.ht.pb?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,n(a,h),a.lineWidth=1,Qn(t,i,l,s,e,this.fb.bind(this),ge.bind(null,o))}}class Me{mb(t,i){const s=this.wb,{gb:n,bb:e,Mb:r,yb:h,cb:l,Sb:o,xb:a}=i;if(void 0===this.Cb||void 0===s||s.gb!==n||s.bb!==e||s.Mb!==r||s.yb!==h||s.cb!==l||s.Sb!==o||s.xb!==a){const{verticalPixelRatio:s}=t,_=l||o>0?s:1,u=o*_,c=a===t.bitmapSize.height?a:a*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Cb=p,this.wb=i}return this.Cb}}class ye extends be{constructor(){super(...arguments),this.Pb=new Me}fb(t,i){const s=this.ht;return this.Pb.mb(t,{gb:i.yr,bb:i.Sr,Mb:i.Cr,yb:i.Pr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class Se extends re{constructor(){super(...arguments),this.Tb=new Me}rb(t,i){const s=this.ht;return this.Tb.mb(t,{gb:i.br,bb:i.br,Mb:i.Mr,yb:i.Mr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class xe extends Jn{constructor(t,i){super(t,i),this.cg=new x,this.kb=new ye,this.Db=new Se,this.cg.nt([this.kb,this.Db])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.Ot();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.At().bu();if(null===this.ag||0===this.og.length)return;let e,r;if(i.relativeGradient){e=this.og[this.ag.from].ct,r=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const i=this.og[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.kb.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineType,cb:s,Sb:e,xb:r,pb:!1,ot:this.ag,sb:n}),this.Db.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineVisible?i.lineType:void 0,eb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,cb:s,Sb:e,xb:r,ot:this.ag,sb:n})}}const Ce={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new xe(t,i)};class Pe extends be{constructor(){super(...arguments),this.Pb=new Me}fb(t,i){return this.Pb.mb(t,{gb:i.wr,bb:"",Mb:"",yb:i.gr,Sb:this.ht?.Sb??0,xb:t.bitmapSize.height})}}class Te extends Jn{constructor(t,i){super(t,i),this.cg=new x,this.Rb=new Pe,this.Fb=new he,this.cg.nt([this.Rb,this.Fb])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W();if(null===this.ag||0===this.og.length)return;let i;if(t.relativeGradient){i=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const s=this.og[t];s.ct<i&&(i=s.ct)}}this.Rb.lt({nb:t.lineType,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,cb:null,Sb:i,pb:t.invertFilledArea,ot:this.ag,sb:this.te.At().bu()}),this.Fb.lt({nb:t.lineVisible?t.lineType:void 0,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,ot:this.ag,sb:this.te.At().bu(),eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const ke={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new Te(t,i)};class De extends C{constructor(){super(...arguments),this.Yt=null,this.Vb=0,this.Ib=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Vb=this.Lb(i),this.Vb>=2){Math.max(1,Math.floor(i))%2!=this.Vb%2&&this.Vb--}this.Ib=this.Yt.Ab?Math.min(this.Vb,Math.floor(i)):this.Vb;let n=null;const e=this.Ib<=this.Vb&&this.Yt.bu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ib),o=Math.round(h.ut*i),a=o-l,_=this.Ib,u=a+_-1,c=Math.min(h.Zo,h.Jo),d=Math.max(h.Zo,h.Jo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Ib);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Vb);if(e){if(this.Yt.Bb){const i=o-m;let n=Math.max(p,Math.round(h.Ko*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Qo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Lb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).bu,t)))}}class Re extends vn{constructor(t,i){super(t,i,!1)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Go(this.og,s,m(this.ag))}Ob(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Ko:NaN,Zo:NaN,Jo:NaN,Qo:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>this.ib(i.Re,i,t))}}class Fe extends Re{constructor(){super(...arguments),this.cg=new De}ib(t,i,s){return{...this.Ob(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.At().bu(),Bb:t.openVisible,Ab:t.thinBars,ot:this.ag})}}const Ve={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},Yg:(t,i)=>new Fe(t,i)};class Ie extends C{constructor(){super(...arguments),this.Yt=null,this.Vb=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Vb=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.bu,i),this.Vb>=2){Math.floor(i)%2!=this.Vb%2&&this.Vb--}const s=this.Yt.Ks;this.Yt.Eb&&this.Wb(t,s,this.Yt.ot),this.Yt.Mi&&this.pv(t,s,this.Yt.ot);const n=this.zb(i);(!this.Yt.Mi||this.Vb>2*n)&&this.$b(t,s,this.Yt.ot)}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.bu*e));l=Math.max(Math.floor(e),Math.min(l,this.Vb));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Ko,s.Qo)*r),u=Math.round(Math.max(s.Ko,s.Qo)*r),c=Math.round(s.Zo*r),d=Math.round(s.Jo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}zb(t){let i=Math.floor(1*t);this.Vb<=2*i&&(i=Math.floor(.5*(this.Vb-1)));const s=Math.max(Math.floor(t),i);return this.Vb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}pv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.pr!==h&&(n.fillStyle=s.pr,h=s.pr);let a=Math.round(s.ut*e)-Math.floor(.5*this.Vb);const _=a+this.Vb-1,u=Math.round(Math.min(s.Ko,s.Qo)*r),c=Math.round(Math.max(s.Ko,s.Qo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.bu*e>2*l)V(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}$b(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Ko,s.Qo)*r),a=Math.round(Math.max(s.Ko,s.Qo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Vb),u=_+this.Vb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class Le extends Re{constructor(){super(...arguments),this.cg=new Ie}ib(t,i,s){return{...this.Ob(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.At().bu(),Eb:t.wickVisible,Mi:t.borderVisible,ot:this.ag})}}const Ae={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},Yg:(t,i)=>new Le(t,i)};class Be extends C{constructor(){super(...arguments),this.Yt=null,this.Hb=[]}lt(t){this.Yt=t,this.Hb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.Hb.length||this.Nb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Ub*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.Hb[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.qh,a,l.yi-l.qh+1,_-a)}}Nb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.Hb=[]);const i=Math.ceil(this.Yt.bu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.bu*t)-i;this.Hb=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.Hb[i-this.Yt.ot.from]={qh:r,yi:h,qb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.Hb[t-this.Yt.ot.from],n=this.Hb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.qb>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.bu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.qb>i.ee?i.yi-=1:i.qh+=1)}}}class Oe extends Jn{constructor(){super(...arguments),this.cg=new Be}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t={_t:this.og,bu:this.te.At().bu(),ot:this.ag,Ub:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Ot()).Ht)};this.cg.lt(t)}}const Ee={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},Yg:(t,i)=>new Oe(t,i)};class We{constructor(t,i){this.Pt=t,this.jb=i,this.Yb()}detach(){this.Pt.detachPrimitive(this.jb)}getPane(){return this.Pt}applyOptions(t){this.jb.lr?.(t)}Yb(){this.Pt.attachPrimitive(this.jb)}}const ze={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},$e={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class He{constructor(t){this.Xb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Gb(i,t.text);e>s.width?t.Tu=s.width/e:t.Tu=1,n+=t.lineHeight*t.Tu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Tu,t.Tu),i.fillText(t.text,0,t.Kb),i.restore(),e+=t.lineHeight*t.Tu}})}Gb(t,i){const s=this.Zb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Zb(t){let i=this.Xb.get(t);return void 0===i&&(i=new Map,this.Xb.set(t,i)),i}}class Ne{constructor(t){this.Ps=qe(t)}Tt(t){this.Ps=qe(t)}renderer(){return new He(this.Ps)}}function Ue(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Kb:0,Tu:0}}function qe(t){return{...t,lines:t.lines.map(Ue)}}function je(t){return{...$e,...t}}function Ye(t){return{...ze,...t,lines:t.lines?.map(je)??[]}}class Xe{constructor(t){this.Ps=Ye(t),this.Jb=[new Ne(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Jb}attached({requestUpdate:t}){this.Qb=t}detached(){this.Qb=void 0}lr(t){this.Ps=Ye({...this.Ps,...t}),this.Qb&&this.Qb()}}function Ge(t,i){return new We(t,new Xe(i))}const Ke={alpha:1,padding:0};class Ze{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.tM(this.Yt,t.mediaSize);s&&this.Yt.iM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.iM,s.ut,s.ct,s.ts,s.qt))})}tM(t,i){const{maxHeight:s,maxWidth:n,sM:e,nM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class Je{constructor(t){this.eM=null,this.rM=0,this.hM=0,this.Ps=t,this.M=Qe(this.Ps,this.eM,this.rM,this.hM)}lM(t){void 0!==t.oM&&(this.rM=t.oM),void 0!==t.aM&&(this.hM=t.aM),void 0!==t._M&&(this.eM=t._M),this.Tt()}uM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Qe(this.Ps,this.eM,this.rM,this.hM)}renderer(){return new Ze(this.M)}}function Qe(t,i,s,n){return{...t,iM:i,nM:s,sM:n}}function tr(t){return{...Ke,...t}}class ir{constructor(t,i){this.cM=null,this.dM=t,this.Ps=tr(i),this.Jb=[new Je(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt())}paneViews(){return this.Jb}attached(t){const{requestUpdate:i}=t;this.pM=i,this.cM=new Image,this.cM.onload=()=>{const t=this.cM?.naturalHeight??1,i=this.cM?.naturalWidth??1;this.Jb.forEach(s=>s.lM({aM:t,oM:i,_M:this.cM})),this.pM&&this.pM()},this.cM.src=this.dM}detached(){this.pM=void 0,this.cM=null}lr(t){this.Ps=tr({...this.Ps,...t}),this.fM(),this.Qb&&this.Qb()}Qb(){this.pM&&this.pM()}fM(){this.Jb.forEach(t=>t.uM(this.Ps))}}function sr(t,i,s){return new We(t,new ir(i,s))}class nr{constructor(t,i){this.Qn=t,this._h=i,this.Yb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}Yb(){this.Qn.attachPrimitive(this._h)}}const er={autoScale:!0,zOrder:"normal"};function rr(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function hr(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return rr(i,1);case"circle":return rr(i,.8);case"square":case"xcross":return rr(i,.7)}}function lr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(rr(t,1))}function or(t){return Math.max(rr(t,.1),3)}function ar(t){return Math.max(or(t),10)}function _r(t,i,s){return i?t:s?Math.ceil(t/2):0}function ur(t,i,s,n){const e=(hr("arrowUp",n)-1)/2*s.vM,r=(Kt(n/2)-1)/2*s.vM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function cr(t,i,s,n,e,r){const h=(hr("arrowUp",n)-1)/2,l=(Kt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&r>=(t?s:s-h)-2&&r<=(t?s+h:s)+2)return!0;return(()=>{if(e<i-h-3||e>i+h+3||r<(t?s-h-3:s)||r>(t?s:s+h+3))return!1;const n=Math.abs(e-i);return Math.abs(r-s)+3>=n/2})()}function dr(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,o=s+l*n,a=o-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),a),t.quadraticCurveTo(i,o,i+(r?h:-h),a),t.lineTo(i-_,s)}function pr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class fr{constructor(){this.Yt=null,this.Wn=new it,this.mM=new it,this.$=-1,this.H="",this.Uf="",this.wM="",this.gM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Uf=g(t,i),this.wM=g(t,i,"600"),this.Wn.In(),this.mM.In()),this.gM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&mr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.bM;if(t.font=r?this.wM:this.Uf,void 0!==e.hi){const i=r?this.mM:this.Wn;e.hi.ts=i.Vi(t,e.hi.MM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.bM){const t=void 0!==e.hi?e.hi.ts:0;e.bM.ts=Math.max(t+2*e.bM.yM,e.bM.qt),e.bM.qh=e.ut-e.bM.ts/2}vr(e,t,i,s)}}}}function vr(t,i,s,n){void 0===t.bM?(i.fillStyle=t.R,void 0!==t.hi&&pr(i,t.hi.MM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Er)return;switch(t.SM){case"arrowDown":return void ur(!1,i,s,t.Er);case"arrowUp":return void ur(!0,i,s,t.Er);case"circle":return void function(t,i,s){const n=(hr("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.vM,0,2*Math.PI,!1),t.fill()}(i,s,t.Er);case"square":return void function(t,i,s){const n=hr("square",s),e=(n-1)*i.vM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.vM,n*i.vM)}(i,s,t.Er);case"xcross":return void function(t,i,s){const n=(hr("xcross",s)-1)/2*i.vM;t.save(),t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1,Math.round(1.5*i.vM)),t.lineCap="round",t.beginPath(),t.moveTo(i.ut-n,i.ct-n),t.lineTo(i.ut+n,i.ct+n),t.moveTo(i.ut+n,i.ct-n),t.lineTo(i.ut-n,i.ct+n),t.stroke(),t.restore()}(i,s,t.Er);case"tag":return}t.SM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,vM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Er)return;(function(t,i){const s=i.xM,n=i.CM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.PM-i.qt/2)*n),l=Math.round((i.PM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.TM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.kM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.kM&&dr(t,o,h,_,u,!0),t.lineTo(r-a,h),t.arcTo(r,h,r,h+a,a),t.lineTo(r,l-a),t.arcTo(r,l,r-a,l,a),"down"===i.kM&&dr(t,o,l,_,u,!1),t.lineTo(e+a,l),t.arcTo(e,l,e,l-a,a),t.lineTo(e,h+a),t.arcTo(e,h,e+a,h,a)):L(t,e,h,r-e,l-h,[a,a,a,a]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,PM:t.ct,ts:i.ts,qt:i.qt,TM:i.TM,kM:i.kM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,xM:n,CM:e}),void 0!==t.hi&&(s.fillStyle=t.DM??"#FFFFFF",pr(s,t.hi.MM,t.hi.ut,t.hi.ct,n,e))}(t,t.bM,i,s,n)}function mr(t,i,s){return void 0!==t.bM?0!==t.Er&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.kM?i-r-s.TM:i-r,l="down"===s.kM?i+r+s.TM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.bM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Er)return!1;switch(t.SM){case"arrowDown":return cr(!0,t.ut,t.ct,t.Er,i,s);case"arrowUp":return cr(!1,t.ut,t.ct,t.Er,i,s);case"circle":return function(t,i,s,n,e){const r=2+hr("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Er,i,s);case"square":return function(t,i,s,n,e){const r=hr("square",s),h=(r-1)/2,l=t-h,o=i-h;return n>=l&&n<=l+r&&e>=o&&e<=o+r}(t.ut,t.ct,t.Er,i,s);case"xcross":return function(t,i,s,n,e){const r=2+hr("xcross",s)/2;return Math.abs(n-t)<=r&&Math.abs(e-i)<=r}(t.ut,t.ct,t.Er,i,s);case"tag":return!1}}(t,i,s)}function wr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function gr(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(wr(i.position)&&void 0!==i.price)return i.price;if("value"in(n=t)&&"number"==typeof n.value)return t.value;var n;if(function(t){return"open"in t&&"high"in t&&"low"in t&&"close"in t}(t)){if("inBar"===i.position)return t.close;if("aboveBar"===i.position)return s?t.low:t.high;if("belowBar"===i.position)return s?t.high:t.low}}(s,i,a);if(void 0===_)return;const c=wr(i.position),d=o.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),o=Math.round(7*h),a=wr(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.RM)-o-_,a||(n.RM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.FM)+o+_,a||(n.FM+=l+o+r)}const d={qt:l,TM:o,kM:u,vt:i.borderRadius??6,yM:9*h,qh:0,ts:0};t.Er=l,t.ct=c,t.bM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=lr(d.options().barSpacing)*p,v=f/2;t.Er=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.FM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.FM+=1.2*e),void(c||(n.FM+=f+r))}}}class br{constructor(t,i,s){this.VM=[],this.xt=!0,this.IM=!0,this.Jt=new fr,this.be=t,this.Lf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.LM();const t=this.Lf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}AM(t){this.VM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.IM=!0)}BM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}LM(){const t=this.Lf.timeScale(),i=this.VM;this.IM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Er:0,SM:t.shape,R:t.color,Gn:t.id,OM:t.OM,hi:void 0,DM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,bM:void 0})),this.IM=!1);const s=this.Lf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=or(t.options().barSpacing),a=ar(t.options().barSpacing),_={RM:a,FM:a};this.Yt.ot=fn(this.Yt._t,e,!0);for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=i[n];e.time!==h&&(_.RM=a,_.FM=a,h=e.time);const u=this.Yt._t[n];u.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(u.hi={MM:e.text,ut:0,ct:0,ts:0,qt:0});const c=this.be.dataByIndex(e.time,0);null!==c&&gr(u,e,c,_,s.fontSize,o,this.be,this.Lf,r)}this.xt=!1}}function Mr(t){return{...er,...t}}class yr{constructor(t){this.eh=null,this.VM=[],this.EM=[],this.WM=null,this.be=null,this.Lf=null,this.zM=!0,this.$M=null,this.HM=null,this.NM=null,this.UM=!0,this.Ps=Mr(t)}attached(t){this.qM(),this.Lf=t.chart,this.be=t.series,this.eh=new br(this.be,l(this.Lf),this.Ps),this.pM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Fg(t)),this.UM=!0,this.Qb()}Qb(){this.pM&&this.pM()}detached(){this.be&&this.WM&&this.be.unsubscribeDataChanged(this.WM),this.Lf=null,this.be=null,this.eh=null,this.WM=null}AM(t){this.UM=!0,this.VM=t,this.qM(),this.zM=!0,this.HM=null,this.Qb()}jM(){return this.VM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.YM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.XM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=Mr({...this.Ps,...t}),this.Qb&&this.Qb()}XM(){const t=l(this.Lf).timeScale().options().barSpacing;if(this.zM||t!==this.NM){if(this.NM=t,this.VM.length>0){const i=or(t),s=1.5*lr(t)+i+ar(t),n=this.GM();this.$M={above:_r(s,n.aboveBar,n.inBar),below:_r(s,n.belowBar,n.inBar)}}else this.$M=null;this.zM=!1}return this.$M}GM(){return null===this.HM&&(this.HM=this.VM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.HM}qM(){if(!this.UM||!this.Lf||!this.be)return;const t=this.Lf.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.EM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.EM=this.VM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),o={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,OM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Dw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.UM=!1}YM(t){this.eh&&(this.qM(),this.eh.AM(this.EM),this.eh.BM(this.Ps),this.eh.Tt(t))}Fg(t){this.UM=!0,this.Qb()}}class Sr extends nr{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.AM(t)}markers(){return this._h.jM()}}function xr(t,i,s){const n=new Sr(t,new yr(s??{}));return i&&n.setMarkers(i),n}class Cr{constructor(t){this.VM=new Map,this.KM=t}ZM(t,i,s){if(this.JM(i),void 0!==s){const n=window.setTimeout(()=>{this.VM.delete(i),this.QM()},s),e={...t,ty:n,iy:Date.now()+s};this.VM.set(i,e)}else this.VM.set(i,{...t,ty:void 0,iy:void 0});this.QM()}JM(t){const i=this.VM.get(t);i&&void 0!==i.ty&&window.clearTimeout(i.ty),this.VM.delete(t),this.QM()}sy(){for(const[t]of this.VM)this.JM(t)}ny(){const t=Date.now(),i=[];for(const[s,n]of this.VM)!n.iy||n.iy>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.JM(s);return i}ey(t){this.KM=t}QM(){this.KM&&this.KM()}}const Pr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Tr{constructor(t,i,s,n){this.Yt=t,this.hy=i,this.ly=s,this.oy=n}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=Math.max(1,Math.floor(t.horizontalPixelRatio))%2/2,n=4*t.verticalPixelRatio+s;this.Yt.forEach(e=>{const r=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const h=this._y(e.uy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.uy&&(i.strokeStyle=h,i.lineWidth=Math.floor(2*t.horizontalPixelRatio),i.beginPath(),i.moveTo((e.ut-4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.uy-7*e.uy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.stroke())})})}_y(t){return 0===t?this.hy:t>0?this.oy:this.ly}}class kr{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,uy:t.sign}}).filter(v)}renderer(){const t=function(t,i){return function(t,i){return"Area"===i}(0,i)?t.lineColor:t.color}(this.be.options(),this.be.seriesType());return new Tr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Dr(t,i){return"Line"===i||"Area"===i}class Rr{constructor(t){this.Lf=void 0,this.be=void 0,this.Jb=[],this.u_=null,this.py=new Map,this.vy=new Cr(()=>this.Qb()),this.Ps={...Pr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Qb()}AM(t){this.vy.sy();const i=this.u_;i&&t.forEach(t=>{this.vy.ZM(t,i.key(t.time))})}jM(){return this.vy.ny()}Qb(){this.pM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Lf=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Jb=[new kr(this.be,this.Lf.timeScale(),this.Ps)],this.pM=n,this.Qb()}detached(){this.Lf=void 0,this.be=void 0,this.pM=void 0}Xf(){return h(this.Lf)}za(){return h(this.be)}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.jM()))}paneViews(){return this.Jb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.py.clear();const s=this.u_;s&&t.forEach(t=>{Ks(t)&&Dr(0,i)&&this.py.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Gs(t)&&this.py.delete(n),Ks(t)&&Dr(0,s)){const i=this.py.get(n);i&&this.vy.ZM({time:t.time,value:t.value,sign:Fr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}my(){this.vy.sy()}}function Fr(t,i){return t===i?0:t-i>0?1:-1}class Vr extends nr{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.jM()}setMarkers(t){return this._h.AM(t)}clearMarkers(){return this._h.my()}}function Ir(t,i={}){return new Vr(t,new Rr(i))}const Lr={position:"bottom",offset:4,fontSize:11,fontFamily:"",color:"#787B86"};class Ar{constructor(t){this.Yt=t}draw(t){const{_t:i,mf:s,wy:n}=this.Yt;0!==i.length&&t.useMediaCoordinateSpace(({context:t,mediaSize:e})=>{const r="top"===s?n:e.height-n;t.save(),t.textAlign="center",t.textBaseline="top"===s?"top":"bottom";for(const s of i)s.ut<-100||s.ut>e.width+100||(t.font=s.T,t.fillStyle=s.R,t.fillText(s.hi,s.ut,r));t.restore()})}}class Br{constructor(){this.Yt={_t:[],mf:"bottom",wy:0}}Tt(t){this.Yt=t}zOrder(){return"top"}renderer(){return new Ar(this.Yt)}}class Or{constructor(t){this.Lf=null,this.pM=null,this.j_=[],this.eh=new Br,this.Ps={...Lr,...t}}attached(t){this.Lf=t.chart,this.pM=t.requestUpdate,this.pM()}detached(){this.Lf=null,this.pM=null}gy(t){this.j_=t.slice(),this.pM?.()}by(){return this.j_}lr(t){this.Ps={...this.Ps,...t},this.pM?.()}updateAllViews(){const t=this.Lf,i=this.Ps;if(null===t)return void this.eh.Tt({_t:[],mf:i.position,wy:i.offset});const s=t.timeScale(),n=i.fontFamily||t.options().layout.fontFamily,e=[];for(const t of this.j_){const r=s.timeToCoordinate(t.time);null!==r&&e.push({ut:r,hi:t.text,R:t.color??i.color,T:g(t.size??i.fontSize,n)})}this.eh.Tt({_t:e,mf:i.position,wy:i.offset})}paneViews(){return[this.eh]}}class Er extends nr{setLabels(t){this._h.gy(t)}labels(){return this._h.by()}}function Wr(t,i,s){const n=new Er(t,new Or(s));return i&&n.setLabels(i),n}class zr{constructor(t,i){this.My=null,this.yy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.My=xr(t)}addPosition(t){this.yy.push(t),this.Sy()}addPositions(t){this.yy.push(...t),this.Sy()}setPositions(t){this.yy=[...t],this.Sy()}closePosition(t,i,s){const n=this.yy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.Sy())}removePosition(t){this.yy=this.yy.filter(i=>i.id!==t),this.Sy()}clearPositions(){this.yy=[],this.Sy()}getPositions(){return this.yy}applyOptions(t){t.longColors&&(this.Ps.longColors={...this.Ps.longColors,...t.longColors}),t.shortColors&&(this.Ps.shortColors={...this.Ps.shortColors,...t.shortColors}),void 0!==t.defaultSize&&(this.Ps.defaultSize=t.defaultSize),void 0!==t.entryOffset&&(this.Ps.entryOffset=t.entryOffset),void 0!==t.exitOffset&&(this.Ps.exitOffset=t.exitOffset),this.Sy()}xy(){const t=[];for(const i of this.yy){const s="long"===i.type,n=i.size??this.Ps.defaultSize,e=i.color?.entry??(s?this.Ps.longColors.entry:this.Ps.shortColors.entry),r=i.color?.exit??(s?this.Ps.longColors.exit:this.Ps.shortColors.exit),h={time:i.entry.time,position:"atPriceMiddle",price:i.entry.price+this.Ps.entryOffset,shape:s?"arrowUp":"arrowDown",color:e,size:n};if(i.text?.entry&&(h.text=i.text.entry),i.id&&(h.id=`${i.id}-entry`),t.push(h),i.exit){const e={time:i.exit.time,position:"atPriceMiddle",price:i.exit.price+this.Ps.exitOffset,shape:s?"arrowDown":"arrowUp",color:r,size:n};i.text?.exit&&(e.text=i.text.exit),i.id&&(e.id=`${i.id}-exit`),t.push(e)}}return t}Sy(){if(this.My){const t=this.xy();this.My.setMarkers(t)}}detach(){this.My&&(this.My.detach(),this.My=null),this.yy=[]}}function $r(t,i,s){const n=new zr(t,s);return i&&i.length>0&&n.setPositions(i),n}const Hr=new WeakMap;function Nr(t){return"string"==typeof t?t:String(t)}function Ur(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Nr(t.time),t.volume);Hr.set(t,s)}function qr(t,i){return Hr.get(t)?.get(Nr(i))}function jr(t){const i=Hr.get(t);return void 0!==i&&i.size>0}const Yr="rgba(0, 0, 0, 0)";function Xr(t){switch(t.seriesType()){case"Candlestick":return Gr(t,{upColor:Yr,downColor:Yr,borderVisible:!1,wickVisible:!1});case"Bar":return Gr(t,{upColor:Yr,downColor:Yr});case"Line":return Gr(t,{color:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Gr(t,{lineColor:Yr,topColor:Yr,bottomColor:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Gr(t,{topLineColor:Yr,topFillColor1:Yr,topFillColor2:Yr,bottomLineColor:Yr,bottomFillColor1:Yr,bottomFillColor2:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Gr(t,{color:Yr});default:return Gr(t,{visible:!1})}}function Gr(t,i){const s={...i,lastValueVisible:!1,priceLineVisible:!1},n=t.options(),e={};for(const t of Object.keys(s))e[t]=n[t];return t.applyOptions(s),()=>{t.applyOptions(e)}}function Kr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Zr(t,i,s){const n=t.panes();for(const t of n)if(-1!==t.getSeries().indexOf(i))return t.paneIndex();return Math.min(s,Math.max(n.length-1,0))}function Jr(t,i="close"){const s=[];for(const n of t)if(null!=n)if("close"in n)switch(i){case"open":s.push(n.open);break;case"high":s.push(n.high);break;case"low":s.push(n.low);break;case"hl2":s.push((n.high+n.low)/2);break;case"hlc3":s.push((n.high+n.low+n.close)/3);break;case"ohlc4":s.push((n.open+n.high+n.low+n.close)/4);break;default:s.push(n.close)}else s.push("value"in n?n.value:0);else s.push(0);return s}function Qr(t,i){let s=[];return n=>{for(const i of s)try{t.removePriceLine(i)}catch(t){}s=n.filter(t=>null!=t).map(s=>{const n={price:s,color:i,lineWidth:1,lineStyle:2,axisLabelVisible:!1,title:""};return t.createPriceLine(n)})}}function th(t){return null==t?void 0:t.time}function ih(t){const{r_:i,Xf:s,Cy:n,Py:e,Ty:r,Jl:h}=t,l=t.ky??[];let o=t.W,a=[],_=new Map,u=!1;const c=(t,i)=>{if(0===i.length)return;const s=_.get(t),n=i[i.length-1];if(void 0!==s&&s.length>0){const e=i.length===s.length+1,r=i.length===s.length,h=th(s[s.length-1])===th(n);if(e||r&&h)return t.update(n),void _.set(t,i)}t.setData(i),_.set(t,i)},d=t=>{if(!u)try{if("full"===t||0===a.length)a=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;a.length>0&&th(a[a.length-1])===th(t)?a[a.length-1]=t:a.push(t)}if(0===a.length)return;const s=e(a,o);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&a.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==r&&r(o),l.some(t=>i[t]!==o[t])&&(_=new Map,d("full"))},options:()=>({...o}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,a=[]}},recalculate:()=>d("full")};return f}function sh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[];for(let s=i-1;s<n.length;s++){let r=0;for(let t=0;t<i;t++)r+=n[s-t];const h=r/i;t[s]&&t[s].time&&e.push({time:t[s].time,value:h})}return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"SMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function nh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??12,color:s.color??"#FF9800",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[],r=2/(i+1);let h=0;for(let t=0;t<i;t++)h+=n[t];h/=i,t[i-1]&&t[i-1].time&&e.push({time:t[i-1].time,value:h});for(let s=i;s<n.length;s++)h=(n[s]-h)*r+h,t[s]&&t[s].time&&e.push({time:t[s].time,value:h});return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"EMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function eh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,color:s.color??"#4CAF50",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[],r=i*(i+1)/2;for(let s=i-1;s<n.length;s++){let h=0;for(let t=0;t<i;t++){const e=t+1;h+=n[s-i+1+t]*e}const l=h/r;t[s]&&t[s].time&&e.push({time:t[s].time,value:l})}return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"WMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function rh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,stdDev:s.stdDev??2,colorUpper:s.colorUpper??"#3F51B5",colorMiddle:s.colorMiddle??"#2196F3",colorLower:s.colorLower??"#3F51B5",lineWidth:s.lineWidth??1},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Bollinger Bands",W:n,ky:["period","stdDev"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Dy:[],Ry:[],Fy:[]};const n=[];for(const i of t)"close"in i?n.push(i.close):"value"in i?n.push(i.value):n.push(0);const e=[],r=[],h=[];for(let l=i-1;l<n.length;l++){let o=0;for(let t=0;t<i;t++)o+=n[l-t];const a=o/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-a,2);const u=Math.sqrt(_/i),c=a+u*s,d=a-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:a}),h.push({time:i,value:d})}}return{Dy:e,Ry:r,Fy:h}})(t,i.period??20,i.stdDev??2);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1;r.applyOptions({color:t.colorUpper,lineWidth:i}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:r,middle:h,lower:l,...o}}function hh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,atrPeriod:s.atrPeriod??10,multiplier:s.multiplier??2,source:s.source??"close",colorUpper:s.colorUpper??"#787B86",colorMiddle:s.colorMiddle??"#2962FF",colorLower:s.colorLower??"#787B86",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??0},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Keltner Channels",W:n,ky:["period","atrPeriod","multiplier","source"],Py:(t,i)=>{const s=((t,i)=>{const s=i.period??20,n=i.atrPeriod??10,e=i.multiplier??2;if(!t||t.length<Math.max(s,n+1))return{Dy:[],Ry:[],Fy:[]};const r=Jr(t,i.source??"close"),h=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=r[t];h.push(o/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const a=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?a.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):a.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=a[t];_[n-1]=u/n;for(let t=n;t<a.length;t++)_[t]=(_[t-1]*(n-1)+a[t])/n;const c=[],d=[],p=[];for(let i=0;i<h.length;i++){const n=s-1+i,r=t[n],l=_[n-1];if(!r||void 0===r.time||void 0===l)continue;const o=h[i],a=l*e;d.push({time:r.time,value:o}),c.push({time:r.time,value:o+a}),p.push({time:r.time,value:o-a})}return{Dy:c,Ry:d,Fy:p}})(t,i);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min((t.lineWidth??1)+1,4),lineStyle:s}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}}function lh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,colorUpper:s.colorUpper??"#089981",colorMiddle:s.colorMiddle??"#787B86",colorLower:s.colorLower??"#F23645",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??0,showMiddle:s.showMiddle??!0},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Donchian Channels",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{Dy:[],Ry:[],Fy:[]};const s=[],n=[],e=[];for(let r=i-1;r<t.length;r++){let h=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[r-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>h&&(h=n),e<l&&(l=e)}const o=t[r];void 0!==o.time&&h!==-1/0&&l!==1/0&&(s.push({time:o.time,value:h}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(h+l)/2}))}return{Dy:s,Ry:n,Fy:e}})(t,i.period??20);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}}function oh(t,i,s={}){const n={paneIndex:s.paneIndex??0,step:s.step??.02,maxStep:s.maxStep??.2,colorUp:s.colorUp??"#089981",colorDown:s.colorDown??"#F23645",dotSize:s.dotSize??2},e=i.addSeries(oe,{color:n.colorUp,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:n.dotSize},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<3)return[];const r=t[0],h=t[1];if(!("high"in r)||!("low"in r))return[];const l=[];let o=h.close>=r.close,a=o?r.low:r.high,_=o?h.high:h.low,u=i;for(let r=1;r<t.length;r++){const h=t[r],c=t[r-1];if("high"in h&&"low"in h&&(a+=u*(_-a),o?(a=Math.min(a,c.low,t[r-2]?t[r-2].low:c.low),h.low<a?(o=!1,a=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(a=Math.max(a,c.high,t[r-2]?t[r-2].high:c.high),h.high>a?(o=!0,a=_,_=h.high,u=i):h.low<_&&(_=h.low,u=Math.min(u+i,s))),void 0!==h.time)){const t={};t.time=h.time,t.value=a,t.color=o?n:e,l.push(t)}}return l},h=ih({r_:t,Xf:i,Cy:[e],Jl:"Parabolic SAR",W:n,ky:["step","maxStep","colorUp","colorDown"],Py:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}}function ah(t,i){let s;if("number"==typeof t)s=new Date(1e3*t);else if("string"==typeof t)s=new Date(`${t}T00:00:00Z`);else{if(null===t||"object"!=typeof t||!("year"in t))return null;{const i=t;s=new Date(Date.UTC(i.Vy,i.Iy-1,i.Ly))}}if(Number.isNaN(s.getTime()))return null;const n=s.getUTCFullYear();if("monthly"===i)return`${n}-${s.getUTCMonth()}`;if("weekly"===i){const t=new Date(s.getTime()),i=(t.getUTCDay()+6)%7;return t.setUTCDate(t.getUTCDate()-i),`${t.getUTCFullYear()}-${t.getUTCMonth()}-${t.getUTCDate()}`}return`${n}-${s.getUTCMonth()}-${s.getUTCDate()}`}function _h(t,i,s={}){const n={paneIndex:s.paneIndex??0,anchorPeriod:s.anchorPeriod??"daily",color:s.color??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,bandMultiplier:s.bandMultiplier??0,bandColor:s.bandColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color},e),h=i.addSeries(oe,{color:n.bandColor},e),l=i.addSeries(oe,{color:n.bandColor},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"VWAP",W:n,ky:["anchorPeriod","bandMultiplier"],Py:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!jr(t))return{Ay:e,Dy:r,Fy:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=ah(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,o=0,a=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=qr(t,u.time)??0;if(o+=d,a+=c*d,_+=c*c*d,0===o)continue;const p=a/o;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/o-p*p,0),i=Math.sqrt(t)*n;r.push({time:u.time,value:p+i}),h.push({time:u.time,value:p-i})}}return{Ay:e,Dy:r,Fy:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.Ay],[h,n.Dy],[l,n.Fy]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;r.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:r,upper:h,lower:l,...o}}function uh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??10,multiplier:s.multiplier??3,colorUp:s.colorUp??"#089981",colorDown:s.colorDown??"#F23645",lineWidth:s.lineWidth??2},e=i.addSeries(oe,{color:n.colorUp,lineWidth:n.lineWidth},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<i+1)return[];const r=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?r.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):r.push(0)}const h=[];let l=0;for(let t=0;t<i;t++)l+=r[t];h[i-1]=l/i;for(let t=i;t<r.length;t++)h[t]=(h[t-1]*(i-1)+r[t])/i;const o=[];let a=0,_=0,u=!0,c=!1;for(let r=i;r<t.length;r++){const i=t[r],l=t[r-1],d=h[r-1];if(!("high"in i)||!("low"in i)||void 0===d)continue;const p=(i.high+i.low)/2,f=p+s*d,v=p-s*d;if(c?(a=f<a||l.close>a?f:a,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>a&&(u=!0)):(a=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:a,m.color=u?n:e,o.push(m)}return o},h=ih({r_:t,Xf:i,Cy:[e],Jl:"SuperTrend",ky:["period","multiplier","colorUp","colorDown"],W:n,Py:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}}class ch{constructor(t,i,s,n){this.Lf=t,this.be=i,this.I_=s,this.By=n}draw(t){const i=this.By();if(!i.Vt||i.Oy<=0)return;const s=this.I_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Lf.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Ey),u=this.be.priceToCoordinate(h.Wy),c=this.be.priceToCoordinate(l.Ey),d=this.be.priceToCoordinate(l.Wy);if(null===_||null===u||null===c||null===d)continue;const p=h.Ey>=h.Wy;n.fillStyle=this.zy(p?i.$y:i.Hy,i.Oy),n.beginPath(),n.moveTo(o*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class dh{constructor(t,i,s,n){this.Jt=new ch(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function ph(t,i,s){if(i<s-1)return null;let n=-1/0,e=1/0;for(let r=0;r<s;r++){const s=t[i-r],h="high"in s?s.high:s.value,l="low"in s?s.low:s.value;h>n&&(n=h),l<e&&(e=l)}return n===-1/0?null:(n+e)/2}function fh(t,i,s={}){const n={paneIndex:s.paneIndex??0,conversionPeriod:s.conversionPeriod??9,basePeriod:s.basePeriod??26,spanBPeriod:s.spanBPeriod??52,displacement:s.displacement??26,colorConversion:s.colorConversion??"#2962FF",colorBase:s.colorBase??"#F23645",colorSpanA:s.colorSpanA??"#089981",colorSpanB:s.colorSpanB??"#F23645",colorLagging:s.colorLagging??"#787B86",cloudBullishColor:s.cloudBullishColor??"#089981",cloudBearishColor:s.cloudBearishColor??"#F23645",cloudOpacity:s.cloudOpacity??.15,showCloud:s.showCloud??!0,showLagging:s.showLagging??!0,lineWidth:s.lineWidth??1},e=n.paneIndex,r=t=>i.addSeries(oe,{color:t},e),h=r(n.colorConversion),l=r(n.colorBase),o=r(n.colorSpanA),a=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new dh(i,t,()=>u,()=>({$y:c.cloudBullishColor??"#089981",Hy:c.cloudBearishColor??"#F23645",Oy:c.cloudOpacity??.15,Vt:c.showCloud??!0})),p={attached:t=>{},detached:()=>{},paneViews:()=>[d],updateAllViews:()=>{}};t.attachPrimitive(p);const f=(t,i)=>{const s=i.conversionPeriod??9,n=i.basePeriod??26,e=i.spanBPeriod??52,r=i.displacement??26,h=[],l=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{Ny:h,rh:l,Ey:o,Wy:a,Uy:_,qy:u};const c=function(t){if(t.length<3)return null;const i=new Map;let s=null,n=0;for(let e=1;e<t.length;e++){const r=t[e-1].time,h=t[e].time;if("number"!=typeof r||"number"!=typeof h)return null;const l=h-r;if(l<=0)continue;const o=(i.get(l)??0)+1;i.set(l,o),o>n&&(n=o,s=l)}return s}(t),d=i=>{if(i<t.length)return t[i].time;if(null===c)return null;return t[t.length-1].time+c*(i-t.length+1)},p=new Map,f=new Map;for(let i=0;i<t.length;i++){const o=t[i];if(void 0===o.time)continue;const a=ph(t,i,s),u=ph(t,i,n);null!==a&&h.push({time:o.time,value:a}),null!==u&&l.push({time:o.time,value:u}),null!==a&&null!==u&&p.set(i+r,(a+u)/2);const c=ph(t,i,e);null!==c&&f.set(i+r,c);const d=i-r;if(d>=0&&void 0!==t[d].time){const i="close"in o?o.close:o.value;_.push({time:t[d].time,value:i})}}const v=t.length-1+r;for(let t=0;t<=v;t++){const i=d(t);if(null==i)continue;const s=p.get(t),n=f.get(t);if(void 0!==s&&o.push({time:i,value:s}),void 0!==n&&a.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Ey:s,Wy:n};u.push(t)}}return{Ny:h,rh:l,Ey:o,Wy:a,Uy:_,qy:u}},v=ih({r_:t,Xf:i,Cy:[h,l,o,a,_],Jl:"Ichimoku",W:n,ky:["conversionPeriod","basePeriod","spanBPeriod","displacement"],Py:(t,i)=>{c=i;const s=f(t,i);return u=s.qy,[[h,s.Ny],[l,s.rh],[o,s.Ey],[a,s.Wy],[_,i.showLagging??1?s.Uy:[]]]},Ty:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),o.applyOptions({color:t.colorSpanA,lineWidth:s}),a.applyOptions({color:t.colorSpanB,lineWidth:s}),_.applyOptions({color:t.colorLagging,lineWidth:s,visible:t.showLagging??!0}),i.timeScale().applyOptions({})}}),m=v.remove;return{conversion:h,base:l,spanA:o,spanB:a,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}}function vh(t,i,s={}){const n={paneIndex:s.paneIndex??0,pivotPeriod:s.pivotPeriod??"daily",levels:s.levels??3,colorPivot:s.colorPivot??"#FF6D00",colorResistance:s.colorResistance??"#F23645",colorSupport:s.colorSupport??"#089981",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??2},e=n.paneIndex,r=t=>i.addSeries(oe,{color:t},e),h=r(n.colorPivot),l=[r(n.colorResistance),r(n.colorResistance),r(n.colorResistance)],o=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],a=ih({r_:t,Xf:i,Cy:[h,...l,...o],Jl:"Pivot Points",W:n,ky:["pivotPeriod"],Py:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{jy:s,Yy:n,Xy:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=ah(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+o)/3,s=h-l;a={Gy:i,Ky:[2*i-l,i+s,h+2*(i-l)],Zy:[2*i-h,i-s,l-2*(h-i)]},r=t,h=-1/0,l=1/0}const u="high"in _?_.high:_.value,c="low"in _?_.low:_.value;if(u>h&&(h=u),c<l&&(l=c),o="close"in _?_.close:_.value,null!==a&&void 0!==_.time){s.push({time:_.time,value:a.Gy});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Ky[t]}),e[t].push({time:_.time,value:a.Zy[t]})}}return{jy:s,Yy:n,Xy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.jy]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Yy[t]:[]]),e.push([o[t],t<n?s.Xy[t]:[]]);return e},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));h.applyOptions({color:t.colorPivot,lineWidth:i,lineStyle:s});for(let e=0;e<3;e++)l[e].applyOptions({color:t.colorResistance,lineWidth:i,lineStyle:s,visible:e<n}),o[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:o,...a}}function mh(t){return null!=t&&"number"==typeof t.close}function wh(t){const i=[];let s=null,n=null;for(const e of t){if(!mh(e)){null!=e&&i.push({time:e.time,customValues:e.customValues});continue}const t=(e.open+e.high+e.low+e.close)/4,r=null===s||null===n?(e.open+e.close)/2:(s+n)/2;i.push({time:e.time,open:r,high:Math.max(e.high,r,t),low:Math.min(e.low,r,t),close:t,customValues:e.customValues}),s=r,n=t}return i}function gh(t,i,s={}){const n={paneIndex:s.paneIndex??0,upColor:s.upColor??"#26a69a",downColor:s.downColor??"#ef5350",borderVisible:s.borderVisible??!0,borderUpColor:s.borderUpColor??"#26a69a",borderDownColor:s.borderDownColor??"#ef5350",wickVisible:s.wickVisible??!0,wickUpColor:s.wickUpColor??"#26a69a",wickDownColor:s.wickDownColor??"#ef5350",hideSource:s.hideSource??!0},e=t.options(),r=i.addSeries(Ae,{upColor:n.upColor,downColor:n.downColor,borderVisible:n.borderVisible,borderUpColor:n.borderUpColor,borderDownColor:n.borderDownColor,wickVisible:n.wickVisible,wickUpColor:n.wickUpColor,wickDownColor:n.wickDownColor,priceScaleId:e.priceScaleId,priceFormat:e.priceFormat,lastValueVisible:e.lastValueVisible,priceLineVisible:e.priceLineVisible},n.paneIndex);let h=null;const l=i=>{i&&null===h?(h=Xr(t),r.setSeriesOrder(t.seriesOrder())):i||null===h||(h(),h=null,r.setSeriesOrder(t.seriesOrder()+1))},o=ih({r_:t,Xf:i,Cy:[r],Jl:"Heikin Ashi",W:n,ky:[],Py:t=>[[r,wh(t)]],Ty:t=>{r.applyOptions({upColor:t.upColor,downColor:t.downColor,borderVisible:t.borderVisible,borderUpColor:t.borderUpColor,borderDownColor:t.borderDownColor,wickVisible:t.wickVisible,wickUpColor:t.wickUpColor,wickDownColor:t.wickDownColor}),l(!0===t.hideSource)}});return{series:r,options:o.options,applyOptions:o.applyOptions,recalculate:o.recalculate,remove:()=>{o.remove();try{l(!1)}catch(t){}}}}function bh(t,i,s={}){const n={paneIndex:s.paneIndex??1,period:s.period??14,color:s.color??"#9C27B0",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?70:s.overbought,oversold:void 0===s.oversold?30:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Kr(0,100)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Qr(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Jr(t,s),e=[],r=[];for(let t=1;t<n.length;t++)r.push(n[t]-n[t-1]);let h=0,l=0;for(let t=0;t<i;t++)r[t]>0?h+=r[t]:l+=Math.abs(r[t]);h/=i,l/=i;let o=0===l?100:h/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<r.length;s++){const n=r[s];h=(h*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:h/l,a=100-100/(1+o),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:a})}return e},a=ih({r_:t,Xf:i,Cy:[r],Jl:"RSI",W:n,ky:["period","source"],Py:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function Mh(t,i,s={}){const n={paneIndex:s.paneIndex??2,fastPeriod:s.fastPeriod??12,slowPeriod:s.slowPeriod??26,signalPeriod:s.signalPeriod??9,colorMACD:s.colorMACD??"#2196F3",colorSignal:s.colorSignal??"#FF6D00",colorHistogramUp:s.colorHistogramUp??"#26a69a",colorHistogramDown:s.colorHistogramDown??"#ef5350",lineWidth:s.lineWidth??2},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorMACD},e),h=Zr(i,r,e),l=i.addSeries(oe,{color:n.colorSignal},h),o=i.addSeries(Ee,{color:n.colorHistogramUp},h),a=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},_=ih({r_:t,Xf:i,Cy:[r,l,o],Jl:"MACD",W:n,ky:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],Py:(t,i)=>{const s=((t,i)=>{const s=i.fastPeriod??12,n=i.slowPeriod??26,e=i.signalPeriod??9;if(!t||t.length<n+e)return{Jy:[],Qy:[],tS:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=a(r,s),l=a(r,n),o=[],_=n-s;for(let t=0;t<l.length;t++)o.push(h[t+_]-l[t]);const u=a(o,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=o[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Jy:c,Qy:d,tS:p}})(t,i);return[[r,s.Jy],[l,s.Qy],[o,s.tS]]},Ty:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),l.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:l,histogram:o,..._}}function yh(t,i,s={}){const n={paneIndex:s.paneIndex??4,kPeriod:s.kPeriod??14,dPeriod:s.dPeriod??3,colorK:s.colorK??"#2196F3",colorD:s.colorD??"#FF6D00",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?80:s.overbought,oversold:void 0===s.oversold?20:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=Kr(0,100),h=i.addSeries(oe,{color:n.colorK,autoscaleInfoProvider:r},e),l=Zr(i,h,e),o=i.addSeries(oe,{color:n.colorD,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Qr(h,n.levelColor),_=ih({r_:t,Xf:i,Cy:[h,o],Jl:"Stochastic",W:n,ky:["kPeriod","dPeriod"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{iS:[],sS:[]};const n=[];for(let s=i-1;s<t.length;s++){let e=-1/0,r=1/0;for(let n=0;n<i;n++){const i=t[s-n];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[s];if("close"in h){const t=(h.close-r)/(e-r)*100;n.push(t)}}const e=[];for(let s=0;s<n.length;s++){const r=i-1+s;t[r]&&t[r].time&&e.push({time:t[r].time,value:n[s]})}const r=[];if(n.length>=s)for(let e=s-1;e<n.length;e++){let h=0;for(let t=0;t<s;t++)h+=n[e-t];const l=h/s,o=i-1+e;t[o]&&t[o].time&&r.push({time:t[o].time,value:l})}return{iS:e,sS:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.iS],[o,s.sS]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:o,..._}}function Sh(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=(t,i)=>{if(!t||t.length<i+1)return[];const s=[];for(let i=1;i<t.length;i++){const n=t[i],e=t[i-1];if("high"in n&&"low"in n&&"close"in e){const t=n.high-n.low,i=Math.abs(n.high-e.close),r=Math.abs(n.low-e.close),h=Math.max(t,i,r);s.push(h)}}if(s.length<i)return[];const n=[];let e=0;for(let t=0;t<i;t++)e+=s[t];e/=i,t[i]&&t[i].time&&n.push({time:t[i].time,value:e});for(let r=i;r<s.length;r++)e=(e*(i-1)+s[r])/i,t[r+1]&&t[r+1].time&&n.push({time:t[r+1].time,value:e});return n},h=ih({r_:t,Xf:i,Cy:[e],Jl:"ATR",W:n,ky:["period"],Py:(t,i)=>[[e,r(t,i.period??14)]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function xh(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Ee,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.8,bottom:0}});const l=(i,s)=>{const n=t.data();if(!n||0===n.length||!jr(t))return[];const e=[];for(const r of n){const n=qr(t,r.time);n&&"close"in r&&"open"in r&&e.push({time:r.time,value:n,color:r.close>=r.open?i:s})}return e},o=ih({r_:t,Xf:i,Cy:[r],Jl:"Volume",W:n,ky:["colorUp","colorDown"],Py:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...o}}function Ch(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!jr(t))return[];const s=[];let n=0;s.push({time:i[0].time,value:n});for(let e=1;e<i.length;e++){const r=i[e],h=i[e-1],l=qr(t,r.time);l&&"close"in r&&"close"in h&&(r.close>h.close?n+=l:r.close<h.close&&(n-=l),s.push({time:r.time,value:n}))}return s},h=ih({r_:t,Xf:i,Cy:[e],Jl:"OBV",W:n,Py:()=>[[e,r()]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function Ph(t,i,s={}){const n={paneIndex:s.paneIndex??7,period:s.period??14,colorADX:s.colorADX??"#F23645",colorPlusDI:s.colorPlusDI??"#089981",colorMinusDI:s.colorMinusDI??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,threshold:void 0===s.threshold?25:s.threshold,levelColor:s.levelColor??"#787B86",showDI:s.showDI??!0},e=n.paneIndex,r=Kr(0,100),h=i.addSeries(oe,{color:n.colorADX,autoscaleInfoProvider:r},e),l=Zr(i,h,e),o=i.addSeries(oe,{color:n.colorPlusDI,autoscaleInfoProvider:r},l),a=i.addSeries(oe,{color:n.colorMinusDI,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Qr(h,n.levelColor),u=ih({r_:t,Xf:i,Cy:[h,o,a],Jl:"ADX",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{nS:[],eS:[],rS:[]};const s=[],n=[],e=[];for(let i=1;i<t.length;i++){const r=t[i],h=t[i-1];if(!("high"in r)||!("low"in r)||!("close"in h)){s.push(0),n.push(0),e.push(0);continue}s.push(Math.max(r.high-r.low,Math.abs(r.high-h.close),Math.abs(r.low-h.close)));const l=r.high-h.high,o=h.low-r.low;n.push(l>o&&l>0?l:0),e.push(o>l&&o>0?o:0)}let r=0,h=0,l=0;for(let t=0;t<i;t++)r+=s[t],h+=n[t],l+=e[t];const o=[],a=[],_=[],u=[];for(let c=i;c<s.length;c++){r=r-r/i+s[c],h=h-h/i+n[c],l=l-l/i+e[c];const d=0===r?0:h/r*100,p=0===r?0:l/r*100,f=d+p,v=0===f?0:Math.abs(d-p)/f*100;u.push(v);const m=t[c+1];if(m&&void 0!==m.time)if(a.push({time:m.time,value:d}),_.push({time:m.time,value:p}),u.length===i){let t=0;for(const i of u)t+=i;o.push({time:m.time,value:t/i})}else if(u.length>i){const t=o[o.length-1].value;o.push({time:m.time,value:(t*(i-1)+v)/i})}}return{nS:o,eS:a,rS:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.nS],[o,n?s.eS:[]],[a,n?s.rS:[]]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),a.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:o,minusDI:a,...u}}function Th(t,i,s={}){const n={paneIndex:s.paneIndex??8,period:s.period??20,color:s.color??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?100:s.overbought,oversold:void 0===s.oversold?-100:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(const i of t)"high"in i&&"low"in i&&"close"in i?s.push((i.high+i.low+i.close)/3):s.push("value"in i?i.value:0);const n=[];for(let e=i-1;e<s.length;e++){let r=0;for(let t=0;t<i;t++)r+=s[e-t];const h=r/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-h);const o=l/i,a=0===o?0:(s[e]-h)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=ih({r_:t,Xf:i,Cy:[r],Jl:"CCI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??20)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function kh(t,i,s={}){const n={paneIndex:s.paneIndex??9,period:s.period??14,color:s.color??"#FF6D00",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?-20:s.overbought,oversold:void 0===s.oversold?-80:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Kr(-100,0)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(let n=i-1;n<t.length;n++){let e=-1/0,r=1/0;for(let s=0;s<i;s++){const i=t[n-s];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[n];if(!("close"in h)||void 0===h.time)continue;const l=e-r,o=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:o})}return s},a=ih({r_:t,Xf:i,Cy:[r],Jl:"Williams %R",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function Dh(t,i,s={}){const n={paneIndex:s.paneIndex??10,period:s.period??14,color:s.color??"#9C27B0",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?80:s.overbought,oversold:void 0===s.oversold?20:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Kr(0,100)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!jr(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const r=i[s],h=i[s-1];if(!("high"in r)||!("low"in r)||!("close"in r)){n.push(0),e.push(0);continue}const l=(r.high+r.low+r.close)/3,o=(h.high+h.low+h.close)/3,a=l*(qr(t,r.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const r=[];for(let t=s-1;t<n.length;t++){let h=0,l=0;for(let i=0;i<s;i++)h+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+h/l),a=i[t+1];a&&void 0!==a.time&&r.push({time:a.time,value:o})}return r},a=ih({r_:t,Xf:i,Cy:[r],Jl:"MFI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}class Rh{constructor(t){this.hS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.hS.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.lS(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}lS(t,i,s,n){const e=i.oS||i.startTime,r=i.aS||i.endTime,h=i.R||i.color,l=i.Oy||i.opacity;if(!i||!e||!r)return;const o=this.hS.getChart().timeScale(),a=o.timeToCoordinate(e),_=o.timeToCoordinate(r);if(null===a||null===_)return;const u=a*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this._S(h,l),t.fillRect(u,d,c-u,p-d)}_S(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Fh{constructor(t){this.Jt=new Rh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const Vh=[{name:"Tokyo",startHour:0,endHour:9,color:"#FF6B00",opacity:.1},{name:"London",startHour:8,endHour:17,color:"#2962FF",opacity:.1},{name:"New York",startHour:13,endHour:22,color:"#089981",opacity:.1}];class Ih{constructor(t,i,s={}){this.uS=[],this.jb=null,this.eh=null,this.Lf=t,this.be=i,this.Ps={sessions:s.sessions||Vh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.cS(),this.Ps.enabled&&this.dS()}cS(){this.eh=new Fh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}dS(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.pS()}),this.pS()}pS(){this.fS();const t=this.Lf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);this.vS(s),this.pM()}vS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.mS(i,t);this.Ps.showOverlaps&&this.wS(t)}}mS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.gS(i);this.bS(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.MS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.MS(s,n[n.length-1].time,t)}wS(t){const i=this.Ps.sessions;for(let s=0;s<i.length;s++)for(let n=s+1;n<i.length;n++){const e=i[s],r=i[n],h=this.yS(e,r);h&&this.SS(h,t)}}yS(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{ae:s,_e:n}:null}SS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.gS(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.xS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.xS(s,n[n.length-1].time)}MS(t,i,s){if(!t||!i)return void console.warn("Invalid session box times:",{startTime:t,endTime:i,session:s.name});const n={an:"session",oS:t,aS:i,R:s.color,Oy:s.opacity,CS:s.name};this.uS.push(n)}xS(t,i){const s={an:"overlap",oS:t,aS:i,R:this.Ps.overlapColor,Oy:this.Ps.overlapOpacity,CS:"Overlap"};this.uS.push(s)}bS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}gS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}fS(){this.uS=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.pS():this.fS(),this.pM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.pS(),this.pM()}disable(){this.Ps.enabled=!1,this.fS(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.fS(),this.pM()}getSessionBoxes(){return this.uS}getChart(){return this.Lf}getSeries(){return this.be}pM(){this.jb&&this.jb.updateAllViews?.(),this.Lf.timeScale().applyOptions({})}}function Lh(t,i,s){return new Ih(t,i,s)}class Ah{constructor(t){this.hS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.hS.getProfileData();if(!s||0===s.bins.length)return;const n=this.hS.options(),e=this.hS.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let o=0;for(const t of s.bins)t.volume>o&&(o=t.volume);if(0!==o){for(const r of s.bins)this.PS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.TS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.kS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}PS(t,i,s,n,e,r,h,l,o,a){const _=i.volume/e*n,u=r.binSize/2,c=l.priceToCoordinate(i.priceLevel+u),d=l.priceToCoordinate(i.priceLevel-u);if(null===c||null===d)return;const p=Math.max(Math.abs(d-c)-1,1),f=s*o,v=Math.min(c,d)*a,m=_*o,w=p*a,g=i.priceLevel>=r.valueAreaLow&&i.priceLevel<=r.valueAreaHigh,b=Math.abs(i.priceLevel-r.poc)<1e-5;let M=h.profileColor||"#2962FF",y=h.opacity||.3;b?(M=h.pocColor||"#FF6B00",y=.6):g&&h.showValueArea&&(M=h.valueAreaColor||"#089981",y=.4),t.fillStyle=this._S(M,y),t.fillRect(f,v,m,w)}TS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const o=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,o),t.lineTo(e*r,o),t.stroke(),t.setLineDash([])}kS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this._S(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}const a=e.priceToCoordinate(s);if(null!==a){const i=a*l;t.strokeStyle=this._S(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}t.setLineDash([])}_S(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Bh{constructor(t){this.Jt=new Ah(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Oh{constructor(t,i,s={}){this.DS=null,this.RS=new Map,this.jb=null,this.eh=null,this.Lf=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.cS(),this.dS()}cS(){this.eh=new Bh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}dS(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.FS()}),this.FS()}setVolumeData(t){this.RS=t,this.FS()}addVolumeData(t,i){this.RS.set(t,i),this.FS()}FS(){const t=this.Lf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);if(0===s.length)return;let n=1/0,e=-1/0;for(const t of s){const i=t.low||t.value||t.close,s=t.high||t.value||t.close;i<n&&(n=i),s>e&&(e=s)}const r=(e-n)/this.Ps.numberOfBins,h=[];for(let t=0;t<this.Ps.numberOfBins;t++)h.push({priceLevel:n+(t+.5)*r,volume:0,percentage:0});let l=0;for(const t of s){const i=t.close||t.value,s=this.RS.get(t.time)||1,e=Math.floor((i-n)/r);h[Math.max(0,Math.min(this.Ps.numberOfBins-1,e))].volume+=s,l+=s}for(const t of h)t.percentage=l>0?t.volume/l*100:0;let o=h[0];for(const t of h)t.volume>o.volume&&(o=t);const a=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<a))break;c.push(t),u+=t.volume}let d=-1/0,p=1/0;for(const t of c)t.priceLevel>d&&(d=t.priceLevel),t.priceLevel<p&&(p=t.priceLevel);this.DS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.pM()}getProfileData(){return this.DS}applyOptions(t){this.Ps={...this.Ps,...t},this.FS(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.DS=null,this.RS.clear(),this.pM()}getChart(){return this.Lf}getSeries(){return this.be}options(){return this.Ps}pM(){this.jb&&this.jb.updateAllViews?.(),this.Lf.timeScale().applyOptions({})}}function Eh(t,i,s){return new Oh(t,i,s)}function Wh(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)}class zh{constructor(t,i){this.VS=new Map,this.IS=null,this.LS=null,this.AS=null,this.BS=null,this.OS=null,this.ES=null,this.WS=!1,this.zS=0,this.$S=null,this.yg=void 0,this.Lf=t,this.Rf=i,this.HS=t=>this.NS(t),this.US=t=>this.qS(t),this.jS=t=>this.YS(t),this.XS=t=>this.GS(t),this.KS=()=>this.ZS(),this.JS=t=>{"Escape"===t.key&&this.ZS()},this.Lf.subscribeCrosshairMove(this.HS),this.Rf.addEventListener("pointerdown",this.US),this.Rf.addEventListener("pointermove",this.jS),this.Rf.addEventListener("pointerup",this.XS),this.Rf.addEventListener("pointercancel",this.KS),document.addEventListener("keydown",this.JS)}QS(t){this.VS.set(t.id(),t)}tx(t){const i=t.id();this.IS===i&&this.ix(null),this.AS===t&&this.ZS(),this.VS.delete(i)}Gi(){return 0===this.VS.size}m(){this.Lf.unsubscribeCrosshairMove(this.HS),this.Rf.removeEventListener("pointerdown",this.US),this.Rf.removeEventListener("pointermove",this.jS),this.Rf.removeEventListener("pointerup",this.XS),this.Rf.removeEventListener("pointercancel",this.KS),document.removeEventListener("keydown",this.JS),this.VS.clear()}NS(t){if(this.$S=t.point?{ut:t.point.x,ct:t.point.y}:null,this.yg=t.paneIndex,null!==this.AS)return;const i=this.sx(t.hoveredObjectId),s=null===i?null:this.VS.get(i.gl)??null;this.ix(s?s.id():null),this.nx(s,null===s?null:i?.hx??null),this.lx()}qS(t){this.WS="mouse"!==t.pointerType;let i=this.WS||null===this.IS?null:this.VS.get(this.IS)??null;null===i&&(i=this.ox(t)),i?(this.OS={ut:t.clientX,ct:t.clientY},this.ES=i,i.isDraggable()&&(this.AS=i,this.BS=t.pointerId,this.Rf.setPointerCapture(t.pointerId),i.beginDrag(),this.zS=this._x(i,t),this.lx(),t.preventDefault(),t.stopPropagation())):this.ux()}YS(t){if(null===this.AS)return;if(!this.vx(t))return void this.ZS();const i=this.mx(t);null!==i&&this.AS.dragTo(i),t.preventDefault(),t.stopPropagation()}GS(t){const i=this.AS,s=this.WS,n=this.ES,e=this.OS;this.wx(),this.ES=null,this.OS=null;const r=s?12:4,h=null!==e&&(Math.abs(t.clientX-e.ut)>r||Math.abs(t.clientY-e.ct)>r);if(null!==i)return this.AS=null,this.zS=0,h?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),this.ux(s),void this.lx();null!==n&&!h&&n.isClickable()&&n.click(),this.ux(s)}ux(t=this.WS){if(!t||null===this.IS)return;const i=this.VS.get(this.IS)??null;this.ix(null),this.nx(i,null),this.lx()}ZS(){if(null===this.AS)return;const t=this.AS;this.AS=null,this.zS=0,this.wx(),t.cancelDrag(),this.lx()}vx(t){const i=this.Rf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}wx(){null!==this.BS&&(this.Rf.hasPointerCapture(this.BS)&&this.Rf.releasePointerCapture(this.BS),this.BS=null)}mx(t){const i=this.AS;if(null===i)return null;const s=this.gx(i,t);return null===s?null:i.priceAt(s-this.zS)}ox(t){for(const i of this.VS.values()){if(!i.hitTestAt)continue;const s=this.bx(i);if(null===s)continue;const n=s.getBoundingClientRect(),e="mouse"===t.pointerType?0:12,r=this.sx(i.hitTestAt(t.clientX-n.left,t.clientY-n.top,e));if(null!==r)return this.ix(i.id()),this.nx(i,r.hx),i}return null}bx(t){const i=this.Lf.panes()[t.paneIndex()];return i?i.getHTMLElement():null}gx(t,i){const s=this.bx(t);return s?i.clientY-s.getBoundingClientRect().top:null!==this.$S&&this.yg===t.paneIndex()?this.$S.ct:null}_x(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.gx(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}sx(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,hx:null}:{gl:t.slice(0,i),hx:t.slice(i+1)}}nx(t,i){this.LS!==i&&(this.LS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}ix(t){this.IS!==t&&(null!==this.IS&&this.VS.get(this.IS)?.setHovered(!1),this.IS=t,this.LS=null,null!==t&&this.VS.get(t)?.setHovered(!0))}lx(){if(null!==this.AS)return void this.Lf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.IS?null:this.VS.get(this.IS);t?this.Lf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Lf.chartElement().style.removeProperty("cursor")}}const $h=new WeakMap;function Hh(t){const i=t.chartElement();if(!i)return null;let s=$h.get(t);return s||(s=new zh(t,i),$h.set(t,s)),s}function Nh(t,i){const s=$h.get(t);s&&(s.tx(i),s.Gi()&&(s.m(),$h.delete(t)))}let Uh=0;class qh{constructor(t,i,s){this.sr=null,this.Mx=!1,this.yx="",this.Sx=null,this.Lf=t,this.be=i,this.So="pipsend-trading-line-"+Uh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.xx(),(this.Ps.draggable||this.Ps.onClick)&&Hh(this.Lf)?.QS(this)}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.Mx!==t&&this.sr&&(this.Mx=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.yx}))}hitTestAt(t,i,s=0){const n=this.be.priceToCoordinate(this.Ps.price);return null!==n&&Math.abs(i-n)<=8+s?this.So:null}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.Sx=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.Cx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.Sx=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.Sx;this.Sx=null,null!==t&&t!==this.Ps.price&&(this.Cx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t))}click(){this.Ps.onClick&&this.Ps.onClick(this.Ps.price)}applyOptions(t){if(this.Ps={...this.Ps,...t},t.color&&(this.yx=t.color),!this.sr)return;const i={title:this.Px()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.Mx||(i.color=t.color),void 0!==t.lineWidth&&(i.lineWidth=t.lineWidth),void 0!==t.lineStyle&&(i.lineStyle=t.lineStyle),this.sr.applyOptions(i)}setTitle(t){this.Ps.title=t,this.sr&&this.sr.applyOptions({title:t})}getPrice(){return this.Ps.price}setPrice(t){this.Cx(t)}remove(){Nh(this.Lf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}Px(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}xx(){this.yx=this.Ps.color,this.sr=this.be.createPriceLine({id:this.So,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.Px()})}Cx(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.Px()})}}function jh(t,i,s){const n={"stop-loss":{color:"#ef5350",lineStyle:2,title:"Stop Loss",draggable:!0},"take-profit":{color:"#26a69a",lineStyle:2,title:"Take Profit",draggable:!0},entry:{color:"#2196F3",lineStyle:0,title:"Entry",draggable:!0},target:{color:"#FF9800",lineStyle:2,title:"Target",draggable:!0},resistance:{color:"#f44336",lineStyle:0,title:"Resistance",draggable:!0},support:{color:"#4CAF50",lineStyle:0,title:"Support",draggable:!0},custom:{color:"#9E9E9E",lineStyle:0,title:"",draggable:!0}},e=s.type?n[s.type]:n.custom,r={price:s.price,color:s.color??e.color??"#9E9E9E",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??e.lineStyle??0,title:s.title??e.title??"",axisLabelVisible:s.axisLabelVisible??!0,draggable:s.draggable??e.draggable??!0,onDragStart:s.onDragStart,onDragMove:s.onDragMove,onDragEnd:s.onDragEnd,onClick:s.onClick,formatTitle:s.formatTitle};return new qh(i,t,r)}class Yh{constructor(t,i){this.If=null,this.Tx=null,this.kx=null,this.Dx={},this.Lf=t,this.be=i,this.Rx()}Rx(){this.If=this.Lf.chartElement()}Fx(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.If?(this.Tx=t,this.Dx=i||{},new Promise(t=>{this.If.style.cursor="crosshair",this.kx=i=>{const s=this.Fx(i),n=this.Vx(s);this.disableClickToCreate(),t(n)},this.If.addEventListener("click",this.kx)})):Promise.resolve(null)}disableClickToCreate(){this.If&&this.kx&&(this.If.removeEventListener("click",this.kx),this.If.style.cursor="default"),this.Tx=null,this.kx=null,this.Dx={}}Vx(t){if(!this.Tx)return null;let i;switch(this.Tx){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.Dx};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.Dx};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.Dx};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.Dx};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.Dx};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.Dx};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.Dx};break;default:return null}return new qh(this.Lf,this.be,i)}getCreationMode(){return this.Tx}isCreating(){return null!==this.Tx}}function Xh(t,i){return new Yh(t,i)}class Gh{constructor(){this.Ix=[],this.Lx=new Map,this.Ax=new Map,this.xt=!0}QS(t){this.Lx.has(t)||(this.Ix.push(t),this.Lx.set(t,[]),this.xt=!0)}tx(t){const i=this.Ix.indexOf(t);-1!==i&&this.Ix.splice(i,1),this.Lx.delete(t),this.xt=!0}Gi(){return 0===this.Ix.length}Bx(t,i){const s=this.Lx.get(t);this.Lx.set(t,i),void 0!==s&&function(t,i){if(t.length!==i.length)return!1;for(let s=0;s<t.length;s++)if(t[s].sn!==i[s].sn||t[s].ct!==i[s].ct||t[s].qt!==i[s].qt)return!1;return!0}(s,i)||(this.xt=!0)}Ox(t,i){return this.xt&&this.Ex(),this.Ax.get(Kh(t,i))??0}Ex(){const t=new Map,i=[];for(const s of this.Ix)for(const n of this.Lx.get(s)??[]){const e=Zh(n.qt),r=n.qt;let h=n.ct;for(const t of i){if(t.ct>=h+e)break;Math.abs(h-t.ct)<e&&(h=t.ct+e)}let l=h-n.ct;l>r&&(l=0),Jh(i,{ct:n.ct+l,qt:n.qt}),t.set(Kh(s,n.sn),l)}this.Ax=t,this.xt=!1}}function Kh(t,i){return`${t}:${i}`}function Zh(t){return Math.max(9,Math.round(.4*t))}function Jh(t,i){let s=0,n=t.length;for(;s<n;){const e=s+n>>1;t[e].ct<=i.ct?s=e+1:n=e}t.splice(s,0,i)}const Qh=new WeakMap;const tl={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},il={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},sl=["takeProfit","entry","stopLoss"];class nl{constructor(){this.Yt=null,this.Wx=[],this.zx=0,this.Uf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i,s=0){for(const n of this.Wx)if(n.$x&&t>=n.Hx-s&&t<=n.Nx+s&&Math.abs(i-n.Ux)<=n.qt/2+s)return{sn:n.sn,hx:"close"};for(const n of this.Wx)if(t>=n.qx-s&&t<=n.jx+s&&Math.abs(i-n.Ux)<=n.qt/2+s)return{sn:n.sn,hx:"body"};for(const t of this.Wx)if(Math.abs(i-t.ct)<=8+s)return{sn:t.sn,hx:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.lw(t))}lw(t){const i=this.Yt;if(this.Wx=[],null===i||0===i.Yx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Uf!==i.T&&(this.Uf=i.T,this.Wn.In()),s.font=i.T,s.textBaseline="middle",this.zx=Math.max(0,n.width-i.yu);const e=i.Xx?this.zx:n.width;for(const s of i.Yx)this.Wx.push(this.Gx(t,i,s,e));i.Xx&&i.Yx.length>1&&this.Kx(t,i),s.restore()}Gx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Zx,o=0===s.Jx.length?0:Math.max(this.Wn.Vi(e,s.Jx)+2*i.yM,.85*l),a=this.Wn.Vi(e,s.hi)+2*i.yM,_=s.$x?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Qx,f=p-l/2;this.tC(t,s,d,c,n),this.iC(t,i,s,{qh:d,sC:f,ts:u,qt:l});let v=d;return o>0&&(this.nC(t,i,s,{qh:v,sC:f,ts:o,qt:l}),v+=o,this.eC(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.DM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.$x&&(this.eC(e,s.R,v,f,l,r,h),this.rC(t,i,s,{qh:v,sC:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Ux:p,qt:l,qx:d,jx:c,Hx:v,Nx:v+_,$x:s.$x}}tC(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=Math.max(1,Math.round(i.dt*o)),_=Math.round(i.ct*o)-Math.floor(a/2);h.save(),h.strokeStyle=i.R,h.lineWidth=a,n(h,i.Kt),h.beginPath(),0!==i.Qx?(h.moveTo(0,_),h.lineTo(Math.round(r*l),_)):(h.moveTo(0,_),h.lineTo(Math.round(Math.max(0,s-8)*l),_),r>e+8&&(h.moveTo(Math.round((e+8)*l),_),h.lineTo(Math.round(r*l),_))),h.stroke(),h.restore()}iC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.hC===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),el(e,n,i.lC,r,h),e.fillStyle=this.Po.X(i.Z,i.oC),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}nC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.aC){const t=i.Wt;e.save(),el(e,{qh:n.qh+t,sC:n.sC+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.lC-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.aC?i._C:s.R,e.fillText(s.Jx,n.qh+n.ts/2,n.sC+n.qt/2),e.restore()}eC(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.Po.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}rC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.hC===s.sn&&"close"===i.uC){e.save();const t=i.Wt;el(e,{qh:n.qh,sC:n.sC+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.lC-t),r,h,"right"),e.fillStyle=this.Po.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,o=(n.sC+n.qt/2)*h,a=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-a,o-a),e.lineTo(l+a,o+a),e.moveTo(l+a,o-a),e.lineTo(l-a,o+a),e.stroke(),e.restore()}Kx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Yx.find(t=>"entry"===t.sn)??i.Yx[0],h=i.Yx.map(t=>t.ct),l=Math.round(this.zx*n);s.save(),s.setLineDash([]),s.strokeStyle=r.R,s.lineWidth=Math.max(1,Math.floor(n)),s.beginPath(),s.moveTo(l,Math.round(Math.min(...h)*e)),s.lineTo(l,Math.round(Math.max(...h)*e)),s.stroke();for(const t of i.Yx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.Po.X(i.Z,i.oC),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function el(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.sC*e),o=Math.round(i.ts*n),a=Math.round(i.qt*e),_=Math.min(s*n,o/2,a/2);L(t,h,l,o,a,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class rl{constructor(){this.Jt=new nl,this.Yt=null}Tt(t){this.Yt=t}renderer(){return null===this.Yt?null:(this.Jt.lt(this.Yt),this.Jt)}zOrder(){return"top"}Xn(t,i,s=0){return null===this.Yt?null:this.Jt.Xn(t,i,s)}}class hl{constructor(t){this.Qt=t}coordinate(){return this.cC()?.Li??-1e3}text(){return this.cC()?.hi??""}textColor(){return this.cC()?.DM??"#FFFFFF"}backColor(){return this.cC()?.R??"#000000"}visible(){return null!==this.cC()}cC(){return this.Qt()}}let ll=0;class ol{constructor(t,i,s){this.eh=new rl,this.Po=new S([]),this.dC=new Map,this.pC=!1,this.fC=null,this.LS=null,this.vC=null,this.Sx=null,this.Lf=t,this.be=i,this.So="pipsend-position-line-"+ll++,this.Ps=s,this.Vf={...il,...s.theme},this.Jb=[this.eh],this.mC=sl.map(t=>new hl(()=>this.wC(t))),this.gC=function(t,i){let s=Qh.get(t);return s||(s=new Gh,Qh.set(t,s)),s.QS(i),s}(this.Lf,this.So),this.be.attachPrimitive(this),Hh(this.Lf)?.QS(this)}attached(t){this.pM=t.requestUpdate,this.pC=!0,this.requestUpdate()}detached(){this.pC=!1,this.pM=void 0}paneViews(){return this.Jb}priceAxisViews(){return this.mC}updateAllViews(){this.eh.Tt(this.bC())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.MC(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.hx}`,zOrder:"top",cursorStyle:"close"===s.hx?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.fC===n&&this.LS===e||(this.fC=n,this.LS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.fC&&"close"!==this.LS&&(this.MC(this.fC)?.draggable??!0)}isClickable(){return"close"===this.LS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}hitTestAt(t,i,s=0){const n=this.eh.Xn(t,i,s);return null===n||null===this.MC(n.sn)?null:`${this.So}#${n.sn}:${n.hx}`}dragAnchorY(){if(null===this.vC)return null;const t=this.MC(this.vC)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.vC=this.fC,null===this.vC)return;const t=this.MC(this.vC)?.price??null;this.Sx=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.vC,t)}dragTo(t){null!==this.vC&&(this.yC(this.vC,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.vC,t))}commitDrag(){const t=this.vC;if(this.vC=null,this.Sx=null,null===t)return;const i=this.MC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.vC,i=this.Sx;if(this.vC=null,this.Sx=null,null===t)return;null!==i&&i!==this.MC(t)?.price&&(this.yC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.MC(t)?.price??0)}click(){const t=this.fC;if(null===t)return;if("close"===this.LS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.MC(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.vC,s=null===i?void 0:this.MC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=al(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=al(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.MC(i);null!==t&&(t.price=s)}t.theme&&(this.Vf={...this.Vf,...t.theme}),this.requestUpdate()}setPrice(t,i){this.vC!==t&&this.yC(t,i)}setText(t,i){const s=this.MC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of sl){const s=this.MC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){Nh(this.Lf,this),function(t,i){const s=Qh.get(t);s&&(s.tx(i),s.Gi()&&Qh.delete(t))}(this.Lf,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.pM&&this.pM()}wC(t){const i=this.MC(t);if(null===i||!isFinite(i.price)||!1===this.Ps.visible||!1===i.axisLabelVisible)return null;const s=this.be.priceToCoordinate(i.price);if(null===s)return null;const n=i.color??tl[t],e=this.be.priceFormatter(),r=this.dC.get(t);if(void 0!==r&&r.bt===i.price&&r.R===n&&r.hl===e)return r.Jl.Li!==s&&(r.Jl={...r.Jl,Li:s}),r.Jl;const h={Li:s,hi:e.format(i.price),R:n,DM:this.Po.K(n).J};return this.dC.set(t,{bt:i.price,R:n,hl:e,Jl:h}),h}MC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}yC(t,i){const s=this.MC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}bC(){if(!this.pC||!1===this.Ps.visible)return null;const t=this.Lf.options().layout,i=this.Vf.fontSize??t.fontSize,s=i+2*this.Vf.paddingY,n=[],e=[];for(const t of sl){const i=this.MC(t);if(null===i||!isFinite(i.price))continue;const r=this.be.priceToCoordinate(i.price);if(null===r)continue;const h="entry"===t;e.push({sn:t,ct:r,qt:s}),n.push({sn:t,ct:r,Qx:0,R:i.color??tl[t],hi:i.formatText?i.formatText(i.price):i.text??"",Jx:i.badge??"",aC:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),$x:i.closable??!0,SC:i.draggable??!0})}if(0===n.length)return this.gC.Bx(this.So,[]),null;this.gC.Bx(this.So,e);for(const t of n)t.Qx=this.gC.Ox(this.So,t.sn);return{Yx:n,Z:this.Vf.background??(r=t.background,"solid"===r.type?r.color:r.topColor),DM:this.Vf.textColor,_C:this.Vf.badgeTextColor,lC:this.Vf.borderRadius,Wt:this.Vf.borderWidth,yM:this.Vf.paddingX,Zx:this.Vf.paddingY,oC:this.Vf.backgroundOpacity,T:g(i,this.Vf.fontFamily??t.fontFamily),P:i,Xx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,hC:this.fC,uC:this.LS};var r}}function al(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}function _l(t,i,s){return new ol(i,t,s)}const ul=new Set(["line","body","stroke","center","move"]);function cl(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?ul.has(n)?"move":"grab":void 0}}function dl(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var pl;function fl(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.Vy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Iy,t.day=i.day??i.Ly,t}return t}function vl(t,i){const s={};return s.price=t,s.time=i,s}function ml(t){if(!t)return vl(0,null);return vl(t.price??t.bt??0,fl(t.time??t.gt??null))}function wl(t,i="time"){return t?t[i]??null:null}function gl(t,i){if(t)return t[i]??void 0}!function(t){t.Idle="idle",t.Creating="creating",t.Editing="editing",t.Dragging="dragging",t.Hovering="hovering"}(pl||(pl={}));class bl{constructor(t,i,s={}){this._state=pl.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.xC(),this._options={color:"#2196F3",lineWidth:2,lineStyle:"solid",visible:!0,locked:!1,zIndex:0,...s},this._visible=this._options.visible??!0,this._locked=this._options.locked??!1}xC(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}isComplete(){return!0}_registerOptions(t){this._ownOptions=t}options(){return{...this._ownOptions??this._options}}applyOptions(t){null!==this._ownOptions&&Object.assign(this._ownOptions,t),this._options={...this._options,...t},void 0!==t.visible&&(this._visible=t.visible),void 0!==t.locked&&(this._locked=t.locked),this._update()}show(){this._visible=!0,this._update()}hide(){this._visible=!1,this._update()}lock(){this._locked=!0}unlock(){this._locked=!1}isLocked(){return this._locked}isVisible(){return this._visible}series(){return this._series}selectionBox(){return null}getState(){return this._state}serialize(){const t=this._serializeShape();return t.id=this._id,t.visible=this._visible,t.locked=this._locked,t}applySerializedState(t){"string"==typeof t.id&&t.id.length>0&&(this._id=t.id),"boolean"==typeof t.visible&&(this._visible=t.visible),"boolean"==typeof t.locked&&(this._locked=t.locked),this._update()}}const Ml=new WeakMap;function yl(t,i){Ml.set(t,i)}function Sl(t){const i=!0===Ml.get(t);return i&&Ml.set(t,!1),i}function xl(t,i,s,n,e){const r=t.canvas.width/s,h=t.canvas.height/n;if(e.ct<0||e.ct>h)return;let l;try{l=i.priceFormatter().format(e.bt)}catch(t){l=String(e.bt)}t.save(),t.font=11*s+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const o=t.measureText(l).width/s+10,a=r-o,_=e.ct-8.5;t.fillStyle=e.Et,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.DM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Cl;!function(t){t.CC="idle",t.PC="waiting_first_point",t.TC="waiting_second_point",t.kC="completed"}(Cl||(Cl={}));class Pl{constructor(t,i,s={}){this.Lv=Cl.CC,this.DC=null,this.kx=null,this.ep=null,this.Lf=t,this.be=i,this.RC=s}FC(){this.Lv===Cl.CC&&(this.Lv=Cl.PC,this.DC=null,this.VC(),this.IC())}LC(){this.Lv=Cl.CC,this.DC=null,this.AC(),this.BC(),this.RC.OC&&this.RC.OC()}EC(){return this.Lv}WC(){return this.Lv===Cl.PC||this.Lv===Cl.TC}VC(){this.kx=t=>{this.zC(t)},this.Lf.subscribeClick(this.kx)}IC(){this.ep=t=>{this.$C(t)},this.Lf.subscribeCrosshairMove(this.ep)}AC(){this.kx&&(this.Lf.unsubscribeClick(this.kx),this.kx=null)}BC(){this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null)}zC(t){if(!t.point)return;if(Sl(this.Lf))return;const i=this.be.coordinateToPrice(t.point.y),s=Kn(this.Lf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Lv===Cl.PC?(this.DC=n,this.Lv=Cl.TC,this.RC.HC&&this.RC.HC(n)):this.Lv===Cl.TC&&this.DC&&(this.Lv=Cl.kC,this.RC.NC&&this.RC.NC(n),this.RC.UC&&this.RC.UC(this.DC,n),this.AC(),this.BC(),this.Lv=Cl.CC,this.DC=null)}$C(t){if(!t.point)return;if(this.Lv!==Cl.TC)return;const i=this.be.coordinateToPrice(t.point.y),s=Kn(this.Lf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.RC.qC&&this.RC.qC(n)}m(){this.LC()}}class Tl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.jC=t,this.Jt=new Tl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends bl{constructor(t,i){super(t,"trend-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null,this.iP=!1,this.sP=null,this.nP=null,this.eP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.eP),this.cS(),this.eP.interactive?this.rP():this.iP=!0}rP(){const t=new Pl(this._chart,this._series,{HC:t=>{this.eP.point1Time=t.gt,this.eP.point1Price=t.bt,this.pM()},NC:t=>{this.eP.point2Time=t.gt,this.eP.point2Price=t.bt,this.iP=!0,this.pM(),this.eP.onUpdate&&this.eP.onUpdate()},qC:t=>{this.eP.point1Time&&!this.iP&&(this.nP=t,this.pM())},UC:()=>{this.iP=!0}});this.sP=t,t.FC()}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new kl(this)}oP(){if(!this.eP.point1Time||!this.eP.point2Time)return null;const t=Zn(this._chart,this._series,this.eP.point1Time)??0,i=this._series.priceToCoordinate(this.eP.point1Price)??0,s=Zn(this._chart,this._series,this.eP.point2Time)??0,n=this._series.priceToCoordinate(this.eP.point2Price)??0;if(!this.eP.extendLeft&&!this.eP.extendRight)return{aP:t,_P:i,uP:s,cP:n};if(s===t)return{aP:t,_P:i,uP:s,cP:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{aP:this.eP.extendLeft?0:t,_P:this.eP.extendLeft?i-r*t:i,uP:this.eP.extendRight?e:s,cP:this.eP.extendRight?i+r*(e-t):n}}dP(){const t=this.oP();if(null===t)return null;const i=t.uP>=t.aP?t.cP:t._P,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.eP.point2Price??this.eP.point1Price??null}drawToCanvas(t,i,s){if(!this.iP&&this.eP.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.eP.point1Time||!this.eP.point2Time)return;const n=(Zn(this._chart,this._series,this.eP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eP.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.eP.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.eP.point2Price)??0)*s,l=this.eP.lineColor,o=this.XC?this.eP.lineWidth+1:this.eP.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.eP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.eP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.oP();if(null===a)return;t.moveTo(a.aP*i,a._P*s),t.lineTo(a.uP*i,a.cP*s),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.isLocked()||(this.fP(t,n,e,i,l),this.fP(t,r,h,i,l));const _=this.dP();if(!1!==this.eP.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&xl(t,this._series,i,s,{bt:_,ct:n,Et:l})}}pP(t,i,s){if(!this.eP.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this.eP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eP.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s;t.strokeStyle=this.eP.lineColor,t.lineWidth=this.eP.lineWidth*i,t.globalAlpha=.7,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),t.globalAlpha=1,this.fP(t,n,e,i,this.eP.lineColor),t.globalAlpha=.5,this.fP(t,r,h,i,this.eP.lineColor),t.globalAlpha=1}fP(t,i,s,n,e){const r=5*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),t.stroke()}setColor(t){this.eP.lineColor=t,this.pM()}color(){return this.eP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}isHovered(){return this.GC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.oP();if(null===s)return!1;return this.vP(t,i,s.aP,s._P,s.uP,s.cP)<=8}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.eP.point1Time||!this.eP.point2Time)return null;const s=Zn(this._chart,this._series,this.eP.point1Time)??0,n=this._series.priceToCoordinate(this.eP.point1Price)??0,e=Zn(this._chart,this._series,this.eP.point2Time)??0,r=this._series.priceToCoordinate(this.eP.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return"point2";return this.vP(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"line"===t&&(this.QC={gt:this.eP.point1Time,bt:this.eP.point1Price},this.tP={gt:this.eP.point2Time,bt:this.eP.point2Price})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null}updateDrag(t,i){if(this.KC&&this.ZC){if("point1"===this.ZC)this.eP.point1Time=t,this.eP.point1Price=i;else if("point2"===this.ZC)this.eP.point2Time=t,this.eP.point2Price=i;else if("line"===this.ZC&&this.QC&&this.tP){const s=dl(this.JC,t,i);this.eP.point1Time=this.QC.gt+s.gt,this.eP.point1Price=this.QC.bt+s.bt,this.eP.point2Time=this.tP.gt+s.gt,this.eP.point2Price=this.tP.bt+s.bt}this.pM(),this.eP.onUpdate&&this.eP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[vl(this.eP.point1Price??0,fl(this.eP.point1Time)),vl(this.eP.point2Price??0,fl(this.eP.point2Time))],style:{lineColor:this.eP.lineColor,lineWidth:this.eP.lineWidth,lineStyle:this.eP.lineStyle,extendLeft:this.eP.extendLeft,extendRight:this.eP.extendRight}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return this.iP}remove(){this.sP&&(this.sP.m(),this.sP=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.eP.onRemove&&this.eP.onRemove()}}function Rl(t,i){return new Dl(t,i)}function Fl(t,i,s,n){let e=0,r=null;const h=()=>{null!==r&&(t.unsubscribeClick(r),r=null)};return r=r=>{if(!r.point||Sl(t))return;const l=i.coordinateToPrice(r.point.y),o=Kn(t,i,r.point.x);null!==l&&null!==o&&(e++,e>=s&&h(),n({gt:o,bt:l,ut:r.point.x,ct:r.point.y},e-1))},t.subscribeClick(r),{mP:()=>null!==r,wP:h}}function Vl(t){const i=t.timeScale();return Math.max(i.width()/5,i.options().barSpacing)}function Il(t,i){const s=t.timeScale(),n=Math.min(i+Vl(t),s.width()-10);return Math.max(n,i+s.options().barSpacing)}class Ll{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Al{constructor(t){this.jC=t,this.Jt=new Ll(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends bl{constructor(t,i){super(t,"horizontal-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.gP=0,this.bP=null,this.MP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.MP),this.cS(),this.MP.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){this.MP.price=t.bt,void 0!==this.MP.startTime&&(this.MP.startTime=t.gt),this.pM()}isComplete(){return!this.bP?.mP()}selectionBox(){const t=void 0===this.MP.price?null:this._series.priceToCoordinate(this.MP.price);return null===t?null:{left:this.SP(),right:this._chart.timeScale().width(),top:t,bottom:t}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Al(this)}SP(){return void 0===this.MP.startTime?0:Zn(this._chart,this._series,this.MP.startTime)??0}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.MP.price)return;const n=(this._series.priceToCoordinate(this.MP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.SP()*i,h=this.MP.lineColor,l=this.XC?this.MP.lineWidth+1:this.MP.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.MP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.MP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.MP.showPriceLabel&&xl(t,this._series,i,s,{bt:this.MP.price,ct:n/s,Et:h}),this.MP.showLabel&&(this.XC||this.GC)&&this.xP(t,n,i,s,h)}xP(t,i,s,n,e){const r=this.MP.labelText||this.MP.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=10*s,u=i-a/2-h;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.MP.lineColor=t,this.pM()}color(){return this.MP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.MP.price)return!1;const s=this._series.priceToCoordinate(this.MP.price)??0;return!(t<this.SP()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.gP=this.MP.price??0}stopDrag(){this.KC=!1,this.JC=null}updateDrag(t,i){this.KC&&(this.MP.price=this.gP+dl(this.JC,t,i).bt,this.pM(),this.MP.onUpdate&&this.MP.onUpdate())}getPrice(){return this.MP.price}setPrice(t){this.MP.price=t,this.pM()}setLabel(t){this.MP.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[vl(this.MP.price??0,fl(this.MP.startTime))],style:{lineColor:this.MP.lineColor,lineWidth:this.MP.lineWidth,lineStyle:this.MP.lineStyle,showLabel:this.MP.showLabel,labelText:this.MP.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.MP.onRemove&&this.MP.onRemove()}}function Ol(t,i){return new Bl(t,i)}class El{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Wl{constructor(t){this.jC=t,this.Jt=new El(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class zl extends bl{constructor(t,i){super(t,"cross-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.CP=0,this.gP=0,this.bP=null,this.PP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.PP),this.cS(),this.PP.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.PP.time=t.gt,this.PP.price=t.bt,this.pM()}))}isComplete(){return!this.bP?.mP()}cS(){this.eh=new Wl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}TP(){if(!this.isComplete()||void 0===this.PP.time||void 0===this.PP.price)return null;const t=Zn(this._chart,this._series,this.PP.time),i=this._series.priceToCoordinate(this.PP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.TP();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.PP.lineColor,_=this.XC||this.GC&&!this.isLocked(),u=_?this.PP.lineWidth+1:this.PP.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.PP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.PP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(r,o),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.PP.showPriceLabel&&void 0!==this.PP.price&&xl(t,this._series,i,s,{bt:this.PP.price,ct:n.ct,Et:a}),_&&!this.isLocked()&&(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,o,5*i,0,2*Math.PI),t.fill(),t.stroke())}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.TP();if(null===s)return!1;return Math.abs(i-s.ct)<=8||Math.abs(t-s.ut)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.CP=this.PP.time,this.gP=this.PP.price??0}updateDrag(t,i){if(!this.KC)return;const s=dl(this.JC,t,i);this.PP.time=this.CP+s.gt,this.PP.price=this.gP+s.bt,this.pM(),this.PP.onUpdate&&this.PP.onUpdate()}stopDrag(){this.KC=!1,this.JC=null}setColor(t){this.PP.lineColor=t,this.pM()}color(){return this.PP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}remove(){if(this.bP?.wP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.PP.onRemove&&this.PP.onRemove()}_serializeShape(){return{type:"crossLine",points:[vl(this.PP.price??0,fl(this.PP.time))],style:{lineColor:this.PP.lineColor,lineWidth:this.PP.lineWidth,lineStyle:this.PP.lineStyle}}}}function $l(t,i){return new zl(t,i)}class Hl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Nl{constructor(t){this.jC=t,this.Jt=new Hl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ul extends bl{constructor(t,i){super(t,"polygon",i),this.I_=[],this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.kP=null,this.iP=!1,this.nP=null,this.kx=null,this.DP=null,this.RP=null,this.FP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.FP),this.I_=[...i.points??[]],this.cS(),this.FP.interactive?this.VP():this.iP=this.I_.length>=3}cS(){this.eh=new Nl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.I_.length>=3&&this.IP(t.point.x,t.point.y)?this.LP():(this.I_.push({time:s,price:i}),this.pM()))},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={time:s,price:i},this.pM())},this.RP=t=>{"Enter"===t.key&&this.I_.length>=3?this.LP():"Escape"===t.key&&(this.I_=[],this.LP())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP),document.addEventListener("keydown",this.RP)}IP(t,i){const s=this.I_[0],n=Zn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Ul.AP&&Math.abs(i-e)<=Ul.AP)}LP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.FP.onComplete&&this.FP.onComplete(),this.FP.onUpdate&&this.FP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null),this.RP&&(document.removeEventListener("keydown",this.RP),this.RP=null)}OP(){const t=[...this.I_];return this.iP||null===this.nP||t.push(this.nP),this.EP(t)}EP(t){const i=[];for(const s of t){const t=Zn(this._chart,this._series,s.time),n=this._series.priceToCoordinate(s.price);null!==t&&null!==n&&i.push({ut:t,ct:n})}return i}drawToCanvas(t,i,s){const n=this.OP();if(n.length<2)return;const e=this.FP.borderColor,r=this.XC?this.FP.borderWidth+1:this.FP.borderWidth;t.beginPath(),t.moveTo(n[0].ut*i,n[0].ct*s);for(let e=1;e<n.length;e++)t.lineTo(n[e].ut*i,n[e].ct*s);this.iP&&(t.closePath(),this.FP.fillOpacity>0&&(t.fillStyle=this.zy(this.FP.fillColor,this.FP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.iP?"dashed"===this.FP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.FP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked())for(const n of this.WP())this.zP(t,n.ut*i,n.ct*s,i,e)}WP(){return this.EP(this.I_)}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.WP();if(s.length<3)return!1;let n=!1;for(let e=0,r=s.length-1;e<s.length;r=e++){s[e].ct>i!=s[r].ct>i&&t<(s[r].ut-s[e].ut)*(i-s[e].ct)/(s[r].ct-s[e].ct)+s[e].ut&&(n=!n)}return n}hitTestEndpoint(t,i){const s=this.WP();for(let n=0;n<s.length;n++)if(Math.abs(t-s[n].ut)<=10&&Math.abs(i-s[n].ct)<=10)return n;return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.kP=this.I_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.KC&&null!==this.ZC&&null!==this.kP){if("shape"===this.ZC){const s=dl(this.JC,t,i);this.I_=this.kP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.ZC;this.I_[s]&&(this.I_[s]={time:t,price:i})}this.pM(),this.FP.onUpdate&&this.FP.onUpdate()}}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.kP=null}setColor(t){this.FP.borderColor=t,this.FP.fillColor=t,this.pM()}color(){return this.FP.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}points(){return this.I_}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.FP.onRemove&&this.FP.onRemove()}_serializeShape(){return{type:"polygon",points:this.I_.map(t=>vl(t.price,fl(t.time))),style:{fillColor:this.FP.fillColor,fillOpacity:this.FP.fillOpacity,borderColor:this.FP.borderColor,borderWidth:this.FP.borderWidth,borderStyle:this.FP.borderStyle}}}}function ql(t,i){return new Ul(t,i)}Ul.AP=12;class jl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Yl{constructor(t){this.jC=t,this.Jt=new jl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Xl extends bl{constructor(t,i){super(t,"parallel-channel",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.iP=!1,this.dd=0,this.nP=null,this.kx=null,this.DP=null,this.HP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.HP),this.cS(),this.HP.interactive?this.VP():this.iP=!0}cS(){this.eh=new Yl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.HP.point1Time=s,this.HP.point1Price=i;else{if(1!==this.dd)return this.HP.channelWidth=i-this.NP(s),void this.LP();this.HP.point2Time=s,this.HP.point2Price=i}this.dd++,this.pM()}},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={gt:s,bt:i},2===this.dd&&(this.HP.channelWidth=i-this.NP(s)),this.pM())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP)}LP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.HP.onComplete&&this.HP.onComplete(),this.HP.onUpdate&&this.HP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null)}NP(t){const i=this.HP.point1Time,s=this.HP.point2Time,n=this.HP.point1Price,e=this.HP.point2Price;if(void 0===i||void 0===n)return 0;if(void 0===s||void 0===e||s===i)return n;return n+(e-n)/(s-i)*(t-i)}VS(){const t=this.HP,i=this.iP?t.point2Time:t.point2Time??this.nP?.gt,s=this.iP?t.point2Price:t.point2Price??this.nP?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Zn(this._chart,this._series,t.point1Time),e=Zn(this._chart,this._series,i),r=this._series.priceToCoordinate(t.point1Price),h=this._series.priceToCoordinate(s);if(null===n||null===e||null===r||null===h)return null;let l=e,o=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,o=r+(h-r)/(e-n)*(t-n)}const a=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+a),u=this._series.priceToCoordinate(this._series.coordinateToPrice(o)+a);return null===_||null===u?null:{aP:n,uP:l,UP:r,qP:o,jP:_,YP:u}}drawToCanvas(t,i,s){const n=this.VS();if(null===n)return;const e=this.HP,r=e.lineColor,h=this.XC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.zy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.aP*l,n.UP*o),t.lineTo(n.uP*l,n.qP*o),t.lineTo(n.uP*l,n.YP*o),t.lineTo(n.aP*l,n.jP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.iP?"dashed"===e.lineStyle?t.setLineDash([10*l,5*l]):"dotted"===e.lineStyle&&t.setLineDash([2*l,3*l]):t.setLineDash([6*l,4*l]),t.beginPath(),t.moveTo(n.aP*l,n.UP*o),t.lineTo(n.uP*l,n.qP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.aP*l,n.jP*o),t.lineTo(n.uP*l,n.YP*o)),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked()&&(this.zP(t,n.aP*l,n.UP*o,l,r),this.zP(t,n.uP*l,n.qP*o,l,r),0!==(e.channelWidth??0))){const i=(n.aP+n.uP)/2,s=(n.jP+n.YP)/2;this.zP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.iP){const i=this._series.coordinateToPrice(n.qP);null!==i&&xl(t,this._series,l,o,{bt:i,ct:n.qP,Et:r})}}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}XP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.VS();if(null===s)return!1;return this.XP(t,i,s.aP,s.UP,s.uP,s.qP)<=8||this.XP(t,i,s.aP,s.jP,s.uP,s.YP)<=8}hitTestEndpoint(t,i){const s=this.VS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.aP,s.UP))return"point1";if(n(s.uP,s.qP))return"point2";if(0!==(this.HP.channelWidth??0)){if(n((s.aP+s.uP)/2,(s.jP+s.YP)/2))return"width"}return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P={GP:{gt:this.HP.point1Time,bt:this.HP.point1Price},KP:{gt:this.HP.point2Time,bt:this.HP.point2Price},ts:this.HP.channelWidth??0}}updateDrag(t,i){if(!this.KC||null===this.ZC||null===this.$P)return;const s=this.HP;if("point1"===this.ZC)s.point1Time=t,s.point1Price=i;else if("point2"===this.ZC)s.point2Time=t,s.point2Price=i;else if("width"===this.ZC)s.channelWidth=i-this.NP(t);else{const n=dl(this.JC,t,i);s.point1Time=this.$P.GP.gt+n.gt,s.point1Price=this.$P.GP.bt+n.bt,s.point2Time=this.$P.KP.gt+n.gt,s.point2Price=this.$P.KP.bt+n.bt,s.channelWidth=this.$P.ts}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}setColor(t){this.HP.lineColor=t,this.HP.fillColor=t,this.pM()}color(){return this.HP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.HP.onRemove&&this.HP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[vl(this.HP.point1Price??0,fl(this.HP.point1Time)),vl(this.HP.point2Price??0,fl(this.HP.point2Time))],style:{lineColor:this.HP.lineColor,lineWidth:this.HP.lineWidth,lineStyle:this.HP.lineStyle,fillColor:this.HP.fillColor,fillOpacity:this.HP.fillOpacity,extendRight:this.HP.extendRight},extra:{channelWidth:this.HP.channelWidth}}}}function Gl(t,i){return new Xl(t,i)}class Kl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zl{constructor(t){this.jC=t,this.Jt=new Kl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Jl extends bl{constructor(t,i){super(t,"pitchfork",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.iP=!1,this.dd=0,this.nP=null,this.kx=null,this.DP=null,this.ZP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.ZP),this.cS(),this.ZP.interactive?this.VP():this.iP=!0}cS(){this.eh=new Zl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.ZP.pivotTime=s,this.ZP.pivotPrice=i;else{if(1!==this.dd)return this.ZP.lowerTime=s,this.ZP.lowerPrice=i,this.dd++,void this.LP();this.ZP.upperTime=s,this.ZP.upperPrice=i}this.dd++,this.pM()}},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={gt:s,bt:i},this.pM())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP)}LP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.ZP.onComplete&&this.ZP.onComplete(),this.ZP.onUpdate&&this.ZP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null)}JP(t,i){if(void 0===t||void 0===i)return null;const s=Zn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}QP(){const t=this.ZP,i=this.JP(t.pivotTime,t.pivotPrice),s=this.JP(t.upperTime,t.upperPrice),n=this.iP?this.JP(t.lowerTime,t.lowerPrice):this.JP(t.lowerTime,t.lowerPrice)??(null!==this.nP&&this.dd>=2?this.JP(this.nP.gt,this.nP.bt):null);if(null===i||null===s||null===n)return null;const e={ut:(s.ut+n.ut)/2,ct:(s.ct+n.ct)/2};if(e.ut===i.ut)return null;const r=this._chart.chartElement().clientWidth,h=(e.ct-i.ct)/(e.ut-i.ut),l=t=>({ut:r,ct:t.ct+h*(r-t.ut)});return{jy:i,tT:e,Dy:s,Fy:n,iT:l(i),sT:l(s),nT:l(n)}}drawToCanvas(t,i,s){const n=this.QP();if(null===n)return void this.eT(t,i,s);const e=this.ZP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.zy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.sT.ut*h,n.sT.ct*l),t.lineTo(n.nT.ut*h,n.nT.ct*l),t.lineTo(n.Fy.ut*h,n.Fy.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.XC?e.lineWidth+1:e.lineWidth)*h,"dashed"===e.lineStyle?t.setLineDash([10*h,5*h]):"dotted"===e.lineStyle&&t.setLineDash([2*h,3*h]),t.beginPath(),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.Fy.ut*h,n.Fy.ct*l),t.moveTo(n.jy.ut*h,n.jy.ct*l),t.lineTo(n.iT.ut*h,n.iT.ct*l),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.sT.ut*h,n.sT.ct*l),t.moveTo(n.Fy.ut*h,n.Fy.ct*l),t.lineTo(n.nT.ut*h,n.nT.ct*l),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked())for(const i of[n.jy,n.Dy,n.Fy])this.zP(t,i.ut*h,i.ct*l,h,r)}eT(t,i,s){const n=this.ZP,e=this.JP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.JP(n.upperTime,n.upperPrice)??(null!==this.nP?this.JP(this.nP.gt,this.nP.bt):null),h=n.lineColor;t.strokeStyle=h,t.lineWidth=n.lineWidth*i,t.setLineDash([6*i,4*i]),null!==r&&(t.beginPath(),t.moveTo(e.ut*i,e.ct*s),t.lineTo(r.ut*i,r.ct*s),t.stroke()),t.setLineDash([]),this.zP(t,e.ut*i,e.ct*s,i,h)}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}XP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.QP();if(null===s)return!1;return[[s.jy,s.iT],[s.Dy,s.sT],[s.Fy,s.nT],[s.Dy,s.Fy]].some(([s,n])=>this.XP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.QP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.jy)?"pivot":n(s.Dy)?"upper":n(s.Fy)?"lower":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P=[{gt:this.ZP.pivotTime,bt:this.ZP.pivotPrice},{gt:this.ZP.upperTime,bt:this.ZP.upperPrice},{gt:this.ZP.lowerTime,bt:this.ZP.lowerPrice}]}updateDrag(t,i){if(!this.KC||null===this.ZC||null===this.$P)return;const s=this.ZP;if("pivot"===this.ZC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.ZC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.ZC)s.lowerTime=t,s.lowerPrice=i;else{const n=dl(this.JC,t,i),[e,r,h]=this.$P;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}setColor(t){this.ZP.lineColor=t,this.ZP.fillColor=t,this.pM()}color(){return this.ZP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.ZP.onRemove&&this.ZP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[vl(this.ZP.pivotPrice??0,fl(this.ZP.pivotTime)),vl(this.ZP.upperPrice??0,fl(this.ZP.upperTime)),vl(this.ZP.lowerPrice??0,fl(this.ZP.lowerTime))],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,lineStyle:this.ZP.lineStyle,fillColor:this.ZP.fillColor,fillOpacity:this.ZP.fillOpacity}}}}function Ql(t,i){return new Jl(t,i)}class to{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class io{constructor(t){this.jC=t,this.Jt=new to(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class so extends bl{constructor(t,i){super(t,"vertical-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.CP=0,this.bP=null,this.rT={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.rT),this.cS(),this.rT.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.rT.time=t.gt,this.pM()}))}isComplete(){return!this.bP?.mP()}selectionBox(){const t=Zn(this._chart,this._series,this.rT.time);if(null===t)return null;let i;try{i=this._series.getPane().getHeight()/2}catch(t){return null}return{left:t,right:t,top:i,bottom:i}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new io(this)}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.rT.time)return;const n=(Zn(this._chart,this._series,this.rT.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.rT.lineColor,h=this.XC||this.GC&&!this.isLocked()?this.rT.lineWidth+1:this.rT.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.rT.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.rT.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.rT.showLabel&&(this.XC||this.GC)&&this.rT.labelText&&this.xP(t,n,i,s,r)}xP(t,i,s,n,e){const r=this.rT.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=i-o/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.rT.lineColor=t,this.pM()}color(){return this.rT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.rT.time)return!1;const s=Zn(this._chart,this._series,this.rT.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.CP=this.rT.time}stopDrag(){this.KC=!1,this.JC=null}updateDrag(t,i){this.KC&&(this.rT.time=this.CP+dl(this.JC,t,i).gt,this.pM(),this.rT.onUpdate&&this.rT.onUpdate())}getTime(){return this.rT.time}setTime(t){this.rT.time=t,this.pM()}setLabel(t){this.rT.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[vl(0,fl(this.rT.time))],style:{lineColor:this.rT.lineColor,lineWidth:this.rT.lineWidth,lineStyle:this.rT.lineStyle,showLabel:this.rT.showLabel,labelText:this.rT.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.rT.onRemove&&this.rT.onRemove()}}function no(t,i){return new so(t,i)}const eo=[{hT:0,Jl:"0.0%"},{hT:.236,Jl:"23.6%"},{hT:.382,Jl:"38.2%"},{hT:.5,Jl:"50.0%"},{hT:.618,Jl:"61.8%"},{hT:.786,Jl:"78.6%"},{hT:1,Jl:"100.0%"}],ro=[...eo,{hT:1.272,Jl:"127.2%"},{hT:1.414,Jl:"141.4%"},{hT:1.618,Jl:"161.8%"},{hT:2,Jl:"200.0%"},{hT:2.618,Jl:"261.8%"}];class ho{constructor(t=!1){this.lT=t?ro:eo}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.lT.map(({hT:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{hT:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.lT=t}getRatios(){return[...this.lT]}getRatioValues(){return this.lT.map(t=>t.hT)}useStandardRatios(){this.lT=eo}useExtendedRatios(){this.lT=ro}}class lo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class oo{constructor(t){this.jC=t,this.Jt=new lo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}function ao(t){return{hT:t,Jl:`${(100*t).toFixed(1)}%`}}class _o extends bl{constructor(t,i){super(t,"fibonacci-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.oT=null,this.iP=!1,this.XC=!1,this.GC=!1,this.nP=null,this.KC=!1,this.aT=null,this.ep=null,this._T={lineColor:"#787b86",lineWidth:1,showLabels:!0,labelPosition:"right",useExtended:!1,levelColors:{0:"#787b86",.236:"#f23645",.382:"#ff9800",.5:"#2196f3",.618:"#4caf50",.786:"#9c27b0",1:"#787b86"},...i},this._registerOptions(this._T),this.uT=new ho(this._T.useExtended),void 0!==this._T.levels&&this._T.levels.length>0&&this.uT.updateRatios(this._T.levels.map(ao)),this.cS(),this._T.interactive?this.rP():(this.iP=!0,this.cT())}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new oo(this)}drawToCanvas(t,i,s){if(!this.iP&&this._T.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.Gb||!this._T.point1Time||!this._T.point2Time)return;const n=(Zn(this._chart,this._series,this._T.point1Time)??0)*i,e=(Zn(this._chart,this._series,this._T.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.XC?2:this._T.lineWidth;this.Gb.levels.forEach(n=>{this.Gx(t,n,r,h,i,s,l)}),!this.XC&&!this.GC||this.isLocked()||(this.fP(t,n,(this._series.priceToCoordinate(this._T.point1Price)??0)*s,i),this.fP(t,e,(this._series.priceToCoordinate(this._T.point2Price)??0)*s,i))}Gx(t,i,s,n,e,r,h=1){const l=i.ratio??i.hT,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this._T.levelColors?.[l.toString()]||this._T.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this._T.showLabels&&this.xP(t,i,s,n,a,e,_)}xP(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.uT.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this._T.labelPosition?n+u:s-_.width-u,d=e;t.fillStyle="rgba(255, 255, 255, 0.9)",t.fillRect(c-u/2,d-11*r/2-u/2,_.width+u,11*r+u),t.fillStyle=h,t.textAlign="right"===this._T.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}cT(){this._T.point1Time&&this._T.point1Price&&this._T.point2Time&&this._T.point2Price&&(this.Gb=this.uT.calculateLevels(this._T.point1Time,this._T.point1Price,this._T.point2Time,this._T.point2Price),this._T.onUpdate&&this.Gb&&this._T.onUpdate(this.Gb))}updatePoints(t,i,s,n){this._T.point1Time=t,this._T.point1Price=i,this._T.point2Time=s,this._T.point2Price=n,this.cT(),this.pM()}getMetrics(){return this.Gb}getLevels(){return this.Gb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.uT.getRatioValues();return{type:"fibRetracement",points:[vl(this._T.point1Price??0,fl(this._T.point1Time)),vl(this._T.point2Price??0,fl(this._T.point2Time))],style:{lineColor:this._T.lineColor,lineWidth:this._T.lineWidth,showLabels:this._T.showLabels,labelPosition:this._T.labelPosition,levelColors:this._T.levelColors},extra:{levels:t,useExtended:this._T.useExtended}}}useExtendedLevels(t){this._T.useExtended=t,t?this.uT.useExtendedRatios():this.uT.useStandardRatios(),this.cT(),this.pM()}rP(){this.oT=new Pl(this._chart,this._series,{HC:t=>{this._T.point1Time=t.gt,this._T.point1Price=t.bt,this.pM()},NC:t=>{this._T.point2Time=t.gt,this._T.point2Price=t.bt},UC:(t,i)=>{this._T.point1Time=t.gt,this._T.point1Price=t.bt,this._T.point2Time=i.gt,this._T.point2Price=i.bt,this.iP=!0,this.nP=null,this.cT(),this.dT(),this.pM()},qC:t=>{this.nP=t,this.pM()}}),this.oT.FC()}pP(t,i,s){if(!this._T.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this._T.point1Time)??0)*i,e=(this._series.priceToCoordinate(this._T.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s,l=this.uT.calculateLevels(this._T.point1Time,this._T.point1Price,this.nP.gt,this.nP.bt),o=Math.min(n,r),a=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.hT,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this._T.levelColors?.[e.toString()]||this._T.lineColor;if(t.strokeStyle=l,t.lineWidth=this._T.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this._T.showLabels){const s=`${n.label??n.Jl} ${this.uT.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this._T.labelPosition?a+_:o-e.width-_,c=h;t.fillStyle="rgba(255, 255, 255, 0.8)",t.fillRect(u-_/2,c-11*i/2-_/2,e.width+_,11*i+_),t.fillStyle=l,t.textAlign="right"===this._T.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.fP(t,n,e,i),t.globalAlpha=.6,this.fP(t,r,h,i),t.globalAlpha=1}fP(t,i,s,n){const e=this._T.lineColor,r=this.XC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.XC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}dT(){this.ep=t=>{this.pT(t)},this._chart.subscribeCrosshairMove(this.ep)}fT(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}pT(t){if(!t.point)return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.XC||!this.KC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.aT?(this._T.point1Time=i,this._T.point1Price=s):"point2"===this.aT&&(this._T.point2Time=i,this._T.point2Price=s),this.cT(),this.pM())}startDrag(t){this.KC=!0,this.aT=t}stopDrag(){this.KC=!1,this.aT=null}updateDrag(t,i){this.KC&&this.aT&&("point1"===this.aT?(this._T.point1Time=t,this._T.point1Price=i):(this._T.point2Time=t,this._T.point2Price=i),this.cT(),this.pM())}hitTestEndpoint(t,i){if(!this.iP||!this._T.point1Time||!this._T.point2Time)return null;const s=Zn(this._chart,this._series,this._T.point1Time)??0,n=this._series.priceToCoordinate(this._T.point1Price)??0,e=Zn(this._chart,this._series,this._T.point2Time)??0,r=this._series.priceToCoordinate(this._T.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}applyOptions(t){this._T={...this._T,...t},void 0!==t.levels&&t.levels.length>0?this.uT.updateRatios(t.levels.map(ao)):void 0!==t.useExtended&&(t.useExtended?this.uT.useExtendedRatios():this.uT.useStandardRatios()),super.applyOptions(t),this.cT(),this.pM()}options(){return{...this._T,levels:this.uT.getRatioValues()}}setColor(t){this._T.lineColor=t,this.pM()}color(){return this._T.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isSelected(){return this.XC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.iP||!this._T.point1Time||!this._T.point2Time)return!1;const s=Zn(this._chart,this._series,this._T.point1Time)??0,n=Zn(this._chart,this._series,this._T.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Gb)return!1;for(const t of this.Gb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.iP}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.oT&&(this.oT.m(),this.oT=null),this.fT(),this._T.onRemove&&this._T.onRemove()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this._T.onRemove&&this._T.onRemove()}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.cT(),this.pM()}}function uo(t,i){return new _o(t,i)}class co{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class po{constructor(t){this.jC=t,this.Jt=new co(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class fo extends bl{constructor(t,i){super(t,"fibonacci-extension",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.bP=null,this._T={levels:[{level:0,color:"#787B86",label:"0%"},{level:.618,color:"#2962FF",label:"61.8%"},{level:1,color:"#787B86",label:"100%"},{level:1.618,color:"#F23645",label:"161.8%"},{level:2.618,color:"#9C27B0",label:"261.8%"}],lineColor:"#787B86",lineWidth:1,showLabels:!0,extendLines:!0,...i},this.cS(),this._T.interactive&&(this.bP=Fl(this._chart,this._series,3,(t,i)=>{const s={time:t.gt,price:t.bt};0===i?this.setPoint1(s):1===i?this.setPoint2(s):this.setPoint3(s)}))}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new po(this)}getPoint1(){return this._T.point1}getPoint2(){return this._T.point2}getPoint3(){return this._T.point3}getLevels(){return this._T.levels||[]}getOptions(){return this._T}setPoint1(t){this._T.point1=t,this.pM()}setPoint2(t){this._T.point2=t,this.pM()}setPoint3(t){this._T.point3=t,this.pM()}isComplete(){return!this.bP?.mP()&&!!(this._T.point1&&this._T.point2&&this._T.point3)}setColor(t){this._T.lineColor=t,this.pM()}color(){return this._T.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this._T.point1,this._T.point2,this._T.point3];for(const n of s){const s=Zn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=10)return!0}const n=this.vT();for(const t of n){const s=this._series.priceToCoordinate(t.bt)??0;if(Math.abs(i-s)<=10)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this._T.point1,n=this._T.point2,e=this._T.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Zn(this._chart,this._series,s.time)??0,e=this._series.priceToCoordinate(s.price)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=20)return"point1"}if(n&&n.time&&void 0!==n.price){const s=Zn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=20)return"point2"}if(e&&e.time&&void 0!==e.price){const s=Zn(this._chart,this._series,e.time)??0,n=this._series.priceToCoordinate(e.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=20)return"point3"}return null}startDrag(t){this.KC=!0,this.ZC=t}stopDrag(){this.KC=!1,this.ZC=null}updateDrag(t,i){if(!this.KC||!this.ZC)return;const s={time:t,price:i};switch(this.ZC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this._T.onUpdate&&this._T.onUpdate()}vT(){if(!this.isComplete())return[];const t=this._T.point1,i=this._T.point2,s=this._T.point3,n=i.price-t.price;return(this._T.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.vT()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this._T.point1,e=this._T.point2,r=this._T.point3,h=this.XC||this.GC&&!this.isLocked(),l=(Zn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Zn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Zn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this._T.lineColor||"#787B86",t.lineWidth=(this._T.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this._T.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this._T.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this._T.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Jl:"A"},{ut:a,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[ml(this._T.point1),ml(this._T.point2),ml(this._T.point3)],style:{lineColor:this._T.lineColor,lineWidth:this._T.lineWidth,showLabels:this._T.showLabels,extendLines:this._T.extendLines},extra:{levels:(this._T.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null)}}function vo(t,i){return new fo(t,i)}class mo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wo{constructor(t){this.jC=t,this.Jt=new mo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const go=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class bo extends bl{constructor(t,i){super(t,"fibonacci-fan",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.wT={levels:go,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.cS(),this.wT.interactive&&!this.wT.point1Time&&this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.wT.point1Time?(this.wT.point2Time=i,this.wT.point2Price=s,this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.wT.onUpdate&&this.wT.onUpdate()):(this.wT.point1Time=i,this.wT.point1Price=s,this.pM()))},this.ep=t=>{if(this.mT&&this.wT.point1Time)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new wo(this)}drawToCanvas(t,i,s){const n=this.wT.point1Time,e=this.wT.point1Price,r=this.mT&&this.nP?this.nP.gt:this.wT.point2Time,h=this.mT&&this.nP?this.nP.bt:this.wT.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Zn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Zn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.XC?this.wT.lineWidth+1:this.wT.lineWidth;if(this.gT(t,l,o,a,_,"#2962FF",u*i),this.wT.levels)for(const n of this.wT.levels)this.bT(t,l,o,a,_,n,i,s,undefined,u);!this.XC&&!this.GC||this.mT||this.isLocked()||(this.fP(t,l,o,i,"#2962ff"),this.fP(t,a,_,i,"#2962ff"))}bT(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.wT.extendLines){const t=this._chart.chartElement().clientWidth*h,n=_-i,e=u-s,r=Math.sqrt(n*n+e*e);if(r>0){const h=2*t;c=i+n/r*h,d=s+e/r*h}}const p=o||r.color;this.gT(t,i,s,c,d,p,a*h),this.wT.showLabels&&!this.mT&&this.xP(t,_,u,r.label,h,p)}gT(t,i,s,n,e,r,h){t.strokeStyle=r,t.lineWidth=h,t.beginPath(),t.moveTo(i,s),t.lineTo(n,e),t.stroke()}fP(t,i,s,n,e){const r=5*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke()}xP(t,i,s,n,e,r){const h=11*e,l=4*e;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(n).width,a=h;t.fillStyle=r,t.fillRect(i+l,s-a-l,o+2*l,a+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-a-l+l)}setColor(t){const i=this.wT.levels??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.wT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.wT.point1Time||!this.wT.point2Time)return!1;const s=Zn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Zn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;if(this.vP(t,i,s,n,e,r)<=8)return!0;if(this.wT.levels)for(const h of this.wT.levels){const l=n+(r-n)*h.level,o=e;if(this.vP(t,i,s,n,o,l)<=8)return!0}return!1}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.wT.point1Time||!this.wT.point2Time)return null;const s=Zn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Zn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;return Math.abs(t-s)<=10&&Math.abs(i-n)<=10?"point1":Math.abs(t-e)<=10&&Math.abs(i-r)<=10?"point2":null}startDrag(t){this.KC=!0,this.ZC=t}stopDrag(){this.KC=!1,this.ZC=null}updateDrag(t,i){this.KC&&this.ZC&&("point1"===this.ZC?(this.wT.point1Time=t,this.wT.point1Price=i):"point2"===this.ZC&&(this.wT.point2Time=t,this.wT.point2Price=i),this.pM(),this.wT.onUpdate&&this.wT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[vl(this.wT.point1Price??0,fl(this.wT.point1Time)),vl(this.wT.point2Price??0,fl(this.wT.point2Time))],style:{lineWidth:this.wT.lineWidth,showLabels:this.wT.showLabels,extendLines:this.wT.extendLines},extra:{levels:(this.wT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.wT.onRemove&&this.wT.onRemove()}}function Mo(t,i){return new bo(t,i)}class yo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class So{constructor(t){this.jC=t,this.Jt=new yo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class xo extends bl{constructor(t,i){super(t,"rectangle",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.MT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.MT),this.cS(),!this.MT.interactive||this.MT.time1&&this.MT.time2||this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.MT.time1?(this.MT.time2=i,this.MT.price2=s,this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.MT.onUpdate&&this.MT.onUpdate()):(this.MT.time1=i,this.MT.price1=s,this.pM()))},this.ep=t=>{if(this.mT&&this.MT.time1)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new So(this)}drawToCanvas(t,i,s){const n=this.MT.time1,e=this.MT.price1,r=this.mT&&this.nP?this.nP.gt:this.MT.time2,h=this.mT&&this.nP?this.nP.bt:this.MT.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Zn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Zn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,a),c=Math.max(l,a),d=Math.min(o,_),p=Math.max(o,_),f=c-u,v=p-d;if(this.MT.fillOpacity>0){const i=this._S(this.MT.fillColor,this.mT?.1:this.MT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.MT.borderColor,w=this.XC?this.MT.borderWidth+1:this.MT.borderWidth;w>0&&(t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.MT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.MT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([])),!this.XC&&!this.GC||this.mT||this.isLocked()||this.yT(t,u,d,c,p,i,m),this.MT.showLabel&&this.MT.labelText&&!this.mT&&this.xP(t,u,d,c,p,i,s,m)}yT(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s},{ut:n,ct:s},{ut:i,ct:e},{ut:n,ct:e}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}xP(t,i,s,n,e,r,h,l){const o=6*r,a=(this.MT.labelFontSize??12)*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.MT.labelText).width,u=a,c=(s+e)/2-u/2-o,d=Math.min(n,t.canvas.width);let p=i+o,f=s+o;switch(this.MT.labelPosition){case"top-right":p=d-_-2*o,f=s+o;break;case"bottom-left":p=i+o,f=e-u-2*o;break;case"bottom-right":p=d-_-2*o,f=e-u-2*o;break;case"center":p=(Math.max(i,0)+d)/2-_/2-o,f=c;break;case"left":p=i+o,f=c;break;case"right":p=d-_-2*o,f=c}t.fillStyle=this.MT.labelBackgroundColor??l,t.fillRect(p,f,_+2*o,u+2*o),t.fillStyle=this.MT.labelColor??"#ffffff",t.textBaseline="top",t.fillText(this.MT.labelText,p+o,f+o)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}setColor(t){this.MT.borderColor=t,this.MT.fillColor=t,this.pM()}color(){return this.MT.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.MT.time1||!this.MT.time2)return!1;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=Zn(this._chart,this._series,this.MT.time2)??0,r=this._series.priceToCoordinate(this.MT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r);return t>=h&&t<=l&&i>=o&&i<=a}hitTestEndpoint(t,i){if(!this.MT.time1||!this.MT.time2)return null;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=Zn(this._chart,this._series,this.MT.time2)??0,r=this._series.priceToCoordinate(this.MT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner4":t>=h&&t<=l&&i>=o&&i<=a?"body":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"body"===t&&(this.QC={gt:this.MT.time1,bt:this.MT.price1},this.tP={gt:this.MT.time2,bt:this.MT.price2})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null}updateDrag(t,i){if(!this.KC||!this.ZC)return;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=s<(Zn(this._chart,this._series,this.MT.time2)??0),r=n<(this._series.priceToCoordinate(this.MT.price2)??0);if("body"===this.ZC&&this.QC&&this.tP){const s=dl(this.JC,t,i);this.MT.time1=this.QC.gt+s.gt,this.MT.price1=this.QC.bt+s.bt,this.MT.time2=this.tP.gt+s.gt,this.MT.price2=this.tP.bt+s.bt}else switch(this.ZC){case"corner1":e&&r?(this.MT.time1=t,this.MT.price1=i):!e&&r?(this.MT.time2=t,this.MT.price1=i):e&&!r?(this.MT.time1=t,this.MT.price2=i):(this.MT.time2=t,this.MT.price2=i);break;case"corner2":e&&r?(this.MT.time2=t,this.MT.price1=i):!e&&r?(this.MT.time1=t,this.MT.price1=i):e&&!r?(this.MT.time2=t,this.MT.price2=i):(this.MT.time1=t,this.MT.price2=i);break;case"corner3":e&&r?(this.MT.time1=t,this.MT.price2=i):!e&&r?(this.MT.time2=t,this.MT.price2=i):e&&!r?(this.MT.time1=t,this.MT.price1=i):(this.MT.time2=t,this.MT.price1=i);break;case"corner4":e&&r?(this.MT.time2=t,this.MT.price2=i):!e&&r?(this.MT.time1=t,this.MT.price2=i):e&&!r?(this.MT.time2=t,this.MT.price1=i):(this.MT.time1=t,this.MT.price1=i)}this.pM(),this.MT.onUpdate&&this.MT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[vl(this.MT.price1??0,fl(this.MT.time1)),vl(this.MT.price2??0,fl(this.MT.time2))],style:{fillColor:this.MT.fillColor,fillOpacity:this.MT.fillOpacity,borderColor:this.MT.borderColor,borderWidth:this.MT.borderWidth,borderStyle:this.MT.borderStyle,showLabel:this.MT.showLabel,labelText:this.MT.labelText,labelPosition:this.MT.labelPosition,labelColor:this.MT.labelColor,labelBackgroundColor:this.MT.labelBackgroundColor,labelFontSize:this.MT.labelFontSize}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.MT.onRemove&&this.MT.onRemove()}}function Co(t,i){return new xo(t,i)}class Po{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class To{constructor(t){this.jC=t,this.Jt=new Po(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ko extends bl{constructor(t,i){super(t,"circle",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.ST={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.ST),this.cS(),this.ST.interactive&&!this.ST.centerTime&&this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.ST.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=Zn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.ST.radiusTime=Math.abs(e-t),this.ST.radiusPrice=Math.abs(r-n),this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.ST.onUpdate&&this.ST.onUpdate()}else this.ST.centerTime=i,this.ST.centerPrice=s,this.pM()},this.ep=t=>{if(this.mT&&this.ST.centerTime)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new To(this)}drawToCanvas(t,i,s){if(!this.ST.centerTime||void 0===this.ST.centerPrice)return;const n=(Zn(this._chart,this._series,this.ST.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.ST.centerPrice)??0)*s;let r,h;if(this.mT&&this.nP){const t=(Zn(this._chart,this._series,this.nP.gt)??0)*i,l=(this._series.priceToCoordinate(this.nP.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.ST.radiusTime||void 0===this.ST.radiusPrice)return;r=this.ST.radiusTime*i,h=this.ST.radiusPrice*s}if(this.ST.fillOpacity>0){const i=this._S(this.ST.fillColor,this.mT?.05:this.ST.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.ST.borderColor,o=this.XC?this.ST.borderWidth+1:this.ST.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.ST.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.ST.borderStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.mT||this.isLocked()||this.xT(t,n,e,i,l),!this.XC&&!this.GC||this.mT||this.isLocked()||this.CT(t,n,e,r,h,i,l),this.ST.showLabel&&this.ST.labelText&&!this.mT&&this.xP(t,n,e,i,l)}xT(t,i,s,n,e){const r=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r/2,0,2*Math.PI),t.fill(),t.stroke()}CT(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s-e},{ut:i+n,ct:s},{ut:i,ct:s+e},{ut:i-n,ct:s}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}xP(t,i,s,n,e){const r=6*n,h=12*n;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const l=t.measureText(this.ST.labelText).width,o=h,a=i-l/2-r,_=s-o/2-r;t.fillStyle=e,t.fillRect(a,_,l+2*r,o+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.ST.labelText,a+r,_+r)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}setColor(t){this.ST.borderColor=t,this.ST.fillColor=t,this.pM()}color(){return this.ST.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.ST.centerTime||void 0===this.ST.radiusTime)return!1;const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=(t-s)/this.ST.radiusTime,r=(i-n)/this.ST.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.ST.centerTime||void 0===this.ST.radiusTime)return null;const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=this.ST.radiusTime,r=this.ST.radiusPrice;if(Math.abs(t-s)<=10&&Math.abs(i-n)<=10)return"center";const h=[{ut:s,ct:n-r},{ut:s+e,ct:n},{ut:s,ct:n+r},{ut:s-e,ct:n}];for(const s of h)if(Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10)return"edge";return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P="center"===t?{gt:this.ST.centerTime,bt:this.ST.centerPrice}:null}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC&&this.ZC){if("center"===this.ZC&&this.$P){const s=dl(this.JC,t,i);this.ST.centerTime=this.$P.gt+s.gt,this.ST.centerPrice=this.$P.bt+s.bt}else if("edge"===this.ZC){const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=Zn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.ST.radiusTime=Math.abs(e-s),this.ST.radiusPrice=Math.abs(r-n)}this.pM(),this.ST.onUpdate&&this.ST.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[vl(this.ST.centerPrice??0,fl(this.ST.centerTime))],style:{fillColor:this.ST.fillColor,fillOpacity:this.ST.fillOpacity,borderColor:this.ST.borderColor,borderWidth:this.ST.borderWidth,borderStyle:this.ST.borderStyle,showLabel:this.ST.showLabel,labelText:this.ST.labelText},extra:{radiusTime:this.ST.radiusTime,radiusPrice:this.ST.radiusPrice}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.ST.onRemove&&this.ST.onRemove()}}function Do(t,i){return new ko(t,i)}class Ro{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Fo{constructor(t){this.jC=t,this.Jt=new Ro(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vo extends bl{constructor(t,i){super(t,"arrow",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.PT=-1,this.mT=!1,this.kx=null,this.TT=null,this.ep=null,this.nP=null,this.kT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.kT),this.cS(),!this.kT.interactive||this.kT.points&&0!==this.kT.points.length||this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kT.points||(this.kT.points=[]),this.kT.points.push({time:i,price:s}),this.pM(),this.kT.onUpdate&&this.kT.onUpdate())},this.ep=t=>{if(this.mT)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this.TT=t=>{this.mT&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.TT)}finishDrawing(){if(this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.TT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.TT),this.TT=null}this.mT=!1,this.nP=null,this.pM(),this.kT.onComplete&&this.kT.onComplete()}isDrawing(){return this.mT}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Fo(this)}drawToCanvas(t,i,s){if(!this.kT.points||0===this.kT.points.length)return;const n=this.kT.lineColor,e=this.XC||this.GC&&!this.isLocked()?this.kT.lineWidth+1:this.kT.lineWidth,r=[];for(const t of this.kT.points)try{let n=Zn(this._chart,this._series,t.time);if(null===n){const i=this._chart.timeScale(),s=i.timeToIndex(t.time,!0);null!=s&&(n=i.logicalToCoordinate(s))}if(null==n)continue;const e=this._series.priceToCoordinate(t.price);if(null===e)continue;r.push({ut:n*i,ct:e*s})}catch{continue}if(0===r.length&&!this.mT)return;let h=null;if(this.mT&&this.nP&&this.kT.points.length>0){h={ut:(Zn(this._chart,this._series,this.nP.gt)??0)*i,ct:(this._series.priceToCoordinate(this.nP.bt)??0)*s}}if(r.length>1){t.strokeStyle=n,t.lineWidth=e*i,t.beginPath(),t.moveTo(r[0].ut,r[0].ct);for(let i=1;i<r.length;i++)t.lineTo(r[i].ut,r[i].ct);t.stroke()}if(h&&r.length>0){const s=r[r.length-1];t.strokeStyle=n,t.lineWidth=e*i,t.globalAlpha=.5,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(h.ut,h.ct),t.stroke(),t.setLineDash([]),t.globalAlpha=1}if(this.kT.showArrowHead&&r.length>1&&this.DT(t,r[r.length-2],r[r.length-1],i,n),this.kT.showCircles)for(let s=0;s<r.length;s++)this.RT(t,r[s].ut,r[s].ct,i,n,0===s)}DT(t,i,s,n,e){const r=12*n,h=Math.atan2(s.ct-i.ct,s.ut-i.ut),l={ut:s.ut-r*Math.cos(h-Math.PI/6),ct:s.ct-r*Math.sin(h-Math.PI/6)},o={ut:s.ut-r*Math.cos(h+Math.PI/6),ct:s.ct-r*Math.sin(h+Math.PI/6)};t.fillStyle=e,t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(l.ut,l.ct),t.lineTo(o.ut,o.ct),t.closePath(),t.fill()}RT(t,i,s,n,e,r){const h=this.kT.circleRadius*n;t.beginPath(),t.arc(i,s,h,0,2*Math.PI),r?(t.fillStyle=e,t.fill()):(t.strokeStyle=e,t.lineWidth=2*n,t.stroke(),t.fillStyle="#ffffff",t.fill(),t.strokeStyle=e,t.stroke())}setColor(t){this.kT.lineColor=t,this.pM()}color(){return this.kT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.kT.points||0===this.kT.points.length)return!1;for(let s=0;s<this.kT.points.length-1;s++)try{const n=this.kT.points[s],e=this.kT.points[s+1];let r=Zn(this._chart,this._series,n.time);if(null===r){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(r=t.logicalToCoordinate(i))}let h=Zn(this._chart,this._series,e.time);if(null===h){const t=this._chart.timeScale(),i=t.timeToIndex(e.time,!0);null!=i&&(h=t.logicalToCoordinate(i))}const l=this._series.priceToCoordinate(n.price),o=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===o)continue;if(this.vP(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.kT.points)try{let n=Zn(this._chart,this._series,s.time);if(null===n){const t=this._chart.timeScale(),i=t.timeToIndex(s.time,!0);null!=i&&(n=t.logicalToCoordinate(i))}const e=this._series.priceToCoordinate(s.price);if(null==n||null===e)continue;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=8)return!0}catch{continue}return!1}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.kT.points||0===this.kT.points.length)return null;for(let s=0;s<this.kT.points.length;s++)try{const n=this.kT.points[s];let e=Zn(this._chart,this._series,n.time);if(null===e){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(e=t.logicalToCoordinate(i))}const r=this._series.priceToCoordinate(n.price);if(null==e||null===r)continue;if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return s}catch{continue}return null}startDrag(t){this.KC=!0,this.PT=t}stopDrag(){this.KC=!1,this.PT=-1}updateDrag(t,i){this.KC&&-1!==this.PT&&this.kT.points&&this.PT>=0&&this.PT<this.kT.points.length&&(this.kT.points[this.PT]={time:t,price:i},this.pM(),this.kT.onUpdate&&this.kT.onUpdate())}getPoints(){return this.kT.points||[]}addPoint(t){this.kT.points||(this.kT.points=[]),this.kT.points.push(t),this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.kT.points||[]).map(t=>ml(t)),style:{lineColor:this.kT.lineColor,lineWidth:this.kT.lineWidth,showArrowHead:this.kT.showArrowHead,showCircles:this.kT.showCircles,circleRadius:this.kT.circleRadius}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){if(this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.TT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.TT),this.TT=null}this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.kT.onRemove&&this.kT.onRemove()}}function Io(t,i){return new Vo(t,i)}class Lo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ao{constructor(t){this.jC=t,this.Jt=new Lo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bo extends bl{constructor(t,i){super(t,"brush",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.FT=!1,this.mT=!1,this.VT=[],this.IT=!1,this.Rf=null,this.BS=null,this.US=null,this.jS=null,this.XS=null,this.LT=void 0,this.HS=null,this.KC=!1,this.JC=null,this.kP=null,this.AT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.AT),this.cS(),0===(this.AT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.FT)return;const t=this._chart.chartElement();t&&(this.Rf=t,this.FT=!0,this.US=t=>this.qS(t),this.jS=t=>this.YS(t),this.XS=()=>this.GS(),this.HS=t=>{this.LT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.HS),t.addEventListener("pointerdown",this.US,!0),t.addEventListener("pointermove",this.jS,!0),t.addEventListener("pointerup",this.XS,!0),t.addEventListener("pointercancel",this.XS,!0))}stopDrawingMode(){if(!this.FT)return;this.BT(),this.FT=!1;const t=this.Rf;t&&(this.US&&t.removeEventListener("pointerdown",this.US,!0),this.jS&&t.removeEventListener("pointermove",this.jS,!0),this.XS&&(t.removeEventListener("pointerup",this.XS,!0),t.removeEventListener("pointercancel",this.XS,!0))),this.HS&&(this._chart.unsubscribeCrosshairMove(this.HS),this.HS=null),this.US=null,this.jS=null,this.XS=null,this.Rf=null}isDrawingModeActive(){return this.FT}qS(t){if(this.OT())return;const i=this.ET(t,!1);null!==i&&(this.mT=!0,this.VT=[i],this.BS=t.pointerId,yl(this._chart,!0),this.Rf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.WT())}YS(t){if(!this.mT)return;const i=this.ET(t,!0);if(null===i)return;const s=this.VT[this.VT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.AT.sampleDistance??4)||(this.VT.push(i),t.preventDefault(),t.stopPropagation(),this.WT())}GS(){this.mT&&this.BT()}BT(){if(!this.mT)return;this.mT=!1,this.wx();const t=[];for(const i of this.VT){const s=Kn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.VT=[],t.length<2?this.pM():(this.AT.points=t,this.stopDrawingMode(),this.pM(),this.AT.onUpdate&&this.AT.onUpdate(),this.AT.onComplete&&this.AT.onComplete())}OT(){const t=this.LT;return"string"==typeof t&&t.split("#")[0]!==this.id}wx(){null!==this.BS&&(this.Rf&&this.Rf.hasPointerCapture(this.BS)&&this.Rf.releasePointerCapture(this.BS),this.BS=null)}ET(t,i){const s=this.zT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.sC;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}zT(){const t=this.$T();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,sC:i.top,ts:n,qt:i.height}}$T(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}WT(){this.IT||(this.IT=!0,requestAnimationFrame(()=>{this.IT=!1,this.pM()}))}drawToCanvas(t,i,s){const n=this.mT?this.VT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.HT(i,s);if(0===n.length)return;const e=this.XC;if(t.strokeStyle=this.AT.color,t.lineWidth=(this.AT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.AT.smoothing&&n.length>2){for(let i=1;i<n.length-1;i++){const s=(n[i].ut+n[i+1].ut)/2,e=(n[i].ct+n[i+1].ct)/2;t.quadraticCurveTo(n[i].ut,n[i].ct,s,e)}t.lineTo(n[n.length-1].ut,n[n.length-1].ct)}else for(let i=1;i<n.length;i++)t.lineTo(n[i].ut,n[i].ct);t.stroke(),!e&&!this.GC||this.isLocked()||(this.fP(t,n[0],i),this.fP(t,n[n.length-1],i))}fP(t,i,s){t.fillStyle=this.AT.color,t.strokeStyle="#ffffff",t.lineWidth=2*s,t.beginPath(),t.arc(i.ut,i.ct,5*s,0,2*Math.PI),t.fill(),t.stroke()}HT(t,i){const s=this.AT.points??[],n=[];for(const e of s){const s=Zn(this._chart,this._series,e.time),r=this._series.priceToCoordinate(e.price);null!==s&&null!==r&&n.push({ut:s*t,ct:r*i})}return n}hitTest(t,i){const s=this.HT(1,1);for(let n=1;n<s.length;n++)if(Oo(t,i,s[n-1],s[n])<=8)return!0;return!1}hitTestEndpoint(t,i){return this.hitTest(t,i)?"stroke":null}startDrag(t,i){this.KC=!0,this.JC=i,this.kP=(this.AT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.kP;if(!this.KC||null===s||!this.AT.points)return;const n=dl(this.JC,t,i);this.AT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.pM(),this.AT.onUpdate&&this.AT.onUpdate()}stopDrag(){this.KC=!1,this.JC=null,this.kP=null}setColor(t){this.AT.color=t,this.pM()}color(){return this.AT.color??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}cS(){this.eh=new Ao(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):null}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.stopDrawingMode(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null),this.eh=null,this.AT.onRemove&&this.AT.onRemove()}_serializeShape(){return{type:"brush",points:(this.AT.points??[]).map(ml),style:{color:this.AT.color,lineWidth:this.AT.lineWidth,smoothing:this.AT.smoothing}}}getPoints(){return this.AT.points??[]}}function Oo(t,i,s,n){const e=n.ut-s.ut,r=n.ct-s.ct,h=e*e+r*r;if(0===h)return Math.hypot(t-s.ut,i-s.ct);let l=((t-s.ut)*e+(i-s.ct)*r)/h;return l=Math.max(0,Math.min(1,l)),Math.hypot(t-(s.ut+l*e),i-(s.ct+l*r))}function Eo(t,i={}){return new Bo(t,i)}class Wo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zo{constructor(t){this.jC=t,this.Jt=new Wo(t)}renderer(){return this.jC.isComplete()?this.Jt:null}}class $o extends bl{constructor(t,i){super(t,"text-tool",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.NT=!1,this.UT=null,this.bP=null,this.qT={text:"Double-click to edit",fontSize:14,fontFamily:"Arial, sans-serif",textColor:"#FFFFFF",backgroundColor:"#2962FF",backgroundOpacity:.8,padding:8,borderColor:"#2962FF",borderWidth:1,textAlign:"left",maxWidth:200,anchor:"top-left",pointer:!1,borderRadius:0,...i},this._registerOptions(this.qT),this.cS(),this.jT(),this.qT.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.setPosition(t.gt,t.bt),this.qT.onComplete&&this.qT.onComplete()}))}jT(){const t=t=>{if(!this.NT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.qT.text&&""!==this.qT.text.trim()&&"Type here..."!==this.qT.text||this.remove())};this.UT=t,this._chart.subscribeClick(t)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new zo(this)}getTime(){return this.qT.time}getPrice(){return this.qT.price}getText(){return this.qT.text||""}getOptions(){return this.qT}setPosition(t,i){this.qT.time=t,this.qT.price=i,this._update()}setText(t){this.qT.text=t,this._update(),this.qT.onTextChange&&this.qT.onTextChange(t)}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.bP?.mP()&&!(!this.qT.time||void 0===this.qT.price)}setColor(t){this.qT.textColor=t,this.qT.borderColor=t,this.pM()}color(){return this.qT.textColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this._update())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this._update())}isHovered(){return this.GC}setEditing(t){this.NT!==t&&(this.NT=t,this._update())}isEditing(){return this.NT}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.qT.time,n=this.qT.price,e=Zn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.qT.fontSize||14,l=this.qT.padding??8,o=this.qT.text||"",a=.6*h,_=Math.min(o.length*a,this.qT.maxWidth||200)+2*l,u=h+2*l,c=this.YT(u),d=this.XT(e,r,_,u,c),p=d.qh-("left"===this.qT.anchor?c:0),f=d.qh+_+("right"===this.qT.anchor?c:0);return t>=p&&t<=f&&i>=d.sC&&i<=d.sC+u}YT(t){const i=this.qT.anchor;return!this.qT.pointer||"left"!==i&&"right"!==i?0:Math.round(.35*t)}XT(t,i,s,n,e){switch(this.qT.anchor){case"left":return{qh:t+e,sC:i-n/2};case"right":return{qh:t-e-s,sC:i-n/2};case"center":return{qh:t-s/2,sC:i-n/2};default:return{qh:t,sC:i}}}GT(t,i,s,n,e,r,h,l,o){const a=Math.max(0,Math.min(o,n/2,e/2));t.beginPath(),t.moveTo(i+a,s),t.lineTo(i+n-a,s),t.arcTo(i+n,s,i+n,s+a,a),r>0&&"right"===this.qT.anchor&&(t.lineTo(i+n,l-r),t.lineTo(h,l),t.lineTo(i+n,l+r)),t.lineTo(i+n,s+e-a),t.arcTo(i+n,s+e,i+n-a,s+e,a),t.lineTo(i+a,s+e),t.arcTo(i,s+e,i,s+e-a,a),r>0&&"left"===this.qT.anchor&&(t.lineTo(i,l+r),t.lineTo(h,l),t.lineTo(i,l-r)),t.lineTo(i,s+a),t.arcTo(i,s,i+a,s,a),t.closePath()}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.qT.time,n=this.qT.price,e=Zn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0;return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"anchor":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P={gt:this.qT.time,bt:this.qT.price}}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC){if("body"===this.ZC&&this.$P){const s=dl(this.JC,t,i);this.setPosition(this.$P.gt+s.gt,this.$P.bt+s.bt)}else this.setPosition(t,i);this.qT.onUpdate&&this.qT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.qT.time,e=this.qT.price,r=this.qT.text||"",h=(Zn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.qT.fontSize||14)*i,a=(this.qT.padding??8)*i,_=(this.qT.maxWidth||200)*i;t.font=`${o}px ${this.qT.fontFamily||"Arial"}`,t.textBaseline="top";const u=r.split(" "),c=[];let d="";for(const i of u){const s=d?`${d} ${i}`:i;t.measureText(s).width>_&&d?(c.push(d),d=i):d=s}d&&c.push(d);let p=0;for(const i of c){const s=t.measureText(i);p=Math.max(p,s.width)}const f=p+2*a,v=1.2*o,m=c.length*v+2*a,w=this.YT(m),{qh:g,sC:b}=this.XT(h,l,f,m,w),M=(this.qT.borderRadius??0)*i,y=this.qT.backgroundOpacity??.8,S=this.qT.backgroundColor||"#2962FF";y>0&&(t.fillStyle=this._S(S,y),this.GT(t,g,b,f,m,w,h,l,M),t.fill()),(this.XC||this.GC)&&(t.strokeStyle=this.qT.borderColor??"#FFFFFF",t.lineWidth=(this.qT.borderWidth||1)*i*(this.XC?2:1),this.GT(t,g,b,f,m,w,h,l,M),t.stroke()),t.fillStyle=this.qT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=g+a;if("center"===this.qT.textAlign){n=g+(f-t.measureText(s).width)/2}else if("right"===this.qT.textAlign){n=g+f-t.measureText(s).width-a}const e=b+a+i*v;t.fillText(s,n,e)}if((this.XC||this.GC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.qT.textColor??"#2962ff",t.beginPath(),t.arc(h,l,s,0,2*Math.PI),t.fill(),t.fillStyle="#FFFFFF",t.beginPath(),t.arc(h,l,s-2*i,0,2*Math.PI),t.fill()}}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}_serializeShape(){return{type:"text",points:[vl(this.qT.price??0,fl(this.qT.time))],style:{fontSize:this.qT.fontSize,fontFamily:this.qT.fontFamily,textColor:this.qT.textColor,backgroundColor:this.qT.backgroundColor,backgroundOpacity:this.qT.backgroundOpacity,padding:this.qT.padding,borderColor:this.qT.borderColor,borderWidth:this.qT.borderWidth,textAlign:this.qT.textAlign,maxWidth:this.qT.maxWidth,anchor:this.qT.anchor,pointer:this.qT.pointer,borderRadius:this.qT.borderRadius},extra:{text:this.qT.text}}}remove(){this.bP?.wP(),this.UT&&(this._chart.unsubscribeClick(this.UT),this.UT=null),this.jb&&this._series&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.qT.onRemove&&this.qT.onRemove()}}function Ho(t,i){return new $o(t,i)}class No{constructor(t){this.KT=t}calculatePips(t,i){return Math.abs(i-t)/this.KT.pipValue}calculatePercent(t,i){return(i-t)/t*100}calculateRiskReward(t,i,s){const n=Math.abs(t-i),e=Math.abs(s-t);return 0===n?0:e/n}calculateMetrics(t,i,s,n){const e={entryPrice:t,stopLoss:i,takeProfit:s,quantity:n,stopLossPips:this.calculatePips(t,i),takeProfitPips:this.calculatePips(t,s),stopLossPercent:this.calculatePercent(t,i),takeProfitPercent:this.calculatePercent(t,s),riskRewardRatio:this.calculateRiskReward(t,i,s)};if(void 0!==n){const r=Math.abs(t-i),h=Math.abs(s-t);e.stopLossAmount=r*n,e.takeProfitAmount=h*n}return e}formatPips(t,i=1){return`${t>=0?"+":""}${t.toFixed(i)} pips`}formatPercent(t,i=2){return`${t>=0?"+":""}${t.toFixed(i)}%`}formatRiskReward(t,i=2){return`1:${t.toFixed(i)}`}updatePipConfig(t){this.KT={...this.KT,...t}}getPipConfig(){return{...this.KT}}}function Uo(t){const i=t.toString().split("."),s=i.length>1?i[1].length:0;let n;return n=s>=5?1e-5:4===s?1e-4:3===s?.001:2===s?.01:1===s?.1:1,{pipValue:n,decimals:s}}function qo(t,i){return"number"==typeof t?Uo(t):void 0!==i?Uo(i):{pipValue:.1,decimals:1}}class jo{constructor(t){this.KT=t}calculateMetrics(t,i,s,n,e){const r=n-i;return{point1:{time:t,price:i},point2:{time:s,price:n},priceDifference:r,pricePercent:r/i*100,pips:Math.abs(r)/this.KT.pipValue,timeDifference:this.ZT(t,s),barCount:e}}ZT(t,i){return"number"==typeof t&&"number"==typeof i?Math.abs(i-t):0}formatPriceDifference(t,i=5){return`${t>=0?"+":""}${t.toFixed(i)}`}formatPips(t,i=1){return`${t.toFixed(i)} pips`}formatPercent(t,i=2){return`${t>=0?"+":""}${t.toFixed(i)}%`}formatTimeDifference(t){if(0===t)return"N/A";const i=Math.floor(t/86400),s=Math.floor(t%86400/3600),n=Math.floor(t%3600/60);return i>0?`${i}d ${s}h`:s>0?`${s}h ${n}m`:n>0?`${n}m`:`${t}s`}formatBarCount(t){return`${t} ${1===t?"bar":"bars"}`}updatePipConfig(t){this.KT={...this.KT,...t}}getPipConfig(){return{...this.KT}}}class Yo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xo{constructor(t){this.jC=t,this.Jt=new Yo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class Go extends bl{constructor(t,i){super(t,"ruler-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.oT=null,this.iP=!1,this.XC=!1,this.GC=!1,this.nP=null,this.KC=!1,this.aT=null,this.ep=null,this.JT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.JT);const s=this.JT.pipConfig||qo(this.JT.symbol||"DEFAULT");this.uT=new jo(s),this.cS(),this.JT.interactive?this.rP():this.JT.point1Time&&this.JT.point2Time&&(this.iP=!0,this.cT())}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Xo(this)}rP(){this.oT=new Pl(this._chart,this._series,{HC:t=>{this.JT.point1Time=t.gt,this.JT.point1Price=t.bt,this.pM()},NC:t=>{this.JT.point2Time=t.gt,this.JT.point2Price=t.bt},UC:(t,i)=>{this.JT.point1Time=t.gt,this.JT.point1Price=t.bt,this.JT.point2Time=i.gt,this.JT.point2Price=i.bt,this.iP=!0,this.nP=null,this.cT(),this.dT(),this.pM()},qC:t=>{this.nP=t,this.pM()}}),this.oT.FC()}drawToCanvas(t,i,s){if(!this.iP&&this.JT.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return;const n=(Zn(this._chart,this._series,this.JT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.JT.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.JT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.JT.point2Price)??0)*s;(this.XC||this.GC&&!this.isLocked())&&(t.strokeStyle=this.JT.selectionColor,t.lineWidth=this.JT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.QT(t,n,e,r,h,i),this.fP(t,n,e,i),this.fP(t,r,h,i),this.JT.showLabel&&this.Gb&&this.xP(t,n,e,r,h,i,s)}QT(t,i,s,n,e,r){const h=this.JT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*r,t.beginPath(),"price"===h)for(const r of[s,e])t.moveTo(Math.min(i,n)-l/2,r),t.lineTo(Math.max(i,n)+l/2,r);else for(const r of[i,n])t.moveTo(r,Math.min(s,e)-l/2),t.lineTo(r,Math.max(s,e)+l/2);t.stroke()}fP(t,i,s,n){const e=this.XC?this.JT.selectionColor:this.JT.lineColor,r=this.XC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.XC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}pP(t,i,s){if(!this.JT.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this.JT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.JT.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s;t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.fP(t,n,e,i),t.globalAlpha=.5,this.fP(t,r,h,i),t.globalAlpha=1}xP(t,i,s,n,e,r,h){if(!this.Gb)return;const l=(i+n)/2,o=(s+e)/2,a=this.JT.measure??"both",_=[];"time"!==a&&(_.push(this.uT.formatPips(this.Gb.pips)),_.push(this.uT.formatPercent(this.Gb.pricePercent))),"price"!==a&&_.push(this.uT.formatBarCount(this.Gb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.JT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.JT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}cT(){if(!this.JT.point1Time||!this.JT.point2Time||void 0===this.JT.point1Price||void 0===this.JT.point2Price)return;const t=this.tk();this.Gb=this.uT.calculateMetrics(this.JT.point1Time,this.JT.point1Price,this.JT.point2Time,this.JT.point2Price,t),this.JT.onUpdate&&this.Gb&&this.JT.onUpdate(this.Gb)}tk(){if(!this.JT.point1Time||!this.JT.point2Time)return 0;const t=Zn(this._chart,this._series,this.JT.point1Time),i=Zn(this._chart,this._series,this.JT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.JT.point1Time=t,this.JT.point1Price=i,this.JT.point2Time=s,this.JT.point2Price=n,this.cT(),this.pM()}getMetrics(){return this.Gb}remove(){this.destroy()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.oT&&(this.oT.m(),this.oT=null),this.fT(),this.JT.onRemove&&this.JT.onRemove()}dT(){this.ep=t=>{this.pT(t)},this._chart.subscribeCrosshairMove(this.ep)}fT(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}pT(t){if(!t.point)return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.XC||!this.KC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.aT?(this.JT.point1Time=i,this.JT.point1Price=s):"point2"===this.aT&&(this.JT.point2Time=i,this.JT.point2Price=s),this.cT(),this.pM())}startDrag(t){this.KC=!0,this.aT=t}stopDrag(){this.KC=!1,this.aT=null}updateDrag(t,i){this.KC&&this.aT&&("point1"===this.aT?(this.JT.point1Time=t,this.JT.point1Price=i):(this.JT.point2Time=t,this.JT.point2Price=i),this.cT(),this.pM())}hitTestEndpoint(t,i){if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return null;const s=Zn(this._chart,this._series,this.JT.point1Time)??0,n=this._series.priceToCoordinate(this.JT.point1Price)??0,e=Zn(this._chart,this._series,this.JT.point2Time)??0,r=this._series.priceToCoordinate(this.JT.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.cT(),this.pM()}_serializeShape(){return{type:"ruler",points:[vl(this.JT.point1Price??0,fl(this.JT.point1Time)),vl(this.JT.point2Price??0,fl(this.JT.point2Time))],style:{lineColor:this.JT.lineColor,lineWidth:this.JT.lineWidth,showLabel:this.JT.showLabel,labelBackgroundColor:this.JT.labelBackgroundColor,labelTextColor:this.JT.labelTextColor,selectionColor:this.JT.selectionColor,selectionLineWidth:this.JT.selectionLineWidth},extra:{symbol:this.JT.symbol,pipConfig:this.JT.pipConfig,measure:this.JT.measure}}}setColor(t){this.JT.lineColor=t,this.pM()}color(){return this.JT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isSelected(){return this.XC}isComplete(){return this.iP}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return!1;const s=Zn(this._chart,this._series,this.JT.point1Time)??0,n=this._series.priceToCoordinate(this.JT.point1Price)??0,e=Zn(this._chart,this._series,this.JT.point2Time)??0,r=this._series.priceToCoordinate(this.JT.point2Price)??0;return this.ik(t,i,s,n,e,r)<=(this.XC?12:8)}ik(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;let a,_,u=-1;0!==o&&(u=((t-s)*h+(i-n)*l)/o),u<0?(a=s,_=n):u>1?(a=e,_=r):(a=s+u*h,_=n+u*l);const c=t-a,d=i-_;return Math.sqrt(c*c+d*d)}}function Ko(t,i){return new Go(t,i)}class Zo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Jo{constructor(t){this.jC=t,this.Jt=new Zo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class Qo extends bl{constructor(t,i){super(t,"position-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.XC=!1,this.GC=!1,this.bP=null,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.sk=null,this.nk=null,this.ek={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.ek);const s=this.ek.pipConfig||qo(this.ek.entryPrice);this.uT=new No(s),this.cS(),this.cT(),this.ek.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){const i=this.ek,s=t.bt-i.entryPrice;i.entryPrice=t.bt,i.entryTime=t.gt,void 0!==i.stopLoss&&(i.stopLoss+=s),void 0!==i.takeProfit&&(i.takeProfit+=s),i.endTime=Kn(this._chart,this._series,Il(this._chart,t.ut))??void 0,this.cT(),this.pM()}isComplete(){return!this.bP?.mP()}rk(){const t=Zn(this._chart,this._series,this.ek.entryTime)??0;return{hk:t,lk:Zn(this._chart,this._series,this.ek.endTime)??t+Vl(this._chart)}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Jo(this)}drawToCanvas(t,i,s){if(!this.isComplete())return;if(this.sk&&this.ek.takeProfit){const n=this._chart.timeScale();this.ak(t,this.sk,i,s,n),(this.GC||this.XC)&&this.xP(t,this.sk,"profit",i,s,n)}if(this.nk&&this.ek.stopLoss){const n=this._chart.timeScale();if(this.ak(t,this.nk,i,s,n),this.GC||this.XC){const n=this._chart.timeScale();this.xP(t,this.nk,"loss",i,s,n)}}const n=this._chart.timeScale();if(this._k(t,i,s,n),this.ek.takeProfit){const n=this._chart.timeScale();this.fP(t,this.ek.takeProfit,this.ek.profitColor,i,s,n)}if(this.ek.stopLoss){const n=this._chart.timeScale();this.fP(t,this.ek.stopLoss,this.ek.lossColor,i,s,n)}}ak(t,i,s,n,e){const r=this.rk(),h=r.hk*s,l=r.lk*s,o=(this._series.priceToCoordinate(i.uk)??0)*n,a=(this._series.priceToCoordinate(i.ck)??0)*n;t.fillStyle=this._S(i.R,.15),t.fillRect(h,Math.min(o,a),l-h,Math.abs(a-o)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(h,a),t.lineTo(l,a),t.stroke()}_k(t,i,s,n){const e=this.rk(),r=e.hk*i,h=e.lk*i,l=(this._series.priceToCoordinate(this.ek.entryPrice)??0)*s,o=this.ek.entryLineColor;t.strokeStyle=o,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(r,l),t.lineTo(h,l),t.stroke(),t.setLineDash([]),t.strokeStyle=this.ek.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(r,0),t.lineTo(r,a),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.isLocked())t.fillStyle=this.ek.entryLineColor,t.beginPath(),t.arc(r,l,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(r,l,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(h-s/2,l-s/2,s,s),t.strokeRect(h-s/2,l-s/2,s,s)}}cT(){this.ek.stopLoss&&this.ek.takeProfit&&(this.Gb=this.uT.calculateMetrics(this.ek.entryPrice,this.ek.stopLoss,this.ek.takeProfit,this.ek.quantity),this.dk(),this.ek.onUpdate&&this.Gb&&this.ek.onUpdate(this.Gb))}dk(){const t=this.pk();this.ek.takeProfit&&(this.sk={fk:this.ek.entryTime,vk:t,uk:this.ek.entryPrice,ck:this.ek.takeProfit,R:this.ek.profitColor,Oy:this.ek.opacity}),this.ek.stopLoss&&(this.nk={fk:this.ek.entryTime,vk:t,uk:this.ek.entryPrice,ck:this.ek.stopLoss,R:this.ek.lossColor,Oy:this.ek.opacity})}pk(){this._chart.timeScale().getVisibleLogicalRange();return this.ek.entryTime}xP(t,i,s,n,e,r){if(!this.Gb)return;const h=(Zn(this._chart,this._series,this.ek.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.ck)??0)*e,o="profit"===s,a=o?this.Gb.takeProfitPips:this.Gb.stopLossPips,_=o?this.ek.takeProfit:this.ek.stopLoss,u=this.Gb.riskRewardRatio,c=o?`Objetivo: ${_?.toFixed(5)} (${a.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${a.toFixed(1)} pips)`;t.font=11*n+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const d=6*n,p=t.measureText(c).width+2*d,f=20*n,v=3*e,m=h+8*n,w=l<=(this._series.priceToCoordinate(this.ek.entryPrice)??0)*e?l-f-v:l+v;t.fillStyle=i.R,t.fillRect(m,w,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,m+d,w+f/2)}fP(t,i,s,n,e,r){const h=this.rk(),l=h.hk*n,o=h.lk*n,a=(this._series.priceToCoordinate(i)??0)*e,_=s;t.fillStyle=_,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(l,a,5*n,0,2*Math.PI),t.fill(),t.stroke();const u=8*n,c=s;t.fillStyle=c,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-u/2,a-u/2,u,u),t.strokeRect(o-u/2,a-u/2,u,u)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}updatePosition(t){this.ek={...this.ek,...t},this.cT(),this._update()}getMetrics(){return this.Gb}setStopLoss(t){this.ek.stopLoss=t,this.cT(),this._update()}setTakeProfit(t){this.ek.takeProfit=t,this.cT(),this._update()}setEntryPrice(t){this.ek.entryPrice=t,this.cT(),this._update()}_serializeShape(){return{type:"position",points:[vl(this.ek.entryPrice,fl(this.ek.entryTime))],style:{profitColor:this.ek.profitColor,lossColor:this.ek.lossColor,entryLineColor:this.ek.entryLineColor,opacity:this.ek.opacity,showTooltips:this.ek.showTooltips},extra:{endTime:fl(this.ek.endTime),stopLoss:this.ek.stopLoss,takeProfit:this.ek.takeProfit,quantity:this.ek.quantity,pipConfig:this.ek.pipConfig}}}setColor(t){this.ek.entryLineColor=t,this.pM()}color(){return this.ek.entryLineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||!this.ek.stopLoss&&!this.ek.takeProfit)return!1;const{hk:s,lk:n}=this.rk(),e=Math.min(s,n),r=Math.max(s,n);if(this.ek.takeProfit&&this.ek.stopLoss){const n=this._series.priceToCoordinate(this.ek.takeProfit)??0,h=this._series.priceToCoordinate(this.ek.stopLoss)??0,l=Math.min(n,h),o=Math.max(n,h);if(t>=e&&t<=r&&i>=l&&i<=o)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=l&&i<=o)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const{hk:s,lk:n}=this.rk(),e=Math.min(s,n),r=Math.max(s,n);if(this.ek.takeProfit){const n=this._series.priceToCoordinate(this.ek.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.ek.stopLoss){const n=this._series.priceToCoordinate(this.ek.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.ek.takeProfit){const s=this._series.priceToCoordinate(this.ek.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.ek.stopLoss){const s=this._series.priceToCoordinate(this.ek.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const h=this._series.priceToCoordinate(this.ek.entryPrice)??0;if(t>=e&&t<=r&&Math.abs(i-h)<=8)return"entry";if(this.ek.takeProfit&&this.ek.stopLoss){const s=this._series.priceToCoordinate(this.ek.takeProfit)??0,n=this._series.priceToCoordinate(this.ek.stopLoss)??0,h=Math.min(s,n),l=Math.max(s,n);if(t>=e&&t<=r&&i>=h&&i<=l)return"move"}return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"move"===t&&(this.$P={mk:this.ek.entryPrice,wk:this.ek.entryTime??null,aS:this.ek.endTime??null,gk:this.ek.takeProfit??null,bk:this.ek.stopLoss??null})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC&&this.ZC){if("entry"===this.ZC)this.ek.entryPrice=i;else if("move"===this.ZC){if(this.$P){const s=dl(this.JC,t,i),n=this.$P;this.ek.entryPrice=n.mk+s.bt,null!==n.gk&&(this.ek.takeProfit=n.gk+s.bt),null!==n.bk&&(this.ek.stopLoss=n.bk+s.bt),null!==n.wk&&(this.ek.entryTime=this.Mk(n.wk,s.gt)),null!==n.aS&&(this.ek.endTime=this.Mk(n.aS,s.gt))}}else"tp"===this.ZC||"tp-right"===this.ZC?(this.ek.takeProfit=i,"tp-right"===this.ZC?this.ek.endTime=t:this.ek.entryTime=t):"sl"!==this.ZC&&"sl-right"!==this.ZC||(this.ek.stopLoss=i,"sl-right"===this.ZC?this.ek.endTime=t:this.ek.entryTime=t);this.cT(),this.pM()}}Mk(t,i){return t+i}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.ek.onRemove&&this.ek.onRemove()}}function ta(t,i){return new Qo(t,i)}class ia{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class sa{constructor(t){this.jC=t,this.Jt=new ia(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class na extends bl{constructor(t,i){super(t,"gantt",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.yk=-1,this.JC=null,this.$P=null,this.Sk=-1,this.bP=null,this.xk={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.xk),this.cS(),this.xk.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){const i=this.xk.segments??[],s=Kn(this._chart,this._series,Il(this._chart,t.ut))??t.gt,n=this.xk.rowHeight+this.xk.rowSpacing,e=Math.max(0,Math.floor((t.ct-50)/n)),r=i.length>0?e-i[0].level:0;for(const n of i)n.startTime=t.gt,n.endTime=s,n.level=Math.max(0,n.level+r);this.pM()}isComplete(){return!this.bP?.mP()}selectionBox(){const t=this.xk.segments??[];if(0===t.length)return null;const i=this.xk.rowHeight,s=i+this.xk.rowSpacing,n={left:1/0,top:1/0,right:-1/0,bottom:-1/0};for(const e of t){const t=50+e.level*s;n.left=Math.min(n.left,Zn(this._chart,this._series,e.startTime)??0),n.right=Math.max(n.right,Zn(this._chart,this._series,e.endTime)??0),n.top=Math.min(n.top,t),n.bottom=Math.max(n.bottom,t+i)}return n}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new sa(this)}drawToCanvas(t,i,s){if(!this.isComplete()||!this.xk.segments||0===this.xk.segments.length)return;const n=50*s,e=this.xk.rowHeight*s,r=this.xk.rowSpacing*s;this.xk.showGrid&&this.rm(t,n,e,r,i,s),this.xk.segments.forEach((s,h)=>{const l=(Zn(this._chart,this._series,s.startTime)??0)*i,o=(Zn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.Sk||this.GC&&!this.isLocked();this.Ck(t,l,o,a,e,s,_,i)})}rm(t,i,s,n,e,r){if(!this.xk.segments)return;const h=Math.max(...this.xk.segments.map(t=>t.level),0),l=this._chart.chartElement().clientWidth*e;t.strokeStyle="rgba(200, 200, 200, 0.3)",t.lineWidth=1*e;for(let e=0;e<=h+1;e++){const r=i+e*(s+n);t.beginPath(),t.moveTo(0,r),t.lineTo(l,r),t.stroke()}}Ck(t,i,s,n,e,r,h,l){const o=s-i,a=this._S(r.color,h?this.xk.fillOpacity+.2:this.xk.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.xk.borderWidth+(this.XC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.xk.showLabels&&r.label&&this.xP(t,i,n,o,e,r.label,l)}xP(t,i,s,n,e,r,h){const l=11*h,o=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let a=r;const _=n-2*o;let u=t.measureText(a).width;if(u>_&&_>0){for(;u>_&&a.length>0;)a=a.slice(0,-1),u=t.measureText(a+"...").width;a+="..."}t.fillText(a,i+o,s+e/2)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${Math.min(1,i)})`}addSegment(t){this.xk.segments||(this.xk.segments=[]),this.xk.segments.push(t),this.pM(),this.xk.onUpdate&&this.xk.onUpdate()}removeSegment(t){this.xk.segments&&t>=0&&t<this.xk.segments.length&&(this.xk.segments.splice(t,1),this.pM(),this.xk.onUpdate&&this.xk.onUpdate())}getSegments(){return this.xk.segments||[]}setColor(t){const i=this.xk.segments??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.xk.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.xk.segments?.[this.Sk];s&&(this.KC=!0,this.yk=this.Sk,this.JC=i,this.$P={oS:s.startTime,aS:s.endTime})}updateDrag(t,i){const s=this.xk.segments?.[this.yk];if(!this.KC||!this.$P||!s)return;const n=dl(this.JC,t,i);s.startTime=this.$P.oS+n.gt,s.endTime=this.$P.aS+n.gt,this.pM(),this.xk.onUpdate&&this.xk.onUpdate()}stopDrag(){this.KC=!1,this.yk=-1,this.JC=null,this.$P=null}hitTest(t,i){if(!this.isComplete()||!this.xk.segments||0===this.xk.segments.length)return!1;const s=this.xk.rowHeight,n=this.xk.rowSpacing;for(let e=0;e<this.xk.segments.length;e++){const r=this.xk.segments[e],h=Zn(this._chart,this._series,r.startTime)??0,l=Zn(this._chart,this._series,r.endTime)??0,o=50+r.level*(s+n);if(t>=h&&t<=l&&i>=o&&i<=o+s)return this.Sk=e,!0}return this.Sk=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.xk.rowHeight,rowSpacing:this.xk.rowSpacing,fillOpacity:this.xk.fillOpacity,borderWidth:this.xk.borderWidth,showLabels:this.xk.showLabels,showGrid:this.xk.showGrid},extra:{segments:(this.xk.segments||[]).map(t=>({oS:fl(t.startTime),aS:fl(t.endTime),sn:t.level,Jl:t.label,R:t.color,Pk:t.category}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.xk.onRemove&&this.xk.onRemove()}}function ea(t,i){return new na(t,i)}class ra{constructor(t,i,s={}){this.Tk=[],this.kk=[],this.Dk=[],this.Rk=!1,this.Fk=new Map,this.Vk=null,this.Ik=null,this.Lk=null,this.kx=null,this.Ak=null,this.ep=null,this.Bk=null,this.Ok=null,this.Ek=null,this.Wk=null,this.zk=null,this.$k=null,this.BS=null,this.Hk=!1,this.Nk=null,this.Uk=null,this.qk=new a,this.KC=!1,this.jk=null,this.Yk=new Set,this.Xk=null,this.Gk=new a,this.Lf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Kk()}startDrawing(t){this.Lk=t,this.Zk()}activeDrawingType(){return this.Lk}stopDrawing(){this.Lk=null}addTool(t,i){const s=i??t.id;return this.Fk.set(s,t),t.isComplete()||this.Yk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Yk.size>0}cancelPendingDrawings(){if(0===this.Yk.size)return 0;let t=0;for(const i of Array.from(this.Yk)){const s=this.Fk.get(i);s&&(this.Vk===i&&this.Jk(null),s.remove(),this.Fk.delete(i),t++)}return this.Yk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Gk.i(t)}unsubscribeDrawingCompleted(t){this.Gk._(t)}Qk(){0!==this.Yk.size&&null===this.Xk&&(this.Xk=setTimeout(()=>{this.Xk=null;const t=[];for(const i of Array.from(this.Yk)){const s=this.Fk.get(i);s?s.isComplete()&&(this.Yk.delete(i),t.push(i)):this.Yk.delete(i)}t.length>0&&this.recordChange();for(const i of t)this.Gk.p(i)},0))}removeTool(t){const i=this.Fk.get(t);return!!i&&(this.Vk===t&&this.Jk(null),i.remove(),this.Fk.delete(t),this.Yk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.Fk.has(t)&&(this.Jk(t),!0)}Jk(t){if(this.Vk===t)return;const i=null===this.Vk?void 0:this.Fk.get(this.Vk);i&&i.setSelected(!1),this.Vk=t;const s=null===t?void 0:this.Fk.get(t);s&&s.setSelected(!0),this.tD()}recordChange(){if(this.Rk)return;const t=this.serializeAll();JSON.stringify(t)!==JSON.stringify(this.Dk)&&(this.Tk.push(this.Dk),this.Tk.length>100&&this.Tk.shift(),this.kk=[],this.Dk=t)}canUndo(){return this.Tk.length>0}canRedo(){return this.kk.length>0}undo(){const t=this.Tk.pop();return void 0!==t&&(this.kk.push(this.Dk),this.iD(t),!0)}redo(){const t=this.kk.pop();return void 0!==t&&(this.Tk.push(this.Dk),this.iD(t),!0)}iD(t){this.Rk=!0;try{this.restoreAll({chart:this.Lf,series:this.be},t,!0),this.Dk=t}finally{this.Rk=!1}}subscribeSelectionChanged(t){this.qk.i(t)}unsubscribeSelectionChanged(t){this.qk._(t)}selectionBounds(){if(null===this.Vk)return null;const t=this.Fk.get(this.Vk);return t?this.sD(t):null}sD(t){const i=t.selectionBox()??this.nD(t);if(null===i)return null;const s=this.eD(t);return{left:i.left+s.ut,right:i.right+s.ut,top:i.top+s.ct,bottom:i.bottom+s.ct}}nD(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Zn(this.Lf,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,o),h=Math.max(h,o))}return l?{left:n,top:e,right:r,bottom:h}:null}eD(t){const i=this.Lf.chartElement(),s=this.bx(t);if(!i||!s)return{ut:0,ct:0};const n=i.getBoundingClientRect(),e=s.getBoundingClientRect();return{ut:e.left-n.left,ct:e.top-n.top}}tD(){this.qk.p({id:this.Vk,bounds:this.selectionBounds()})}deselectAll(){this.Zk()}deleteSelected(){if(this.Vk){const t=this.Fk.get(this.Vk);return(!t||!t.isLocked())&&this.removeTool(this.Vk)}return!1}getSelectedToolId(){return this.Vk}getAllTools(){return new Map(this.Fk)}getTool(t){return this.Fk.get(t)}clearAll(){this.Jk(null),this.Fk.forEach(t=>t.remove()),this.Fk.clear(),this.Yk.clear(),this.recordChange()}getToolCount(){return this.Fk.size}isToolSelected(t){return this.Vk===t}serializeAll(){const t=[];for(const i of this.Fk.values())i.isComplete()&&t.push(i.serialize());return t}restoreTool(t,i){const s=ra.rD(t,i);return s.applySerializedState(i),this.addTool(s,s.id),s}restoreAll(t,i,s=!0){s&&this.clearAll();for(const s of i)this.restoreTool(t,s)}static rD(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({hD:wl(n[t]),lD:gl(n[t],"price")??0});switch(s){case"trendLine":return Rl(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,...e});case"horizontalLine":return Ol(t,{price:h(0).lD,startTime:h(0).hD??void 0,...e});case"parallelChannel":return Gl(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,channelWidth:r?.channelWidth,...e});case"pitchfork":return Ql(t,{pivotTime:h(0).hD,pivotPrice:h(0).lD,upperTime:h(1).hD,upperPrice:h(1).lD,lowerTime:h(2).hD,lowerPrice:h(2).lD,...e});case"polygon":return ql(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).hD,s.price=h(i).lD,s}),...e});case"crossLine":return $l(t,{time:h(0).hD,price:h(0).lD,...e});case"verticalLine":return no(t,{time:h(0).hD,...e});case"fibRetracement":return uo(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return vo(t,{point1:i.hD?{time:i.hD,price:i.lD}:void 0,point2:s.hD?{time:s.hD,price:s.lD}:void 0,point3:n.hD?{time:n.hD,price:n.lD}:void 0,levels:r?.levels,...e})}case"fibFan":return Mo(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,levels:r?.levels,...e});case"rectangle":return Co(t,{time1:h(0).hD,price1:h(0).lD,time2:h(1).hD,price2:h(1).lD,...e});case"circle":return Do(t,{centerTime:h(0).hD,centerPrice:h(0).lD,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Io(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Eo(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Ho(t,{time:h(0).hD,price:h(0).lD,text:r?.text,...e});case"ruler":return Ko(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ta(t,{entryPrice:h(0).lD,entryTime:h(0).hD,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return ea(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.Xk&&(clearTimeout(this.Xk),this.Xk=null),this.Gk.m(),this.qk.m(),this.clearAll(),this.oD(),this.Tk=[],this.kk=[],this.Dk=[]}Kk(){this.kx=t=>{this.zC(t)},this.Lf.subscribeClick(this.kx),this.ep=t=>{this.$C(t)},this.Lf.subscribeCrosshairMove(this.ep);const t=this.Lf.chartElement();t&&(this.Bk=t=>this.aD(t),this.Ok=t=>this._D(t),this.Ek=t=>this.uD(t),this.Wk=t=>this._D(t),this.zk=t=>this.cD(t),t.addEventListener("pointerdown",this.Bk),t.addEventListener("pointerup",this.Ok),t.addEventListener("pointermove",this.Ek),t.addEventListener("pointercancel",this.Wk),t.addEventListener("lostpointercapture",this.zk)),us&&(this.$k=t=>this._D(t),window.addEventListener("pointerup",this.$k)),this.Ps.enableKeyboardShortcuts&&(this.Ak=t=>{this.dD(t)},document.addEventListener("keydown",this.Ak))}oD(){this.kx&&(this.Lf.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null);const t=this.Lf.chartElement();t&&(this.Bk&&(t.removeEventListener("pointerdown",this.Bk),this.Bk=null),this.Ok&&(t.removeEventListener("pointerup",this.Ok),this.Ok=null),this.Ek&&(t.removeEventListener("pointermove",this.Ek),this.Ek=null),this.Wk&&(t.removeEventListener("pointercancel",this.Wk),this.Wk=null),this.zk&&(t.removeEventListener("lostpointercapture",this.zk),this.zk=null)),this.$k&&(window.removeEventListener("pointerup",this.$k),this.$k=null),this.Ak&&(document.removeEventListener("keydown",this.Ak),this.Ak=null)}zC(t){if(this.Qk(),!t.point)return;if(this.Hk)return void(this.Hk=!1);if(this.KC)return;const i=this.pD(t.hoveredObjectId);i?this.selectTool(i):this.Zk()}$C(t){if(this.Nk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.KC&&this.jk){const i=this.Fk.get(this.jk);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Kn(this.Lf,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.pD(t.hoveredObjectId);if(this.Ik&&this.Ik!==i){const t=this.Fk.get(this.Ik);t&&t.setHovered(!1)}if(i){const t=this.Fk.get(i);t&&t.setHovered(!0)}this.Ik=i}pD(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.Fk)if(s.id===i)return t;return null}aD(t){if(this.KC)return;yl(this.Lf,!1);const i=this.Lf.chartElement();if(!i)return;const s=null!==this.Ik&&null!==this.Nk?{fD:this.Ik,Rw:this.Nk}:this.vD(t);if(null===s)return;const{fD:n,Rw:e}=s,r=this.Fk.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.mD(r,e.ut,e.ct);if(null!==h&&null!==l){yl(this.Lf,!0),this.selectTool(n),this.KC=!0,this.Hk=!0,this.jk=n,this.BS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.BS=null}r.startDrag(h,l),this.wD()}}uD(t){if(!this.KC||null===this.jk||"mouse"===t.pointerType)return;if(null!==this.BS&&t.pointerId!==this.BS)return;const i=this.Fk.get(this.jk);if(!i)return;const s=this.bx(i);if(null===s)return;const n=s.getBoundingClientRect(),e=i.series(),r=e.coordinateToPrice(t.clientY-n.top),h=Kn(this.Lf,e,t.clientX-n.left);null!==r&&null!==h&&(i.updateDrag(h,r),t.preventDefault())}_D(t){if(!this.KC||null===this.jk)return;if(t&&null!==this.BS&&t.pointerId!==this.BS)return;const i=this.jk;this.KC=!1,this.jk=null;try{const t=this.Fk.get(i);t&&t.stopDrag()}finally{this.wx(),this.gD()}this.recordChange()}cD(t){null!==this.BS&&t.pointerId!==this.BS||(this.BS=null,this._D())}bx(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}vD(t){for(const[i,s]of this.Fk){if(!s.isVisible()||s.isLocked())continue;const n=this.bx(s);if(null===n)continue;const e=n.getBoundingClientRect(),r={ut:t.clientX-e.left,ct:t.clientY-e.top};if(s.hitTest(r.ut,r.ct))return{fD:i,Rw:r}}return null}wx(){if(null===this.BS)return;const t=this.Lf.chartElement();t&&t.hasPointerCapture(this.BS)&&t.releasePointerCapture(this.BS),this.BS=null}wD(){if(null!==this.Uk)return;const t=this.Lf.options();this.Uk={bD:f(t.handleScroll),MD:f(t.handleScale)},this.Lf.applyOptions({handleScroll:!1,handleScale:!1})}gD(){const t=this.Uk;this.Uk=null,null!==t&&this.Lf.applyOptions({handleScroll:t.bD,handleScale:t.MD})}dD(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Qk(),"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const s=t.metaKey||t.ctrlKey;if(s&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}s&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.cancelPendingDrawings(),this._D(),this.Zk(),this.stopDrawing(),t.preventDefault())}mD(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Kn(this.Lf,t.series(),i)}}Zk(){this.Jk(null)}}const ha={...t,color:"#2196f3"};function la(){return"2.3.18-dev+202610170141"}export{ke as AreaSeries,Vo as ArrowTool,Ve as BarSeries,Ce as BaselineSeries,Bo as BrushTool,Ae as CandlestickSeries,ko as CircleTool,Li as ColorType,zl as CrossLineTool,U as CrosshairMode,Vh as DEFAULT_SESSIONS,qh as DraggablePriceLine,ra as DrawingToolsManager,ro as EXTENDED_FIBONACCI_RATIOS,ho as FibonacciCalculator,fo as FibonacciExtensionTool,bo as FibonacciFanTool,_o as FibonacciTool,na as GanttTool,Ee as HistogramSeries,Bl as HorizontalLineTool,Yh as InteractiveLineManager,Vi as LastPriceAnimationMode,oe as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,Xl as ParallelChannelTool,Jl as PitchforkTool,Ul as PolygonTool,No as PositionCalculator,ol as PositionLine,zr as PositionMarkersManager,Qo as PositionTool,Ii as PriceLineSource,di as PriceScaleMode,xo as RectangleTool,jo as RulerCalculator,Go as RulerTool,eo as STANDARD_FIBONACCI_RATIOS,$o as TextTool,Ai as TickMarkType,Fi as TrackingModeExitMode,Ih as TradingSessionsIndicator,Dl as TrendLineTool,so as VerticalLineTool,Oh as VolumeProfileIndicator,Ph as applyADX,Sh as applyATR,rh as applyBollingerBands,Th as applyCCI,lh as applyDonchianChannels,nh as applyEMA,gh as applyHeikinAshi,fh as applyIchimoku,hh as applyKeltnerChannels,Mh as applyMACD,Dh as applyMFI,Ch as applyOBV,oh as applyParabolicSAR,vh as applyPivotPoints,bh as applyRSI,sh as applySMA,yh as applyStochastic,uh as applySuperTrend,_h as applyVWAP,xh as applyVolume,eh as applyWMA,kh as applyWilliamsR,wh as calculateHeikinAshi,Uo as calculatePipConfig,Zn as coordinateFromTime,Io as createArrowTool,Eo as createBrushTool,Yn as createChart,jn as createChartEx,Do as createCircleTool,$l as createCrossLineTool,vo as createFibonacciExtensionTool,Mo as createFibonacciFanTool,uo as createFibonacciTool,ea as createGanttTool,Ol as createHorizontalLineTool,sr as createImageWatermark,Xh as createInteractiveLineManager,we as createOptionsChart,Gl as createParallelChannelTool,Ql as createPitchforkTool,ql as createPolygonTool,_l as createPositionLine,$r as createPositionMarkers,ta as createPositionTool,Co as createRectangleTool,Ko as createRulerTool,xr as createSeriesMarkers,Ho as createTextTool,Ge as createTextWatermark,Wr as createTimeLabels,jh as createTradingLine,Lh as createTradingSessionsIndicator,Rl as createTrendLineTool,Ir as createUpDownMarkers,no as createVerticalLineTool,Eh as createVolumeProfileIndicator,fe as createYieldCurveChart,ha as customSeriesDefaultOptions,Xn as defaultHorzScaleBehavior,qo as getPipConfig,Xr as hideSeriesPaint,Ei as isBusinessDay,Wi as isUTCTimestamp,Ur as setSeriesVolumes,Wh as setVolumeProfileData,Kn as timeFromCoordinate,la as version};
8
+ const t={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var i,s;function n(t,i){const s={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}function e(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(s,i+e),t.lineTo(n,i+e),t.stroke()}function r(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function h(t){if(void 0===t)throw new Error("Value is undefined");return t}function l(t){if(null===t)throw new Error("Value is null");return t}function o(t){return l(h(t))}!function(t){t[t.Simple=0]="Simple",t[t.WithSteps=1]="WithSteps",t[t.Curved=2]="Curved"}(i||(i={})),function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(s||(s={}));class a{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",V:0,I:0,A:0,L:0,B:0},this.O=t}W(){const t=this.M,i=this.$(),s=this.H();return t.P===i&&t.D===s||(t.P=i,t.D=s,t.T=g(i,s),t.L=2.5/12*i,t.V=t.L,t.I=i/12*t.C,t.A=i/12*t.C,t.B=0),t.R=this.N(),t.F=this.U(),this.M}N(){return this.O.W().layout.textColor}U(){return this.O.q()}$(){return this.O.W().layout.fontSize}H(){return this.O.W().layout.fontFamily}}function M(t){return t<0?0:t>255?255:Math.round(t)||0}function y(t){return.199*t[0]+.687*t[1]+.114*t[2]}class S{constructor(t,i){this.j=new Map,this.Y=t,i&&(this.j=i)}X(t,i){if("transparent"===t)return t;const s=this.G(t),n=s[3];return`rgba(${s[0]}, ${s[1]}, ${s[2]}, ${i*n})`}K(t){const i=this.G(t);return{Z:`rgb(${i[0]}, ${i[1]}, ${i[2]})`,J:y(i)>160?"black":"white"}}tt(t){return y(this.G(t))}it(t,i,s){const[n,e,r,h]=this.G(t),[l,o,a,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(o-e)),M(r+s*(a-r)),(c=h+s*(_-h),c<=0||c>1?Math.min(Math.max(c,0),1):Math.round(1e4*c)/1e4)];var c;return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}G(t){const i=this.j.get(t);if(i)return i;const s=function(t){const i=document.createElement("div");i.style.display="none",document.body.appendChild(i),i.style.color=t;const s=window.getComputedStyle(i).color;return document.body.removeChild(i),s}(t),n=s.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/);if(!n){if(this.Y.length)for(const i of this.Y){const s=i(t);if(s)return this.j.set(t,s),s}throw new Error(`Failed to parse color: ${t}`)}const e=[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10),n[4]?parseFloat(n[4]):1];return this.j.set(t,e),e}}class x{constructor(){this.st=[]}nt(t){this.st=t}et(t,i,s){this.st.forEach(n=>{n.et(t,i,s)})}}class C{et(t,i,s){t.useBitmapCoordinateSpace(t=>this.rt(t,i,s))}}class P extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.ht||null===this.ht.ot)return;const n=this.ht.ot,e=this.ht,r=Math.max(1,Math.floor(i))%2/2,h=h=>{t.beginPath();for(let l=n.to-1;l>=n.from;--l){const n=e._t[l],o=Math.round(n.ut*i)+r,a=n.ct*s,_=h*s+r;t.moveTo(o,a),t.arc(o,a,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.Vt(),i=this.Pt.It(),s=this.Ct.At(),n=this.O.Lt();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Bt(s),l=i.Ot();!t&&null!==h&&i.Vt()&&null!==l?(r.wt=h.Et,r.vt=h.vt,r.dt=h.Wt,r._t[0].bt=h.bt,r._t[0].ct=i.$t().zt(h.bt,l.Ht),r.ft=h.Nt??this.O.Ut(r._t[0].ct/i.$t().qt()),r._t[0].gt=s,r._t[0].ut=n.jt(s),r.ot=k):r.ot=null})}}class R extends C{constructor(t){super(),this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;const h=this.Yt.Xt.Vt,l=this.Yt.Gt.Vt;if(!h&&!l)return;const o=Math.round(this.Yt.ut*s),a=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,o,0,i.height)),l&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,a,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",Vt:!1},Gt:{dt:1,Kt:0,R:"",Vt:!1},ut:0,ct:0},this.Jt=new R(this.Zt),this.Qt=t,this.Pt=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.Rt(),this.xt=!1),this.Jt}Rt(){const t=this.Qt.Vt(),i=this.Pt.ti().W().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.Vt=!1,void(s.Xt.Vt=!1);s.Gt.Vt=t&&this.Qt.ii(this.Pt),s.Xt.Vt=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Kt=i.horzLine.style,s.Gt.R=i.horzLine.color,s.Xt.dt=i.vertLine.width,s.Xt.Kt=i.vertLine.style,s.Xt.R=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function V(t,i,s,n,e,r){t.fillRect(i+r,s,n-2*r,r),t.fillRect(i+r,s+e-r,n-2*r,r),t.fillRect(i,s,r,e),t.fillRect(i+n-r,s,r,e)}function I(t,i,s,n,e,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(i,s,n,e),t.restore()}function A(t,i,s,n,e,r){t.beginPath(),t.roundRect?t.roundRect(i,s,n,e,r):(t.lineTo(i+n-r[1],s),0!==r[1]&&t.arcTo(i+n,s,i+n,s+r[1],r[1]),t.lineTo(i+n,s+e-r[2]),0!==r[2]&&t.arcTo(i+n,s+e,i+n-r[2],s+e,r[2]),t.lineTo(i+r[3],s+e),0!==r[3]&&t.arcTo(i,s+e,i,s+e-r[3],r[3]),t.lineTo(i,s+r[0]),0!==r[0]&&t.arcTo(i,s,i+r[0],s,r[0]))}function L(t,i,s,n,e,r,h=0,l=[0,0,0,0],o=""){if(t.save(),!h||!o||o===r)return A(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const a=h/2;var _;A(t,i+a,s+a,n-h,e-h,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==o&&(t.lineWidth=h,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function B(t,i,s,n,e,r,h){t.save(),t.globalCompositeOperation="copy";const l=t.createLinearGradient(0,0,0,e);l.addColorStop(0,r),l.addColorStop(1,h),t.fillStyle=l,t.fillRect(i,s,n,e),t.restore()}class O{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.ri=i}qt(t,i){return this.Yt.Vt?t.P+t.L+t.V:0}et(t,i,s,n){if(!this.Yt.Vt||0===this.Yt.hi.length)return;const e=this.Yt.R,r=this.ri.Z,h=t.useBitmapCoordinateSpace(t=>{const h=t.context;h.font=i.T;const l=this.li(t,i,s,n),o=l.oi;return l.ai?L(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):L(h,o.fi,o.ui,o.ci,o.di,r,o.pi,[0,o.vt,o.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.ai?o.yi-o.pi:0,o.ui,o.pi,o.Si-o.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.ai?"right":"left",t.textBaseline="middle",t.fillStyle=e,t.fillText(this.Yt.hi,s.Ci,(s.ui+s.Si)/2+s.Pi)})}li(t,i,s,n){const{context:e,bitmapSize:r,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.L+this.ri.Di,c=i.V+this.ri.Ri,d=i.I,p=i.A,f=this.Yt.hi,v=i.P,m=s.Fi(e,f),w=Math.ceil(s.Vi(e,f)),g=v+u+c,b=i.S+d+p+w+a,M=Math.max(1,Math.floor(o));let y=Math.round(g*o);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(a*l),P=this.ri.Ii??this.ri.Ai,T=Math.round(P*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,V=R?r.width-S:S;let I,A,L;return R?(I=V-x,A=V-C,L=F-a-d-_):(I=V+x,A=V+C,L=F+a+d),{ai:R,oi:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:I,fi:V,gi:A,bi:M,yi:r.width},xi:{ui:k/o,Si:D/o,Ci:L,Pi:m}}}}class E{constructor(t){this.Li={Ai:0,Z:"#000",Ri:0,Di:0},this.Bi={hi:"",Vt:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Oi={hi:"",Vt:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Ei=new(t||O)(this.Bi,this.Li),this.Wi=new(t||O)(this.Oi,this.Li)}hi(){return this.zi(),this.Bi.hi}Ai(){return this.zi(),this.Li.Ai}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Ei.qt(t,i),this.Wi.qt(t,i))}$i(){return this.Li.Ii||0}Hi(t){this.Li.Ii=t}Ni(){return this.zi(),this.Bi.Vt||this.Oi.Vt}Ui(){return this.zi(),this.Bi.Vt}Dt(t){return this.zi(),this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Oi.mi=this.Oi.mi&&t.W().ticksVisible,this.Ei.lt(this.Bi,this.Li),this.Wi.lt(this.Oi,this.Li),this.Ei}qi(){return this.zi(),this.Ei.lt(this.Bi,this.Li),this.Wi.lt(this.Oi,this.Li),this.Wi}zi(){this.xt&&(this.Bi.mi=!0,this.Oi.mi=!1,this.ji(this.Bi,this.Oi,this.Li))}}class W extends E{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Xi=s}ji(t,i,s){if(t.Vt=!1,2===this.Qt.W().mode)return;const n=this.Qt.W().horzLine;if(!n.labelVisible)return;const e=this.Yi.Ot();if(!this.Qt.Vt()||this.Yi.Gi()||null===e)return;const r=this.Yi.Ki().K(n.labelBackgroundColor);s.Z=r.Z,t.R=r.J;const h=2/12*this.Yi.P();s.Di=h,s.Ri=h;const l=this.Xi(this.Yi);s.Ai=l.Ai,t.hi=this.Yi.Zi(l.bt,e),t.Vt=!0}}const z=/[1-9]/g;class ${constructor(){this.Yt=null}lt(t){this.Yt=t}et(t,i){if(null===this.Yt||!1===this.Yt.Vt||0===this.Yt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Vi(t,l(this.Yt).hi,z))));if(s<=0)return;const n=i.Qi,e=s+2*n,r=e/2,h=this.Yt.ts;let o=this.Yt.Ai,a=Math.floor(o-r)+.5;a<0?(o+=Math.abs(0-a),a=Math.floor(o-r)+.5):a+e>h&&(o-=Math.abs(h-(a+e)),a=Math.floor(o-r)+.5);const _=a+e,u=Math.ceil(0+i.S+i.C+i.L+i.P+i.V);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(a*s),h=Math.round(0*n),o=Math.round(_*s),c=Math.round(u*n),d=Math.round(2*s);if(t.beginPath(),t.moveTo(r,h),t.lineTo(r,c-d),t.arcTo(r,c,r+d,c,d),t.lineTo(o-d,c),t.arcTo(o,c,o,c-d,d),t.lineTo(o,h),t.fill(),e.mi){const r=Math.round(e.Ai*s),l=h,o=Math.round((l+i.C)*n);t.fillStyle=e.R;const a=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,a,o-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.L+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(a+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={Vt:!1,Z:"#4c525e",R:"white",hi:"",ts:0,Ai:NaN,mi:!0},this.Ct=t,this.ss=i,this.Xi=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}Rt(){const t=this.Zt;if(t.Vt=!1,2===this.Ct.W().mode)return;const i=this.Ct.W().vertLine;if(!i.labelVisible)return;const s=this.ss.Lt();if(s.Gi())return;t.ts=s.ts();const n=this.Xi();if(null===n)return;t.Ai=n.Ai;const e=s.ns(this.Ct.At());t.hi=s.es(l(e)),t.Vt=!0;const r=this.ss.Ki().K(i.labelBackgroundColor);t.Z=r.Z,t.R=r.J,t.mi=s.W().ticksVisible}}class N{constructor(){this.rs=null,this.hs=0}ls(){return this.hs}_s(t){this.hs=t}$t(){return this.rs}us(t){this.rs=t}cs(t){return[]}ds(){return[]}Vt(){return!0}}var U;!function(t){t[t.Normal=0]="Normal",t[t.Magnet=1]="Magnet",t[t.Hidden=2]="Hidden",t[t.MagnetOHLC=3]="MagnetOHLC"}(U||(U={}));class q extends N{constructor(t,i){super(),this.Pt=null,this.ps=NaN,this.fs=0,this.vs=!1,this.ws=new Map,this.gs=!1,this.bs=new WeakMap,this.Ms=new WeakMap,this.ys=NaN,this.Ss=NaN,this.xs=NaN,this.Cs=NaN,this.ss=t,this.Ps=i;this.Ts=((t,i)=>s=>{const n=i(),e=t();if(s===l(this.Pt).ks())return{bt:e,Ai:n};{const t=l(s.Ot());return{bt:s.Ds(n,t),Ai:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.Lt().Rs(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Ai:n}:null})(()=>this.fs,()=>this.ni());this.Fs=new H(this,t,s)}W(){return this.Ps}Vs(t,i){this.xs=t,this.Cs=i}Is(){this.xs=NaN,this.Cs=NaN}As(){return this.xs}Ls(){return this.Cs}Bs(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Os(t,i,s)}At(){return this.fs}ni(){return this.ys}ei(){return this.Ss}Vt(){return this.vs}Es(){this.vs=!1,this.Ws(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Pt=null,this.Is(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new F(this,t),this.bs.set(t,i));let s=this.Ms.get(t);return s||(s=new D(this.ss,this,t),this.Ms.set(t,s)),[i,s]}ii(t){return t===this.Pt&&this.Ps.horzLine.visible}si(){return this.Ps.vertLine.visible}Hs(t,i){this.vs&&this.Pt===t||this.ws.clear();const s=[];return this.Pt===t&&s.push(this.Ns(this.ws,i,this.Ts)),s}ds(){return this.vs?[this.Fs]:[]}Us(){return this.Pt}zs(){this.ss.qs().forEach(t=>{this.bs.get(t)?.Tt(),this.Ms.get(t)?.Tt()}),this.ws.forEach(t=>t.Tt()),this.Fs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}Os(t,i,s){this.Ys(t,i,s)&&this.zs()}Ys(t,i,s){const n=this.ys,e=this.Ss,r=this.ps,h=this.fs,l=this.Pt,o=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.Lt().jt(t),this.Pt=s;const a=null!==o?o.Ot():null;return null!==o&&null!==a?(this.ps=i,this.Ss=o.zt(i,a)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||h!==this.fs||r!==this.ps||l!==this.Pt}Ws(){const t=this.ss.Xs().map(t=>t.Ks().Gs()).filter(v),i=0===t.length?null:Math.max(...t);this.fs=null!==i?i:NaN}Ns(t,i,s){let n=t.get(i);return void 0===n&&(n=new W(this,i,s),t.set(i,n)),n}}function j(t){return"left"===t||"right"===t}class Y{constructor(t){this.Zs=new Map,this.Js=[],this.Qs=t}tn(t,i){const s=function(t,i){return void 0===t?i:{sn:Math.max(t.sn,i.sn),nn:t.nn||i.nn}}(this.Zs.get(t),i);this.Zs.set(t,s)}en(){return this.Qs}rn(t){const i=this.Zs.get(t);return void 0===i?{sn:this.Qs}:{sn:Math.max(this.Qs,i.sn),nn:i.nn}}hn(){this.ln(),this.Js=[{an:0}]}_n(t){this.ln(),this.Js=[{an:1,Ht:t}]}un(t){this.cn(),this.Js.push({an:5,Ht:t})}ln(){this.cn(),this.Js.push({an:6})}dn(){this.ln(),this.Js=[{an:4}]}pn(t){this.ln(),this.Js.push({an:2,Ht:t})}fn(t){this.ln(),this.Js.push({an:3,Ht:t})}vn(){return this.Js}mn(t){for(const i of t.Js)this.wn(i);this.Qs=Math.max(this.Qs,t.Qs),t.Zs.forEach((t,i)=>{this.tn(i,t)})}static gn(){return new Y(2)}static bn(){return new Y(3)}wn(t){switch(t.an){case 0:this.hn();break;case 1:this._n(t.Ht);break;case 2:this.pn(t.Ht);break;case 3:this.fn(t.Ht);break;case 4:this.dn();break;case 5:this.un(t.Ht);break;case 6:this.cn()}}cn(){const t=this.Js.findIndex(t=>5===t.an);-1!==t&&this.Js.splice(t,1)}}class X{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function K(t,i){if(!u(t))return"n/a";if(!c(i))throw new TypeError("invalid length");if(i<0||i>16)throw new TypeError("invalid length");if(0===i)return t.toString();return("0000000000000000"+t.toString()).slice(-i)}class Z extends X{constructor(t,i){if(super(),i||(i=1),u(t)&&c(t)||(t=100),t<0)throw new TypeError("invalid base");this.Yi=t,this.Mn=i,this.yn()}format(t){const i=t<0?"−":"";return t=Math.abs(t),i+this.Sn(t)}yn(){if(this.xn=0,this.Yi>0&&this.Mn>0){let t=this.Yi;for(;t>1;)t/=10,this.xn++}}Sn(t){const i=this.Yi/this.Mn;let s=Math.floor(t),n="";const e=void 0!==this.xn?this.xn:NaN;if(i>1){let r=+(Math.round(t*i)-s*i).toFixed(this.xn);r>=i&&(r-=i,s+=1),n=G+K(+r.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+K(0,e));return s.toFixed(0)+n}}class J extends Z{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Q extends X{constructor(t){super(),this.Cn=t}format(t){let i="";return t<0&&(i="-",t=-t),t<995?i+this.Pn(t):t<999995?i+this.Pn(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),i+this.Pn(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),i+this.Pn(t/1e9)+"B")}Pn(t){let i;const s=Math.pow(10,this.Cn);return i=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.Cn).replace(/\.?0+$/,""):String(t),i.replace(/(\.[1-9]*)0+$/,(t,i)=>i)}}const tt=/[2-9]/g;class it{constructor(t=50){this.Tn=0,this.kn=1,this.Dn=1,this.Rn={},this.Fn=new Map,this.Vn=t}In(){this.Tn=0,this.Fn.clear(),this.kn=1,this.Dn=1,this.Rn={}}Vi(t,i,s){return this.An(t,i,s).width}Fi(t,i,s){const n=this.An(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}An(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Fn.has(e))return h(this.Fn.get(e)).Ln;if(this.Tn===this.Vn){const t=this.Rn[this.Dn];delete this.Rn[this.Dn],this.Fn.delete(t),this.Dn++,this.Tn--}t.save(),t.textBaseline="middle";const r=t.measureText(e);return t.restore(),0===r.width&&i.length||(this.Fn.set(e,{Ln:r,Bn:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.On=null,this.M=null,this.En="right",this.Wn=t}zn(t,i,s){this.On=t,this.M=i,this.En=s}et(t){null!==this.M&&null!==this.On&&this.On.et(t,this.M,this.Wn,this.En)}}class nt{constructor(t,i,s){this.$n=t,this.Wn=new it(50),this.Hn=i,this.O=s,this.$=-1,this.Jt=new st(this.Wn)}Dt(){const t=this.O.Nn(this.Hn);if(null===t)return null;const i=t.Un(this.Hn)?t.qn():this.Hn.$t();if(null===i)return null;const s=t.jn(i);if("overlay"===s)return null;const n=this.O.Yn();return n.P!==this.$&&(this.$=n.P,this.Wn.In()),this.Jt.zn(this.$n.qi(),n,s),this.Jt}}class et extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}Xn(t,i){if(!this.Yt?.Vt)return null;const{ct:s,dt:n,Gn:e}=this.Yt;return i>=s-n-7&&i<=s+n+7?{Kn:this.Yt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;if(!1===this.Yt.Vt)return;const h=Math.round(this.Yt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.R,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Kt),e(t,h,0,i.width))}}class rt{constructor(t){this.Zn={ct:0,R:"rgba(0, 0, 0, 0)",dt:1,Kt:0,Vt:!1},this.Jn=new et,this.xt=!0,this.Qn=t,this.te=t.ti(),this.Jn.lt(this.Zn)}Tt(){this.xt=!0}Dt(){return this.Qn.Vt()?(this.xt&&(this.ie(),this.xt=!1),this.Jn):null}}class ht extends rt{constructor(t){super(t)}ie(){this.Zn.Vt=!1;const t=this.Qn.$t(),i=t.se().se;if(2!==i&&3!==i)return;const s=this.Qn.W();if(!s.baseLineVisible||!this.Qn.Vt())return;const n=this.Qn.Ot();null!==n&&(this.Zn.Vt=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.R=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Kt=s.baseLineStyle)}}class lt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ne(){return this.Yt}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.Yt;if(null===n)return;const e=Math.max(1,Math.floor(i)),r=e%2/2,h=Math.round(n.ee.x*i)+r,l=n.ee.y*s;t.fillStyle=n.re,t.beginPath();const o=Math.max(2,1.5*n.he)*i;t.arc(h,l,o,0,2*Math.PI,!1),t.fill(),t.fillStyle=n.le,t.beginPath(),t.arc(h,l,n.vt*i,0,2*Math.PI,!1),t.fill(),t.lineWidth=e,t.strokeStyle=n.oe,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const ot=[{ae:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{ae:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{ae:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class at{constructor(t){this.Jt=new lt,this.xt=!0,this.me=!0,this.we=performance.now(),this.ge=this.we-1,this.be=t}Me(){this.ge=this.we-1,this.Tt()}ye(){if(this.Tt(),2===this.be.W().lastPriceAnimation){const t=performance.now(),i=this.ge-t;if(i>0)return void(i<650&&(this.ge+=2600));this.we=t,this.ge=t+2600}}Tt(){this.xt=!0}Se(){this.me=!0}Vt(){return 0!==this.be.W().lastPriceAnimation}xe(){switch(this.be.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.ge}}Dt(){return this.xt?(this.Rt(),this.xt=!1,this.me=!1):this.me&&(this.Ce(),this.me=!1),this.Jt}Rt(){this.Jt.lt(null);const t=this.be.ti().Lt(),i=t.Pe(),s=this.be.Ot();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Re))return;const e={x:t.jt(n.Re),y:this.be.$t().zt(n.bt,s.Ht)},r=n.R,h=this.be.W().lineWidth,l=this.Fe(this.Ve(),r);this.Jt.lt({re:r,he:h,le:l.le,oe:l.oe,vt:l.vt,ee:e})}Ce(){const t=this.Jt.ne();if(null!==t){const i=this.Fe(this.Ve(),t.re);t.le=i.le,t.oe=i.oe,t.vt=i.vt}}Ve(){return this.xe()?performance.now()-this.we:2599}Ie(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Ki().X(t,e)}Fe(t,i){const s=t%2600/2600;let n;for(const t of ot)if(s>=t.ae&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.ae)/(n._e-n.ae);return{le:this.Ie(i,e,n.de,n.pe),oe:this.Ie(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,o=n.ce,l+(o-l)*h)};var h,l,o}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.Vt=!1;const i=this.Qn.W();if(!i.priceLineVisible||!this.Qn.Vt())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.Vt=!0,t.ct=s.Ai,t.R=this.Qn.Ae(s.R),t.dt=i.priceLineWidth,t.Kt=i.priceLineStyle)}}class ut extends E{constructor(t){super(),this.Qt=t}ji(t,i,s){t.Vt=!1,i.Vt=!1;const n=this.Qt;if(!n.Vt())return;const e=n.W(),r=e.lastValueVisible,h=""!==n.Le(),l=0===e.seriesLastValueMode,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Be(o,r,l),t.Vt=0!==t.hi.length),(h||l)&&(i.hi=this.Oe(o,r,h,l),i.Vt=i.hi.length>0);const a=n.Ae(o.R),_=this.Qt.ti().Ki().K(a);s.Z=_.Z,s.Ai=o.Ai,i.Nt=n.ti().Ut(o.Ai/n.$t().qt()),t.Nt=a,t.R=_.J,i.R=_.J}Oe(t,i,s,n){let e="";const r=this.Qt.Le();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Ee()?t.We:t.ze),e.trim()}Be(t,i,s){return i?s?this.Qt.$t().Ee()?t.ze:t.We:t.hi:""}}function ct(t,i,s,n){const e=Number.isFinite(i),r=Number.isFinite(s);return e&&r?t(i,s):e||r?e?i:s:n}class dt{constructor(t,i){this.$e=t,this.He=i}Ne(t){return null!==t&&(this.$e===t.$e&&this.He===t.He)}Ue(){return new dt(this.$e,this.He)}qe(){return this.$e}je(){return this.He}Ye(){return this.He-this.$e}Gi(){return this.He===this.$e||Number.isNaN(this.He)||Number.isNaN(this.$e)}mn(t){return null===t?this:new dt(ct(Math.min,this.qe(),t.qe(),-1/0),ct(Math.max,this.je(),t.je(),1/0))}Xe(t){if(!u(t))return;if(0===this.He-this.$e)return;const i=.5*(this.He+this.$e);let s=this.He-i,n=this.$e-i;s*=t,n*=t,this.He=i+s,this.$e=i+n}Ge(t){u(t)&&(this.He+=t,this.$e+=t)}Ke(){return{minValue:this.$e,maxValue:this.He}}static Ze(t){return null===t?null:new dt(t.minValue,t.maxValue)}}class pt{constructor(t,i){this.Je=t,this.Qe=i||null}tr(){return this.Je}ir(){return this.Qe}Ke(){return{priceRange:null===this.Je?null:this.Je.Ke(),margins:this.Qe||void 0}}static Ze(t){return null===t?null:new pt(dt.Ze(t.priceRange),t.margins)}}class ft extends rt{constructor(t,i){super(t),this.sr=i}ie(){const t=this.Zn;t.Vt=!1;const i=this.sr.W();if(!this.Qn.Vt()||!i.lineVisible)return;const s=this.sr.nr();null!==s&&(t.Vt=!0,t.ct=s,t.R=i.color,t.dt=i.lineWidth,t.Kt=i.lineStyle,t.Gn=this.sr.W().id)}}class vt extends E{constructor(t,i){super(),this.be=t,this.sr=i}ji(t,i,s){t.Vt=!1,i.Vt=!1;const n=this.sr.W(),e=n.axisLabelVisible,r=""!==n.title,h=this.be;if(!e||!h.Vt())return;const l=this.sr.nr();if(null===l)return;r&&(i.hi=n.title,i.Vt=!0),i.Nt=h.ti().Ut(l/h.$t().qt()),t.hi=this.er(n.price),t.Vt=!0;const o=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.R=a,i.R=a,s.Ai=l}er(t){const i=this.be.Ot();return null===i?"":this.be.$t().Zi(t,i.Ht)}}class mt{constructor(t,i){this.be=t,this.Ps=i,this.rr=new ft(t,this),this.$n=new vt(t,this),this.hr=new nt(this.$n,t,t.ti())}lr(t){_(this.Ps,t),this.Tt(),this.be.ti().ar()}W(){return this.Ps}_r(){return this.rr}ur(){return this.hr}cr(){return this.$n}Tt(){this.rr.Tt(),this.$n.Tt()}nr(){const t=this.be,i=t.$t();if(t.ti().Lt().Gi()||i.Gi())return null;const s=t.Ot();return null===s?null:i.zt(this.Ps.price,s.Ht)}}class wt extends N{constructor(t){super(),this.ss=t}ti(){return this.ss}}const gt={Bar:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=l(t(s,n)),a=o(h.Ht[0])<=o(h.Ht[3]);return{dr:h.R??(a?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,a=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=o(c.Ht[0])<=o(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:a),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}Vr(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Ir=[],this.Ar=new Map,this.Lr=new Map,this.Br=[]}Or(){return this.Er()>0?this.Ir[this.Ir.length-1]:null}Wr(){return this.Er()>0?this.zr(0):null}Gs(){return this.Er()>0?this.zr(this.Ir.length-1):null}Er(){return this.Ir.length}Gi(){return 0===this.Er()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Ir}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Lr.clear(),this.Ar.clear(),this.Ir=t,this.Br=t.map(t=>t.Re)}Yr(){return this.Br}zr(t){return this.Ir[t].Re}Nr(t){return this.Ir[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Ir.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Ir.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Ir.length||t<this.Ir[i].Re?null:i}Zr(t){return yt(this.Ir,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Ir,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Ir[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(o,a,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Ar.get(s);void 0===u&&(u=new Map,this.Ar.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(o);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.ah=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.ah?.rh===t)return this.ah.hh;const i=t.map(t=>new Rt(t));return this.ah={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let Vt=class extends Ft{cs(){return[]}};class It{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class At{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new It(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}function Lt(t){return{hi:t.text(),Ai:t.coordinate(),Ii:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),Vt:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Bt{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...Lt(this.dh)}),this.Jt}}class Ot extends E{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=Lt(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Ai=n.Ai,void 0!==n.Ii&&(s.Ii=n.Ii),t.hi=n.hi,t.Vt=n.Vt,t.mi=n.mi}}class Et extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().Lt(),s=t.map(t=>new Bt(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Ot(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new At(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new At(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.oh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new at(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Ae(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().Lt().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().Lt().Pe(),e=this.Ot();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Or();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Fh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Vh(l),ze:s.Ih(l,e.Ht),R:o.dr,Ai:a,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Ah(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Lh()),this.ti().Bh(this),this.ti().Oh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Eh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Bh(this),this.ti().Oh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Bh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Bh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Ot(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().Lt().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.Vt()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Bt(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ol(),Nt:this.al(),Wt:this._l(),Et:this.ul(t)}}Le(){return this.Ps.title}Vt(){return this.Ps.visible}cl(t){this.kh.push(new Et(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Ot();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.Vt())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=o(n.Ot()),a=3===this.Ps.mode?jt:qt;return t.concat(a.map(t=>e.zt(h.Ht[t],l.Ht)))},[]);if(0===l.length)return n;l.sort((t,i)=>Math.abs(t-h)-Math.abs(i-h));const a=l[0];return n=e.Ds(a,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Vl(),Pl:(this.Pt.ti().Lt().Vl()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Il:4,Al:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Al)+i.Il;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Il)-i.Al;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.je(),i);return new dt(s,n)}function ai(t){if(null===t)return ti;const i=Math.abs(t.je()-t.qe());if(i>=1||i<1e-15)return ti;const s=Math.ceil(Math.abs(Math.log10(i))),n=ti.Il+s;return{Il:n,Al:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Ll=t,this.Bl=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Ll))this.Ol=[2,2.5,2];else{this.Ol=[];for(let t=this.Ll;1!==t;){if(t%2==0)this.Ol.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Ol.push(2,2.5),t/=5}if(this.Ol.length>100)throw new Error("something wrong with base")}}}El(t,i,s){const n=0===this.Ll?0:1/this.Ll;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.Bl[0];for(;;){const t=Gt(e,n,1e-14)&&e>n+1e-14,i=Gt(e,s*h,1e-14),l=Gt(e,1,1e-14);if(!(t&&i&&l))break;e/=h,h=this.Bl[++r%this.Bl.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Ol.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Ol[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Ol[++r%this.Ol.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Ll=i,this.zl=s,this.$l=n}El(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Ll,[2,2.5,2]),r=new _i(this.Ll,[2,2,2.5]),h=new _i(this.Ll,[2.5,2,2]),l=[];return l.push(e.El(t,i,n),r.El(t,i,n),h.El(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Ot();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Wl=[]);const _=this.El(o,a);if(this.ql(i,_,o,a,h,l),t.jl()&&this.Yl(_,a,o)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Vl(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.max(1,Math.ceil(this.Ul()*this.Yi.W().tickMarkSpacing))}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.io()&&(i=this.El(c*a,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.so(t,s,e,r),o=this.so(t,n,-r,-e),a=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<a/2&&h.shift(),h.length>0&&o.Tl-h[h.length-1].Tl<a/2&&h.pop(),h.unshift(l),h.push(o)}so(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.El(o,l)),_=this.zl(i+e,t),u=_-_%a,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=o(this.Yi.tr());return this.Yi.io()&&(n=oi(n,this.Yi.no())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.eo=0,this.ro=null,this.Je=null,this.ho=null,this.lo={oo:!1,ao:null},this._o=!1,this.uo=0,this.co=0,this.do=new a,this.po=new a,this.fo=[],this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.Mo=null,this.ll=fi,this.yo=ai(null),this.So=t,this.Ps=i,this.xo=s,this.Co=n,this.Po=e,this.To=new ui(this,100,this.ko.bind(this),this.Do.bind(this))}gl(){return this.So}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.Ro({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Fo(),this.wo=null}void 0!==t.tickMarkSpacing&&(this.wo=null)}Vo(){return this.Ps.autoScale}Io(){return this._o}io(){return 1===this.Ps.mode}Ee(){return 2===this.Ps.mode}Ao(){return 3===this.Ps.mode}no(){return this.yo}se(){return{nn:this.Ps.autoScale,Lo:this.Ps.invertScale,se:this.Ps.mode}}Ro(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.lo.oo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.yo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.yo),null!==s&&this.Bo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Bo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Ee())&&this.bl(),n&&(3===i.se||this.Ao())&&this.bl(),void 0!==t.Lo&&i.Lo!==t.Lo&&(this.Ps.invertScale=t.Lo,this.Oo()),this.po.p(i,this.se())}Eo(){return this.po}P(){return this.xo.fontSize}qt(){return this.eo}Wo(t){this.eo!==t&&(this.eo=t,this.Fo(),this.wo=null)}zo(){if(this.ro)return this.ro;const t=this.qt()-this.$o()-this.Ho();return this.ro=t,t}tr(){return this.No(),this.Je}Bo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.wo=null,this.Je=t)}Uo(t){this.Bo(t),this.qo(null!==t)}Gi(){return this.No(),0===this.eo||!this.Je||this.Je.Gi()}jo(t){return this.Lo()?t:this.qt()-1-t}zt(t,i){return this.Ee()?t=ii(t,i):this.Ao()&&(t=ni(t,i)),this.Do(t,i)}Yo(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.eo-1-o;e.ct=u}}Go(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,o=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),o=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=a?c:this.eo-1-c;e.Ko=p,c=n+_*(l-r),p=a?c:this.eo-1-c,e.Zo=p,c=n+_*(o-r),p=a?c:this.eo-1-c,e.Jo=p,c=n+_*(u-r),p=a?c:this.eo-1-c,e.Qo=p}}Ds(t,i){const s=this.ko(t,i);return this.ta(s,i)}ta(t,i){let s=t;return this.Ee()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Ao()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.fo}Ft(){return this.mo||(this.mo=ci(this.fo)),this.mo}ia(t){-1===this.fo.indexOf(t)&&(this.fo.push(t),this.bl(),this.sa())}na(t){const i=this.fo.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.fo.splice(i,1),0===this.fo.length&&(this.Ro({nn:!0}),this.Bo(null)),this.bl(),this.sa()}Ot(){let t=null;for(const i of this.fo){const s=i.Ot();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Lo(){return this.Ps.invertScale}Vl(){const t=null===this.Ot();if(null!==this.wo&&(t||this.wo.ea===t))return this.wo.Vl;this.To.Nl();const i=this.To.Vl();return this.wo={Vl:i,ea:t},this.do.p(),i}ra(){return this.do}ha(t){this.Ee()||this.Ao()||null===this.bo&&null===this.ho&&(this.Gi()||(this.bo=this.eo-t,this.ho=l(this.tr()).Ue()))}la(t){if(this.Ee()||this.Ao())return;if(null===this.bo)return;this.Ro({nn:!1}),(t=this.eo-t)<0&&(t=0);let i=(this.bo+.2*(this.eo-1))/(t+.2*(this.eo-1));const s=l(this.ho).Ue();i=Math.max(i,.1),s.Xe(i),this.Bo(s)}oa(){this.Ee()||this.Ao()||(this.bo=null,this.ho=null)}aa(t){this.Vo()||null===this.Mo&&null===this.ho&&(this.Gi()||(this.Mo=t,this.ho=l(this.tr()).Ue()))}_a(t){if(this.Vo())return;if(null===this.Mo)return;const i=l(this.tr()).Ye()/(this.zo()-1);let s=t-this.Mo;this.Lo()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Bo(e,!0),this.wo=null}ua(){this.Vo()||null!==this.Mo&&(this.Mo=null,this.ho=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.ca(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.da(t);case 3:return this.hl().formatTickmarks(t);default:return this.pa(t)}}Vh(t){return this.er(t,l(this.vo).hl())}Ih(t,i){return t=ii(t,i),this.ca(t,pi)}fa(){return this.fo}va(t){this.lo={ao:t,oo:!1}}zs(){this.fo.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Vo()}Xl(){return this.P()/2}bl(){this.wo=null;let t=1/0;this.vo=null;for(const i of this.fo)i.ls()<t&&(t=i.ls(),this.vo=i);let i=100;null!==this.vo&&(i=Math.round(this.vo.rh())),this.ll=fi,this.Ee()?(this.ll=pi,i=100):this.Ao()?(this.ll=new Z(100,1),i=100):null!==this.vo&&(this.ll=this.vo.hl()),this.To=new ui(this,i,this.ko.bind(this),this.Do.bind(this)),this.To.Nl()}sa(){this.mo=null}ma(){return null===this.vo||this.Ee()||this.Ao()?1:1/this.vo.rh()}Ki(){return this.Po}qo(t){this._o=t}$o(){return this.Lo()?this.Ps.scaleMargins.bottom*this.qt()+this.co:this.Ps.scaleMargins.top*this.qt()+this.uo}Ho(){return this.Lo()?this.Ps.scaleMargins.top*this.qt()+this.uo:this.Ps.scaleMargins.bottom*this.qt()+this.co}No(){this.lo.oo||(this.lo.oo=!0,this.wa())}Fo(){this.ro=null}Do(t,i){if(this.No(),this.Gi())return 0;t=this.io()&&t?ri(t,this.yo):t;const s=l(this.tr()),n=this.Ho()+(this.zo()-1)*(t-s.qe())/s.Ye();return this.jo(n)}ko(t,i){if(this.No(),this.Gi())return 0;const s=this.jo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.Ho())/(this.zo()-1));return this.io()?hi(e,this.yo):e}Oo(){this.wo=null,this.To.Nl()}wa(){if(this.Io()&&!this.Vo())return;const t=this.lo.ao;if(null===t)return;let i=null;const s=this.fa();let n=0,e=0;for(const r of s){if(!r.Vt())continue;const s=r.Ot();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.yo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this.uo&&e===this.co||(this.uo=n,this.co=e,this.wo=null,this.Fo()),null!==i){const t=this.io(),s=t?oi(i,this.yo):i,n=this.Ee()||this.Ao()?0:10*this.ma();if(s.qe()===s.je()||s.Ye()<n){const e=Math.max(5*this.ma(),n/2),r=(s.qe()+s.je())/2,h=new dt(r-e,r+e);i=t?li(h,this.yo):h}if(this.io()){const t=oi(i,this.yo),s=ai(t);if(r=s,h=this.yo,r.Il!==h.Il||r.Al!==h.Al){const n=null!==this.ho?oi(this.ho,this.yo):null;this.yo=s,i=li(t,s),null!==n&&(this.ho=li(n,s))}}this.Bo(i)}else null===this.Je&&(this.Bo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Ee()?ii:this.Ao()?ni:this.io()?t=>ri(t,this.yo):null}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}ba(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.ga(t,this.Co.priceFormatter,i)}pa(t,i){const s=this.Co.priceFormatter;return this.ba(t,this.Co.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ca(t,i){return this.ga(t,this.Co.percentageFormatter,i)}da(t,i){const s=this.Co.percentageFormatter;return this.ba(t,this.Co.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.fo=[],this.Ma=new Map,this.eo=0,this.ya=0,this.Sa=1,this.mo=null,this.xa=!1,this.Ca=new a,this.kh=[],this.ph=t,this.ss=i,this.Pa=new Qt(this);const s=i.W();this.Ta=this.ka("left",s.leftPriceScale),this.Da=this.ka("right",s.rightPriceScale),this.Ta.Eo().i(this.Ra.bind(this,this.Ta),this),this.Da.Eo().i(this.Ra.bind(this,this.Da),this),this.Fa(s)}Fa(t){if(t.leftPriceScale&&this.Ta.lr(t.leftPriceScale),t.rightPriceScale&&this.Da.lr(t.rightPriceScale),t.localization&&(this.Ta.bl(),this.Da.bl()),t.overlayPriceScales){const i=Array.from(this.Ma.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Va(t){switch(t){case"left":return this.Ta;case"right":return this.Da}return this.Ma.has(t)?h(this.Ma.get(t))[0].$t():null}m(){this.ti().Ia().u(this),this.Ta.Eo().u(this),this.Da.Eo().u(this),this.fo.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Ca.p()}Aa(){return this.Sa}La(t){this.Sa=t}ti(){return this.ss}ts(){return this.ya}qt(){return this.eo}Ba(t){this.ya=t,this.Oa()}Wo(t){this.eo=t,this.Ta.Wo(t),this.Da.Wo(t),this.fo.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Wo(t)}}),this.Oa()}Ea(t){this.xa=t}Wa(){return this.xa}za(){return this.fo.filter(mi)}yl(){return this.fo}Un(t){const i=t.$t();return null===i||this.Ta!==i&&this.Da!==i}ia(t,i,s){this.$a(t,i,s?t.ls():this.fo.length)}na(t,i){const s=this.fo.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.fo.splice(s,1),i||this.fo.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Ma.has(n)){const i=h(this.Ma.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Ma.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.na(t),this.Ha(e)),this.mo=null}jn(t){return t===this.Ta?"left":t===this.Da?"right":"overlay"}Na(){return this.Ta}Ua(){return this.Da}qa(t,i){t.ha(i)}ja(t,i){t.la(i),this.Oa()}Ya(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Oa()}Ka(t){t.ua()}Oa(){this.fo.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Da.yl().length?t=this.Da:this.ss.W().leftPriceScale.visible&&0!==this.Ta.yl().length?t=this.Ta:0!==this.fo.length&&(t=this.fo[0].$t()),null===t&&(t=this.Da),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Da:this.ss.W().leftPriceScale.visible&&(t=this.Ta),t}Ha(t){null!==t&&t.Vo()&&this.Za(t)}Ja(t){const i=this.ph.Pe();t.Ro({nn:!0}),null!==i&&t.va(i),this.Oa()}Qa(){this.Za(this.Ta),this.Za(this.Da)}t_(){this.Ha(this.Ta),this.Ha(this.Da),this.fo.forEach(t=>{this.Un(t)&&this.Ha(t.$t())}),this.Oa(),this.ss.ar()}Ft(){return null===this.mo&&(this.mo=ci(this.fo)),this.mo}i_(t,i){i=Xt(i,0,this.fo.length-1);const s=this.fo.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.fo.splice(s,1),this.fo.splice(i,0,t),this.fo.forEach((t,i)=>t._s(i)),this.mo=null;for(const t of[this.Ta,this.Da])t.sa(),t.bl();this.ss.ar()}It(){return this.Ft().filter(mi)}s_(){return this.Ca}n_(){return this.Pa}cl(t){this.kh.push(new Vt(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Za(t){const i=t.fa();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.va(i)}t.zs()}$a(t,i,s){let n=this.Va(i);if(null===n&&(n=this.ka(i,this.ss.W().overlayPriceScales)),this.fo.splice(s,0,t),!j(i)){const s=this.Ma.get(i)||[];s.push(t),this.Ma.set(i,s)}t._s(s),n.ia(t),t.us(n),this.Ha(n),this.mo=null}Ra(t,i,s){i.se!==s.se&&this.Za(t)}ka(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Wo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},o_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{a_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,a_:n.a_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.Vn=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.Vn){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,Bn:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(){this.Fn=null}M_(t,i){this.y_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}S_(t,i,s,n,e,r=()=>!0){const h=Math.ceil(i/t);return null!==this.Fn&&this.Fn.x_===h&&e===this.Fn.C_&&s===this.Fn.P_||(this.Fn={C_:e,P_:s,Vl:this.T_(h,s,n,r),x_:h}),this.Fn.Vl}y_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}T_(t,i,s,n){let e=[];const r=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=e;e=[];const l=s.length;let o=0;const a=h(this.m_.get(i)),_=a.length;let u=1/0,c=-1/0;for(let i=0;i<_;i++){const h=a[i];if(!n(h,t))continue;const _=h.index;for(;o<l;){const t=s[o],i=t.index;if(!(i<_&&r(t))){u=i;break}o++,e.push(t),c=i,u=1/0}if(u-_>=t&&_-c>=t&&r(h))e.push(h),c=_;else if(this.w_)return s}for(;o<l;o++)r(s[o])&&e.push(s[o])}return e}}class ki{constructor(t){this.k_=t}D_(){return null===this.k_?null:new Ci(Math.floor(this.k_.qh()),Math.ceil(this.k_.yi()))}R_(){return this.k_}static F_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.ya=0,this.V_=null,this.I_=[],this.Mo=null,this.bo=null,this.A_=new Ti,this.L_=new Map,this.B_=ki.F_(),this.O_=!0,this.E_=new a,this.W_=new a,this.z_=new a,this.H_=null,this.N_=null,this.U_=new Map,this.q_=-1,this.j_=[],this.Ps=i,this.Co=s,this.Y_=i.rightOffset,this.X_=i.barSpacing,this.ss=t,this.G_(i),this.u_=n,this.K_(),this.A_.g_(i.uniformDistribution),this.Z_()}W(){return this.Ps}J_(t){_(this.Co,t),this.Q_(),this.K_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.tu(),this.Ps.fixRightEdge&&this.iu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.G_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.X_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.Z_(),this.Q_(),this.K_(),this.z_.p()}Rs(t){return this.I_[t]?.time??null}ns(t){return this.I_[t]??null}su(t,i){if(this.I_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.I_[this.I_.length-1].time))return i?this.I_.length-1:null;const s=yt(this.I_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.I_[s].time)?i?s:null:s}Gi(){return 0===this.ya||0===this.I_.length||null===this.V_}nu(){return this.I_.length>0}Pe(){return this.eu(),this.B_.D_()}ru(){return this.eu(),this.B_.R_()}hu(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.lu(i)}lu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.ou()),e=l(this.au());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}_u(t){return{from:l(this.su(t.from,!0)),to:l(this.su(t.to,!0))}}ts(){return this.ya}Ba(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.ru(),s=this.ya;if(this.ya=t,this.O_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.X_*t/s;this.X_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.Y_-=Math.round(i/this.X_)+1,this.O_=!0}this.uu(),this.cu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.du()+this.Y_-t;return this.ya-(i+.5)*this.X_-1}pu(t,i){const s=this.du(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.Y_-n,r=this.ya-(e+.5)*this.X_-1;t[i].ut=r}}fu(t,i){const s=Math.ceil(this.vu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.mu(s)?this.wu(s):s}fn(t){this.O_=!0,this.Y_=t,this.cu(),this.ss.gu(),this.ss.ar()}bu(){return this.X_}pn(t){const i=this.X_;if(this.Mu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.Y_*i/this.X_;this.Y_=t}this.cu(),this.ss.gu(),this.ss.ar()}yu(){return this.Y_}Vl(){if(this.Gi())return null;if(null!==this.N_)return this.N_;const t=this.X_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.A_.S_(t,i,this.Ps.ignoreWhitespaceIndices,this.U_,this.q_,(t,i)=>this.u_.allowsTickMark?.(t,i)??!0),o=this.ou()+s,a=this.au()-s,_=this.Su(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.j_.length?(s=this.j_[d],s.coord=this.jt(t.index),s.label=this.xu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.xu(t),weight:t.weight},this.j_.push(s)),this.X_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.j_.length=d,this.N_=this.j_,this.j_}Cu(){let t;this.O_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.bu():this.Ps.rightOffset,this.fn(t)}Pu(t){this.O_=!0,this.V_=t,this.cu(),this.tu()}Tu(t,i){const s=this.vu(t),n=this.bu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.yu()+(s-this.vu(t)))}ha(t){this.Mo&&this.ua(),null===this.bo&&null===this.H_&&(this.Gi()||(this.bo=t,this.ku()))}la(t){if(null===this.H_)return;const i=Xt(this.ya-t,0,this.ya),s=Xt(this.ya-l(this.bo),0,this.ya);0!==i&&0!==s&&this.pn(this.H_.bu*i/s)}oa(){null!==this.bo&&(this.bo=null,this.Du())}aa(t){null===this.Mo&&null===this.H_&&(this.Gi()||(this.Mo=t,this.ku()))}_a(t){if(null===this.Mo)return;const i=(this.Mo-t)/this.bu();this.Y_=l(this.H_).yu+i,this.O_=!0,this.cu()}ua(){null!==this.Mo&&(this.Mo=null,this.Du())}Ru(){this.Fu(this.Ps.rightOffset)}Fu(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.Y_,n=performance.now();this.ss.un({Vu:t=>(t-n)/i>=1,Iu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.O_=!0,this.I_=t,this.A_.M_(t,i),this.cu()}Au(){return this.E_}Lu(){return this.W_}Bu(){return this.z_}du(){return this.V_||0}Ou(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.Mu((this.ya-n)/s),this.Y_=t.yi()-this.du(),i&&(this.Y_=n?n/this.bu():this.Ps.rightOffset),this.cu(),this.O_=!0,this.ss.gu(),this.ss.ar()}Eu(){const t=this.ou(),i=this.au();null!==t&&null!==i&&this.Ou(new Ci(t,i),!0)}Wu(t){const i=new Ci(t.from,t.to);this.Ou(i)}es(t){return void 0!==this.Co.timeFormatter?this.Co.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}Z_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.U_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.U_.set(t,!0);this.q_++}Su(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}ou(){return 0===this.I_.length?null:0}au(){return 0===this.I_.length?null:this.I_.length-1}zu(t){return(this.ya-1-t)/this.X_}vu(t){const i=this.zu(t),s=this.du()+this.Y_-i;return Math.round(1e6*s)/1e6}Mu(t){const i=this.X_;this.X_=t,this.uu(),i!==this.X_&&(this.O_=!0,this.$u())}eu(){if(!this.O_)return;if(this.O_=!1,this.Gi())return void this.Hu(ki.F_());const t=this.du(),i=this.ya/this.X_,s=this.Y_+t,n=new Ci(s-i+1,s);this.Hu(new ki(n))}uu(){const t=Xt(this.X_,this.Nu(),this.Uu());this.X_!==t&&(this.X_=t,this.O_=!0)}Uu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.ya}Nu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.I_.length?this.ya/this.I_.length:this.Ps.minBarSpacing}cu(){const t=this.qu();null!==t&&this.Y_<t&&(this.Y_=t,this.O_=!0);const i=this.ju();this.Y_>i&&(this.Y_=i,this.O_=!0)}qu(){const t=this.ou(),i=this.V_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.ya/this.X_:Math.min(2,this.I_.length))}ju(){return this.Ps.fixRightEdge?0:this.ya/this.X_-Math.min(2,this.I_.length)}ku(){this.H_={bu:this.bu(),yu:this.yu()}}Du(){this.H_=null}xu(t){let i=this.L_.get(t.weight);return void 0===i&&(i=new xi(t=>this.Yu(t),this.u_),this.L_.set(t.weight,i)),i.c_(t)}Yu(t){return this.u_.formatTickmark(t,this.Co)}Hu(t){const i=this.B_;this.B_=t,Pi(i.D_(),this.B_.D_())||this.E_.p(),Pi(i.R_(),this.B_.R_())||this.W_.p(),this.$u()}$u(){this.N_=null}Q_(){this.$u(),this.L_.clear(),this.A_.b_()}K_(){this.u_.updateFormatter(this.Co)}tu(){if(!this.Ps.fixLeftEdge)return;const t=this.ou();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.Y_-s-1;this.fn(t)}this.uu()}iu(){this.cu(),this.uu()}mu(t){return!this.Ps.ignoreWhitespaceIndices||(this.U_.get(t)||!1)}wu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.au();for(;s;){const t=i.next().value;if(this.U_.get(t))return t;if(t<0||t>s)break}return t}G_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.X_);this.ss.fn(i)}}}var Fi,Vi,Ii,Ai,Li;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Bi{constructor(t,i,s){this.Xu=[],this.Gu=[],this.ya=0,this.Ku=null,this.Zu=new a,this.Ju=new a,this.Qu=null,this.tc=t,this.Ps=i,this.u_=s,this.Po=new S(this.Ps.layout.colorParsers),this.sc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.nc=new Yt(i.crosshair),i.addDefaultPane&&(this.ec(0),this.Xu[0].La(2)),this.rc=this.hc(0),this.lc=this.hc(1)}Lh(){this.oc(Y.bn())}ar(){this.oc(Y.gn())}Jh(){this.oc(new Y(1))}Bh(t){const i=this.ac(t);this.oc(i)}_c(){return this.Ku}uc(t){if(this.Ku?.r_===t?.r_&&this.Ku?.h_?.Gn===t?.h_?.Gn)return;const i=this.Ku;this.Ku=t,null!==i&&this.Bh(i.r_),null!==t&&t.r_!==i?.r_&&this.Bh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Xu.forEach(i=>i.Fa(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.J_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Zu.p(),this.rc=this.hc(0),this.lc=this.hc(1),this.Lh()}cc(t,i,s=0){const n=this.Xu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fa({leftPriceScale:i}),this.Zu.p(),void this.Lh();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fa({rightPriceScale:i}),this.Zu.p(),void this.Lh();const e=this.dc(t,s);null!==e&&(e.$t.lr(i),this.Zu.p())}dc(t,i){const s=this.Xu[i];if(void 0===s)return null;const n=s.Va(t);return null!==n?{Us:s,$t:n}:null}Lt(){return this.ph}qs(){return this.Xu}fc(){return this.Ct}vc(){return this.Ju}mc(t,i){t.Wo(i),this.gu()}Ba(t){this.ya=t,this.ph.Ba(this.ya),this.Xu.forEach(i=>i.Ba(t)),this.gu()}wc(t){1!==this.Xu.length&&(r(t>=0&&t<this.Xu.length,"Invalid pane index"),this.Xu.splice(t,1),this.Lh())}gc(t,i){if(this.Xu.length<2)return;r(t>=0&&t<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu.reduce((t,i)=>t+i.Aa(),0),e=this.Xu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Xu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.La(i*l);let a=i-o,_=this.Xu.length-1;for(const t of this.Xu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.La(s)}this.Lh()}bc(t,i){r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu[i];this.Xu[t]=n,this.Xu[i]=s,this.Lh()}Mc(t,i){if(r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index"),t===i)return;const[s]=this.Xu.splice(t,1);this.Xu.splice(i,0,s),this.Lh()}qa(t,i,s){t.qa(i,s)}ja(t,i,s){t.ja(i,s),this.Oh(),this.oc(this.yc(t,2))}Ya(t,i){t.Ya(i),this.oc(this.yc(t,2))}Xa(t,i,s){i.Vo()||t.Xa(i,s)}Ga(t,i,s){i.Vo()||(t.Ga(i,s),this.Oh(),this.oc(this.yc(t,2)))}Ka(t,i){i.Vo()||(t.Ka(i),this.oc(this.yc(t,2)))}Ja(t,i){t.Ja(i),this.oc(this.yc(t,2))}Sc(t){this.ph.ha(t)}xc(t,i){const s=this.Lt();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Tu(t,i),this.gu()}Cc(t){this.Pc(0),this.Tc(t),this.kc()}Dc(t){this.ph.la(t),this.gu()}Rc(){this.ph.oa(),this.ar()}Pc(t){this.ph.aa(t)}Tc(t){this.ph._a(t),this.gu()}kc(){this.ph.ua(),this.ar()}Xs(){return this.Gu}Fc(t,i,s,n,e){this.Ct.Vs(t,i);let r=NaN,h=this.ph.fu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const o=n.ks(),a=o.Ot();if(null!==a&&(r=o.Ds(i,a)),r=this.nc.Ml(r,h,n),this.Ct.Bs(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this.uc(e&&{r_:e.r_,h_:e.h_,o_:e.o_||null}),this.Ju.p(this.Ct.At(),{x:t,y:i},s)}}Vc(t,i,s){const n=s.ks(),e=n.Ot(),r=n.zt(t,l(e)),h=this.ph.su(i,!0),o=this.ph.jt(l(h));this.Fc(o,r,null,s,!0)}Ic(t){this.fc().Es(),this.Jh(),t||this.Ju.p(null,null,null)}Oh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.As(),s=this.Ct.Ls();this.Fc(i,s,null,t)}this.Ct.zs()}Ac(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.du(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),o=null!==t&&t>r&&!l,a=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.ph.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.ph.fn(this.ph.yu()-i)}}this.ph.Pu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Xu.find(i=>i.Ft().includes(t));return void 0===i?null:i}gu(){this.Xu.forEach(t=>t.t_()),this.Oh()}m(){this.Xu.forEach(t=>t.m()),this.Xu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Lc(){return this.sc}Yn(){return this.sc.W()}Ia(){return this.Zu}Bc(t,i){const s=this.ec(i);this.Oc(t,s),this.Gu.push(t),1===this.Gu.length?this.Lh():this.ar()}Ec(t){const i=this.Nn(t),s=this.Gu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Gu.splice(s,1),n.na(t),t.m&&t.m(),this.ph.Z_();const e=this.Xu.length;this.Wc(n),this.Xu.length<e&&this.Lh()}Ah(t,i){const s=l(this.Nn(t));s.na(t,!0),s.ia(t,i,!0)}Eu(){const t=Y.gn();t.hn(),this.oc(t)}zc(t){const i=Y.gn();i._n(t),this.oc(i)}dn(){const t=Y.gn();t.dn(),this.oc(t)}pn(t){const i=Y.gn();i.pn(t),this.oc(i)}fn(t){const i=Y.gn();i.fn(t),this.oc(i)}un(t){const i=Y.gn();i.un(t),this.oc(i)}ln(){const t=Y.gn();t.ln(),this.oc(t)}$c(){return this.Ps.rightPriceScale.visible?"right":"left"}Hc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Nc(t))return;const s=l(this.Nn(t));s.na(t);const n=this.ec(i);this.Oc(t,n),0===s.yl().length&&this.Wc(s),this.Lh()}Uc(){return this.lc}q(){return this.rc}Ut(t){const i=this.lc,s=this.rc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Qu||this.Qu.wr!==s||this.Qu.gr!==i)this.Qu={wr:s,gr:i,qc:new Map};else{const i=this.Qu.qc.get(t);if(void 0!==i)return i}const n=this.Po.it(s,i,t/100);return this.Qu.qc.set(t,n),n}jc(t){return this.Xu.indexOf(t)}Ki(){return this.Po}Yc(){return this.Xc()}Xc(t){const i=new wi(this.ph,this);this.Xu.push(i);const s=t??this.Xu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.oc(n),i}ec(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Xu.length,t))<this.Xu.length?this.Xu[t]:this.Xc(t)}Nc(t){return this.Xu.findIndex(i=>i.za().includes(t))}yc(t,i){const s=new Y(i);if(null!==t){const n=this.Xu.indexOf(t);s.tn(n,{sn:i})}return s}ac(t,i){return void 0===i&&(i=2),this.yc(this.Nn(t),i)}oc(t){this.tc&&this.tc(t),this.Xu.forEach(t=>t.n_()._r().Tt())}Oc(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.$c();i.ia(t,n),j(n)||t.lr(t.W())}hc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Wc(t){!t.Wa()&&0===t.yl().length&&this.Xu.length>1&&this.Xu.splice(this.jc(t),1)}}function Oi(t){if(t>=1)return 0;let i=0;for(;i<8;i++){const s=Math.round(t);if(Math.abs(s-t)<1e-8)return i;t*=10}return i}function Ei(t){return!u(t)&&!d(t)}function Wi(t){return u(t)}!function(t){t[t.Disabled=0]="Disabled",t[t.Continuous=1]="Continuous",t[t.OnDataUpdate=2]="OnDataUpdate"}(Vi||(Vi={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Ii||(Ii={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Ai||(Ai={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Li||(Li={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>K(zi(t),4))(t)).replace(/yy/g,(t=>K(zi(t)%100,2))(t)).replace(/MMMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(t,s)).replace(/MMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(t,s)).replace(/MM/g,(t=>K((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>K((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Gc=t,this.Kc=i}c_(t){return $i(t,this.Gc,this.Kc)}}class Ni{constructor(t){this.Zc=t||"%h:%m:%s"}c_(t){return this.Zc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Jc:"yyyy-MM-dd",Qc:"%h:%m:%s",td:" ",sd:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.nd=new Hi(i.Jc,i.sd),this.ed=new Ni(i.Qc),this.rd=i.td}c_(t){return`${this.nd.c_(t)}${this.rd}${this.ed.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{hd:(Gi=1,1e3*Gi),ld:10},{hd:Yi(1),ld:20},{hd:Yi(5),ld:21},{hd:Yi(30),ld:22},{hd:ji(1),ld:30},{hd:ji(3),ld:31},{hd:ji(6),ld:32},{hd:ji(12),ld:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].hd)!==Math.floor(t.getTime()/Xi[s].hd))return Xi[s].ld;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Ei(i))throw new Error("time must be of type BusinessDay");const s=new Date(Date.UTC(i.year,i.month-1,i.day,0,0,0,0));return{od:Math.round(s.getTime()/1e3),ad:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{od:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}function ss(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}class ns{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Ei(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"od"in t?t.od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ad?new Date(1e3*i.od).getTime():new Date(Date.UTC(i.ad.year,i.ad.month-1,i.ad.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Ei(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this._d=new qi({Jc:i,Qc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",td:" ",sd:t.locale}):this._d=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this._d.c_(new Date(1e3*i.od))}allowsTickMark(t,i){const s=this.Ps.timeScale.tickMarkFilter;if(void 0===s)return!0;const n=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible);return s(t.originalTime,n,i)}formatTickmark(t,i){const s=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.ad?new Date(1e3*t.od):new Date(Date.UTC(t.ad.year,t.ad.month-1,t.ad.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.od,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).od);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).od-(s||Zi(i.time).od),s=Zi(i.time).od,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.od-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.od),s)}}(t,i)}static ud(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function es(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function rs(t,i){return t.width===i.width&&t.height===i.height}var hs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var ls=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=es({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return es({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=es(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;rs(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=es(this._transformBitmapSize(t,this._canvasElementClientSize)),n=rs(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&rs(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=os(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new hs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=os(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return es({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):es({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=es({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function os(t){return t.ownerDocument.defaultView}var as=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function _s(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new as(e,s,n)}const us="undefined"!=typeof window;function cs(){return!!us&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ds(){return!!us&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ps(t){return t+t%2}function fs(t){us&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class vs{constructor(t,i,s){this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.gd=null,this.bd=!1,this.Md=null,this.yd=null,this.Sd=!1,this.xd=!1,this.Cd=!1,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Vd=null,this.Id=0,this.Ad=!1,this.Ld=!1,this.Bd=!1,this.Od=0,this.Ed=null,this.Wd=!ds(),this.zd=t=>{this.$d(t)},this.Hd=t=>{if(this.Nd(t)){const i=this.Ud(t);if(++this.vd,this.md&&this.vd>1){const{qd:s}=this.jd(gs(t),this.wd);s<30&&!this.Cd&&this.Yd(i,this.Gd.Xd),this.Kd()}}else{const i=this.Ud(t);if(++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}}},this.tp=t,this.Gd=i,this.Ps=s,this.ip()}m(){null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Fd&&(this.Fd(),this.Fd=null),null!==this.kd&&(this.kd(),this.kd=null),this.sp(),this.Qd()}np(t){this.Dd&&this.Dd();const i=this.ep.bind(this);if(this.Dd=()=>{this.tp.removeEventListener("mousemove",i)},this.tp.addEventListener("mousemove",i),this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.rp),this.Wd=!0}Qd(){null!==this.pd&&clearTimeout(this.pd),this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Kd(){null!==this.md&&clearTimeout(this.md),this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}ep(t){if(this.Bd||null!==this.yd)return;if(this.Nd(t))return;const i=this.Ud(t);this.Zd(i,this.Gd.hp),this.Wd=!0}lp(t){const i=Ms(t.changedTouches,l(this.Ed));if(null===i)return;if(this.Od=bs(t),null!==this.Vd)return;if(this.Ld)return;this.Ad=!0;const s=this.jd(gs(i),l(this.yd)),{op:n,ap:e,qd:r}=s;if(this.Sd||!(r<5)){if(!this.Sd){const t=.5*n,i=e>=t&&!this.Ps._p(),s=t>e&&!this.Ps.up();i||s||(this.Ld=!0),this.Sd=!0,this.Cd=!0,this.sp(),this.Kd()}if(!this.Ld){const s=this.Ud(t,i);this.Yd(s,this.Gd.cp),ws(t)}}}dp(t){if(0!==t.button)return;const i=this.jd(gs(t),l(this.Md)),{qd:s}=i;if(s>=5&&(this.xd=!0,this.Qd()),this.xd){const i=this.Ud(t);this.Zd(i,this.Gd.pp)}}jd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{op:s,ap:n,qd:s+n}}fp(t){let i=Ms(t.changedTouches,l(this.Ed));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ed=null,this.Od=bs(t),this.sp(),this.yd=null,this.Fd&&(this.Fd(),this.Fd=null);const s=this.Ud(t,i);if(this.Yd(s,this.Gd.vp),++this.vd,this.md&&this.vd>1){const{qd:t}=this.jd(gs(i),this.wd);t<30&&!this.Cd&&this.Yd(s,this.Gd.Xd),this.Kd()}else this.Cd||(this.Yd(s,this.Gd.mp),this.Gd.mp&&ws(t));0===this.vd&&ws(t),0===t.touches.length&&this.bd&&(this.bd=!1,ws(t))}$d(t){if(0!==t.button)return;const i=this.Ud(t);if(this.Md=null,this.Bd=!1,this.Rd&&(this.Rd(),this.Rd=null),cs()){this.tp.ownerDocument.documentElement.removeEventListener("mouseleave",this.zd)}if(!this.Nd(t))if(this.Zd(i,this.Gd.wp),++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}else this.xd||this.Zd(i,this.Gd.gp)}sp(){null!==this.gd&&(clearTimeout(this.gd),this.gd=null)}bp(t){if(null!==this.Ed)return;const i=t.changedTouches[0];this.Ed=i.identifier,this.Od=bs(t);const s=this.tp.ownerDocument.documentElement;this.Cd=!1,this.Sd=!1,this.Ld=!1,this.yd=gs(i),this.Fd&&(this.Fd(),this.Fd=null);{const i=this.lp.bind(this),n=this.fp.bind(this);this.Fd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.sp(),this.gd=setTimeout(this.Mp.bind(this,t),240)}const n=this.Ud(t,i);this.Yd(n,this.Gd.yp),this.md||(this.vd=0,this.md=setTimeout(this.Kd.bind(this),500),this.wd=gs(i))}Sp(t){if(0!==t.button)return;const i=this.tp.ownerDocument.documentElement;cs()&&i.addEventListener("mouseleave",this.zd),this.xd=!1,this.Md=gs(t),this.Rd&&(this.Rd(),this.Rd=null);{const t=this.dp.bind(this),s=this.$d.bind(this);this.Rd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Bd=!0,this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.xp),this.pd||(this.dd=0,this.pd=setTimeout(this.Qd.bind(this),500),this.fd=gs(t))}ip(){this.tp.addEventListener("mouseenter",this.np.bind(this)),this.tp.addEventListener("touchcancel",this.sp.bind(this));{const t=this.tp.ownerDocument,i=t=>{this.Gd.Cp&&(t.composed&&this.tp.contains(t.composedPath()[0])||t.target&&this.tp.contains(t.target)||this.Gd.Cp())};this.Td=()=>{t.removeEventListener("touchstart",i)},this.Pd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}ds()&&(this.kd=()=>{this.tp.removeEventListener("dblclick",this.Hd)},this.tp.addEventListener("dblclick",this.Hd)),this.tp.addEventListener("mouseleave",this.Pp.bind(this)),this.tp.addEventListener("touchstart",this.bp.bind(this),{passive:!0}),fs(this.tp),this.tp.addEventListener("mousedown",this.Sp.bind(this)),this.Tp(),this.tp.addEventListener("touchmove",()=>{},{passive:!1})}Tp(){void 0===this.Gd.kp&&void 0===this.Gd.Dp&&void 0===this.Gd.Rp||(this.tp.addEventListener("touchstart",t=>this.Fp(t.touches),{passive:!0}),this.tp.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Vd&&void 0!==this.Gd.Dp){const i=ms(t.touches[0],t.touches[1])/this.Id;this.Gd.Dp(this.Vd,i),ws(t)}},{passive:!1}),this.tp.addEventListener("touchend",t=>{this.Fp(t.touches)}))}Fp(t){1===t.length&&(this.Ad=!1),2!==t.length||this.Ad||this.bd?this.Vp():this.Ip(t)}Ip(t){const i=this.tp.getBoundingClientRect()||{left:0,top:0};this.Vd={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Id=ms(t[0],t[1]),void 0!==this.Gd.kp&&this.Gd.kp(),this.sp()}Vp(){null!==this.Vd&&(this.Vd=null,void 0!==this.Gd.Rp&&this.Gd.Rp())}Pp(t){if(this.Dd&&this.Dd(),this.Nd(t))return;if(!this.Wd)return;const i=this.Ud(t);this.Zd(i,this.Gd.Ap),this.Wd=!ds()}Mp(t){const i=Ms(t.touches,l(this.Ed));if(null===i)return;const s=this.Ud(t,i);this.Yd(s,this.Gd.Lp),this.Cd=!0,this.bd=!0}Nd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:bs(t)<this.Od+500}Yd(t,i){i&&i.call(this.Gd,t)}Zd(t,i){i&&i.call(this.Gd,t)}Ud(t,i){const s=i||t,n=this.tp.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Bp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Op:t.type,Ep:s.target,a_:t.view,Wp:()=>{"touchstart"!==t.type&&ws(t)}}}}function ms(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ws(t){t.cancelable&&t.preventDefault()}function gs(t){return{ut:t.pageX,ct:t.pageY}}function bs(t){return t.timeStamp||performance.now()}function Ms(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class ys{constructor(t,i,s){this.zp=null,this.$p=null,this.Hp=!0,this.Np=null,this.Up=t,this.qp=t.jp()[i],this.Yp=t.jp()[s],this.Xp=document.createElement("tr"),this.Xp.style.height="1px",this.Gp=document.createElement("td"),this.Gp.style.position="relative",this.Gp.style.padding="0",this.Gp.style.margin="0",this.Gp.setAttribute("colspan","3"),this.Kp(),this.Xp.appendChild(this.Gp),this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(this.zp=null,this.$p=null)}m(){null!==this.$p&&this.$p.m()}Jp(){return this.Xp}Qp(){return es({width:this.qp.Qp().width,height:1})}tf(){return es({width:this.qp.tf().width,height:1*window.devicePixelRatio})}if(t,i,s){const n=this.tf();t.fillStyle=this.Up.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Kp(),this.Up.W().layout.panes.enableResize!==this.Hp&&(this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(null!==this.zp&&(this.Gp.removeChild(this.zp.sf),this.Gp.removeChild(this.zp.nf),this.zp=null),null!==this.$p&&(this.$p.m(),this.$p=null)))}Zp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Gp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Gp.appendChild(s);const e={rp:this.ef.bind(this),Ap:this.rf.bind(this),xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),wp:this.af.bind(this),vp:this.af.bind(this)};this.$p=new vs(s,e,{_p:()=>!1,up:()=>!0}),this.zp={nf:s,sf:t}}Kp(){this.Gp.style.background=this.Up.W().layout.panes.separatorColor}ef(t){null!==this.zp&&(this.zp.nf.style.backgroundColor=this.Up.W().layout.panes.separatorHoverColor)}rf(t){null!==this.zp&&null===this.Np&&(this.zp.nf.style.backgroundColor="")}hf(t){if(null===this.zp)return;const i=this.qp._f().Aa()+this.Yp._f().Aa(),s=i/(this.qp.Qp().height+this.Yp.Qp().height),n=30*s;i<=2*n||(this.Np={uf:t.pageY,cf:this.qp._f().Aa(),df:i-n,pf:i,ff:s,vf:n},this.zp.sf.style.display="block")}lf(t){const i=this.Np;if(null===i)return;const s=(t.pageY-i.uf)*i.ff,n=Xt(i.cf+s,i.vf,i.df);this.qp._f().La(n),this.Yp._f().La(i.pf-n),this.Up.ti().Lh()}af(t){null!==this.Np&&null!==this.zp&&(this.Np=null,this.zp.sf.style.display="none")}}function Ss(t,i){return t.mf-i.mf}function xs(t,i,s){const n=(t.mf-i.mf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class Cs{constructor(t,i,s,n){this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=null,this.Sf=0,this.xf=0,this.Cf=t,this.Pf=i,this.Tf=s,this.Mn=n}kf(t,i){if(null!==this.wf){if(this.wf.gt===i)return void(this.wf.mf=t);if(Math.abs(this.wf.mf-t)<this.Mn)return}this.Mf=this.bf,this.bf=this.gf,this.gf=this.wf,this.wf={gt:i,mf:t}}ae(t,i){if(null===this.wf||null===this.gf)return;if(i-this.wf.gt>50)return;let s=0;const n=xs(this.wf,this.gf,this.Pf),e=Ss(this.wf,this.gf),r=[n],h=[e];if(s+=e,null!==this.bf){const t=xs(this.gf,this.bf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.gf,this.bf);if(r.push(t),h.push(i),s+=i,null!==this.Mf){const t=xs(this.bf,this.Mf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.bf,this.Mf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.Cf||(this.yf={mf:t,gt:i},this.xf=l,this.Sf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Tf))}Iu(t){const i=l(this.yf),s=t-i.gt;return i.mf+this.xf*(Math.pow(this.Tf,s)-1)/Math.log(this.Tf)}Vu(t){return null===this.yf||this.Df(t)===this.Sf}Df(t){const i=t-l(this.yf).gt;return Math.min(i,this.Sf)}}class Ps{constructor(t,i){this.Rf=void 0,this.Ff=void 0,this.Vf=void 0,this.vs=!1,this.If=t,this.Af=i,this.Lf()}Tt(){this.Lf()}Bf(){this.Rf&&this.If.removeChild(this.Rf),this.Ff&&this.If.removeChild(this.Ff),this.Rf=void 0,this.Ff=void 0}Of(){return this.vs!==this.Ef()||this.Vf!==this.Wf()}Wf(){return this.Af.ti().Ki().tt(this.Af.W().layout.textColor)>160?"dark":"light"}Ef(){return this.Af.W().layout.attributionLogo}zf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Lf(){this.Of()&&(this.Bf(),this.vs=this.Ef(),this.vs&&(this.Vf=this.Wf(),this.Ff=document.createElement("style"),this.Ff.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.Rf=document.createElement("a"),this.Rf.href=`https://pipsend.com${this.zf()}`,this.Rf.title="Powered by Pipsend Charts",this.Rf.id="pipsend-attr-logo",this.Rf.target="_blank",this.Rf.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.Rf.toggleAttribute("data-dark","dark"===this.Vf),this.If.appendChild(this.Ff),this.If.appendChild(this.Rf)))}}function Ts(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new ls(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function ks(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function Ds(t,i,s,n){t.nh&&t.nh(i,s,n)}function Rs(t,i,s,n){t.et(i,s,n)}function Fs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Vs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],o=t[r-1],a=o.qt(n,!1),_=l.$i(),u=o.$i();if(1===i?_>u-a:_<u+a){const n=u-a*i;l.Hi(n);const r=n-i*a/2;if((1===i?r<0:r>s)&&h>0){const n=1===i?-1-r:r-s,l=Math.min(n,h);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);h-=l}}else e=r,h=1===i?u-a-_:_-(u+a)}}class As{constructor(t,i,s,n){this.Yi=null,this.$f=null,this.Hf=!1,this.Nf=new it(200),this.Uf=null,this.qf=0,this.jf=!1,this.Yf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Gf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Pt=t,this.Ps=i,this.xo=i.layout,this.sc=s,this.Kf="left"===n,this.Zf=Vs("normal",n),this.Jf=Vs("top",n),this.Qf=Vs("bottom",n),this.Gp=document.createElement("div"),this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.Gp.style.width="25px",this.Gp.style.left="0",this.Gp.style.position="relative",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.iv=Ts(this.Gp,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const r=this.iv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),Cp:this.sv.bind(this),wp:this.af.bind(this),vp:this.af.bind(this),Jd:this.nv.bind(this),Xd:this.nv.bind(this),rp:this.ev.bind(this),Ap:this.rf.bind(this)};this.$p=new vs(this.iv.canvasElement,h,{_p:()=>!this.Ps.handleScroll.vertTouchDrag,up:()=>!0})}m(){this.$p.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Yi&&this.Yi.ra().u(this),this.Yi=null}Jp(){return this.Gp}P(){return this.xo.fontSize}rv(){const t=this.sc.W();return this.Uf!==t.T&&(this.Nf.In(),this.Uf=t.T),t}hv(){if(null===this.Yi)return 0;let t=0;const i=this.rv(),s=l(this.tv.canvasElement.getContext("2d",{colorSpace:this.Pt.Xf().W().layout.colorSpace}));s.save();const n=this.Yi.Vl();s.font=this.lv(),n.length>0&&(t=Math.max(this.Nf.Vi(s,n[0].Jl),this.Nf.Vi(s,n[n.length-1].Jl)));const e=this.ov();for(let i=e.length;i--;){const n=this.Nf.Vi(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Ot();if(null!==r&&null!==this.$f&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.$f.height-2,r);t=Math.max(t,this.Nf.Vi(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Nf.Vi(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ps(Math.ceil(i.S+i.C+i.I+i.A+5+o))}av(t){null!==this.$f&&rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`)}_v(){return l(this.$f).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ra().u(this),this.Yi=t,t.ra().i(this.do.bind(this),this))}$t(){return this.Yi}In(){const t=this.Pt._f();this.Pt.Xf().ti().Ja(t,l(this.$t()))}uv(t){if(null===this.$f)return;const i={colorSpace:this.Pt.Xf().W().layout.colorSpace};if(1!==t){this.cv(),this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)}),this.Pt.fv(t,this.Qf),this.vv(t),this.Pt.fv(t,this.Zf),this.mv(t))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.wv(s),this.Pt.fv(s,this.Jf))}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Vl()}hf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!0,i.qa(s,this.Yi,t.localY)}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f(),n=this.Yi;i.ja(s,n,t.localY)}sv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Xf().ti(),i=this.Pt._f(),s=this.Yi;this.Hf&&(this.Hf=!1,t.Ya(i,s))}af(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!1,i.Ya(s,this.Yi)}nv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.In()}ev(t){if(null===this.Yi)return;!this.Pt.Xf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Ee()||this.Yi.Ao()||this.gv(1)}rf(t){this.gv(0)}ov(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt._f(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt._f().Ft()),t}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt._f().ti(),r=e.q(),h=e.Uc();r===h?I(t,0,0,s,n,r):B(t,0,0,s,n,r,h)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.$f||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.rv().S*s));let e;e=this.Kf?i.width-n:0,t.fillRect(e,0,n,i.height)}vv(t){if(null===this.$f||null===this.Yi)return;const i=this.Yi.Vl(),s=this.Yi.W(),n=this.rv(),e=this.Kf?this.$f.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.lv(),t.fillStyle=s.textColor??this.xo.textColor,t.textAlign=this.Kf?"right":"left",t.textBaseline="middle";const r=this.Kf?Math.round(e-n.I):Math.round(e+n.C+n.I),h=i.map(i=>this.Nf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}cv(){if(null===this.$f||null===this.Yi)return;let t=this.$f.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt._f(),e=this.rv();this.Yi===n.qn()&&this.Pt._f().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Ai())}),i.forEach(t=>t.Hi(t.Ai()));this.Yi.W().alignLabels&&this.bv(i,e,t)}bv(t,i,s){if(null===this.$f)return;const n=t.filter(t=>t.Ai()<=s),e=t.filter(t=>t.Ai()>s);n.sort((t,i)=>i.Ai()-t.Ai()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Ai()-i.Ai());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Ai();n>-t&&n<t&&s.Hi(t),n>this.$f.height-t&&n<this.$f.height+t&&s.Hi(this.$f.height-t)}Is(n,1,this.$f.height,i),Is(e,-1,this.$f.height,i)}mv(t){if(null===this.$f)return;const i=this.ov(),s=this.rv(),n=this.Kf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Nf,n)}})}wv(t){if(null===this.$f||null===this.Yi)return;const i=this.Pt.Xf().ti(),s=[],n=this.Pt._f(),e=i.fc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.rv(),h=this.Kf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Nf,h)})})}gv(t){this.Gp.style.cursor=1===t?"ns-resize":"default"}do(){const t=this.hv();this.qf<t&&this.Pt.Xf().ti().Lh(),this.qf=t}lv(){return g(this.xo.fontSize,this.xo.fontFamily)}}function Ls(t,i){return t.tl?.(i)??[]}function Bs(t,i){return t.$s?.(i)??[]}function Os(t,i){return t.cs?.(i)??[]}function Es(t,i){return t.Zh?.(i)??[]}class Ws{constructor(t,i){this.$f=es({width:0,height:0}),this.Mv=null,this.yv=null,this.Sv=null,this.xv=null,this.Cv=!1,this.Pv=new a,this.Tv=new a,this.kv=0,this.Dv=!1,this.Rv=null,this.Fv=!1,this.Vv=null,this.Iv=null,this.jf=!1,this.Yf=()=>{this.jf||null===this.Av||this.ss().ar()},this.Gf=()=>{this.jf||null===this.Av||this.ss().ar()},this.Af=t,this.Av=i,this.Av.s_().i(this.Lv.bind(this),this,!0),this.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Bv.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Ov=document.createElement("td"),this.Ov.style.padding="0",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Bv.appendChild(s),this.tv=Ts(s,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.iv=Ts(s,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const e=this.iv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Xp=document.createElement("tr"),this.Xp.appendChild(this.Ov),this.Xp.appendChild(this.Bv),this.Xp.appendChild(this.Ev),this.Wv(),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>null===this.Rv&&!this.Af.W().handleScroll.vertTouchDrag,up:()=>null===this.Rv&&!this.Af.W().handleScroll.horzTouchDrag})}m(){null!==this.Mv&&this.Mv.m(),null!==this.yv&&this.yv.m(),this.Sv=null,this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Av&&(this.Av.s_().u(this),this.Av.m()),this.$p.m()}_f(){return l(this.Av)}zv(t){null!==this.Av&&this.Av.s_().u(this),this.Av=t,null!==this.Av&&this.Av.s_().i(Ws.prototype.Lv.bind(this),this,!0),this.Wv(),this.Af.jp().indexOf(this)===this.Af.jp().length-1?(this.Sv=this.Sv??new Ps(this.Bv,this.Af),this.Sv.Tt()):(this.Sv?.Bf(),this.Sv=null)}Xf(){return this.Af}Jp(){return this.Xp}Wv(){if(null!==this.Av&&(this.$v(),0!==this.ss().Xs().length)){if(null!==this.Mv){const t=this.Av.Na();this.Mv.us(l(t))}if(null!==this.yv){const t=this.Av.Ua();this.yv.us(l(t))}}}Hv(){null!==this.Mv&&this.Mv.Tt(),null!==this.yv&&this.yv.Tt()}Aa(){return null!==this.Av?this.Av.Aa():0}La(t){this.Av&&this.Av.La(t)}rp(t){if(!this.Av)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}xp(t){this.Nv(),this.qv(),this.Uv(t.localX,t.localY,t)}hp(t){if(!this.Av)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}gp(t){null!==this.Av&&(this.Nv(),this.jv(t))}Jd(t){null!==this.Av&&this.Yv(this.Tv,t)}Xd(t){this.Jd(t)}pp(t){this.Nv(),this.Xv(t),this.Uv(t.localX,t.localY,t)}wp(t){null!==this.Av&&(this.Nv(),this.Dv=!1,this.Gv(t))}mp(t){null!==this.Av&&this.jv(t)}Lp(t){if(this.Dv=!0,null===this.Rv){const i={x:t.localX,y:t.localY};this.Kv(i,i,t)}}Ap(t){null!==this.Av&&(this.Nv(),this.Av.ti().uc(null),this.Zv())}Jv(){return this.Pv}Qv(){return this.Tv}kp(){this.kv=1,this.ss().ln()}Dp(t,i){if(!this.Af.W().handleScale.pinch)return;const s=5*(i-this.kv);this.kv=i,this.ss().xc(t.ut,s)}yp(t){this.Dv=!1,this.Fv=null!==this.Rv,this.qv();const i=this.ss().fc();null!==this.Rv&&i.Vt()&&(this.Vv={x:i.ni(),y:i.ei()},this.Rv={x:t.localX,y:t.localY})}cp(t){if(null===this.Av)return;const i=t.localX,s=t.localY;if(null!==this.Rv){this.Fv=!1;const n=l(this.Vv),e=n.x+(i-this.Rv.x),r=n.y+(s-this.Rv.y);return void this.Uv(e,r,t)}this.Xv(t)}vp(t){0===this.Xf().W().trackingMode.exitMode&&(this.Fv=!0),this.tm(),this.Gv(t)}Xn(t,i){const s=this.Av;return null===s?null:Si(s,t,i)}im(t,i){l("left"===i?this.Mv:this.yv).av(es({width:t,height:this.$f.height}))}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Bv.style.width=t.width+"px",this.Bv.style.height=t.height+"px")}sm(){const t=l(this.Av);t.Ha(t.Na()),t.Ha(t.Ua());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ha(s),i.zs()}for(const i of t.e_())i.zs()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;null!==t&&t.drawImage(n,i,s)}}uv(t){if(0===t)return;if(null===this.Av)return;t>1&&this.sm(),null!==this.Mv&&this.Mv.uv(t),null!==this.yv&&this.yv.uv(t);const i={colorSpace:this.Af.W().layout.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t)}),this.Av&&(this.nm(t,Ls),this.rm(t),this.nm(t,Bs),this.nm(t,Os)))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.hm(s),this.nm(s,Es),this.nm(s,Os))}lm(){return this.Mv}om(){return this.yv}fv(t,i){this.nm(t,i)}Lv(){null!==this.Av&&this.Av.s_().u(this),this.Av=null}jv(t){this.Yv(this.Pv,t)}Yv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().Lt().fu(s),{x:s,y:n},i)}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Uc();r===h?I(t,0,0,s,n,h):B(t,0,0,s,n,r,h)}rm(t){const i=l(this.Av),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}hm(t){this.am(t,Bs,Rs,this.ss().fc())}nm(t,i){const s=l(this.Av),n=s.Ft(),e=s.e_();for(const s of e)this.am(t,i,Ds,s);for(const s of n)this.am(t,i,Ds,s);for(const s of e)this.am(t,i,Rs,s);for(const s of n)this.am(t,i,Rs,s)}am(t,i,s,n){const e=l(this.Av),r=e.ti()._c(),h=null!==r&&r.r_===n,o=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Fs(i,i=>s(i,t,h,o),n,e)}$v(){if(null===this.Av)return;const t=this.Af,i=this.Av.Na().W().visible,s=this.Av.Ua().W().visible;i||null===this.Mv||(this.Ov.removeChild(this.Mv.Jp()),this.Mv.m(),this.Mv=null),s||null===this.yv||(this.Ev.removeChild(this.yv.Jp()),this.yv.m(),this.yv=null);const n=t.ti().Lc();i&&null===this.Mv&&(this.Mv=new As(this,t.W(),n,"left"),this.Ov.appendChild(this.Mv.Jp())),s&&null===this.yv&&(this.yv=new As(this,t.W(),n,"right"),this.Ev.appendChild(this.yv.Jp()))}_m(t){return t.Bp&&this.Dv||null!==this.Rv}um(t){return Math.max(0,Math.min(t,this.$f.width-1))}dm(t){return Math.max(0,Math.min(t,this.$f.height-1))}Uv(t,i,s){this.ss().Fc(this.um(t),this.dm(i),s,l(this.Av))}Zv(){this.ss().Ic()}tm(){this.Fv&&(this.Rv=null,this.Zv())}Kv(t,i,s){this.Rv=t,this.Fv=!1,this.Uv(i.x,i.y,s);const n=this.ss().fc();this.Vv={x:n.ni(),y:n.ei()}}ss(){return this.Af.ti()}Gv(t){if(!this.Cv)return;const i=this.ss(),s=this._f();if(i.Ka(s,s.ks()),this.xv=null,this.Cv=!1,i.kc(),null!==this.Iv){const t=performance.now(),s=i.Lt();this.Iv.ae(s.yu(),t),this.Iv.Vu(t)||i.un(this.Iv)}}Nv(){this.Rv=null}qv(){if(!this.Av)return;if(this.ss().ln(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)l(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Av.ks().Gi()&&this.ss().Lt().Gi()}Xv(t){if(null===this.Av)return;const i=this.ss(),s=i.Lt();if(s.Gi())return;const n=this.Af.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Bp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Bp))return;const h=this.Av.ks(),l=performance.now();if(null!==this.xv||this._m(t)||(this.xv={x:t.clientX,y:t.clientY,od:l,pm:t.localX,fm:t.localY}),null!==this.xv&&!this.Cv&&(this.xv.x!==t.clientX||this.xv.y!==t.clientY)){if(t.Bp&&r.touch||!t.Bp&&r.mouse){const t=s.bu();this.Iv=new Cs(.2/t,7/t,.997,15/t),this.Iv.kf(s.yu(),this.xv.od)}else this.Iv=null;h.Gi()||i.Xa(this.Av,h,t.localY),i.Pc(t.localX),this.Cv=!0}this.Cv&&(h.Gi()||i.Ga(this.Av,h,t.localY),i.Tc(t.localX),null!==this.Iv&&this.Iv.kf(s.yu(),l))}}class zs{constructor(t,i,s,n,e){this.xt=!0,this.$f=es({width:0,height:0}),this.Yf=()=>this.uv(3),this.Kf="left"===t,this.sc=s.Lc,this.Ps=i,this.vm=n,this.wm=e,this.Gp=document.createElement("div"),this.Gp.style.width="25px",this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf)}m(){this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Gp}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.tv.resizeCanvasElement(t),this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.xt=!0)}uv(t){if(t<3&&!this.xt)return;if(0===this.$f.width||0===this.$f.height)return;this.xt=!1,this.tv.applySuggestedBitmapSize();const i=_s(this.tv,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)})}tf(){return this.tv.bitmapSize}if(t,i,s){const n=this.tf();n.width>0&&n.height>0&&t.drawImage(this.tv.canvasElement,i,s)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.vm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.sc.W().S*s),r=Math.floor(this.sc.W().S*n),h=this.Kf?i.width-e:0;t.fillRect(h,0,e,r)}dv({context:t,bitmapSize:i}){I(t,0,0,i.width,i.height,this.wm())}}function $s(t){return i=>i.nl?.(t)??[]}const Hs=$s("normal"),Ns=$s("top"),Us=$s("bottom");class qs{constructor(t,i){this.gm=null,this.bm=null,this.M=null,this.Mm=!1,this.$f=es({width:0,height:0}),this.ym=new a,this.Nf=new it(5),this.jf=!1,this.Yf=()=>{this.jf||this.Af.ti().ar()},this.Gf=()=>{this.jf||this.Af.ti().ar()},this.Af=t,this.u_=i,this.Ps=t.W().layout,this.Rf=document.createElement("tr"),this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.xm=document.createElement("td"),this.xm.style.padding="0",this.Gp=document.createElement("td"),this.Gp.style.height="25px",this.Gp.style.padding="0",this.Cm=document.createElement("div"),this.Cm.style.width="100%",this.Cm.style.height="100%",this.Cm.style.position="relative",this.Cm.style.overflow="hidden",this.Gp.appendChild(this.Cm),this.tv=Ts(this.Cm,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const s=this.tv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.iv=Ts(this.Cm,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const n=this.iv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Rf.appendChild(this.Sm),this.Rf.appendChild(this.Gp),this.Rf.appendChild(this.xm),this.Pm(),this.Af.ti().Ia().i(this.Pm.bind(this),this),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>!0,up:()=>!this.Af.W().handleScroll.horzTouchDrag})}m(){this.$p.m(),null!==this.gm&&this.gm.m(),null!==this.bm&&this.bm.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Rf}Tm(){return this.gm}km(){return this.bm}xp(t){if(this.Mm)return;this.Mm=!0;const i=this.Af.ti();!i.Lt().Gi()&&this.Af.W().handleScale.axisPressedMouseMove.time&&i.Sc(t.localX)}yp(t){this.xp(t)}Cp(){const t=this.Af.ti();!t.Lt().Gi()&&this.Mm&&(this.Mm=!1,this.Af.W().handleScale.axisPressedMouseMove.time&&t.Rc())}pp(t){const i=this.Af.ti();!i.Lt().Gi()&&this.Af.W().handleScale.axisPressedMouseMove.time&&i.Dc(t.localX)}cp(t){this.pp(t)}wp(){this.Mm=!1;const t=this.Af.ti();t.Lt().Gi()&&!this.Af.W().handleScale.axisPressedMouseMove.time||t.Rc()}vp(){this.wp()}Jd(){this.Af.W().handleScale.axisDoubleClickReset.time&&this.Af.ti().dn()}Xd(){this.Jd()}rp(){this.Af.ti().W().handleScale.axisPressedMouseMove.time&&this.gv(1)}Ap(){this.gv(0)}Qp(){return this.$f}Dm(){return this.ym}Rm(t,i,s){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.ym.p(t)),null!==this.gm&&this.gm.av(es({width:i,height:t.height})),null!==this.bm&&this.bm.av(es({width:s,height:t.height}))}Fm(){const t=this.Vm();return Math.ceil(t.S+t.C+t.P+t.L+t.V+t.Im)}Tt(){this.Af.ti().Lt().Vl()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}uv(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const s=_s(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t),this.Am(s,Us)}),this.vv(s),this.Am(s,Hs)),null!==this.gm&&this.gm.uv(t),null!==this.bm&&this.bm.uv(t)}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Lm([...this.Af.ti().Xs(),this.Af.ti().fc()],s),this.Am(s,Ns))}Am(t,i){const s=this.Af.ti().Xs();for(const n of s)Fs(i,i=>Ds(i,t,!1,void 0),n,void 0);for(const n of s)Fs(i,i=>Rs(i,t,!1,void 0),n,void 0)}dv({context:t,bitmapSize:i}){I(t,0,0,i.width,i.height,this.Af.ti().Uc())}pv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Af.W().timeScale.borderVisible){t.fillStyle=this.Bm();const n=Math.max(1,Math.floor(this.Vm().S*s));t.fillRect(0,0,i.width,n)}}vv(t){const i=this.Af.ti().Lt(),s=i.Vl();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Vm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Bm(),t.fillStyle=this.Bm();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.L+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.lv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Af.W().timeScale.allowBoldLabels&&(t.font=this.Em());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Om(t,i,s){const n=this.Nf.Vi(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.$f.width&&(i-=Math.abs(this.$f.width-(r+n))),i}Lm(t,i){const s=this.Vm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Bm(){return this.Af.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}lv(){return g(this.$(),this.Ps.fontFamily)}Em(){return g(this.$(),this.Ps.fontFamily,"bold")}Vm(){null===this.M&&(this.M={S:1,B:NaN,L:NaN,V:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Im:0});const t=this.M,i=this.lv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.L=3*s/12,t.V=3*s/12,t.Qi=9*s/12,t.B=0,t.Im=4*s/12,t.Ji.In()}return this.M}gv(t){this.Gp.style.cursor=1===t?"ew-resize":"default"}Pm(){const t=this.Af.ti(),i=t.W();i.leftPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Jp()),this.gm.m(),this.gm=null),i.rightPriceScale.visible||null===this.bm||(this.xm.removeChild(this.bm.Jp()),this.bm.m(),this.bm=null);const s={Lc:this.Af.ti().Lc()},n=()=>i.leftPriceScale.borderVisible&&t.Lt().W().borderVisible,e=()=>t.Uc();i.leftPriceScale.visible&&null===this.gm&&(this.gm=new zs("left",i,s,n,e),this.Sm.appendChild(this.gm.Jp())),i.rightPriceScale.visible&&null===this.bm&&(this.bm=new zs("right",i,s,n,e),this.xm.appendChild(this.bm.Jp()))}}const js=!!us&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!us&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class Ys{constructor(t,i,s){var n;this.Wm=[],this.zm=[],this.$m=0,this.eo=0,this.ya=0,this.Hm=0,this.Nm=0,this.Um=null,this.qm=!1,this.Pv=new a,this.Tv=new a,this.Ju=new a,this.jm=null,this.Ym=null,this.If=t,this.Ps=i,this.u_=s,this.Rf=document.createElement("div"),this.Rf.classList.add("tv-lightweight-charts"),this.Rf.style.overflow="hidden",this.Rf.style.direction="ltr",this.Rf.style.width="100%",this.Rf.style.height="100%",(n=this.Rf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Xm=document.createElement("table"),this.Xm.setAttribute("cellspacing","0"),this.Rf.appendChild(this.Xm),this.Gm=this.Km.bind(this),Xs(this.Ps)&&this.Zm(!0),this.ss=new Bi(this.tc.bind(this),this.Ps,s),this.ti().vc().i(this.Jm.bind(this),this),this.Qm=new qs(this,this.u_),this.Xm.appendChild(this.Qm.Jp());const e=i.autoSize&&this.tw();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.iw(r,h),this.sw(),t.appendChild(this.Rf),this.nw(),this.ss.Lt().Bu().i(this.ss.Lh.bind(this.ss),this),this.ss.Ia().i(this.ss.Lh.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}jp(){return this.Wm}ew(){return this.Qm}m(){this.Zm(!1),0!==this.$m&&window.cancelAnimationFrame(this.$m),this.ss.vc().u(this),this.ss.Lt().Bu().u(this),this.ss.Ia().u(this),this.ss.m();for(const t of this.Wm)this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();this.Wm=[];for(const t of this.zm)this.rw(t);this.zm=[],l(this.Qm).m(),null!==this.Rf.parentElement&&this.Rf.parentElement.removeChild(this.Rf),this.Ju.m(),this.Pv.m(),this.Tv.m(),this.hw()}iw(t,i,s=!1){if(this.eo===i&&this.ya===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return es({width:i-i%2,height:s-s%2})}(es({width:t,height:i}));this.eo=n.height,this.ya=n.width;const e=this.eo+"px",r=this.ya+"px";l(this.Rf).style.height=e,l(this.Rf).style.width=r,this.Xm.style.height=e,this.Xm.style.width=r,s?this.lw(Y.bn(),performance.now()):this.ss.Lh()}uv(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Wm.length;i++)this.Wm[i].uv(t.rn(i).sn);this.Ps.timeScale.visible&&this.Qm.uv(t.en())}lr(t){const i=Xs(this.Ps);this.ss.lr(t);const s=Xs(this.Ps);s!==i&&this.Zm(s),t.layout?.panes&&this.ow(),this.nw(),this.aw(t)}Jv(){return this.Pv}Qv(){return this.Tv}vc(){return this.Ju}_w(t=!1){null!==this.Um&&(this.lw(this.Um,performance.now()),this.Um=null);const i=this.uw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.uw(n,t),s}cw(t){if("left"===t&&!this.dw())return 0;if("right"===t&&!this.pw())return 0;if(0===this.Wm.length)return 0;return l("left"===t?this.Wm[0].lm():this.Wm[0].om())._v()}fw(){return this.Ps.autoSize&&null!==this.jm}nf(){return this.Rf}mw(t){this.Ym=t,this.Ym?this.nf().style.setProperty("cursor",t):this.nf().style.removeProperty("cursor")}ww(){return this.Ym}gw(t){return h(this.Wm[t]).Qp()}ow(){this.zm.forEach(t=>{t.Tt()})}aw(t){(void 0!==t.autoSize||!this.jm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.jm&&this.tw(),!1===t.autoSize&&null!==this.jm&&this.hw(),t.autoSize||void 0===t.width&&void 0===t.height||this.iw(t.width||this.ya,t.height||this.eo))}uw(t,i){let s=0,n=0;const e=this.Wm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Wm.length;r++){const h=this.Wm[r],o=l("left"===s?h.lm():h.om()),a=o.tf();if(null!==t&&o.if(t,n,e,i),e+=a.height,r<this.Wm.length-1){const i=this.zm[r],s=i.tf();null!==t&&i.if(t,n,e),e+=s.height}}};if(this.dw()){r("left",0);s+=l(e.lm()).tf().width}for(let e=0;e<this.Wm.length;e++){const r=this.Wm[e],h=r.tf();if(null!==t&&r.if(t,s,n,i),n+=h.height,e<this.Wm.length-1){const i=this.zm[e],r=i.tf();null!==t&&i.if(t,s,n),n+=r.height}}if(s+=e.tf().width,this.pw()){r("right",s);s+=l(e.om()).tf().width}const h=(i,s,n)=>{l("left"===i?this.Qm.Tm():this.Qm.km()).if(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Qm.tf();if(null!==t){let r=0;this.dw()&&(h("left",r,n),r=l(e.lm()).tf().width),this.Qm.if(t,r,n,i),r+=s.width,this.pw()&&h("right",r,n)}n+=s.height}return es({width:s,height:n})}bw(){let t=0,i=0,s=0;for(const n of this.Wm)this.dw()&&(i=Math.max(i,l(n.lm()).hv(),this.Ps.leftPriceScale.minimumWidth)),this.pw()&&(s=Math.max(s,l(n.om()).hv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Aa();i=ps(i),s=ps(s);const n=this.ya,e=this.eo,r=Math.max(n-i-s,0),h=1*this.zm.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Qm.Fm(),this.Ps.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=h+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Wm.length;++t){const n=this.Wm[t];n.zv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Wm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Aa()*d*f)/f,e=Math.max(h,2),p+=e,n.av(es({width:r,height:e})),this.dw()&&n.im(i,"left"),this.pw()&&n.im(s,"right"),n._f()&&this.ss.mc(n._f(),e)}this.Qm.Rm(es({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ba(r),this.Hm!==i&&(this.Hm=i),this.Nm!==s&&(this.Nm=s)}Zm(t){t?this.Rf.addEventListener("wheel",this.Gm,{passive:!1}):this.Rf.removeEventListener("wheel",this.Gm)}Mw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return js?1/window.devicePixelRatio:1}Km(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.Mw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.Rf.getBoundingClientRect().left;this.ti().xc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Cc(-80*s)}lw(t,i){const s=t.en();3===s&&this.yw(),3!==s&&2!==s||(this.Sw(t),this.xw(t,i),this.Qm.Tt(),this.Wm.forEach(t=>{t.Hv()}),3===this.Um?.en()&&(this.Um.mn(t),this.yw(),this.Sw(this.Um),this.xw(this.Um,i),t=this.Um,this.Um=null)),this.uv(t)}xw(t,i){for(const s of t.vn())this.wn(s,i)}Sw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qa()}wn(t,i){const s=this.ss.Lt();switch(t.an){case 0:s.Eu();break;case 1:s.Wu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Cu();break;case 5:t.Ht.Vu(i)||s.fn(t.Ht.Iu(i))}}tc(t){null!==this.Um?this.Um.mn(t):this.Um=t,this.qm||(this.qm=!0,this.$m=window.requestAnimationFrame(t=>{if(this.qm=!1,this.$m=0,null!==this.Um){const i=this.Um;this.Um=null,this.lw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Vu(t)){this.ti().un(s.Ht);break}}}))}yw(){this.sw()}rw(t){this.Xm.removeChild(t.Jp()),t.m()}sw(){const t=this.ss.qs(),i=t.length,s=this.Wm.length;for(let t=i;t<s;t++){const t=h(this.Wm.pop());this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();const i=this.zm.pop();void 0!==i&&this.rw(i)}for(let n=s;n<i;n++){const i=new Ws(this,t[n]);if(i.Jv().i(this.Cw.bind(this,i),this),i.Qv().i(this.Pw.bind(this,i),this),this.Wm.push(i),n>0){const t=new ys(this,n-1,n);this.zm.push(t),this.Xm.insertBefore(t.Jp(),this.Qm.Jp())}this.Xm.insertBefore(i.Jp(),this.Qm.Jp())}for(let s=0;s<i;s++){const i=t[s],n=this.Wm[s];n._f()!==i?n.zv(i):n.Wv()}this.nw(),this.bw()}Tw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.Lt().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti()._c(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,o=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,a=this.kw(n);return{Dw:r,Re:t??void 0,Rw:i??void 0,Fw:-1!==a?a:void 0,Vw:l,Iw:e,Aw:o,Lw:s??void 0}}kw(t){let i=-1;if(t)i=this.Wm.indexOf(t);else{const t=this.ti().fc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Cw(t,i,s,n){this.Pv.p(()=>this.Tw(i,s,n,t))}Pw(t,i,s,n){this.Tv.p(()=>this.Tw(i,s,n,t))}Jm(t,i,s){this.mw(this.ti()._c()?.o_??null),this.Ju.p(()=>this.Tw(t,i,s))}nw(){const t=this.Ps.timeScale.visible?"":"none";this.Qm.Jp().style.display=t}dw(){return this.Wm[0]._f().Na().W().visible}pw(){return this.Wm[0]._f().Ua().W().visible}tw(){return"ResizeObserver"in window&&(this.jm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.iw(i.contentRect.width,i.contentRect.height)}),this.jm.observe(this.If,{box:"border-box"}),!0)}hw(){null!==this.jm&&this.jm.disconnect(),this.jm=null}}function Xs(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Gs(t){return void 0===t.open&&void 0===t.value}function Ks(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.color&&(r.R=s.color),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Qs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),e}function sn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function nn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),o=Math.min(...r),a=r[r.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,Dw:n,ne:d,R:c}}function en(t){return void 0!==t.Ht}function rn(t,i){return void 0!==i.customValues&&(t.Bw=i.customValues),t}function hn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Gs(t)}(n,h)?rn({gt:i,Re:s,Dw:e},n):rn(t(i,s,n,e,r),n)}function ln(t){return{Candlestick:hn(sn),Bar:hn(tn),Area:hn(Js),Baseline:hn(Qs),Histogram:hn(Zs),Line:hn(Zs),Custom:hn(nn)}[t]}function on(t){return{Re:0,Ow:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Ew:i.key(t[0].gt),Ww:i.key(t[t.length-1].gt)}}function _n(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Dw)}),h(i)}class un{constructor(t){this.zw=new Map,this.$w=new Map,this.Hw=new Map,this.Nw=[],this.u_=t}m(){this.zw.clear(),this.$w.clear(),this.Hw.clear(),this.Nw=[]}Uw(t,i){let s=0!==this.zw.size,n=!1;const e=this.$w.get(t);if(void 0!==e)if(1===this.$w.size)s=!1,n=!0,this.zw.clear();else for(const i of this.Nw)i.pointData.Ow.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=ln(t.Rr()),l=t.pl(),o=t.vl();r=i.map((i,r)=>{const a=e(i.time),_=this.u_.key(a);let u=this.zw.get(_);void 0===u&&(u=on(a),this.zw.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Ow.set(t,c),c})}s&&this.qw(),this.jw(t,r);let h=-1;if(n){const t=[];this.zw.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:_n(i.Ow)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.Yw(t)}return this.Xw(t,h,function(t,i,s){const n=an(t,s),e=an(i,s);if(void 0!==n&&void 0!==e)return{Gw:!1,Eh:n.Ww>=e.Ww&&n.Ew>=e.Ew}}(this.$w.get(t),e,this.u_))}Ec(t){return this.Uw(t,[])}Kw(t,i,s){const n=i;!function(t){void 0===t.Dw&&(t.Dw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.Hw.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.zw.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=on(e),this.zw.set(this.u_.key(e),h));const o=ln(t.Rr()),a=t.pl(),_=t.vl(),u=o(e,h.Re,i,n.Dw,a,_);h.Ow.set(t,u),s?this.Zw(t,u,h.Re):this.Jw(t,u);const c={Eh:en(u),Gw:s};if(!l)return this.Xw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:_n(h.Ow)},p=yt(this.Nw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Nw.splice(p,0,d);for(let t=p;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Nw,p),this.Xw(t,p,c)}Qw(t,i){const s=this.$w.get(t);if(void 0===s||i<=0)return[[],this.tg()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.Hw.delete(t):this.Hw.set(t,s[s.length-1].gt);for(const i of n){const s=this.zw.get(this.u_.key(i.gt));if(s&&(s.Ow.delete(t),0===s.Ow.size)){this.zw.delete(this.u_.key(s.Uh)),this.Nw.splice(s.Re,1);for(let t=s.Re;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t)}}return[n,this.Xw(t,this.Nw.length-1,{Gw:!1,Eh:!1})]}Jw(t,i){let s=this.$w.get(t);void 0===s&&(s=[],this.$w.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?en(i)&&s.push(i):en(i)?s[s.length-1]=i:s.splice(-1,1),this.Hw.set(t,i.gt)}Zw(t,i,s){const n=this.$w.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);en(i)?n[e]=i:n.splice(e,1)}jw(t,i){0!==i.length?(this.$w.set(t,i.filter(en)),this.Hw.set(t,i[i.length-1].gt)):(this.$w.delete(t),this.Hw.delete(t))}qw(){for(const t of this.Nw)0===t.pointData.Ow.size&&this.zw.delete(this.u_.key(t.time))}Yw(t){let i=-1;for(let s=0;s<this.Nw.length&&s<t.length;++s){const n=this.Nw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,cn(e.pointData,s)}if(-1===i&&this.Nw.length!==t.length&&(i=Math.min(this.Nw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)cn(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Nw=t,i}ig(){if(0===this.$w.size)return null;let t=0;return this.$w.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Xw(t,i,s){const n=this.tg();if(-1!==i)this.$w.forEach((i,e)=>{n.za.set(e,{ne:i,sg:e===t?s:void 0})}),this.$w.has(t)||n.za.set(t,{ne:[],sg:s}),n.Lt.ng=this.Nw,n.Lt.eg=i;else{const i=this.$w.get(t);n.za.set(t,{ne:i||[],sg:s})}return n}tg(){return{za:new Map,Lt:{du:this.ig()}}}}function cn(t,i){t.Re=i,t.Ow.forEach(t=>{t.Re=i})}function dn(t,i){return t.gt<i}function pn(t,i){return i<t.gt}function fn(t,i,s){const n=i.qh(),e=i.yi(),r=yt(t,n,dn),h=St(t,e,pn);if(!s)return{from:r,to:h};let l=r,o=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(o=h+1),{from:l,to:o}}class vn{constructor(t,i,s){this.rg=!0,this.hg=!0,this.lg=!0,this.og=[],this.ag=null,this.Qn=t,this.te=i,this._g=s}Tt(t){this.rg=!0,"data"===t&&(this.hg=!0),"options"===t&&(this.lg=!0)}Dt(){return this.Qn.Vt()?(this.ug(),null===this.ag?null:this.cg):null}dg(){const t=this.Qn.Fh();this.og=this.og.map(i=>{const s=t.Vr(i.gt);return null===s?i:{...i,...s}})}pg(){this.ag=null}ug(){this.hg&&(this.fg(),this.hg=!1),this.lg&&(this.dg(),this.lg=!1),this.rg&&(this.vg(),this.rg=!1)}vg(){const t=this.Qn.$t(),i=this.te.Lt();if(this.pg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Er())return;const n=this.Qn.Ot();null!==n&&(this.ag=fn(this.og,s,this._g),this.mg(t,i,n.Ht),this.wg())}}class mn{constructor(t,i){this.gg=t,this.Yi=i}et(t,i,s){this.gg.draw(t,this.Yi,i,s)}}class wn extends vn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.cg=new mn(this.eh.renderer(),i=>{const s=t.Ot();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),bg:i.ne}))}mg(t,i){i.pu(this.og,m(this.ag))}wg(){this.eh.update({bars:this.og.map(gn),barSpacing:this.te.Lt().bu(),visibleRange:this.ag},this.Qn.W())}}function gn(t){return{x:t.ut,time:t.gt,originalData:t.bg,barColor:t.dr}}const bn={color:"#2196f3"},Mn=(t,i,s)=>{const n=o(s);return new wn(t,i,n)};function yn(t){const i={value:t.Ht[3],time:t.Dw};return void 0!==t.Bw&&(i.customValues=t.Bw),i}function Sn(t){const i=yn(t);return void 0!==t.R&&(i.color=t.R),i}function xn(t){const i=yn(t);return void 0!==t.wt&&(i.lineColor=t.wt),void 0!==t.wr&&(i.topColor=t.wr),void 0!==t.gr&&(i.bottomColor=t.gr),i}function Cn(t){const i=yn(t);return void 0!==t.br&&(i.topLineColor=t.br),void 0!==t.Mr&&(i.bottomLineColor=t.Mr),void 0!==t.yr&&(i.topFillColor1=t.yr),void 0!==t.Sr&&(i.topFillColor2=t.Sr),void 0!==t.Cr&&(i.bottomFillColor1=t.Cr),void 0!==t.Pr&&(i.bottomFillColor2=t.Pr),i}function Pn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Dw};return void 0!==t.Bw&&(i.customValues=t.Bw),i}function Tn(t){const i=Pn(t);return void 0!==t.R&&(i.color=t.R),i}function kn(t){const i=Pn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function Dn(t){return{Area:xn,Line:Sn,Baseline:Cn,Histogram:Sn,Bar:Tn,Candlestick:kn,Custom:Rn}[t]}function Rn(t){const i=t.Dw;return{...t.ne,time:i}}const Fn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},Vn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},In={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},An={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0,ensureEdgeTickMarksVisible:!1,tickMarkSpacing:2.5},Ln={rightOffset:0,barSpacing:6,minBarSpacing:.5,maxBarSpacing:0,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0,ignoreWhitespaceIndices:!1};function Bn(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:In,crosshair:Fn,grid:Vn,overlayPriceScales:{...An},leftPriceScale:{...An,visible:!1},rightPriceScale:{...An,visible:!0},timeScale:Ln,localization:{locale:us?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class On{constructor(t,i,s){this.Up=t,this.Mg=i,this.yg=s??0}applyOptions(t){this.Up.ti().cc(this.Mg,t,this.yg)}options(){return this.Yi().W()}width(){return j(this.Mg)?this.Up.cw(this.Mg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Uo(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().io()){const n=this.Yi().ma(),e=Oi(n);s=oi(s,this.Yi().no()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Up.ti().dc(this.Mg,this.yg)).$t}}class En{constructor(t,i,s,n){this.Up=t,this.Pt=s,this.Sg=i,this.xg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Up.ti(),s=i.jc(this.Pt);i.gc(s,t)}getStretchFactor(){return this.Pt.Aa()}setStretchFactor(t){this.Pt.La(t),this.Up.ti().Lh()}paneIndex(){return this.Up.ti().jc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Up.jp().length,"Invalid pane index"),this.Up.ti().Mc(i,t))}getSeries(){return this.Pt.za().map(t=>this.Sg(t))??[]}getHTMLElement(){const t=this.Up.jp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Jp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.xg,requestUpdate:()=>this.Pt.ti().Lh()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Va(t))throw new Error(`Cannot find price scale with id: ${t}`);return new On(this.Up,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Ea(t)}preserveEmptyPane(){return this.Pt.Wa()}addCustomSeries(t,i={},s=0){return this.xg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.xg.addSeries(t,i,this.paneIndex())}}const Wn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class zn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Cg(){return this.sr}}class $n{constructor(t,i,s,n,e,r){this.Pg=new a,this.Qn=t,this.Tg=i,this.kg=s,this.u_=e,this.xg=n,this.Dg=r}m(){this.Pg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.Ot();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Ot();return null===i?null:this.Qn.$t().Ds(t,i.Ht)}barsInLogicalRange(t){if(null===t)return null;const i=new ki(new Ci(t.from,t.to)).D_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(o.from=n.Dw,o.to=e.Dw),o}setData(t){this.u_,this.Qn.Rr(),this.Tg.Rg(this.Qn,t),this.Fg("full")}update(t,i=!1){this.Qn.Rr(),this.Tg.Vg(this.Qn,t,i),this.Fg("update")}pop(t=1){const i=this.Tg.Ig(this.Qn,t);0!==i.length&&this.Fg("update");const s=Dn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return Dn(this.seriesType())(s)}data(){const t=Dn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Pg.i(t)}unsubscribeDataChanged(t){this.Pg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.kg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(Wn),t),s=this.Qn.zh(i);return new zn(s)}removePriceLine(t){this.Qn.$h(t.Cg())}priceLines(){return this.Qn.Hh().map(t=>new zn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.xg,series:this,requestUpdate:()=>this.Qn.ti().Lh(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Lh()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Dg(i)}moveToPane(t){this.Qn.ti().Hc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.za().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Fg(t){this.Pg.v()&&this.Pg.p(t)}}class Hn{constructor(t,i,s){this.Ag=new a,this.W_=new a,this.ym=new a,this.ss=t,this.ph=t.Lt(),this.Qm=i,this.ph.Au().i(this.Lg.bind(this)),this.ph.Lu().i(this.Bg.bind(this)),this.Qm.Dm().i(this.Og.bind(this)),this.u_=s}m(){this.ph.Au().u(this),this.ph.Lu().u(this),this.Qm.Dm().u(this),this.Ag.m(),this.W_.m(),this.ym.m()}scrollPosition(){return this.ph.yu()}scrollToPosition(t,i){i?this.ph.Fu(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Ru()}getVisibleRange(){const t=this.ph.hu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph._u(i);this.ss.zc(s)}getVisibleLogicalRange(){const t=this.ph.ru();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.zc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Eu()}logicalToCoordinate(t){const i=this.ss.Lt();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.fu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.su(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.Lt(),s=i.fu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Qm.Qp().width}height(){return this.Qm.Qp().height}subscribeVisibleTimeRangeChange(t){this.Ag.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Ag._(t)}subscribeVisibleLogicalRangeChange(t){this.W_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.W_._(t)}subscribeSizeChange(t){this.ym.i(t)}unsubscribeSizeChange(t){this.ym._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.bu()}}Lg(){this.Ag.v()&&this.Ag.p(this.getVisibleRange())}Bg(){this.W_.v()&&this.W_.p(this.getVisibleLogicalRange())}Og(t){this.ym.p(t.width,t.height)}}function Nn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Un{constructor(t,i,s){this.Eg=new Map,this.Wg=new Map,this.zg=new a,this.$g=new a,this.Hg=new a,this.Xu=new WeakMap,this.Ng=new un(i);const n=void 0===s?f(Bn()):_(f(Bn()),Nn(s));this.Ug=i,this.Up=new Ys(t,n,i),this.Up.Jv().i(t=>{this.zg.v()&&this.zg.p(this.qg(t()))},this),this.Up.Qv().i(t=>{this.$g.v()&&this.$g.p(this.qg(t()))},this),this.Up.vc().i(t=>{this.Hg.v()&&this.Hg.p(this.qg(t()))},this);const e=this.Up.ti();this.jg=new Hn(e,this.Up.ew(),this.Ug)}remove(){this.Up.Jv().u(this),this.Up.Qv().u(this),this.Up.vc().u(this),this.jg.m(),this.Up.m(),this.Eg.clear(),this.Wg.clear(),this.zg.m(),this.$g.m(),this.Hg.m(),this.Ng.m()}resize(t,i,s){this.autoSizeActive()||this.Up.iw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...bn,...t.defaultOptions()},Yg:Mn,Xg:t}))(o(t));return this.Gg(n,i,s)}addSeries(t,i={},s=0){return this.Gg(t,i,s)}removeSeries(t){const i=h(this.Eg.get(t)),s=this.Ng.Ec(i);this.Up.ti().Ec(i),this.Kg(s),this.Eg.delete(t),this.Wg.delete(i)}Rg(t,i){this.Kg(this.Ng.Uw(t,i))}Vg(t,i,s){this.Kg(this.Ng.Kw(t,i,s))}Ig(t,i){const[s,n]=this.Ng.Qw(t,i);return 0!==s.length&&this.Kg(n),s}subscribeClick(t){this.zg.i(t)}unsubscribeClick(t){this.zg._(t)}subscribeCrosshairMove(t){this.Hg.i(t)}unsubscribeCrosshairMove(t){this.Hg._(t)}subscribeDblClick(t){this.$g.i(t)}unsubscribeDblClick(t){this.$g._(t)}priceScale(t,i=0){return new On(this.Up,t,i)}timeScale(){return this.jg}applyOptions(t){this.Up.lr(Nn(t))}options(){return this.Up.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Up.ti().W().crosshair.mode,this.Up.lr({crosshair:{mode:2}})),n=this.Up._w(t)}finally{i||void 0===s||this.Up.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Up.ti().Yc();return i.Ea(t),this.Zg(i)}removePane(t){this.Up.ti().wc(t)}swapPanes(t,i){this.Up.ti().bc(t,i)}autoSizeActive(){return this.Up.fw()}chartElement(){return this.Up.nf()}panes(){return this.Up.ti().qs().map(t=>this.Zg(t))}paneSize(t=0){const i=this.Up.gw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Eg.get(s);if(void 0===n)return;const e=this.Up.ti().Nn(n);null!==e&&this.Up.ti().Vc(t,i,e)}clearCrosshairPosition(){this.Up.ti().Ic(!0)}horzBehaviour(){return this.Ug}Gg(i,s={},n=0){r(void 0!==i.Yg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Oi(i.minMove))}(s.priceFormat),"Candlestick"===i.type&&function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(s);const e=_(f(t),f(i.defaultOptions),s),h=i.Yg,l=new Ut(this.Up.ti(),i.type,e,h,i.Xg);this.Up.ti().Bc(l,n);const o=new $n(l,this,this,this,this.Ug,t=>this.Zg(t));return this.Eg.set(o,l),this.Wg.set(l,o),o}Kg(t){const i=this.Up.ti();i.Ac(t.Lt.du,t.Lt.ng,t.Lt.eg),t.za.forEach((t,i)=>i.lt(t.ne,t.sg)),i.Lt().Z_(),i.gu()}Jg(t){return h(this.Wg.get(t))}qg(t){const i=new Map;t.Iw.forEach((t,s)=>{const n=s.Rr(),e=Dn(n)(t);if("Custom"!==n)r(Ks(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Jg(s),e)});const s=void 0!==t.Vw&&this.Wg.has(t.Vw)?this.Jg(t.Vw):void 0;return{time:t.Dw,logical:t.Re,point:t.Rw,paneIndex:t.Fw,hoveredSeries:s,hoveredObjectId:t.Aw,seriesData:i,sourceEvent:t.Lw}}Zg(t){let i=this.Xu.get(t);return i||(i=new En(this.Up,t=>this.Jg(t),t,this),this.Xu.set(t,i)),i}}function qn(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function jn(t,i,s){const n=qn(t),e=new Un(n,i,s);return i.setOptions(e.options()),e}function Yn(t,i){return jn(t,new ns,ns.ud(i))}function Xn(){return ns}function Gn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Qg:n.time-h.time}}function Kn(t,i,s){const n=t.timeScale(),e=n.coordinateToTime(s);if(null!==e)return e;const r=n.coordinateToLogical(s);if(null===r)return null;const h=Gn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.Qg)}function Zn(t,i,s){if(null==s)return null;const n=t.timeScale(),e=n.timeToCoordinate(s);if(null!==e)return e;if("number"!=typeof s)return null;const r=Gn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.Qg,l=n.logicalToCoordinate(h);return null===l?null:l}class Jn extends vn{constructor(t,i){super(t,i,!0)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Yo(this.og,s,m(this.ag))}tb(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.ib(i.Re,s,t,i)})}}function Qn(t,i,s,n,e,r,h){if(0===i.length||n.from>=i.length||n.to<=0)return;const{context:l,horizontalPixelRatio:o,verticalPixelRatio:a}=t,_=i[n.from];let u=r(t,_),c=_;if(n.to-n.from<2){const i=e/2;l.beginPath();const s={ut:_.ut-i,ct:_.ct},n={ut:_.ut+i,ct:_.ct};l.moveTo(s.ut*o,s.ct*a),l.lineTo(n.ut*o,n.ct*a),h(t,u,s,n)}else{const e=(i,s)=>{h(t,u,c,s),l.beginPath(),u=i,c=s};let d=c;l.beginPath(),l.moveTo(_.ut*o,_.ct*a);for(let h=n.from+1;h<n.to;++h){d=i[h];const n=r(t,d);switch(s){case 0:l.lineTo(d.ut*o,d.ct*a);break;case 1:l.lineTo(d.ut*o,i[h-1].ct*a),n!==u&&(e(n,d),l.lineTo(d.ut*o,i[h-1].ct*a)),l.lineTo(d.ut*o,d.ct*a);break;case 2:{const[t,s]=ne(i,h-1,h);l.bezierCurveTo(t.ut*o,t.ct*a,s.ut*o,s.ct*a,d.ut*o,d.ct*a);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*o,d.ct*a))}(c!==d||c===d&&1===s)&&h(t,u,c,d)}}const te=6;function ie(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function se(t,i){return{ut:t.ut/i,ct:t.ct/i}}function ne(t,i,s){const n=Math.max(0,i-1),e=Math.min(t.length-1,s+1);var r,h;return[(r=t[i],h=se(ie(t[s],t[n]),te),{ut:r.ut+h.ut,ct:r.ct+h.ct}),ie(t[s],se(ie(t[e],t[i]),te))]}function ee(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class re extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,nb:r,dt:h,Kt:l,eb:o}=this.ht;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=h*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.rb.bind(this);void 0!==r&&Qn(t,i,r,s,e,_,ee),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let o=null;const a=Math.max(1,Math.floor(r))%2/2,_=s*h+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(null!==o&&l.fill(),l.beginPath(),l.fillStyle=i,o=i);const s=Math.round(n.ut*r)+a,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class he extends re{rb(t,i){return i.wt}}class le extends Jn{constructor(){super(...arguments),this.cg=new he}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W(),i={_t:this.og,Kt:t.lineStyle,nb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.ag,sb:this.te.Lt().bu()};this.cg.lt(i)}}const oe={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new le(t,i)};function ae(t,i){return t.weight>i.weight?t:i}function _e(t){return t}class ue{constructor(){this.hb=new a,this.lb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.hb.p(this.ob)),this.ob=0}ab(){return this.hb}m(){this.hb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.lb(),t=>(t>this.ob&&(this.ob=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this._b(t)}formatTickmark(t){return this._b(t.time)}maxTickMarkWeight(t){return t.reduce(ae,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t%120==0?10:t%60==0?9:t%36==0?8:t%12==0?7:t%6==0?6:t%3==0?5:t%1==0?4:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(_e(t[n].time));this.ob=t[t.length-1].time,this.lb()}_b(t){if(this.Ps.localization?.timeFormatter)return this.Ps.localization.timeFormatter(t);if(t<12)return`${t}M`;const i=Math.floor(t/12),s=t%12;return 0===s?`${i}Y`:`${i}Y${s}M`}}const ce={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},de={lastValueVisible:!1,priceLineVisible:!1};class pe extends Un{constructor(t,i){const s=_(ce,i||{}),n=new ue;super(t,n,s),n.setOptions(this.options()),this._initWhitespaceSeries()}addSeries(t,i={},s=0){if(t.isBuiltIn&&!1===["Area","Line"].includes(t.type))throw new Error("Yield curve only support Area and Line series");const n={...de,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(oe);let s;function n(n){const e=function(t,i){return{ae:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),ub:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ub:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ub:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ab().i(n)}}function fe(t,i){const s=qn(t);return new pe(s,i)}function ve(t,i){return t.weight>i.weight?t:i}class me{options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return t=>t}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return t.toFixed(this.Cn())}formatTickmark(t,i){return t.time.toFixed(this.Cn())}maxTickMarkWeight(t){return t.reduce(ve,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t===100*Math.ceil(t/100)?8:t===50*Math.ceil(t/50)?7:t===25*Math.ceil(t/25)?6:t===10*Math.ceil(t/10)?5:t===5*Math.ceil(t/5)?4:t===Math.ceil(t)?3:2*t===Math.ceil(2*t)?1:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(t[n].time)}Cn(){return this.Ps.localization.precision}}function we(t,i){return jn(t,new me,i)}function ge(t,i,s,n,e){const{context:r,horizontalPixelRatio:h,verticalPixelRatio:l}=i;r.lineTo(e.ut*h,t*l),r.lineTo(n.ut*h,t*l),r.closePath(),r.fillStyle=s,r.fill()}class be extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,dt:r,Kt:h,nb:l}=this.ht,o=this.ht.cb??(this.ht.pb?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,n(a,h),a.lineWidth=1,Qn(t,i,l,s,e,this.fb.bind(this),ge.bind(null,o))}}class Me{mb(t,i){const s=this.wb,{gb:n,bb:e,Mb:r,yb:h,cb:l,Sb:o,xb:a}=i;if(void 0===this.Cb||void 0===s||s.gb!==n||s.bb!==e||s.Mb!==r||s.yb!==h||s.cb!==l||s.Sb!==o||s.xb!==a){const{verticalPixelRatio:s}=t,_=l||o>0?s:1,u=o*_,c=a===t.bitmapSize.height?a:a*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Cb=p,this.wb=i}return this.Cb}}class ye extends be{constructor(){super(...arguments),this.Pb=new Me}fb(t,i){const s=this.ht;return this.Pb.mb(t,{gb:i.yr,bb:i.Sr,Mb:i.Cr,yb:i.Pr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class Se extends re{constructor(){super(...arguments),this.Tb=new Me}rb(t,i){const s=this.ht;return this.Tb.mb(t,{gb:i.br,bb:i.br,Mb:i.Mr,yb:i.Mr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class xe extends Jn{constructor(t,i){super(t,i),this.cg=new x,this.kb=new ye,this.Db=new Se,this.cg.nt([this.kb,this.Db])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.Ot();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.Lt().bu();if(null===this.ag||0===this.og.length)return;let e,r;if(i.relativeGradient){e=this.og[this.ag.from].ct,r=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const i=this.og[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.kb.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineType,cb:s,Sb:e,xb:r,pb:!1,ot:this.ag,sb:n}),this.Db.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineVisible?i.lineType:void 0,eb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,cb:s,Sb:e,xb:r,ot:this.ag,sb:n})}}const Ce={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new xe(t,i)};class Pe extends be{constructor(){super(...arguments),this.Pb=new Me}fb(t,i){return this.Pb.mb(t,{gb:i.wr,bb:"",Mb:"",yb:i.gr,Sb:this.ht?.Sb??0,xb:t.bitmapSize.height})}}class Te extends Jn{constructor(t,i){super(t,i),this.cg=new x,this.Rb=new Pe,this.Fb=new he,this.cg.nt([this.Rb,this.Fb])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W();if(null===this.ag||0===this.og.length)return;let i;if(t.relativeGradient){i=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const s=this.og[t];s.ct<i&&(i=s.ct)}}this.Rb.lt({nb:t.lineType,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,cb:null,Sb:i,pb:t.invertFilledArea,ot:this.ag,sb:this.te.Lt().bu()}),this.Fb.lt({nb:t.lineVisible?t.lineType:void 0,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,ot:this.ag,sb:this.te.Lt().bu(),eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const ke={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new Te(t,i)};class De extends C{constructor(){super(...arguments),this.Yt=null,this.Vb=0,this.Ib=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Vb=this.Ab(i),this.Vb>=2){Math.max(1,Math.floor(i))%2!=this.Vb%2&&this.Vb--}this.Ib=this.Yt.Lb?Math.min(this.Vb,Math.floor(i)):this.Vb;let n=null;const e=this.Ib<=this.Vb&&this.Yt.bu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ib),o=Math.round(h.ut*i),a=o-l,_=this.Ib,u=a+_-1,c=Math.min(h.Zo,h.Jo),d=Math.max(h.Zo,h.Jo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Ib);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Vb);if(e){if(this.Yt.Bb){const i=o-m;let n=Math.max(p,Math.round(h.Ko*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Qo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Ab(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).bu,t)))}}class Re extends vn{constructor(t,i){super(t,i,!1)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Go(this.og,s,m(this.ag))}Ob(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Ko:NaN,Zo:NaN,Jo:NaN,Qo:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>this.ib(i.Re,i,t))}}class Fe extends Re{constructor(){super(...arguments),this.cg=new De}ib(t,i,s){return{...this.Ob(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.Lt().bu(),Bb:t.openVisible,Lb:t.thinBars,ot:this.ag})}}const Ve={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},Yg:(t,i)=>new Fe(t,i)};class Ie extends C{constructor(){super(...arguments),this.Yt=null,this.Vb=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Vb=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.bu,i),this.Vb>=2){Math.floor(i)%2!=this.Vb%2&&this.Vb--}const s=this.Yt.Ks;this.Yt.Eb&&this.Wb(t,s,this.Yt.ot),this.Yt.Mi&&this.pv(t,s,this.Yt.ot);const n=this.zb(i);(!this.Yt.Mi||this.Vb>2*n)&&this.$b(t,s,this.Yt.ot)}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.bu*e));l=Math.max(Math.floor(e),Math.min(l,this.Vb));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Ko,s.Qo)*r),u=Math.round(Math.max(s.Ko,s.Qo)*r),c=Math.round(s.Zo*r),d=Math.round(s.Jo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}zb(t){let i=Math.floor(1*t);this.Vb<=2*i&&(i=Math.floor(.5*(this.Vb-1)));const s=Math.max(Math.floor(t),i);return this.Vb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}pv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.pr!==h&&(n.fillStyle=s.pr,h=s.pr);let a=Math.round(s.ut*e)-Math.floor(.5*this.Vb);const _=a+this.Vb-1,u=Math.round(Math.min(s.Ko,s.Qo)*r),c=Math.round(Math.max(s.Ko,s.Qo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.bu*e>2*l)V(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}$b(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Ko,s.Qo)*r),a=Math.round(Math.max(s.Ko,s.Qo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Vb),u=_+this.Vb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class Ae extends Re{constructor(){super(...arguments),this.cg=new Ie}ib(t,i,s){return{...this.Ob(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.Lt().bu(),Eb:t.wickVisible,Mi:t.borderVisible,ot:this.ag})}}const Le={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},Yg:(t,i)=>new Ae(t,i)};class Be extends C{constructor(){super(...arguments),this.Yt=null,this.Hb=[]}lt(t){this.Yt=t,this.Hb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.Hb.length||this.Nb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Ub*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.Hb[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.qh,a,l.yi-l.qh+1,_-a)}}Nb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.Hb=[]);const i=Math.ceil(this.Yt.bu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.bu*t)-i;this.Hb=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.Hb[i-this.Yt.ot.from]={qh:r,yi:h,qb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.Hb[t-this.Yt.ot.from],n=this.Hb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.qb>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.bu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.qb>i.ee?i.yi-=1:i.qh+=1)}}}class Oe extends Jn{constructor(){super(...arguments),this.cg=new Be}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t={_t:this.og,bu:this.te.Lt().bu(),ot:this.ag,Ub:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Ot()).Ht)};this.cg.lt(t)}}const Ee={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},Yg:(t,i)=>new Oe(t,i)};class We{constructor(t,i){this.Pt=t,this.jb=i,this.Yb()}detach(){this.Pt.detachPrimitive(this.jb)}getPane(){return this.Pt}applyOptions(t){this.jb.lr?.(t)}Yb(){this.Pt.attachPrimitive(this.jb)}}const ze={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},$e={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class He{constructor(t){this.Xb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Gb(i,t.text);e>s.width?t.Tu=s.width/e:t.Tu=1,n+=t.lineHeight*t.Tu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Tu,t.Tu),i.fillText(t.text,0,t.Kb),i.restore(),e+=t.lineHeight*t.Tu}})}Gb(t,i){const s=this.Zb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Zb(t){let i=this.Xb.get(t);return void 0===i&&(i=new Map,this.Xb.set(t,i)),i}}class Ne{constructor(t){this.Ps=qe(t)}Tt(t){this.Ps=qe(t)}renderer(){return new He(this.Ps)}}function Ue(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Kb:0,Tu:0}}function qe(t){return{...t,lines:t.lines.map(Ue)}}function je(t){return{...$e,...t}}function Ye(t){return{...ze,...t,lines:t.lines?.map(je)??[]}}class Xe{constructor(t){this.Ps=Ye(t),this.Jb=[new Ne(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Jb}attached({requestUpdate:t}){this.Qb=t}detached(){this.Qb=void 0}lr(t){this.Ps=Ye({...this.Ps,...t}),this.Qb&&this.Qb()}}function Ge(t,i){return new We(t,new Xe(i))}const Ke={alpha:1,padding:0};class Ze{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.tM(this.Yt,t.mediaSize);s&&this.Yt.iM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.iM,s.ut,s.ct,s.ts,s.qt))})}tM(t,i){const{maxHeight:s,maxWidth:n,sM:e,nM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class Je{constructor(t){this.eM=null,this.rM=0,this.hM=0,this.Ps=t,this.M=Qe(this.Ps,this.eM,this.rM,this.hM)}lM(t){void 0!==t.oM&&(this.rM=t.oM),void 0!==t.aM&&(this.hM=t.aM),void 0!==t._M&&(this.eM=t._M),this.Tt()}uM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Qe(this.Ps,this.eM,this.rM,this.hM)}renderer(){return new Ze(this.M)}}function Qe(t,i,s,n){return{...t,iM:i,nM:s,sM:n}}function tr(t){return{...Ke,...t}}class ir{constructor(t,i){this.cM=null,this.dM=t,this.Ps=tr(i),this.Jb=[new Je(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt())}paneViews(){return this.Jb}attached(t){const{requestUpdate:i}=t;this.pM=i,this.cM=new Image,this.cM.onload=()=>{const t=this.cM?.naturalHeight??1,i=this.cM?.naturalWidth??1;this.Jb.forEach(s=>s.lM({aM:t,oM:i,_M:this.cM})),this.pM&&this.pM()},this.cM.src=this.dM}detached(){this.pM=void 0,this.cM=null}lr(t){this.Ps=tr({...this.Ps,...t}),this.fM(),this.Qb&&this.Qb()}Qb(){this.pM&&this.pM()}fM(){this.Jb.forEach(t=>t.uM(this.Ps))}}function sr(t,i,s){return new We(t,new ir(i,s))}class nr{constructor(t,i){this.Qn=t,this._h=i,this.Yb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}Yb(){this.Qn.attachPrimitive(this._h)}}const er={autoScale:!0,zOrder:"normal"};function rr(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function hr(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return rr(i,1);case"circle":return rr(i,.8);case"square":case"xcross":return rr(i,.7)}}function lr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(rr(t,1))}function or(t){return Math.max(rr(t,.1),3)}function ar(t){return Math.max(or(t),10)}function _r(t,i,s){return i?t:s?Math.ceil(t/2):0}function ur(t,i,s,n){const e=(hr("arrowUp",n)-1)/2*s.vM,r=(Kt(n/2)-1)/2*s.vM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function cr(t,i,s,n,e,r){const h=(hr("arrowUp",n)-1)/2,l=(Kt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&r>=(t?s:s-h)-2&&r<=(t?s+h:s)+2)return!0;return(()=>{if(e<i-h-3||e>i+h+3||r<(t?s-h-3:s)||r>(t?s:s+h+3))return!1;const n=Math.abs(e-i);return Math.abs(r-s)+3>=n/2})()}function dr(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,o=s+l*n,a=o-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),a),t.quadraticCurveTo(i,o,i+(r?h:-h),a),t.lineTo(i-_,s)}function pr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class fr{constructor(){this.Yt=null,this.Wn=new it,this.mM=new it,this.$=-1,this.H="",this.Uf="",this.wM="",this.gM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Uf=g(t,i),this.wM=g(t,i,"600"),this.Wn.In(),this.mM.In()),this.gM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&mr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.bM;if(t.font=r?this.wM:this.Uf,void 0!==e.hi){const i=r?this.mM:this.Wn;e.hi.ts=i.Vi(t,e.hi.MM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.bM){const t=void 0!==e.hi?e.hi.ts:0;e.bM.ts=Math.max(t+2*e.bM.yM,e.bM.qt),e.bM.qh=e.ut-e.bM.ts/2}vr(e,t,i,s)}}}}function vr(t,i,s,n){void 0===t.bM?(i.fillStyle=t.R,void 0!==t.hi&&pr(i,t.hi.MM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Er)return;switch(t.SM){case"arrowDown":return void ur(!1,i,s,t.Er);case"arrowUp":return void ur(!0,i,s,t.Er);case"circle":return void function(t,i,s){const n=(hr("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.vM,0,2*Math.PI,!1),t.fill()}(i,s,t.Er);case"square":return void function(t,i,s){const n=hr("square",s),e=(n-1)*i.vM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.vM,n*i.vM)}(i,s,t.Er);case"xcross":return void function(t,i,s){const n=(hr("xcross",s)-1)/2*i.vM;t.save(),t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1,Math.round(1.5*i.vM)),t.lineCap="round",t.beginPath(),t.moveTo(i.ut-n,i.ct-n),t.lineTo(i.ut+n,i.ct+n),t.moveTo(i.ut+n,i.ct-n),t.lineTo(i.ut-n,i.ct+n),t.stroke(),t.restore()}(i,s,t.Er);case"tag":return}t.SM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,vM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Er)return;(function(t,i){const s=i.xM,n=i.CM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.PM-i.qt/2)*n),l=Math.round((i.PM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.TM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.kM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.kM&&dr(t,o,h,_,u,!0),t.lineTo(r-a,h),t.arcTo(r,h,r,h+a,a),t.lineTo(r,l-a),t.arcTo(r,l,r-a,l,a),"down"===i.kM&&dr(t,o,l,_,u,!1),t.lineTo(e+a,l),t.arcTo(e,l,e,l-a,a),t.lineTo(e,h+a),t.arcTo(e,h,e+a,h,a)):A(t,e,h,r-e,l-h,[a,a,a,a]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,PM:t.ct,ts:i.ts,qt:i.qt,TM:i.TM,kM:i.kM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,xM:n,CM:e}),void 0!==t.hi&&(s.fillStyle=t.DM??"#FFFFFF",pr(s,t.hi.MM,t.hi.ut,t.hi.ct,n,e))}(t,t.bM,i,s,n)}function mr(t,i,s){return void 0!==t.bM?0!==t.Er&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.kM?i-r-s.TM:i-r,l="down"===s.kM?i+r+s.TM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.bM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Er)return!1;switch(t.SM){case"arrowDown":return cr(!0,t.ut,t.ct,t.Er,i,s);case"arrowUp":return cr(!1,t.ut,t.ct,t.Er,i,s);case"circle":return function(t,i,s,n,e){const r=2+hr("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Er,i,s);case"square":return function(t,i,s,n,e){const r=hr("square",s),h=(r-1)/2,l=t-h,o=i-h;return n>=l&&n<=l+r&&e>=o&&e<=o+r}(t.ut,t.ct,t.Er,i,s);case"xcross":return function(t,i,s,n,e){const r=2+hr("xcross",s)/2;return Math.abs(n-t)<=r&&Math.abs(e-i)<=r}(t.ut,t.ct,t.Er,i,s);case"tag":return!1}}(t,i,s)}function wr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function gr(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(wr(i.position)&&void 0!==i.price)return i.price;if("value"in(n=t)&&"number"==typeof n.value)return t.value;var n;if(function(t){return"open"in t&&"high"in t&&"low"in t&&"close"in t}(t)){if("inBar"===i.position)return t.close;if("aboveBar"===i.position)return s?t.low:t.high;if("belowBar"===i.position)return s?t.high:t.low}}(s,i,a);if(void 0===_)return;const c=wr(i.position),d=o.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),o=Math.round(7*h),a=wr(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.RM)-o-_,a||(n.RM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.FM)+o+_,a||(n.FM+=l+o+r)}const d={qt:l,TM:o,kM:u,vt:i.borderRadius??6,yM:9*h,qh:0,ts:0};t.Er=l,t.ct=c,t.bM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=lr(d.options().barSpacing)*p,v=f/2;t.Er=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.FM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.FM+=1.2*e),void(c||(n.FM+=f+r))}}}class br{constructor(t,i,s){this.VM=[],this.xt=!0,this.IM=!0,this.Jt=new fr,this.be=t,this.Af=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.AM();const t=this.Af.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}LM(t){this.VM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.IM=!0)}BM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}AM(){const t=this.Af.timeScale(),i=this.VM;this.IM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Er:0,SM:t.shape,R:t.color,Gn:t.id,OM:t.OM,hi:void 0,DM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,bM:void 0})),this.IM=!1);const s=this.Af.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=or(t.options().barSpacing),a=ar(t.options().barSpacing),_={RM:a,FM:a};this.Yt.ot=fn(this.Yt._t,e,!0);for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=i[n];e.time!==h&&(_.RM=a,_.FM=a,h=e.time);const u=this.Yt._t[n];u.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(u.hi={MM:e.text,ut:0,ct:0,ts:0,qt:0});const c=this.be.dataByIndex(e.time,0);null!==c&&gr(u,e,c,_,s.fontSize,o,this.be,this.Af,r)}this.xt=!1}}function Mr(t){return{...er,...t}}class yr{constructor(t){this.eh=null,this.VM=[],this.EM=[],this.WM=null,this.be=null,this.Af=null,this.zM=!0,this.$M=null,this.HM=null,this.NM=null,this.UM=!0,this.Ps=Mr(t)}attached(t){this.qM(),this.Af=t.chart,this.be=t.series,this.eh=new br(this.be,l(this.Af),this.Ps),this.pM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Fg(t)),this.UM=!0,this.Qb()}Qb(){this.pM&&this.pM()}detached(){this.be&&this.WM&&this.be.unsubscribeDataChanged(this.WM),this.Af=null,this.be=null,this.eh=null,this.WM=null}LM(t){this.UM=!0,this.VM=t,this.qM(),this.zM=!0,this.HM=null,this.Qb()}jM(){return this.VM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.YM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.XM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=Mr({...this.Ps,...t}),this.Qb&&this.Qb()}XM(){const t=l(this.Af).timeScale().options().barSpacing;if(this.zM||t!==this.NM){if(this.NM=t,this.VM.length>0){const i=or(t),s=1.5*lr(t)+i+ar(t),n=this.GM();this.$M={above:_r(s,n.aboveBar,n.inBar),below:_r(s,n.belowBar,n.inBar)}}else this.$M=null;this.zM=!1}return this.$M}GM(){return null===this.HM&&(this.HM=this.VM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.HM}qM(){if(!this.UM||!this.Af||!this.be)return;const t=this.Af.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.EM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.EM=this.VM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),o={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,OM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Dw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.UM=!1}YM(t){this.eh&&(this.qM(),this.eh.LM(this.EM),this.eh.BM(this.Ps),this.eh.Tt(t))}Fg(t){this.UM=!0,this.Qb()}}class Sr extends nr{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.LM(t)}markers(){return this._h.jM()}}function xr(t,i,s){const n=new Sr(t,new yr(s??{}));return i&&n.setMarkers(i),n}class Cr{constructor(t){this.VM=new Map,this.KM=t}ZM(t,i,s){if(this.JM(i),void 0!==s){const n=window.setTimeout(()=>{this.VM.delete(i),this.QM()},s),e={...t,ty:n,iy:Date.now()+s};this.VM.set(i,e)}else this.VM.set(i,{...t,ty:void 0,iy:void 0});this.QM()}JM(t){const i=this.VM.get(t);i&&void 0!==i.ty&&window.clearTimeout(i.ty),this.VM.delete(t),this.QM()}sy(){for(const[t]of this.VM)this.JM(t)}ny(){const t=Date.now(),i=[];for(const[s,n]of this.VM)!n.iy||n.iy>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.JM(s);return i}ey(t){this.KM=t}QM(){this.KM&&this.KM()}}const Pr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Tr{constructor(t,i,s,n){this.Yt=t,this.hy=i,this.ly=s,this.oy=n}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=Math.max(1,Math.floor(t.horizontalPixelRatio))%2/2,n=4*t.verticalPixelRatio+s;this.Yt.forEach(e=>{const r=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const h=this._y(e.uy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.uy&&(i.strokeStyle=h,i.lineWidth=Math.floor(2*t.horizontalPixelRatio),i.beginPath(),i.moveTo((e.ut-4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.uy-7*e.uy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.stroke())})})}_y(t){return 0===t?this.hy:t>0?this.oy:this.ly}}class kr{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,uy:t.sign}}).filter(v)}renderer(){const t=function(t,i){return function(t,i){return"Area"===i}(0,i)?t.lineColor:t.color}(this.be.options(),this.be.seriesType());return new Tr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Dr(t,i){return"Line"===i||"Area"===i}class Rr{constructor(t){this.Af=void 0,this.be=void 0,this.Jb=[],this.u_=null,this.py=new Map,this.vy=new Cr(()=>this.Qb()),this.Ps={...Pr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Qb()}LM(t){this.vy.sy();const i=this.u_;i&&t.forEach(t=>{this.vy.ZM(t,i.key(t.time))})}jM(){return this.vy.ny()}Qb(){this.pM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Af=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Jb=[new kr(this.be,this.Af.timeScale(),this.Ps)],this.pM=n,this.Qb()}detached(){this.Af=void 0,this.be=void 0,this.pM=void 0}Xf(){return h(this.Af)}za(){return h(this.be)}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.jM()))}paneViews(){return this.Jb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.py.clear();const s=this.u_;s&&t.forEach(t=>{Ks(t)&&Dr(0,i)&&this.py.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Gs(t)&&this.py.delete(n),Ks(t)&&Dr(0,s)){const i=this.py.get(n);i&&this.vy.ZM({time:t.time,value:t.value,sign:Fr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}my(){this.vy.sy()}}function Fr(t,i){return t===i?0:t-i>0?1:-1}class Vr extends nr{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.jM()}setMarkers(t){return this._h.LM(t)}clearMarkers(){return this._h.my()}}function Ir(t,i={}){return new Vr(t,new Rr(i))}const Ar={position:"bottom",offset:4,fontSize:11,fontFamily:"",color:"#787B86"};class Lr{constructor(t){this.Yt=t}draw(t){const{_t:i,mf:s,wy:n}=this.Yt;0!==i.length&&t.useMediaCoordinateSpace(({context:t,mediaSize:e})=>{const r="top"===s?n:e.height-n;t.save(),t.textAlign="center",t.textBaseline="top"===s?"top":"bottom";for(const s of i)s.ut<-100||s.ut>e.width+100||(t.font=s.T,t.fillStyle=s.R,t.fillText(s.hi,s.ut,r));t.restore()})}}class Br{constructor(){this.Yt={_t:[],mf:"bottom",wy:0}}Tt(t){this.Yt=t}zOrder(){return"top"}renderer(){return new Lr(this.Yt)}}class Or{constructor(t){this.Af=null,this.pM=null,this.j_=[],this.eh=new Br,this.Ps={...Ar,...t}}attached(t){this.Af=t.chart,this.pM=t.requestUpdate,this.pM()}detached(){this.Af=null,this.pM=null}gy(t){this.j_=t.slice(),this.pM?.()}by(){return this.j_}lr(t){this.Ps={...this.Ps,...t},this.pM?.()}updateAllViews(){const t=this.Af,i=this.Ps;if(null===t)return void this.eh.Tt({_t:[],mf:i.position,wy:i.offset});const s=t.timeScale(),n=i.fontFamily||t.options().layout.fontFamily,e=[];for(const t of this.j_){const r=s.timeToCoordinate(t.time);null!==r&&e.push({ut:r,hi:t.text,R:t.color??i.color,T:g(t.size??i.fontSize,n)})}this.eh.Tt({_t:e,mf:i.position,wy:i.offset})}paneViews(){return[this.eh]}}class Er extends nr{setLabels(t){this._h.gy(t)}labels(){return this._h.by()}}function Wr(t,i,s){const n=new Er(t,new Or(s));return i&&n.setLabels(i),n}class zr{constructor(t,i){this.My=null,this.yy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.My=xr(t)}addPosition(t){this.yy.push(t),this.Sy()}addPositions(t){this.yy.push(...t),this.Sy()}setPositions(t){this.yy=[...t],this.Sy()}closePosition(t,i,s){const n=this.yy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.Sy())}removePosition(t){this.yy=this.yy.filter(i=>i.id!==t),this.Sy()}clearPositions(){this.yy=[],this.Sy()}getPositions(){return this.yy}applyOptions(t){t.longColors&&(this.Ps.longColors={...this.Ps.longColors,...t.longColors}),t.shortColors&&(this.Ps.shortColors={...this.Ps.shortColors,...t.shortColors}),void 0!==t.defaultSize&&(this.Ps.defaultSize=t.defaultSize),void 0!==t.entryOffset&&(this.Ps.entryOffset=t.entryOffset),void 0!==t.exitOffset&&(this.Ps.exitOffset=t.exitOffset),this.Sy()}xy(){const t=[];for(const i of this.yy){const s="long"===i.type,n=i.size??this.Ps.defaultSize,e=i.color?.entry??(s?this.Ps.longColors.entry:this.Ps.shortColors.entry),r=i.color?.exit??(s?this.Ps.longColors.exit:this.Ps.shortColors.exit),h={time:i.entry.time,position:"atPriceMiddle",price:i.entry.price+this.Ps.entryOffset,shape:s?"arrowUp":"arrowDown",color:e,size:n};if(i.text?.entry&&(h.text=i.text.entry),i.id&&(h.id=`${i.id}-entry`),t.push(h),i.exit){const e={time:i.exit.time,position:"atPriceMiddle",price:i.exit.price+this.Ps.exitOffset,shape:s?"arrowDown":"arrowUp",color:r,size:n};i.text?.exit&&(e.text=i.text.exit),i.id&&(e.id=`${i.id}-exit`),t.push(e)}}return t}Sy(){if(this.My){const t=this.xy();this.My.setMarkers(t)}}detach(){this.My&&(this.My.detach(),this.My=null),this.yy=[]}}function $r(t,i,s){const n=new zr(t,s);return i&&i.length>0&&n.setPositions(i),n}const Hr=new WeakMap;function Nr(t){return"string"==typeof t?t:String(t)}function Ur(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Nr(t.time),t.volume);Hr.set(t,s)}function qr(t,i){return Hr.get(t)?.get(Nr(i))}function jr(t){const i=Hr.get(t);return void 0!==i&&i.size>0}const Yr="rgba(0, 0, 0, 0)";function Xr(t){switch(t.seriesType()){case"Candlestick":return Gr(t,{upColor:Yr,downColor:Yr,borderVisible:!1,wickVisible:!1});case"Bar":return Gr(t,{upColor:Yr,downColor:Yr});case"Line":return Gr(t,{color:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Gr(t,{lineColor:Yr,topColor:Yr,bottomColor:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Gr(t,{topLineColor:Yr,topFillColor1:Yr,topFillColor2:Yr,bottomLineColor:Yr,bottomFillColor1:Yr,bottomFillColor2:Yr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Gr(t,{color:Yr});default:return Gr(t,{visible:!1})}}function Gr(t,i){const s={...i,lastValueVisible:!1,priceLineVisible:!1},n=t.options(),e={};for(const t of Object.keys(s))e[t]=n[t];return t.applyOptions(s),()=>{t.applyOptions(e)}}function Kr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Zr(t,i,s){const n=t.panes();for(const t of n)if(-1!==t.getSeries().indexOf(i))return t.paneIndex();return Math.min(s,Math.max(n.length-1,0))}function Jr(t,i="close"){const s=[];for(const n of t)if(null!=n)if("close"in n)switch(i){case"open":s.push(n.open);break;case"high":s.push(n.high);break;case"low":s.push(n.low);break;case"hl2":s.push((n.high+n.low)/2);break;case"hlc3":s.push((n.high+n.low+n.close)/3);break;case"ohlc4":s.push((n.open+n.high+n.low+n.close)/4);break;default:s.push(n.close)}else s.push("value"in n?n.value:0);else s.push(0);return s}function Qr(t,i){let s=[];return n=>{for(const i of s)try{t.removePriceLine(i)}catch(t){}s=n.filter(t=>null!=t).map(s=>{const n={price:s,color:i,lineWidth:1,lineStyle:2,axisLabelVisible:!1,title:""};return t.createPriceLine(n)})}}function th(t){return null==t?void 0:t.time}function ih(t){const{r_:i,Xf:s,Cy:n,Py:e,Ty:r,Jl:h}=t,l=t.ky??[];let o=t.W,a=[],_=new Map,u=!1;const c=(t,i)=>{if(0===i.length)return;const s=_.get(t),n=i[i.length-1];if(void 0!==s&&s.length>0){const e=i.length===s.length+1,r=i.length===s.length,h=th(s[s.length-1])===th(n);if(e||r&&h)return t.update(n),void _.set(t,i)}t.setData(i),_.set(t,i)},d=t=>{if(!u)try{if("full"===t||0===a.length)a=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;a.length>0&&th(a[a.length-1])===th(t)?a[a.length-1]=t:a.push(t)}if(0===a.length)return;const s=e(a,o);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&a.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==r&&r(o),l.some(t=>i[t]!==o[t])&&(_=new Map,d("full"))},options:()=>({...o}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,a=[]}},recalculate:()=>d("full")};return f}function sh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[];for(let s=i-1;s<n.length;s++){let r=0;for(let t=0;t<i;t++)r+=n[s-t];const h=r/i;t[s]&&t[s].time&&e.push({time:t[s].time,value:h})}return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"SMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function nh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??12,color:s.color??"#FF9800",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[],r=2/(i+1);let h=0;for(let t=0;t<i;t++)h+=n[t];h/=i,t[i-1]&&t[i-1].time&&e.push({time:t[i-1].time,value:h});for(let s=i;s<n.length;s++)h=(n[s]-h)*r+h,t[s]&&t[s].time&&e.push({time:t[s].time,value:h});return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"EMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function eh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,color:s.color??"#4CAF50",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),r=(t,i,s)=>{if(!t||t.length<i)return[];const n=Jr(t,s),e=[],r=i*(i+1)/2;for(let s=i-1;s<n.length;s++){let h=0;for(let t=0;t<i;t++){const e=t+1;h+=n[s-i+1+t]*e}const l=h/r;t[s]&&t[s].time&&e.push({time:t[s].time,value:l})}return e},h=ih({r_:t,Xf:i,Cy:[e],Jl:"WMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function rh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,stdDev:s.stdDev??2,colorUpper:s.colorUpper??"#3F51B5",colorMiddle:s.colorMiddle??"#2196F3",colorLower:s.colorLower??"#3F51B5",lineWidth:s.lineWidth??1},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Bollinger Bands",W:n,ky:["period","stdDev"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Dy:[],Ry:[],Fy:[]};const n=[];for(const i of t)"close"in i?n.push(i.close):"value"in i?n.push(i.value):n.push(0);const e=[],r=[],h=[];for(let l=i-1;l<n.length;l++){let o=0;for(let t=0;t<i;t++)o+=n[l-t];const a=o/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-a,2);const u=Math.sqrt(_/i),c=a+u*s,d=a-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:a}),h.push({time:i,value:d})}}return{Dy:e,Ry:r,Fy:h}})(t,i.period??20,i.stdDev??2);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1;r.applyOptions({color:t.colorUpper,lineWidth:i}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:r,middle:h,lower:l,...o}}function hh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,atrPeriod:s.atrPeriod??10,multiplier:s.multiplier??2,source:s.source??"close",colorUpper:s.colorUpper??"#787B86",colorMiddle:s.colorMiddle??"#2962FF",colorLower:s.colorLower??"#787B86",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??0},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Keltner Channels",W:n,ky:["period","atrPeriod","multiplier","source"],Py:(t,i)=>{const s=((t,i)=>{const s=i.period??20,n=i.atrPeriod??10,e=i.multiplier??2;if(!t||t.length<Math.max(s,n+1))return{Dy:[],Ry:[],Fy:[]};const r=Jr(t,i.source??"close"),h=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=r[t];h.push(o/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const a=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?a.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):a.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=a[t];_[n-1]=u/n;for(let t=n;t<a.length;t++)_[t]=(_[t-1]*(n-1)+a[t])/n;const c=[],d=[],p=[];for(let i=0;i<h.length;i++){const n=s-1+i,r=t[n],l=_[n-1];if(!r||void 0===r.time||void 0===l)continue;const o=h[i],a=l*e;d.push({time:r.time,value:o}),c.push({time:r.time,value:o+a}),p.push({time:r.time,value:o-a})}return{Dy:c,Ry:d,Fy:p}})(t,i);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min((t.lineWidth??1)+1,4),lineStyle:s}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}}function lh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??20,colorUpper:s.colorUpper??"#089981",colorMiddle:s.colorMiddle??"#787B86",colorLower:s.colorLower??"#F23645",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??0,showMiddle:s.showMiddle??!0},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorUpper},e),h=i.addSeries(oe,{color:n.colorMiddle},e),l=i.addSeries(oe,{color:n.colorLower},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"Donchian Channels",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{Dy:[],Ry:[],Fy:[]};const s=[],n=[],e=[];for(let r=i-1;r<t.length;r++){let h=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[r-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>h&&(h=n),e<l&&(l=e)}const o=t[r];void 0!==o.time&&h!==-1/0&&l!==1/0&&(s.push({time:o.time,value:h}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(h+l)/2}))}return{Dy:s,Ry:n,Fy:e}})(t,i.period??20);return[[r,s.Dy],[h,s.Ry],[l,s.Fy]]},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}}function oh(t,i,s={}){const n={paneIndex:s.paneIndex??0,step:s.step??.02,maxStep:s.maxStep??.2,colorUp:s.colorUp??"#089981",colorDown:s.colorDown??"#F23645",dotSize:s.dotSize??2},e=i.addSeries(oe,{color:n.colorUp,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:n.dotSize},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<3)return[];const r=t[0],h=t[1];if(!("high"in r)||!("low"in r))return[];const l=[];let o=h.close>=r.close,a=o?r.low:r.high,_=o?h.high:h.low,u=i;for(let r=1;r<t.length;r++){const h=t[r],c=t[r-1];if("high"in h&&"low"in h&&(a+=u*(_-a),o?(a=Math.min(a,c.low,t[r-2]?t[r-2].low:c.low),h.low<a?(o=!1,a=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(a=Math.max(a,c.high,t[r-2]?t[r-2].high:c.high),h.high>a?(o=!0,a=_,_=h.high,u=i):h.low<_&&(_=h.low,u=Math.min(u+i,s))),void 0!==h.time)){const t={};t.time=h.time,t.value=a,t.color=o?n:e,l.push(t)}}return l},h=ih({r_:t,Xf:i,Cy:[e],Jl:"Parabolic SAR",W:n,ky:["step","maxStep","colorUp","colorDown"],Py:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}}function ah(t,i){let s;if("number"==typeof t)s=new Date(1e3*t);else if("string"==typeof t)s=new Date(`${t}T00:00:00Z`);else{if(null===t||"object"!=typeof t||!("year"in t))return null;{const i=t;s=new Date(Date.UTC(i.Vy,i.Iy-1,i.Ay))}}if(Number.isNaN(s.getTime()))return null;const n=s.getUTCFullYear();if("monthly"===i)return`${n}-${s.getUTCMonth()}`;if("weekly"===i){const t=new Date(s.getTime()),i=(t.getUTCDay()+6)%7;return t.setUTCDate(t.getUTCDate()-i),`${t.getUTCFullYear()}-${t.getUTCMonth()}-${t.getUTCDate()}`}return`${n}-${s.getUTCMonth()}-${s.getUTCDate()}`}function _h(t,i,s={}){const n={paneIndex:s.paneIndex??0,anchorPeriod:s.anchorPeriod??"daily",color:s.color??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,bandMultiplier:s.bandMultiplier??0,bandColor:s.bandColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color},e),h=i.addSeries(oe,{color:n.bandColor},e),l=i.addSeries(oe,{color:n.bandColor},e),o=ih({r_:t,Xf:i,Cy:[r,h,l],Jl:"VWAP",W:n,ky:["anchorPeriod","bandMultiplier"],Py:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!jr(t))return{Ly:e,Dy:r,Fy:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=ah(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,o=0,a=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=qr(t,u.time)??0;if(o+=d,a+=c*d,_+=c*c*d,0===o)continue;const p=a/o;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/o-p*p,0),i=Math.sqrt(t)*n;r.push({time:u.time,value:p+i}),h.push({time:u.time,value:p-i})}}return{Ly:e,Dy:r,Fy:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.Ly],[h,n.Dy],[l,n.Fy]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;r.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:r,upper:h,lower:l,...o}}function uh(t,i,s={}){const n={paneIndex:s.paneIndex??0,period:s.period??10,multiplier:s.multiplier??3,colorUp:s.colorUp??"#089981",colorDown:s.colorDown??"#F23645",lineWidth:s.lineWidth??2},e=i.addSeries(oe,{color:n.colorUp,lineWidth:n.lineWidth},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<i+1)return[];const r=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?r.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):r.push(0)}const h=[];let l=0;for(let t=0;t<i;t++)l+=r[t];h[i-1]=l/i;for(let t=i;t<r.length;t++)h[t]=(h[t-1]*(i-1)+r[t])/i;const o=[];let a=0,_=0,u=!0,c=!1;for(let r=i;r<t.length;r++){const i=t[r],l=t[r-1],d=h[r-1];if(!("high"in i)||!("low"in i)||void 0===d)continue;const p=(i.high+i.low)/2,f=p+s*d,v=p-s*d;if(c?(a=f<a||l.close>a?f:a,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>a&&(u=!0)):(a=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:a,m.color=u?n:e,o.push(m)}return o},h=ih({r_:t,Xf:i,Cy:[e],Jl:"SuperTrend",ky:["period","multiplier","colorUp","colorDown"],W:n,Py:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}}class ch{constructor(t,i,s,n){this.Af=t,this.be=i,this.I_=s,this.By=n}draw(t){const i=this.By();if(!i.Vt||i.Oy<=0)return;const s=this.I_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Af.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Ey),u=this.be.priceToCoordinate(h.Wy),c=this.be.priceToCoordinate(l.Ey),d=this.be.priceToCoordinate(l.Wy);if(null===_||null===u||null===c||null===d)continue;const p=h.Ey>=h.Wy;n.fillStyle=this.zy(p?i.$y:i.Hy,i.Oy),n.beginPath(),n.moveTo(o*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class dh{constructor(t,i,s,n){this.Jt=new ch(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function ph(t,i,s){if(i<s-1)return null;let n=-1/0,e=1/0;for(let r=0;r<s;r++){const s=t[i-r],h="high"in s?s.high:s.value,l="low"in s?s.low:s.value;h>n&&(n=h),l<e&&(e=l)}return n===-1/0?null:(n+e)/2}function fh(t,i,s={}){const n={paneIndex:s.paneIndex??0,conversionPeriod:s.conversionPeriod??9,basePeriod:s.basePeriod??26,spanBPeriod:s.spanBPeriod??52,displacement:s.displacement??26,colorConversion:s.colorConversion??"#2962FF",colorBase:s.colorBase??"#F23645",colorSpanA:s.colorSpanA??"#089981",colorSpanB:s.colorSpanB??"#F23645",colorLagging:s.colorLagging??"#787B86",cloudBullishColor:s.cloudBullishColor??"#089981",cloudBearishColor:s.cloudBearishColor??"#F23645",cloudOpacity:s.cloudOpacity??.15,showCloud:s.showCloud??!0,showLagging:s.showLagging??!0,lineWidth:s.lineWidth??1},e=n.paneIndex,r=t=>i.addSeries(oe,{color:t},e),h=r(n.colorConversion),l=r(n.colorBase),o=r(n.colorSpanA),a=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new dh(i,t,()=>u,()=>({$y:c.cloudBullishColor??"#089981",Hy:c.cloudBearishColor??"#F23645",Oy:c.cloudOpacity??.15,Vt:c.showCloud??!0})),p={attached:t=>{},detached:()=>{},paneViews:()=>[d],updateAllViews:()=>{}};t.attachPrimitive(p);const f=(t,i)=>{const s=i.conversionPeriod??9,n=i.basePeriod??26,e=i.spanBPeriod??52,r=i.displacement??26,h=[],l=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{Ny:h,rh:l,Ey:o,Wy:a,Uy:_,qy:u};const c=function(t){if(t.length<3)return null;const i=new Map;let s=null,n=0;for(let e=1;e<t.length;e++){const r=t[e-1].time,h=t[e].time;if("number"!=typeof r||"number"!=typeof h)return null;const l=h-r;if(l<=0)continue;const o=(i.get(l)??0)+1;i.set(l,o),o>n&&(n=o,s=l)}return s}(t),d=i=>{if(i<t.length)return t[i].time;if(null===c)return null;return t[t.length-1].time+c*(i-t.length+1)},p=new Map,f=new Map;for(let i=0;i<t.length;i++){const o=t[i];if(void 0===o.time)continue;const a=ph(t,i,s),u=ph(t,i,n);null!==a&&h.push({time:o.time,value:a}),null!==u&&l.push({time:o.time,value:u}),null!==a&&null!==u&&p.set(i+r,(a+u)/2);const c=ph(t,i,e);null!==c&&f.set(i+r,c);const d=i-r;if(d>=0&&void 0!==t[d].time){const i="close"in o?o.close:o.value;_.push({time:t[d].time,value:i})}}const v=t.length-1+r;for(let t=0;t<=v;t++){const i=d(t);if(null==i)continue;const s=p.get(t),n=f.get(t);if(void 0!==s&&o.push({time:i,value:s}),void 0!==n&&a.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Ey:s,Wy:n};u.push(t)}}return{Ny:h,rh:l,Ey:o,Wy:a,Uy:_,qy:u}},v=ih({r_:t,Xf:i,Cy:[h,l,o,a,_],Jl:"Ichimoku",W:n,ky:["conversionPeriod","basePeriod","spanBPeriod","displacement"],Py:(t,i)=>{c=i;const s=f(t,i);return u=s.qy,[[h,s.Ny],[l,s.rh],[o,s.Ey],[a,s.Wy],[_,i.showLagging??1?s.Uy:[]]]},Ty:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),o.applyOptions({color:t.colorSpanA,lineWidth:s}),a.applyOptions({color:t.colorSpanB,lineWidth:s}),_.applyOptions({color:t.colorLagging,lineWidth:s,visible:t.showLagging??!0}),i.timeScale().applyOptions({})}}),m=v.remove;return{conversion:h,base:l,spanA:o,spanB:a,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}}function vh(t,i,s={}){const n={paneIndex:s.paneIndex??0,pivotPeriod:s.pivotPeriod??"daily",levels:s.levels??3,colorPivot:s.colorPivot??"#FF6D00",colorResistance:s.colorResistance??"#F23645",colorSupport:s.colorSupport??"#089981",lineWidth:s.lineWidth??1,lineStyle:s.lineStyle??2},e=n.paneIndex,r=t=>i.addSeries(oe,{color:t},e),h=r(n.colorPivot),l=[r(n.colorResistance),r(n.colorResistance),r(n.colorResistance)],o=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],a=ih({r_:t,Xf:i,Cy:[h,...l,...o],Jl:"Pivot Points",W:n,ky:["pivotPeriod"],Py:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{jy:s,Yy:n,Xy:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=ah(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+o)/3,s=h-l;a={Gy:i,Ky:[2*i-l,i+s,h+2*(i-l)],Zy:[2*i-h,i-s,l-2*(h-i)]},r=t,h=-1/0,l=1/0}const u="high"in _?_.high:_.value,c="low"in _?_.low:_.value;if(u>h&&(h=u),c<l&&(l=c),o="close"in _?_.close:_.value,null!==a&&void 0!==_.time){s.push({time:_.time,value:a.Gy});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Ky[t]}),e[t].push({time:_.time,value:a.Zy[t]})}}return{jy:s,Yy:n,Xy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.jy]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Yy[t]:[]]),e.push([o[t],t<n?s.Xy[t]:[]]);return e},Ty:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));h.applyOptions({color:t.colorPivot,lineWidth:i,lineStyle:s});for(let e=0;e<3;e++)l[e].applyOptions({color:t.colorResistance,lineWidth:i,lineStyle:s,visible:e<n}),o[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:o,...a}}function mh(t){return null!=t&&"number"==typeof t.close}function wh(t){const i=[];let s=null,n=null;for(const e of t){if(!mh(e)){null!=e&&i.push({time:e.time,customValues:e.customValues});continue}const t=(e.open+e.high+e.low+e.close)/4,r=null===s||null===n?(e.open+e.close)/2:(s+n)/2;i.push({time:e.time,open:r,high:Math.max(e.high,r,t),low:Math.min(e.low,r,t),close:t,customValues:e.customValues}),s=r,n=t}return i}function gh(t,i,s={}){const n={paneIndex:s.paneIndex??0,upColor:s.upColor??"#26a69a",downColor:s.downColor??"#ef5350",borderVisible:s.borderVisible??!0,borderUpColor:s.borderUpColor??"#26a69a",borderDownColor:s.borderDownColor??"#ef5350",wickVisible:s.wickVisible??!0,wickUpColor:s.wickUpColor??"#26a69a",wickDownColor:s.wickDownColor??"#ef5350",hideSource:s.hideSource??!0},e=t.options(),r=i.addSeries(Le,{upColor:n.upColor,downColor:n.downColor,borderVisible:n.borderVisible,borderUpColor:n.borderUpColor,borderDownColor:n.borderDownColor,wickVisible:n.wickVisible,wickUpColor:n.wickUpColor,wickDownColor:n.wickDownColor,priceScaleId:e.priceScaleId,priceFormat:e.priceFormat,lastValueVisible:e.lastValueVisible,priceLineVisible:e.priceLineVisible},n.paneIndex);let h=null;const l=i=>{i&&null===h?(h=Xr(t),r.setSeriesOrder(t.seriesOrder())):i||null===h||(h(),h=null,r.setSeriesOrder(t.seriesOrder()+1))},o=ih({r_:t,Xf:i,Cy:[r],Jl:"Heikin Ashi",W:n,ky:[],Py:t=>[[r,wh(t)]],Ty:t=>{r.applyOptions({upColor:t.upColor,downColor:t.downColor,borderVisible:t.borderVisible,borderUpColor:t.borderUpColor,borderDownColor:t.borderDownColor,wickVisible:t.wickVisible,wickUpColor:t.wickUpColor,wickDownColor:t.wickDownColor}),l(!0===t.hideSource)}});return{series:r,options:o.options,applyOptions:o.applyOptions,recalculate:o.recalculate,remove:()=>{o.remove();try{l(!1)}catch(t){}}}}function bh(t,i,s={}){const n={paneIndex:s.paneIndex??1,period:s.period??14,color:s.color??"#9C27B0",lineWidth:s.lineWidth??2,source:s.source??"close",lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?70:s.overbought,oversold:void 0===s.oversold?30:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Kr(0,100)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Qr(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Jr(t,s),e=[],r=[];for(let t=1;t<n.length;t++)r.push(n[t]-n[t-1]);let h=0,l=0;for(let t=0;t<i;t++)r[t]>0?h+=r[t]:l+=Math.abs(r[t]);h/=i,l/=i;let o=0===l?100:h/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<r.length;s++){const n=r[s];h=(h*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:h/l,a=100-100/(1+o),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:a})}return e},a=ih({r_:t,Xf:i,Cy:[r],Jl:"RSI",W:n,ky:["period","source"],Py:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function Mh(t,i,s={}){const n={paneIndex:s.paneIndex??2,fastPeriod:s.fastPeriod??12,slowPeriod:s.slowPeriod??26,signalPeriod:s.signalPeriod??9,colorMACD:s.colorMACD??"#2196F3",colorSignal:s.colorSignal??"#FF6D00",colorHistogramUp:s.colorHistogramUp??"#26a69a",colorHistogramDown:s.colorHistogramDown??"#ef5350",lineWidth:s.lineWidth??2},e=n.paneIndex,r=i.addSeries(oe,{color:n.colorMACD},e),h=Zr(i,r,e),l=i.addSeries(oe,{color:n.colorSignal},h),o=i.addSeries(Ee,{color:n.colorHistogramUp},h),a=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},_=ih({r_:t,Xf:i,Cy:[r,l,o],Jl:"MACD",W:n,ky:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],Py:(t,i)=>{const s=((t,i)=>{const s=i.fastPeriod??12,n=i.slowPeriod??26,e=i.signalPeriod??9;if(!t||t.length<n+e)return{Jy:[],Qy:[],tS:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=a(r,s),l=a(r,n),o=[],_=n-s;for(let t=0;t<l.length;t++)o.push(h[t+_]-l[t]);const u=a(o,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=o[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Jy:c,Qy:d,tS:p}})(t,i);return[[r,s.Jy],[l,s.Qy],[o,s.tS]]},Ty:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),l.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:l,histogram:o,..._}}function yh(t,i,s={}){const n={paneIndex:s.paneIndex??4,kPeriod:s.kPeriod??14,dPeriod:s.dPeriod??3,colorK:s.colorK??"#2196F3",colorD:s.colorD??"#FF6D00",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?80:s.overbought,oversold:void 0===s.oversold?20:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=Kr(0,100),h=i.addSeries(oe,{color:n.colorK,autoscaleInfoProvider:r},e),l=Zr(i,h,e),o=i.addSeries(oe,{color:n.colorD,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Qr(h,n.levelColor),_=ih({r_:t,Xf:i,Cy:[h,o],Jl:"Stochastic",W:n,ky:["kPeriod","dPeriod"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{iS:[],sS:[]};const n=[];for(let s=i-1;s<t.length;s++){let e=-1/0,r=1/0;for(let n=0;n<i;n++){const i=t[s-n];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[s];if("close"in h){const t=(h.close-r)/(e-r)*100;n.push(t)}}const e=[];for(let s=0;s<n.length;s++){const r=i-1+s;t[r]&&t[r].time&&e.push({time:t[r].time,value:n[s]})}const r=[];if(n.length>=s)for(let e=s-1;e<n.length;e++){let h=0;for(let t=0;t<s;t++)h+=n[e-t];const l=h/s,o=i-1+e;t[o]&&t[o].time&&r.push({time:t[o].time,value:l})}return{iS:e,sS:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.iS],[o,s.sS]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:o,..._}}function Sh(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=(t,i)=>{if(!t||t.length<i+1)return[];const s=[];for(let i=1;i<t.length;i++){const n=t[i],e=t[i-1];if("high"in n&&"low"in n&&"close"in e){const t=n.high-n.low,i=Math.abs(n.high-e.close),r=Math.abs(n.low-e.close),h=Math.max(t,i,r);s.push(h)}}if(s.length<i)return[];const n=[];let e=0;for(let t=0;t<i;t++)e+=s[t];e/=i,t[i]&&t[i].time&&n.push({time:t[i].time,value:e});for(let r=i;r<s.length;r++)e=(e*(i-1)+s[r])/i,t[r+1]&&t[r+1].time&&n.push({time:t[r+1].time,value:e});return n},h=ih({r_:t,Xf:i,Cy:[e],Jl:"ATR",W:n,ky:["period"],Py:(t,i)=>[[e,r(t,i.period??14)]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function xh(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Ee,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.8,bottom:0}});const l=(i,s)=>{const n=t.data();if(!n||0===n.length||!jr(t))return[];const e=[];for(const r of n){const n=qr(t,r.time);n&&"close"in r&&"open"in r&&e.push({time:r.time,value:n,color:r.close>=r.open?i:s})}return e},o=ih({r_:t,Xf:i,Cy:[r],Jl:"Volume",W:n,ky:["colorUp","colorDown"],Py:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...o}}function Ch(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!jr(t))return[];const s=[];let n=0;s.push({time:i[0].time,value:n});for(let e=1;e<i.length;e++){const r=i[e],h=i[e-1],l=qr(t,r.time);l&&"close"in r&&"close"in h&&(r.close>h.close?n+=l:r.close<h.close&&(n-=l),s.push({time:r.time,value:n}))}return s},h=ih({r_:t,Xf:i,Cy:[e],Jl:"OBV",W:n,Py:()=>[[e,r()]],Ty:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function Ph(t,i,s={}){const n={paneIndex:s.paneIndex??7,period:s.period??14,colorADX:s.colorADX??"#F23645",colorPlusDI:s.colorPlusDI??"#089981",colorMinusDI:s.colorMinusDI??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,threshold:void 0===s.threshold?25:s.threshold,levelColor:s.levelColor??"#787B86",showDI:s.showDI??!0},e=n.paneIndex,r=Kr(0,100),h=i.addSeries(oe,{color:n.colorADX,autoscaleInfoProvider:r},e),l=Zr(i,h,e),o=i.addSeries(oe,{color:n.colorPlusDI,autoscaleInfoProvider:r},l),a=i.addSeries(oe,{color:n.colorMinusDI,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Qr(h,n.levelColor),u=ih({r_:t,Xf:i,Cy:[h,o,a],Jl:"ADX",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{nS:[],eS:[],rS:[]};const s=[],n=[],e=[];for(let i=1;i<t.length;i++){const r=t[i],h=t[i-1];if(!("high"in r)||!("low"in r)||!("close"in h)){s.push(0),n.push(0),e.push(0);continue}s.push(Math.max(r.high-r.low,Math.abs(r.high-h.close),Math.abs(r.low-h.close)));const l=r.high-h.high,o=h.low-r.low;n.push(l>o&&l>0?l:0),e.push(o>l&&o>0?o:0)}let r=0,h=0,l=0;for(let t=0;t<i;t++)r+=s[t],h+=n[t],l+=e[t];const o=[],a=[],_=[],u=[];for(let c=i;c<s.length;c++){r=r-r/i+s[c],h=h-h/i+n[c],l=l-l/i+e[c];const d=0===r?0:h/r*100,p=0===r?0:l/r*100,f=d+p,v=0===f?0:Math.abs(d-p)/f*100;u.push(v);const m=t[c+1];if(m&&void 0!==m.time)if(a.push({time:m.time,value:d}),_.push({time:m.time,value:p}),u.length===i){let t=0;for(const i of u)t+=i;o.push({time:m.time,value:t/i})}else if(u.length>i){const t=o[o.length-1].value;o.push({time:m.time,value:(t*(i-1)+v)/i})}}return{nS:o,eS:a,rS:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.nS],[o,n?s.eS:[]],[a,n?s.rS:[]]]},Ty:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),a.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:o,minusDI:a,...u}}function Th(t,i,s={}){const n={paneIndex:s.paneIndex??8,period:s.period??20,color:s.color??"#2962FF",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?100:s.overbought,oversold:void 0===s.oversold?-100:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(const i of t)"high"in i&&"low"in i&&"close"in i?s.push((i.high+i.low+i.close)/3):s.push("value"in i?i.value:0);const n=[];for(let e=i-1;e<s.length;e++){let r=0;for(let t=0;t<i;t++)r+=s[e-t];const h=r/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-h);const o=l/i,a=0===o?0:(s[e]-h)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=ih({r_:t,Xf:i,Cy:[r],Jl:"CCI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??20)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function kh(t,i,s={}){const n={paneIndex:s.paneIndex??9,period:s.period??14,color:s.color??"#FF6D00",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?-20:s.overbought,oversold:void 0===s.oversold?-80:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Kr(-100,0)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(let n=i-1;n<t.length;n++){let e=-1/0,r=1/0;for(let s=0;s<i;s++){const i=t[n-s];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[n];if(!("close"in h)||void 0===h.time)continue;const l=e-r,o=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:o})}return s},a=ih({r_:t,Xf:i,Cy:[r],Jl:"Williams %R",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}function Dh(t,i,s={}){const n={paneIndex:s.paneIndex??10,period:s.period??14,color:s.color??"#9C27B0",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??0,overbought:void 0===s.overbought?80:s.overbought,oversold:void 0===s.oversold?20:s.oversold,levelColor:s.levelColor??"#787B86"},e=n.paneIndex,r=i.addSeries(oe,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Kr(0,100)},e),h=Zr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Qr(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!jr(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const r=i[s],h=i[s-1];if(!("high"in r)||!("low"in r)||!("close"in r)){n.push(0),e.push(0);continue}const l=(r.high+r.low+r.close)/3,o=(h.high+h.low+h.close)/3,a=l*(qr(t,r.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const r=[];for(let t=s-1;t<n.length;t++){let h=0,l=0;for(let i=0;i<s;i++)h+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+h/l),a=i[t+1];a&&void 0!==a.time&&r.push({time:a.time,value:o})}return r},a=ih({r_:t,Xf:i,Cy:[r],Jl:"MFI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}}class Rh{constructor(t){this.hS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.hS.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.lS(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}lS(t,i,s,n){const e=i.oS||i.startTime,r=i.aS||i.endTime,h=i.R||i.color,l=i.Oy||i.opacity;if(!i||!e||!r)return;const o=this.hS.getChart().timeScale(),a=o.timeToCoordinate(e),_=o.timeToCoordinate(r);if(null===a||null===_)return;const u=a*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this._S(h,l),t.fillRect(u,d,c-u,p-d)}_S(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Fh{constructor(t){this.Jt=new Rh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const Vh=[{name:"Tokyo",startHour:0,endHour:9,color:"#FF6B00",opacity:.1},{name:"London",startHour:8,endHour:17,color:"#2962FF",opacity:.1},{name:"New York",startHour:13,endHour:22,color:"#089981",opacity:.1}];class Ih{constructor(t,i,s={}){this.uS=[],this.jb=null,this.eh=null,this.Af=t,this.be=i,this.Ps={sessions:s.sessions||Vh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.cS(),this.Ps.enabled&&this.dS()}cS(){this.eh=new Fh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}dS(){this.Af.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.pS()}),this.pS()}pS(){this.fS();const t=this.Af.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);this.vS(s),this.pM()}vS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.mS(i,t);this.Ps.showOverlaps&&this.wS(t)}}mS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.gS(i);this.bS(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.MS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.MS(s,n[n.length-1].time,t)}wS(t){const i=this.Ps.sessions;for(let s=0;s<i.length;s++)for(let n=s+1;n<i.length;n++){const e=i[s],r=i[n],h=this.yS(e,r);h&&this.SS(h,t)}}yS(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{ae:s,_e:n}:null}SS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.gS(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.xS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.xS(s,n[n.length-1].time)}MS(t,i,s){if(!t||!i)return void console.warn("Invalid session box times:",{startTime:t,endTime:i,session:s.name});const n={an:"session",oS:t,aS:i,R:s.color,Oy:s.opacity,CS:s.name};this.uS.push(n)}xS(t,i){const s={an:"overlap",oS:t,aS:i,R:this.Ps.overlapColor,Oy:this.Ps.overlapOpacity,CS:"Overlap"};this.uS.push(s)}bS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}gS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}fS(){this.uS=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.pS():this.fS(),this.pM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.pS(),this.pM()}disable(){this.Ps.enabled=!1,this.fS(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.fS(),this.pM()}getSessionBoxes(){return this.uS}getChart(){return this.Af}getSeries(){return this.be}pM(){this.jb&&this.jb.updateAllViews?.(),this.Af.timeScale().applyOptions({})}}function Ah(t,i,s){return new Ih(t,i,s)}class Lh{constructor(t){this.hS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.hS.getProfileData();if(!s||0===s.bins.length)return;const n=this.hS.options(),e=this.hS.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let o=0;for(const t of s.bins)t.volume>o&&(o=t.volume);if(0!==o){for(const r of s.bins)this.PS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.TS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.kS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}PS(t,i,s,n,e,r,h,l,o,a){const _=i.volume/e*n,u=r.binSize/2,c=l.priceToCoordinate(i.priceLevel+u),d=l.priceToCoordinate(i.priceLevel-u);if(null===c||null===d)return;const p=Math.max(Math.abs(d-c)-1,1),f=s*o,v=Math.min(c,d)*a,m=_*o,w=p*a,g=i.priceLevel>=r.valueAreaLow&&i.priceLevel<=r.valueAreaHigh,b=Math.abs(i.priceLevel-r.poc)<1e-5;let M=h.profileColor||"#2962FF",y=h.opacity||.3;b?(M=h.pocColor||"#FF6B00",y=.6):g&&h.showValueArea&&(M=h.valueAreaColor||"#089981",y=.4),t.fillStyle=this._S(M,y),t.fillRect(f,v,m,w)}TS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const o=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,o),t.lineTo(e*r,o),t.stroke(),t.setLineDash([])}kS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this._S(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}const a=e.priceToCoordinate(s);if(null!==a){const i=a*l;t.strokeStyle=this._S(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}t.setLineDash([])}_S(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Bh{constructor(t){this.Jt=new Lh(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Oh{constructor(t,i,s={}){this.DS=null,this.RS=new Map,this.jb=null,this.eh=null,this.Af=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.cS(),this.dS()}cS(){this.eh=new Bh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}dS(){this.Af.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.FS()}),this.FS()}setVolumeData(t){this.RS=t,this.FS()}addVolumeData(t,i){this.RS.set(t,i),this.FS()}FS(){const t=this.Af.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);if(0===s.length)return;let n=1/0,e=-1/0;for(const t of s){const i=t.low||t.value||t.close,s=t.high||t.value||t.close;i<n&&(n=i),s>e&&(e=s)}const r=(e-n)/this.Ps.numberOfBins,h=[];for(let t=0;t<this.Ps.numberOfBins;t++)h.push({priceLevel:n+(t+.5)*r,volume:0,percentage:0});let l=0;for(const t of s){const i=t.close||t.value,s=this.RS.get(t.time)||1,e=Math.floor((i-n)/r);h[Math.max(0,Math.min(this.Ps.numberOfBins-1,e))].volume+=s,l+=s}for(const t of h)t.percentage=l>0?t.volume/l*100:0;let o=h[0];for(const t of h)t.volume>o.volume&&(o=t);const a=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<a))break;c.push(t),u+=t.volume}let d=-1/0,p=1/0;for(const t of c)t.priceLevel>d&&(d=t.priceLevel),t.priceLevel<p&&(p=t.priceLevel);this.DS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.pM()}getProfileData(){return this.DS}applyOptions(t){this.Ps={...this.Ps,...t},this.FS(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.DS=null,this.RS.clear(),this.pM()}getChart(){return this.Af}getSeries(){return this.be}options(){return this.Ps}pM(){this.jb&&this.jb.updateAllViews?.(),this.Af.timeScale().applyOptions({})}}function Eh(t,i,s){return new Oh(t,i,s)}function Wh(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)}class zh{constructor(t,i){this.VS=new Map,this.IS=null,this.AS=null,this.LS=null,this.BS=null,this.OS=null,this.ES=null,this.WS=!1,this.zS=0,this.$S=null,this.yg=void 0,this.Af=t,this.Rf=i,this.HS=t=>this.NS(t),this.US=t=>this.qS(t),this.jS=t=>this.YS(t),this.XS=t=>this.GS(t),this.KS=()=>this.ZS(),this.JS=t=>{"Escape"===t.key&&this.ZS()},this.Af.subscribeCrosshairMove(this.HS),this.Rf.addEventListener("pointerdown",this.US),this.Rf.addEventListener("pointermove",this.jS),this.Rf.addEventListener("pointerup",this.XS),this.Rf.addEventListener("pointercancel",this.KS),document.addEventListener("keydown",this.JS)}QS(t){this.VS.set(t.id(),t)}tx(t){const i=t.id();this.IS===i&&this.ix(null),this.LS===t&&this.ZS(),this.VS.delete(i)}Gi(){return 0===this.VS.size}m(){this.Af.unsubscribeCrosshairMove(this.HS),this.Rf.removeEventListener("pointerdown",this.US),this.Rf.removeEventListener("pointermove",this.jS),this.Rf.removeEventListener("pointerup",this.XS),this.Rf.removeEventListener("pointercancel",this.KS),document.removeEventListener("keydown",this.JS),this.VS.clear()}NS(t){if(this.$S=t.point?{ut:t.point.x,ct:t.point.y}:null,this.yg=t.paneIndex,null!==this.LS)return;const i=this.sx(t.hoveredObjectId),s=null===i?null:this.VS.get(i.gl)??null;this.ix(s?s.id():null),this.nx(s,null===s?null:i?.hx??null),this.lx()}qS(t){this.WS="mouse"!==t.pointerType;let i=this.WS||null===this.IS?null:this.VS.get(this.IS)??null;null===i&&(i=this.ox(t)),i?(this.OS={ut:t.clientX,ct:t.clientY},this.ES=i,i.isDraggable()&&(this.LS=i,this.BS=t.pointerId,this.Rf.setPointerCapture(t.pointerId),i.beginDrag(),this.zS=this._x(i,t),this.lx(),t.preventDefault(),t.stopPropagation())):this.ux()}YS(t){if(null===this.LS)return;if(!this.vx(t))return void this.ZS();const i=this.mx(t);null!==i&&this.LS.dragTo(i),t.preventDefault(),t.stopPropagation()}GS(t){const i=this.LS,s=this.WS,n=this.ES,e=this.OS;this.wx(),this.ES=null,this.OS=null;const r=s?12:4,h=null!==e&&(Math.abs(t.clientX-e.ut)>r||Math.abs(t.clientY-e.ct)>r);if(null!==i)return this.LS=null,this.zS=0,h?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),this.ux(s),void this.lx();null!==n&&!h&&n.isClickable()&&n.click(),this.ux(s)}ux(t=this.WS){if(!t||null===this.IS)return;const i=this.VS.get(this.IS)??null;this.ix(null),this.nx(i,null),this.lx()}ZS(){if(null===this.LS)return;const t=this.LS;this.LS=null,this.zS=0,this.wx(),t.cancelDrag(),this.lx()}vx(t){const i=this.Rf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}wx(){null!==this.BS&&(this.Rf.hasPointerCapture(this.BS)&&this.Rf.releasePointerCapture(this.BS),this.BS=null)}mx(t){const i=this.LS;if(null===i)return null;const s=this.gx(i,t);return null===s?null:i.priceAt(s-this.zS)}ox(t){for(const i of this.VS.values()){if(!i.hitTestAt)continue;const s=this.bx(i);if(null===s)continue;const n=s.getBoundingClientRect(),e="mouse"===t.pointerType?0:12,r=this.sx(i.hitTestAt(t.clientX-n.left,t.clientY-n.top,e));if(null!==r)return this.ix(i.id()),this.nx(i,r.hx),i}return null}bx(t){const i=this.Af.panes()[t.paneIndex()];return i?i.getHTMLElement():null}gx(t,i){const s=this.bx(t);return s?i.clientY-s.getBoundingClientRect().top:null!==this.$S&&this.yg===t.paneIndex()?this.$S.ct:null}_x(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.gx(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}sx(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,hx:null}:{gl:t.slice(0,i),hx:t.slice(i+1)}}nx(t,i){this.AS!==i&&(this.AS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}ix(t){this.IS!==t&&(null!==this.IS&&this.VS.get(this.IS)?.setHovered(!1),this.IS=t,this.AS=null,null!==t&&this.VS.get(t)?.setHovered(!0))}lx(){if(null!==this.LS)return void this.Af.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.IS?null:this.VS.get(this.IS);t?this.Af.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Af.chartElement().style.removeProperty("cursor")}}const $h=new WeakMap;function Hh(t){const i=t.chartElement();if(!i)return null;let s=$h.get(t);return s||(s=new zh(t,i),$h.set(t,s)),s}function Nh(t,i){const s=$h.get(t);s&&(s.tx(i),s.Gi()&&(s.m(),$h.delete(t)))}let Uh=0;class qh{constructor(t,i,s){this.sr=null,this.Mx=!1,this.yx="",this.Sx=null,this.Af=t,this.be=i,this.So="pipsend-trading-line-"+Uh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.xx(),(this.Ps.draggable||this.Ps.onClick)&&Hh(this.Af)?.QS(this)}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.Mx!==t&&this.sr&&(this.Mx=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.yx}))}hitTestAt(t,i,s=0){const n=this.be.priceToCoordinate(this.Ps.price);return null!==n&&Math.abs(i-n)<=8+s?this.So:null}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.Sx=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.Cx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.Sx=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.Sx;this.Sx=null,null!==t&&t!==this.Ps.price&&(this.Cx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t))}click(){this.Ps.onClick&&this.Ps.onClick(this.Ps.price)}applyOptions(t){if(this.Ps={...this.Ps,...t},t.color&&(this.yx=t.color),!this.sr)return;const i={title:this.Px()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.Mx||(i.color=t.color),void 0!==t.lineWidth&&(i.lineWidth=t.lineWidth),void 0!==t.lineStyle&&(i.lineStyle=t.lineStyle),this.sr.applyOptions(i)}setTitle(t){this.Ps.title=t,this.sr&&this.sr.applyOptions({title:t})}getPrice(){return this.Ps.price}setPrice(t){this.Cx(t)}remove(){Nh(this.Af,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}Px(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}xx(){this.yx=this.Ps.color,this.sr=this.be.createPriceLine({id:this.So,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.Px()})}Cx(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.Px()})}}function jh(t,i,s){const n={"stop-loss":{color:"#ef5350",lineStyle:2,title:"Stop Loss",draggable:!0},"take-profit":{color:"#26a69a",lineStyle:2,title:"Take Profit",draggable:!0},entry:{color:"#2196F3",lineStyle:0,title:"Entry",draggable:!0},target:{color:"#FF9800",lineStyle:2,title:"Target",draggable:!0},resistance:{color:"#f44336",lineStyle:0,title:"Resistance",draggable:!0},support:{color:"#4CAF50",lineStyle:0,title:"Support",draggable:!0},custom:{color:"#9E9E9E",lineStyle:0,title:"",draggable:!0}},e=s.type?n[s.type]:n.custom,r={price:s.price,color:s.color??e.color??"#9E9E9E",lineWidth:s.lineWidth??2,lineStyle:s.lineStyle??e.lineStyle??0,title:s.title??e.title??"",axisLabelVisible:s.axisLabelVisible??!0,draggable:s.draggable??e.draggable??!0,onDragStart:s.onDragStart,onDragMove:s.onDragMove,onDragEnd:s.onDragEnd,onClick:s.onClick,formatTitle:s.formatTitle};return new qh(i,t,r)}class Yh{constructor(t,i){this.If=null,this.Tx=null,this.kx=null,this.Dx={},this.Af=t,this.be=i,this.Rx()}Rx(){this.If=this.Af.chartElement()}Fx(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.If?(this.Tx=t,this.Dx=i||{},new Promise(t=>{this.If.style.cursor="crosshair",this.kx=i=>{const s=this.Fx(i),n=this.Vx(s);this.disableClickToCreate(),t(n)},this.If.addEventListener("click",this.kx)})):Promise.resolve(null)}disableClickToCreate(){this.If&&this.kx&&(this.If.removeEventListener("click",this.kx),this.If.style.cursor="default"),this.Tx=null,this.kx=null,this.Dx={}}Vx(t){if(!this.Tx)return null;let i;switch(this.Tx){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.Dx};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.Dx};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.Dx};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.Dx};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.Dx};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.Dx};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.Dx};break;default:return null}return new qh(this.Af,this.be,i)}getCreationMode(){return this.Tx}isCreating(){return null!==this.Tx}}function Xh(t,i){return new Yh(t,i)}class Gh{constructor(){this.Ix=[],this.Ax=new Map,this.Lx=new Map,this.xt=!0}QS(t){this.Ax.has(t)||(this.Ix.push(t),this.Ax.set(t,[]),this.xt=!0)}tx(t){const i=this.Ix.indexOf(t);-1!==i&&this.Ix.splice(i,1),this.Ax.delete(t),this.xt=!0}Gi(){return 0===this.Ix.length}Bx(t,i){const s=this.Ax.get(t);this.Ax.set(t,i),void 0!==s&&function(t,i){if(t.length!==i.length)return!1;for(let s=0;s<t.length;s++)if(t[s].sn!==i[s].sn||t[s].ct!==i[s].ct||t[s].qt!==i[s].qt)return!1;return!0}(s,i)||(this.xt=!0)}Ox(t,i){return this.xt&&this.Ex(),this.Lx.get(Kh(t,i))??0}Ex(){const t=new Map,i=[];for(const s of this.Ix)for(const n of this.Ax.get(s)??[]){const e=Zh(n.qt),r=n.qt;let h=n.ct;for(const t of i){if(t.ct>=h+e)break;Math.abs(h-t.ct)<e&&(h=t.ct+e)}let l=h-n.ct;l>r&&(l=0),Jh(i,{ct:n.ct+l,qt:n.qt}),t.set(Kh(s,n.sn),l)}this.Lx=t,this.xt=!1}}function Kh(t,i){return`${t}:${i}`}function Zh(t){return Math.max(9,Math.round(.4*t))}function Jh(t,i){let s=0,n=t.length;for(;s<n;){const e=s+n>>1;t[e].ct<=i.ct?s=e+1:n=e}t.splice(s,0,i)}const Qh=new WeakMap;const tl={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},il={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},sl=["takeProfit","entry","stopLoss"];class nl{constructor(){this.Yt=null,this.Wx=[],this.zx=0,this.Uf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i,s=0){for(const n of this.Wx)if(n.$x&&t>=n.Hx-s&&t<=n.Nx+s&&Math.abs(i-n.Ux)<=n.qt/2+s)return{sn:n.sn,hx:"close"};for(const n of this.Wx)if(t>=n.qx-s&&t<=n.jx+s&&Math.abs(i-n.Ux)<=n.qt/2+s)return{sn:n.sn,hx:"body"};for(const t of this.Wx)if(Math.abs(i-t.ct)<=8+s)return{sn:t.sn,hx:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.lw(t))}lw(t){const i=this.Yt;if(this.Wx=[],null===i||0===i.Yx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Uf!==i.T&&(this.Uf=i.T,this.Wn.In()),s.font=i.T,s.textBaseline="middle",this.zx=Math.max(0,n.width-i.yu);const e=i.Xx?this.zx:n.width;for(const s of i.Yx)this.Wx.push(this.Gx(t,i,s,e));i.Xx&&i.Yx.length>1&&this.Kx(t,i),s.restore()}Gx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Zx,o=0===s.Jx.length?0:Math.max(this.Wn.Vi(e,s.Jx)+2*i.yM,.85*l),a=this.Wn.Vi(e,s.hi)+2*i.yM,_=s.$x?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Qx,f=p-l/2;this.tC(t,s,d,c,n),this.iC(t,i,s,{qh:d,sC:f,ts:u,qt:l});let v=d;return o>0&&(this.nC(t,i,s,{qh:v,sC:f,ts:o,qt:l}),v+=o,this.eC(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.DM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.$x&&(this.eC(e,s.R,v,f,l,r,h),this.rC(t,i,s,{qh:v,sC:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Ux:p,qt:l,qx:d,jx:c,Hx:v,Nx:v+_,$x:s.$x}}tC(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=Math.max(1,Math.round(i.dt*o)),_=Math.round(i.ct*o)-Math.floor(a/2);h.save(),h.strokeStyle=i.R,h.lineWidth=a,n(h,i.Kt),h.beginPath(),0!==i.Qx?(h.moveTo(0,_),h.lineTo(Math.round(r*l),_)):(h.moveTo(0,_),h.lineTo(Math.round(Math.max(0,s-8)*l),_),r>e+8&&(h.moveTo(Math.round((e+8)*l),_),h.lineTo(Math.round(r*l),_))),h.stroke(),h.restore()}iC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.hC===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),el(e,n,i.lC,r,h),e.fillStyle=this.Po.X(i.Z,i.oC),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}nC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.aC){const t=i.Wt;e.save(),el(e,{qh:n.qh+t,sC:n.sC+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.lC-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.aC?i._C:s.R,e.fillText(s.Jx,n.qh+n.ts/2,n.sC+n.qt/2),e.restore()}eC(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.Po.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}rC(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.hC===s.sn&&"close"===i.uC){e.save();const t=i.Wt;el(e,{qh:n.qh,sC:n.sC+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.lC-t),r,h,"right"),e.fillStyle=this.Po.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,o=(n.sC+n.qt/2)*h,a=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-a,o-a),e.lineTo(l+a,o+a),e.moveTo(l+a,o-a),e.lineTo(l-a,o+a),e.stroke(),e.restore()}Kx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Yx.find(t=>"entry"===t.sn)??i.Yx[0],h=i.Yx.map(t=>t.ct),l=Math.round(this.zx*n);s.save(),s.setLineDash([]),s.strokeStyle=r.R,s.lineWidth=Math.max(1,Math.floor(n)),s.beginPath(),s.moveTo(l,Math.round(Math.min(...h)*e)),s.lineTo(l,Math.round(Math.max(...h)*e)),s.stroke();for(const t of i.Yx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.Po.X(i.Z,i.oC),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function el(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.sC*e),o=Math.round(i.ts*n),a=Math.round(i.qt*e),_=Math.min(s*n,o/2,a/2);A(t,h,l,o,a,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class rl{constructor(){this.Jt=new nl,this.Yt=null}Tt(t){this.Yt=t}renderer(){return null===this.Yt?null:(this.Jt.lt(this.Yt),this.Jt)}zOrder(){return"top"}Xn(t,i,s=0){return null===this.Yt?null:this.Jt.Xn(t,i,s)}}class hl{constructor(t){this.Qt=t}coordinate(){return this.cC()?.Ai??-1e3}text(){return this.cC()?.hi??""}textColor(){return this.cC()?.DM??"#FFFFFF"}backColor(){return this.cC()?.R??"#000000"}visible(){return null!==this.cC()}cC(){return this.Qt()}}let ll=0;class ol{constructor(t,i,s){this.eh=new rl,this.Po=new S([]),this.dC=new Map,this.pC=!1,this.fC=null,this.AS=null,this.vC=null,this.Sx=null,this.Af=t,this.be=i,this.So="pipsend-position-line-"+ll++,this.Ps=s,this.Vf={...il,...s.theme},this.Jb=[this.eh],this.mC=sl.map(t=>new hl(()=>this.wC(t))),this.gC=function(t,i){let s=Qh.get(t);return s||(s=new Gh,Qh.set(t,s)),s.QS(i),s}(this.Af,this.So),this.be.attachPrimitive(this),Hh(this.Af)?.QS(this)}attached(t){this.pM=t.requestUpdate,this.pC=!0,this.requestUpdate()}detached(){this.pC=!1,this.pM=void 0}paneViews(){return this.Jb}priceAxisViews(){return this.mC}updateAllViews(){this.eh.Tt(this.bC())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.MC(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.hx}`,zOrder:"top",cursorStyle:"close"===s.hx?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.fC===n&&this.AS===e||(this.fC=n,this.AS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.fC&&"close"!==this.AS&&(this.MC(this.fC)?.draggable??!0)}isClickable(){return"close"===this.AS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}hitTestAt(t,i,s=0){const n=this.eh.Xn(t,i,s);return null===n||null===this.MC(n.sn)?null:`${this.So}#${n.sn}:${n.hx}`}dragAnchorY(){if(null===this.vC)return null;const t=this.MC(this.vC)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.vC=this.fC,null===this.vC)return;const t=this.MC(this.vC)?.price??null;this.Sx=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.vC,t)}dragTo(t){null!==this.vC&&(this.yC(this.vC,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.vC,t))}commitDrag(){const t=this.vC;if(this.vC=null,this.Sx=null,null===t)return;const i=this.MC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.vC,i=this.Sx;if(this.vC=null,this.Sx=null,null===t)return;null!==i&&i!==this.MC(t)?.price&&(this.yC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.MC(t)?.price??0)}click(){const t=this.fC;if(null===t)return;if("close"===this.AS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.MC(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.vC,s=null===i?void 0:this.MC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=al(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=al(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.MC(i);null!==t&&(t.price=s)}t.theme&&(this.Vf={...this.Vf,...t.theme}),this.requestUpdate()}setPrice(t,i){this.vC!==t&&this.yC(t,i)}setText(t,i){const s=this.MC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of sl){const s=this.MC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){Nh(this.Af,this),function(t,i){const s=Qh.get(t);s&&(s.tx(i),s.Gi()&&Qh.delete(t))}(this.Af,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.pM&&this.pM()}wC(t){const i=this.MC(t);if(null===i||!isFinite(i.price)||!1===this.Ps.visible||!1===i.axisLabelVisible)return null;const s=this.be.priceToCoordinate(i.price);if(null===s)return null;const n=i.color??tl[t],e=this.be.priceFormatter(),r=this.dC.get(t);if(void 0!==r&&r.bt===i.price&&r.R===n&&r.hl===e)return r.Jl.Ai!==s&&(r.Jl={...r.Jl,Ai:s}),r.Jl;const h={Ai:s,hi:e.format(i.price),R:n,DM:this.Po.K(n).J};return this.dC.set(t,{bt:i.price,R:n,hl:e,Jl:h}),h}MC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}yC(t,i){const s=this.MC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}bC(){if(!this.pC||!1===this.Ps.visible)return null;const t=this.Af.options().layout,i=this.Vf.fontSize??t.fontSize,s=i+2*this.Vf.paddingY,n=[],e=[];for(const t of sl){const i=this.MC(t);if(null===i||!isFinite(i.price))continue;const r=this.be.priceToCoordinate(i.price);if(null===r)continue;const h="entry"===t;e.push({sn:t,ct:r,qt:s}),n.push({sn:t,ct:r,Qx:0,R:i.color??tl[t],hi:i.formatText?i.formatText(i.price):i.text??"",Jx:i.badge??"",aC:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),$x:i.closable??!0,SC:i.draggable??!0})}if(0===n.length)return this.gC.Bx(this.So,[]),null;this.gC.Bx(this.So,e);for(const t of n)t.Qx=this.gC.Ox(this.So,t.sn);return{Yx:n,Z:this.Vf.background??(r=t.background,"solid"===r.type?r.color:r.topColor),DM:this.Vf.textColor,_C:this.Vf.badgeTextColor,lC:this.Vf.borderRadius,Wt:this.Vf.borderWidth,yM:this.Vf.paddingX,Zx:this.Vf.paddingY,oC:this.Vf.backgroundOpacity,T:g(i,this.Vf.fontFamily??t.fontFamily),P:i,Xx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,hC:this.fC,uC:this.AS};var r}}function al(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}function _l(t,i,s){return new ol(i,t,s)}const ul=new Set(["line","body","stroke","center","move"]);function cl(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?ul.has(n)?"move":"grab":void 0}}function dl(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var pl;function fl(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.Vy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Iy,t.day=i.day??i.Ay,t}return t}function vl(t,i){const s={};return s.price=t,s.time=i,s}function ml(t){if(!t)return vl(0,null);return vl(t.price??t.bt??0,fl(t.time??t.gt??null))}function wl(t,i="time"){return t?t[i]??null:null}function gl(t,i){if(t)return t[i]??void 0}!function(t){t.Idle="idle",t.Creating="creating",t.Editing="editing",t.Dragging="dragging",t.Hovering="hovering"}(pl||(pl={}));class bl{constructor(t,i,s={}){this._state=pl.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.xC(),this._options={color:"#2196F3",lineWidth:2,lineStyle:"solid",visible:!0,locked:!1,zIndex:0,...s},this._visible=this._options.visible??!0,this._locked=this._options.locked??!1}xC(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}isComplete(){return!0}_registerOptions(t){this._ownOptions=t}options(){return{...this._ownOptions??this._options}}applyOptions(t){null!==this._ownOptions&&Object.assign(this._ownOptions,t),this._options={...this._options,...t},void 0!==t.visible&&(this._visible=t.visible),void 0!==t.locked&&(this._locked=t.locked),this._update()}show(){this._visible=!0,this._update()}hide(){this._visible=!1,this._update()}lock(){this._locked=!0}unlock(){this._locked=!1}isLocked(){return this._locked}isVisible(){return this._visible}series(){return this._series}selectionBox(){return null}getState(){return this._state}serialize(){const t=this._serializeShape();return t.id=this._id,t.visible=this._visible,t.locked=this._locked,t}applySerializedState(t){"string"==typeof t.id&&t.id.length>0&&(this._id=t.id),"boolean"==typeof t.visible&&(this._visible=t.visible),"boolean"==typeof t.locked&&(this._locked=t.locked),this._update()}}const Ml=new WeakMap;function yl(t,i){Ml.set(t,i)}function Sl(t){const i=!0===Ml.get(t);return i&&Ml.set(t,!1),i}function xl(t,i,s,n,e){const r=t.canvas.width/s,h=t.canvas.height/n;if(e.ct<0||e.ct>h)return;let l;try{l=i.priceFormatter().format(e.bt)}catch(t){l=String(e.bt)}t.save(),t.font=11*s+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const o=t.measureText(l).width/s+10,a=r-o,_=e.ct-8.5;t.fillStyle=e.Et,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.DM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Cl;!function(t){t.CC="idle",t.PC="waiting_first_point",t.TC="waiting_second_point",t.kC="completed"}(Cl||(Cl={}));class Pl{constructor(t,i,s={}){this.Av=Cl.CC,this.DC=null,this.kx=null,this.ep=null,this.Af=t,this.be=i,this.RC=s}FC(){this.Av===Cl.CC&&(this.Av=Cl.PC,this.DC=null,this.VC(),this.IC())}AC(){this.Av=Cl.CC,this.DC=null,this.LC(),this.BC(),this.RC.OC&&this.RC.OC()}EC(){return this.Av}WC(){return this.Av===Cl.PC||this.Av===Cl.TC}VC(){this.kx=t=>{this.zC(t)},this.Af.subscribeClick(this.kx)}IC(){this.ep=t=>{this.$C(t)},this.Af.subscribeCrosshairMove(this.ep)}LC(){this.kx&&(this.Af.unsubscribeClick(this.kx),this.kx=null)}BC(){this.ep&&(this.Af.unsubscribeCrosshairMove(this.ep),this.ep=null)}zC(t){if(!t.point)return;if(Sl(this.Af))return;const i=this.be.coordinateToPrice(t.point.y),s=Kn(this.Af,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Av===Cl.PC?(this.DC=n,this.Av=Cl.TC,this.RC.HC&&this.RC.HC(n)):this.Av===Cl.TC&&this.DC&&(this.Av=Cl.kC,this.RC.NC&&this.RC.NC(n),this.RC.UC&&this.RC.UC(this.DC,n),this.LC(),this.BC(),this.Av=Cl.CC,this.DC=null)}$C(t){if(!t.point)return;if(this.Av!==Cl.TC)return;const i=this.be.coordinateToPrice(t.point.y),s=Kn(this.Af,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.RC.qC&&this.RC.qC(n)}m(){this.AC()}}class Tl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.jC=t,this.Jt=new Tl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends bl{constructor(t,i){super(t,"trend-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null,this.iP=!1,this.sP=null,this.nP=null,this.eP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.eP),this.cS(),this.eP.interactive?this.rP():this.iP=!0}rP(){const t=new Pl(this._chart,this._series,{HC:t=>{this.eP.point1Time=t.gt,this.eP.point1Price=t.bt,this.pM()},NC:t=>{this.eP.point2Time=t.gt,this.eP.point2Price=t.bt,this.iP=!0,this.pM(),this.eP.onUpdate&&this.eP.onUpdate()},qC:t=>{this.eP.point1Time&&!this.iP&&(this.nP=t,this.pM())},UC:()=>{this.iP=!0}});this.sP=t,t.FC()}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new kl(this)}oP(){if(!this.eP.point1Time||!this.eP.point2Time)return null;const t=Zn(this._chart,this._series,this.eP.point1Time)??0,i=this._series.priceToCoordinate(this.eP.point1Price)??0,s=Zn(this._chart,this._series,this.eP.point2Time)??0,n=this._series.priceToCoordinate(this.eP.point2Price)??0;if(!this.eP.extendLeft&&!this.eP.extendRight)return{aP:t,_P:i,uP:s,cP:n};if(s===t)return{aP:t,_P:i,uP:s,cP:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{aP:this.eP.extendLeft?0:t,_P:this.eP.extendLeft?i-r*t:i,uP:this.eP.extendRight?e:s,cP:this.eP.extendRight?i+r*(e-t):n}}dP(){const t=this.oP();if(null===t)return null;const i=t.uP>=t.aP?t.cP:t._P,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.eP.point2Price??this.eP.point1Price??null}drawToCanvas(t,i,s){if(!this.iP&&this.eP.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.eP.point1Time||!this.eP.point2Time)return;const n=(Zn(this._chart,this._series,this.eP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eP.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.eP.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.eP.point2Price)??0)*s,l=this.eP.lineColor,o=this.XC?this.eP.lineWidth+1:this.eP.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.eP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.eP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.oP();if(null===a)return;t.moveTo(a.aP*i,a._P*s),t.lineTo(a.uP*i,a.cP*s),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.isLocked()||(this.fP(t,n,e,i,l),this.fP(t,r,h,i,l));const _=this.dP();if(!1!==this.eP.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&xl(t,this._series,i,s,{bt:_,ct:n,Et:l})}}pP(t,i,s){if(!this.eP.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this.eP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eP.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s;t.strokeStyle=this.eP.lineColor,t.lineWidth=this.eP.lineWidth*i,t.globalAlpha=.7,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),t.globalAlpha=1,this.fP(t,n,e,i,this.eP.lineColor),t.globalAlpha=.5,this.fP(t,r,h,i,this.eP.lineColor),t.globalAlpha=1}fP(t,i,s,n,e){const r=5*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),t.stroke()}setColor(t){this.eP.lineColor=t,this.pM()}color(){return this.eP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}isHovered(){return this.GC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.oP();if(null===s)return!1;return this.vP(t,i,s.aP,s._P,s.uP,s.cP)<=8}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.eP.point1Time||!this.eP.point2Time)return null;const s=Zn(this._chart,this._series,this.eP.point1Time)??0,n=this._series.priceToCoordinate(this.eP.point1Price)??0,e=Zn(this._chart,this._series,this.eP.point2Time)??0,r=this._series.priceToCoordinate(this.eP.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return"point2";return this.vP(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"line"===t&&(this.QC={gt:this.eP.point1Time,bt:this.eP.point1Price},this.tP={gt:this.eP.point2Time,bt:this.eP.point2Price})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null}updateDrag(t,i){if(this.KC&&this.ZC){if("point1"===this.ZC)this.eP.point1Time=t,this.eP.point1Price=i;else if("point2"===this.ZC)this.eP.point2Time=t,this.eP.point2Price=i;else if("line"===this.ZC&&this.QC&&this.tP){const s=dl(this.JC,t,i);this.eP.point1Time=this.QC.gt+s.gt,this.eP.point1Price=this.QC.bt+s.bt,this.eP.point2Time=this.tP.gt+s.gt,this.eP.point2Price=this.tP.bt+s.bt}this.pM(),this.eP.onUpdate&&this.eP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[vl(this.eP.point1Price??0,fl(this.eP.point1Time)),vl(this.eP.point2Price??0,fl(this.eP.point2Time))],style:{lineColor:this.eP.lineColor,lineWidth:this.eP.lineWidth,lineStyle:this.eP.lineStyle,extendLeft:this.eP.extendLeft,extendRight:this.eP.extendRight}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return this.iP}remove(){this.sP&&(this.sP.m(),this.sP=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.eP.onRemove&&this.eP.onRemove()}}function Rl(t,i){return new Dl(t,i)}function Fl(t,i,s,n){let e=0,r=null;const h=()=>{null!==r&&(t.unsubscribeClick(r),r=null)};return r=r=>{if(!r.point||Sl(t))return;const l=i.coordinateToPrice(r.point.y),o=Kn(t,i,r.point.x);null!==l&&null!==o&&(e++,e>=s&&h(),n({gt:o,bt:l,ut:r.point.x,ct:r.point.y},e-1))},t.subscribeClick(r),{mP:()=>null!==r,wP:h}}function Vl(t){const i=t.timeScale();return Math.max(i.width()/5,i.options().barSpacing)}function Il(t,i){const s=t.timeScale(),n=Math.min(i+Vl(t),s.width()-10);return Math.max(n,i+s.options().barSpacing)}class Al{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ll{constructor(t){this.jC=t,this.Jt=new Al(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends bl{constructor(t,i){super(t,"horizontal-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.gP=0,this.bP=null,this.MP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.MP),this.cS(),this.MP.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){this.MP.price=t.bt,void 0!==this.MP.startTime&&(this.MP.startTime=t.gt),this.pM()}isComplete(){return!this.bP?.mP()}selectionBox(){const t=void 0===this.MP.price?null:this._series.priceToCoordinate(this.MP.price);return null===t?null:{left:this.SP(),right:this._chart.timeScale().width(),top:t,bottom:t}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Ll(this)}SP(){return void 0===this.MP.startTime?0:Zn(this._chart,this._series,this.MP.startTime)??0}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.MP.price)return;const n=(this._series.priceToCoordinate(this.MP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.SP()*i,h=this.MP.lineColor,l=this.XC?this.MP.lineWidth+1:this.MP.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.MP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.MP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.MP.showPriceLabel&&xl(t,this._series,i,s,{bt:this.MP.price,ct:n/s,Et:h}),this.MP.showLabel&&(this.XC||this.GC)&&this.xP(t,n,i,s,h)}xP(t,i,s,n,e){const r=this.MP.labelText||this.MP.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=10*s,u=i-a/2-h;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.MP.lineColor=t,this.pM()}color(){return this.MP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.MP.price)return!1;const s=this._series.priceToCoordinate(this.MP.price)??0;return!(t<this.SP()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.gP=this.MP.price??0}stopDrag(){this.KC=!1,this.JC=null}updateDrag(t,i){this.KC&&(this.MP.price=this.gP+dl(this.JC,t,i).bt,this.pM(),this.MP.onUpdate&&this.MP.onUpdate())}getPrice(){return this.MP.price}setPrice(t){this.MP.price=t,this.pM()}setLabel(t){this.MP.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[vl(this.MP.price??0,fl(this.MP.startTime))],style:{lineColor:this.MP.lineColor,lineWidth:this.MP.lineWidth,lineStyle:this.MP.lineStyle,showLabel:this.MP.showLabel,labelText:this.MP.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.MP.onRemove&&this.MP.onRemove()}}function Ol(t,i){return new Bl(t,i)}class El{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Wl{constructor(t){this.jC=t,this.Jt=new El(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class zl extends bl{constructor(t,i){super(t,"cross-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.CP=0,this.gP=0,this.bP=null,this.PP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.PP),this.cS(),this.PP.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.PP.time=t.gt,this.PP.price=t.bt,this.pM()}))}isComplete(){return!this.bP?.mP()}cS(){this.eh=new Wl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}TP(){if(!this.isComplete()||void 0===this.PP.time||void 0===this.PP.price)return null;const t=Zn(this._chart,this._series,this.PP.time),i=this._series.priceToCoordinate(this.PP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.TP();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.PP.lineColor,_=this.XC||this.GC&&!this.isLocked(),u=_?this.PP.lineWidth+1:this.PP.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.PP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.PP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(r,o),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.PP.showPriceLabel&&void 0!==this.PP.price&&xl(t,this._series,i,s,{bt:this.PP.price,ct:n.ct,Et:a}),_&&!this.isLocked()&&(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,o,5*i,0,2*Math.PI),t.fill(),t.stroke())}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.TP();if(null===s)return!1;return Math.abs(i-s.ct)<=8||Math.abs(t-s.ut)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.CP=this.PP.time,this.gP=this.PP.price??0}updateDrag(t,i){if(!this.KC)return;const s=dl(this.JC,t,i);this.PP.time=this.CP+s.gt,this.PP.price=this.gP+s.bt,this.pM(),this.PP.onUpdate&&this.PP.onUpdate()}stopDrag(){this.KC=!1,this.JC=null}setColor(t){this.PP.lineColor=t,this.pM()}color(){return this.PP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}remove(){if(this.bP?.wP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.PP.onRemove&&this.PP.onRemove()}_serializeShape(){return{type:"crossLine",points:[vl(this.PP.price??0,fl(this.PP.time))],style:{lineColor:this.PP.lineColor,lineWidth:this.PP.lineWidth,lineStyle:this.PP.lineStyle}}}}function $l(t,i){return new zl(t,i)}class Hl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Nl{constructor(t){this.jC=t,this.Jt=new Hl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ul extends bl{constructor(t,i){super(t,"polygon",i),this.I_=[],this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.kP=null,this.iP=!1,this.nP=null,this.kx=null,this.DP=null,this.RP=null,this.FP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.FP),this.I_=[...i.points??[]],this.cS(),this.FP.interactive?this.VP():this.iP=this.I_.length>=3}cS(){this.eh=new Nl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.I_.length>=3&&this.IP(t.point.x,t.point.y)?this.AP():(this.I_.push({time:s,price:i}),this.pM()))},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={time:s,price:i},this.pM())},this.RP=t=>{"Enter"===t.key&&this.I_.length>=3?this.AP():"Escape"===t.key&&(this.I_=[],this.AP())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP),document.addEventListener("keydown",this.RP)}IP(t,i){const s=this.I_[0],n=Zn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Ul.LP&&Math.abs(i-e)<=Ul.LP)}AP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.FP.onComplete&&this.FP.onComplete(),this.FP.onUpdate&&this.FP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null),this.RP&&(document.removeEventListener("keydown",this.RP),this.RP=null)}OP(){const t=[...this.I_];return this.iP||null===this.nP||t.push(this.nP),this.EP(t)}EP(t){const i=[];for(const s of t){const t=Zn(this._chart,this._series,s.time),n=this._series.priceToCoordinate(s.price);null!==t&&null!==n&&i.push({ut:t,ct:n})}return i}drawToCanvas(t,i,s){const n=this.OP();if(n.length<2)return;const e=this.FP.borderColor,r=this.XC?this.FP.borderWidth+1:this.FP.borderWidth;t.beginPath(),t.moveTo(n[0].ut*i,n[0].ct*s);for(let e=1;e<n.length;e++)t.lineTo(n[e].ut*i,n[e].ct*s);this.iP&&(t.closePath(),this.FP.fillOpacity>0&&(t.fillStyle=this.zy(this.FP.fillColor,this.FP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.iP?"dashed"===this.FP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.FP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked())for(const n of this.WP())this.zP(t,n.ut*i,n.ct*s,i,e)}WP(){return this.EP(this.I_)}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){const s=this.WP();if(s.length<3)return!1;let n=!1;for(let e=0,r=s.length-1;e<s.length;r=e++){s[e].ct>i!=s[r].ct>i&&t<(s[r].ut-s[e].ut)*(i-s[e].ct)/(s[r].ct-s[e].ct)+s[e].ut&&(n=!n)}return n}hitTestEndpoint(t,i){const s=this.WP();for(let n=0;n<s.length;n++)if(Math.abs(t-s[n].ut)<=10&&Math.abs(i-s[n].ct)<=10)return n;return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.kP=this.I_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.KC&&null!==this.ZC&&null!==this.kP){if("shape"===this.ZC){const s=dl(this.JC,t,i);this.I_=this.kP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.ZC;this.I_[s]&&(this.I_[s]={time:t,price:i})}this.pM(),this.FP.onUpdate&&this.FP.onUpdate()}}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.kP=null}setColor(t){this.FP.borderColor=t,this.FP.fillColor=t,this.pM()}color(){return this.FP.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}points(){return this.I_}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.FP.onRemove&&this.FP.onRemove()}_serializeShape(){return{type:"polygon",points:this.I_.map(t=>vl(t.price,fl(t.time))),style:{fillColor:this.FP.fillColor,fillOpacity:this.FP.fillOpacity,borderColor:this.FP.borderColor,borderWidth:this.FP.borderWidth,borderStyle:this.FP.borderStyle}}}}function ql(t,i){return new Ul(t,i)}Ul.LP=12;class jl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Yl{constructor(t){this.jC=t,this.Jt=new jl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Xl extends bl{constructor(t,i){super(t,"parallel-channel",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.iP=!1,this.dd=0,this.nP=null,this.kx=null,this.DP=null,this.HP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.HP),this.cS(),this.HP.interactive?this.VP():this.iP=!0}cS(){this.eh=new Yl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.HP.point1Time=s,this.HP.point1Price=i;else{if(1!==this.dd)return this.HP.channelWidth=i-this.NP(s),void this.AP();this.HP.point2Time=s,this.HP.point2Price=i}this.dd++,this.pM()}},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={gt:s,bt:i},2===this.dd&&(this.HP.channelWidth=i-this.NP(s)),this.pM())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP)}AP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.HP.onComplete&&this.HP.onComplete(),this.HP.onUpdate&&this.HP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null)}NP(t){const i=this.HP.point1Time,s=this.HP.point2Time,n=this.HP.point1Price,e=this.HP.point2Price;if(void 0===i||void 0===n)return 0;if(void 0===s||void 0===e||s===i)return n;return n+(e-n)/(s-i)*(t-i)}VS(){const t=this.HP,i=this.iP?t.point2Time:t.point2Time??this.nP?.gt,s=this.iP?t.point2Price:t.point2Price??this.nP?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Zn(this._chart,this._series,t.point1Time),e=Zn(this._chart,this._series,i),r=this._series.priceToCoordinate(t.point1Price),h=this._series.priceToCoordinate(s);if(null===n||null===e||null===r||null===h)return null;let l=e,o=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,o=r+(h-r)/(e-n)*(t-n)}const a=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+a),u=this._series.priceToCoordinate(this._series.coordinateToPrice(o)+a);return null===_||null===u?null:{aP:n,uP:l,UP:r,qP:o,jP:_,YP:u}}drawToCanvas(t,i,s){const n=this.VS();if(null===n)return;const e=this.HP,r=e.lineColor,h=this.XC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.zy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.aP*l,n.UP*o),t.lineTo(n.uP*l,n.qP*o),t.lineTo(n.uP*l,n.YP*o),t.lineTo(n.aP*l,n.jP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.iP?"dashed"===e.lineStyle?t.setLineDash([10*l,5*l]):"dotted"===e.lineStyle&&t.setLineDash([2*l,3*l]):t.setLineDash([6*l,4*l]),t.beginPath(),t.moveTo(n.aP*l,n.UP*o),t.lineTo(n.uP*l,n.qP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.aP*l,n.jP*o),t.lineTo(n.uP*l,n.YP*o)),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked()&&(this.zP(t,n.aP*l,n.UP*o,l,r),this.zP(t,n.uP*l,n.qP*o,l,r),0!==(e.channelWidth??0))){const i=(n.aP+n.uP)/2,s=(n.jP+n.YP)/2;this.zP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.iP){const i=this._series.coordinateToPrice(n.qP);null!==i&&xl(t,this._series,l,o,{bt:i,ct:n.qP,Et:r})}}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}XP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.VS();if(null===s)return!1;return this.XP(t,i,s.aP,s.UP,s.uP,s.qP)<=8||this.XP(t,i,s.aP,s.jP,s.uP,s.YP)<=8}hitTestEndpoint(t,i){const s=this.VS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.aP,s.UP))return"point1";if(n(s.uP,s.qP))return"point2";if(0!==(this.HP.channelWidth??0)){if(n((s.aP+s.uP)/2,(s.jP+s.YP)/2))return"width"}return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P={GP:{gt:this.HP.point1Time,bt:this.HP.point1Price},KP:{gt:this.HP.point2Time,bt:this.HP.point2Price},ts:this.HP.channelWidth??0}}updateDrag(t,i){if(!this.KC||null===this.ZC||null===this.$P)return;const s=this.HP;if("point1"===this.ZC)s.point1Time=t,s.point1Price=i;else if("point2"===this.ZC)s.point2Time=t,s.point2Price=i;else if("width"===this.ZC)s.channelWidth=i-this.NP(t);else{const n=dl(this.JC,t,i);s.point1Time=this.$P.GP.gt+n.gt,s.point1Price=this.$P.GP.bt+n.bt,s.point2Time=this.$P.KP.gt+n.gt,s.point2Price=this.$P.KP.bt+n.bt,s.channelWidth=this.$P.ts}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}setColor(t){this.HP.lineColor=t,this.HP.fillColor=t,this.pM()}color(){return this.HP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.HP.onRemove&&this.HP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[vl(this.HP.point1Price??0,fl(this.HP.point1Time)),vl(this.HP.point2Price??0,fl(this.HP.point2Time))],style:{lineColor:this.HP.lineColor,lineWidth:this.HP.lineWidth,lineStyle:this.HP.lineStyle,fillColor:this.HP.fillColor,fillOpacity:this.HP.fillOpacity,extendRight:this.HP.extendRight},extra:{channelWidth:this.HP.channelWidth}}}}function Gl(t,i){return new Xl(t,i)}class Kl{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zl{constructor(t){this.jC=t,this.Jt=new Kl(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Jl extends bl{constructor(t,i){super(t,"pitchfork",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.iP=!1,this.dd=0,this.nP=null,this.kx=null,this.DP=null,this.ZP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.ZP),this.cS(),this.ZP.interactive?this.VP():this.iP=!0}cS(){this.eh=new Zl(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.YC&&this.YC()}_update(){this.pM()}VP(){this.kx=t=>{if(!t.point||Sl(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.ZP.pivotTime=s,this.ZP.pivotPrice=i;else{if(1!==this.dd)return this.ZP.lowerTime=s,this.ZP.lowerPrice=i,this.dd++,void this.AP();this.ZP.upperTime=s,this.ZP.upperPrice=i}this.dd++,this.pM()}},this.DP=t=>{if(!t.point||this.iP)return;const i=this._series.coordinateToPrice(t.point.y),s=Kn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.nP={gt:s,bt:i},this.pM())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.DP)}AP(){this.iP=!0,this.nP=null,this.BP(),this.pM(),this.ZP.onComplete&&this.ZP.onComplete(),this.ZP.onUpdate&&this.ZP.onUpdate()}BP(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.DP&&(this._chart.unsubscribeCrosshairMove(this.DP),this.DP=null)}JP(t,i){if(void 0===t||void 0===i)return null;const s=Zn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}QP(){const t=this.ZP,i=this.JP(t.pivotTime,t.pivotPrice),s=this.JP(t.upperTime,t.upperPrice),n=this.iP?this.JP(t.lowerTime,t.lowerPrice):this.JP(t.lowerTime,t.lowerPrice)??(null!==this.nP&&this.dd>=2?this.JP(this.nP.gt,this.nP.bt):null);if(null===i||null===s||null===n)return null;const e={ut:(s.ut+n.ut)/2,ct:(s.ct+n.ct)/2};if(e.ut===i.ut)return null;const r=this._chart.chartElement().clientWidth,h=(e.ct-i.ct)/(e.ut-i.ut),l=t=>({ut:r,ct:t.ct+h*(r-t.ut)});return{jy:i,tT:e,Dy:s,Fy:n,iT:l(i),sT:l(s),nT:l(n)}}drawToCanvas(t,i,s){const n=this.QP();if(null===n)return void this.eT(t,i,s);const e=this.ZP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.zy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.sT.ut*h,n.sT.ct*l),t.lineTo(n.nT.ut*h,n.nT.ct*l),t.lineTo(n.Fy.ut*h,n.Fy.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.XC?e.lineWidth+1:e.lineWidth)*h,"dashed"===e.lineStyle?t.setLineDash([10*h,5*h]):"dotted"===e.lineStyle&&t.setLineDash([2*h,3*h]),t.beginPath(),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.Fy.ut*h,n.Fy.ct*l),t.moveTo(n.jy.ut*h,n.jy.ct*l),t.lineTo(n.iT.ut*h,n.iT.ct*l),t.moveTo(n.Dy.ut*h,n.Dy.ct*l),t.lineTo(n.sT.ut*h,n.sT.ct*l),t.moveTo(n.Fy.ut*h,n.Fy.ct*l),t.lineTo(n.nT.ut*h,n.nT.ct*l),t.stroke(),t.setLineDash([]);if((this.XC||this.GC||!this.iP)&&!this.isLocked())for(const i of[n.jy,n.Dy,n.Fy])this.zP(t,i.ut*h,i.ct*l,h,r)}eT(t,i,s){const n=this.ZP,e=this.JP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.JP(n.upperTime,n.upperPrice)??(null!==this.nP?this.JP(this.nP.gt,this.nP.bt):null),h=n.lineColor;t.strokeStyle=h,t.lineWidth=n.lineWidth*i,t.setLineDash([6*i,4*i]),null!==r&&(t.beginPath(),t.moveTo(e.ut*i,e.ct*s),t.lineTo(r.ut*i,r.ct*s),t.stroke()),t.setLineDash([]),this.zP(t,e.ut*i,e.ct*s,i,h)}zP(t,i,s,n,e){t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,5*n,0,2*Math.PI),t.fill(),t.stroke()}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}lP(t,i){if(!this.isVisible()||!this.iP)return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}XP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.QP();if(null===s)return!1;return[[s.jy,s.iT],[s.Dy,s.sT],[s.Fy,s.nT],[s.Dy,s.Fy]].some(([s,n])=>this.XP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.QP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.jy)?"pivot":n(s.Dy)?"upper":n(s.Fy)?"lower":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P=[{gt:this.ZP.pivotTime,bt:this.ZP.pivotPrice},{gt:this.ZP.upperTime,bt:this.ZP.upperPrice},{gt:this.ZP.lowerTime,bt:this.ZP.lowerPrice}]}updateDrag(t,i){if(!this.KC||null===this.ZC||null===this.$P)return;const s=this.ZP;if("pivot"===this.ZC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.ZC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.ZC)s.lowerTime=t,s.lowerPrice=i;else{const n=dl(this.JC,t,i),[e,r,h]=this.$P;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}setColor(t){this.ZP.lineColor=t,this.ZP.fillColor=t,this.pM()}color(){return this.ZP.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isComplete(){return this.iP}remove(){if(this.BP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.YC=null,this.ZP.onRemove&&this.ZP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[vl(this.ZP.pivotPrice??0,fl(this.ZP.pivotTime)),vl(this.ZP.upperPrice??0,fl(this.ZP.upperTime)),vl(this.ZP.lowerPrice??0,fl(this.ZP.lowerTime))],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,lineStyle:this.ZP.lineStyle,fillColor:this.ZP.fillColor,fillOpacity:this.ZP.fillOpacity}}}}function Ql(t,i){return new Jl(t,i)}class to{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class io{constructor(t){this.jC=t,this.Jt=new to(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class so extends bl{constructor(t,i){super(t,"vertical-line",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.JC=null,this.CP=0,this.bP=null,this.rT={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.rT),this.cS(),this.rT.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.rT.time=t.gt,this.pM()}))}isComplete(){return!this.bP?.mP()}selectionBox(){const t=Zn(this._chart,this._series,this.rT.time);if(null===t)return null;let i;try{i=this._series.getPane().getHeight()/2}catch(t){return null}return{left:t,right:t,top:i,bottom:i}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new io(this)}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.rT.time)return;const n=(Zn(this._chart,this._series,this.rT.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.rT.lineColor,h=this.XC||this.GC&&!this.isLocked()?this.rT.lineWidth+1:this.rT.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.rT.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.rT.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.rT.showLabel&&(this.XC||this.GC)&&this.rT.labelText&&this.xP(t,n,i,s,r)}xP(t,i,s,n,e){const r=this.rT.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=i-o/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.rT.lineColor=t,this.pM()}color(){return this.rT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.rT.time)return!1;const s=Zn(this._chart,this._series,this.rT.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.KC=!0,this.JC=i,this.CP=this.rT.time}stopDrag(){this.KC=!1,this.JC=null}updateDrag(t,i){this.KC&&(this.rT.time=this.CP+dl(this.JC,t,i).gt,this.pM(),this.rT.onUpdate&&this.rT.onUpdate())}getTime(){return this.rT.time}setTime(t){this.rT.time=t,this.pM()}setLabel(t){this.rT.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[vl(0,fl(this.rT.time))],style:{lineColor:this.rT.lineColor,lineWidth:this.rT.lineWidth,lineStyle:this.rT.lineStyle,showLabel:this.rT.showLabel,labelText:this.rT.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.rT.onRemove&&this.rT.onRemove()}}function no(t,i){return new so(t,i)}const eo=[{hT:0,Jl:"0.0%"},{hT:.236,Jl:"23.6%"},{hT:.382,Jl:"38.2%"},{hT:.5,Jl:"50.0%"},{hT:.618,Jl:"61.8%"},{hT:.786,Jl:"78.6%"},{hT:1,Jl:"100.0%"}],ro=[...eo,{hT:1.272,Jl:"127.2%"},{hT:1.414,Jl:"141.4%"},{hT:1.618,Jl:"161.8%"},{hT:2,Jl:"200.0%"},{hT:2.618,Jl:"261.8%"}];class ho{constructor(t=!1){this.lT=t?ro:eo}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.lT.map(({hT:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{hT:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.lT=t}getRatios(){return[...this.lT]}getRatioValues(){return this.lT.map(t=>t.hT)}useStandardRatios(){this.lT=eo}useExtendedRatios(){this.lT=ro}}class lo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class oo{constructor(t){this.jC=t,this.Jt=new lo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}function ao(t){return{hT:t,Jl:`${(100*t).toFixed(1)}%`}}class _o extends bl{constructor(t,i){super(t,"fibonacci-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.oT=null,this.iP=!1,this.XC=!1,this.GC=!1,this.nP=null,this.KC=!1,this.aT=null,this.ep=null,this._T={lineColor:"#787b86",lineWidth:1,showLabels:!0,labelPosition:"right",useExtended:!1,levelColors:{0:"#787b86",.236:"#f23645",.382:"#ff9800",.5:"#2196f3",.618:"#4caf50",.786:"#9c27b0",1:"#787b86"},...i},this._registerOptions(this._T),this.uT=new ho(this._T.useExtended),void 0!==this._T.levels&&this._T.levels.length>0&&this.uT.updateRatios(this._T.levels.map(ao)),this.cS(),this._T.interactive?this.rP():(this.iP=!0,this.cT())}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new oo(this)}drawToCanvas(t,i,s){if(!this.iP&&this._T.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.Gb||!this._T.point1Time||!this._T.point2Time)return;const n=(Zn(this._chart,this._series,this._T.point1Time)??0)*i,e=(Zn(this._chart,this._series,this._T.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.XC?2:this._T.lineWidth;this.Gb.levels.forEach(n=>{this.Gx(t,n,r,h,i,s,l)}),!this.XC&&!this.GC||this.isLocked()||(this.fP(t,n,(this._series.priceToCoordinate(this._T.point1Price)??0)*s,i),this.fP(t,e,(this._series.priceToCoordinate(this._T.point2Price)??0)*s,i))}Gx(t,i,s,n,e,r,h=1){const l=i.ratio??i.hT,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this._T.levelColors?.[l.toString()]||this._T.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this._T.showLabels&&this.xP(t,i,s,n,a,e,_)}xP(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.uT.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this._T.labelPosition?n+u:s-_.width-u,d=e;t.fillStyle="rgba(255, 255, 255, 0.9)",t.fillRect(c-u/2,d-11*r/2-u/2,_.width+u,11*r+u),t.fillStyle=h,t.textAlign="right"===this._T.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}cT(){this._T.point1Time&&this._T.point1Price&&this._T.point2Time&&this._T.point2Price&&(this.Gb=this.uT.calculateLevels(this._T.point1Time,this._T.point1Price,this._T.point2Time,this._T.point2Price),this._T.onUpdate&&this.Gb&&this._T.onUpdate(this.Gb))}updatePoints(t,i,s,n){this._T.point1Time=t,this._T.point1Price=i,this._T.point2Time=s,this._T.point2Price=n,this.cT(),this.pM()}getMetrics(){return this.Gb}getLevels(){return this.Gb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.uT.getRatioValues();return{type:"fibRetracement",points:[vl(this._T.point1Price??0,fl(this._T.point1Time)),vl(this._T.point2Price??0,fl(this._T.point2Time))],style:{lineColor:this._T.lineColor,lineWidth:this._T.lineWidth,showLabels:this._T.showLabels,labelPosition:this._T.labelPosition,levelColors:this._T.levelColors},extra:{levels:t,useExtended:this._T.useExtended}}}useExtendedLevels(t){this._T.useExtended=t,t?this.uT.useExtendedRatios():this.uT.useStandardRatios(),this.cT(),this.pM()}rP(){this.oT=new Pl(this._chart,this._series,{HC:t=>{this._T.point1Time=t.gt,this._T.point1Price=t.bt,this.pM()},NC:t=>{this._T.point2Time=t.gt,this._T.point2Price=t.bt},UC:(t,i)=>{this._T.point1Time=t.gt,this._T.point1Price=t.bt,this._T.point2Time=i.gt,this._T.point2Price=i.bt,this.iP=!0,this.nP=null,this.cT(),this.dT(),this.pM()},qC:t=>{this.nP=t,this.pM()}}),this.oT.FC()}pP(t,i,s){if(!this._T.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this._T.point1Time)??0)*i,e=(this._series.priceToCoordinate(this._T.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s,l=this.uT.calculateLevels(this._T.point1Time,this._T.point1Price,this.nP.gt,this.nP.bt),o=Math.min(n,r),a=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.hT,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this._T.levelColors?.[e.toString()]||this._T.lineColor;if(t.strokeStyle=l,t.lineWidth=this._T.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this._T.showLabels){const s=`${n.label??n.Jl} ${this.uT.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this._T.labelPosition?a+_:o-e.width-_,c=h;t.fillStyle="rgba(255, 255, 255, 0.8)",t.fillRect(u-_/2,c-11*i/2-_/2,e.width+_,11*i+_),t.fillStyle=l,t.textAlign="right"===this._T.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.fP(t,n,e,i),t.globalAlpha=.6,this.fP(t,r,h,i),t.globalAlpha=1}fP(t,i,s,n){const e=this._T.lineColor,r=this.XC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.XC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}dT(){this.ep=t=>{this.pT(t)},this._chart.subscribeCrosshairMove(this.ep)}fT(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}pT(t){if(!t.point)return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.XC||!this.KC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.aT?(this._T.point1Time=i,this._T.point1Price=s):"point2"===this.aT&&(this._T.point2Time=i,this._T.point2Price=s),this.cT(),this.pM())}startDrag(t){this.KC=!0,this.aT=t}stopDrag(){this.KC=!1,this.aT=null}updateDrag(t,i){this.KC&&this.aT&&("point1"===this.aT?(this._T.point1Time=t,this._T.point1Price=i):(this._T.point2Time=t,this._T.point2Price=i),this.cT(),this.pM())}hitTestEndpoint(t,i){if(!this.iP||!this._T.point1Time||!this._T.point2Time)return null;const s=Zn(this._chart,this._series,this._T.point1Time)??0,n=this._series.priceToCoordinate(this._T.point1Price)??0,e=Zn(this._chart,this._series,this._T.point2Time)??0,r=this._series.priceToCoordinate(this._T.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}applyOptions(t){this._T={...this._T,...t},void 0!==t.levels&&t.levels.length>0?this.uT.updateRatios(t.levels.map(ao)):void 0!==t.useExtended&&(t.useExtended?this.uT.useExtendedRatios():this.uT.useStandardRatios()),super.applyOptions(t),this.cT(),this.pM()}options(){return{...this._T,levels:this.uT.getRatioValues()}}setColor(t){this._T.lineColor=t,this.pM()}color(){return this._T.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isSelected(){return this.XC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.iP||!this._T.point1Time||!this._T.point2Time)return!1;const s=Zn(this._chart,this._series,this._T.point1Time)??0,n=Zn(this._chart,this._series,this._T.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Gb)return!1;for(const t of this.Gb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.iP}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.oT&&(this.oT.m(),this.oT=null),this.fT(),this._T.onRemove&&this._T.onRemove()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this._T.onRemove&&this._T.onRemove()}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.cT(),this.pM()}}function uo(t,i){return new _o(t,i)}class co{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class po{constructor(t){this.jC=t,this.Jt=new co(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class fo extends bl{constructor(t,i){super(t,"fibonacci-extension",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.bP=null,this._T={levels:[{level:0,color:"#787B86",label:"0%"},{level:.618,color:"#2962FF",label:"61.8%"},{level:1,color:"#787B86",label:"100%"},{level:1.618,color:"#F23645",label:"161.8%"},{level:2.618,color:"#9C27B0",label:"261.8%"}],lineColor:"#787B86",lineWidth:1,showLabels:!0,extendLines:!0,...i},this.cS(),this._T.interactive&&(this.bP=Fl(this._chart,this._series,3,(t,i)=>{const s={time:t.gt,price:t.bt};0===i?this.setPoint1(s):1===i?this.setPoint2(s):this.setPoint3(s)}))}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new po(this)}getPoint1(){return this._T.point1}getPoint2(){return this._T.point2}getPoint3(){return this._T.point3}getLevels(){return this._T.levels||[]}getOptions(){return this._T}setPoint1(t){this._T.point1=t,this.pM()}setPoint2(t){this._T.point2=t,this.pM()}setPoint3(t){this._T.point3=t,this.pM()}isComplete(){return!this.bP?.mP()&&!!(this._T.point1&&this._T.point2&&this._T.point3)}setColor(t){this._T.lineColor=t,this.pM()}color(){return this._T.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this._T.point1,this._T.point2,this._T.point3];for(const n of s){const s=Zn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=10)return!0}const n=this.vT();for(const t of n){const s=this._series.priceToCoordinate(t.bt)??0;if(Math.abs(i-s)<=10)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this._T.point1,n=this._T.point2,e=this._T.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Zn(this._chart,this._series,s.time)??0,e=this._series.priceToCoordinate(s.price)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=20)return"point1"}if(n&&n.time&&void 0!==n.price){const s=Zn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=20)return"point2"}if(e&&e.time&&void 0!==e.price){const s=Zn(this._chart,this._series,e.time)??0,n=this._series.priceToCoordinate(e.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=20)return"point3"}return null}startDrag(t){this.KC=!0,this.ZC=t}stopDrag(){this.KC=!1,this.ZC=null}updateDrag(t,i){if(!this.KC||!this.ZC)return;const s={time:t,price:i};switch(this.ZC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this._T.onUpdate&&this._T.onUpdate()}vT(){if(!this.isComplete())return[];const t=this._T.point1,i=this._T.point2,s=this._T.point3,n=i.price-t.price;return(this._T.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.vT()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this._T.point1,e=this._T.point2,r=this._T.point3,h=this.XC||this.GC&&!this.isLocked(),l=(Zn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Zn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Zn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this._T.lineColor||"#787B86",t.lineWidth=(this._T.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this._T.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this._T.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this._T.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Jl:"A"},{ut:a,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[ml(this._T.point1),ml(this._T.point2),ml(this._T.point3)],style:{lineColor:this._T.lineColor,lineWidth:this._T.lineWidth,showLabels:this._T.showLabels,extendLines:this._T.extendLines},extra:{levels:(this._T.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null)}}function vo(t,i){return new fo(t,i)}class mo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wo{constructor(t){this.jC=t,this.Jt=new mo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const go=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class bo extends bl{constructor(t,i){super(t,"fibonacci-fan",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.wT={levels:go,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.cS(),this.wT.interactive&&!this.wT.point1Time&&this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.wT.point1Time?(this.wT.point2Time=i,this.wT.point2Price=s,this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.wT.onUpdate&&this.wT.onUpdate()):(this.wT.point1Time=i,this.wT.point1Price=s,this.pM()))},this.ep=t=>{if(this.mT&&this.wT.point1Time)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new wo(this)}drawToCanvas(t,i,s){const n=this.wT.point1Time,e=this.wT.point1Price,r=this.mT&&this.nP?this.nP.gt:this.wT.point2Time,h=this.mT&&this.nP?this.nP.bt:this.wT.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Zn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Zn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.XC?this.wT.lineWidth+1:this.wT.lineWidth;if(this.gT(t,l,o,a,_,"#2962FF",u*i),this.wT.levels)for(const n of this.wT.levels)this.bT(t,l,o,a,_,n,i,s,undefined,u);!this.XC&&!this.GC||this.mT||this.isLocked()||(this.fP(t,l,o,i,"#2962ff"),this.fP(t,a,_,i,"#2962ff"))}bT(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.wT.extendLines){const t=this._chart.chartElement().clientWidth*h,n=_-i,e=u-s,r=Math.sqrt(n*n+e*e);if(r>0){const h=2*t;c=i+n/r*h,d=s+e/r*h}}const p=o||r.color;this.gT(t,i,s,c,d,p,a*h),this.wT.showLabels&&!this.mT&&this.xP(t,_,u,r.label,h,p)}gT(t,i,s,n,e,r,h){t.strokeStyle=r,t.lineWidth=h,t.beginPath(),t.moveTo(i,s),t.lineTo(n,e),t.stroke()}fP(t,i,s,n,e){const r=5*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke()}xP(t,i,s,n,e,r){const h=11*e,l=4*e;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(n).width,a=h;t.fillStyle=r,t.fillRect(i+l,s-a-l,o+2*l,a+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-a-l+l)}setColor(t){const i=this.wT.levels??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.wT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.wT.point1Time||!this.wT.point2Time)return!1;const s=Zn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Zn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;if(this.vP(t,i,s,n,e,r)<=8)return!0;if(this.wT.levels)for(const h of this.wT.levels){const l=n+(r-n)*h.level,o=e;if(this.vP(t,i,s,n,o,l)<=8)return!0}return!1}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.wT.point1Time||!this.wT.point2Time)return null;const s=Zn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Zn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;return Math.abs(t-s)<=10&&Math.abs(i-n)<=10?"point1":Math.abs(t-e)<=10&&Math.abs(i-r)<=10?"point2":null}startDrag(t){this.KC=!0,this.ZC=t}stopDrag(){this.KC=!1,this.ZC=null}updateDrag(t,i){this.KC&&this.ZC&&("point1"===this.ZC?(this.wT.point1Time=t,this.wT.point1Price=i):"point2"===this.ZC&&(this.wT.point2Time=t,this.wT.point2Price=i),this.pM(),this.wT.onUpdate&&this.wT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[vl(this.wT.point1Price??0,fl(this.wT.point1Time)),vl(this.wT.point2Price??0,fl(this.wT.point2Time))],style:{lineWidth:this.wT.lineWidth,showLabels:this.wT.showLabels,extendLines:this.wT.extendLines},extra:{levels:(this.wT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.wT.onRemove&&this.wT.onRemove()}}function Mo(t,i){return new bo(t,i)}class yo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class So{constructor(t){this.jC=t,this.Jt=new yo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class xo extends bl{constructor(t,i){super(t,"rectangle",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.MT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.MT),this.cS(),!this.MT.interactive||this.MT.time1&&this.MT.time2||this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.MT.time1?(this.MT.time2=i,this.MT.price2=s,this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.MT.onUpdate&&this.MT.onUpdate()):(this.MT.time1=i,this.MT.price1=s,this.pM()))},this.ep=t=>{if(this.mT&&this.MT.time1)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new So(this)}drawToCanvas(t,i,s){const n=this.MT.time1,e=this.MT.price1,r=this.mT&&this.nP?this.nP.gt:this.MT.time2,h=this.mT&&this.nP?this.nP.bt:this.MT.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Zn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Zn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,a),c=Math.max(l,a),d=Math.min(o,_),p=Math.max(o,_),f=c-u,v=p-d;if(this.MT.fillOpacity>0){const i=this._S(this.MT.fillColor,this.mT?.1:this.MT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.MT.borderColor,w=this.XC?this.MT.borderWidth+1:this.MT.borderWidth;w>0&&(t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.MT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.MT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([])),!this.XC&&!this.GC||this.mT||this.isLocked()||this.yT(t,u,d,c,p,i,m),this.MT.showLabel&&this.MT.labelText&&!this.mT&&this.xP(t,u,d,c,p,i,s,m)}yT(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s},{ut:n,ct:s},{ut:i,ct:e},{ut:n,ct:e}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}xP(t,i,s,n,e,r,h,l){const o=6*r,a=(this.MT.labelFontSize??12)*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.MT.labelText).width,u=a,c=(s+e)/2-u/2-o,d=Math.min(n,t.canvas.width);let p=i+o,f=s+o;switch(this.MT.labelPosition){case"top-right":p=d-_-2*o,f=s+o;break;case"bottom-left":p=i+o,f=e-u-2*o;break;case"bottom-right":p=d-_-2*o,f=e-u-2*o;break;case"center":p=(Math.max(i,0)+d)/2-_/2-o,f=c;break;case"left":p=i+o,f=c;break;case"right":p=d-_-2*o,f=c}t.fillStyle=this.MT.labelBackgroundColor??l,t.fillRect(p,f,_+2*o,u+2*o),t.fillStyle=this.MT.labelColor??"#ffffff",t.textBaseline="top",t.fillText(this.MT.labelText,p+o,f+o)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}setColor(t){this.MT.borderColor=t,this.MT.fillColor=t,this.pM()}color(){return this.MT.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.MT.time1||!this.MT.time2)return!1;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=Zn(this._chart,this._series,this.MT.time2)??0,r=this._series.priceToCoordinate(this.MT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r);return t>=h&&t<=l&&i>=o&&i<=a}hitTestEndpoint(t,i){if(!this.MT.time1||!this.MT.time2)return null;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=Zn(this._chart,this._series,this.MT.time2)??0,r=this._series.priceToCoordinate(this.MT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner4":t>=h&&t<=l&&i>=o&&i<=a?"body":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"body"===t&&(this.QC={gt:this.MT.time1,bt:this.MT.price1},this.tP={gt:this.MT.time2,bt:this.MT.price2})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.QC=null,this.tP=null}updateDrag(t,i){if(!this.KC||!this.ZC)return;const s=Zn(this._chart,this._series,this.MT.time1)??0,n=this._series.priceToCoordinate(this.MT.price1)??0,e=s<(Zn(this._chart,this._series,this.MT.time2)??0),r=n<(this._series.priceToCoordinate(this.MT.price2)??0);if("body"===this.ZC&&this.QC&&this.tP){const s=dl(this.JC,t,i);this.MT.time1=this.QC.gt+s.gt,this.MT.price1=this.QC.bt+s.bt,this.MT.time2=this.tP.gt+s.gt,this.MT.price2=this.tP.bt+s.bt}else switch(this.ZC){case"corner1":e&&r?(this.MT.time1=t,this.MT.price1=i):!e&&r?(this.MT.time2=t,this.MT.price1=i):e&&!r?(this.MT.time1=t,this.MT.price2=i):(this.MT.time2=t,this.MT.price2=i);break;case"corner2":e&&r?(this.MT.time2=t,this.MT.price1=i):!e&&r?(this.MT.time1=t,this.MT.price1=i):e&&!r?(this.MT.time2=t,this.MT.price2=i):(this.MT.time1=t,this.MT.price2=i);break;case"corner3":e&&r?(this.MT.time1=t,this.MT.price2=i):!e&&r?(this.MT.time2=t,this.MT.price2=i):e&&!r?(this.MT.time1=t,this.MT.price1=i):(this.MT.time2=t,this.MT.price1=i);break;case"corner4":e&&r?(this.MT.time2=t,this.MT.price2=i):!e&&r?(this.MT.time1=t,this.MT.price2=i):e&&!r?(this.MT.time2=t,this.MT.price1=i):(this.MT.time1=t,this.MT.price1=i)}this.pM(),this.MT.onUpdate&&this.MT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[vl(this.MT.price1??0,fl(this.MT.time1)),vl(this.MT.price2??0,fl(this.MT.time2))],style:{fillColor:this.MT.fillColor,fillOpacity:this.MT.fillOpacity,borderColor:this.MT.borderColor,borderWidth:this.MT.borderWidth,borderStyle:this.MT.borderStyle,showLabel:this.MT.showLabel,labelText:this.MT.labelText,labelPosition:this.MT.labelPosition,labelColor:this.MT.labelColor,labelBackgroundColor:this.MT.labelBackgroundColor,labelFontSize:this.MT.labelFontSize}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.MT.onRemove&&this.MT.onRemove()}}function Co(t,i){return new xo(t,i)}class Po{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class To{constructor(t){this.jC=t,this.Jt=new Po(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ko extends bl{constructor(t,i){super(t,"circle",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.mT=!1,this.kx=null,this.ep=null,this.nP=null,this.ST={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.ST),this.cS(),this.ST.interactive&&!this.ST.centerTime&&this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.ST.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=Zn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.ST.radiusTime=Math.abs(e-t),this.ST.radiusPrice=Math.abs(r-n),this.mT=!1,this.nP=null,this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.ST.onUpdate&&this.ST.onUpdate()}else this.ST.centerTime=i,this.ST.centerPrice=s,this.pM()},this.ep=t=>{if(this.mT&&this.ST.centerTime)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new To(this)}drawToCanvas(t,i,s){if(!this.ST.centerTime||void 0===this.ST.centerPrice)return;const n=(Zn(this._chart,this._series,this.ST.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.ST.centerPrice)??0)*s;let r,h;if(this.mT&&this.nP){const t=(Zn(this._chart,this._series,this.nP.gt)??0)*i,l=(this._series.priceToCoordinate(this.nP.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.ST.radiusTime||void 0===this.ST.radiusPrice)return;r=this.ST.radiusTime*i,h=this.ST.radiusPrice*s}if(this.ST.fillOpacity>0){const i=this._S(this.ST.fillColor,this.mT?.05:this.ST.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.ST.borderColor,o=this.XC?this.ST.borderWidth+1:this.ST.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.ST.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.ST.borderStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.mT||this.isLocked()||this.xT(t,n,e,i,l),!this.XC&&!this.GC||this.mT||this.isLocked()||this.CT(t,n,e,r,h,i,l),this.ST.showLabel&&this.ST.labelText&&!this.mT&&this.xP(t,n,e,i,l)}xT(t,i,s,n,e){const r=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r/2,0,2*Math.PI),t.fill(),t.stroke()}CT(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s-e},{ut:i+n,ct:s},{ut:i,ct:s+e},{ut:i-n,ct:s}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}xP(t,i,s,n,e){const r=6*n,h=12*n;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const l=t.measureText(this.ST.labelText).width,o=h,a=i-l/2-r,_=s-o/2-r;t.fillStyle=e,t.fillRect(a,_,l+2*r,o+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.ST.labelText,a+r,_+r)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}setColor(t){this.ST.borderColor=t,this.ST.fillColor=t,this.pM()}color(){return this.ST.borderColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.ST.centerTime||void 0===this.ST.radiusTime)return!1;const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=(t-s)/this.ST.radiusTime,r=(i-n)/this.ST.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.ST.centerTime||void 0===this.ST.radiusTime)return null;const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=this.ST.radiusTime,r=this.ST.radiusPrice;if(Math.abs(t-s)<=10&&Math.abs(i-n)<=10)return"center";const h=[{ut:s,ct:n-r},{ut:s+e,ct:n},{ut:s,ct:n+r},{ut:s-e,ct:n}];for(const s of h)if(Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10)return"edge";return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P="center"===t?{gt:this.ST.centerTime,bt:this.ST.centerPrice}:null}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC&&this.ZC){if("center"===this.ZC&&this.$P){const s=dl(this.JC,t,i);this.ST.centerTime=this.$P.gt+s.gt,this.ST.centerPrice=this.$P.bt+s.bt}else if("edge"===this.ZC){const s=Zn(this._chart,this._series,this.ST.centerTime)??0,n=this._series.priceToCoordinate(this.ST.centerPrice)??0,e=Zn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.ST.radiusTime=Math.abs(e-s),this.ST.radiusPrice=Math.abs(r-n)}this.pM(),this.ST.onUpdate&&this.ST.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[vl(this.ST.centerPrice??0,fl(this.ST.centerTime))],style:{fillColor:this.ST.fillColor,fillOpacity:this.ST.fillOpacity,borderColor:this.ST.borderColor,borderWidth:this.ST.borderWidth,borderStyle:this.ST.borderStyle,showLabel:this.ST.showLabel,labelText:this.ST.labelText},extra:{radiusTime:this.ST.radiusTime,radiusPrice:this.ST.radiusPrice}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.ST.onRemove&&this.ST.onRemove()}}function Do(t,i){return new ko(t,i)}class Ro{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Fo{constructor(t){this.jC=t,this.Jt=new Ro(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vo extends bl{constructor(t,i){super(t,"arrow",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.PT=-1,this.mT=!1,this.kx=null,this.TT=null,this.ep=null,this.nP=null,this.kT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.kT),this.cS(),!this.kT.interactive||this.kT.points&&0!==this.kT.points.length||this.rP()}rP(){this.mT=!0,this.kx=t=>{if(!t.point)return;if(Sl(this._chart))return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kT.points||(this.kT.points=[]),this.kT.points.push({time:i,price:s}),this.pM(),this.kT.onUpdate&&this.kT.onUpdate())},this.ep=t=>{if(this.mT)if(t.point){const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.nP={gt:i,bt:s},this.pM())}else this.nP=null,this.pM()},this.TT=t=>{this.mT&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.kx),this._chart.subscribeCrosshairMove(this.ep);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.TT)}finishDrawing(){if(this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.TT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.TT),this.TT=null}this.mT=!1,this.nP=null,this.pM(),this.kT.onComplete&&this.kT.onComplete()}isDrawing(){return this.mT}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Fo(this)}drawToCanvas(t,i,s){if(!this.kT.points||0===this.kT.points.length)return;const n=this.kT.lineColor,e=this.XC||this.GC&&!this.isLocked()?this.kT.lineWidth+1:this.kT.lineWidth,r=[];for(const t of this.kT.points)try{let n=Zn(this._chart,this._series,t.time);if(null===n){const i=this._chart.timeScale(),s=i.timeToIndex(t.time,!0);null!=s&&(n=i.logicalToCoordinate(s))}if(null==n)continue;const e=this._series.priceToCoordinate(t.price);if(null===e)continue;r.push({ut:n*i,ct:e*s})}catch{continue}if(0===r.length&&!this.mT)return;let h=null;if(this.mT&&this.nP&&this.kT.points.length>0){h={ut:(Zn(this._chart,this._series,this.nP.gt)??0)*i,ct:(this._series.priceToCoordinate(this.nP.bt)??0)*s}}if(r.length>1){t.strokeStyle=n,t.lineWidth=e*i,t.beginPath(),t.moveTo(r[0].ut,r[0].ct);for(let i=1;i<r.length;i++)t.lineTo(r[i].ut,r[i].ct);t.stroke()}if(h&&r.length>0){const s=r[r.length-1];t.strokeStyle=n,t.lineWidth=e*i,t.globalAlpha=.5,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(h.ut,h.ct),t.stroke(),t.setLineDash([]),t.globalAlpha=1}if(this.kT.showArrowHead&&r.length>1&&this.DT(t,r[r.length-2],r[r.length-1],i,n),this.kT.showCircles)for(let s=0;s<r.length;s++)this.RT(t,r[s].ut,r[s].ct,i,n,0===s)}DT(t,i,s,n,e){const r=12*n,h=Math.atan2(s.ct-i.ct,s.ut-i.ut),l={ut:s.ut-r*Math.cos(h-Math.PI/6),ct:s.ct-r*Math.sin(h-Math.PI/6)},o={ut:s.ut-r*Math.cos(h+Math.PI/6),ct:s.ct-r*Math.sin(h+Math.PI/6)};t.fillStyle=e,t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(l.ut,l.ct),t.lineTo(o.ut,o.ct),t.closePath(),t.fill()}RT(t,i,s,n,e,r){const h=this.kT.circleRadius*n;t.beginPath(),t.arc(i,s,h,0,2*Math.PI),r?(t.fillStyle=e,t.fill()):(t.strokeStyle=e,t.lineWidth=2*n,t.stroke(),t.fillStyle="#ffffff",t.fill(),t.strokeStyle=e,t.stroke())}setColor(t){this.kT.lineColor=t,this.pM()}color(){return this.kT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.kT.points||0===this.kT.points.length)return!1;for(let s=0;s<this.kT.points.length-1;s++)try{const n=this.kT.points[s],e=this.kT.points[s+1];let r=Zn(this._chart,this._series,n.time);if(null===r){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(r=t.logicalToCoordinate(i))}let h=Zn(this._chart,this._series,e.time);if(null===h){const t=this._chart.timeScale(),i=t.timeToIndex(e.time,!0);null!=i&&(h=t.logicalToCoordinate(i))}const l=this._series.priceToCoordinate(n.price),o=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===o)continue;if(this.vP(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.kT.points)try{let n=Zn(this._chart,this._series,s.time);if(null===n){const t=this._chart.timeScale(),i=t.timeToIndex(s.time,!0);null!=i&&(n=t.logicalToCoordinate(i))}const e=this._series.priceToCoordinate(s.price);if(null==n||null===e)continue;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=8)return!0}catch{continue}return!1}vP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.kT.points||0===this.kT.points.length)return null;for(let s=0;s<this.kT.points.length;s++)try{const n=this.kT.points[s];let e=Zn(this._chart,this._series,n.time);if(null===e){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(e=t.logicalToCoordinate(i))}const r=this._series.priceToCoordinate(n.price);if(null==e||null===r)continue;if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return s}catch{continue}return null}startDrag(t){this.KC=!0,this.PT=t}stopDrag(){this.KC=!1,this.PT=-1}updateDrag(t,i){this.KC&&-1!==this.PT&&this.kT.points&&this.PT>=0&&this.PT<this.kT.points.length&&(this.kT.points[this.PT]={time:t,price:i},this.pM(),this.kT.onUpdate&&this.kT.onUpdate())}getPoints(){return this.kT.points||[]}addPoint(t){this.kT.points||(this.kT.points=[]),this.kT.points.push(t),this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.kT.points||[]).map(t=>ml(t)),style:{lineColor:this.kT.lineColor,lineWidth:this.kT.lineWidth,showArrowHead:this.kT.showArrowHead,showCircles:this.kT.showCircles,circleRadius:this.kT.circleRadius}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.mT}remove(){if(this.kx&&(this._chart.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.TT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.TT),this.TT=null}this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.kT.onRemove&&this.kT.onRemove()}}function Io(t,i){return new Vo(t,i)}class Ao{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Lo{constructor(t){this.jC=t,this.Jt=new Ao(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bo extends bl{constructor(t,i){super(t,"brush",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.FT=!1,this.mT=!1,this.VT=[],this.IT=!1,this.Rf=null,this.BS=null,this.US=null,this.jS=null,this.XS=null,this.AT=void 0,this.HS=null,this.KC=!1,this.JC=null,this.kP=null,this.LT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.LT),this.cS(),0===(this.LT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.FT)return;const t=this._chart.chartElement();t&&(this.Rf=t,this.FT=!0,this.US=t=>this.qS(t),this.jS=t=>this.YS(t),this.XS=()=>this.GS(),this.HS=t=>{this.AT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.HS),t.addEventListener("pointerdown",this.US,!0),t.addEventListener("pointermove",this.jS,!0),t.addEventListener("pointerup",this.XS,!0),t.addEventListener("pointercancel",this.XS,!0))}stopDrawingMode(){if(!this.FT)return;this.BT(),this.FT=!1;const t=this.Rf;t&&(this.US&&t.removeEventListener("pointerdown",this.US,!0),this.jS&&t.removeEventListener("pointermove",this.jS,!0),this.XS&&(t.removeEventListener("pointerup",this.XS,!0),t.removeEventListener("pointercancel",this.XS,!0))),this.HS&&(this._chart.unsubscribeCrosshairMove(this.HS),this.HS=null),this.US=null,this.jS=null,this.XS=null,this.Rf=null}isDrawingModeActive(){return this.FT}isComplete(){return(this.LT.points??[]).length>0}qS(t){if(this.OT())return;const i=this.ET(t,!1);null!==i&&(this.mT=!0,this.VT=[i],this.BS=t.pointerId,yl(this._chart,!0),this.Rf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.WT())}YS(t){if(!this.mT)return;const i=this.ET(t,!0);if(null===i)return;const s=this.VT[this.VT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.LT.sampleDistance??4)||(this.VT.push(i),t.preventDefault(),t.stopPropagation(),this.WT())}GS(){this.mT&&this.BT()}BT(){if(!this.mT)return;this.mT=!1,this.wx();const t=[];for(const i of this.VT){const s=Kn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.VT=[],t.length<2?this.pM():(this.LT.points=t,this.stopDrawingMode(),this.pM(),this.LT.onUpdate&&this.LT.onUpdate(),this.LT.onComplete&&this.LT.onComplete())}OT(){const t=this.AT;return"string"==typeof t&&t.split("#")[0]!==this.id}wx(){null!==this.BS&&(this.Rf&&this.Rf.hasPointerCapture(this.BS)&&this.Rf.releasePointerCapture(this.BS),this.BS=null)}ET(t,i){const s=this.zT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.sC;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}zT(){const t=this.$T();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,sC:i.top,ts:n,qt:i.height}}$T(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}WT(){this.IT||(this.IT=!0,requestAnimationFrame(()=>{this.IT=!1,this.pM()}))}drawToCanvas(t,i,s){const n=this.mT?this.VT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.HT(i,s);if(0===n.length)return;const e=this.XC;if(t.strokeStyle=this.LT.color,t.lineWidth=(this.LT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.LT.smoothing&&n.length>2){for(let i=1;i<n.length-1;i++){const s=(n[i].ut+n[i+1].ut)/2,e=(n[i].ct+n[i+1].ct)/2;t.quadraticCurveTo(n[i].ut,n[i].ct,s,e)}t.lineTo(n[n.length-1].ut,n[n.length-1].ct)}else for(let i=1;i<n.length;i++)t.lineTo(n[i].ut,n[i].ct);t.stroke(),!e&&!this.GC||this.isLocked()||(this.fP(t,n[0],i),this.fP(t,n[n.length-1],i))}fP(t,i,s){t.fillStyle=this.LT.color,t.strokeStyle="#ffffff",t.lineWidth=2*s,t.beginPath(),t.arc(i.ut,i.ct,5*s,0,2*Math.PI),t.fill(),t.stroke()}HT(t,i){const s=this.LT.points??[],n=[];for(const e of s){const s=Zn(this._chart,this._series,e.time),r=this._series.priceToCoordinate(e.price);null!==s&&null!==r&&n.push({ut:s*t,ct:r*i})}return n}hitTest(t,i){const s=this.HT(1,1);for(let n=1;n<s.length;n++)if(Oo(t,i,s[n-1],s[n])<=8)return!0;return!1}hitTestEndpoint(t,i){return this.hitTest(t,i)?"stroke":null}startDrag(t,i){this.KC=!0,this.JC=i,this.kP=(this.LT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.kP;if(!this.KC||null===s||!this.LT.points)return;const n=dl(this.JC,t,i);this.LT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.pM(),this.LT.onUpdate&&this.LT.onUpdate()}stopDrag(){this.KC=!1,this.JC=null,this.kP=null}setColor(t){this.LT.color=t,this.pM()}color(){return this.LT.color??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}cS(){this.eh=new Lo(this);const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):null}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.stopDrawingMode(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null),this.eh=null,this.LT.onRemove&&this.LT.onRemove()}_serializeShape(){return{type:"brush",points:(this.LT.points??[]).map(ml),style:{color:this.LT.color,lineWidth:this.LT.lineWidth,smoothing:this.LT.smoothing}}}getPoints(){return this.LT.points??[]}}function Oo(t,i,s,n){const e=n.ut-s.ut,r=n.ct-s.ct,h=e*e+r*r;if(0===h)return Math.hypot(t-s.ut,i-s.ct);let l=((t-s.ut)*e+(i-s.ct)*r)/h;return l=Math.max(0,Math.min(1,l)),Math.hypot(t-(s.ut+l*e),i-(s.ct+l*r))}function Eo(t,i={}){return new Bo(t,i)}class Wo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zo{constructor(t){this.jC=t,this.Jt=new Wo(t)}renderer(){return this.jC.isComplete()?this.Jt:null}}class $o extends bl{constructor(t,i){super(t,"text-tool",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.NT=!1,this.UT=null,this.bP=null,this.qT={text:"Double-click to edit",fontSize:14,fontFamily:"Arial, sans-serif",textColor:"#FFFFFF",backgroundColor:"#2962FF",backgroundOpacity:.8,padding:8,borderColor:"#2962FF",borderWidth:1,textAlign:"left",maxWidth:200,anchor:"top-left",pointer:!1,borderRadius:0,...i},this._registerOptions(this.qT),this.cS(),this.jT(),this.qT.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>{this.setPosition(t.gt,t.bt),this.qT.onComplete&&this.qT.onComplete()}))}jT(){const t=t=>{if(!this.NT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.qT.text&&""!==this.qT.text.trim()&&"Type here..."!==this.qT.text||this.remove())};this.UT=t,this._chart.subscribeClick(t)}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new zo(this)}getTime(){return this.qT.time}getPrice(){return this.qT.price}getText(){return this.qT.text||""}getOptions(){return this.qT}setPosition(t,i){this.qT.time=t,this.qT.price=i,this._update()}setText(t){this.qT.text=t,this._update(),this.qT.onTextChange&&this.qT.onTextChange(t)}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}isComplete(){return!this.bP?.mP()&&!(!this.qT.time||void 0===this.qT.price)}setColor(t){this.qT.textColor=t,this.qT.borderColor=t,this.pM()}color(){return this.qT.textColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this._update())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this._update())}isHovered(){return this.GC}setEditing(t){this.NT!==t&&(this.NT=t,this._update())}isEditing(){return this.NT}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.qT.time,n=this.qT.price,e=Zn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.qT.fontSize||14,l=this.qT.padding??8,o=this.qT.text||"",a=.6*h,_=Math.min(o.length*a,this.qT.maxWidth||200)+2*l,u=h+2*l,c=this.YT(u),d=this.XT(e,r,_,u,c),p=d.qh-("left"===this.qT.anchor?c:0),f=d.qh+_+("right"===this.qT.anchor?c:0);return t>=p&&t<=f&&i>=d.sC&&i<=d.sC+u}YT(t){const i=this.qT.anchor;return!this.qT.pointer||"left"!==i&&"right"!==i?0:Math.round(.35*t)}XT(t,i,s,n,e){switch(this.qT.anchor){case"left":return{qh:t+e,sC:i-n/2};case"right":return{qh:t-e-s,sC:i-n/2};case"center":return{qh:t-s/2,sC:i-n/2};default:return{qh:t,sC:i}}}GT(t,i,s,n,e,r,h,l,o){const a=Math.max(0,Math.min(o,n/2,e/2));t.beginPath(),t.moveTo(i+a,s),t.lineTo(i+n-a,s),t.arcTo(i+n,s,i+n,s+a,a),r>0&&"right"===this.qT.anchor&&(t.lineTo(i+n,l-r),t.lineTo(h,l),t.lineTo(i+n,l+r)),t.lineTo(i+n,s+e-a),t.arcTo(i+n,s+e,i+n-a,s+e,a),t.lineTo(i+a,s+e),t.arcTo(i,s+e,i,s+e-a,a),r>0&&"left"===this.qT.anchor&&(t.lineTo(i,l+r),t.lineTo(h,l),t.lineTo(i,l-r)),t.lineTo(i,s+a),t.arcTo(i,s,i+a,s,a),t.closePath()}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.qT.time,n=this.qT.price,e=Zn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0;return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"anchor":null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,this.$P={gt:this.qT.time,bt:this.qT.price}}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC){if("body"===this.ZC&&this.$P){const s=dl(this.JC,t,i);this.setPosition(this.$P.gt+s.gt,this.$P.bt+s.bt)}else this.setPosition(t,i);this.qT.onUpdate&&this.qT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.qT.time,e=this.qT.price,r=this.qT.text||"",h=(Zn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.qT.fontSize||14)*i,a=(this.qT.padding??8)*i,_=(this.qT.maxWidth||200)*i;t.font=`${o}px ${this.qT.fontFamily||"Arial"}`,t.textBaseline="top";const u=r.split(" "),c=[];let d="";for(const i of u){const s=d?`${d} ${i}`:i;t.measureText(s).width>_&&d?(c.push(d),d=i):d=s}d&&c.push(d);let p=0;for(const i of c){const s=t.measureText(i);p=Math.max(p,s.width)}const f=p+2*a,v=1.2*o,m=c.length*v+2*a,w=this.YT(m),{qh:g,sC:b}=this.XT(h,l,f,m,w),M=(this.qT.borderRadius??0)*i,y=this.qT.backgroundOpacity??.8,S=this.qT.backgroundColor||"#2962FF";y>0&&(t.fillStyle=this._S(S,y),this.GT(t,g,b,f,m,w,h,l,M),t.fill()),(this.XC||this.GC)&&(t.strokeStyle=this.qT.borderColor??"#FFFFFF",t.lineWidth=(this.qT.borderWidth||1)*i*(this.XC?2:1),this.GT(t,g,b,f,m,w,h,l,M),t.stroke()),t.fillStyle=this.qT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=g+a;if("center"===this.qT.textAlign){n=g+(f-t.measureText(s).width)/2}else if("right"===this.qT.textAlign){n=g+f-t.measureText(s).width-a}const e=b+a+i*v;t.fillText(s,n,e)}if((this.XC||this.GC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.qT.textColor??"#2962ff",t.beginPath(),t.arc(h,l,s,0,2*Math.PI),t.fill(),t.fillStyle="#FFFFFF",t.beginPath(),t.arc(h,l,s-2*i,0,2*Math.PI),t.fill()}}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}_serializeShape(){return{type:"text",points:[vl(this.qT.price??0,fl(this.qT.time))],style:{fontSize:this.qT.fontSize,fontFamily:this.qT.fontFamily,textColor:this.qT.textColor,backgroundColor:this.qT.backgroundColor,backgroundOpacity:this.qT.backgroundOpacity,padding:this.qT.padding,borderColor:this.qT.borderColor,borderWidth:this.qT.borderWidth,textAlign:this.qT.textAlign,maxWidth:this.qT.maxWidth,anchor:this.qT.anchor,pointer:this.qT.pointer,borderRadius:this.qT.borderRadius},extra:{text:this.qT.text}}}remove(){this.bP?.wP(),this.UT&&(this._chart.unsubscribeClick(this.UT),this.UT=null),this.jb&&this._series&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.qT.onRemove&&this.qT.onRemove()}}function Ho(t,i){return new $o(t,i)}class No{constructor(t){this.KT=t}calculatePips(t,i){return Math.abs(i-t)/this.KT.pipValue}calculatePercent(t,i){return(i-t)/t*100}calculateRiskReward(t,i,s){const n=Math.abs(t-i),e=Math.abs(s-t);return 0===n?0:e/n}calculateMetrics(t,i,s,n){const e={entryPrice:t,stopLoss:i,takeProfit:s,quantity:n,stopLossPips:this.calculatePips(t,i),takeProfitPips:this.calculatePips(t,s),stopLossPercent:this.calculatePercent(t,i),takeProfitPercent:this.calculatePercent(t,s),riskRewardRatio:this.calculateRiskReward(t,i,s)};if(void 0!==n){const r=Math.abs(t-i),h=Math.abs(s-t);e.stopLossAmount=r*n,e.takeProfitAmount=h*n}return e}formatPips(t,i=1){return`${t>=0?"+":""}${t.toFixed(i)} pips`}formatPercent(t,i=2){return`${t>=0?"+":""}${t.toFixed(i)}%`}formatRiskReward(t,i=2){return`1:${t.toFixed(i)}`}updatePipConfig(t){this.KT={...this.KT,...t}}getPipConfig(){return{...this.KT}}}function Uo(t){const i=t.toString().split("."),s=i.length>1?i[1].length:0;let n;return n=s>=5?1e-5:4===s?1e-4:3===s?.001:2===s?.01:1===s?.1:1,{pipValue:n,decimals:s}}function qo(t,i){return"number"==typeof t?Uo(t):void 0!==i?Uo(i):{pipValue:.1,decimals:1}}class jo{constructor(t){this.KT=t}calculateMetrics(t,i,s,n,e){const r=n-i;return{point1:{time:t,price:i},point2:{time:s,price:n},priceDifference:r,pricePercent:r/i*100,pips:Math.abs(r)/this.KT.pipValue,timeDifference:this.ZT(t,s),barCount:e}}ZT(t,i){return"number"==typeof t&&"number"==typeof i?Math.abs(i-t):0}formatPriceDifference(t,i=5){return`${t>=0?"+":""}${t.toFixed(i)}`}formatPips(t,i=1){return`${t.toFixed(i)} pips`}formatPercent(t,i=2){return`${t>=0?"+":""}${t.toFixed(i)}%`}formatTimeDifference(t){if(0===t)return"N/A";const i=Math.floor(t/86400),s=Math.floor(t%86400/3600),n=Math.floor(t%3600/60);return i>0?`${i}d ${s}h`:s>0?`${s}h ${n}m`:n>0?`${n}m`:`${t}s`}formatBarCount(t){return`${t} ${1===t?"bar":"bars"}`}updatePipConfig(t){this.KT={...this.KT,...t}}getPipConfig(){return{...this.KT}}}class Yo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xo{constructor(t){this.jC=t,this.Jt=new Yo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class Go extends bl{constructor(t,i){super(t,"ruler-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.oT=null,this.iP=!1,this.XC=!1,this.GC=!1,this.nP=null,this.KC=!1,this.aT=null,this.ep=null,this.JT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.JT);const s=this.JT.pipConfig||qo(this.JT.symbol||"DEFAULT");this.uT=new jo(s),this.cS(),this.JT.interactive?this.rP():this.JT.point1Time&&this.JT.point2Time&&(this.iP=!0,this.cT())}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Xo(this)}rP(){this.oT=new Pl(this._chart,this._series,{HC:t=>{this.JT.point1Time=t.gt,this.JT.point1Price=t.bt,this.pM()},NC:t=>{this.JT.point2Time=t.gt,this.JT.point2Price=t.bt},UC:(t,i)=>{this.JT.point1Time=t.gt,this.JT.point1Price=t.bt,this.JT.point2Time=i.gt,this.JT.point2Price=i.bt,this.iP=!0,this.nP=null,this.cT(),this.dT(),this.pM()},qC:t=>{this.nP=t,this.pM()}}),this.oT.FC()}drawToCanvas(t,i,s){if(!this.iP&&this.JT.point1Time&&this.nP)return void this.pP(t,i,s);if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return;const n=(Zn(this._chart,this._series,this.JT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.JT.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.JT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.JT.point2Price)??0)*s;(this.XC||this.GC&&!this.isLocked())&&(t.strokeStyle=this.JT.selectionColor,t.lineWidth=this.JT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.QT(t,n,e,r,h,i),this.fP(t,n,e,i),this.fP(t,r,h,i),this.JT.showLabel&&this.Gb&&this.xP(t,n,e,r,h,i,s)}QT(t,i,s,n,e,r){const h=this.JT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*r,t.beginPath(),"price"===h)for(const r of[s,e])t.moveTo(Math.min(i,n)-l/2,r),t.lineTo(Math.max(i,n)+l/2,r);else for(const r of[i,n])t.moveTo(r,Math.min(s,e)-l/2),t.lineTo(r,Math.max(s,e)+l/2);t.stroke()}fP(t,i,s,n){const e=this.XC?this.JT.selectionColor:this.JT.lineColor,r=this.XC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.XC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}pP(t,i,s){if(!this.JT.point1Time||!this.nP)return;const n=(Zn(this._chart,this._series,this.JT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.JT.point1Price)??0)*s,r=(Zn(this._chart,this._series,this.nP.gt)??0)*i,h=(this._series.priceToCoordinate(this.nP.bt)??0)*s;t.strokeStyle=this.JT.lineColor,t.lineWidth=this.JT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.fP(t,n,e,i),t.globalAlpha=.5,this.fP(t,r,h,i),t.globalAlpha=1}xP(t,i,s,n,e,r,h){if(!this.Gb)return;const l=(i+n)/2,o=(s+e)/2,a=this.JT.measure??"both",_=[];"time"!==a&&(_.push(this.uT.formatPips(this.Gb.pips)),_.push(this.uT.formatPercent(this.Gb.pricePercent))),"price"!==a&&_.push(this.uT.formatBarCount(this.Gb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.JT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.JT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}cT(){if(!this.JT.point1Time||!this.JT.point2Time||void 0===this.JT.point1Price||void 0===this.JT.point2Price)return;const t=this.tk();this.Gb=this.uT.calculateMetrics(this.JT.point1Time,this.JT.point1Price,this.JT.point2Time,this.JT.point2Price,t),this.JT.onUpdate&&this.Gb&&this.JT.onUpdate(this.Gb)}tk(){if(!this.JT.point1Time||!this.JT.point2Time)return 0;const t=Zn(this._chart,this._series,this.JT.point1Time),i=Zn(this._chart,this._series,this.JT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.JT.point1Time=t,this.JT.point1Price=i,this.JT.point2Time=s,this.JT.point2Price=n,this.cT(),this.pM()}getMetrics(){return this.Gb}remove(){this.destroy()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.oT&&(this.oT.m(),this.oT=null),this.fT(),this.JT.onRemove&&this.JT.onRemove()}dT(){this.ep=t=>{this.pT(t)},this._chart.subscribeCrosshairMove(this.ep)}fT(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}pT(t){if(!t.point)return;const i=Kn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.XC||!this.KC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.aT?(this.JT.point1Time=i,this.JT.point1Price=s):"point2"===this.aT&&(this.JT.point2Time=i,this.JT.point2Price=s),this.cT(),this.pM())}startDrag(t){this.KC=!0,this.aT=t}stopDrag(){this.KC=!1,this.aT=null}updateDrag(t,i){this.KC&&this.aT&&("point1"===this.aT?(this.JT.point1Time=t,this.JT.point1Price=i):(this.JT.point2Time=t,this.JT.point2Price=i),this.cT(),this.pM())}hitTestEndpoint(t,i){if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return null;const s=Zn(this._chart,this._series,this.JT.point1Time)??0,n=this._series.priceToCoordinate(this.JT.point1Price)??0,e=Zn(this._chart,this._series,this.JT.point2Time)??0,r=this._series.priceToCoordinate(this.JT.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.cT(),this.pM()}_serializeShape(){return{type:"ruler",points:[vl(this.JT.point1Price??0,fl(this.JT.point1Time)),vl(this.JT.point2Price??0,fl(this.JT.point2Time))],style:{lineColor:this.JT.lineColor,lineWidth:this.JT.lineWidth,showLabel:this.JT.showLabel,labelBackgroundColor:this.JT.labelBackgroundColor,labelTextColor:this.JT.labelTextColor,selectionColor:this.JT.selectionColor,selectionLineWidth:this.JT.selectionLineWidth},extra:{symbol:this.JT.symbol,pipConfig:this.JT.pipConfig,measure:this.JT.measure}}}setColor(t){this.JT.lineColor=t,this.pM()}color(){return this.JT.lineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}isSelected(){return this.XC}isComplete(){return this.iP}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.iP||!this.JT.point1Time||!this.JT.point2Time)return!1;const s=Zn(this._chart,this._series,this.JT.point1Time)??0,n=this._series.priceToCoordinate(this.JT.point1Price)??0,e=Zn(this._chart,this._series,this.JT.point2Time)??0,r=this._series.priceToCoordinate(this.JT.point2Price)??0;return this.ik(t,i,s,n,e,r)<=(this.XC?12:8)}ik(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;let a,_,u=-1;0!==o&&(u=((t-s)*h+(i-n)*l)/o),u<0?(a=s,_=n):u>1?(a=e,_=r):(a=s+u*h,_=n+u*l);const c=t-a,d=i-_;return Math.sqrt(c*c+d*d)}}function Ko(t,i){return new Go(t,i)}class Zo{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Jo{constructor(t){this.jC=t,this.Jt=new Zo(t)}renderer(){return this.jC.isVisible()?this.Jt:null}}class Qo extends bl{constructor(t,i){super(t,"position-tool",i),this.jb=null,this.YC=null,this.Gb=null,this.eh=null,this.XC=!1,this.GC=!1,this.bP=null,this.KC=!1,this.ZC=null,this.JC=null,this.$P=null,this.sk=null,this.nk=null,this.ek={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.ek);const s=this.ek.pipConfig||qo(this.ek.entryPrice);this.uT=new No(s),this.cS(),this.cT(),this.ek.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){const i=this.ek,s=t.bt-i.entryPrice;i.entryPrice=t.bt,i.entryTime=t.gt,void 0!==i.stopLoss&&(i.stopLoss+=s),void 0!==i.takeProfit&&(i.takeProfit+=s),i.endTime=Kn(this._chart,this._series,Il(this._chart,t.ut))??void 0,this.cT(),this.pM()}isComplete(){return!this.bP?.mP()}rk(){const t=Zn(this._chart,this._series,this.ek.entryTime)??0;return{hk:t,lk:Zn(this._chart,this._series,this.ek.endTime)??t+Vl(this._chart)}}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new Jo(this)}drawToCanvas(t,i,s){if(!this.isComplete())return;if(this.sk&&this.ek.takeProfit){const n=this._chart.timeScale();this.ak(t,this.sk,i,s,n),(this.GC||this.XC)&&this.xP(t,this.sk,"profit",i,s,n)}if(this.nk&&this.ek.stopLoss){const n=this._chart.timeScale();if(this.ak(t,this.nk,i,s,n),this.GC||this.XC){const n=this._chart.timeScale();this.xP(t,this.nk,"loss",i,s,n)}}const n=this._chart.timeScale();if(this._k(t,i,s,n),this.ek.takeProfit){const n=this._chart.timeScale();this.fP(t,this.ek.takeProfit,this.ek.profitColor,i,s,n)}if(this.ek.stopLoss){const n=this._chart.timeScale();this.fP(t,this.ek.stopLoss,this.ek.lossColor,i,s,n)}}ak(t,i,s,n,e){const r=this.rk(),h=r.hk*s,l=r.lk*s,o=(this._series.priceToCoordinate(i.uk)??0)*n,a=(this._series.priceToCoordinate(i.ck)??0)*n;t.fillStyle=this._S(i.R,.15),t.fillRect(h,Math.min(o,a),l-h,Math.abs(a-o)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(h,a),t.lineTo(l,a),t.stroke()}_k(t,i,s,n){const e=this.rk(),r=e.hk*i,h=e.lk*i,l=(this._series.priceToCoordinate(this.ek.entryPrice)??0)*s,o=this.ek.entryLineColor;t.strokeStyle=o,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(r,l),t.lineTo(h,l),t.stroke(),t.setLineDash([]),t.strokeStyle=this.ek.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(r,0),t.lineTo(r,a),t.stroke(),t.setLineDash([]),!this.XC&&!this.GC||this.isLocked())t.fillStyle=this.ek.entryLineColor,t.beginPath(),t.arc(r,l,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(r,l,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(h-s/2,l-s/2,s,s),t.strokeRect(h-s/2,l-s/2,s,s)}}cT(){this.ek.stopLoss&&this.ek.takeProfit&&(this.Gb=this.uT.calculateMetrics(this.ek.entryPrice,this.ek.stopLoss,this.ek.takeProfit,this.ek.quantity),this.dk(),this.ek.onUpdate&&this.Gb&&this.ek.onUpdate(this.Gb))}dk(){const t=this.pk();this.ek.takeProfit&&(this.sk={fk:this.ek.entryTime,vk:t,uk:this.ek.entryPrice,ck:this.ek.takeProfit,R:this.ek.profitColor,Oy:this.ek.opacity}),this.ek.stopLoss&&(this.nk={fk:this.ek.entryTime,vk:t,uk:this.ek.entryPrice,ck:this.ek.stopLoss,R:this.ek.lossColor,Oy:this.ek.opacity})}pk(){this._chart.timeScale().getVisibleLogicalRange();return this.ek.entryTime}xP(t,i,s,n,e,r){if(!this.Gb)return;const h=(Zn(this._chart,this._series,this.ek.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.ck)??0)*e,o="profit"===s,a=o?this.Gb.takeProfitPips:this.Gb.stopLossPips,_=o?this.ek.takeProfit:this.ek.stopLoss,u=this.Gb.riskRewardRatio,c=o?`Objetivo: ${_?.toFixed(5)} (${a.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${a.toFixed(1)} pips)`;t.font=11*n+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const d=6*n,p=t.measureText(c).width+2*d,f=20*n,v=3*e,m=h+8*n,w=l<=(this._series.priceToCoordinate(this.ek.entryPrice)??0)*e?l-f-v:l+v;t.fillStyle=i.R,t.fillRect(m,w,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,m+d,w+f/2)}fP(t,i,s,n,e,r){const h=this.rk(),l=h.hk*n,o=h.lk*n,a=(this._series.priceToCoordinate(i)??0)*e,_=s;t.fillStyle=_,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(l,a,5*n,0,2*Math.PI),t.fill(),t.stroke();const u=8*n,c=s;t.fillStyle=c,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-u/2,a-u/2,u,u),t.strokeRect(o-u/2,a-u/2,u,u)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}updatePosition(t){this.ek={...this.ek,...t},this.cT(),this._update()}getMetrics(){return this.Gb}setStopLoss(t){this.ek.stopLoss=t,this.cT(),this._update()}setTakeProfit(t){this.ek.takeProfit=t,this.cT(),this._update()}setEntryPrice(t){this.ek.entryPrice=t,this.cT(),this._update()}_serializeShape(){return{type:"position",points:[vl(this.ek.entryPrice,fl(this.ek.entryTime))],style:{profitColor:this.ek.profitColor,lossColor:this.ek.lossColor,entryLineColor:this.ek.entryLineColor,opacity:this.ek.opacity,showTooltips:this.ek.showTooltips},extra:{endTime:fl(this.ek.endTime),stopLoss:this.ek.stopLoss,takeProfit:this.ek.takeProfit,quantity:this.ek.quantity,pipConfig:this.ek.pipConfig}}}setColor(t){this.ek.entryLineColor=t,this.pM()}color(){return this.ek.entryLineColor??""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):this.hitTest(t,i)?cl(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||!this.ek.stopLoss&&!this.ek.takeProfit)return!1;const{hk:s,lk:n}=this.rk(),e=Math.min(s,n),r=Math.max(s,n);if(this.ek.takeProfit&&this.ek.stopLoss){const n=this._series.priceToCoordinate(this.ek.takeProfit)??0,h=this._series.priceToCoordinate(this.ek.stopLoss)??0,l=Math.min(n,h),o=Math.max(n,h);if(t>=e&&t<=r&&i>=l&&i<=o)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=l&&i<=o)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const{hk:s,lk:n}=this.rk(),e=Math.min(s,n),r=Math.max(s,n);if(this.ek.takeProfit){const n=this._series.priceToCoordinate(this.ek.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.ek.stopLoss){const n=this._series.priceToCoordinate(this.ek.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.ek.takeProfit){const s=this._series.priceToCoordinate(this.ek.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.ek.stopLoss){const s=this._series.priceToCoordinate(this.ek.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const h=this._series.priceToCoordinate(this.ek.entryPrice)??0;if(t>=e&&t<=r&&Math.abs(i-h)<=8)return"entry";if(this.ek.takeProfit&&this.ek.stopLoss){const s=this._series.priceToCoordinate(this.ek.takeProfit)??0,n=this._series.priceToCoordinate(this.ek.stopLoss)??0,h=Math.min(s,n),l=Math.max(s,n);if(t>=e&&t<=r&&i>=h&&i<=l)return"move"}return null}startDrag(t,i){this.KC=!0,this.ZC=t,this.JC=i,"move"===t&&(this.$P={mk:this.ek.entryPrice,wk:this.ek.entryTime??null,aS:this.ek.endTime??null,gk:this.ek.takeProfit??null,bk:this.ek.stopLoss??null})}stopDrag(){this.KC=!1,this.ZC=null,this.JC=null,this.$P=null}updateDrag(t,i){if(this.KC&&this.ZC){if("entry"===this.ZC)this.ek.entryPrice=i;else if("move"===this.ZC){if(this.$P){const s=dl(this.JC,t,i),n=this.$P;this.ek.entryPrice=n.mk+s.bt,null!==n.gk&&(this.ek.takeProfit=n.gk+s.bt),null!==n.bk&&(this.ek.stopLoss=n.bk+s.bt),null!==n.wk&&(this.ek.entryTime=this.Mk(n.wk,s.gt)),null!==n.aS&&(this.ek.endTime=this.Mk(n.aS,s.gt))}}else"tp"===this.ZC||"tp-right"===this.ZC?(this.ek.takeProfit=i,"tp-right"===this.ZC?this.ek.endTime=t:this.ek.entryTime=t):"sl"!==this.ZC&&"sl-right"!==this.ZC||(this.ek.stopLoss=i,"sl-right"===this.ZC?this.ek.endTime=t:this.ek.entryTime=t);this.cT(),this.pM()}}Mk(t,i){return t+i}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.ek.onRemove&&this.ek.onRemove()}}function ta(t,i){return new Qo(t,i)}class ia{constructor(t){this.jC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.jC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class sa{constructor(t){this.jC=t,this.Jt=new ia(t)}renderer(){return this.jC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class na extends bl{constructor(t,i){super(t,"gantt",i),this.jb=null,this.YC=null,this.eh=null,this.XC=!1,this.GC=!1,this.KC=!1,this.yk=-1,this.JC=null,this.$P=null,this.Sk=-1,this.bP=null,this.xk={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.xk),this.cS(),this.xk.interactive&&(this.bP=Fl(this._chart,this._series,1,t=>this.yP(t)))}yP(t){const i=this.xk.segments??[],s=Kn(this._chart,this._series,Il(this._chart,t.ut))??t.gt,n=this.xk.rowHeight+this.xk.rowSpacing,e=Math.max(0,Math.floor((t.ct-50)/n)),r=i.length>0?e-i[0].level:0;for(const n of i)n.startTime=t.gt,n.endTime=s,n.level=Math.max(0,n.level+r);this.pM()}isComplete(){return!this.bP?.mP()}selectionBox(){const t=this.xk.segments??[];if(0===t.length)return null;const i=this.xk.rowHeight,s=i+this.xk.rowSpacing,n={left:1/0,top:1/0,right:-1/0,bottom:-1/0};for(const e of t){const t=50+e.level*s;n.left=Math.min(n.left,Zn(this._chart,this._series,e.startTime)??0),n.right=Math.max(n.right,Zn(this._chart,this._series,e.endTime)??0),n.top=Math.min(n.top,t),n.bottom=Math.max(n.bottom,t+i)}return n}cS(){this.eh=this.hP();const t={attached:t=>{this.YC=t.requestUpdate},detached:()=>{this.YC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.lP(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}hP(){return new sa(this)}drawToCanvas(t,i,s){if(!this.isComplete()||!this.xk.segments||0===this.xk.segments.length)return;const n=50*s,e=this.xk.rowHeight*s,r=this.xk.rowSpacing*s;this.xk.showGrid&&this.rm(t,n,e,r,i,s),this.xk.segments.forEach((s,h)=>{const l=(Zn(this._chart,this._series,s.startTime)??0)*i,o=(Zn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.Sk||this.GC&&!this.isLocked();this.Ck(t,l,o,a,e,s,_,i)})}rm(t,i,s,n,e,r){if(!this.xk.segments)return;const h=Math.max(...this.xk.segments.map(t=>t.level),0),l=this._chart.chartElement().clientWidth*e;t.strokeStyle="rgba(200, 200, 200, 0.3)",t.lineWidth=1*e;for(let e=0;e<=h+1;e++){const r=i+e*(s+n);t.beginPath(),t.moveTo(0,r),t.lineTo(l,r),t.stroke()}}Ck(t,i,s,n,e,r,h,l){const o=s-i,a=this._S(r.color,h?this.xk.fillOpacity+.2:this.xk.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.xk.borderWidth+(this.XC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.xk.showLabels&&r.label&&this.xP(t,i,n,o,e,r.label,l)}xP(t,i,s,n,e,r,h){const l=11*h,o=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let a=r;const _=n-2*o;let u=t.measureText(a).width;if(u>_&&_>0){for(;u>_&&a.length>0;)a=a.slice(0,-1),u=t.measureText(a+"...").width;a+="..."}t.fillText(a,i+o,s+e/2)}_S(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${Math.min(1,i)})`}addSegment(t){this.xk.segments||(this.xk.segments=[]),this.xk.segments.push(t),this.pM(),this.xk.onUpdate&&this.xk.onUpdate()}removeSegment(t){this.xk.segments&&t>=0&&t<this.xk.segments.length&&(this.xk.segments.splice(t,1),this.pM(),this.xk.onUpdate&&this.xk.onUpdate())}getSegments(){return this.xk.segments||[]}setColor(t){const i=this.xk.segments??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.xk.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.XC!==t&&(this.XC=t,this.pM())}isSelected(){return this.XC}setHovered(t){this.GC!==t&&(this.GC=t,this.pM())}isHovered(){return this.GC}lP(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?cl(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.xk.segments?.[this.Sk];s&&(this.KC=!0,this.yk=this.Sk,this.JC=i,this.$P={oS:s.startTime,aS:s.endTime})}updateDrag(t,i){const s=this.xk.segments?.[this.yk];if(!this.KC||!this.$P||!s)return;const n=dl(this.JC,t,i);s.startTime=this.$P.oS+n.gt,s.endTime=this.$P.aS+n.gt,this.pM(),this.xk.onUpdate&&this.xk.onUpdate()}stopDrag(){this.KC=!1,this.yk=-1,this.JC=null,this.$P=null}hitTest(t,i){if(!this.isComplete()||!this.xk.segments||0===this.xk.segments.length)return!1;const s=this.xk.rowHeight,n=this.xk.rowSpacing;for(let e=0;e<this.xk.segments.length;e++){const r=this.xk.segments[e],h=Zn(this._chart,this._series,r.startTime)??0,l=Zn(this._chart,this._series,r.endTime)??0,o=50+r.level*(s+n);if(t>=h&&t<=l&&i>=o&&i<=o+s)return this.Sk=e,!0}return this.Sk=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.xk.rowHeight,rowSpacing:this.xk.rowSpacing,fillOpacity:this.xk.fillOpacity,borderWidth:this.xk.borderWidth,showLabels:this.xk.showLabels,showGrid:this.xk.showGrid},extra:{segments:(this.xk.segments||[]).map(t=>({oS:fl(t.startTime),aS:fl(t.endTime),sn:t.level,Jl:t.label,R:t.color,Pk:t.category}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.YC?.()}_update(){this.pM()}remove(){this.bP?.wP(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.xk.onRemove&&this.xk.onRemove()}}function ea(t,i){return new na(t,i)}class ra{constructor(t,i,s={}){this.Tk=[],this.kk=[],this.Dk=[],this.Rk=!1,this.Fk=new Map,this.Vk=null,this.Ik=null,this.Ak=null,this.kx=null,this.Lk=null,this.ep=null,this.Bk=null,this.Ok=null,this.Ek=null,this.Wk=null,this.zk=null,this.$k=null,this.BS=null,this.Hk=!1,this.Nk=null,this.Uk=null,this.qk=new a,this.KC=!1,this.jk=null,this.Yk=new Set,this.Xk=null,this.Gk=new a,this.Af=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Kk()}startDrawing(t){this.Ak=t,this.Zk()}activeDrawingType(){return this.Ak}stopDrawing(){this.Ak=null}addTool(t,i){const s=i??t.id;return this.Fk.set(s,t),t.isComplete()||this.Yk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Yk.size>0}cancelPendingDrawings(){if(0===this.Yk.size)return 0;let t=0;for(const i of Array.from(this.Yk)){const s=this.Fk.get(i);s&&(this.Vk===i&&this.Jk(null),s.remove(),this.Fk.delete(i),t++)}return this.Yk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Gk.i(t)}unsubscribeDrawingCompleted(t){this.Gk._(t)}Qk(){0!==this.Yk.size&&null===this.Xk&&(this.Xk=setTimeout(()=>{this.Xk=null;const t=[];for(const i of Array.from(this.Yk)){const s=this.Fk.get(i);s?s.isComplete()&&(this.Yk.delete(i),t.push(i)):this.Yk.delete(i)}t.length>0&&this.recordChange();for(const i of t)this.Gk.p(i)},0))}removeTool(t){const i=this.Fk.get(t);return!!i&&(this.Vk===t&&this.Jk(null),i.remove(),this.Fk.delete(t),this.Yk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.Fk.has(t)&&(this.Jk(t),!0)}Jk(t){if(this.Vk===t)return;const i=null===this.Vk?void 0:this.Fk.get(this.Vk);i&&i.setSelected(!1),this.Vk=t;const s=null===t?void 0:this.Fk.get(t);s&&s.setSelected(!0),this.tD()}recordChange(){if(this.Rk)return;const t=this.serializeAll();JSON.stringify(t)!==JSON.stringify(this.Dk)&&(this.Tk.push(this.Dk),this.Tk.length>100&&this.Tk.shift(),this.kk=[],this.Dk=t)}canUndo(){return this.Tk.length>0}canRedo(){return this.kk.length>0}undo(){const t=this.Tk.pop();return void 0!==t&&(this.kk.push(this.Dk),this.iD(t),!0)}redo(){const t=this.kk.pop();return void 0!==t&&(this.Tk.push(this.Dk),this.iD(t),!0)}iD(t){this.Rk=!0;try{this.Jk(null);for(const[t,i]of Array.from(this.Fk))i.isComplete()&&(i.remove(),this.Fk.delete(t),this.Yk.delete(t));const i={chart:this.Af,series:this.be};for(const s of t)this.restoreTool(i,s);this.Dk=t}finally{this.Rk=!1}}subscribeSelectionChanged(t){this.qk.i(t)}unsubscribeSelectionChanged(t){this.qk._(t)}selectionBounds(){if(null===this.Vk)return null;const t=this.Fk.get(this.Vk);return t?this.sD(t):null}sD(t){const i=t.selectionBox()??this.nD(t);if(null===i)return null;const s=this.eD(t);return{left:i.left+s.ut,right:i.right+s.ut,top:i.top+s.ct,bottom:i.bottom+s.ct}}nD(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Zn(this.Af,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,o),h=Math.max(h,o))}return l?{left:n,top:e,right:r,bottom:h}:null}eD(t){const i=this.Af.chartElement(),s=this.bx(t);if(!i||!s)return{ut:0,ct:0};const n=i.getBoundingClientRect(),e=s.getBoundingClientRect();return{ut:e.left-n.left,ct:e.top-n.top}}tD(){this.qk.p({id:this.Vk,bounds:this.selectionBounds()})}deselectAll(){this.Zk()}deleteSelected(){if(this.Vk){const t=this.Fk.get(this.Vk);return(!t||!t.isLocked())&&this.removeTool(this.Vk)}return!1}getSelectedToolId(){return this.Vk}getAllTools(){return new Map(this.Fk)}getTool(t){return this.Fk.get(t)}clearAll(){this.Jk(null),this.Fk.forEach(t=>t.remove()),this.Fk.clear(),this.Yk.clear(),this.recordChange()}getToolCount(){return this.Fk.size}isToolSelected(t){return this.Vk===t}serializeAll(){const t=[];for(const i of this.Fk.values())i.isComplete()&&t.push(i.serialize());return t}restoreTool(t,i){const s=ra.rD(t,i);return s.applySerializedState(i),this.addTool(s,s.id),s}restoreAll(t,i,s=!0){s&&this.clearAll();for(const s of i)this.restoreTool(t,s)}static rD(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({hD:wl(n[t]),lD:gl(n[t],"price")??0});switch(s){case"trendLine":return Rl(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,...e});case"horizontalLine":return Ol(t,{price:h(0).lD,startTime:h(0).hD??void 0,...e});case"parallelChannel":return Gl(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,channelWidth:r?.channelWidth,...e});case"pitchfork":return Ql(t,{pivotTime:h(0).hD,pivotPrice:h(0).lD,upperTime:h(1).hD,upperPrice:h(1).lD,lowerTime:h(2).hD,lowerPrice:h(2).lD,...e});case"polygon":return ql(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).hD,s.price=h(i).lD,s}),...e});case"crossLine":return $l(t,{time:h(0).hD,price:h(0).lD,...e});case"verticalLine":return no(t,{time:h(0).hD,...e});case"fibRetracement":return uo(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return vo(t,{point1:i.hD?{time:i.hD,price:i.lD}:void 0,point2:s.hD?{time:s.hD,price:s.lD}:void 0,point3:n.hD?{time:n.hD,price:n.lD}:void 0,levels:r?.levels,...e})}case"fibFan":return Mo(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,levels:r?.levels,...e});case"rectangle":return Co(t,{time1:h(0).hD,price1:h(0).lD,time2:h(1).hD,price2:h(1).lD,...e});case"circle":return Do(t,{centerTime:h(0).hD,centerPrice:h(0).lD,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Io(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Eo(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Ho(t,{time:h(0).hD,price:h(0).lD,text:r?.text,...e});case"ruler":return Ko(t,{point1Time:h(0).hD,point1Price:h(0).lD,point2Time:h(1).hD,point2Price:h(1).lD,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ta(t,{entryPrice:h(0).lD,entryTime:h(0).hD,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return ea(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.Xk&&(clearTimeout(this.Xk),this.Xk=null),this.Gk.m(),this.qk.m(),this.clearAll(),this.oD(),this.Tk=[],this.kk=[],this.Dk=[]}Kk(){this.kx=t=>{this.zC(t)},this.Af.subscribeClick(this.kx),this.ep=t=>{this.$C(t)},this.Af.subscribeCrosshairMove(this.ep);const t=this.Af.chartElement();t&&(this.Bk=t=>this.aD(t),this.Ok=t=>this._D(t),this.Ek=t=>this.uD(t),this.Wk=t=>this._D(t),this.zk=t=>this.cD(t),t.addEventListener("pointerdown",this.Bk),t.addEventListener("pointerup",this.Ok),t.addEventListener("pointermove",this.Ek),t.addEventListener("pointercancel",this.Wk),t.addEventListener("lostpointercapture",this.zk)),us&&(this.$k=t=>this._D(t),window.addEventListener("pointerup",this.$k)),this.Ps.enableKeyboardShortcuts&&(this.Lk=t=>{this.dD(t)},document.addEventListener("keydown",this.Lk))}oD(){this.kx&&(this.Af.unsubscribeClick(this.kx),this.kx=null),this.ep&&(this.Af.unsubscribeCrosshairMove(this.ep),this.ep=null);const t=this.Af.chartElement();t&&(this.Bk&&(t.removeEventListener("pointerdown",this.Bk),this.Bk=null),this.Ok&&(t.removeEventListener("pointerup",this.Ok),this.Ok=null),this.Ek&&(t.removeEventListener("pointermove",this.Ek),this.Ek=null),this.Wk&&(t.removeEventListener("pointercancel",this.Wk),this.Wk=null),this.zk&&(t.removeEventListener("lostpointercapture",this.zk),this.zk=null)),this.$k&&(window.removeEventListener("pointerup",this.$k),this.$k=null),this.Lk&&(document.removeEventListener("keydown",this.Lk),this.Lk=null)}zC(t){if(this.Qk(),!t.point)return;if(this.Hk)return void(this.Hk=!1);if(this.KC)return;const i=this.pD(t.hoveredObjectId);i?this.selectTool(i):this.Zk()}$C(t){if(this.Nk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.KC&&this.jk){const i=this.Fk.get(this.jk);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Kn(this.Af,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.pD(t.hoveredObjectId);if(this.Ik&&this.Ik!==i){const t=this.Fk.get(this.Ik);t&&t.setHovered(!1)}if(i){const t=this.Fk.get(i);t&&t.setHovered(!0)}this.Ik=i}pD(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.Fk)if(s.id===i)return t;return null}aD(t){if(this.KC)return;yl(this.Af,!1);const i=this.Af.chartElement();if(!i)return;const s=null!==this.Ik&&null!==this.Nk?{fD:this.Ik,Rw:this.Nk}:this.vD(t);if(null===s)return;const{fD:n,Rw:e}=s,r=this.Fk.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.mD(r,e.ut,e.ct);if(null!==h&&null!==l){yl(this.Af,!0),this.selectTool(n),this.KC=!0,this.Hk=!0,this.jk=n,this.BS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.BS=null}r.startDrag(h,l),this.wD()}}uD(t){if(!this.KC||null===this.jk||"mouse"===t.pointerType)return;if(null!==this.BS&&t.pointerId!==this.BS)return;const i=this.Fk.get(this.jk);if(!i)return;const s=this.bx(i);if(null===s)return;const n=s.getBoundingClientRect(),e=i.series(),r=e.coordinateToPrice(t.clientY-n.top),h=Kn(this.Af,e,t.clientX-n.left);null!==r&&null!==h&&(i.updateDrag(h,r),t.preventDefault())}_D(t){if(this.Qk(),!this.KC||null===this.jk)return;if(t&&null!==this.BS&&t.pointerId!==this.BS)return;const i=this.jk;this.KC=!1,this.jk=null;try{const t=this.Fk.get(i);t&&t.stopDrag()}finally{this.wx(),this.gD()}this.recordChange()}cD(t){null!==this.BS&&t.pointerId!==this.BS||(this.BS=null,this._D())}bx(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}vD(t){for(const[i,s]of this.Fk){if(!s.isVisible()||s.isLocked())continue;const n=this.bx(s);if(null===n)continue;const e=n.getBoundingClientRect(),r={ut:t.clientX-e.left,ct:t.clientY-e.top};if(s.hitTest(r.ut,r.ct))return{fD:i,Rw:r}}return null}wx(){if(null===this.BS)return;const t=this.Af.chartElement();t&&t.hasPointerCapture(this.BS)&&t.releasePointerCapture(this.BS),this.BS=null}wD(){if(null!==this.Uk)return;const t=this.Af.options();this.Uk={bD:f(t.handleScroll),MD:f(t.handleScale)},this.Af.applyOptions({handleScroll:!1,handleScale:!1})}gD(){const t=this.Uk;this.Uk=null,null!==t&&this.Af.applyOptions({handleScroll:t.bD,handleScale:t.MD})}dD(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Qk(),"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const s=t.metaKey||t.ctrlKey;if(s&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}s&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.cancelPendingDrawings(),this._D(),this.Zk(),this.stopDrawing(),t.preventDefault())}mD(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Kn(this.Af,t.series(),i)}}Zk(){this.Jk(null)}}const ha={...t,color:"#2196f3"};function la(){return"2.3.19-dev+202610211514"}export{ke as AreaSeries,Vo as ArrowTool,Ve as BarSeries,Ce as BaselineSeries,Bo as BrushTool,Le as CandlestickSeries,ko as CircleTool,Ai as ColorType,zl as CrossLineTool,U as CrosshairMode,Vh as DEFAULT_SESSIONS,qh as DraggablePriceLine,ra as DrawingToolsManager,ro as EXTENDED_FIBONACCI_RATIOS,ho as FibonacciCalculator,fo as FibonacciExtensionTool,bo as FibonacciFanTool,_o as FibonacciTool,na as GanttTool,Ee as HistogramSeries,Bl as HorizontalLineTool,Yh as InteractiveLineManager,Vi as LastPriceAnimationMode,oe as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,Xl as ParallelChannelTool,Jl as PitchforkTool,Ul as PolygonTool,No as PositionCalculator,ol as PositionLine,zr as PositionMarkersManager,Qo as PositionTool,Ii as PriceLineSource,di as PriceScaleMode,xo as RectangleTool,jo as RulerCalculator,Go as RulerTool,eo as STANDARD_FIBONACCI_RATIOS,$o as TextTool,Li as TickMarkType,Fi as TrackingModeExitMode,Ih as TradingSessionsIndicator,Dl as TrendLineTool,so as VerticalLineTool,Oh as VolumeProfileIndicator,Ph as applyADX,Sh as applyATR,rh as applyBollingerBands,Th as applyCCI,lh as applyDonchianChannels,nh as applyEMA,gh as applyHeikinAshi,fh as applyIchimoku,hh as applyKeltnerChannels,Mh as applyMACD,Dh as applyMFI,Ch as applyOBV,oh as applyParabolicSAR,vh as applyPivotPoints,bh as applyRSI,sh as applySMA,yh as applyStochastic,uh as applySuperTrend,_h as applyVWAP,xh as applyVolume,eh as applyWMA,kh as applyWilliamsR,wh as calculateHeikinAshi,Uo as calculatePipConfig,Zn as coordinateFromTime,Io as createArrowTool,Eo as createBrushTool,Yn as createChart,jn as createChartEx,Do as createCircleTool,$l as createCrossLineTool,vo as createFibonacciExtensionTool,Mo as createFibonacciFanTool,uo as createFibonacciTool,ea as createGanttTool,Ol as createHorizontalLineTool,sr as createImageWatermark,Xh as createInteractiveLineManager,we as createOptionsChart,Gl as createParallelChannelTool,Ql as createPitchforkTool,ql as createPolygonTool,_l as createPositionLine,$r as createPositionMarkers,ta as createPositionTool,Co as createRectangleTool,Ko as createRulerTool,xr as createSeriesMarkers,Ho as createTextTool,Ge as createTextWatermark,Wr as createTimeLabels,jh as createTradingLine,Ah as createTradingSessionsIndicator,Rl as createTrendLineTool,Ir as createUpDownMarkers,no as createVerticalLineTool,Eh as createVolumeProfileIndicator,fe as createYieldCurveChart,ha as customSeriesDefaultOptions,Xn as defaultHorzScaleBehavior,qo as getPipConfig,Xr as hideSeriesPaint,Ei as isBusinessDay,Wi as isUTCTimestamp,Ur as setSeriesVolumes,Wh as setVolumeProfileData,Kn as timeFromCoordinate,la as version};