@pipsend/charts 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/dist/pipsend-charts.development.mjs +98 -15
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +98 -14
- package/dist/pipsend-charts.standalone.development.mjs +98 -15
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +23 -5
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.
|
|
3
|
+
* Pipsend Charts v2.2.0
|
|
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 h(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function r(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(r(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,P:5,C:NaN,T:"",D:"",I:"",R:"",V:0,F:0,L:0,A:0,B:0},this.W=t}O(){const t=this.M,i=this.$(),s=this.H();return t.C===i&&t.D===s||(t.C=i,t.D=s,t.T=g(i,s),t.A=2.5/12*i,t.V=t.A,t.F=i/12*t.P,t.L=i/12*t.P,t.B=0),t.I=this.N(),t.R=this.U(),this.M}N(){return this.W.O().layout.textColor}U(){return this.W.q()}$(){return this.W.O().layout.fontSize}H(){return this.W.O().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)}K(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})`}X(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,h,r]=this.G(t),[l,o,a,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(o-e)),M(h+s*(a-h)),(c=r+s*(_-r),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 P{et(t,i,s){t.useBitmapCoordinateSpace(t=>this.ht(t,i,s))}}class C extends P{constructor(){super(...arguments),this.rt=null}lt(t){this.rt=t}ht({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.rt||null===this.rt.ot)return;const n=this.rt.ot,e=this.rt,h=Math.max(1,Math.floor(i))%2/2,r=r=>{t.beginPath();for(let l=n.to-1;l>=n.from;--l){const n=e._t[l],o=Math.round(n.ut*i)+h,a=n.ct*s,_=r*s+h;t.moveTo(o,a),t.arc(o,a,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,r(e.vt+e.dt)),t.fillStyle=e.wt,r(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.W=t,this.Pt=i,this.Ct=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.It(),this.xt=!1),this.Mt}kt(){const t=this.Ct.Rt();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new C;return i.lt(t),i}),this.Mt.nt(this.yt))}It(){const t=2===this.Pt.O().mode||!this.Pt.Vt(),i=this.Ct.Ft(),s=this.Pt.Et(),n=this.W.Lt();this.kt(),i.forEach((i,e)=>{const h=this.St[e],r=i.At(s),l=i.Bt();!t&&null!==r&&i.Vt()&&null!==l?(h.wt=r.Wt,h.vt=r.vt,h.dt=r.Ot,h._t[0].bt=r.bt,h._t[0].ct=i.$t().zt(r.bt,l.Ht),h.ft=r.Nt??this.W.Ut(h._t[0].ct/i.$t().qt()),h._t[0].gt=s,h._t[0].ut=n.jt(s),h.ot=k):h.ot=null})}}class I extends P{constructor(t){super(),this.Yt=t}ht({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:h}){if(null===this.Yt)return;const r=this.Yt.Kt.Vt,l=this.Yt.Gt.Vt;if(!r&&!l)return;const o=Math.round(this.Yt.ut*s),a=Math.round(this.Yt.ct*h);t.lineCap="butt",r&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Kt.dt*s),t.strokeStyle=this.Yt.Kt.I,t.fillStyle=this.Yt.Kt.I,n(t,this.Yt.Kt.Xt),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*h),t.strokeStyle=this.Yt.Gt.I,t.fillStyle=this.Yt.Gt.I,n(t,this.Yt.Gt.Xt),e(t,a,0,i.width))}}class R{constructor(t,i){this.xt=!0,this.Zt={Kt:{dt:1,Xt:0,I:"",Vt:!1},Gt:{dt:1,Xt:0,I:"",Vt:!1},ut:0,ct:0},this.Jt=new I(this.Zt),this.Qt=t,this.Ct=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.It(),this.xt=!1),this.Jt}It(){const t=this.Qt.Vt(),i=this.Ct.ti().O().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.Vt=!1,void(s.Kt.Vt=!1);s.Gt.Vt=t&&this.Qt.ii(this.Ct),s.Kt.Vt=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Xt=i.horzLine.style,s.Gt.I=i.horzLine.color,s.Kt.dt=i.vertLine.width,s.Kt.Xt=i.vertLine.style,s.Kt.I=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function V(t,i,s,n,e,h){t.fillRect(i+h,s,n-2*h,h),t.fillRect(i+h,s+e-h,n-2*h,h),t.fillRect(i,s,h,e),t.fillRect(i+n-h,s,h,e)}function F(t,i,s,n,e,h){t.save(),t.globalCompositeOperation="copy",t.fillStyle=h,t.fillRect(i,s,n,e),t.restore()}function E(t,i,s,n,e,h){t.beginPath(),t.roundRect?t.roundRect(i,s,n,e,h):(t.lineTo(i+n-h[1],s),0!==h[1]&&t.arcTo(i+n,s,i+n,s+h[1],h[1]),t.lineTo(i+n,s+e-h[2]),0!==h[2]&&t.arcTo(i+n,s+e,i+n-h[2],s+e,h[2]),t.lineTo(i+h[3],s+e),0!==h[3]&&t.arcTo(i,s+e,i,s+e-h[3],h[3]),t.lineTo(i,s+h[0]),0!==h[0]&&t.arcTo(i,s,i+h[0],s,h[0]))}function L(t,i,s,n,e,h,r=0,l=[0,0,0,0],o=""){if(t.save(),!r||!o||o===h)return E(t,i,s,n,e,l),t.fillStyle=h,t.fill(),void t.restore();const a=r/2;var _;E(t,i+a,s+a,n-r,e-r,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==h&&(t.fillStyle=h,t.fill()),"transparent"!==o&&(t.lineWidth=r,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function A(t,i,s,n,e,h,r){t.save(),t.globalCompositeOperation="copy";const l=t.createLinearGradient(0,0,0,e);l.addColorStop(0,h),l.addColorStop(1,r),t.fillStyle=l,t.fillRect(i,s,n,e),t.restore()}class B{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.hi=i}qt(t,i){return this.Yt.Vt?t.C+t.A+t.V:0}et(t,i,s,n){if(!this.Yt.Vt||0===this.Yt.ri.length)return;const e=this.Yt.I,h=this.hi.Z,r=t.useBitmapCoordinateSpace(t=>{const r=t.context;r.font=i.T;const l=this.li(t,i,s,n),o=l.oi;return l.ai?L(r,o._i,o.ui,o.ci,o.di,h,o.pi,[o.vt,0,0,o.vt],h):L(r,o.fi,o.ui,o.ci,o.di,h,o.pi,[0,o.vt,o.vt,0],h),this.Yt.mi&&(r.fillStyle=e,r.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.Yt.Mi&&(r.fillStyle=i.R,r.fillRect(l.ai?o.yi-o.pi:0,o.ui,o.pi,o.Si-o.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=r.xi;t.font=i.T,t.textAlign=r.ai?"right":"left",t.textBaseline="middle",t.fillStyle=e,t.fillText(this.Yt.ri,s.Pi,(s.ui+s.Si)/2+s.Ci)})}li(t,i,s,n){const{context:e,bitmapSize:h,mediaSize:r,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=this.Yt.mi||!this.Yt.Ti?i.P:0,_=this.Yt.ki?i.S:0,u=i.A+this.hi.Di,c=i.V+this.hi.Ii,d=i.F,p=i.L,f=this.Yt.ri,v=i.C,m=s.Ri(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),P=Math.round(a*l),C=this.hi.Fi??this.hi.Ei,T=Math.round(C*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,I="right"===n,R=I?r.width-_:_,V=I?h.width-S:S;let F,E,L;return I?(F=V-x,E=V-P,L=R-a-d-_):(F=V+x,E=V+P,L=R+a+d),{ai:I,oi:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:F,fi:V,gi:E,bi:M,yi:h.width},xi:{ui:k/o,Si:D/o,Pi:L,Ci:m}}}}class W{constructor(t){this.Li={Ei:0,Z:"#000",Ii:0,Di:0},this.Ai={ri:"",Vt:!1,mi:!0,Ti:!1,Nt:"",I:"#FFF",Mi:!1,ki:!1},this.Bi={ri:"",Vt:!1,mi:!1,Ti:!0,Nt:"",I:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Wi=new(t||B)(this.Ai,this.Li),this.Oi=new(t||B)(this.Bi,this.Li)}ri(){return this.zi(),this.Ai.ri}Ei(){return this.zi(),this.Li.Ei}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Wi.qt(t,i),this.Oi.qt(t,i))}$i(){return this.Li.Fi||0}Hi(t){this.Li.Fi=t}Ni(){return this.zi(),this.Ai.Vt||this.Bi.Vt}Ui(){return this.zi(),this.Ai.Vt}Dt(t){return this.zi(),this.Ai.mi=this.Ai.mi&&t.O().ticksVisible,this.Bi.mi=this.Bi.mi&&t.O().ticksVisible,this.Wi.lt(this.Ai,this.Li),this.Oi.lt(this.Bi,this.Li),this.Wi}qi(){return this.zi(),this.Wi.lt(this.Ai,this.Li),this.Oi.lt(this.Bi,this.Li),this.Oi}zi(){this.xt&&(this.Ai.mi=!0,this.Bi.mi=!1,this.ji(this.Ai,this.Bi,this.Li))}}class O extends W{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Ki=s}ji(t,i,s){if(t.Vt=!1,2===this.Qt.O().mode)return;const n=this.Qt.O().horzLine;if(!n.labelVisible)return;const e=this.Yi.Bt();if(!this.Qt.Vt()||this.Yi.Gi()||null===e)return;const h=this.Yi.Xi().X(n.labelBackgroundColor);s.Z=h.Z,t.I=h.J;const r=2/12*this.Yi.C();s.Di=r,s.Ii=r;const l=this.Ki(this.Yi);s.Ei=l.Ei,t.ri=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.ri.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Vi(t,l(this.Yt).ri,z))));if(s<=0)return;const n=i.Qi,e=s+2*n,h=e/2,r=this.Yt.ts;let o=this.Yt.Ei,a=Math.floor(o-h)+.5;a<0?(o+=Math.abs(0-a),a=Math.floor(o-h)+.5):a+e>r&&(o-=Math.abs(r-(a+e)),a=Math.floor(o-h)+.5);const _=a+e,u=Math.ceil(0+i.S+i.P+i.A+i.C+i.V);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const h=Math.round(a*s),r=Math.round(0*n),o=Math.round(_*s),c=Math.round(u*n),d=Math.round(2*s);if(t.beginPath(),t.moveTo(h,r),t.lineTo(h,c-d),t.arcTo(h,c,h+d,c,d),t.lineTo(o-d,c),t.arcTo(o,c,o,c-d,d),t.lineTo(o,r),t.fill(),e.mi){const h=Math.round(e.Ei*s),l=r,o=Math.round((l+i.P)*n);t.fillStyle=e.I;const a=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(h-_,l,a,o-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.P+i.A+i.C/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.I;const h=i.Ji.Ri(t,"Apr0");t.translate(a+n,e+h),t.fillText(s.ri,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={Vt:!1,Z:"#4c525e",I:"white",ri:"",ts:0,Ei:NaN,mi:!0},this.Pt=t,this.ss=i,this.Ki=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.It(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}It(){const t=this.Zt;if(t.Vt=!1,2===this.Pt.O().mode)return;const i=this.Pt.O().vertLine;if(!i.labelVisible)return;const s=this.ss.Lt();if(s.Gi())return;t.ts=s.ts();const n=this.Ki();if(null===n)return;t.Ei=n.Ei;const e=s.ns(this.Pt.Et());t.ri=s.es(l(e)),t.Vt=!0;const h=this.ss.Xi().X(i.labelBackgroundColor);t.Z=h.Z,t.I=h.J,t.mi=s.O().ticksVisible}}class N{constructor(){this.hs=null,this.rs=0}ls(){return this.rs}_s(t){this.rs=t}$t(){return this.hs}us(t){this.hs=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.Ct=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.Ps=NaN,this.ss=t,this.Cs=i;this.Ts=((t,i)=>s=>{const n=i(),e=t();if(s===l(this.Ct).ks())return{bt:e,Ei:n};{const t=l(s.Bt());return{bt:s.Ds(n,t),Ei:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.Lt().Is(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Ei:n}:null})(()=>this.fs,()=>this.ni());this.Rs=new H(this,t,s)}O(){return this.Cs}Vs(t,i){this.xs=t,this.Ps=i}Fs(){this.xs=NaN,this.Ps=NaN}Es(){return this.xs}Ls(){return this.Ps}As(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Bs(t,i,s)}Et(){return this.fs}ni(){return this.ys}ei(){return this.Ss}Vt(){return this.vs}Ws(){this.vs=!1,this.Os(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Ct=null,this.Fs(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new R(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.Ct&&this.Cs.horzLine.visible}si(){return this.Cs.vertLine.visible}Hs(t,i){this.vs&&this.Ct===t||this.ws.clear();const s=[];return this.Ct===t&&s.push(this.Ns(this.ws,i,this.Ts)),s}ds(){return this.vs?[this.Rs]:[]}Us(){return this.Ct}zs(){this.ss.qs().forEach(t=>{this.bs.get(t)?.Tt(),this.Ms.get(t)?.Tt()}),this.ws.forEach(t=>t.Tt()),this.Rs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}Bs(t,i,s){this.Ys(t,i,s)&&this.zs()}Ys(t,i,s){const n=this.ys,e=this.Ss,h=this.ps,r=this.fs,l=this.Ct,o=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.Lt().jt(t),this.Ct=s;const a=null!==o?o.Bt():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||r!==this.fs||h!==this.ps||l!==this.Ct}Os(){const t=this.ss.Ks().map(t=>t.Xs().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 O(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}hn(t){const i=this.Zs.get(t);return void 0===i?{sn:this.Qs}:{sn:Math.max(this.Qs,i.sn),nn:i.nn}}rn(){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.rn();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 K{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function X(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 K{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 h=+(Math.round(t*i)-s*i).toFixed(this.xn);h>=i&&(h-=i,s+=1),n=G+X(+h.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+X(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 K{constructor(t){super(),this.Pn=t}format(t){let i="";return t<0&&(i="-",t=-t),t<995?i+this.Cn(t):t<999995?i+this.Cn(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),i+this.Cn(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),i+this.Cn(t/1e9)+"B")}Cn(t){let i;const s=Math.pow(10,this.Pn);return i=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.Pn).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.In={},this.Rn=new Map,this.Vn=t}Fn(){this.Tn=0,this.Rn.clear(),this.kn=1,this.Dn=1,this.In={}}Vi(t,i,s){return this.En(t,i,s).width}Ri(t,i,s){const n=this.En(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}En(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Rn.has(e))return r(this.Rn.get(e)).Ln;if(this.Tn===this.Vn){const t=this.In[this.Dn];delete this.In[this.Dn],this.Rn.delete(t),this.Dn++,this.Tn--}t.save(),t.textBaseline="middle";const h=t.measureText(e);return t.restore(),0===h.width&&i.length||(this.Rn.set(e,{Ln:h,An:this.kn}),this.In[this.kn]=e,this.Tn++,this.kn++),h}}class st{constructor(t){this.Bn=null,this.M=null,this.Wn="right",this.On=t}zn(t,i,s){this.Bn=t,this.M=i,this.Wn=s}et(t){null!==this.M&&null!==this.Bn&&this.Bn.et(t,this.M,this.On,this.Wn)}}class nt{constructor(t,i,s){this.$n=t,this.On=new it(50),this.Hn=i,this.W=s,this.$=-1,this.Jt=new st(this.On)}Dt(){const t=this.W.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.W.Yn();return n.C!==this.$&&(this.$=n.C,this.On.Fn()),this.Jt.zn(this.$n.qi(),n,s),this.Jt}}class et extends P{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}Kn(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?{Xn:this.Yt,Gn:e}:null}ht({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:h}){if(null===this.Yt)return;if(!1===this.Yt.Vt)return;const r=Math.round(this.Yt.ct*h);r<0||r>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.I,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Xt),e(t,r,0,i.width))}}class ht{constructor(t){this.Zn={ct:0,I:"rgba(0, 0, 0, 0)",dt:1,Xt: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 rt extends ht{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.O();if(!s.baseLineVisible||!this.Qn.Vt())return;const n=this.Qn.Bt();null!==n&&(this.Zn.Vt=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.I=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Xt=s.baseLineStyle)}}class lt extends P{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ne(){return this.Yt}ht({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.Yt;if(null===n)return;const e=Math.max(1,Math.floor(i)),h=e%2/2,r=Math.round(n.ee.x*i)+h,l=n.ee.y*s;t.fillStyle=n.he,t.beginPath();const o=Math.max(2,1.5*n.re)*i;t.arc(r,l,o,0,2*Math.PI,!1),t.fill(),t.fillStyle=n.le,t.beginPath(),t.arc(r,l,n.vt*i,0,2*Math.PI,!1),t.fill(),t.lineWidth=e,t.strokeStyle=n.oe,t.beginPath(),t.arc(r,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.O().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.O().lastPriceAnimation}xe(){switch(this.be.O().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.ge}}Dt(){return this.xt?(this.It(),this.xt=!1,this.me=!1):this.me&&(this.Pe(),this.me=!1),this.Jt}It(){this.Jt.lt(null);const t=this.be.ti().Lt(),i=t.Ce(),s=this.be.Bt();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Ie))return;const e={x:t.jt(n.Ie),y:this.be.$t().zt(n.bt,s.Ht)},h=n.I,r=this.be.O().lineWidth,l=this.Re(this.Ve(),h);this.Jt.lt({he:h,re:r,le:l.le,oe:l.oe,vt:l.vt,ee:e})}Pe(){const t=this.Jt.ne();if(null!==t){const i=this.Re(this.Ve(),t.he);t.le=i.le,t.oe=i.oe,t.vt=i.vt}}Ve(){return this.xe()?performance.now()-this.we:2599}Fe(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Xi().K(t,e)}Re(t,i){const s=t%2600/2600;let n;for(const t of ot)if(s>=t.ae&&s<=t._e){n=t;break}h(void 0!==n,"Last price animation internal logic error");const e=(s-n.ae)/(n._e-n.ae);return{le:this.Fe(i,e,n.de,n.pe),oe:this.Fe(i,e,n.fe,n.ve),vt:(r=e,l=n.ue,o=n.ce,l+(o-l)*r)};var r,l,o}}class _t extends ht{constructor(t){super(t)}ie(){const t=this.Zn;t.Vt=!1;const i=this.Qn.O();if(!i.priceLineVisible||!this.Qn.Vt())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.Vt=!0,t.ct=s.Ei,t.I=this.Qn.Ee(s.I),t.dt=i.priceLineWidth,t.Xt=i.priceLineStyle)}}class ut extends W{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.O(),h=e.lastValueVisible,r=""!==n.Le(),l=0===e.seriesLastValueMode,o=n.Te(!1);if(o.ke)return;h&&(t.ri=this.Ae(o,h,l),t.Vt=0!==t.ri.length),(r||l)&&(i.ri=this.Be(o,h,r,l),i.Vt=i.ri.length>0);const a=n.Ee(o.I),_=this.Qt.ti().Xi().X(a);s.Z=_.Z,s.Ei=o.Ei,i.Nt=n.ti().Ut(o.Ei/n.$t().qt()),t.Nt=a,t.I=_.J,i.I=_.J}Be(t,i,s,n){let e="";const h=this.Qt.Le();return s&&0!==h.length&&(e+=`${h} `),i&&n&&(e+=this.Qt.$t().We()?t.Oe:t.ze),e.trim()}Ae(t,i,s){return i?s?this.Qt.$t().We()?t.ze:t.Oe:t.ri:""}}function ct(t,i,s,n){const e=Number.isFinite(i),h=Number.isFinite(s);return e&&h?t(i,s):e||h?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))}Ke(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)}Xe(){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}th(){return this.Je}ih(){return this.Qe}Xe(){return{priceRange:null===this.Je?null:this.Je.Xe(),margins:this.Qe||void 0}}static Ze(t){return null===t?null:new pt(dt.Ze(t.priceRange),t.margins)}}class ft extends ht{constructor(t,i){super(t),this.sh=i}ie(){const t=this.Zn;t.Vt=!1;const i=this.sh.O();if(!this.Qn.Vt()||!i.lineVisible)return;const s=this.sh.nh();null!==s&&(t.Vt=!0,t.ct=s,t.I=i.color,t.dt=i.lineWidth,t.Xt=i.lineStyle,t.Gn=this.sh.O().id)}}class vt extends W{constructor(t,i){super(),this.be=t,this.sh=i}ji(t,i,s){t.Vt=!1,i.Vt=!1;const n=this.sh.O(),e=n.axisLabelVisible,h=""!==n.title,r=this.be;if(!e||!r.Vt())return;const l=this.sh.nh();if(null===l)return;h&&(i.ri=n.title,i.Vt=!0),i.Nt=r.ti().Ut(l/r.$t().qt()),t.ri=this.eh(n.price),t.Vt=!0;const o=this.be.ti().Xi().X(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.I=a,i.I=a,s.Ei=l}eh(t){const i=this.be.Bt();return null===i?"":this.be.$t().Zi(t,i.Ht)}}class mt{constructor(t,i){this.be=t,this.Cs=i,this.hh=new ft(t,this),this.$n=new vt(t,this),this.rh=new nt(this.$n,t,t.ti())}oh(t){_(this.Cs,t),this.Tt(),this.be.ti().ah()}O(){return this.Cs}_h(){return this.hh}uh(){return this.rh}dh(){return this.$n}Tt(){this.hh.Tt(),this.$n.Tt()}nh(){const t=this.be,i=t.$t();if(t.ti().Lt().Gi()||i.Gi())return null;const s=t.Bt();return null===s?null:i.zt(this.Cs.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,h=i.downColor,r=l(t(s,n)),a=o(r.Ht[0])<=o(r.Ht[3]);return{ph:r.I??(a?e:h)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,h=i.downColor,r=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{ph:c.I??(d?e:h),fh:c.Nt??(d?r:a),mh:c.wh??(d?_:u)}},Custom:(t,i,s,n)=>({ph:l(t(s,n)).I??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{ph:e.wt??i.lineColor,wt:e.wt??i.lineColor,gh:e.gh??i.topColor,bh:e.bh??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{ph:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,Mh:e.Mh??i.topLineColor,yh:e.yh??i.bottomLineColor,Sh:e.Sh??i.topFillColor1,xh:e.xh??i.topFillColor2,Ph:e.Ph??i.bottomFillColor1,Ch:e.Ch??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{ph:e.I??i.color,wt:e.I??i.color}},Histogram:(t,i,s,n)=>({ph:l(t(s,n)).I??i.color})};class bt{constructor(t){this.Th=(t,i)=>void 0!==i?i.Ht:this.be.Xs().kh(t),this.be=t,this.Dh=gt[t.Ih()]}Rh(t,i){return this.Dh(this.Th,this.be.O(),t,i)}}function Mt(t,i,s,n,e=0,h=i.length){let r=h-e;for(;0<r;){const h=r>>1,l=e+h;n(i[l],s)===t?(e=l+1,r-=h+1):r=h}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 Pt=30;class Ct{constructor(){this.Vh=[],this.Fh=new Map,this.Eh=new Map,this.Lh=[]}Ah(){return this.Bh()>0?this.Vh[this.Vh.length-1]:null}Wh(){return this.Bh()>0?this.Oh(0):null}Gs(){return this.Bh()>0?this.Oh(this.Vh.length-1):null}Bh(){return this.Vh.length}Gi(){return 0===this.Bh()}De(t){return null!==this.zh(t,0)}kh(t){return this.$h(t)}$h(t,i=0){const s=this.zh(t,i);return null===s?null:{...this.Hh(s),Ie:this.Oh(s)}}Nh(){return this.Vh}Uh(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.qh(t,i,e))}return n}lt(t){this.Eh.clear(),this.Fh.clear(),this.Vh=t,this.Lh=t.map(t=>t.Ie)}jh(){return this.Lh}Oh(t){return this.Vh[t].Ie}Hh(t){return this.Vh[t]}zh(t,i){const s=this.Yh(t);if(null===s&&0!==i)switch(i){case-1:return this.Kh(t);case 1:return this.Gh(t);default:throw new TypeError("Unknown search mode")}return s}Kh(t){let i=this.Xh(t);return i>0&&(i-=1),i!==this.Vh.length&&this.Oh(i)<t?i:null}Gh(t){const i=this.Zh(t);return i!==this.Vh.length&&t<this.Oh(i)?i:null}Yh(t){const i=this.Xh(t);return i===this.Vh.length||t<this.Vh[i].Ie?null:i}Xh(t){return yt(this.Vh,t,(t,i)=>t.Ie<i)}Zh(t){return St(this.Vh,t,(t,i)=>t.Ie>i)}Jh(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Vh[e].Ht[s];Number.isNaN(t)||(null===n?n={Qh:t,tr:t}:(t<n.Qh&&(n.Qh=t),t>n.tr&&(n.tr=t)))}return n}qh(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wh()),h=l(this.Gs()),r=Math.max(t,e),o=Math.min(i,h),a=Math.ceil(r/Pt)*Pt,_=Math.max(a,Math.floor(o/Pt)*Pt);{const t=this.Xh(r),e=this.Zh(Math.min(o,a,i));n=Tt(n,this.Jh(t,e,s))}let u=this.Fh.get(s);void 0===u&&(u=new Map,this.Fh.set(s,u));for(let t=Math.max(a+1,r);t<_;t+=Pt){const i=Math.floor(t/Pt);let e=u.get(i);if(void 0===e){const t=this.Xh(i*Pt),n=this.Zh((i+1)*Pt-1);e=this.Jh(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Xh(_),i=this.Zh(o);n=Tt(n,this.Jh(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{Qh:Math.min(t.Qh,i.Qh),tr:Math.max(t.tr,i.tr)}}const kt={setLineStyle:n};class Dt{constructor(t){this.ir=t}et(t,i,s){this.ir.draw(t,kt)}sr(t,i,s){this.ir.drawBackground?.(t,kt)}}class It{constructor(t){this.Rn=null,this.nr=t}Dt(){const t=this.nr.renderer();if(null===t)return null;if(this.Rn?.er===t)return this.Rn.hr;const i=new Dt(t);return this.Rn={er:t,hr:i},i}rr(){return this.nr.zOrder?.()??"normal"}}class Rt{constructor(t){this.lr=null,this.ar=t}_r(){return this.ar}zs(){this.ar.updateAllViews?.()}$s(){const t=this.ar.paneViews?.()??[];if(this.lr?.er===t)return this.lr.hr;const i=t.map(t=>new It(t));return this.lr={er:t,hr:i},i}Kn(t,i){return this.ar.hitTest?.(t,i)??null}}let Vt=class extends Rt{cs(){return[]}};class Ft{constructor(t){this.ir=t}et(t,i,s){this.ir.draw(t,kt)}sr(t,i,s){this.ir.drawBackground?.(t,kt)}}class Et{constructor(t){this.Rn=null,this.nr=t}Dt(){const t=this.nr.renderer();if(null===t)return null;if(this.Rn?.er===t)return this.Rn.hr;const i=new Ft(t);return this.Rn={er:t,hr:i},i}rr(){return this.nr.zOrder?.()??"normal"}}function Lt(t){return{ri:t.text(),Ei:t.coordinate(),Fi:t.fixedCoordinate?.(),I:t.textColor(),Z:t.backColor(),Vt:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class At{constructor(t,i){this.Jt=new $,this.ur=t,this.cr=i}Dt(){return this.Jt.lt({ts:this.cr.ts(),...Lt(this.ur)}),this.Jt}}class Bt extends W{constructor(t,i){super(),this.ur=t,this.Yi=i}ji(t,i,s){const n=Lt(this.ur);s.Z=n.Z,t.I=n.I;const e=2/12*this.Yi.C();s.Di=e,s.Ii=e,s.Ei=n.Ei,s.Fi=n.Fi,t.ri=n.ri,t.Vt=n.Vt,t.mi=n.mi}}class Wt extends Rt{constructor(t,i){super(t),this.dr=null,this.pr=null,this.vr=null,this.mr=null,this.be=i}ds(){const t=this.ar.timeAxisViews?.()??[];if(this.dr?.er===t)return this.dr.hr;const i=this.be.ti().Lt(),s=t.map(t=>new At(t,i));return this.dr={er:t,hr:s},s}Hs(){const t=this.ar.priceAxisViews?.()??[];if(this.pr?.er===t)return this.pr.hr;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.pr={er:t,hr:s},s}wr(){const t=this.ar.priceAxisPaneViews?.()??[];if(this.vr?.er===t)return this.vr.hr;const i=t.map(t=>new Et(t));return this.vr={er:t,hr:i},i}gr(){const t=this.ar.timeAxisPaneViews?.()??[];if(this.mr?.er===t)return this.mr.hr;const i=t.map(t=>new Et(t));return this.mr={er:t,hr:i},i}br(t,i){return this.ar.autoscaleInfo?.(t,i)??null}}function Ot(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.rr()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.wr()}function Ht(t){return t.gr()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Ct,this.hh=new _t(this),this.Mr=[],this.yr=new rt(this),this.Sr=null,this.Pr=null,this.Cr=null,this.Tr=[],this.Cs=s,this.kr=i;const h=new ut(this);this.ws=[h],this.rh=new nt(h,this,t),Nt.includes(this.kr)&&(this.Sr=new at(this)),this.Dr(),this.nr=n(this,this.ti(),e)}m(){null!==this.Cr&&clearTimeout(this.Cr)}Ee(t){return this.Cs.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().Ce(),e=this.Bt();if(null===n||null===e)return i;let h,r;if(t){const t=this.Yt.Ah();if(null===t)return i;h=t,r=t.Ie}else{const t=this.Yt.$h(n.yi(),-1);if(null===t)return i;if(h=this.Yt.kh(t.Ie),null===h)return i;r=t.Ie}const l=h.Ht[3],o=this.Ir().Rh(r,{Ht:h}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,ri:s.Zi(l,e.Ht),Oe:s.Rr(l),ze:s.Vr(l,e.Ht),I:o.ph,Ei:a,Ie:r}}Ir(){return null!==this.Pr||(this.Pr=new bt(this)),this.Pr}O(){return this.Cs}oh(t){const i=t.priceScaleId;void 0!==i&&i!==this.Cs.priceScaleId&&this.ti().Fr(this,i),_(this.Cs,t),void 0!==t.priceFormat&&(this.Dr(),this.ti().Er()),this.ti().Lr(this),this.ti().Ar(),this.nr.Tt("options")}lt(t,i){this.Yt.lt(t),this.nr.Tt("data"),null!==this.Sr&&(i&&i.Br?this.Sr.ye():0===t.length&&this.Sr.Me());const s=this.ti().Nn(this);this.ti().Wr(s),this.ti().Lr(this),this.ti().Ar(),this.ti().ah()}Or(t){const i=new mt(this,t);return this.Mr.push(i),this.ti().Lr(this),i}zr(t){const i=this.Mr.indexOf(t);-1!==i&&this.Mr.splice(i,1),this.ti().Lr(this)}$r(){return this.Mr}Ih(){return this.kr}Bt(){const t=this.Hr();return null===t?null:{Ht:t.Ht[3],Nr:t.gt}}Hr(){const t=this.ti().Lt().Ce();if(null===t)return null;const i=t.Ur();return this.Yt.$h(i,1)}Xs(){return this.Yt}qr(t){const i=this.Yt.kh(t);return null===i?null:"Bar"===this.kr||"Candlestick"===this.kr||"Custom"===this.kr?{jr:i.Ht[0],Yr:i.Ht[1],Kr:i.Ht[2],Gr:i.Ht[3]}:i.Ht[3]}Xr(t){const i=[];Ot(this.Tr,zt,"top",i);const s=this.Sr;return null!==s&&s.Vt()?(null===this.Cr&&s.xe()&&(this.Cr=setTimeout(()=>{this.Cr=null,this.ti().Zr()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Jr()||t.push(this.yr),t.push(this.nr,this.hh);const i=this.Mr.map(t=>t._h());return t.push(...i),Ot(this.Tr,zt,"normal",t),t}Qr(){return this.tl(zt,"bottom")}il(t){return this.tl($t,t)}sl(t){return this.tl(Ht,t)}nl(t,i){return this.Tr.map(s=>s.Kn(t,i)).filter(t=>null!==t)}cs(){return[this.rh,...this.Mr.map(t=>t.uh())]}Hs(t,i){if(i!==this.hs&&!this.Jr())return[];const s=[...this.ws];for(const t of this.Mr)s.push(t.dh());return this.Tr.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.Tr.forEach(i=>{t.push(...i.ds())}),t}br(t,i){if(void 0!==this.Cs.autoscaleInfoProvider){const s=this.Cs.autoscaleInfoProvider(()=>{const s=this.el(t,i);return null===s?null:s.Xe()});return pt.Ze(s)}return this.el(t,i)}er(){const t=this.Cs.priceFormat;return t.base??1/t.minMove}hl(){return this.rl}zs(){this.nr.Tt();for(const t of this.ws)t.Tt();for(const t of this.Mr)t.Tt();this.hh.Tt(),this.yr.Tt(),this.Sr?.Tt(),this.Tr.forEach(t=>t.zs())}$t(){return l(super.$t())}At(t){if(!(("Line"===this.kr||"Area"===this.kr||"Baseline"===this.kr)&&this.Cs.crosshairMarkerVisible))return null;const i=this.Yt.kh(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ll(),Nt:this.ol(),Ot:this.al(),Wt:this._l(t)}}Le(){return this.Cs.title}Vt(){return this.Cs.visible}ul(t){this.Tr.push(new Wt(t,this))}cl(t){this.Tr=this.Tr.filter(i=>i._r()!==t)}dl(){if("Custom"===this.kr)return t=>this.nr.pl(t)}fl(){if("Custom"===this.kr)return t=>this.nr.vl(t)}ml(){return this.Yt.jh()}Jr(){return!j(this.$t().wl())}el(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.kr||"Area"===this.kr||"Baseline"===this.kr||"Histogram"===this.kr?[3]:[2,1],n=this.Yt.Uh(t,i,s);let e=null!==n?new dt(n.Qh,n.tr):null,h=null;if("Histogram"===this.Ih()){const t=this.Cs.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.Tr.forEach(s=>{const n=s.br(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(h=n.margins)}),new pt(e,h)}ll(){switch(this.kr){case"Line":case"Area":case"Baseline":return this.Cs.crosshairMarkerRadius}return 0}ol(){switch(this.kr){case"Line":case"Area":case"Baseline":{const t=this.Cs.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}al(){switch(this.kr){case"Line":case"Area":case"Baseline":return this.Cs.crosshairMarkerBorderWidth}return 0}_l(t){switch(this.kr){case"Line":case"Area":case"Baseline":{const t=this.Cs.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Ir().Rh(t).ph}Dr(){switch(this.Cs.priceFormat.type){case"custom":{const t=this.Cs.priceFormat.formatter;this.rl={format:t,formatTickmarks:this.Cs.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.rl=new Q(this.Cs.priceFormat.precision);break;case"percent":this.rl=new J(this.Cs.priceFormat.precision);break;default:{const t=Math.pow(10,this.Cs.priceFormat.precision);this.rl=new Z(t,this.Cs.priceFormat.minMove*t)}}null!==this.hs&&this.hs.gl()}tl(t,i){const s=[];return Ot(this.Tr,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Cs=t}bl(t,i,s){let n=t;if(0===this.Cs.mode)return n;const e=s.ks(),h=e.Bt();if(null===h)return n;const r=e.zt(t,h),l=s.Ml().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.Vt())return t;const e=n.$t(),h=n.Xs();if(e.Gi()||!h.De(i))return t;const r=h.kh(i);if(null===r)return t;const l=o(n.Bt()),a=3===this.Cs.mode?jt:qt;return t.concat(a.map(t=>e.zt(r.Ht[t],l.Ht)))},[]);if(0===l.length)return n;l.sort((t,i)=>Math.abs(t-r)-Math.abs(i-r));const a=l[0];return n=e.Ds(a,h),n}}function Kt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Xt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends P{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ht({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const h=Math.max(1,Math.floor(s));t.lineWidth=h,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const r=l(this.Yt);if(r.yl){t.strokeStyle=r.Sl,n(t,r.xl),t.beginPath();for(const n of r.Pl){const e=Math.round(n.Cl*s);t.moveTo(e,-h),t.lineTo(e,i.height+h)}t.stroke()}if(r.Tl){t.strokeStyle=r.kl,n(t,r.Dl),t.beginPath();for(const s of r.Il){const n=Math.round(s.Cl*e);t.moveTo(-h,n),t.lineTo(i.width+h,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Ct=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Ct.ti().O().grid,i={Tl:t.horzLines.visible,yl:t.vertLines.visible,kl:t.horzLines.color,Sl:t.vertLines.color,Dl:t.horzLines.style,xl:t.vertLines.style,Il:this.Ct.ks().Rl(),Pl:(this.Ct.ti().Lt().Rl()||[]).map(t=>({Cl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.nr=new Jt(t)}_h(){return this.nr}}const ti={Vl:4,Fl: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 hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Fl)+i.Vl;return t<0?-n:n}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Vl)-i.Fl;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.je(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(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.Vl+s;return{Vl:n,Fl:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.El=t,this.Ll=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.El))this.Al=[2,2.5,2];else{this.Al=[];for(let t=this.El;1!==t;){if(t%2==0)this.Al.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Al.push(2,2.5),t/=5}if(this.Al.length>100)throw new Error("something wrong with base")}}}Bl(t,i,s){const n=0===this.El?0:1/this.El;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),h=0,r=this.Ll[0];for(;;){const t=Gt(e,n,1e-14)&&e>n+1e-14,i=Gt(e,s*r,1e-14),l=Gt(e,1,1e-14);if(!(t&&i&&l))break;e/=r,r=this.Ll[++h%this.Ll.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Al.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(h=0,r=this.Al[0];Gt(e,s*r,1e-14)&&e>n+1e-14;)e/=r,r=this.Al[++h%this.Al.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.El=i,this.Ol=s,this.zl=n}Bl(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.$l()/s,e=new _i(this.El,[2,2.5,2]),h=new _i(this.El,[2,2,2.5]),r=new _i(this.El,[2.5,2,2]),l=[];return l.push(e.Bl(t,i,n),h.Bl(t,i,n),r.Bl(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)}Hl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.Ol(s-1,i),e=this.Ol(0,i),h=this.Yi.O().entireTextOnly?this.Nl()/2:0,r=h,l=s-1-h,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Wl=[]);const _=this.Bl(o,a);if(this.Ul(i,_,o,a,r,l),t.ql()&&this.jl(_,a,o)){const t=this.Yi.Yl();this.Kl(i,_,r,l,t,2*t)}const u=this.Wl.map(t=>t.Gl),c=this.Yi.Xl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Zl=c[t]}Rl(){return this.Wl}Nl(){return this.Yi.C()}$l(){return Math.ceil(2.5*this.Nl())}Ul(t,i,s,n,e,h){const r=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.zl(c,t,!0);null!==_&&Math.abs(s-_)<this.$l()||(s<e||s>h||(u<r.length?(r[u].Cl=s,r[u].Zl=l.Jl(c),r[u].Gl=c):r.push({Cl:s,Zl:l.Jl(c),Gl:c}),u++,_=s,l.Ql()&&(i=this.Bl(c*a,n))))}r.length=u}Kl(t,i,s,n,e,h){const r=this.Wl,l=this.io(t,s,e,h),o=this.io(t,n,-h,-e),a=this.zl(0,t,!0)-this.zl(i,t,!0);r.length>0&&r[0].Cl-l.Cl<a/2&&r.shift(),r.length>0&&o.Cl-r[r.length-1].Cl<a/2&&r.pop(),r.unshift(l),r.push(o)}io(t,i,s,n){const e=(s+n)/2,h=this.Ol(i+s,t),r=this.Ol(i+n,t),l=Math.min(h,r),o=Math.max(h,r),a=Math.max(.1,this.Bl(o,l)),_=this.Ol(i+e,t),u=_-_%a,c=this.zl(u,t,!0);return{Zl:this.Yi.Jl(u),Cl:c,Gl:u}}jl(t,i,s){let n=o(this.Yi.th());return this.Yi.Ql()&&(n=oi(n,this.Yi.so())),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.no=0,this.eo=null,this.Je=null,this.ho=null,this.ro={lo:!1,oo:null},this.ao=!1,this._o=0,this.uo=0,this.co=new a,this.do=new a,this.po=[],this.fo=null,this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.rl=fi,this.Mo=ai(null),this.yo=t,this.Cs=i,this.So=s,this.xo=n,this.Po=e,this.Co=new ui(this,100,this.To.bind(this),this.ko.bind(this))}wl(){return this.yo}O(){return this.Cs}oh(t){if(_(this.Cs,t),this.gl(),void 0!==t.mode&&this.Do({se:t.mode}),void 0!==t.scaleMargins){const i=r(t.scaleMargins.top),s=r(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.Io(),this.mo=null}}Ro(){return this.Cs.autoScale}Vo(){return this.ao}Ql(){return 1===this.Cs.mode}We(){return 2===this.Cs.mode}Fo(){return 3===this.Cs.mode}so(){return this.Mo}se(){return{nn:this.Cs.autoScale,Eo:this.Cs.invertScale,se:this.Cs.mode}}Do(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Cs.autoScale=t.nn),void 0!==t.se&&(this.Cs.mode=t.se,2!==t.se&&3!==t.se||(this.Cs.autoScale=!0),this.ro.lo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=ri(t.qe(),i),n=ri(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.Mo)?this.Cs.autoScale=!0:(s=oi(this.Je,this.Mo),null!==s&&this.Lo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.Mo),null!==s&&this.Lo(s));const n=i.se!==this.Cs.mode;n&&(2===i.se||this.We())&&this.gl(),n&&(3===i.se||this.Fo())&&this.gl(),void 0!==t.Eo&&i.Eo!==t.Eo&&(this.Cs.invertScale=t.Eo,this.Ao()),this.do.p(i,this.se())}Bo(){return this.do}C(){return this.So.fontSize}qt(){return this.no}Wo(t){this.no!==t&&(this.no=t,this.Io(),this.mo=null)}Oo(){if(this.eo)return this.eo;const t=this.qt()-this.zo()-this.$o();return this.eo=t,t}th(){return this.Ho(),this.Je}Lo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.mo=null,this.Je=t)}No(t){this.Lo(t),this.Uo(null!==t)}Gi(){return this.Ho(),0===this.no||!this.Je||this.Je.Gi()}qo(t){return this.Eo()?t:this.qt()-1-t}zt(t,i){return this.We()?t=ii(t,i):this.Fo()&&(t=ni(t,i)),this.ko(t,i)}jo(t,i,s){this.Ho();const n=this.$o(),e=l(this.th()),h=e.qe(),r=e.je(),o=this.Oo()-1,a=this.Eo(),_=o/(r-h),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s],r=e.bt;if(isNaN(r))continue;let l=r;null!==d&&(l=d(e.bt,i));const o=n+_*(l-h),u=a?o:this.no-1-o;e.ct=u}}Ko(t,i,s){this.Ho();const n=this.$o(),e=l(this.th()),h=e.qe(),r=e.je(),o=this.Oo()-1,a=this.Eo(),_=o/(r-h),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s];let r=e.jr,l=e.Yr,o=e.Kr,u=e.Gr;null!==d&&(r=d(e.jr,i),l=d(e.Yr,i),o=d(e.Kr,i),u=d(e.Gr,i));let c=n+_*(r-h),p=a?c:this.no-1-c;e.Go=p,c=n+_*(l-h),p=a?c:this.no-1-c,e.Xo=p,c=n+_*(o-h),p=a?c:this.no-1-c,e.Zo=p,c=n+_*(u-h),p=a?c:this.no-1-c,e.Jo=p}}Ds(t,i){const s=this.To(t,i);return this.Qo(s,i)}Qo(t,i){let s=t;return this.We()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Fo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}Ml(){return this.po}Rt(){return this.vo||(this.vo=ci(this.po)),this.vo}ta(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.gl(),this.ia())}sa(t){const i=this.po.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.po.splice(i,1),0===this.po.length&&(this.Do({nn:!0}),this.Lo(null)),this.gl(),this.ia()}Bt(){let t=null;for(const i of this.po){const s=i.Bt();null!==s&&((null===t||s.Nr<t.Nr)&&(t=s))}return null===t?null:t.Ht}Eo(){return this.Cs.invertScale}Rl(){const t=null===this.Bt();if(null!==this.mo&&(t||this.mo.na===t))return this.mo.Rl;this.Co.Hl();const i=this.Co.Rl();return this.mo={Rl:i,na:t},this.co.p(),i}ea(){return this.co}ha(t){this.We()||this.Fo()||null===this.wo&&null===this.ho&&(this.Gi()||(this.wo=this.no-t,this.ho=l(this.th()).Ue()))}ra(t){if(this.We()||this.Fo())return;if(null===this.wo)return;this.Do({nn:!1}),(t=this.no-t)<0&&(t=0);let i=(this.wo+.2*(this.no-1))/(t+.2*(this.no-1));const s=l(this.ho).Ue();i=Math.max(i,.1),s.Ke(i),this.Lo(s)}la(){this.We()||this.Fo()||(this.wo=null,this.ho=null)}oa(t){this.Ro()||null===this.bo&&null===this.ho&&(this.Gi()||(this.bo=t,this.ho=l(this.th()).Ue()))}aa(t){if(this.Ro())return;if(null===this.bo)return;const i=l(this.th()).Ye()/(this.Oo()-1);let s=t-this.bo;this.Eo()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Lo(e,!0),this.mo=null}_a(){this.Ro()||null!==this.bo&&(this.bo=null,this.ho=null)}hl(){return this.rl||this.gl(),this.rl}Zi(t,i){switch(this.Cs.mode){case 2:return this.ua(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.eh(t)}}Jl(t){switch(this.Cs.mode){case 2:return this.ua(t);case 3:return this.hl().format(t);default:return this.eh(t)}}Xl(t){switch(this.Cs.mode){case 2:return this.ca(t);case 3:return this.hl().formatTickmarks(t);default:return this.da(t)}}Rr(t){return this.eh(t,l(this.fo).hl())}Vr(t,i){return t=ii(t,i),this.ua(t,pi)}pa(){return this.po}fa(t){this.ro={oo:t,lo:!1}}zs(){this.po.forEach(t=>t.zs())}ql(){return this.Cs.ensureEdgeTickMarksVisible&&this.Ro()}Yl(){return this.C()/2}gl(){this.mo=null;let t=1/0;this.fo=null;for(const i of this.po)i.ls()<t&&(t=i.ls(),this.fo=i);let i=100;null!==this.fo&&(i=Math.round(this.fo.er())),this.rl=fi,this.We()?(this.rl=pi,i=100):this.Fo()?(this.rl=new Z(100,1),i=100):null!==this.fo&&(this.rl=this.fo.hl()),this.Co=new ui(this,i,this.To.bind(this),this.ko.bind(this)),this.Co.Hl()}ia(){this.vo=null}va(){return null===this.fo||this.We()||this.Fo()?1:1/this.fo.er()}Xi(){return this.Po}Uo(t){this.ao=t}zo(){return this.Eo()?this.Cs.scaleMargins.bottom*this.qt()+this.uo:this.Cs.scaleMargins.top*this.qt()+this._o}$o(){return this.Eo()?this.Cs.scaleMargins.top*this.qt()+this._o:this.Cs.scaleMargins.bottom*this.qt()+this.uo}Ho(){this.ro.lo||(this.ro.lo=!0,this.ma())}Io(){this.eo=null}ko(t,i){if(this.Ho(),this.Gi())return 0;t=this.Ql()&&t?hi(t,this.Mo):t;const s=l(this.th()),n=this.$o()+(this.Oo()-1)*(t-s.qe())/s.Ye();return this.qo(n)}To(t,i){if(this.Ho(),this.Gi())return 0;const s=this.qo(t),n=l(this.th()),e=n.qe()+n.Ye()*((s-this.$o())/(this.Oo()-1));return this.Ql()?ri(e,this.Mo):e}Ao(){this.mo=null,this.Co.Hl()}ma(){if(this.Vo()&&!this.Ro())return;const t=this.ro.oo;if(null===t)return;let i=null;const s=this.pa();let n=0,e=0;for(const h of s){if(!h.Vt())continue;const s=h.Bt();if(null===s)continue;const r=h.br(t.Ur(),t.yi());let o=r&&r.th();if(null!==o){switch(this.Cs.mode){case 1:o=li(o,this.Mo);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!==r){const t=r.ih();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.ql()&&(n=Math.max(n,this.Yl()),e=Math.max(e,this.Yl())),n===this._o&&e===this.uo||(this._o=n,this.uo=e,this.mo=null,this.Io()),null!==i){if(i.qe()===i.je()){const t=5*this.va();this.Ql()&&(i=oi(i,this.Mo)),i=new dt(i.qe()-t,i.je()+t),this.Ql()&&(i=li(i,this.Mo))}if(this.Ql()){const t=oi(i,this.Mo),s=ai(t);if(h=s,r=this.Mo,h.Vl!==r.Vl||h.Fl!==r.Fl){const n=null!==this.ho?oi(this.ho,this.Mo):null;this.Mo=s,i=li(t,s),null!==n&&(this.ho=li(n,s))}}this.Lo(i)}else null===this.Je&&(this.Lo(new dt(-.5,.5)),this.Mo=ai(null));var h,r}Yo(){return this.We()?ii:this.Fo()?ni:this.Ql()?t=>hi(t,this.Mo):null}wa(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}eh(t,i){return this.wa(t,this.xo.priceFormatter,i)}da(t,i){const s=this.xo.priceFormatter;return this.ga(t,this.xo.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ua(t,i){return this.wa(t,this.xo.percentageFormatter,i)}ca(t,i){const s=this.xo.percentageFormatter;return this.ga(t,this.xo.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.po=[],this.ba=new Map,this.no=0,this.Ma=0,this.ya=1,this.vo=null,this.Sa=!1,this.xa=new a,this.Tr=[],this.cr=t,this.ss=i,this.Pa=new Qt(this);const s=i.O();this.Ca=this.Ta("left",s.leftPriceScale),this.ka=this.Ta("right",s.rightPriceScale),this.Ca.Bo().i(this.Da.bind(this,this.Ca),this),this.ka.Bo().i(this.Da.bind(this,this.ka),this),this.Ia(s)}Ia(t){if(t.leftPriceScale&&this.Ca.oh(t.leftPriceScale),t.rightPriceScale&&this.ka.oh(t.rightPriceScale),t.localization&&(this.Ca.gl(),this.ka.gl()),t.overlayPriceScales){const i=Array.from(this.ba.values());for(const s of i){const i=l(s[0].$t());i.oh(t.overlayPriceScales),t.localization&&i.gl()}}}Ra(t){switch(t){case"left":return this.Ca;case"right":return this.ka}return this.ba.has(t)?r(this.ba.get(t))[0].$t():null}m(){this.ti().Va().u(this),this.Ca.Bo().u(this),this.ka.Bo().u(this),this.po.forEach(t=>{t.m&&t.m()}),this.Tr=this.Tr.filter(t=>{const i=t._r();return i.detached&&i.detached(),!1}),this.xa.p()}Fa(){return this.ya}Ea(t){this.ya=t}ti(){return this.ss}ts(){return this.Ma}qt(){return this.no}La(t){this.Ma=t,this.Aa()}Wo(t){this.no=t,this.Ca.Wo(t),this.ka.Wo(t),this.po.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Wo(t)}}),this.Aa()}Ba(t){this.Sa=t}Wa(){return this.Sa}Oa(){return this.po.filter(mi)}Ml(){return this.po}Un(t){const i=t.$t();return null===i||this.Ca!==i&&this.ka!==i}ta(t,i,s){this.za(t,i,s?t.ls():this.po.length)}sa(t,i){const s=this.po.indexOf(t);h(-1!==s,"removeDataSource: invalid data source"),this.po.splice(s,1),i||this.po.forEach((t,i)=>t._s(i));const n=l(t.$t()).wl();if(this.ba.has(n)){const i=r(this.ba.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.ba.delete(n))}const e=t.$t();e&&e.Ml().indexOf(t)>=0&&(e.sa(t),this.$a(e)),this.vo=null}jn(t){return t===this.Ca?"left":t===this.ka?"right":"overlay"}Ha(){return this.Ca}Na(){return this.ka}Ua(t,i){t.ha(i)}qa(t,i){t.ra(i),this.Aa()}ja(t){t.la()}Ya(t,i){t.oa(i)}Ka(t,i){t.aa(i),this.Aa()}Ga(t){t._a()}Aa(){this.po.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.O().rightPriceScale.visible&&0!==this.ka.Ml().length?t=this.ka:this.ss.O().leftPriceScale.visible&&0!==this.Ca.Ml().length?t=this.Ca:0!==this.po.length&&(t=this.po[0].$t()),null===t&&(t=this.ka),t}qn(){let t=null;return this.ss.O().rightPriceScale.visible?t=this.ka:this.ss.O().leftPriceScale.visible&&(t=this.Ca),t}$a(t){null!==t&&t.Ro()&&this.Xa(t)}Za(t){const i=this.cr.Ce();t.Do({nn:!0}),null!==i&&t.fa(i),this.Aa()}Ja(){this.Xa(this.Ca),this.Xa(this.ka)}Qa(){this.$a(this.Ca),this.$a(this.ka),this.po.forEach(t=>{this.Un(t)&&this.$a(t.$t())}),this.Aa(),this.ss.ah()}Rt(){return null===this.vo&&(this.vo=ci(this.po)),this.vo}t_(t,i){i=Kt(i,0,this.po.length-1);const s=this.po.indexOf(t);h(-1!==s,"setSeriesOrder: invalid data source"),this.po.splice(s,1),this.po.splice(i,0,t),this.po.forEach((t,i)=>t._s(i)),this.vo=null;for(const t of[this.Ca,this.ka])t.ia(),t.gl();this.ss.ah()}Ft(){return this.Rt().filter(mi)}i_(){return this.xa}s_(){return this.Pa}ul(t){this.Tr.push(new Vt(t))}cl(t){this.Tr=this.Tr.filter(i=>i._r()!==t),t.detached&&t.detached(),this.ss.ah()}n_(){return this.Tr}nl(t,i){return this.Tr.map(s=>s.Kn(t,i)).filter(t=>null!==t)}Xa(t){const i=t.pa();if(i&&i.length>0&&!this.cr.Gi()){const i=this.cr.Ce();null!==i&&t.fa(i)}t.zs()}za(t,i,s){let n=this.Ra(i);if(null===n&&(n=this.Ta(i,this.ss.O().overlayPriceScales)),this.po.splice(s,0,t),!j(i)){const s=this.ba.get(i)||[];s.push(t),this.ba.set(i,s)}t._s(s),n.ta(t),t.us(n),this.$a(n),this.vo=null}Da(t,i,s){i.se!==s.se&&this.Xa(t)}Ta(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.O().layout,this.ss.O().localization,this.ss.Xi());return n.Wo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{e_:t.e_,h_:{Gn:t.r_.externalId},l_:t.r_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Kn){const n=t.Kn(i,s);if(null!==n)return{o_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Rt()],e=function(t,i,s){let n,e;for(const h of t){const t=h.nl?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=h)}return n&&e?{r_:n,e_:e}:null}(n,i,s);if("top"===e?.r_.zOrder)return bi(e);for(const h of n){if(e&&e.e_===h&&"bottom"!==e.r_.zOrder&&!e.r_.isBackground)return bi(e);if(yi(h)){const n=Mi(h.$s(t),i,s,t);if(null!==n)return{e_:h,o_:n.o_,h_:n.h_}}if(e&&e.e_===h&&"bottom"!==e.r_.zOrder&&e.r_.isBackground)return bi(e)}return e?.r_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Rn=new Map,this.In=new Map,this.a_=t,this.__=i,this.Vn=s}u_(t){const i=t.time,s=this.__.cacheKey(i),n=this.Rn.get(s);if(void 0!==n)return n.c_;if(this.Tn===this.Vn){const t=this.In.get(this.Dn);this.In.delete(this.Dn),this.Rn.delete(r(t)),this.Dn++,this.Tn--}const e=this.a_(t);return this.Rn.set(s,{c_:e,An:this.kn}),this.In.set(this.kn,s),this.Tn++,this.kn++,e}}class Pi{constructor(t,i){h(t<=i,"right should be >= left"),this.d_=t,this.p_=i}Ur(){return this.d_}yi(){return this.p_}f_(){return this.p_-this.d_+1}De(t){return this.d_<=t&&t<=this.p_}Ne(t){return this.d_===t.Ur()&&this.p_===t.yi()}}function Ci(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.v_=new Map,this.Rn=null,this.m_=!1}w_(t){this.m_=t,this.Rn=null}g_(t,i){this.b_(i),this.Rn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.v_.get(i.timeWeight);void 0===n&&(n=[],this.v_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}M_(t,i,s,n,e){const h=Math.ceil(i/t);return null!==this.Rn&&this.Rn.y_===h&&e===this.Rn.S_&&s===this.Rn.x_||(this.Rn={S_:e,x_:s,Rl:this.P_(h,s,n),y_:h}),this.Rn.Rl}b_(t){if(0===t)return void this.v_.clear();const i=[];this.v_.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.v_.delete(t)}P_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.v_.keys()).sort((t,i)=>i-t)){if(!this.v_.get(i))continue;const s=n;n=[];const h=s.length;let l=0;const o=r(this.v_.get(i)),a=o.length;let _=1/0,u=-1/0;for(let i=0;i<a;i++){const r=o[i],a=r.index;for(;l<h;){const t=s[l],i=t.index;if(!(i<a&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-a>=t&&a-u>=t&&e(r))n.push(r),u=a;else if(this.m_)return s}for(;l<h;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.C_=t}T_(){return null===this.C_?null:new Pi(Math.floor(this.C_.Ur()),Math.ceil(this.C_.yi()))}k_(){return this.C_}static D_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ii{constructor(t,i,s,n){this.Ma=0,this.I_=null,this.R_=[],this.bo=null,this.wo=null,this.V_=new Ti,this.F_=new Map,this.E_=ki.D_(),this.L_=!0,this.A_=new a,this.B_=new a,this.W_=new a,this.O_=null,this.z_=null,this.H_=new Map,this.N_=-1,this.U_=[],this.Cs=i,this.xo=s,this.q_=i.rightOffset,this.j_=i.barSpacing,this.ss=t,this.Y_(i),this.__=n,this.K_(),this.V_.w_(i.uniformDistribution),this.G_()}O(){return this.Cs}X_(t){_(this.xo,t),this.Z_(),this.K_()}oh(t,i){_(this.Cs,t),this.Cs.fixLeftEdge&&this.J_(),this.Cs.fixRightEdge&&this.Q_(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.Y_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.j_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Cs.ignoreWhitespaceIndices&&this.G_(),this.Z_(),this.K_(),this.W_.p()}Is(t){return this.R_[t]?.time??null}ns(t){return this.R_[t]??null}tu(t,i){if(this.R_.length<1)return null;if(this.__.key(t)>this.__.key(this.R_[this.R_.length-1].time))return i?this.R_.length-1:null;const s=yt(this.R_,this.__.key(t),(t,i)=>this.__.key(t.time)<i);return this.__.key(t)<this.__.key(this.R_[s].time)?i?s:null:s}Gi(){return 0===this.Ma||0===this.R_.length||null===this.I_}iu(){return this.R_.length>0}Ce(){return this.su(),this.E_.T_()}nu(){return this.su(),this.E_.k_()}eu(){const t=this.Ce();if(null===t)return null;const i={from:t.Ur(),to:t.yi()};return this.hu(i)}hu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.ru()),e=l(this.lu());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.tu(t.from,!0)),to:l(this.tu(t.to,!0))}}ts(){return this.Ma}La(t){if(!isFinite(t)||t<=0)return;if(this.Ma===t)return;const i=this.nu(),s=this.Ma;if(this.Ma=t,this.L_=!0,this.Cs.lockVisibleTimeRangeOnResize&&0!==s){const i=this.j_*t/s;this.j_=i}if(this.Cs.fixLeftEdge&&null!==i&&i.Ur()<=0){const i=s-t;this.q_-=Math.round(i/this.j_)+1,this.L_=!0}this.au(),this._u()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.uu()+this.q_-t;return this.Ma-(i+.5)*this.j_-1}cu(t,i){const s=this.uu(),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.q_-n,h=this.Ma-(e+.5)*this.j_-1;t[i].ut=h}}du(t,i){const s=Math.ceil(this.pu(t));return i&&this.Cs.ignoreWhitespaceIndices&&!this.fu(s)?this.vu(s):s}fn(t){this.L_=!0,this.q_=t,this._u(),this.ss.mu(),this.ss.ah()}wu(){return this.j_}pn(t){const i=this.j_;if(this.gu(t),void 0!==this.Cs.rightOffsetPixels&&0!==i){const t=this.q_*i/this.j_;this.q_=t}this._u(),this.ss.mu(),this.ss.ah()}bu(){return this.q_}Rl(){if(this.Gi())return null;if(null!==this.z_)return this.z_;const t=this.j_,i=5*(this.ss.O().layout.fontSize+4)/8*(this.Cs.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Ce()),e=Math.max(n.Ur(),n.Ur()-s),h=Math.max(n.yi(),n.yi()-s),r=this.V_.M_(t,i,this.Cs.ignoreWhitespaceIndices,this.H_,this.N_),o=this.ru()+s,a=this.lu()-s,_=this.Mu(),u=this.Cs.fixLeftEdge||_,c=this.Cs.fixRightEdge||_;let d=0;for(const t of r){if(!(e<=t.index&&t.index<=h))continue;let s;d<this.U_.length?(s=this.U_[d],s.coord=this.jt(t.index),s.label=this.yu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.yu(t),weight:t.weight},this.U_.push(s)),this.j_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.U_.length=d,this.z_=this.U_,this.U_}Su(){let t;this.L_=!0,this.pn(this.Cs.barSpacing),t=void 0!==this.Cs.rightOffsetPixels?this.Cs.rightOffsetPixels/this.wu():this.Cs.rightOffset,this.fn(t)}xu(t){this.L_=!0,this.I_=t,this._u(),this.J_()}Pu(t,i){const s=this.pu(t),n=this.wu(),e=n+i*(n/10);this.pn(e),this.Cs.rightBarStaysOnScroll||this.fn(this.bu()+(s-this.pu(t)))}ha(t){this.bo&&this._a(),null===this.wo&&null===this.O_&&(this.Gi()||(this.wo=t,this.Cu()))}ra(t){if(null===this.O_)return;const i=Kt(this.Ma-t,0,this.Ma),s=Kt(this.Ma-l(this.wo),0,this.Ma);0!==i&&0!==s&&this.pn(this.O_.wu*i/s)}la(){null!==this.wo&&(this.wo=null,this.Tu())}oa(t){null===this.bo&&null===this.O_&&(this.Gi()||(this.bo=t,this.Cu()))}aa(t){if(null===this.bo)return;const i=(this.bo-t)/this.wu();this.q_=l(this.O_).bu+i,this.L_=!0,this._u()}_a(){null!==this.bo&&(this.bo=null,this.Tu())}ku(){this.Du(this.Cs.rightOffset)}Du(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.q_,n=performance.now();this.ss.un({Iu:t=>(t-n)/i>=1,Ru:e=>{const h=(e-n)/i;return h>=1?t:s+(t-s)*h}})}Tt(t,i){this.L_=!0,this.R_=t,this.V_.g_(t,i),this._u()}Vu(){return this.A_}Fu(){return this.B_}Eu(){return this.W_}uu(){return this.I_||0}Lu(t,i){const s=t.f_(),n=i&&this.Cs.rightOffsetPixels||0;this.gu((this.Ma-n)/s),this.q_=t.yi()-this.uu(),i&&(this.q_=n?n/this.wu():this.Cs.rightOffset),this._u(),this.L_=!0,this.ss.mu(),this.ss.ah()}Au(){const t=this.ru(),i=this.lu();null!==t&&null!==i&&this.Lu(new Pi(t,i),!0)}Bu(t){const i=new Pi(t.from,t.to);this.Lu(i)}es(t){return void 0!==this.xo.timeFormatter?this.xo.timeFormatter(t.originalTime):this.__.formatHorzItem(t.time)}G_(){if(!this.Cs.ignoreWhitespaceIndices)return;this.H_.clear();const t=this.ss.Ks();for(const i of t)for(const t of i.ml())this.H_.set(t,!0);this.N_++}Mu(){const t=this.ss.O().handleScroll,i=this.ss.O().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}ru(){return 0===this.R_.length?null:0}lu(){return 0===this.R_.length?null:this.R_.length-1}Wu(t){return(this.Ma-1-t)/this.j_}pu(t){const i=this.Wu(t),s=this.uu()+this.q_-i;return Math.round(1e6*s)/1e6}gu(t){const i=this.j_;this.j_=t,this.au(),i!==this.j_&&(this.L_=!0,this.Ou())}su(){if(!this.L_)return;if(this.L_=!1,this.Gi())return void this.zu(ki.D_());const t=this.uu(),i=this.Ma/this.j_,s=this.q_+t,n=new Pi(s-i+1,s);this.zu(new ki(n))}au(){const t=Kt(this.j_,this.$u(),this.Hu());this.j_!==t&&(this.j_=t,this.L_=!0)}Hu(){return this.Cs.maxBarSpacing>0?this.Cs.maxBarSpacing:.5*this.Ma}$u(){return this.Cs.fixLeftEdge&&this.Cs.fixRightEdge&&0!==this.R_.length?this.Ma/this.R_.length:this.Cs.minBarSpacing}_u(){const t=this.Nu();null!==t&&this.q_<t&&(this.q_=t,this.L_=!0);const i=this.Uu();this.q_>i&&(this.q_=i,this.L_=!0)}Nu(){const t=this.ru(),i=this.I_;if(null===t||null===i)return null;return t-i-1+(this.Cs.fixLeftEdge?this.Ma/this.j_:Math.min(2,this.R_.length))}Uu(){return this.Cs.fixRightEdge?0:this.Ma/this.j_-Math.min(2,this.R_.length)}Cu(){this.O_={wu:this.wu(),bu:this.bu()}}Tu(){this.O_=null}yu(t){let i=this.F_.get(t.weight);return void 0===i&&(i=new xi(t=>this.qu(t),this.__),this.F_.set(t.weight,i)),i.u_(t)}qu(t){return this.__.formatTickmark(t,this.xo)}zu(t){const i=this.E_;this.E_=t,Ci(i.T_(),this.E_.T_())||this.A_.p(),Ci(i.k_(),this.E_.k_())||this.B_.p(),this.Ou()}Ou(){this.z_=null}Z_(){this.Ou(),this.F_.clear()}K_(){this.__.updateFormatter(this.xo)}J_(){if(!this.Cs.fixLeftEdge)return;const t=this.ru();if(null===t)return;const i=this.Ce();if(null===i)return;const s=i.Ur()-t;if(s<0){const t=this.q_-s-1;this.fn(t)}this.au()}Q_(){this._u(),this.au()}fu(t){return!this.Cs.ignoreWhitespaceIndices||(this.H_.get(t)||!1)}vu(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.lu();for(;s;){const t=i.next().value;if(this.H_.get(t))return t;if(t<0||t>s)break}return t}Y_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.j_);this.ss.fn(i)}}}var Ri,Vi,Fi,Ei,Li;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Ri||(Ri={}));class Ai{constructor(t,i,s){this.ju=[],this.Yu=[],this.Ma=0,this.Ku=null,this.Gu=new a,this.Xu=new a,this.Zu=null,this.Ju=t,this.Cs=i,this.__=s,this.Po=new S(this.Cs.layout.colorParsers),this.Qu=new b(this),this.cr=new Ii(this,i.timeScale,this.Cs.localization,s),this.Pt=new q(this,i.crosshair),this.tc=new Yt(i.crosshair),i.addDefaultPane&&(this.sc(0),this.ju[0].Ea(2)),this.nc=this.ec(0),this.hc=this.ec(1)}Er(){this.rc(Y.bn())}ah(){this.rc(Y.gn())}Zr(){this.rc(new Y(1))}Lr(t){const i=this.lc(t);this.rc(i)}oc(){return this.Ku}ac(t){if(this.Ku?.e_===t?.e_&&this.Ku?.h_?.Gn===t?.h_?.Gn)return;const i=this.Ku;this.Ku=t,null!==i&&this.Lr(i.e_),null!==t&&t.e_!==i?.e_&&this.Lr(t.e_)}O(){return this.Cs}oh(t){_(this.Cs,t),this.ju.forEach(i=>i.Ia(t)),void 0!==t.timeScale&&this.cr.oh(t.timeScale),void 0!==t.localization&&this.cr.X_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Gu.p(),this.nc=this.ec(0),this.hc=this.ec(1),this.Er()}_c(t,i,s=0){const n=this.ju[s];if(void 0===n)return;if("left"===t)return _(this.Cs,{leftPriceScale:i}),n.Ia({leftPriceScale:i}),this.Gu.p(),void this.Er();if("right"===t)return _(this.Cs,{rightPriceScale:i}),n.Ia({rightPriceScale:i}),this.Gu.p(),void this.Er();const e=this.uc(t,s);null!==e&&(e.$t.oh(i),this.Gu.p())}uc(t,i){const s=this.ju[i];if(void 0===s)return null;const n=s.Ra(t);return null!==n?{Us:s,$t:n}:null}Lt(){return this.cr}qs(){return this.ju}cc(){return this.Pt}dc(){return this.Xu}fc(t,i){t.Wo(i),this.mu()}La(t){this.Ma=t,this.cr.La(this.Ma),this.ju.forEach(i=>i.La(t)),this.mu()}vc(t){1!==this.ju.length&&(h(t>=0&&t<this.ju.length,"Invalid pane index"),this.ju.splice(t,1),this.Er())}mc(t,i){if(this.ju.length<2)return;h(t>=0&&t<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju.reduce((t,i)=>t+i.Fa(),0),e=this.ju.reduce((t,i)=>t+i.qt(),0),r=e-30*(this.ju.length-1);i=Math.min(r,Math.max(30,i));const l=n/e,o=s.qt();s.Ea(i*l);let a=i-o,_=this.ju.length-1;for(const t of this.ju)if(t!==s){const i=Math.min(r,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.Ea(s)}this.Er()}wc(t,i){h(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju[i];this.ju[t]=n,this.ju[i]=s,this.Er()}gc(t,i){if(h(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index"),t===i)return;const[s]=this.ju.splice(t,1);this.ju.splice(i,0,s),this.Er()}Ua(t,i,s){t.Ua(i,s)}qa(t,i,s){t.qa(i,s),this.Ar(),this.rc(this.bc(t,2))}ja(t,i){t.ja(i),this.rc(this.bc(t,2))}Ya(t,i,s){i.Ro()||t.Ya(i,s)}Ka(t,i,s){i.Ro()||(t.Ka(i,s),this.Ar(),this.rc(this.bc(t,2)))}Ga(t,i){i.Ro()||(t.Ga(i),this.rc(this.bc(t,2)))}Za(t,i){t.Za(i),this.rc(this.bc(t,2))}Mc(t){this.cr.ha(t)}yc(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.Pu(t,i),this.mu()}Sc(t){this.xc(0),this.Pc(t),this.Cc()}Tc(t){this.cr.ra(t),this.mu()}kc(){this.cr.la(),this.ah()}xc(t){this.cr.oa(t)}Pc(t){this.cr.aa(t),this.mu()}Cc(){this.cr._a(),this.ah()}Ks(){return this.Yu}Dc(t,i,s,n,e){this.Pt.Vs(t,i);let h=NaN,r=this.cr.du(t,!0);const l=this.cr.Ce();null!==l&&(r=Math.min(Math.max(l.Ur(),r),l.yi()));const o=n.ks(),a=o.Bt();if(null!==a&&(h=o.Ds(i,a)),h=this.tc.bl(h,r,n),this.Pt.As(r,h,n),this.Zr(),!e){const e=Si(n,t,i);this.ac(e&&{e_:e.e_,h_:e.h_,l_:e.l_||null}),this.Xu.p(this.Pt.Et(),{x:t,y:i},s)}}Ic(t,i,s){const n=s.ks(),e=n.Bt(),h=n.zt(t,l(e)),r=this.cr.tu(i,!0),o=this.cr.jt(l(r));this.Dc(o,h,null,s,!0)}Rc(t){this.cc().Ws(),this.Zr(),t||this.Xu.p(null,null,null)}Ar(){const t=this.Pt.Us();if(null!==t){const i=this.Pt.Es(),s=this.Pt.Ls();this.Dc(i,s,null,t)}this.Pt.zs()}Vc(t,i,s){const n=this.cr.Is(0);void 0!==i&&void 0!==s&&this.cr.Tt(i,s);const e=this.cr.Is(0),h=this.cr.uu(),r=this.cr.Ce();if(null!==r&&null!==n&&null!==e){const i=r.De(h),l=this.__.key(n)>this.__.key(e),o=null!==t&&t>h&&!l,a=this.cr.O().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.cr.O().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-h;this.cr.fn(this.cr.bu()-i)}}this.cr.xu(t)}Wr(t){null!==t&&t.Qa()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.ju.find(i=>i.Rt().includes(t));return void 0===i?null:i}mu(){this.ju.forEach(t=>t.Qa()),this.Ar()}m(){this.ju.forEach(t=>t.m()),this.ju.length=0,this.Cs.localization.priceFormatter=void 0,this.Cs.localization.percentageFormatter=void 0,this.Cs.localization.timeFormatter=void 0}Fc(){return this.Qu}Yn(){return this.Qu.O()}Va(){return this.Gu}Ec(t,i){const s=this.sc(i);this.Lc(t,s),this.Yu.push(t),1===this.Yu.length?this.Er():this.ah()}Ac(t){const i=this.Nn(t),s=this.Yu.indexOf(t);h(-1!==s,"Series not found");const n=l(i);this.Yu.splice(s,1),n.sa(t),t.m&&t.m(),this.cr.G_();const e=this.ju.length;this.Bc(n),this.ju.length<e&&this.Er()}Fr(t,i){const s=l(this.Nn(t));s.sa(t,!0),s.ta(t,i,!0)}Au(){const t=Y.gn();t.rn(),this.rc(t)}Wc(t){const i=Y.gn();i._n(t),this.rc(i)}dn(){const t=Y.gn();t.dn(),this.rc(t)}pn(t){const i=Y.gn();i.pn(t),this.rc(i)}fn(t){const i=Y.gn();i.fn(t),this.rc(i)}un(t){const i=Y.gn();i.un(t),this.rc(i)}ln(){const t=Y.gn();t.ln(),this.rc(t)}Oc(){return this.Cs.rightPriceScale.visible?"right":"left"}zc(t,i){h(i>=0,"Index should be greater or equal to 0");if(i===this.$c(t))return;const s=l(this.Nn(t));s.sa(t);const n=this.sc(i);this.Lc(t,n),0===s.Ml().length&&this.Bc(s),this.Er()}Hc(){return this.hc}q(){return this.nc}Ut(t){const i=this.hc,s=this.nc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Zu||this.Zu.gh!==s||this.Zu.bh!==i)this.Zu={gh:s,bh:i,Nc:new Map};else{const i=this.Zu.Nc.get(t);if(void 0!==i)return i}const n=this.Po.it(s,i,t/100);return this.Zu.Nc.set(t,n),n}Uc(t){return this.ju.indexOf(t)}Xi(){return this.Po}qc(){return this.jc()}jc(t){const i=new wi(this.cr,this);this.ju.push(i);const s=t??this.ju.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.rc(n),i}sc(t){return h(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.ju.length,t))<this.ju.length?this.ju[t]:this.jc(t)}$c(t){return this.ju.findIndex(i=>i.Oa().includes(t))}bc(t,i){const s=new Y(i);if(null!==t){const n=this.ju.indexOf(t);s.tn(n,{sn:i})}return s}lc(t,i){return void 0===i&&(i=2),this.bc(this.Nn(t),i)}rc(t){this.Ju&&this.Ju(t),this.ju.forEach(t=>t.s_()._h().Tt())}Lc(t,i){const s=t.O().priceScaleId,n=void 0!==s?s:this.Oc();i.ta(t,n),j(n)||t.oh(t.O())}ec(t){const i=this.Cs.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Bc(t){!t.Wa()&&0===t.Ml().length&&this.ju.length>1&&this.ju.splice(this.Uc(t),1)}}function Bi(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 Wi(t){return!u(t)&&!d(t)}function Oi(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"}(Fi||(Fi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Ei||(Ei={})),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=>X(zi(t),4))(t)).replace(/yy/g,(t=>X(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=>X((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>X((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Yc=t,this.Kc=i}u_(t){return $i(t,this.Yc,this.Kc)}}class Ni{constructor(t){this.Gc=t||"%h:%m:%s"}u_(t){return this.Gc.replace("%h",X(t.getUTCHours(),2)).replace("%m",X(t.getUTCMinutes(),2)).replace("%s",X(t.getUTCSeconds(),2))}}const Ui={Xc:"yyyy-MM-dd",Zc:"%h:%m:%s",Jc:" ",Qc:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.td=new Hi(i.Xc,i.Qc),this.sd=new Ni(i.Zc),this.nd=i.Jc}u_(t){return`${this.td.u_(t)}${this.nd}${this.sd.u_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Ki=[{ed:(Gi=1,1e3*Gi),hd:10},{ed:Yi(1),hd:20},{ed:Yi(5),hd:21},{ed:Yi(30),hd:22},{ed:ji(1),hd:30},{ed:ji(3),hd:31},{ed:ji(6),hd:32},{ed:ji(12),hd:33}];var Gi;function Xi(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=Ki.length-1;s>=0;--s)if(Math.floor(i.getTime()/Ki[s].ed)!==Math.floor(t.getTime()/Ki[s].ed))return Ki[s].hd;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Wi(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{rd:Math.round(s.getTime()/1e3),ld:i}}function Qi(t){if(!Oi(t))throw new Error("time must be of type isUTCTimestamp");return{rd: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))}class ss{options(){return this.Cs}setOptions(t){this.Cs=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:Wi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"rd"in t?t.rd:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ld?new Date(1e3*i.rd).getTime():new Date(Date.UTC(i.ld.year,i.ld.month-1,i.ld.day)).getTime()}convertHorzItemToInternal(t){return Oi(i=t)?Qi(i):Wi(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Cs)return;const i=t.dateFormat;this.Cs.timeScale.timeVisible?this.od=new qi({Xc:i,Zc:this.Cs.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Jc:" ",Qc:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.u_(new Date(1e3*i.rd))}formatTickmark(t,i){const s=function(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}}(t.weight,this.Cs.timeScale.timeVisible,this.Cs.timeScale.secondsVisible),n=this.Cs.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.ld?new Date(1e3*t.rd):new Date(Date.UTC(t.ld.year,t.ld.month-1,t.ld.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.rd,n=null!==s?new Date(1e3*s):null,e=0;for(let h=i;h<t.length;++h){const i=t[h],r=new Date(1e3*Zi(i.time).rd);null!==n&&(i.timeWeight=Xi(r,n)),e+=Zi(i.time).rd-(s||Zi(i.time).rd),s=Zi(i.time).rd,n=r}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.rd-i));t[0].timeWeight=Xi(new Date(1e3*t[0].time.rd),s)}}(t,i)}static ad(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function ns(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 es(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 rs=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=ns({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 ns({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=ns(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;es(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=ns(this._transformBitmapSize(t,this._canvasElementClientSize)),n=es(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&es(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=ls(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=ls(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(),h=void 0!==e[0]?function(t,i){return ns({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):ns({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(h)}}},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=ns({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function ls(t){return t.ownerDocument.defaultView}var os=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 as(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 os(e,s,n)}const _s="undefined"!=typeof window;function us(){return!!_s&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function cs(){return!!_s&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ds(t){return t+t%2}function ps(t){_s&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class fs{constructor(t,i,s){this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.md=null,this.wd=!1,this.gd=null,this.bd=null,this.Md=!1,this.yd=!1,this.Sd=!1,this.xd=null,this.Pd=null,this.Cd=null,this.Td=null,this.kd=null,this.Dd=null,this.Id=null,this.Rd=0,this.Vd=!1,this.Fd=!1,this.Ed=!1,this.Ld=0,this.Ad=null,this.Bd=!cs(),this.Wd=t=>{this.Od(t)},this.zd=t=>{if(this.$d(t)){const i=this.Hd(t);if(++this.pd,this.fd&&this.pd>1){const{Nd:s}=this.Ud(ws(t),this.vd);s<30&&!this.Sd&&this.qd(i,this.Yd.jd),this.Kd()}}else{const i=this.Hd(t);if(++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Xd),this.Zd()}}},this.Jd=t,this.Yd=i,this.Cs=s,this.Qd()}m(){null!==this.xd&&(this.xd(),this.xd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Cd&&(this.Cd(),this.Cd=null),this.tp(),this.Zd()}ip(t){this.Td&&this.Td();const i=this.sp.bind(this);if(this.Td=()=>{this.Jd.removeEventListener("mousemove",i)},this.Jd.addEventListener("mousemove",i),this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.np),this.Bd=!0}Zd(){null!==this.ud&&clearTimeout(this.ud),this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Kd(){null!==this.fd&&clearTimeout(this.fd),this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}sp(t){if(this.Ed||null!==this.bd)return;if(this.$d(t))return;const i=this.Hd(t);this.Gd(i,this.Yd.ep),this.Bd=!0}hp(t){const i=bs(t.changedTouches,l(this.Ad));if(null===i)return;if(this.Ld=gs(t),null!==this.Id)return;if(this.Fd)return;this.Vd=!0;const s=this.Ud(ws(i),l(this.bd)),{rp:n,lp:e,Nd:h}=s;if(this.Md||!(h<5)){if(!this.Md){const t=.5*n,i=e>=t&&!this.Cs.op(),s=t>e&&!this.Cs.ap();i||s||(this.Fd=!0),this.Md=!0,this.Sd=!0,this.tp(),this.Kd()}if(!this.Fd){const s=this.Hd(t,i);this.qd(s,this.Yd._p),ms(t)}}}up(t){if(0!==t.button)return;const i=this.Ud(ws(t),l(this.gd)),{Nd:s}=i;if(s>=5&&(this.yd=!0,this.Zd()),this.yd){const i=this.Hd(t);this.Gd(i,this.Yd.cp)}}Ud(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{rp:s,lp:n,Nd:s+n}}dp(t){let i=bs(t.changedTouches,l(this.Ad));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ad=null,this.Ld=gs(t),this.tp(),this.bd=null,this.Dd&&(this.Dd(),this.Dd=null);const s=this.Hd(t,i);if(this.qd(s,this.Yd.pp),++this.pd,this.fd&&this.pd>1){const{Nd:t}=this.Ud(ws(i),this.vd);t<30&&!this.Sd&&this.qd(s,this.Yd.jd),this.Kd()}else this.Sd||(this.qd(s,this.Yd.fp),this.Yd.fp&&ms(t));0===this.pd&&ms(t),0===t.touches.length&&this.wd&&(this.wd=!1,ms(t))}Od(t){if(0!==t.button)return;const i=this.Hd(t);if(this.gd=null,this.Ed=!1,this.kd&&(this.kd(),this.kd=null),us()){this.Jd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Wd)}if(!this.$d(t))if(this.Gd(i,this.Yd.vp),++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Xd),this.Zd()}else this.yd||this.Gd(i,this.Yd.mp)}tp(){null!==this.md&&(clearTimeout(this.md),this.md=null)}wp(t){if(null!==this.Ad)return;const i=t.changedTouches[0];this.Ad=i.identifier,this.Ld=gs(t);const s=this.Jd.ownerDocument.documentElement;this.Sd=!1,this.Md=!1,this.Fd=!1,this.bd=ws(i),this.Dd&&(this.Dd(),this.Dd=null);{const i=this.hp.bind(this),n=this.dp.bind(this);this.Dd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.tp(),this.md=setTimeout(this.gp.bind(this,t),240)}const n=this.Hd(t,i);this.qd(n,this.Yd.bp),this.fd||(this.pd=0,this.fd=setTimeout(this.Kd.bind(this),500),this.vd=ws(i))}Mp(t){if(0!==t.button)return;const i=this.Jd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Wd),this.yd=!1,this.gd=ws(t),this.kd&&(this.kd(),this.kd=null);{const t=this.up.bind(this),s=this.Od.bind(this);this.kd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ed=!0,this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.yp),this.ud||(this._d=0,this.ud=setTimeout(this.Zd.bind(this),500),this.dd=ws(t))}Qd(){this.Jd.addEventListener("mouseenter",this.ip.bind(this)),this.Jd.addEventListener("touchcancel",this.tp.bind(this));{const t=this.Jd.ownerDocument,i=t=>{this.Yd.Sp&&(t.composed&&this.Jd.contains(t.composedPath()[0])||t.target&&this.Jd.contains(t.target)||this.Yd.Sp())};this.Pd=()=>{t.removeEventListener("touchstart",i)},this.xd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Cd=()=>{this.Jd.removeEventListener("dblclick",this.zd)},this.Jd.addEventListener("dblclick",this.zd)),this.Jd.addEventListener("mouseleave",this.xp.bind(this)),this.Jd.addEventListener("touchstart",this.wp.bind(this),{passive:!0}),ps(this.Jd),this.Jd.addEventListener("mousedown",this.Mp.bind(this)),this.Pp(),this.Jd.addEventListener("touchmove",()=>{},{passive:!1})}Pp(){void 0===this.Yd.Cp&&void 0===this.Yd.Tp&&void 0===this.Yd.kp||(this.Jd.addEventListener("touchstart",t=>this.Dp(t.touches),{passive:!0}),this.Jd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Id&&void 0!==this.Yd.Tp){const i=vs(t.touches[0],t.touches[1])/this.Rd;this.Yd.Tp(this.Id,i),ms(t)}},{passive:!1}),this.Jd.addEventListener("touchend",t=>{this.Dp(t.touches)}))}Dp(t){1===t.length&&(this.Vd=!1),2!==t.length||this.Vd||this.wd?this.Ip():this.Rp(t)}Rp(t){const i=this.Jd.getBoundingClientRect()||{left:0,top:0};this.Id={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.Rd=vs(t[0],t[1]),void 0!==this.Yd.Cp&&this.Yd.Cp(),this.tp()}Ip(){null!==this.Id&&(this.Id=null,void 0!==this.Yd.kp&&this.Yd.kp())}xp(t){if(this.Td&&this.Td(),this.$d(t))return;if(!this.Bd)return;const i=this.Hd(t);this.Gd(i,this.Yd.Vp),this.Bd=!cs()}gp(t){const i=bs(t.touches,l(this.Ad));if(null===i)return;const s=this.Hd(t,i);this.qd(s,this.Yd.Fp),this.Sd=!0,this.wd=!0}$d(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ld+500}qd(t,i){i&&i.call(this.Yd,t)}Gd(t,i){i&&i.call(this.Yd,t)}Hd(t,i){const s=i||t,n=this.Jd.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,Ep:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Lp:t.type,Ap:s.target,o_:t.view,Bp:()=>{"touchstart"!==t.type&&ms(t)}}}}function vs(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ms(t){t.cancelable&&t.preventDefault()}function ws(t){return{ut:t.pageX,ct:t.pageY}}function gs(t){return t.timeStamp||performance.now()}function bs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ms{constructor(t,i,s){this.Wp=null,this.Op=null,this.zp=!0,this.$p=null,this.Hp=t,this.Np=t.Up()[i],this.qp=t.Up()[s],this.jp=document.createElement("tr"),this.jp.style.height="1px",this.Yp=document.createElement("td"),this.Yp.style.position="relative",this.Yp.style.padding="0",this.Yp.style.margin="0",this.Yp.setAttribute("colspan","3"),this.Kp(),this.jp.appendChild(this.Yp),this.zp=this.Hp.O().layout.panes.enableResize,this.zp?this.Gp():(this.Wp=null,this.Op=null)}m(){null!==this.Op&&this.Op.m()}Xp(){return this.jp}Zp(){return ns({width:this.Np.Zp().width,height:1})}Jp(){return ns({width:this.Np.Jp().width,height:1*window.devicePixelRatio})}Qp(t,i,s){const n=this.Jp();t.fillStyle=this.Hp.O().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Kp(),this.Hp.O().layout.panes.enableResize!==this.zp&&(this.zp=this.Hp.O().layout.panes.enableResize,this.zp?this.Gp():(null!==this.Wp&&(this.Yp.removeChild(this.Wp.tf),this.Yp.removeChild(this.Wp.if),this.Wp=null),null!==this.Op&&(this.Op.m(),this.Op=null)))}Gp(){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.Yp.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.Yp.appendChild(s);const e={np:this.sf.bind(this),Vp:this.nf.bind(this),yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.hf.bind(this),_p:this.hf.bind(this),vp:this.rf.bind(this),pp:this.rf.bind(this)};this.Op=new fs(s,e,{op:()=>!1,ap:()=>!0}),this.Wp={if:s,tf:t}}Kp(){this.Yp.style.background=this.Hp.O().layout.panes.separatorColor}sf(t){null!==this.Wp&&(this.Wp.if.style.backgroundColor=this.Hp.O().layout.panes.separatorHoverColor)}nf(t){null!==this.Wp&&null===this.$p&&(this.Wp.if.style.backgroundColor="")}ef(t){if(null===this.Wp)return;const i=this.Np.lf().Fa()+this.qp.lf().Fa(),s=i/(this.Np.Zp().height+this.qp.Zp().height),n=30*s;i<=2*n||(this.$p={af:t.pageY,_f:this.Np.lf().Fa(),uf:i-n,cf:i,df:s,pf:n},this.Wp.tf.style.display="block")}hf(t){const i=this.$p;if(null===i)return;const s=(t.pageY-i.af)*i.df,n=Kt(i._f+s,i.pf,i.uf);this.Np.lf().Ea(n),this.qp.lf().Ea(i.cf-n),this.Hp.ti().Er()}rf(t){null!==this.$p&&null!==this.Wp&&(this.$p=null,this.Wp.tf.style.display="none")}}function ys(t,i){return t.ff-i.ff}function Ss(t,i,s){const n=(t.ff-i.ff)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.vf=null,this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=0,this.yf=0,this.Sf=t,this.xf=i,this.Pf=s,this.Mn=n}Cf(t,i){if(null!==this.vf){if(this.vf.gt===i)return void(this.vf.ff=t);if(Math.abs(this.vf.ff-t)<this.Mn)return}this.gf=this.wf,this.wf=this.mf,this.mf=this.vf,this.vf={gt:i,ff:t}}ae(t,i){if(null===this.vf||null===this.mf)return;if(i-this.vf.gt>50)return;let s=0;const n=Ss(this.vf,this.mf,this.xf),e=ys(this.vf,this.mf),h=[n],r=[e];if(s+=e,null!==this.wf){const t=Ss(this.mf,this.wf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.mf,this.wf);if(h.push(t),r.push(i),s+=i,null!==this.gf){const t=Ss(this.wf,this.gf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);h.push(t),r.push(i),s+=i}}}}let l=0;for(let t=0;t<h.length;++t)l+=r[t]/s*h[t];Math.abs(l)<this.Sf||(this.bf={ff:t,gt:i},this.yf=l,this.Mf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Pf))}Ru(t){const i=l(this.bf),s=t-i.gt;return i.ff+this.yf*(Math.pow(this.Pf,s)-1)/Math.log(this.Pf)}Iu(t){return null===this.bf||this.Tf(t)===this.Mf}Tf(t){const i=t-l(this.bf).gt;return Math.min(i,this.Mf)}}class Ps{constructor(t,i){this.kf=void 0,this.Df=void 0,this.If=void 0,this.vs=!1,this.Rf=t,this.Vf=i,this.Ff()}Tt(){this.Ff()}Ef(){this.kf&&this.Rf.removeChild(this.kf),this.Df&&this.Rf.removeChild(this.Df),this.kf=void 0,this.Df=void 0}Lf(){return this.vs!==this.Af()||this.If!==this.Bf()}Bf(){return this.Vf.ti().Xi().tt(this.Vf.O().layout.textColor)>160?"dark":"light"}Af(){return this.Vf.O().layout.attributionLogo}Wf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Ff(){this.Lf()&&(this.Ef(),this.vs=this.Af(),this.vs&&(this.If=this.Bf(),this.Df=document.createElement("style"),this.Df.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.kf=document.createElement("a"),this.kf.href=`https://pipsend.com${this.Wf()}`,this.kf.title="Powered by Pipsend Charts",this.kf.id="pipsend-attr-logo",this.kf.target="_blank",this.kf.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.kf.toggleAttribute("data-dark","dark"===this.If),this.Rf.appendChild(this.Df),this.Rf.appendChild(this.kf)))}}function Cs(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new rs(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 Ts(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function ks(t,i,s,n){t.sr&&t.sr(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function Is(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Rs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.wl()??"")!==i?[]:s.il?.(t)??[]}}function Vs(t,i,s,n){if(!t.length)return;let e=0;const h=t[0].qt(n,!0);let r=1===i?s/2-(t[0].$i()-h/2):t[0].$i()-h/2-s/2;r=Math.max(0,r);for(let h=1;h<t.length;h++){const l=t[h],o=t[h-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 h=n-i*a/2;if((1===i?h<0:h>s)&&r>0){const n=1===i?-1-h:h-s,l=Math.min(n,r);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);r-=l}}else e=h,r=1===i?u-a-_:_-(u+a)}}class Fs{constructor(t,i,s,n){this.Yi=null,this.Of=null,this.zf=!1,this.$f=new it(200),this.Hf=null,this.Nf=0,this.Uf=!1,this.qf=()=>{this.Uf||this.Ct.jf().ti().ah()},this.Yf=()=>{this.Uf||this.Ct.jf().ti().ah()},this.Ct=t,this.Cs=i,this.So=i.layout,this.Qu=s,this.Kf="left"===n,this.Gf=Rs("normal",n),this.Xf=Rs("top",n),this.Zf=Rs("bottom",n),this.Yp=document.createElement("div"),this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Yp.style.width="25px",this.Yp.style.left="0",this.Yp.style.position="relative",this.Jf=Cs(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const e=this.Jf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.Qf=Cs(this.Yp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const h=this.Qf.canvasElement;h.style.position="absolute",h.style.zIndex="2",h.style.left="0",h.style.top="0";const r={yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.hf.bind(this),_p:this.hf.bind(this),Sp:this.tv.bind(this),vp:this.rf.bind(this),pp:this.rf.bind(this),Xd:this.iv.bind(this),jd:this.iv.bind(this),np:this.sv.bind(this),Vp:this.nf.bind(this)};this.Op=new fs(this.Qf.canvasElement,r,{op:()=>!this.Cs.handleScroll.vertTouchDrag,ap:()=>!0})}m(){this.Op.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Yi&&this.Yi.ea().u(this),this.Yi=null}Xp(){return this.Yp}C(){return this.So.fontSize}nv(){const t=this.Qu.O();return this.Hf!==t.T&&(this.$f.Fn(),this.Hf=t.T),t}ev(){if(null===this.Yi)return 0;let t=0;const i=this.nv(),s=l(this.Jf.canvasElement.getContext("2d",{colorSpace:this.Ct.jf().O().layout.colorSpace}));s.save();const n=this.Yi.Rl();s.font=this.hv(),n.length>0&&(t=Math.max(this.$f.Vi(s,n[0].Zl),this.$f.Vi(s,n[n.length-1].Zl)));const e=this.rv();for(let i=e.length;i--;){const n=this.$f.Vi(s,e[i].ri());n>t&&(t=n)}const h=this.Yi.Bt();if(null!==h&&null!==this.Of&&(2!==(r=this.Cs.crosshair).mode&&r.horzLine.visible&&r.horzLine.labelVisible)){const i=this.Yi.Ds(1,h),n=this.Yi.Ds(this.Of.height-2,h);t=Math.max(t,this.$f.Vi(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,h)),this.$f.Vi(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,h)))}var r;s.restore();const o=t||34;return ds(Math.ceil(i.S+i.P+i.F+i.L+5+o))}lv(t){null!==this.Of&&es(this.Of,t)||(this.Of=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`)}ov(){return l(this.Of).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ea().u(this),this.Yi=t,t.ea().i(this.co.bind(this),this))}$t(){return this.Yi}Fn(){const t=this.Ct.lf();this.Ct.jf().ti().Za(t,l(this.$t()))}av(t){if(null===this.Of)return;const i={colorSpace:this.Ct.jf().O().layout.colorSpace};if(1!==t){this._v(),this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)}),this.Ct.dv(t,this.Zf),this.pv(t),this.Ct.dv(t,this.Gf),this.fv(t))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.vv(s),this.Ct.dv(s,this.Xf))}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Rl()}ef(t){if(null===this.Yi||this.Yi.Gi()||!this.Cs.handleScale.axisPressedMouseMove.price)return;const i=this.Ct.jf().ti(),s=this.Ct.lf();this.zf=!0,i.Ua(s,this.Yi,t.localY)}hf(t){if(null===this.Yi||!this.Cs.handleScale.axisPressedMouseMove.price)return;const i=this.Ct.jf().ti(),s=this.Ct.lf(),n=this.Yi;i.qa(s,n,t.localY)}tv(){if(null===this.Yi||!this.Cs.handleScale.axisPressedMouseMove.price)return;const t=this.Ct.jf().ti(),i=this.Ct.lf(),s=this.Yi;this.zf&&(this.zf=!1,t.ja(i,s))}rf(t){if(null===this.Yi||!this.Cs.handleScale.axisPressedMouseMove.price)return;const i=this.Ct.jf().ti(),s=this.Ct.lf();this.zf=!1,i.ja(s,this.Yi)}iv(t){this.Cs.handleScale.axisDoubleClickReset.price&&this.Fn()}sv(t){if(null===this.Yi)return;!this.Ct.jf().ti().O().handleScale.axisPressedMouseMove.price||this.Yi.We()||this.Yi.Fo()||this.mv(1)}nf(t){this.mv(0)}rv(){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.Ct.lf(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Ct.lf().Rt()),t}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Ct.lf().ti(),h=e.q(),r=e.Hc();h===r?F(t,0,0,s,n,h):A(t,0,0,s,n,h,r)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.Of||null===this.Yi||!this.Yi.O().borderVisible)return;t.fillStyle=this.Yi.O().borderColor;const n=Math.max(1,Math.floor(this.nv().S*s));let e;e=this.Kf?i.width-n:0,t.fillRect(e,0,n,i.height)}pv(t){if(null===this.Of||null===this.Yi)return;const i=this.Yi.Rl(),s=this.Yi.O(),n=this.nv(),e=this.Kf?this.Of.width-n.P:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:h,verticalPixelRatio:r})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(r)),o=Math.floor(.5*r),a=Math.round(n.P*h);t.beginPath();for(const s of i)t.rect(Math.floor(e*h),Math.round(s.Cl*r)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.hv(),t.fillStyle=s.textColor??this.So.textColor,t.textAlign=this.Kf?"right":"left",t.textBaseline="middle";const h=this.Kf?Math.round(e-n.F):Math.round(e+n.P+n.F),r=i.map(i=>this.$f.Ri(t,i.Zl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Zl,h,n.Cl+r[s])}})}_v(){if(null===this.Of||null===this.Yi)return;let t=this.Of.height/2;const i=[],s=this.Yi.Rt().slice(),n=this.Ct.lf(),e=this.nv();this.Yi===n.qn()&&this.Ct.lf().Rt().forEach(t=>{n.Un(t)&&s.push(t)});const h=this.Yi.Ml()[0],r=this.Yi;s.forEach(s=>{const e=s.Hs(n,r);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),h===s&&e.length>0&&(t=e[0].Ei())}),i.forEach(t=>t.Hi(t.Ei()));this.Yi.O().alignLabels&&this.wv(i,e,t)}wv(t,i,s){if(null===this.Of)return;const n=t.filter(t=>t.Ei()<=s),e=t.filter(t=>t.Ei()>s);n.sort((t,i)=>i.Ei()-t.Ei()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Ei()-i.Ei());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Ei();n>-t&&n<t&&s.Hi(t),n>this.Of.height-t&&n<this.Of.height+t&&s.Hi(this.Of.height-t)}Vs(n,1,this.Of.height,i),Vs(e,-1,this.Of.height,i)}fv(t){if(null===this.Of)return;const i=this.rv(),s=this.nv(),n=this.Kf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.$f,n)}})}vv(t){if(null===this.Of||null===this.Yi)return;const i=this.Ct.jf().ti(),s=[],n=this.Ct.lf(),e=i.cc().Hs(n,this.Yi);e.length&&s.push(e);const h=this.nv(),r=this.Kf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,h,this.$f,r)})})}mv(t){this.Yp.style.cursor=1===t?"ns-resize":"default"}co(){const t=this.ev();this.Nf<t&&this.Ct.jf().ti().Er(),this.Nf=t}hv(){return g(this.So.fontSize,this.So.fontFamily)}}function Es(t,i){return t.Qr?.(i)??[]}function Ls(t,i){return t.$s?.(i)??[]}function As(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Xr?.(i)??[]}class Ws{constructor(t,i){this.Of=ns({width:0,height:0}),this.gv=null,this.bv=null,this.Mv=null,this.yv=null,this.Sv=!1,this.xv=new a,this.Pv=new a,this.Cv=0,this.Tv=!1,this.kv=null,this.Dv=!1,this.Iv=null,this.Rv=null,this.Uf=!1,this.qf=()=>{this.Uf||null===this.Vv||this.ss().ah()},this.Yf=()=>{this.Uf||null===this.Vv||this.ss().ah()},this.Vf=t,this.Vv=i,this.Vv.i_().i(this.Fv.bind(this),this,!0),this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Ev.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.Lv=document.createElement("td"),this.Lv.style.padding="0",this.Av=document.createElement("td"),this.Av.style.padding="0",this.Ev.appendChild(s),this.Jf=Cs(s,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const n=this.Jf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Qf=Cs(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.jp=document.createElement("tr"),this.jp.appendChild(this.Lv),this.jp.appendChild(this.Ev),this.jp.appendChild(this.Av),this.Bv(),this.Op=new fs(this.Qf.canvasElement,this,{op:()=>null===this.kv&&!this.Vf.O().handleScroll.vertTouchDrag,ap:()=>null===this.kv&&!this.Vf.O().handleScroll.horzTouchDrag})}m(){null!==this.gv&&this.gv.m(),null!==this.bv&&this.bv.m(),this.Mv=null,this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Vv&&(this.Vv.i_().u(this),this.Vv.m()),this.Op.m()}lf(){return l(this.Vv)}Wv(t){null!==this.Vv&&this.Vv.i_().u(this),this.Vv=t,null!==this.Vv&&this.Vv.i_().i(Ws.prototype.Fv.bind(this),this,!0),this.Bv(),this.Vf.Up().indexOf(this)===this.Vf.Up().length-1?(this.Mv=this.Mv??new Ps(this.Ev,this.Vf),this.Mv.Tt()):(this.Mv?.Ef(),this.Mv=null)}jf(){return this.Vf}Xp(){return this.jp}Bv(){if(null!==this.Vv&&(this.Ov(),0!==this.ss().Ks().length)){if(null!==this.gv){const t=this.Vv.Ha();this.gv.us(l(t))}if(null!==this.bv){const t=this.Vv.Na();this.bv.us(l(t))}}}zv(){null!==this.gv&&this.gv.Tt(),null!==this.bv&&this.bv.Tt()}Fa(){return null!==this.Vv?this.Vv.Fa():0}Ea(t){this.Vv&&this.Vv.Ea(t)}np(t){if(!this.Vv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}yp(t){this.$v(),this.Nv(),this.Hv(t.localX,t.localY,t)}ep(t){if(!this.Vv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}mp(t){null!==this.Vv&&(this.$v(),this.Uv(t))}Xd(t){null!==this.Vv&&this.qv(this.Pv,t)}jd(t){this.Xd(t)}cp(t){this.$v(),this.jv(t),this.Hv(t.localX,t.localY,t)}vp(t){null!==this.Vv&&(this.$v(),this.Tv=!1,this.Yv(t))}fp(t){null!==this.Vv&&this.Uv(t)}Fp(t){if(this.Tv=!0,null===this.kv){const i={x:t.localX,y:t.localY};this.Kv(i,i,t)}}Vp(t){null!==this.Vv&&(this.$v(),this.Vv.ti().ac(null),this.Gv())}Xv(){return this.xv}Zv(){return this.Pv}Cp(){this.Cv=1,this.ss().ln()}Tp(t,i){if(!this.Vf.O().handleScale.pinch)return;const s=5*(i-this.Cv);this.Cv=i,this.ss().yc(t.ut,s)}bp(t){this.Tv=!1,this.Dv=null!==this.kv,this.Nv();const i=this.ss().cc();null!==this.kv&&i.Vt()&&(this.Iv={x:i.ni(),y:i.ei()},this.kv={x:t.localX,y:t.localY})}_p(t){if(null===this.Vv)return;const i=t.localX,s=t.localY;if(null!==this.kv){this.Dv=!1;const n=l(this.Iv),e=n.x+(i-this.kv.x),h=n.y+(s-this.kv.y);return void this.Hv(e,h,t)}this.jv(t)}pp(t){0===this.jf().O().trackingMode.exitMode&&(this.Dv=!0),this.Jv(),this.Yv(t)}Kn(t,i){const s=this.Vv;return null===s?null:Si(s,t,i)}Qv(t,i){l("left"===i?this.gv:this.bv).lv(ns({width:t,height:this.Of.height}))}Zp(){return this.Of}lv(t){es(this.Of,t)||(this.Of=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Ev.style.width=t.width+"px",this.Ev.style.height=t.height+"px")}tm(){const t=l(this.Vv);t.$a(t.Ha()),t.$a(t.Na());for(const i of t.Ml())if(t.Un(i)){const s=i.$t();null!==s&&t.$a(s),i.zs()}for(const i of t.n_())i.zs()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;null!==t&&t.drawImage(n,i,s)}}av(t){if(0===t)return;if(null===this.Vv)return;t>1&&this.tm(),null!==this.gv&&this.gv.av(t),null!==this.bv&&this.bv.av(t);const i={colorSpace:this.Vf.O().layout.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t)}),this.Vv&&(this.im(t,Es),this.sm(t),this.im(t,Ls),this.im(t,As)))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.nm(s),this.im(s,Bs),this.im(s,As))}hm(){return this.gv}rm(){return this.bv}dv(t,i){this.im(t,i)}Fv(){null!==this.Vv&&this.Vv.i_().u(this),this.Vv=null}Uv(t){this.qv(this.xv,t)}qv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().Lt().du(s),{x:s,y:n},i)}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),h=e.q(),r=e.Hc();h===r?F(t,0,0,s,n,r):A(t,0,0,s,n,h,r)}sm(t){const i=l(this.Vv),s=i.s_()._h().Dt(i);null!==s&&s.et(t,!1)}nm(t){this.lm(t,Ls,Ds,this.ss().cc())}im(t,i){const s=l(this.Vv),n=s.Rt(),e=s.n_();for(const s of e)this.lm(t,i,ks,s);for(const s of n)this.lm(t,i,ks,s);for(const s of e)this.lm(t,i,Ds,s);for(const s of n)this.lm(t,i,Ds,s)}lm(t,i,s,n){const e=l(this.Vv),h=e.ti().oc(),r=null!==h&&h.e_===n,o=null!==h&&r&&void 0!==h.h_?h.h_.Xn:void 0;Is(i,i=>s(i,t,r,o),n,e)}Ov(){if(null===this.Vv)return;const t=this.Vf,i=this.Vv.Ha().O().visible,s=this.Vv.Na().O().visible;i||null===this.gv||(this.Lv.removeChild(this.gv.Xp()),this.gv.m(),this.gv=null),s||null===this.bv||(this.Av.removeChild(this.bv.Xp()),this.bv.m(),this.bv=null);const n=t.ti().Fc();i&&null===this.gv&&(this.gv=new Fs(this,t.O(),n,"left"),this.Lv.appendChild(this.gv.Xp())),s&&null===this.bv&&(this.bv=new Fs(this,t.O(),n,"right"),this.Av.appendChild(this.bv.Xp()))}om(t){return t.Ep&&this.Tv||null!==this.kv}am(t){return Math.max(0,Math.min(t,this.Of.width-1))}_m(t){return Math.max(0,Math.min(t,this.Of.height-1))}Hv(t,i,s){this.ss().Dc(this.am(t),this._m(i),s,l(this.Vv))}Gv(){this.ss().Rc()}Jv(){this.Dv&&(this.kv=null,this.Gv())}Kv(t,i,s){this.kv=t,this.Dv=!1,this.Hv(i.x,i.y,s);const n=this.ss().cc();this.Iv={x:n.ni(),y:n.ei()}}ss(){return this.Vf.ti()}Yv(t){if(!this.Sv)return;const i=this.ss(),s=this.lf();if(i.Ga(s,s.ks()),this.yv=null,this.Sv=!1,i.Cc(),null!==this.Rv){const t=performance.now(),s=i.Lt();this.Rv.ae(s.bu(),t),this.Rv.Iu(t)||i.un(this.Rv)}}$v(){this.kv=null}Nv(){if(!this.Vv)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.Vv.ks().Gi()&&this.ss().Lt().Gi()}jv(t){if(null===this.Vv)return;const i=this.ss(),s=i.Lt();if(s.Gi())return;const n=this.Vf.O(),e=n.handleScroll,h=n.kineticScroll;if((!e.pressedMouseMove||t.Ep)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Ep))return;const r=this.Vv.ks(),l=performance.now();if(null!==this.yv||this.om(t)||(this.yv={x:t.clientX,y:t.clientY,rd:l,um:t.localX,dm:t.localY}),null!==this.yv&&!this.Sv&&(this.yv.x!==t.clientX||this.yv.y!==t.clientY)){if(t.Ep&&h.touch||!t.Ep&&h.mouse){const t=s.wu();this.Rv=new xs(.2/t,7/t,.997,15/t),this.Rv.Cf(s.bu(),this.yv.rd)}else this.Rv=null;r.Gi()||i.Ya(this.Vv,r,t.localY),i.xc(t.localX),this.Sv=!0}this.Sv&&(r.Gi()||i.Ka(this.Vv,r,t.localY),i.Pc(t.localX),null!==this.Rv&&this.Rv.Cf(s.bu(),l))}}class Os{constructor(t,i,s,n,e){this.xt=!0,this.Of=ns({width:0,height:0}),this.qf=()=>this.av(3),this.Kf="left"===t,this.Qu=s.Fc,this.Cs=i,this.pm=n,this.fm=e,this.Yp=document.createElement("div"),this.Yp.style.width="25px",this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Jf=Cs(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf)}m(){this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Xp(){return this.Yp}Zp(){return this.Of}lv(t){es(this.Of,t)||(this.Of=t,this.Jf.resizeCanvasElement(t),this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.xt=!0)}av(t){if(t<3&&!this.xt)return;if(0===this.Of.width||0===this.Of.height)return;this.xt=!1,this.Jf.applySuggestedBitmapSize();const i=as(this.Jf,{colorSpace:this.Cs.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)})}Jp(){return this.Jf.bitmapSize}Qp(t,i,s){const n=this.Jp();n.width>0&&n.height>0&&t.drawImage(this.Jf.canvasElement,i,s)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.pm())return;t.fillStyle=this.Cs.timeScale.borderColor;const e=Math.floor(this.Qu.O().S*s),h=Math.floor(this.Qu.O().S*n),r=this.Kf?i.width-e:0;t.fillRect(r,0,e,h)}uv({context:t,bitmapSize:i}){F(t,0,0,i.width,i.height,this.fm())}}function zs(t){return i=>i.sl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.vm=null,this.wm=null,this.M=null,this.gm=!1,this.Of=ns({width:0,height:0}),this.bm=new a,this.$f=new it(5),this.Uf=!1,this.qf=()=>{this.Uf||this.Vf.ti().ah()},this.Yf=()=>{this.Uf||this.Vf.ti().ah()},this.Vf=t,this.__=i,this.Cs=t.O().layout,this.kf=document.createElement("tr"),this.Mm=document.createElement("td"),this.Mm.style.padding="0",this.ym=document.createElement("td"),this.ym.style.padding="0",this.Yp=document.createElement("td"),this.Yp.style.height="25px",this.Yp.style.padding="0",this.Sm=document.createElement("div"),this.Sm.style.width="100%",this.Sm.style.height="100%",this.Sm.style.position="relative",this.Sm.style.overflow="hidden",this.Yp.appendChild(this.Sm),this.Jf=Cs(this.Sm,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const s=this.Jf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Qf=Cs(this.Sm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.kf.appendChild(this.Mm),this.kf.appendChild(this.Yp),this.kf.appendChild(this.ym),this.xm(),this.Vf.ti().Va().i(this.xm.bind(this),this),this.Op=new fs(this.Qf.canvasElement,this,{op:()=>!0,ap:()=>!this.Vf.O().handleScroll.horzTouchDrag})}m(){this.Op.m(),null!==this.vm&&this.vm.m(),null!==this.wm&&this.wm.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Xp(){return this.kf}Pm(){return this.vm}Cm(){return this.wm}yp(t){if(this.gm)return;this.gm=!0;const i=this.Vf.ti();!i.Lt().Gi()&&this.Vf.O().handleScale.axisPressedMouseMove.time&&i.Mc(t.localX)}bp(t){this.yp(t)}Sp(){const t=this.Vf.ti();!t.Lt().Gi()&&this.gm&&(this.gm=!1,this.Vf.O().handleScale.axisPressedMouseMove.time&&t.kc())}cp(t){const i=this.Vf.ti();!i.Lt().Gi()&&this.Vf.O().handleScale.axisPressedMouseMove.time&&i.Tc(t.localX)}_p(t){this.cp(t)}vp(){this.gm=!1;const t=this.Vf.ti();t.Lt().Gi()&&!this.Vf.O().handleScale.axisPressedMouseMove.time||t.kc()}pp(){this.vp()}Xd(){this.Vf.O().handleScale.axisDoubleClickReset.time&&this.Vf.ti().dn()}jd(){this.Xd()}np(){this.Vf.ti().O().handleScale.axisPressedMouseMove.time&&this.mv(1)}Vp(){this.mv(0)}Zp(){return this.Of}Tm(){return this.bm}km(t,i,s){es(this.Of,t)||(this.Of=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.bm.p(t)),null!==this.vm&&this.vm.lv(ns({width:i,height:t.height})),null!==this.wm&&this.wm.lv(ns({width:s,height:t.height}))}Dm(){const t=this.Im();return Math.ceil(t.S+t.P+t.C+t.A+t.V+t.Rm)}Tt(){this.Vf.ti().Lt().Rl()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}av(t){if(0===t)return;const i={colorSpace:this.Cs.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const s=as(this.Jf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t),this.Vm(s,Ns)}),this.pv(s),this.Vm(s,$s)),null!==this.vm&&this.vm.av(t),null!==this.wm&&this.wm.av(t)}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Fm([...this.Vf.ti().Ks(),this.Vf.ti().cc()],s),this.Vm(s,Hs))}Vm(t,i){const s=this.Vf.ti().Ks();for(const n of s)Is(i,i=>ks(i,t,!1,void 0),n,void 0);for(const n of s)Is(i,i=>Ds(i,t,!1,void 0),n,void 0)}uv({context:t,bitmapSize:i}){F(t,0,0,i.width,i.height,this.Vf.ti().Hc())}cv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Vf.O().timeScale.borderVisible){t.fillStyle=this.Em();const n=Math.max(1,Math.floor(this.Im().S*s));t.fillRect(0,0,i.width,n)}}pv(t){const i=this.Vf.ti().Lt(),s=i.Rl();if(!s||0===s.length)return;const n=this.__.maxTickMarkWeight(s),e=this.Im(),h=i.O();h.borderVisible&&h.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Em(),t.fillStyle=this.Em();const h=Math.max(1,Math.floor(i)),r=Math.floor(.5*i);t.beginPath();const l=Math.round(e.P*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-r,0,h,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.P+e.A+e.C/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.hv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Lm(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Vf.O().timeScale.allowBoldLabels&&(t.font=this.Am());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Lm(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Lm(t,i,s){const n=this.$f.Vi(t,s),e=n/2,h=Math.floor(i-e)+.5;return h<0?i+=Math.abs(0-h):h+n>this.Of.width&&(i-=Math.abs(this.Of.width-(h+n))),i}Fm(t,i){const s=this.Im();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Em(){return this.Vf.O().timeScale.borderColor}N(){return this.Cs.textColor}$(){return this.Cs.fontSize}hv(){return g(this.$(),this.Cs.fontFamily)}Am(){return g(this.$(),this.Cs.fontFamily,"bold")}Im(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,V:NaN,Qi:NaN,P:5,C:NaN,T:"",Ji:new it,Rm:0});const t=this.M,i=this.hv();if(t.T!==i){const s=this.$();t.C=s,t.T=i,t.A=3*s/12,t.V=3*s/12,t.Qi=9*s/12,t.B=0,t.Rm=4*s/12,t.Ji.Fn()}return this.M}mv(t){this.Yp.style.cursor=1===t?"ew-resize":"default"}xm(){const t=this.Vf.ti(),i=t.O();i.leftPriceScale.visible||null===this.vm||(this.Mm.removeChild(this.vm.Xp()),this.vm.m(),this.vm=null),i.rightPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Xp()),this.wm.m(),this.wm=null);const s={Fc:this.Vf.ti().Fc()},n=()=>i.leftPriceScale.borderVisible&&t.Lt().O().borderVisible,e=()=>t.Hc();i.leftPriceScale.visible&&null===this.vm&&(this.vm=new Os("left",i,s,n,e),this.Mm.appendChild(this.vm.Xp())),i.rightPriceScale.visible&&null===this.wm&&(this.wm=new Os("right",i,s,n,e),this.ym.appendChild(this.wm.Xp()))}}const qs=!!_s&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!_s&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class js{constructor(t,i,s){var n;this.Bm=[],this.Wm=[],this.Om=0,this.no=0,this.Ma=0,this.zm=0,this.$m=0,this.Hm=null,this.Nm=!1,this.xv=new a,this.Pv=new a,this.Xu=new a,this.Um=null,this.qm=null,this.Rf=t,this.Cs=i,this.__=s,this.kf=document.createElement("div"),this.kf.classList.add("tv-lightweight-charts"),this.kf.style.overflow="hidden",this.kf.style.direction="ltr",this.kf.style.width="100%",this.kf.style.height="100%",(n=this.kf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.jm=document.createElement("table"),this.jm.setAttribute("cellspacing","0"),this.kf.appendChild(this.jm),this.Ym=this.Km.bind(this),Ys(this.Cs)&&this.Gm(!0),this.ss=new Ai(this.Ju.bind(this),this.Cs,s),this.ti().dc().i(this.Xm.bind(this),this),this.Zm=new Us(this,this.__),this.jm.appendChild(this.Zm.Xp());const e=i.autoSize&&this.Jm();let h=this.Cs.width,r=this.Cs.height;if(e||0===h||0===r){const i=t.getBoundingClientRect();h=h||i.width,r=r||i.height}this.Qm(h,r),this.tw(),t.appendChild(this.kf),this.iw(),this.ss.Lt().Eu().i(this.ss.Er.bind(this.ss),this),this.ss.Va().i(this.ss.Er.bind(this.ss),this)}ti(){return this.ss}O(){return this.Cs}Up(){return this.Bm}sw(){return this.Zm}m(){this.Gm(!1),0!==this.Om&&window.cancelAnimationFrame(this.Om),this.ss.dc().u(this),this.ss.Lt().Eu().u(this),this.ss.Va().u(this),this.ss.m();for(const t of this.Bm)this.jm.removeChild(t.Xp()),t.Xv().u(this),t.Zv().u(this),t.m();this.Bm=[];for(const t of this.Wm)this.nw(t);this.Wm=[],l(this.Zm).m(),null!==this.kf.parentElement&&this.kf.parentElement.removeChild(this.kf),this.Xu.m(),this.xv.m(),this.Pv.m(),this.ew()}Qm(t,i,s=!1){if(this.no===i&&this.Ma===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return ns({width:i-i%2,height:s-s%2})}(ns({width:t,height:i}));this.no=n.height,this.Ma=n.width;const e=this.no+"px",h=this.Ma+"px";l(this.kf).style.height=e,l(this.kf).style.width=h,this.jm.style.height=e,this.jm.style.width=h,s?this.hw(Y.bn(),performance.now()):this.ss.Er()}av(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Bm.length;i++)this.Bm[i].av(t.hn(i).sn);this.Cs.timeScale.visible&&this.Zm.av(t.en())}oh(t){const i=Ys(this.Cs);this.ss.oh(t);const s=Ys(this.Cs);s!==i&&this.Gm(s),t.layout?.panes&&this.rw(),this.iw(),this.lw(t)}Xv(){return this.xv}Zv(){return this.Pv}dc(){return this.Xu}ow(t=!1){null!==this.Hm&&(this.hw(this.Hm,performance.now()),this.Hm=null);const i=this.aw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.aw(n,t),s}_w(t){if("left"===t&&!this.uw())return 0;if("right"===t&&!this.cw())return 0;if(0===this.Bm.length)return 0;return l("left"===t?this.Bm[0].hm():this.Bm[0].rm()).ov()}dw(){return this.Cs.autoSize&&null!==this.Um}if(){return this.kf}pw(t){this.qm=t,this.qm?this.if().style.setProperty("cursor",t):this.if().style.removeProperty("cursor")}fw(){return this.qm}mw(t){return r(this.Bm[t]).Zp()}rw(){this.Wm.forEach(t=>{t.Tt()})}lw(t){(void 0!==t.autoSize||!this.Um||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.Um&&this.Jm(),!1===t.autoSize&&null!==this.Um&&this.ew(),t.autoSize||void 0===t.width&&void 0===t.height||this.Qm(t.width||this.Ma,t.height||this.no))}aw(t,i){let s=0,n=0;const e=this.Bm[0],h=(s,n)=>{let e=0;for(let h=0;h<this.Bm.length;h++){const r=this.Bm[h],o=l("left"===s?r.hm():r.rm()),a=o.Jp();if(null!==t&&o.Qp(t,n,e,i),e+=a.height,h<this.Bm.length-1){const i=this.Wm[h],s=i.Jp();null!==t&&i.Qp(t,n,e),e+=s.height}}};if(this.uw()){h("left",0);s+=l(e.hm()).Jp().width}for(let e=0;e<this.Bm.length;e++){const h=this.Bm[e],r=h.Jp();if(null!==t&&h.Qp(t,s,n,i),n+=r.height,e<this.Bm.length-1){const i=this.Wm[e],h=i.Jp();null!==t&&i.Qp(t,s,n),n+=h.height}}if(s+=e.Jp().width,this.cw()){h("right",s);s+=l(e.rm()).Jp().width}const r=(i,s,n)=>{l("left"===i?this.Zm.Pm():this.Zm.Cm()).Qp(l(t),s,n)};if(this.Cs.timeScale.visible){const s=this.Zm.Jp();if(null!==t){let h=0;this.uw()&&(r("left",h,n),h=l(e.hm()).Jp().width),this.Zm.Qp(t,h,n,i),h+=s.width,this.cw()&&r("right",h,n)}n+=s.height}return ns({width:s,height:n})}ww(){let t=0,i=0,s=0;for(const n of this.Bm)this.uw()&&(i=Math.max(i,l(n.hm()).ev(),this.Cs.leftPriceScale.minimumWidth)),this.cw()&&(s=Math.max(s,l(n.rm()).ev(),this.Cs.rightPriceScale.minimumWidth)),t+=n.Fa();i=ds(i),s=ds(s);const n=this.Ma,e=this.no,h=Math.max(n-i-s,0),r=1*this.Wm.length,o=this.Cs.timeScale.visible;let a=o?Math.max(this.Zm.Dm(),this.Cs.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=r+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Bm.length;++t){const n=this.Bm[t];n.Wv(this.ss.qs()[t]);let e=0,r=0;r=t===this.Bm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Fa()*d*f)/f,e=Math.max(r,2),p+=e,n.lv(ns({width:h,height:e})),this.uw()&&n.Qv(i,"left"),this.cw()&&n.Qv(s,"right"),n.lf()&&this.ss.fc(n.lf(),e)}this.Zm.km(ns({width:o?h:0,height:a}),o?i:0,o?s:0),this.ss.La(h),this.zm!==i&&(this.zm=i),this.$m!==s&&(this.$m=s)}Gm(t){t?this.kf.addEventListener("wheel",this.Ym,{passive:!1}):this.kf.removeEventListener("wheel",this.Ym)}gw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Km(t){if(!(0!==t.deltaX&&this.Cs.handleScroll.mouseWheel||0!==t.deltaY&&this.Cs.handleScale.mouseWheel))return;const i=this.gw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Cs.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.kf.getBoundingClientRect().left;this.ti().yc(s,i)}0!==s&&this.Cs.handleScroll.mouseWheel&&this.ti().Sc(-80*s)}hw(t,i){const s=t.en();3===s&&this.bw(),3!==s&&2!==s||(this.Mw(t),this.yw(t,i),this.Zm.Tt(),this.Bm.forEach(t=>{t.zv()}),3===this.Hm?.en()&&(this.Hm.mn(t),this.bw(),this.Mw(this.Hm),this.yw(this.Hm,i),t=this.Hm,this.Hm=null)),this.av(t)}yw(t,i){for(const s of t.vn())this.wn(s,i)}Mw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.hn(s).nn&&i[s].Ja()}wn(t,i){const s=this.ss.Lt();switch(t.an){case 0:s.Au();break;case 1:s.Bu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Su();break;case 5:t.Ht.Iu(i)||s.fn(t.Ht.Ru(i))}}Ju(t){null!==this.Hm?this.Hm.mn(t):this.Hm=t,this.Nm||(this.Nm=!0,this.Om=window.requestAnimationFrame(t=>{if(this.Nm=!1,this.Om=0,null!==this.Hm){const i=this.Hm;this.Hm=null,this.hw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Iu(t)){this.ti().un(s.Ht);break}}}))}bw(){this.tw()}nw(t){this.jm.removeChild(t.Xp()),t.m()}tw(){const t=this.ss.qs(),i=t.length,s=this.Bm.length;for(let t=i;t<s;t++){const t=r(this.Bm.pop());this.jm.removeChild(t.Xp()),t.Xv().u(this),t.Zv().u(this),t.m();const i=this.Wm.pop();void 0!==i&&this.nw(i)}for(let n=s;n<i;n++){const i=new Ws(this,t[n]);if(i.Xv().i(this.Sw.bind(this,i),this),i.Zv().i(this.xw.bind(this,i),this),this.Bm.push(i),n>0){const t=new Ms(this,n-1,n);this.Wm.push(t),this.jm.insertBefore(t.Xp(),this.Zm.Xp())}this.jm.insertBefore(i.Xp(),this.Zm.Xp())}for(let s=0;s<i;s++){const i=t[s],n=this.Bm[s];n.lf()!==i?n.Wv(i):n.Bv()}this.iw(),this.ww()}Pw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Ks().forEach(i=>{const s=i.Xs().$h(t);null!==s&&e.set(i,s)})}let h;if(null!==t){const i=this.ss.Lt().ns(t)?.originalTime;void 0!==i&&(h=i)}const r=this.ti().oc(),l=null!==r&&r.e_ instanceof Ut?r.e_:void 0,o=null!==r&&void 0!==r.h_?r.h_.Gn:void 0,a=this.Cw(n);return{Tw:h,Ie:t??void 0,kw:i??void 0,Dw:-1!==a?a:void 0,Iw:l,Rw:e,Vw:o,Fw:s??void 0}}Cw(t){let i=-1;if(t)i=this.Bm.indexOf(t);else{const t=this.ti().cc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Sw(t,i,s,n){this.xv.p(()=>this.Pw(i,s,n,t))}xw(t,i,s,n){this.Pv.p(()=>this.Pw(i,s,n,t))}Xm(t,i,s){this.pw(this.ti().oc()?.l_??null),this.Xu.p(()=>this.Pw(t,i,s))}iw(){const t=this.Cs.timeScale.visible?"":"none";this.Zm.Xp().style.display=t}uw(){return this.Bm[0].lf().Ha().O().visible}cw(){return this.Bm[0].lf().Na().O().visible}Jm(){return"ResizeObserver"in window&&(this.Um=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.Qm(i.contentRect.width,i.contentRect.height)}),this.Um.observe(this.Rf,{box:"border-box"}),!0)}ew(){null!==this.Um&&this.Um.disconnect(),this.Um=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Ks(t){return void 0===t.open&&void 0===t.value}function Gs(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Xs(t,i,s,n){const e=s.value,h={Ie:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.color&&(h.I=s.color),h}function Zs(t,i,s,n){const e=s.value,h={Ie:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.lineColor&&(h.wt=s.lineColor),void 0!==s.topColor&&(h.gh=s.topColor),void 0!==s.bottomColor&&(h.bh=s.bottomColor),h}function Js(t,i,s,n){const e=s.value,h={Ie:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.topLineColor&&(h.Mh=s.topLineColor),void 0!==s.bottomLineColor&&(h.yh=s.bottomLineColor),void 0!==s.topFillColor1&&(h.Sh=s.topFillColor1),void 0!==s.topFillColor2&&(h.xh=s.topFillColor2),void 0!==s.bottomFillColor1&&(h.Ph=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(h.Ch=s.bottomFillColor2),h}function Qs(t,i,s,n){const e={Ie:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw:n};return void 0!==s.color&&(e.I=s.color),e}function tn(t,i,s,n){const e={Ie:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw:n};return void 0!==s.color&&(e.I=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.wh=s.wickColor),e}function sn(t,i,s,n,e){const h=r(e)(s),l=Math.max(...h),o=Math.min(...h),a=h[h.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Ie:i,gt:t,Ht:_,Tw:n,ne:d,I:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Ew=i.customValues),t}function hn(t){return(i,s,n,e,h,r)=>function(t,i){return i?i(t):Ks(t)}(n,r)?en({gt:i,Ie:s,Tw:e},n):en(t(i,s,n,e,h),n)}function rn(t){return{Candlestick:hn(tn),Bar:hn(Qs),Area:hn(Zs),Baseline:hn(Js),Histogram:hn(Xs),Line:hn(Xs),Custom:hn(sn)}[t]}function ln(t){return{Ie:0,Lw:new Map,Nr:t}}function on(t,i){if(void 0!==t&&0!==t.length)return{Aw:i.key(t[0].gt),Bw:i.key(t[t.length-1].gt)}}function an(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Tw)}),r(i)}class _n{constructor(t){this.Ww=new Map,this.Ow=new Map,this.zw=new Map,this.$w=[],this.__=t}m(){this.Ww.clear(),this.Ow.clear(),this.zw.clear(),this.$w=[]}Hw(t,i){let s=0!==this.Ww.size,n=!1;const e=this.Ow.get(t);if(void 0!==e)if(1===this.Ow.size)s=!1,n=!0,this.Ww.clear();else for(const i of this.$w)i.pointData.Lw.delete(t)&&(n=!0);let h=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.__.createConverterToInternalObj(i),r=rn(t.Ih()),l=t.dl(),o=t.fl();h=i.map((i,h)=>{const a=e(i.time),_=this.__.key(a);let u=this.Ww.get(_);void 0===u&&(u=ln(a),this.Ww.set(_,u),n=!0);const c=r(a,u.Ie,i,s[h],l,o);return u.Lw.set(t,c),c})}s&&this.Nw(),this.Uw(t,h);let r=-1;if(n){const t=[];this.Ww.forEach(i=>{t.push({timeWeight:0,time:i.Nr,pointData:i,originalTime:an(i.Lw)})}),t.sort((t,i)=>this.__.key(t.time)-this.__.key(i.time)),r=this.qw(t)}return this.jw(t,r,function(t,i,s){const n=on(t,s),e=on(i,s);if(void 0!==n&&void 0!==e)return{Yw:!1,Br:n.Bw>=e.Bw&&n.Aw>=e.Aw}}(this.Ow.get(t),e,this.__))}Ac(t){return this.Hw(t,[])}Kw(t,i,s){const n=i;!function(t){void 0===t.Tw&&(t.Tw=t.time)}(n),this.__.preprocessData(i);const e=this.__.createConverterToInternalObj([i])(i.time),h=this.zw.get(t);if(!s&&void 0!==h&&this.__.key(e)<this.__.key(h))throw new Error(`Cannot update oldest data, last time=${h}, new time=${e}`);let r=this.Ww.get(this.__.key(e));if(s&&void 0===r)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===r;void 0===r&&(r=ln(e),this.Ww.set(this.__.key(e),r));const o=rn(t.Ih()),a=t.dl(),_=t.fl(),u=o(e,r.Ie,i,n.Tw,a,_);r.Lw.set(t,u),s?this.Gw(t,u,r.Ie):this.Xw(t,u);const c={Br:nn(u),Yw:s};if(!l)return this.jw(t,-1,c);const d={timeWeight:0,time:r.Nr,pointData:r,originalTime:an(r.Lw)},p=yt(this.$w,this.__.key(d.time),(t,i)=>this.__.key(t.time)<i);this.$w.splice(p,0,d);for(let t=p;t<this.$w.length;++t)un(this.$w[t].pointData,t);return this.__.fillWeightsForPoints(this.$w,p),this.jw(t,p,c)}Zw(t,i){const s=this.Ow.get(t);if(void 0===s||i<=0)return[[],this.Jw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.zw.delete(t):this.zw.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ww.get(this.__.key(i.gt));if(s&&(s.Lw.delete(t),0===s.Lw.size)){this.Ww.delete(this.__.key(s.Nr)),this.$w.splice(s.Ie,1);for(let t=s.Ie;t<this.$w.length;++t)un(this.$w[t].pointData,t)}}return[n,this.jw(t,this.$w.length-1,{Yw:!1,Br:!1})]}Xw(t,i){let s=this.Ow.get(t);void 0===s&&(s=[],this.Ow.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.__.key(i.gt)>this.__.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.zw.set(t,i.gt)}Gw(t,i,s){const n=this.Ow.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Ie<i);nn(i)?n[e]=i:n.splice(e,1)}Uw(t,i){0!==i.length?(this.Ow.set(t,i.filter(nn)),this.zw.set(t,i[i.length-1].gt)):(this.Ow.delete(t),this.zw.delete(t))}Nw(){for(const t of this.$w)0===t.pointData.Lw.size&&this.Ww.delete(this.__.key(t.time))}qw(t){let i=-1;for(let s=0;s<this.$w.length&&s<t.length;++s){const n=this.$w[s],e=t[s];if(this.__.key(n.time)!==this.__.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.$w.length!==t.length&&(i=Math.min(this.$w.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.__.fillWeightsForPoints(t,i),this.$w=t,i}Qw(){if(0===this.Ow.size)return null;let t=0;return this.Ow.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Ie))}),t}jw(t,i,s){const n=this.Jw();if(-1!==i)this.Ow.forEach((i,e)=>{n.Oa.set(e,{ne:i,tg:e===t?s:void 0})}),this.Ow.has(t)||n.Oa.set(t,{ne:[],tg:s}),n.Lt.ig=this.$w,n.Lt.sg=i;else{const i=this.Ow.get(t);n.Oa.set(t,{ne:i||[],tg:s})}return n}Jw(){return{Oa:new Map,Lt:{uu:this.Qw()}}}}function un(t,i){t.Ie=i,t.Lw.forEach(t=>{t.Ie=i})}function cn(t,i){return t.gt<i}function dn(t,i){return i<t.gt}function pn(t,i,s){const n=i.Ur(),e=i.yi(),h=yt(t,n,cn),r=St(t,e,dn);if(!s)return{from:h,to:r};let l=h,o=r;return h>0&&h<t.length&&t[h].gt>=n&&(l=h-1),r>0&&r<t.length&&t[r-1].gt<=e&&(o=r+1),{from:l,to:o}}class fn{constructor(t,i,s){this.ng=!0,this.eg=!0,this.hg=!0,this.rg=[],this.lg=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.ng=!0,"data"===t&&(this.eg=!0),"options"===t&&(this.hg=!0)}Dt(){return this.Qn.Vt()?(this.ag(),null===this.lg?null:this._g):null}ug(){this.rg=this.rg.map(t=>({...t,...this.Qn.Ir().Rh(t.gt)}))}cg(){this.lg=null}ag(){this.eg&&(this.dg(),this.eg=!1),this.hg&&(this.ug(),this.hg=!1),this.ng&&(this.pg(),this.ng=!1)}pg(){const t=this.Qn.$t(),i=this.te.Lt();if(this.cg(),i.Gi()||t.Gi())return;const s=i.Ce();if(null===s)return;if(0===this.Qn.Xs().Bh())return;const n=this.Qn.Bt();null!==n&&(this.lg=pn(this.rg,s,this.og),this.fg(t,i,n.Ht),this.vg())}}class vn{constructor(t,i){this.mg=t,this.Yi=i}et(t,i,s){this.mg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.nr=s,this._g=new vn(this.nr.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}pl(t){return this.nr.priceValueBuilder(t)}vl(t){return this.nr.isWhitespace(t)}dg(){const t=this.Qn.Ir();this.rg=this.Qn.Xs().Nh().map(i=>({gt:i.Ie,ut:NaN,...t.Rh(i.Ie),wg:i.ne}))}fg(t,i){i.cu(this.rg,m(this.lg))}vg(){this.nr.update({bars:this.rg.map(wn),barSpacing:this.te.Lt().wu(),visibleRange:this.lg},this.Qn.O())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.wg,barColor:t.ph}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=o(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.Tw};return void 0!==t.Ew&&(i.customValues=t.Ew),i}function yn(t){const i=Mn(t);return void 0!==t.I&&(i.color=t.I),i}function Sn(t){const i=Mn(t);return void 0!==t.wt&&(i.lineColor=t.wt),void 0!==t.gh&&(i.topColor=t.gh),void 0!==t.bh&&(i.bottomColor=t.bh),i}function xn(t){const i=Mn(t);return void 0!==t.Mh&&(i.topLineColor=t.Mh),void 0!==t.yh&&(i.bottomLineColor=t.yh),void 0!==t.Sh&&(i.topFillColor1=t.Sh),void 0!==t.xh&&(i.topFillColor2=t.xh),void 0!==t.Ph&&(i.bottomFillColor1=t.Ph),void 0!==t.Ch&&(i.bottomFillColor2=t.Ch),i}function Pn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Tw};return void 0!==t.Ew&&(i.customValues=t.Ew),i}function Cn(t){const i=Pn(t);return void 0!==t.I&&(i.color=t.I),i}function Tn(t){const i=Pn(t),{I:s,Nt:n,wh:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function kn(t){return{Area:Sn,Line:yn,Baseline:xn,Histogram:yn,Bar:Cn,Candlestick:Tn,Custom:Dn}[t]}function Dn(t){const i=t.Tw;return{...t.ne,time:i}}const In={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},Rn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},Vn={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:[]},Fn={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},En={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 Ln(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:Vn,crosshair:In,grid:Rn,overlayPriceScales:{...Fn},leftPriceScale:{...Fn,visible:!1},rightPriceScale:{...Fn,visible:!0},timeScale:En,localization:{locale:_s?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 An{constructor(t,i,s){this.Hp=t,this.gg=i,this.bg=s??0}applyOptions(t){this.Hp.ti()._c(this.gg,t,this.bg)}options(){return this.Yi().O()}width(){return j(this.gg)?this.Hp._w(this.gg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().No(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().th();if(null===s)return null;if(this.Yi().Ql()){const n=this.Yi().va(),e=Bi(n);s=oi(s,this.Yi().so()),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.Hp.ti().uc(this.gg,this.bg)).$t}}class Bn{constructor(t,i,s,n){this.Hp=t,this.Ct=s,this.Mg=i,this.yg=n}getHeight(){return this.Ct.qt()}setHeight(t){const i=this.Hp.ti(),s=i.Uc(this.Ct);i.mc(s,t)}getStretchFactor(){return this.Ct.Fa()}setStretchFactor(t){this.Ct.Ea(t),this.Hp.ti().Er()}paneIndex(){return this.Hp.ti().Uc(this.Ct)}moveTo(t){const i=this.paneIndex();i!==t&&(h(t>=0&&t<this.Hp.Up().length,"Invalid pane index"),this.Hp.ti().gc(i,t))}getSeries(){return this.Ct.Oa().map(t=>this.Mg(t))??[]}getHTMLElement(){const t=this.Hp.Up();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Xp():null}attachPrimitive(t){this.Ct.ul(t),t.attached&&t.attached({chart:this.yg,requestUpdate:()=>this.Ct.ti().Er()})}detachPrimitive(t){this.Ct.cl(t)}priceScale(t){if(null===this.Ct.Ra(t))throw new Error(`Cannot find price scale with id: ${t}`);return new An(this.Hp,t,this.paneIndex())}setPreserveEmptyPane(t){this.Ct.Ba(t)}preserveEmptyPane(){return this.Ct.Wa()}addCustomSeries(t,i={},s=0){return this.yg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.yg.addSeries(t,i,this.paneIndex())}}const Wn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class On{constructor(t){this.sh=t}applyOptions(t){this.sh.oh(t)}options(){return this.sh.O()}Sg(){return this.sh}}class zn{constructor(t,i,s,n,e,h){this.xg=new a,this.Qn=t,this.Pg=i,this.Cg=s,this.__=e,this.yg=n,this.Tg=h}m(){this.xg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.Bt();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Bt();return null===i?null:this.Qn.$t().Ds(t,i.Ht)}barsInLogicalRange(t){if(null===t)return null;const i=new ki(new Pi(t.from,t.to)).T_(),s=this.Qn.Xs();if(s.Gi())return null;const n=s.$h(i.Ur(),1),e=s.$h(i.yi(),-1),h=l(s.Wh()),r=l(s.Gs());if(null!==n&&null!==e&&n.Ie>e.Ie)return{barsBefore:t.from-h,barsAfter:r-t.to};const o={barsBefore:null===n||n.Ie===h?t.from-h:n.Ie-h,barsAfter:null===e||e.Ie===r?r-t.to:r-e.Ie};return null!==n&&null!==e&&(o.from=n.Tw,o.to=e.Tw),o}setData(t){this.__,this.Qn.Ih(),this.Pg.kg(this.Qn,t),this.Dg("full")}update(t,i=!1){this.Qn.Ih(),this.Pg.Ig(this.Qn,t,i),this.Dg("update")}pop(t=1){const i=this.Pg.Rg(this.Qn,t);0!==i.length&&this.Dg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Xs().$h(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Xs().Nh().map(i=>t(i))}subscribeDataChanged(t){this.xg.i(t)}unsubscribeDataChanged(t){this.xg._(t)}applyOptions(t){this.Qn.oh(t)}options(){return f(this.Qn.O())}priceScale(){return this.Cg.priceScale(this.Qn.$t().wl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(Wn),t),s=this.Qn.Or(i);return new On(s)}removePriceLine(t){this.Qn.zr(t.Sg())}priceLines(){return this.Qn.$r().map(t=>new On(t))}seriesType(){return this.Qn.Ih()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.I}}attachPrimitive(t){this.Qn.ul(t),t.attached&&t.attached({chart:this.yg,series:this,requestUpdate:()=>this.Qn.ti().Er(),horzScaleBehavior:this.__})}detachPrimitive(t){this.Qn.cl(t),t.detached&&t.detached(),this.Qn.ti().Er()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Tg(i)}moveToPane(t){this.Qn.ti().zc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.Oa().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.t_(this.Qn,t)}Dg(t){this.xg.v()&&this.xg.p(t)}}class $n{constructor(t,i,s){this.Vg=new a,this.B_=new a,this.bm=new a,this.ss=t,this.cr=t.Lt(),this.Zm=i,this.cr.Vu().i(this.Fg.bind(this)),this.cr.Fu().i(this.Eg.bind(this)),this.Zm.Tm().i(this.Lg.bind(this)),this.__=s}m(){this.cr.Vu().u(this),this.cr.Fu().u(this),this.Zm.Tm().u(this),this.Vg.m(),this.B_.m(),this.bm.m()}scrollPosition(){return this.cr.bu()}scrollToPosition(t,i){i?this.cr.Du(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.cr.ku()}getVisibleRange(){const t=this.cr.eu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.__.convertHorzItemToInternal(t.from),to:this.__.convertHorzItemToInternal(t.to)},s=this.cr.ou(i);this.ss.Wc(s)}getVisibleLogicalRange(){const t=this.cr.nu();return null===t?null:{from:t.Ur(),to:t.yi()}}setVisibleLogicalRange(t){h(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Wc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Au()}logicalToCoordinate(t){const i=this.ss.Lt();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.cr.Gi()?null:this.cr.du(t)}timeToIndex(t,i){const s=this.__.convertHorzItemToInternal(t);return this.cr.tu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.cr.jt(i)}coordinateToTime(t){const i=this.ss.Lt(),s=i.du(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Zm.Zp().width}height(){return this.Zm.Zp().height}subscribeVisibleTimeRangeChange(t){this.Vg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Vg._(t)}subscribeVisibleLogicalRangeChange(t){this.B_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.B_._(t)}subscribeSizeChange(t){this.bm.i(t)}unsubscribeSizeChange(t){this.bm._(t)}applyOptions(t){this.cr.oh(t)}options(){return{...f(this.cr.O()),barSpacing:this.cr.wu()}}Fg(){this.Vg.v()&&this.Vg.p(this.getVisibleRange())}Eg(){this.B_.v()&&this.B_.p(this.getVisibleLogicalRange())}Lg(t){this.bm.p(t.width,t.height)}}function Hn(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 Nn{constructor(t,i,s){this.Ag=new Map,this.Bg=new Map,this.Wg=new a,this.Og=new a,this.zg=new a,this.ju=new WeakMap,this.$g=new _n(i);const n=void 0===s?f(Ln()):_(f(Ln()),Hn(s));this.Hg=i,this.Hp=new js(t,n,i),this.Hp.Xv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ng(t()))},this),this.Hp.Zv().i(t=>{this.Og.v()&&this.Og.p(this.Ng(t()))},this),this.Hp.dc().i(t=>{this.zg.v()&&this.zg.p(this.Ng(t()))},this);const e=this.Hp.ti();this.Ug=new $n(e,this.Hp.sw(),this.Hg)}remove(){this.Hp.Xv().u(this),this.Hp.Zv().u(this),this.Hp.dc().u(this),this.Ug.m(),this.Hp.m(),this.Ag.clear(),this.Bg.clear(),this.Wg.m(),this.Og.m(),this.zg.m(),this.$g.m()}resize(t,i,s){this.autoSizeActive()||this.Hp.Qm(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},qg:bn,jg:t}))(o(t));return this.Yg(n,i,s)}addSeries(t,i={},s=0){return this.Yg(t,i,s)}removeSeries(t){const i=r(this.Ag.get(t)),s=this.$g.Ac(i);this.Hp.ti().Ac(i),this.Kg(s),this.Ag.delete(t),this.Bg.delete(i)}kg(t,i){this.Kg(this.$g.Hw(t,i))}Ig(t,i,s){this.Kg(this.$g.Kw(t,i,s))}Rg(t,i){const[s,n]=this.$g.Zw(t,i);return 0!==s.length&&this.Kg(n),s}subscribeClick(t){this.Wg.i(t)}unsubscribeClick(t){this.Wg._(t)}subscribeCrosshairMove(t){this.zg.i(t)}unsubscribeCrosshairMove(t){this.zg._(t)}subscribeDblClick(t){this.Og.i(t)}unsubscribeDblClick(t){this.Og._(t)}priceScale(t,i=0){return new An(this.Hp,t,i)}timeScale(){return this.Ug}applyOptions(t){this.Hp.oh(Hn(t))}options(){return this.Hp.O()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Hp.ti().O().crosshair.mode,this.Hp.oh({crosshair:{mode:2}})),n=this.Hp.ow(t)}finally{i||void 0===s||this.Hp.ti().oh({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Hp.ti().qc();return i.Ba(t),this.Gg(i)}removePane(t){this.Hp.ti().vc(t)}swapPanes(t,i){this.Hp.ti().wc(t,i)}autoSizeActive(){return this.Hp.dw()}chartElement(){return this.Hp.if()}panes(){return this.Hp.ti().qs().map(t=>this.Gg(t))}paneSize(t=0){const i=this.Hp.mw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Ag.get(s);if(void 0===n)return;const e=this.Hp.ti().Nn(n);null!==e&&this.Hp.ti().Ic(t,i,e)}clearCrosshairPosition(){this.Hp.ti().Rc(!0)}horzBehaviour(){return this.Hg}Yg(i,s={},n=0){h(void 0!==i.qg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Bi(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),r=i.qg,l=new Ut(this.Hp.ti(),i.type,e,r,i.jg);this.Hp.ti().Ec(l,n);const o=new zn(l,this,this,this,this.Hg,t=>this.Gg(t));return this.Ag.set(o,l),this.Bg.set(l,o),o}Kg(t){const i=this.Hp.ti();i.Vc(t.Lt.uu,t.Lt.ig,t.Lt.sg),t.Oa.forEach((t,i)=>i.lt(t.ne,t.tg)),i.Lt().G_(),i.mu()}Xg(t){return r(this.Bg.get(t))}Ng(t){const i=new Map;t.Rw.forEach((t,s)=>{const n=s.Ih(),e=kn(n)(t);if("Custom"!==n)h(Gs(e));else{const t=s.fl();h(!t||!1===t(e))}i.set(this.Xg(s),e)});const s=void 0!==t.Iw&&this.Bg.has(t.Iw)?this.Xg(t.Iw):void 0;return{time:t.Tw,logical:t.Ie,point:t.kw,paneIndex:t.Dw,hoveredSeries:s,hoveredObjectId:t.Vw,seriesData:i,sourceEvent:t.Fw}}Gg(t){let i=this.ju.get(t);return i||(i=new Bn(this.Hp,t=>this.Xg(t),t,this),this.ju.set(t,i)),i}}function Un(t){if(d(t)){const i=document.getElementById(t);return h(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function qn(t,i,s){const n=Un(t),e=new Nn(n,i,s);return i.setOptions(e.options()),e}function jn(t,i){return qn(t,new ss,ss.ad(i))}function Yn(){return ss}function Kn(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 h=s.coordinateToLogical(e);if(null===h)return null;const r=i.dataByIndex(h-1,-1);return!r||"number"!=typeof r.time||r.time>=n.time?null:{gt:n.time,Gl:h,Zg:n.time-r.time}}function Gn(t,i,s){const n=t.timeScale(),e=n.coordinateToTime(s);if(null!==e)return e;const h=n.coordinateToLogical(s);if(null===h)return null;const r=Kn(t,i);if(null===r)return null;const l=h-r.Gl;return Math.round(r.gt+l*r.Zg)}function Xn(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 h=Kn(t,i);if(null===h)return null;const r=h.Gl+(s-h.gt)/h.Zg,l=n.logicalToCoordinate(r);return null===l?null:l}class Zn extends fn{constructor(t,i){super(t,i,!0)}fg(t,i,s){i.cu(this.rg,m(this.lg)),t.jo(this.rg,s,m(this.lg))}Jg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}dg(){const t=this.Qn.Ir();this.rg=this.Qn.Xs().Nh().map(i=>{const s=i.Ht[3];return this.Qg(i.Ie,s,t)})}}function Jn(t,i,s,n,e,h,r){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=h(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),r(t,u,s,n)}else{const e=(i,s)=>{r(t,u,c,s),l.beginPath(),u=i,c=s};let d=c;l.beginPath(),l.moveTo(_.ut*o,_.ct*a);for(let r=n.from+1;r<n.to;++r){d=i[r];const n=h(t,d);switch(s){case 0:l.lineTo(d.ut*o,d.ct*a);break;case 1:l.lineTo(d.ut*o,i[r-1].ct*a),n!==u&&(e(n,d),l.lineTo(d.ut*o,i[r-1].ct*a)),l.lineTo(d.ut*o,d.ct*a);break;case 2:{const[t,s]=se(i,r-1,r);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)&&r(t,u,c,d)}}const Qn=6;function te(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function ie(t,i){return{ut:t.ut/i,ct:t.ct/i}}function se(t,i,s){const n=Math.max(0,i-1),e=Math.min(t.length-1,s+1);var h,r;return[(h=t[i],r=ie(te(t[s],t[n]),Qn),{ut:h.ut+r.ut,ct:h.ct+r.ct}),te(t[s],ie(te(t[e],t[i]),Qn))]}function ne(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class ee extends P{constructor(){super(...arguments),this.rt=null}lt(t){this.rt=t}ht(t){if(null===this.rt)return;const{_t:i,ot:s,tb:e,ib:h,dt:r,Xt:l,sb:o}=this.rt;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=r*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.nb.bind(this);void 0!==h&&Jn(t,i,h,s,e,_,ne),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:h,verticalPixelRatio:r,context:l}=t;let o=null;const a=Math.max(1,Math.floor(h))%2/2,_=s*r+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(l.beginPath(),null!==o&&l.fill(),l.fillStyle=i,o=i);const s=Math.round(n.ut*h)+a,u=n.ct*r;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class he extends ee{nb(t,i){return i.wt}}class re extends Zn{constructor(){super(...arguments),this._g=new he}Qg(t,i,s){return{...this.Jg(t,i),...s.Rh(t)}}vg(){const t=this.Qn.O(),i={_t:this.rg,Xt:t.lineStyle,ib:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.lg,tb:this.te.Lt().wu()};this._g.lt(i)}}const le={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},qg:(t,i)=>new re(t,i)};function oe(t,i){return t.weight>i.weight?t:i}function ae(t){return t}class _e{constructor(){this.eb=new a,this.hb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.eb.p(this.rb)),this.rb=0}lb(){return this.eb}m(){this.eb.m()}options(){return this.Cs}setOptions(t){this.Cs=t}preprocessData(t){}updateFormatter(t){this.Cs&&(this.Cs.localization=t)}createConverterToInternalObj(t){return this.hb(),t=>(t>this.rb&&(this.rb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.ob(t)}formatTickmark(t){return this.ob(t.time)}maxTickMarkWeight(t){return t.reduce(oe,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(ae(t[n].time));this.rb=t[t.length-1].time,this.hb()}ob(t){if(this.Cs.localization?.timeFormatter)return this.Cs.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 ue={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},ce={lastValueVisible:!1,priceLineVisible:!1};class de extends Nn{constructor(t,i){const s=_(ue,i||{}),n=new _e;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={...ce,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(le);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),ab:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),h=(({ae:t,_e:i,ab:s})=>`${t}~${i}~${s}`)(e);h!==s&&(s=h,i.setData(function({ae:t,_e:i,ab:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.lb().i(n)}}function pe(t,i){const s=Un(t);return new de(s,i)}function fe(t,i){return t.weight>i.weight?t:i}class ve{options(){return this.Cs}setOptions(t){this.Cs=t}preprocessData(t){}updateFormatter(t){this.Cs&&(this.Cs.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.Pn())}formatTickmark(t,i){return t.time.toFixed(this.Pn())}maxTickMarkWeight(t){return t.reduce(fe,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)}Pn(){return this.Cs.localization.precision}}function me(t,i){return qn(t,new ve,i)}function we(t,i,s,n,e){const{context:h,horizontalPixelRatio:r,verticalPixelRatio:l}=i;h.lineTo(e.ut*r,t*l),h.lineTo(n.ut*r,t*l),h.closePath(),h.fillStyle=s,h.fill()}class ge extends P{constructor(){super(...arguments),this.rt=null}lt(t){this.rt=t}ht(t){if(null===this.rt)return;const{_t:i,ot:s,tb:e,dt:h,Xt:r,ib:l}=this.rt,o=this.rt._b??(this.rt.ub?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=h,n(a,r),a.lineWidth=1,Jn(t,i,l,s,e,this.cb.bind(this),we.bind(null,o))}}class be{pb(t,i){const s=this.fb,{mb:n,wb:e,gb:h,bb:r,_b:l,Mb:o,yb:a}=i;if(void 0===this.Sb||void 0===s||s.mb!==n||s.wb!==e||s.gb!==h||s.bb!==r||s._b!==l||s.Mb!==o||s.yb!==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=Kt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,h)}p.addColorStop(1,r),this.Sb=p,this.fb=i}return this.Sb}}class Me extends ge{constructor(){super(...arguments),this.xb=new be}cb(t,i){const s=this.rt;return this.xb.pb(t,{mb:i.Sh,wb:i.xh,gb:i.Ph,bb:i.Ch,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class ye extends ee{constructor(){super(...arguments),this.Pb=new be}nb(t,i){const s=this.rt;return this.Pb.pb(t,{mb:i.Mh,wb:i.Mh,gb:i.yh,bb:i.yh,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class Se extends Zn{constructor(t,i){super(t,i),this._g=new x,this.Cb=new Me,this.Tb=new ye,this._g.nt([this.Cb,this.Tb])}Qg(t,i,s){return{...this.Jg(t,i),...s.Rh(t)}}vg(){const t=this.Qn.Bt();if(null===t)return;const i=this.Qn.O(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.Lt().wu();if(null===this.lg||0===this.rg.length)return;let e,h;if(i.relativeGradient){e=this.rg[this.lg.from].ct,h=this.rg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const i=this.rg[t];i.ct<e&&(e=i.ct),i.ct>h&&(h=i.ct)}}this.Cb.lt({_t:this.rg,dt:i.lineWidth,Xt:i.lineStyle,ib:i.lineType,_b:s,Mb:e,yb:h,ub:!1,ot:this.lg,tb:n}),this.Tb.lt({_t:this.rg,dt:i.lineWidth,Xt:i.lineStyle,ib:i.lineVisible?i.lineType:void 0,sb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,_b:s,Mb:e,yb:h,ot:this.lg,tb:n})}}const xe={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},qg:(t,i)=>new Se(t,i)};class Pe extends ge{constructor(){super(...arguments),this.xb=new be}cb(t,i){return this.xb.pb(t,{mb:i.gh,wb:"",gb:"",bb:i.bh,Mb:this.rt?.Mb??0,yb:t.bitmapSize.height})}}class Ce extends Zn{constructor(t,i){super(t,i),this._g=new x,this.kb=new Pe,this.Db=new he,this._g.nt([this.kb,this.Db])}Qg(t,i,s){return{...this.Jg(t,i),...s.Rh(t)}}vg(){const t=this.Qn.O();if(null===this.lg||0===this.rg.length)return;let i;if(t.relativeGradient){i=this.rg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const s=this.rg[t];s.ct<i&&(i=s.ct)}}this.kb.lt({ib:t.lineType,_t:this.rg,Xt:t.lineStyle,dt:t.lineWidth,_b:null,Mb:i,ub:t.invertFilledArea,ot:this.lg,tb:this.te.Lt().wu()}),this.Db.lt({ib:t.lineVisible?t.lineType:void 0,_t:this.rg,Xt:t.lineStyle,dt:t.lineWidth,ot:this.lg,tb:this.te.Lt().wu(),sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const Te={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},qg:(t,i)=>new Ce(t,i)};class ke extends P{constructor(){super(...arguments),this.Yt=null,this.Ib=0,this.Rb=0}lt(t){this.Yt=t}ht({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Xs.length||null===this.Yt.ot)return;if(this.Ib=this.Vb(i),this.Ib>=2){Math.max(1,Math.floor(i))%2!=this.Ib%2&&this.Ib--}this.Rb=this.Yt.Fb?Math.min(this.Ib,Math.floor(i)):this.Ib;let n=null;const e=this.Rb<=this.Ib&&this.Yt.wu>=Math.floor(1.5*i);for(let h=this.Yt.ot.from;h<this.Yt.ot.to;++h){const r=this.Yt.Xs[h];n!==r.ph&&(t.fillStyle=r.ph,n=r.ph);const l=Math.floor(.5*this.Rb),o=Math.round(r.ut*i),a=o-l,_=this.Rb,u=a+_-1,c=Math.min(r.Xo,r.Zo),d=Math.max(r.Xo,r.Zo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Rb);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Ib);if(e){if(this.Yt.Eb){const i=o-m;let n=Math.max(p,Math.round(r.Go*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(r.Jo*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)}}}Vb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).wu,t)))}}class De extends fn{constructor(t,i){super(t,i,!1)}fg(t,i,s){i.cu(this.rg,m(this.lg)),t.Ko(this.rg,s,m(this.lg))}Lb(t,i,s){return{gt:t,jr:i.Ht[0],Yr:i.Ht[1],Kr:i.Ht[2],Gr:i.Ht[3],ut:NaN,Go:NaN,Xo:NaN,Zo:NaN,Jo:NaN}}dg(){const t=this.Qn.Ir();this.rg=this.Qn.Xs().Nh().map(i=>this.Qg(i.Ie,i,t))}}class Ie extends De{constructor(){super(...arguments),this._g=new ke}Qg(t,i,s){return{...this.Lb(t,i,s),...s.Rh(t)}}vg(){const t=this.Qn.O();this._g.lt({Xs:this.rg,wu:this.te.Lt().wu(),Eb:t.openVisible,Fb:t.thinBars,ot:this.lg})}}const Re={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},qg:(t,i)=>new Ie(t,i)};class Ve extends P{constructor(){super(...arguments),this.Yt=null,this.Ib=0}lt(t){this.Yt=t}ht(t){if(null===this.Yt||0===this.Yt.Xs.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Ib=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),h=Math.min(n,e);return Math.max(Math.floor(i),h)}(this.Yt.wu,i),this.Ib>=2){Math.floor(i)%2!=this.Ib%2&&this.Ib--}const s=this.Yt.Xs;this.Yt.Ab&&this.Bb(t,s,this.Yt.ot),this.Yt.Mi&&this.cv(t,s,this.Yt.ot);const n=this.Wb(i);(!this.Yt.Mi||this.Ib>2*n)&&this.Ob(t,s,this.Yt.ot)}Bb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:h}=t;let r="",l=Math.min(Math.floor(e),Math.floor(this.Yt.wu*e));l=Math.max(Math.floor(e),Math.min(l,this.Ib));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.mh!==r&&(n.fillStyle=s.mh,r=s.mh);const _=Math.round(Math.min(s.Go,s.Jo)*h),u=Math.round(Math.max(s.Go,s.Jo)*h),c=Math.round(s.Xo*h),d=Math.round(s.Zo*h);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}}Wb(t){let i=Math.floor(1*t);this.Ib<=2*i&&(i=Math.floor(.5*(this.Ib-1)));const s=Math.max(Math.floor(t),i);return this.Ib<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}cv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:h}=t;let r="";const l=this.Wb(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.fh!==r&&(n.fillStyle=s.fh,r=s.fh);let a=Math.round(s.ut*e)-Math.floor(.5*this.Ib);const _=a+this.Ib-1,u=Math.round(Math.min(s.Go,s.Jo)*h),c=Math.round(Math.max(s.Go,s.Jo)*h);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.wu*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=_}}Ob(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:h}=t;let r="";const l=this.Wb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Go,s.Jo)*h),a=Math.round(Math.max(s.Go,s.Jo)*h),_=Math.round(s.ut*e)-Math.floor(.5*this.Ib),u=_+this.Ib-1;if(s.ph!==r){const t=s.ph;n.fillStyle=t,r=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class Fe extends De{constructor(){super(...arguments),this._g=new Ve}Qg(t,i,s){return{...this.Lb(t,i,s),...s.Rh(t)}}vg(){const t=this.Qn.O();this._g.lt({Xs:this.rg,wu:this.te.Lt().wu(),Ab:t.wickVisible,Mi:t.borderVisible,ot:this.lg})}}const Ee={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"},qg:(t,i)=>new Fe(t,i)};class Le extends P{constructor(){super(...arguments),this.Yt=null,this.zb=[]}lt(t){this.Yt=t,this.zb=[]}ht({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.zb.length||this.$b(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Hb*s)-Math.floor(n/2),h=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const r=this.Yt._t[i],l=this.zb[i-this.Yt.ot.from],o=Math.round(r.ct*s);let a,_;t.fillStyle=r.ph,o<=e?(a=o,_=h):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.Ur,a,l.yi-l.Ur+1,_-a)}}$b(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.zb=[]);const i=Math.ceil(this.Yt.wu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.wu*t)-i;this.zb=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 h,r;if(s%2){const t=(s-1)/2;h=e-t,r=e+t}else{const t=s/2;h=e-t,r=e+t-1}this.zb[i-this.Yt.ot.from]={Ur:h,yi:r,Nb: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.zb[t-this.Yt.ot.from],n=this.zb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.Ur-n.yi!==i+1&&(n.Nb>n.ee?n.yi=s.Ur-i-1:s.Ur=n.yi+i+1))}let n=Math.ceil(this.Yt.wu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi<i.Ur&&(i.yi=i.Ur);const s=i.yi-i.Ur+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.zb[t-this.Yt.ot.from];i.yi-i.Ur+1>n&&(i.Nb>i.ee?i.yi-=1:i.Ur+=1)}}}class Ae extends Zn{constructor(){super(...arguments),this._g=new Le}Qg(t,i,s){return{...this.Jg(t,i),...s.Rh(t)}}vg(){const t={_t:this.rg,wu:this.te.Lt().wu(),ot:this.lg,Hb:this.Qn.$t().zt(this.Qn.O().base,l(this.Qn.Bt()).Ht)};this._g.lt(t)}}const Be={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},qg:(t,i)=>new Ae(t,i)};class We{constructor(t,i){this.Ct=t,this.Ub=i,this.qb()}detach(){this.Ct.detachPrimitive(this.Ub)}getPane(){return this.Ct}applyOptions(t){this.Ub.oh?.(t)}qb(){this.Ct.attachPrimitive(this.Ub)}}const Oe={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},ze={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class $e{constructor(t){this.jb=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.Yb(i,t.text);e>s.width?t.Pu=s.width/e:t.Pu=1,n+=t.lineHeight*t.Pu}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.Pu,t.Pu),i.fillText(t.text,0,t.Kb),i.restore(),e+=t.lineHeight*t.Pu}})}Yb(t,i){const s=this.Gb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Gb(t){let i=this.jb.get(t);return void 0===i&&(i=new Map,this.jb.set(t,i)),i}}class He{constructor(t){this.Cs=Ue(t)}Tt(t){this.Cs=Ue(t)}renderer(){return new $e(this.Cs)}}function Ne(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Kb:0,Pu:0}}function Ue(t){return{...t,lines:t.lines.map(Ne)}}function qe(t){return{...ze,...t}}function je(t){return{...Oe,...t,lines:t.lines?.map(qe)??[]}}class Ye{constructor(t){this.Cs=je(t),this.Xb=[new He(this.Cs)]}updateAllViews(){this.Xb.forEach(t=>t.Tt(this.Cs))}paneViews(){return this.Xb}attached({requestUpdate:t}){this.Zb=t}detached(){this.Zb=void 0}oh(t){this.Cs=je({...this.Cs,...t}),this.Zb&&this.Zb()}}function Ke(t,i){return new We(t,new Ye(i))}const Ge={alpha:1,padding:0};class Xe{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Jb(this.Yt,t.mediaSize);s&&this.Yt.Qb&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.Qb,s.ut,s.ct,s.ts,s.qt))})}Jb(t,i){const{maxHeight:s,maxWidth:n,tM:e,iM:h,padding:r}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=r??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/h,d=u/e,p=Math.min(c,d),f=h*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class Ze{constructor(t){this.sM=null,this.nM=0,this.eM=0,this.Cs=t,this.M=Je(this.Cs,this.sM,this.nM,this.eM)}hM(t){void 0!==t.rM&&(this.nM=t.rM),void 0!==t.lM&&(this.eM=t.lM),void 0!==t.oM&&(this.sM=t.oM),this.Tt()}aM(t){this.Cs=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Je(this.Cs,this.sM,this.nM,this.eM)}renderer(){return new Xe(this.M)}}function Je(t,i,s,n){return{...t,Qb:i,iM:s,tM:n}}function Qe(t){return{...Ge,...t}}class th{constructor(t,i){this._M=null,this.uM=t,this.Cs=Qe(i),this.Xb=[new Ze(this.Cs)]}updateAllViews(){this.Xb.forEach(t=>t.Tt())}paneViews(){return this.Xb}attached(t){const{requestUpdate:i}=t;this.cM=i,this._M=new Image,this._M.onload=()=>{const t=this._M?.naturalHeight??1,i=this._M?.naturalWidth??1;this.Xb.forEach(s=>s.hM({lM:t,rM:i,oM:this._M})),this.cM&&this.cM()},this._M.src=this.uM}detached(){this.cM=void 0,this._M=null}oh(t){this.Cs=Qe({...this.Cs,...t}),this.dM(),this.Zb&&this.Zb()}Zb(){this.cM&&this.cM()}dM(){this.Xb.forEach(t=>t.aM(this.Cs))}}function ih(t,i,s){return new We(t,new th(i,s))}class sh{constructor(t,i){this.Qn=t,this.ar=i,this.qb()}detach(){this.Qn.detachPrimitive(this.ar)}getSeries(){return this.Qn}applyOptions(t){this.ar&&this.ar.oh&&this.ar.oh(t)}qb(){this.Qn.attachPrimitive(this.ar)}}const nh={autoScale:!0,zOrder:"normal"};function eh(t,i){return Xt(Math.min(Math.max(t,12),30)*i)}function hh(t,i){switch(t){case"arrowDown":case"arrowUp":return eh(i,1);case"circle":return eh(i,.8);case"square":return eh(i,.7)}}function rh(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(eh(t,1))}function lh(t){return Math.max(eh(t,.1),3)}function oh(t,i,s){return i?t:s?Math.ceil(t/2):0}function ah(t,i,s,n){const e=(hh("arrowUp",n)-1)/2*s.pM,h=(Xt(n/2)-1)/2*s.pM;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+h,s.ct),i.lineTo(s.ut+h,s.ct+e),i.lineTo(s.ut-h,s.ct+e),i.lineTo(s.ut-h,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+h,s.ct),i.lineTo(s.ut+h,s.ct-e),i.lineTo(s.ut-h,s.ct-e),i.lineTo(s.ut-h,s.ct)),i.fill()}function _h(t,i,s,n,e,h){const r=(hh("arrowUp",n)-1)/2,l=(Xt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&h>=(t?s:s-r)-2&&h<=(t?s+r:s)+2)return!0;return(()=>{if(e<i-r-3||e>i+r+3||h<(t?s-r-3:s)||h>(t?s:s+r+3))return!1;const n=Math.abs(e-i);return Math.abs(h-s)+3>=n/2})()}class uh{constructor(){this.Yt=null,this.On=new it,this.$=-1,this.H="",this.Hf="",this.fM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Hf=g(t,i),this.On.Fn()),this.fM=s}Kn(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&&dh(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.fM&&t.useBitmapCoordinateSpace(t=>{this.ht(t)})}drawBackground(t){"aboveSeries"===this.fM&&t.useBitmapCoordinateSpace(t=>{this.ht(t)})}ht({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle",t.font=this.Hf;for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n];void 0!==e.ri&&(e.ri.ts=this.On.Vi(t,e.ri.vM),e.ri.qt=this.$,e.ri.ut=e.ut-e.ri.ts/2),ch(e,t,i,s)}}}}function ch(t,i,s,n){i.fillStyle=t.I,void 0!==t.ri&&function(t,i,s,n,e,h){t.save(),t.scale(e,h),t.fillText(i,s,n),t.restore()}(i,t.ri.vM,t.ri.ut,t.ri.ct,s,n),function(t,i,s){if(0===t.Bh)return;switch(t.mM){case"arrowDown":return void ah(!1,i,s,t.Bh);case"arrowUp":return void ah(!0,i,s,t.Bh);case"circle":return void function(t,i,s){const n=(hh("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.pM,0,2*Math.PI,!1),t.fill()}(i,s,t.Bh);case"square":return void function(t,i,s){const n=hh("square",s),e=(n-1)*i.pM/2,h=i.ut-e,r=i.ct-e;t.fillRect(h,r,n*i.pM,n*i.pM)}(i,s,t.Bh)}t.mM}(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,pM:i}}(t,s,n))}function dh(t,i,s){return!(void 0===t.ri||!function(t,i,s,n,e,h){const r=n/2;return e>=t&&e<=t+s&&h>=i-r&&h<=i+r}(t.ri.ut,t.ri.ct,t.ri.ts,t.ri.qt,i,s))||function(t,i,s){if(0===t.Bh)return!1;switch(t.mM){case"arrowDown":return _h(!0,t.ut,t.ct,t.Bh,i,s);case"arrowUp":return _h(!1,t.ut,t.ct,t.Bh,i,s);case"circle":return function(t,i,s,n,e){const h=2+hh("circle",s)/2,r=t-n,l=i-e;return Math.sqrt(r*r+l*l)<=h}(t.ut,t.ct,t.Bh,i,s);case"square":return function(t,i,s,n,e){const h=hh("square",s),r=(h-1)/2,l=t-r,o=i-r;return n>=l&&n<=l+h&&e>=o&&e<=o+h}(t.ut,t.ct,t.Bh,i,s)}}(t,i,s)}function ph(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function fh(t,i,s,n,e,h,r,o){const a=function(t,i,s){if(ph(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,r.priceScale().options().invertScale);if(void 0===a)return;const _=ph(i.position),c=o.timeScale(),d=u(i.size)?Math.max(i.size,0):1,p=rh(c.options().barSpacing)*d,f=p/2;t.Bh=p;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(r.priceToCoordinate(a)),void(void 0!==t.ri&&(t.ri.ct=t.ct+f+h+.6*e));case"aboveBar":case"atPriceTop":{const i=_?0:n.wM;return t.ct=l(r.priceToCoordinate(a))-f-i,void 0!==t.ri&&(t.ri.ct=t.ct-f-.6*e,n.wM+=1.2*e),void(_||(n.wM+=p+h))}case"belowBar":case"atPriceBottom":{const i=_?0:n.gM;return t.ct=l(r.priceToCoordinate(a))+f+i,void 0!==t.ri&&(t.ri.ct=t.ct+f+h+.6*e,n.gM+=1.2*e),void(_||(n.gM+=p+h))}}}class vh{constructor(t,i,s){this.bM=[],this.xt=!0,this.MM=!0,this.Jt=new uh,this.be=t,this.Vf=i,this.Yt={_t:[],ot:null},this.Cs=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.yM();const t=this.Vf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Cs.zOrder),this.Jt.lt(this.Yt),this.Jt}SM(t){this.bM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.MM=!0)}xM(t){this.xt=!0,this.Cs=t}zOrder(){return"aboveSeries"===this.Cs.zOrder?"top":this.Cs.zOrder}yM(){const t=this.Vf.timeScale(),i=this.bM;this.MM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Bh:0,mM:t.shape,I:t.color,Gn:t.id,PM:t.PM,ri:void 0})),this.MM=!1);const s=this.Vf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Pi(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.data()[0])return;if(0===this.Yt._t.length)return;let h=NaN;const r=lh(t.options().barSpacing),o={wM:r,gM:r};this.Yt.ot=pn(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&&(o.wM=r,o.gM=r,h=e.time);const a=this.Yt._t[n];a.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(a.ri={vM:e.text,ut:0,ct:0,ts:0,qt:0});const _=this.be.dataByIndex(e.time,0);null!==_&&fh(a,e,_,o,s.fontSize,r,this.be,this.Vf)}this.xt=!1}}function mh(t){return{...nh,...t}}class wh{constructor(t){this.nr=null,this.bM=[],this.CM=[],this.TM=null,this.be=null,this.Vf=null,this.kM=!0,this.DM=null,this.IM=null,this.RM=null,this.VM=!0,this.Cs=mh(t)}attached(t){this.FM(),this.Vf=t.chart,this.be=t.series,this.nr=new vh(this.be,l(this.Vf),this.Cs),this.cM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Dg(t)),this.VM=!0,this.Zb()}Zb(){this.cM&&this.cM()}detached(){this.be&&this.TM&&this.be.unsubscribeDataChanged(this.TM),this.Vf=null,this.be=null,this.nr=null,this.TM=null}SM(t){this.VM=!0,this.bM=t,this.FM(),this.kM=!0,this.IM=null,this.Zb()}EM(){return this.bM}paneViews(){return this.nr?[this.nr]:[]}updateAllViews(){this.LM()}hitTest(t,i){return this.nr?this.nr.renderer()?.Kn(t,i)??null:null}autoscaleInfo(t,i){if(this.Cs.autoScale&&this.nr){const t=this.AM();if(t)return{priceRange:null,margins:t}}return null}oh(t){this.Cs=mh({...this.Cs,...t}),this.Zb&&this.Zb()}AM(){const t=l(this.Vf).timeScale().options().barSpacing;if(this.kM||t!==this.RM){if(this.RM=t,this.bM.length>0){const i=lh(t),s=1.5*rh(t)+2*i,n=this.BM();this.DM={above:oh(s,n.aboveBar,n.inBar),below:oh(s,n.belowBar,n.inBar)}}else this.DM=null;this.kM=!1}return this.DM}BM(){return null===this.IM&&(this.IM=this.bM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.IM}FM(){if(!this.VM||!this.Vf||!this.be)return;const t=this.Vf.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.CM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.CM=this.bM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),h=e<s?1:-1,r=l(this.be).dataByIndex(e,h),o={time:t.timeToIndex(l(r).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,PM:n,text:i.text,size:i.size,price:i.price,Tw: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.VM=!1}LM(t){this.nr&&(this.FM(),this.nr.SM(this.CM),this.nr.xM(this.Cs),this.nr.Tt(t))}Dg(t){this.VM=!0,this.Zb()}}class gh extends sh{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this.ar.SM(t)}markers(){return this.ar.EM()}}function bh(t,i,s){const n=new gh(t,new wh(s??{}));return i&&n.setMarkers(i),n}class Mh{constructor(t){this.bM=new Map,this.WM=t}OM(t,i,s){if(this.zM(i),void 0!==s){const n=window.setTimeout(()=>{this.bM.delete(i),this.$M()},s),e={...t,HM:n,NM:Date.now()+s};this.bM.set(i,e)}else this.bM.set(i,{...t,HM:void 0,NM:void 0});this.$M()}zM(t){const i=this.bM.get(t);i&&void 0!==i.HM&&window.clearTimeout(i.HM),this.bM.delete(t),this.$M()}UM(){for(const[t]of this.bM)this.zM(t)}qM(){const t=Date.now(),i=[];for(const[s,n]of this.bM)!n.NM||n.NM>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.zM(s);return i}jM(t){this.WM=t}$M(){this.WM&&this.WM()}}const yh={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Sh{constructor(t,i,s,n){this.Yt=t,this.YM=i,this.KM=s,this.GM=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 h=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const r=this.XM(e.ZM);i.fillStyle=r,i.arc(h,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.ZM&&(i.strokeStyle=r,i.lineWidth=Math.floor(2*t.horizontalPixelRatio),i.beginPath(),i.moveTo((e.ut-4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.ZM)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.ZM-7*e.ZM*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.ZM)*t.verticalPixelRatio),i.stroke())})})}XM(t){return 0===t?this.YM:t>0?this.GM:this.KM}}class xh{constructor(t,i,s){this.Yt=[],this.be=t,this.cr=i,this.Cs=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.cr.timeToCoordinate(t.time)),ct:i,ZM: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 Sh(this.Yt,t,this.Cs.negativeColor,this.Cs.positiveColor)}}function Ph(t,i){return"Line"===i||"Area"===i}class Ch{constructor(t){this.Vf=void 0,this.be=void 0,this.Xb=[],this.__=null,this.JM=new Map,this.QM=new Mh(()=>this.Zb()),this.Cs={...yh,...t}}oh(t){this.Cs={...this.Cs,...t},this.Zb()}SM(t){this.QM.UM();const i=this.__;i&&t.forEach(t=>{this.QM.OM(t,i.key(t.time))})}EM(){return this.QM.qM()}Zb(){this.cM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Vf=i,this.be=s,this.__=e;const h=this.be.seriesType();if("Area"!==h&&"Line"!==h)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Xb=[new xh(this.be,this.Vf.timeScale(),this.Cs)],this.cM=n,this.Zb()}detached(){this.Vf=void 0,this.be=void 0,this.cM=void 0}jf(){return r(this.Vf)}Oa(){return r(this.be)}updateAllViews(){this.Xb.forEach(t=>t.Tt(this.EM()))}paneViews(){return this.Xb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.JM.clear();const s=this.__;s&&t.forEach(t=>{Gs(t)&&Ph(0,i)&&this.JM.set(s.key(t.time),t.value)}),r(this.be).setData(t)}Tt(t,i){if(!this.be||!this.__)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.__.key(t.time);if(Ks(t)&&this.JM.delete(n),Gs(t)&&Ph(0,s)){const i=this.JM.get(n);i&&this.QM.OM({time:t.time,value:t.value,sign:Th(t.value,i)},n,this.Cs.updateVisibilityDuration)}r(this.be).update(t,i)}ty(){this.QM.UM()}}function Th(t,i){return t===i?0:t-i>0?1:-1}class kh extends sh{setData(t){return this.ar.lt(t)}update(t,i){return this.ar.Tt(t,i)}markers(){return this.ar.EM()}setMarkers(t){return this.ar.SM(t)}clearMarkers(){return this.ar.ty()}}function Dh(t,i={}){return new kh(t,new Ch(i))}class Ih{constructor(t,i){this.iy=null,this.sy=[],this.Cs={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.iy=bh(t)}addPosition(t){this.sy.push(t),this.ny()}addPositions(t){this.sy.push(...t),this.ny()}setPositions(t){this.sy=[...t],this.ny()}closePosition(t,i,s){const n=this.sy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.ny())}removePosition(t){this.sy=this.sy.filter(i=>i.id!==t),this.ny()}clearPositions(){this.sy=[],this.ny()}getPositions(){return this.sy}applyOptions(t){t.longColors&&(this.Cs.longColors={...this.Cs.longColors,...t.longColors}),t.shortColors&&(this.Cs.shortColors={...this.Cs.shortColors,...t.shortColors}),void 0!==t.defaultSize&&(this.Cs.defaultSize=t.defaultSize),void 0!==t.entryOffset&&(this.Cs.entryOffset=t.entryOffset),void 0!==t.exitOffset&&(this.Cs.exitOffset=t.exitOffset),this.ny()}ey(){const t=[];for(const i of this.sy){const s="long"===i.type,n=i.size??this.Cs.defaultSize,e=i.color?.entry??(s?this.Cs.longColors.entry:this.Cs.shortColors.entry),h=i.color?.exit??(s?this.Cs.longColors.exit:this.Cs.shortColors.exit),r={time:i.entry.time,position:"atPriceMiddle",price:i.entry.price+this.Cs.entryOffset,shape:s?"arrowUp":"arrowDown",color:e,size:n};if(i.text?.entry&&(r.text=i.text.entry),i.id&&(r.id=`${i.id}-entry`),t.push(r),i.exit){const e={time:i.exit.time,position:"atPriceMiddle",price:i.exit.price+this.Cs.exitOffset,shape:s?"arrowDown":"arrowUp",color:h,size:n};i.text?.exit&&(e.text=i.text.exit),i.id&&(e.id=`${i.id}-exit`),t.push(e)}}return t}ny(){if(this.iy){const t=this.ey();this.iy.setMarkers(t)}}detach(){this.iy&&(this.iy.detach(),this.iy=null),this.sy=[]}}function Rh(t,i,s){const n=new Ih(t,s);return i&&i.length>0&&n.setPositions(i),n}const Vh=new WeakMap;function Fh(t){return"string"==typeof t?t:String(t)}function Eh(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Fh(t.time),t.volume);Vh.set(t,s)}function Lh(t,i){return Vh.get(t)?.get(Fh(i))}function Ah(t){const i=Vh.get(t);return void 0!==i&&i.size>0}function Bh(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Wh(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 Oh(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 zh(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 $h(t){return null==t?void 0:t.time}function Hh(t){const{e_:i,jf:s,hy:n,ly:e,oy:h,Zl:r}=t,l=t._y??[];let o=t.O,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,h=i.length===s.length,r=$h(s[s.length-1])===$h(n);if(e||h&&r)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&&$h(a[a.length-1])===$h(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 ${r}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==h&&h(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==h&&h(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 Nh(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(le,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),h=(t,i,s)=>{if(!t||t.length<i)return[];const n=Oh(t,s),e=[];for(let s=i-1;s<n.length;s++){let h=0;for(let t=0;t<i;t++)h+=n[s-t];const r=h/i;t[s]&&t[s].time&&e.push({time:t[s].time,value:r})}return e},r=Hh({e_:t,jf:i,hy:[e],Zl:"SMA",O:n,_y:["period","source"],ly:(t,i)=>[[e,h(t,i.period??20,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...r}}function Uh(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(le,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),h=(t,i,s)=>{if(!t||t.length<i)return[];const n=Oh(t,s),e=[],h=2/(i+1);let r=0;for(let t=0;t<i;t++)r+=n[t];r/=i,t[i-1]&&t[i-1].time&&e.push({time:t[i-1].time,value:r});for(let s=i;s<n.length;s++)r=(n[s]-r)*h+r,t[s]&&t[s].time&&e.push({time:t[s].time,value:r});return e},r=Hh({e_:t,jf:i,hy:[e],Zl:"EMA",O:n,_y:["period","source"],ly:(t,i)=>[[e,h(t,i.period??12,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...r}}function qh(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(le,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01}},n.paneIndex),h=(t,i,s)=>{if(!t||t.length<i)return[];const n=Oh(t,s),e=[],h=i*(i+1)/2;for(let s=i-1;s<n.length;s++){let r=0;for(let t=0;t<i;t++){const e=t+1;r+=n[s-i+1+t]*e}const l=r/h;t[s]&&t[s].time&&e.push({time:t[s].time,value:l})}return e},r=Hh({e_:t,jf:i,hy:[e],Zl:"WMA",O:n,_y:["period","source"],ly:(t,i)=>[[e,h(t,i.period??20,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...r}}function jh(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,h=i.addSeries(le,{color:n.colorUpper},e),r=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=Hh({e_:t,jf:i,hy:[h,r,l],Zl:"Bollinger Bands",O:n,_y:["period","stdDev"],ly:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{uy:[],py:[],vy:[]};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=[],h=[],r=[];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}),h.push({time:i,value:a}),r.push({time:i,value:d})}}return{uy:e,py:h,vy:r}})(t,i.period??20,i.stdDev??2);return[[h,s.uy],[r,s.py],[l,s.vy]]},oy:t=>{const i=t.lineWidth??1;h.applyOptions({color:t.colorUpper,lineWidth:i}),r.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:h,middle:r,lower:l,...o}}function Yh(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,h=i.addSeries(le,{color:n.colorUpper},e),r=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=Hh({e_:t,jf:i,hy:[h,r,l],Zl:"Keltner Channels",O:n,_y:["period","atrPeriod","multiplier","source"],ly:(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{uy:[],py:[],vy:[]};const h=Oh(t,i.source??"close"),r=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=h[t];r.push(o/s);for(let t=s;t<h.length;t++)r.push((h[t]-r[r.length-1])*l+r[r.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<r.length;i++){const n=s-1+i,h=t[n],l=_[n-1];if(!h||void 0===h.time||void 0===l)continue;const o=r[i],a=l*e;d.push({time:h.time,value:o}),c.push({time:h.time,value:o+a}),p.push({time:h.time,value:o-a})}return{uy:c,py:d,vy:p}})(t,i);return[[h,s.uy],[r,s.py],[l,s.vy]]},oy:t=>{const i=t.lineWidth??1,s=t.lineStyle;h.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),r.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:h,middle:r,lower:l,...o}}function Kh(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,h=i.addSeries(le,{color:n.colorUpper},e),r=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=Hh({e_:t,jf:i,hy:[h,r,l],Zl:"Donchian Channels",O:n,_y:["period"],ly:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{uy:[],py:[],vy:[]};const s=[],n=[],e=[];for(let h=i-1;h<t.length;h++){let r=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[h-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>r&&(r=n),e<l&&(l=e)}const o=t[h];void 0!==o.time&&r!==-1/0&&l!==1/0&&(s.push({time:o.time,value:r}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(r+l)/2}))}return{uy:s,py:n,vy:e}})(t,i.period??20);return[[h,s.uy],[r,s.py],[l,s.vy]]},oy:t=>{const i=t.lineWidth??1,s=t.lineStyle;h.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),r.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:h,middle:r,lower:l,...o}}function Gh(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(le,{color:n.colorUp,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:n.dotSize},n.paneIndex),h=(t,i,s,n,e)=>{if(!t||t.length<3)return[];const h=t[0],r=t[1];if(!("high"in h)||!("low"in h))return[];const l=[];let o=r.close>=h.close,a=o?h.low:h.high,_=o?r.high:r.low,u=i;for(let h=1;h<t.length;h++){const r=t[h],c=t[h-1];if("high"in r&&"low"in r&&(a+=u*(_-a),o?(a=Math.min(a,c.low,t[h-2]?t[h-2].low:c.low),r.low<a?(o=!1,a=_,_=r.low,u=i):r.high>_&&(_=r.high,u=Math.min(u+i,s))):(a=Math.max(a,c.high,t[h-2]?t[h-2].high:c.high),r.high>a?(o=!0,a=_,_=r.high,u=i):r.low<_&&(_=r.low,u=Math.min(u+i,s))),void 0!==r.time)){const t={};t.time=r.time,t.value=a,t.color=o?n:e,l.push(t)}}return l},r=Hh({e_:t,jf:i,hy:[e],Zl:"Parabolic SAR",O:n,_y:["step","maxStep","colorUp","colorDown"],ly:(t,i)=>[[e,h(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],oy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...r}}function Xh(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.my,i.wy-1,i.gy))}}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 Zh(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,h=i.addSeries(le,{color:n.color},e),r=i.addSeries(le,{color:n.bandColor},e),l=i.addSeries(le,{color:n.bandColor},e),o=Hh({e_:t,jf:i,hy:[h,r,l],Zl:"VWAP",O:n,_y:["anchorPeriod","bandMultiplier"],ly:(i,s)=>{const n=((i,s,n)=>{const e=[],h=[],r=[];if(!i||0===i.length||!Ah(t))return{by:e,uy:h,vy:r};let l=null,o=0,a=0,_=0;for(const u of i){const i=Xh(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=Lh(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;h.push({time:u.time,value:p+i}),r.push({time:u.time,value:p-i})}}return{by:e,uy:h,vy:r}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[h,n.by],[r,n.uy],[l,n.vy]]},oy:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;h.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),r.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:h,upper:r,lower:l,...o}}function Jh(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(le,{color:n.colorUp,lineWidth:n.lineWidth},n.paneIndex),h=(t,i,s,n,e)=>{if(!t||t.length<i+1)return[];const h=[];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?h.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):h.push(0)}const r=[];let l=0;for(let t=0;t<i;t++)l+=h[t];r[i-1]=l/i;for(let t=i;t<h.length;t++)r[t]=(r[t-1]*(i-1)+h[t])/i;const o=[];let a=0,_=0,u=!0,c=!1;for(let h=i;h<t.length;h++){const i=t[h],l=t[h-1],d=r[h-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},r=Hh({e_:t,jf:i,hy:[e],Zl:"SuperTrend",_y:["period","multiplier","colorUp","colorDown"],O:n,ly:(t,i)=>[[e,h(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],oy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...r}}class Qh{constructor(t,i,s,n){this.Vf=t,this.be=i,this.R_=s,this.My=n}draw(t){const i=this.My();if(!i.Vt||i.yy<=0)return;const s=this.R_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Vf.timeScale();for(let h=1;h<s.length;h++){const r=s[h-1],l=s[h],o=e.timeToCoordinate(r.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(r.Sy),u=this.be.priceToCoordinate(r.xy),c=this.be.priceToCoordinate(l.Sy),d=this.be.priceToCoordinate(l.xy);if(null===_||null===u||null===c||null===d)continue;const p=r.Sy>=r.xy;n.fillStyle=this.Py(p?i.Cy:i.Ty,i.yy),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()}})}Py(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class tr{constructor(t,i,s,n){this.Jt=new Qh(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function ir(t,i,s){if(i<s-1)return null;let n=-1/0,e=1/0;for(let h=0;h<s;h++){const s=t[i-h],r="high"in s?s.high:s.value,l="low"in s?s.low:s.value;r>n&&(n=r),l<e&&(e=l)}return n===-1/0?null:(n+e)/2}function sr(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,h=t=>i.addSeries(le,{color:t},e),r=h(n.colorConversion),l=h(n.colorBase),o=h(n.colorSpanA),a=h(n.colorSpanB),_=h(n.colorLagging);let u=[],c=n;const d=new tr(i,t,()=>u,()=>({Cy:c.cloudBullishColor??"#089981",Ty:c.cloudBearishColor??"#F23645",yy: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,h=i.displacement??26,r=[],l=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{ky:r,er:l,Sy:o,xy:a,Dy:_,Iy: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 h=t[e-1].time,r=t[e].time;if("number"!=typeof h||"number"!=typeof r)return null;const l=r-h;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=ir(t,i,s),u=ir(t,i,n);null!==a&&r.push({time:o.time,value:a}),null!==u&&l.push({time:o.time,value:u}),null!==a&&null!==u&&p.set(i+h,(a+u)/2);const c=ir(t,i,e);null!==c&&f.set(i+h,c);const d=i-h;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+h;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,Sy:s,xy:n};u.push(t)}}return{ky:r,er:l,Sy:o,xy:a,Dy:_,Iy:u}},v=Hh({e_:t,jf:i,hy:[r,l,o,a,_],Zl:"Ichimoku",O:n,_y:["conversionPeriod","basePeriod","spanBPeriod","displacement"],ly:(t,i)=>{c=i;const s=f(t,i);return u=s.Iy,[[r,s.ky],[l,s.er],[o,s.Sy],[a,s.xy],[_,i.showLagging??1?s.Dy:[]]]},oy:t=>{c=t;const s=t.lineWidth??1;r.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:r,base:l,spanA:o,spanB:a,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}}function nr(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,h=t=>i.addSeries(le,{color:t},e),r=h(n.colorPivot),l=[h(n.colorResistance),h(n.colorResistance),h(n.colorResistance)],o=[h(n.colorSupport),h(n.colorSupport),h(n.colorSupport)],a=Hh({e_:t,jf:i,hy:[r,...l,...o],Zl:"Pivot Points",O:n,_y:["pivotPeriod"],ly:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{Ry:s,Vy:n,Fy:e};let h=null,r=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=Xh(_.time,i);if(null===t)continue;if(null===h)h=t;else if(t!==h){const i=(r+l+o)/3,s=r-l;a={Ey:i,Ly:[2*i-l,i+s,r+2*(i-l)],Ay:[2*i-r,i-s,l-2*(r-i)]},h=t,r=-1/0,l=1/0}const u="high"in _?_.high:_.value,c="low"in _?_.low:_.value;if(u>r&&(r=u),c<l&&(l=c),o="close"in _?_.close:_.value,null!==a&&void 0!==_.time){s.push({time:_.time,value:a.Ey});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Ly[t]}),e[t].push({time:_.time,value:a.Ay[t]})}}return{Ry:s,Vy:n,Fy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[r,s.Ry]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Vy[t]:[]]),e.push([o[t],t<n?s.Fy[t]:[]]);return e},oy:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));r.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:r,resistances:l,supports:o,...a}}function er(t){return null!=t&&"number"==typeof t.close}function hr(t){const i=[];let s=null,n=null;for(const e of t){if(!er(e)){null!=e&&i.push({time:e.time,customValues:e.customValues});continue}const t=(e.open+e.high+e.low+e.close)/4,h=null===s||null===n?(e.open+e.close)/2:(s+n)/2;i.push({time:e.time,open:h,high:Math.max(e.high,h,t),low:Math.min(e.low,h,t),close:t,customValues:e.customValues}),s=h,n=t}return i}function rr(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(),h=i.addSeries(Ee,{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},n.paneIndex),r=e.visible;!0===n.hideSource&&t.applyOptions({visible:!1});const l=Hh({e_:t,jf:i,hy:[h],Zl:"Heikin Ashi",O:n,_y:[],ly:t=>[[h,hr(t)]],oy:i=>{h.applyOptions({upColor:i.upColor,downColor:i.downColor,borderVisible:i.borderVisible,borderUpColor:i.borderUpColor,borderDownColor:i.borderDownColor,wickVisible:i.wickVisible,wickUpColor:i.wickUpColor,wickDownColor:i.wickDownColor}),t.applyOptions({visible:!0!==i.hideSource&&r})}});return{Oa:h,options:l.options,applyOptions:l.applyOptions,recalculate:l.recalculate,remove:()=>{l.remove();try{t.applyOptions({visible:r})}catch(t){}}}}function lr(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,h=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Bh(0,100)},e),r=Wh(i,h,e);i.priceScale(h.options().priceScaleId??"right",r).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=zh(h,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Oh(t,s),e=[],h=[];for(let t=1;t<n.length;t++)h.push(n[t]-n[t-1]);let r=0,l=0;for(let t=0;t<i;t++)h[t]>0?r+=h[t]:l+=Math.abs(h[t]);r/=i,l/=i;let o=0===l?100:r/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<h.length;s++){const n=h[s];r=(r*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:r/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=Hh({e_:t,jf:i,hy:[h],Zl:"RSI",O:n,_y:["period","source"],ly:(t,i)=>[[h,o(t,i.period??14,i.source??"close")]],oy:t=>{h.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:h,...a}}function or(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,h=i.addSeries(le,{color:n.colorMACD},e),r=i.addSeries(le,{color:n.colorSignal},e),l=i.addSeries(Be,{color:n.colorHistogramUp},e),o=(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},a=Hh({e_:t,jf:i,hy:[h,r,l],Zl:"MACD",O:n,_y:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],ly:(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{By:[],Wy:[],Oy:[]};const h=[];for(const i of t)"close"in i?h.push(i.close):"value"in i?h.push(i.value):h.push(0);const r=o(h,s),l=o(h,n),a=[],_=n-s;for(let t=0;t<l.length;t++)a.push(r[t+_]-l[t]);const u=o(a,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,h=a[s],r=u[s],l=h-r;c.push({time:e,value:h}),d.push({time:e,value:r}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{By:c,Wy:d,Oy:p}})(t,i);return[[h,s.By],[r,s.Wy],[l,s.Oy]]},oy:t=>{const i=t.lineWidth??2;h.applyOptions({color:t.colorMACD,lineWidth:i}),r.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:h,signal:r,histogram:l,...a}}function ar(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,h=Bh(0,100),r=i.addSeries(le,{color:n.colorK,autoscaleInfoProvider:h},e),l=i.addSeries(le,{color:n.colorD,autoscaleInfoProvider:h},e),o=Wh(i,r,e);i.priceScale(r.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=zh(r,n.levelColor),_=Hh({e_:t,jf:i,hy:[r,l],Zl:"Stochastic",O:n,_y:["kPeriod","dPeriod"],ly:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{zy:[],$y:[]};const n=[];for(let s=i-1;s<t.length;s++){let e=-1/0,h=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),h=Math.min(h,i.low))}const r=t[s];if("close"in r){const t=(r.close-h)/(e-h)*100;n.push(t)}}const e=[];for(let s=0;s<n.length;s++){const h=i-1+s;t[h]&&t[h].time&&e.push({time:t[h].time,value:n[s]})}const h=[];if(n.length>=s)for(let e=s-1;e<n.length;e++){let r=0;for(let t=0;t<s;t++)r+=n[e-t];const l=r/s,o=i-1+e;t[o]&&t[o].time&&h.push({time:t[o].time,value:l})}return{zy:e,$y:h}})(t,i.kPeriod??14,i.dPeriod??3);return[[r,s.zy],[l,s.$y]]},oy:t=>{const i=t.lineWidth??2,s=t.lineStyle;r.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:r,d:l,..._}}function _r(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),h=(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),h=Math.abs(n.low-e.close),r=Math.max(t,i,h);s.push(r)}}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 h=i;h<s.length;h++)e=(e*(i-1)+s[h])/i,t[h+1]&&t[h+1].time&&n.push({time:t[h+1].time,value:e});return n},r=Hh({e_:t,jf:i,hy:[e],Zl:"ATR",O:n,_y:["period"],ly:(t,i)=>[[e,h(t,i.period??14)]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...r}}function ur(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,h=i.addSeries(Be,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),r=Wh(i,h,e);i.priceScale(h.options().priceScaleId??"right",r).applyOptions({scaleMargins:{top:.8,bottom:0}});const l=(i,s)=>{const n=t.data();if(!n||0===n.length||!Ah(t))return[];const e=[];for(const h of n){const n=Lh(t,h.time);n&&"close"in h&&"open"in h&&e.push({time:h.time,value:n,color:h.close>=h.open?i:s})}return e},o=Hh({e_:t,jf:i,hy:[h],Zl:"Volume",O:n,_y:["colorUp","colorDown"],ly:(t,i)=>[[h,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:h,...o}}function cr(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),h=()=>{const i=t.data();if(!i||i.length<2||!Ah(t))return[];const s=[];let n=0;s.push({time:i[0].time,value:n});for(let e=1;e<i.length;e++){const h=i[e],r=i[e-1],l=Lh(t,h.time);l&&"close"in h&&"close"in r&&(h.close>r.close?n+=l:h.close<r.close&&(n-=l),s.push({time:h.time,value:n}))}return s},r=Hh({e_:t,jf:i,hy:[e],Zl:"OBV",O:n,ly:()=>[[e,h()]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...r}}function dr(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,h=Bh(0,100),r=i.addSeries(le,{color:n.colorADX,autoscaleInfoProvider:h},e),l=i.addSeries(le,{color:n.colorPlusDI,autoscaleInfoProvider:h},e),o=i.addSeries(le,{color:n.colorMinusDI,autoscaleInfoProvider:h},e),a=Wh(i,r,e);i.priceScale(r.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=zh(r,n.levelColor),u=Hh({e_:t,jf:i,hy:[r,l,o],Zl:"ADX",O:n,_y:["period"],ly:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Hy:[],Ny:[],Uy:[]};const s=[],n=[],e=[];for(let i=1;i<t.length;i++){const h=t[i],r=t[i-1];if(!("high"in h)||!("low"in h)||!("close"in r)){s.push(0),n.push(0),e.push(0);continue}s.push(Math.max(h.high-h.low,Math.abs(h.high-r.close),Math.abs(h.low-r.close)));const l=h.high-r.high,o=r.low-h.low;n.push(l>o&&l>0?l:0),e.push(o>l&&o>0?o:0)}let h=0,r=0,l=0;for(let t=0;t<i;t++)h+=s[t],r+=n[t],l+=e[t];const o=[],a=[],_=[],u=[];for(let c=i;c<s.length;c++){h=h-h/i+s[c],r=r-r/i+n[c],l=l-l/i+e[c];const d=0===h?0:r/h*100,p=0===h?0:l/h*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{Hy:o,Ny:a,Uy:_}})(t,i.period??14),n=i.showDI??!0;return[[r,s.Hy],[l,n?s.Ny:[]],[o,n?s.Uy:[]]]},oy:t=>{const i=t.lineWidth??2,s=t.lineStyle;r.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),o.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:r,plusDI:l,minusDI:o,...u}}function pr(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,h=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth},e),r=Wh(i,h,e);i.priceScale(h.options().priceScaleId??"right",r).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=zh(h,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 h=0;for(let t=0;t<i;t++)h+=s[e-t];const r=h/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-r);const o=l/i,a=0===o?0:(s[e]-r)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=Hh({e_:t,jf:i,hy:[h],Zl:"CCI",O:n,_y:["period"],ly:(t,i)=>[[h,o(t,i.period??20)]],oy:t=>{h.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:h,...a}}function fr(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,h=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Bh(-100,0)},e),r=Wh(i,h,e);i.priceScale(h.options().priceScaleId??"right",r).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=zh(h,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,h=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),h=Math.min(h,i.low))}const r=t[n];if(!("close"in r)||void 0===r.time)continue;const l=e-h,o=0===l?0:(e-r.close)/l*-100;s.push({time:r.time,value:o})}return s},a=Hh({e_:t,jf:i,hy:[h],Zl:"Williams %R",O:n,_y:["period"],ly:(t,i)=>[[h,o(t,i.period??14)]],oy:t=>{h.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:h,...a}}function vr(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,h=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Bh(0,100)},e),r=Wh(i,h,e);i.priceScale(h.options().priceScaleId??"right",r).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=zh(h,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Ah(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const h=i[s],r=i[s-1];if(!("high"in h)||!("low"in h)||!("close"in h)){n.push(0),e.push(0);continue}const l=(h.high+h.low+h.close)/3,o=(r.high+r.low+r.close)/3,a=l*(Lh(t,h.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const h=[];for(let t=s-1;t<n.length;t++){let r=0,l=0;for(let i=0;i<s;i++)r+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+r/l),a=i[t+1];a&&void 0!==a.time&&h.push({time:a.time,value:o})}return h},a=Hh({e_:t,jf:i,hy:[h],Zl:"MFI",O:n,_y:["period"],ly:(t,i)=>[[h,o(t,i.period??14)]],oy:t=>{h.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:h,...a}}class mr{constructor(t){this.qy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.qy.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.jy(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}jy(t,i,s,n){const e=i.Yy||i.startTime,h=i.Ky||i.endTime,r=i.I||i.color,l=i.yy||i.opacity;if(!i||!e||!h)return;const o=this.qy.getChart().timeScale(),a=o.timeToCoordinate(e),_=o.timeToCoordinate(h);if(null===a||null===_)return;const u=a*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this.Gy(r,l),t.fillRect(u,d,c-u,p-d)}Gy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class wr{constructor(t){this.Jt=new mr(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const gr=[{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 br{constructor(t,i,s={}){this.Xy=[],this.Ub=null,this.nr=null,this.Vf=t,this.be=i,this.Cs={sessions:s.sessions||gr,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.Zy(),this.Cs.enabled&&this.Jy()}Zy(){this.nr=new wr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nr?[this.nr]:[],updateAllViews:()=>{this.nr}};this.Ub=t,this.be.attachPrimitive(t)}Jy(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Qy()}),this.Qy()}Qy(){this.tS();const t=this.Vf.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.iS(s),this.cM()}iS(t){if(0!==t.length){for(const i of this.Cs.sessions)this.sS(i,t);this.Cs.showOverlaps&&this.nS(t)}}sS(t,i){let s=null,n=[];for(const e of i){const i=e.time,h=this.eS(i);this.hS(h,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.rS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.rS(s,n[n.length-1].time,t)}nS(t){const i=this.Cs.sessions;for(let s=0;s<i.length;s++)for(let n=s+1;n<i.length;n++){const e=i[s],h=i[n],r=this.lS(e,h);r&&this.oS(r,t)}}lS(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}oS(t,i){let s=null,n=[];for(const e of i){const i=e.time,h=this.eS(i);h>=t.ae&&h<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.aS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.aS(s,n[n.length-1].time)}rS(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",Yy:t,Ky:i,I:s.color,yy:s.opacity,_S:s.name};this.Xy.push(n)}aS(t,i){const s={an:"overlap",Yy:t,Ky:i,I:this.Cs.overlapColor,yy:this.Cs.overlapOpacity,_S:"Overlap"};this.Xy.push(s)}hS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}eS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}tS(){this.Xy=[]}applyOptions(t){this.Cs={...this.Cs,...t},this.Cs.enabled?this.Qy():this.tS(),this.cM()}options(){return{...this.Cs}}enable(){this.Cs.enabled=!0,this.Qy(),this.cM()}disable(){this.Cs.enabled=!1,this.tS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.tS(),this.cM()}getSessionBoxes(){return this.Xy}getChart(){return this.Vf}getSeries(){return this.be}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Mr(t,i,s){return new br(t,i,s)}class yr{constructor(t){this.qy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.qy.getProfileData();if(!s||0===s.bins.length)return;const n=this.qy.options(),e=this.qy.getSeries(),h=i.canvas.width/t.horizontalPixelRatio,r=Math.min(n.width||100,.2*h),l="right"===n.position?h-r:0;let o=0;for(const t of s.bins)t.volume>o&&(o=t.volume);if(0!==o){for(const h of s.bins)this.uS(i,h,l,r,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.cS(i,s.poc,n.pocColor||"#FF6B00",e,h,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.dS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,h,t.horizontalPixelRatio,t.verticalPixelRatio)}})}uS(t,i,s,n,e,h,r,l,o,a){const _=i.volume/e*n,u=h.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>=h.valueAreaLow&&i.priceLevel<=h.valueAreaHigh,b=Math.abs(i.priceLevel-h.poc)<1e-5;let M=r.profileColor||"#2962FF",y=r.opacity||.3;b?(M=r.pocColor||"#FF6B00",y=.6):g&&r.showValueArea&&(M=r.valueAreaColor||"#089981",y=.4),t.fillStyle=this.Gy(M,y),t.fillRect(f,v,m,w)}cS(t,i,s,n,e,h,r){const l=n.priceToCoordinate(i);if(null===l)return;const o=l*r;t.strokeStyle=s,t.lineWidth=2*Math.min(h,r),t.setLineDash([5*h,3*h]),t.beginPath(),t.moveTo(0,o),t.lineTo(e*h,o),t.stroke(),t.setLineDash([])}dS(t,i,s,n,e,h,r,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Gy(n,.5),t.lineWidth=1*Math.min(r,l),t.setLineDash([3*r,2*r]),t.beginPath(),t.moveTo(0,i),t.lineTo(h*r,i),t.stroke()}const a=e.priceToCoordinate(s);if(null!==a){const i=a*l;t.strokeStyle=this.Gy(n,.5),t.lineWidth=1*Math.min(r,l),t.setLineDash([3*r,2*r]),t.beginPath(),t.moveTo(0,i),t.lineTo(h*r,i),t.stroke()}t.setLineDash([])}Gy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Sr{constructor(t){this.Jt=new yr(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class xr{constructor(t,i,s={}){this.pS=null,this.fS=new Map,this.Ub=null,this.nr=null,this.Vf=t,this.be=i,this.Cs={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.Zy(),this.Jy()}Zy(){this.nr=new Sr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nr?[this.nr]:[],updateAllViews:()=>{this.nr}};this.Ub=t,this.be.attachPrimitive(t)}Jy(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.vS()}),this.vS()}setVolumeData(t){this.fS=t,this.vS()}addVolumeData(t,i){this.fS.set(t,i),this.vS()}vS(){const t=this.Vf.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 h=(e-n)/this.Cs.numberOfBins,r=[];for(let t=0;t<this.Cs.numberOfBins;t++)r.push({priceLevel:n+(t+.5)*h,volume:0,percentage:0});let l=0;for(const t of s){const i=t.close||t.value,s=this.fS.get(t.time)||1,e=Math.floor((i-n)/h);r[Math.max(0,Math.min(this.Cs.numberOfBins-1,e))].volume+=s,l+=s}for(const t of r)t.percentage=l>0?t.volume/l*100:0;let o=r[0];for(const t of r)t.volume>o.volume&&(o=t);const a=l*this.Cs.valueAreaPercentage,_=[...r].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.pS={bins:r,binSize:h,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.cM()}getProfileData(){return this.pS}applyOptions(t){this.Cs={...this.Cs,...t},this.vS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.pS=null,this.fS.clear(),this.cM()}getChart(){return this.Vf}getSeries(){return this.be}options(){return this.Cs}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Pr(t,i,s){return new xr(t,i,s)}function Cr(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)}class Tr{constructor(t,i){this.mS=new Map,this.wS=null,this.gS=null,this.bS=null,this.MS=null,this.yS=null,this.SS=null,this.bg=void 0,this.Vf=t,this.kf=i,this.xS=t=>this.PS(t),this.CS=t=>this.TS(t),this.kS=t=>this.DS(t),this.IS=t=>this.RS(t),this.VS=()=>this.FS(),this.ES=t=>{"Escape"===t.key&&this.FS()},this.Vf.subscribeCrosshairMove(this.xS),this.kf.addEventListener("pointerdown",this.CS),this.kf.addEventListener("pointermove",this.kS),this.kf.addEventListener("pointerup",this.IS),this.kf.addEventListener("pointercancel",this.VS),document.addEventListener("keydown",this.ES)}LS(t){this.mS.set(t.id(),t)}AS(t){const i=t.id();this.wS===i&&this.BS(null),this.gS===t&&this.FS(),this.mS.delete(i)}Gi(){return 0===this.mS.size}m(){this.Vf.unsubscribeCrosshairMove(this.xS),this.kf.removeEventListener("pointerdown",this.CS),this.kf.removeEventListener("pointermove",this.kS),this.kf.removeEventListener("pointerup",this.IS),this.kf.removeEventListener("pointercancel",this.VS),document.removeEventListener("keydown",this.ES),this.mS.clear()}PS(t){if(this.SS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.bg=t.paneIndex,null!==this.gS)return;const i=this.WS(t.hoveredObjectId);this.BS(i?i.id():null),this.OS()}TS(t){const i=null===this.wS?null:this.mS.get(this.wS)??null;i&&(this.MS={ut:t.clientX,ct:t.clientY},this.yS=i,i.isDraggable()&&(this.gS=i,this.bS=t.pointerId,this.kf.setPointerCapture(t.pointerId),i.beginDrag(),this.OS(),t.preventDefault(),t.stopPropagation()))}DS(t){if(null===this.gS)return;if(!this.zS(t))return void this.FS();const i=this.$S(t);null!==i&&this.gS.dragTo(i),t.preventDefault(),t.stopPropagation()}RS(t){const i=this.gS,s=this.yS,n=this.MS;this.HS(),this.yS=null,this.MS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.gS=null,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.OS();null!==s&&!e&&s.isClickable()&&s.click()}FS(){if(null===this.gS)return;const t=this.gS;this.gS=null,this.HS(),t.cancelDrag(),this.OS()}zS(t){const i=this.kf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}HS(){null!==this.bS&&(this.kf.hasPointerCapture(this.bS)&&this.kf.releasePointerCapture(this.bS),this.bS=null)}$S(t){const i=this.gS;if(null===i)return null;if(null!==this.SS&&this.bg===i.paneIndex())return i.priceAt(this.SS.ct);const s=this.Vf.panes()[i.paneIndex()],n=s?s.getHTMLElement():null;return n?i.priceAt(t.clientY-n.getBoundingClientRect().top):null}WS(t){return"string"!=typeof t?null:this.mS.get(t)??null}BS(t){this.wS!==t&&(null!==this.wS&&this.mS.get(this.wS)?.setHovered(!1),this.wS=t,null!==t&&this.mS.get(t)?.setHovered(!0))}OS(){if(null!==this.gS)return void this.Vf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.wS?null:this.mS.get(this.wS);t?this.Vf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Vf.chartElement().style.removeProperty("cursor")}}const kr=new WeakMap;let Dr=0;class Ir{constructor(t,i,s){this.sh=null,this.NS=!1,this.US="",this.qS=null,this.Vf=t,this.be=i,this.yo="pipsend-trading-line-"+Dr++,this.Cs={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.jS(),(this.Cs.draggable||this.Cs.onClick)&&function(t){const i=t.chartElement();if(!i)return null;let s=kr.get(t);return s||(s=new Tr(t,i),kr.set(t,s)),s}(this.Vf)?.LS(this)}id(){return this.yo}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Cs.draggable}isClickable(){return void 0!==this.Cs.onClick}setHovered(t){this.NS!==t&&this.sh&&(this.NS=t,this.sh.applyOptions({color:t?this.Cs.hoverColor:this.US}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.qS=this.Cs.price,this.Cs.onDragStart&&this.Cs.onDragStart(this.Cs.price)}dragTo(t){this.YS(t),this.Cs.onDragMove&&this.Cs.onDragMove(t)}commitDrag(){this.qS=null,this.Cs.onDragEnd&&this.Cs.onDragEnd(this.Cs.price)}cancelDrag(){const t=this.qS;this.qS=null,null!==t&&t!==this.Cs.price&&(this.YS(t),this.Cs.onDragMove&&this.Cs.onDragMove(t))}click(){this.Cs.onClick&&this.Cs.onClick(this.Cs.price)}applyOptions(t){if(this.Cs={...this.Cs,...t},t.color&&(this.US=t.color),!this.sh)return;const i={title:this.KS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.NS||(i.color=t.color),void 0!==t.lineWidth&&(i.lineWidth=t.lineWidth),void 0!==t.lineStyle&&(i.lineStyle=t.lineStyle),this.sh.applyOptions(i)}setTitle(t){this.Cs.title=t,this.sh&&this.sh.applyOptions({title:t})}getPrice(){return this.Cs.price}setPrice(t){this.YS(t)}remove(){!function(t,i){const s=kr.get(t);s&&(s.AS(i),s.Gi()&&(s.m(),kr.delete(t)))}(this.Vf,this),this.sh&&(this.be.removePriceLine(this.sh),this.sh=null)}getPriceLine(){return this.sh}KS(){if(this.Cs.formatTitle)try{return this.Cs.formatTitle(this.Cs.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Cs.title||""}jS(){this.US=this.Cs.color,this.sh=this.be.createPriceLine({id:this.yo,price:this.Cs.price,color:this.Cs.color,lineWidth:this.Cs.lineWidth,lineStyle:this.Cs.lineStyle,axisLabelVisible:this.Cs.axisLabelVisible,title:this.KS()})}YS(t){this.Cs.price=t,this.sh&&this.sh.applyOptions({price:t,title:this.KS()})}}function Rr(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,h={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 Ir(i,t,h)}class Vr{constructor(t,i){this.Rf=null,this.GS=null,this.XS=null,this.ZS={},this.Vf=t,this.be=i,this.JS()}JS(){this.Rf=this.Vf.chartElement()}QS(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.Rf?(this.GS=t,this.ZS=i||{},new Promise(t=>{this.Rf.style.cursor="crosshair",this.XS=i=>{const s=this.QS(i),n=this.tx(s);this.disableClickToCreate(),t(n)},this.Rf.addEventListener("click",this.XS)})):Promise.resolve(null)}disableClickToCreate(){this.Rf&&this.XS&&(this.Rf.removeEventListener("click",this.XS),this.Rf.style.cursor="default"),this.GS=null,this.XS=null,this.ZS={}}tx(t){if(!this.GS)return null;let i;switch(this.GS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.ZS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.ZS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.ZS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.ZS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.ZS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.ZS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.ZS};break;default:return null}return new Ir(this.Vf,this.be,i)}getCreationMode(){return this.GS}isCreating(){return null!==this.GS}}function Fr(t,i){return new Vr(t,i)}const Er=new Set(["line","body","stroke","center","move"]);function Lr(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?Er.has(n)?"move":"grab":void 0}}function Ar(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var Br;function Wr(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.my;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.wy,t.day=i.day??i.gy,t}return t}function Or(t,i){const s={};return s.price=t,s.time=i,s}function zr(t){if(!t)return Or(0,null);return Or(t.price??t.bt??0,Wr(t.time??t.gt??null))}function $r(t,i="time"){return t?t[i]??null:null}function Hr(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"}(Br||(Br={}));class Nr{constructor(t,i,s={}){this._state=Br.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.ix(),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}ix(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}_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}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 Ur=new WeakMap;function qr(t,i){Ur.set(t,i)}function jr(t){const i=!0===Ur.get(t);return i&&Ur.set(t,!1),i}function Yr(t,i,s,n,e){const h=t.canvas.width/s,r=t.canvas.height/n;if(e.ct<0||e.ct>r)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=h-o,_=e.ct-8.5;t.fillStyle=e.Wt,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.sx??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Kr;!function(t){t.nx="idle",t.hx="waiting_first_point",t.lx="waiting_second_point",t.ox="completed"}(Kr||(Kr={}));class Gr{constructor(t,i,s={}){this.Vv=Kr.nx,this._x=null,this.XS=null,this.sp=null,this.Vf=t,this.be=i,this.ux=s}vx(){this.Vv===Kr.nx&&(this.Vv=Kr.hx,this._x=null,this.mx(),this.wx())}gx(){this.Vv=Kr.nx,this._x=null,this.bx(),this.Mx(),this.ux.yx&&this.ux.yx()}Sx(){return this.Vv}xx(){return this.Vv===Kr.hx||this.Vv===Kr.lx}mx(){this.XS=t=>{this.Px(t)},this.Vf.subscribeClick(this.XS)}wx(){this.sp=t=>{this.Cx(t)},this.Vf.subscribeCrosshairMove(this.sp)}bx(){this.XS&&(this.Vf.unsubscribeClick(this.XS),this.XS=null)}Mx(){this.sp&&(this.Vf.unsubscribeCrosshairMove(this.sp),this.sp=null)}Px(t){if(!t.point)return;if(jr(this.Vf))return;const i=this.be.coordinateToPrice(t.point.y),s=Gn(this.Vf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Vv===Kr.hx?(this._x=n,this.Vv=Kr.lx,this.ux.Tx&&this.ux.Tx(n)):this.Vv===Kr.lx&&this._x&&(this.Vv=Kr.ox,this.ux.kx&&this.ux.kx(n),this.ux.Dx&&this.ux.Dx(this._x,n),this.bx(),this.Mx(),this.Vv=Kr.nx,this._x=null)}Cx(t){if(!t.point)return;if(this.Vv!==Kr.lx)return;const i=this.be.coordinateToPrice(t.point.y),s=Gn(this.Vf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.ux.Ix&&this.ux.Ix(n)}m(){this.gx()}}class Xr{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zr{constructor(t){this.Rx=t,this.Jt=new Xr(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Jr extends Nr{constructor(t,i){super(t,"trend-line",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.Wx=null,this.Ox=null,this.zx=!1,this.$x=null,this.Hx={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.Hx),this.Zy(),this.Hx.interactive?this.Nx():this.zx=!0}Nx(){new Gr(this._chart,this._series,{Tx:t=>{this.Hx.point1Time=t.gt,this.Hx.point1Price=t.bt,this.cM()},kx:t=>{this.Hx.point2Time=t.gt,this.Hx.point2Price=t.bt,this.zx=!0,this.cM(),this.Hx.onUpdate&&this.Hx.onUpdate()},Ix:t=>{this.Hx.point1Time&&!this.zx&&(this.$x=t,this.cM())},Dx:()=>{this.zx=!0}}).vx()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Zr(this)}jx(){if(!this.Hx.point1Time||!this.Hx.point2Time)return null;const t=Xn(this._chart,this._series,this.Hx.point1Time)??0,i=this._series.priceToCoordinate(this.Hx.point1Price)??0,s=Xn(this._chart,this._series,this.Hx.point2Time)??0,n=this._series.priceToCoordinate(this.Hx.point2Price)??0;if(!this.Hx.extendLeft&&!this.Hx.extendRight)return{Yx:t,Kx:i,Gx:s,Xx:n};if(s===t)return{Yx:t,Kx:i,Gx:s,Xx:n};const e=this._chart.chartElement().clientWidth,h=(n-i)/(s-t);return{Yx:this.Hx.extendLeft?0:t,Kx:this.Hx.extendLeft?i-h*t:i,Gx:this.Hx.extendRight?e:s,Xx:this.Hx.extendRight?i+h*(e-t):n}}Zx(){const t=this.jx();if(null===t)return null;const i=t.Gx>=t.Yx?t.Xx:t.Kx,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.Hx.point2Price??this.Hx.point1Price??null}drawToCanvas(t,i,s){if(!this.zx&&this.Hx.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.Hx.point1Time||!this.Hx.point2Time)return;const n=(Xn(this._chart,this._series,this.Hx.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.Hx.point1Price)??0)*s,h=(Xn(this._chart,this._series,this.Hx.point2Time)??0)*i,r=(this._series.priceToCoordinate(this.Hx.point2Price)??0)*s,l=this.Hx.lineColor,o=this.Fx?this.Hx.lineWidth+1:this.Hx.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.Hx.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.Hx.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.jx();if(null===a)return;t.moveTo(a.Yx*i,a.Kx*s),t.lineTo(a.Gx*i,a.Xx*s),t.stroke(),t.setLineDash([]),!this.Fx&&!this.Ex||this.isLocked()||(this.Qx(t,n,e,i,l),this.Qx(t,h,r,i,l));const _=this.Zx();if(!1!==this.Hx.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Yr(t,this._series,i,s,{bt:_,ct:n,Wt:l})}}Jx(t,i,s){if(!this.Hx.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.Hx.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.Hx.point1Price)??0)*s,h=(Xn(this._chart,this._series,this.$x.gt)??0)*i,r=(this._series.priceToCoordinate(this.$x.bt)??0)*s;t.strokeStyle=this.Hx.lineColor,t.lineWidth=this.Hx.lineWidth*i,t.globalAlpha=.7,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(h,r),t.stroke(),t.setLineDash([]),t.globalAlpha=1,this.Qx(t,n,e,i,this.Hx.lineColor),t.globalAlpha=.5,this.Qx(t,h,r,i,this.Hx.lineColor),t.globalAlpha=1}Qx(t,i,s,n,e){const h=5*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,h,0,2*Math.PI),t.fill(),t.stroke()}setColor(t){this.Hx.lineColor=t,this.cM()}color(){return this.Hx.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}isHovered(){return this.Ex}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){const s=this.jx();if(null===s)return!1;return this.tP(t,i,s.Yx,s.Kx,s.Gx,s.Xx)<=8}tP(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*r+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*r,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.Hx.point1Time||!this.Hx.point2Time)return null;const s=Xn(this._chart,this._series,this.Hx.point1Time)??0,n=this._series.priceToCoordinate(this.Hx.point1Price)??0,e=Xn(this._chart,this._series,this.Hx.point2Time)??0,h=this._series.priceToCoordinate(this.Hx.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-h,2))<=10)return"point2";return this.tP(t,i,s,n,e,h)<=10?"line":null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,"line"===t&&(this.Wx={gt:this.Hx.point1Time,bt:this.Hx.point1Price},this.Ox={gt:this.Hx.point2Time,bt:this.Hx.point2Price})}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.Wx=null,this.Ox=null}updateDrag(t,i){if(this.Lx&&this.Ax){if("point1"===this.Ax)this.Hx.point1Time=t,this.Hx.point1Price=i;else if("point2"===this.Ax)this.Hx.point2Time=t,this.Hx.point2Price=i;else if("line"===this.Ax&&this.Wx&&this.Ox){const s=Ar(this.Bx,t,i);this.Hx.point1Time=this.Wx.gt+s.gt,this.Hx.point1Price=this.Wx.bt+s.bt,this.Hx.point2Time=this.Ox.gt+s.gt,this.Hx.point2Price=this.Ox.bt+s.bt}this.cM(),this.Hx.onUpdate&&this.Hx.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Or(this.Hx.point1Price??0,Wr(this.Hx.point1Time)),Or(this.Hx.point2Price??0,Wr(this.Hx.point2Time))],style:{lineColor:this.Hx.lineColor,lineWidth:this.Hx.lineWidth,lineStyle:this.Hx.lineStyle,extendLeft:this.Hx.extendLeft,extendRight:this.Hx.extendRight}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.Hx.onRemove&&this.Hx.onRemove()}}function Qr(t,i){return new Jr(t,i)}class tl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class il{constructor(t){this.Rx=t,this.Jt=new tl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class sl extends Nr{constructor(t,i){super(t,"horizontal-line",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Bx=null,this.iP=0,this.sP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.sP),this.Zy()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new il(this)}nP(){return void 0===this.sP.startTime?0:Xn(this._chart,this._series,this.sP.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.sP.price)return;const n=(this._series.priceToCoordinate(this.sP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,h=this.nP()*i,r=this.sP.lineColor,l=this.Fx?this.sP.lineWidth+1:this.sP.lineWidth;t.strokeStyle=r,t.lineWidth=l*i,"dashed"===this.sP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.sP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(h,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.sP.showPriceLabel&&Yr(t,this._series,i,s,{bt:this.sP.price,ct:n/s,Wt:r}),this.sP.showLabel&&(this.Fx||this.Ex)&&this.eP(t,n,i,s,r)}eP(t,i,s,n,e){const h=this.sP.labelText||this.sP.price.toFixed(4),r=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(h).width,a=l,_=10*s,u=i-a/2-r;t.fillStyle=e,t.fillRect(_,u,o+2*r,a+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(h,_+r,u+r)}setColor(t){this.sP.lineColor=t,this.cM()}color(){return this.sP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.sP.price)return!1;const s=this._series.priceToCoordinate(this.sP.price)??0;return!(t<this.nP()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.Lx=!0,this.Bx=i,this.iP=this.sP.price??0}stopDrag(){this.Lx=!1,this.Bx=null}updateDrag(t,i){this.Lx&&(this.sP.price=this.iP+Ar(this.Bx,t,i).bt,this.cM(),this.sP.onUpdate&&this.sP.onUpdate())}getPrice(){return this.sP.price}setPrice(t){this.sP.price=t,this.cM()}setLabel(t){this.sP.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Or(this.sP.price??0,Wr(this.sP.startTime))],style:{lineColor:this.sP.lineColor,lineWidth:this.sP.lineWidth,lineStyle:this.sP.lineStyle,showLabel:this.sP.showLabel,labelText:this.sP.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.sP.onRemove&&this.sP.onRemove()}}function nl(t,i){return new sl(t,i)}class el{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class hl{constructor(t){this.Rx=t,this.Jt=new el(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class rl extends Nr{constructor(t,i){super(t,"cross-line",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Bx=null,this.hP=0,this.iP=0,this.rP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.rP),this.Zy()}Zy(){this.nr=new hl(this);const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Vx&&this.Vx()}_update(){this.cM()}lP(){if(void 0===this.rP.time||void 0===this.rP.price)return null;const t=Xn(this._chart,this._series,this.rP.time),i=this._series.priceToCoordinate(this.rP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.lP();if(null===n)return;const e=this._chart.chartElement(),h=e.clientWidth*i,r=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.rP.lineColor,_=this.Fx||this.Ex&&!this.isLocked(),u=_?this.rP.lineWidth+1:this.rP.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.rP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.rP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(h,o),t.moveTo(l,0),t.lineTo(l,r),t.stroke(),t.setLineDash([]),!1!==this.rP.showPriceLabel&&void 0!==this.rP.price&&Yr(t,this._series,i,s,{bt:this.rP.price,ct:n.ct,Wt: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())}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){const s=this.lP();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.Lx=!0,this.Bx=i,this.hP=this.rP.time,this.iP=this.rP.price??0}updateDrag(t,i){if(!this.Lx)return;const s=Ar(this.Bx,t,i);this.rP.time=this.hP+s.gt,this.rP.price=this.iP+s.bt,this.cM(),this.rP.onUpdate&&this.rP.onUpdate()}stopDrag(){this.Lx=!1,this.Bx=null}setColor(t){this.rP.lineColor=t,this.cM()}color(){return this.rP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}remove(){if(this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Vx=null,this.rP.onRemove&&this.rP.onRemove()}_serializeShape(){return{type:"crossLine",points:[Or(this.rP.price??0,Wr(this.rP.time))],style:{lineColor:this.rP.lineColor,lineWidth:this.rP.lineWidth,lineStyle:this.rP.lineStyle}}}}function ll(t,i){return new rl(t,i)}class ol{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class al{constructor(t){this.Rx=t,this.Jt=new ol(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class _l extends Nr{constructor(t,i){super(t,"polygon",i),this.R_=[],this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.oP=null,this.zx=!1,this.$x=null,this.XS=null,this.aP=null,this._P=null,this.uP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.uP),this.R_=[...i.points??[]],this.Zy(),this.uP.interactive?this.cP():this.zx=this.R_.length>=3}Zy(){this.nr=new al(this);const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Vx&&this.Vx()}_update(){this.cM()}cP(){this.XS=t=>{if(!t.point||jr(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.R_.length>=3&&this.dP(t.point.x,t.point.y)?this.pP():(this.R_.push({time:s,price:i}),this.cM()))},this.aP=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={time:s,price:i},this.cM())},this._P=t=>{"Enter"===t.key&&this.R_.length>=3?this.pP():"Escape"===t.key&&(this.R_=[],this.pP())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aP),document.addEventListener("keydown",this._P)}dP(t,i){const s=this.R_[0],n=Xn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=_l.fP&&Math.abs(i-e)<=_l.fP)}pP(){this.zx=!0,this.$x=null,this.vP(),this.cM(),this.uP.onComplete&&this.uP.onComplete(),this.uP.onUpdate&&this.uP.onUpdate()}vP(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aP&&(this._chart.unsubscribeCrosshairMove(this.aP),this.aP=null),this._P&&(document.removeEventListener("keydown",this._P),this._P=null)}mP(){const t=[...this.R_];return this.zx||null===this.$x||t.push(this.$x),this.wP(t)}wP(t){const i=[];for(const s of t){const t=Xn(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.mP();if(n.length<2)return;const e=this.uP.borderColor,h=this.Fx?this.uP.borderWidth+1:this.uP.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.zx&&(t.closePath(),this.uP.fillOpacity>0&&(t.fillStyle=this.Py(this.uP.fillColor,this.uP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=h*i,this.zx?"dashed"===this.uP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.uP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.Fx||this.Ex||!this.zx)&&!this.isLocked())for(const n of this.gP())this.bP(t,n.ut*i,n.ct*s,i,e)}gP(){return this.wP(this.R_)}bP(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()}Py(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){const s=this.gP();if(s.length<3)return!1;let n=!1;for(let e=0,h=s.length-1;e<s.length;h=e++){s[e].ct>i!=s[h].ct>i&&t<(s[h].ut-s[e].ut)*(i-s[e].ct)/(s[h].ct-s[e].ct)+s[e].ut&&(n=!n)}return n}hitTestEndpoint(t,i){const s=this.gP();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.Lx=!0,this.Ax=t,this.Bx=i,this.oP=this.R_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.Lx&&null!==this.Ax&&null!==this.oP){if("shape"===this.Ax){const s=Ar(this.Bx,t,i);this.R_=this.oP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.Ax;this.R_[s]&&(this.R_[s]={time:t,price:i})}this.cM(),this.uP.onUpdate&&this.uP.onUpdate()}}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.oP=null}setColor(t){this.uP.borderColor=t,this.uP.fillColor=t,this.cM()}color(){return this.uP.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}points(){return this.R_}remove(){if(this.vP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Vx=null,this.uP.onRemove&&this.uP.onRemove()}_serializeShape(){return{type:"polygon",points:this.R_.map(t=>Or(t.price,Wr(t.time))),style:{fillColor:this.uP.fillColor,fillOpacity:this.uP.fillOpacity,borderColor:this.uP.borderColor,borderWidth:this.uP.borderWidth,borderStyle:this.uP.borderStyle}}}}function ul(t,i){return new _l(t,i)}_l.fP=12;class cl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class dl{constructor(t){this.Rx=t,this.Jt=new cl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class pl extends Nr{constructor(t,i){super(t,"parallel-channel",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null,this.zx=!1,this._d=0,this.$x=null,this.XS=null,this.aP=null,this.yP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.yP),this.Zy(),this.yP.interactive?this.cP():this.zx=!0}Zy(){this.nr=new dl(this);const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Vx&&this.Vx()}_update(){this.cM()}cP(){this.XS=t=>{if(!t.point||jr(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.yP.point1Time=s,this.yP.point1Price=i;else{if(1!==this._d)return this.yP.channelWidth=i-this.SP(s),void this.pP();this.yP.point2Time=s,this.yP.point2Price=i}this._d++,this.cM()}},this.aP=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={gt:s,bt:i},2===this._d&&(this.yP.channelWidth=i-this.SP(s)),this.cM())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aP)}pP(){this.zx=!0,this.$x=null,this.vP(),this.cM(),this.yP.onComplete&&this.yP.onComplete(),this.yP.onUpdate&&this.yP.onUpdate()}vP(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aP&&(this._chart.unsubscribeCrosshairMove(this.aP),this.aP=null)}SP(t){const i=this.yP.point1Time,s=this.yP.point2Time,n=this.yP.point1Price,e=this.yP.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)}mS(){const t=this.yP,i=this.zx?t.point2Time:t.point2Time??this.$x?.gt,s=this.zx?t.point2Price:t.point2Price??this.$x?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Xn(this._chart,this._series,t.point1Time),e=Xn(this._chart,this._series,i),h=this._series.priceToCoordinate(t.point1Price),r=this._series.priceToCoordinate(s);if(null===n||null===e||null===h||null===r)return null;let l=e,o=r;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,o=h+(r-h)/(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:{Yx:n,Gx:l,xP:h,PP:o,CP:_,TP:u}}drawToCanvas(t,i,s){const n=this.mS();if(null===n)return;const e=this.yP,h=e.lineColor,r=this.Fx?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Py(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Yx*l,n.xP*o),t.lineTo(n.Gx*l,n.PP*o),t.lineTo(n.Gx*l,n.TP*o),t.lineTo(n.Yx*l,n.CP*o),t.closePath(),t.fill()),t.strokeStyle=h,t.lineWidth=r*l,this.zx?"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.Yx*l,n.xP*o),t.lineTo(n.Gx*l,n.PP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.Yx*l,n.CP*o),t.lineTo(n.Gx*l,n.TP*o)),t.stroke(),t.setLineDash([]);if((this.Fx||this.Ex||!this.zx)&&!this.isLocked()&&(this.bP(t,n.Yx*l,n.xP*o,l,h),this.bP(t,n.Gx*l,n.PP*o,l,h),0!==(e.channelWidth??0))){const i=(n.Yx+n.Gx)/2,s=(n.CP+n.TP)/2;this.bP(t,i*l,s*o,l,h)}if(!1!==e.showPriceLabel&&this.zx){const i=this._series.coordinateToPrice(n.PP);null!==i&&Yr(t,this._series,l,o,{bt:i,ct:n.PP,Wt:h})}}bP(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()}Py(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}kP(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*r+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*r),i-(n+a*l))}hitTest(t,i){const s=this.mS();if(null===s)return!1;return this.kP(t,i,s.Yx,s.xP,s.Gx,s.PP)<=8||this.kP(t,i,s.Yx,s.CP,s.Gx,s.TP)<=8}hitTestEndpoint(t,i){const s=this.mS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.Yx,s.xP))return"point1";if(n(s.Gx,s.PP))return"point2";if(0!==(this.yP.channelWidth??0)){if(n((s.Yx+s.Gx)/2,(s.CP+s.TP)/2))return"width"}return null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,this.MP={DP:{gt:this.yP.point1Time,bt:this.yP.point1Price},IP:{gt:this.yP.point2Time,bt:this.yP.point2Price},ts:this.yP.channelWidth??0}}updateDrag(t,i){if(!this.Lx||null===this.Ax||null===this.MP)return;const s=this.yP;if("point1"===this.Ax)s.point1Time=t,s.point1Price=i;else if("point2"===this.Ax)s.point2Time=t,s.point2Price=i;else if("width"===this.Ax)s.channelWidth=i-this.SP(t);else{const n=Ar(this.Bx,t,i);s.point1Time=this.MP.DP.gt+n.gt,s.point1Price=this.MP.DP.bt+n.bt,s.point2Time=this.MP.IP.gt+n.gt,s.point2Price=this.MP.IP.bt+n.bt,s.channelWidth=this.MP.ts}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null}setColor(t){this.yP.lineColor=t,this.yP.fillColor=t,this.cM()}color(){return this.yP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}remove(){if(this.vP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Vx=null,this.yP.onRemove&&this.yP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Or(this.yP.point1Price??0,Wr(this.yP.point1Time)),Or(this.yP.point2Price??0,Wr(this.yP.point2Time))],style:{lineColor:this.yP.lineColor,lineWidth:this.yP.lineWidth,lineStyle:this.yP.lineStyle,fillColor:this.yP.fillColor,fillOpacity:this.yP.fillOpacity,extendRight:this.yP.extendRight},extra:{channelWidth:this.yP.channelWidth}}}}function fl(t,i){return new pl(t,i)}class vl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ml{constructor(t){this.Rx=t,this.Jt=new vl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class wl extends Nr{constructor(t,i){super(t,"pitchfork",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null,this.zx=!1,this._d=0,this.$x=null,this.XS=null,this.aP=null,this.RP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.RP),this.Zy(),this.RP.interactive?this.cP():this.zx=!0}Zy(){this.nr=new ml(this);const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Vx&&this.Vx()}_update(){this.cM()}cP(){this.XS=t=>{if(!t.point||jr(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.RP.pivotTime=s,this.RP.pivotPrice=i;else{if(1!==this._d)return this.RP.lowerTime=s,this.RP.lowerPrice=i,this._d++,void this.pP();this.RP.upperTime=s,this.RP.upperPrice=i}this._d++,this.cM()}},this.aP=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={gt:s,bt:i},this.cM())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aP)}pP(){this.zx=!0,this.$x=null,this.vP(),this.cM(),this.RP.onComplete&&this.RP.onComplete(),this.RP.onUpdate&&this.RP.onUpdate()}vP(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aP&&(this._chart.unsubscribeCrosshairMove(this.aP),this.aP=null)}VP(t,i){if(void 0===t||void 0===i)return null;const s=Xn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}FP(){const t=this.RP,i=this.VP(t.pivotTime,t.pivotPrice),s=this.VP(t.upperTime,t.upperPrice),n=this.zx?this.VP(t.lowerTime,t.lowerPrice):this.VP(t.lowerTime,t.lowerPrice)??(null!==this.$x&&this._d>=2?this.VP(this.$x.gt,this.$x.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 h=this._chart.chartElement().clientWidth,r=(e.ct-i.ct)/(e.ut-i.ut),l=t=>({ut:h,ct:t.ct+r*(h-t.ut)});return{Ry:i,EP:e,uy:s,vy:n,LP:l(i),AP:l(s),BP:l(n)}}drawToCanvas(t,i,s){const n=this.FP();if(null===n)return void this.WP(t,i,s);const e=this.RP,h=e.lineColor,r=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Py(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.uy.ut*r,n.uy.ct*l),t.lineTo(n.AP.ut*r,n.AP.ct*l),t.lineTo(n.BP.ut*r,n.BP.ct*l),t.lineTo(n.vy.ut*r,n.vy.ct*l),t.closePath(),t.fill()),t.strokeStyle=h,t.lineWidth=(this.Fx?e.lineWidth+1:e.lineWidth)*r,"dashed"===e.lineStyle?t.setLineDash([10*r,5*r]):"dotted"===e.lineStyle&&t.setLineDash([2*r,3*r]),t.beginPath(),t.moveTo(n.uy.ut*r,n.uy.ct*l),t.lineTo(n.vy.ut*r,n.vy.ct*l),t.moveTo(n.Ry.ut*r,n.Ry.ct*l),t.lineTo(n.LP.ut*r,n.LP.ct*l),t.moveTo(n.uy.ut*r,n.uy.ct*l),t.lineTo(n.AP.ut*r,n.AP.ct*l),t.moveTo(n.vy.ut*r,n.vy.ct*l),t.lineTo(n.BP.ut*r,n.BP.ct*l),t.stroke(),t.setLineDash([]);if((this.Fx||this.Ex||!this.zx)&&!this.isLocked())for(const i of[n.Ry,n.uy,n.vy])this.bP(t,i.ut*r,i.ct*l,r,h)}WP(t,i,s){const n=this.RP,e=this.VP(n.pivotTime,n.pivotPrice);if(null===e)return;const h=this.VP(n.upperTime,n.upperPrice)??(null!==this.$x?this.VP(this.$x.gt,this.$x.bt):null),r=n.lineColor;t.strokeStyle=r,t.lineWidth=n.lineWidth*i,t.setLineDash([6*i,4*i]),null!==h&&(t.beginPath(),t.moveTo(e.ut*i,e.ct*s),t.lineTo(h.ut*i,h.ct*s),t.stroke()),t.setLineDash([]),this.bP(t,e.ut*i,e.ct*s,i,r)}bP(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()}Py(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}kP(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*r+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*r),i-(n+a*l))}hitTest(t,i){const s=this.FP();if(null===s)return!1;return[[s.Ry,s.LP],[s.uy,s.AP],[s.vy,s.BP],[s.uy,s.vy]].some(([s,n])=>this.kP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.FP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.Ry)?"pivot":n(s.uy)?"upper":n(s.vy)?"lower":null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,this.MP=[{gt:this.RP.pivotTime,bt:this.RP.pivotPrice},{gt:this.RP.upperTime,bt:this.RP.upperPrice},{gt:this.RP.lowerTime,bt:this.RP.lowerPrice}]}updateDrag(t,i){if(!this.Lx||null===this.Ax||null===this.MP)return;const s=this.RP;if("pivot"===this.Ax)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.Ax)s.upperTime=t,s.upperPrice=i;else if("lower"===this.Ax)s.lowerTime=t,s.lowerPrice=i;else{const n=Ar(this.Bx,t,i),[e,h,r]=this.MP;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=h.gt+n.gt,s.upperPrice=h.bt+n.bt,s.lowerTime=r.gt+n.gt,s.lowerPrice=r.bt+n.bt}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null}setColor(t){this.RP.lineColor=t,this.RP.fillColor=t,this.cM()}color(){return this.RP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}remove(){if(this.vP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Vx=null,this.RP.onRemove&&this.RP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Or(this.RP.pivotPrice??0,Wr(this.RP.pivotTime)),Or(this.RP.upperPrice??0,Wr(this.RP.upperTime)),Or(this.RP.lowerPrice??0,Wr(this.RP.lowerTime))],style:{lineColor:this.RP.lineColor,lineWidth:this.RP.lineWidth,lineStyle:this.RP.lineStyle,fillColor:this.RP.fillColor,fillOpacity:this.RP.fillOpacity}}}}function gl(t,i){return new wl(t,i)}class bl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ml{constructor(t){this.Rx=t,this.Jt=new bl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class yl extends Nr{constructor(t,i){super(t,"vertical-line",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Bx=null,this.hP=0,this.OP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.OP),this.Zy()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Ml(this)}drawToCanvas(t,i,s){if(void 0===this.OP.time)return;const n=(Xn(this._chart,this._series,this.OP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,h=this.OP.lineColor,r=this.Fx||this.Ex&&!this.isLocked()?this.OP.lineWidth+1:this.OP.lineWidth;t.strokeStyle=h,t.lineWidth=r*i,"dashed"===this.OP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.OP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.OP.showLabel&&(this.Fx||this.Ex)&&this.OP.labelText&&this.eP(t,n,i,s,h)}eP(t,i,s,n,e){const h=this.OP.labelText,r=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(h).width,a=l,_=i-o/2-r,u=10*n;t.fillStyle=e,t.fillRect(_,u,o+2*r,a+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(h,_+r,u+r)}setColor(t){this.OP.lineColor=t,this.cM()}color(){return this.OP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.OP.time)return!1;const s=Xn(this._chart,this._series,this.OP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.Lx=!0,this.Bx=i,this.hP=this.OP.time}stopDrag(){this.Lx=!1,this.Bx=null}updateDrag(t,i){this.Lx&&(this.OP.time=this.hP+Ar(this.Bx,t,i).gt,this.cM(),this.OP.onUpdate&&this.OP.onUpdate())}getTime(){return this.OP.time}setTime(t){this.OP.time=t,this.cM()}setLabel(t){this.OP.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Or(0,Wr(this.OP.time))],style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,lineStyle:this.OP.lineStyle,showLabel:this.OP.showLabel,labelText:this.OP.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.OP.onRemove&&this.OP.onRemove()}}function Sl(t,i){return new yl(t,i)}const xl=[{zP:0,Zl:"0.0%"},{zP:.236,Zl:"23.6%"},{zP:.382,Zl:"38.2%"},{zP:.5,Zl:"50.0%"},{zP:.618,Zl:"61.8%"},{zP:.786,Zl:"78.6%"},{zP:1,Zl:"100.0%"}],Pl=[...xl,{zP:1.272,Zl:"127.2%"},{zP:1.414,Zl:"141.4%"},{zP:1.618,Zl:"161.8%"},{zP:2,Zl:"200.0%"},{zP:2.618,Zl:"261.8%"}];class Cl{constructor(t=!1){this.$P=t?Pl:xl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),h=e/i*100,r=n>i,l=this.$P.map(({zP:t,Zl:i})=>{let s;return s=r?n-e*t:n+e*t,{zP:t,bt:s,Zl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:h,levels:l,isUptrend:r}}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.$P=t}getRatios(){return[...this.$P]}getRatioValues(){return this.$P.map(t=>t.zP)}useStandardRatios(){this.$P=xl}useExtendedRatios(){this.$P=Pl}}class Tl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.Rx=t,this.Jt=new Tl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}}function Dl(t){return{zP:t,Zl:`${(100*t).toFixed(1)}%`}}class Il extends Nr{constructor(t,i){super(t,"fibonacci-tool",i),this.Ub=null,this.Vx=null,this.Yb=null,this.nr=null,this.HP=null,this.zx=!1,this.Fx=!1,this.Ex=!1,this.$x=null,this.Lx=!1,this.NP=null,this.sp=null,this.UP={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.UP),this.qP=new Cl(this.UP.useExtended),void 0!==this.UP.levels&&this.UP.levels.length>0&&this.qP.updateRatios(this.UP.levels.map(Dl)),this.Zy(),this.UP.interactive?this.Nx():(this.zx=!0,this.jP())}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new kl(this)}drawToCanvas(t,i,s){if(!this.zx&&this.UP.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.Yb||!this.UP.point1Time||!this.UP.point2Time)return;const n=(Xn(this._chart,this._series,this.UP.point1Time)??0)*i,e=(Xn(this._chart,this._series,this.UP.point2Time)??0)*i,h=Math.min(n,e),r=Math.max(n,e),l=this.Fx?2:this.UP.lineWidth;this.Yb.levels.forEach(n=>{this.YP(t,n,h,r,i,s,l)}),!this.Fx&&!this.Ex||this.isLocked()||(this.Qx(t,n,(this._series.priceToCoordinate(this.UP.point1Price)??0)*s,i),this.Qx(t,e,(this._series.priceToCoordinate(this.UP.point2Price)??0)*s,i))}YP(t,i,s,n,e,h,r=1){const l=i.ratio??i.zP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*h;let _=this.UP.levelColors?.[l.toString()]||this.UP.lineColor;t.strokeStyle=_,t.lineWidth=r*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.UP.showLabels&&this.eP(t,i,s,n,a,e,_)}eP(t,i,s,n,e,h,r){const l=i.label??i.Zl,o=i.price??i.bt,a=`${l} ${this.qP.formatPrice(o)}`;t.font=11*h+"px sans-serif";const _=t.measureText(a),u=4*h,c="right"===this.UP.labelPosition?n+u:s-_.width-u,d=e;t.fillStyle="rgba(255, 255, 255, 0.9)",t.fillRect(c-u/2,d-11*h/2-u/2,_.width+u,11*h+u),t.fillStyle=r,t.textAlign="right"===this.UP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}jP(){this.UP.point1Time&&this.UP.point1Price&&this.UP.point2Time&&this.UP.point2Price&&(this.Yb=this.qP.calculateLevels(this.UP.point1Time,this.UP.point1Price,this.UP.point2Time,this.UP.point2Price),this.UP.onUpdate&&this.Yb&&this.UP.onUpdate(this.Yb))}updatePoints(t,i,s,n){this.UP.point1Time=t,this.UP.point1Price=i,this.UP.point2Time=s,this.UP.point2Price=n,this.jP(),this.cM()}getMetrics(){return this.Yb}getLevels(){return this.Yb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.qP.getRatioValues();return{type:"fibRetracement",points:[Or(this.UP.point1Price??0,Wr(this.UP.point1Time)),Or(this.UP.point2Price??0,Wr(this.UP.point2Time))],style:{lineColor:this.UP.lineColor,lineWidth:this.UP.lineWidth,showLabels:this.UP.showLabels,labelPosition:this.UP.labelPosition,levelColors:this.UP.levelColors},extra:{levels:t,useExtended:this.UP.useExtended}}}useExtendedLevels(t){this.UP.useExtended=t,t?this.qP.useExtendedRatios():this.qP.useStandardRatios(),this.jP(),this.cM()}Nx(){this.HP=new Gr(this._chart,this._series,{Tx:t=>{this.UP.point1Time=t.gt,this.UP.point1Price=t.bt,this.cM()},kx:t=>{this.UP.point2Time=t.gt,this.UP.point2Price=t.bt},Dx:(t,i)=>{this.UP.point1Time=t.gt,this.UP.point1Price=t.bt,this.UP.point2Time=i.gt,this.UP.point2Price=i.bt,this.zx=!0,this.$x=null,this.jP(),this.KP(),this.cM()},Ix:t=>{this.$x=t,this.cM()}}),this.HP.vx()}Jx(t,i,s){if(!this.UP.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.UP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.UP.point1Price)??0)*s,h=(Xn(this._chart,this._series,this.$x.gt)??0)*i,r=(this._series.priceToCoordinate(this.$x.bt)??0)*s,l=this.qP.calculateLevels(this.UP.point1Time,this.UP.point1Price,this.$x.gt,this.$x.bt),o=Math.min(n,h),a=Math.max(n,h);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.zP,h=n.price??n.bt;if(void 0===e||void 0===h)return;const r=(this._series.priceToCoordinate(h)??0)*s,l=this.UP.levelColors?.[e.toString()]||this.UP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.UP.lineWidth*i,t.beginPath(),t.moveTo(o,r),t.lineTo(a,r),t.stroke(),this.UP.showLabels){const s=`${n.label??n.Zl} ${this.qP.formatPrice(h)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.UP.labelPosition?a+_:o-e.width-_,c=r;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.UP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.Qx(t,n,e,i),t.globalAlpha=.6,this.Qx(t,h,r,i),t.globalAlpha=1}Qx(t,i,s,n){const e=this.UP.lineColor,h=this.Fx?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,h,0,2*Math.PI),t.fill(),this.Fx&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}KP(){this.sp=t=>{this.GP(t)},this._chart.subscribeCrosshairMove(this.sp)}XP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}GP(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.Fx||!this.Lx)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.NP?(this.UP.point1Time=i,this.UP.point1Price=s):"point2"===this.NP&&(this.UP.point2Time=i,this.UP.point2Price=s),this.jP(),this.cM())}startDrag(t){this.Lx=!0,this.NP=t}stopDrag(){this.Lx=!1,this.NP=null}updateDrag(t,i){this.Lx&&this.NP&&("point1"===this.NP?(this.UP.point1Time=t,this.UP.point1Price=i):(this.UP.point2Time=t,this.UP.point2Price=i),this.jP(),this.cM())}hitTestEndpoint(t,i){if(!this.zx||!this.UP.point1Time||!this.UP.point2Time)return null;const s=Xn(this._chart,this._series,this.UP.point1Time)??0,n=this._series.priceToCoordinate(this.UP.point1Price)??0,e=Xn(this._chart,this._series,this.UP.point2Time)??0,h=this._series.priceToCoordinate(this.UP.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-h,2))<=10?"point2":null}applyOptions(t){this.UP={...this.UP,...t},void 0!==t.levels&&t.levels.length>0?this.qP.updateRatios(t.levels.map(Dl)):void 0!==t.useExtended&&(t.useExtended?this.qP.useExtendedRatios():this.qP.useStandardRatios()),super.applyOptions(t),this.jP(),this.cM()}options(){return{...this.UP,levels:this.qP.getRatioValues()}}setColor(t){this.UP.lineColor=t,this.cM()}color(){return this.UP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}isSelected(){return this.Fx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.zx||!this.UP.point1Time||!this.UP.point2Time)return!1;const s=Xn(this._chart,this._series,this.UP.point1Time)??0,n=Xn(this._chart,this._series,this.UP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Yb)return!1;for(const t of this.Yb.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}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.HP&&(this.HP.m(),this.HP=null),this.XP(),this.UP.onRemove&&this.UP.onRemove()}destroy(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.UP.onRemove&&this.UP.onRemove()}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.jP(),this.cM()}}function Rl(t,i){return new Il(t,i)}class Vl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Fl{constructor(t){this.Rx=t,this.Jt=new Vl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}}class El extends Nr{constructor(t,i){super(t,"fibonacci-extension",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.UP={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.Zy()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Fl(this)}getPoint1(){return this.UP.point1}getPoint2(){return this.UP.point2}getPoint3(){return this.UP.point3}getLevels(){return this.UP.levels||[]}getOptions(){return this.UP}setPoint1(t){this.UP.point1=t,this.cM()}setPoint2(t){this.UP.point2=t,this.cM()}setPoint3(t){this.UP.point3=t,this.cM()}isComplete(){return!!(this.UP.point1&&this.UP.point2&&this.UP.point3)}setColor(t){this.UP.lineColor=t,this.cM()}color(){return this.UP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.UP.point1,this.UP.point2,this.UP.point3];for(const n of s){const s=Xn(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.ZP();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.UP.point1,n=this.UP.point2,e=this.UP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Xn(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=Xn(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=Xn(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.Lx=!0,this.Ax=t}stopDrag(){this.Lx=!1,this.Ax=null}updateDrag(t,i){if(!this.Lx||!this.Ax)return;const s={time:t,price:i};switch(this.Ax){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.UP.onUpdate&&this.UP.onUpdate()}ZP(){if(!this.isComplete())return[];const t=this.UP.point1,i=this.UP.point2,s=this.UP.point3,n=i.price-t.price;return(this.UP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Zl:t.label,I:t.color}))}getExtensionLevels(){return this.ZP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.UP.point1,e=this.UP.point2,h=this.UP.point3,r=this.Fx||this.Ex&&!this.isLocked(),l=(Xn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Xn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Xn(this._chart,this._series,h.time)??0)*i,c=(this._series.priceToCoordinate(h.price)??0)*s;t.strokeStyle=this.UP.lineColor||"#787B86",t.lineWidth=(this.UP.lineWidth||1)*i*(r?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,h=n.I??n.color,l=n.Zl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=h,t.lineWidth=(this.UP.lineWidth||1)*i*(r?1.5:1),t.beginPath(),this.UP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.UP.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=h,t.textAlign="left",t.textBaseline="middle";const n=5*i,r=Math.max(u,10*i)+n;t.fillText(s,r,o)}}const f=(r?6:4)*i,v=[{ut:l,ct:o,Zl:"A"},{ut:a,ct:_,Zl:"B"},{ut:u,ct:c,Zl:"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(),r&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Zl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[zr(this.UP.point1),zr(this.UP.point2),zr(this.UP.point3)],style:{lineColor:this.UP.lineColor,lineWidth:this.UP.lineWidth,showLabels:this.UP.showLabels,extendLines:this.UP.extendLines},extra:{levels:(this.UP.levels||[]).map(t=>({sn:t.level,I:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}}}function Ll(t,i){return new El(t,i)}class Al{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Bl{constructor(t){this.Rx=t,this.Jt=new Al(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const Wl=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Ol extends Nr{constructor(t,i){super(t,"fibonacci-fan",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.JP=!1,this.XS=null,this.sp=null,this.$x=null,this.QP={levels:Wl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.Zy(),this.QP.interactive&&!this.QP.point1Time&&this.Nx()}Nx(){this.JP=!0,this.XS=t=>{if(!t.point)return;if(jr(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.QP.point1Time?(this.QP.point2Time=i,this.QP.point2Price=s,this.JP=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.QP.onUpdate&&this.QP.onUpdate()):(this.QP.point1Time=i,this.QP.point1Price=s,this.cM()))},this.sp=t=>{if(this.JP&&this.QP.point1Time)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Bl(this)}drawToCanvas(t,i,s){const n=this.QP.point1Time,e=this.QP.point1Price,h=this.JP&&this.$x?this.$x.gt:this.QP.point2Time,r=this.JP&&this.$x?this.$x.bt:this.QP.point2Price;if(!n||void 0===e||!h||void 0===r)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,h)??0)*i,_=(this._series.priceToCoordinate(r)??0)*s,u=this.Fx?this.QP.lineWidth+1:this.QP.lineWidth;if(this.tC(t,l,o,a,_,"#2962FF",u*i),this.QP.levels)for(const n of this.QP.levels)this.iC(t,l,o,a,_,n,i,s,undefined,u);!this.Fx&&!this.Ex||this.JP||this.isLocked()||(this.Qx(t,l,o,i,"#2962ff"),this.Qx(t,a,_,i,"#2962ff"))}iC(t,i,s,n,e,h,r,l,o,a){const _=n,u=s+(e-s)*h.level;let c=_,d=u;if(this.QP.extendLines){const t=this._chart.chartElement().clientWidth*r,n=_-i,e=u-s,h=Math.sqrt(n*n+e*e);if(h>0){const r=2*t;c=i+n/h*r,d=s+e/h*r}}const p=o||h.color;this.tC(t,i,s,c,d,p,a*r),this.QP.showLabels&&!this.JP&&this.eP(t,_,u,h.label,r,p)}tC(t,i,s,n,e,h,r){t.strokeStyle=h,t.lineWidth=r,t.beginPath(),t.moveTo(i,s),t.lineTo(n,e),t.stroke()}Qx(t,i,s,n,e){const h=5*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,h,0,2*Math.PI),t.fill(),t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke()}eP(t,i,s,n,e,h){const r=11*e,l=4*e;t.font=`${r}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(n).width,a=r;t.fillStyle=h,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.QP.levels??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.QP.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.QP.point1Time||!this.QP.point2Time)return!1;const s=Xn(this._chart,this._series,this.QP.point1Time)??0,n=this._series.priceToCoordinate(this.QP.point1Price)??0,e=Xn(this._chart,this._series,this.QP.point2Time)??0,h=this._series.priceToCoordinate(this.QP.point2Price)??0;if(this.tP(t,i,s,n,e,h)<=8)return!0;if(this.QP.levels)for(const r of this.QP.levels){const l=n+(h-n)*r.level,o=e;if(this.tP(t,i,s,n,o,l)<=8)return!0}return!1}tP(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*r+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*r,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.QP.point1Time||!this.QP.point2Time)return null;const s=Xn(this._chart,this._series,this.QP.point1Time)??0,n=this._series.priceToCoordinate(this.QP.point1Price)??0,e=Xn(this._chart,this._series,this.QP.point2Time)??0,h=this._series.priceToCoordinate(this.QP.point2Price)??0;return Math.abs(t-s)<=10&&Math.abs(i-n)<=10?"point1":Math.abs(t-e)<=10&&Math.abs(i-h)<=10?"point2":null}startDrag(t){this.Lx=!0,this.Ax=t}stopDrag(){this.Lx=!1,this.Ax=null}updateDrag(t,i){this.Lx&&this.Ax&&("point1"===this.Ax?(this.QP.point1Time=t,this.QP.point1Price=i):"point2"===this.Ax&&(this.QP.point2Time=t,this.QP.point2Price=i),this.cM(),this.QP.onUpdate&&this.QP.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Or(this.QP.point1Price??0,Wr(this.QP.point1Time)),Or(this.QP.point2Price??0,Wr(this.QP.point2Time))],style:{lineWidth:this.QP.lineWidth,showLabels:this.QP.showLabels,extendLines:this.QP.extendLines},extra:{levels:(this.QP.levels||[]).map(t=>({sn:t.level,I:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.QP.onRemove&&this.QP.onRemove()}}function zl(t,i){return new Ol(t,i)}class $l{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Hl{constructor(t){this.Rx=t,this.Jt=new $l(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Nl extends Nr{constructor(t,i){super(t,"rectangle",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.Wx=null,this.Ox=null,this.JP=!1,this.XS=null,this.sp=null,this.$x=null,this.sC={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.sC),this.Zy(),!this.sC.interactive||this.sC.time1&&this.sC.time2||this.Nx()}Nx(){this.JP=!0,this.XS=t=>{if(!t.point)return;if(jr(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.sC.time1?(this.sC.time2=i,this.sC.price2=s,this.JP=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.sC.onUpdate&&this.sC.onUpdate()):(this.sC.time1=i,this.sC.price1=s,this.cM()))},this.sp=t=>{if(this.JP&&this.sC.time1)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Hl(this)}drawToCanvas(t,i,s){const n=this.sC.time1,e=this.sC.price1,h=this.JP&&this.$x?this.$x.gt:this.sC.time2,r=this.JP&&this.$x?this.$x.bt:this.sC.price2;if(!n||void 0===e||!h||void 0===r)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,h)??0)*i,_=(this._series.priceToCoordinate(r)??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.sC.fillOpacity>0){const i=this.Gy(this.sC.fillColor,this.JP?.1:this.sC.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.sC.borderColor,w=this.Fx?this.sC.borderWidth+1:this.sC.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.sC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.sC.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.Fx&&!this.Ex||this.JP||this.isLocked()||this.nC(t,u,d,c,p,i,m),this.sC.showLabel&&this.sC.labelText&&!this.JP&&this.eP(t,u,d,c,p,i,s,m)}nC(t,i,s,n,e,h,r){const l=8*h,o=[{ut:i,ct:s},{ut:n,ct:s},{ut:i,ct:e},{ut:n,ct:e}];t.fillStyle=r,t.strokeStyle="#ffffff",t.lineWidth=2*h;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)}eP(t,i,s,n,e,h,r,l){const o=6*h,a=12*h;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.sC.labelText).width,u=a;let c=i+o,d=s+o;switch(this.sC.labelPosition){case"top-right":c=n-_-2*o,d=s+o;break;case"bottom-left":c=i+o,d=e-u-2*o;break;case"bottom-right":c=n-_-2*o,d=e-u-2*o;break;case"center":c=(i+n)/2-_/2-o,d=(s+e)/2-u/2-o}t.fillStyle=l,t.fillRect(c,d,_+2*o,u+2*o),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.sC.labelText,c+o,d+o)}Gy(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.sC.borderColor=t,this.sC.fillColor=t,this.cM()}color(){return this.sC.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.sC.time1||!this.sC.time2)return!1;const s=Xn(this._chart,this._series,this.sC.time1)??0,n=this._series.priceToCoordinate(this.sC.price1)??0,e=Xn(this._chart,this._series,this.sC.time2)??0,h=this._series.priceToCoordinate(this.sC.price2)??0,r=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,h),a=Math.max(n,h);return t>=r&&t<=l&&i>=o&&i<=a}hitTestEndpoint(t,i){if(!this.sC.time1||!this.sC.time2)return null;const s=Xn(this._chart,this._series,this.sC.time1)??0,n=this._series.priceToCoordinate(this.sC.price1)??0,e=Xn(this._chart,this._series,this.sC.time2)??0,h=this._series.priceToCoordinate(this.sC.price2)??0,r=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,h),a=Math.max(n,h),_=10;return Math.abs(t-r)<=_&&Math.abs(i-o)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner2":Math.abs(t-r)<=_&&Math.abs(i-a)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner4":t>=r&&t<=l&&i>=o&&i<=a?"body":null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,"body"===t&&(this.Wx={gt:this.sC.time1,bt:this.sC.price1},this.Ox={gt:this.sC.time2,bt:this.sC.price2})}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.Wx=null,this.Ox=null}updateDrag(t,i){if(!this.Lx||!this.Ax)return;const s=Xn(this._chart,this._series,this.sC.time1)??0,n=this._series.priceToCoordinate(this.sC.price1)??0,e=s<(Xn(this._chart,this._series,this.sC.time2)??0),h=n<(this._series.priceToCoordinate(this.sC.price2)??0);if("body"===this.Ax&&this.Wx&&this.Ox){const s=Ar(this.Bx,t,i);this.sC.time1=this.Wx.gt+s.gt,this.sC.price1=this.Wx.bt+s.bt,this.sC.time2=this.Ox.gt+s.gt,this.sC.price2=this.Ox.bt+s.bt}else switch(this.Ax){case"corner1":e&&h?(this.sC.time1=t,this.sC.price1=i):!e&&h?(this.sC.time2=t,this.sC.price1=i):e&&!h?(this.sC.time1=t,this.sC.price2=i):(this.sC.time2=t,this.sC.price2=i);break;case"corner2":e&&h?(this.sC.time2=t,this.sC.price1=i):!e&&h?(this.sC.time1=t,this.sC.price1=i):e&&!h?(this.sC.time2=t,this.sC.price2=i):(this.sC.time1=t,this.sC.price2=i);break;case"corner3":e&&h?(this.sC.time1=t,this.sC.price2=i):!e&&h?(this.sC.time2=t,this.sC.price2=i):e&&!h?(this.sC.time1=t,this.sC.price1=i):(this.sC.time2=t,this.sC.price1=i);break;case"corner4":e&&h?(this.sC.time2=t,this.sC.price2=i):!e&&h?(this.sC.time1=t,this.sC.price2=i):e&&!h?(this.sC.time2=t,this.sC.price1=i):(this.sC.time1=t,this.sC.price1=i)}this.cM(),this.sC.onUpdate&&this.sC.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Or(this.sC.price1??0,Wr(this.sC.time1)),Or(this.sC.price2??0,Wr(this.sC.time2))],style:{fillColor:this.sC.fillColor,fillOpacity:this.sC.fillOpacity,borderColor:this.sC.borderColor,borderWidth:this.sC.borderWidth,borderStyle:this.sC.borderStyle,showLabel:this.sC.showLabel,labelText:this.sC.labelText,labelPosition:this.sC.labelPosition}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.sC.onRemove&&this.sC.onRemove()}}function Ul(t,i){return new Nl(t,i)}class ql{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class jl{constructor(t){this.Rx=t,this.Jt=new ql(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Yl extends Nr{constructor(t,i){super(t,"circle",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null,this.JP=!1,this.XS=null,this.sp=null,this.$x=null,this.eC={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.eC),this.Zy(),this.eC.interactive&&!this.eC.centerTime&&this.Nx()}Nx(){this.JP=!0,this.XS=t=>{if(!t.point)return;if(jr(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.eC.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.eC.centerTime)??0,n=this._series.priceToCoordinate(this.eC.centerPrice)??0,e=Xn(this._chart,this._series,i)??0,h=this._series.priceToCoordinate(s)??0;this.eC.radiusTime=Math.abs(e-t),this.eC.radiusPrice=Math.abs(h-n),this.JP=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.eC.onUpdate&&this.eC.onUpdate()}else this.eC.centerTime=i,this.eC.centerPrice=s,this.cM()},this.sp=t=>{if(this.JP&&this.eC.centerTime)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new jl(this)}drawToCanvas(t,i,s){if(!this.eC.centerTime||void 0===this.eC.centerPrice)return;const n=(Xn(this._chart,this._series,this.eC.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.eC.centerPrice)??0)*s;let h,r;if(this.JP&&this.$x){const t=(Xn(this._chart,this._series,this.$x.gt)??0)*i,l=(this._series.priceToCoordinate(this.$x.bt)??0)*s;h=Math.abs(t-n),r=Math.abs(l-e)}else{if(void 0===this.eC.radiusTime||void 0===this.eC.radiusPrice)return;h=this.eC.radiusTime*i,r=this.eC.radiusPrice*s}if(this.eC.fillOpacity>0){const i=this.Gy(this.eC.fillColor,this.JP?.05:this.eC.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,h,r,0,0,2*Math.PI),t.fill()}const l=this.eC.borderColor,o=this.Fx?this.eC.borderWidth+1:this.eC.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.eC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.eC.borderStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.ellipse(n,e,h,r,0,0,2*Math.PI),t.stroke(),t.setLineDash([]),!this.Fx&&!this.Ex||this.JP||this.isLocked()||this.hC(t,n,e,i,l),!this.Fx&&!this.Ex||this.JP||this.isLocked()||this.rC(t,n,e,h,r,i,l),this.eC.showLabel&&this.eC.labelText&&!this.JP&&this.eP(t,n,e,i,l)}hC(t,i,s,n,e){const h=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,h/2,0,2*Math.PI),t.fill(),t.stroke()}rC(t,i,s,n,e,h,r){const l=8*h,o=[{ut:i,ct:s-e},{ut:i+n,ct:s},{ut:i,ct:s+e},{ut:i-n,ct:s}];t.fillStyle=r,t.strokeStyle="#ffffff",t.lineWidth=2*h;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)}eP(t,i,s,n,e){const h=6*n,r=12*n;t.font=`${r}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const l=t.measureText(this.eC.labelText).width,o=r,a=i-l/2-h,_=s-o/2-h;t.fillStyle=e,t.fillRect(a,_,l+2*h,o+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.eC.labelText,a+h,_+h)}Gy(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.eC.borderColor=t,this.eC.fillColor=t,this.cM()}color(){return this.eC.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.eC.centerTime||void 0===this.eC.radiusTime)return!1;const s=Xn(this._chart,this._series,this.eC.centerTime)??0,n=this._series.priceToCoordinate(this.eC.centerPrice)??0,e=(t-s)/this.eC.radiusTime,h=(i-n)/this.eC.radiusPrice;return e*e+h*h<=1}hitTestEndpoint(t,i){if(!this.eC.centerTime||void 0===this.eC.radiusTime)return null;const s=Xn(this._chart,this._series,this.eC.centerTime)??0,n=this._series.priceToCoordinate(this.eC.centerPrice)??0,e=this.eC.radiusTime,h=this.eC.radiusPrice;if(Math.abs(t-s)<=10&&Math.abs(i-n)<=10)return"center";const r=[{ut:s,ct:n-h},{ut:s+e,ct:n},{ut:s,ct:n+h},{ut:s-e,ct:n}];for(const s of r)if(Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10)return"edge";return null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,this.MP="center"===t?{gt:this.eC.centerTime,bt:this.eC.centerPrice}:null}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null}updateDrag(t,i){if(this.Lx&&this.Ax){if("center"===this.Ax&&this.MP){const s=Ar(this.Bx,t,i);this.eC.centerTime=this.MP.gt+s.gt,this.eC.centerPrice=this.MP.bt+s.bt}else if("edge"===this.Ax){const s=Xn(this._chart,this._series,this.eC.centerTime)??0,n=this._series.priceToCoordinate(this.eC.centerPrice)??0,e=Xn(this._chart,this._series,t)??0,h=this._series.priceToCoordinate(i)??0;this.eC.radiusTime=Math.abs(e-s),this.eC.radiusPrice=Math.abs(h-n)}this.cM(),this.eC.onUpdate&&this.eC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Or(this.eC.centerPrice??0,Wr(this.eC.centerTime))],style:{fillColor:this.eC.fillColor,fillOpacity:this.eC.fillOpacity,borderColor:this.eC.borderColor,borderWidth:this.eC.borderWidth,borderStyle:this.eC.borderStyle,showLabel:this.eC.showLabel,labelText:this.eC.labelText},extra:{radiusTime:this.eC.radiusTime,radiusPrice:this.eC.radiusPrice}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.eC.onRemove&&this.eC.onRemove()}}function Kl(t,i){return new Yl(t,i)}class Gl{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xl{constructor(t){this.Rx=t,this.Jt=new Gl(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Zl extends Nr{constructor(t,i){super(t,"arrow",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.lC=-1,this.JP=!1,this.XS=null,this.oC=null,this.sp=null,this.$x=null,this.aC={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.aC),this.Zy(),!this.aC.interactive||this.aC.points&&0!==this.aC.points.length||this.Nx()}Nx(){this.JP=!0,this.XS=t=>{if(!t.point)return;if(jr(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.aC.points||(this.aC.points=[]),this.aC.points.push({time:i,price:s}),this.cM(),this.aC.onUpdate&&this.aC.onUpdate())},this.sp=t=>{if(this.JP)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this.oC=t=>{this.JP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.oC)}finishDrawing(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.oC){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.oC),this.oC=null}this.JP=!1,this.$x=null,this.cM(),this.aC.onComplete&&this.aC.onComplete()}isDrawing(){return this.JP}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Xl(this)}drawToCanvas(t,i,s){if(!this.aC.points||0===this.aC.points.length)return;const n=this.aC.lineColor,e=this.Fx||this.Ex&&!this.isLocked()?this.aC.lineWidth+1:this.aC.lineWidth,h=[];for(const t of this.aC.points)try{let n=Xn(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;h.push({ut:n*i,ct:e*s})}catch{continue}if(0===h.length&&!this.JP)return;let r=null;if(this.JP&&this.$x&&this.aC.points.length>0){r={ut:(Xn(this._chart,this._series,this.$x.gt)??0)*i,ct:(this._series.priceToCoordinate(this.$x.bt)??0)*s}}if(h.length>1){t.strokeStyle=n,t.lineWidth=e*i,t.beginPath(),t.moveTo(h[0].ut,h[0].ct);for(let i=1;i<h.length;i++)t.lineTo(h[i].ut,h[i].ct);t.stroke()}if(r&&h.length>0){const s=h[h.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(r.ut,r.ct),t.stroke(),t.setLineDash([]),t.globalAlpha=1}if(this.aC.showArrowHead&&h.length>1&&this._C(t,h[h.length-2],h[h.length-1],i,n),this.aC.showCircles)for(let s=0;s<h.length;s++)this.uC(t,h[s].ut,h[s].ct,i,n,0===s)}_C(t,i,s,n,e){const h=12*n,r=Math.atan2(s.ct-i.ct,s.ut-i.ut),l={ut:s.ut-h*Math.cos(r-Math.PI/6),ct:s.ct-h*Math.sin(r-Math.PI/6)},o={ut:s.ut-h*Math.cos(r+Math.PI/6),ct:s.ct-h*Math.sin(r+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()}uC(t,i,s,n,e,h){const r=this.aC.circleRadius*n;t.beginPath(),t.arc(i,s,r,0,2*Math.PI),h?(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.aC.lineColor=t,this.cM()}color(){return this.aC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.aC.points||0===this.aC.points.length)return!1;for(let s=0;s<this.aC.points.length-1;s++)try{const n=this.aC.points[s],e=this.aC.points[s+1];let h=Xn(this._chart,this._series,n.time);if(null===h){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(h=t.logicalToCoordinate(i))}let r=Xn(this._chart,this._series,e.time);if(null===r){const t=this._chart.timeScale(),i=t.timeToIndex(e.time,!0);null!=i&&(r=t.logicalToCoordinate(i))}const l=this._series.priceToCoordinate(n.price),o=this._series.priceToCoordinate(e.price);if(null==h||null===l||null==r||null===o)continue;if(this.tP(t,i,h,l,r,o)<=8)return!0}catch{continue}for(const s of this.aC.points)try{let n=Xn(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}tP(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*r+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*r,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.aC.points||0===this.aC.points.length)return null;for(let s=0;s<this.aC.points.length;s++)try{const n=this.aC.points[s];let e=Xn(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 h=this._series.priceToCoordinate(n.price);if(null==e||null===h)continue;if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-h,2))<=10)return s}catch{continue}return null}startDrag(t){this.Lx=!0,this.lC=t}stopDrag(){this.Lx=!1,this.lC=-1}updateDrag(t,i){this.Lx&&-1!==this.lC&&this.aC.points&&this.lC>=0&&this.lC<this.aC.points.length&&(this.aC.points[this.lC]={time:t,price:i},this.cM(),this.aC.onUpdate&&this.aC.onUpdate())}getPoints(){return this.aC.points||[]}addPoint(t){this.aC.points||(this.aC.points=[]),this.aC.points.push(t),this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.aC.points||[]).map(t=>zr(t)),style:{lineColor:this.aC.lineColor,lineWidth:this.aC.lineWidth,showArrowHead:this.aC.showArrowHead,showCircles:this.aC.showCircles,circleRadius:this.aC.circleRadius}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.oC){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.oC),this.oC=null}if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.aC.onRemove&&this.aC.onRemove()}}function Jl(t,i){return new Zl(t,i)}class Ql{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class to{constructor(t){this.Rx=t,this.Jt=new Ql(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class io extends Nr{constructor(t,i){super(t,"brush",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.cC=!1,this.JP=!1,this.dC=[],this.pC=!1,this.kf=null,this.bS=null,this.CS=null,this.kS=null,this.IS=null,this.fC=void 0,this.xS=null,this.Lx=!1,this.Bx=null,this.oP=null,this.vC={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.vC),this.Zy(),0===(this.vC.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.cC)return;const t=this._chart.chartElement();t&&(this.kf=t,this.cC=!0,this.CS=t=>this.TS(t),this.kS=t=>this.DS(t),this.IS=()=>this.RS(),this.xS=t=>{this.fC=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.xS),t.addEventListener("pointerdown",this.CS,!0),t.addEventListener("pointermove",this.kS,!0),t.addEventListener("pointerup",this.IS,!0),t.addEventListener("pointercancel",this.IS,!0))}stopDrawingMode(){if(!this.cC)return;this.mC(),this.cC=!1;const t=this.kf;t&&(this.CS&&t.removeEventListener("pointerdown",this.CS,!0),this.kS&&t.removeEventListener("pointermove",this.kS,!0),this.IS&&(t.removeEventListener("pointerup",this.IS,!0),t.removeEventListener("pointercancel",this.IS,!0))),this.xS&&(this._chart.unsubscribeCrosshairMove(this.xS),this.xS=null),this.CS=null,this.kS=null,this.IS=null,this.kf=null}isDrawingModeActive(){return this.cC}TS(t){if(this.wC())return;const i=this.gC(t);null!==i&&(this.JP=!0,this.dC=[i],this.bS=t.pointerId,qr(this._chart,!0),this.kf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.bC())}DS(t){if(!this.JP)return;const i=this.gC(t);if(null===i)return;const s=this.dC[this.dC.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.vC.sampleDistance??4)||(this.dC.push(i),t.preventDefault(),t.stopPropagation(),this.bC())}RS(){this.JP&&this.mC()}mC(){if(!this.JP)return;this.JP=!1,this.HS();const t=[];for(const i of this.dC){const s=Gn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.dC=[],t.length<2?this.cM():(this.vC.points=t,this.stopDrawingMode(),this.cM(),this.vC.onUpdate&&this.vC.onUpdate(),this.vC.onComplete&&this.vC.onComplete())}wC(){const t=this.fC;return"string"==typeof t&&t.split("#")[0]!==this.id}HS(){null!==this.bS&&(this.kf&&this.kf.hasPointerCapture(this.bS)&&this.kf.releasePointerCapture(this.bS),this.bS=null)}gC(t){const i=this.MC();if(null===i)return null;const s=i.getBoundingClientRect();return{ut:t.clientX-s.left,ct:t.clientY-s.top}}MC(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}bC(){this.pC||(this.pC=!0,requestAnimationFrame(()=>{this.pC=!1,this.cM()}))}drawToCanvas(t,i,s){const n=this.JP?this.dC.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.yC(i,s);if(0===n.length)return;const e=this.Fx;if(t.strokeStyle=this.vC.color,t.lineWidth=(this.vC.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.vC.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.Ex||this.isLocked()||(this.Qx(t,n[0],i),this.Qx(t,n[n.length-1],i))}Qx(t,i,s){t.fillStyle=this.vC.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()}yC(t,i){const s=this.vC.points??[],n=[];for(const e of s){const s=Xn(this._chart,this._series,e.time),h=this._series.priceToCoordinate(e.price);null!==s&&null!==h&&n.push({ut:s*t,ct:h*i})}return n}hitTest(t,i){const s=this.yC(1,1);for(let n=1;n<s.length;n++)if(so(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.Lx=!0,this.Bx=i,this.oP=(this.vC.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.oP;if(!this.Lx||null===s||!this.vC.points)return;const n=Ar(this.Bx,t,i);this.vC.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.cM(),this.vC.onUpdate&&this.vC.onUpdate()}stopDrag(){this.Lx=!1,this.Bx=null,this.oP=null}setColor(t){this.vC.color=t,this.cM()}color(){return this.vC.color??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}Zy(){this.nr=new to(this);const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){this.stopDrawingMode(),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null),this.nr=null,this.vC.onRemove&&this.vC.onRemove()}_serializeShape(){return{type:"brush",points:(this.vC.points??[]).map(zr),style:{color:this.vC.color,lineWidth:this.vC.lineWidth,smoothing:this.vC.smoothing}}}getPoints(){return this.vC.points??[]}}function so(t,i,s,n){const e=n.ut-s.ut,h=n.ct-s.ct,r=e*e+h*h;if(0===r)return Math.hypot(t-s.ut,i-s.ct);let l=((t-s.ut)*e+(i-s.ct)*h)/r;return l=Math.max(0,Math.min(1,l)),Math.hypot(t-(s.ut+l*e),i-(s.ct+l*h))}function no(t,i={}){return new io(t,i)}class eo{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ho{constructor(t){this.Rx=t,this.Jt=new eo(t)}renderer(){return this.Rx.isComplete()?this.Jt:null}}class ro extends Nr{constructor(t,i){super(t,"text-tool",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null,this.SC=!1,this.xC=null,this.PC={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,...i},this._registerOptions(this.PC),this.Zy(),this.CC()}CC(){this.xC=this._chart.subscribeClick(t=>{if(!this.SC)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.PC.text&&""!==this.PC.text.trim()&&"Type here..."!==this.PC.text||this.remove())})}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new ho(this)}getTime(){return this.PC.time}getPrice(){return this.PC.price}getText(){return this.PC.text||""}getOptions(){return this.PC}setPosition(t,i){this.PC.time=t,this.PC.price=i,this._update()}setText(t){this.PC.text=t,this._update(),this.PC.onTextChange&&this.PC.onTextChange(t)}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}isComplete(){return!(!this.PC.time||void 0===this.PC.price)}setColor(t){this.PC.textColor=t,this.PC.borderColor=t,this.cM()}color(){return this.PC.textColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this._update())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this._update())}isHovered(){return this.Ex}setEditing(t){this.SC!==t&&(this.SC=t,this._update())}isEditing(){return this.SC}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.PC.time,n=this.PC.price,e=Xn(this._chart,this._series,s)??0,h=this._series.priceToCoordinate(n)??0,r=this.PC.fontSize||14,l=this.PC.padding||8,o=this.PC.text||"",a=.6*r,_=Math.min(o.length*a,this.PC.maxWidth||200);return t>=e&&t<=e+_+2*l&&i>=h&&i<=h+(r+2*l)}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.PC.time,n=this.PC.price,e=Xn(this._chart,this._series,s)??0,h=this._series.priceToCoordinate(n)??0;return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-h,2))<=10?"anchor":null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,this.MP={gt:this.PC.time,bt:this.PC.price}}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null}updateDrag(t,i){if(this.Lx){if("body"===this.Ax&&this.MP){const s=Ar(this.Bx,t,i);this.setPosition(this.MP.gt+s.gt,this.MP.bt+s.bt)}else this.setPosition(t,i);this.PC.onUpdate&&this.PC.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.PC.time,e=this.PC.price,h=this.PC.text||"",r=(Xn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.PC.fontSize||14)*i,a=(this.PC.padding||8)*i,_=(this.PC.maxWidth||200)*i;t.font=`${o}px ${this.PC.fontFamily||"Arial"}`,t.textBaseline="top";const u=h.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.PC.backgroundOpacity||.8,g=this.PC.backgroundColor||"#2962FF";t.fillStyle=this.Gy(g,w),t.fillRect(r,l,f,m),(this.Fx||this.Ex)&&(t.strokeStyle=this.PC.borderColor??"#FFFFFF",t.lineWidth=(this.PC.borderWidth||1)*i*(this.Fx?2:1),t.strokeRect(r,l,f,m)),t.fillStyle=this.PC.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=r+a;if("center"===this.PC.textAlign){n=r+(f-t.measureText(s).width)/2}else if("right"===this.PC.textAlign){n=r+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.Fx||this.Ex)&&!this.isLocked()){const s=4*i;t.fillStyle=this.PC.textColor??"#2962ff",t.beginPath(),t.arc(r,l,s,0,2*Math.PI),t.fill(),t.fillStyle="#FFFFFF",t.beginPath(),t.arc(r,l,s-2*i,0,2*Math.PI),t.fill()}}Gy(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:[Or(this.PC.price??0,Wr(this.PC.time))],style:{fontSize:this.PC.fontSize,fontFamily:this.PC.fontFamily,textColor:this.PC.textColor,backgroundColor:this.PC.backgroundColor,backgroundOpacity:this.PC.backgroundOpacity,padding:this.PC.padding,borderColor:this.PC.borderColor,borderWidth:this.PC.borderWidth,textAlign:this.PC.textAlign,maxWidth:this.PC.maxWidth},extra:{text:this.PC.text}}}remove(){if(this.xC&&(this._chart.unsubscribeClick(this.xC),this.xC=null),this.Ub&&this._series){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.PC.onRemove&&this.PC.onRemove()}}function lo(t,i){return new ro(t,i)}class oo{constructor(t){this.TC=t}calculatePips(t,i){return Math.abs(i-t)/this.TC.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 h=Math.abs(t-i),r=Math.abs(s-t);e.stopLossAmount=h*n,e.takeProfitAmount=r*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.TC={...this.TC,...t}}getPipConfig(){return{...this.TC}}}function ao(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 _o(t,i){return"number"==typeof t?ao(t):void 0!==i?ao(i):{pipValue:.1,decimals:1}}class uo{constructor(t){this.TC=t}calculateMetrics(t,i,s,n,e){const h=n-i;return{point1:{time:t,price:i},point2:{time:s,price:n},priceDifference:h,pricePercent:h/i*100,pips:Math.abs(h)/this.TC.pipValue,timeDifference:this.kC(t,s),barCount:e}}kC(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.TC={...this.TC,...t}}getPipConfig(){return{...this.TC}}}class co{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class po{constructor(t){this.Rx=t,this.Jt=new co(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}}class fo extends Nr{constructor(t,i){super(t,"ruler-tool",i),this.Ub=null,this.Vx=null,this.Yb=null,this.nr=null,this.HP=null,this.zx=!1,this.Fx=!1,this.Ex=!1,this.$x=null,this.Lx=!1,this.NP=null,this.sp=null,this.DC={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.DC);const s=this.DC.pipConfig||_o(this.DC.symbol||"DEFAULT");this.qP=new uo(s),this.Zy(),this.DC.interactive?this.Nx():this.DC.point1Time&&this.DC.point2Time&&(this.zx=!0,this.jP())}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new po(this)}Nx(){this.HP=new Gr(this._chart,this._series,{Tx:t=>{this.DC.point1Time=t.gt,this.DC.point1Price=t.bt,this.cM()},kx:t=>{this.DC.point2Time=t.gt,this.DC.point2Price=t.bt},Dx:(t,i)=>{this.DC.point1Time=t.gt,this.DC.point1Price=t.bt,this.DC.point2Time=i.gt,this.DC.point2Price=i.bt,this.zx=!0,this.$x=null,this.jP(),this.KP(),this.cM()},Ix:t=>{this.$x=t,this.cM()}}),this.HP.vx()}drawToCanvas(t,i,s){if(!this.zx&&this.DC.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.zx||!this.DC.point1Time||!this.DC.point2Time)return;const n=(Xn(this._chart,this._series,this.DC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DC.point1Price)??0)*s,h=(Xn(this._chart,this._series,this.DC.point2Time)??0)*i,r=(this._series.priceToCoordinate(this.DC.point2Price)??0)*s;(this.Fx||this.Ex&&!this.isLocked())&&(t.strokeStyle=this.DC.selectionColor,t.lineWidth=this.DC.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(h,r),t.stroke()),t.strokeStyle=this.DC.lineColor,t.lineWidth=this.DC.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(h,r),t.stroke(),this.IC(t,n,e,h,r,i),this.Qx(t,n,e,i),this.Qx(t,h,r,i),this.DC.showLabel&&this.Yb&&this.eP(t,n,e,h,r,i,s)}IC(t,i,s,n,e,h){const r=this.DC.measure??"both";if("both"===r)return;const l=14*h;if(t.strokeStyle=this.DC.lineColor,t.lineWidth=this.DC.lineWidth*h,t.beginPath(),"price"===r)for(const h of[s,e])t.moveTo(Math.min(i,n)-l/2,h),t.lineTo(Math.max(i,n)+l/2,h);else for(const h of[i,n])t.moveTo(h,Math.min(s,e)-l/2),t.lineTo(h,Math.max(s,e)+l/2);t.stroke()}Qx(t,i,s,n){const e=this.Fx?this.DC.selectionColor:this.DC.lineColor,h=this.Fx?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,h,0,2*Math.PI),t.fill(),this.Fx&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}Jx(t,i,s){if(!this.DC.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.DC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DC.point1Price)??0)*s,h=(Xn(this._chart,this._series,this.$x.gt)??0)*i,r=(this._series.priceToCoordinate(this.$x.bt)??0)*s;t.strokeStyle=this.DC.lineColor,t.lineWidth=this.DC.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(h,r),t.stroke(),t.setLineDash([]),this.Qx(t,n,e,i),t.globalAlpha=.5,this.Qx(t,h,r,i),t.globalAlpha=1}eP(t,i,s,n,e,h,r){if(!this.Yb)return;const l=(i+n)/2,o=(s+e)/2,a=this.DC.measure??"both",_=[];"time"!==a&&(_.push(this.qP.formatPips(this.Yb.pips)),_.push(this.qP.formatPercent(this.Yb.pricePercent))),"price"!==a&&_.push(this.qP.formatBarCount(this.Yb.barCount));const u=_.join(" | ");t.font=12*h+"px sans-serif";const c=6*h,d=t.measureText(u).width+2*c,p=12*h+2*c;t.fillStyle=this.DC.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.DC.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}jP(){if(!this.DC.point1Time||!this.DC.point2Time||void 0===this.DC.point1Price||void 0===this.DC.point2Price)return;const t=this.RC();this.Yb=this.qP.calculateMetrics(this.DC.point1Time,this.DC.point1Price,this.DC.point2Time,this.DC.point2Price,t),this.DC.onUpdate&&this.Yb&&this.DC.onUpdate(this.Yb)}RC(){if(!this.DC.point1Time||!this.DC.point2Time)return 0;const t=Xn(this._chart,this._series,this.DC.point1Time),i=Xn(this._chart,this._series,this.DC.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.DC.point1Time=t,this.DC.point1Price=i,this.DC.point2Time=s,this.DC.point2Price=n,this.jP(),this.cM()}getMetrics(){return this.Yb}remove(){this.destroy()}destroy(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.HP&&(this.HP.m(),this.HP=null),this.XP(),this.DC.onRemove&&this.DC.onRemove()}KP(){this.sp=t=>{this.GP(t)},this._chart.subscribeCrosshairMove(this.sp)}XP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}GP(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.Fx||!this.Lx)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.NP?(this.DC.point1Time=i,this.DC.point1Price=s):"point2"===this.NP&&(this.DC.point2Time=i,this.DC.point2Price=s),this.jP(),this.cM())}startDrag(t){this.Lx=!0,this.NP=t}stopDrag(){this.Lx=!1,this.NP=null}updateDrag(t,i){this.Lx&&this.NP&&("point1"===this.NP?(this.DC.point1Time=t,this.DC.point1Price=i):(this.DC.point2Time=t,this.DC.point2Price=i),this.jP(),this.cM())}hitTestEndpoint(t,i){if(!this.zx||!this.DC.point1Time||!this.DC.point2Time)return null;const s=Xn(this._chart,this._series,this.DC.point1Time)??0,n=this._series.priceToCoordinate(this.DC.point1Price)??0,e=Xn(this._chart,this._series,this.DC.point2Time)??0,h=this._series.priceToCoordinate(this.DC.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-h,2))<=10?"point2":null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.jP(),this.cM()}_serializeShape(){return{type:"ruler",points:[Or(this.DC.point1Price??0,Wr(this.DC.point1Time)),Or(this.DC.point2Price??0,Wr(this.DC.point2Time))],style:{lineColor:this.DC.lineColor,lineWidth:this.DC.lineWidth,showLabel:this.DC.showLabel,labelBackgroundColor:this.DC.labelBackgroundColor,labelTextColor:this.DC.labelTextColor,selectionColor:this.DC.selectionColor,selectionLineWidth:this.DC.selectionLineWidth},extra:{symbol:this.DC.symbol,pipConfig:this.DC.pipConfig,measure:this.DC.measure}}}setColor(t){this.DC.lineColor=t,this.cM()}color(){return this.DC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}isSelected(){return this.Fx}isComplete(){return this.zx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.zx||!this.DC.point1Time||!this.DC.point2Time)return!1;const s=Xn(this._chart,this._series,this.DC.point1Time)??0,n=this._series.priceToCoordinate(this.DC.point1Price)??0,e=Xn(this._chart,this._series,this.DC.point2Time)??0,h=this._series.priceToCoordinate(this.DC.point2Price)??0;return this.VC(t,i,s,n,e,h)<=(this.Fx?12:8)}VC(t,i,s,n,e,h){const r=e-s,l=h-n,o=r*r+l*l;let a,_,u=-1;0!==o&&(u=((t-s)*r+(i-n)*l)/o),u<0?(a=s,_=n):u>1?(a=e,_=h):(a=s+u*r,_=n+u*l);const c=t-a,d=i-_;return Math.sqrt(c*c+d*d)}}function vo(t,i){return new fo(t,i)}class mo{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wo{constructor(t){this.Rx=t,this.Jt=new mo(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}}class go extends Nr{constructor(t,i){super(t,"position-tool",i),this.Ub=null,this.Vx=null,this.Yb=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null,this.FC=null,this.EC=null,this.LC={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.LC);const s=this.LC.pipConfig||_o(this.LC.entryPrice);this.qP=new oo(s),this.Zy(),this.jP()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new wo(this)}drawToCanvas(t,i,s){if(this.FC&&this.LC.takeProfit){const n=this._chart.timeScale();this.AC(t,this.FC,i,s,n),(this.Ex||this.Fx)&&this.eP(t,this.FC,"profit",i,s,n)}if(this.EC&&this.LC.stopLoss){const n=this._chart.timeScale();if(this.AC(t,this.EC,i,s,n),this.Ex||this.Fx){const n=this._chart.timeScale();this.eP(t,this.EC,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.BC(t,i,s,n),this.LC.takeProfit){const n=this._chart.timeScale();this.Qx(t,this.LC.takeProfit,this.LC.profitColor,i,s,n)}if(this.LC.stopLoss){const n=this._chart.timeScale();this.Qx(t,this.LC.stopLoss,this.LC.lossColor,i,s,n)}}AC(t,i,s,n,e){const h=(Xn(this._chart,this._series,this.LC.entryTime)??0)*s;let r;if(this.LC.endTime)r=(Xn(this._chart,this._series,this.LC.endTime)??0)*s;else{r=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.WC)??0)*n,o=(this._series.priceToCoordinate(i.OC)??0)*n;t.fillStyle=this.Gy(i.I,.15),t.fillRect(h,Math.min(l,o),r-h,Math.abs(o-l)),t.strokeStyle=i.I,t.lineWidth=2*s,t.beginPath(),t.moveTo(h,o),t.lineTo(r,o),t.stroke()}BC(t,i,s,n){const e=(Xn(this._chart,this._series,this.LC.entryTime)??0)*i,h=(this._series.priceToCoordinate(this.LC.entryPrice)??0)*s;let r;if(this.LC.endTime)r=(Xn(this._chart,this._series,this.LC.endTime)??0)*i;else{r=this._chart.chartElement().clientWidth*i}const l=this.LC.entryLineColor;t.strokeStyle=l,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(e,h),t.lineTo(r,h),t.stroke(),t.setLineDash([]),t.strokeStyle=this.LC.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const o=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,o),t.stroke(),t.setLineDash([]),!this.Fx&&!this.Ex||this.isLocked())t.fillStyle=this.LC.entryLineColor,t.beginPath(),t.arc(e,h,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=l,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(e,h,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=l,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(r-s/2,h-s/2,s,s),t.strokeRect(r-s/2,h-s/2,s,s)}}jP(){this.LC.stopLoss&&this.LC.takeProfit&&(this.Yb=this.qP.calculateMetrics(this.LC.entryPrice,this.LC.stopLoss,this.LC.takeProfit,this.LC.quantity),this.zC(),this.LC.onUpdate&&this.Yb&&this.LC.onUpdate(this.Yb))}zC(){const t=this.$C();this.LC.takeProfit&&(this.FC={HC:this.LC.entryTime,NC:t,WC:this.LC.entryPrice,OC:this.LC.takeProfit,I:this.LC.profitColor,yy:this.LC.opacity}),this.LC.stopLoss&&(this.EC={HC:this.LC.entryTime,NC:t,WC:this.LC.entryPrice,OC:this.LC.stopLoss,I:this.LC.lossColor,yy:this.LC.opacity})}$C(){this._chart.timeScale().getVisibleLogicalRange();return this.LC.entryTime}eP(t,i,s,n,e,h){if(!this.Yb)return;const r=(Xn(this._chart,this._series,this.LC.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.OC)??0)*e,o="profit"===s,a=o?this.Yb.takeProfitPips:this.Yb.stopLossPips,_=o?this.LC.takeProfit:this.LC.stopLoss,u=this.Yb.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=r+8*n,m=l-f/2;t.fillStyle=i.I,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}Qx(t,i,s,n,e,h){const r=(Xn(this._chart,this._series,this.LC.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,o=s;let a;if(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(r,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this.LC.endTime)a=(Xn(this._chart,this._series,this.LC.endTime)??0)*n;else{a=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(a-_/2,l-_/2,_,_),t.strokeRect(a-_/2,l-_/2,_,_)}Gy(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.LC={...this.LC,...t},this.jP(),this._update()}getMetrics(){return this.Yb}setStopLoss(t){this.LC.stopLoss=t,this.jP(),this._update()}setTakeProfit(t){this.LC.takeProfit=t,this.jP(),this._update()}setEntryPrice(t){this.LC.entryPrice=t,this.jP(),this._update()}_serializeShape(){return{type:"position",points:[Or(this.LC.entryPrice,Wr(this.LC.entryTime))],style:{profitColor:this.LC.profitColor,lossColor:this.LC.lossColor,entryLineColor:this.LC.entryLineColor,opacity:this.LC.opacity,showTooltips:this.LC.showTooltips},extra:{endTime:Wr(this.LC.endTime),stopLoss:this.LC.stopLoss,takeProfit:this.LC.takeProfit,quantity:this.LC.quantity,pipConfig:this.LC.pipConfig}}}setColor(t){this.LC.entryLineColor=t,this.cM()}color(){return this.LC.entryLineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):this.hitTest(t,i)?Lr(this.id,"body",!1):null}hitTest(t,i){if(!this.LC.stopLoss&&!this.LC.takeProfit)return!1;const s=Xn(this._chart,this._series,this.LC.entryTime)??0;let n;if(this.LC.endTime)n=Xn(this._chart,this._series,this.LC.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.LC.takeProfit&&this.LC.stopLoss){const e=this._series.priceToCoordinate(this.LC.takeProfit)??0,h=this._series.priceToCoordinate(this.LC.stopLoss)??0,r=Math.min(e,h),l=Math.max(e,h);if(t>=s&&t<=n&&i>=r&&i<=l)return!0;const o=8;if(Math.abs(t-s)<=o&&i>=r&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Xn(this._chart,this._series,this.LC.entryTime)??0;let n;if(this.LC.endTime)n=Xn(this._chart,this._series,this.LC.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.LC.takeProfit){const n=this._series.priceToCoordinate(this.LC.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.LC.stopLoss){const n=this._series.priceToCoordinate(this.LC.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.LC.takeProfit){const s=this._series.priceToCoordinate(this.LC.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.LC.stopLoss){const s=this._series.priceToCoordinate(this.LC.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const e=this._series.priceToCoordinate(this.LC.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.LC.takeProfit&&this.LC.stopLoss){const e=this._series.priceToCoordinate(this.LC.takeProfit)??0,h=this._series.priceToCoordinate(this.LC.stopLoss)??0,r=Math.min(e,h),l=Math.max(e,h);if(t>=s&&t<=n&&i>=r&&i<=l)return"move"}return null}startDrag(t,i){this.Lx=!0,this.Ax=t,this.Bx=i,"move"===t&&(this.MP={UC:this.LC.entryPrice,qC:this.LC.entryTime??null,Ky:this.LC.endTime??null,jC:this.LC.takeProfit??null,YC:this.LC.stopLoss??null})}stopDrag(){this.Lx=!1,this.Ax=null,this.Bx=null,this.MP=null}updateDrag(t,i){if(this.Lx&&this.Ax){if("entry"===this.Ax)this.LC.entryPrice=i;else if("move"===this.Ax){if(this.MP){const s=Ar(this.Bx,t,i),n=this.MP;this.LC.entryPrice=n.UC+s.bt,null!==n.jC&&(this.LC.takeProfit=n.jC+s.bt),null!==n.YC&&(this.LC.stopLoss=n.YC+s.bt),null!==n.qC&&(this.LC.entryTime=this.KC(n.qC,s.gt)),null!==n.Ky&&(this.LC.endTime=this.KC(n.Ky,s.gt))}}else"tp"===this.Ax||"tp-right"===this.Ax?(this.LC.takeProfit=i,"tp-right"===this.Ax?this.LC.endTime=t:this.LC.entryTime=t):"sl"!==this.Ax&&"sl-right"!==this.Ax||(this.LC.stopLoss=i,"sl-right"===this.Ax?this.LC.endTime=t:this.LC.entryTime=t);this.jP(),this.cM()}}KC(t,i){return t+i}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.LC.onRemove&&this.LC.onRemove()}}function bo(t,i){return new go(t,i)}class Mo{constructor(t){this.Rx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Rx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class yo{constructor(t){this.Rx=t,this.Jt=new Mo(t)}renderer(){return this.Rx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class So extends Nr{constructor(t,i){super(t,"gantt",i),this.Ub=null,this.Vx=null,this.nr=null,this.Fx=!1,this.Ex=!1,this.Lx=!1,this.GC=-1,this.Bx=null,this.MP=null,this.XC=-1,this.ZC={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.ZC),this.Zy()}Zy(){this.nr=this.Ux();const t={attached:t=>{this.Vx=t.requestUpdate},detached:()=>{this.Vx=null},updateAllViews:()=>{},paneViews:()=>this.nr?[this.nr]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new yo(this)}drawToCanvas(t,i,s){if(!this.ZC.segments||0===this.ZC.segments.length)return;const n=50*s,e=this.ZC.rowHeight*s,h=this.ZC.rowSpacing*s;this.ZC.showGrid&&this.sm(t,n,e,h,i,s),this.ZC.segments.forEach((s,r)=>{const l=(Xn(this._chart,this._series,s.startTime)??0)*i,o=(Xn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+h),_=r===this.XC||this.Ex&&!this.isLocked();this.JC(t,l,o,a,e,s,_,i)})}sm(t,i,s,n,e,h){if(!this.ZC.segments)return;const r=Math.max(...this.ZC.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<=r+1;e++){const h=i+e*(s+n);t.beginPath(),t.moveTo(0,h),t.lineTo(l,h),t.stroke()}}JC(t,i,s,n,e,h,r,l){const o=s-i,a=this.Gy(h.color,r?this.ZC.fillOpacity+.2:this.ZC.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=h.color;const _=this.ZC.borderWidth+(this.Fx?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.ZC.showLabels&&h.label&&this.eP(t,i,n,o,e,h.label,l)}eP(t,i,s,n,e,h,r){const l=11*r,o=6*r;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let a=h;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)}Gy(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.ZC.segments||(this.ZC.segments=[]),this.ZC.segments.push(t),this.cM(),this.ZC.onUpdate&&this.ZC.onUpdate()}removeSegment(t){this.ZC.segments&&t>=0&&t<this.ZC.segments.length&&(this.ZC.segments.splice(t,1),this.cM(),this.ZC.onUpdate&&this.ZC.onUpdate())}getSegments(){return this.ZC.segments||[]}setColor(t){const i=this.ZC.segments??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.ZC.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Ex!==t&&(this.Ex=t,this.cM())}isHovered(){return this.Ex}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Lr(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.ZC.segments?.[this.XC];s&&(this.Lx=!0,this.GC=this.XC,this.Bx=i,this.MP={Yy:s.startTime,Ky:s.endTime})}updateDrag(t,i){const s=this.ZC.segments?.[this.GC];if(!this.Lx||!this.MP||!s)return;const n=Ar(this.Bx,t,i);s.startTime=this.MP.Yy+n.gt,s.endTime=this.MP.Ky+n.gt,this.cM(),this.ZC.onUpdate&&this.ZC.onUpdate()}stopDrag(){this.Lx=!1,this.GC=-1,this.Bx=null,this.MP=null}hitTest(t,i){if(!this.ZC.segments||0===this.ZC.segments.length)return!1;const s=this.ZC.rowHeight,n=this.ZC.rowSpacing;for(let e=0;e<this.ZC.segments.length;e++){const h=this.ZC.segments[e],r=Xn(this._chart,this._series,h.startTime)??0,l=Xn(this._chart,this._series,h.endTime)??0,o=50+h.level*(s+n);if(t>=r&&t<=l&&i>=o&&i<=o+s)return this.XC=e,!0}return this.XC=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.ZC.rowHeight,rowSpacing:this.ZC.rowSpacing,fillOpacity:this.ZC.fillOpacity,borderWidth:this.ZC.borderWidth,showLabels:this.ZC.showLabels,showGrid:this.ZC.showGrid},extra:{segments:(this.ZC.segments||[]).map(t=>({Yy:Wr(t.startTime),Ky:Wr(t.endTime),sn:t.level,Zl:t.label,I:t.color,QC:t.category}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Vx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nr=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.ZC.onRemove&&this.ZC.onRemove()}}function xo(t,i){return new So(t,i)}class Po{constructor(t,i,s={}){this.tT=[],this.iT=[],this.sT=[],this.nT=!1,this.eT=new Map,this.hT=null,this.rT=null,this.lT=null,this.XS=null,this.oT=null,this.sp=null,this.aT=null,this._T=null,this.uT=null,this.bS=null,this.cT=!1,this.dT=null,this.pT=null,this.fT=new a,this.Lx=!1,this.vT=null,this.Vf=t,this.be=i,this.Cs={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.mT()}startDrawing(t){this.lT=t,this.wT()}activeDrawingType(){return this.lT}stopDrawing(){this.lT=null}addTool(t,i){const s=i??t.id;return this.eT.set(s,t),this.recordChange(),s}removeTool(t){const i=this.eT.get(t);return!!i&&(this.hT===t&&this.gT(null),i.remove(),this.eT.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.eT.has(t)&&(this.gT(t),!0)}gT(t){if(this.hT===t)return;const i=null===this.hT?void 0:this.eT.get(this.hT);i&&i.setSelected(!1),this.hT=t;const s=null===t?void 0:this.eT.get(t);s&&s.setSelected(!0),this.bT()}recordChange(){this.nT||(this.tT.push(this.sT),this.iT=[],this.sT=this.serializeAll())}canUndo(){return this.tT.length>0}canRedo(){return this.iT.length>0}undo(){const t=this.tT.pop();return void 0!==t&&(this.iT.push(this.sT),this.MT(t),!0)}redo(){const t=this.iT.pop();return void 0!==t&&(this.tT.push(this.sT),this.MT(t),!0)}MT(t){this.nT=!0;try{this.restoreAll({chart:this.Vf,series:this.be},t,!0),this.sT=t}finally{this.nT=!1}}subscribeSelectionChanged(t){this.fT.i(t)}unsubscribeSelectionChanged(t){this.fT._(t)}selectionBounds(){if(null===this.hT)return null;const t=this.eT.get(this.hT);return t?this.yT(t):null}yT(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Xn(this.Vf,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),h=Math.max(h,s),e=Math.min(e,o),r=Math.max(r,o))}if(!l)return null;const o=this.ST(t);return{left:n+o.ut,right:h+o.ut,top:e+o.ct,bottom:r+o.ct}}ST(t){const i=this.Vf.chartElement(),s=this.xT(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}}bT(){this.fT.p({id:this.hT,bounds:this.selectionBounds()})}deselectAll(){this.wT()}deleteSelected(){if(this.hT){const t=this.eT.get(this.hT);return(!t||!t.isLocked())&&this.removeTool(this.hT)}return!1}getSelectedToolId(){return this.hT}getAllTools(){return new Map(this.eT)}getTool(t){return this.eT.get(t)}clearAll(){this.gT(null),this.eT.forEach(t=>t.remove()),this.eT.clear(),this.recordChange()}getToolCount(){return this.eT.size}isToolSelected(t){return this.hT===t}serializeAll(){const t=[];for(const i of this.eT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=Po.PT(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 PT(t,i){const{type:s,points:n,style:e,extra:h}=i,r=t=>({CT:$r(n[t]),TT:Hr(n[t],"price")??0});switch(s){case"trendLine":return Qr(t,{point1Time:r(0).CT,point1Price:r(0).TT,point2Time:r(1).CT,point2Price:r(1).TT,...e});case"horizontalLine":return nl(t,{price:r(0).TT,startTime:r(0).CT??void 0,...e});case"parallelChannel":return fl(t,{point1Time:r(0).CT,point1Price:r(0).TT,point2Time:r(1).CT,point2Price:r(1).TT,channelWidth:h?.channelWidth,...e});case"pitchfork":return gl(t,{pivotTime:r(0).CT,pivotPrice:r(0).TT,upperTime:r(1).CT,upperPrice:r(1).TT,lowerTime:r(2).CT,lowerPrice:r(2).TT,...e});case"polygon":return ul(t,{points:n.map((t,i)=>{const s={};return s.time=r(i).CT,s.price=r(i).TT,s}),...e});case"crossLine":return ll(t,{time:r(0).CT,price:r(0).TT,...e});case"verticalLine":return Sl(t,{time:r(0).CT,...e});case"fibRetracement":return Rl(t,{point1Time:r(0).CT,point1Price:r(0).TT,point2Time:r(1).CT,point2Price:r(1).TT,useExtended:h?.useExtended,levels:h?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=r(0),s=r(1),n=r(2);return Ll(t,{point1:i.CT?{time:i.CT,price:i.TT}:void 0,point2:s.CT?{time:s.CT,price:s.TT}:void 0,point3:n.CT?{time:n.CT,price:n.TT}:void 0,levels:h?.levels,...e})}case"fibFan":return zl(t,{point1Time:r(0).CT,point1Price:r(0).TT,point2Time:r(1).CT,point2Price:r(1).TT,levels:h?.levels,...e});case"rectangle":return Ul(t,{time1:r(0).CT,price1:r(0).TT,time2:r(1).CT,price2:r(1).TT,...e});case"circle":return Kl(t,{centerTime:r(0).CT,centerPrice:r(0).TT,radiusTime:h?.radiusTime,radiusPrice:h?.radiusPrice,...e});case"arrow":return Jl(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return no(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return lo(t,{time:r(0).CT,price:r(0).TT,text:h?.text,...e});case"ruler":return vo(t,{point1Time:r(0).CT,point1Price:r(0).TT,point2Time:r(1).CT,point2Price:r(1).TT,symbol:h?.symbol,pipConfig:h?.pipConfig,measure:h?.measure,...e});case"position":return bo(t,{entryPrice:r(0).TT,entryTime:r(0).CT,endTime:h?.endTime,stopLoss:h?.stopLoss,takeProfit:h?.takeProfit,quantity:h?.quantity,pipConfig:h?.pipConfig,...e});case"gantt":return xo(t,{segments:h?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){this.clearAll(),this.kT()}mT(){this.XS=t=>{this.Px(t)},this.Vf.subscribeClick(this.XS),this.sp=t=>{this.Cx(t)},this.Vf.subscribeCrosshairMove(this.sp);const t=this.Vf.chartElement();t&&(this.aT=t=>this.DT(t),this._T=t=>this.IT(),this.uT=t=>this.IT(),t.addEventListener("pointerdown",this.aT),t.addEventListener("pointerup",this._T),t.addEventListener("pointercancel",this.uT)),this.Cs.enableKeyboardShortcuts&&(this.oT=t=>{this.RT(t)},document.addEventListener("keydown",this.oT))}kT(){this.XS&&(this.Vf.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this.Vf.unsubscribeCrosshairMove(this.sp),this.sp=null);const t=this.Vf.chartElement();t&&(this.aT&&(t.removeEventListener("pointerdown",this.aT),this.aT=null),this._T&&(t.removeEventListener("pointerup",this._T),this._T=null),this.uT&&(t.removeEventListener("pointercancel",this.uT),this.uT=null)),this.oT&&(document.removeEventListener("keydown",this.oT),this.oT=null)}Px(t){if(!t.point)return;if(this.cT)return void(this.cT=!1);if(this.Lx)return;const i=this.VT(t.hoveredObjectId);i?this.selectTool(i):this.wT()}Cx(t){if(this.dT=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.Lx&&this.vT){const i=this.eT.get(this.vT);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Gn(this.Vf,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.VT(t.hoveredObjectId);if(this.rT&&this.rT!==i){const t=this.eT.get(this.rT);t&&t.setHovered(!1)}if(i){const t=this.eT.get(i);t&&t.setHovered(!0)}this.rT=i}VT(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.eT)if(s.id===i)return t;return null}DT(t){qr(this.Vf,!1);const i=this.Vf.chartElement();if(!i)return;const s=null!==this.rT&&null!==this.dT?{FT:this.rT,kw:this.dT}:this.ET(t);if(null===s)return;const{FT:n,kw:e}=s,h=this.eT.get(n);if(!h||h.isLocked())return;const r=h.hitTestEndpoint(e.ut,e.ct),l=this.LT(h,e.ut,e.ct);null!==r&&null!==l&&(qr(this.Vf,!0),this.selectTool(n),this.Lx=!0,this.cT=!0,this.vT=n,this.bS=t.pointerId,i.setPointerCapture(t.pointerId),h.startDrag(r,l),this.AT())}IT(){if(!this.Lx||null===this.vT)return;const t=this.eT.get(this.vT);t&&t.stopDrag(),this.HS(),this.BT(),this.Lx=!1,this.vT=null,this.recordChange()}xT(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}ET(t){for(const[i,s]of this.eT){if(!s.isVisible()||s.isLocked())continue;const n=this.xT(s);if(null===n)continue;const e=n.getBoundingClientRect(),h={ut:t.clientX-e.left,ct:t.clientY-e.top};if(s.hitTest(h.ut,h.ct))return{FT:i,kw:h}}return null}HS(){if(null===this.bS)return;const t=this.Vf.chartElement();t&&t.hasPointerCapture(this.bS)&&t.releasePointerCapture(this.bS),this.bS=null}AT(){const t=this.Vf.options();this.pT={WT:t.handleScroll,OT:t.handleScale},this.Vf.applyOptions({handleScroll:!1,handleScale:!1})}BT(){const t=this.pT;this.pT=null,null!==t&&this.Vf.applyOptions({handleScroll:t.WT,handleScale:t.OT})}RT(t){"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const i=t.metaKey||t.ctrlKey;if(i&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}i&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.IT(),this.wT(),this.stopDrawing(),t.preventDefault())}LT(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Gn(this.Vf,t.series(),i)}}wT(){this.gT(null)}}const Co={...t,color:"#2196f3"};function To(){return"2.1.0"}export{Te as AreaSeries,Zl as ArrowTool,Re as BarSeries,xe as BaselineSeries,io as BrushTool,Ee as CandlestickSeries,Yl as CircleTool,Ei as ColorType,rl as CrossLineTool,U as CrosshairMode,gr as DEFAULT_SESSIONS,Ir as DraggablePriceLine,Po as DrawingToolsManager,Pl as EXTENDED_FIBONACCI_RATIOS,Cl as FibonacciCalculator,El as FibonacciExtensionTool,Ol as FibonacciFanTool,Il as FibonacciTool,So as GanttTool,Be as HistogramSeries,sl as HorizontalLineTool,Vr as InteractiveLineManager,Vi as LastPriceAnimationMode,le as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,pl as ParallelChannelTool,wl as PitchforkTool,_l as PolygonTool,oo as PositionCalculator,Ih as PositionMarkersManager,go as PositionTool,Fi as PriceLineSource,di as PriceScaleMode,Nl as RectangleTool,uo as RulerCalculator,fo as RulerTool,xl as STANDARD_FIBONACCI_RATIOS,ro as TextTool,Li as TickMarkType,Ri as TrackingModeExitMode,br as TradingSessionsIndicator,Jr as TrendLineTool,yl as VerticalLineTool,xr as VolumeProfileIndicator,dr as applyADX,_r as applyATR,jh as applyBollingerBands,pr as applyCCI,Kh as applyDonchianChannels,Uh as applyEMA,rr as applyHeikinAshi,sr as applyIchimoku,Yh as applyKeltnerChannels,or as applyMACD,vr as applyMFI,cr as applyOBV,Gh as applyParabolicSAR,nr as applyPivotPoints,lr as applyRSI,Nh as applySMA,ar as applyStochastic,Jh as applySuperTrend,Zh as applyVWAP,ur as applyVolume,qh as applyWMA,fr as applyWilliamsR,hr as calculateHeikinAshi,ao as calculatePipConfig,Xn as coordinateFromTime,Jl as createArrowTool,no as createBrushTool,jn as createChart,qn as createChartEx,Kl as createCircleTool,ll as createCrossLineTool,Ll as createFibonacciExtensionTool,zl as createFibonacciFanTool,Rl as createFibonacciTool,xo as createGanttTool,nl as createHorizontalLineTool,ih as createImageWatermark,Fr as createInteractiveLineManager,me as createOptionsChart,fl as createParallelChannelTool,gl as createPitchforkTool,ul as createPolygonTool,Rh as createPositionMarkers,bo as createPositionTool,Ul as createRectangleTool,vo as createRulerTool,bh as createSeriesMarkers,lo as createTextTool,Ke as createTextWatermark,Rr as createTradingLine,Mr as createTradingSessionsIndicator,Qr as createTrendLineTool,Dh as createUpDownMarkers,Sl as createVerticalLineTool,Pr as createVolumeProfileIndicator,pe as createYieldCurveChart,Co as customSeriesDefaultOptions,Yn as defaultHorzScaleBehavior,_o as getPipConfig,Wi as isBusinessDay,Oi as isUTCTimestamp,Eh as setSeriesVolumes,Cr as setVolumeProfileData,Gn as timeFromCoordinate,To 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:"",I:"",V:"",R:0,F:0,L:0,B:0,A: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.B=2.5/12*i,t.R=t.B,t.F=i/12*t.C,t.L=i/12*t.C,t.A=0),t.I=this.N(),t.V=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)}K(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})`}X(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.It(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Vt();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))}It(){const t=2===this.Ct.W().mode||!this.Ct.Rt(),i=this.Pt.Ft(),s=this.Ct.Lt(),n=this.O.Et();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Bt(s),l=i.At();!t&&null!==h&&i.Rt()&&null!==l?(r.wt=h.Ot,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 I 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.Kt.Rt,l=this.Yt.Gt.Rt;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.Kt.dt*s),t.strokeStyle=this.Yt.Kt.I,t.fillStyle=this.Yt.Kt.I,n(t,this.Yt.Kt.Xt),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.I,t.fillStyle=this.Yt.Gt.I,n(t,this.Yt.Gt.Xt),e(t,a,0,i.width))}}class V{constructor(t,i){this.xt=!0,this.Zt={Kt:{dt:1,Xt:0,I:"",Rt:!1},Gt:{dt:1,Xt:0,I:"",Rt:!1},ut:0,ct:0},this.Jt=new I(this.Zt),this.Qt=t,this.Pt=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.It(),this.xt=!1),this.Jt}It(){const t=this.Qt.Rt(),i=this.Pt.ti().W().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.Rt=!1,void(s.Kt.Rt=!1);s.Gt.Rt=t&&this.Qt.ii(this.Pt),s.Kt.Rt=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Xt=i.horzLine.style,s.Gt.I=i.horzLine.color,s.Kt.dt=i.vertLine.width,s.Kt.Xt=i.vertLine.style,s.Kt.I=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function R(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 F(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 E(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 A{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.ri=i}qt(t,i){return this.Yt.Rt?t.P+t.B+t.R:0}et(t,i,s,n){if(!this.Yt.Rt||0===this.Yt.hi.length)return;const e=this.Yt.I,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?E(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):E(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.V,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.B+this.ri.Di,c=i.R+this.ri.Ii,d=i.F,p=i.L,f=this.Yt.hi,v=i.P,m=s.Vi(e,f),w=Math.ceil(s.Ri(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.Fi??this.ri.Li,T=Math.round(P*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,I="right"===n,V=I?h.width-_:_,R=I?r.width-S:S;let F,L,E;return I?(F=R-x,L=R-C,E=V-a-d-_):(F=R+x,L=R+C,E=V+a+d),{ai:I,oi:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:F,fi:R,gi:L,bi:M,yi:r.width},xi:{ui:k/o,Si:D/o,Ci:E,Pi:m}}}}class O{constructor(t){this.Ei={Li:0,Z:"#000",Ii:0,Di:0},this.Bi={hi:"",Rt:!1,mi:!0,Ti:!1,Nt:"",I:"#FFF",Mi:!1,ki:!1},this.Ai={hi:"",Rt:!1,mi:!1,Ti:!0,Nt:"",I:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Oi=new(t||A)(this.Bi,this.Ei),this.Wi=new(t||A)(this.Ai,this.Ei)}hi(){return this.zi(),this.Bi.hi}Li(){return this.zi(),this.Ei.Li}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Oi.qt(t,i),this.Wi.qt(t,i))}$i(){return this.Ei.Fi||0}Hi(t){this.Ei.Fi=t}Ni(){return this.zi(),this.Bi.Rt||this.Ai.Rt}Ui(){return this.zi(),this.Bi.Rt}Dt(t){return this.zi(),this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Ai.mi=this.Ai.mi&&t.W().ticksVisible,this.Oi.lt(this.Bi,this.Ei),this.Wi.lt(this.Ai,this.Ei),this.Oi}qi(){return this.zi(),this.Oi.lt(this.Bi,this.Ei),this.Wi.lt(this.Ai,this.Ei),this.Wi}zi(){this.xt&&(this.Bi.mi=!0,this.Ai.mi=!1,this.ji(this.Bi,this.Ai,this.Ei))}}class W extends O{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Ki=s}ji(t,i,s){if(t.Rt=!1,2===this.Qt.W().mode)return;const n=this.Qt.W().horzLine;if(!n.labelVisible)return;const e=this.Yi.At();if(!this.Qt.Rt()||this.Yi.Gi()||null===e)return;const r=this.Yi.Xi().X(n.labelBackgroundColor);s.Z=r.Z,t.I=r.J;const h=2/12*this.Yi.P();s.Di=h,s.Ii=h;const l=this.Ki(this.Yi);s.Li=l.Li,t.hi=this.Yi.Zi(l.bt,e),t.Rt=!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.Rt||0===this.Yt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Ri(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.B+i.P+i.R);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.I;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.B+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.I;const r=i.Ji.Vi(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={Rt:!1,Z:"#4c525e",I:"white",hi:"",ts:0,Li:NaN,mi:!0},this.Ct=t,this.ss=i,this.Ki=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.It(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}It(){const t=this.Zt;if(t.Rt=!1,2===this.Ct.W().mode)return;const i=this.Ct.W().vertLine;if(!i.labelVisible)return;const s=this.ss.Et();if(s.Gi())return;t.ts=s.ts();const n=this.Ki();if(null===n)return;t.Li=n.Li;const e=s.ns(this.Ct.Lt());t.hi=s.es(l(e)),t.Rt=!0;const r=this.ss.Xi().X(i.labelBackgroundColor);t.Z=r.Z,t.I=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[]}Rt(){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.At());return{bt:s.Ds(n,t),Li:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.Et().Is(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Li:n}:null})(()=>this.fs,()=>this.ni());this.Vs=new H(this,t,s)}W(){return this.Ps}Rs(t,i){this.xs=t,this.Cs=i}Fs(){this.xs=NaN,this.Cs=NaN}Ls(){return this.xs}Es(){return this.Cs}Bs(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.As(t,i,s)}Lt(){return this.fs}ni(){return this.ys}ei(){return this.Ss}Rt(){return this.vs}Os(){this.vs=!1,this.Ws(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Pt=null,this.Fs(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new V(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.Vs]:[]}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.Vs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}As(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.Et().jt(t),this.Pt=s;const a=null!==o?o.At():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.Ks().map(t=>t.Xs().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 K{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function X(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 K{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+X(+r.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+X(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 K{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.In={},this.Vn=new Map,this.Rn=t}Fn(){this.Tn=0,this.Vn.clear(),this.kn=1,this.Dn=1,this.In={}}Ri(t,i,s){return this.Ln(t,i,s).width}Vi(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.Vn.has(e))return h(this.Vn.get(e)).En;if(this.Tn===this.Rn){const t=this.In[this.Dn];delete this.In[this.Dn],this.Vn.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.Vn.set(e,{En:r,Bn:this.kn}),this.In[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.An=null,this.M=null,this.On="right",this.Wn=t}zn(t,i,s){this.An=t,this.M=i,this.On=s}et(t){null!==this.M&&null!==this.An&&this.An.et(t,this.M,this.Wn,this.On)}}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.Fn()),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}Kn(t,i){if(!this.Yt?.Rt)return null;const{ct:s,dt:n,Gn:e}=this.Yt;return i>=s-n-7&&i<=s+n+7?{Xn:this.Yt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;if(!1===this.Yt.Rt)return;const h=Math.round(this.Yt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.I,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Xt),e(t,h,0,i.width))}}class rt{constructor(t){this.Zn={ct:0,I:"rgba(0, 0, 0, 0)",dt:1,Xt:0,Rt:!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.Rt()?(this.xt&&(this.ie(),this.xt=!1),this.Jn):null}}class ht extends rt{constructor(t){super(t)}ie(){this.Zn.Rt=!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.Rt())return;const n=this.Qn.At();null!==n&&(this.Zn.Rt=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.I=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Xt=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}Rt(){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.It(),this.xt=!1,this.me=!1):this.me&&(this.Ce(),this.me=!1),this.Jt}It(){this.Jt.lt(null);const t=this.be.ti().Et(),i=t.Pe(),s=this.be.At();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Ie))return;const e={x:t.jt(n.Ie),y:this.be.$t().zt(n.bt,s.Ht)},r=n.I,h=this.be.W().lineWidth,l=this.Ve(this.Re(),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.Ve(this.Re(),t.re);t.le=i.le,t.oe=i.oe,t.vt=i.vt}}Re(){return this.xe()?performance.now()-this.we:2599}Fe(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Xi().K(t,e)}Ve(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.Fe(i,e,n.de,n.pe),oe:this.Fe(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.Rt=!1;const i=this.Qn.W();if(!i.priceLineVisible||!this.Qn.Rt())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.Rt=!0,t.ct=s.Li,t.I=this.Qn.Le(s.I),t.dt=i.priceLineWidth,t.Xt=i.priceLineStyle)}}class ut extends O{constructor(t){super(),this.Qt=t}ji(t,i,s){t.Rt=!1,i.Rt=!1;const n=this.Qt;if(!n.Rt())return;const e=n.W(),r=e.lastValueVisible,h=""!==n.Ee(),l=0===e.seriesLastValueMode,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Be(o,r,l),t.Rt=0!==t.hi.length),(h||l)&&(i.hi=this.Ae(o,r,h,l),i.Rt=i.hi.length>0);const a=n.Le(o.I),_=this.Qt.ti().Xi().X(a);s.Z=_.Z,s.Li=o.Li,i.Nt=n.ti().Ut(o.Li/n.$t().qt()),t.Nt=a,t.I=_.J,i.I=_.J}Ae(t,i,s,n){let e="";const r=this.Qt.Ee();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Oe()?t.We:t.ze),e.trim()}Be(t,i,s){return i?s?this.Qt.$t().Oe()?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))}Ke(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)}Xe(){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}Xe(){return{priceRange:null===this.Je?null:this.Je.Xe(),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.Rt=!1;const i=this.sr.W();if(!this.Qn.Rt()||!i.lineVisible)return;const s=this.sr.nr();null!==s&&(t.Rt=!0,t.ct=s,t.I=i.color,t.dt=i.lineWidth,t.Xt=i.lineStyle,t.Gn=this.sr.W().id)}}class vt extends O{constructor(t,i){super(),this.be=t,this.sr=i}ji(t,i,s){t.Rt=!1,i.Rt=!1;const n=this.sr.W(),e=n.axisLabelVisible,r=""!==n.title,h=this.be;if(!e||!h.Rt())return;const l=this.sr.nr();if(null===l)return;r&&(i.hi=n.title,i.Rt=!0),i.Nt=h.ti().Ut(l/h.$t().qt()),t.hi=this.er(n.price),t.Rt=!0;const o=this.be.ti().Xi().X(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.I=a,i.I=a,s.Li=l}er(t){const i=this.be.At();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().Et().Gi()||i.Gi())return null;const s=t.At();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.I??(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.I??(d?e:r),pr:c.Nt??(d?h:a),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).I??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.I??i.color,wt:e.I??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).I??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Xs().kr(t),this.be=t,this.Dr=gt[t.Ir()]}Vr(t,i){return this.Dr(this.Tr,this.be.W(),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.Rr=[],this.Fr=new Map,this.Lr=new Map,this.Er=[]}Br(){return this.Ar()>0?this.Rr[this.Rr.length-1]:null}Or(){return this.Ar()>0?this.Wr(0):null}Gs(){return this.Ar()>0?this.Wr(this.Rr.length-1):null}Ar(){return this.Rr.length}Gi(){return 0===this.Ar()}De(t){return null!==this.zr(t,0)}kr(t){return this.$r(t)}$r(t,i=0){const s=this.zr(t,i);return null===s?null:{...this.Hr(s),Ie:this.Wr(s)}}Nr(){return this.Rr}Ur(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.qr(t,i,e))}return n}lt(t){this.Lr.clear(),this.Fr.clear(),this.Rr=t,this.Er=t.map(t=>t.Ie)}jr(){return this.Er}Wr(t){return this.Rr[t].Ie}Hr(t){return this.Rr[t]}zr(t,i){const s=this.Yr(t);if(null===s&&0!==i)switch(i){case-1:return this.Kr(t);case 1:return this.Gr(t);default:throw new TypeError("Unknown search mode")}return s}Kr(t){let i=this.Xr(t);return i>0&&(i-=1),i!==this.Rr.length&&this.Wr(i)<t?i:null}Gr(t){const i=this.Zr(t);return i!==this.Rr.length&&t<this.Wr(i)?i:null}Yr(t){const i=this.Xr(t);return i===this.Rr.length||t<this.Rr[i].Ie?null:i}Xr(t){return yt(this.Rr,t,(t,i)=>t.Ie<i)}Zr(t){return St(this.Rr,t,(t,i)=>t.Ie>i)}Jr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Rr[e].Ht[s];Number.isNaN(t)||(null===n?n={Qr:t,th:t}:(t<n.Qr&&(n.Qr=t),t>n.th&&(n.th=t)))}return n}qr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Or()),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.Xr(h),e=this.Zr(Math.min(o,a,i));n=Tt(n,this.Jr(t,e,s))}let u=this.Fr.get(s);void 0===u&&(u=new Map,this.Fr.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.Xr(i*Ct),n=this.Zr((i+1)*Ct-1);e=this.Jr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Xr(_),i=this.Zr(o);n=Tt(n,this.Jr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{Qr:Math.min(t.Qr,i.Qr),th:Math.max(t.th,i.th)}}const kt={setLineStyle:n};class Dt{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class It{constructor(t){this.Vn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Vn?.eh===t)return this.Vn.rh;const i=new Dt(t);return this.Vn={eh:t,rh:i},i}hh(){return this.nh.zOrder?.()??"normal"}}class Vt{constructor(t){this.oh=null,this.ah=t}_h(){return this.ah}zs(){this.ah.updateAllViews?.()}$s(){const t=this.ah.paneViews?.()??[];if(this.oh?.eh===t)return this.oh.rh;const i=t.map(t=>new It(t));return this.oh={eh:t,rh:i},i}Kn(t,i){return this.ah.hitTest?.(t,i)??null}}let Rt=class extends Vt{cs(){return[]}};class Ft{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Vn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Vn?.eh===t)return this.Vn.rh;const i=new Ft(t);return this.Vn={eh:t,rh:i},i}hh(){return this.nh.zOrder?.()??"normal"}}function Et(t){return{hi:t.text(),Li:t.coordinate(),Fi:t.fixedCoordinate?.(),I:t.textColor(),Z:t.backColor(),Rt:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Bt{constructor(t,i){this.Jt=new $,this.uh=t,this.dh=i}Dt(){return this.Jt.lt({ts:this.dh.ts(),...Et(this.uh)}),this.Jt}}class At extends O{constructor(t,i){super(),this.uh=t,this.Yi=i}ji(t,i,s){const n=Et(this.uh);s.Z=n.Z,t.I=n.I;const e=2/12*this.Yi.P();s.Di=e,s.Ii=e,s.Li=n.Li,s.Fi=n.Fi,t.hi=n.hi,t.Rt=n.Rt,t.mi=n.mi}}class Ot extends Vt{constructor(t,i){super(t),this.ph=null,this.fh=null,this.mh=null,this.wh=null,this.be=i}ds(){const t=this.ah.timeAxisViews?.()??[];if(this.ph?.eh===t)return this.ph.rh;const i=this.be.ti().Et(),s=t.map(t=>new Bt(t,i));return this.ph={eh:t,rh:s},s}Hs(){const t=this.ah.priceAxisViews?.()??[];if(this.fh?.eh===t)return this.fh.rh;const i=this.be.$t(),s=t.map(t=>new At(t,i));return this.fh={eh:t,rh:s},s}gh(){const t=this.ah.priceAxisPaneViews?.()??[];if(this.mh?.eh===t)return this.mh.rh;const i=t.map(t=>new Lt(t));return this.mh={eh:t,rh:i},i}bh(){const t=this.ah.timeAxisPaneViews?.()??[];if(this.wh?.eh===t)return this.wh.rh;const i=t.map(t=>new Lt(t));return this.wh={eh:t,rh:i},i}Mh(t,i){return this.ah.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.hh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.gh()}function Ht(t){return t.bh()}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.yh=[],this.Sh=new ht(this),this.xh=null,this.Ch=null,this.Ph=null,this.Th=[],this.Ps=s,this.kh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.kh)&&(this.xh=new at(this)),this.Dh(),this.nh=n(this,this.ti(),e)}m(){null!==this.Ph&&clearTimeout(this.Ph)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().Et().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().Et().Pe(),e=this.At();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Br();if(null===t)return i;r=t,h=t.Ie}else{const t=this.Yt.$r(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Ie),null===r)return i;h=t.Ie}const l=r.Ht[3],o=this.Ih().Vr(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.Rh(l,e.Ht),I:o.dr,Li:a,Ie:h}}Ih(){return null!==this.Ch||(this.Ch=new bt(this)),this.Ch}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Fh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Dh(),this.ti().Lh()),this.ti().Eh(this),this.ti().Bh(),this.nh.Tt("options")}lt(t,i){this.Yt.lt(t),this.nh.Tt("data"),null!==this.xh&&(i&&i.Ah?this.xh.ye():0===t.length&&this.xh.Me());const s=this.ti().Nn(this);this.ti().Oh(s),this.ti().Eh(this),this.ti().Bh(),this.ti().ar()}Wh(t){const i=new mt(this,t);return this.yh.push(i),this.ti().Eh(this),i}zh(t){const i=this.yh.indexOf(t);-1!==i&&this.yh.splice(i,1),this.ti().Eh(this)}$h(){return this.yh}Ir(){return this.kh}At(){const t=this.Hh();return null===t?null:{Ht:t.Ht[3],Nh:t.gt}}Hh(){const t=this.ti().Et().Pe();if(null===t)return null;const i=t.Uh();return this.Yt.$r(i,1)}Xs(){return this.Yt}qh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.kh||"Candlestick"===this.kh||"Custom"===this.kh?{jh:i.Ht[0],Yh:i.Ht[1],Kh:i.Ht[2],Gh:i.Ht[3]}:i.Ht[3]}Xh(t){const i=[];Wt(this.Th,zt,"top",i);const s=this.xh;return null!==s&&s.Rt()?(null===this.Ph&&s.xe()&&(this.Ph=setTimeout(()=>{this.Ph=null,this.ti().Zh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Jh()||t.push(this.Sh),t.push(this.nh,this.rr);const i=this.yh.map(t=>t._r());return t.push(...i),Wt(this.Th,zt,"normal",t),t}Qh(){return this.tl(zt,"bottom")}il(t){return this.tl($t,t)}sl(t){return this.tl(Ht,t)}nl(t,i){return this.Th.map(s=>s.Kn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.yh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Jh())return[];const s=[...this.ws];for(const t of this.yh)s.push(t.cr());return this.Th.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.Th.forEach(i=>{t.push(...i.ds())}),t}Mh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.el(t,i);return null===s?null:s.Xe()});return pt.Ze(s)}return this.el(t,i)}eh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}rl(){return this.hl}zs(){this.nh.Tt();for(const t of this.ws)t.Tt();for(const t of this.yh)t.Tt();this.rr.Tt(),this.Sh.Tt(),this.xh?.Tt(),this.Th.forEach(t=>t.zs())}$t(){return l(super.$t())}Bt(t){if(!(("Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ll(),Nt:this.ol(),Wt:this.al(),Ot:this._l(t)}}Ee(){return this.Ps.title}Rt(){return this.Ps.visible}ul(t){this.Th.push(new Ot(t,this))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t)}dl(){if("Custom"===this.kh)return t=>this.nh.pl(t)}fl(){if("Custom"===this.kh)return t=>this.nh.vl(t)}ml(){return this.Yt.jr()}Jh(){return!j(this.$t().wl())}el(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh||"Histogram"===this.kh?[3]:[2,1],n=this.Yt.Ur(t,i,s);let e=null!==n?new dt(n.Qr,n.th):null,r=null;if("Histogram"===this.Ir()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.Th.forEach(s=>{const n=s.Mh(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)}ll(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}ol(){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}al(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}_l(t){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Ih().Vr(t).dr}Dh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.hl={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.hl=new Q(this.Ps.priceFormat.precision);break;case"percent":this.hl=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.hl=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.gl()}tl(t,i){const s=[];return Wt(this.Th,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}bl(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.At();if(null===r)return n;const h=e.zt(t,r),l=s.Ml().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.Rt())return t;const e=n.$t(),r=n.Xs();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=o(n.At()),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 Kt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Xt(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.yl){t.strokeStyle=h.Sl,n(t,h.xl),t.beginPath();for(const n of h.Cl){const e=Math.round(n.Pl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.Tl){t.strokeStyle=h.kl,n(t,h.Dl),t.beginPath();for(const s of h.Il){const n=Math.round(s.Pl*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={Tl:t.horzLines.visible,yl:t.vertLines.visible,kl:t.horzLines.color,Sl:t.vertLines.color,Dl:t.horzLines.style,xl:t.vertLines.style,Il:this.Pt.ks().Vl(),Cl:(this.Pt.ti().Et().Vl()||[]).map(t=>({Pl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.nh=new Jt(t)}_r(){return this.nh}}const ti={Rl:4,Fl: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.Fl)+i.Rl;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.Rl)-i.Fl;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.Rl+s;return{Rl:n,Fl:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Ll=t,this.El=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.Bl=[2,2.5,2];else{this.Bl=[];for(let t=this.Ll;1!==t;){if(t%2==0)this.Bl.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Bl.push(2,2.5),t/=5}if(this.Bl.length>100)throw new Error("something wrong with base")}}}Al(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.El[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.El[++r%this.El.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Bl.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Bl[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Bl[++r%this.Bl.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Ol=[],this.Yi=t,this.Ll=i,this.Wl=s,this.zl=n}Al(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.$l()/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.Al(t,i,n),r.Al(t,i,n),h.Al(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)}Hl(){const t=this.Yi,i=t.At();if(null===i)return void(this.Ol=[]);const s=t.qt(),n=this.Wl(s-1,i),e=this.Wl(0,i),r=this.Yi.W().entireTextOnly?this.Nl()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Ol=[]);const _=this.Al(o,a);if(this.Ul(i,_,o,a,h,l),t.ql()&&this.jl(_,a,o)){const t=this.Yi.Yl();this.Kl(i,_,h,l,t,2*t)}const u=this.Ol.map(t=>t.Gl),c=this.Yi.Xl(u);for(let t=0;t<this.Ol.length;t++)this.Ol[t].Zl=c[t]}Vl(){return this.Ol}Nl(){return this.Yi.P()}$l(){return Math.ceil(2.5*this.Nl())}Ul(t,i,s,n,e,r){const h=this.Ol,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.zl(c,t,!0);null!==_&&Math.abs(s-_)<this.$l()||(s<e||s>r||(u<h.length?(h[u].Pl=s,h[u].Zl=l.Jl(c),h[u].Gl=c):h.push({Pl:s,Zl:l.Jl(c),Gl:c}),u++,_=s,l.Ql()&&(i=this.Al(c*a,n))))}h.length=u}Kl(t,i,s,n,e,r){const h=this.Ol,l=this.io(t,s,e,r),o=this.io(t,n,-r,-e),a=this.zl(0,t,!0)-this.zl(i,t,!0);h.length>0&&h[0].Pl-l.Pl<a/2&&h.shift(),h.length>0&&o.Pl-h[h.length-1].Pl<a/2&&h.pop(),h.unshift(l),h.push(o)}io(t,i,s,n){const e=(s+n)/2,r=this.Wl(i+s,t),h=this.Wl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.Al(o,l)),_=this.Wl(i+e,t),u=_-_%a,c=this.zl(u,t,!0);return{Zl:this.Yi.Jl(u),Pl:c,Gl:u}}jl(t,i,s){let n=o(this.Yi.tr());return this.Yi.Ql()&&(n=oi(n,this.Yi.so())),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.no=0,this.eo=null,this.Je=null,this.ro=null,this.ho={lo:!1,oo:null},this.ao=!1,this._o=0,this.uo=0,this.co=new a,this.do=new a,this.po=[],this.fo=null,this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.hl=fi,this.Mo=ai(null),this.yo=t,this.Ps=i,this.So=s,this.xo=n,this.Co=e,this.Po=new ui(this,100,this.To.bind(this),this.ko.bind(this))}wl(){return this.yo}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.gl(),void 0!==t.mode&&this.Do({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.Io(),this.mo=null}}Vo(){return this.Ps.autoScale}Ro(){return this.ao}Ql(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Fo(){return 3===this.Ps.mode}so(){return this.Mo}se(){return{nn:this.Ps.autoScale,Lo:this.Ps.invertScale,se:this.Ps.mode}}Do(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.ho.lo=!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.Mo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.Mo),null!==s&&this.Eo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.Mo),null!==s&&this.Eo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.gl(),n&&(3===i.se||this.Fo())&&this.gl(),void 0!==t.Lo&&i.Lo!==t.Lo&&(this.Ps.invertScale=t.Lo,this.Bo()),this.do.p(i,this.se())}Ao(){return this.do}P(){return this.So.fontSize}qt(){return this.no}Oo(t){this.no!==t&&(this.no=t,this.Io(),this.mo=null)}Wo(){if(this.eo)return this.eo;const t=this.qt()-this.zo()-this.$o();return this.eo=t,t}tr(){return this.Ho(),this.Je}Eo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.mo=null,this.Je=t)}No(t){this.Eo(t),this.Uo(null!==t)}Gi(){return this.Ho(),0===this.no||!this.Je||this.Je.Gi()}qo(t){return this.Lo()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Fo()&&(t=ni(t,i)),this.ko(t,i)}jo(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();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.no-1-o;e.ct=u}}Ko(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s];let h=e.jh,l=e.Yh,o=e.Kh,u=e.Gh;null!==d&&(h=d(e.jh,i),l=d(e.Yh,i),o=d(e.Kh,i),u=d(e.Gh,i));let c=n+_*(h-r),p=a?c:this.no-1-c;e.Go=p,c=n+_*(l-r),p=a?c:this.no-1-c,e.Xo=p,c=n+_*(o-r),p=a?c:this.no-1-c,e.Zo=p,c=n+_*(u-r),p=a?c:this.no-1-c,e.Jo=p}}Ds(t,i){const s=this.To(t,i);return this.Qo(s,i)}Qo(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Fo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}Ml(){return this.po}Vt(){return this.vo||(this.vo=ci(this.po)),this.vo}ta(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.gl(),this.ia())}sa(t){const i=this.po.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.po.splice(i,1),0===this.po.length&&(this.Do({nn:!0}),this.Eo(null)),this.gl(),this.ia()}At(){let t=null;for(const i of this.po){const s=i.At();null!==s&&((null===t||s.Nh<t.Nh)&&(t=s))}return null===t?null:t.Ht}Lo(){return this.Ps.invertScale}Vl(){const t=null===this.At();if(null!==this.mo&&(t||this.mo.na===t))return this.mo.Vl;this.Po.Hl();const i=this.Po.Vl();return this.mo={Vl:i,na:t},this.co.p(),i}ea(){return this.co}ra(t){this.Oe()||this.Fo()||null===this.wo&&null===this.ro&&(this.Gi()||(this.wo=this.no-t,this.ro=l(this.tr()).Ue()))}ha(t){if(this.Oe()||this.Fo())return;if(null===this.wo)return;this.Do({nn:!1}),(t=this.no-t)<0&&(t=0);let i=(this.wo+.2*(this.no-1))/(t+.2*(this.no-1));const s=l(this.ro).Ue();i=Math.max(i,.1),s.Ke(i),this.Eo(s)}la(){this.Oe()||this.Fo()||(this.wo=null,this.ro=null)}oa(t){this.Vo()||null===this.bo&&null===this.ro&&(this.Gi()||(this.bo=t,this.ro=l(this.tr()).Ue()))}aa(t){if(this.Vo())return;if(null===this.bo)return;const i=l(this.tr()).Ye()/(this.Wo()-1);let s=t-this.bo;this.Lo()&&(s*=-1);const n=s*i,e=l(this.ro).Ue();e.Ge(n),this.Eo(e,!0),this.mo=null}_a(){this.Vo()||null!==this.bo&&(this.bo=null,this.ro=null)}rl(){return this.hl||this.gl(),this.hl}Zi(t,i){switch(this.Ps.mode){case 2:return this.ua(ii(t,i));case 3:return this.rl().format(ni(t,i));default:return this.er(t)}}Jl(t){switch(this.Ps.mode){case 2:return this.ua(t);case 3:return this.rl().format(t);default:return this.er(t)}}Xl(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.rl().formatTickmarks(t);default:return this.da(t)}}Vh(t){return this.er(t,l(this.fo).rl())}Rh(t,i){return t=ii(t,i),this.ua(t,pi)}pa(){return this.po}fa(t){this.ho={oo:t,lo:!1}}zs(){this.po.forEach(t=>t.zs())}ql(){return this.Ps.ensureEdgeTickMarksVisible&&this.Vo()}Yl(){return this.P()/2}gl(){this.mo=null;let t=1/0;this.fo=null;for(const i of this.po)i.ls()<t&&(t=i.ls(),this.fo=i);let i=100;null!==this.fo&&(i=Math.round(this.fo.eh())),this.hl=fi,this.Oe()?(this.hl=pi,i=100):this.Fo()?(this.hl=new Z(100,1),i=100):null!==this.fo&&(this.hl=this.fo.rl()),this.Po=new ui(this,i,this.To.bind(this),this.ko.bind(this)),this.Po.Hl()}ia(){this.vo=null}va(){return null===this.fo||this.Oe()||this.Fo()?1:1/this.fo.eh()}Xi(){return this.Co}Uo(t){this.ao=t}zo(){return this.Lo()?this.Ps.scaleMargins.bottom*this.qt()+this.uo:this.Ps.scaleMargins.top*this.qt()+this._o}$o(){return this.Lo()?this.Ps.scaleMargins.top*this.qt()+this._o:this.Ps.scaleMargins.bottom*this.qt()+this.uo}Ho(){this.ho.lo||(this.ho.lo=!0,this.ma())}Io(){this.eo=null}ko(t,i){if(this.Ho(),this.Gi())return 0;t=this.Ql()&&t?ri(t,this.Mo):t;const s=l(this.tr()),n=this.$o()+(this.Wo()-1)*(t-s.qe())/s.Ye();return this.qo(n)}To(t,i){if(this.Ho(),this.Gi())return 0;const s=this.qo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.$o())/(this.Wo()-1));return this.Ql()?hi(e,this.Mo):e}Bo(){this.mo=null,this.Po.Hl()}ma(){if(this.Ro()&&!this.Vo())return;const t=this.ho.oo;if(null===t)return;let i=null;const s=this.pa();let n=0,e=0;for(const r of s){if(!r.Rt())continue;const s=r.At();if(null===s)continue;const h=r.Mh(t.Uh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.Mo);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.ql()&&(n=Math.max(n,this.Yl()),e=Math.max(e,this.Yl())),n===this._o&&e===this.uo||(this._o=n,this.uo=e,this.mo=null,this.Io()),null!==i){if(i.qe()===i.je()){const t=5*this.va();this.Ql()&&(i=oi(i,this.Mo)),i=new dt(i.qe()-t,i.je()+t),this.Ql()&&(i=li(i,this.Mo))}if(this.Ql()){const t=oi(i,this.Mo),s=ai(t);if(r=s,h=this.Mo,r.Rl!==h.Rl||r.Fl!==h.Fl){const n=null!==this.ro?oi(this.ro,this.Mo):null;this.Mo=s,i=li(t,s),null!==n&&(this.ro=li(n,s))}}this.Eo(i)}else null===this.Je&&(this.Eo(new dt(-.5,.5)),this.Mo=ai(null));var r,h}Yo(){return this.Oe()?ii:this.Fo()?ni:this.Ql()?t=>ri(t,this.Mo):null}wa(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.format(t)):i(t)}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.wa(t,this.xo.priceFormatter,i)}da(t,i){const s=this.xo.priceFormatter;return this.ga(t,this.xo.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ua(t,i){return this.wa(t,this.xo.percentageFormatter,i)}ca(t,i){const s=this.xo.percentageFormatter;return this.ga(t,this.xo.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.po=[],this.ba=new Map,this.no=0,this.Ma=0,this.ya=1,this.vo=null,this.Sa=!1,this.xa=new a,this.Th=[],this.dh=t,this.ss=i,this.Ca=new Qt(this);const s=i.W();this.Pa=this.Ta("left",s.leftPriceScale),this.ka=this.Ta("right",s.rightPriceScale),this.Pa.Ao().i(this.Da.bind(this,this.Pa),this),this.ka.Ao().i(this.Da.bind(this,this.ka),this),this.Ia(s)}Ia(t){if(t.leftPriceScale&&this.Pa.lr(t.leftPriceScale),t.rightPriceScale&&this.ka.lr(t.rightPriceScale),t.localization&&(this.Pa.gl(),this.ka.gl()),t.overlayPriceScales){const i=Array.from(this.ba.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.gl()}}}Va(t){switch(t){case"left":return this.Pa;case"right":return this.ka}return this.ba.has(t)?h(this.ba.get(t))[0].$t():null}m(){this.ti().Ra().u(this),this.Pa.Ao().u(this),this.ka.Ao().u(this),this.po.forEach(t=>{t.m&&t.m()}),this.Th=this.Th.filter(t=>{const i=t._h();return i.detached&&i.detached(),!1}),this.xa.p()}Fa(){return this.ya}La(t){this.ya=t}ti(){return this.ss}ts(){return this.Ma}qt(){return this.no}Ea(t){this.Ma=t,this.Ba()}Oo(t){this.no=t,this.Pa.Oo(t),this.ka.Oo(t),this.po.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Oo(t)}}),this.Ba()}Aa(t){this.Sa=t}Oa(){return this.Sa}Wa(){return this.po.filter(mi)}Ml(){return this.po}Un(t){const i=t.$t();return null===i||this.Pa!==i&&this.ka!==i}ta(t,i,s){this.za(t,i,s?t.ls():this.po.length)}sa(t,i){const s=this.po.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.po.splice(s,1),i||this.po.forEach((t,i)=>t._s(i));const n=l(t.$t()).wl();if(this.ba.has(n)){const i=h(this.ba.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.ba.delete(n))}const e=t.$t();e&&e.Ml().indexOf(t)>=0&&(e.sa(t),this.$a(e)),this.vo=null}jn(t){return t===this.Pa?"left":t===this.ka?"right":"overlay"}Ha(){return this.Pa}Na(){return this.ka}Ua(t,i){t.ra(i)}qa(t,i){t.ha(i),this.Ba()}ja(t){t.la()}Ya(t,i){t.oa(i)}Ka(t,i){t.aa(i),this.Ba()}Ga(t){t._a()}Ba(){this.po.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.ka.Ml().length?t=this.ka:this.ss.W().leftPriceScale.visible&&0!==this.Pa.Ml().length?t=this.Pa:0!==this.po.length&&(t=this.po[0].$t()),null===t&&(t=this.ka),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.ka:this.ss.W().leftPriceScale.visible&&(t=this.Pa),t}$a(t){null!==t&&t.Vo()&&this.Xa(t)}Za(t){const i=this.dh.Pe();t.Do({nn:!0}),null!==i&&t.fa(i),this.Ba()}Ja(){this.Xa(this.Pa),this.Xa(this.ka)}Qa(){this.$a(this.Pa),this.$a(this.ka),this.po.forEach(t=>{this.Un(t)&&this.$a(t.$t())}),this.Ba(),this.ss.ar()}Vt(){return null===this.vo&&(this.vo=ci(this.po)),this.vo}t_(t,i){i=Kt(i,0,this.po.length-1);const s=this.po.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.po.splice(s,1),this.po.splice(i,0,t),this.po.forEach((t,i)=>t._s(i)),this.vo=null;for(const t of[this.Pa,this.ka])t.ia(),t.gl();this.ss.ar()}Ft(){return this.Vt().filter(mi)}i_(){return this.xa}s_(){return this.Ca}ul(t){this.Th.push(new Rt(t))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t),t.detached&&t.detached(),this.ss.ar()}n_(){return this.Th}nl(t,i){return this.Th.map(s=>s.Kn(t,i)).filter(t=>null!==t)}Xa(t){const i=t.pa();if(i&&i.length>0&&!this.dh.Gi()){const i=this.dh.Pe();null!==i&&t.fa(i)}t.zs()}za(t,i,s){let n=this.Va(i);if(null===n&&(n=this.Ta(i,this.ss.W().overlayPriceScales)),this.po.splice(s,0,t),!j(i)){const s=this.ba.get(i)||[];s.push(t),this.ba.set(i,s)}t._s(s),n.ta(t),t.us(n),this.$a(n),this.vo=null}Da(t,i,s){i.se!==s.se&&this.Xa(t)}Ta(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.Xi());return n.Oo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{e_:t.e_,r_:{Gn:t.h_.externalId},l_:t.h_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Kn){const n=t.Kn(i,s);if(null!==n)return{o_:e,r_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Vt()],e=function(t,i,s){let n,e;for(const r of t){const t=r.nl?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{h_:n,e_:e}:null}(n,i,s);if("top"===e?.h_.zOrder)return bi(e);for(const r of n){if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&!e.h_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{e_:r,o_:n.o_,r_:n.r_}}if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&e.h_.isBackground)return bi(e)}return e?.h_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Vn=new Map,this.In=new Map,this.a_=t,this.__=i,this.Rn=s}u_(t){const i=t.time,s=this.__.cacheKey(i),n=this.Vn.get(s);if(void 0!==n)return n.c_;if(this.Tn===this.Rn){const t=this.In.get(this.Dn);this.In.delete(this.Dn),this.Vn.delete(h(t)),this.Dn++,this.Tn--}const e=this.a_(t);return this.Vn.set(s,{c_:e,Bn:this.kn}),this.In.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.d_=t,this.p_=i}Uh(){return this.d_}yi(){return this.p_}f_(){return this.p_-this.d_+1}De(t){return this.d_<=t&&t<=this.p_}Ne(t){return this.d_===t.Uh()&&this.p_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.v_=new Map,this.Vn=null,this.m_=!1}w_(t){this.m_=t,this.Vn=null}g_(t,i){this.b_(i),this.Vn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.v_.get(i.timeWeight);void 0===n&&(n=[],this.v_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}M_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Vn&&this.Vn.y_===r&&e===this.Vn.S_&&s===this.Vn.x_||(this.Vn={S_:e,x_:s,Vl:this.C_(r,s,n),y_:r}),this.Vn.Vl}b_(t){if(0===t)return void this.v_.clear();const i=[];this.v_.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.v_.delete(t)}C_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.v_.keys()).sort((t,i)=>i-t)){if(!this.v_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const o=h(this.v_.get(i)),a=o.length;let _=1/0,u=-1/0;for(let i=0;i<a;i++){const h=o[i],a=h.index;for(;l<r;){const t=s[l],i=t.index;if(!(i<a&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-a>=t&&a-u>=t&&e(h))n.push(h),u=a;else if(this.m_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.P_=t}T_(){return null===this.P_?null:new Ci(Math.floor(this.P_.Uh()),Math.ceil(this.P_.yi()))}k_(){return this.P_}static D_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ii{constructor(t,i,s,n){this.Ma=0,this.I_=null,this.V_=[],this.bo=null,this.wo=null,this.R_=new Ti,this.F_=new Map,this.L_=ki.D_(),this.E_=!0,this.B_=new a,this.A_=new a,this.O_=new a,this.W_=null,this.z_=null,this.H_=new Map,this.N_=-1,this.U_=[],this.Ps=i,this.xo=s,this.q_=i.rightOffset,this.j_=i.barSpacing,this.ss=t,this.Y_(i),this.__=n,this.K_(),this.R_.w_(i.uniformDistribution),this.G_()}W(){return this.Ps}X_(t){_(this.xo,t),this.Z_(),this.K_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.J_(),this.Ps.fixRightEdge&&this.Q_(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.Y_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.j_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.G_(),this.Z_(),this.K_(),this.O_.p()}Is(t){return this.V_[t]?.time??null}ns(t){return this.V_[t]??null}tu(t,i){if(this.V_.length<1)return null;if(this.__.key(t)>this.__.key(this.V_[this.V_.length-1].time))return i?this.V_.length-1:null;const s=yt(this.V_,this.__.key(t),(t,i)=>this.__.key(t.time)<i);return this.__.key(t)<this.__.key(this.V_[s].time)?i?s:null:s}Gi(){return 0===this.Ma||0===this.V_.length||null===this.I_}iu(){return this.V_.length>0}Pe(){return this.su(),this.L_.T_()}nu(){return this.su(),this.L_.k_()}eu(){const t=this.Pe();if(null===t)return null;const i={from:t.Uh(),to:t.yi()};return this.ru(i)}ru(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.hu()),e=l(this.lu());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.tu(t.from,!0)),to:l(this.tu(t.to,!0))}}ts(){return this.Ma}Ea(t){if(!isFinite(t)||t<=0)return;if(this.Ma===t)return;const i=this.nu(),s=this.Ma;if(this.Ma=t,this.E_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.j_*t/s;this.j_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.Uh()<=0){const i=s-t;this.q_-=Math.round(i/this.j_)+1,this.E_=!0}this.au(),this._u()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.uu()+this.q_-t;return this.Ma-(i+.5)*this.j_-1}cu(t,i){const s=this.uu(),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.q_-n,r=this.Ma-(e+.5)*this.j_-1;t[i].ut=r}}du(t,i){const s=Math.ceil(this.pu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.fu(s)?this.vu(s):s}fn(t){this.E_=!0,this.q_=t,this._u(),this.ss.mu(),this.ss.ar()}wu(){return this.j_}pn(t){const i=this.j_;if(this.gu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.q_*i/this.j_;this.q_=t}this._u(),this.ss.mu(),this.ss.ar()}bu(){return this.q_}Vl(){if(this.Gi())return null;if(null!==this.z_)return this.z_;const t=this.j_,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.Uh(),n.Uh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.R_.M_(t,i,this.Ps.ignoreWhitespaceIndices,this.H_,this.N_),o=this.hu()+s,a=this.lu()-s,_=this.Mu(),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.U_.length?(s=this.U_[d],s.coord=this.jt(t.index),s.label=this.yu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.yu(t),weight:t.weight},this.U_.push(s)),this.j_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.U_.length=d,this.z_=this.U_,this.U_}Su(){let t;this.E_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.wu():this.Ps.rightOffset,this.fn(t)}xu(t){this.E_=!0,this.I_=t,this._u(),this.J_()}Cu(t,i){const s=this.pu(t),n=this.wu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.bu()+(s-this.pu(t)))}ra(t){this.bo&&this._a(),null===this.wo&&null===this.W_&&(this.Gi()||(this.wo=t,this.Pu()))}ha(t){if(null===this.W_)return;const i=Kt(this.Ma-t,0,this.Ma),s=Kt(this.Ma-l(this.wo),0,this.Ma);0!==i&&0!==s&&this.pn(this.W_.wu*i/s)}la(){null!==this.wo&&(this.wo=null,this.Tu())}oa(t){null===this.bo&&null===this.W_&&(this.Gi()||(this.bo=t,this.Pu()))}aa(t){if(null===this.bo)return;const i=(this.bo-t)/this.wu();this.q_=l(this.W_).bu+i,this.E_=!0,this._u()}_a(){null!==this.bo&&(this.bo=null,this.Tu())}ku(){this.Du(this.Ps.rightOffset)}Du(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.q_,n=performance.now();this.ss.un({Iu:t=>(t-n)/i>=1,Vu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.E_=!0,this.V_=t,this.R_.g_(t,i),this._u()}Ru(){return this.B_}Fu(){return this.A_}Lu(){return this.O_}uu(){return this.I_||0}Eu(t,i){const s=t.f_(),n=i&&this.Ps.rightOffsetPixels||0;this.gu((this.Ma-n)/s),this.q_=t.yi()-this.uu(),i&&(this.q_=n?n/this.wu():this.Ps.rightOffset),this._u(),this.E_=!0,this.ss.mu(),this.ss.ar()}Bu(){const t=this.hu(),i=this.lu();null!==t&&null!==i&&this.Eu(new Ci(t,i),!0)}Au(t){const i=new Ci(t.from,t.to);this.Eu(i)}es(t){return void 0!==this.xo.timeFormatter?this.xo.timeFormatter(t.originalTime):this.__.formatHorzItem(t.time)}G_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.H_.clear();const t=this.ss.Ks();for(const i of t)for(const t of i.ml())this.H_.set(t,!0);this.N_++}Mu(){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)}hu(){return 0===this.V_.length?null:0}lu(){return 0===this.V_.length?null:this.V_.length-1}Ou(t){return(this.Ma-1-t)/this.j_}pu(t){const i=this.Ou(t),s=this.uu()+this.q_-i;return Math.round(1e6*s)/1e6}gu(t){const i=this.j_;this.j_=t,this.au(),i!==this.j_&&(this.E_=!0,this.Wu())}su(){if(!this.E_)return;if(this.E_=!1,this.Gi())return void this.zu(ki.D_());const t=this.uu(),i=this.Ma/this.j_,s=this.q_+t,n=new Ci(s-i+1,s);this.zu(new ki(n))}au(){const t=Kt(this.j_,this.$u(),this.Hu());this.j_!==t&&(this.j_=t,this.E_=!0)}Hu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.Ma}$u(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.V_.length?this.Ma/this.V_.length:this.Ps.minBarSpacing}_u(){const t=this.Nu();null!==t&&this.q_<t&&(this.q_=t,this.E_=!0);const i=this.Uu();this.q_>i&&(this.q_=i,this.E_=!0)}Nu(){const t=this.hu(),i=this.I_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.Ma/this.j_:Math.min(2,this.V_.length))}Uu(){return this.Ps.fixRightEdge?0:this.Ma/this.j_-Math.min(2,this.V_.length)}Pu(){this.W_={wu:this.wu(),bu:this.bu()}}Tu(){this.W_=null}yu(t){let i=this.F_.get(t.weight);return void 0===i&&(i=new xi(t=>this.qu(t),this.__),this.F_.set(t.weight,i)),i.u_(t)}qu(t){return this.__.formatTickmark(t,this.xo)}zu(t){const i=this.L_;this.L_=t,Pi(i.T_(),this.L_.T_())||this.B_.p(),Pi(i.k_(),this.L_.k_())||this.A_.p(),this.Wu()}Wu(){this.z_=null}Z_(){this.Wu(),this.F_.clear()}K_(){this.__.updateFormatter(this.xo)}J_(){if(!this.Ps.fixLeftEdge)return;const t=this.hu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.Uh()-t;if(s<0){const t=this.q_-s-1;this.fn(t)}this.au()}Q_(){this._u(),this.au()}fu(t){return!this.Ps.ignoreWhitespaceIndices||(this.H_.get(t)||!1)}vu(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.lu();for(;s;){const t=i.next().value;if(this.H_.get(t))return t;if(t<0||t>s)break}return t}Y_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.j_);this.ss.fn(i)}}}var Vi,Ri,Fi,Li,Ei;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Vi||(Vi={}));class Bi{constructor(t,i,s){this.ju=[],this.Yu=[],this.Ma=0,this.Ku=null,this.Gu=new a,this.Xu=new a,this.Zu=null,this.Ju=t,this.Ps=i,this.__=s,this.Co=new S(this.Ps.layout.colorParsers),this.Qu=new b(this),this.dh=new Ii(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.tc=new Yt(i.crosshair),i.addDefaultPane&&(this.sc(0),this.ju[0].La(2)),this.nc=this.ec(0),this.rc=this.ec(1)}Lh(){this.hc(Y.bn())}ar(){this.hc(Y.gn())}Zh(){this.hc(new Y(1))}Eh(t){const i=this.lc(t);this.hc(i)}oc(){return this.Ku}ac(t){if(this.Ku?.e_===t?.e_&&this.Ku?.r_?.Gn===t?.r_?.Gn)return;const i=this.Ku;this.Ku=t,null!==i&&this.Eh(i.e_),null!==t&&t.e_!==i?.e_&&this.Eh(t.e_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.ju.forEach(i=>i.Ia(t)),void 0!==t.timeScale&&this.dh.lr(t.timeScale),void 0!==t.localization&&this.dh.X_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Gu.p(),this.nc=this.ec(0),this.rc=this.ec(1),this.Lh()}_c(t,i,s=0){const n=this.ju[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Ia({leftPriceScale:i}),this.Gu.p(),void this.Lh();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Ia({rightPriceScale:i}),this.Gu.p(),void this.Lh();const e=this.uc(t,s);null!==e&&(e.$t.lr(i),this.Gu.p())}uc(t,i){const s=this.ju[i];if(void 0===s)return null;const n=s.Va(t);return null!==n?{Us:s,$t:n}:null}Et(){return this.dh}qs(){return this.ju}cc(){return this.Ct}dc(){return this.Xu}fc(t,i){t.Oo(i),this.mu()}Ea(t){this.Ma=t,this.dh.Ea(this.Ma),this.ju.forEach(i=>i.Ea(t)),this.mu()}vc(t){1!==this.ju.length&&(r(t>=0&&t<this.ju.length,"Invalid pane index"),this.ju.splice(t,1),this.Lh())}mc(t,i){if(this.ju.length<2)return;r(t>=0&&t<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju.reduce((t,i)=>t+i.Fa(),0),e=this.ju.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.ju.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.ju.length-1;for(const t of this.ju)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()}wc(t,i){r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju[i];this.ju[t]=n,this.ju[i]=s,this.Lh()}gc(t,i){if(r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index"),t===i)return;const[s]=this.ju.splice(t,1);this.ju.splice(i,0,s),this.Lh()}Ua(t,i,s){t.Ua(i,s)}qa(t,i,s){t.qa(i,s),this.Bh(),this.hc(this.bc(t,2))}ja(t,i){t.ja(i),this.hc(this.bc(t,2))}Ya(t,i,s){i.Vo()||t.Ya(i,s)}Ka(t,i,s){i.Vo()||(t.Ka(i,s),this.Bh(),this.hc(this.bc(t,2)))}Ga(t,i){i.Vo()||(t.Ga(i),this.hc(this.bc(t,2)))}Za(t,i){t.Za(i),this.hc(this.bc(t,2))}Mc(t){this.dh.ra(t)}yc(t,i){const s=this.Et();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Cu(t,i),this.mu()}Sc(t){this.xc(0),this.Cc(t),this.Pc()}Tc(t){this.dh.ha(t),this.mu()}kc(){this.dh.la(),this.ar()}xc(t){this.dh.oa(t)}Cc(t){this.dh.aa(t),this.mu()}Pc(){this.dh._a(),this.ar()}Ks(){return this.Yu}Dc(t,i,s,n,e){this.Ct.Rs(t,i);let r=NaN,h=this.dh.du(t,!0);const l=this.dh.Pe();null!==l&&(h=Math.min(Math.max(l.Uh(),h),l.yi()));const o=n.ks(),a=o.At();if(null!==a&&(r=o.Ds(i,a)),r=this.tc.bl(r,h,n),this.Ct.Bs(h,r,n),this.Zh(),!e){const e=Si(n,t,i);this.ac(e&&{e_:e.e_,r_:e.r_,l_:e.l_||null}),this.Xu.p(this.Ct.Lt(),{x:t,y:i},s)}}Ic(t,i,s){const n=s.ks(),e=n.At(),r=n.zt(t,l(e)),h=this.dh.tu(i,!0),o=this.dh.jt(l(h));this.Dc(o,r,null,s,!0)}Vc(t){this.cc().Os(),this.Zh(),t||this.Xu.p(null,null,null)}Bh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.Es();this.Dc(i,s,null,t)}this.Ct.zs()}Rc(t,i,s){const n=this.dh.Is(0);void 0!==i&&void 0!==s&&this.dh.Tt(i,s);const e=this.dh.Is(0),r=this.dh.uu(),h=this.dh.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.__.key(n)>this.__.key(e),o=null!==t&&t>r&&!l,a=this.dh.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.dh.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.dh.fn(this.dh.bu()-i)}}this.dh.xu(t)}Oh(t){null!==t&&t.Qa()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.ju.find(i=>i.Vt().includes(t));return void 0===i?null:i}mu(){this.ju.forEach(t=>t.Qa()),this.Bh()}m(){this.ju.forEach(t=>t.m()),this.ju.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Fc(){return this.Qu}Yn(){return this.Qu.W()}Ra(){return this.Gu}Lc(t,i){const s=this.sc(i);this.Ec(t,s),this.Yu.push(t),1===this.Yu.length?this.Lh():this.ar()}Bc(t){const i=this.Nn(t),s=this.Yu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Yu.splice(s,1),n.sa(t),t.m&&t.m(),this.dh.G_();const e=this.ju.length;this.Ac(n),this.ju.length<e&&this.Lh()}Fh(t,i){const s=l(this.Nn(t));s.sa(t,!0),s.ta(t,i,!0)}Bu(){const t=Y.gn();t.hn(),this.hc(t)}Oc(t){const i=Y.gn();i._n(t),this.hc(i)}dn(){const t=Y.gn();t.dn(),this.hc(t)}pn(t){const i=Y.gn();i.pn(t),this.hc(i)}fn(t){const i=Y.gn();i.fn(t),this.hc(i)}un(t){const i=Y.gn();i.un(t),this.hc(i)}ln(){const t=Y.gn();t.ln(),this.hc(t)}Wc(){return this.Ps.rightPriceScale.visible?"right":"left"}zc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.$c(t))return;const s=l(this.Nn(t));s.sa(t);const n=this.sc(i);this.Ec(t,n),0===s.Ml().length&&this.Ac(s),this.Lh()}Hc(){return this.rc}q(){return this.nc}Ut(t){const i=this.rc,s=this.nc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Zu||this.Zu.wr!==s||this.Zu.gr!==i)this.Zu={wr:s,gr:i,Nc:new Map};else{const i=this.Zu.Nc.get(t);if(void 0!==i)return i}const n=this.Co.it(s,i,t/100);return this.Zu.Nc.set(t,n),n}Uc(t){return this.ju.indexOf(t)}Xi(){return this.Co}qc(){return this.jc()}jc(t){const i=new wi(this.dh,this);this.ju.push(i);const s=t??this.ju.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.hc(n),i}sc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.ju.length,t))<this.ju.length?this.ju[t]:this.jc(t)}$c(t){return this.ju.findIndex(i=>i.Wa().includes(t))}bc(t,i){const s=new Y(i);if(null!==t){const n=this.ju.indexOf(t);s.tn(n,{sn:i})}return s}lc(t,i){return void 0===i&&(i=2),this.bc(this.Nn(t),i)}hc(t){this.Ju&&this.Ju(t),this.ju.forEach(t=>t.s_()._r().Tt())}Ec(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.Wc();i.ta(t,n),j(n)||t.lr(t.W())}ec(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Ac(t){!t.Oa()&&0===t.Ml().length&&this.ju.length>1&&this.ju.splice(this.Uc(t),1)}}function Ai(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 Oi(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"}(Ri||(Ri={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Fi||(Fi={})),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"}(Ei||(Ei={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>X(zi(t),4))(t)).replace(/yy/g,(t=>X(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=>X((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>X((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Yc=t,this.Kc=i}u_(t){return $i(t,this.Yc,this.Kc)}}class Ni{constructor(t){this.Gc=t||"%h:%m:%s"}u_(t){return this.Gc.replace("%h",X(t.getUTCHours(),2)).replace("%m",X(t.getUTCMinutes(),2)).replace("%s",X(t.getUTCSeconds(),2))}}const Ui={Xc:"yyyy-MM-dd",Zc:"%h:%m:%s",Jc:" ",Qc:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.td=new Hi(i.Xc,i.Qc),this.sd=new Ni(i.Zc),this.nd=i.Jc}u_(t){return`${this.td.u_(t)}${this.nd}${this.sd.u_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Ki=[{ed:(Gi=1,1e3*Gi),rd:10},{ed:Yi(1),rd:20},{ed:Yi(5),rd:21},{ed:Yi(30),rd:22},{ed:ji(1),rd:30},{ed:ji(3),rd:31},{ed:ji(6),rd:32},{ed:ji(12),rd:33}];var Gi;function Xi(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=Ki.length-1;s>=0;--s)if(Math.floor(i.getTime()/Ki[s].ed)!==Math.floor(t.getTime()/Ki[s].ed))return Ki[s].rd;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Oi(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{hd:Math.round(s.getTime()/1e3),ld:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{hd: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))}class ss{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:Oi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"hd"in t?t.hd:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ld?new Date(1e3*i.hd).getTime():new Date(Date.UTC(i.ld.year,i.ld.month-1,i.ld.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Oi(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this.od=new qi({Xc:i,Zc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Jc:" ",Qc:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.u_(new Date(1e3*i.hd))}formatTickmark(t,i){const s=function(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}}(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.ld?new Date(1e3*t.hd):new Date(Date.UTC(t.ld.year,t.ld.month-1,t.ld.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.hd,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).hd);null!==n&&(i.timeWeight=Xi(h,n)),e+=Zi(i.time).hd-(s||Zi(i.time).hd),s=Zi(i.time).hd,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.hd-i));t[0].timeWeight=Xi(new Date(1e3*t[0].time.hd),s)}}(t,i)}static ad(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function ns(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 es(t,i){return t.width===i.width&&t.height===i.height}var rs=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 hs=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=ns({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 ns({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=ns(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;es(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=ns(this._transformBitmapSize(t,this._canvasElementClientSize)),n=es(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&es(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=ls(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new rs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=ls(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 ns({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):ns({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=ns({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function ls(t){return t.ownerDocument.defaultView}var os=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 as(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 os(e,s,n)}const _s="undefined"!=typeof window;function us(){return!!_s&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function cs(){return!!_s&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ds(t){return t+t%2}function ps(t){_s&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class fs{constructor(t,i,s){this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.md=null,this.wd=!1,this.gd=null,this.bd=null,this.Md=!1,this.yd=!1,this.Sd=!1,this.xd=null,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Id=null,this.Vd=0,this.Rd=!1,this.Fd=!1,this.Ld=!1,this.Ed=0,this.Bd=null,this.Ad=!cs(),this.Od=t=>{this.Wd(t)},this.zd=t=>{if(this.$d(t)){const i=this.Hd(t);if(++this.pd,this.fd&&this.pd>1){const{Nd:s}=this.Ud(ws(t),this.vd);s<30&&!this.Sd&&this.qd(i,this.Yd.jd),this.Kd()}}else{const i=this.Hd(t);if(++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Xd),this.Zd()}}},this.Jd=t,this.Yd=i,this.Ps=s,this.Qd()}m(){null!==this.xd&&(this.xd(),this.xd=null),null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),this.tp(),this.Zd()}ip(t){this.Td&&this.Td();const i=this.sp.bind(this);if(this.Td=()=>{this.Jd.removeEventListener("mousemove",i)},this.Jd.addEventListener("mousemove",i),this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.np),this.Ad=!0}Zd(){null!==this.ud&&clearTimeout(this.ud),this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Kd(){null!==this.fd&&clearTimeout(this.fd),this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}sp(t){if(this.Ld||null!==this.bd)return;if(this.$d(t))return;const i=this.Hd(t);this.Gd(i,this.Yd.ep),this.Ad=!0}rp(t){const i=bs(t.changedTouches,l(this.Bd));if(null===i)return;if(this.Ed=gs(t),null!==this.Id)return;if(this.Fd)return;this.Rd=!0;const s=this.Ud(ws(i),l(this.bd)),{hp:n,lp:e,Nd:r}=s;if(this.Md||!(r<5)){if(!this.Md){const t=.5*n,i=e>=t&&!this.Ps.op(),s=t>e&&!this.Ps.ap();i||s||(this.Fd=!0),this.Md=!0,this.Sd=!0,this.tp(),this.Kd()}if(!this.Fd){const s=this.Hd(t,i);this.qd(s,this.Yd._p),ms(t)}}}up(t){if(0!==t.button)return;const i=this.Ud(ws(t),l(this.gd)),{Nd:s}=i;if(s>=5&&(this.yd=!0,this.Zd()),this.yd){const i=this.Hd(t);this.Gd(i,this.Yd.cp)}}Ud(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{hp:s,lp:n,Nd:s+n}}dp(t){let i=bs(t.changedTouches,l(this.Bd));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Bd=null,this.Ed=gs(t),this.tp(),this.bd=null,this.Dd&&(this.Dd(),this.Dd=null);const s=this.Hd(t,i);if(this.qd(s,this.Yd.pp),++this.pd,this.fd&&this.pd>1){const{Nd:t}=this.Ud(ws(i),this.vd);t<30&&!this.Sd&&this.qd(s,this.Yd.jd),this.Kd()}else this.Sd||(this.qd(s,this.Yd.fp),this.Yd.fp&&ms(t));0===this.pd&&ms(t),0===t.touches.length&&this.wd&&(this.wd=!1,ms(t))}Wd(t){if(0!==t.button)return;const i=this.Hd(t);if(this.gd=null,this.Ld=!1,this.kd&&(this.kd(),this.kd=null),us()){this.Jd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Od)}if(!this.$d(t))if(this.Gd(i,this.Yd.vp),++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Xd),this.Zd()}else this.yd||this.Gd(i,this.Yd.mp)}tp(){null!==this.md&&(clearTimeout(this.md),this.md=null)}wp(t){if(null!==this.Bd)return;const i=t.changedTouches[0];this.Bd=i.identifier,this.Ed=gs(t);const s=this.Jd.ownerDocument.documentElement;this.Sd=!1,this.Md=!1,this.Fd=!1,this.bd=ws(i),this.Dd&&(this.Dd(),this.Dd=null);{const i=this.rp.bind(this),n=this.dp.bind(this);this.Dd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.tp(),this.md=setTimeout(this.gp.bind(this,t),240)}const n=this.Hd(t,i);this.qd(n,this.Yd.bp),this.fd||(this.pd=0,this.fd=setTimeout(this.Kd.bind(this),500),this.vd=ws(i))}Mp(t){if(0!==t.button)return;const i=this.Jd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Od),this.yd=!1,this.gd=ws(t),this.kd&&(this.kd(),this.kd=null);{const t=this.up.bind(this),s=this.Wd.bind(this);this.kd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ld=!0,this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.yp),this.ud||(this._d=0,this.ud=setTimeout(this.Zd.bind(this),500),this.dd=ws(t))}Qd(){this.Jd.addEventListener("mouseenter",this.ip.bind(this)),this.Jd.addEventListener("touchcancel",this.tp.bind(this));{const t=this.Jd.ownerDocument,i=t=>{this.Yd.Sp&&(t.composed&&this.Jd.contains(t.composedPath()[0])||t.target&&this.Jd.contains(t.target)||this.Yd.Sp())};this.Cd=()=>{t.removeEventListener("touchstart",i)},this.xd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Pd=()=>{this.Jd.removeEventListener("dblclick",this.zd)},this.Jd.addEventListener("dblclick",this.zd)),this.Jd.addEventListener("mouseleave",this.xp.bind(this)),this.Jd.addEventListener("touchstart",this.wp.bind(this),{passive:!0}),ps(this.Jd),this.Jd.addEventListener("mousedown",this.Mp.bind(this)),this.Cp(),this.Jd.addEventListener("touchmove",()=>{},{passive:!1})}Cp(){void 0===this.Yd.Pp&&void 0===this.Yd.Tp&&void 0===this.Yd.kp||(this.Jd.addEventListener("touchstart",t=>this.Dp(t.touches),{passive:!0}),this.Jd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Id&&void 0!==this.Yd.Tp){const i=vs(t.touches[0],t.touches[1])/this.Vd;this.Yd.Tp(this.Id,i),ms(t)}},{passive:!1}),this.Jd.addEventListener("touchend",t=>{this.Dp(t.touches)}))}Dp(t){1===t.length&&(this.Rd=!1),2!==t.length||this.Rd||this.wd?this.Ip():this.Vp(t)}Vp(t){const i=this.Jd.getBoundingClientRect()||{left:0,top:0};this.Id={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.Vd=vs(t[0],t[1]),void 0!==this.Yd.Pp&&this.Yd.Pp(),this.tp()}Ip(){null!==this.Id&&(this.Id=null,void 0!==this.Yd.kp&&this.Yd.kp())}xp(t){if(this.Td&&this.Td(),this.$d(t))return;if(!this.Ad)return;const i=this.Hd(t);this.Gd(i,this.Yd.Rp),this.Ad=!cs()}gp(t){const i=bs(t.touches,l(this.Bd));if(null===i)return;const s=this.Hd(t,i);this.qd(s,this.Yd.Fp),this.Sd=!0,this.wd=!0}$d(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ed+500}qd(t,i){i&&i.call(this.Yd,t)}Gd(t,i){i&&i.call(this.Yd,t)}Hd(t,i){const s=i||t,n=this.Jd.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,Lp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ep:t.type,Bp:s.target,o_:t.view,Ap:()=>{"touchstart"!==t.type&&ms(t)}}}}function vs(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ms(t){t.cancelable&&t.preventDefault()}function ws(t){return{ut:t.pageX,ct:t.pageY}}function gs(t){return t.timeStamp||performance.now()}function bs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ms{constructor(t,i,s){this.Op=null,this.Wp=null,this.zp=!0,this.$p=null,this.Hp=t,this.Np=t.Up()[i],this.qp=t.Up()[s],this.jp=document.createElement("tr"),this.jp.style.height="1px",this.Yp=document.createElement("td"),this.Yp.style.position="relative",this.Yp.style.padding="0",this.Yp.style.margin="0",this.Yp.setAttribute("colspan","3"),this.Kp(),this.jp.appendChild(this.Yp),this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(this.Op=null,this.Wp=null)}m(){null!==this.Wp&&this.Wp.m()}Xp(){return this.jp}Zp(){return ns({width:this.Np.Zp().width,height:1})}Jp(){return ns({width:this.Np.Jp().width,height:1*window.devicePixelRatio})}Qp(t,i,s){const n=this.Jp();t.fillStyle=this.Hp.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Kp(),this.Hp.W().layout.panes.enableResize!==this.zp&&(this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(null!==this.Op&&(this.Yp.removeChild(this.Op.tf),this.Yp.removeChild(this.Op.if),this.Op=null),null!==this.Wp&&(this.Wp.m(),this.Wp=null)))}Gp(){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.Yp.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.Yp.appendChild(s);const e={np:this.sf.bind(this),Rp:this.nf.bind(this),yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this)};this.Wp=new fs(s,e,{op:()=>!1,ap:()=>!0}),this.Op={if:s,tf:t}}Kp(){this.Yp.style.background=this.Hp.W().layout.panes.separatorColor}sf(t){null!==this.Op&&(this.Op.if.style.backgroundColor=this.Hp.W().layout.panes.separatorHoverColor)}nf(t){null!==this.Op&&null===this.$p&&(this.Op.if.style.backgroundColor="")}ef(t){if(null===this.Op)return;const i=this.Np.lf().Fa()+this.qp.lf().Fa(),s=i/(this.Np.Zp().height+this.qp.Zp().height),n=30*s;i<=2*n||(this.$p={af:t.pageY,_f:this.Np.lf().Fa(),uf:i-n,cf:i,df:s,pf:n},this.Op.tf.style.display="block")}rf(t){const i=this.$p;if(null===i)return;const s=(t.pageY-i.af)*i.df,n=Kt(i._f+s,i.pf,i.uf);this.Np.lf().La(n),this.qp.lf().La(i.cf-n),this.Hp.ti().Lh()}hf(t){null!==this.$p&&null!==this.Op&&(this.$p=null,this.Op.tf.style.display="none")}}function ys(t,i){return t.ff-i.ff}function Ss(t,i,s){const n=(t.ff-i.ff)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.vf=null,this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=0,this.yf=0,this.Sf=t,this.xf=i,this.Cf=s,this.Mn=n}Pf(t,i){if(null!==this.vf){if(this.vf.gt===i)return void(this.vf.ff=t);if(Math.abs(this.vf.ff-t)<this.Mn)return}this.gf=this.wf,this.wf=this.mf,this.mf=this.vf,this.vf={gt:i,ff:t}}ae(t,i){if(null===this.vf||null===this.mf)return;if(i-this.vf.gt>50)return;let s=0;const n=Ss(this.vf,this.mf,this.xf),e=ys(this.vf,this.mf),r=[n],h=[e];if(s+=e,null!==this.wf){const t=Ss(this.mf,this.wf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.mf,this.wf);if(r.push(t),h.push(i),s+=i,null!==this.gf){const t=Ss(this.wf,this.gf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);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.Sf||(this.bf={ff:t,gt:i},this.yf=l,this.Mf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Cf))}Vu(t){const i=l(this.bf),s=t-i.gt;return i.ff+this.yf*(Math.pow(this.Cf,s)-1)/Math.log(this.Cf)}Iu(t){return null===this.bf||this.Tf(t)===this.Mf}Tf(t){const i=t-l(this.bf).gt;return Math.min(i,this.Mf)}}class Cs{constructor(t,i){this.kf=void 0,this.Df=void 0,this.If=void 0,this.vs=!1,this.Vf=t,this.Rf=i,this.Ff()}Tt(){this.Ff()}Lf(){this.kf&&this.Vf.removeChild(this.kf),this.Df&&this.Vf.removeChild(this.Df),this.kf=void 0,this.Df=void 0}Ef(){return this.vs!==this.Bf()||this.If!==this.Af()}Af(){return this.Rf.ti().Xi().tt(this.Rf.W().layout.textColor)>160?"dark":"light"}Bf(){return this.Rf.W().layout.attributionLogo}Of(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Ff(){this.Ef()&&(this.Lf(),this.vs=this.Bf(),this.vs&&(this.If=this.Af(),this.Df=document.createElement("style"),this.Df.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.kf=document.createElement("a"),this.kf.href=`https://pipsend.com${this.Of()}`,this.kf.title="Powered by Pipsend Charts",this.kf.id="pipsend-attr-logo",this.kf.target="_blank",this.kf.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.kf.toggleAttribute("data-dark","dark"===this.If),this.Vf.appendChild(this.Df),this.Vf.appendChild(this.kf)))}}function Ps(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new hs(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 Ts(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function ks(t,i,s,n){t.sh&&t.sh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function Is(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()?.wl()??"")!==i?[]:s.il?.(t)??[]}}function Rs(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 Fs{constructor(t,i,s,n){this.Yi=null,this.Wf=null,this.zf=!1,this.$f=new it(200),this.Hf=null,this.Nf=0,this.Uf=!1,this.qf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Yf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Pt=t,this.Ps=i,this.So=i.layout,this.Qu=s,this.Kf="left"===n,this.Gf=Vs("normal",n),this.Xf=Vs("top",n),this.Zf=Vs("bottom",n),this.Yp=document.createElement("div"),this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Yp.style.width="25px",this.Yp.style.left="0",this.Yp.style.position="relative",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const e=this.Jf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.Qf=Ps(this.Yp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const r=this.Qf.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),Sp:this.tv.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this),Xd:this.iv.bind(this),jd:this.iv.bind(this),np:this.sv.bind(this),Rp:this.nf.bind(this)};this.Wp=new fs(this.Qf.canvasElement,h,{op:()=>!this.Ps.handleScroll.vertTouchDrag,ap:()=>!0})}m(){this.Wp.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Yi&&this.Yi.ea().u(this),this.Yi=null}Xp(){return this.Yp}P(){return this.So.fontSize}nv(){const t=this.Qu.W();return this.Hf!==t.T&&(this.$f.Fn(),this.Hf=t.T),t}ev(){if(null===this.Yi)return 0;let t=0;const i=this.nv(),s=l(this.Jf.canvasElement.getContext("2d",{colorSpace:this.Pt.jf().W().layout.colorSpace}));s.save();const n=this.Yi.Vl();s.font=this.rv(),n.length>0&&(t=Math.max(this.$f.Ri(s,n[0].Zl),this.$f.Ri(s,n[n.length-1].Zl)));const e=this.hv();for(let i=e.length;i--;){const n=this.$f.Ri(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.At();if(null!==r&&null!==this.Wf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.Wf.height-2,r);t=Math.max(t,this.$f.Ri(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.$f.Ri(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ds(Math.ceil(i.S+i.C+i.F+i.L+5+o))}lv(t){null!==this.Wf&&es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`)}ov(){return l(this.Wf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ea().u(this),this.Yi=t,t.ea().i(this.co.bind(this),this))}$t(){return this.Yi}Fn(){const t=this.Pt.lf();this.Pt.jf().ti().Za(t,l(this.$t()))}av(t){if(null===this.Wf)return;const i={colorSpace:this.Pt.jf().W().layout.colorSpace};if(1!==t){this._v(),this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)}),this.Pt.dv(t,this.Zf),this.pv(t),this.Pt.dv(t,this.Gf),this.fv(t))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.vv(s),this.Pt.dv(s,this.Xf))}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Vl()}ef(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!0,i.Ua(s,this.Yi,t.localY)}rf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf(),n=this.Yi;i.qa(s,n,t.localY)}tv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.jf().ti(),i=this.Pt.lf(),s=this.Yi;this.zf&&(this.zf=!1,t.ja(i,s))}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!1,i.ja(s,this.Yi)}iv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Fn()}sv(t){if(null===this.Yi)return;!this.Pt.jf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Fo()||this.mv(1)}nf(t){this.mv(0)}hv(){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.lf(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.lf().Vt()),t}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.lf().ti(),r=e.q(),h=e.Hc();r===h?F(t,0,0,s,n,r):B(t,0,0,s,n,r,h)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.Wf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.nv().S*s));let e;e=this.Kf?i.width-n:0,t.fillRect(e,0,n,i.height)}pv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Yi.Vl(),s=this.Yi.W(),n=this.nv(),e=this.Kf?this.Wf.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.Pl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.rv(),t.fillStyle=s.textColor??this.So.textColor,t.textAlign=this.Kf?"right":"left",t.textBaseline="middle";const r=this.Kf?Math.round(e-n.F):Math.round(e+n.C+n.F),h=i.map(i=>this.$f.Vi(t,i.Zl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Zl,r,n.Pl+h[s])}})}_v(){if(null===this.Wf||null===this.Yi)return;let t=this.Wf.height/2;const i=[],s=this.Yi.Vt().slice(),n=this.Pt.lf(),e=this.nv();this.Yi===n.qn()&&this.Pt.lf().Vt().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.Ml()[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.wv(i,e,t)}wv(t,i,s){if(null===this.Wf)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.Wf.height-t&&n<this.Wf.height+t&&s.Hi(this.Wf.height-t)}Rs(n,1,this.Wf.height,i),Rs(e,-1,this.Wf.height,i)}fv(t){if(null===this.Wf)return;const i=this.hv(),s=this.nv(),n=this.Kf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.$f,n)}})}vv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Pt.jf().ti(),s=[],n=this.Pt.lf(),e=i.cc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.nv(),h=this.Kf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.$f,h)})})}mv(t){this.Yp.style.cursor=1===t?"ns-resize":"default"}co(){const t=this.ev();this.Nf<t&&this.Pt.jf().ti().Lh(),this.Nf=t}rv(){return g(this.So.fontSize,this.So.fontFamily)}}function Ls(t,i){return t.Qh?.(i)??[]}function Es(t,i){return t.$s?.(i)??[]}function Bs(t,i){return t.cs?.(i)??[]}function As(t,i){return t.Xh?.(i)??[]}class Os{constructor(t,i){this.Wf=ns({width:0,height:0}),this.gv=null,this.bv=null,this.Mv=null,this.yv=null,this.Sv=!1,this.xv=new a,this.Cv=new a,this.Pv=0,this.Tv=!1,this.kv=null,this.Dv=!1,this.Iv=null,this.Vv=null,this.Uf=!1,this.qf=()=>{this.Uf||null===this.Rv||this.ss().ar()},this.Yf=()=>{this.Uf||null===this.Rv||this.ss().ar()},this.Rf=t,this.Rv=i,this.Rv.i_().i(this.Fv.bind(this),this,!0),this.Lv=document.createElement("td"),this.Lv.style.padding="0",this.Lv.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.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Lv.appendChild(s),this.Jf=Ps(s,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const n=this.Jf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.jp=document.createElement("tr"),this.jp.appendChild(this.Ev),this.jp.appendChild(this.Lv),this.jp.appendChild(this.Bv),this.Av(),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>null===this.kv&&!this.Rf.W().handleScroll.vertTouchDrag,ap:()=>null===this.kv&&!this.Rf.W().handleScroll.horzTouchDrag})}m(){null!==this.gv&&this.gv.m(),null!==this.bv&&this.bv.m(),this.Mv=null,this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Rv&&(this.Rv.i_().u(this),this.Rv.m()),this.Wp.m()}lf(){return l(this.Rv)}Ov(t){null!==this.Rv&&this.Rv.i_().u(this),this.Rv=t,null!==this.Rv&&this.Rv.i_().i(Os.prototype.Fv.bind(this),this,!0),this.Av(),this.Rf.Up().indexOf(this)===this.Rf.Up().length-1?(this.Mv=this.Mv??new Cs(this.Lv,this.Rf),this.Mv.Tt()):(this.Mv?.Lf(),this.Mv=null)}jf(){return this.Rf}Xp(){return this.jp}Av(){if(null!==this.Rv&&(this.Wv(),0!==this.ss().Ks().length)){if(null!==this.gv){const t=this.Rv.Ha();this.gv.us(l(t))}if(null!==this.bv){const t=this.Rv.Na();this.bv.us(l(t))}}}zv(){null!==this.gv&&this.gv.Tt(),null!==this.bv&&this.bv.Tt()}Fa(){return null!==this.Rv?this.Rv.Fa():0}La(t){this.Rv&&this.Rv.La(t)}np(t){if(!this.Rv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}yp(t){this.$v(),this.Nv(),this.Hv(t.localX,t.localY,t)}ep(t){if(!this.Rv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}mp(t){null!==this.Rv&&(this.$v(),this.Uv(t))}Xd(t){null!==this.Rv&&this.qv(this.Cv,t)}jd(t){this.Xd(t)}cp(t){this.$v(),this.jv(t),this.Hv(t.localX,t.localY,t)}vp(t){null!==this.Rv&&(this.$v(),this.Tv=!1,this.Yv(t))}fp(t){null!==this.Rv&&this.Uv(t)}Fp(t){if(this.Tv=!0,null===this.kv){const i={x:t.localX,y:t.localY};this.Kv(i,i,t)}}Rp(t){null!==this.Rv&&(this.$v(),this.Rv.ti().ac(null),this.Gv())}Xv(){return this.xv}Zv(){return this.Cv}Pp(){this.Pv=1,this.ss().ln()}Tp(t,i){if(!this.Rf.W().handleScale.pinch)return;const s=5*(i-this.Pv);this.Pv=i,this.ss().yc(t.ut,s)}bp(t){this.Tv=!1,this.Dv=null!==this.kv,this.Nv();const i=this.ss().cc();null!==this.kv&&i.Rt()&&(this.Iv={x:i.ni(),y:i.ei()},this.kv={x:t.localX,y:t.localY})}_p(t){if(null===this.Rv)return;const i=t.localX,s=t.localY;if(null!==this.kv){this.Dv=!1;const n=l(this.Iv),e=n.x+(i-this.kv.x),r=n.y+(s-this.kv.y);return void this.Hv(e,r,t)}this.jv(t)}pp(t){0===this.jf().W().trackingMode.exitMode&&(this.Dv=!0),this.Jv(),this.Yv(t)}Kn(t,i){const s=this.Rv;return null===s?null:Si(s,t,i)}Qv(t,i){l("left"===i?this.gv:this.bv).lv(ns({width:t,height:this.Wf.height}))}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Lv.style.width=t.width+"px",this.Lv.style.height=t.height+"px")}tm(){const t=l(this.Rv);t.$a(t.Ha()),t.$a(t.Na());for(const i of t.Ml())if(t.Un(i)){const s=i.$t();null!==s&&t.$a(s),i.zs()}for(const i of t.n_())i.zs()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;null!==t&&t.drawImage(n,i,s)}}av(t){if(0===t)return;if(null===this.Rv)return;t>1&&this.tm(),null!==this.gv&&this.gv.av(t),null!==this.bv&&this.bv.av(t);const i={colorSpace:this.Rf.W().layout.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t)}),this.Rv&&(this.im(t,Ls),this.sm(t),this.im(t,Es),this.im(t,Bs)))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.nm(s),this.im(s,As),this.im(s,Bs))}rm(){return this.gv}hm(){return this.bv}dv(t,i){this.im(t,i)}Fv(){null!==this.Rv&&this.Rv.i_().u(this),this.Rv=null}Uv(t){this.qv(this.xv,t)}qv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().Et().du(s),{x:s,y:n},i)}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Hc();r===h?F(t,0,0,s,n,h):B(t,0,0,s,n,r,h)}sm(t){const i=l(this.Rv),s=i.s_()._r().Dt(i);null!==s&&s.et(t,!1)}nm(t){this.lm(t,Es,Ds,this.ss().cc())}im(t,i){const s=l(this.Rv),n=s.Vt(),e=s.n_();for(const s of e)this.lm(t,i,ks,s);for(const s of n)this.lm(t,i,ks,s);for(const s of e)this.lm(t,i,Ds,s);for(const s of n)this.lm(t,i,Ds,s)}lm(t,i,s,n){const e=l(this.Rv),r=e.ti().oc(),h=null!==r&&r.e_===n,o=null!==r&&h&&void 0!==r.r_?r.r_.Xn:void 0;Is(i,i=>s(i,t,h,o),n,e)}Wv(){if(null===this.Rv)return;const t=this.Rf,i=this.Rv.Ha().W().visible,s=this.Rv.Na().W().visible;i||null===this.gv||(this.Ev.removeChild(this.gv.Xp()),this.gv.m(),this.gv=null),s||null===this.bv||(this.Bv.removeChild(this.bv.Xp()),this.bv.m(),this.bv=null);const n=t.ti().Fc();i&&null===this.gv&&(this.gv=new Fs(this,t.W(),n,"left"),this.Ev.appendChild(this.gv.Xp())),s&&null===this.bv&&(this.bv=new Fs(this,t.W(),n,"right"),this.Bv.appendChild(this.bv.Xp()))}om(t){return t.Lp&&this.Tv||null!==this.kv}am(t){return Math.max(0,Math.min(t,this.Wf.width-1))}_m(t){return Math.max(0,Math.min(t,this.Wf.height-1))}Hv(t,i,s){this.ss().Dc(this.am(t),this._m(i),s,l(this.Rv))}Gv(){this.ss().Vc()}Jv(){this.Dv&&(this.kv=null,this.Gv())}Kv(t,i,s){this.kv=t,this.Dv=!1,this.Hv(i.x,i.y,s);const n=this.ss().cc();this.Iv={x:n.ni(),y:n.ei()}}ss(){return this.Rf.ti()}Yv(t){if(!this.Sv)return;const i=this.ss(),s=this.lf();if(i.Ga(s,s.ks()),this.yv=null,this.Sv=!1,i.Pc(),null!==this.Vv){const t=performance.now(),s=i.Et();this.Vv.ae(s.bu(),t),this.Vv.Iu(t)||i.un(this.Vv)}}$v(){this.kv=null}Nv(){if(!this.Rv)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.Rv.ks().Gi()&&this.ss().Et().Gi()}jv(t){if(null===this.Rv)return;const i=this.ss(),s=i.Et();if(s.Gi())return;const n=this.Rf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Lp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Lp))return;const h=this.Rv.ks(),l=performance.now();if(null!==this.yv||this.om(t)||(this.yv={x:t.clientX,y:t.clientY,hd:l,um:t.localX,dm:t.localY}),null!==this.yv&&!this.Sv&&(this.yv.x!==t.clientX||this.yv.y!==t.clientY)){if(t.Lp&&r.touch||!t.Lp&&r.mouse){const t=s.wu();this.Vv=new xs(.2/t,7/t,.997,15/t),this.Vv.Pf(s.bu(),this.yv.hd)}else this.Vv=null;h.Gi()||i.Ya(this.Rv,h,t.localY),i.xc(t.localX),this.Sv=!0}this.Sv&&(h.Gi()||i.Ka(this.Rv,h,t.localY),i.Cc(t.localX),null!==this.Vv&&this.Vv.Pf(s.bu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.Wf=ns({width:0,height:0}),this.qf=()=>this.av(3),this.Kf="left"===t,this.Qu=s.Fc,this.Ps=i,this.pm=n,this.fm=e,this.Yp=document.createElement("div"),this.Yp.style.width="25px",this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf)}m(){this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Xp(){return this.Yp}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Jf.resizeCanvasElement(t),this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.xt=!0)}av(t){if(t<3&&!this.xt)return;if(0===this.Wf.width||0===this.Wf.height)return;this.xt=!1,this.Jf.applySuggestedBitmapSize();const i=as(this.Jf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)})}Jp(){return this.Jf.bitmapSize}Qp(t,i,s){const n=this.Jp();n.width>0&&n.height>0&&t.drawImage(this.Jf.canvasElement,i,s)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.pm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.Qu.W().S*s),r=Math.floor(this.Qu.W().S*n),h=this.Kf?i.width-e:0;t.fillRect(h,0,e,r)}uv({context:t,bitmapSize:i}){F(t,0,0,i.width,i.height,this.fm())}}function zs(t){return i=>i.sl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.vm=null,this.wm=null,this.M=null,this.gm=!1,this.Wf=ns({width:0,height:0}),this.bm=new a,this.$f=new it(5),this.Uf=!1,this.qf=()=>{this.Uf||this.Rf.ti().ar()},this.Yf=()=>{this.Uf||this.Rf.ti().ar()},this.Rf=t,this.__=i,this.Ps=t.W().layout,this.kf=document.createElement("tr"),this.Mm=document.createElement("td"),this.Mm.style.padding="0",this.ym=document.createElement("td"),this.ym.style.padding="0",this.Yp=document.createElement("td"),this.Yp.style.height="25px",this.Yp.style.padding="0",this.Sm=document.createElement("div"),this.Sm.style.width="100%",this.Sm.style.height="100%",this.Sm.style.position="relative",this.Sm.style.overflow="hidden",this.Yp.appendChild(this.Sm),this.Jf=Ps(this.Sm,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const s=this.Jf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Qf=Ps(this.Sm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.kf.appendChild(this.Mm),this.kf.appendChild(this.Yp),this.kf.appendChild(this.ym),this.xm(),this.Rf.ti().Ra().i(this.xm.bind(this),this),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>!0,ap:()=>!this.Rf.W().handleScroll.horzTouchDrag})}m(){this.Wp.m(),null!==this.vm&&this.vm.m(),null!==this.wm&&this.wm.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Xp(){return this.kf}Cm(){return this.vm}Pm(){return this.wm}yp(t){if(this.gm)return;this.gm=!0;const i=this.Rf.ti();!i.Et().Gi()&&this.Rf.W().handleScale.axisPressedMouseMove.time&&i.Mc(t.localX)}bp(t){this.yp(t)}Sp(){const t=this.Rf.ti();!t.Et().Gi()&&this.gm&&(this.gm=!1,this.Rf.W().handleScale.axisPressedMouseMove.time&&t.kc())}cp(t){const i=this.Rf.ti();!i.Et().Gi()&&this.Rf.W().handleScale.axisPressedMouseMove.time&&i.Tc(t.localX)}_p(t){this.cp(t)}vp(){this.gm=!1;const t=this.Rf.ti();t.Et().Gi()&&!this.Rf.W().handleScale.axisPressedMouseMove.time||t.kc()}pp(){this.vp()}Xd(){this.Rf.W().handleScale.axisDoubleClickReset.time&&this.Rf.ti().dn()}jd(){this.Xd()}np(){this.Rf.ti().W().handleScale.axisPressedMouseMove.time&&this.mv(1)}Rp(){this.mv(0)}Zp(){return this.Wf}Tm(){return this.bm}km(t,i,s){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.bm.p(t)),null!==this.vm&&this.vm.lv(ns({width:i,height:t.height})),null!==this.wm&&this.wm.lv(ns({width:s,height:t.height}))}Dm(){const t=this.Im();return Math.ceil(t.S+t.C+t.P+t.B+t.R+t.Vm)}Tt(){this.Rf.ti().Et().Vl()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}av(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const s=as(this.Jf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t),this.Rm(s,Ns)}),this.pv(s),this.Rm(s,$s)),null!==this.vm&&this.vm.av(t),null!==this.wm&&this.wm.av(t)}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Fm([...this.Rf.ti().Ks(),this.Rf.ti().cc()],s),this.Rm(s,Hs))}Rm(t,i){const s=this.Rf.ti().Ks();for(const n of s)Is(i,i=>ks(i,t,!1,void 0),n,void 0);for(const n of s)Is(i,i=>Ds(i,t,!1,void 0),n,void 0)}uv({context:t,bitmapSize:i}){F(t,0,0,i.width,i.height,this.Rf.ti().Hc())}cv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Rf.W().timeScale.borderVisible){t.fillStyle=this.Lm();const n=Math.max(1,Math.floor(this.Im().S*s));t.fillRect(0,0,i.width,n)}}pv(t){const i=this.Rf.ti().Et(),s=i.Vl();if(!s||0===s.length)return;const n=this.__.maxTickMarkWeight(s),e=this.Im(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Lm(),t.fillStyle=this.Lm();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.B+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.rv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Em(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Rf.W().timeScale.allowBoldLabels&&(t.font=this.Bm());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Em(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Em(t,i,s){const n=this.$f.Ri(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.Wf.width&&(i-=Math.abs(this.Wf.width-(r+n))),i}Fm(t,i){const s=this.Im();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Lm(){return this.Rf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}rv(){return g(this.$(),this.Ps.fontFamily)}Bm(){return g(this.$(),this.Ps.fontFamily,"bold")}Im(){null===this.M&&(this.M={S:1,A:NaN,B:NaN,R:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Vm:0});const t=this.M,i=this.rv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.B=3*s/12,t.R=3*s/12,t.Qi=9*s/12,t.A=0,t.Vm=4*s/12,t.Ji.Fn()}return this.M}mv(t){this.Yp.style.cursor=1===t?"ew-resize":"default"}xm(){const t=this.Rf.ti(),i=t.W();i.leftPriceScale.visible||null===this.vm||(this.Mm.removeChild(this.vm.Xp()),this.vm.m(),this.vm=null),i.rightPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Xp()),this.wm.m(),this.wm=null);const s={Fc:this.Rf.ti().Fc()},n=()=>i.leftPriceScale.borderVisible&&t.Et().W().borderVisible,e=()=>t.Hc();i.leftPriceScale.visible&&null===this.vm&&(this.vm=new Ws("left",i,s,n,e),this.Mm.appendChild(this.vm.Xp())),i.rightPriceScale.visible&&null===this.wm&&(this.wm=new Ws("right",i,s,n,e),this.ym.appendChild(this.wm.Xp()))}}const qs=!!_s&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!_s&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class js{constructor(t,i,s){var n;this.Am=[],this.Om=[],this.Wm=0,this.no=0,this.Ma=0,this.zm=0,this.$m=0,this.Hm=null,this.Nm=!1,this.xv=new a,this.Cv=new a,this.Xu=new a,this.Um=null,this.qm=null,this.Vf=t,this.Ps=i,this.__=s,this.kf=document.createElement("div"),this.kf.classList.add("tv-lightweight-charts"),this.kf.style.overflow="hidden",this.kf.style.direction="ltr",this.kf.style.width="100%",this.kf.style.height="100%",(n=this.kf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.jm=document.createElement("table"),this.jm.setAttribute("cellspacing","0"),this.kf.appendChild(this.jm),this.Ym=this.Km.bind(this),Ys(this.Ps)&&this.Gm(!0),this.ss=new Bi(this.Ju.bind(this),this.Ps,s),this.ti().dc().i(this.Xm.bind(this),this),this.Zm=new Us(this,this.__),this.jm.appendChild(this.Zm.Xp());const e=i.autoSize&&this.Jm();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.Qm(r,h),this.tw(),t.appendChild(this.kf),this.iw(),this.ss.Et().Lu().i(this.ss.Lh.bind(this.ss),this),this.ss.Ra().i(this.ss.Lh.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}Up(){return this.Am}sw(){return this.Zm}m(){this.Gm(!1),0!==this.Wm&&window.cancelAnimationFrame(this.Wm),this.ss.dc().u(this),this.ss.Et().Lu().u(this),this.ss.Ra().u(this),this.ss.m();for(const t of this.Am)this.jm.removeChild(t.Xp()),t.Xv().u(this),t.Zv().u(this),t.m();this.Am=[];for(const t of this.Om)this.nw(t);this.Om=[],l(this.Zm).m(),null!==this.kf.parentElement&&this.kf.parentElement.removeChild(this.kf),this.Xu.m(),this.xv.m(),this.Cv.m(),this.ew()}Qm(t,i,s=!1){if(this.no===i&&this.Ma===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return ns({width:i-i%2,height:s-s%2})}(ns({width:t,height:i}));this.no=n.height,this.Ma=n.width;const e=this.no+"px",r=this.Ma+"px";l(this.kf).style.height=e,l(this.kf).style.width=r,this.jm.style.height=e,this.jm.style.width=r,s?this.rw(Y.bn(),performance.now()):this.ss.Lh()}av(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Am.length;i++)this.Am[i].av(t.rn(i).sn);this.Ps.timeScale.visible&&this.Zm.av(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Gm(s),t.layout?.panes&&this.hw(),this.iw(),this.lw(t)}Xv(){return this.xv}Zv(){return this.Cv}dc(){return this.Xu}ow(t=!1){null!==this.Hm&&(this.rw(this.Hm,performance.now()),this.Hm=null);const i=this.aw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.aw(n,t),s}_w(t){if("left"===t&&!this.uw())return 0;if("right"===t&&!this.cw())return 0;if(0===this.Am.length)return 0;return l("left"===t?this.Am[0].rm():this.Am[0].hm()).ov()}dw(){return this.Ps.autoSize&&null!==this.Um}if(){return this.kf}pw(t){this.qm=t,this.qm?this.if().style.setProperty("cursor",t):this.if().style.removeProperty("cursor")}fw(){return this.qm}mw(t){return h(this.Am[t]).Zp()}hw(){this.Om.forEach(t=>{t.Tt()})}lw(t){(void 0!==t.autoSize||!this.Um||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.Um&&this.Jm(),!1===t.autoSize&&null!==this.Um&&this.ew(),t.autoSize||void 0===t.width&&void 0===t.height||this.Qm(t.width||this.Ma,t.height||this.no))}aw(t,i){let s=0,n=0;const e=this.Am[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Am.length;r++){const h=this.Am[r],o=l("left"===s?h.rm():h.hm()),a=o.Jp();if(null!==t&&o.Qp(t,n,e,i),e+=a.height,r<this.Am.length-1){const i=this.Om[r],s=i.Jp();null!==t&&i.Qp(t,n,e),e+=s.height}}};if(this.uw()){r("left",0);s+=l(e.rm()).Jp().width}for(let e=0;e<this.Am.length;e++){const r=this.Am[e],h=r.Jp();if(null!==t&&r.Qp(t,s,n,i),n+=h.height,e<this.Am.length-1){const i=this.Om[e],r=i.Jp();null!==t&&i.Qp(t,s,n),n+=r.height}}if(s+=e.Jp().width,this.cw()){r("right",s);s+=l(e.hm()).Jp().width}const h=(i,s,n)=>{l("left"===i?this.Zm.Cm():this.Zm.Pm()).Qp(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Zm.Jp();if(null!==t){let r=0;this.uw()&&(h("left",r,n),r=l(e.rm()).Jp().width),this.Zm.Qp(t,r,n,i),r+=s.width,this.cw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}ww(){let t=0,i=0,s=0;for(const n of this.Am)this.uw()&&(i=Math.max(i,l(n.rm()).ev(),this.Ps.leftPriceScale.minimumWidth)),this.cw()&&(s=Math.max(s,l(n.hm()).ev(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Fa();i=ds(i),s=ds(s);const n=this.Ma,e=this.no,r=Math.max(n-i-s,0),h=1*this.Om.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Zm.Dm(),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.Am.length;++t){const n=this.Am[t];n.Ov(this.ss.qs()[t]);let e=0,h=0;h=t===this.Am.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Fa()*d*f)/f,e=Math.max(h,2),p+=e,n.lv(ns({width:r,height:e})),this.uw()&&n.Qv(i,"left"),this.cw()&&n.Qv(s,"right"),n.lf()&&this.ss.fc(n.lf(),e)}this.Zm.km(ns({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ea(r),this.zm!==i&&(this.zm=i),this.$m!==s&&(this.$m=s)}Gm(t){t?this.kf.addEventListener("wheel",this.Ym,{passive:!1}):this.kf.removeEventListener("wheel",this.Ym)}gw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?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.gw(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.kf.getBoundingClientRect().left;this.ti().yc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Sc(-80*s)}rw(t,i){const s=t.en();3===s&&this.bw(),3!==s&&2!==s||(this.Mw(t),this.yw(t,i),this.Zm.Tt(),this.Am.forEach(t=>{t.zv()}),3===this.Hm?.en()&&(this.Hm.mn(t),this.bw(),this.Mw(this.Hm),this.yw(this.Hm,i),t=this.Hm,this.Hm=null)),this.av(t)}yw(t,i){for(const s of t.vn())this.wn(s,i)}Mw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Ja()}wn(t,i){const s=this.ss.Et();switch(t.an){case 0:s.Bu();break;case 1:s.Au(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Su();break;case 5:t.Ht.Iu(i)||s.fn(t.Ht.Vu(i))}}Ju(t){null!==this.Hm?this.Hm.mn(t):this.Hm=t,this.Nm||(this.Nm=!0,this.Wm=window.requestAnimationFrame(t=>{if(this.Nm=!1,this.Wm=0,null!==this.Hm){const i=this.Hm;this.Hm=null,this.rw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Iu(t)){this.ti().un(s.Ht);break}}}))}bw(){this.tw()}nw(t){this.jm.removeChild(t.Xp()),t.m()}tw(){const t=this.ss.qs(),i=t.length,s=this.Am.length;for(let t=i;t<s;t++){const t=h(this.Am.pop());this.jm.removeChild(t.Xp()),t.Xv().u(this),t.Zv().u(this),t.m();const i=this.Om.pop();void 0!==i&&this.nw(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Xv().i(this.Sw.bind(this,i),this),i.Zv().i(this.xw.bind(this,i),this),this.Am.push(i),n>0){const t=new Ms(this,n-1,n);this.Om.push(t),this.jm.insertBefore(t.Xp(),this.Zm.Xp())}this.jm.insertBefore(i.Xp(),this.Zm.Xp())}for(let s=0;s<i;s++){const i=t[s],n=this.Am[s];n.lf()!==i?n.Ov(i):n.Av()}this.iw(),this.ww()}Cw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Ks().forEach(i=>{const s=i.Xs().$r(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.Et().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti().oc(),l=null!==h&&h.e_ instanceof Ut?h.e_:void 0,o=null!==h&&void 0!==h.r_?h.r_.Gn:void 0,a=this.Pw(n);return{Tw:r,Ie:t??void 0,kw:i??void 0,Dw:-1!==a?a:void 0,Iw:l,Vw:e,Rw:o,Fw:s??void 0}}Pw(t){let i=-1;if(t)i=this.Am.indexOf(t);else{const t=this.ti().cc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Sw(t,i,s,n){this.xv.p(()=>this.Cw(i,s,n,t))}xw(t,i,s,n){this.Cv.p(()=>this.Cw(i,s,n,t))}Xm(t,i,s){this.pw(this.ti().oc()?.l_??null),this.Xu.p(()=>this.Cw(t,i,s))}iw(){const t=this.Ps.timeScale.visible?"":"none";this.Zm.Xp().style.display=t}uw(){return this.Am[0].lf().Ha().W().visible}cw(){return this.Am[0].lf().Na().W().visible}Jm(){return"ResizeObserver"in window&&(this.Um=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.Qm(i.contentRect.width,i.contentRect.height)}),this.Um.observe(this.Vf,{box:"border-box"}),!0)}ew(){null!==this.Um&&this.Um.disconnect(),this.Um=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Ks(t){return void 0===t.open&&void 0===t.value}function Gs(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Xs(t,i,s,n){const e=s.value,r={Ie:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.color&&(r.I=s.color),r}function Zs(t,i,s,n){const e=s.value,r={Ie:i,gt:t,Ht:[e,e,e,e],Tw: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 Js(t,i,s,n){const e=s.value,r={Ie:i,gt:t,Ht:[e,e,e,e],Tw: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 Qs(t,i,s,n){const e={Ie:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw:n};return void 0!==s.color&&(e.I=s.color),e}function tn(t,i,s,n){const e={Ie:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw:n};return void 0!==s.color&&(e.I=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function sn(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{Ie:i,gt:t,Ht:_,Tw:n,ne:d,I:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Lw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Ks(t)}(n,h)?en({gt:i,Ie:s,Tw:e},n):en(t(i,s,n,e,r),n)}function hn(t){return{Candlestick:rn(tn),Bar:rn(Qs),Area:rn(Zs),Baseline:rn(Js),Histogram:rn(Xs),Line:rn(Xs),Custom:rn(sn)}[t]}function ln(t){return{Ie:0,Ew:new Map,Nh:t}}function on(t,i){if(void 0!==t&&0!==t.length)return{Bw:i.key(t[0].gt),Aw:i.key(t[t.length-1].gt)}}function an(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Tw)}),h(i)}class _n{constructor(t){this.Ow=new Map,this.Ww=new Map,this.zw=new Map,this.$w=[],this.__=t}m(){this.Ow.clear(),this.Ww.clear(),this.zw.clear(),this.$w=[]}Hw(t,i){let s=0!==this.Ow.size,n=!1;const e=this.Ww.get(t);if(void 0!==e)if(1===this.Ww.size)s=!1,n=!0,this.Ow.clear();else for(const i of this.$w)i.pointData.Ew.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.__.createConverterToInternalObj(i),h=hn(t.Ir()),l=t.dl(),o=t.fl();r=i.map((i,r)=>{const a=e(i.time),_=this.__.key(a);let u=this.Ow.get(_);void 0===u&&(u=ln(a),this.Ow.set(_,u),n=!0);const c=h(a,u.Ie,i,s[r],l,o);return u.Ew.set(t,c),c})}s&&this.Nw(),this.Uw(t,r);let h=-1;if(n){const t=[];this.Ow.forEach(i=>{t.push({timeWeight:0,time:i.Nh,pointData:i,originalTime:an(i.Ew)})}),t.sort((t,i)=>this.__.key(t.time)-this.__.key(i.time)),h=this.qw(t)}return this.jw(t,h,function(t,i,s){const n=on(t,s),e=on(i,s);if(void 0!==n&&void 0!==e)return{Yw:!1,Ah:n.Aw>=e.Aw&&n.Bw>=e.Bw}}(this.Ww.get(t),e,this.__))}Bc(t){return this.Hw(t,[])}Kw(t,i,s){const n=i;!function(t){void 0===t.Tw&&(t.Tw=t.time)}(n),this.__.preprocessData(i);const e=this.__.createConverterToInternalObj([i])(i.time),r=this.zw.get(t);if(!s&&void 0!==r&&this.__.key(e)<this.__.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ow.get(this.__.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=ln(e),this.Ow.set(this.__.key(e),h));const o=hn(t.Ir()),a=t.dl(),_=t.fl(),u=o(e,h.Ie,i,n.Tw,a,_);h.Ew.set(t,u),s?this.Gw(t,u,h.Ie):this.Xw(t,u);const c={Ah:nn(u),Yw:s};if(!l)return this.jw(t,-1,c);const d={timeWeight:0,time:h.Nh,pointData:h,originalTime:an(h.Ew)},p=yt(this.$w,this.__.key(d.time),(t,i)=>this.__.key(t.time)<i);this.$w.splice(p,0,d);for(let t=p;t<this.$w.length;++t)un(this.$w[t].pointData,t);return this.__.fillWeightsForPoints(this.$w,p),this.jw(t,p,c)}Zw(t,i){const s=this.Ww.get(t);if(void 0===s||i<=0)return[[],this.Jw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.zw.delete(t):this.zw.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ow.get(this.__.key(i.gt));if(s&&(s.Ew.delete(t),0===s.Ew.size)){this.Ow.delete(this.__.key(s.Nh)),this.$w.splice(s.Ie,1);for(let t=s.Ie;t<this.$w.length;++t)un(this.$w[t].pointData,t)}}return[n,this.jw(t,this.$w.length-1,{Yw:!1,Ah:!1})]}Xw(t,i){let s=this.Ww.get(t);void 0===s&&(s=[],this.Ww.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.__.key(i.gt)>this.__.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.zw.set(t,i.gt)}Gw(t,i,s){const n=this.Ww.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Ie<i);nn(i)?n[e]=i:n.splice(e,1)}Uw(t,i){0!==i.length?(this.Ww.set(t,i.filter(nn)),this.zw.set(t,i[i.length-1].gt)):(this.Ww.delete(t),this.zw.delete(t))}Nw(){for(const t of this.$w)0===t.pointData.Ew.size&&this.Ow.delete(this.__.key(t.time))}qw(t){let i=-1;for(let s=0;s<this.$w.length&&s<t.length;++s){const n=this.$w[s],e=t[s];if(this.__.key(n.time)!==this.__.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.$w.length!==t.length&&(i=Math.min(this.$w.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.__.fillWeightsForPoints(t,i),this.$w=t,i}Qw(){if(0===this.Ww.size)return null;let t=0;return this.Ww.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Ie))}),t}jw(t,i,s){const n=this.Jw();if(-1!==i)this.Ww.forEach((i,e)=>{n.Wa.set(e,{ne:i,tg:e===t?s:void 0})}),this.Ww.has(t)||n.Wa.set(t,{ne:[],tg:s}),n.Et.ig=this.$w,n.Et.sg=i;else{const i=this.Ww.get(t);n.Wa.set(t,{ne:i||[],tg:s})}return n}Jw(){return{Wa:new Map,Et:{uu:this.Qw()}}}}function un(t,i){t.Ie=i,t.Ew.forEach(t=>{t.Ie=i})}function cn(t,i){return t.gt<i}function dn(t,i){return i<t.gt}function pn(t,i,s){const n=i.Uh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);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 fn{constructor(t,i,s){this.ng=!0,this.eg=!0,this.rg=!0,this.hg=[],this.lg=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.ng=!0,"data"===t&&(this.eg=!0),"options"===t&&(this.rg=!0)}Dt(){return this.Qn.Rt()?(this.ag(),null===this.lg?null:this._g):null}ug(){this.hg=this.hg.map(t=>({...t,...this.Qn.Ih().Vr(t.gt)}))}cg(){this.lg=null}ag(){this.eg&&(this.dg(),this.eg=!1),this.rg&&(this.ug(),this.rg=!1),this.ng&&(this.pg(),this.ng=!1)}pg(){const t=this.Qn.$t(),i=this.te.Et();if(this.cg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Xs().Ar())return;const n=this.Qn.At();null!==n&&(this.lg=pn(this.hg,s,this.og),this.fg(t,i,n.Ht),this.vg())}}class vn{constructor(t,i){this.mg=t,this.Yi=i}et(t,i,s){this.mg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.nh=s,this._g=new vn(this.nh.renderer(),i=>{const s=t.At();return null===s?null:t.$t().zt(i,s.Ht)})}pl(t){return this.nh.priceValueBuilder(t)}vl(t){return this.nh.isWhitespace(t)}dg(){const t=this.Qn.Ih();this.hg=this.Qn.Xs().Nr().map(i=>({gt:i.Ie,ut:NaN,...t.Vr(i.Ie),wg:i.ne}))}fg(t,i){i.cu(this.hg,m(this.lg))}vg(){this.nh.update({bars:this.hg.map(wn),barSpacing:this.te.Et().wu(),visibleRange:this.lg},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.wg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=o(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),i}function yn(t){const i=Mn(t);return void 0!==t.I&&(i.color=t.I),i}function Sn(t){const i=Mn(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 xn(t){const i=Mn(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 Cn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),i}function Pn(t){const i=Cn(t);return void 0!==t.I&&(i.color=t.I),i}function Tn(t){const i=Cn(t),{I: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 kn(t){return{Area:Sn,Line:yn,Baseline:xn,Histogram:yn,Bar:Pn,Candlestick:Tn,Custom:Dn}[t]}function Dn(t){const i=t.Tw;return{...t.ne,time:i}}const In={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}},Rn={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:[]},Fn={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},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 En(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:Rn,crosshair:In,grid:Vn,overlayPriceScales:{...Fn},leftPriceScale:{...Fn,visible:!1},rightPriceScale:{...Fn,visible:!0},timeScale:Ln,localization:{locale:_s?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 Bn{constructor(t,i,s){this.Hp=t,this.gg=i,this.bg=s??0}applyOptions(t){this.Hp.ti()._c(this.gg,t,this.bg)}options(){return this.Yi().W()}width(){return j(this.gg)?this.Hp._w(this.gg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().No(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().Ql()){const n=this.Yi().va(),e=Ai(n);s=oi(s,this.Yi().so()),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.Hp.ti().uc(this.gg,this.bg)).$t}}class An{constructor(t,i,s,n){this.Hp=t,this.Pt=s,this.Mg=i,this.yg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Hp.ti(),s=i.Uc(this.Pt);i.mc(s,t)}getStretchFactor(){return this.Pt.Fa()}setStretchFactor(t){this.Pt.La(t),this.Hp.ti().Lh()}paneIndex(){return this.Hp.ti().Uc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Hp.Up().length,"Invalid pane index"),this.Hp.ti().gc(i,t))}getSeries(){return this.Pt.Wa().map(t=>this.Mg(t))??[]}getHTMLElement(){const t=this.Hp.Up();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Xp():null}attachPrimitive(t){this.Pt.ul(t),t.attached&&t.attached({chart:this.yg,requestUpdate:()=>this.Pt.ti().Lh()})}detachPrimitive(t){this.Pt.cl(t)}priceScale(t){if(null===this.Pt.Va(t))throw new Error(`Cannot find price scale with id: ${t}`);return new Bn(this.Hp,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Aa(t)}preserveEmptyPane(){return this.Pt.Oa()}addCustomSeries(t,i={},s=0){return this.yg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.yg.addSeries(t,i,this.paneIndex())}}const On={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Wn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Sg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.xg=new a,this.Qn=t,this.Cg=i,this.Pg=s,this.__=e,this.yg=n,this.Tg=r}m(){this.xg.m()}priceFormatter(){return this.Qn.rl()}priceToCoordinate(t){const i=this.Qn.At();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.At();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)).T_(),s=this.Qn.Xs();if(s.Gi())return null;const n=s.$r(i.Uh(),1),e=s.$r(i.yi(),-1),r=l(s.Or()),h=l(s.Gs());if(null!==n&&null!==e&&n.Ie>e.Ie)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Ie===r?t.from-r:n.Ie-r,barsAfter:null===e||e.Ie===h?h-t.to:h-e.Ie};return null!==n&&null!==e&&(o.from=n.Tw,o.to=e.Tw),o}setData(t){this.__,this.Qn.Ir(),this.Cg.kg(this.Qn,t),this.Dg("full")}update(t,i=!1){this.Qn.Ir(),this.Cg.Ig(this.Qn,t,i),this.Dg("update")}pop(t=1){const i=this.Cg.Vg(this.Qn,t);0!==i.length&&this.Dg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Xs().$r(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Xs().Nr().map(i=>t(i))}subscribeDataChanged(t){this.xg.i(t)}unsubscribeDataChanged(t){this.xg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Pg.priceScale(this.Qn.$t().wl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.Wh(i);return new Wn(s)}removePriceLine(t){this.Qn.zh(t.Sg())}priceLines(){return this.Qn.$h().map(t=>new Wn(t))}seriesType(){return this.Qn.Ir()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.I}}attachPrimitive(t){this.Qn.ul(t),t.attached&&t.attached({chart:this.yg,series:this,requestUpdate:()=>this.Qn.ti().Lh(),horzScaleBehavior:this.__})}detachPrimitive(t){this.Qn.cl(t),t.detached&&t.detached(),this.Qn.ti().Lh()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Tg(i)}moveToPane(t){this.Qn.ti().zc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.Wa().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.t_(this.Qn,t)}Dg(t){this.xg.v()&&this.xg.p(t)}}class $n{constructor(t,i,s){this.Rg=new a,this.A_=new a,this.bm=new a,this.ss=t,this.dh=t.Et(),this.Zm=i,this.dh.Ru().i(this.Fg.bind(this)),this.dh.Fu().i(this.Lg.bind(this)),this.Zm.Tm().i(this.Eg.bind(this)),this.__=s}m(){this.dh.Ru().u(this),this.dh.Fu().u(this),this.Zm.Tm().u(this),this.Rg.m(),this.A_.m(),this.bm.m()}scrollPosition(){return this.dh.bu()}scrollToPosition(t,i){i?this.dh.Du(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.dh.ku()}getVisibleRange(){const t=this.dh.eu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.__.convertHorzItemToInternal(t.from),to:this.__.convertHorzItemToInternal(t.to)},s=this.dh.ou(i);this.ss.Oc(s)}getVisibleLogicalRange(){const t=this.dh.nu();return null===t?null:{from:t.Uh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Oc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Bu()}logicalToCoordinate(t){const i=this.ss.Et();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.dh.Gi()?null:this.dh.du(t)}timeToIndex(t,i){const s=this.__.convertHorzItemToInternal(t);return this.dh.tu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.dh.jt(i)}coordinateToTime(t){const i=this.ss.Et(),s=i.du(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Zm.Zp().width}height(){return this.Zm.Zp().height}subscribeVisibleTimeRangeChange(t){this.Rg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Rg._(t)}subscribeVisibleLogicalRangeChange(t){this.A_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.A_._(t)}subscribeSizeChange(t){this.bm.i(t)}unsubscribeSizeChange(t){this.bm._(t)}applyOptions(t){this.dh.lr(t)}options(){return{...f(this.dh.W()),barSpacing:this.dh.wu()}}Fg(){this.Rg.v()&&this.Rg.p(this.getVisibleRange())}Lg(){this.A_.v()&&this.A_.p(this.getVisibleLogicalRange())}Eg(t){this.bm.p(t.width,t.height)}}function Hn(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 Nn{constructor(t,i,s){this.Bg=new Map,this.Ag=new Map,this.Og=new a,this.Wg=new a,this.zg=new a,this.ju=new WeakMap,this.$g=new _n(i);const n=void 0===s?f(En()):_(f(En()),Hn(s));this.Hg=i,this.Hp=new js(t,n,i),this.Hp.Xv().i(t=>{this.Og.v()&&this.Og.p(this.Ng(t()))},this),this.Hp.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ng(t()))},this),this.Hp.dc().i(t=>{this.zg.v()&&this.zg.p(this.Ng(t()))},this);const e=this.Hp.ti();this.Ug=new $n(e,this.Hp.sw(),this.Hg)}remove(){this.Hp.Xv().u(this),this.Hp.Zv().u(this),this.Hp.dc().u(this),this.Ug.m(),this.Hp.m(),this.Bg.clear(),this.Ag.clear(),this.Og.m(),this.Wg.m(),this.zg.m(),this.$g.m()}resize(t,i,s){this.autoSizeActive()||this.Hp.Qm(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},qg:bn,jg:t}))(o(t));return this.Yg(n,i,s)}addSeries(t,i={},s=0){return this.Yg(t,i,s)}removeSeries(t){const i=h(this.Bg.get(t)),s=this.$g.Bc(i);this.Hp.ti().Bc(i),this.Kg(s),this.Bg.delete(t),this.Ag.delete(i)}kg(t,i){this.Kg(this.$g.Hw(t,i))}Ig(t,i,s){this.Kg(this.$g.Kw(t,i,s))}Vg(t,i){const[s,n]=this.$g.Zw(t,i);return 0!==s.length&&this.Kg(n),s}subscribeClick(t){this.Og.i(t)}unsubscribeClick(t){this.Og._(t)}subscribeCrosshairMove(t){this.zg.i(t)}unsubscribeCrosshairMove(t){this.zg._(t)}subscribeDblClick(t){this.Wg.i(t)}unsubscribeDblClick(t){this.Wg._(t)}priceScale(t,i=0){return new Bn(this.Hp,t,i)}timeScale(){return this.Ug}applyOptions(t){this.Hp.lr(Hn(t))}options(){return this.Hp.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Hp.ti().W().crosshair.mode,this.Hp.lr({crosshair:{mode:2}})),n=this.Hp.ow(t)}finally{i||void 0===s||this.Hp.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Hp.ti().qc();return i.Aa(t),this.Gg(i)}removePane(t){this.Hp.ti().vc(t)}swapPanes(t,i){this.Hp.ti().wc(t,i)}autoSizeActive(){return this.Hp.dw()}chartElement(){return this.Hp.if()}panes(){return this.Hp.ti().qs().map(t=>this.Gg(t))}paneSize(t=0){const i=this.Hp.mw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Bg.get(s);if(void 0===n)return;const e=this.Hp.ti().Nn(n);null!==e&&this.Hp.ti().Ic(t,i,e)}clearCrosshairPosition(){this.Hp.ti().Vc(!0)}horzBehaviour(){return this.Hg}Yg(i,s={},n=0){r(void 0!==i.qg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Ai(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.qg,l=new Ut(this.Hp.ti(),i.type,e,h,i.jg);this.Hp.ti().Lc(l,n);const o=new zn(l,this,this,this,this.Hg,t=>this.Gg(t));return this.Bg.set(o,l),this.Ag.set(l,o),o}Kg(t){const i=this.Hp.ti();i.Rc(t.Et.uu,t.Et.ig,t.Et.sg),t.Wa.forEach((t,i)=>i.lt(t.ne,t.tg)),i.Et().G_(),i.mu()}Xg(t){return h(this.Ag.get(t))}Ng(t){const i=new Map;t.Vw.forEach((t,s)=>{const n=s.Ir(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.fl();r(!t||!1===t(e))}i.set(this.Xg(s),e)});const s=void 0!==t.Iw&&this.Ag.has(t.Iw)?this.Xg(t.Iw):void 0;return{time:t.Tw,logical:t.Ie,point:t.kw,paneIndex:t.Dw,hoveredSeries:s,hoveredObjectId:t.Rw,seriesData:i,sourceEvent:t.Fw}}Gg(t){let i=this.ju.get(t);return i||(i=new An(this.Hp,t=>this.Xg(t),t,this),this.ju.set(t,i)),i}}function Un(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 qn(t,i,s){const n=Un(t),e=new Nn(n,i,s);return i.setOptions(e.options()),e}function jn(t,i){return qn(t,new ss,ss.ad(i))}function Yn(){return ss}function Kn(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,Gl:r,Zg:n.time-h.time}}function Gn(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=Kn(t,i);if(null===h)return null;const l=r-h.Gl;return Math.round(h.gt+l*h.Zg)}function Xn(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=Kn(t,i);if(null===r)return null;const h=r.Gl+(s-r.gt)/r.Zg,l=n.logicalToCoordinate(h);return null===l?null:l}class Zn extends fn{constructor(t,i){super(t,i,!0)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.jo(this.hg,s,m(this.lg))}Jg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}dg(){const t=this.Qn.Ih();this.hg=this.Qn.Xs().Nr().map(i=>{const s=i.Ht[3];return this.Qg(i.Ie,s,t)})}}function Jn(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]=se(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 Qn=6;function te(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function ie(t,i){return{ut:t.ut/i,ct:t.ct/i}}function se(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=ie(te(t[s],t[n]),Qn),{ut:r.ut+h.ut,ct:r.ct+h.ct}),te(t[s],ie(te(t[e],t[i]),Qn))]}function ne(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class ee 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,tb:e,ib:r,dt:h,Xt:l,sb: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.nb.bind(this);void 0!==r&&Jn(t,i,r,s,e,_,ne),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&&(l.beginPath(),null!==o&&l.fill(),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 re extends ee{nb(t,i){return i.wt}}class he extends Zn{constructor(){super(...arguments),this._g=new re}Qg(t,i,s){return{...this.Jg(t,i),...s.Vr(t)}}vg(){const t=this.Qn.W(),i={_t:this.hg,Xt:t.lineStyle,ib:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.lg,tb:this.te.Et().wu()};this._g.lt(i)}}const le={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},qg:(t,i)=>new he(t,i)};function oe(t,i){return t.weight>i.weight?t:i}function ae(t){return t}class _e{constructor(){this.eb=new a,this.rb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.eb.p(this.hb)),this.hb=0}lb(){return this.eb}m(){this.eb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.rb(),t=>(t>this.hb&&(this.hb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.ob(t)}formatTickmark(t){return this.ob(t.time)}maxTickMarkWeight(t){return t.reduce(oe,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(ae(t[n].time));this.hb=t[t.length-1].time,this.rb()}ob(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 ue={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},ce={lastValueVisible:!1,priceLineVisible:!1};class de extends Nn{constructor(t,i){const s=_(ue,i||{}),n=new _e;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={...ce,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(le);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),ab:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ab:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ab:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.lb().i(n)}}function pe(t,i){const s=Un(t);return new de(s,i)}function fe(t,i){return t.weight>i.weight?t:i}class ve{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(fe,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 me(t,i){return qn(t,new ve,i)}function we(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 ge 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,tb:e,dt:r,Xt:h,ib:l}=this.ht,o=this.ht._b??(this.ht.ub?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,Jn(t,i,l,s,e,this.cb.bind(this),we.bind(null,o))}}class be{pb(t,i){const s=this.fb,{mb:n,wb:e,gb:r,bb:h,_b:l,Mb:o,yb:a}=i;if(void 0===this.Sb||void 0===s||s.mb!==n||s.wb!==e||s.gb!==r||s.bb!==h||s._b!==l||s.Mb!==o||s.yb!==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=Kt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Sb=p,this.fb=i}return this.Sb}}class Me extends ge{constructor(){super(...arguments),this.xb=new be}cb(t,i){const s=this.ht;return this.xb.pb(t,{mb:i.yr,wb:i.Sr,gb:i.Cr,bb:i.Pr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class ye extends ee{constructor(){super(...arguments),this.Cb=new be}nb(t,i){const s=this.ht;return this.Cb.pb(t,{mb:i.br,wb:i.br,gb:i.Mr,bb:i.Mr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class Se extends Zn{constructor(t,i){super(t,i),this._g=new x,this.Pb=new Me,this.Tb=new ye,this._g.nt([this.Pb,this.Tb])}Qg(t,i,s){return{...this.Jg(t,i),...s.Vr(t)}}vg(){const t=this.Qn.At();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.Et().wu();if(null===this.lg||0===this.hg.length)return;let e,r;if(i.relativeGradient){e=this.hg[this.lg.from].ct,r=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const i=this.hg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Pb.lt({_t:this.hg,dt:i.lineWidth,Xt:i.lineStyle,ib:i.lineType,_b:s,Mb:e,yb:r,ub:!1,ot:this.lg,tb:n}),this.Tb.lt({_t:this.hg,dt:i.lineWidth,Xt:i.lineStyle,ib:i.lineVisible?i.lineType:void 0,sb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,_b:s,Mb:e,yb:r,ot:this.lg,tb:n})}}const xe={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},qg:(t,i)=>new Se(t,i)};class Ce extends ge{constructor(){super(...arguments),this.xb=new be}cb(t,i){return this.xb.pb(t,{mb:i.wr,wb:"",gb:"",bb:i.gr,Mb:this.ht?.Mb??0,yb:t.bitmapSize.height})}}class Pe extends Zn{constructor(t,i){super(t,i),this._g=new x,this.kb=new Ce,this.Db=new re,this._g.nt([this.kb,this.Db])}Qg(t,i,s){return{...this.Jg(t,i),...s.Vr(t)}}vg(){const t=this.Qn.W();if(null===this.lg||0===this.hg.length)return;let i;if(t.relativeGradient){i=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const s=this.hg[t];s.ct<i&&(i=s.ct)}}this.kb.lt({ib:t.lineType,_t:this.hg,Xt:t.lineStyle,dt:t.lineWidth,_b:null,Mb:i,ub:t.invertFilledArea,ot:this.lg,tb:this.te.Et().wu()}),this.Db.lt({ib:t.lineVisible?t.lineType:void 0,_t:this.hg,Xt:t.lineStyle,dt:t.lineWidth,ot:this.lg,tb:this.te.Et().wu(),sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const Te={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},qg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Ib=0,this.Vb=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Xs.length||null===this.Yt.ot)return;if(this.Ib=this.Rb(i),this.Ib>=2){Math.max(1,Math.floor(i))%2!=this.Ib%2&&this.Ib--}this.Vb=this.Yt.Fb?Math.min(this.Ib,Math.floor(i)):this.Ib;let n=null;const e=this.Vb<=this.Ib&&this.Yt.wu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Xs[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Vb),o=Math.round(h.ut*i),a=o-l,_=this.Vb,u=a+_-1,c=Math.min(h.Xo,h.Zo),d=Math.max(h.Xo,h.Zo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Vb);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Ib);if(e){if(this.Yt.Lb){const i=o-m;let n=Math.max(p,Math.round(h.Go*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.Jo*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)}}}Rb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).wu,t)))}}class De extends fn{constructor(t,i){super(t,i,!1)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.Ko(this.hg,s,m(this.lg))}Eb(t,i,s){return{gt:t,jh:i.Ht[0],Yh:i.Ht[1],Kh:i.Ht[2],Gh:i.Ht[3],ut:NaN,Go:NaN,Xo:NaN,Zo:NaN,Jo:NaN}}dg(){const t=this.Qn.Ih();this.hg=this.Qn.Xs().Nr().map(i=>this.Qg(i.Ie,i,t))}}class Ie extends De{constructor(){super(...arguments),this._g=new ke}Qg(t,i,s){return{...this.Eb(t,i,s),...s.Vr(t)}}vg(){const t=this.Qn.W();this._g.lt({Xs:this.hg,wu:this.te.Et().wu(),Lb:t.openVisible,Fb:t.thinBars,ot:this.lg})}}const Ve={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},qg:(t,i)=>new Ie(t,i)};class Re extends C{constructor(){super(...arguments),this.Yt=null,this.Ib=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Xs.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Ib=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.wu,i),this.Ib>=2){Math.floor(i)%2!=this.Ib%2&&this.Ib--}const s=this.Yt.Xs;this.Yt.Bb&&this.Ab(t,s,this.Yt.ot),this.Yt.Mi&&this.cv(t,s,this.Yt.ot);const n=this.Ob(i);(!this.Yt.Mi||this.Ib>2*n)&&this.Wb(t,s,this.Yt.ot)}Ab(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.wu*e));l=Math.max(Math.floor(e),Math.min(l,this.Ib));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.Go,s.Jo)*r),u=Math.round(Math.max(s.Go,s.Jo)*r),c=Math.round(s.Xo*r),d=Math.round(s.Zo*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}}Ob(t){let i=Math.floor(1*t);this.Ib<=2*i&&(i=Math.floor(.5*(this.Ib-1)));const s=Math.max(Math.floor(t),i);return this.Ib<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}cv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(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.Ib);const _=a+this.Ib-1,u=Math.round(Math.min(s.Go,s.Jo)*r),c=Math.round(Math.max(s.Go,s.Jo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.wu*e>2*l)R(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Go,s.Jo)*r),a=Math.round(Math.max(s.Go,s.Jo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Ib),u=_+this.Ib-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 Fe extends De{constructor(){super(...arguments),this._g=new Re}Qg(t,i,s){return{...this.Eb(t,i,s),...s.Vr(t)}}vg(){const t=this.Qn.W();this._g.lt({Xs:this.hg,wu:this.te.Et().wu(),Bb:t.wickVisible,Mi:t.borderVisible,ot:this.lg})}}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"},qg:(t,i)=>new Fe(t,i)};class Ee extends C{constructor(){super(...arguments),this.Yt=null,this.zb=[]}lt(t){this.Yt=t,this.zb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.zb.length||this.$b(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Hb*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.zb[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.Uh,a,l.yi-l.Uh+1,_-a)}}$b(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.zb=[]);const i=Math.ceil(this.Yt.wu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.wu*t)-i;this.zb=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.zb[i-this.Yt.ot.from]={Uh:r,yi:h,Nb: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.zb[t-this.Yt.ot.from],n=this.zb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.Uh-n.yi!==i+1&&(n.Nb>n.ee?n.yi=s.Uh-i-1:s.Uh=n.yi+i+1))}let n=Math.ceil(this.Yt.wu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi<i.Uh&&(i.yi=i.Uh);const s=i.yi-i.Uh+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.zb[t-this.Yt.ot.from];i.yi-i.Uh+1>n&&(i.Nb>i.ee?i.yi-=1:i.Uh+=1)}}}class Be extends Zn{constructor(){super(...arguments),this._g=new Ee}Qg(t,i,s){return{...this.Jg(t,i),...s.Vr(t)}}vg(){const t={_t:this.hg,wu:this.te.Et().wu(),ot:this.lg,Hb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.At()).Ht)};this._g.lt(t)}}const Ae={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},qg:(t,i)=>new Be(t,i)};class Oe{constructor(t,i){this.Pt=t,this.Ub=i,this.qb()}detach(){this.Pt.detachPrimitive(this.Ub)}getPane(){return this.Pt}applyOptions(t){this.Ub.lr?.(t)}qb(){this.Pt.attachPrimitive(this.Ub)}}const We={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},ze={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class $e{constructor(t){this.jb=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.Yb(i,t.text);e>s.width?t.Cu=s.width/e:t.Cu=1,n+=t.lineHeight*t.Cu}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.Cu,t.Cu),i.fillText(t.text,0,t.Kb),i.restore(),e+=t.lineHeight*t.Cu}})}Yb(t,i){const s=this.Gb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Gb(t){let i=this.jb.get(t);return void 0===i&&(i=new Map,this.jb.set(t,i)),i}}class He{constructor(t){this.Ps=Ue(t)}Tt(t){this.Ps=Ue(t)}renderer(){return new $e(this.Ps)}}function Ne(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Kb:0,Cu:0}}function Ue(t){return{...t,lines:t.lines.map(Ne)}}function qe(t){return{...ze,...t}}function je(t){return{...We,...t,lines:t.lines?.map(qe)??[]}}class Ye{constructor(t){this.Ps=je(t),this.Xb=[new He(this.Ps)]}updateAllViews(){this.Xb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Xb}attached({requestUpdate:t}){this.Zb=t}detached(){this.Zb=void 0}lr(t){this.Ps=je({...this.Ps,...t}),this.Zb&&this.Zb()}}function Ke(t,i){return new Oe(t,new Ye(i))}const Ge={alpha:1,padding:0};class Xe{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Jb(this.Yt,t.mediaSize);s&&this.Yt.Qb&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.Qb,s.ut,s.ct,s.ts,s.qt))})}Jb(t,i){const{maxHeight:s,maxWidth:n,tM:e,iM: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 Ze{constructor(t){this.sM=null,this.nM=0,this.eM=0,this.Ps=t,this.M=Je(this.Ps,this.sM,this.nM,this.eM)}rM(t){void 0!==t.hM&&(this.nM=t.hM),void 0!==t.lM&&(this.eM=t.lM),void 0!==t.oM&&(this.sM=t.oM),this.Tt()}aM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Je(this.Ps,this.sM,this.nM,this.eM)}renderer(){return new Xe(this.M)}}function Je(t,i,s,n){return{...t,Qb:i,iM:s,tM:n}}function Qe(t){return{...Ge,...t}}class tr{constructor(t,i){this._M=null,this.uM=t,this.Ps=Qe(i),this.Xb=[new Ze(this.Ps)]}updateAllViews(){this.Xb.forEach(t=>t.Tt())}paneViews(){return this.Xb}attached(t){const{requestUpdate:i}=t;this.cM=i,this._M=new Image,this._M.onload=()=>{const t=this._M?.naturalHeight??1,i=this._M?.naturalWidth??1;this.Xb.forEach(s=>s.rM({lM:t,hM:i,oM:this._M})),this.cM&&this.cM()},this._M.src=this.uM}detached(){this.cM=void 0,this._M=null}lr(t){this.Ps=Qe({...this.Ps,...t}),this.dM(),this.Zb&&this.Zb()}Zb(){this.cM&&this.cM()}dM(){this.Xb.forEach(t=>t.aM(this.Ps))}}function ir(t,i,s){return new Oe(t,new tr(i,s))}class sr{constructor(t,i){this.Qn=t,this.ah=i,this.qb()}detach(){this.Qn.detachPrimitive(this.ah)}getSeries(){return this.Qn}applyOptions(t){this.ah&&this.ah.lr&&this.ah.lr(t)}qb(){this.Qn.attachPrimitive(this.ah)}}const nr={autoScale:!0,zOrder:"normal"};function er(t,i){return Xt(Math.min(Math.max(t,12),30)*i)}function rr(t,i){switch(t){case"arrowDown":case"arrowUp":return er(i,1);case"circle":return er(i,.8);case"square":return er(i,.7)}}function hr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(er(t,1))}function lr(t){return Math.max(er(t,.1),3)}function or(t,i,s){return i?t:s?Math.ceil(t/2):0}function ar(t,i,s,n){const e=(rr("arrowUp",n)-1)/2*s.pM,r=(Xt(n/2)-1)/2*s.pM;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 _r(t,i,s,n,e,r){const h=(rr("arrowUp",n)-1)/2,l=(Xt(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})()}class ur{constructor(){this.Yt=null,this.Wn=new it,this.$=-1,this.H="",this.Hf="",this.fM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Hf=g(t,i),this.Wn.Fn()),this.fM=s}Kn(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&&dr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.fM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.fM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle",t.font=this.Hf;for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n];void 0!==e.hi&&(e.hi.ts=this.Wn.Ri(t,e.hi.vM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2),cr(e,t,i,s)}}}}function cr(t,i,s,n){i.fillStyle=t.I,void 0!==t.hi&&function(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}(i,t.hi.vM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Ar)return;switch(t.mM){case"arrowDown":return void ar(!1,i,s,t.Ar);case"arrowUp":return void ar(!0,i,s,t.Ar);case"circle":return void function(t,i,s){const n=(rr("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.pM,0,2*Math.PI,!1),t.fill()}(i,s,t.Ar);case"square":return void function(t,i,s){const n=rr("square",s),e=(n-1)*i.pM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.pM,n*i.pM)}(i,s,t.Ar)}t.mM}(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,pM:i}}(t,s,n))}function dr(t,i,s){return!(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.Ar)return!1;switch(t.mM){case"arrowDown":return _r(!0,t.ut,t.ct,t.Ar,i,s);case"arrowUp":return _r(!1,t.ut,t.ct,t.Ar,i,s);case"circle":return function(t,i,s,n,e){const r=2+rr("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Ar,i,s);case"square":return function(t,i,s,n,e){const r=rr("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.Ar,i,s)}}(t,i,s)}function pr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function fr(t,i,s,n,e,r,h,o){const a=function(t,i,s){if(pr(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,h.priceScale().options().invertScale);if(void 0===a)return;const _=pr(i.position),c=o.timeScale(),d=u(i.size)?Math.max(i.size,0):1,p=hr(c.options().barSpacing)*d,f=p/2;t.Ar=p;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(a)),void(void 0!==t.hi&&(t.hi.ct=t.ct+f+r+.6*e));case"aboveBar":case"atPriceTop":{const i=_?0:n.wM;return t.ct=l(h.priceToCoordinate(a))-f-i,void 0!==t.hi&&(t.hi.ct=t.ct-f-.6*e,n.wM+=1.2*e),void(_||(n.wM+=p+r))}case"belowBar":case"atPriceBottom":{const i=_?0:n.gM;return t.ct=l(h.priceToCoordinate(a))+f+i,void 0!==t.hi&&(t.hi.ct=t.ct+f+r+.6*e,n.gM+=1.2*e),void(_||(n.gM+=p+r))}}}class vr{constructor(t,i,s){this.bM=[],this.xt=!0,this.MM=!0,this.Jt=new ur,this.be=t,this.Rf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.yM();const t=this.Rf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}SM(t){this.bM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.MM=!0)}xM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}yM(){const t=this.Rf.timeScale(),i=this.bM;this.MM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Ar:0,mM:t.shape,I:t.color,Gn:t.id,CM:t.CM,hi:void 0})),this.MM=!1);const s=this.Rf.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.data()[0])return;if(0===this.Yt._t.length)return;let r=NaN;const h=lr(t.options().barSpacing),o={wM:h,gM:h};this.Yt.ot=pn(this.Yt._t,e,!0);for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=i[n];e.time!==r&&(o.wM=h,o.gM=h,r=e.time);const a=this.Yt._t[n];a.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(a.hi={vM:e.text,ut:0,ct:0,ts:0,qt:0});const _=this.be.dataByIndex(e.time,0);null!==_&&fr(a,e,_,o,s.fontSize,h,this.be,this.Rf)}this.xt=!1}}function mr(t){return{...nr,...t}}class wr{constructor(t){this.nh=null,this.bM=[],this.PM=[],this.TM=null,this.be=null,this.Rf=null,this.kM=!0,this.DM=null,this.IM=null,this.VM=null,this.RM=!0,this.Ps=mr(t)}attached(t){this.FM(),this.Rf=t.chart,this.be=t.series,this.nh=new vr(this.be,l(this.Rf),this.Ps),this.cM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Dg(t)),this.RM=!0,this.Zb()}Zb(){this.cM&&this.cM()}detached(){this.be&&this.TM&&this.be.unsubscribeDataChanged(this.TM),this.Rf=null,this.be=null,this.nh=null,this.TM=null}SM(t){this.RM=!0,this.bM=t,this.FM(),this.kM=!0,this.IM=null,this.Zb()}LM(){return this.bM}paneViews(){return this.nh?[this.nh]:[]}updateAllViews(){this.EM()}hitTest(t,i){return this.nh?this.nh.renderer()?.Kn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.nh){const t=this.BM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=mr({...this.Ps,...t}),this.Zb&&this.Zb()}BM(){const t=l(this.Rf).timeScale().options().barSpacing;if(this.kM||t!==this.VM){if(this.VM=t,this.bM.length>0){const i=lr(t),s=1.5*hr(t)+2*i,n=this.AM();this.DM={above:or(s,n.aboveBar,n.inBar),below:or(s,n.belowBar,n.inBar)}}else this.DM=null;this.kM=!1}return this.DM}AM(){return null===this.IM&&(this.IM=this.bM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.IM}FM(){if(!this.RM||!this.Rf||!this.be)return;const t=this.Rf.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.PM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.PM=this.bM.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,CM:n,text:i.text,size:i.size,price:i.price,Tw: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.RM=!1}EM(t){this.nh&&(this.FM(),this.nh.SM(this.PM),this.nh.xM(this.Ps),this.nh.Tt(t))}Dg(t){this.RM=!0,this.Zb()}}class gr extends sr{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this.ah.SM(t)}markers(){return this.ah.LM()}}function br(t,i,s){const n=new gr(t,new wr(s??{}));return i&&n.setMarkers(i),n}class Mr{constructor(t){this.bM=new Map,this.OM=t}WM(t,i,s){if(this.zM(i),void 0!==s){const n=window.setTimeout(()=>{this.bM.delete(i),this.$M()},s),e={...t,HM:n,NM:Date.now()+s};this.bM.set(i,e)}else this.bM.set(i,{...t,HM:void 0,NM:void 0});this.$M()}zM(t){const i=this.bM.get(t);i&&void 0!==i.HM&&window.clearTimeout(i.HM),this.bM.delete(t),this.$M()}UM(){for(const[t]of this.bM)this.zM(t)}qM(){const t=Date.now(),i=[];for(const[s,n]of this.bM)!n.NM||n.NM>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.zM(s);return i}jM(t){this.OM=t}$M(){this.OM&&this.OM()}}const yr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Sr{constructor(t,i,s,n){this.Yt=t,this.YM=i,this.KM=s,this.GM=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.XM(e.ZM);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.ZM&&(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.ZM)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.ZM-7*e.ZM*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.ZM)*t.verticalPixelRatio),i.stroke())})})}XM(t){return 0===t?this.YM:t>0?this.GM:this.KM}}class xr{constructor(t,i,s){this.Yt=[],this.be=t,this.dh=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.dh.timeToCoordinate(t.time)),ct:i,ZM: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 Sr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Cr(t,i){return"Line"===i||"Area"===i}class Pr{constructor(t){this.Rf=void 0,this.be=void 0,this.Xb=[],this.__=null,this.JM=new Map,this.QM=new Mr(()=>this.Zb()),this.Ps={...yr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Zb()}SM(t){this.QM.UM();const i=this.__;i&&t.forEach(t=>{this.QM.WM(t,i.key(t.time))})}LM(){return this.QM.qM()}Zb(){this.cM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Rf=i,this.be=s,this.__=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.Xb=[new xr(this.be,this.Rf.timeScale(),this.Ps)],this.cM=n,this.Zb()}detached(){this.Rf=void 0,this.be=void 0,this.cM=void 0}jf(){return h(this.Rf)}Wa(){return h(this.be)}updateAllViews(){this.Xb.forEach(t=>t.Tt(this.LM()))}paneViews(){return this.Xb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.JM.clear();const s=this.__;s&&t.forEach(t=>{Gs(t)&&Cr(0,i)&&this.JM.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.__)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.__.key(t.time);if(Ks(t)&&this.JM.delete(n),Gs(t)&&Cr(0,s)){const i=this.JM.get(n);i&&this.QM.WM({time:t.time,value:t.value,sign:Tr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}ty(){this.QM.UM()}}function Tr(t,i){return t===i?0:t-i>0?1:-1}class kr extends sr{setData(t){return this.ah.lt(t)}update(t,i){return this.ah.Tt(t,i)}markers(){return this.ah.LM()}setMarkers(t){return this.ah.SM(t)}clearMarkers(){return this.ah.ty()}}function Dr(t,i={}){return new kr(t,new Pr(i))}class Ir{constructor(t,i){this.iy=null,this.sy=[],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.iy=br(t)}addPosition(t){this.sy.push(t),this.ny()}addPositions(t){this.sy.push(...t),this.ny()}setPositions(t){this.sy=[...t],this.ny()}closePosition(t,i,s){const n=this.sy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.ny())}removePosition(t){this.sy=this.sy.filter(i=>i.id!==t),this.ny()}clearPositions(){this.sy=[],this.ny()}getPositions(){return this.sy}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.ny()}ey(){const t=[];for(const i of this.sy){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}ny(){if(this.iy){const t=this.ey();this.iy.setMarkers(t)}}detach(){this.iy&&(this.iy.detach(),this.iy=null),this.sy=[]}}function Vr(t,i,s){const n=new Ir(t,s);return i&&i.length>0&&n.setPositions(i),n}const Rr=new WeakMap;function Fr(t){return"string"==typeof t?t:String(t)}function Lr(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Fr(t.time),t.volume);Rr.set(t,s)}function Er(t,i){return Rr.get(t)?.get(Fr(i))}function Br(t){const i=Rr.get(t);return void 0!==i&&i.size>0}const Ar="rgba(0, 0, 0, 0)";function Or(t){switch(t.seriesType()){case"Candlestick":return Wr(t,{upColor:Ar,downColor:Ar,borderVisible:!1,wickVisible:!1});case"Bar":return Wr(t,{upColor:Ar,downColor:Ar});case"Line":return Wr(t,{color:Ar,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Wr(t,{lineColor:Ar,topColor:Ar,bottomColor:Ar,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Wr(t,{topLineColor:Ar,topFillColor1:Ar,topFillColor2:Ar,bottomLineColor:Ar,bottomFillColor1:Ar,bottomFillColor2:Ar,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Wr(t,{color:Ar});default:return Wr(t,{visible:!1})}}function Wr(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 zr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function $r(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 Hr(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 Nr(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 Ur(t){return null==t?void 0:t.time}function qr(t){const{e_:i,jf:s,hy:n,ly:e,oy:r,Zl:h}=t,l=t._y??[];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=Ur(s[s.length-1])===Ur(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&&Ur(a[a.length-1])===Ur(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 jr(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(le,{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=Hr(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=qr({e_:t,jf:i,hy:[e],Zl:"SMA",W:n,_y:["period","source"],ly:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function Yr(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(le,{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=Hr(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=qr({e_:t,jf:i,hy:[e],Zl:"EMA",W:n,_y:["period","source"],ly:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function Kr(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(le,{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=Hr(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=qr({e_:t,jf:i,hy:[e],Zl:"WMA",W:n,_y:["period","source"],ly:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function Gr(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(le,{color:n.colorUpper},e),h=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=qr({e_:t,jf:i,hy:[r,h,l],Zl:"Bollinger Bands",W:n,_y:["period","stdDev"],ly:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{uy:[],py:[],vy:[]};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{uy:e,py:r,vy:h}})(t,i.period??20,i.stdDev??2);return[[r,s.uy],[h,s.py],[l,s.vy]]},oy: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 Xr(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(le,{color:n.colorUpper},e),h=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=qr({e_:t,jf:i,hy:[r,h,l],Zl:"Keltner Channels",W:n,_y:["period","atrPeriod","multiplier","source"],ly:(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{uy:[],py:[],vy:[]};const r=Hr(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{uy:c,py:d,vy:p}})(t,i);return[[r,s.uy],[h,s.py],[l,s.vy]]},oy: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 Zr(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(le,{color:n.colorUpper},e),h=i.addSeries(le,{color:n.colorMiddle},e),l=i.addSeries(le,{color:n.colorLower},e),o=qr({e_:t,jf:i,hy:[r,h,l],Zl:"Donchian Channels",W:n,_y:["period"],ly:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{uy:[],py:[],vy:[]};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{uy:s,py:n,vy:e}})(t,i.period??20);return[[r,s.uy],[h,s.py],[l,s.vy]]},oy: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 Jr(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(le,{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=qr({e_:t,jf:i,hy:[e],Zl:"Parabolic SAR",W:n,_y:["step","maxStep","colorUp","colorDown"],ly:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],oy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}}function Qr(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.my,i.wy-1,i.gy))}}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 th(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(le,{color:n.color},e),h=i.addSeries(le,{color:n.bandColor},e),l=i.addSeries(le,{color:n.bandColor},e),o=qr({e_:t,jf:i,hy:[r,h,l],Zl:"VWAP",W:n,_y:["anchorPeriod","bandMultiplier"],ly:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Br(t))return{by:e,uy:r,vy:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=Qr(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=Er(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{by:e,uy:r,vy:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.by],[h,n.uy],[l,n.vy]]},oy: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 ih(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(le,{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=qr({e_:t,jf:i,hy:[e],Zl:"SuperTrend",_y:["period","multiplier","colorUp","colorDown"],W:n,ly:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],oy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}}class sh{constructor(t,i,s,n){this.Rf=t,this.be=i,this.V_=s,this.My=n}draw(t){const i=this.My();if(!i.Rt||i.yy<=0)return;const s=this.V_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Rf.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.Sy),u=this.be.priceToCoordinate(h.xy),c=this.be.priceToCoordinate(l.Sy),d=this.be.priceToCoordinate(l.xy);if(null===_||null===u||null===c||null===d)continue;const p=h.Sy>=h.xy;n.fillStyle=this.Cy(p?i.Py:i.Ty,i.yy),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()}})}Cy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class nh{constructor(t,i,s,n){this.Jt=new sh(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function eh(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 rh(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(le,{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 nh(i,t,()=>u,()=>({Py:c.cloudBullishColor??"#089981",Ty:c.cloudBearishColor??"#F23645",yy:c.cloudOpacity??.15,Rt: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{ky:h,eh:l,Sy:o,xy:a,Dy:_,Iy: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=eh(t,i,s),u=eh(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=eh(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,Sy:s,xy:n};u.push(t)}}return{ky:h,eh:l,Sy:o,xy:a,Dy:_,Iy:u}},v=qr({e_:t,jf:i,hy:[h,l,o,a,_],Zl:"Ichimoku",W:n,_y:["conversionPeriod","basePeriod","spanBPeriod","displacement"],ly:(t,i)=>{c=i;const s=f(t,i);return u=s.Iy,[[h,s.ky],[l,s.eh],[o,s.Sy],[a,s.xy],[_,i.showLagging??1?s.Dy:[]]]},oy: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 hh(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(le,{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=qr({e_:t,jf:i,hy:[h,...l,...o],Zl:"Pivot Points",W:n,_y:["pivotPeriod"],ly:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{Vy:s,Ry:n,Fy:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=Qr(_.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={Ly:i,Ey:[2*i-l,i+s,h+2*(i-l)],By:[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.Ly});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Ey[t]}),e[t].push({time:_.time,value:a.By[t]})}}return{Vy:s,Ry:n,Fy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.Vy]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Ry[t]:[]]),e.push([o[t],t<n?s.Fy[t]:[]]);return e},oy: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 lh(t){return null!=t&&"number"==typeof t.close}function oh(t){const i=[];let s=null,n=null;for(const e of t){if(!lh(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 ah(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},n.paneIndex);let h=null;const l=i=>{i&&null===h?h=Or(t):i||null===h||(h(),h=null)},o=qr({e_:t,jf:i,hy:[r],Zl:"Heikin Ashi",W:n,_y:[],ly:t=>[[r,oh(t)]],oy: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{Wa:r,options:o.options,applyOptions:o.applyOptions,recalculate:o.recalculate,remove:()=>{o.remove();try{l(!1)}catch(t){}}}}function _h(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(le,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:zr(0,100)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Nr(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Hr(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=qr({e_:t,jf:i,hy:[r],Zl:"RSI",W:n,_y:["period","source"],ly:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],oy: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 uh(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(le,{color:n.colorMACD},e),h=i.addSeries(le,{color:n.colorSignal},e),l=i.addSeries(Ae,{color:n.colorHistogramUp},e),o=(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},a=qr({e_:t,jf:i,hy:[r,h,l],Zl:"MACD",W:n,_y:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],ly:(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{Ay:[],Oy:[],Wy:[]};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=o(r,s),l=o(r,n),a=[],_=n-s;for(let t=0;t<l.length;t++)a.push(h[t+_]-l[t]);const u=o(a,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=a[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{Ay:c,Oy:d,Wy:p}})(t,i);return[[r,s.Ay],[h,s.Oy],[l,s.Wy]]},oy:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),h.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:h,histogram:l,...a}}function ch(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=zr(0,100),h=i.addSeries(le,{color:n.colorK,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorD,autoscaleInfoProvider:r},e),o=$r(i,h,e);i.priceScale(h.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Nr(h,n.levelColor),_=qr({e_:t,jf:i,hy:[h,l],Zl:"Stochastic",W:n,_y:["kPeriod","dPeriod"],ly:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{zy:[],$y:[]};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{zy:e,$y:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.zy],[l,s.$y]]},oy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:l,..._}}function dh(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(le,{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=qr({e_:t,jf:i,hy:[e],Zl:"ATR",W:n,_y:["period"],ly:(t,i)=>[[e,r(t,i.period??14)]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function ph(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Ae,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=$r(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||!Br(t))return[];const e=[];for(const r of n){const n=Er(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=qr({e_:t,jf:i,hy:[r],Zl:"Volume",W:n,_y:["colorUp","colorDown"],ly:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...o}}function fh(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(le,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!Br(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=Er(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=qr({e_:t,jf:i,hy:[e],Zl:"OBV",W:n,ly:()=>[[e,r()]],oy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function vh(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=zr(0,100),h=i.addSeries(le,{color:n.colorADX,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorPlusDI,autoscaleInfoProvider:r},e),o=i.addSeries(le,{color:n.colorMinusDI,autoscaleInfoProvider:r},e),a=$r(i,h,e);i.priceScale(h.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Nr(h,n.levelColor),u=qr({e_:t,jf:i,hy:[h,l,o],Zl:"ADX",W:n,_y:["period"],ly:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Hy:[],Ny:[],Uy:[]};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{Hy:o,Ny:a,Uy:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Hy],[l,n?s.Ny:[]],[o,n?s.Uy:[]]]},oy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),o.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:l,minusDI:o,...u}}function mh(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(le,{color:n.color,lineWidth:n.lineWidth},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(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=qr({e_:t,jf:i,hy:[r],Zl:"CCI",W:n,_y:["period"],ly:(t,i)=>[[r,o(t,i.period??20)]],oy: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 wh(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(le,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:zr(-100,0)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(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=qr({e_:t,jf:i,hy:[r],Zl:"Williams %R",W:n,_y:["period"],ly:(t,i)=>[[r,o(t,i.period??14)]],oy: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 gh(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(le,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:zr(0,100)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Br(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*(Er(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=qr({e_:t,jf:i,hy:[r],Zl:"MFI",W:n,_y:["period"],ly:(t,i)=>[[r,o(t,i.period??14)]],oy: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 bh{constructor(t){this.qy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.qy.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.jy(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}jy(t,i,s,n){const e=i.Yy||i.startTime,r=i.Ky||i.endTime,h=i.I||i.color,l=i.yy||i.opacity;if(!i||!e||!r)return;const o=this.qy.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.Gy(h,l),t.fillRect(u,d,c-u,p-d)}Gy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Mh{constructor(t){this.Jt=new bh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const yh=[{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 Sh{constructor(t,i,s={}){this.Xy=[],this.Ub=null,this.nh=null,this.Rf=t,this.be=i,this.Ps={sessions:s.sessions||yh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.Zy(),this.Ps.enabled&&this.Jy()}Zy(){this.nh=new Mh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}Jy(){this.Rf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Qy()}),this.Qy()}Qy(){this.tS();const t=this.Rf.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.iS(s),this.cM()}iS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.sS(i,t);this.Ps.showOverlaps&&this.nS(t)}}sS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.eS(i);this.rS(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.hS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.hS(s,n[n.length-1].time,t)}nS(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.lS(e,r);h&&this.oS(h,t)}}lS(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}oS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.eS(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.aS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.aS(s,n[n.length-1].time)}hS(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",Yy:t,Ky:i,I:s.color,yy:s.opacity,_S:s.name};this.Xy.push(n)}aS(t,i){const s={an:"overlap",Yy:t,Ky:i,I:this.Ps.overlapColor,yy:this.Ps.overlapOpacity,_S:"Overlap"};this.Xy.push(s)}rS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}eS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}tS(){this.Xy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Qy():this.tS(),this.cM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Qy(),this.cM()}disable(){this.Ps.enabled=!1,this.tS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.tS(),this.cM()}getSessionBoxes(){return this.Xy}getChart(){return this.Rf}getSeries(){return this.be}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rf.timeScale().applyOptions({})}}function xh(t,i,s){return new Sh(t,i,s)}class Ch{constructor(t){this.qy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.qy.getProfileData();if(!s||0===s.bins.length)return;const n=this.qy.options(),e=this.qy.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.uS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.cS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.dS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}uS(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.Gy(M,y),t.fillRect(f,v,m,w)}cS(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([])}dS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Gy(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.Gy(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([])}Gy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Ph{constructor(t){this.Jt=new Ch(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Th{constructor(t,i,s={}){this.pS=null,this.fS=new Map,this.Ub=null,this.nh=null,this.Rf=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.Zy(),this.Jy()}Zy(){this.nh=new Ph(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}Jy(){this.Rf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.vS()}),this.vS()}setVolumeData(t){this.fS=t,this.vS()}addVolumeData(t,i){this.fS.set(t,i),this.vS()}vS(){const t=this.Rf.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.fS.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.pS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.cM()}getProfileData(){return this.pS}applyOptions(t){this.Ps={...this.Ps,...t},this.vS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.pS=null,this.fS.clear(),this.cM()}getChart(){return this.Rf}getSeries(){return this.be}options(){return this.Ps}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rf.timeScale().applyOptions({})}}function kh(t,i,s){return new Th(t,i,s)}function Dh(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)}class Ih{constructor(t,i){this.mS=new Map,this.wS=null,this.gS=null,this.bS=null,this.MS=null,this.yS=null,this.SS=null,this.bg=void 0,this.Rf=t,this.kf=i,this.xS=t=>this.CS(t),this.PS=t=>this.TS(t),this.kS=t=>this.DS(t),this.IS=t=>this.VS(t),this.RS=()=>this.FS(),this.LS=t=>{"Escape"===t.key&&this.FS()},this.Rf.subscribeCrosshairMove(this.xS),this.kf.addEventListener("pointerdown",this.PS),this.kf.addEventListener("pointermove",this.kS),this.kf.addEventListener("pointerup",this.IS),this.kf.addEventListener("pointercancel",this.RS),document.addEventListener("keydown",this.LS)}ES(t){this.mS.set(t.id(),t)}BS(t){const i=t.id();this.wS===i&&this.AS(null),this.gS===t&&this.FS(),this.mS.delete(i)}Gi(){return 0===this.mS.size}m(){this.Rf.unsubscribeCrosshairMove(this.xS),this.kf.removeEventListener("pointerdown",this.PS),this.kf.removeEventListener("pointermove",this.kS),this.kf.removeEventListener("pointerup",this.IS),this.kf.removeEventListener("pointercancel",this.RS),document.removeEventListener("keydown",this.LS),this.mS.clear()}CS(t){if(this.SS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.bg=t.paneIndex,null!==this.gS)return;const i=this.OS(t.hoveredObjectId);this.AS(i?i.id():null),this.WS()}TS(t){const i=null===this.wS?null:this.mS.get(this.wS)??null;i&&(this.MS={ut:t.clientX,ct:t.clientY},this.yS=i,i.isDraggable()&&(this.gS=i,this.bS=t.pointerId,this.kf.setPointerCapture(t.pointerId),i.beginDrag(),this.WS(),t.preventDefault(),t.stopPropagation()))}DS(t){if(null===this.gS)return;if(!this.zS(t))return void this.FS();const i=this.$S(t);null!==i&&this.gS.dragTo(i),t.preventDefault(),t.stopPropagation()}VS(t){const i=this.gS,s=this.yS,n=this.MS;this.HS(),this.yS=null,this.MS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.gS=null,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.WS();null!==s&&!e&&s.isClickable()&&s.click()}FS(){if(null===this.gS)return;const t=this.gS;this.gS=null,this.HS(),t.cancelDrag(),this.WS()}zS(t){const i=this.kf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}HS(){null!==this.bS&&(this.kf.hasPointerCapture(this.bS)&&this.kf.releasePointerCapture(this.bS),this.bS=null)}$S(t){const i=this.gS;if(null===i)return null;if(null!==this.SS&&this.bg===i.paneIndex())return i.priceAt(this.SS.ct);const s=this.Rf.panes()[i.paneIndex()],n=s?s.getHTMLElement():null;return n?i.priceAt(t.clientY-n.getBoundingClientRect().top):null}OS(t){return"string"!=typeof t?null:this.mS.get(t)??null}AS(t){this.wS!==t&&(null!==this.wS&&this.mS.get(this.wS)?.setHovered(!1),this.wS=t,null!==t&&this.mS.get(t)?.setHovered(!0))}WS(){if(null!==this.gS)return void this.Rf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.wS?null:this.mS.get(this.wS);t?this.Rf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Rf.chartElement().style.removeProperty("cursor")}}const Vh=new WeakMap;let Rh=0;class Fh{constructor(t,i,s){this.sr=null,this.NS=!1,this.US="",this.qS=null,this.Rf=t,this.be=i,this.yo="pipsend-trading-line-"+Rh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.jS(),(this.Ps.draggable||this.Ps.onClick)&&function(t){const i=t.chartElement();if(!i)return null;let s=Vh.get(t);return s||(s=new Ih(t,i),Vh.set(t,s)),s}(this.Rf)?.ES(this)}id(){return this.yo}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.NS!==t&&this.sr&&(this.NS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.US}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.qS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.YS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.qS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.qS;this.qS=null,null!==t&&t!==this.Ps.price&&(this.YS(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.US=t.color),!this.sr)return;const i={title:this.KS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.NS||(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.YS(t)}remove(){!function(t,i){const s=Vh.get(t);s&&(s.BS(i),s.Gi()&&(s.m(),Vh.delete(t)))}(this.Rf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}KS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}jS(){this.US=this.Ps.color,this.sr=this.be.createPriceLine({id:this.yo,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.KS()})}YS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.KS()})}}function Lh(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 Fh(i,t,r)}class Eh{constructor(t,i){this.Vf=null,this.GS=null,this.XS=null,this.ZS={},this.Rf=t,this.be=i,this.JS()}JS(){this.Vf=this.Rf.chartElement()}QS(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.Vf?(this.GS=t,this.ZS=i||{},new Promise(t=>{this.Vf.style.cursor="crosshair",this.XS=i=>{const s=this.QS(i),n=this.tx(s);this.disableClickToCreate(),t(n)},this.Vf.addEventListener("click",this.XS)})):Promise.resolve(null)}disableClickToCreate(){this.Vf&&this.XS&&(this.Vf.removeEventListener("click",this.XS),this.Vf.style.cursor="default"),this.GS=null,this.XS=null,this.ZS={}}tx(t){if(!this.GS)return null;let i;switch(this.GS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.ZS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.ZS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.ZS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.ZS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.ZS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.ZS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.ZS};break;default:return null}return new Fh(this.Rf,this.be,i)}getCreationMode(){return this.GS}isCreating(){return null!==this.GS}}function Bh(t,i){return new Eh(t,i)}const Ah=new Set(["line","body","stroke","center","move"]);function Oh(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?Ah.has(n)?"move":"grab":void 0}}function Wh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var zh;function $h(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.my;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.wy,t.day=i.day??i.gy,t}return t}function Hh(t,i){const s={};return s.price=t,s.time=i,s}function Nh(t){if(!t)return Hh(0,null);return Hh(t.price??t.bt??0,$h(t.time??t.gt??null))}function Uh(t,i="time"){return t?t[i]??null:null}function qh(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"}(zh||(zh={}));class jh{constructor(t,i,s={}){this._state=zh.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.ix(),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}ix(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}_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}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 Yh=new WeakMap;function Kh(t,i){Yh.set(t,i)}function Gh(t){const i=!0===Yh.get(t);return i&&Yh.set(t,!1),i}function Xh(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.Ot,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.sx??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Zh;!function(t){t.nx="idle",t.hx="waiting_first_point",t.lx="waiting_second_point",t.ox="completed"}(Zh||(Zh={}));class Jh{constructor(t,i,s={}){this.Rv=Zh.nx,this._x=null,this.XS=null,this.sp=null,this.Rf=t,this.be=i,this.ux=s}vx(){this.Rv===Zh.nx&&(this.Rv=Zh.hx,this._x=null,this.mx(),this.wx())}gx(){this.Rv=Zh.nx,this._x=null,this.bx(),this.Mx(),this.ux.yx&&this.ux.yx()}Sx(){return this.Rv}xx(){return this.Rv===Zh.hx||this.Rv===Zh.lx}mx(){this.XS=t=>{this.Cx(t)},this.Rf.subscribeClick(this.XS)}wx(){this.sp=t=>{this.Px(t)},this.Rf.subscribeCrosshairMove(this.sp)}bx(){this.XS&&(this.Rf.unsubscribeClick(this.XS),this.XS=null)}Mx(){this.sp&&(this.Rf.unsubscribeCrosshairMove(this.sp),this.sp=null)}Cx(t){if(!t.point)return;if(Gh(this.Rf))return;const i=this.be.coordinateToPrice(t.point.y),s=Gn(this.Rf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Rv===Zh.hx?(this._x=n,this.Rv=Zh.lx,this.ux.Tx&&this.ux.Tx(n)):this.Rv===Zh.lx&&this._x&&(this.Rv=Zh.ox,this.ux.kx&&this.ux.kx(n),this.ux.Dx&&this.ux.Dx(this._x,n),this.bx(),this.Mx(),this.Rv=Zh.nx,this._x=null)}Px(t){if(!t.point)return;if(this.Rv!==Zh.lx)return;const i=this.be.coordinateToPrice(t.point.y),s=Gn(this.Rf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.ux.Ix&&this.ux.Ix(n)}m(){this.gx()}}class Qh{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class tl{constructor(t){this.Vx=t,this.Jt=new Qh(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class il extends jh{constructor(t,i){super(t,"trend-line",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.Ox=null,this.Wx=null,this.zx=!1,this.$x=null,this.Hx={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.Hx),this.Zy(),this.Hx.interactive?this.Nx():this.zx=!0}Nx(){new Jh(this._chart,this._series,{Tx:t=>{this.Hx.point1Time=t.gt,this.Hx.point1Price=t.bt,this.cM()},kx:t=>{this.Hx.point2Time=t.gt,this.Hx.point2Price=t.bt,this.zx=!0,this.cM(),this.Hx.onUpdate&&this.Hx.onUpdate()},Ix:t=>{this.Hx.point1Time&&!this.zx&&(this.$x=t,this.cM())},Dx:()=>{this.zx=!0}}).vx()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new tl(this)}jx(){if(!this.Hx.point1Time||!this.Hx.point2Time)return null;const t=Xn(this._chart,this._series,this.Hx.point1Time)??0,i=this._series.priceToCoordinate(this.Hx.point1Price)??0,s=Xn(this._chart,this._series,this.Hx.point2Time)??0,n=this._series.priceToCoordinate(this.Hx.point2Price)??0;if(!this.Hx.extendLeft&&!this.Hx.extendRight)return{Yx:t,Kx:i,Gx:s,Xx:n};if(s===t)return{Yx:t,Kx:i,Gx:s,Xx:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{Yx:this.Hx.extendLeft?0:t,Kx:this.Hx.extendLeft?i-r*t:i,Gx:this.Hx.extendRight?e:s,Xx:this.Hx.extendRight?i+r*(e-t):n}}Zx(){const t=this.jx();if(null===t)return null;const i=t.Gx>=t.Yx?t.Xx:t.Kx,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.Hx.point2Price??this.Hx.point1Price??null}drawToCanvas(t,i,s){if(!this.zx&&this.Hx.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.Hx.point1Time||!this.Hx.point2Time)return;const n=(Xn(this._chart,this._series,this.Hx.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.Hx.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.Hx.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.Hx.point2Price)??0)*s,l=this.Hx.lineColor,o=this.Fx?this.Hx.lineWidth+1:this.Hx.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.Hx.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.Hx.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.jx();if(null===a)return;t.moveTo(a.Yx*i,a.Kx*s),t.lineTo(a.Gx*i,a.Xx*s),t.stroke(),t.setLineDash([]),!this.Fx&&!this.Lx||this.isLocked()||(this.Qx(t,n,e,i,l),this.Qx(t,r,h,i,l));const _=this.Zx();if(!1!==this.Hx.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Xh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}Jx(t,i,s){if(!this.Hx.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.Hx.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.Hx.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.$x.gt)??0)*i,h=(this._series.priceToCoordinate(this.$x.bt)??0)*s;t.strokeStyle=this.Hx.lineColor,t.lineWidth=this.Hx.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.Qx(t,n,e,i,this.Hx.lineColor),t.globalAlpha=.5,this.Qx(t,r,h,i,this.Hx.lineColor),t.globalAlpha=1}Qx(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.Hx.lineColor=t,this.cM()}color(){return this.Hx.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}isHovered(){return this.Lx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){const s=this.jx();if(null===s)return!1;return this.tC(t,i,s.Yx,s.Kx,s.Gx,s.Xx)<=8}tC(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.Hx.point1Time||!this.Hx.point2Time)return null;const s=Xn(this._chart,this._series,this.Hx.point1Time)??0,n=this._series.priceToCoordinate(this.Hx.point1Price)??0,e=Xn(this._chart,this._series,this.Hx.point2Time)??0,r=this._series.priceToCoordinate(this.Hx.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.tC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.Ex=!0,this.Bx=t,this.Ax=i,"line"===t&&(this.Ox={gt:this.Hx.point1Time,bt:this.Hx.point1Price},this.Wx={gt:this.Hx.point2Time,bt:this.Hx.point2Price})}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.Ox=null,this.Wx=null}updateDrag(t,i){if(this.Ex&&this.Bx){if("point1"===this.Bx)this.Hx.point1Time=t,this.Hx.point1Price=i;else if("point2"===this.Bx)this.Hx.point2Time=t,this.Hx.point2Price=i;else if("line"===this.Bx&&this.Ox&&this.Wx){const s=Wh(this.Ax,t,i);this.Hx.point1Time=this.Ox.gt+s.gt,this.Hx.point1Price=this.Ox.bt+s.bt,this.Hx.point2Time=this.Wx.gt+s.gt,this.Hx.point2Price=this.Wx.bt+s.bt}this.cM(),this.Hx.onUpdate&&this.Hx.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Hh(this.Hx.point1Price??0,$h(this.Hx.point1Time)),Hh(this.Hx.point2Price??0,$h(this.Hx.point2Time))],style:{lineColor:this.Hx.lineColor,lineWidth:this.Hx.lineWidth,lineStyle:this.Hx.lineStyle,extendLeft:this.Hx.extendLeft,extendRight:this.Hx.extendRight}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.Hx.onRemove&&this.Hx.onRemove()}}function sl(t,i){return new il(t,i)}class nl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class el{constructor(t){this.Vx=t,this.Jt=new nl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class rl extends jh{constructor(t,i){super(t,"horizontal-line",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Ax=null,this.iC=0,this.sC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.sC),this.Zy()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new el(this)}nC(){return void 0===this.sC.startTime?0:Xn(this._chart,this._series,this.sC.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.sC.price)return;const n=(this._series.priceToCoordinate(this.sC.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.nC()*i,h=this.sC.lineColor,l=this.Fx?this.sC.lineWidth+1:this.sC.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.sC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.sC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.sC.showPriceLabel&&Xh(t,this._series,i,s,{bt:this.sC.price,ct:n/s,Ot:h}),this.sC.showLabel&&(this.Fx||this.Lx)&&this.eC(t,n,i,s,h)}eC(t,i,s,n,e){const r=this.sC.labelText||this.sC.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.sC.lineColor=t,this.cM()}color(){return this.sC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.sC.price)return!1;const s=this._series.priceToCoordinate(this.sC.price)??0;return!(t<this.nC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.Ex=!0,this.Ax=i,this.iC=this.sC.price??0}stopDrag(){this.Ex=!1,this.Ax=null}updateDrag(t,i){this.Ex&&(this.sC.price=this.iC+Wh(this.Ax,t,i).bt,this.cM(),this.sC.onUpdate&&this.sC.onUpdate())}getPrice(){return this.sC.price}setPrice(t){this.sC.price=t,this.cM()}setLabel(t){this.sC.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Hh(this.sC.price??0,$h(this.sC.startTime))],style:{lineColor:this.sC.lineColor,lineWidth:this.sC.lineWidth,lineStyle:this.sC.lineStyle,showLabel:this.sC.showLabel,labelText:this.sC.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.sC.onRemove&&this.sC.onRemove()}}function hl(t,i){return new rl(t,i)}class ll{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ol{constructor(t){this.Vx=t,this.Jt=new ll(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class al extends jh{constructor(t,i){super(t,"cross-line",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Ax=null,this.rC=0,this.iC=0,this.hC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.hC),this.Zy()}Zy(){this.nh=new ol(this);const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Rx&&this.Rx()}_update(){this.cM()}lC(){if(void 0===this.hC.time||void 0===this.hC.price)return null;const t=Xn(this._chart,this._series,this.hC.time),i=this._series.priceToCoordinate(this.hC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.lC();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.hC.lineColor,_=this.Fx||this.Lx&&!this.isLocked(),u=_?this.hC.lineWidth+1:this.hC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.hC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.hC.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.hC.showPriceLabel&&void 0!==this.hC.price&&Xh(t,this._series,i,s,{bt:this.hC.price,ct:n.ct,Ot: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())}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){const s=this.lC();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.Ex=!0,this.Ax=i,this.rC=this.hC.time,this.iC=this.hC.price??0}updateDrag(t,i){if(!this.Ex)return;const s=Wh(this.Ax,t,i);this.hC.time=this.rC+s.gt,this.hC.price=this.iC+s.bt,this.cM(),this.hC.onUpdate&&this.hC.onUpdate()}stopDrag(){this.Ex=!1,this.Ax=null}setColor(t){this.hC.lineColor=t,this.cM()}color(){return this.hC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}remove(){if(this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Rx=null,this.hC.onRemove&&this.hC.onRemove()}_serializeShape(){return{type:"crossLine",points:[Hh(this.hC.price??0,$h(this.hC.time))],style:{lineColor:this.hC.lineColor,lineWidth:this.hC.lineWidth,lineStyle:this.hC.lineStyle}}}}function _l(t,i){return new al(t,i)}class ul{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class cl{constructor(t){this.Vx=t,this.Jt=new ul(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class dl extends jh{constructor(t,i){super(t,"polygon",i),this.V_=[],this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.oC=null,this.zx=!1,this.$x=null,this.XS=null,this.aC=null,this._C=null,this.uC={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.uC),this.V_=[...i.points??[]],this.Zy(),this.uC.interactive?this.cC():this.zx=this.V_.length>=3}Zy(){this.nh=new cl(this);const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Rx&&this.Rx()}_update(){this.cM()}cC(){this.XS=t=>{if(!t.point||Gh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.V_.length>=3&&this.dC(t.point.x,t.point.y)?this.pC():(this.V_.push({time:s,price:i}),this.cM()))},this.aC=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={time:s,price:i},this.cM())},this._C=t=>{"Enter"===t.key&&this.V_.length>=3?this.pC():"Escape"===t.key&&(this.V_=[],this.pC())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aC),document.addEventListener("keydown",this._C)}dC(t,i){const s=this.V_[0],n=Xn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=dl.fC&&Math.abs(i-e)<=dl.fC)}pC(){this.zx=!0,this.$x=null,this.vC(),this.cM(),this.uC.onComplete&&this.uC.onComplete(),this.uC.onUpdate&&this.uC.onUpdate()}vC(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aC&&(this._chart.unsubscribeCrosshairMove(this.aC),this.aC=null),this._C&&(document.removeEventListener("keydown",this._C),this._C=null)}mC(){const t=[...this.V_];return this.zx||null===this.$x||t.push(this.$x),this.wC(t)}wC(t){const i=[];for(const s of t){const t=Xn(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.mC();if(n.length<2)return;const e=this.uC.borderColor,r=this.Fx?this.uC.borderWidth+1:this.uC.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.zx&&(t.closePath(),this.uC.fillOpacity>0&&(t.fillStyle=this.Cy(this.uC.fillColor,this.uC.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.zx?"dashed"===this.uC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.uC.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.Fx||this.Lx||!this.zx)&&!this.isLocked())for(const n of this.gC())this.bC(t,n.ut*i,n.ct*s,i,e)}gC(){return this.wC(this.V_)}bC(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()}Cy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){const s=this.gC();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.gC();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.Ex=!0,this.Bx=t,this.Ax=i,this.oC=this.V_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.Ex&&null!==this.Bx&&null!==this.oC){if("shape"===this.Bx){const s=Wh(this.Ax,t,i);this.V_=this.oC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.Bx;this.V_[s]&&(this.V_[s]={time:t,price:i})}this.cM(),this.uC.onUpdate&&this.uC.onUpdate()}}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.oC=null}setColor(t){this.uC.borderColor=t,this.uC.fillColor=t,this.cM()}color(){return this.uC.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}points(){return this.V_}remove(){if(this.vC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Rx=null,this.uC.onRemove&&this.uC.onRemove()}_serializeShape(){return{type:"polygon",points:this.V_.map(t=>Hh(t.price,$h(t.time))),style:{fillColor:this.uC.fillColor,fillOpacity:this.uC.fillOpacity,borderColor:this.uC.borderColor,borderWidth:this.uC.borderWidth,borderStyle:this.uC.borderStyle}}}}function pl(t,i){return new dl(t,i)}dl.fC=12;class fl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class vl{constructor(t){this.Vx=t,this.Jt=new fl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ml extends jh{constructor(t,i){super(t,"parallel-channel",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null,this.zx=!1,this._d=0,this.$x=null,this.XS=null,this.aC=null,this.yC={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.yC),this.Zy(),this.yC.interactive?this.cC():this.zx=!0}Zy(){this.nh=new vl(this);const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Rx&&this.Rx()}_update(){this.cM()}cC(){this.XS=t=>{if(!t.point||Gh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.yC.point1Time=s,this.yC.point1Price=i;else{if(1!==this._d)return this.yC.channelWidth=i-this.SC(s),void this.pC();this.yC.point2Time=s,this.yC.point2Price=i}this._d++,this.cM()}},this.aC=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={gt:s,bt:i},2===this._d&&(this.yC.channelWidth=i-this.SC(s)),this.cM())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aC)}pC(){this.zx=!0,this.$x=null,this.vC(),this.cM(),this.yC.onComplete&&this.yC.onComplete(),this.yC.onUpdate&&this.yC.onUpdate()}vC(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aC&&(this._chart.unsubscribeCrosshairMove(this.aC),this.aC=null)}SC(t){const i=this.yC.point1Time,s=this.yC.point2Time,n=this.yC.point1Price,e=this.yC.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)}mS(){const t=this.yC,i=this.zx?t.point2Time:t.point2Time??this.$x?.gt,s=this.zx?t.point2Price:t.point2Price??this.$x?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Xn(this._chart,this._series,t.point1Time),e=Xn(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:{Yx:n,Gx:l,xC:r,CC:o,PC:_,TC:u}}drawToCanvas(t,i,s){const n=this.mS();if(null===n)return;const e=this.yC,r=e.lineColor,h=this.Fx?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Cy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Yx*l,n.xC*o),t.lineTo(n.Gx*l,n.CC*o),t.lineTo(n.Gx*l,n.TC*o),t.lineTo(n.Yx*l,n.PC*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.zx?"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.Yx*l,n.xC*o),t.lineTo(n.Gx*l,n.CC*o),0!==(e.channelWidth??0)&&(t.moveTo(n.Yx*l,n.PC*o),t.lineTo(n.Gx*l,n.TC*o)),t.stroke(),t.setLineDash([]);if((this.Fx||this.Lx||!this.zx)&&!this.isLocked()&&(this.bC(t,n.Yx*l,n.xC*o,l,r),this.bC(t,n.Gx*l,n.CC*o,l,r),0!==(e.channelWidth??0))){const i=(n.Yx+n.Gx)/2,s=(n.PC+n.TC)/2;this.bC(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.zx){const i=this._series.coordinateToPrice(n.CC);null!==i&&Xh(t,this._series,l,o,{bt:i,ct:n.CC,Ot:r})}}bC(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()}Cy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}kC(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.mS();if(null===s)return!1;return this.kC(t,i,s.Yx,s.xC,s.Gx,s.CC)<=8||this.kC(t,i,s.Yx,s.PC,s.Gx,s.TC)<=8}hitTestEndpoint(t,i){const s=this.mS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.Yx,s.xC))return"point1";if(n(s.Gx,s.CC))return"point2";if(0!==(this.yC.channelWidth??0)){if(n((s.Yx+s.Gx)/2,(s.PC+s.TC)/2))return"width"}return null}startDrag(t,i){this.Ex=!0,this.Bx=t,this.Ax=i,this.MC={DC:{gt:this.yC.point1Time,bt:this.yC.point1Price},IC:{gt:this.yC.point2Time,bt:this.yC.point2Price},ts:this.yC.channelWidth??0}}updateDrag(t,i){if(!this.Ex||null===this.Bx||null===this.MC)return;const s=this.yC;if("point1"===this.Bx)s.point1Time=t,s.point1Price=i;else if("point2"===this.Bx)s.point2Time=t,s.point2Price=i;else if("width"===this.Bx)s.channelWidth=i-this.SC(t);else{const n=Wh(this.Ax,t,i);s.point1Time=this.MC.DC.gt+n.gt,s.point1Price=this.MC.DC.bt+n.bt,s.point2Time=this.MC.IC.gt+n.gt,s.point2Price=this.MC.IC.bt+n.bt,s.channelWidth=this.MC.ts}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null}setColor(t){this.yC.lineColor=t,this.yC.fillColor=t,this.cM()}color(){return this.yC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}remove(){if(this.vC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Rx=null,this.yC.onRemove&&this.yC.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Hh(this.yC.point1Price??0,$h(this.yC.point1Time)),Hh(this.yC.point2Price??0,$h(this.yC.point2Time))],style:{lineColor:this.yC.lineColor,lineWidth:this.yC.lineWidth,lineStyle:this.yC.lineStyle,fillColor:this.yC.fillColor,fillOpacity:this.yC.fillOpacity,extendRight:this.yC.extendRight},extra:{channelWidth:this.yC.channelWidth}}}}function wl(t,i){return new ml(t,i)}class gl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class bl{constructor(t){this.Vx=t,this.Jt=new gl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ml extends jh{constructor(t,i){super(t,"pitchfork",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null,this.zx=!1,this._d=0,this.$x=null,this.XS=null,this.aC=null,this.VC={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.VC),this.Zy(),this.VC.interactive?this.cC():this.zx=!0}Zy(){this.nh=new bl(this);const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.Rx&&this.Rx()}_update(){this.cM()}cC(){this.XS=t=>{if(!t.point||Gh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.VC.pivotTime=s,this.VC.pivotPrice=i;else{if(1!==this._d)return this.VC.lowerTime=s,this.VC.lowerPrice=i,this._d++,void this.pC();this.VC.upperTime=s,this.VC.upperPrice=i}this._d++,this.cM()}},this.aC=t=>{if(!t.point||this.zx)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.$x={gt:s,bt:i},this.cM())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.aC)}pC(){this.zx=!0,this.$x=null,this.vC(),this.cM(),this.VC.onComplete&&this.VC.onComplete(),this.VC.onUpdate&&this.VC.onUpdate()}vC(){this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.aC&&(this._chart.unsubscribeCrosshairMove(this.aC),this.aC=null)}RC(t,i){if(void 0===t||void 0===i)return null;const s=Xn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}FC(){const t=this.VC,i=this.RC(t.pivotTime,t.pivotPrice),s=this.RC(t.upperTime,t.upperPrice),n=this.zx?this.RC(t.lowerTime,t.lowerPrice):this.RC(t.lowerTime,t.lowerPrice)??(null!==this.$x&&this._d>=2?this.RC(this.$x.gt,this.$x.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{Vy:i,LC:e,uy:s,vy:n,EC:l(i),BC:l(s),AC:l(n)}}drawToCanvas(t,i,s){const n=this.FC();if(null===n)return void this.OC(t,i,s);const e=this.VC,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Cy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.uy.ut*h,n.uy.ct*l),t.lineTo(n.BC.ut*h,n.BC.ct*l),t.lineTo(n.AC.ut*h,n.AC.ct*l),t.lineTo(n.vy.ut*h,n.vy.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.Fx?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.uy.ut*h,n.uy.ct*l),t.lineTo(n.vy.ut*h,n.vy.ct*l),t.moveTo(n.Vy.ut*h,n.Vy.ct*l),t.lineTo(n.EC.ut*h,n.EC.ct*l),t.moveTo(n.uy.ut*h,n.uy.ct*l),t.lineTo(n.BC.ut*h,n.BC.ct*l),t.moveTo(n.vy.ut*h,n.vy.ct*l),t.lineTo(n.AC.ut*h,n.AC.ct*l),t.stroke(),t.setLineDash([]);if((this.Fx||this.Lx||!this.zx)&&!this.isLocked())for(const i of[n.Vy,n.uy,n.vy])this.bC(t,i.ut*h,i.ct*l,h,r)}OC(t,i,s){const n=this.VC,e=this.RC(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.RC(n.upperTime,n.upperPrice)??(null!==this.$x?this.RC(this.$x.gt,this.$x.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.bC(t,e.ut*i,e.ct*s,i,h)}bC(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()}Cy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}qx(t,i){if(!this.isVisible()||!this.zx)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}kC(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.FC();if(null===s)return!1;return[[s.Vy,s.EC],[s.uy,s.BC],[s.vy,s.AC],[s.uy,s.vy]].some(([s,n])=>this.kC(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.FC();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.Vy)?"pivot":n(s.uy)?"upper":n(s.vy)?"lower":null}startDrag(t,i){this.Ex=!0,this.Bx=t,this.Ax=i,this.MC=[{gt:this.VC.pivotTime,bt:this.VC.pivotPrice},{gt:this.VC.upperTime,bt:this.VC.upperPrice},{gt:this.VC.lowerTime,bt:this.VC.lowerPrice}]}updateDrag(t,i){if(!this.Ex||null===this.Bx||null===this.MC)return;const s=this.VC;if("pivot"===this.Bx)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.Bx)s.upperTime=t,s.upperPrice=i;else if("lower"===this.Bx)s.lowerTime=t,s.lowerPrice=i;else{const n=Wh(this.Ax,t,i),[e,r,h]=this.MC;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.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null}setColor(t){this.VC.lineColor=t,this.VC.fillColor=t,this.cM()}color(){return this.VC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}remove(){if(this.vC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.Rx=null,this.VC.onRemove&&this.VC.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Hh(this.VC.pivotPrice??0,$h(this.VC.pivotTime)),Hh(this.VC.upperPrice??0,$h(this.VC.upperTime)),Hh(this.VC.lowerPrice??0,$h(this.VC.lowerTime))],style:{lineColor:this.VC.lineColor,lineWidth:this.VC.lineWidth,lineStyle:this.VC.lineStyle,fillColor:this.VC.fillColor,fillOpacity:this.VC.fillOpacity}}}}function yl(t,i){return new Ml(t,i)}class Sl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class xl{constructor(t){this.Vx=t,this.Jt=new Sl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Cl extends jh{constructor(t,i){super(t,"vertical-line",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Ax=null,this.rC=0,this.WC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.WC),this.Zy()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new xl(this)}drawToCanvas(t,i,s){if(void 0===this.WC.time)return;const n=(Xn(this._chart,this._series,this.WC.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.WC.lineColor,h=this.Fx||this.Lx&&!this.isLocked()?this.WC.lineWidth+1:this.WC.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.WC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.WC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.WC.showLabel&&(this.Fx||this.Lx)&&this.WC.labelText&&this.eC(t,n,i,s,r)}eC(t,i,s,n,e){const r=this.WC.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.WC.lineColor=t,this.cM()}color(){return this.WC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.WC.time)return!1;const s=Xn(this._chart,this._series,this.WC.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.Ex=!0,this.Ax=i,this.rC=this.WC.time}stopDrag(){this.Ex=!1,this.Ax=null}updateDrag(t,i){this.Ex&&(this.WC.time=this.rC+Wh(this.Ax,t,i).gt,this.cM(),this.WC.onUpdate&&this.WC.onUpdate())}getTime(){return this.WC.time}setTime(t){this.WC.time=t,this.cM()}setLabel(t){this.WC.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Hh(0,$h(this.WC.time))],style:{lineColor:this.WC.lineColor,lineWidth:this.WC.lineWidth,lineStyle:this.WC.lineStyle,showLabel:this.WC.showLabel,labelText:this.WC.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.WC.onRemove&&this.WC.onRemove()}}function Pl(t,i){return new Cl(t,i)}const Tl=[{zC:0,Zl:"0.0%"},{zC:.236,Zl:"23.6%"},{zC:.382,Zl:"38.2%"},{zC:.5,Zl:"50.0%"},{zC:.618,Zl:"61.8%"},{zC:.786,Zl:"78.6%"},{zC:1,Zl:"100.0%"}],kl=[...Tl,{zC:1.272,Zl:"127.2%"},{zC:1.414,Zl:"141.4%"},{zC:1.618,Zl:"161.8%"},{zC:2,Zl:"200.0%"},{zC:2.618,Zl:"261.8%"}];class Dl{constructor(t=!1){this.$C=t?kl:Tl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.$C.map(({zC:t,Zl:i})=>{let s;return s=h?n-e*t:n+e*t,{zC:t,bt:s,Zl: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.$C=t}getRatios(){return[...this.$C]}getRatioValues(){return this.$C.map(t=>t.zC)}useStandardRatios(){this.$C=Tl}useExtendedRatios(){this.$C=kl}}class Il{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Vl{constructor(t){this.Vx=t,this.Jt=new Il(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}}function Rl(t){return{zC:t,Zl:`${(100*t).toFixed(1)}%`}}class Fl extends jh{constructor(t,i){super(t,"fibonacci-tool",i),this.Ub=null,this.Rx=null,this.Yb=null,this.nh=null,this.HC=null,this.zx=!1,this.Fx=!1,this.Lx=!1,this.$x=null,this.Ex=!1,this.NC=null,this.sp=null,this.UC={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.UC),this.qC=new Dl(this.UC.useExtended),void 0!==this.UC.levels&&this.UC.levels.length>0&&this.qC.updateRatios(this.UC.levels.map(Rl)),this.Zy(),this.UC.interactive?this.Nx():(this.zx=!0,this.jC())}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Vl(this)}drawToCanvas(t,i,s){if(!this.zx&&this.UC.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.Yb||!this.UC.point1Time||!this.UC.point2Time)return;const n=(Xn(this._chart,this._series,this.UC.point1Time)??0)*i,e=(Xn(this._chart,this._series,this.UC.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.Fx?2:this.UC.lineWidth;this.Yb.levels.forEach(n=>{this.YC(t,n,r,h,i,s,l)}),!this.Fx&&!this.Lx||this.isLocked()||(this.Qx(t,n,(this._series.priceToCoordinate(this.UC.point1Price)??0)*s,i),this.Qx(t,e,(this._series.priceToCoordinate(this.UC.point2Price)??0)*s,i))}YC(t,i,s,n,e,r,h=1){const l=i.ratio??i.zC,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.UC.levelColors?.[l.toString()]||this.UC.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.UC.showLabels&&this.eC(t,i,s,n,a,e,_)}eC(t,i,s,n,e,r,h){const l=i.label??i.Zl,o=i.price??i.bt,a=`${l} ${this.qC.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.UC.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.UC.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}jC(){this.UC.point1Time&&this.UC.point1Price&&this.UC.point2Time&&this.UC.point2Price&&(this.Yb=this.qC.calculateLevels(this.UC.point1Time,this.UC.point1Price,this.UC.point2Time,this.UC.point2Price),this.UC.onUpdate&&this.Yb&&this.UC.onUpdate(this.Yb))}updatePoints(t,i,s,n){this.UC.point1Time=t,this.UC.point1Price=i,this.UC.point2Time=s,this.UC.point2Price=n,this.jC(),this.cM()}getMetrics(){return this.Yb}getLevels(){return this.Yb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.qC.getRatioValues();return{type:"fibRetracement",points:[Hh(this.UC.point1Price??0,$h(this.UC.point1Time)),Hh(this.UC.point2Price??0,$h(this.UC.point2Time))],style:{lineColor:this.UC.lineColor,lineWidth:this.UC.lineWidth,showLabels:this.UC.showLabels,labelPosition:this.UC.labelPosition,levelColors:this.UC.levelColors},extra:{levels:t,useExtended:this.UC.useExtended}}}useExtendedLevels(t){this.UC.useExtended=t,t?this.qC.useExtendedRatios():this.qC.useStandardRatios(),this.jC(),this.cM()}Nx(){this.HC=new Jh(this._chart,this._series,{Tx:t=>{this.UC.point1Time=t.gt,this.UC.point1Price=t.bt,this.cM()},kx:t=>{this.UC.point2Time=t.gt,this.UC.point2Price=t.bt},Dx:(t,i)=>{this.UC.point1Time=t.gt,this.UC.point1Price=t.bt,this.UC.point2Time=i.gt,this.UC.point2Price=i.bt,this.zx=!0,this.$x=null,this.jC(),this.KC(),this.cM()},Ix:t=>{this.$x=t,this.cM()}}),this.HC.vx()}Jx(t,i,s){if(!this.UC.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.UC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.UC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.$x.gt)??0)*i,h=(this._series.priceToCoordinate(this.$x.bt)??0)*s,l=this.qC.calculateLevels(this.UC.point1Time,this.UC.point1Price,this.$x.gt,this.$x.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.zC,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.UC.levelColors?.[e.toString()]||this.UC.lineColor;if(t.strokeStyle=l,t.lineWidth=this.UC.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.UC.showLabels){const s=`${n.label??n.Zl} ${this.qC.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.UC.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.UC.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.Qx(t,n,e,i),t.globalAlpha=.6,this.Qx(t,r,h,i),t.globalAlpha=1}Qx(t,i,s,n){const e=this.UC.lineColor,r=this.Fx?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.Fx&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}KC(){this.sp=t=>{this.GC(t)},this._chart.subscribeCrosshairMove(this.sp)}XC(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}GC(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.Fx||!this.Ex)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.NC?(this.UC.point1Time=i,this.UC.point1Price=s):"point2"===this.NC&&(this.UC.point2Time=i,this.UC.point2Price=s),this.jC(),this.cM())}startDrag(t){this.Ex=!0,this.NC=t}stopDrag(){this.Ex=!1,this.NC=null}updateDrag(t,i){this.Ex&&this.NC&&("point1"===this.NC?(this.UC.point1Time=t,this.UC.point1Price=i):(this.UC.point2Time=t,this.UC.point2Price=i),this.jC(),this.cM())}hitTestEndpoint(t,i){if(!this.zx||!this.UC.point1Time||!this.UC.point2Time)return null;const s=Xn(this._chart,this._series,this.UC.point1Time)??0,n=this._series.priceToCoordinate(this.UC.point1Price)??0,e=Xn(this._chart,this._series,this.UC.point2Time)??0,r=this._series.priceToCoordinate(this.UC.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.UC={...this.UC,...t},void 0!==t.levels&&t.levels.length>0?this.qC.updateRatios(t.levels.map(Rl)):void 0!==t.useExtended&&(t.useExtended?this.qC.useExtendedRatios():this.qC.useStandardRatios()),super.applyOptions(t),this.jC(),this.cM()}options(){return{...this.UC,levels:this.qC.getRatioValues()}}setColor(t){this.UC.lineColor=t,this.cM()}color(){return this.UC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}isSelected(){return this.Fx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.zx||!this.UC.point1Time||!this.UC.point2Time)return!1;const s=Xn(this._chart,this._series,this.UC.point1Time)??0,n=Xn(this._chart,this._series,this.UC.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Yb)return!1;for(const t of this.Yb.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}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.HC&&(this.HC.m(),this.HC=null),this.XC(),this.UC.onRemove&&this.UC.onRemove()}destroy(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.UC.onRemove&&this.UC.onRemove()}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.jC(),this.cM()}}function Ll(t,i){return new Fl(t,i)}class El{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Bl{constructor(t){this.Vx=t,this.Jt=new El(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}}class Al extends jh{constructor(t,i){super(t,"fibonacci-extension",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.UC={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.Zy()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Bl(this)}getPoint1(){return this.UC.point1}getPoint2(){return this.UC.point2}getPoint3(){return this.UC.point3}getLevels(){return this.UC.levels||[]}getOptions(){return this.UC}setPoint1(t){this.UC.point1=t,this.cM()}setPoint2(t){this.UC.point2=t,this.cM()}setPoint3(t){this.UC.point3=t,this.cM()}isComplete(){return!!(this.UC.point1&&this.UC.point2&&this.UC.point3)}setColor(t){this.UC.lineColor=t,this.cM()}color(){return this.UC.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.UC.point1,this.UC.point2,this.UC.point3];for(const n of s){const s=Xn(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.ZC();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.UC.point1,n=this.UC.point2,e=this.UC.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Xn(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=Xn(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=Xn(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.Ex=!0,this.Bx=t}stopDrag(){this.Ex=!1,this.Bx=null}updateDrag(t,i){if(!this.Ex||!this.Bx)return;const s={time:t,price:i};switch(this.Bx){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.UC.onUpdate&&this.UC.onUpdate()}ZC(){if(!this.isComplete())return[];const t=this.UC.point1,i=this.UC.point2,s=this.UC.point3,n=i.price-t.price;return(this.UC.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Zl:t.label,I:t.color}))}getExtensionLevels(){return this.ZC()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.UC.point1,e=this.UC.point2,r=this.UC.point3,h=this.Fx||this.Lx&&!this.isLocked(),l=(Xn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Xn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Xn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.UC.lineColor||"#787B86",t.lineWidth=(this.UC.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.I??n.color,l=n.Zl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.UC.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.UC.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.UC.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,Zl:"A"},{ut:a,ct:_,Zl:"B"},{ut:u,ct:c,Zl:"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.Zl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[Nh(this.UC.point1),Nh(this.UC.point2),Nh(this.UC.point3)],style:{lineColor:this.UC.lineColor,lineWidth:this.UC.lineWidth,showLabels:this.UC.showLabels,extendLines:this.UC.extendLines},extra:{levels:(this.UC.levels||[]).map(t=>({sn:t.level,I:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}}}function Ol(t,i){return new Al(t,i)}class Wl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.Vx=t,this.Jt=new Wl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const $l=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Hl extends jh{constructor(t,i){super(t,"fibonacci-fan",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.JC=!1,this.XS=null,this.sp=null,this.$x=null,this.QC={levels:$l,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.Zy(),this.QC.interactive&&!this.QC.point1Time&&this.Nx()}Nx(){this.JC=!0,this.XS=t=>{if(!t.point)return;if(Gh(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.QC.point1Time?(this.QC.point2Time=i,this.QC.point2Price=s,this.JC=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.QC.onUpdate&&this.QC.onUpdate()):(this.QC.point1Time=i,this.QC.point1Price=s,this.cM()))},this.sp=t=>{if(this.JC&&this.QC.point1Time)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new zl(this)}drawToCanvas(t,i,s){const n=this.QC.point1Time,e=this.QC.point1Price,r=this.JC&&this.$x?this.$x.gt:this.QC.point2Time,h=this.JC&&this.$x?this.$x.bt:this.QC.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.Fx?this.QC.lineWidth+1:this.QC.lineWidth;if(this.tP(t,l,o,a,_,"#2962FF",u*i),this.QC.levels)for(const n of this.QC.levels)this.iP(t,l,o,a,_,n,i,s,undefined,u);!this.Fx&&!this.Lx||this.JC||this.isLocked()||(this.Qx(t,l,o,i,"#2962ff"),this.Qx(t,a,_,i,"#2962ff"))}iP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.QC.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.tP(t,i,s,c,d,p,a*h),this.QC.showLabels&&!this.JC&&this.eC(t,_,u,r.label,h,p)}tP(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()}Qx(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()}eC(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.QC.levels??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.QC.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.QC.point1Time||!this.QC.point2Time)return!1;const s=Xn(this._chart,this._series,this.QC.point1Time)??0,n=this._series.priceToCoordinate(this.QC.point1Price)??0,e=Xn(this._chart,this._series,this.QC.point2Time)??0,r=this._series.priceToCoordinate(this.QC.point2Price)??0;if(this.tC(t,i,s,n,e,r)<=8)return!0;if(this.QC.levels)for(const h of this.QC.levels){const l=n+(r-n)*h.level,o=e;if(this.tC(t,i,s,n,o,l)<=8)return!0}return!1}tC(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.QC.point1Time||!this.QC.point2Time)return null;const s=Xn(this._chart,this._series,this.QC.point1Time)??0,n=this._series.priceToCoordinate(this.QC.point1Price)??0,e=Xn(this._chart,this._series,this.QC.point2Time)??0,r=this._series.priceToCoordinate(this.QC.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.Ex=!0,this.Bx=t}stopDrag(){this.Ex=!1,this.Bx=null}updateDrag(t,i){this.Ex&&this.Bx&&("point1"===this.Bx?(this.QC.point1Time=t,this.QC.point1Price=i):"point2"===this.Bx&&(this.QC.point2Time=t,this.QC.point2Price=i),this.cM(),this.QC.onUpdate&&this.QC.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Hh(this.QC.point1Price??0,$h(this.QC.point1Time)),Hh(this.QC.point2Price??0,$h(this.QC.point2Time))],style:{lineWidth:this.QC.lineWidth,showLabels:this.QC.showLabels,extendLines:this.QC.extendLines},extra:{levels:(this.QC.levels||[]).map(t=>({sn:t.level,I:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.QC.onRemove&&this.QC.onRemove()}}function Nl(t,i){return new Hl(t,i)}class Ul{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ql{constructor(t){this.Vx=t,this.Jt=new Ul(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class jl extends jh{constructor(t,i){super(t,"rectangle",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.Ox=null,this.Wx=null,this.JC=!1,this.XS=null,this.sp=null,this.$x=null,this.sP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.sP),this.Zy(),!this.sP.interactive||this.sP.time1&&this.sP.time2||this.Nx()}Nx(){this.JC=!0,this.XS=t=>{if(!t.point)return;if(Gh(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.sP.time1?(this.sP.time2=i,this.sP.price2=s,this.JC=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.sP.onUpdate&&this.sP.onUpdate()):(this.sP.time1=i,this.sP.price1=s,this.cM()))},this.sp=t=>{if(this.JC&&this.sP.time1)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new ql(this)}drawToCanvas(t,i,s){const n=this.sP.time1,e=this.sP.price1,r=this.JC&&this.$x?this.$x.gt:this.sP.time2,h=this.JC&&this.$x?this.$x.bt:this.sP.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(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.sP.fillOpacity>0){const i=this.Gy(this.sP.fillColor,this.JC?.1:this.sP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.sP.borderColor,w=this.Fx?this.sP.borderWidth+1:this.sP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.sP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.sP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.Fx&&!this.Lx||this.JC||this.isLocked()||this.nP(t,u,d,c,p,i,m),this.sP.showLabel&&this.sP.labelText&&!this.JC&&this.eC(t,u,d,c,p,i,s,m)}nP(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)}eC(t,i,s,n,e,r,h,l){const o=6*r,a=12*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.sP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.sP.labelPosition){case"top-right":c=n-_-2*o,d=s+o;break;case"bottom-left":c=i+o,d=e-u-2*o;break;case"bottom-right":c=n-_-2*o,d=e-u-2*o;break;case"center":c=(i+n)/2-_/2-o,d=(s+e)/2-u/2-o}t.fillStyle=l,t.fillRect(c,d,_+2*o,u+2*o),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.sP.labelText,c+o,d+o)}Gy(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.sP.borderColor=t,this.sP.fillColor=t,this.cM()}color(){return this.sP.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.sP.time1||!this.sP.time2)return!1;const s=Xn(this._chart,this._series,this.sP.time1)??0,n=this._series.priceToCoordinate(this.sP.price1)??0,e=Xn(this._chart,this._series,this.sP.time2)??0,r=this._series.priceToCoordinate(this.sP.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.sP.time1||!this.sP.time2)return null;const s=Xn(this._chart,this._series,this.sP.time1)??0,n=this._series.priceToCoordinate(this.sP.price1)??0,e=Xn(this._chart,this._series,this.sP.time2)??0,r=this._series.priceToCoordinate(this.sP.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.Ex=!0,this.Bx=t,this.Ax=i,"body"===t&&(this.Ox={gt:this.sP.time1,bt:this.sP.price1},this.Wx={gt:this.sP.time2,bt:this.sP.price2})}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.Ox=null,this.Wx=null}updateDrag(t,i){if(!this.Ex||!this.Bx)return;const s=Xn(this._chart,this._series,this.sP.time1)??0,n=this._series.priceToCoordinate(this.sP.price1)??0,e=s<(Xn(this._chart,this._series,this.sP.time2)??0),r=n<(this._series.priceToCoordinate(this.sP.price2)??0);if("body"===this.Bx&&this.Ox&&this.Wx){const s=Wh(this.Ax,t,i);this.sP.time1=this.Ox.gt+s.gt,this.sP.price1=this.Ox.bt+s.bt,this.sP.time2=this.Wx.gt+s.gt,this.sP.price2=this.Wx.bt+s.bt}else switch(this.Bx){case"corner1":e&&r?(this.sP.time1=t,this.sP.price1=i):!e&&r?(this.sP.time2=t,this.sP.price1=i):e&&!r?(this.sP.time1=t,this.sP.price2=i):(this.sP.time2=t,this.sP.price2=i);break;case"corner2":e&&r?(this.sP.time2=t,this.sP.price1=i):!e&&r?(this.sP.time1=t,this.sP.price1=i):e&&!r?(this.sP.time2=t,this.sP.price2=i):(this.sP.time1=t,this.sP.price2=i);break;case"corner3":e&&r?(this.sP.time1=t,this.sP.price2=i):!e&&r?(this.sP.time2=t,this.sP.price2=i):e&&!r?(this.sP.time1=t,this.sP.price1=i):(this.sP.time2=t,this.sP.price1=i);break;case"corner4":e&&r?(this.sP.time2=t,this.sP.price2=i):!e&&r?(this.sP.time1=t,this.sP.price2=i):e&&!r?(this.sP.time2=t,this.sP.price1=i):(this.sP.time1=t,this.sP.price1=i)}this.cM(),this.sP.onUpdate&&this.sP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Hh(this.sP.price1??0,$h(this.sP.time1)),Hh(this.sP.price2??0,$h(this.sP.time2))],style:{fillColor:this.sP.fillColor,fillOpacity:this.sP.fillOpacity,borderColor:this.sP.borderColor,borderWidth:this.sP.borderWidth,borderStyle:this.sP.borderStyle,showLabel:this.sP.showLabel,labelText:this.sP.labelText,labelPosition:this.sP.labelPosition}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.sP.onRemove&&this.sP.onRemove()}}function Yl(t,i){return new jl(t,i)}class Kl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Gl{constructor(t){this.Vx=t,this.Jt=new Kl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Xl extends jh{constructor(t,i){super(t,"circle",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null,this.JC=!1,this.XS=null,this.sp=null,this.$x=null,this.eP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.eP),this.Zy(),this.eP.interactive&&!this.eP.centerTime&&this.Nx()}Nx(){this.JC=!0,this.XS=t=>{if(!t.point)return;if(Gh(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.eP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.eP.centerTime)??0,n=this._series.priceToCoordinate(this.eP.centerPrice)??0,e=Xn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.eP.radiusTime=Math.abs(e-t),this.eP.radiusPrice=Math.abs(r-n),this.JC=!1,this.$x=null,this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.eP.onUpdate&&this.eP.onUpdate()}else this.eP.centerTime=i,this.eP.centerPrice=s,this.cM()},this.sp=t=>{if(this.JC&&this.eP.centerTime)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp)}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Gl(this)}drawToCanvas(t,i,s){if(!this.eP.centerTime||void 0===this.eP.centerPrice)return;const n=(Xn(this._chart,this._series,this.eP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.eP.centerPrice)??0)*s;let r,h;if(this.JC&&this.$x){const t=(Xn(this._chart,this._series,this.$x.gt)??0)*i,l=(this._series.priceToCoordinate(this.$x.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.eP.radiusTime||void 0===this.eP.radiusPrice)return;r=this.eP.radiusTime*i,h=this.eP.radiusPrice*s}if(this.eP.fillOpacity>0){const i=this.Gy(this.eP.fillColor,this.JC?.05:this.eP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.eP.borderColor,o=this.Fx?this.eP.borderWidth+1:this.eP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.eP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.eP.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.Fx&&!this.Lx||this.JC||this.isLocked()||this.rP(t,n,e,i,l),!this.Fx&&!this.Lx||this.JC||this.isLocked()||this.hP(t,n,e,r,h,i,l),this.eP.showLabel&&this.eP.labelText&&!this.JC&&this.eC(t,n,e,i,l)}rP(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()}hP(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)}eC(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.eP.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.eP.labelText,a+r,_+r)}Gy(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.eP.borderColor=t,this.eP.fillColor=t,this.cM()}color(){return this.eP.borderColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.eP.centerTime||void 0===this.eP.radiusTime)return!1;const s=Xn(this._chart,this._series,this.eP.centerTime)??0,n=this._series.priceToCoordinate(this.eP.centerPrice)??0,e=(t-s)/this.eP.radiusTime,r=(i-n)/this.eP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.eP.centerTime||void 0===this.eP.radiusTime)return null;const s=Xn(this._chart,this._series,this.eP.centerTime)??0,n=this._series.priceToCoordinate(this.eP.centerPrice)??0,e=this.eP.radiusTime,r=this.eP.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.Ex=!0,this.Bx=t,this.Ax=i,this.MC="center"===t?{gt:this.eP.centerTime,bt:this.eP.centerPrice}:null}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null}updateDrag(t,i){if(this.Ex&&this.Bx){if("center"===this.Bx&&this.MC){const s=Wh(this.Ax,t,i);this.eP.centerTime=this.MC.gt+s.gt,this.eP.centerPrice=this.MC.bt+s.bt}else if("edge"===this.Bx){const s=Xn(this._chart,this._series,this.eP.centerTime)??0,n=this._series.priceToCoordinate(this.eP.centerPrice)??0,e=Xn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.eP.radiusTime=Math.abs(e-s),this.eP.radiusPrice=Math.abs(r-n)}this.cM(),this.eP.onUpdate&&this.eP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Hh(this.eP.centerPrice??0,$h(this.eP.centerTime))],style:{fillColor:this.eP.fillColor,fillOpacity:this.eP.fillOpacity,borderColor:this.eP.borderColor,borderWidth:this.eP.borderWidth,borderStyle:this.eP.borderStyle,showLabel:this.eP.showLabel,labelText:this.eP.labelText},extra:{radiusTime:this.eP.radiusTime,radiusPrice:this.eP.radiusPrice}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.eP.onRemove&&this.eP.onRemove()}}function Zl(t,i){return new Xl(t,i)}class Jl{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ql{constructor(t){this.Vx=t,this.Jt=new Jl(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class to extends jh{constructor(t,i){super(t,"arrow",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.lP=-1,this.JC=!1,this.XS=null,this.oP=null,this.sp=null,this.$x=null,this.aP={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.aP),this.Zy(),!this.aP.interactive||this.aP.points&&0!==this.aP.points.length||this.Nx()}Nx(){this.JC=!0,this.XS=t=>{if(!t.point)return;if(Gh(this._chart))return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.aP.points||(this.aP.points=[]),this.aP.points.push({time:i,price:s}),this.cM(),this.aP.onUpdate&&this.aP.onUpdate())},this.sp=t=>{if(this.JC)if(t.point){const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.$x={gt:i,bt:s},this.cM())}else this.$x=null,this.cM()},this.oP=t=>{this.JC&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.XS),this._chart.subscribeCrosshairMove(this.sp);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.oP)}finishDrawing(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.oP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.oP),this.oP=null}this.JC=!1,this.$x=null,this.cM(),this.aP.onComplete&&this.aP.onComplete()}isDrawing(){return this.JC}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Ql(this)}drawToCanvas(t,i,s){if(!this.aP.points||0===this.aP.points.length)return;const n=this.aP.lineColor,e=this.Fx||this.Lx&&!this.isLocked()?this.aP.lineWidth+1:this.aP.lineWidth,r=[];for(const t of this.aP.points)try{let n=Xn(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.JC)return;let h=null;if(this.JC&&this.$x&&this.aP.points.length>0){h={ut:(Xn(this._chart,this._series,this.$x.gt)??0)*i,ct:(this._series.priceToCoordinate(this.$x.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.aP.showArrowHead&&r.length>1&&this._P(t,r[r.length-2],r[r.length-1],i,n),this.aP.showCircles)for(let s=0;s<r.length;s++)this.uP(t,r[s].ut,r[s].ct,i,n,0===s)}_P(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()}uP(t,i,s,n,e,r){const h=this.aP.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.aP.lineColor=t,this.cM()}color(){return this.aP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.aP.points||0===this.aP.points.length)return!1;for(let s=0;s<this.aP.points.length-1;s++)try{const n=this.aP.points[s],e=this.aP.points[s+1];let r=Xn(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=Xn(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.tC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.aP.points)try{let n=Xn(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}tC(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.aP.points||0===this.aP.points.length)return null;for(let s=0;s<this.aP.points.length;s++)try{const n=this.aP.points[s];let e=Xn(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.Ex=!0,this.lP=t}stopDrag(){this.Ex=!1,this.lP=-1}updateDrag(t,i){this.Ex&&-1!==this.lP&&this.aP.points&&this.lP>=0&&this.lP<this.aP.points.length&&(this.aP.points[this.lP]={time:t,price:i},this.cM(),this.aP.onUpdate&&this.aP.onUpdate())}getPoints(){return this.aP.points||[]}addPoint(t){this.aP.points||(this.aP.points=[]),this.aP.points.push(t),this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.aP.points||[]).map(t=>Nh(t)),style:{lineColor:this.aP.lineColor,lineWidth:this.aP.lineWidth,showArrowHead:this.aP.showArrowHead,showCircles:this.aP.showCircles,circleRadius:this.aP.circleRadius}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.XS&&(this._chart.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.oP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.oP),this.oP=null}if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.aP.onRemove&&this.aP.onRemove()}}function io(t,i){return new to(t,i)}class so{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class no{constructor(t){this.Vx=t,this.Jt=new so(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class eo extends jh{constructor(t,i){super(t,"brush",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.cP=!1,this.JC=!1,this.dP=[],this.pP=!1,this.kf=null,this.bS=null,this.PS=null,this.kS=null,this.IS=null,this.fP=void 0,this.xS=null,this.Ex=!1,this.Ax=null,this.oC=null,this.vP={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.vP),this.Zy(),0===(this.vP.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.cP)return;const t=this._chart.chartElement();t&&(this.kf=t,this.cP=!0,this.PS=t=>this.TS(t),this.kS=t=>this.DS(t),this.IS=()=>this.VS(),this.xS=t=>{this.fP=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.xS),t.addEventListener("pointerdown",this.PS,!0),t.addEventListener("pointermove",this.kS,!0),t.addEventListener("pointerup",this.IS,!0),t.addEventListener("pointercancel",this.IS,!0))}stopDrawingMode(){if(!this.cP)return;this.mP(),this.cP=!1;const t=this.kf;t&&(this.PS&&t.removeEventListener("pointerdown",this.PS,!0),this.kS&&t.removeEventListener("pointermove",this.kS,!0),this.IS&&(t.removeEventListener("pointerup",this.IS,!0),t.removeEventListener("pointercancel",this.IS,!0))),this.xS&&(this._chart.unsubscribeCrosshairMove(this.xS),this.xS=null),this.PS=null,this.kS=null,this.IS=null,this.kf=null}isDrawingModeActive(){return this.cP}TS(t){if(this.wP())return;const i=this.gP(t);null!==i&&(this.JC=!0,this.dP=[i],this.bS=t.pointerId,Kh(this._chart,!0),this.kf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.bP())}DS(t){if(!this.JC)return;const i=this.gP(t);if(null===i)return;const s=this.dP[this.dP.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.vP.sampleDistance??4)||(this.dP.push(i),t.preventDefault(),t.stopPropagation(),this.bP())}VS(){this.JC&&this.mP()}mP(){if(!this.JC)return;this.JC=!1,this.HS();const t=[];for(const i of this.dP){const s=Gn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.dP=[],t.length<2?this.cM():(this.vP.points=t,this.stopDrawingMode(),this.cM(),this.vP.onUpdate&&this.vP.onUpdate(),this.vP.onComplete&&this.vP.onComplete())}wP(){const t=this.fP;return"string"==typeof t&&t.split("#")[0]!==this.id}HS(){null!==this.bS&&(this.kf&&this.kf.hasPointerCapture(this.bS)&&this.kf.releasePointerCapture(this.bS),this.bS=null)}gP(t){const i=this.MP();if(null===i)return null;const s=i.getBoundingClientRect();return{ut:t.clientX-s.left,ct:t.clientY-s.top}}MP(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}bP(){this.pP||(this.pP=!0,requestAnimationFrame(()=>{this.pP=!1,this.cM()}))}drawToCanvas(t,i,s){const n=this.JC?this.dP.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.yP(i,s);if(0===n.length)return;const e=this.Fx;if(t.strokeStyle=this.vP.color,t.lineWidth=(this.vP.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.vP.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.Lx||this.isLocked()||(this.Qx(t,n[0],i),this.Qx(t,n[n.length-1],i))}Qx(t,i,s){t.fillStyle=this.vP.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()}yP(t,i){const s=this.vP.points??[],n=[];for(const e of s){const s=Xn(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.yP(1,1);for(let n=1;n<s.length;n++)if(ro(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.Ex=!0,this.Ax=i,this.oC=(this.vP.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.oC;if(!this.Ex||null===s||!this.vP.points)return;const n=Wh(this.Ax,t,i);this.vP.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.cM(),this.vP.onUpdate&&this.vP.onUpdate()}stopDrag(){this.Ex=!1,this.Ax=null,this.oC=null}setColor(t){this.vP.color=t,this.cM()}color(){return this.vP.color??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}Zy(){this.nh=new no(this);const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){this.stopDrawingMode(),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null),this.nh=null,this.vP.onRemove&&this.vP.onRemove()}_serializeShape(){return{type:"brush",points:(this.vP.points??[]).map(Nh),style:{color:this.vP.color,lineWidth:this.vP.lineWidth,smoothing:this.vP.smoothing}}}getPoints(){return this.vP.points??[]}}function ro(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 ho(t,i={}){return new eo(t,i)}class lo{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class oo{constructor(t){this.Vx=t,this.Jt=new lo(t)}renderer(){return this.Vx.isComplete()?this.Jt:null}}class ao extends jh{constructor(t,i){super(t,"text-tool",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null,this.SP=!1,this.xP=null,this.CP={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,...i},this._registerOptions(this.CP),this.Zy(),this.PP()}PP(){this.xP=this._chart.subscribeClick(t=>{if(!this.SP)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.CP.text&&""!==this.CP.text.trim()&&"Type here..."!==this.CP.text||this.remove())})}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new oo(this)}getTime(){return this.CP.time}getPrice(){return this.CP.price}getText(){return this.CP.text||""}getOptions(){return this.CP}setPosition(t,i){this.CP.time=t,this.CP.price=i,this._update()}setText(t){this.CP.text=t,this._update(),this.CP.onTextChange&&this.CP.onTextChange(t)}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}isComplete(){return!(!this.CP.time||void 0===this.CP.price)}setColor(t){this.CP.textColor=t,this.CP.borderColor=t,this.cM()}color(){return this.CP.textColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this._update())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this._update())}isHovered(){return this.Lx}setEditing(t){this.SP!==t&&(this.SP=t,this._update())}isEditing(){return this.SP}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.CP.time,n=this.CP.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.CP.fontSize||14,l=this.CP.padding||8,o=this.CP.text||"",a=.6*h,_=Math.min(o.length*a,this.CP.maxWidth||200);return t>=e&&t<=e+_+2*l&&i>=r&&i<=r+(h+2*l)}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.CP.time,n=this.CP.price,e=Xn(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.Ex=!0,this.Bx=t,this.Ax=i,this.MC={gt:this.CP.time,bt:this.CP.price}}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null}updateDrag(t,i){if(this.Ex){if("body"===this.Bx&&this.MC){const s=Wh(this.Ax,t,i);this.setPosition(this.MC.gt+s.gt,this.MC.bt+s.bt)}else this.setPosition(t,i);this.CP.onUpdate&&this.CP.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.CP.time,e=this.CP.price,r=this.CP.text||"",h=(Xn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.CP.fontSize||14)*i,a=(this.CP.padding||8)*i,_=(this.CP.maxWidth||200)*i;t.font=`${o}px ${this.CP.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.CP.backgroundOpacity||.8,g=this.CP.backgroundColor||"#2962FF";t.fillStyle=this.Gy(g,w),t.fillRect(h,l,f,m),(this.Fx||this.Lx)&&(t.strokeStyle=this.CP.borderColor??"#FFFFFF",t.lineWidth=(this.CP.borderWidth||1)*i*(this.Fx?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.CP.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.CP.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.CP.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.Fx||this.Lx)&&!this.isLocked()){const s=4*i;t.fillStyle=this.CP.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()}}Gy(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:[Hh(this.CP.price??0,$h(this.CP.time))],style:{fontSize:this.CP.fontSize,fontFamily:this.CP.fontFamily,textColor:this.CP.textColor,backgroundColor:this.CP.backgroundColor,backgroundOpacity:this.CP.backgroundOpacity,padding:this.CP.padding,borderColor:this.CP.borderColor,borderWidth:this.CP.borderWidth,textAlign:this.CP.textAlign,maxWidth:this.CP.maxWidth},extra:{text:this.CP.text}}}remove(){if(this.xP&&(this._chart.unsubscribeClick(this.xP),this.xP=null),this.Ub&&this._series){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.CP.onRemove&&this.CP.onRemove()}}function _o(t,i){return new ao(t,i)}class uo{constructor(t){this.TP=t}calculatePips(t,i){return Math.abs(i-t)/this.TP.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.TP={...this.TP,...t}}getPipConfig(){return{...this.TP}}}function co(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 po(t,i){return"number"==typeof t?co(t):void 0!==i?co(i):{pipValue:.1,decimals:1}}class fo{constructor(t){this.TP=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.TP.pipValue,timeDifference:this.kP(t,s),barCount:e}}kP(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.TP={...this.TP,...t}}getPipConfig(){return{...this.TP}}}class vo{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class mo{constructor(t){this.Vx=t,this.Jt=new vo(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}}class wo extends jh{constructor(t,i){super(t,"ruler-tool",i),this.Ub=null,this.Rx=null,this.Yb=null,this.nh=null,this.HC=null,this.zx=!1,this.Fx=!1,this.Lx=!1,this.$x=null,this.Ex=!1,this.NC=null,this.sp=null,this.DP={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.DP);const s=this.DP.pipConfig||po(this.DP.symbol||"DEFAULT");this.qC=new fo(s),this.Zy(),this.DP.interactive?this.Nx():this.DP.point1Time&&this.DP.point2Time&&(this.zx=!0,this.jC())}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new mo(this)}Nx(){this.HC=new Jh(this._chart,this._series,{Tx:t=>{this.DP.point1Time=t.gt,this.DP.point1Price=t.bt,this.cM()},kx:t=>{this.DP.point2Time=t.gt,this.DP.point2Price=t.bt},Dx:(t,i)=>{this.DP.point1Time=t.gt,this.DP.point1Price=t.bt,this.DP.point2Time=i.gt,this.DP.point2Price=i.bt,this.zx=!0,this.$x=null,this.jC(),this.KC(),this.cM()},Ix:t=>{this.$x=t,this.cM()}}),this.HC.vx()}drawToCanvas(t,i,s){if(!this.zx&&this.DP.point1Time&&this.$x)return void this.Jx(t,i,s);if(!this.zx||!this.DP.point1Time||!this.DP.point2Time)return;const n=(Xn(this._chart,this._series,this.DP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DP.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.DP.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.DP.point2Price)??0)*s;(this.Fx||this.Lx&&!this.isLocked())&&(t.strokeStyle=this.DP.selectionColor,t.lineWidth=this.DP.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.DP.lineColor,t.lineWidth=this.DP.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.IP(t,n,e,r,h,i),this.Qx(t,n,e,i),this.Qx(t,r,h,i),this.DP.showLabel&&this.Yb&&this.eC(t,n,e,r,h,i,s)}IP(t,i,s,n,e,r){const h=this.DP.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.DP.lineColor,t.lineWidth=this.DP.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()}Qx(t,i,s,n){const e=this.Fx?this.DP.selectionColor:this.DP.lineColor,r=this.Fx?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.Fx&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}Jx(t,i,s){if(!this.DP.point1Time||!this.$x)return;const n=(Xn(this._chart,this._series,this.DP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DP.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.$x.gt)??0)*i,h=(this._series.priceToCoordinate(this.$x.bt)??0)*s;t.strokeStyle=this.DP.lineColor,t.lineWidth=this.DP.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.Qx(t,n,e,i),t.globalAlpha=.5,this.Qx(t,r,h,i),t.globalAlpha=1}eC(t,i,s,n,e,r,h){if(!this.Yb)return;const l=(i+n)/2,o=(s+e)/2,a=this.DP.measure??"both",_=[];"time"!==a&&(_.push(this.qC.formatPips(this.Yb.pips)),_.push(this.qC.formatPercent(this.Yb.pricePercent))),"price"!==a&&_.push(this.qC.formatBarCount(this.Yb.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.DP.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.DP.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}jC(){if(!this.DP.point1Time||!this.DP.point2Time||void 0===this.DP.point1Price||void 0===this.DP.point2Price)return;const t=this.VP();this.Yb=this.qC.calculateMetrics(this.DP.point1Time,this.DP.point1Price,this.DP.point2Time,this.DP.point2Price,t),this.DP.onUpdate&&this.Yb&&this.DP.onUpdate(this.Yb)}VP(){if(!this.DP.point1Time||!this.DP.point2Time)return 0;const t=Xn(this._chart,this._series,this.DP.point1Time),i=Xn(this._chart,this._series,this.DP.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.DP.point1Time=t,this.DP.point1Price=i,this.DP.point2Time=s,this.DP.point2Price=n,this.jC(),this.cM()}getMetrics(){return this.Yb}remove(){this.destroy()}destroy(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.HC&&(this.HC.m(),this.HC=null),this.XC(),this.DP.onRemove&&this.DP.onRemove()}KC(){this.sp=t=>{this.GC(t)},this._chart.subscribeCrosshairMove(this.sp)}XC(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}GC(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.Fx||!this.Ex)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.NC?(this.DP.point1Time=i,this.DP.point1Price=s):"point2"===this.NC&&(this.DP.point2Time=i,this.DP.point2Price=s),this.jC(),this.cM())}startDrag(t){this.Ex=!0,this.NC=t}stopDrag(){this.Ex=!1,this.NC=null}updateDrag(t,i){this.Ex&&this.NC&&("point1"===this.NC?(this.DP.point1Time=t,this.DP.point1Price=i):(this.DP.point2Time=t,this.DP.point2Price=i),this.jC(),this.cM())}hitTestEndpoint(t,i){if(!this.zx||!this.DP.point1Time||!this.DP.point2Time)return null;const s=Xn(this._chart,this._series,this.DP.point1Time)??0,n=this._series.priceToCoordinate(this.DP.point1Price)??0,e=Xn(this._chart,this._series,this.DP.point2Time)??0,r=this._series.priceToCoordinate(this.DP.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}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.jC(),this.cM()}_serializeShape(){return{type:"ruler",points:[Hh(this.DP.point1Price??0,$h(this.DP.point1Time)),Hh(this.DP.point2Price??0,$h(this.DP.point2Time))],style:{lineColor:this.DP.lineColor,lineWidth:this.DP.lineWidth,showLabel:this.DP.showLabel,labelBackgroundColor:this.DP.labelBackgroundColor,labelTextColor:this.DP.labelTextColor,selectionColor:this.DP.selectionColor,selectionLineWidth:this.DP.selectionLineWidth},extra:{symbol:this.DP.symbol,pipConfig:this.DP.pipConfig,measure:this.DP.measure}}}setColor(t){this.DP.lineColor=t,this.cM()}color(){return this.DP.lineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}isSelected(){return this.Fx}isComplete(){return this.zx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.zx||!this.DP.point1Time||!this.DP.point2Time)return!1;const s=Xn(this._chart,this._series,this.DP.point1Time)??0,n=this._series.priceToCoordinate(this.DP.point1Price)??0,e=Xn(this._chart,this._series,this.DP.point2Time)??0,r=this._series.priceToCoordinate(this.DP.point2Price)??0;return this.RP(t,i,s,n,e,r)<=(this.Fx?12:8)}RP(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 go(t,i){return new wo(t,i)}class bo{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Mo{constructor(t){this.Vx=t,this.Jt=new bo(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}}class yo extends jh{constructor(t,i){super(t,"position-tool",i),this.Ub=null,this.Rx=null,this.Yb=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null,this.FP=null,this.LP=null,this.EP={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.EP);const s=this.EP.pipConfig||po(this.EP.entryPrice);this.qC=new uo(s),this.Zy(),this.jC()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Mo(this)}drawToCanvas(t,i,s){if(this.FP&&this.EP.takeProfit){const n=this._chart.timeScale();this.BP(t,this.FP,i,s,n),(this.Lx||this.Fx)&&this.eC(t,this.FP,"profit",i,s,n)}if(this.LP&&this.EP.stopLoss){const n=this._chart.timeScale();if(this.BP(t,this.LP,i,s,n),this.Lx||this.Fx){const n=this._chart.timeScale();this.eC(t,this.LP,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.AP(t,i,s,n),this.EP.takeProfit){const n=this._chart.timeScale();this.Qx(t,this.EP.takeProfit,this.EP.profitColor,i,s,n)}if(this.EP.stopLoss){const n=this._chart.timeScale();this.Qx(t,this.EP.stopLoss,this.EP.lossColor,i,s,n)}}BP(t,i,s,n,e){const r=(Xn(this._chart,this._series,this.EP.entryTime)??0)*s;let h;if(this.EP.endTime)h=(Xn(this._chart,this._series,this.EP.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.OP)??0)*n,o=(this._series.priceToCoordinate(i.WP)??0)*n;t.fillStyle=this.Gy(i.I,.15),t.fillRect(r,Math.min(l,o),h-r,Math.abs(o-l)),t.strokeStyle=i.I,t.lineWidth=2*s,t.beginPath(),t.moveTo(r,o),t.lineTo(h,o),t.stroke()}AP(t,i,s,n){const e=(Xn(this._chart,this._series,this.EP.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.EP.entryPrice)??0)*s;let h;if(this.EP.endTime)h=(Xn(this._chart,this._series,this.EP.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.EP.entryLineColor;t.strokeStyle=l,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(e,r),t.lineTo(h,r),t.stroke(),t.setLineDash([]),t.strokeStyle=this.EP.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const o=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,o),t.stroke(),t.setLineDash([]),!this.Fx&&!this.Lx||this.isLocked())t.fillStyle=this.EP.entryLineColor,t.beginPath(),t.arc(e,r,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=l,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(e,r,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=l,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(h-s/2,r-s/2,s,s),t.strokeRect(h-s/2,r-s/2,s,s)}}jC(){this.EP.stopLoss&&this.EP.takeProfit&&(this.Yb=this.qC.calculateMetrics(this.EP.entryPrice,this.EP.stopLoss,this.EP.takeProfit,this.EP.quantity),this.zP(),this.EP.onUpdate&&this.Yb&&this.EP.onUpdate(this.Yb))}zP(){const t=this.$P();this.EP.takeProfit&&(this.FP={HP:this.EP.entryTime,NP:t,OP:this.EP.entryPrice,WP:this.EP.takeProfit,I:this.EP.profitColor,yy:this.EP.opacity}),this.EP.stopLoss&&(this.LP={HP:this.EP.entryTime,NP:t,OP:this.EP.entryPrice,WP:this.EP.stopLoss,I:this.EP.lossColor,yy:this.EP.opacity})}$P(){this._chart.timeScale().getVisibleLogicalRange();return this.EP.entryTime}eC(t,i,s,n,e,r){if(!this.Yb)return;const h=(Xn(this._chart,this._series,this.EP.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.WP)??0)*e,o="profit"===s,a=o?this.Yb.takeProfitPips:this.Yb.stopLossPips,_=o?this.EP.takeProfit:this.EP.stopLoss,u=this.Yb.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=h+8*n,m=l-f/2;t.fillStyle=i.I,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}Qx(t,i,s,n,e,r){const h=(Xn(this._chart,this._series,this.EP.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,o=s;let a;if(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(h,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this.EP.endTime)a=(Xn(this._chart,this._series,this.EP.endTime)??0)*n;else{a=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(a-_/2,l-_/2,_,_),t.strokeRect(a-_/2,l-_/2,_,_)}Gy(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.EP={...this.EP,...t},this.jC(),this._update()}getMetrics(){return this.Yb}setStopLoss(t){this.EP.stopLoss=t,this.jC(),this._update()}setTakeProfit(t){this.EP.takeProfit=t,this.jC(),this._update()}setEntryPrice(t){this.EP.entryPrice=t,this.jC(),this._update()}_serializeShape(){return{type:"position",points:[Hh(this.EP.entryPrice,$h(this.EP.entryTime))],style:{profitColor:this.EP.profitColor,lossColor:this.EP.lossColor,entryLineColor:this.EP.entryLineColor,opacity:this.EP.opacity,showTooltips:this.EP.showTooltips},extra:{endTime:$h(this.EP.endTime),stopLoss:this.EP.stopLoss,takeProfit:this.EP.takeProfit,quantity:this.EP.quantity,pipConfig:this.EP.pipConfig}}}setColor(t){this.EP.entryLineColor=t,this.cM()}color(){return this.EP.entryLineColor??""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Oh(this.id,"body",!1):null}hitTest(t,i){if(!this.EP.stopLoss&&!this.EP.takeProfit)return!1;const s=Xn(this._chart,this._series,this.EP.entryTime)??0;let n;if(this.EP.endTime)n=Xn(this._chart,this._series,this.EP.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.EP.takeProfit&&this.EP.stopLoss){const e=this._series.priceToCoordinate(this.EP.takeProfit)??0,r=this._series.priceToCoordinate(this.EP.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return!0;const o=8;if(Math.abs(t-s)<=o&&i>=h&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Xn(this._chart,this._series,this.EP.entryTime)??0;let n;if(this.EP.endTime)n=Xn(this._chart,this._series,this.EP.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.EP.takeProfit){const n=this._series.priceToCoordinate(this.EP.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.EP.stopLoss){const n=this._series.priceToCoordinate(this.EP.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.EP.takeProfit){const s=this._series.priceToCoordinate(this.EP.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.EP.stopLoss){const s=this._series.priceToCoordinate(this.EP.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const e=this._series.priceToCoordinate(this.EP.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.EP.takeProfit&&this.EP.stopLoss){const e=this._series.priceToCoordinate(this.EP.takeProfit)??0,r=this._series.priceToCoordinate(this.EP.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return"move"}return null}startDrag(t,i){this.Ex=!0,this.Bx=t,this.Ax=i,"move"===t&&(this.MC={UP:this.EP.entryPrice,qP:this.EP.entryTime??null,Ky:this.EP.endTime??null,jP:this.EP.takeProfit??null,YP:this.EP.stopLoss??null})}stopDrag(){this.Ex=!1,this.Bx=null,this.Ax=null,this.MC=null}updateDrag(t,i){if(this.Ex&&this.Bx){if("entry"===this.Bx)this.EP.entryPrice=i;else if("move"===this.Bx){if(this.MC){const s=Wh(this.Ax,t,i),n=this.MC;this.EP.entryPrice=n.UP+s.bt,null!==n.jP&&(this.EP.takeProfit=n.jP+s.bt),null!==n.YP&&(this.EP.stopLoss=n.YP+s.bt),null!==n.qP&&(this.EP.entryTime=this.KP(n.qP,s.gt)),null!==n.Ky&&(this.EP.endTime=this.KP(n.Ky,s.gt))}}else"tp"===this.Bx||"tp-right"===this.Bx?(this.EP.takeProfit=i,"tp-right"===this.Bx?this.EP.endTime=t:this.EP.entryTime=t):"sl"!==this.Bx&&"sl-right"!==this.Bx||(this.EP.stopLoss=i,"sl-right"===this.Bx?this.EP.endTime=t:this.EP.entryTime=t);this.jC(),this.cM()}}KP(t,i){return t+i}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.EP.onRemove&&this.EP.onRemove()}}function So(t,i){return new yo(t,i)}class xo{constructor(t){this.Vx=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.Vx.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Co{constructor(t){this.Vx=t,this.Jt=new xo(t)}renderer(){return this.Vx.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Po extends jh{constructor(t,i){super(t,"gantt",i),this.Ub=null,this.Rx=null,this.nh=null,this.Fx=!1,this.Lx=!1,this.Ex=!1,this.GP=-1,this.Ax=null,this.MC=null,this.XP=-1,this.ZP={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.ZP),this.Zy()}Zy(){this.nh=this.Ux();const t={attached:t=>{this.Rx=t.requestUpdate},detached:()=>{this.Rx=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.qx(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}Ux(){return new Co(this)}drawToCanvas(t,i,s){if(!this.ZP.segments||0===this.ZP.segments.length)return;const n=50*s,e=this.ZP.rowHeight*s,r=this.ZP.rowSpacing*s;this.ZP.showGrid&&this.sm(t,n,e,r,i,s),this.ZP.segments.forEach((s,h)=>{const l=(Xn(this._chart,this._series,s.startTime)??0)*i,o=(Xn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.XP||this.Lx&&!this.isLocked();this.JP(t,l,o,a,e,s,_,i)})}sm(t,i,s,n,e,r){if(!this.ZP.segments)return;const h=Math.max(...this.ZP.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()}}JP(t,i,s,n,e,r,h,l){const o=s-i,a=this.Gy(r.color,h?this.ZP.fillOpacity+.2:this.ZP.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.ZP.borderWidth+(this.Fx?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.ZP.showLabels&&r.label&&this.eC(t,i,n,o,e,r.label,l)}eC(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)}Gy(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.ZP.segments||(this.ZP.segments=[]),this.ZP.segments.push(t),this.cM(),this.ZP.onUpdate&&this.ZP.onUpdate()}removeSegment(t){this.ZP.segments&&t>=0&&t<this.ZP.segments.length&&(this.ZP.segments.splice(t,1),this.cM(),this.ZP.onUpdate&&this.ZP.onUpdate())}getSegments(){return this.ZP.segments||[]}setColor(t){const i=this.ZP.segments??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.ZP.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.Fx!==t&&(this.Fx=t,this.cM())}isSelected(){return this.Fx}setHovered(t){this.Lx!==t&&(this.Lx=t,this.cM())}isHovered(){return this.Lx}qx(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Oh(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.ZP.segments?.[this.XP];s&&(this.Ex=!0,this.GP=this.XP,this.Ax=i,this.MC={Yy:s.startTime,Ky:s.endTime})}updateDrag(t,i){const s=this.ZP.segments?.[this.GP];if(!this.Ex||!this.MC||!s)return;const n=Wh(this.Ax,t,i);s.startTime=this.MC.Yy+n.gt,s.endTime=this.MC.Ky+n.gt,this.cM(),this.ZP.onUpdate&&this.ZP.onUpdate()}stopDrag(){this.Ex=!1,this.GP=-1,this.Ax=null,this.MC=null}hitTest(t,i){if(!this.ZP.segments||0===this.ZP.segments.length)return!1;const s=this.ZP.rowHeight,n=this.ZP.rowSpacing;for(let e=0;e<this.ZP.segments.length;e++){const r=this.ZP.segments[e],h=Xn(this._chart,this._series,r.startTime)??0,l=Xn(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.XP=e,!0}return this.XP=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.ZP.rowHeight,rowSpacing:this.ZP.rowSpacing,fillOpacity:this.ZP.fillOpacity,borderWidth:this.ZP.borderWidth,showLabels:this.ZP.showLabels,showGrid:this.ZP.showGrid},extra:{segments:(this.ZP.segments||[]).map(t=>({Yy:$h(t.startTime),Ky:$h(t.endTime),sn:t.level,Zl:t.label,I:t.color,QP:t.category}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.Rx?.()}_update(){this.cM()}remove(){if(this.Ub){this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null;const t=this._chart.chartElement?.();if(t){const i=t.clientWidth,s=t.clientHeight;this._chart.resize(i,s)}}this.ZP.onRemove&&this.ZP.onRemove()}}function To(t,i){return new Po(t,i)}class ko{constructor(t,i,s={}){this.tT=[],this.iT=[],this.sT=[],this.nT=!1,this.eT=new Map,this.rT=null,this.hT=null,this.lT=null,this.XS=null,this.oT=null,this.sp=null,this.aT=null,this._T=null,this.uT=null,this.bS=null,this.cT=!1,this.dT=null,this.pT=null,this.fT=new a,this.Ex=!1,this.vT=null,this.Rf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.mT()}startDrawing(t){this.lT=t,this.wT()}activeDrawingType(){return this.lT}stopDrawing(){this.lT=null}addTool(t,i){const s=i??t.id;return this.eT.set(s,t),this.recordChange(),s}removeTool(t){const i=this.eT.get(t);return!!i&&(this.rT===t&&this.gT(null),i.remove(),this.eT.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.eT.has(t)&&(this.gT(t),!0)}gT(t){if(this.rT===t)return;const i=null===this.rT?void 0:this.eT.get(this.rT);i&&i.setSelected(!1),this.rT=t;const s=null===t?void 0:this.eT.get(t);s&&s.setSelected(!0),this.bT()}recordChange(){this.nT||(this.tT.push(this.sT),this.iT=[],this.sT=this.serializeAll())}canUndo(){return this.tT.length>0}canRedo(){return this.iT.length>0}undo(){const t=this.tT.pop();return void 0!==t&&(this.iT.push(this.sT),this.MT(t),!0)}redo(){const t=this.iT.pop();return void 0!==t&&(this.tT.push(this.sT),this.MT(t),!0)}MT(t){this.nT=!0;try{this.restoreAll({chart:this.Rf,series:this.be},t,!0),this.sT=t}finally{this.nT=!1}}subscribeSelectionChanged(t){this.fT.i(t)}unsubscribeSelectionChanged(t){this.fT._(t)}selectionBounds(){if(null===this.rT)return null;const t=this.eT.get(this.rT);return t?this.yT(t):null}yT(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=Xn(this.Rf,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))}if(!l)return null;const o=this.ST(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}ST(t){const i=this.Rf.chartElement(),s=this.xT(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}}bT(){this.fT.p({id:this.rT,bounds:this.selectionBounds()})}deselectAll(){this.wT()}deleteSelected(){if(this.rT){const t=this.eT.get(this.rT);return(!t||!t.isLocked())&&this.removeTool(this.rT)}return!1}getSelectedToolId(){return this.rT}getAllTools(){return new Map(this.eT)}getTool(t){return this.eT.get(t)}clearAll(){this.gT(null),this.eT.forEach(t=>t.remove()),this.eT.clear(),this.recordChange()}getToolCount(){return this.eT.size}isToolSelected(t){return this.rT===t}serializeAll(){const t=[];for(const i of this.eT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=ko.CT(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 CT(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({PT:Uh(n[t]),TT:qh(n[t],"price")??0});switch(s){case"trendLine":return sl(t,{point1Time:h(0).PT,point1Price:h(0).TT,point2Time:h(1).PT,point2Price:h(1).TT,...e});case"horizontalLine":return hl(t,{price:h(0).TT,startTime:h(0).PT??void 0,...e});case"parallelChannel":return wl(t,{point1Time:h(0).PT,point1Price:h(0).TT,point2Time:h(1).PT,point2Price:h(1).TT,channelWidth:r?.channelWidth,...e});case"pitchfork":return yl(t,{pivotTime:h(0).PT,pivotPrice:h(0).TT,upperTime:h(1).PT,upperPrice:h(1).TT,lowerTime:h(2).PT,lowerPrice:h(2).TT,...e});case"polygon":return pl(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).PT,s.price=h(i).TT,s}),...e});case"crossLine":return _l(t,{time:h(0).PT,price:h(0).TT,...e});case"verticalLine":return Pl(t,{time:h(0).PT,...e});case"fibRetracement":return Ll(t,{point1Time:h(0).PT,point1Price:h(0).TT,point2Time:h(1).PT,point2Price:h(1).TT,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return Ol(t,{point1:i.PT?{time:i.PT,price:i.TT}:void 0,point2:s.PT?{time:s.PT,price:s.TT}:void 0,point3:n.PT?{time:n.PT,price:n.TT}:void 0,levels:r?.levels,...e})}case"fibFan":return Nl(t,{point1Time:h(0).PT,point1Price:h(0).TT,point2Time:h(1).PT,point2Price:h(1).TT,levels:r?.levels,...e});case"rectangle":return Yl(t,{time1:h(0).PT,price1:h(0).TT,time2:h(1).PT,price2:h(1).TT,...e});case"circle":return Zl(t,{centerTime:h(0).PT,centerPrice:h(0).TT,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 ho(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return _o(t,{time:h(0).PT,price:h(0).TT,text:r?.text,...e});case"ruler":return go(t,{point1Time:h(0).PT,point1Price:h(0).TT,point2Time:h(1).PT,point2Price:h(1).TT,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return So(t,{entryPrice:h(0).TT,entryTime:h(0).PT,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return To(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){this.clearAll(),this.kT()}mT(){this.XS=t=>{this.Cx(t)},this.Rf.subscribeClick(this.XS),this.sp=t=>{this.Px(t)},this.Rf.subscribeCrosshairMove(this.sp);const t=this.Rf.chartElement();t&&(this.aT=t=>this.DT(t),this._T=t=>this.IT(),this.uT=t=>this.IT(),t.addEventListener("pointerdown",this.aT),t.addEventListener("pointerup",this._T),t.addEventListener("pointercancel",this.uT)),this.Ps.enableKeyboardShortcuts&&(this.oT=t=>{this.VT(t)},document.addEventListener("keydown",this.oT))}kT(){this.XS&&(this.Rf.unsubscribeClick(this.XS),this.XS=null),this.sp&&(this.Rf.unsubscribeCrosshairMove(this.sp),this.sp=null);const t=this.Rf.chartElement();t&&(this.aT&&(t.removeEventListener("pointerdown",this.aT),this.aT=null),this._T&&(t.removeEventListener("pointerup",this._T),this._T=null),this.uT&&(t.removeEventListener("pointercancel",this.uT),this.uT=null)),this.oT&&(document.removeEventListener("keydown",this.oT),this.oT=null)}Cx(t){if(!t.point)return;if(this.cT)return void(this.cT=!1);if(this.Ex)return;const i=this.RT(t.hoveredObjectId);i?this.selectTool(i):this.wT()}Px(t){if(this.dT=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.Ex&&this.vT){const i=this.eT.get(this.vT);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Gn(this.Rf,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.RT(t.hoveredObjectId);if(this.hT&&this.hT!==i){const t=this.eT.get(this.hT);t&&t.setHovered(!1)}if(i){const t=this.eT.get(i);t&&t.setHovered(!0)}this.hT=i}RT(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.eT)if(s.id===i)return t;return null}DT(t){Kh(this.Rf,!1);const i=this.Rf.chartElement();if(!i)return;const s=null!==this.hT&&null!==this.dT?{FT:this.hT,kw:this.dT}:this.LT(t);if(null===s)return;const{FT:n,kw:e}=s,r=this.eT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.ET(r,e.ut,e.ct);null!==h&&null!==l&&(Kh(this.Rf,!0),this.selectTool(n),this.Ex=!0,this.cT=!0,this.vT=n,this.bS=t.pointerId,i.setPointerCapture(t.pointerId),r.startDrag(h,l),this.BT())}IT(){if(!this.Ex||null===this.vT)return;const t=this.eT.get(this.vT);t&&t.stopDrag(),this.HS(),this.AT(),this.Ex=!1,this.vT=null,this.recordChange()}xT(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}LT(t){for(const[i,s]of this.eT){if(!s.isVisible()||s.isLocked())continue;const n=this.xT(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{FT:i,kw:r}}return null}HS(){if(null===this.bS)return;const t=this.Rf.chartElement();t&&t.hasPointerCapture(this.bS)&&t.releasePointerCapture(this.bS),this.bS=null}BT(){const t=this.Rf.options();this.pT={OT:t.handleScroll,WT:t.handleScale},this.Rf.applyOptions({handleScroll:!1,handleScale:!1})}AT(){const t=this.pT;this.pT=null,null!==t&&this.Rf.applyOptions({handleScroll:t.OT,handleScale:t.WT})}VT(t){"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const i=t.metaKey||t.ctrlKey;if(i&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}i&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.IT(),this.wT(),this.stopDrawing(),t.preventDefault())}ET(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Gn(this.Rf,t.series(),i)}}wT(){this.gT(null)}}const Do={...t,color:"#2196f3"};function Io(){return"2.2.0"}export{Te as AreaSeries,to as ArrowTool,Ve as BarSeries,xe as BaselineSeries,eo as BrushTool,Le as CandlestickSeries,Xl as CircleTool,Li as ColorType,al as CrossLineTool,U as CrosshairMode,yh as DEFAULT_SESSIONS,Fh as DraggablePriceLine,ko as DrawingToolsManager,kl as EXTENDED_FIBONACCI_RATIOS,Dl as FibonacciCalculator,Al as FibonacciExtensionTool,Hl as FibonacciFanTool,Fl as FibonacciTool,Po as GanttTool,Ae as HistogramSeries,rl as HorizontalLineTool,Eh as InteractiveLineManager,Ri as LastPriceAnimationMode,le as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,ml as ParallelChannelTool,Ml as PitchforkTool,dl as PolygonTool,uo as PositionCalculator,Ir as PositionMarkersManager,yo as PositionTool,Fi as PriceLineSource,di as PriceScaleMode,jl as RectangleTool,fo as RulerCalculator,wo as RulerTool,Tl as STANDARD_FIBONACCI_RATIOS,ao as TextTool,Ei as TickMarkType,Vi as TrackingModeExitMode,Sh as TradingSessionsIndicator,il as TrendLineTool,Cl as VerticalLineTool,Th as VolumeProfileIndicator,vh as applyADX,dh as applyATR,Gr as applyBollingerBands,mh as applyCCI,Zr as applyDonchianChannels,Yr as applyEMA,ah as applyHeikinAshi,rh as applyIchimoku,Xr as applyKeltnerChannels,uh as applyMACD,gh as applyMFI,fh as applyOBV,Jr as applyParabolicSAR,hh as applyPivotPoints,_h as applyRSI,jr as applySMA,ch as applyStochastic,ih as applySuperTrend,th as applyVWAP,ph as applyVolume,Kr as applyWMA,wh as applyWilliamsR,oh as calculateHeikinAshi,co as calculatePipConfig,Xn as coordinateFromTime,io as createArrowTool,ho as createBrushTool,jn as createChart,qn as createChartEx,Zl as createCircleTool,_l as createCrossLineTool,Ol as createFibonacciExtensionTool,Nl as createFibonacciFanTool,Ll as createFibonacciTool,To as createGanttTool,hl as createHorizontalLineTool,ir as createImageWatermark,Bh as createInteractiveLineManager,me as createOptionsChart,wl as createParallelChannelTool,yl as createPitchforkTool,pl as createPolygonTool,Vr as createPositionMarkers,So as createPositionTool,Yl as createRectangleTool,go as createRulerTool,br as createSeriesMarkers,_o as createTextTool,Ke as createTextWatermark,Lh as createTradingLine,xh as createTradingSessionsIndicator,sl as createTrendLineTool,Dr as createUpDownMarkers,Pl as createVerticalLineTool,kh as createVolumeProfileIndicator,pe as createYieldCurveChart,Do as customSeriesDefaultOptions,Yn as defaultHorzScaleBehavior,po as getPipConfig,Or as hideSeriesPaint,Oi as isBusinessDay,Wi as isUTCTimestamp,Lr as setSeriesVolumes,Dh as setVolumeProfileData,Gn as timeFromCoordinate,Io as version};
|