@pipsend/charts 2.3.3 → 2.3.4
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/dist/pipsend-charts.development.mjs +19 -14
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +19 -14
- package/dist/pipsend-charts.standalone.development.mjs +19 -14
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.3.
|
|
3
|
+
* Pipsend Charts v2.3.4
|
|
4
4
|
* Copyright (c) 2026 Pipsend
|
|
5
5
|
* Licensed under MIT License
|
|
6
6
|
* Built on TradingView Lightweight Charts™ (Apache 2.0)
|
|
7
7
|
*/
|
|
8
|
-
const t={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var i,s;function n(t,i){const s={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}function e(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(s,i+e),t.lineTo(n,i+e),t.stroke()}function r(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function h(t){if(void 0===t)throw new Error("Value is undefined");return t}function l(t){if(null===t)throw new Error("Value is null");return t}function a(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 o{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",I:0,V:0,L:0,A:0,B:0},this.O=t}W(){const t=this.M,i=this.$(),s=this.H();return t.P===i&&t.D===s||(t.P=i,t.D=s,t.T=g(i,s),t.A=2.5/12*i,t.I=t.A,t.V=i/12*t.C,t.L=i/12*t.C,t.B=0),t.R=this.N(),t.F=this.U(),this.M}N(){return this.O.W().layout.textColor}U(){return this.O.q()}$(){return this.O.W().layout.fontSize}H(){return this.O.W().layout.fontFamily}}function M(t){return t<0?0:t>255?255:Math.round(t)||0}function y(t){return.199*t[0]+.687*t[1]+.114*t[2]}class S{constructor(t,i){this.j=new Map,this.Y=t,i&&(this.j=i)}X(t,i){if("transparent"===t)return t;const s=this.G(t),n=s[3];return`rgba(${s[0]}, ${s[1]}, ${s[2]}, ${i*n})`}K(t){const i=this.G(t);return{Z:`rgb(${i[0]}, ${i[1]}, ${i[2]})`,J:y(i)>160?"black":"white"}}tt(t){return y(this.G(t))}it(t,i,s){const[n,e,r,h]=this.G(t),[l,a,o,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(a-e)),M(r+s*(o-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],a=Math.round(n.ut*i)+r,o=n.ct*s,_=h*s+r;t.moveTo(a,o),t.arc(a,o,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.It(),i=this.Pt.Vt(),s=this.Ct.Lt(),n=this.O.At();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Et(s),l=i.Bt();!t&&null!==h&&i.It()&&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 R extends C{constructor(t){super(),this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;const h=this.Yt.Xt.It,l=this.Yt.Gt.It;if(!h&&!l)return;const a=Math.round(this.Yt.ut*s),o=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,a,0,i.height)),l&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,o,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",It:!1},Gt:{dt:1,Kt:0,R:"",It:!1},ut:0,ct:0},this.Jt=new R(this.Zt),this.Qt=t,this.Pt=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.Rt(),this.xt=!1),this.Jt}Rt(){const t=this.Qt.It(),i=this.Pt.ti().W().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.It=!1,void(s.Xt.It=!1);s.Gt.It=t&&this.Qt.ii(this.Pt),s.Xt.It=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Kt=i.horzLine.style,s.Gt.R=i.horzLine.color,s.Xt.dt=i.vertLine.width,s.Xt.Kt=i.vertLine.style,s.Xt.R=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function I(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 V(t,i,s,n,e,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(i,s,n,e),t.restore()}function L(t,i,s,n,e,r){t.beginPath(),t.roundRect?t.roundRect(i,s,n,e,r):(t.lineTo(i+n-r[1],s),0!==r[1]&&t.arcTo(i+n,s,i+n,s+r[1],r[1]),t.lineTo(i+n,s+e-r[2]),0!==r[2]&&t.arcTo(i+n,s+e,i+n-r[2],s+e,r[2]),t.lineTo(i+r[3],s+e),0!==r[3]&&t.arcTo(i,s+e,i,s+e-r[3],r[3]),t.lineTo(i,s+r[0]),0!==r[0]&&t.arcTo(i,s,i+r[0],s,r[0]))}function A(t,i,s,n,e,r,h=0,l=[0,0,0,0],a=""){if(t.save(),!h||!a||a===r)return L(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const o=h/2;var _;L(t,i+o,s+o,n-h,e-h,(_=-o,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==a&&(t.lineWidth=h,t.strokeStyle=a,t.closePath(),t.stroke()),t.restore()}function E(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 B{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.ri=i}qt(t,i){return this.Yt.It?t.P+t.A+t.I:0}et(t,i,s,n){if(!this.Yt.It||0===this.Yt.hi.length)return;const e=this.Yt.R,r=this.ri.Z,h=t.useBitmapCoordinateSpace(t=>{const h=t.context;h.font=i.T;const l=this.li(t,i,s,n),a=l.ai;return l.oi?A(h,a._i,a.ui,a.ci,a.di,r,a.pi,[a.vt,0,0,a.vt],r):A(h,a.fi,a.ui,a.ci,a.di,r,a.pi,[0,a.vt,a.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(a.fi,a.wi,a.gi-a.fi,a.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.oi?a.yi-a.pi:0,a.ui,a.pi,a.Si-a.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.oi?"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:a}=t,o=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.A+this.ri.Di,c=i.I+this.ri.Ri,d=i.V,p=i.L,f=this.Yt.hi,v=i.P,m=s.Fi(e,f),w=Math.ceil(s.Ii(e,f)),g=v+u+c,b=i.S+d+p+w+o,M=Math.max(1,Math.floor(a));let y=Math.round(g*a);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(o*l),P=this.ri.Vi??this.ri.Li,T=Math.round(P*a)-Math.floor(.5*a),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,I=R?r.width-S:S;let V,L,A;return R?(V=I-x,L=I-C,A=F-o-d-_):(V=I+x,L=I+C,A=F+o+d),{oi:R,ai:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:V,fi:I,gi:L,bi:M,yi:r.width},xi:{ui:k/a,Si:D/a,Ci:A,Pi:m}}}}class O{constructor(t){this.Ai={Li:0,Z:"#000",Ri:0,Di:0},this.Ei={hi:"",It:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Bi={hi:"",It:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Oi=new(t||B)(this.Ei,this.Ai),this.Wi=new(t||B)(this.Bi,this.Ai)}hi(){return this.zi(),this.Ei.hi}Li(){return this.zi(),this.Ai.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.Ai.Vi||0}Hi(t){this.Ai.Vi=t}Ni(){return this.zi(),this.Ei.It||this.Bi.It}Ui(){return this.zi(),this.Ei.It}Dt(t){return this.zi(),this.Ei.mi=this.Ei.mi&&t.W().ticksVisible,this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Oi.lt(this.Ei,this.Ai),this.Wi.lt(this.Bi,this.Ai),this.Oi}qi(){return this.zi(),this.Oi.lt(this.Ei,this.Ai),this.Wi.lt(this.Bi,this.Ai),this.Wi}zi(){this.xt&&(this.Ei.mi=!0,this.Bi.mi=!1,this.ji(this.Ei,this.Bi,this.Ai))}}class W extends O{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Xi=s}ji(t,i,s){if(t.It=!1,2===this.Qt.W().mode)return;const n=this.Qt.W().horzLine;if(!n.labelVisible)return;const e=this.Yi.Bt();if(!this.Qt.It()||this.Yi.Gi()||null===e)return;const r=this.Yi.Ki().K(n.labelBackgroundColor);s.Z=r.Z,t.R=r.J;const h=2/12*this.Yi.P();s.Di=h,s.Ri=h;const l=this.Xi(this.Yi);s.Li=l.Li,t.hi=this.Yi.Zi(l.bt,e),t.It=!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.It||0===this.Yt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Ii(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 a=this.Yt.Li,o=Math.floor(a-r)+.5;o<0?(a+=Math.abs(0-o),o=Math.floor(a-r)+.5):o+e>h&&(a-=Math.abs(h-(o+e)),o=Math.floor(a-r)+.5);const _=o+e,u=Math.ceil(0+i.S+i.C+i.A+i.P+i.I);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(o*s),h=Math.round(0*n),a=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(a-d,c),t.arcTo(a,c,a,c-d,d),t.lineTo(a,h),t.fill(),e.mi){const r=Math.round(e.Li*s),l=h,a=Math.round((l+i.C)*n);t.fillStyle=e.R;const o=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,o,a-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.A+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(o+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={It:!1,Z:"#4c525e",R:"white",hi:"",ts:0,Li:NaN,mi:!0},this.Ct=t,this.ss=i,this.Xi=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}Rt(){const t=this.Zt;if(t.It=!1,2===this.Ct.W().mode)return;const i=this.Ct.W().vertLine;if(!i.labelVisible)return;const s=this.ss.At();if(s.Gi())return;t.ts=s.ts();const n=this.Xi();if(null===n)return;t.Li=n.Li;const e=s.ns(this.Ct.Lt());t.hi=s.es(l(e)),t.It=!0;const r=this.ss.Ki().K(i.labelBackgroundColor);t.Z=r.Z,t.R=r.J,t.mi=s.W().ticksVisible}}class N{constructor(){this.rs=null,this.hs=0}ls(){return this.hs}_s(t){this.hs=t}$t(){return this.rs}us(t){this.rs=t}cs(t){return[]}ds(){return[]}It(){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.Bt());return{bt:s.Ds(n,t),Li:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.At().Rs(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Li:n}:null})(()=>this.fs,()=>this.ni());this.Fs=new H(this,t,s)}W(){return this.Ps}Is(t,i){this.xs=t,this.Cs=i}Vs(){this.xs=NaN,this.Cs=NaN}Ls(){return this.xs}As(){return this.Cs}Es(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Bs(t,i,s)}Lt(){return this.fs}ni(){return this.ys}ei(){return this.Ss}It(){return this.vs}Os(){this.vs=!1,this.Ws(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Pt=null,this.Vs(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new F(this,t),this.bs.set(t,i));let s=this.Ms.get(t);return s||(s=new D(this.ss,this,t),this.Ms.set(t,s)),[i,s]}ii(t){return t===this.Pt&&this.Ps.horzLine.visible}si(){return this.Ps.vertLine.visible}Hs(t,i){this.vs&&this.Pt===t||this.ws.clear();const s=[];return this.Pt===t&&s.push(this.Ns(this.ws,i,this.Ts)),s}ds(){return this.vs?[this.Fs]:[]}Us(){return this.Pt}zs(){this.ss.qs().forEach(t=>{this.bs.get(t)?.Tt(),this.Ms.get(t)?.Tt()}),this.ws.forEach(t=>t.Tt()),this.Fs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}Bs(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,a=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.At().jt(t),this.Pt=s;const o=null!==a?a.Bt():null;return null!==a&&null!==o?(this.ps=i,this.Ss=a.zt(i,o)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||h!==this.fs||r!==this.ps||l!==this.Pt}Ws(){const t=this.ss.Xs().map(t=>t.Ks().Gs()).filter(v),i=0===t.length?null:Math.max(...t);this.fs=null!==i?i:NaN}Ns(t,i,s){let n=t.get(i);return void 0===n&&(n=new W(this,i,s),t.set(i,n)),n}}function j(t){return"left"===t||"right"===t}class Y{constructor(t){this.Zs=new Map,this.Js=[],this.Qs=t}tn(t,i){const s=function(t,i){return void 0===t?i:{sn:Math.max(t.sn,i.sn),nn:t.nn||i.nn}}(this.Zs.get(t),i);this.Zs.set(t,s)}en(){return this.Qs}rn(t){const i=this.Zs.get(t);return void 0===i?{sn:this.Qs}:{sn:Math.max(this.Qs,i.sn),nn:i.nn}}hn(){this.ln(),this.Js=[{an:0}]}_n(t){this.ln(),this.Js=[{an:1,Ht:t}]}un(t){this.cn(),this.Js.push({an:5,Ht:t})}ln(){this.cn(),this.Js.push({an:6})}dn(){this.ln(),this.Js=[{an:4}]}pn(t){this.ln(),this.Js.push({an:2,Ht:t})}fn(t){this.ln(),this.Js.push({an:3,Ht:t})}vn(){return this.Js}mn(t){for(const i of t.Js)this.wn(i);this.Qs=Math.max(this.Qs,t.Qs),t.Zs.forEach((t,i)=>{this.tn(i,t)})}static gn(){return new Y(2)}static bn(){return new Y(3)}wn(t){switch(t.an){case 0:this.hn();break;case 1:this._n(t.Ht);break;case 2:this.pn(t.Ht);break;case 3:this.fn(t.Ht);break;case 4:this.dn();break;case 5:this.un(t.Ht);break;case 6:this.cn()}}cn(){const t=this.Js.findIndex(t=>5===t.an);-1!==t&&this.Js.splice(t,1)}}class X{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function K(t,i){if(!u(t))return"n/a";if(!c(i))throw new TypeError("invalid length");if(i<0||i>16)throw new TypeError("invalid length");if(0===i)return t.toString();return("0000000000000000"+t.toString()).slice(-i)}class Z extends X{constructor(t,i){if(super(),i||(i=1),u(t)&&c(t)||(t=100),t<0)throw new TypeError("invalid base");this.Yi=t,this.Mn=i,this.yn()}format(t){const i=t<0?"−":"";return t=Math.abs(t),i+this.Sn(t)}yn(){if(this.xn=0,this.Yi>0&&this.Mn>0){let t=this.Yi;for(;t>1;)t/=10,this.xn++}}Sn(t){const i=this.Yi/this.Mn;let s=Math.floor(t),n="";const e=void 0!==this.xn?this.xn:NaN;if(i>1){let r=+(Math.round(t*i)-s*i).toFixed(this.xn);r>=i&&(r-=i,s+=1),n=G+K(+r.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+K(0,e));return s.toFixed(0)+n}}class J extends Z{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Q extends X{constructor(t){super(),this.Cn=t}format(t){let i="";return t<0&&(i="-",t=-t),t<995?i+this.Pn(t):t<999995?i+this.Pn(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),i+this.Pn(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),i+this.Pn(t/1e9)+"B")}Pn(t){let i;const s=Math.pow(10,this.Cn);return i=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.Cn).replace(/\.?0+$/,""):String(t),i.replace(/(\.[1-9]*)0+$/,(t,i)=>i)}}const tt=/[2-9]/g;class it{constructor(t=50){this.Tn=0,this.kn=1,this.Dn=1,this.Rn={},this.Fn=new Map,this.In=t}Vn(){this.Tn=0,this.Fn.clear(),this.kn=1,this.Dn=1,this.Rn={}}Ii(t,i,s){return this.Ln(t,i,s).width}Fi(t,i,s){const n=this.Ln(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}Ln(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Fn.has(e))return h(this.Fn.get(e)).An;if(this.Tn===this.In){const t=this.Rn[this.Dn];delete this.Rn[this.Dn],this.Fn.delete(t),this.Dn++,this.Tn--}t.save(),t.textBaseline="middle";const r=t.measureText(e);return t.restore(),0===r.width&&i.length||(this.Fn.set(e,{An:r,En:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.Bn=null,this.M=null,this.On="right",this.Wn=t}zn(t,i,s){this.Bn=t,this.M=i,this.On=s}et(t){null!==this.M&&null!==this.Bn&&this.Bn.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.Vn()),this.Jt.zn(this.$n.qi(),n,s),this.Jt}}class et extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}Xn(t,i){if(!this.Yt?.It)return null;const{ct:s,dt:n,Gn:e}=this.Yt;return i>=s-n-7&&i<=s+n+7?{Kn:this.Yt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;if(!1===this.Yt.It)return;const h=Math.round(this.Yt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.R,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Kt),e(t,h,0,i.width))}}class rt{constructor(t){this.Zn={ct:0,R:"rgba(0, 0, 0, 0)",dt:1,Kt:0,It:!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.It()?(this.xt&&(this.ie(),this.xt=!1),this.Jn):null}}class ht extends rt{constructor(t){super(t)}ie(){this.Zn.It=!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.It())return;const n=this.Qn.Bt();null!==n&&(this.Zn.It=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.R=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Kt=s.baseLineStyle)}}class lt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ne(){return this.Yt}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.Yt;if(null===n)return;const e=Math.max(1,Math.floor(i)),r=e%2/2,h=Math.round(n.ee.x*i)+r,l=n.ee.y*s;t.fillStyle=n.re,t.beginPath();const a=Math.max(2,1.5*n.he)*i;t.arc(h,l,a,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.ae,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const at=[{oe:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{oe:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{oe:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class ot{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}It(){return 0!==this.be.W().lastPriceAnimation}xe(){switch(this.be.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.ge}}Dt(){return this.xt?(this.Rt(),this.xt=!1,this.me=!1):this.me&&(this.Ce(),this.me=!1),this.Jt}Rt(){this.Jt.lt(null);const t=this.be.ti().At(),i=t.Pe(),s=this.be.Bt();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Re))return;const e={x:t.jt(n.Re),y:this.be.$t().zt(n.bt,s.Ht)},r=n.R,h=this.be.W().lineWidth,l=this.Fe(this.Ie(),r);this.Jt.lt({re:r,he:h,le:l.le,ae:l.ae,vt:l.vt,ee:e})}Ce(){const t=this.Jt.ne();if(null!==t){const i=this.Fe(this.Ie(),t.re);t.le=i.le,t.ae=i.ae,t.vt=i.vt}}Ie(){return this.xe()?performance.now()-this.we:2599}Ve(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Ki().X(t,e)}Fe(t,i){const s=t%2600/2600;let n;for(const t of at)if(s>=t.oe&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.oe)/(n._e-n.oe);return{le:this.Ve(i,e,n.de,n.pe),ae:this.Ve(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,a=n.ce,l+(a-l)*h)};var h,l,a}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.It=!1;const i=this.Qn.W();if(!i.priceLineVisible||!this.Qn.It())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.It=!0,t.ct=s.Li,t.R=this.Qn.Le(s.R),t.dt=i.priceLineWidth,t.Kt=i.priceLineStyle)}}class ut extends O{constructor(t){super(),this.Qt=t}ji(t,i,s){t.It=!1,i.It=!1;const n=this.Qt;if(!n.It())return;const e=n.W(),r=e.lastValueVisible,h=""!==n.Ae(),l=0===e.seriesLastValueMode,a=n.Te(!1);if(a.ke)return;r&&(t.hi=this.Ee(a,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Be(a,r,h,l),i.It=i.hi.length>0);const o=n.Le(a.R),_=this.Qt.ti().Ki().K(o);s.Z=_.Z,s.Li=a.Li,i.Nt=n.ti().Ut(a.Li/n.$t().qt()),t.Nt=o,t.R=_.J,i.R=_.J}Be(t,i,s,n){let e="";const r=this.Qt.Ae();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Oe()?t.We:t.ze),e.trim()}Ee(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))}Xe(t){if(!u(t))return;if(0===this.He-this.$e)return;const i=.5*(this.He+this.$e);let s=this.He-i,n=this.$e-i;s*=t,n*=t,this.He=i+s,this.$e=i+n}Ge(t){u(t)&&(this.He+=t,this.$e+=t)}Ke(){return{minValue:this.$e,maxValue:this.He}}static Ze(t){return null===t?null:new dt(t.minValue,t.maxValue)}}class pt{constructor(t,i){this.Je=t,this.Qe=i||null}tr(){return this.Je}ir(){return this.Qe}Ke(){return{priceRange:null===this.Je?null:this.Je.Ke(),margins:this.Qe||void 0}}static Ze(t){return null===t?null:new pt(dt.Ze(t.priceRange),t.margins)}}class ft extends rt{constructor(t,i){super(t),this.sr=i}ie(){const t=this.Zn;t.It=!1;const i=this.sr.W();if(!this.Qn.It()||!i.lineVisible)return;const s=this.sr.nr();null!==s&&(t.It=!0,t.ct=s,t.R=i.color,t.dt=i.lineWidth,t.Kt=i.lineStyle,t.Gn=this.sr.W().id)}}class vt extends O{constructor(t,i){super(),this.be=t,this.sr=i}ji(t,i,s){t.It=!1,i.It=!1;const n=this.sr.W(),e=n.axisLabelVisible,r=""!==n.title,h=this.be;if(!e||!h.It())return;const l=this.sr.nr();if(null===l)return;r&&(i.hi=n.title,i.It=!0),i.Nt=h.ti().Ut(l/h.$t().qt()),t.hi=this.er(n.price),t.It=!0;const a=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=a.Z;const o=n.axisLabelTextColor||a.J;t.R=o,i.R=o,s.Li=l}er(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.Ps=i,this.rr=new ft(t,this),this.$n=new vt(t,this),this.hr=new nt(this.$n,t,t.ti())}lr(t){_(this.Ps,t),this.Tt(),this.be.ti().ar()}W(){return this.Ps}_r(){return this.rr}ur(){return this.hr}cr(){return this.$n}Tt(){this.rr.Tt(),this.$n.Tt()}nr(){const t=this.be,i=t.$t();if(t.ti().At().Gi()||i.Gi())return null;const s=t.Bt();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)),o=a(h.Ht[0])<=a(h.Ht[3]);return{dr:h.R??(o?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,o=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=a(c.Ht[0])<=a(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:o),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}Ir(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Vr=[],this.Lr=new Map,this.Ar=new Map,this.Er=[]}Br(){return this.Or()>0?this.Vr[this.Vr.length-1]:null}Wr(){return this.Or()>0?this.zr(0):null}Gs(){return this.Or()>0?this.zr(this.Vr.length-1):null}Or(){return this.Vr.length}Gi(){return 0===this.Or()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Vr}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Ar.clear(),this.Lr.clear(),this.Vr=t,this.Er=t.map(t=>t.Re)}Yr(){return this.Er}zr(t){return this.Vr[t].Re}Nr(t){return this.Vr[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Vr.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Vr.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Vr.length||t<this.Vr[i].Re?null:i}Zr(t){return yt(this.Vr,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Vr,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Vr[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),a=Math.min(i,r),o=Math.ceil(h/Ct)*Ct,_=Math.max(o,Math.floor(a/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(a,o,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Lr.get(s);void 0===u&&(u=new Map,this.Lr.set(s,u));for(let t=Math.max(o+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(a);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}ah(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.oh=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.oh?.rh===t)return this.oh.hh;const i=t.map(t=>new Rt(t));return this.oh={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Vt(t);return this.Fn={rh:t,hh:i},i}ah(){return this.eh.zOrder?.()??"normal"}}function At(t){return{hi:t.text(),Li:t.coordinate(),Vi:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),It:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Et{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...At(this.dh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=At(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Li=n.Li,s.Vi=n.Vi,t.hi=n.hi,t.It=n.It,t.mi=n.mi}}class Ot extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new Lt(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new Lt(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.ah()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new ot(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().At().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().At().Pe(),e=this.Bt();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.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],a=this.Fh().Fr(h,{Ht:r}),o=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Ih(l),ze:s.Vh(l,e.Ht),R:a.dr,Li:o,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Lh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Ah()),this.ti().Eh(this),this.ti().Bh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Oh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Eh(this),this.ti().Bh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Eh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Eh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Bt(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.It()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.al(),Nt:this.ol(),Wt:this._l(),Ot:this.ul(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}cl(t){this.kh.push(new Ot(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.It())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=a(n.Bt()),o=3===this.Ps.mode?jt:qt;return t.concat(o.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 o=l[0];return n=e.Ds(o,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Il(),Pl:(this.Pt.ti().At().Il()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Vl:4,Ll:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Ll)+i.Vl;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.Vl)-i.Ll;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function ai(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){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,Ll:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Al=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.Al))this.Bl=[2,2.5,2];else{this.Bl=[];for(let t=this.Al;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")}}}Ol(t,i,s){const n=0===this.Al?0:1/this.Al;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.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,a=1,o=1e-14,Math.abs(l-a)<o))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,a,o;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Al=i,this.zl=s,this.$l=n}Ol(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Al,[2,2.5,2]),r=new _i(this.Al,[2,2,2.5]),h=new _i(this.Al,[2.5,2,2]),l=[];return l.push(e.Ol(t,i,n),r.Ol(t,i,n),h.Ol(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,a=Math.max(n,e),o=Math.min(n,e);if(a===o)return void(this.Wl=[]);const _=this.Ol(a,o);if(this.ql(i,_,a,o,h,l),t.jl()&&this.Yl(_,o,a)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Il(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.ceil(2.5*this.Ul())}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let a=s%i;a+=a<0?i:0;const o=s>=n?1:-1;let _=null,u=0;for(let c=s-a;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.ta()&&(i=this.Ol(c*o,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.ia(t,s,e,r),a=this.ia(t,n,-r,-e),o=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<o/2&&h.shift(),h.length>0&&a.Tl-h[h.length-1].Tl<o/2&&h.pop(),h.unshift(l),h.push(a)}ia(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),a=Math.max(r,h),o=Math.max(.1,this.Ol(a,l)),_=this.zl(i+e,t),u=_-_%o,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=a(this.Yi.tr());return this.Yi.ta()&&(n=ai(n,this.Yi.sa())),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.na=0,this.ea=null,this.Je=null,this.ra=null,this.ha={la:!1,aa:null},this.oa=!1,this._a=0,this.ua=0,this.ca=new o,this.da=new o,this.pa=[],this.fa=null,this.va=null,this.ma=null,this.wa=null,this.ga=null,this.ll=fi,this.ba=oi(null),this.Ma=t,this.Ps=i,this.ya=s,this.Sa=n,this.xa=e,this.Ca=new ui(this,100,this.Pa.bind(this),this.Ta.bind(this))}gl(){return this.Ma}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.ka({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.Da(),this.ma=null}}Ra(){return this.Ps.autoScale}Fa(){return this.oa}ta(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Ia(){return 3===this.Ps.mode}sa(){return this.ba}se(){return{nn:this.Ps.autoScale,Va:this.Ps.invertScale,se:this.Ps.mode}}ka(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.ha.la=!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.ba)?this.Ps.autoScale=!0:(s=ai(this.Je,this.ba),null!==s&&this.La(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.ba),null!==s&&this.La(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.bl(),n&&(3===i.se||this.Ia())&&this.bl(),void 0!==t.Va&&i.Va!==t.Va&&(this.Ps.invertScale=t.Va,this.Aa()),this.da.p(i,this.se())}Ea(){return this.da}P(){return this.ya.fontSize}qt(){return this.na}Ba(t){this.na!==t&&(this.na=t,this.Da(),this.ma=null)}Oa(){if(this.ea)return this.ea;const t=this.qt()-this.Wa()-this.za();return this.ea=t,t}tr(){return this.$a(),this.Je}La(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.ma=null,this.Je=t)}Ha(t){this.La(t),this.Na(null!==t)}Gi(){return this.$a(),0===this.na||!this.Je||this.Je.Gi()}Ua(t){return this.Va()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Ia()&&(t=ni(t,i)),this.Ta(t,i)}qa(t,i,s){this.$a();const n=this.za(),e=l(this.tr()),r=e.qe(),h=e.je(),a=this.Oa()-1,o=this.Va(),_=a/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.ja();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 a=n+_*(l-r),u=o?a:this.na-1-a;e.ct=u}}Ya(t,i,s){this.$a();const n=this.za(),e=l(this.tr()),r=e.qe(),h=e.je(),a=this.Oa()-1,o=this.Va(),_=a/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.ja();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,a=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),a=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=o?c:this.na-1-c;e.Xa=p,c=n+_*(l-r),p=o?c:this.na-1-c,e.Ga=p,c=n+_*(a-r),p=o?c:this.na-1-c,e.Ka=p,c=n+_*(u-r),p=o?c:this.na-1-c,e.Za=p}}Ds(t,i){const s=this.Pa(t,i);return this.Ja(s,i)}Ja(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Ia()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.pa}Ft(){return this.va||(this.va=ci(this.pa)),this.va}Qa(t){-1===this.pa.indexOf(t)&&(this.pa.push(t),this.bl(),this.io())}so(t){const i=this.pa.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.pa.splice(i,1),0===this.pa.length&&(this.ka({nn:!0}),this.La(null)),this.bl(),this.io()}Bt(){let t=null;for(const i of this.pa){const s=i.Bt();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Va(){return this.Ps.invertScale}Il(){const t=null===this.Bt();if(null!==this.ma&&(t||this.ma.no===t))return this.ma.Il;this.Ca.Nl();const i=this.Ca.Il();return this.ma={Il:i,no:t},this.ca.p(),i}eo(){return this.ca}ro(t){this.Oe()||this.Ia()||null===this.wa&&null===this.ra&&(this.Gi()||(this.wa=this.na-t,this.ra=l(this.tr()).Ue()))}ho(t){if(this.Oe()||this.Ia())return;if(null===this.wa)return;this.ka({nn:!1}),(t=this.na-t)<0&&(t=0);let i=(this.wa+.2*(this.na-1))/(t+.2*(this.na-1));const s=l(this.ra).Ue();i=Math.max(i,.1),s.Xe(i),this.La(s)}lo(){this.Oe()||this.Ia()||(this.wa=null,this.ra=null)}ao(t){this.Ra()||null===this.ga&&null===this.ra&&(this.Gi()||(this.ga=t,this.ra=l(this.tr()).Ue()))}oo(t){if(this.Ra())return;if(null===this.ga)return;const i=l(this.tr()).Ye()/(this.Oa()-1);let s=t-this.ga;this.Va()&&(s*=-1);const n=s*i,e=l(this.ra).Ue();e.Ge(n),this.La(e,!0),this.ma=null}_o(){this.Ra()||null!==this.ga&&(this.ga=null,this.ra=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.uo(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.uo(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.co(t);case 3:return this.hl().formatTickmarks(t);default:return this.do(t)}}Ih(t){return this.er(t,l(this.fa).hl())}Vh(t,i){return t=ii(t,i),this.uo(t,pi)}po(){return this.pa}fo(t){this.ha={aa:t,la:!1}}zs(){this.pa.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Ra()}Xl(){return this.P()/2}bl(){this.ma=null;let t=1/0;this.fa=null;for(const i of this.pa)i.ls()<t&&(t=i.ls(),this.fa=i);let i=100;null!==this.fa&&(i=Math.round(this.fa.rh())),this.ll=fi,this.Oe()?(this.ll=pi,i=100):this.Ia()?(this.ll=new Z(100,1),i=100):null!==this.fa&&(this.ll=this.fa.hl()),this.Ca=new ui(this,i,this.Pa.bind(this),this.Ta.bind(this)),this.Ca.Nl()}io(){this.va=null}vo(){return null===this.fa||this.Oe()||this.Ia()?1:1/this.fa.rh()}Ki(){return this.xa}Na(t){this.oa=t}Wa(){return this.Va()?this.Ps.scaleMargins.bottom*this.qt()+this.ua:this.Ps.scaleMargins.top*this.qt()+this._a}za(){return this.Va()?this.Ps.scaleMargins.top*this.qt()+this._a:this.Ps.scaleMargins.bottom*this.qt()+this.ua}$a(){this.ha.la||(this.ha.la=!0,this.mo())}Da(){this.ea=null}Ta(t,i){if(this.$a(),this.Gi())return 0;t=this.ta()&&t?ri(t,this.ba):t;const s=l(this.tr()),n=this.za()+(this.Oa()-1)*(t-s.qe())/s.Ye();return this.Ua(n)}Pa(t,i){if(this.$a(),this.Gi())return 0;const s=this.Ua(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.za())/(this.Oa()-1));return this.ta()?hi(e,this.ba):e}Aa(){this.ma=null,this.Ca.Nl()}mo(){if(this.Fa()&&!this.Ra())return;const t=this.ha.aa;if(null===t)return;let i=null;const s=this.po();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let a=h&&h.tr();if(null!==a){switch(this.Ps.mode){case 1:a=li(a,this.ba);break;case 2:a=si(a,s.Ht);break;case 3:a=ei(a,s.Ht)}if(i=null===i?a:i.mn(l(a)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this._a&&e===this.ua||(this._a=n,this.ua=e,this.ma=null,this.Da()),null!==i){if(i.qe()===i.je()){const t=5*this.vo();this.ta()&&(i=ai(i,this.ba)),i=new dt(i.qe()-t,i.je()+t),this.ta()&&(i=li(i,this.ba))}if(this.ta()){const t=ai(i,this.ba),s=oi(t);if(r=s,h=this.ba,r.Vl!==h.Vl||r.Ll!==h.Ll){const n=null!==this.ra?ai(this.ra,this.ba):null;this.ba=s,i=li(t,s),null!==n&&(this.ra=li(n,s))}}this.La(i)}else null===this.Je&&(this.La(new dt(-.5,.5)),this.ba=oi(null));var r,h}ja(){return this.Oe()?ii:this.Ia()?ni:this.ta()?t=>ri(t,this.ba):null}wo(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}bo(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.wo(t,this.Sa.priceFormatter,i)}do(t,i){const s=this.Sa.priceFormatter;return this.bo(t,this.Sa.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}uo(t,i){return this.wo(t,this.Sa.percentageFormatter,i)}co(t,i){const s=this.Sa.percentageFormatter;return this.bo(t,this.Sa.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.pa=[],this.Mo=new Map,this.na=0,this.yo=0,this.So=1,this.va=null,this.xo=!1,this.Co=new o,this.kh=[],this.ph=t,this.ss=i,this.Po=new Qt(this);const s=i.W();this.To=this.ko("left",s.leftPriceScale),this.Do=this.ko("right",s.rightPriceScale),this.To.Ea().i(this.Ro.bind(this,this.To),this),this.Do.Ea().i(this.Ro.bind(this,this.Do),this),this.Fo(s)}Fo(t){if(t.leftPriceScale&&this.To.lr(t.leftPriceScale),t.rightPriceScale&&this.Do.lr(t.rightPriceScale),t.localization&&(this.To.bl(),this.Do.bl()),t.overlayPriceScales){const i=Array.from(this.Mo.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Io(t){switch(t){case"left":return this.To;case"right":return this.Do}return this.Mo.has(t)?h(this.Mo.get(t))[0].$t():null}m(){this.ti().Vo().u(this),this.To.Ea().u(this),this.Do.Ea().u(this),this.pa.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Co.p()}Lo(){return this.So}Ao(t){this.So=t}ti(){return this.ss}ts(){return this.yo}qt(){return this.na}Eo(t){this.yo=t,this.Bo()}Ba(t){this.na=t,this.To.Ba(t),this.Do.Ba(t),this.pa.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Ba(t)}}),this.Bo()}Oo(t){this.xo=t}Wo(){return this.xo}zo(){return this.pa.filter(mi)}yl(){return this.pa}Un(t){const i=t.$t();return null===i||this.To!==i&&this.Do!==i}Qa(t,i,s){this.$o(t,i,s?t.ls():this.pa.length)}so(t,i){const s=this.pa.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.pa.splice(s,1),i||this.pa.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Mo.has(n)){const i=h(this.Mo.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Mo.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.so(t),this.Ho(e)),this.va=null}jn(t){return t===this.To?"left":t===this.Do?"right":"overlay"}No(){return this.To}Uo(){return this.Do}qo(t,i){t.ro(i)}jo(t,i){t.ho(i),this.Bo()}Yo(t){t.lo()}Xo(t,i){t.ao(i)}Go(t,i){t.oo(i),this.Bo()}Ko(t){t._o()}Bo(){this.pa.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Do.yl().length?t=this.Do:this.ss.W().leftPriceScale.visible&&0!==this.To.yl().length?t=this.To:0!==this.pa.length&&(t=this.pa[0].$t()),null===t&&(t=this.Do),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Do:this.ss.W().leftPriceScale.visible&&(t=this.To),t}Ho(t){null!==t&&t.Ra()&&this.Zo(t)}Jo(t){const i=this.ph.Pe();t.ka({nn:!0}),null!==i&&t.fo(i),this.Bo()}Qo(){this.Zo(this.To),this.Zo(this.Do)}t_(){this.Ho(this.To),this.Ho(this.Do),this.pa.forEach(t=>{this.Un(t)&&this.Ho(t.$t())}),this.Bo(),this.ss.ar()}Ft(){return null===this.va&&(this.va=ci(this.pa)),this.va}i_(t,i){i=Xt(i,0,this.pa.length-1);const s=this.pa.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.pa.splice(s,1),this.pa.splice(i,0,t),this.pa.forEach((t,i)=>t._s(i)),this.va=null;for(const t of[this.To,this.Do])t.io(),t.bl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}s_(){return this.Co}n_(){return this.Po}cl(t){this.kh.push(new It(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Zo(t){const i=t.po();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.fo(i)}t.zs()}$o(t,i,s){let n=this.Io(i);if(null===n&&(n=this.ko(i,this.ss.W().overlayPriceScales)),this.pa.splice(s,0,t),!j(i)){const s=this.Mo.get(i)||[];s.push(t),this.Mo.set(i,s)}t._s(s),n.Qa(t),t.us(n),this.Ho(n),this.va=null}Ro(t,i,s){i.se!==s.se&&this.Zo(t)}ko(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Ba(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},a_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{o_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,o_:n.o_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.In=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.In){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,En:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(t,i){this.M_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}y_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Fn&&this.Fn.S_===r&&e===this.Fn.x_&&s===this.Fn.C_||(this.Fn={x_:e,C_:s,Il:this.P_(r,s,n),S_:r}),this.Fn.Il}M_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}P_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const a=h(this.m_.get(i)),o=a.length;let _=1/0,u=-1/0;for(let i=0;i<o;i++){const h=a[i],o=h.index;for(;l<r;){const t=s[l],i=t.index;if(!(i<o&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-o>=t&&o-u>=t&&e(h))n.push(h),u=o;else if(this.w_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.T_=t}k_(){return null===this.T_?null:new Ci(Math.floor(this.T_.qh()),Math.ceil(this.T_.yi()))}D_(){return this.T_}static R_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.yo=0,this.F_=null,this.I_=[],this.ga=null,this.wa=null,this.V_=new Ti,this.L_=new Map,this.A_=ki.R_(),this.E_=!0,this.B_=new o,this.O_=new o,this.W_=new o,this.z_=null,this.H_=null,this.N_=new Map,this.U_=-1,this.q_=[],this.Ps=i,this.Sa=s,this.j_=i.rightOffset,this.Y_=i.barSpacing,this.ss=t,this.X_(i),this.u_=n,this.G_(),this.V_.g_(i.uniformDistribution),this.K_()}W(){return this.Ps}Z_(t){_(this.Sa,t),this.J_(),this.G_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.Q_(),this.Ps.fixRightEdge&&this.tu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.X_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.Y_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.K_(),this.J_(),this.G_(),this.W_.p()}Rs(t){return this.I_[t]?.time??null}ns(t){return this.I_[t]??null}iu(t,i){if(this.I_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.I_[this.I_.length-1].time))return i?this.I_.length-1:null;const s=yt(this.I_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.I_[s].time)?i?s:null:s}Gi(){return 0===this.yo||0===this.I_.length||null===this.F_}su(){return this.I_.length>0}Pe(){return this.nu(),this.A_.k_()}eu(){return this.nu(),this.A_.D_()}ru(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.hu(i)}hu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.lu()),e=l(this.au());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.iu(t.from,!0)),to:l(this.iu(t.to,!0))}}ts(){return this.yo}Eo(t){if(!isFinite(t)||t<=0)return;if(this.yo===t)return;const i=this.eu(),s=this.yo;if(this.yo=t,this.E_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.Y_*t/s;this.Y_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.j_-=Math.round(i/this.Y_)+1,this.E_=!0}this._u(),this.uu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.cu()+this.j_-t;return this.yo-(i+.5)*this.Y_-1}du(t,i){const s=this.cu(),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.j_-n,r=this.yo-(e+.5)*this.Y_-1;t[i].ut=r}}pu(t,i){const s=Math.ceil(this.fu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.vu(s)?this.mu(s):s}fn(t){this.E_=!0,this.j_=t,this.uu(),this.ss.wu(),this.ss.ar()}gu(){return this.Y_}pn(t){const i=this.Y_;if(this.bu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.j_*i/this.Y_;this.j_=t}this.uu(),this.ss.wu(),this.ss.ar()}Mu(){return this.j_}Il(){if(this.Gi())return null;if(null!==this.H_)return this.H_;const t=this.Y_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.V_.y_(t,i,this.Ps.ignoreWhitespaceIndices,this.N_,this.U_),a=this.lu()+s,o=this.au()-s,_=this.yu(),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.q_.length?(s=this.q_[d],s.coord=this.jt(t.index),s.label=this.Su(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.Su(t),weight:t.weight},this.q_.push(s)),this.Y_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=a||c&&t.index>=o,d++}return this.q_.length=d,this.H_=this.q_,this.q_}xu(){let t;this.E_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.gu():this.Ps.rightOffset,this.fn(t)}Cu(t){this.E_=!0,this.F_=t,this.uu(),this.Q_()}Pu(t,i){const s=this.fu(t),n=this.gu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.Mu()+(s-this.fu(t)))}ro(t){this.ga&&this._o(),null===this.wa&&null===this.z_&&(this.Gi()||(this.wa=t,this.Tu()))}ho(t){if(null===this.z_)return;const i=Xt(this.yo-t,0,this.yo),s=Xt(this.yo-l(this.wa),0,this.yo);0!==i&&0!==s&&this.pn(this.z_.gu*i/s)}lo(){null!==this.wa&&(this.wa=null,this.ku())}ao(t){null===this.ga&&null===this.z_&&(this.Gi()||(this.ga=t,this.Tu()))}oo(t){if(null===this.ga)return;const i=(this.ga-t)/this.gu();this.j_=l(this.z_).Mu+i,this.E_=!0,this.uu()}_o(){null!==this.ga&&(this.ga=null,this.ku())}Du(){this.Ru(this.Ps.rightOffset)}Ru(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.j_,n=performance.now();this.ss.un({Fu:t=>(t-n)/i>=1,Iu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.E_=!0,this.I_=t,this.V_.b_(t,i),this.uu()}Vu(){return this.B_}Lu(){return this.O_}Au(){return this.W_}cu(){return this.F_||0}Eu(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.bu((this.yo-n)/s),this.j_=t.yi()-this.cu(),i&&(this.j_=n?n/this.gu():this.Ps.rightOffset),this.uu(),this.E_=!0,this.ss.wu(),this.ss.ar()}Bu(){const t=this.lu(),i=this.au();null!==t&&null!==i&&this.Eu(new Ci(t,i),!0)}Ou(t){const i=new Ci(t.from,t.to);this.Eu(i)}es(t){return void 0!==this.Sa.timeFormatter?this.Sa.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}K_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.N_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.N_.set(t,!0);this.U_++}yu(){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)}lu(){return 0===this.I_.length?null:0}au(){return 0===this.I_.length?null:this.I_.length-1}Wu(t){return(this.yo-1-t)/this.Y_}fu(t){const i=this.Wu(t),s=this.cu()+this.j_-i;return Math.round(1e6*s)/1e6}bu(t){const i=this.Y_;this.Y_=t,this._u(),i!==this.Y_&&(this.E_=!0,this.zu())}nu(){if(!this.E_)return;if(this.E_=!1,this.Gi())return void this.$u(ki.R_());const t=this.cu(),i=this.yo/this.Y_,s=this.j_+t,n=new Ci(s-i+1,s);this.$u(new ki(n))}_u(){const t=Xt(this.Y_,this.Hu(),this.Nu());this.Y_!==t&&(this.Y_=t,this.E_=!0)}Nu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.yo}Hu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.I_.length?this.yo/this.I_.length:this.Ps.minBarSpacing}uu(){const t=this.Uu();null!==t&&this.j_<t&&(this.j_=t,this.E_=!0);const i=this.qu();this.j_>i&&(this.j_=i,this.E_=!0)}Uu(){const t=this.lu(),i=this.F_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.yo/this.Y_:Math.min(2,this.I_.length))}qu(){return this.Ps.fixRightEdge?0:this.yo/this.Y_-Math.min(2,this.I_.length)}Tu(){this.z_={gu:this.gu(),Mu:this.Mu()}}ku(){this.z_=null}Su(t){let i=this.L_.get(t.weight);return void 0===i&&(i=new xi(t=>this.ju(t),this.u_),this.L_.set(t.weight,i)),i.c_(t)}ju(t){return this.u_.formatTickmark(t,this.Sa)}$u(t){const i=this.A_;this.A_=t,Pi(i.k_(),this.A_.k_())||this.B_.p(),Pi(i.D_(),this.A_.D_())||this.O_.p(),this.zu()}zu(){this.H_=null}J_(){this.zu(),this.L_.clear()}G_(){this.u_.updateFormatter(this.Sa)}Q_(){if(!this.Ps.fixLeftEdge)return;const t=this.lu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.j_-s-1;this.fn(t)}this._u()}tu(){this.uu(),this._u()}vu(t){return!this.Ps.ignoreWhitespaceIndices||(this.N_.get(t)||!1)}mu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.au();for(;s;){const t=i.next().value;if(this.N_.get(t))return t;if(t<0||t>s)break}return t}X_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.Y_);this.ss.fn(i)}}}var Fi,Ii,Vi,Li,Ai;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Ei{constructor(t,i,s){this.Yu=[],this.Xu=[],this.yo=0,this.Gu=null,this.Ku=new o,this.Zu=new o,this.Ju=null,this.Qu=t,this.Ps=i,this.u_=s,this.xa=new S(this.Ps.layout.colorParsers),this.tc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.sc=new Yt(i.crosshair),i.addDefaultPane&&(this.nc(0),this.Yu[0].Ao(2)),this.ec=this.rc(0),this.hc=this.rc(1)}Ah(){this.lc(Y.bn())}ar(){this.lc(Y.gn())}Jh(){this.lc(new Y(1))}Eh(t){const i=this.ac(t);this.lc(i)}oc(){return this.Gu}_c(t){if(this.Gu?.r_===t?.r_&&this.Gu?.h_?.Gn===t?.h_?.Gn)return;const i=this.Gu;this.Gu=t,null!==i&&this.Eh(i.r_),null!==t&&t.r_!==i?.r_&&this.Eh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Yu.forEach(i=>i.Fo(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.Z_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Ku.p(),this.ec=this.rc(0),this.hc=this.rc(1),this.Ah()}uc(t,i,s=0){const n=this.Yu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fo({leftPriceScale:i}),this.Ku.p(),void this.Ah();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fo({rightPriceScale:i}),this.Ku.p(),void this.Ah();const e=this.cc(t,s);null!==e&&(e.$t.lr(i),this.Ku.p())}cc(t,i){const s=this.Yu[i];if(void 0===s)return null;const n=s.Io(t);return null!==n?{Us:s,$t:n}:null}At(){return this.ph}qs(){return this.Yu}dc(){return this.Ct}fc(){return this.Zu}vc(t,i){t.Ba(i),this.wu()}Eo(t){this.yo=t,this.ph.Eo(this.yo),this.Yu.forEach(i=>i.Eo(t)),this.wu()}mc(t){1!==this.Yu.length&&(r(t>=0&&t<this.Yu.length,"Invalid pane index"),this.Yu.splice(t,1),this.Ah())}wc(t,i){if(this.Yu.length<2)return;r(t>=0&&t<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu.reduce((t,i)=>t+i.Lo(),0),e=this.Yu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Yu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,a=s.qt();s.Ao(i*l);let o=i-a,_=this.Yu.length-1;for(const t of this.Yu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-o/_));o-=t.qt()-i,_-=1;const s=i*l;t.Ao(s)}this.Ah()}gc(t,i){r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu[i];this.Yu[t]=n,this.Yu[i]=s,this.Ah()}bc(t,i){if(r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index"),t===i)return;const[s]=this.Yu.splice(t,1);this.Yu.splice(i,0,s),this.Ah()}qo(t,i,s){t.qo(i,s)}jo(t,i,s){t.jo(i,s),this.Bh(),this.lc(this.Mc(t,2))}Yo(t,i){t.Yo(i),this.lc(this.Mc(t,2))}Xo(t,i,s){i.Ra()||t.Xo(i,s)}Go(t,i,s){i.Ra()||(t.Go(i,s),this.Bh(),this.lc(this.Mc(t,2)))}Ko(t,i){i.Ra()||(t.Ko(i),this.lc(this.Mc(t,2)))}Jo(t,i){t.Jo(i),this.lc(this.Mc(t,2))}yc(t){this.ph.ro(t)}Sc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Pu(t,i),this.wu()}xc(t){this.Cc(0),this.Pc(t),this.Tc()}kc(t){this.ph.ho(t),this.wu()}Dc(){this.ph.lo(),this.ar()}Cc(t){this.ph.ao(t)}Pc(t){this.ph.oo(t),this.wu()}Tc(){this.ph._o(),this.ar()}Xs(){return this.Xu}Rc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.ph.pu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const a=n.ks(),o=a.Bt();if(null!==o&&(r=a.Ds(i,o)),r=this.sc.Ml(r,h,n),this.Ct.Es(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this._c(e&&{r_:e.r_,h_:e.h_,a_:e.a_||null}),this.Zu.p(this.Ct.Lt(),{x:t,y:i},s)}}Fc(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.ph.iu(i,!0),a=this.ph.jt(l(h));this.Rc(a,r,null,s,!0)}Ic(t){this.dc().Os(),this.Jh(),t||this.Zu.p(null,null,null)}Bh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Rc(i,s,null,t)}this.Ct.zs()}Vc(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.cu(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),a=null!==t&&t>r&&!l,o=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||o)&&this.ph.W().shiftVisibleRangeOnNewBar;if(a&&!_){const i=t-r;this.ph.fn(this.ph.Mu()-i)}}this.ph.Cu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Yu.find(i=>i.Ft().includes(t));return void 0===i?null:i}wu(){this.Yu.forEach(t=>t.t_()),this.Bh()}m(){this.Yu.forEach(t=>t.m()),this.Yu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Lc(){return this.tc}Yn(){return this.tc.W()}Vo(){return this.Ku}Ac(t,i){const s=this.nc(i);this.Ec(t,s),this.Xu.push(t),1===this.Xu.length?this.Ah():this.ar()}Bc(t){const i=this.Nn(t),s=this.Xu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Xu.splice(s,1),n.so(t),t.m&&t.m(),this.ph.K_();const e=this.Yu.length;this.Oc(n),this.Yu.length<e&&this.Ah()}Lh(t,i){const s=l(this.Nn(t));s.so(t,!0),s.Qa(t,i,!0)}Bu(){const t=Y.gn();t.hn(),this.lc(t)}Wc(t){const i=Y.gn();i._n(t),this.lc(i)}dn(){const t=Y.gn();t.dn(),this.lc(t)}pn(t){const i=Y.gn();i.pn(t),this.lc(i)}fn(t){const i=Y.gn();i.fn(t),this.lc(i)}un(t){const i=Y.gn();i.un(t),this.lc(i)}ln(){const t=Y.gn();t.ln(),this.lc(t)}zc(){return this.Ps.rightPriceScale.visible?"right":"left"}$c(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Hc(t))return;const s=l(this.Nn(t));s.so(t);const n=this.nc(i);this.Ec(t,n),0===s.yl().length&&this.Oc(s),this.Ah()}Nc(){return this.hc}q(){return this.ec}Ut(t){const i=this.hc,s=this.ec;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Ju||this.Ju.wr!==s||this.Ju.gr!==i)this.Ju={wr:s,gr:i,Uc:new Map};else{const i=this.Ju.Uc.get(t);if(void 0!==i)return i}const n=this.xa.it(s,i,t/100);return this.Ju.Uc.set(t,n),n}qc(t){return this.Yu.indexOf(t)}Ki(){return this.xa}jc(){return this.Yc()}Yc(t){const i=new wi(this.ph,this);this.Yu.push(i);const s=t??this.Yu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.lc(n),i}nc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Yu.length,t))<this.Yu.length?this.Yu[t]:this.Yc(t)}Hc(t){return this.Yu.findIndex(i=>i.zo().includes(t))}Mc(t,i){const s=new Y(i);if(null!==t){const n=this.Yu.indexOf(t);s.tn(n,{sn:i})}return s}ac(t,i){return void 0===i&&(i=2),this.Mc(this.Nn(t),i)}lc(t){this.Qu&&this.Qu(t),this.Yu.forEach(t=>t.n_()._r().Tt())}Ec(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.zc();i.Qa(t,n),j(n)||t.lr(t.W())}rc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Oc(t){!t.Wo()&&0===t.yl().length&&this.Yu.length>1&&this.Yu.splice(this.qc(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 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"}(Ii||(Ii={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Vi||(Vi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Li||(Li={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Ai||(Ai={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>K(zi(t),4))(t)).replace(/yy/g,(t=>K(zi(t)%100,2))(t)).replace(/MMMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(t,s)).replace(/MMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(t,s)).replace(/MM/g,(t=>K((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>K((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Xc=t,this.Gc=i}c_(t){return $i(t,this.Xc,this.Gc)}}class Ni{constructor(t){this.Kc=t||"%h:%m:%s"}c_(t){return this.Kc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Zc:"yyyy-MM-dd",Jc:"%h:%m:%s",Qc:" ",td:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.sd=new Hi(i.Zc,i.td),this.nd=new Ni(i.Jc),this.ed=i.Qc}c_(t){return`${this.sd.c_(t)}${this.ed}${this.nd.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{rd:(Gi=1,1e3*Gi),hd:10},{rd:Yi(1),hd:20},{rd:Yi(5),hd:21},{rd:Yi(30),hd:22},{rd:ji(1),hd:30},{rd:ji(3),hd:31},{rd:ji(6),hd:32},{rd:ji(12),hd:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].rd)!==Math.floor(t.getTime()/Xi[s].rd))return Xi[s].hd;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{ld:Math.round(s.getTime()/1e3),ad:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{ld: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&&"ld"in t?t.ld:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ad?new Date(1e3*i.ld).getTime():new Date(Date.UTC(i.ad.year,i.ad.month-1,i.ad.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({Zc:i,Jc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Qc:" ",td:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.c_(new Date(1e3*i.ld))}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.ad?new Date(1e3*t.ld):new Date(Date.UTC(t.ad.year,t.ad.month-1,t.ad.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.ld,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).ld);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).ld-(s||Zi(i.time).ld),s=Zi(i.time).ld,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.ld-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.ld),s)}}(t,i)}static _d(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 as=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function os(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new as(e,s,n)}const _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.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.wd=null,this.gd=!1,this.bd=null,this.Md=null,this.yd=!1,this.Sd=!1,this.xd=!1,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Id=0,this.Vd=!1,this.Ld=!1,this.Ad=!1,this.Ed=0,this.Bd=null,this.Od=!cs(),this.Wd=t=>{this.zd(t)},this.$d=t=>{if(this.Hd(t)){const i=this.Nd(t);if(++this.fd,this.vd&&this.fd>1){const{Ud:s}=this.qd(ws(t),this.md);s<30&&!this.xd&&this.jd(i,this.Xd.Yd),this.Gd()}}else{const i=this.Nd(t);if(++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}}},this.Qd=t,this.Xd=i,this.Ps=s,this.tp()}m(){null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Td&&(this.Td(),this.Td=null),this.ip(),this.Jd()}sp(t){this.kd&&this.kd();const i=this.np.bind(this);if(this.kd=()=>{this.Qd.removeEventListener("mousemove",i)},this.Qd.addEventListener("mousemove",i),this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.ep),this.Od=!0}Jd(){null!==this.dd&&clearTimeout(this.dd),this.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Gd(){null!==this.vd&&clearTimeout(this.vd),this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}np(t){if(this.Ad||null!==this.Md)return;if(this.Hd(t))return;const i=this.Nd(t);this.Kd(i,this.Xd.rp),this.Od=!0}hp(t){const i=bs(t.changedTouches,l(this.Bd));if(null===i)return;if(this.Ed=gs(t),null!==this.Fd)return;if(this.Ld)return;this.Vd=!0;const s=this.qd(ws(i),l(this.Md)),{lp:n,ap:e,Ud:r}=s;if(this.yd||!(r<5)){if(!this.yd){const t=.5*n,i=e>=t&&!this.Ps.op(),s=t>e&&!this.Ps._p();i||s||(this.Ld=!0),this.yd=!0,this.xd=!0,this.ip(),this.Gd()}if(!this.Ld){const s=this.Nd(t,i);this.jd(s,this.Xd.up),ms(t)}}}cp(t){if(0!==t.button)return;const i=this.qd(ws(t),l(this.bd)),{Ud:s}=i;if(s>=5&&(this.Sd=!0,this.Jd()),this.Sd){const i=this.Nd(t);this.Kd(i,this.Xd.dp)}}qd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{lp:s,ap:n,Ud:s+n}}pp(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.ip(),this.Md=null,this.Rd&&(this.Rd(),this.Rd=null);const s=this.Nd(t,i);if(this.jd(s,this.Xd.fp),++this.fd,this.vd&&this.fd>1){const{Ud:t}=this.qd(ws(i),this.md);t<30&&!this.xd&&this.jd(s,this.Xd.Yd),this.Gd()}else this.xd||(this.jd(s,this.Xd.vp),this.Xd.vp&&ms(t));0===this.fd&&ms(t),0===t.touches.length&&this.gd&&(this.gd=!1,ms(t))}zd(t){if(0!==t.button)return;const i=this.Nd(t);if(this.bd=null,this.Ad=!1,this.Dd&&(this.Dd(),this.Dd=null),us()){this.Qd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Wd)}if(!this.Hd(t))if(this.Kd(i,this.Xd.mp),++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}else this.Sd||this.Kd(i,this.Xd.wp)}ip(){null!==this.wd&&(clearTimeout(this.wd),this.wd=null)}gp(t){if(null!==this.Bd)return;const i=t.changedTouches[0];this.Bd=i.identifier,this.Ed=gs(t);const s=this.Qd.ownerDocument.documentElement;this.xd=!1,this.yd=!1,this.Ld=!1,this.Md=ws(i),this.Rd&&(this.Rd(),this.Rd=null);{const i=this.hp.bind(this),n=this.pp.bind(this);this.Rd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.ip(),this.wd=setTimeout(this.bp.bind(this,t),240)}const n=this.Nd(t,i);this.jd(n,this.Xd.Mp),this.vd||(this.fd=0,this.vd=setTimeout(this.Gd.bind(this),500),this.md=ws(i))}yp(t){if(0!==t.button)return;const i=this.Qd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Wd),this.Sd=!1,this.bd=ws(t),this.Dd&&(this.Dd(),this.Dd=null);{const t=this.cp.bind(this),s=this.zd.bind(this);this.Dd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ad=!0,this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.Sp),this.dd||(this.ud=0,this.dd=setTimeout(this.Jd.bind(this),500),this.pd=ws(t))}tp(){this.Qd.addEventListener("mouseenter",this.sp.bind(this)),this.Qd.addEventListener("touchcancel",this.ip.bind(this));{const t=this.Qd.ownerDocument,i=t=>{this.Xd.xp&&(t.composed&&this.Qd.contains(t.composedPath()[0])||t.target&&this.Qd.contains(t.target)||this.Xd.xp())};this.Pd=()=>{t.removeEventListener("touchstart",i)},this.Cd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Td=()=>{this.Qd.removeEventListener("dblclick",this.$d)},this.Qd.addEventListener("dblclick",this.$d)),this.Qd.addEventListener("mouseleave",this.Cp.bind(this)),this.Qd.addEventListener("touchstart",this.gp.bind(this),{passive:!0}),ps(this.Qd),this.Qd.addEventListener("mousedown",this.yp.bind(this)),this.Pp(),this.Qd.addEventListener("touchmove",()=>{},{passive:!1})}Pp(){void 0===this.Xd.Tp&&void 0===this.Xd.kp&&void 0===this.Xd.Dp||(this.Qd.addEventListener("touchstart",t=>this.Rp(t.touches),{passive:!0}),this.Qd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Fd&&void 0!==this.Xd.kp){const i=vs(t.touches[0],t.touches[1])/this.Id;this.Xd.kp(this.Fd,i),ms(t)}},{passive:!1}),this.Qd.addEventListener("touchend",t=>{this.Rp(t.touches)}))}Rp(t){1===t.length&&(this.Vd=!1),2!==t.length||this.Vd||this.gd?this.Fp():this.Ip(t)}Ip(t){const i=this.Qd.getBoundingClientRect()||{left:0,top:0};this.Fd={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Id=vs(t[0],t[1]),void 0!==this.Xd.Tp&&this.Xd.Tp(),this.ip()}Fp(){null!==this.Fd&&(this.Fd=null,void 0!==this.Xd.Dp&&this.Xd.Dp())}Cp(t){if(this.kd&&this.kd(),this.Hd(t))return;if(!this.Od)return;const i=this.Nd(t);this.Kd(i,this.Xd.Vp),this.Od=!cs()}bp(t){const i=bs(t.touches,l(this.Bd));if(null===i)return;const s=this.Nd(t,i);this.jd(s,this.Xd.Lp),this.xd=!0,this.gd=!0}Hd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ed+500}jd(t,i){i&&i.call(this.Xd,t)}Kd(t,i){i&&i.call(this.Xd,t)}Nd(t,i){const s=i||t,n=this.Qd.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,Ap:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ep:t.type,Bp:s.target,o_:t.view,Op:()=>{"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.zp=null,this.$p=!0,this.Hp=null,this.Np=t,this.Up=t.qp()[i],this.jp=t.qp()[s],this.Yp=document.createElement("tr"),this.Yp.style.height="1px",this.Xp=document.createElement("td"),this.Xp.style.position="relative",this.Xp.style.padding="0",this.Xp.style.margin="0",this.Xp.setAttribute("colspan","3"),this.Gp(),this.Yp.appendChild(this.Xp),this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(this.Wp=null,this.zp=null)}m(){null!==this.zp&&this.zp.m()}Zp(){return this.Yp}Jp(){return ns({width:this.Up.Jp().width,height:1})}Qp(){return ns({width:this.Up.Qp().width,height:1*window.devicePixelRatio})}tf(t,i,s){const n=this.Qp();t.fillStyle=this.Np.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Gp(),this.Np.W().layout.panes.enableResize!==this.$p&&(this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(null!==this.Wp&&(this.Xp.removeChild(this.Wp.if),this.Xp.removeChild(this.Wp.sf),this.Wp=null),null!==this.zp&&(this.zp.m(),this.zp=null)))}Kp(){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.Xp.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.Xp.appendChild(s);const e={ep:this.nf.bind(this),Vp:this.ef.bind(this),Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this)};this.zp=new fs(s,e,{op:()=>!1,_p:()=>!0}),this.Wp={sf:s,if:t}}Gp(){this.Xp.style.background=this.Np.W().layout.panes.separatorColor}nf(t){null!==this.Wp&&(this.Wp.sf.style.backgroundColor=this.Np.W().layout.panes.separatorHoverColor)}ef(t){null!==this.Wp&&null===this.Hp&&(this.Wp.sf.style.backgroundColor="")}rf(t){if(null===this.Wp)return;const i=this.Up.af().Lo()+this.jp.af().Lo(),s=i/(this.Up.Jp().height+this.jp.Jp().height),n=30*s;i<=2*n||(this.Hp={_f:t.pageY,uf:this.Up.af().Lo(),cf:i-n,df:i,pf:s,ff:n},this.Wp.if.style.display="block")}hf(t){const i=this.Hp;if(null===i)return;const s=(t.pageY-i._f)*i.pf,n=Xt(i.uf+s,i.ff,i.cf);this.Up.af().Ao(n),this.jp.af().Ao(i.df-n),this.Np.ti().Ah()}lf(t){null!==this.Hp&&null!==this.Wp&&(this.Hp=null,this.Wp.if.style.display="none")}}function ys(t,i){return t.vf-i.vf}function Ss(t,i,s){const n=(t.vf-i.vf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=0,this.Sf=0,this.xf=t,this.Cf=i,this.Pf=s,this.Mn=n}Tf(t,i){if(null!==this.mf){if(this.mf.gt===i)return void(this.mf.vf=t);if(Math.abs(this.mf.vf-t)<this.Mn)return}this.bf=this.gf,this.gf=this.wf,this.wf=this.mf,this.mf={gt:i,vf:t}}oe(t,i){if(null===this.mf||null===this.wf)return;if(i-this.mf.gt>50)return;let s=0;const n=Ss(this.mf,this.wf,this.Cf),e=ys(this.mf,this.wf),r=[n],h=[e];if(s+=e,null!==this.gf){const t=Ss(this.wf,this.gf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);if(r.push(t),h.push(i),s+=i,null!==this.bf){const t=Ss(this.gf,this.bf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.gf,this.bf);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.xf||(this.Mf={vf:t,gt:i},this.Sf=l,this.yf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Pf))}Iu(t){const i=l(this.Mf),s=t-i.gt;return i.vf+this.Sf*(Math.pow(this.Pf,s)-1)/Math.log(this.Pf)}Fu(t){return null===this.Mf||this.kf(t)===this.yf}kf(t){const i=t-l(this.Mf).gt;return Math.min(i,this.yf)}}class Cs{constructor(t,i){this.Df=void 0,this.Rf=void 0,this.Ff=void 0,this.vs=!1,this.If=t,this.Vf=i,this.Lf()}Tt(){this.Lf()}Af(){this.Df&&this.If.removeChild(this.Df),this.Rf&&this.If.removeChild(this.Rf),this.Df=void 0,this.Rf=void 0}Ef(){return this.vs!==this.Bf()||this.Ff!==this.Of()}Of(){return this.Vf.ti().Ki().tt(this.Vf.W().layout.textColor)>160?"dark":"light"}Bf(){return this.Vf.W().layout.attributionLogo}Wf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Lf(){this.Ef()&&(this.Af(),this.vs=this.Bf(),this.vs&&(this.Ff=this.Of(),this.Rf=document.createElement("style"),this.Rf.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.Df=document.createElement("a"),this.Df.href=`https://pipsend.com${this.Wf()}`,this.Df.title="Powered by Pipsend Charts",this.Df.id="pipsend-attr-logo",this.Df.target="_blank",this.Df.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.Df.toggleAttribute("data-dark","dark"===this.Ff),this.If.appendChild(this.Rf),this.If.appendChild(this.Df)))}}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.nh&&t.nh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function Rs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Fs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],a=t[r-1],o=a.qt(n,!1),_=l.$i(),u=a.$i();if(1===i?_>u-o:_<u+o){const n=u-o*i;l.Hi(n);const r=n-i*o/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-o-_:_-(u+o)}}class Vs{constructor(t,i,s,n){this.Yi=null,this.zf=null,this.$f=!1,this.Hf=new it(200),this.Nf=null,this.Uf=0,this.qf=!1,this.jf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Xf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Pt=t,this.Ps=i,this.ya=i.layout,this.tc=s,this.Gf="left"===n,this.Kf=Fs("normal",n),this.Zf=Fs("top",n),this.Jf=Fs("bottom",n),this.Xp=document.createElement("div"),this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Xp.style.width="25px",this.Xp.style.left="0",this.Xp.style.position="relative",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.tv=Ps(this.Xp,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const r=this.tv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),xp:this.iv.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this),Zd:this.sv.bind(this),Yd:this.sv.bind(this),ep:this.nv.bind(this),Vp:this.ef.bind(this)};this.zp=new fs(this.tv.canvasElement,h,{op:()=>!this.Ps.handleScroll.vertTouchDrag,_p:()=>!0})}m(){this.zp.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Yi&&this.Yi.eo().u(this),this.Yi=null}Zp(){return this.Xp}P(){return this.ya.fontSize}ev(){const t=this.tc.W();return this.Nf!==t.T&&(this.Hf.Vn(),this.Nf=t.T),t}rv(){if(null===this.Yi)return 0;let t=0;const i=this.ev(),s=l(this.Qf.canvasElement.getContext("2d",{colorSpace:this.Pt.Yf().W().layout.colorSpace}));s.save();const n=this.Yi.Il();s.font=this.hv(),n.length>0&&(t=Math.max(this.Hf.Ii(s,n[0].Jl),this.Hf.Ii(s,n[n.length-1].Jl)));const e=this.lv();for(let i=e.length;i--;){const n=this.Hf.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.zf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.zf.height-2,r);t=Math.max(t,this.Hf.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Hf.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const a=t||34;return ds(Math.ceil(i.S+i.C+i.V+i.L+5+a))}av(t){null!==this.zf&&es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`)}ov(){return l(this.zf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.eo().u(this),this.Yi=t,t.eo().i(this.ca.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt.af();this.Pt.Yf().ti().Jo(t,l(this.$t()))}_v(t){if(null===this.zf)return;const i={colorSpace:this.Pt.Yf().W().layout.colorSpace};if(1!==t){this.uv(),this.Qf.applySuggestedBitmapSize();const t=os(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)}),this.Pt.pv(t,this.Jf),this.fv(t),this.Pt.pv(t,this.Kf),this.vv(t))}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.mv(s),this.Pt.pv(s,this.Zf))}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Il()}rf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!0,i.qo(s,this.Yi,t.localY)}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af(),n=this.Yi;i.jo(s,n,t.localY)}iv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Yf().ti(),i=this.Pt.af(),s=this.Yi;this.$f&&(this.$f=!1,t.Yo(i,s))}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!1,i.Yo(s,this.Yi)}sv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}nv(t){if(null===this.Yi)return;!this.Pt.Yf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Ia()||this.wv(1)}ef(t){this.wv(0)}lv(){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.af(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.af().Ft()),t}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.af().ti(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.zf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.ev().S*s));let e;e=this.Gf?i.width-n:0,t.fillRect(e,0,n,i.height)}fv(t){if(null===this.zf||null===this.Yi)return;const i=this.Yi.Il(),s=this.Yi.W(),n=this.ev(),e=this.Gf?this.zf.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)),a=Math.floor(.5*h),o=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-a,o,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.hv(),t.fillStyle=s.textColor??this.ya.textColor,t.textAlign=this.Gf?"right":"left",t.textBaseline="middle";const r=this.Gf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.Hf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}uv(){if(null===this.zf||null===this.Yi)return;let t=this.zf.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt.af(),e=this.ev();this.Yi===n.qn()&&this.Pt.af().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.gv(i,e,t)}gv(t,i,s){if(null===this.zf)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.zf.height-t&&n<this.zf.height+t&&s.Hi(this.zf.height-t)}Is(n,1,this.zf.height,i),Is(e,-1,this.zf.height,i)}vv(t){if(null===this.zf)return;const i=this.lv(),s=this.ev(),n=this.Gf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Hf,n)}})}mv(t){if(null===this.zf||null===this.Yi)return;const i=this.Pt.Yf().ti(),s=[],n=this.Pt.af(),e=i.dc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.ev(),h=this.Gf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Hf,h)})})}wv(t){this.Xp.style.cursor=1===t?"ns-resize":"default"}ca(){const t=this.rv();this.Uf<t&&this.Pt.Yf().ti().Ah(),this.Uf=t}hv(){return g(this.ya.fontSize,this.ya.fontFamily)}}function Ls(t,i){return t.tl?.(i)??[]}function As(t,i){return t.$s?.(i)??[]}function Es(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Zh?.(i)??[]}class Os{constructor(t,i){this.zf=ns({width:0,height:0}),this.bv=null,this.Mv=null,this.yv=null,this.Sv=null,this.xv=!1,this.Cv=new o,this.Pv=new o,this.Tv=0,this.kv=!1,this.Dv=null,this.Rv=!1,this.Fv=null,this.Iv=null,this.qf=!1,this.jf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Xf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Vf=t,this.Vv=i,this.Vv.s_().i(this.Lv.bind(this),this,!0),this.Av=document.createElement("td"),this.Av.style.padding="0",this.Av.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.Av.appendChild(s),this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.tv=Ps(s,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Yp=document.createElement("tr"),this.Yp.appendChild(this.Ev),this.Yp.appendChild(this.Av),this.Yp.appendChild(this.Bv),this.Ov(),this.zp=new fs(this.tv.canvasElement,this,{op:()=>null===this.Dv&&!this.Vf.W().handleScroll.vertTouchDrag,_p:()=>null===this.Dv&&!this.Vf.W().handleScroll.horzTouchDrag})}m(){null!==this.bv&&this.bv.m(),null!==this.Mv&&this.Mv.m(),this.yv=null,this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Vv&&(this.Vv.s_().u(this),this.Vv.m()),this.zp.m()}af(){return l(this.Vv)}Wv(t){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=t,null!==this.Vv&&this.Vv.s_().i(Os.prototype.Lv.bind(this),this,!0),this.Ov(),this.Vf.qp().indexOf(this)===this.Vf.qp().length-1?(this.yv=this.yv??new Cs(this.Av,this.Vf),this.yv.Tt()):(this.yv?.Af(),this.yv=null)}Yf(){return this.Vf}Zp(){return this.Yp}Ov(){if(null!==this.Vv&&(this.zv(),0!==this.ss().Xs().length)){if(null!==this.bv){const t=this.Vv.No();this.bv.us(l(t))}if(null!==this.Mv){const t=this.Vv.Uo();this.Mv.us(l(t))}}}$v(){null!==this.bv&&this.bv.Tt(),null!==this.Mv&&this.Mv.Tt()}Lo(){return null!==this.Vv?this.Vv.Lo():0}Ao(t){this.Vv&&this.Vv.Ao(t)}ep(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}Sp(t){this.Hv(),this.Uv(),this.Nv(t.localX,t.localY,t)}rp(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}wp(t){null!==this.Vv&&(this.Hv(),this.qv(t))}Zd(t){null!==this.Vv&&this.jv(this.Pv,t)}Yd(t){this.Zd(t)}dp(t){this.Hv(),this.Yv(t),this.Nv(t.localX,t.localY,t)}mp(t){null!==this.Vv&&(this.Hv(),this.kv=!1,this.Xv(t))}vp(t){null!==this.Vv&&this.qv(t)}Lp(t){if(this.kv=!0,null===this.Dv){const i={x:t.localX,y:t.localY};this.Gv(i,i,t)}}Vp(t){null!==this.Vv&&(this.Hv(),this.Vv.ti()._c(null),this.Kv())}Zv(){return this.Cv}Jv(){return this.Pv}Tp(){this.Tv=1,this.ss().ln()}kp(t,i){if(!this.Vf.W().handleScale.pinch)return;const s=5*(i-this.Tv);this.Tv=i,this.ss().Sc(t.ut,s)}Mp(t){this.kv=!1,this.Rv=null!==this.Dv,this.Uv();const i=this.ss().dc();null!==this.Dv&&i.It()&&(this.Fv={x:i.ni(),y:i.ei()},this.Dv={x:t.localX,y:t.localY})}up(t){if(null===this.Vv)return;const i=t.localX,s=t.localY;if(null!==this.Dv){this.Rv=!1;const n=l(this.Fv),e=n.x+(i-this.Dv.x),r=n.y+(s-this.Dv.y);return void this.Nv(e,r,t)}this.Yv(t)}fp(t){0===this.Yf().W().trackingMode.exitMode&&(this.Rv=!0),this.Qv(),this.Xv(t)}Xn(t,i){const s=this.Vv;return null===s?null:Si(s,t,i)}tm(t,i){l("left"===i?this.bv:this.Mv).av(ns({width:t,height:this.zf.height}))}Jp(){return this.zf}av(t){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Av.style.width=t.width+"px",this.Av.style.height=t.height+"px")}im(){const t=l(this.Vv);t.Ho(t.No()),t.Ho(t.Uo());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ho(s),i.zs()}for(const i of t.e_())i.zs()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;null!==t&&t.drawImage(n,i,s)}}_v(t){if(0===t)return;if(null===this.Vv)return;t>1&&this.im(),null!==this.bv&&this.bv._v(t),null!==this.Mv&&this.Mv._v(t);const i={colorSpace:this.Vf.W().layout.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const t=os(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t)}),this.Vv&&(this.sm(t,Ls),this.nm(t),this.sm(t,As),this.sm(t,Es)))}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.rm(s),this.sm(s,Bs),this.sm(s,Es))}hm(){return this.bv}lm(){return this.Mv}pv(t,i){this.sm(t,i)}Lv(){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=null}qv(t){this.jv(this.Cv,t)}jv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().pu(s),{x:s,y:n},i)}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}nm(t){const i=l(this.Vv),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}rm(t){this.am(t,As,Ds,this.ss().dc())}sm(t,i){const s=l(this.Vv),n=s.Ft(),e=s.e_();for(const s of e)this.am(t,i,ks,s);for(const s of n)this.am(t,i,ks,s);for(const s of e)this.am(t,i,Ds,s);for(const s of n)this.am(t,i,Ds,s)}am(t,i,s,n){const e=l(this.Vv),r=e.ti().oc(),h=null!==r&&r.r_===n,a=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Rs(i,i=>s(i,t,h,a),n,e)}zv(){if(null===this.Vv)return;const t=this.Vf,i=this.Vv.No().W().visible,s=this.Vv.Uo().W().visible;i||null===this.bv||(this.Ev.removeChild(this.bv.Zp()),this.bv.m(),this.bv=null),s||null===this.Mv||(this.Bv.removeChild(this.Mv.Zp()),this.Mv.m(),this.Mv=null);const n=t.ti().Lc();i&&null===this.bv&&(this.bv=new Vs(this,t.W(),n,"left"),this.Ev.appendChild(this.bv.Zp())),s&&null===this.Mv&&(this.Mv=new Vs(this,t.W(),n,"right"),this.Bv.appendChild(this.Mv.Zp()))}om(t){return t.Ap&&this.kv||null!==this.Dv}_m(t){return Math.max(0,Math.min(t,this.zf.width-1))}um(t){return Math.max(0,Math.min(t,this.zf.height-1))}Nv(t,i,s){this.ss().Rc(this._m(t),this.um(i),s,l(this.Vv))}Kv(){this.ss().Ic()}Qv(){this.Rv&&(this.Dv=null,this.Kv())}Gv(t,i,s){this.Dv=t,this.Rv=!1,this.Nv(i.x,i.y,s);const n=this.ss().dc();this.Fv={x:n.ni(),y:n.ei()}}ss(){return this.Vf.ti()}Xv(t){if(!this.xv)return;const i=this.ss(),s=this.af();if(i.Ko(s,s.ks()),this.Sv=null,this.xv=!1,i.Tc(),null!==this.Iv){const t=performance.now(),s=i.At();this.Iv.oe(s.Mu(),t),this.Iv.Fu(t)||i.un(this.Iv)}}Hv(){this.Dv=null}Uv(){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().At().Gi()}Yv(t){if(null===this.Vv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.Vf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Ap)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Ap))return;const h=this.Vv.ks(),l=performance.now();if(null!==this.Sv||this.om(t)||(this.Sv={x:t.clientX,y:t.clientY,ld:l,dm:t.localX,pm:t.localY}),null!==this.Sv&&!this.xv&&(this.Sv.x!==t.clientX||this.Sv.y!==t.clientY)){if(t.Ap&&r.touch||!t.Ap&&r.mouse){const t=s.gu();this.Iv=new xs(.2/t,7/t,.997,15/t),this.Iv.Tf(s.Mu(),this.Sv.ld)}else this.Iv=null;h.Gi()||i.Xo(this.Vv,h,t.localY),i.Cc(t.localX),this.xv=!0}this.xv&&(h.Gi()||i.Go(this.Vv,h,t.localY),i.Pc(t.localX),null!==this.Iv&&this.Iv.Tf(s.Mu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.zf=ns({width:0,height:0}),this.jf=()=>this._v(3),this.Gf="left"===t,this.tc=s.Lc,this.Ps=i,this.fm=n,this.vm=e,this.Xp=document.createElement("div"),this.Xp.style.width="25px",this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf)}m(){this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Xp}Jp(){return this.zf}av(t){es(this.zf,t)||(this.zf=t,this.Qf.resizeCanvasElement(t),this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.xt=!0)}_v(t){if(t<3&&!this.xt)return;if(0===this.zf.width||0===this.zf.height)return;this.xt=!1,this.Qf.applySuggestedBitmapSize();const i=os(this.Qf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)})}Qp(){return this.Qf.bitmapSize}tf(t,i,s){const n=this.Qp();n.width>0&&n.height>0&&t.drawImage(this.Qf.canvasElement,i,s)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.fm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.tc.W().S*s),r=Math.floor(this.tc.W().S*n),h=this.Gf?i.width-e:0;t.fillRect(h,0,e,r)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.vm())}}function zs(t){return i=>i.nl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.wm=null,this.gm=null,this.M=null,this.bm=!1,this.zf=ns({width:0,height:0}),this.Mm=new o,this.Hf=new it(5),this.qf=!1,this.jf=()=>{this.qf||this.Vf.ti().ar()},this.Xf=()=>{this.qf||this.Vf.ti().ar()},this.Vf=t,this.u_=i,this.Ps=t.W().layout,this.Df=document.createElement("tr"),this.ym=document.createElement("td"),this.ym.style.padding="0",this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.Xp=document.createElement("td"),this.Xp.style.height="25px",this.Xp.style.padding="0",this.xm=document.createElement("div"),this.xm.style.width="100%",this.xm.style.height="100%",this.xm.style.position="relative",this.xm.style.overflow="hidden",this.Xp.appendChild(this.xm),this.Qf=Ps(this.xm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const s=this.Qf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.tv=Ps(this.xm,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Df.appendChild(this.ym),this.Df.appendChild(this.Xp),this.Df.appendChild(this.Sm),this.Cm(),this.Vf.ti().Vo().i(this.Cm.bind(this),this),this.zp=new fs(this.tv.canvasElement,this,{op:()=>!0,_p:()=>!this.Vf.W().handleScroll.horzTouchDrag})}m(){this.zp.m(),null!==this.wm&&this.wm.m(),null!==this.gm&&this.gm.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Df}Pm(){return this.wm}Tm(){return this.gm}Sp(t){if(this.bm)return;this.bm=!0;const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.yc(t.localX)}Mp(t){this.Sp(t)}xp(){const t=this.Vf.ti();!t.At().Gi()&&this.bm&&(this.bm=!1,this.Vf.W().handleScale.axisPressedMouseMove.time&&t.Dc())}dp(t){const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.kc(t.localX)}up(t){this.dp(t)}mp(){this.bm=!1;const t=this.Vf.ti();t.At().Gi()&&!this.Vf.W().handleScale.axisPressedMouseMove.time||t.Dc()}fp(){this.mp()}Zd(){this.Vf.W().handleScale.axisDoubleClickReset.time&&this.Vf.ti().dn()}Yd(){this.Zd()}ep(){this.Vf.ti().W().handleScale.axisPressedMouseMove.time&&this.wv(1)}Vp(){this.wv(0)}Jp(){return this.zf}km(){return this.Mm}Dm(t,i,s){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.Mm.p(t)),null!==this.wm&&this.wm.av(ns({width:i,height:t.height})),null!==this.gm&&this.gm.av(ns({width:s,height:t.height}))}Rm(){const t=this.Fm();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Im)}Tt(){this.Vf.ti().At().Il()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}_v(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const s=os(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t),this.Vm(s,Ns)}),this.fv(s),this.Vm(s,$s)),null!==this.wm&&this.wm._v(t),null!==this.gm&&this.gm._v(t)}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Lm([...this.Vf.ti().Xs(),this.Vf.ti().dc()],s),this.Vm(s,Hs))}Vm(t,i){const s=this.Vf.ti().Xs();for(const n of s)Rs(i,i=>ks(i,t,!1,void 0),n,void 0);for(const n of s)Rs(i,i=>Ds(i,t,!1,void 0),n,void 0)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.Vf.ti().Nc())}dv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Vf.W().timeScale.borderVisible){t.fillStyle=this.Am();const n=Math.max(1,Math.floor(this.Fm().S*s));t.fillRect(0,0,i.width,n)}}fv(t){const i=this.Vf.ti().At(),s=i.Il();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Fm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Am(),t.fillStyle=this.Am();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.hv();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.Vf.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.Hf.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.zf.width&&(i-=Math.abs(this.zf.width-(r+n))),i}Lm(t,i){const s=this.Fm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Am(){return this.Vf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}hv(){return g(this.$(),this.Ps.fontFamily)}Bm(){return g(this.$(),this.Ps.fontFamily,"bold")}Fm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Im:0});const t=this.M,i=this.hv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.A=3*s/12,t.I=3*s/12,t.Qi=9*s/12,t.B=0,t.Im=4*s/12,t.Ji.Vn()}return this.M}wv(t){this.Xp.style.cursor=1===t?"ew-resize":"default"}Cm(){const t=this.Vf.ti(),i=t.W();i.leftPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Zp()),this.wm.m(),this.wm=null),i.rightPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Zp()),this.gm.m(),this.gm=null);const s={Lc:this.Vf.ti().Lc()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Nc();i.leftPriceScale.visible&&null===this.wm&&(this.wm=new Ws("left",i,s,n,e),this.ym.appendChild(this.wm.Zp())),i.rightPriceScale.visible&&null===this.gm&&(this.gm=new Ws("right",i,s,n,e),this.Sm.appendChild(this.gm.Zp()))}}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.Om=[],this.Wm=[],this.zm=0,this.na=0,this.yo=0,this.$m=0,this.Hm=0,this.Nm=null,this.Um=!1,this.Cv=new o,this.Pv=new o,this.Zu=new o,this.qm=null,this.jm=null,this.If=t,this.Ps=i,this.u_=s,this.Df=document.createElement("div"),this.Df.classList.add("tv-lightweight-charts"),this.Df.style.overflow="hidden",this.Df.style.direction="ltr",this.Df.style.width="100%",this.Df.style.height="100%",(n=this.Df).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Ym=document.createElement("table"),this.Ym.setAttribute("cellspacing","0"),this.Df.appendChild(this.Ym),this.Xm=this.Gm.bind(this),Ys(this.Ps)&&this.Km(!0),this.ss=new Ei(this.Qu.bind(this),this.Ps,s),this.ti().fc().i(this.Zm.bind(this),this),this.Jm=new Us(this,this.u_),this.Ym.appendChild(this.Jm.Zp());const e=i.autoSize&&this.Qm();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.tw(r,h),this.iw(),t.appendChild(this.Df),this.sw(),this.ss.At().Au().i(this.ss.Ah.bind(this.ss),this),this.ss.Vo().i(this.ss.Ah.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}qp(){return this.Om}nw(){return this.Jm}m(){this.Km(!1),0!==this.zm&&window.cancelAnimationFrame(this.zm),this.ss.fc().u(this),this.ss.At().Au().u(this),this.ss.Vo().u(this),this.ss.m();for(const t of this.Om)this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();this.Om=[];for(const t of this.Wm)this.ew(t);this.Wm=[],l(this.Jm).m(),null!==this.Df.parentElement&&this.Df.parentElement.removeChild(this.Df),this.Zu.m(),this.Cv.m(),this.Pv.m(),this.rw()}tw(t,i,s=!1){if(this.na===i&&this.yo===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.na=n.height,this.yo=n.width;const e=this.na+"px",r=this.yo+"px";l(this.Df).style.height=e,l(this.Df).style.width=r,this.Ym.style.height=e,this.Ym.style.width=r,s?this.hw(Y.bn(),performance.now()):this.ss.Ah()}_v(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Om.length;i++)this.Om[i]._v(t.rn(i).sn);this.Ps.timeScale.visible&&this.Jm._v(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Km(s),t.layout?.panes&&this.lw(),this.sw(),this.aw(t)}Zv(){return this.Cv}Jv(){return this.Pv}fc(){return this.Zu}ow(t=!1){null!==this.Nm&&(this.hw(this.Nm,performance.now()),this.Nm=null);const i=this._w(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this._w(n,t),s}uw(t){if("left"===t&&!this.cw())return 0;if("right"===t&&!this.dw())return 0;if(0===this.Om.length)return 0;return l("left"===t?this.Om[0].hm():this.Om[0].lm()).ov()}pw(){return this.Ps.autoSize&&null!==this.qm}sf(){return this.Df}fw(t){this.jm=t,this.jm?this.sf().style.setProperty("cursor",t):this.sf().style.removeProperty("cursor")}mw(){return this.jm}ww(t){return h(this.Om[t]).Jp()}lw(){this.Wm.forEach(t=>{t.Tt()})}aw(t){(void 0!==t.autoSize||!this.qm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.qm&&this.Qm(),!1===t.autoSize&&null!==this.qm&&this.rw(),t.autoSize||void 0===t.width&&void 0===t.height||this.tw(t.width||this.yo,t.height||this.na))}_w(t,i){let s=0,n=0;const e=this.Om[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Om.length;r++){const h=this.Om[r],a=l("left"===s?h.hm():h.lm()),o=a.Qp();if(null!==t&&a.tf(t,n,e,i),e+=o.height,r<this.Om.length-1){const i=this.Wm[r],s=i.Qp();null!==t&&i.tf(t,n,e),e+=s.height}}};if(this.cw()){r("left",0);s+=l(e.hm()).Qp().width}for(let e=0;e<this.Om.length;e++){const r=this.Om[e],h=r.Qp();if(null!==t&&r.tf(t,s,n,i),n+=h.height,e<this.Om.length-1){const i=this.Wm[e],r=i.Qp();null!==t&&i.tf(t,s,n),n+=r.height}}if(s+=e.Qp().width,this.dw()){r("right",s);s+=l(e.lm()).Qp().width}const h=(i,s,n)=>{l("left"===i?this.Jm.Pm():this.Jm.Tm()).tf(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Jm.Qp();if(null!==t){let r=0;this.cw()&&(h("left",r,n),r=l(e.hm()).Qp().width),this.Jm.tf(t,r,n,i),r+=s.width,this.dw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}gw(){let t=0,i=0,s=0;for(const n of this.Om)this.cw()&&(i=Math.max(i,l(n.hm()).rv(),this.Ps.leftPriceScale.minimumWidth)),this.dw()&&(s=Math.max(s,l(n.lm()).rv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Lo();i=ds(i),s=ds(s);const n=this.yo,e=this.na,r=Math.max(n-i-s,0),h=1*this.Wm.length,a=this.Ps.timeScale.visible;let o=a?Math.max(this.Jm.Rm(),this.Ps.timeScale.minimumHeight):0;var _;o=(_=o)+_%2;const u=h+o,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Om.length;++t){const n=this.Om[t];n.Wv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Om.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Lo()*d*f)/f,e=Math.max(h,2),p+=e,n.av(ns({width:r,height:e})),this.cw()&&n.tm(i,"left"),this.dw()&&n.tm(s,"right"),n.af()&&this.ss.vc(n.af(),e)}this.Jm.Dm(ns({width:a?r:0,height:o}),a?i:0,a?s:0),this.ss.Eo(r),this.$m!==i&&(this.$m=i),this.Hm!==s&&(this.Hm=s)}Km(t){t?this.Df.addEventListener("wheel",this.Xm,{passive:!1}):this.Df.removeEventListener("wheel",this.Xm)}bw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Gm(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.bw(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.Df.getBoundingClientRect().left;this.ti().Sc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().xc(-80*s)}hw(t,i){const s=t.en();3===s&&this.Mw(),3!==s&&2!==s||(this.yw(t),this.Sw(t,i),this.Jm.Tt(),this.Om.forEach(t=>{t.$v()}),3===this.Nm?.en()&&(this.Nm.mn(t),this.Mw(),this.yw(this.Nm),this.Sw(this.Nm,i),t=this.Nm,this.Nm=null)),this._v(t)}Sw(t,i){for(const s of t.vn())this.wn(s,i)}yw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qo()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Bu();break;case 1:s.Ou(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.xu();break;case 5:t.Ht.Fu(i)||s.fn(t.Ht.Iu(i))}}Qu(t){null!==this.Nm?this.Nm.mn(t):this.Nm=t,this.Um||(this.Um=!0,this.zm=window.requestAnimationFrame(t=>{if(this.Um=!1,this.zm=0,null!==this.Nm){const i=this.Nm;this.Nm=null,this.hw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Fu(t)){this.ti().un(s.Ht);break}}}))}Mw(){this.iw()}ew(t){this.Ym.removeChild(t.Zp()),t.m()}iw(){const t=this.ss.qs(),i=t.length,s=this.Om.length;for(let t=i;t<s;t++){const t=h(this.Om.pop());this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();const i=this.Wm.pop();void 0!==i&&this.ew(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Zv().i(this.xw.bind(this,i),this),i.Jv().i(this.Cw.bind(this,i),this),this.Om.push(i),n>0){const t=new Ms(this,n-1,n);this.Wm.push(t),this.Ym.insertBefore(t.Zp(),this.Jm.Zp())}this.Ym.insertBefore(i.Zp(),this.Jm.Zp())}for(let s=0;s<i;s++){const i=t[s],n=this.Om[s];n.af()!==i?n.Wv(i):n.Ov()}this.sw(),this.gw()}Pw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.At().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti().oc(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,a=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,o=this.Tw(n);return{kw:r,Re:t??void 0,Dw:i??void 0,Rw:-1!==o?o:void 0,Fw:l,Iw:e,Vw:a,Lw:s??void 0}}Tw(t){let i=-1;if(t)i=this.Om.indexOf(t);else{const t=this.ti().dc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}xw(t,i,s,n){this.Cv.p(()=>this.Pw(i,s,n,t))}Cw(t,i,s,n){this.Pv.p(()=>this.Pw(i,s,n,t))}Zm(t,i,s){this.fw(this.ti().oc()?.a_??null),this.Zu.p(()=>this.Pw(t,i,s))}sw(){const t=this.Ps.timeScale.visible?"":"none";this.Jm.Zp().style.display=t}cw(){return this.Om[0].af().No().W().visible}dw(){return this.Om[0].af().Uo().W().visible}Qm(){return"ResizeObserver"in window&&(this.qm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.tw(i.contentRect.width,i.contentRect.height)}),this.qm.observe(this.If,{box:"border-box"}),!0)}rw(){null!==this.qm&&this.qm.disconnect(),this.qm=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Xs(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 Ks(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw:n};return void 0!==s.color&&(r.R=s.color),r}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw: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={Re:i,gt:t,Ht:[e,e,e,e],kw: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={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),e}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function sn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),a=Math.min(...r),o=r[r.length-1],_=[o,l,a,o],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,kw:n,ne:d,R:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Aw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Xs(t)}(n,h)?en({gt:i,Re:s,kw: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(Ks),Line:rn(Ks),Custom:rn(sn)}[t]}function ln(t){return{Re:0,Ew:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Bw:i.key(t[0].gt),Ow:i.key(t[t.length-1].gt)}}function on(t){let i;return t.forEach(t=>{void 0===i&&(i=t.kw)}),h(i)}class _n{constructor(t){this.Ww=new Map,this.zw=new Map,this.$w=new Map,this.Hw=[],this.u_=t}m(){this.Ww.clear(),this.zw.clear(),this.$w.clear(),this.Hw=[]}Nw(t,i){let s=0!==this.Ww.size,n=!1;const e=this.zw.get(t);if(void 0!==e)if(1===this.zw.size)s=!1,n=!0,this.Ww.clear();else for(const i of this.Hw)i.pointData.Ew.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=hn(t.Rr()),l=t.pl(),a=t.vl();r=i.map((i,r)=>{const o=e(i.time),_=this.u_.key(o);let u=this.Ww.get(_);void 0===u&&(u=ln(o),this.Ww.set(_,u),n=!0);const c=h(o,u.Re,i,s[r],l,a);return u.Ew.set(t,c),c})}s&&this.Uw(),this.qw(t,r);let h=-1;if(n){const t=[];this.Ww.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:on(i.Ew)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.jw(t)}return this.Yw(t,h,function(t,i,s){const n=an(t,s),e=an(i,s);if(void 0!==n&&void 0!==e)return{Xw:!1,Oh:n.Ow>=e.Ow&&n.Bw>=e.Bw}}(this.zw.get(t),e,this.u_))}Bc(t){return this.Nw(t,[])}Gw(t,i,s){const n=i;!function(t){void 0===t.kw&&(t.kw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.$w.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ww.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=ln(e),this.Ww.set(this.u_.key(e),h));const a=hn(t.Rr()),o=t.pl(),_=t.vl(),u=a(e,h.Re,i,n.kw,o,_);h.Ew.set(t,u),s?this.Kw(t,u,h.Re):this.Zw(t,u);const c={Oh:nn(u),Xw:s};if(!l)return this.Yw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:on(h.Ew)},p=yt(this.Hw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Hw.splice(p,0,d);for(let t=p;t<this.Hw.length;++t)un(this.Hw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Hw,p),this.Yw(t,p,c)}Jw(t,i){const s=this.zw.get(t);if(void 0===s||i<=0)return[[],this.Qw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.$w.delete(t):this.$w.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ww.get(this.u_.key(i.gt));if(s&&(s.Ew.delete(t),0===s.Ew.size)){this.Ww.delete(this.u_.key(s.Uh)),this.Hw.splice(s.Re,1);for(let t=s.Re;t<this.Hw.length;++t)un(this.Hw[t].pointData,t)}}return[n,this.Yw(t,this.Hw.length-1,{Xw:!1,Oh:!1})]}Zw(t,i){let s=this.zw.get(t);void 0===s&&(s=[],this.zw.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.$w.set(t,i.gt)}Kw(t,i,s){const n=this.zw.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);nn(i)?n[e]=i:n.splice(e,1)}qw(t,i){0!==i.length?(this.zw.set(t,i.filter(nn)),this.$w.set(t,i[i.length-1].gt)):(this.zw.delete(t),this.$w.delete(t))}Uw(){for(const t of this.Hw)0===t.pointData.Ew.size&&this.Ww.delete(this.u_.key(t.time))}jw(t){let i=-1;for(let s=0;s<this.Hw.length&&s<t.length;++s){const n=this.Hw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.Hw.length!==t.length&&(i=Math.min(this.Hw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Hw=t,i}tg(){if(0===this.zw.size)return null;let t=0;return this.zw.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Yw(t,i,s){const n=this.Qw();if(-1!==i)this.zw.forEach((i,e)=>{n.zo.set(e,{ne:i,ig:e===t?s:void 0})}),this.zw.has(t)||n.zo.set(t,{ne:[],ig:s}),n.At.sg=this.Hw,n.At.ng=i;else{const i=this.zw.get(t);n.zo.set(t,{ne:i||[],ig:s})}return n}Qw(){return{zo:new Map,At:{cu:this.tg()}}}}function un(t,i){t.Re=i,t.Ew.forEach(t=>{t.Re=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.qh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);if(!s)return{from:r,to:h};let l=r,a=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(a=h+1),{from:l,to:a}}class fn{constructor(t,i,s){this.eg=!0,this.rg=!0,this.hg=!0,this.lg=[],this.ag=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.eg=!0,"data"===t&&(this.rg=!0),"options"===t&&(this.hg=!0)}Dt(){return this.Qn.It()?(this._g(),null===this.ag?null:this.ug):null}cg(){const t=this.Qn.Fh();this.lg=this.lg.map(i=>{const s=t.Ir(i.gt);return null===s?i:{...i,...s}})}dg(){this.ag=null}_g(){this.rg&&(this.pg(),this.rg=!1),this.hg&&(this.cg(),this.hg=!1),this.eg&&(this.fg(),this.eg=!1)}fg(){const t=this.Qn.$t(),i=this.te.At();if(this.dg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Or())return;const n=this.Qn.Bt();null!==n&&(this.ag=pn(this.lg,s,this.og),this.vg(t,i,n.Ht),this.mg())}}class vn{constructor(t,i){this.wg=t,this.Yi=i}et(t,i,s){this.wg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.ug=new vn(this.eh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re),gg:i.ne}))}vg(t,i){i.du(this.lg,m(this.ag))}mg(){this.eh.update({bars:this.lg.map(wn),barSpacing:this.te.At().gu(),visibleRange:this.ag},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.gg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=a(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function yn(t){const i=Mn(t);return void 0!==t.R&&(i.color=t.R),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.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function Pn(t){const i=Cn(t);return void 0!==t.R&&(i.color=t.R),i}function Tn(t){const i=Cn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function kn(t){return{Area:Sn,Line:yn,Baseline:xn,Histogram:yn,Bar:Pn,Candlestick:Tn,Custom:Dn}[t]}function Dn(t){const i=t.kw;return{...t.ne,time:i}}const Rn={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},Fn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},In={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},Vn={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 An(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:In,crosshair:Rn,grid:Fn,overlayPriceScales:{...Vn},leftPriceScale:{...Vn,visible:!1},rightPriceScale:{...Vn,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 En{constructor(t,i,s){this.Np=t,this.bg=i,this.Mg=s??0}applyOptions(t){this.Np.ti().uc(this.bg,t,this.Mg)}options(){return this.Yi().W()}width(){return j(this.bg)?this.Np.uw(this.bg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Ha(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().ta()){const n=this.Yi().vo(),e=Bi(n);s=ai(s,this.Yi().sa()),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.Np.ti().cc(this.bg,this.Mg)).$t}}class Bn{constructor(t,i,s,n){this.Np=t,this.Pt=s,this.yg=i,this.Sg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Np.ti(),s=i.qc(this.Pt);i.wc(s,t)}getStretchFactor(){return this.Pt.Lo()}setStretchFactor(t){this.Pt.Ao(t),this.Np.ti().Ah()}paneIndex(){return this.Np.ti().qc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Np.qp().length,"Invalid pane index"),this.Np.ti().bc(i,t))}getSeries(){return this.Pt.zo().map(t=>this.yg(t))??[]}getHTMLElement(){const t=this.Np.qp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Zp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.Sg,requestUpdate:()=>this.Pt.ti().Ah()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Io(t))throw new Error(`Cannot find price scale with id: ${t}`);return new En(this.Np,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Oo(t)}preserveEmptyPane(){return this.Pt.Wo()}addCustomSeries(t,i={},s=0){return this.Sg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.Sg.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()}xg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.Cg=new o,this.Qn=t,this.Pg=i,this.Tg=s,this.u_=e,this.Sg=n,this.kg=r}m(){this.Cg.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 Ci(t.from,t.to)).k_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const a={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(a.from=n.kw,a.to=e.kw),a}setData(t){this.u_,this.Qn.Rr(),this.Pg.Dg(this.Qn,t),this.Rg("full")}update(t,i=!1){this.Qn.Rr(),this.Pg.Fg(this.Qn,t,i),this.Rg("update")}pop(t=1){const i=this.Pg.Ig(this.Qn,t);0!==i.length&&this.Rg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Cg.i(t)}unsubscribeDataChanged(t){this.Cg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Tg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.zh(i);return new Wn(s)}removePriceLine(t){this.Qn.$h(t.xg())}priceLines(){return this.Qn.Hh().map(t=>new Wn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.Sg,series:this,requestUpdate:()=>this.Qn.ti().Ah(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Ah()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.kg(i)}moveToPane(t){this.Qn.ti().$c(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.zo().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Rg(t){this.Cg.v()&&this.Cg.p(t)}}class $n{constructor(t,i,s){this.Vg=new o,this.O_=new o,this.Mm=new o,this.ss=t,this.ph=t.At(),this.Jm=i,this.ph.Vu().i(this.Lg.bind(this)),this.ph.Lu().i(this.Ag.bind(this)),this.Jm.km().i(this.Eg.bind(this)),this.u_=s}m(){this.ph.Vu().u(this),this.ph.Lu().u(this),this.Jm.km().u(this),this.Vg.m(),this.O_.m(),this.Mm.m()}scrollPosition(){return this.ph.Mu()}scrollToPosition(t,i){i?this.ph.Ru(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Du()}getVisibleRange(){const t=this.ph.ru();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph.ou(i);this.ss.Wc(s)}getVisibleLogicalRange(){const t=this.ph.eu();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Wc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Bu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.pu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.iu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.pu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Jm.Jp().width}height(){return this.Jm.Jp().height}subscribeVisibleTimeRangeChange(t){this.Vg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Vg._(t)}subscribeVisibleLogicalRangeChange(t){this.O_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.O_._(t)}subscribeSizeChange(t){this.Mm.i(t)}unsubscribeSizeChange(t){this.Mm._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.gu()}}Lg(){this.Vg.v()&&this.Vg.p(this.getVisibleRange())}Ag(){this.O_.v()&&this.O_.p(this.getVisibleLogicalRange())}Eg(t){this.Mm.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.Og=new Map,this.Wg=new o,this.zg=new o,this.$g=new o,this.Yu=new WeakMap,this.Hg=new _n(i);const n=void 0===s?f(An()):_(f(An()),Hn(s));this.Ng=i,this.Np=new js(t,n,i),this.Np.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ug(t()))},this),this.Np.Jv().i(t=>{this.zg.v()&&this.zg.p(this.Ug(t()))},this),this.Np.fc().i(t=>{this.$g.v()&&this.$g.p(this.Ug(t()))},this);const e=this.Np.ti();this.qg=new $n(e,this.Np.nw(),this.Ng)}remove(){this.Np.Zv().u(this),this.Np.Jv().u(this),this.Np.fc().u(this),this.qg.m(),this.Np.m(),this.Bg.clear(),this.Og.clear(),this.Wg.m(),this.zg.m(),this.$g.m(),this.Hg.m()}resize(t,i,s){this.autoSizeActive()||this.Np.tw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},jg:bn,Yg:t}))(a(t));return this.Xg(n,i,s)}addSeries(t,i={},s=0){return this.Xg(t,i,s)}removeSeries(t){const i=h(this.Bg.get(t)),s=this.Hg.Bc(i);this.Np.ti().Bc(i),this.Gg(s),this.Bg.delete(t),this.Og.delete(i)}Dg(t,i){this.Gg(this.Hg.Nw(t,i))}Fg(t,i,s){this.Gg(this.Hg.Gw(t,i,s))}Ig(t,i){const[s,n]=this.Hg.Jw(t,i);return 0!==s.length&&this.Gg(n),s}subscribeClick(t){this.Wg.i(t)}unsubscribeClick(t){this.Wg._(t)}subscribeCrosshairMove(t){this.$g.i(t)}unsubscribeCrosshairMove(t){this.$g._(t)}subscribeDblClick(t){this.zg.i(t)}unsubscribeDblClick(t){this.zg._(t)}priceScale(t,i=0){return new En(this.Np,t,i)}timeScale(){return this.qg}applyOptions(t){this.Np.lr(Hn(t))}options(){return this.Np.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Np.ti().W().crosshair.mode,this.Np.lr({crosshair:{mode:2}})),n=this.Np.ow(t)}finally{i||void 0===s||this.Np.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Np.ti().jc();return i.Oo(t),this.Kg(i)}removePane(t){this.Np.ti().mc(t)}swapPanes(t,i){this.Np.ti().gc(t,i)}autoSizeActive(){return this.Np.pw()}chartElement(){return this.Np.sf()}panes(){return this.Np.ti().qs().map(t=>this.Kg(t))}paneSize(t=0){const i=this.Np.ww(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.Np.ti().Nn(n);null!==e&&this.Np.ti().Fc(t,i,e)}clearCrosshairPosition(){this.Np.ti().Ic(!0)}horzBehaviour(){return this.Ng}Xg(i,s={},n=0){r(void 0!==i.jg),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),h=i.jg,l=new Ut(this.Np.ti(),i.type,e,h,i.Yg);this.Np.ti().Ac(l,n);const a=new zn(l,this,this,this,this.Ng,t=>this.Kg(t));return this.Bg.set(a,l),this.Og.set(l,a),a}Gg(t){const i=this.Np.ti();i.Vc(t.At.cu,t.At.sg,t.At.ng),t.zo.forEach((t,i)=>i.lt(t.ne,t.ig)),i.At().K_(),i.wu()}Zg(t){return h(this.Og.get(t))}Ug(t){const i=new Map;t.Iw.forEach((t,s)=>{const n=s.Rr(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Zg(s),e)});const s=void 0!==t.Fw&&this.Og.has(t.Fw)?this.Zg(t.Fw):void 0;return{time:t.kw,logical:t.Re,point:t.Dw,paneIndex:t.Rw,hoveredSeries:s,hoveredObjectId:t.Vw,seriesData:i,sourceEvent:t.Lw}}Kg(t){let i=this.Yu.get(t);return i||(i=new Bn(this.Np,t=>this.Zg(t),t,this),this.Yu.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._d(i))}function Yn(){return ss}function Xn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Jg: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=Xn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.Jg)}function Kn(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=Xn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.Jg,l=n.logicalToCoordinate(h);return null===l?null:l}class Zn extends fn{constructor(t,i){super(t,i,!0)}vg(t,i,s){i.du(this.lg,m(this.ag)),t.qa(this.lg,s,m(this.ag))}Qg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.tb(i.Re,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:a,verticalPixelRatio:o}=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*a,s.ct*o),l.lineTo(n.ut*a,n.ct*o),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*a,_.ct*o);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*a,d.ct*o);break;case 1:l.lineTo(d.ut*a,i[h-1].ct*o),n!==u&&(e(n,d),l.lineTo(d.ut*a,i[h-1].ct*o)),l.lineTo(d.ut*a,d.ct*o);break;case 2:{const[t,s]=se(i,h-1,h);l.bezierCurveTo(t.ut*a,t.ct*o,s.ut*a,s.ct*o,d.ut*a,d.ct*o);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*a,d.ct*o))}(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,ib:e,sb:r,dt:h,Kt:l,nb:a}=this.ht;if(null===s)return;const o=t.context;o.lineCap="butt",o.lineWidth=h*t.verticalPixelRatio,n(o,l),o.lineJoin="round";const _=this.eb.bind(this);void 0!==r&&Jn(t,i,r,s,e,_,ne),a&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let a=null;const o=Math.max(1,Math.floor(r))%2/2,_=s*h+o;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==a&&(l.beginPath(),null!==a&&l.fill(),l.fillStyle=i,a=i);const s=Math.round(n.ut*r)+o,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,a,s,_)}}class re extends ee{eb(t,i){return i.wt}}class he extends Zn{constructor(){super(...arguments),this.ug=new re}tb(t,i,s){return{...this.Qg(t,i),...s.Fr(t)}}mg(){const t=this.Qn.W(),i={_t:this.lg,Kt:t.lineStyle,sb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,nb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.ag,ib:this.te.At().gu()};this.ug.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},jg:(t,i)=>new he(t,i)};function ae(t,i){return t.weight>i.weight?t:i}function oe(t){return t}class _e{constructor(){this.rb=new o,this.hb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.rb.p(this.lb)),this.lb=0}ab(){return this.rb}m(){this.rb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.hb(),t=>(t>this.lb&&(this.lb=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(ae,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t%120==0?10:t%60==0?9:t%36==0?8:t%12==0?7:t%6==0?6:t%3==0?5:t%1==0?4:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(oe(t[n].time));this.lb=t[t.length-1].time,this.hb()}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{oe:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),_b:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({oe:t,_e:i,_b:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({oe:t,_e:i,_b:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ab().i(n)}}function 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,ib:e,dt:r,Kt:h,sb:l}=this.ht,a=this.ht.ub??(this.ht.cb?0:t.mediaSize.height);if(null===s)return;const o=t.context;o.lineCap="butt",o.lineJoin="round",o.lineWidth=r,n(o,h),o.lineWidth=1,Jn(t,i,l,s,e,this.pb.bind(this),we.bind(null,a))}}class be{fb(t,i){const s=this.mb,{wb:n,gb:e,bb:r,Mb:h,ub:l,yb:a,Sb:o}=i;if(void 0===this.xb||void 0===s||s.wb!==n||s.gb!==e||s.bb!==r||s.Mb!==h||s.ub!==l||s.yb!==a||s.Sb!==o){const{verticalPixelRatio:s}=t,_=l||a>0?s:1,u=a*_,c=o===t.bitmapSize.height?o:o*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.xb=p,this.mb=i}return this.xb}}class Me extends ge{constructor(){super(...arguments),this.Cb=new be}pb(t,i){const s=this.ht;return this.Cb.fb(t,{wb:i.yr,gb:i.Sr,bb:i.Cr,Mb:i.Pr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class ye extends ee{constructor(){super(...arguments),this.Pb=new be}eb(t,i){const s=this.ht;return this.Pb.fb(t,{wb:i.br,gb:i.br,bb:i.Mr,Mb:i.Mr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class Se extends Zn{constructor(t,i){super(t,i),this.ug=new x,this.Tb=new Me,this.kb=new ye,this.ug.nt([this.Tb,this.kb])}tb(t,i,s){return{...this.Qg(t,i),...s.Fr(t)}}mg(){const t=this.Qn.Bt();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.At().gu();if(null===this.ag||0===this.lg.length)return;let e,r;if(i.relativeGradient){e=this.lg[this.ag.from].ct,r=this.lg[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const i=this.lg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Tb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineType,ub:s,yb:e,Sb:r,cb:!1,ot:this.ag,ib:n}),this.kb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineVisible?i.lineType:void 0,nb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,ub:s,yb:e,Sb:r,ot:this.ag,ib: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},jg:(t,i)=>new Se(t,i)};class Ce extends ge{constructor(){super(...arguments),this.Cb=new be}pb(t,i){return this.Cb.fb(t,{wb:i.wr,gb:"",bb:"",Mb:i.gr,yb:this.ht?.yb??0,Sb:t.bitmapSize.height})}}class Pe extends Zn{constructor(t,i){super(t,i),this.ug=new x,this.Db=new Ce,this.Rb=new re,this.ug.nt([this.Db,this.Rb])}tb(t,i,s){return{...this.Qg(t,i),...s.Fr(t)}}mg(){const t=this.Qn.W();if(null===this.ag||0===this.lg.length)return;let i;if(t.relativeGradient){i=this.lg[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const s=this.lg[t];s.ct<i&&(i=s.ct)}}this.Db.lt({sb:t.lineType,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ub:null,yb:i,cb:t.invertFilledArea,ot:this.ag,ib:this.te.At().gu()}),this.Rb.lt({sb:t.lineVisible?t.lineType:void 0,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.ag,ib:this.te.At().gu(),nb: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},jg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0,this.Ib=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Fb=this.Vb(i),this.Fb>=2){Math.max(1,Math.floor(i))%2!=this.Fb%2&&this.Fb--}this.Ib=this.Yt.Lb?Math.min(this.Fb,Math.floor(i)):this.Fb;let n=null;const e=this.Ib<=this.Fb&&this.Yt.gu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ib),a=Math.round(h.ut*i),o=a-l,_=this.Ib,u=o+_-1,c=Math.min(h.Ga,h.Ka),d=Math.max(h.Ga,h.Ka),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Ib);t.fillRect(o,p,_,v);const m=Math.ceil(1.5*this.Fb);if(e){if(this.Yt.Ab){const i=a-m;let n=Math.max(p,Math.round(h.Xa*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,o-i,e-n+1)}const i=a+m;let n=Math.max(p,Math.round(h.Za*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).gu,t)))}}class De extends fn{constructor(t,i){super(t,i,!1)}vg(t,i,s){i.du(this.lg,m(this.ag)),t.Ya(this.lg,s,m(this.ag))}Eb(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Xa:NaN,Ga:NaN,Ka:NaN,Za:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>this.tb(i.Re,i,t))}}class Re extends De{constructor(){super(...arguments),this.ug=new ke}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t)}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Ab:t.openVisible,Lb:t.thinBars,ot:this.ag})}}const Fe={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},jg:(t,i)=>new Re(t,i)};class Ie extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Fb=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.gu,i),this.Fb>=2){Math.floor(i)%2!=this.Fb%2&&this.Fb--}const s=this.Yt.Ks;this.Yt.Bb&&this.Ob(t,s,this.Yt.ot),this.Yt.Mi&&this.dv(t,s,this.Yt.ot);const n=this.Wb(i);(!this.Yt.Mi||this.Fb>2*n)&&this.zb(t,s,this.Yt.ot)}Ob(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.gu*e));l=Math.max(Math.floor(e),Math.min(l,this.Fb));const a=Math.floor(.5*l);let o=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.Xa,s.Za)*r),u=Math.round(Math.max(s.Xa,s.Za)*r),c=Math.round(s.Ga*r),d=Math.round(s.Ka*r);let p=Math.round(e*s.ut)-a;const f=p+l-1;null!==o&&(p=Math.max(o+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),o=f}}Wb(t){let i=Math.floor(1*t);this.Fb<=2*i&&(i=Math.floor(.5*(this.Fb-1)));const s=Math.max(Math.floor(t),i);return this.Fb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}dv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);let a=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 o=Math.round(s.ut*e)-Math.floor(.5*this.Fb);const _=o+this.Fb-1,u=Math.round(Math.min(s.Xa,s.Za)*r),c=Math.round(Math.max(s.Xa,s.Za)*r);if(null!==a&&(o=Math.max(a+1,o),o=Math.min(o,_)),this.Yt.gu*e>2*l)I(n,o,u,_-o+1,c-u+1,l);else{const t=_-o+1;n.fillRect(o,u,t,c-u+1)}a=_}}zb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let a=Math.round(Math.min(s.Xa,s.Za)*r),o=Math.round(Math.max(s.Xa,s.Za)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Fb),u=_+this.Fb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,a+=l,u-=l,o-=l),a>o||n.fillRect(_,a,u-_+1,o-a+1)}}}class Ve extends De{constructor(){super(...arguments),this.ug=new Ie}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t)}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Bb:t.wickVisible,Mi:t.borderVisible,ot:this.ag})}}const Le={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},jg:(t,i)=>new Ve(t,i)};class Ae extends C{constructor(){super(...arguments),this.Yt=null,this.$b=[]}lt(t){this.Yt=t,this.$b=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.$b.length||this.Hb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Nb*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.$b[i-this.Yt.ot.from],a=Math.round(h.ct*s);let o,_;t.fillStyle=h.dr,a<=e?(o=a,_=r):(o=e,_=a-Math.floor(n/2)+n),t.fillRect(l.qh,o,l.yi-l.qh+1,_-o)}}Hb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.$b=[]);const i=Math.ceil(this.Yt.gu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.gu*t)-i;this.$b=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.$b[i-this.Yt.ot.from]={qh:r,yi:h,Ub: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.$b[t-this.Yt.ot.from],n=this.$b[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.Ub>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.gu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.Ub>i.ee?i.yi-=1:i.qh+=1)}}}class Ee extends Zn{constructor(){super(...arguments),this.ug=new Ae}tb(t,i,s){return{...this.Qg(t,i),...s.Fr(t)}}mg(){const t={_t:this.lg,gu:this.te.At().gu(),ot:this.ag,Nb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this.ug.lt(t)}}const Be={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},jg:(t,i)=>new Ee(t,i)};class Oe{constructor(t,i){this.Pt=t,this.qb=i,this.jb()}detach(){this.Pt.detachPrimitive(this.qb)}getPane(){return this.Pt}applyOptions(t){this.qb.lr?.(t)}jb(){this.Pt.attachPrimitive(this.qb)}}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.Yb=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.Xb(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.Gb),i.restore(),e+=t.lineHeight*t.Pu}})}Xb(t,i){const s=this.Kb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Kb(t){let i=this.Yb.get(t);return void 0===i&&(i=new Map,this.Yb.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,Gb:0,Pu: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.Zb=[new He(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Zb}attached({requestUpdate:t}){this.Jb=t}detached(){this.Jb=void 0}lr(t){this.Ps=je({...this.Ps,...t}),this.Jb&&this.Jb()}}function Xe(t,i){return new Oe(t,new Ye(i))}const Ge={alpha:1,padding:0};class Ke{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Qb(this.Yt,t.mediaSize);s&&this.Yt.tM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.tM,s.ut,s.ct,s.ts,s.qt))})}Qb(t,i){const{maxHeight:s,maxWidth:n,iM:e,sM:r,padding:h}=t,l=Math.round(i.width/2),a=Math.round(i.height/2),o=h??0;let _=i.width-2*o,u=i.height-2*o;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:a-.5*v,qt:v,ts:f}}}class Ze{constructor(t){this.nM=null,this.eM=0,this.rM=0,this.Ps=t,this.M=Je(this.Ps,this.nM,this.eM,this.rM)}hM(t){void 0!==t.lM&&(this.eM=t.lM),void 0!==t.aM&&(this.rM=t.aM),void 0!==t.oM&&(this.nM=t.oM),this.Tt()}_M(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Je(this.Ps,this.nM,this.eM,this.rM)}renderer(){return new Ke(this.M)}}function Je(t,i,s,n){return{...t,tM:i,sM:s,iM:n}}function Qe(t){return{...Ge,...t}}class tr{constructor(t,i){this.uM=null,this.cM=t,this.Ps=Qe(i),this.Zb=[new Ze(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt())}paneViews(){return this.Zb}attached(t){const{requestUpdate:i}=t;this.dM=i,this.uM=new Image,this.uM.onload=()=>{const t=this.uM?.naturalHeight??1,i=this.uM?.naturalWidth??1;this.Zb.forEach(s=>s.hM({aM:t,lM:i,oM:this.uM})),this.dM&&this.dM()},this.uM.src=this.cM}detached(){this.dM=void 0,this.uM=null}lr(t){this.Ps=Qe({...this.Ps,...t}),this.pM(),this.Jb&&this.Jb()}Jb(){this.dM&&this.dM()}pM(){this.Zb.forEach(t=>t._M(this.Ps))}}function ir(t,i,s){return new Oe(t,new tr(i,s))}class sr{constructor(t,i){this.Qn=t,this._h=i,this.jb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}jb(){this.Qn.attachPrimitive(this._h)}}const nr={autoScale:!0,zOrder:"normal"};function er(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function rr(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":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 ar(t,i,s){return i?t:s?Math.ceil(t/2):0}function or(t,i,s,n){const e=(rr("arrowUp",n)-1)/2*s.fM,r=(Kt(n/2)-1)/2*s.fM;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=(Kt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&r>=(t?s:s-h)-2&&r<=(t?s+h:s)+2)return!0;return(()=>{if(e<i-h-3||e>i+h+3||r<(t?s-h-3:s)||r>(t?s:s+h+3))return!1;const n=Math.abs(e-i);return Math.abs(r-s)+3>=n/2})()}function ur(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,a=s+l*n,o=a-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),o),t.quadraticCurveTo(i,a,i+(r?h:-h),o),t.lineTo(i-_,s)}function cr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class dr{constructor(){this.Yt=null,this.Wn=new it,this.vM=new it,this.$=-1,this.H="",this.Nf="",this.mM="",this.wM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Nf=g(t,i),this.mM=g(t,i,"600"),this.Wn.Vn(),this.vM.Vn()),this.wM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&fr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.gM;if(t.font=r?this.mM:this.Nf,void 0!==e.hi){const i=r?this.vM:this.Wn;e.hi.ts=i.Ii(t,e.hi.bM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.gM){const t=void 0!==e.hi?e.hi.ts:0;e.gM.ts=Math.max(t+2*e.gM.MM,e.gM.qt),e.gM.qh=e.ut-e.gM.ts/2}pr(e,t,i,s)}}}}function pr(t,i,s,n){void 0===t.gM?(i.fillStyle=t.R,void 0!==t.hi&&cr(i,t.hi.bM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Or)return;switch(t.yM){case"arrowDown":return void or(!1,i,s,t.Or);case"arrowUp":return void or(!0,i,s,t.Or);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.fM,0,2*Math.PI,!1),t.fill()}(i,s,t.Or);case"square":return void function(t,i,s){const n=rr("square",s),e=(n-1)*i.fM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.fM,n*i.fM)}(i,s,t.Or);case"tag":return}t.yM}(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,fM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Or)return;(function(t,i){const s=i.SM,n=i.xM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.CM-i.qt/2)*n),l=Math.round((i.CM+i.qt/2)*n),a=Math.round(i.ut*s),o=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.PM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-o)),c="none"!==i.TM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+o,h),"up"===i.TM&&ur(t,a,h,_,u,!0),t.lineTo(r-o,h),t.arcTo(r,h,r,h+o,o),t.lineTo(r,l-o),t.arcTo(r,l,r-o,l,o),"down"===i.TM&&ur(t,a,l,_,u,!1),t.lineTo(e+o,l),t.arcTo(e,l,e,l-o,o),t.lineTo(e,h+o),t.arcTo(e,h,e+o,h,o)):L(t,e,h,r-e,l-h,[o,o,o,o]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,CM:t.ct,ts:i.ts,qt:i.qt,PM:i.PM,TM:i.TM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,SM:n,xM:e}),void 0!==t.hi&&(s.fillStyle=t.kM??"#FFFFFF",cr(s,t.hi.bM,t.hi.ut,t.hi.ct,n,e))}(t,t.gM,i,s,n)}function fr(t,i,s){return void 0!==t.gM?0!==t.Or&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.TM?i-r-s.PM:i-r,l="down"===s.TM?i+r+s.PM:i+r,a=t-s.ts/2;return n>=a&&n<=a+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.gM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Or)return!1;switch(t.yM){case"arrowDown":return _r(!0,t.ut,t.ct,t.Or,i,s);case"arrowUp":return _r(!1,t.ut,t.ct,t.Or,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.Or,i,s);case"square":return function(t,i,s,n,e){const r=rr("square",s),h=(r-1)/2,l=t-h,a=i-h;return n>=l&&n<=l+r&&e>=a&&e<=a+r}(t.ut,t.ct,t.Or,i,s);case"tag":return!1}}(t,i,s)}function vr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function mr(t,i,s,n,e,r,h,a,o){const _=function(t,i,s){if(vr(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,o);if(void 0===_)return;const c=vr(i.position),d=a.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),a=Math.round(7*h),o=vr(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(o?0:n.DM)-a-_,o||(n.DM+=l+a+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(o?0:n.RM)+a+_,o||(n.RM+=l+a+r)}const d={qt:l,PM:a,TM:u,vt:i.borderRadius??6,MM:9*h,qh:0,ts:0};t.Or=l,t.ct=c,t.gM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=hr(d.options().barSpacing)*p,v=f/2;t.Or=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.DM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.DM+=1.2*e),void(c||(n.DM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}}}class wr{constructor(t,i,s){this.FM=[],this.xt=!0,this.IM=!0,this.Jt=new dr,this.be=t,this.Vf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.VM();const t=this.Vf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}LM(t){this.FM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.IM=!0)}AM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}VM(){const t=this.Vf.timeScale(),i=this.FM;this.IM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Or:0,yM:t.shape,R:t.color,Gn:t.id,EM:t.EM,hi:void 0,kM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,gM:void 0})),this.IM=!1);const s=this.Vf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const a=lr(t.options().barSpacing),o={DM:a,RM:a};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.DM=a,o.RM=a,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={bM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&mr(_,e,u,o,s.fontSize,a,this.be,this.Vf,r)}this.xt=!1}}function gr(t){return{...nr,...t}}class br{constructor(t){this.eh=null,this.FM=[],this.BM=[],this.OM=null,this.be=null,this.Vf=null,this.WM=!0,this.zM=null,this.$M=null,this.HM=null,this.NM=!0,this.Ps=gr(t)}attached(t){this.UM(),this.Vf=t.chart,this.be=t.series,this.eh=new wr(this.be,l(this.Vf),this.Ps),this.dM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Rg(t)),this.NM=!0,this.Jb()}Jb(){this.dM&&this.dM()}detached(){this.be&&this.OM&&this.be.unsubscribeDataChanged(this.OM),this.Vf=null,this.be=null,this.eh=null,this.OM=null}LM(t){this.NM=!0,this.FM=t,this.UM(),this.WM=!0,this.$M=null,this.Jb()}qM(){return this.FM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.jM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.YM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=gr({...this.Ps,...t}),this.Jb&&this.Jb()}YM(){const t=l(this.Vf).timeScale().options().barSpacing;if(this.WM||t!==this.HM){if(this.HM=t,this.FM.length>0){const i=lr(t),s=1.5*hr(t)+2*i,n=this.XM();this.zM={above:ar(s,n.aboveBar,n.inBar),below:ar(s,n.belowBar,n.inBar)}}else this.zM=null;this.WM=!1}return this.zM}XM(){return null===this.$M&&(this.$M=this.FM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.$M}UM(){if(!this.NM||!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.BM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.BM=this.FM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),a={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,EM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,kw: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{...a,position:i.position,price:i.price}}return{...a,position:i.position,price:i.price}}),this.NM=!1}jM(t){this.eh&&(this.UM(),this.eh.LM(this.BM),this.eh.AM(this.Ps),this.eh.Tt(t))}Rg(t){this.NM=!0,this.Jb()}}class Mr extends sr{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.LM(t)}markers(){return this._h.qM()}}function yr(t,i,s){const n=new Mr(t,new br(s??{}));return i&&n.setMarkers(i),n}class Sr{constructor(t){this.FM=new Map,this.GM=t}KM(t,i,s){if(this.ZM(i),void 0!==s){const n=window.setTimeout(()=>{this.FM.delete(i),this.JM()},s),e={...t,QM:n,ty:Date.now()+s};this.FM.set(i,e)}else this.FM.set(i,{...t,QM:void 0,ty:void 0});this.JM()}ZM(t){const i=this.FM.get(t);i&&void 0!==i.QM&&window.clearTimeout(i.QM),this.FM.delete(t),this.JM()}iy(){for(const[t]of this.FM)this.ZM(t)}sy(){const t=Date.now(),i=[];for(const[s,n]of this.FM)!n.ty||n.ty>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.ZM(s);return i}ny(t){this.GM=t}JM(){this.GM&&this.GM()}}const xr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Cr{constructor(t,i,s,n){this.Yt=t,this.ey=i,this.hy=s,this.ly=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.oy(e._y);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e._y&&(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._y)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e._y-7*e._y*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e._y)*t.verticalPixelRatio),i.stroke())})})}oy(t){return 0===t?this.ey:t>0?this.ly:this.hy}}class Pr{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,_y: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 Cr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Tr(t,i){return"Line"===i||"Area"===i}class kr{constructor(t){this.Vf=void 0,this.be=void 0,this.Zb=[],this.u_=null,this.uy=new Map,this.py=new Sr(()=>this.Jb()),this.Ps={...xr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Jb()}LM(t){this.py.iy();const i=this.u_;i&&t.forEach(t=>{this.py.KM(t,i.key(t.time))})}qM(){return this.py.sy()}Jb(){this.dM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Vf=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Zb=[new Pr(this.be,this.Vf.timeScale(),this.Ps)],this.dM=n,this.Jb()}detached(){this.Vf=void 0,this.be=void 0,this.dM=void 0}Yf(){return h(this.Vf)}zo(){return h(this.be)}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.qM()))}paneViews(){return this.Zb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.uy.clear();const s=this.u_;s&&t.forEach(t=>{Gs(t)&&Tr(0,i)&&this.uy.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Xs(t)&&this.uy.delete(n),Gs(t)&&Tr(0,s)){const i=this.uy.get(n);i&&this.py.KM({time:t.time,value:t.value,sign:Dr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}vy(){this.py.iy()}}function Dr(t,i){return t===i?0:t-i>0?1:-1}class Rr extends sr{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.qM()}setMarkers(t){return this._h.LM(t)}clearMarkers(){return this._h.vy()}}function Fr(t,i={}){return new Rr(t,new kr(i))}class Ir{constructor(t,i){this.my=null,this.wy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.my=yr(t)}addPosition(t){this.wy.push(t),this.gy()}addPositions(t){this.wy.push(...t),this.gy()}setPositions(t){this.wy=[...t],this.gy()}closePosition(t,i,s){const n=this.wy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.gy())}removePosition(t){this.wy=this.wy.filter(i=>i.id!==t),this.gy()}clearPositions(){this.wy=[],this.gy()}getPositions(){return this.wy}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.gy()}by(){const t=[];for(const i of this.wy){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}gy(){if(this.my){const t=this.by();this.my.setMarkers(t)}}detach(){this.my&&(this.my.detach(),this.my=null),this.wy=[]}}function Vr(t,i,s){const n=new Ir(t,s);return i&&i.length>0&&n.setPositions(i),n}const Lr=new WeakMap;function Ar(t){return"string"==typeof t?t:String(t)}function Er(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Ar(t.time),t.volume);Lr.set(t,s)}function Br(t,i){return Lr.get(t)?.get(Ar(i))}function Or(t){const i=Lr.get(t);return void 0!==i&&i.size>0}const Wr="rgba(0, 0, 0, 0)";function zr(t){switch(t.seriesType()){case"Candlestick":return $r(t,{upColor:Wr,downColor:Wr,borderVisible:!1,wickVisible:!1});case"Bar":return $r(t,{upColor:Wr,downColor:Wr});case"Line":return $r(t,{color:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return $r(t,{lineColor:Wr,topColor:Wr,bottomColor:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return $r(t,{topLineColor:Wr,topFillColor1:Wr,topFillColor2:Wr,bottomLineColor:Wr,bottomFillColor1:Wr,bottomFillColor2:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return $r(t,{color:Wr});default:return $r(t,{visible:!1})}}function $r(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 Hr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Nr(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 Ur(t,i="close"){const s=[];for(const n of t)if(null!=n)if("close"in n)switch(i){case"open":s.push(n.open);break;case"high":s.push(n.high);break;case"low":s.push(n.low);break;case"hl2":s.push((n.high+n.low)/2);break;case"hlc3":s.push((n.high+n.low+n.close)/3);break;case"ohlc4":s.push((n.open+n.high+n.low+n.close)/4);break;default:s.push(n.close)}else s.push("value"in n?n.value:0);else s.push(0);return s}function qr(t,i){let s=[];return n=>{for(const i of s)try{t.removePriceLine(i)}catch(t){}s=n.filter(t=>null!=t).map(s=>{const n={price:s,color:i,lineWidth:1,lineStyle:2,axisLabelVisible:!1,title:""};return t.createPriceLine(n)})}}function jr(t){return null==t?void 0:t.time}function Yr(t){const{r_:i,Yf:s,My:n,yy:e,Sy:r,Jl:h}=t,l=t.xy??[];let a=t.W,o=[],_=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=jr(s[s.length-1])===jr(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===o.length)o=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;o.length>0&&jr(o[o.length-1])===jr(t)?o[o.length-1]=t:o.push(t)}if(0===o.length)return;const s=e(o,a);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&o.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(a),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=a;a={...a,...t},void 0!==r&&r(a),l.some(t=>i[t]!==a[t])&&(_=new Map,d("full"))},options:()=>({...a}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,o=[]}},recalculate:()=>d("full")};return f}function Xr(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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"SMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy: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??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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"EMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Sy: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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"WMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function Zr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Bollinger Bands",W:n,xy:["period","stdDev"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Cy:[],Py:[],Ty:[]};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 a=0;for(let t=0;t<i;t++)a+=n[l-t];const o=a/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-o,2);const u=Math.sqrt(_/i),c=o+u*s,d=o-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:o}),h.push({time:i,value:d})}}return{Cy:e,Py:r,Ty:h}})(t,i.period??20,i.stdDev??2);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function Jr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Keltner Channels",W:n,xy:["period","atrPeriod","multiplier","source"],yy:(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{Cy:[],Py:[],Ty:[]};const r=Ur(t,i.source??"close"),h=[],l=2/(s+1);let a=0;for(let t=0;t<s;t++)a+=r[t];h.push(a/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const o=[];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?o.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):o.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=o[t];_[n-1]=u/n;for(let t=n;t<o.length;t++)_[t]=(_[t-1]*(n-1)+o[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 a=h[i],o=l*e;d.push({time:r.time,value:a}),c.push({time:r.time,value:a+o}),p.push({time:r.time,value:a-o})}return{Cy:c,Py:d,Ty:p}})(t,i);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function Qr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Donchian Channels",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{Cy:[],Py:[],Ty:[]};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 a=t[r];void 0!==a.time&&h!==-1/0&&l!==1/0&&(s.push({time:a.time,value:h}),e.push({time:a.time,value:l}),n.push({time:a.time,value:(h+l)/2}))}return{Cy:s,Py:n,Ty:e}})(t,i.period??20);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function th(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 a=h.close>=r.close,o=a?r.low:r.high,_=a?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&&(o+=u*(_-o),a?(o=Math.min(o,c.low,t[r-2]?t[r-2].low:c.low),h.low<o?(a=!1,o=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(o=Math.max(o,c.high,t[r-2]?t[r-2].high:c.high),h.high>o?(a=!0,o=_,_=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=o,t.color=a?n:e,l.push(t)}}return l},h=Yr({r_:t,Yf:i,My:[e],Jl:"Parabolic SAR",W:n,xy:["step","maxStep","colorUp","colorDown"],yy:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}}function ih(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.ky,i.Dy-1,i.Ry))}}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 sh(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"VWAP",W:n,xy:["anchorPeriod","bandMultiplier"],yy:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Or(t))return{Fy:e,Cy:r,Ty:h};let l=null,a=0,o=0,_=0;for(const u of i){const i=ih(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,a=0,o=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=Br(t,u.time)??0;if(a+=d,o+=c*d,_+=c*c*d,0===a)continue;const p=o/a;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/a-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{Fy:e,Cy:r,Ty:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.Fy],[h,n.Cy],[l,n.Ty]]},Sy: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,...a}}function nh(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 a=[];let o=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?(o=f<o||l.close>o?f:o,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>o&&(u=!0)):(o=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:o,m.color=u?n:e,a.push(m)}return a},h=Yr({r_:t,Yf:i,My:[e],Jl:"SuperTrend",xy:["period","multiplier","colorUp","colorDown"],W:n,yy:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}}class eh{constructor(t,i,s,n){this.Vf=t,this.be=i,this.I_=s,this.Iy=n}draw(t){const i=this.Iy();if(!i.It||i.Vy<=0)return;const s=this.I_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Vf.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],a=e.timeToCoordinate(h.gt),o=e.timeToCoordinate(l.gt);if(null===a||null===o)continue;const _=this.be.priceToCoordinate(h.Ly),u=this.be.priceToCoordinate(h.Ay),c=this.be.priceToCoordinate(l.Ly),d=this.be.priceToCoordinate(l.Ay);if(null===_||null===u||null===c||null===d)continue;const p=h.Ly>=h.Ay;n.fillStyle=this.Ey(p?i.By:i.Oy,i.Vy),n.beginPath(),n.moveTo(a*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class rh{constructor(t,i,s,n){this.Jt=new eh(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function hh(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 lh(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),a=r(n.colorSpanA),o=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new rh(i,t,()=>u,()=>({By:c.cloudBullishColor??"#089981",Oy:c.cloudBearishColor??"#F23645",Vy:c.cloudOpacity??.15,It: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=[],a=[],o=[],_=[],u=[];if(!t||t.length<e)return{Wy:h,rh:l,Ly:a,Ay:o,zy:_,$y: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 a=(i.get(l)??0)+1;i.set(l,a),a>n&&(n=a,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 a=t[i];if(void 0===a.time)continue;const o=hh(t,i,s),u=hh(t,i,n);null!==o&&h.push({time:a.time,value:o}),null!==u&&l.push({time:a.time,value:u}),null!==o&&null!==u&&p.set(i+r,(o+u)/2);const c=hh(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 a?a.close:a.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&&a.push({time:i,value:s}),void 0!==n&&o.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Ly:s,Ay:n};u.push(t)}}return{Wy:h,rh:l,Ly:a,Ay:o,zy:_,$y:u}},v=Yr({r_:t,Yf:i,My:[h,l,a,o,_],Jl:"Ichimoku",W:n,xy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],yy:(t,i)=>{c=i;const s=f(t,i);return u=s.$y,[[h,s.Wy],[l,s.rh],[a,s.Ly],[o,s.Ay],[_,i.showLagging??1?s.zy:[]]]},Sy:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),a.applyOptions({color:t.colorSpanA,lineWidth:s}),o.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:a,spanB:o,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}}function ah(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)],a=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],o=Yr({r_:t,Yf:i,My:[h,...l,...a],Jl:"Pivot Points",W:n,xy:["pivotPeriod"],yy:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{Hy:s,Ny:n,Uy:e};let r=null,h=-1/0,l=1/0,a=0,o=null;for(const _ of t){const t=ih(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+a)/3,s=h-l;o={qy:i,jy:[2*i-l,i+s,h+2*(i-l)],Yy:[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),a="close"in _?_.close:_.value,null!==o&&void 0!==_.time){s.push({time:_.time,value:o.qy});for(let t=0;t<3;t++)n[t].push({time:_.time,value:o.jy[t]}),e[t].push({time:_.time,value:o.Yy[t]})}}return{Hy:s,Ny:n,Uy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.Hy]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Ny[t]:[]]),e.push([a[t],t<n?s.Uy[t]:[]]);return e},Sy: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}),a[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:a,...o}}function oh(t){return null!=t&&"number"==typeof t.close}function _h(t){const i=[];let s=null,n=null;for(const e of t){if(!oh(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 uh(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=zr(t):i||null===h||(h(),h=null)},a=Yr({r_:t,Yf:i,My:[r],Jl:"Heikin Ashi",W:n,xy:[],yy:t=>[[r,_h(t)]],Sy: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{zo:r,options:a.options,applyOptions:a.applyOptions,recalculate:a.recalculate,remove:()=>{a.remove();try{l(!1)}catch(t){}}}}function ch(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:Hr(0,100)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=qr(r,n.levelColor),a=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Ur(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 a=0===l?100:h/l,o=100-100/(1+a);t[i]&&t[i].time&&e.push({time:t[i].time,value:o});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,a=0===l?100:h/l,o=100-100/(1+a),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:o})}return e},o=Yr({r_:t,Yf:i,My:[r],Jl:"RSI",W:n,xy:["period","source"],yy:(t,i)=>[[r,a(t,i.period??14,i.source??"close")]],Sy: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,...o}}function dh(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(Be,{color:n.colorHistogramUp},e),a=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},o=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"MACD",W:n,xy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],yy:(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{Xy:[],Gy:[],Ky:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=a(r,s),l=a(r,n),o=[],_=n-s;for(let t=0;t<l.length;t++)o.push(h[t+_]-l[t]);const u=a(o,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=o[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Xy:c,Gy:d,Ky:p}})(t,i);return[[r,s.Xy],[h,s.Gy],[l,s.Ky]]},Sy: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,...o}}function ph(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=Hr(0,100),h=i.addSeries(le,{color:n.colorK,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorD,autoscaleInfoProvider:r},e),a=Nr(i,h,e);i.priceScale(h.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const o=qr(h,n.levelColor),_=Yr({r_:t,Yf:i,My:[h,l],Jl:"Stochastic",W:n,xy:["kPeriod","dPeriod"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Zy:[],Jy:[]};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,a=i-1+e;t[a]&&t[a].time&&r.push({time:t[a].time,value:l})}return{Zy:e,Jy:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Zy],[l,s.Jy]]},Sy: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}),o([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:l,..._}}function fh(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=Yr({r_:t,Yf:i,My:[e],Jl:"ATR",W:n,xy:["period"],yy:(t,i)=>[[e,r(t,i.period??14)]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function vh(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Be,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Nr(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||!Or(t))return[];const e=[];for(const r of n){const n=Br(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},a=Yr({r_:t,Yf:i,My:[r],Jl:"Volume",W:n,xy:["colorUp","colorDown"],yy:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...a}}function mh(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||!Or(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=Br(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=Yr({r_:t,Yf:i,My:[e],Jl:"OBV",W:n,yy:()=>[[e,r()]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function wh(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=Hr(0,100),h=i.addSeries(le,{color:n.colorADX,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorPlusDI,autoscaleInfoProvider:r},e),a=i.addSeries(le,{color:n.colorMinusDI,autoscaleInfoProvider:r},e),o=Nr(i,h,e);i.priceScale(h.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=qr(h,n.levelColor),u=Yr({r_:t,Yf:i,My:[h,l,a],Jl:"ADX",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Qy:[],tS:[],iS:[]};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,a=h.low-r.low;n.push(l>a&&l>0?l:0),e.push(a>l&&a>0?a: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 a=[],o=[],_=[],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(o.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;a.push({time:m.time,value:t/i})}else if(u.length>i){const t=a[a.length-1].value;a.push({time:m.time,value:(t*(i-1)+v)/i})}}return{Qy:a,tS:o,iS:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Qy],[l,n?s.tS:[]],[a,n?s.iS:[]]]},Sy: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}),a.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:l,minusDI:a,...u}}function gh(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=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(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 a=l/i,o=0===a?0:(s[e]-h)/(.015*a);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:o})}return n},o=Yr({r_:t,Yf:i,My:[r],Jl:"CCI",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??20)]],Sy: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,...o}}function bh(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:Hr(-100,0)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(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,a=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:a})}return s},o=Yr({r_:t,Yf:i,My:[r],Jl:"Williams %R",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??14)]],Sy: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,...o}}function Mh(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:Hr(0,100)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(i,s)=>{if(!i||i.length<s+1||!Or(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,a=(h.high+h.low+h.close)/3,o=l*(Br(t,r.time)??0);n.push(l>a?o:0),e.push(l<a?o: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 a=0===l?100:100-100/(1+h/l),o=i[t+1];o&&void 0!==o.time&&r.push({time:o.time,value:a})}return r},o=Yr({r_:t,Yf:i,My:[r],Jl:"MFI",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??14)]],Sy: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,...o}}class yh{constructor(t){this.sS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.sS.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.nS(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}nS(t,i,s,n){const e=i.eS||i.startTime,r=i.rS||i.endTime,h=i.R||i.color,l=i.Vy||i.opacity;if(!i||!e||!r)return;const a=this.sS.getChart().timeScale(),o=a.timeToCoordinate(e),_=a.timeToCoordinate(r);if(null===o||null===_)return;const u=o*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this.hS(h,l),t.fillRect(u,d,c-u,p-d)}hS(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Sh{constructor(t){this.Jt=new yh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const xh=[{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 Ch{constructor(t,i,s={}){this.lS=[],this.qb=null,this.eh=null,this.Vf=t,this.be=i,this.Ps={sessions:s.sessions||xh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.aS(),this.Ps.enabled&&this.oS()}aS(){this.eh=new Sh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}oS(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this._S()}),this._S()}_S(){this.uS();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.cS(s),this.dM()}cS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.dS(i,t);this.Ps.showOverlaps&&this.pS(t)}}dS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.fS(i);this.vS(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.mS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.mS(s,n[n.length-1].time,t)}pS(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.wS(e,r);h&&this.gS(h,t)}}wS(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{oe:s,_e:n}:null}gS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.fS(i);r>=t.oe&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.bS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.bS(s,n[n.length-1].time)}mS(t,i,s){if(!t||!i)return void console.warn("Invalid session box times:",{startTime:t,endTime:i,session:s.name});const n={an:"session",eS:t,rS:i,R:s.color,Vy:s.opacity,MS:s.name};this.lS.push(n)}bS(t,i){const s={an:"overlap",eS:t,rS:i,R:this.Ps.overlapColor,Vy:this.Ps.overlapOpacity,MS:"Overlap"};this.lS.push(s)}vS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}fS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}uS(){this.lS=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this._S():this.uS(),this.dM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this._S(),this.dM()}disable(){this.Ps.enabled=!1,this.uS(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.uS(),this.dM()}getSessionBoxes(){return this.lS}getChart(){return this.Vf}getSeries(){return this.be}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Ph(t,i,s){return new Ch(t,i,s)}class Th{constructor(t){this.sS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.sS.getProfileData();if(!s||0===s.bins.length)return;const n=this.sS.options(),e=this.sS.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let a=0;for(const t of s.bins)t.volume>a&&(a=t.volume);if(0!==a){for(const r of s.bins)this.yS(i,r,l,h,a,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.SS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.xS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}yS(t,i,s,n,e,r,h,l,a,o){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*a,v=Math.min(c,d)*o,m=_*a,w=p*o,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.hS(M,y),t.fillRect(f,v,m,w)}SS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const a=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,a),t.lineTo(e*r,a),t.stroke(),t.setLineDash([])}xS(t,i,s,n,e,r,h,l){const a=e.priceToCoordinate(i);if(null!==a){const i=a*l;t.strokeStyle=this.hS(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 o=e.priceToCoordinate(s);if(null!==o){const i=o*l;t.strokeStyle=this.hS(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([])}hS(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class kh{constructor(t){this.Jt=new Th(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Dh{constructor(t,i,s={}){this.CS=null,this.PS=new Map,this.qb=null,this.eh=null,this.Vf=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.aS(),this.oS()}aS(){this.eh=new kh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}oS(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.TS()}),this.TS()}setVolumeData(t){this.PS=t,this.TS()}addVolumeData(t,i){this.PS.set(t,i),this.TS()}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);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.PS.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 a=h[0];for(const t of h)t.volume>a.volume&&(a=t);const o=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<o))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.CS={bins:h,binSize:r,poc:a.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.dM()}getProfileData(){return this.CS}applyOptions(t){this.Ps={...this.Ps,...t},this.TS(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.CS=null,this.PS.clear(),this.dM()}getChart(){return this.Vf}getSeries(){return this.be}options(){return this.Ps}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Rh(t,i,s){return new Dh(t,i,s)}function Fh(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.kS=new Map,this.DS=null,this.RS=null,this.FS=null,this.IS=null,this.VS=null,this.LS=null,this.AS=0,this.ES=null,this.Mg=void 0,this.Vf=t,this.Df=i,this.BS=t=>this.OS(t),this.WS=t=>this.zS(t),this.$S=t=>this.HS(t),this.NS=t=>this.US(t),this.qS=()=>this.jS(),this.YS=t=>{"Escape"===t.key&&this.jS()},this.Vf.subscribeCrosshairMove(this.BS),this.Df.addEventListener("pointerdown",this.WS),this.Df.addEventListener("pointermove",this.$S),this.Df.addEventListener("pointerup",this.NS),this.Df.addEventListener("pointercancel",this.qS),document.addEventListener("keydown",this.YS)}XS(t){this.kS.set(t.id(),t)}GS(t){const i=t.id();this.DS===i&&this.KS(null),this.FS===t&&this.jS(),this.kS.delete(i)}Gi(){return 0===this.kS.size}m(){this.Vf.unsubscribeCrosshairMove(this.BS),this.Df.removeEventListener("pointerdown",this.WS),this.Df.removeEventListener("pointermove",this.$S),this.Df.removeEventListener("pointerup",this.NS),this.Df.removeEventListener("pointercancel",this.qS),document.removeEventListener("keydown",this.YS),this.kS.clear()}OS(t){if(this.ES=t.point?{ut:t.point.x,ct:t.point.y}:null,this.Mg=t.paneIndex,null!==this.FS)return;const i=this.ZS(t.hoveredObjectId),s=null===i?null:this.kS.get(i.gl)??null;this.KS(s?s.id():null),this.JS(s,null===s?null:i?.QS??null),this.tx()}zS(t){const i=null===this.DS?null:this.kS.get(this.DS)??null;i&&(this.VS={ut:t.clientX,ct:t.clientY},this.LS=i,i.isDraggable()&&(this.FS=i,this.IS=t.pointerId,this.Df.setPointerCapture(t.pointerId),i.beginDrag(),this.AS=this.ix(i,t),this.tx(),t.preventDefault(),t.stopPropagation()))}HS(t){if(null===this.FS)return;if(!this.sx(t))return void this.jS();const i=this.nx(t);null!==i&&this.FS.dragTo(i),t.preventDefault(),t.stopPropagation()}US(t){const i=this.FS,s=this.LS,n=this.VS;this.hx(),this.LS=null,this.VS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.FS=null,this.AS=0,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.tx();null!==s&&!e&&s.isClickable()&&s.click()}jS(){if(null===this.FS)return;const t=this.FS;this.FS=null,this.AS=0,this.hx(),t.cancelDrag(),this.tx()}sx(t){const i=this.Df.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}hx(){null!==this.IS&&(this.Df.hasPointerCapture(this.IS)&&this.Df.releasePointerCapture(this.IS),this.IS=null)}nx(t){const i=this.FS;if(null===i)return null;const s=this.lx(i,t);return null===s?null:i.priceAt(s-this.AS)}lx(t,i){const s=this.Vf.panes()[t.paneIndex()],n=s?s.getHTMLElement():null;return n?i.clientY-n.getBoundingClientRect().top:null!==this.ES&&this.Mg===t.paneIndex()?this.ES.ct:null}ix(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.lx(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}ZS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,QS:null}:{gl:t.slice(0,i),QS:t.slice(i+1)}}JS(t,i){this.RS!==i&&(this.RS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}KS(t){this.DS!==t&&(null!==this.DS&&this.kS.get(this.DS)?.setHovered(!1),this.DS=t,this.RS=null,null!==t&&this.kS.get(t)?.setHovered(!0))}tx(){if(null!==this.FS)return void this.Vf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.DS?null:this.kS.get(this.DS);t?this.Vf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Vf.chartElement().style.removeProperty("cursor")}}const Vh=new WeakMap;function Lh(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}function Ah(t,i){const s=Vh.get(t);s&&(s.GS(i),s.Gi()&&(s.m(),Vh.delete(t)))}let Eh=0;class Bh{constructor(t,i,s){this.sr=null,this.ox=!1,this._x="",this.ux=null,this.Vf=t,this.be=i,this.Ma="pipsend-trading-line-"+Eh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.vx(),(this.Ps.draggable||this.Ps.onClick)&&Lh(this.Vf)?.XS(this)}id(){return this.Ma}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.ox!==t&&this.sr&&(this.ox=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this._x}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.ux=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.mx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.ux=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.ux;this.ux=null,null!==t&&t!==this.Ps.price&&(this.mx(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._x=t.color),!this.sr)return;const i={title:this.wx()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.ox||(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.mx(t)}remove(){Ah(this.Vf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}wx(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}vx(){this._x=this.Ps.color,this.sr=this.be.createPriceLine({id:this.Ma,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.wx()})}mx(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.wx()})}}function Oh(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 Bh(i,t,r)}class Wh{constructor(t,i){this.If=null,this.gx=null,this.bx=null,this.Mx={},this.Vf=t,this.be=i,this.yx()}yx(){this.If=this.Vf.chartElement()}Sx(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.If?(this.gx=t,this.Mx=i||{},new Promise(t=>{this.If.style.cursor="crosshair",this.bx=i=>{const s=this.Sx(i),n=this.xx(s);this.disableClickToCreate(),t(n)},this.If.addEventListener("click",this.bx)})):Promise.resolve(null)}disableClickToCreate(){this.If&&this.bx&&(this.If.removeEventListener("click",this.bx),this.If.style.cursor="default"),this.gx=null,this.bx=null,this.Mx={}}xx(t){if(!this.gx)return null;let i;switch(this.gx){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.Mx};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.Mx};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.Mx};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.Mx};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.Mx};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.Mx};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.Mx};break;default:return null}return new Bh(this.Vf,this.be,i)}getCreationMode(){return this.gx}isCreating(){return null!==this.gx}}function zh(t,i){return new Wh(t,i)}class $h{constructor(){this.Cx=[],this.Px=new Map,this.Tx=new Map,this.xt=!0}XS(t){this.Px.has(t)||(this.Cx.push(t),this.Px.set(t,[]),this.xt=!0)}GS(t){const i=this.Cx.indexOf(t);-1!==i&&this.Cx.splice(i,1),this.Px.delete(t),this.xt=!0}Gi(){return 0===this.Cx.length}kx(t,i){this.Px.set(t,i),this.xt=!0}Dx(t,i){return this.xt&&this.Rx(),this.Tx.get(Hh(t,i))??0}Rx(){const t=new Map,i=[];for(const s of this.Cx)for(const n of this.Px.get(s)??[]){const e=Nh(n.qt),r=n.qt;let h=n.ct;for(const t of[...i].sort(Uh))Math.abs(h-t.ct)<e&&(h=t.ct+e);let l=h-n.ct;l>r&&(l=0),i.push({ct:n.ct+l,qt:n.qt}),t.set(Hh(s,n.sn),l)}this.Tx=t,this.xt=!1}}function Hh(t,i){return`${t}:${i}`}function Nh(t){return Math.max(9,Math.round(.4*t))}function Uh(t,i){return t.ct-i.ct}const qh=new WeakMap;const jh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},Yh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},Xh=["takeProfit","entry","stopLoss"];class Gh{constructor(){this.Yt=null,this.Fx=[],this.Ix=0,this.Nf="",this.xa=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.Fx)if(s.Vx&&t>=s.Lx&&t<=s.Ax&&Math.abs(i-s.Ex)<=s.qt/2)return{sn:s.sn,QS:"close"};for(const s of this.Fx)if(t>=s.Bx&&t<=s.Ox&&Math.abs(i-s.Ex)<=s.qt/2)return{sn:s.sn,QS:"body"};for(const t of this.Fx)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,QS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.hw(t))}hw(t){const i=this.Yt;if(this.Fx=[],null===i||0===i.Wx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Nf!==i.T&&(this.Nf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.Ix=Math.max(0,n.width-i.Mu);const e=i.zx?this.Ix:n.width;for(const s of i.Wx)this.Fx.push(this.$x(t,i,s,e));i.zx&&i.Wx.length>1&&this.Hx(t,i),s.restore()}$x(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Nx,a=0===s.Ux.length?0:Math.max(this.Wn.Ii(e,s.Ux)+2*i.MM,.85*l),o=this.Wn.Ii(e,s.hi)+2*i.MM,_=s.Vx?l:0,u=a+o+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.qx,f=p-l/2;this.jx(t,s,d,c,n),this.Yx(t,i,s,{qh:d,Xx:f,ts:u,qt:l});let v=d;return a>0&&(this.Gx(t,i,s,{qh:v,Xx:f,ts:a,qt:l}),v+=a,this.Kx(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.kM??s.R,e.fillText(s.hi,v+o/2,p),e.restore(),v+=o,s.Vx&&(this.Kx(e,s.R,v,f,l,r,h),this.Zx(t,i,s,{qh:v,Xx:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Ex:p,qt:l,Bx:d,Ox:c,Lx:v,Ax:v+_,Vx:s.Vx}}jx(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,o=Math.max(1,Math.round(i.dt*a)),_=Math.round(i.ct*a)-Math.floor(o/2);h.save(),h.strokeStyle=i.R,h.lineWidth=o,n(h,i.Kt),h.beginPath(),0!==i.qx?(h.moveTo(0,_),h.lineTo(Math.round(r*l),_)):(h.moveTo(0,_),h.lineTo(Math.round(Math.max(0,s-8)*l),_),r>e+8&&(h.moveTo(Math.round((e+8)*l),_),h.lineTo(Math.round(r*l),_))),h.stroke(),h.restore()}Yx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Jx===s.sn,a=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),Kh(e,n,i.Qx,r,h),e.fillStyle=this.xa.X(i.Z,i.tC),e.fill(),e.lineWidth=a,e.strokeStyle=s.R,e.stroke(),e.restore()}Gx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.iC){const t=i.Wt;e.save(),Kh(e,{qh:n.qh+t,Xx:n.Xx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Qx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.iC?i.sC:s.R,e.fillText(s.Ux,n.qh+n.ts/2,n.Xx+n.qt/2),e.restore()}Kx(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.xa.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}Zx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Jx===s.sn&&"close"===i.nC){e.save();const t=i.Wt;Kh(e,{qh:n.qh,Xx:n.Xx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Qx-t),r,h,"right"),e.fillStyle=this.xa.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,a=(n.Xx+n.qt/2)*h,o=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-o,a-o),e.lineTo(l+o,a+o),e.moveTo(l+o,a-o),e.lineTo(l-o,a+o),e.stroke(),e.restore()}Hx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Wx.find(t=>"entry"===t.sn)??i.Wx[0],h=i.Wx.map(t=>t.ct),l=Math.round(this.Ix*n);s.save(),s.setLineDash([]),s.strokeStyle=r.R,s.lineWidth=Math.max(1,Math.floor(n)),s.beginPath(),s.moveTo(l,Math.round(Math.min(...h)*e)),s.lineTo(l,Math.round(Math.max(...h)*e)),s.stroke();for(const t of i.Wx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.xa.X(i.Z,i.tC),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function Kh(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.Xx*e),a=Math.round(i.ts*n),o=Math.round(i.qt*e),_=Math.min(s*n,a/2,o/2);L(t,h,l,a,o,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class Zh{constructor(){this.Jt=new Gh,this.Yt=null}Tt(t){this.Yt=t}renderer(){return null===this.Yt?null:(this.Jt.lt(this.Yt),this.Jt)}zOrder(){return"top"}Xn(t,i){return null===this.Yt?null:this.Jt.Xn(t,i)}}class Jh{constructor(t){this.Qt=t}coordinate(){return this.eC()?.Li??-1e3}text(){return this.eC()?.hi??""}textColor(){return this.eC()?.kM??"#FFFFFF"}backColor(){return this.eC()?.R??"#000000"}visible(){return null!==this.eC()}eC(){return this.Qt()}}let Qh=0;class tl{constructor(t,i,s){this.eh=new Zh,this.xa=new S([]),this.rC=!1,this.hC=null,this.RS=null,this.lC=null,this.ux=null,this.Vf=t,this.be=i,this.Ma="pipsend-position-line-"+Qh++,this.Ps=s,this.Ff={...Yh,...s.theme},this.Zb=[this.eh],this.aC=Xh.map(t=>new Jh(()=>this.oC(t))),this._C=function(t,i){let s=qh.get(t);return s||(s=new $h,qh.set(t,s)),s.XS(i),s}(this.Vf,this.Ma),this.be.attachPrimitive(this),Lh(this.Vf)?.XS(this)}attached(t){this.dM=t.requestUpdate,this.rC=!0,this.requestUpdate()}detached(){this.rC=!1,this.dM=void 0}paneViews(){return this.Zb}priceAxisViews(){return this.aC}updateAllViews(){this.eh.Tt(this.uC())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.cC(s.sn);return null===n?null:{externalId:`${this.Ma}#${s.sn}:${s.QS}`,zOrder:"top",cursorStyle:"close"===s.QS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.Ma}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.hC===n&&this.RS===e||(this.hC=n,this.RS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.hC&&"close"!==this.RS&&(this.cC(this.hC)?.draggable??!0)}isClickable(){return"close"===this.RS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}dragAnchorY(){if(null===this.lC)return null;const t=this.cC(this.lC)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.lC=this.hC,null===this.lC)return;const t=this.cC(this.lC)?.price??null;this.ux=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.lC,t)}dragTo(t){null!==this.lC&&(this.dC(this.lC,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.lC,t))}commitDrag(){const t=this.lC;if(this.lC=null,this.ux=null,null===t)return;const i=this.cC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.lC,i=this.ux;if(this.lC=null,this.ux=null,null===t)return;null!==i&&i!==this.cC(t)?.price&&(this.dC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.cC(t)?.price??0)}click(){const t=this.hC;if(null===t)return;if("close"===this.RS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.cC(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.lC,s=null===i?void 0:this.cC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=il(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=il(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.cC(i);null!==t&&(t.price=s)}t.theme&&(this.Ff={...this.Ff,...t.theme}),this.requestUpdate()}setPrice(t,i){this.lC!==t&&this.dC(t,i)}setText(t,i){const s=this.cC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of Xh){const s=this.cC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){Ah(this.Vf,this),function(t,i){const s=qh.get(t);s&&(s.GS(i),s.Gi()&&qh.delete(t))}(this.Vf,this.Ma),this.be.detachPrimitive(this)}requestUpdate(){this.dM&&this.dM()}oC(t){const i=this.cC(t);if(null===i||!isFinite(i.price)||!1===this.Ps.visible||!1===i.axisLabelVisible)return null;const s=this.be.priceToCoordinate(i.price);if(null===s)return null;const n=i.color??jh[t];return{Li:s,hi:this.be.priceFormatter().format(i.price),R:n,kM:this.xa.K(n).J}}cC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}dC(t,i){const s=this.cC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}uC(){if(!this.rC||!1===this.Ps.visible)return null;const t=this.Vf.options().layout,i=this.Ff.fontSize??t.fontSize,s=i+2*this.Ff.paddingY,n=[],e=[];for(const t of Xh){const i=this.cC(t);if(null===i||!isFinite(i.price))continue;const r=this.be.priceToCoordinate(i.price);if(null===r)continue;const h="entry"===t;e.push({sn:t,ct:r,qt:s}),n.push({sn:t,ct:r,qx:0,R:i.color??jh[t],hi:i.formatText?i.formatText(i.price):i.text??"",Ux:i.badge??"",iC:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),Vx:i.closable??!0,pC:i.draggable??!0})}if(0===n.length)return this._C.kx(this.Ma,[]),null;this._C.kx(this.Ma,e);for(const t of n)t.qx=this._C.Dx(this.Ma,t.sn);return{Wx:n,Z:this.Ff.background??(r=t.background,"solid"===r.type?r.color:r.topColor),kM:this.Ff.textColor,sC:this.Ff.badgeTextColor,Qx:this.Ff.borderRadius,Wt:this.Ff.borderWidth,MM:this.Ff.paddingX,Nx:this.Ff.paddingY,tC:this.Ff.backgroundOpacity,T:g(i,this.Ff.fontFamily??t.fontFamily),P:i,zx:!1!==this.Ps.connectorVisible&&n.length>1,Mu:this.Ps.rightOffset??56,Jx:this.hC,nC:this.RS};var r}}function il(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}function sl(t,i,s){return new tl(i,t,s)}const nl=new Set(["line","body","stroke","center","move"]);function el(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?nl.has(n)?"move":"grab":void 0}}function rl(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var hl;function ll(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.ky;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Dy,t.day=i.day??i.Ry,t}return t}function al(t,i){const s={};return s.price=t,s.time=i,s}function ol(t){if(!t)return al(0,null);return al(t.price??t.bt??0,ll(t.time??t.gt??null))}function _l(t,i="time"){return t?t[i]??null:null}function ul(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"}(hl||(hl={}));class cl{constructor(t,i,s={}){this._state=hl.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.fC(),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}fC(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}isComplete(){return!0}_registerOptions(t){this._ownOptions=t}options(){return{...this._ownOptions??this._options}}applyOptions(t){null!==this._ownOptions&&Object.assign(this._ownOptions,t),this._options={...this._options,...t},void 0!==t.visible&&(this._visible=t.visible),void 0!==t.locked&&(this._locked=t.locked),this._update()}show(){this._visible=!0,this._update()}hide(){this._visible=!1,this._update()}lock(){this._locked=!0}unlock(){this._locked=!1}isLocked(){return this._locked}isVisible(){return this._visible}series(){return this._series}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 dl=new WeakMap;function pl(t,i){dl.set(t,i)}function fl(t){const i=!0===dl.get(t);return i&&dl.set(t,!1),i}function vl(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 a=t.measureText(l).width/s+10,o=r-a,_=e.ct-8.5;t.fillStyle=e.Ot,t.beginPath(),t.rect(o*s,_*n,a*s,17*n),t.fill(),t.fillStyle=e.kM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(o+5)*s,e.ct*n),t.restore()}var ml;!function(t){t.vC="idle",t.mC="waiting_first_point",t.wC="waiting_second_point",t.gC="completed"}(ml||(ml={}));class wl{constructor(t,i,s={}){this.Vv=ml.vC,this.bC=null,this.bx=null,this.np=null,this.Vf=t,this.be=i,this.MC=s}yC(){this.Vv===ml.vC&&(this.Vv=ml.mC,this.bC=null,this.SC(),this.xC())}CC(){this.Vv=ml.vC,this.bC=null,this.PC(),this.TC(),this.MC.kC&&this.MC.kC()}DC(){return this.Vv}RC(){return this.Vv===ml.mC||this.Vv===ml.wC}SC(){this.bx=t=>{this.FC(t)},this.Vf.subscribeClick(this.bx)}xC(){this.np=t=>{this.IC(t)},this.Vf.subscribeCrosshairMove(this.np)}PC(){this.bx&&(this.Vf.unsubscribeClick(this.bx),this.bx=null)}TC(){this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null)}FC(t){if(!t.point)return;if(fl(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===ml.mC?(this.bC=n,this.Vv=ml.wC,this.MC.VC&&this.MC.VC(n)):this.Vv===ml.wC&&this.bC&&(this.Vv=ml.gC,this.MC.LC&&this.MC.LC(n),this.MC.AC&&this.MC.AC(this.bC,n),this.PC(),this.TC(),this.Vv=ml.vC,this.bC=null)}IC(t){if(!t.point)return;if(this.Vv!==ml.wC)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.MC.EC&&this.MC.EC(n)}m(){this.CC()}}class gl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class bl{constructor(t){this.BC=t,this.Jt=new gl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ml extends cl{constructor(t,i){super(t,"trend-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null,this.jC=!1,this.YC=null,this.XC=null,this.GC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.GC),this.aS(),this.GC.interactive?this.KC():this.jC=!0}KC(){const t=new wl(this._chart,this._series,{VC:t=>{this.GC.point1Time=t.gt,this.GC.point1Price=t.bt,this.dM()},LC:t=>{this.GC.point2Time=t.gt,this.GC.point2Price=t.bt,this.jC=!0,this.dM(),this.GC.onUpdate&&this.GC.onUpdate()},EC:t=>{this.GC.point1Time&&!this.jC&&(this.XC=t,this.dM())},AC:()=>{this.jC=!0}});this.YC=t,t.yC()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new bl(this)}QC(){if(!this.GC.point1Time||!this.GC.point2Time)return null;const t=Kn(this._chart,this._series,this.GC.point1Time)??0,i=this._series.priceToCoordinate(this.GC.point1Price)??0,s=Kn(this._chart,this._series,this.GC.point2Time)??0,n=this._series.priceToCoordinate(this.GC.point2Price)??0;if(!this.GC.extendLeft&&!this.GC.extendRight)return{tP:t,iP:i,sP:s,nP:n};if(s===t)return{tP:t,iP:i,sP:s,nP:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{tP:this.GC.extendLeft?0:t,iP:this.GC.extendLeft?i-r*t:i,sP:this.GC.extendRight?e:s,nP:this.GC.extendRight?i+r*(e-t):n}}eP(){const t=this.QC();if(null===t)return null;const i=t.sP>=t.tP?t.nP:t.iP,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.GC.point2Price??this.GC.point1Price??null}drawToCanvas(t,i,s){if(!this.jC&&this.GC.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.GC.point1Time||!this.GC.point2Time)return;const n=(Kn(this._chart,this._series,this.GC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.GC.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.GC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.GC.point2Price)??0)*s,l=this.GC.lineColor,a=this.WC?this.GC.lineWidth+1:this.GC.lineWidth;t.strokeStyle=l,t.lineWidth=a*i,"dashed"===this.GC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.GC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const o=this.QC();if(null===o)return;t.moveTo(o.tP*i,o.iP*s),t.lineTo(o.sP*i,o.nP*s),t.stroke(),t.setLineDash([]),!this.WC&&!this.zC||this.isLocked()||(this.hP(t,n,e,i,l),this.hP(t,r,h,i,l));const _=this.eP();if(!1!==this.GC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&vl(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}rP(t,i,s){if(!this.GC.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.GC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.GC.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s;t.strokeStyle=this.GC.lineColor,t.lineWidth=this.GC.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.hP(t,n,e,i,this.GC.lineColor),t.globalAlpha=.5,this.hP(t,r,h,i,this.GC.lineColor),t.globalAlpha=1}hP(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.GC.lineColor=t,this.dM()}color(){return this.GC.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}isHovered(){return this.zC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.QC();if(null===s)return!1;return this.lP(t,i,s.tP,s.iP,s.sP,s.nP)<=8}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.GC.point1Time||!this.GC.point2Time)return null;const s=Kn(this._chart,this._series,this.GC.point1Time)??0,n=this._series.priceToCoordinate(this.GC.point1Price)??0,e=Kn(this._chart,this._series,this.GC.point2Time)??0,r=this._series.priceToCoordinate(this.GC.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.lP(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,"line"===t&&(this.UC={gt:this.GC.point1Time,bt:this.GC.point1Price},this.qC={gt:this.GC.point2Time,bt:this.GC.point2Price})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null}updateDrag(t,i){if(this.$C&&this.HC){if("point1"===this.HC)this.GC.point1Time=t,this.GC.point1Price=i;else if("point2"===this.HC)this.GC.point2Time=t,this.GC.point2Price=i;else if("line"===this.HC&&this.UC&&this.qC){const s=rl(this.NC,t,i);this.GC.point1Time=this.UC.gt+s.gt,this.GC.point1Price=this.UC.bt+s.bt,this.GC.point2Time=this.qC.gt+s.gt,this.GC.point2Price=this.qC.bt+s.bt}this.dM(),this.GC.onUpdate&&this.GC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[al(this.GC.point1Price??0,ll(this.GC.point1Time)),al(this.GC.point2Price??0,ll(this.GC.point2Time))],style:{lineColor:this.GC.lineColor,lineWidth:this.GC.lineWidth,lineStyle:this.GC.lineStyle,extendLeft:this.GC.extendLeft,extendRight:this.GC.extendRight}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return this.jC}remove(){this.YC&&(this.YC.m(),this.YC=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GC.onRemove&&this.GC.onRemove()}}function yl(t,i){return new Ml(t,i)}class Sl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class xl{constructor(t){this.BC=t,this.Jt=new Sl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Cl extends cl{constructor(t,i){super(t,"horizontal-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.aP=0,this.oP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.oP),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new xl(this)}_P(){return void 0===this.oP.startTime?0:Kn(this._chart,this._series,this.oP.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.oP.price)return;const n=(this._series.priceToCoordinate(this.oP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this._P()*i,h=this.oP.lineColor,l=this.WC?this.oP.lineWidth+1:this.oP.lineWidth;t.strokeStyle=h,t.lineWidth=l*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(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.oP.showPriceLabel&&vl(t,this._series,i,s,{bt:this.oP.price,ct:n/s,Ot:h}),this.oP.showLabel&&(this.WC||this.zC)&&this.uP(t,n,i,s,h)}uP(t,i,s,n,e){const r=this.oP.labelText||this.oP.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const a=t.measureText(r).width,o=l,_=10*s,u=i-o/2-h;t.fillStyle=e,t.fillRect(_,u,a+2*h,o+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.oP.lineColor=t,this.dM()}color(){return this.oP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.oP.price)return!1;const s=this._series.priceToCoordinate(this.oP.price)??0;return!(t<this._P()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.$C=!0,this.NC=i,this.aP=this.oP.price??0}stopDrag(){this.$C=!1,this.NC=null}updateDrag(t,i){this.$C&&(this.oP.price=this.aP+rl(this.NC,t,i).bt,this.dM(),this.oP.onUpdate&&this.oP.onUpdate())}getPrice(){return this.oP.price}setPrice(t){this.oP.price=t,this.dM()}setLabel(t){this.oP.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[al(this.oP.price??0,ll(this.oP.startTime))],style:{lineColor:this.oP.lineColor,lineWidth:this.oP.lineWidth,lineStyle:this.oP.lineStyle,showLabel:this.oP.showLabel,labelText:this.oP.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.oP.onRemove&&this.oP.onRemove()}}function Pl(t,i){return new Cl(t,i)}class Tl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.BC=t,this.Jt=new Tl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends cl{constructor(t,i){super(t,"cross-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.cP=0,this.aP=0,this.dP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.dP),this.aS()}aS(){this.eh=new kl(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}pP(){if(void 0===this.dP.time||void 0===this.dP.price)return null;const t=Kn(this._chart,this._series,this.dP.time),i=this._series.priceToCoordinate(this.dP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.pP();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,a=n.ct*s,o=this.dP.lineColor,_=this.WC||this.zC&&!this.isLocked(),u=_?this.dP.lineWidth+1:this.dP.lineWidth;t.strokeStyle=o,t.lineWidth=u*i,"dashed"===this.dP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.dP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,a),t.lineTo(r,a),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.dP.showPriceLabel&&void 0!==this.dP.price&&vl(t,this._series,i,s,{bt:this.dP.price,ct:n.ct,Ot:o}),_&&!this.isLocked()&&(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,a,5*i,0,2*Math.PI),t.fill(),t.stroke())}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.pP();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.$C=!0,this.NC=i,this.cP=this.dP.time,this.aP=this.dP.price??0}updateDrag(t,i){if(!this.$C)return;const s=rl(this.NC,t,i);this.dP.time=this.cP+s.gt,this.dP.price=this.aP+s.bt,this.dM(),this.dP.onUpdate&&this.dP.onUpdate()}stopDrag(){this.$C=!1,this.NC=null}setColor(t){this.dP.lineColor=t,this.dM()}color(){return this.dP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}remove(){if(this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.dP.onRemove&&this.dP.onRemove()}_serializeShape(){return{type:"crossLine",points:[al(this.dP.price??0,ll(this.dP.time))],style:{lineColor:this.dP.lineColor,lineWidth:this.dP.lineWidth,lineStyle:this.dP.lineStyle}}}}function Rl(t,i){return new Dl(t,i)}class Fl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Il{constructor(t){this.BC=t,this.Jt=new Fl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vl extends cl{constructor(t,i){super(t,"polygon",i),this.I_=[],this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.fP=null,this.jC=!1,this.XC=null,this.bx=null,this.vP=null,this.mP=null,this.wP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.wP),this.I_=[...i.points??[]],this.aS(),this.wP.interactive?this.gP():this.jC=this.I_.length>=3}aS(){this.eh=new Il(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.I_.length>=3&&this.bP(t.point.x,t.point.y)?this.MP():(this.I_.push({time:s,price:i}),this.dM()))},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={time:s,price:i},this.dM())},this.mP=t=>{"Enter"===t.key&&this.I_.length>=3?this.MP():"Escape"===t.key&&(this.I_=[],this.MP())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP),document.addEventListener("keydown",this.mP)}bP(t,i){const s=this.I_[0],n=Kn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Vl.yP&&Math.abs(i-e)<=Vl.yP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.wP.onComplete&&this.wP.onComplete(),this.wP.onUpdate&&this.wP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null),this.mP&&(document.removeEventListener("keydown",this.mP),this.mP=null)}xP(){const t=[...this.I_];return this.jC||null===this.XC||t.push(this.XC),this.CP(t)}CP(t){const i=[];for(const s of t){const t=Kn(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.xP();if(n.length<2)return;const e=this.wP.borderColor,r=this.WC?this.wP.borderWidth+1:this.wP.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.jC&&(t.closePath(),this.wP.fillOpacity>0&&(t.fillStyle=this.Ey(this.wP.fillColor,this.wP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.jC?"dashed"===this.wP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.wP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked())for(const n of this.PP())this.TP(t,n.ut*i,n.ct*s,i,e)}PP(){return this.CP(this.I_)}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.PP();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.PP();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.$C=!0,this.HC=t,this.NC=i,this.fP=this.I_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.$C&&null!==this.HC&&null!==this.fP){if("shape"===this.HC){const s=rl(this.NC,t,i);this.I_=this.fP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.HC;this.I_[s]&&(this.I_[s]={time:t,price:i})}this.dM(),this.wP.onUpdate&&this.wP.onUpdate()}}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.fP=null}setColor(t){this.wP.borderColor=t,this.wP.fillColor=t,this.dM()}color(){return this.wP.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}points(){return this.I_}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.wP.onRemove&&this.wP.onRemove()}_serializeShape(){return{type:"polygon",points:this.I_.map(t=>al(t.price,ll(t.time))),style:{fillColor:this.wP.fillColor,fillOpacity:this.wP.fillOpacity,borderColor:this.wP.borderColor,borderWidth:this.wP.borderWidth,borderStyle:this.wP.borderStyle}}}}function Ll(t,i){return new Vl(t,i)}Vl.yP=12;class Al{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.BC=t,this.Jt=new Al(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends cl{constructor(t,i){super(t,"parallel-channel",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.jC=!1,this.ud=0,this.XC=null,this.bx=null,this.vP=null,this.DP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.DP),this.aS(),this.DP.interactive?this.gP():this.jC=!0}aS(){this.eh=new El(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.ud)this.DP.point1Time=s,this.DP.point1Price=i;else{if(1!==this.ud)return this.DP.channelWidth=i-this.RP(s),void this.MP();this.DP.point2Time=s,this.DP.point2Price=i}this.ud++,this.dM()}},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={gt:s,bt:i},2===this.ud&&(this.DP.channelWidth=i-this.RP(s)),this.dM())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.DP.onComplete&&this.DP.onComplete(),this.DP.onUpdate&&this.DP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null)}RP(t){const i=this.DP.point1Time,s=this.DP.point2Time,n=this.DP.point1Price,e=this.DP.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)}kS(){const t=this.DP,i=this.jC?t.point2Time:t.point2Time??this.XC?.gt,s=this.jC?t.point2Price:t.point2Price??this.XC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Kn(this._chart,this._series,t.point1Time),e=Kn(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,a=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,a=r+(h-r)/(e-n)*(t-n)}const o=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+o),u=this._series.priceToCoordinate(this._series.coordinateToPrice(a)+o);return null===_||null===u?null:{tP:n,sP:l,FP:r,IP:a,VP:_,LP:u}}drawToCanvas(t,i,s){const n=this.kS();if(null===n)return;const e=this.DP,r=e.lineColor,h=this.WC?e.lineWidth+1:e.lineWidth,l=i,a=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Ey(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.tP*l,n.FP*a),t.lineTo(n.sP*l,n.IP*a),t.lineTo(n.sP*l,n.LP*a),t.lineTo(n.tP*l,n.VP*a),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.jC?"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.tP*l,n.FP*a),t.lineTo(n.sP*l,n.IP*a),0!==(e.channelWidth??0)&&(t.moveTo(n.tP*l,n.VP*a),t.lineTo(n.sP*l,n.LP*a)),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked()&&(this.TP(t,n.tP*l,n.FP*a,l,r),this.TP(t,n.sP*l,n.IP*a,l,r),0!==(e.channelWidth??0))){const i=(n.tP+n.sP)/2,s=(n.VP+n.LP)/2;this.TP(t,i*l,s*a,l,r)}if(!1!==e.showPriceLabel&&this.jC){const i=this._series.coordinateToPrice(n.IP);null!==i&&vl(t,this._series,l,a,{bt:i,ct:n.IP,Ot:r})}}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}AP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.hypot(t-s,i-n);let o=((t-s)*h+(i-n)*l)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(t-(s+o*h),i-(n+o*l))}hitTest(t,i){const s=this.kS();if(null===s)return!1;return this.AP(t,i,s.tP,s.FP,s.sP,s.IP)<=8||this.AP(t,i,s.tP,s.VP,s.sP,s.LP)<=8}hitTestEndpoint(t,i){const s=this.kS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.tP,s.FP))return"point1";if(n(s.sP,s.IP))return"point2";if(0!==(this.DP.channelWidth??0)){if(n((s.tP+s.sP)/2,(s.VP+s.LP)/2))return"width"}return null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,this.kP={EP:{gt:this.DP.point1Time,bt:this.DP.point1Price},BP:{gt:this.DP.point2Time,bt:this.DP.point2Price},ts:this.DP.channelWidth??0}}updateDrag(t,i){if(!this.$C||null===this.HC||null===this.kP)return;const s=this.DP;if("point1"===this.HC)s.point1Time=t,s.point1Price=i;else if("point2"===this.HC)s.point2Time=t,s.point2Price=i;else if("width"===this.HC)s.channelWidth=i-this.RP(t);else{const n=rl(this.NC,t,i);s.point1Time=this.kP.EP.gt+n.gt,s.point1Price=this.kP.EP.bt+n.bt,s.point2Time=this.kP.BP.gt+n.gt,s.point2Price=this.kP.BP.bt+n.bt,s.channelWidth=this.kP.ts}this.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}setColor(t){this.DP.lineColor=t,this.DP.fillColor=t,this.dM()}color(){return this.DP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.DP.onRemove&&this.DP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[al(this.DP.point1Price??0,ll(this.DP.point1Time)),al(this.DP.point2Price??0,ll(this.DP.point2Time))],style:{lineColor:this.DP.lineColor,lineWidth:this.DP.lineWidth,lineStyle:this.DP.lineStyle,fillColor:this.DP.fillColor,fillOpacity:this.DP.fillOpacity,extendRight:this.DP.extendRight},extra:{channelWidth:this.DP.channelWidth}}}}function Ol(t,i){return new Bl(t,i)}class Wl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.BC=t,this.Jt=new Wl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class $l extends cl{constructor(t,i){super(t,"pitchfork",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.jC=!1,this.ud=0,this.XC=null,this.bx=null,this.vP=null,this.OP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.OP),this.aS(),this.OP.interactive?this.gP():this.jC=!0}aS(){this.eh=new zl(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.ud)this.OP.pivotTime=s,this.OP.pivotPrice=i;else{if(1!==this.ud)return this.OP.lowerTime=s,this.OP.lowerPrice=i,this.ud++,void this.MP();this.OP.upperTime=s,this.OP.upperPrice=i}this.ud++,this.dM()}},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={gt:s,bt:i},this.dM())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.OP.onComplete&&this.OP.onComplete(),this.OP.onUpdate&&this.OP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null)}WP(t,i){if(void 0===t||void 0===i)return null;const s=Kn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}zP(){const t=this.OP,i=this.WP(t.pivotTime,t.pivotPrice),s=this.WP(t.upperTime,t.upperPrice),n=this.jC?this.WP(t.lowerTime,t.lowerPrice):this.WP(t.lowerTime,t.lowerPrice)??(null!==this.XC&&this.ud>=2?this.WP(this.XC.gt,this.XC.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{Hy:i,$P:e,Cy:s,Ty:n,HP:l(i),NP:l(s),UP:l(n)}}drawToCanvas(t,i,s){const n=this.zP();if(null===n)return void this.qP(t,i,s);const e=this.OP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Ey(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.lineTo(n.UP.ut*h,n.UP.ct*l),t.lineTo(n.Ty.ut*h,n.Ty.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.WC?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.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.Ty.ut*h,n.Ty.ct*l),t.moveTo(n.Hy.ut*h,n.Hy.ct*l),t.lineTo(n.HP.ut*h,n.HP.ct*l),t.moveTo(n.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.moveTo(n.Ty.ut*h,n.Ty.ct*l),t.lineTo(n.UP.ut*h,n.UP.ct*l),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked())for(const i of[n.Hy,n.Cy,n.Ty])this.TP(t,i.ut*h,i.ct*l,h,r)}qP(t,i,s){const n=this.OP,e=this.WP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.WP(n.upperTime,n.upperPrice)??(null!==this.XC?this.WP(this.XC.gt,this.XC.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.TP(t,e.ut*i,e.ct*s,i,h)}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}AP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.hypot(t-s,i-n);let o=((t-s)*h+(i-n)*l)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(t-(s+o*h),i-(n+o*l))}hitTest(t,i){const s=this.zP();if(null===s)return!1;return[[s.Hy,s.HP],[s.Cy,s.NP],[s.Ty,s.UP],[s.Cy,s.Ty]].some(([s,n])=>this.AP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.zP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.Hy)?"pivot":n(s.Cy)?"upper":n(s.Ty)?"lower":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,this.kP=[{gt:this.OP.pivotTime,bt:this.OP.pivotPrice},{gt:this.OP.upperTime,bt:this.OP.upperPrice},{gt:this.OP.lowerTime,bt:this.OP.lowerPrice}]}updateDrag(t,i){if(!this.$C||null===this.HC||null===this.kP)return;const s=this.OP;if("pivot"===this.HC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.HC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.HC)s.lowerTime=t,s.lowerPrice=i;else{const n=rl(this.NC,t,i),[e,r,h]=this.kP;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.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}setColor(t){this.OP.lineColor=t,this.OP.fillColor=t,this.dM()}color(){return this.OP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.OP.onRemove&&this.OP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[al(this.OP.pivotPrice??0,ll(this.OP.pivotTime)),al(this.OP.upperPrice??0,ll(this.OP.upperTime)),al(this.OP.lowerPrice??0,ll(this.OP.lowerTime))],style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,lineStyle:this.OP.lineStyle,fillColor:this.OP.fillColor,fillOpacity:this.OP.fillOpacity}}}}function Hl(t,i){return new $l(t,i)}class Nl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ul{constructor(t){this.BC=t,this.Jt=new Nl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ql extends cl{constructor(t,i){super(t,"vertical-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.cP=0,this.jP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.jP),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ul(this)}drawToCanvas(t,i,s){if(void 0===this.jP.time)return;const n=(Kn(this._chart,this._series,this.jP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.jP.lineColor,h=this.WC||this.zC&&!this.isLocked()?this.jP.lineWidth+1:this.jP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.jP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.jP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.jP.showLabel&&(this.WC||this.zC)&&this.jP.labelText&&this.uP(t,n,i,s,r)}uP(t,i,s,n,e){const r=this.jP.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const a=t.measureText(r).width,o=l,_=i-a/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,a+2*h,o+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.jP.lineColor=t,this.dM()}color(){return this.jP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.jP.time)return!1;const s=Kn(this._chart,this._series,this.jP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.$C=!0,this.NC=i,this.cP=this.jP.time}stopDrag(){this.$C=!1,this.NC=null}updateDrag(t,i){this.$C&&(this.jP.time=this.cP+rl(this.NC,t,i).gt,this.dM(),this.jP.onUpdate&&this.jP.onUpdate())}getTime(){return this.jP.time}setTime(t){this.jP.time=t,this.dM()}setLabel(t){this.jP.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[al(0,ll(this.jP.time))],style:{lineColor:this.jP.lineColor,lineWidth:this.jP.lineWidth,lineStyle:this.jP.lineStyle,showLabel:this.jP.showLabel,labelText:this.jP.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.jP.onRemove&&this.jP.onRemove()}}function jl(t,i){return new ql(t,i)}const Yl=[{YP:0,Jl:"0.0%"},{YP:.236,Jl:"23.6%"},{YP:.382,Jl:"38.2%"},{YP:.5,Jl:"50.0%"},{YP:.618,Jl:"61.8%"},{YP:.786,Jl:"78.6%"},{YP:1,Jl:"100.0%"}],Xl=[...Yl,{YP:1.272,Jl:"127.2%"},{YP:1.414,Jl:"141.4%"},{YP:1.618,Jl:"161.8%"},{YP:2,Jl:"200.0%"},{YP:2.618,Jl:"261.8%"}];class Gl{constructor(t=!1){this.XP=t?Xl:Yl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.XP.map(({YP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{YP:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.XP=t}getRatios(){return[...this.XP]}getRatioValues(){return this.XP.map(t=>t.YP)}useStandardRatios(){this.XP=Yl}useExtendedRatios(){this.XP=Xl}}class Kl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zl{constructor(t){this.BC=t,this.Jt=new Kl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}function Jl(t){return{YP:t,Jl:`${(100*t).toFixed(1)}%`}}class Ql extends cl{constructor(t,i){super(t,"fibonacci-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.GP=null,this.jC=!1,this.WC=!1,this.zC=!1,this.XC=null,this.$C=!1,this.KP=null,this.np=null,this.ZP={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.ZP),this.JP=new Gl(this.ZP.useExtended),void 0!==this.ZP.levels&&this.ZP.levels.length>0&&this.JP.updateRatios(this.ZP.levels.map(Jl)),this.aS(),this.ZP.interactive?this.KC():(this.jC=!0,this.QP())}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Zl(this)}drawToCanvas(t,i,s){if(!this.jC&&this.ZP.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.Xb||!this.ZP.point1Time||!this.ZP.point2Time)return;const n=(Kn(this._chart,this._series,this.ZP.point1Time)??0)*i,e=(Kn(this._chart,this._series,this.ZP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.WC?2:this.ZP.lineWidth;this.Xb.levels.forEach(n=>{this.$x(t,n,r,h,i,s,l)}),!this.WC&&!this.zC||this.isLocked()||(this.hP(t,n,(this._series.priceToCoordinate(this.ZP.point1Price)??0)*s,i),this.hP(t,e,(this._series.priceToCoordinate(this.ZP.point2Price)??0)*s,i))}$x(t,i,s,n,e,r,h=1){const l=i.ratio??i.YP,a=i.price??i.bt;if(void 0===l||void 0===a)return;const o=(this._series.priceToCoordinate(a)??0)*r;let _=this.ZP.levelColors?.[l.toString()]||this.ZP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,o),t.lineTo(n,o),t.stroke(),this.ZP.showLabels&&this.uP(t,i,s,n,o,e,_)}uP(t,i,s,n,e,r,h){const l=i.label??i.Jl,a=i.price??i.bt,o=`${l} ${this.JP.formatPrice(a)}`;t.font=11*r+"px sans-serif";const _=t.measureText(o),u=4*r,c="right"===this.ZP.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.ZP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(o,c,d)}QP(){this.ZP.point1Time&&this.ZP.point1Price&&this.ZP.point2Time&&this.ZP.point2Price&&(this.Xb=this.JP.calculateLevels(this.ZP.point1Time,this.ZP.point1Price,this.ZP.point2Time,this.ZP.point2Price),this.ZP.onUpdate&&this.Xb&&this.ZP.onUpdate(this.Xb))}updatePoints(t,i,s,n){this.ZP.point1Time=t,this.ZP.point1Price=i,this.ZP.point2Time=s,this.ZP.point2Price=n,this.QP(),this.dM()}getMetrics(){return this.Xb}getLevels(){return this.Xb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.JP.getRatioValues();return{type:"fibRetracement",points:[al(this.ZP.point1Price??0,ll(this.ZP.point1Time)),al(this.ZP.point2Price??0,ll(this.ZP.point2Time))],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,showLabels:this.ZP.showLabels,labelPosition:this.ZP.labelPosition,levelColors:this.ZP.levelColors},extra:{levels:t,useExtended:this.ZP.useExtended}}}useExtendedLevels(t){this.ZP.useExtended=t,t?this.JP.useExtendedRatios():this.JP.useStandardRatios(),this.QP(),this.dM()}KC(){this.GP=new wl(this._chart,this._series,{VC:t=>{this.ZP.point1Time=t.gt,this.ZP.point1Price=t.bt,this.dM()},LC:t=>{this.ZP.point2Time=t.gt,this.ZP.point2Price=t.bt},AC:(t,i)=>{this.ZP.point1Time=t.gt,this.ZP.point1Price=t.bt,this.ZP.point2Time=i.gt,this.ZP.point2Price=i.bt,this.jC=!0,this.XC=null,this.QP(),this.tT(),this.dM()},EC:t=>{this.XC=t,this.dM()}}),this.GP.yC()}rP(t,i,s){if(!this.ZP.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.ZP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ZP.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s,l=this.JP.calculateLevels(this.ZP.point1Time,this.ZP.point1Price,this.XC.gt,this.XC.bt),a=Math.min(n,r),o=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.YP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.ZP.levelColors?.[e.toString()]||this.ZP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.ZP.lineWidth*i,t.beginPath(),t.moveTo(a,h),t.lineTo(o,h),t.stroke(),this.ZP.showLabels){const s=`${n.label??n.Jl} ${this.JP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.ZP.labelPosition?o+_:a-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.ZP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.hP(t,n,e,i),t.globalAlpha=.6,this.hP(t,r,h,i),t.globalAlpha=1}hP(t,i,s,n){const e=this.ZP.lineColor,r=this.WC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.WC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}tT(){this.np=t=>{this.iT(t)},this._chart.subscribeCrosshairMove(this.np)}sT(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}iT(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.WC||!this.$C)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.KP?(this.ZP.point1Time=i,this.ZP.point1Price=s):"point2"===this.KP&&(this.ZP.point2Time=i,this.ZP.point2Price=s),this.QP(),this.dM())}startDrag(t){this.$C=!0,this.KP=t}stopDrag(){this.$C=!1,this.KP=null}updateDrag(t,i){this.$C&&this.KP&&("point1"===this.KP?(this.ZP.point1Time=t,this.ZP.point1Price=i):(this.ZP.point2Time=t,this.ZP.point2Price=i),this.QP(),this.dM())}hitTestEndpoint(t,i){if(!this.jC||!this.ZP.point1Time||!this.ZP.point2Time)return null;const s=Kn(this._chart,this._series,this.ZP.point1Time)??0,n=this._series.priceToCoordinate(this.ZP.point1Price)??0,e=Kn(this._chart,this._series,this.ZP.point2Time)??0,r=this._series.priceToCoordinate(this.ZP.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.ZP={...this.ZP,...t},void 0!==t.levels&&t.levels.length>0?this.JP.updateRatios(t.levels.map(Jl)):void 0!==t.useExtended&&(t.useExtended?this.JP.useExtendedRatios():this.JP.useStandardRatios()),super.applyOptions(t),this.QP(),this.dM()}options(){return{...this.ZP,levels:this.JP.getRatioValues()}}setColor(t){this.ZP.lineColor=t,this.dM()}color(){return this.ZP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isSelected(){return this.WC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.jC||!this.ZP.point1Time||!this.ZP.point2Time)return!1;const s=Kn(this._chart,this._series,this.ZP.point1Time)??0,n=Kn(this._chart,this._series,this.ZP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Xb)return!1;for(const t of this.Xb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.jC}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GP&&(this.GP.m(),this.GP=null),this.sT(),this.ZP.onRemove&&this.ZP.onRemove()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.ZP.onRemove&&this.ZP.onRemove()}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.QP(),this.dM()}}function ta(t,i){return new Ql(t,i)}class ia{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class sa{constructor(t){this.BC=t,this.Jt=new ia(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class na extends cl{constructor(t,i){super(t,"fibonacci-extension",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.ZP={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.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new sa(this)}getPoint1(){return this.ZP.point1}getPoint2(){return this.ZP.point2}getPoint3(){return this.ZP.point3}getLevels(){return this.ZP.levels||[]}getOptions(){return this.ZP}setPoint1(t){this.ZP.point1=t,this.dM()}setPoint2(t){this.ZP.point2=t,this.dM()}setPoint3(t){this.ZP.point3=t,this.dM()}isComplete(){return!!(this.ZP.point1&&this.ZP.point2&&this.ZP.point3)}setColor(t){this.ZP.lineColor=t,this.dM()}color(){return this.ZP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.ZP.point1,this.ZP.point2,this.ZP.point3];for(const n of s){const s=Kn(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.nT();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.ZP.point1,n=this.ZP.point2,e=this.ZP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Kn(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=Kn(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=Kn(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.$C=!0,this.HC=t}stopDrag(){this.$C=!1,this.HC=null}updateDrag(t,i){if(!this.$C||!this.HC)return;const s={time:t,price:i};switch(this.HC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.ZP.onUpdate&&this.ZP.onUpdate()}nT(){if(!this.isComplete())return[];const t=this.ZP.point1,i=this.ZP.point2,s=this.ZP.point3,n=i.price-t.price;return(this.ZP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.nT()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.ZP.point1,e=this.ZP.point2,r=this.ZP.point3,h=this.WC||this.zC&&!this.isLocked(),l=(Kn(this._chart,this._series,n.time)??0)*i,a=(this._series.priceToCoordinate(n.price)??0)*s,o=(Kn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Kn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.ZP.lineColor||"#787B86",t.lineWidth=(this.ZP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,a),t.lineTo(o,_),t.stroke(),t.beginPath(),t.moveTo(o,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const a=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.ZP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.ZP.extendLines?(t.moveTo(0,a),t.lineTo(p,a)):(t.moveTo(u,a),t.lineTo(p,a)),t.stroke(),this.ZP.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,a)}}const f=(h?6:4)*i,v=[{ut:l,ct:a,Jl:"A"},{ut:o,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[ol(this.ZP.point1),ol(this.ZP.point2),ol(this.ZP.point3)],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,showLabels:this.ZP.showLabels,extendLines:this.ZP.extendLines},extra:{levels:(this.ZP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null)}}function ea(t,i){return new na(t,i)}class ra{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ha{constructor(t){this.BC=t,this.Jt=new ra(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const la=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class aa extends cl{constructor(t,i){super(t,"fibonacci-fan",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this.rT={levels:la,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.aS(),this.rT.interactive&&!this.rT.point1Time&&this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.rT.point1Time?(this.rT.point2Time=i,this.rT.point2Price=s,this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.rT.onUpdate&&this.rT.onUpdate()):(this.rT.point1Time=i,this.rT.point1Price=s,this.dM()))},this.np=t=>{if(this.eT&&this.rT.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ha(this)}drawToCanvas(t,i,s){const n=this.rT.point1Time,e=this.rT.point1Price,r=this.eT&&this.XC?this.XC.gt:this.rT.point2Time,h=this.eT&&this.XC?this.XC.bt:this.rT.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Kn(this._chart,this._series,n)??0)*i,a=(this._series.priceToCoordinate(e)??0)*s,o=(Kn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.WC?this.rT.lineWidth+1:this.rT.lineWidth;if(this.hT(t,l,a,o,_,"#2962FF",u*i),this.rT.levels)for(const n of this.rT.levels)this.lT(t,l,a,o,_,n,i,s,undefined,u);!this.WC&&!this.zC||this.eT||this.isLocked()||(this.hP(t,l,a,i,"#2962ff"),this.hP(t,o,_,i,"#2962ff"))}lT(t,i,s,n,e,r,h,l,a,o){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.rT.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=a||r.color;this.hT(t,i,s,c,d,p,o*h),this.rT.showLabels&&!this.eT&&this.uP(t,_,u,r.label,h,p)}hT(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()}hP(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()}uP(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 a=t.measureText(n).width,o=h;t.fillStyle=r,t.fillRect(i+l,s-o-l,a+2*l,o+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-o-l+l)}setColor(t){const i=this.rT.levels??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.rT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.rT.point1Time||!this.rT.point2Time)return!1;const s=Kn(this._chart,this._series,this.rT.point1Time)??0,n=this._series.priceToCoordinate(this.rT.point1Price)??0,e=Kn(this._chart,this._series,this.rT.point2Time)??0,r=this._series.priceToCoordinate(this.rT.point2Price)??0;if(this.lP(t,i,s,n,e,r)<=8)return!0;if(this.rT.levels)for(const h of this.rT.levels){const l=n+(r-n)*h.level,a=e;if(this.lP(t,i,s,n,a,l)<=8)return!0}return!1}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.rT.point1Time||!this.rT.point2Time)return null;const s=Kn(this._chart,this._series,this.rT.point1Time)??0,n=this._series.priceToCoordinate(this.rT.point1Price)??0,e=Kn(this._chart,this._series,this.rT.point2Time)??0,r=this._series.priceToCoordinate(this.rT.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.$C=!0,this.HC=t}stopDrag(){this.$C=!1,this.HC=null}updateDrag(t,i){this.$C&&this.HC&&("point1"===this.HC?(this.rT.point1Time=t,this.rT.point1Price=i):"point2"===this.HC&&(this.rT.point2Time=t,this.rT.point2Price=i),this.dM(),this.rT.onUpdate&&this.rT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[al(this.rT.point1Price??0,ll(this.rT.point1Time)),al(this.rT.point2Price??0,ll(this.rT.point2Time))],style:{lineWidth:this.rT.lineWidth,showLabels:this.rT.showLabels,extendLines:this.rT.extendLines},extra:{levels:(this.rT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.rT.onRemove&&this.rT.onRemove()}}function oa(t,i){return new aa(t,i)}class _a{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ua{constructor(t){this.BC=t,this.Jt=new _a(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ca extends cl{constructor(t,i){super(t,"rectangle",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this.aT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.aT),this.aS(),!this.aT.interactive||this.aT.time1&&this.aT.time2||this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.aT.time1?(this.aT.time2=i,this.aT.price2=s,this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.aT.onUpdate&&this.aT.onUpdate()):(this.aT.time1=i,this.aT.price1=s,this.dM()))},this.np=t=>{if(this.eT&&this.aT.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ua(this)}drawToCanvas(t,i,s){const n=this.aT.time1,e=this.aT.price1,r=this.eT&&this.XC?this.XC.gt:this.aT.time2,h=this.eT&&this.XC?this.XC.bt:this.aT.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Kn(this._chart,this._series,n)??0)*i,a=(this._series.priceToCoordinate(e)??0)*s,o=(Kn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,o),c=Math.max(l,o),d=Math.min(a,_),p=Math.max(a,_),f=c-u,v=p-d;if(this.aT.fillOpacity>0){const i=this.hS(this.aT.fillColor,this.eT?.1:this.aT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.aT.borderColor,w=this.WC?this.aT.borderWidth+1:this.aT.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.aT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.aT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.WC&&!this.zC||this.eT||this.isLocked()||this.oT(t,u,d,c,p,i,m),this.aT.showLabel&&this.aT.labelText&&!this.eT&&this.uP(t,u,d,c,p,i,s,m)}oT(t,i,s,n,e,r,h){const l=8*r,a=[{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 a)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}uP(t,i,s,n,e,r,h,l){const a=6*r,o=12*r;t.font=`${o}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.aT.labelText).width,u=o;let c=i+a,d=s+a;switch(this.aT.labelPosition){case"top-right":c=n-_-2*a,d=s+a;break;case"bottom-left":c=i+a,d=e-u-2*a;break;case"bottom-right":c=n-_-2*a,d=e-u-2*a;break;case"center":c=(i+n)/2-_/2-a,d=(s+e)/2-u/2-a}t.fillStyle=l,t.fillRect(c,d,_+2*a,u+2*a),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.aT.labelText,c+a,d+a)}hS(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.aT.borderColor=t,this.aT.fillColor=t,this.dM()}color(){return this.aT.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.aT.time1||!this.aT.time2)return!1;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=Kn(this._chart,this._series,this.aT.time2)??0,r=this._series.priceToCoordinate(this.aT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),a=Math.min(n,r),o=Math.max(n,r);return t>=h&&t<=l&&i>=a&&i<=o}hitTestEndpoint(t,i){if(!this.aT.time1||!this.aT.time2)return null;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=Kn(this._chart,this._series,this.aT.time2)??0,r=this._series.priceToCoordinate(this.aT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),a=Math.min(n,r),o=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner4":t>=h&&t<=l&&i>=a&&i<=o?"body":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,"body"===t&&(this.UC={gt:this.aT.time1,bt:this.aT.price1},this.qC={gt:this.aT.time2,bt:this.aT.price2})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null}updateDrag(t,i){if(!this.$C||!this.HC)return;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=s<(Kn(this._chart,this._series,this.aT.time2)??0),r=n<(this._series.priceToCoordinate(this.aT.price2)??0);if("body"===this.HC&&this.UC&&this.qC){const s=rl(this.NC,t,i);this.aT.time1=this.UC.gt+s.gt,this.aT.price1=this.UC.bt+s.bt,this.aT.time2=this.qC.gt+s.gt,this.aT.price2=this.qC.bt+s.bt}else switch(this.HC){case"corner1":e&&r?(this.aT.time1=t,this.aT.price1=i):!e&&r?(this.aT.time2=t,this.aT.price1=i):e&&!r?(this.aT.time1=t,this.aT.price2=i):(this.aT.time2=t,this.aT.price2=i);break;case"corner2":e&&r?(this.aT.time2=t,this.aT.price1=i):!e&&r?(this.aT.time1=t,this.aT.price1=i):e&&!r?(this.aT.time2=t,this.aT.price2=i):(this.aT.time1=t,this.aT.price2=i);break;case"corner3":e&&r?(this.aT.time1=t,this.aT.price2=i):!e&&r?(this.aT.time2=t,this.aT.price2=i):e&&!r?(this.aT.time1=t,this.aT.price1=i):(this.aT.time2=t,this.aT.price1=i);break;case"corner4":e&&r?(this.aT.time2=t,this.aT.price2=i):!e&&r?(this.aT.time1=t,this.aT.price2=i):e&&!r?(this.aT.time2=t,this.aT.price1=i):(this.aT.time1=t,this.aT.price1=i)}this.dM(),this.aT.onUpdate&&this.aT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[al(this.aT.price1??0,ll(this.aT.time1)),al(this.aT.price2??0,ll(this.aT.time2))],style:{fillColor:this.aT.fillColor,fillOpacity:this.aT.fillOpacity,borderColor:this.aT.borderColor,borderWidth:this.aT.borderWidth,borderStyle:this.aT.borderStyle,showLabel:this.aT.showLabel,labelText:this.aT.labelText,labelPosition:this.aT.labelPosition}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.aT.onRemove&&this.aT.onRemove()}}function da(t,i){return new ca(t,i)}class pa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class fa{constructor(t){this.BC=t,this.Jt=new pa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class va extends cl{constructor(t,i){super(t,"circle",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this._T={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this._T),this.aS(),this._T.interactive&&!this._T.centerTime&&this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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._T.centerTime){const t=this._chart.timeScale().timeToCoordinate(this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=Kn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this._T.radiusTime=Math.abs(e-t),this._T.radiusPrice=Math.abs(r-n),this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this._T.onUpdate&&this._T.onUpdate()}else this._T.centerTime=i,this._T.centerPrice=s,this.dM()},this.np=t=>{if(this.eT&&this._T.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new fa(this)}drawToCanvas(t,i,s){if(!this._T.centerTime||void 0===this._T.centerPrice)return;const n=(Kn(this._chart,this._series,this._T.centerTime)??0)*i,e=(this._series.priceToCoordinate(this._T.centerPrice)??0)*s;let r,h;if(this.eT&&this.XC){const t=(Kn(this._chart,this._series,this.XC.gt)??0)*i,l=(this._series.priceToCoordinate(this.XC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this._T.radiusTime||void 0===this._T.radiusPrice)return;r=this._T.radiusTime*i,h=this._T.radiusPrice*s}if(this._T.fillOpacity>0){const i=this.hS(this._T.fillColor,this.eT?.05:this._T.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this._T.borderColor,a=this.WC?this._T.borderWidth+1:this._T.borderWidth;t.strokeStyle=l,t.lineWidth=a*i,"dashed"===this._T.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this._T.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.WC&&!this.zC||this.eT||this.isLocked()||this.uT(t,n,e,i,l),!this.WC&&!this.zC||this.eT||this.isLocked()||this.cT(t,n,e,r,h,i,l),this._T.showLabel&&this._T.labelText&&!this.eT&&this.uP(t,n,e,i,l)}uT(t,i,s,n,e){const r=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r/2,0,2*Math.PI),t.fill(),t.stroke()}cT(t,i,s,n,e,r,h){const l=8*r,a=[{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 a)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}uP(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._T.labelText).width,a=h,o=i-l/2-r,_=s-a/2-r;t.fillStyle=e,t.fillRect(o,_,l+2*r,a+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this._T.labelText,o+r,_+r)}hS(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._T.borderColor=t,this._T.fillColor=t,this.dM()}color(){return this._T.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this._T.centerTime||void 0===this._T.radiusTime)return!1;const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=(t-s)/this._T.radiusTime,r=(i-n)/this._T.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this._T.centerTime||void 0===this._T.radiusTime)return null;const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=this._T.radiusTime,r=this._T.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.$C=!0,this.HC=t,this.NC=i,this.kP="center"===t?{gt:this._T.centerTime,bt:this._T.centerPrice}:null}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C&&this.HC){if("center"===this.HC&&this.kP){const s=rl(this.NC,t,i);this._T.centerTime=this.kP.gt+s.gt,this._T.centerPrice=this.kP.bt+s.bt}else if("edge"===this.HC){const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=Kn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this._T.radiusTime=Math.abs(e-s),this._T.radiusPrice=Math.abs(r-n)}this.dM(),this._T.onUpdate&&this._T.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[al(this._T.centerPrice??0,ll(this._T.centerTime))],style:{fillColor:this._T.fillColor,fillOpacity:this._T.fillOpacity,borderColor:this._T.borderColor,borderWidth:this._T.borderWidth,borderStyle:this._T.borderStyle,showLabel:this._T.showLabel,labelText:this._T.labelText},extra:{radiusTime:this._T.radiusTime,radiusPrice:this._T.radiusPrice}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this._T.onRemove&&this._T.onRemove()}}function ma(t,i){return new va(t,i)}class wa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ga{constructor(t){this.BC=t,this.Jt=new wa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ba extends cl{constructor(t,i){super(t,"arrow",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.dT=-1,this.eT=!1,this.bx=null,this.pT=null,this.np=null,this.XC=null,this.fT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.fT),this.aS(),!this.fT.interactive||this.fT.points&&0!==this.fT.points.length||this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.fT.points||(this.fT.points=[]),this.fT.points.push({time:i,price:s}),this.dM(),this.fT.onUpdate&&this.fT.onUpdate())},this.np=t=>{if(this.eT)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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this.pT=t=>{this.eT&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.pT)}finishDrawing(){if(this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.pT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.pT),this.pT=null}this.eT=!1,this.XC=null,this.dM(),this.fT.onComplete&&this.fT.onComplete()}isDrawing(){return this.eT}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ga(this)}drawToCanvas(t,i,s){if(!this.fT.points||0===this.fT.points.length)return;const n=this.fT.lineColor,e=this.WC||this.zC&&!this.isLocked()?this.fT.lineWidth+1:this.fT.lineWidth,r=[];for(const t of this.fT.points)try{let n=Kn(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.eT)return;let h=null;if(this.eT&&this.XC&&this.fT.points.length>0){h={ut:(Kn(this._chart,this._series,this.XC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.XC.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.fT.showArrowHead&&r.length>1&&this.vT(t,r[r.length-2],r[r.length-1],i,n),this.fT.showCircles)for(let s=0;s<r.length;s++)this.mT(t,r[s].ut,r[s].ct,i,n,0===s)}vT(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)},a={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(a.ut,a.ct),t.closePath(),t.fill()}mT(t,i,s,n,e,r){const h=this.fT.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.fT.lineColor=t,this.dM()}color(){return this.fT.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.fT.points||0===this.fT.points.length)return!1;for(let s=0;s<this.fT.points.length-1;s++)try{const n=this.fT.points[s],e=this.fT.points[s+1];let r=Kn(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=Kn(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),a=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===a)continue;if(this.lP(t,i,r,l,h,a)<=8)return!0}catch{continue}for(const s of this.fT.points)try{let n=Kn(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}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.fT.points||0===this.fT.points.length)return null;for(let s=0;s<this.fT.points.length;s++)try{const n=this.fT.points[s];let e=Kn(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.$C=!0,this.dT=t}stopDrag(){this.$C=!1,this.dT=-1}updateDrag(t,i){this.$C&&-1!==this.dT&&this.fT.points&&this.dT>=0&&this.dT<this.fT.points.length&&(this.fT.points[this.dT]={time:t,price:i},this.dM(),this.fT.onUpdate&&this.fT.onUpdate())}getPoints(){return this.fT.points||[]}addPoint(t){this.fT.points||(this.fT.points=[]),this.fT.points.push(t),this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.fT.points||[]).map(t=>ol(t)),style:{lineColor:this.fT.lineColor,lineWidth:this.fT.lineWidth,showArrowHead:this.fT.showArrowHead,showCircles:this.fT.showCircles,circleRadius:this.fT.circleRadius}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){if(this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.pT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.pT),this.pT=null}this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.fT.onRemove&&this.fT.onRemove()}}function Ma(t,i){return new ba(t,i)}class ya{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Sa{constructor(t){this.BC=t,this.Jt=new ya(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class xa extends cl{constructor(t,i){super(t,"brush",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.wT=!1,this.eT=!1,this.gT=[],this.bT=!1,this.Df=null,this.IS=null,this.WS=null,this.$S=null,this.NS=null,this.MT=void 0,this.BS=null,this.$C=!1,this.NC=null,this.fP=null,this.yT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.yT),this.aS(),0===(this.yT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.wT)return;const t=this._chart.chartElement();t&&(this.Df=t,this.wT=!0,this.WS=t=>this.zS(t),this.$S=t=>this.HS(t),this.NS=()=>this.US(),this.BS=t=>{this.MT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.BS),t.addEventListener("pointerdown",this.WS,!0),t.addEventListener("pointermove",this.$S,!0),t.addEventListener("pointerup",this.NS,!0),t.addEventListener("pointercancel",this.NS,!0))}stopDrawingMode(){if(!this.wT)return;this.ST(),this.wT=!1;const t=this.Df;t&&(this.WS&&t.removeEventListener("pointerdown",this.WS,!0),this.$S&&t.removeEventListener("pointermove",this.$S,!0),this.NS&&(t.removeEventListener("pointerup",this.NS,!0),t.removeEventListener("pointercancel",this.NS,!0))),this.BS&&(this._chart.unsubscribeCrosshairMove(this.BS),this.BS=null),this.WS=null,this.$S=null,this.NS=null,this.Df=null}isDrawingModeActive(){return this.wT}zS(t){if(this.xT())return;const i=this.CT(t,!1);null!==i&&(this.eT=!0,this.gT=[i],this.IS=t.pointerId,pl(this._chart,!0),this.Df?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.PT())}HS(t){if(!this.eT)return;const i=this.CT(t,!0);if(null===i)return;const s=this.gT[this.gT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.yT.sampleDistance??4)||(this.gT.push(i),t.preventDefault(),t.stopPropagation(),this.PT())}US(){this.eT&&this.ST()}ST(){if(!this.eT)return;this.eT=!1,this.hx();const t=[];for(const i of this.gT){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.gT=[],t.length<2?this.dM():(this.yT.points=t,this.stopDrawingMode(),this.dM(),this.yT.onUpdate&&this.yT.onUpdate(),this.yT.onComplete&&this.yT.onComplete())}xT(){const t=this.MT;return"string"==typeof t&&t.split("#")[0]!==this.id}hx(){null!==this.IS&&(this.Df&&this.Df.hasPointerCapture(this.IS)&&this.Df.releasePointerCapture(this.IS),this.IS=null)}CT(t,i){const s=this.TT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Xx;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}TT(){const t=this.kT();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,Xx:i.top,ts:n,qt:i.height}}kT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}PT(){this.bT||(this.bT=!0,requestAnimationFrame(()=>{this.bT=!1,this.dM()}))}drawToCanvas(t,i,s){const n=this.eT?this.gT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.DT(i,s);if(0===n.length)return;const e=this.WC;if(t.strokeStyle=this.yT.color,t.lineWidth=(this.yT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.yT.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.zC||this.isLocked()||(this.hP(t,n[0],i),this.hP(t,n[n.length-1],i))}hP(t,i,s){t.fillStyle=this.yT.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()}DT(t,i){const s=this.yT.points??[],n=[];for(const e of s){const s=Kn(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.DT(1,1);for(let n=1;n<s.length;n++)if(Ca(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.$C=!0,this.NC=i,this.fP=(this.yT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.fP;if(!this.$C||null===s||!this.yT.points)return;const n=rl(this.NC,t,i);this.yT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.dM(),this.yT.onUpdate&&this.yT.onUpdate()}stopDrag(){this.$C=!1,this.NC=null,this.fP=null}setColor(t){this.yT.color=t,this.dM()}color(){return this.yT.color??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}aS(){this.eh=new Sa(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):null}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.stopDrawingMode(),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null),this.eh=null,this.yT.onRemove&&this.yT.onRemove()}_serializeShape(){return{type:"brush",points:(this.yT.points??[]).map(ol),style:{color:this.yT.color,lineWidth:this.yT.lineWidth,smoothing:this.yT.smoothing}}}getPoints(){return this.yT.points??[]}}function Ca(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 Pa(t,i={}){return new xa(t,i)}class Ta{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ka{constructor(t){this.BC=t,this.Jt=new Ta(t)}renderer(){return this.BC.isComplete()?this.Jt:null}}class Da extends cl{constructor(t,i){super(t,"text-tool",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.RT=!1,this.FT=null,this.IT={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.IT),this.aS(),this.VT()}VT(){const t=t=>{if(!this.RT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.IT.text&&""!==this.IT.text.trim()&&"Type here..."!==this.IT.text||this.remove())};this.FT=t,this._chart.subscribeClick(t)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ka(this)}getTime(){return this.IT.time}getPrice(){return this.IT.price}getText(){return this.IT.text||""}getOptions(){return this.IT}setPosition(t,i){this.IT.time=t,this.IT.price=i,this._update()}setText(t){this.IT.text=t,this._update(),this.IT.onTextChange&&this.IT.onTextChange(t)}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!(!this.IT.time||void 0===this.IT.price)}setColor(t){this.IT.textColor=t,this.IT.borderColor=t,this.dM()}color(){return this.IT.textColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this._update())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this._update())}isHovered(){return this.zC}setEditing(t){this.RT!==t&&(this.RT=t,this._update())}isEditing(){return this.RT}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.IT.time,n=this.IT.price,e=Kn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.IT.fontSize||14,l=this.IT.padding||8,a=this.IT.text||"",o=.6*h,_=Math.min(a.length*o,this.IT.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.IT.time,n=this.IT.price,e=Kn(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.$C=!0,this.HC=t,this.NC=i,this.kP={gt:this.IT.time,bt:this.IT.price}}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C){if("body"===this.HC&&this.kP){const s=rl(this.NC,t,i);this.setPosition(this.kP.gt+s.gt,this.kP.bt+s.bt)}else this.setPosition(t,i);this.IT.onUpdate&&this.IT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.IT.time,e=this.IT.price,r=this.IT.text||"",h=(Kn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,a=(this.IT.fontSize||14)*i,o=(this.IT.padding||8)*i,_=(this.IT.maxWidth||200)*i;t.font=`${a}px ${this.IT.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*o,v=1.2*a,m=c.length*v+2*o,w=this.IT.backgroundOpacity||.8,g=this.IT.backgroundColor||"#2962FF";t.fillStyle=this.hS(g,w),t.fillRect(h,l,f,m),(this.WC||this.zC)&&(t.strokeStyle=this.IT.borderColor??"#FFFFFF",t.lineWidth=(this.IT.borderWidth||1)*i*(this.WC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.IT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+o;if("center"===this.IT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.IT.textAlign){n=h+f-t.measureText(s).width-o}const e=l+o+i*v;t.fillText(s,n,e)}if((this.WC||this.zC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.IT.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()}}hS(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:[al(this.IT.price??0,ll(this.IT.time))],style:{fontSize:this.IT.fontSize,fontFamily:this.IT.fontFamily,textColor:this.IT.textColor,backgroundColor:this.IT.backgroundColor,backgroundOpacity:this.IT.backgroundOpacity,padding:this.IT.padding,borderColor:this.IT.borderColor,borderWidth:this.IT.borderWidth,textAlign:this.IT.textAlign,maxWidth:this.IT.maxWidth},extra:{text:this.IT.text}}}remove(){this.FT&&(this._chart.unsubscribeClick(this.FT),this.FT=null),this.qb&&this._series&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.IT.onRemove&&this.IT.onRemove()}}function Ra(t,i){return new Da(t,i)}class Fa{constructor(t){this.LT=t}calculatePips(t,i){return Math.abs(i-t)/this.LT.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.LT={...this.LT,...t}}getPipConfig(){return{...this.LT}}}function Ia(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 Va(t,i){return"number"==typeof t?Ia(t):void 0!==i?Ia(i):{pipValue:.1,decimals:1}}class La{constructor(t){this.LT=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.LT.pipValue,timeDifference:this.AT(t,s),barCount:e}}AT(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.LT={...this.LT,...t}}getPipConfig(){return{...this.LT}}}class Aa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ea{constructor(t){this.BC=t,this.Jt=new Aa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class Ba extends cl{constructor(t,i){super(t,"ruler-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.GP=null,this.jC=!1,this.WC=!1,this.zC=!1,this.XC=null,this.$C=!1,this.KP=null,this.np=null,this.ET={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.ET);const s=this.ET.pipConfig||Va(this.ET.symbol||"DEFAULT");this.JP=new La(s),this.aS(),this.ET.interactive?this.KC():this.ET.point1Time&&this.ET.point2Time&&(this.jC=!0,this.QP())}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ea(this)}KC(){this.GP=new wl(this._chart,this._series,{VC:t=>{this.ET.point1Time=t.gt,this.ET.point1Price=t.bt,this.dM()},LC:t=>{this.ET.point2Time=t.gt,this.ET.point2Price=t.bt},AC:(t,i)=>{this.ET.point1Time=t.gt,this.ET.point1Price=t.bt,this.ET.point2Time=i.gt,this.ET.point2Price=i.bt,this.jC=!0,this.XC=null,this.QP(),this.tT(),this.dM()},EC:t=>{this.XC=t,this.dM()}}),this.GP.yC()}drawToCanvas(t,i,s){if(!this.jC&&this.ET.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return;const n=(Kn(this._chart,this._series,this.ET.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ET.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.ET.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.ET.point2Price)??0)*s;(this.WC||this.zC&&!this.isLocked())&&(t.strokeStyle=this.ET.selectionColor,t.lineWidth=this.ET.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.BT(t,n,e,r,h,i),this.hP(t,n,e,i),this.hP(t,r,h,i),this.ET.showLabel&&this.Xb&&this.uP(t,n,e,r,h,i,s)}BT(t,i,s,n,e,r){const h=this.ET.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.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()}hP(t,i,s,n){const e=this.WC?this.ET.selectionColor:this.ET.lineColor,r=this.WC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.WC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}rP(t,i,s){if(!this.ET.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.ET.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ET.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s;t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.hP(t,n,e,i),t.globalAlpha=.5,this.hP(t,r,h,i),t.globalAlpha=1}uP(t,i,s,n,e,r,h){if(!this.Xb)return;const l=(i+n)/2,a=(s+e)/2,o=this.ET.measure??"both",_=[];"time"!==o&&(_.push(this.JP.formatPips(this.Xb.pips)),_.push(this.JP.formatPercent(this.Xb.pricePercent))),"price"!==o&&_.push(this.JP.formatBarCount(this.Xb.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.ET.labelBackgroundColor,t.fillRect(l-d/2,a-p/2,d,p),t.fillStyle=this.ET.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,a)}QP(){if(!this.ET.point1Time||!this.ET.point2Time||void 0===this.ET.point1Price||void 0===this.ET.point2Price)return;const t=this.OT();this.Xb=this.JP.calculateMetrics(this.ET.point1Time,this.ET.point1Price,this.ET.point2Time,this.ET.point2Price,t),this.ET.onUpdate&&this.Xb&&this.ET.onUpdate(this.Xb)}OT(){if(!this.ET.point1Time||!this.ET.point2Time)return 0;const t=Kn(this._chart,this._series,this.ET.point1Time),i=Kn(this._chart,this._series,this.ET.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.ET.point1Time=t,this.ET.point1Price=i,this.ET.point2Time=s,this.ET.point2Price=n,this.QP(),this.dM()}getMetrics(){return this.Xb}remove(){this.destroy()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GP&&(this.GP.m(),this.GP=null),this.sT(),this.ET.onRemove&&this.ET.onRemove()}tT(){this.np=t=>{this.iT(t)},this._chart.subscribeCrosshairMove(this.np)}sT(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}iT(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.WC||!this.$C)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.KP?(this.ET.point1Time=i,this.ET.point1Price=s):"point2"===this.KP&&(this.ET.point2Time=i,this.ET.point2Price=s),this.QP(),this.dM())}startDrag(t){this.$C=!0,this.KP=t}stopDrag(){this.$C=!1,this.KP=null}updateDrag(t,i){this.$C&&this.KP&&("point1"===this.KP?(this.ET.point1Time=t,this.ET.point1Price=i):(this.ET.point2Time=t,this.ET.point2Price=i),this.QP(),this.dM())}hitTestEndpoint(t,i){if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return null;const s=Kn(this._chart,this._series,this.ET.point1Time)??0,n=this._series.priceToCoordinate(this.ET.point1Price)??0,e=Kn(this._chart,this._series,this.ET.point2Time)??0,r=this._series.priceToCoordinate(this.ET.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}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.QP(),this.dM()}_serializeShape(){return{type:"ruler",points:[al(this.ET.point1Price??0,ll(this.ET.point1Time)),al(this.ET.point2Price??0,ll(this.ET.point2Time))],style:{lineColor:this.ET.lineColor,lineWidth:this.ET.lineWidth,showLabel:this.ET.showLabel,labelBackgroundColor:this.ET.labelBackgroundColor,labelTextColor:this.ET.labelTextColor,selectionColor:this.ET.selectionColor,selectionLineWidth:this.ET.selectionLineWidth},extra:{symbol:this.ET.symbol,pipConfig:this.ET.pipConfig,measure:this.ET.measure}}}setColor(t){this.ET.lineColor=t,this.dM()}color(){return this.ET.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isSelected(){return this.WC}isComplete(){return this.jC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return!1;const s=Kn(this._chart,this._series,this.ET.point1Time)??0,n=this._series.priceToCoordinate(this.ET.point1Price)??0,e=Kn(this._chart,this._series,this.ET.point2Time)??0,r=this._series.priceToCoordinate(this.ET.point2Price)??0;return this.WT(t,i,s,n,e,r)<=(this.WC?12:8)}WT(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;let o,_,u=-1;0!==a&&(u=((t-s)*h+(i-n)*l)/a),u<0?(o=s,_=n):u>1?(o=e,_=r):(o=s+u*h,_=n+u*l);const c=t-o,d=i-_;return Math.sqrt(c*c+d*d)}}function Oa(t,i){return new Ba(t,i)}class Wa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class za{constructor(t){this.BC=t,this.Jt=new Wa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class $a extends cl{constructor(t,i){super(t,"position-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.zT=null,this.$T=null,this.HT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.HT);const s=this.HT.pipConfig||Va(this.HT.entryPrice);this.JP=new Fa(s),this.aS(),this.QP()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new za(this)}drawToCanvas(t,i,s){if(this.zT&&this.HT.takeProfit){const n=this._chart.timeScale();this.NT(t,this.zT,i,s,n),(this.zC||this.WC)&&this.uP(t,this.zT,"profit",i,s,n)}if(this.$T&&this.HT.stopLoss){const n=this._chart.timeScale();if(this.NT(t,this.$T,i,s,n),this.zC||this.WC){const n=this._chart.timeScale();this.uP(t,this.$T,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.UT(t,i,s,n),this.HT.takeProfit){const n=this._chart.timeScale();this.hP(t,this.HT.takeProfit,this.HT.profitColor,i,s,n)}if(this.HT.stopLoss){const n=this._chart.timeScale();this.hP(t,this.HT.stopLoss,this.HT.lossColor,i,s,n)}}NT(t,i,s,n,e){const r=(Kn(this._chart,this._series,this.HT.entryTime)??0)*s;let h;if(this.HT.endTime)h=(Kn(this._chart,this._series,this.HT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.qT)??0)*n,a=(this._series.priceToCoordinate(i.jT)??0)*n;t.fillStyle=this.hS(i.R,.15),t.fillRect(r,Math.min(l,a),h-r,Math.abs(a-l)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(r,a),t.lineTo(h,a),t.stroke()}UT(t,i,s,n){const e=(Kn(this._chart,this._series,this.HT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.HT.entryPrice)??0)*s;let h;if(this.HT.endTime)h=(Kn(this._chart,this._series,this.HT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.HT.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.HT.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,a),t.stroke(),t.setLineDash([]),!this.WC&&!this.zC||this.isLocked())t.fillStyle=this.HT.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)}}QP(){this.HT.stopLoss&&this.HT.takeProfit&&(this.Xb=this.JP.calculateMetrics(this.HT.entryPrice,this.HT.stopLoss,this.HT.takeProfit,this.HT.quantity),this.YT(),this.HT.onUpdate&&this.Xb&&this.HT.onUpdate(this.Xb))}YT(){const t=this.XT();this.HT.takeProfit&&(this.zT={GT:this.HT.entryTime,KT:t,qT:this.HT.entryPrice,jT:this.HT.takeProfit,R:this.HT.profitColor,Vy:this.HT.opacity}),this.HT.stopLoss&&(this.$T={GT:this.HT.entryTime,KT:t,qT:this.HT.entryPrice,jT:this.HT.stopLoss,R:this.HT.lossColor,Vy:this.HT.opacity})}XT(){this._chart.timeScale().getVisibleLogicalRange();return this.HT.entryTime}uP(t,i,s,n,e,r){if(!this.Xb)return;const h=(Kn(this._chart,this._series,this.HT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.jT)??0)*e,a="profit"===s,o=a?this.Xb.takeProfitPips:this.Xb.stopLossPips,_=a?this.HT.takeProfit:this.HT.stopLoss,u=this.Xb.riskRewardRatio,c=a?`Objetivo: ${_?.toFixed(5)} (${o.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${o.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.R,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}hP(t,i,s,n,e,r){const h=(Kn(this._chart,this._series,this.HT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,a=s;let o;if(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(h,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this.HT.endTime)o=(Kn(this._chart,this._series,this.HT.endTime)??0)*n;else{o=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-_/2,l-_/2,_,_),t.strokeRect(o-_/2,l-_/2,_,_)}hS(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.HT={...this.HT,...t},this.QP(),this._update()}getMetrics(){return this.Xb}setStopLoss(t){this.HT.stopLoss=t,this.QP(),this._update()}setTakeProfit(t){this.HT.takeProfit=t,this.QP(),this._update()}setEntryPrice(t){this.HT.entryPrice=t,this.QP(),this._update()}_serializeShape(){return{type:"position",points:[al(this.HT.entryPrice,ll(this.HT.entryTime))],style:{profitColor:this.HT.profitColor,lossColor:this.HT.lossColor,entryLineColor:this.HT.entryLineColor,opacity:this.HT.opacity,showTooltips:this.HT.showTooltips},extra:{endTime:ll(this.HT.endTime),stopLoss:this.HT.stopLoss,takeProfit:this.HT.takeProfit,quantity:this.HT.quantity,pipConfig:this.HT.pipConfig}}}setColor(t){this.HT.entryLineColor=t,this.dM()}color(){return this.HT.entryLineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.HT.stopLoss&&!this.HT.takeProfit)return!1;const s=Kn(this._chart,this._series,this.HT.entryTime)??0;let n;if(this.HT.endTime)n=Kn(this._chart,this._series,this.HT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.HT.takeProfit&&this.HT.stopLoss){const e=this._series.priceToCoordinate(this.HT.takeProfit)??0,r=this._series.priceToCoordinate(this.HT.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=h&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Kn(this._chart,this._series,this.HT.entryTime)??0;let n;if(this.HT.endTime)n=Kn(this._chart,this._series,this.HT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.HT.takeProfit){const n=this._series.priceToCoordinate(this.HT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.HT.stopLoss){const n=this._series.priceToCoordinate(this.HT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.HT.takeProfit){const s=this._series.priceToCoordinate(this.HT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.HT.stopLoss){const s=this._series.priceToCoordinate(this.HT.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.HT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.HT.takeProfit&&this.HT.stopLoss){const e=this._series.priceToCoordinate(this.HT.takeProfit)??0,r=this._series.priceToCoordinate(this.HT.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.$C=!0,this.HC=t,this.NC=i,"move"===t&&(this.kP={ZT:this.HT.entryPrice,JT:this.HT.entryTime??null,rS:this.HT.endTime??null,QT:this.HT.takeProfit??null,tk:this.HT.stopLoss??null})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C&&this.HC){if("entry"===this.HC)this.HT.entryPrice=i;else if("move"===this.HC){if(this.kP){const s=rl(this.NC,t,i),n=this.kP;this.HT.entryPrice=n.ZT+s.bt,null!==n.QT&&(this.HT.takeProfit=n.QT+s.bt),null!==n.tk&&(this.HT.stopLoss=n.tk+s.bt),null!==n.JT&&(this.HT.entryTime=this.ik(n.JT,s.gt)),null!==n.rS&&(this.HT.endTime=this.ik(n.rS,s.gt))}}else"tp"===this.HC||"tp-right"===this.HC?(this.HT.takeProfit=i,"tp-right"===this.HC?this.HT.endTime=t:this.HT.entryTime=t):"sl"!==this.HC&&"sl-right"!==this.HC||(this.HT.stopLoss=i,"sl-right"===this.HC?this.HT.endTime=t:this.HT.entryTime=t);this.QP(),this.dM()}}ik(t,i){return t+i}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.HT.onRemove&&this.HT.onRemove()}}function Ha(t,i){return new $a(t,i)}class Na{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ua{constructor(t){this.BC=t,this.Jt=new Na(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class qa extends cl{constructor(t,i){super(t,"gantt",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.sk=-1,this.NC=null,this.kP=null,this.nk=-1,this.ek={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.ek),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ua(this)}drawToCanvas(t,i,s){if(!this.ek.segments||0===this.ek.segments.length)return;const n=50*s,e=this.ek.rowHeight*s,r=this.ek.rowSpacing*s;this.ek.showGrid&&this.nm(t,n,e,r,i,s),this.ek.segments.forEach((s,h)=>{const l=(Kn(this._chart,this._series,s.startTime)??0)*i,a=(Kn(this._chart,this._series,s.endTime)??0)*i,o=n+s.level*(e+r),_=h===this.nk||this.zC&&!this.isLocked();this.rk(t,l,a,o,e,s,_,i)})}nm(t,i,s,n,e,r){if(!this.ek.segments)return;const h=Math.max(...this.ek.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()}}rk(t,i,s,n,e,r,h,l){const a=s-i,o=this.hS(r.color,h?this.ek.fillOpacity+.2:this.ek.fillOpacity);t.fillStyle=o,t.fillRect(i,n,a,e),t.strokeStyle=r.color;const _=this.ek.borderWidth+(this.WC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,a,e),this.ek.showLabels&&r.label&&this.uP(t,i,n,a,e,r.label,l)}uP(t,i,s,n,e,r,h){const l=11*h,a=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let o=r;const _=n-2*a;let u=t.measureText(o).width;if(u>_&&_>0){for(;u>_&&o.length>0;)o=o.slice(0,-1),u=t.measureText(o+"...").width;o+="..."}t.fillText(o,i+a,s+e/2)}hS(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.ek.segments||(this.ek.segments=[]),this.ek.segments.push(t),this.dM(),this.ek.onUpdate&&this.ek.onUpdate()}removeSegment(t){this.ek.segments&&t>=0&&t<this.ek.segments.length&&(this.ek.segments.splice(t,1),this.dM(),this.ek.onUpdate&&this.ek.onUpdate())}getSegments(){return this.ek.segments||[]}setColor(t){const i=this.ek.segments??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.ek.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.ek.segments?.[this.nk];s&&(this.$C=!0,this.sk=this.nk,this.NC=i,this.kP={eS:s.startTime,rS:s.endTime})}updateDrag(t,i){const s=this.ek.segments?.[this.sk];if(!this.$C||!this.kP||!s)return;const n=rl(this.NC,t,i);s.startTime=this.kP.eS+n.gt,s.endTime=this.kP.rS+n.gt,this.dM(),this.ek.onUpdate&&this.ek.onUpdate()}stopDrag(){this.$C=!1,this.sk=-1,this.NC=null,this.kP=null}hitTest(t,i){if(!this.ek.segments||0===this.ek.segments.length)return!1;const s=this.ek.rowHeight,n=this.ek.rowSpacing;for(let e=0;e<this.ek.segments.length;e++){const r=this.ek.segments[e],h=Kn(this._chart,this._series,r.startTime)??0,l=Kn(this._chart,this._series,r.endTime)??0,a=50+r.level*(s+n);if(t>=h&&t<=l&&i>=a&&i<=a+s)return this.nk=e,!0}return this.nk=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.ek.rowHeight,rowSpacing:this.ek.rowSpacing,fillOpacity:this.ek.fillOpacity,borderWidth:this.ek.borderWidth,showLabels:this.ek.showLabels,showGrid:this.ek.showGrid},extra:{segments:(this.ek.segments||[]).map(t=>({eS:ll(t.startTime),rS:ll(t.endTime),sn:t.level,Jl:t.label,R:t.color,hk:t.category}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.ek.onRemove&&this.ek.onRemove()}}function ja(t,i){return new qa(t,i)}class Ya{constructor(t,i,s={}){this.lk=[],this.ak=[],this._k=[],this.uk=!1,this.ck=new Map,this.dk=null,this.pk=null,this.fk=null,this.bx=null,this.vk=null,this.np=null,this.mk=null,this.wk=null,this.gk=null,this.bk=null,this.Mk=null,this.IS=null,this.yk=!1,this.Sk=null,this.xk=null,this.Ck=new o,this.$C=!1,this.Pk=null,this.Tk=new Set,this.kk=null,this.Dk=new o,this.Vf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Rk()}startDrawing(t){this.fk=t,this.Fk()}activeDrawingType(){return this.fk}stopDrawing(){this.fk=null}addTool(t,i){const s=i??t.id;return this.ck.set(s,t),t.isComplete()||this.Tk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Tk.size>0}cancelPendingDrawings(){if(0===this.Tk.size)return 0;let t=0;for(const i of Array.from(this.Tk)){const s=this.ck.get(i);s&&(this.dk===i&&this.Ik(null),s.remove(),this.ck.delete(i),t++)}return this.Tk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Dk.i(t)}unsubscribeDrawingCompleted(t){this.Dk._(t)}Vk(){0!==this.Tk.size&&null===this.kk&&(this.kk=setTimeout(()=>{this.kk=null;for(const t of Array.from(this.Tk)){const i=this.ck.get(t);i?i.isComplete()&&(this.Tk.delete(t),this.Dk.p(t)):this.Tk.delete(t)}},0))}removeTool(t){const i=this.ck.get(t);return!!i&&(this.dk===t&&this.Ik(null),i.remove(),this.ck.delete(t),this.Tk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.ck.has(t)&&(this.Ik(t),!0)}Ik(t){if(this.dk===t)return;const i=null===this.dk?void 0:this.ck.get(this.dk);i&&i.setSelected(!1),this.dk=t;const s=null===t?void 0:this.ck.get(t);s&&s.setSelected(!0),this.Lk()}recordChange(){this.uk||(this.lk.push(this._k),this.lk.length>100&&this.lk.shift(),this.ak=[],this._k=this.serializeAll())}canUndo(){return this.lk.length>0}canRedo(){return this.ak.length>0}undo(){const t=this.lk.pop();return void 0!==t&&(this.ak.push(this._k),this.Ak(t),!0)}redo(){const t=this.ak.pop();return void 0!==t&&(this.lk.push(this._k),this.Ak(t),!0)}Ak(t){this.uk=!0;try{this.restoreAll({chart:this.Vf,series:this.be},t,!0),this._k=t}finally{this.uk=!1}}subscribeSelectionChanged(t){this.Ck.i(t)}unsubscribeSelectionChanged(t){this.Ck._(t)}selectionBounds(){if(null===this.dk)return null;const t=this.ck.get(this.dk);return t?this.Ek(t):null}Ek(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=Kn(this.Vf,i,t.time),a=i.priceToCoordinate(t.price);null!==s&&null!==a&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,a),h=Math.max(h,a))}if(!l)return null;const a=this.Bk(t);return{left:n+a.ut,right:r+a.ut,top:e+a.ct,bottom:h+a.ct}}Bk(t){const i=this.Vf.chartElement(),s=this.Ok(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}}Lk(){this.Ck.p({id:this.dk,bounds:this.selectionBounds()})}deselectAll(){this.Fk()}deleteSelected(){if(this.dk){const t=this.ck.get(this.dk);return(!t||!t.isLocked())&&this.removeTool(this.dk)}return!1}getSelectedToolId(){return this.dk}getAllTools(){return new Map(this.ck)}getTool(t){return this.ck.get(t)}clearAll(){this.Ik(null),this.ck.forEach(t=>t.remove()),this.ck.clear(),this.Tk.clear(),this.recordChange()}getToolCount(){return this.ck.size}isToolSelected(t){return this.dk===t}serializeAll(){const t=[];for(const i of this.ck.values())t.push(i.serialize());return t}restoreTool(t,i){const s=Ya.Wk(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 Wk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({zk:_l(n[t]),$k:ul(n[t],"price")??0});switch(s){case"trendLine":return yl(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,...e});case"horizontalLine":return Pl(t,{price:h(0).$k,startTime:h(0).zk??void 0,...e});case"parallelChannel":return Ol(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,channelWidth:r?.channelWidth,...e});case"pitchfork":return Hl(t,{pivotTime:h(0).zk,pivotPrice:h(0).$k,upperTime:h(1).zk,upperPrice:h(1).$k,lowerTime:h(2).zk,lowerPrice:h(2).$k,...e});case"polygon":return Ll(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).zk,s.price=h(i).$k,s}),...e});case"crossLine":return Rl(t,{time:h(0).zk,price:h(0).$k,...e});case"verticalLine":return jl(t,{time:h(0).zk,...e});case"fibRetracement":return ta(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return ea(t,{point1:i.zk?{time:i.zk,price:i.$k}:void 0,point2:s.zk?{time:s.zk,price:s.$k}:void 0,point3:n.zk?{time:n.zk,price:n.$k}:void 0,levels:r?.levels,...e})}case"fibFan":return oa(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,levels:r?.levels,...e});case"rectangle":return da(t,{time1:h(0).zk,price1:h(0).$k,time2:h(1).zk,price2:h(1).$k,...e});case"circle":return ma(t,{centerTime:h(0).zk,centerPrice:h(0).$k,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Ma(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Pa(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Ra(t,{time:h(0).zk,price:h(0).$k,text:r?.text,...e});case"ruler":return Oa(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return Ha(t,{entryPrice:h(0).$k,entryTime:h(0).zk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return ja(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.kk&&(clearTimeout(this.kk),this.kk=null),this.Dk.m(),this.Ck.m(),this.clearAll(),this.Hk(),this.lk=[],this.ak=[],this._k=[]}Rk(){this.bx=t=>{this.FC(t)},this.Vf.subscribeClick(this.bx),this.np=t=>{this.IC(t)},this.Vf.subscribeCrosshairMove(this.np);const t=this.Vf.chartElement();t&&(this.mk=t=>this.Nk(t),this.wk=t=>this.Uk(t),this.gk=t=>this.Uk(t),this.bk=t=>this.qk(t),t.addEventListener("pointerdown",this.mk),t.addEventListener("pointerup",this.wk),t.addEventListener("pointercancel",this.gk),t.addEventListener("lostpointercapture",this.bk)),_s&&(this.Mk=t=>this.Uk(t),window.addEventListener("pointerup",this.Mk)),this.Ps.enableKeyboardShortcuts&&(this.vk=t=>{this.jk(t)},document.addEventListener("keydown",this.vk))}Hk(){this.bx&&(this.Vf.unsubscribeClick(this.bx),this.bx=null),this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null);const t=this.Vf.chartElement();t&&(this.mk&&(t.removeEventListener("pointerdown",this.mk),this.mk=null),this.wk&&(t.removeEventListener("pointerup",this.wk),this.wk=null),this.gk&&(t.removeEventListener("pointercancel",this.gk),this.gk=null),this.bk&&(t.removeEventListener("lostpointercapture",this.bk),this.bk=null)),this.Mk&&(window.removeEventListener("pointerup",this.Mk),this.Mk=null),this.vk&&(document.removeEventListener("keydown",this.vk),this.vk=null)}FC(t){if(this.Vk(),!t.point)return;if(this.yk)return void(this.yk=!1);if(this.$C)return;const i=this.Yk(t.hoveredObjectId);i?this.selectTool(i):this.Fk()}IC(t){if(this.Sk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.$C&&this.Pk){const i=this.ck.get(this.Pk);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.Yk(t.hoveredObjectId);if(this.pk&&this.pk!==i){const t=this.ck.get(this.pk);t&&t.setHovered(!1)}if(i){const t=this.ck.get(i);t&&t.setHovered(!0)}this.pk=i}Yk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.ck)if(s.id===i)return t;return null}Nk(t){if(this.$C)return;pl(this.Vf,!1);const i=this.Vf.chartElement();if(!i)return;const s=null!==this.pk&&null!==this.Sk?{Xk:this.pk,Dw:this.Sk}:this.Gk(t);if(null===s)return;const{Xk:n,Dw:e}=s,r=this.ck.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Kk(r,e.ut,e.ct);if(null!==h&&null!==l){pl(this.Vf,!0),this.selectTool(n),this.$C=!0,this.yk=!0,this.Pk=n,this.IS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.IS=null}r.startDrag(h,l),this.Zk()}}Uk(t){if(!this.$C||null===this.Pk)return;if(t&&null!==this.IS&&t.pointerId!==this.IS)return;const i=this.Pk;this.$C=!1,this.Pk=null;try{const t=this.ck.get(i);t&&t.stopDrag()}finally{this.hx(),this.Jk()}this.recordChange()}qk(t){null!==this.IS&&t.pointerId!==this.IS||(this.IS=null,this.Uk())}Ok(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Gk(t){for(const[i,s]of this.ck){if(!s.isVisible()||s.isLocked())continue;const n=this.Ok(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{Xk:i,Dw:r}}return null}hx(){if(null===this.IS)return;const t=this.Vf.chartElement();t&&t.hasPointerCapture(this.IS)&&t.releasePointerCapture(this.IS),this.IS=null}Zk(){if(null!==this.xk)return;const t=this.Vf.options();this.xk={Qk:f(t.handleScroll),tD:f(t.handleScale)},this.Vf.applyOptions({handleScroll:!1,handleScale:!1})}Jk(){const t=this.xk;this.xk=null,null!==t&&this.Vf.applyOptions({handleScroll:t.Qk,handleScale:t.tD})}jk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Vk(),"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const s=t.metaKey||t.ctrlKey;if(s&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}s&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.cancelPendingDrawings(),this.Uk(),this.Fk(),this.stopDrawing(),t.preventDefault())}Kk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Gn(this.Vf,t.series(),i)}}Fk(){this.Ik(null)}}const Xa={...t,color:"#2196f3"};function Ga(){return"2.3.3"}export{Te as AreaSeries,ba as ArrowTool,Fe as BarSeries,xe as BaselineSeries,xa as BrushTool,Le as CandlestickSeries,va as CircleTool,Li as ColorType,Dl as CrossLineTool,U as CrosshairMode,xh as DEFAULT_SESSIONS,Bh as DraggablePriceLine,Ya as DrawingToolsManager,Xl as EXTENDED_FIBONACCI_RATIOS,Gl as FibonacciCalculator,na as FibonacciExtensionTool,aa as FibonacciFanTool,Ql as FibonacciTool,qa as GanttTool,Be as HistogramSeries,Cl as HorizontalLineTool,Wh as InteractiveLineManager,Ii as LastPriceAnimationMode,le as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,Bl as ParallelChannelTool,$l as PitchforkTool,Vl as PolygonTool,Fa as PositionCalculator,tl as PositionLine,Ir as PositionMarkersManager,$a as PositionTool,Vi as PriceLineSource,di as PriceScaleMode,ca as RectangleTool,La as RulerCalculator,Ba as RulerTool,Yl as STANDARD_FIBONACCI_RATIOS,Da as TextTool,Ai as TickMarkType,Fi as TrackingModeExitMode,Ch as TradingSessionsIndicator,Ml as TrendLineTool,ql as VerticalLineTool,Dh as VolumeProfileIndicator,wh as applyADX,fh as applyATR,Zr as applyBollingerBands,gh as applyCCI,Qr as applyDonchianChannels,Gr as applyEMA,uh as applyHeikinAshi,lh as applyIchimoku,Jr as applyKeltnerChannels,dh as applyMACD,Mh as applyMFI,mh as applyOBV,th as applyParabolicSAR,ah as applyPivotPoints,ch as applyRSI,Xr as applySMA,ph as applyStochastic,nh as applySuperTrend,sh as applyVWAP,vh as applyVolume,Kr as applyWMA,bh as applyWilliamsR,_h as calculateHeikinAshi,Ia as calculatePipConfig,Kn as coordinateFromTime,Ma as createArrowTool,Pa as createBrushTool,jn as createChart,qn as createChartEx,ma as createCircleTool,Rl as createCrossLineTool,ea as createFibonacciExtensionTool,oa as createFibonacciFanTool,ta as createFibonacciTool,ja as createGanttTool,Pl as createHorizontalLineTool,ir as createImageWatermark,zh as createInteractiveLineManager,me as createOptionsChart,Ol as createParallelChannelTool,Hl as createPitchforkTool,Ll as createPolygonTool,sl as createPositionLine,Vr as createPositionMarkers,Ha as createPositionTool,da as createRectangleTool,Oa as createRulerTool,yr as createSeriesMarkers,Ra as createTextTool,Xe as createTextWatermark,Oh as createTradingLine,Ph as createTradingSessionsIndicator,yl as createTrendLineTool,Fr as createUpDownMarkers,jl as createVerticalLineTool,Rh as createVolumeProfileIndicator,pe as createYieldCurveChart,Xa as customSeriesDefaultOptions,Yn as defaultHorzScaleBehavior,Va as getPipConfig,zr as hideSeriesPaint,Oi as isBusinessDay,Wi as isUTCTimestamp,Er as setSeriesVolumes,Fh as setVolumeProfileData,Gn as timeFromCoordinate,Ga 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 a(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 o{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",I:0,V:0,L:0,A:0,B:0},this.O=t}W(){const t=this.M,i=this.$(),s=this.H();return t.P===i&&t.D===s||(t.P=i,t.D=s,t.T=g(i,s),t.A=2.5/12*i,t.I=t.A,t.V=i/12*t.C,t.L=i/12*t.C,t.B=0),t.R=this.N(),t.F=this.U(),this.M}N(){return this.O.W().layout.textColor}U(){return this.O.q()}$(){return this.O.W().layout.fontSize}H(){return this.O.W().layout.fontFamily}}function M(t){return t<0?0:t>255?255:Math.round(t)||0}function y(t){return.199*t[0]+.687*t[1]+.114*t[2]}class S{constructor(t,i){this.j=new Map,this.Y=t,i&&(this.j=i)}X(t,i){if("transparent"===t)return t;const s=this.G(t),n=s[3];return`rgba(${s[0]}, ${s[1]}, ${s[2]}, ${i*n})`}K(t){const i=this.G(t);return{Z:`rgb(${i[0]}, ${i[1]}, ${i[2]})`,J:y(i)>160?"black":"white"}}tt(t){return y(this.G(t))}it(t,i,s){const[n,e,r,h]=this.G(t),[l,a,o,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(a-e)),M(r+s*(o-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],a=Math.round(n.ut*i)+r,o=n.ct*s,_=h*s+r;t.moveTo(a,o),t.arc(a,o,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.It(),i=this.Pt.Vt(),s=this.Ct.Lt(),n=this.O.At();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Et(s),l=i.Bt();!t&&null!==h&&i.It()&&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 R extends C{constructor(t){super(),this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;const h=this.Yt.Xt.It,l=this.Yt.Gt.It;if(!h&&!l)return;const a=Math.round(this.Yt.ut*s),o=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,a,0,i.height)),l&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,o,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",It:!1},Gt:{dt:1,Kt:0,R:"",It:!1},ut:0,ct:0},this.Jt=new R(this.Zt),this.Qt=t,this.Pt=i}Tt(){this.xt=!0}Dt(t){return this.xt&&(this.Rt(),this.xt=!1),this.Jt}Rt(){const t=this.Qt.It(),i=this.Pt.ti().W().crosshair,s=this.Zt;if(2===i.mode)return s.Gt.It=!1,void(s.Xt.It=!1);s.Gt.It=t&&this.Qt.ii(this.Pt),s.Xt.It=t&&this.Qt.si(),s.Gt.dt=i.horzLine.width,s.Gt.Kt=i.horzLine.style,s.Gt.R=i.horzLine.color,s.Xt.dt=i.vertLine.width,s.Xt.Kt=i.vertLine.style,s.Xt.R=i.vertLine.color,s.ut=this.Qt.ni(),s.ct=this.Qt.ei()}}function I(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 V(t,i,s,n,e,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(i,s,n,e),t.restore()}function L(t,i,s,n,e,r){t.beginPath(),t.roundRect?t.roundRect(i,s,n,e,r):(t.lineTo(i+n-r[1],s),0!==r[1]&&t.arcTo(i+n,s,i+n,s+r[1],r[1]),t.lineTo(i+n,s+e-r[2]),0!==r[2]&&t.arcTo(i+n,s+e,i+n-r[2],s+e,r[2]),t.lineTo(i+r[3],s+e),0!==r[3]&&t.arcTo(i,s+e,i,s+e-r[3],r[3]),t.lineTo(i,s+r[0]),0!==r[0]&&t.arcTo(i,s,i+r[0],s,r[0]))}function A(t,i,s,n,e,r,h=0,l=[0,0,0,0],a=""){if(t.save(),!h||!a||a===r)return L(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const o=h/2;var _;L(t,i+o,s+o,n-h,e-h,(_=-o,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==a&&(t.lineWidth=h,t.strokeStyle=a,t.closePath(),t.stroke()),t.restore()}function E(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 B{constructor(t,i){this.lt(t,i)}lt(t,i){this.Yt=t,this.ri=i}qt(t,i){return this.Yt.It?t.P+t.A+t.I:0}et(t,i,s,n){if(!this.Yt.It||0===this.Yt.hi.length)return;const e=this.Yt.R,r=this.ri.Z,h=t.useBitmapCoordinateSpace(t=>{const h=t.context;h.font=i.T;const l=this.li(t,i,s,n),a=l.ai;return l.oi?A(h,a._i,a.ui,a.ci,a.di,r,a.pi,[a.vt,0,0,a.vt],r):A(h,a.fi,a.ui,a.ci,a.di,r,a.pi,[0,a.vt,a.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(a.fi,a.wi,a.gi-a.fi,a.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.oi?a.yi-a.pi:0,a.ui,a.pi,a.Si-a.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.oi?"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:a}=t,o=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.A+this.ri.Di,c=i.I+this.ri.Ri,d=i.V,p=i.L,f=this.Yt.hi,v=i.P,m=s.Fi(e,f),w=Math.ceil(s.Ii(e,f)),g=v+u+c,b=i.S+d+p+w+o,M=Math.max(1,Math.floor(a));let y=Math.round(g*a);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(o*l),P=this.ri.Vi??this.ri.Li,T=Math.round(P*a)-Math.floor(.5*a),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,I=R?r.width-S:S;let V,L,A;return R?(V=I-x,L=I-C,A=F-o-d-_):(V=I+x,L=I+C,A=F+o+d),{oi:R,ai:{ui:k,wi:T,Si:D,ci:x,di:y,vt:2*l,pi:S,_i:V,fi:I,gi:L,bi:M,yi:r.width},xi:{ui:k/a,Si:D/a,Ci:A,Pi:m}}}}class O{constructor(t){this.Ai={Li:0,Z:"#000",Ri:0,Di:0},this.Ei={hi:"",It:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Bi={hi:"",It:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Oi=new(t||B)(this.Ei,this.Ai),this.Wi=new(t||B)(this.Bi,this.Ai)}hi(){return this.zi(),this.Ei.hi}Li(){return this.zi(),this.Ai.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.Ai.Vi||0}Hi(t){this.Ai.Vi=t}Ni(){return this.zi(),this.Ei.It||this.Bi.It}Ui(){return this.zi(),this.Ei.It}Dt(t){return this.zi(),this.Ei.mi=this.Ei.mi&&t.W().ticksVisible,this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Oi.lt(this.Ei,this.Ai),this.Wi.lt(this.Bi,this.Ai),this.Oi}qi(){return this.zi(),this.Oi.lt(this.Ei,this.Ai),this.Wi.lt(this.Bi,this.Ai),this.Wi}zi(){this.xt&&(this.Ei.mi=!0,this.Bi.mi=!1,this.ji(this.Ei,this.Bi,this.Ai))}}class W extends O{constructor(t,i,s){super(),this.Qt=t,this.Yi=i,this.Xi=s}ji(t,i,s){if(t.It=!1,2===this.Qt.W().mode)return;const n=this.Qt.W().horzLine;if(!n.labelVisible)return;const e=this.Yi.Bt();if(!this.Qt.It()||this.Yi.Gi()||null===e)return;const r=this.Yi.Ki().K(n.labelBackgroundColor);s.Z=r.Z,t.R=r.J;const h=2/12*this.Yi.P();s.Di=h,s.Ri=h;const l=this.Xi(this.Yi);s.Li=l.Li,t.hi=this.Yi.Zi(l.bt,e),t.It=!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.It||0===this.Yt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Ii(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 a=this.Yt.Li,o=Math.floor(a-r)+.5;o<0?(a+=Math.abs(0-o),o=Math.floor(a-r)+.5):o+e>h&&(a-=Math.abs(h-(o+e)),o=Math.floor(a-r)+.5);const _=o+e,u=Math.ceil(0+i.S+i.C+i.A+i.P+i.I);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(o*s),h=Math.round(0*n),a=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(a-d,c),t.arcTo(a,c,a,c-d,d),t.lineTo(a,h),t.fill(),e.mi){const r=Math.round(e.Li*s),l=h,a=Math.round((l+i.C)*n);t.fillStyle=e.R;const o=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,o,a-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.A+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(o+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={It:!1,Z:"#4c525e",R:"white",hi:"",ts:0,Li:NaN,mi:!0},this.Ct=t,this.ss=i,this.Xi=s}Tt(){this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Jt.lt(this.Zt),this.Jt}Rt(){const t=this.Zt;if(t.It=!1,2===this.Ct.W().mode)return;const i=this.Ct.W().vertLine;if(!i.labelVisible)return;const s=this.ss.At();if(s.Gi())return;t.ts=s.ts();const n=this.Xi();if(null===n)return;t.Li=n.Li;const e=s.ns(this.Ct.Lt());t.hi=s.es(l(e)),t.It=!0;const r=this.ss.Ki().K(i.labelBackgroundColor);t.Z=r.Z,t.R=r.J,t.mi=s.W().ticksVisible}}class N{constructor(){this.rs=null,this.hs=0}ls(){return this.hs}_s(t){this.hs=t}$t(){return this.rs}us(t){this.rs=t}cs(t){return[]}ds(){return[]}It(){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.Bt());return{bt:s.Ds(n,t),Li:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.At().Rs(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Li:n}:null})(()=>this.fs,()=>this.ni());this.Fs=new H(this,t,s)}W(){return this.Ps}Is(t,i){this.xs=t,this.Cs=i}Vs(){this.xs=NaN,this.Cs=NaN}Ls(){return this.xs}As(){return this.Cs}Es(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Bs(t,i,s)}Lt(){return this.fs}ni(){return this.ys}ei(){return this.Ss}It(){return this.vs}Os(){this.vs=!1,this.Ws(),this.ps=NaN,this.ys=NaN,this.Ss=NaN,this.Pt=null,this.Vs(),this.zs()}$s(t){let i=this.bs.get(t);i||(i=new F(this,t),this.bs.set(t,i));let s=this.Ms.get(t);return s||(s=new D(this.ss,this,t),this.Ms.set(t,s)),[i,s]}ii(t){return t===this.Pt&&this.Ps.horzLine.visible}si(){return this.Ps.vertLine.visible}Hs(t,i){this.vs&&this.Pt===t||this.ws.clear();const s=[];return this.Pt===t&&s.push(this.Ns(this.ws,i,this.Ts)),s}ds(){return this.vs?[this.Fs]:[]}Us(){return this.Pt}zs(){this.ss.qs().forEach(t=>{this.bs.get(t)?.Tt(),this.Ms.get(t)?.Tt()}),this.ws.forEach(t=>t.Tt()),this.Fs.Tt()}js(t){return t&&!t.ks().Gi()?t.ks():null}Bs(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,a=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.At().jt(t),this.Pt=s;const o=null!==a?a.Bt():null;return null!==a&&null!==o?(this.ps=i,this.Ss=a.zt(i,o)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||h!==this.fs||r!==this.ps||l!==this.Pt}Ws(){const t=this.ss.Xs().map(t=>t.Ks().Gs()).filter(v),i=0===t.length?null:Math.max(...t);this.fs=null!==i?i:NaN}Ns(t,i,s){let n=t.get(i);return void 0===n&&(n=new W(this,i,s),t.set(i,n)),n}}function j(t){return"left"===t||"right"===t}class Y{constructor(t){this.Zs=new Map,this.Js=[],this.Qs=t}tn(t,i){const s=function(t,i){return void 0===t?i:{sn:Math.max(t.sn,i.sn),nn:t.nn||i.nn}}(this.Zs.get(t),i);this.Zs.set(t,s)}en(){return this.Qs}rn(t){const i=this.Zs.get(t);return void 0===i?{sn:this.Qs}:{sn:Math.max(this.Qs,i.sn),nn:i.nn}}hn(){this.ln(),this.Js=[{an:0}]}_n(t){this.ln(),this.Js=[{an:1,Ht:t}]}un(t){this.cn(),this.Js.push({an:5,Ht:t})}ln(){this.cn(),this.Js.push({an:6})}dn(){this.ln(),this.Js=[{an:4}]}pn(t){this.ln(),this.Js.push({an:2,Ht:t})}fn(t){this.ln(),this.Js.push({an:3,Ht:t})}vn(){return this.Js}mn(t){for(const i of t.Js)this.wn(i);this.Qs=Math.max(this.Qs,t.Qs),t.Zs.forEach((t,i)=>{this.tn(i,t)})}static gn(){return new Y(2)}static bn(){return new Y(3)}wn(t){switch(t.an){case 0:this.hn();break;case 1:this._n(t.Ht);break;case 2:this.pn(t.Ht);break;case 3:this.fn(t.Ht);break;case 4:this.dn();break;case 5:this.un(t.Ht);break;case 6:this.cn()}}cn(){const t=this.Js.findIndex(t=>5===t.an);-1!==t&&this.Js.splice(t,1)}}class X{formatTickmarks(t){return t.map(t=>this.format(t))}}const G=".";function K(t,i){if(!u(t))return"n/a";if(!c(i))throw new TypeError("invalid length");if(i<0||i>16)throw new TypeError("invalid length");if(0===i)return t.toString();return("0000000000000000"+t.toString()).slice(-i)}class Z extends X{constructor(t,i){if(super(),i||(i=1),u(t)&&c(t)||(t=100),t<0)throw new TypeError("invalid base");this.Yi=t,this.Mn=i,this.yn()}format(t){const i=t<0?"−":"";return t=Math.abs(t),i+this.Sn(t)}yn(){if(this.xn=0,this.Yi>0&&this.Mn>0){let t=this.Yi;for(;t>1;)t/=10,this.xn++}}Sn(t){const i=this.Yi/this.Mn;let s=Math.floor(t),n="";const e=void 0!==this.xn?this.xn:NaN;if(i>1){let r=+(Math.round(t*i)-s*i).toFixed(this.xn);r>=i&&(r-=i,s+=1),n=G+K(+r.toFixed(this.xn)*this.Mn,e)}else s=Math.round(s*i)/i,e>0&&(n=G+K(0,e));return s.toFixed(0)+n}}class J extends Z{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class Q extends X{constructor(t){super(),this.Cn=t}format(t){let i="";return t<0&&(i="-",t=-t),t<995?i+this.Pn(t):t<999995?i+this.Pn(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),i+this.Pn(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),i+this.Pn(t/1e9)+"B")}Pn(t){let i;const s=Math.pow(10,this.Cn);return i=(t=Math.round(t*s)/s)>=1e-15&&t<1?t.toFixed(this.Cn).replace(/\.?0+$/,""):String(t),i.replace(/(\.[1-9]*)0+$/,(t,i)=>i)}}const tt=/[2-9]/g;class it{constructor(t=50){this.Tn=0,this.kn=1,this.Dn=1,this.Rn={},this.Fn=new Map,this.In=t}Vn(){this.Tn=0,this.Fn.clear(),this.kn=1,this.Dn=1,this.Rn={}}Ii(t,i,s){return this.Ln(t,i,s).width}Fi(t,i,s){const n=this.Ln(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}Ln(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Fn.has(e))return h(this.Fn.get(e)).An;if(this.Tn===this.In){const t=this.Rn[this.Dn];delete this.Rn[this.Dn],this.Fn.delete(t),this.Dn++,this.Tn--}t.save(),t.textBaseline="middle";const r=t.measureText(e);return t.restore(),0===r.width&&i.length||(this.Fn.set(e,{An:r,En:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.Bn=null,this.M=null,this.On="right",this.Wn=t}zn(t,i,s){this.Bn=t,this.M=i,this.On=s}et(t){null!==this.M&&null!==this.Bn&&this.Bn.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.Vn()),this.Jt.zn(this.$n.qi(),n,s),this.Jt}}class et extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}Xn(t,i){if(!this.Yt?.It)return null;const{ct:s,dt:n,Gn:e}=this.Yt;return i>=s-n-7&&i<=s+n+7?{Kn:this.Yt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.Yt)return;if(!1===this.Yt.It)return;const h=Math.round(this.Yt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.Yt.R,t.lineWidth=Math.floor(this.Yt.dt*s),n(t,this.Yt.Kt),e(t,h,0,i.width))}}class rt{constructor(t){this.Zn={ct:0,R:"rgba(0, 0, 0, 0)",dt:1,Kt:0,It:!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.It()?(this.xt&&(this.ie(),this.xt=!1),this.Jn):null}}class ht extends rt{constructor(t){super(t)}ie(){this.Zn.It=!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.It())return;const n=this.Qn.Bt();null!==n&&(this.Zn.It=!0,this.Zn.ct=t.zt(n.Ht,n.Ht),this.Zn.R=s.baseLineColor,this.Zn.dt=s.baseLineWidth,this.Zn.Kt=s.baseLineStyle)}}class lt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}ne(){return this.Yt}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.Yt;if(null===n)return;const e=Math.max(1,Math.floor(i)),r=e%2/2,h=Math.round(n.ee.x*i)+r,l=n.ee.y*s;t.fillStyle=n.re,t.beginPath();const a=Math.max(2,1.5*n.he)*i;t.arc(h,l,a,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.ae,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const at=[{oe:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{oe:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{oe:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class ot{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}It(){return 0!==this.be.W().lastPriceAnimation}xe(){switch(this.be.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.ge}}Dt(){return this.xt?(this.Rt(),this.xt=!1,this.me=!1):this.me&&(this.Ce(),this.me=!1),this.Jt}Rt(){this.Jt.lt(null);const t=this.be.ti().At(),i=t.Pe(),s=this.be.Bt();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Re))return;const e={x:t.jt(n.Re),y:this.be.$t().zt(n.bt,s.Ht)},r=n.R,h=this.be.W().lineWidth,l=this.Fe(this.Ie(),r);this.Jt.lt({re:r,he:h,le:l.le,ae:l.ae,vt:l.vt,ee:e})}Ce(){const t=this.Jt.ne();if(null!==t){const i=this.Fe(this.Ie(),t.re);t.le=i.le,t.ae=i.ae,t.vt=i.vt}}Ie(){return this.xe()?performance.now()-this.we:2599}Ve(t,i,s,n){const e=s+(n-s)*i;return this.be.ti().Ki().X(t,e)}Fe(t,i){const s=t%2600/2600;let n;for(const t of at)if(s>=t.oe&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.oe)/(n._e-n.oe);return{le:this.Ve(i,e,n.de,n.pe),ae:this.Ve(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,a=n.ce,l+(a-l)*h)};var h,l,a}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.It=!1;const i=this.Qn.W();if(!i.priceLineVisible||!this.Qn.It())return;const s=this.Qn.Te(0===i.priceLineSource);s.ke||(t.It=!0,t.ct=s.Li,t.R=this.Qn.Le(s.R),t.dt=i.priceLineWidth,t.Kt=i.priceLineStyle)}}class ut extends O{constructor(t){super(),this.Qt=t}ji(t,i,s){t.It=!1,i.It=!1;const n=this.Qt;if(!n.It())return;const e=n.W(),r=e.lastValueVisible,h=""!==n.Ae(),l=0===e.seriesLastValueMode,a=n.Te(!1);if(a.ke)return;r&&(t.hi=this.Ee(a,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Be(a,r,h,l),i.It=i.hi.length>0);const o=n.Le(a.R),_=this.Qt.ti().Ki().K(o);s.Z=_.Z,s.Li=a.Li,i.Nt=n.ti().Ut(a.Li/n.$t().qt()),t.Nt=o,t.R=_.J,i.R=_.J}Be(t,i,s,n){let e="";const r=this.Qt.Ae();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Oe()?t.We:t.ze),e.trim()}Ee(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))}Xe(t){if(!u(t))return;if(0===this.He-this.$e)return;const i=.5*(this.He+this.$e);let s=this.He-i,n=this.$e-i;s*=t,n*=t,this.He=i+s,this.$e=i+n}Ge(t){u(t)&&(this.He+=t,this.$e+=t)}Ke(){return{minValue:this.$e,maxValue:this.He}}static Ze(t){return null===t?null:new dt(t.minValue,t.maxValue)}}class pt{constructor(t,i){this.Je=t,this.Qe=i||null}tr(){return this.Je}ir(){return this.Qe}Ke(){return{priceRange:null===this.Je?null:this.Je.Ke(),margins:this.Qe||void 0}}static Ze(t){return null===t?null:new pt(dt.Ze(t.priceRange),t.margins)}}class ft extends rt{constructor(t,i){super(t),this.sr=i}ie(){const t=this.Zn;t.It=!1;const i=this.sr.W();if(!this.Qn.It()||!i.lineVisible)return;const s=this.sr.nr();null!==s&&(t.It=!0,t.ct=s,t.R=i.color,t.dt=i.lineWidth,t.Kt=i.lineStyle,t.Gn=this.sr.W().id)}}class vt extends O{constructor(t,i){super(),this.be=t,this.sr=i}ji(t,i,s){t.It=!1,i.It=!1;const n=this.sr.W(),e=n.axisLabelVisible,r=""!==n.title,h=this.be;if(!e||!h.It())return;const l=this.sr.nr();if(null===l)return;r&&(i.hi=n.title,i.It=!0),i.Nt=h.ti().Ut(l/h.$t().qt()),t.hi=this.er(n.price),t.It=!0;const a=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=a.Z;const o=n.axisLabelTextColor||a.J;t.R=o,i.R=o,s.Li=l}er(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.Ps=i,this.rr=new ft(t,this),this.$n=new vt(t,this),this.hr=new nt(this.$n,t,t.ti())}lr(t){_(this.Ps,t),this.Tt(),this.be.ti().ar()}W(){return this.Ps}_r(){return this.rr}ur(){return this.hr}cr(){return this.$n}Tt(){this.rr.Tt(),this.$n.Tt()}nr(){const t=this.be,i=t.$t();if(t.ti().At().Gi()||i.Gi())return null;const s=t.Bt();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)),o=a(h.Ht[0])<=a(h.Ht[3]);return{dr:h.R??(o?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,o=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=a(c.Ht[0])<=a(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:o),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}Ir(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Vr=[],this.Lr=new Map,this.Ar=new Map,this.Er=[]}Br(){return this.Or()>0?this.Vr[this.Vr.length-1]:null}Wr(){return this.Or()>0?this.zr(0):null}Gs(){return this.Or()>0?this.zr(this.Vr.length-1):null}Or(){return this.Vr.length}Gi(){return 0===this.Or()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Vr}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Ar.clear(),this.Lr.clear(),this.Vr=t,this.Er=t.map(t=>t.Re)}Yr(){return this.Er}zr(t){return this.Vr[t].Re}Nr(t){return this.Vr[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Vr.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Vr.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Vr.length||t<this.Vr[i].Re?null:i}Zr(t){return yt(this.Vr,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Vr,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Vr[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),a=Math.min(i,r),o=Math.ceil(h/Ct)*Ct,_=Math.max(o,Math.floor(a/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(a,o,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Lr.get(s);void 0===u&&(u=new Map,this.Lr.set(s,u));for(let t=Math.max(o+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(a);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}ah(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.oh=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.oh?.rh===t)return this.oh.hh;const i=t.map(t=>new Rt(t));return this.oh={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Vt(t);return this.Fn={rh:t,hh:i},i}ah(){return this.eh.zOrder?.()??"normal"}}function At(t){return{hi:t.text(),Li:t.coordinate(),Vi:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),It:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Et{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...At(this.dh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=At(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Li=n.Li,s.Vi=n.Vi,t.hi=n.hi,t.It=n.It,t.mi=n.mi}}class Ot extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new Lt(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new Lt(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.ah()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new ot(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().At().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().At().Pe(),e=this.Bt();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.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],a=this.Fh().Fr(h,{Ht:r}),o=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Ih(l),ze:s.Vh(l,e.Ht),R:a.dr,Li:o,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Lh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Ah()),this.ti().Eh(this),this.ti().Bh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Oh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Eh(this),this.ti().Bh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Eh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Eh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Bt(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.It()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.al(),Nt:this.ol(),Wt:this._l(),Ot:this.ul(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}cl(t){this.kh.push(new Ot(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.It())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=a(n.Bt()),o=3===this.Ps.mode?jt:qt;return t.concat(o.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 o=l[0];return n=e.Ds(o,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Il(),Pl:(this.Pt.ti().At().Il()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Vl:4,Ll:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Ll)+i.Vl;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.Vl)-i.Ll;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function ai(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){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,Ll:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Al=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.Al))this.Bl=[2,2.5,2];else{this.Bl=[];for(let t=this.Al;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")}}}Ol(t,i,s){const n=0===this.Al?0:1/this.Al;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.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,a=1,o=1e-14,Math.abs(l-a)<o))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,a,o;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Al=i,this.zl=s,this.$l=n}Ol(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Al,[2,2.5,2]),r=new _i(this.Al,[2,2,2.5]),h=new _i(this.Al,[2.5,2,2]),l=[];return l.push(e.Ol(t,i,n),r.Ol(t,i,n),h.Ol(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,a=Math.max(n,e),o=Math.min(n,e);if(a===o)return void(this.Wl=[]);const _=this.Ol(a,o);if(this.ql(i,_,a,o,h,l),t.jl()&&this.Yl(_,o,a)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Il(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.ceil(2.5*this.Ul())}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let a=s%i;a+=a<0?i:0;const o=s>=n?1:-1;let _=null,u=0;for(let c=s-a;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.ta()&&(i=this.Ol(c*o,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.ia(t,s,e,r),a=this.ia(t,n,-r,-e),o=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<o/2&&h.shift(),h.length>0&&a.Tl-h[h.length-1].Tl<o/2&&h.pop(),h.unshift(l),h.push(a)}ia(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),a=Math.max(r,h),o=Math.max(.1,this.Ol(a,l)),_=this.zl(i+e,t),u=_-_%o,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=a(this.Yi.tr());return this.Yi.ta()&&(n=ai(n,this.Yi.sa())),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.na=0,this.ea=null,this.Je=null,this.ra=null,this.ha={la:!1,aa:null},this.oa=!1,this._a=0,this.ua=0,this.ca=new o,this.da=new o,this.pa=[],this.fa=null,this.va=null,this.ma=null,this.wa=null,this.ga=null,this.ll=fi,this.ba=oi(null),this.Ma=t,this.Ps=i,this.ya=s,this.Sa=n,this.xa=e,this.Ca=new ui(this,100,this.Pa.bind(this),this.Ta.bind(this))}gl(){return this.Ma}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.ka({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.Da(),this.ma=null}}Ra(){return this.Ps.autoScale}Fa(){return this.oa}ta(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Ia(){return 3===this.Ps.mode}sa(){return this.ba}se(){return{nn:this.Ps.autoScale,Va:this.Ps.invertScale,se:this.Ps.mode}}ka(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.ha.la=!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.ba)?this.Ps.autoScale=!0:(s=ai(this.Je,this.ba),null!==s&&this.La(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.ba),null!==s&&this.La(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.bl(),n&&(3===i.se||this.Ia())&&this.bl(),void 0!==t.Va&&i.Va!==t.Va&&(this.Ps.invertScale=t.Va,this.Aa()),this.da.p(i,this.se())}Ea(){return this.da}P(){return this.ya.fontSize}qt(){return this.na}Ba(t){this.na!==t&&(this.na=t,this.Da(),this.ma=null)}Oa(){if(this.ea)return this.ea;const t=this.qt()-this.Wa()-this.za();return this.ea=t,t}tr(){return this.$a(),this.Je}La(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.ma=null,this.Je=t)}Ha(t){this.La(t),this.Na(null!==t)}Gi(){return this.$a(),0===this.na||!this.Je||this.Je.Gi()}Ua(t){return this.Va()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Ia()&&(t=ni(t,i)),this.Ta(t,i)}qa(t,i,s){this.$a();const n=this.za(),e=l(this.tr()),r=e.qe(),h=e.je(),a=this.Oa()-1,o=this.Va(),_=a/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.ja();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 a=n+_*(l-r),u=o?a:this.na-1-a;e.ct=u}}Ya(t,i,s){this.$a();const n=this.za(),e=l(this.tr()),r=e.qe(),h=e.je(),a=this.Oa()-1,o=this.Va(),_=a/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.ja();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,a=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),a=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=o?c:this.na-1-c;e.Xa=p,c=n+_*(l-r),p=o?c:this.na-1-c,e.Ga=p,c=n+_*(a-r),p=o?c:this.na-1-c,e.Ka=p,c=n+_*(u-r),p=o?c:this.na-1-c,e.Za=p}}Ds(t,i){const s=this.Pa(t,i);return this.Ja(s,i)}Ja(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Ia()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.pa}Ft(){return this.va||(this.va=ci(this.pa)),this.va}Qa(t){-1===this.pa.indexOf(t)&&(this.pa.push(t),this.bl(),this.io())}so(t){const i=this.pa.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.pa.splice(i,1),0===this.pa.length&&(this.ka({nn:!0}),this.La(null)),this.bl(),this.io()}Bt(){let t=null;for(const i of this.pa){const s=i.Bt();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Va(){return this.Ps.invertScale}Il(){const t=null===this.Bt();if(null!==this.ma&&(t||this.ma.no===t))return this.ma.Il;this.Ca.Nl();const i=this.Ca.Il();return this.ma={Il:i,no:t},this.ca.p(),i}eo(){return this.ca}ro(t){this.Oe()||this.Ia()||null===this.wa&&null===this.ra&&(this.Gi()||(this.wa=this.na-t,this.ra=l(this.tr()).Ue()))}ho(t){if(this.Oe()||this.Ia())return;if(null===this.wa)return;this.ka({nn:!1}),(t=this.na-t)<0&&(t=0);let i=(this.wa+.2*(this.na-1))/(t+.2*(this.na-1));const s=l(this.ra).Ue();i=Math.max(i,.1),s.Xe(i),this.La(s)}lo(){this.Oe()||this.Ia()||(this.wa=null,this.ra=null)}ao(t){this.Ra()||null===this.ga&&null===this.ra&&(this.Gi()||(this.ga=t,this.ra=l(this.tr()).Ue()))}oo(t){if(this.Ra())return;if(null===this.ga)return;const i=l(this.tr()).Ye()/(this.Oa()-1);let s=t-this.ga;this.Va()&&(s*=-1);const n=s*i,e=l(this.ra).Ue();e.Ge(n),this.La(e,!0),this.ma=null}_o(){this.Ra()||null!==this.ga&&(this.ga=null,this.ra=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.uo(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.uo(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.co(t);case 3:return this.hl().formatTickmarks(t);default:return this.do(t)}}Ih(t){return this.er(t,l(this.fa).hl())}Vh(t,i){return t=ii(t,i),this.uo(t,pi)}po(){return this.pa}fo(t){this.ha={aa:t,la:!1}}zs(){this.pa.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Ra()}Xl(){return this.P()/2}bl(){this.ma=null;let t=1/0;this.fa=null;for(const i of this.pa)i.ls()<t&&(t=i.ls(),this.fa=i);let i=100;null!==this.fa&&(i=Math.round(this.fa.rh())),this.ll=fi,this.Oe()?(this.ll=pi,i=100):this.Ia()?(this.ll=new Z(100,1),i=100):null!==this.fa&&(this.ll=this.fa.hl()),this.Ca=new ui(this,i,this.Pa.bind(this),this.Ta.bind(this)),this.Ca.Nl()}io(){this.va=null}vo(){return null===this.fa||this.Oe()||this.Ia()?1:1/this.fa.rh()}Ki(){return this.xa}Na(t){this.oa=t}Wa(){return this.Va()?this.Ps.scaleMargins.bottom*this.qt()+this.ua:this.Ps.scaleMargins.top*this.qt()+this._a}za(){return this.Va()?this.Ps.scaleMargins.top*this.qt()+this._a:this.Ps.scaleMargins.bottom*this.qt()+this.ua}$a(){this.ha.la||(this.ha.la=!0,this.mo())}Da(){this.ea=null}Ta(t,i){if(this.$a(),this.Gi())return 0;t=this.ta()&&t?ri(t,this.ba):t;const s=l(this.tr()),n=this.za()+(this.Oa()-1)*(t-s.qe())/s.Ye();return this.Ua(n)}Pa(t,i){if(this.$a(),this.Gi())return 0;const s=this.Ua(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.za())/(this.Oa()-1));return this.ta()?hi(e,this.ba):e}Aa(){this.ma=null,this.Ca.Nl()}mo(){if(this.Fa()&&!this.Ra())return;const t=this.ha.aa;if(null===t)return;let i=null;const s=this.po();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let a=h&&h.tr();if(null!==a){switch(this.Ps.mode){case 1:a=li(a,this.ba);break;case 2:a=si(a,s.Ht);break;case 3:a=ei(a,s.Ht)}if(i=null===i?a:i.mn(l(a)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this._a&&e===this.ua||(this._a=n,this.ua=e,this.ma=null,this.Da()),null!==i){if(i.qe()===i.je()){const t=5*this.vo();this.ta()&&(i=ai(i,this.ba)),i=new dt(i.qe()-t,i.je()+t),this.ta()&&(i=li(i,this.ba))}if(this.ta()){const t=ai(i,this.ba),s=oi(t);if(r=s,h=this.ba,r.Vl!==h.Vl||r.Ll!==h.Ll){const n=null!==this.ra?ai(this.ra,this.ba):null;this.ba=s,i=li(t,s),null!==n&&(this.ra=li(n,s))}}this.La(i)}else null===this.Je&&(this.La(new dt(-.5,.5)),this.ba=oi(null));var r,h}ja(){return this.Oe()?ii:this.Ia()?ni:this.ta()?t=>ri(t,this.ba):null}wo(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}bo(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.wo(t,this.Sa.priceFormatter,i)}do(t,i){const s=this.Sa.priceFormatter;return this.bo(t,this.Sa.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}uo(t,i){return this.wo(t,this.Sa.percentageFormatter,i)}co(t,i){const s=this.Sa.percentageFormatter;return this.bo(t,this.Sa.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.pa=[],this.Mo=new Map,this.na=0,this.yo=0,this.So=1,this.va=null,this.xo=!1,this.Co=new o,this.kh=[],this.ph=t,this.ss=i,this.Po=new Qt(this);const s=i.W();this.To=this.ko("left",s.leftPriceScale),this.Do=this.ko("right",s.rightPriceScale),this.To.Ea().i(this.Ro.bind(this,this.To),this),this.Do.Ea().i(this.Ro.bind(this,this.Do),this),this.Fo(s)}Fo(t){if(t.leftPriceScale&&this.To.lr(t.leftPriceScale),t.rightPriceScale&&this.Do.lr(t.rightPriceScale),t.localization&&(this.To.bl(),this.Do.bl()),t.overlayPriceScales){const i=Array.from(this.Mo.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Io(t){switch(t){case"left":return this.To;case"right":return this.Do}return this.Mo.has(t)?h(this.Mo.get(t))[0].$t():null}m(){this.ti().Vo().u(this),this.To.Ea().u(this),this.Do.Ea().u(this),this.pa.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Co.p()}Lo(){return this.So}Ao(t){this.So=t}ti(){return this.ss}ts(){return this.yo}qt(){return this.na}Eo(t){this.yo=t,this.Bo()}Ba(t){this.na=t,this.To.Ba(t),this.Do.Ba(t),this.pa.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Ba(t)}}),this.Bo()}Oo(t){this.xo=t}Wo(){return this.xo}zo(){return this.pa.filter(mi)}yl(){return this.pa}Un(t){const i=t.$t();return null===i||this.To!==i&&this.Do!==i}Qa(t,i,s){this.$o(t,i,s?t.ls():this.pa.length)}so(t,i){const s=this.pa.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.pa.splice(s,1),i||this.pa.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Mo.has(n)){const i=h(this.Mo.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Mo.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.so(t),this.Ho(e)),this.va=null}jn(t){return t===this.To?"left":t===this.Do?"right":"overlay"}No(){return this.To}Uo(){return this.Do}qo(t,i){t.ro(i)}jo(t,i){t.ho(i),this.Bo()}Yo(t){t.lo()}Xo(t,i){t.ao(i)}Go(t,i){t.oo(i),this.Bo()}Ko(t){t._o()}Bo(){this.pa.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Do.yl().length?t=this.Do:this.ss.W().leftPriceScale.visible&&0!==this.To.yl().length?t=this.To:0!==this.pa.length&&(t=this.pa[0].$t()),null===t&&(t=this.Do),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Do:this.ss.W().leftPriceScale.visible&&(t=this.To),t}Ho(t){null!==t&&t.Ra()&&this.Zo(t)}Jo(t){const i=this.ph.Pe();t.ka({nn:!0}),null!==i&&t.fo(i),this.Bo()}Qo(){this.Zo(this.To),this.Zo(this.Do)}t_(){this.Ho(this.To),this.Ho(this.Do),this.pa.forEach(t=>{this.Un(t)&&this.Ho(t.$t())}),this.Bo(),this.ss.ar()}Ft(){return null===this.va&&(this.va=ci(this.pa)),this.va}i_(t,i){i=Xt(i,0,this.pa.length-1);const s=this.pa.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.pa.splice(s,1),this.pa.splice(i,0,t),this.pa.forEach((t,i)=>t._s(i)),this.va=null;for(const t of[this.To,this.Do])t.io(),t.bl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}s_(){return this.Co}n_(){return this.Po}cl(t){this.kh.push(new It(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Zo(t){const i=t.po();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.fo(i)}t.zs()}$o(t,i,s){let n=this.Io(i);if(null===n&&(n=this.ko(i,this.ss.W().overlayPriceScales)),this.pa.splice(s,0,t),!j(i)){const s=this.Mo.get(i)||[];s.push(t),this.Mo.set(i,s)}t._s(s),n.Qa(t),t.us(n),this.Ho(n),this.va=null}Ro(t,i,s){i.se!==s.se&&this.Zo(t)}ko(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Ba(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},a_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{o_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,o_:n.o_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.In=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.In){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,En:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(t,i){this.M_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}y_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Fn&&this.Fn.S_===r&&e===this.Fn.x_&&s===this.Fn.C_||(this.Fn={x_:e,C_:s,Il:this.P_(r,s,n),S_:r}),this.Fn.Il}M_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}P_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const a=h(this.m_.get(i)),o=a.length;let _=1/0,u=-1/0;for(let i=0;i<o;i++){const h=a[i],o=h.index;for(;l<r;){const t=s[l],i=t.index;if(!(i<o&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-o>=t&&o-u>=t&&e(h))n.push(h),u=o;else if(this.w_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.T_=t}k_(){return null===this.T_?null:new Ci(Math.floor(this.T_.qh()),Math.ceil(this.T_.yi()))}D_(){return this.T_}static R_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.yo=0,this.F_=null,this.I_=[],this.ga=null,this.wa=null,this.V_=new Ti,this.L_=new Map,this.A_=ki.R_(),this.E_=!0,this.B_=new o,this.O_=new o,this.W_=new o,this.z_=null,this.H_=null,this.N_=new Map,this.U_=-1,this.q_=[],this.Ps=i,this.Sa=s,this.j_=i.rightOffset,this.Y_=i.barSpacing,this.ss=t,this.X_(i),this.u_=n,this.G_(),this.V_.g_(i.uniformDistribution),this.K_()}W(){return this.Ps}Z_(t){_(this.Sa,t),this.J_(),this.G_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.Q_(),this.Ps.fixRightEdge&&this.tu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.X_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.Y_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.K_(),this.J_(),this.G_(),this.W_.p()}Rs(t){return this.I_[t]?.time??null}ns(t){return this.I_[t]??null}iu(t,i){if(this.I_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.I_[this.I_.length-1].time))return i?this.I_.length-1:null;const s=yt(this.I_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.I_[s].time)?i?s:null:s}Gi(){return 0===this.yo||0===this.I_.length||null===this.F_}su(){return this.I_.length>0}Pe(){return this.nu(),this.A_.k_()}eu(){return this.nu(),this.A_.D_()}ru(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.hu(i)}hu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.lu()),e=l(this.au());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.iu(t.from,!0)),to:l(this.iu(t.to,!0))}}ts(){return this.yo}Eo(t){if(!isFinite(t)||t<=0)return;if(this.yo===t)return;const i=this.eu(),s=this.yo;if(this.yo=t,this.E_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.Y_*t/s;this.Y_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.j_-=Math.round(i/this.Y_)+1,this.E_=!0}this._u(),this.uu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.cu()+this.j_-t;return this.yo-(i+.5)*this.Y_-1}du(t,i){const s=this.cu(),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.j_-n,r=this.yo-(e+.5)*this.Y_-1;t[i].ut=r}}pu(t,i){const s=Math.ceil(this.fu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.vu(s)?this.mu(s):s}fn(t){this.E_=!0,this.j_=t,this.uu(),this.ss.wu(),this.ss.ar()}gu(){return this.Y_}pn(t){const i=this.Y_;if(this.bu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.j_*i/this.Y_;this.j_=t}this.uu(),this.ss.wu(),this.ss.ar()}Mu(){return this.j_}Il(){if(this.Gi())return null;if(null!==this.H_)return this.H_;const t=this.Y_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.V_.y_(t,i,this.Ps.ignoreWhitespaceIndices,this.N_,this.U_),a=this.lu()+s,o=this.au()-s,_=this.yu(),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.q_.length?(s=this.q_[d],s.coord=this.jt(t.index),s.label=this.Su(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.Su(t),weight:t.weight},this.q_.push(s)),this.Y_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=a||c&&t.index>=o,d++}return this.q_.length=d,this.H_=this.q_,this.q_}xu(){let t;this.E_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.gu():this.Ps.rightOffset,this.fn(t)}Cu(t){this.E_=!0,this.F_=t,this.uu(),this.Q_()}Pu(t,i){const s=this.fu(t),n=this.gu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.Mu()+(s-this.fu(t)))}ro(t){this.ga&&this._o(),null===this.wa&&null===this.z_&&(this.Gi()||(this.wa=t,this.Tu()))}ho(t){if(null===this.z_)return;const i=Xt(this.yo-t,0,this.yo),s=Xt(this.yo-l(this.wa),0,this.yo);0!==i&&0!==s&&this.pn(this.z_.gu*i/s)}lo(){null!==this.wa&&(this.wa=null,this.ku())}ao(t){null===this.ga&&null===this.z_&&(this.Gi()||(this.ga=t,this.Tu()))}oo(t){if(null===this.ga)return;const i=(this.ga-t)/this.gu();this.j_=l(this.z_).Mu+i,this.E_=!0,this.uu()}_o(){null!==this.ga&&(this.ga=null,this.ku())}Du(){this.Ru(this.Ps.rightOffset)}Ru(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.j_,n=performance.now();this.ss.un({Fu:t=>(t-n)/i>=1,Iu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.E_=!0,this.I_=t,this.V_.b_(t,i),this.uu()}Vu(){return this.B_}Lu(){return this.O_}Au(){return this.W_}cu(){return this.F_||0}Eu(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.bu((this.yo-n)/s),this.j_=t.yi()-this.cu(),i&&(this.j_=n?n/this.gu():this.Ps.rightOffset),this.uu(),this.E_=!0,this.ss.wu(),this.ss.ar()}Bu(){const t=this.lu(),i=this.au();null!==t&&null!==i&&this.Eu(new Ci(t,i),!0)}Ou(t){const i=new Ci(t.from,t.to);this.Eu(i)}es(t){return void 0!==this.Sa.timeFormatter?this.Sa.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}K_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.N_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.N_.set(t,!0);this.U_++}yu(){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)}lu(){return 0===this.I_.length?null:0}au(){return 0===this.I_.length?null:this.I_.length-1}Wu(t){return(this.yo-1-t)/this.Y_}fu(t){const i=this.Wu(t),s=this.cu()+this.j_-i;return Math.round(1e6*s)/1e6}bu(t){const i=this.Y_;this.Y_=t,this._u(),i!==this.Y_&&(this.E_=!0,this.zu())}nu(){if(!this.E_)return;if(this.E_=!1,this.Gi())return void this.$u(ki.R_());const t=this.cu(),i=this.yo/this.Y_,s=this.j_+t,n=new Ci(s-i+1,s);this.$u(new ki(n))}_u(){const t=Xt(this.Y_,this.Hu(),this.Nu());this.Y_!==t&&(this.Y_=t,this.E_=!0)}Nu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.yo}Hu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.I_.length?this.yo/this.I_.length:this.Ps.minBarSpacing}uu(){const t=this.Uu();null!==t&&this.j_<t&&(this.j_=t,this.E_=!0);const i=this.qu();this.j_>i&&(this.j_=i,this.E_=!0)}Uu(){const t=this.lu(),i=this.F_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.yo/this.Y_:Math.min(2,this.I_.length))}qu(){return this.Ps.fixRightEdge?0:this.yo/this.Y_-Math.min(2,this.I_.length)}Tu(){this.z_={gu:this.gu(),Mu:this.Mu()}}ku(){this.z_=null}Su(t){let i=this.L_.get(t.weight);return void 0===i&&(i=new xi(t=>this.ju(t),this.u_),this.L_.set(t.weight,i)),i.c_(t)}ju(t){return this.u_.formatTickmark(t,this.Sa)}$u(t){const i=this.A_;this.A_=t,Pi(i.k_(),this.A_.k_())||this.B_.p(),Pi(i.D_(),this.A_.D_())||this.O_.p(),this.zu()}zu(){this.H_=null}J_(){this.zu(),this.L_.clear()}G_(){this.u_.updateFormatter(this.Sa)}Q_(){if(!this.Ps.fixLeftEdge)return;const t=this.lu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.j_-s-1;this.fn(t)}this._u()}tu(){this.uu(),this._u()}vu(t){return!this.Ps.ignoreWhitespaceIndices||(this.N_.get(t)||!1)}mu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.au();for(;s;){const t=i.next().value;if(this.N_.get(t))return t;if(t<0||t>s)break}return t}X_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.Y_);this.ss.fn(i)}}}var Fi,Ii,Vi,Li,Ai;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Ei{constructor(t,i,s){this.Yu=[],this.Xu=[],this.yo=0,this.Gu=null,this.Ku=new o,this.Zu=new o,this.Ju=null,this.Qu=t,this.Ps=i,this.u_=s,this.xa=new S(this.Ps.layout.colorParsers),this.tc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.sc=new Yt(i.crosshair),i.addDefaultPane&&(this.nc(0),this.Yu[0].Ao(2)),this.ec=this.rc(0),this.hc=this.rc(1)}Ah(){this.lc(Y.bn())}ar(){this.lc(Y.gn())}Jh(){this.lc(new Y(1))}Eh(t){const i=this.ac(t);this.lc(i)}oc(){return this.Gu}_c(t){if(this.Gu?.r_===t?.r_&&this.Gu?.h_?.Gn===t?.h_?.Gn)return;const i=this.Gu;this.Gu=t,null!==i&&this.Eh(i.r_),null!==t&&t.r_!==i?.r_&&this.Eh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Yu.forEach(i=>i.Fo(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.Z_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Ku.p(),this.ec=this.rc(0),this.hc=this.rc(1),this.Ah()}uc(t,i,s=0){const n=this.Yu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fo({leftPriceScale:i}),this.Ku.p(),void this.Ah();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fo({rightPriceScale:i}),this.Ku.p(),void this.Ah();const e=this.cc(t,s);null!==e&&(e.$t.lr(i),this.Ku.p())}cc(t,i){const s=this.Yu[i];if(void 0===s)return null;const n=s.Io(t);return null!==n?{Us:s,$t:n}:null}At(){return this.ph}qs(){return this.Yu}dc(){return this.Ct}fc(){return this.Zu}vc(t,i){t.Ba(i),this.wu()}Eo(t){this.yo=t,this.ph.Eo(this.yo),this.Yu.forEach(i=>i.Eo(t)),this.wu()}mc(t){1!==this.Yu.length&&(r(t>=0&&t<this.Yu.length,"Invalid pane index"),this.Yu.splice(t,1),this.Ah())}wc(t,i){if(this.Yu.length<2)return;r(t>=0&&t<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu.reduce((t,i)=>t+i.Lo(),0),e=this.Yu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Yu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,a=s.qt();s.Ao(i*l);let o=i-a,_=this.Yu.length-1;for(const t of this.Yu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-o/_));o-=t.qt()-i,_-=1;const s=i*l;t.Ao(s)}this.Ah()}gc(t,i){r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu[i];this.Yu[t]=n,this.Yu[i]=s,this.Ah()}bc(t,i){if(r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index"),t===i)return;const[s]=this.Yu.splice(t,1);this.Yu.splice(i,0,s),this.Ah()}qo(t,i,s){t.qo(i,s)}jo(t,i,s){t.jo(i,s),this.Bh(),this.lc(this.Mc(t,2))}Yo(t,i){t.Yo(i),this.lc(this.Mc(t,2))}Xo(t,i,s){i.Ra()||t.Xo(i,s)}Go(t,i,s){i.Ra()||(t.Go(i,s),this.Bh(),this.lc(this.Mc(t,2)))}Ko(t,i){i.Ra()||(t.Ko(i),this.lc(this.Mc(t,2)))}Jo(t,i){t.Jo(i),this.lc(this.Mc(t,2))}yc(t){this.ph.ro(t)}Sc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Pu(t,i),this.wu()}xc(t){this.Cc(0),this.Pc(t),this.Tc()}kc(t){this.ph.ho(t),this.wu()}Dc(){this.ph.lo(),this.ar()}Cc(t){this.ph.ao(t)}Pc(t){this.ph.oo(t),this.wu()}Tc(){this.ph._o(),this.ar()}Xs(){return this.Xu}Rc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.ph.pu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const a=n.ks(),o=a.Bt();if(null!==o&&(r=a.Ds(i,o)),r=this.sc.Ml(r,h,n),this.Ct.Es(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this._c(e&&{r_:e.r_,h_:e.h_,a_:e.a_||null}),this.Zu.p(this.Ct.Lt(),{x:t,y:i},s)}}Fc(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.ph.iu(i,!0),a=this.ph.jt(l(h));this.Rc(a,r,null,s,!0)}Ic(t){this.dc().Os(),this.Jh(),t||this.Zu.p(null,null,null)}Bh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Rc(i,s,null,t)}this.Ct.zs()}Vc(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.cu(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),a=null!==t&&t>r&&!l,o=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||o)&&this.ph.W().shiftVisibleRangeOnNewBar;if(a&&!_){const i=t-r;this.ph.fn(this.ph.Mu()-i)}}this.ph.Cu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Yu.find(i=>i.Ft().includes(t));return void 0===i?null:i}wu(){this.Yu.forEach(t=>t.t_()),this.Bh()}m(){this.Yu.forEach(t=>t.m()),this.Yu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Lc(){return this.tc}Yn(){return this.tc.W()}Vo(){return this.Ku}Ac(t,i){const s=this.nc(i);this.Ec(t,s),this.Xu.push(t),1===this.Xu.length?this.Ah():this.ar()}Bc(t){const i=this.Nn(t),s=this.Xu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Xu.splice(s,1),n.so(t),t.m&&t.m(),this.ph.K_();const e=this.Yu.length;this.Oc(n),this.Yu.length<e&&this.Ah()}Lh(t,i){const s=l(this.Nn(t));s.so(t,!0),s.Qa(t,i,!0)}Bu(){const t=Y.gn();t.hn(),this.lc(t)}Wc(t){const i=Y.gn();i._n(t),this.lc(i)}dn(){const t=Y.gn();t.dn(),this.lc(t)}pn(t){const i=Y.gn();i.pn(t),this.lc(i)}fn(t){const i=Y.gn();i.fn(t),this.lc(i)}un(t){const i=Y.gn();i.un(t),this.lc(i)}ln(){const t=Y.gn();t.ln(),this.lc(t)}zc(){return this.Ps.rightPriceScale.visible?"right":"left"}$c(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Hc(t))return;const s=l(this.Nn(t));s.so(t);const n=this.nc(i);this.Ec(t,n),0===s.yl().length&&this.Oc(s),this.Ah()}Nc(){return this.hc}q(){return this.ec}Ut(t){const i=this.hc,s=this.ec;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Ju||this.Ju.wr!==s||this.Ju.gr!==i)this.Ju={wr:s,gr:i,Uc:new Map};else{const i=this.Ju.Uc.get(t);if(void 0!==i)return i}const n=this.xa.it(s,i,t/100);return this.Ju.Uc.set(t,n),n}qc(t){return this.Yu.indexOf(t)}Ki(){return this.xa}jc(){return this.Yc()}Yc(t){const i=new wi(this.ph,this);this.Yu.push(i);const s=t??this.Yu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.lc(n),i}nc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Yu.length,t))<this.Yu.length?this.Yu[t]:this.Yc(t)}Hc(t){return this.Yu.findIndex(i=>i.zo().includes(t))}Mc(t,i){const s=new Y(i);if(null!==t){const n=this.Yu.indexOf(t);s.tn(n,{sn:i})}return s}ac(t,i){return void 0===i&&(i=2),this.Mc(this.Nn(t),i)}lc(t){this.Qu&&this.Qu(t),this.Yu.forEach(t=>t.n_()._r().Tt())}Ec(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.zc();i.Qa(t,n),j(n)||t.lr(t.W())}rc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Oc(t){!t.Wo()&&0===t.yl().length&&this.Yu.length>1&&this.Yu.splice(this.qc(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 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"}(Ii||(Ii={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Vi||(Vi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Li||(Li={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Ai||(Ai={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>K(zi(t),4))(t)).replace(/yy/g,(t=>K(zi(t)%100,2))(t)).replace(/MMMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(t,s)).replace(/MMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(t,s)).replace(/MM/g,(t=>K((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>K((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Xc=t,this.Gc=i}c_(t){return $i(t,this.Xc,this.Gc)}}class Ni{constructor(t){this.Kc=t||"%h:%m:%s"}c_(t){return this.Kc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Zc:"yyyy-MM-dd",Jc:"%h:%m:%s",Qc:" ",td:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.sd=new Hi(i.Zc,i.td),this.nd=new Ni(i.Jc),this.ed=i.Qc}c_(t){return`${this.sd.c_(t)}${this.ed}${this.nd.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{rd:(Gi=1,1e3*Gi),hd:10},{rd:Yi(1),hd:20},{rd:Yi(5),hd:21},{rd:Yi(30),hd:22},{rd:ji(1),hd:30},{rd:ji(3),hd:31},{rd:ji(6),hd:32},{rd:ji(12),hd:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].rd)!==Math.floor(t.getTime()/Xi[s].rd))return Xi[s].hd;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{ld:Math.round(s.getTime()/1e3),ad:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{ld: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&&"ld"in t?t.ld:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ad?new Date(1e3*i.ld).getTime():new Date(Date.UTC(i.ad.year,i.ad.month-1,i.ad.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({Zc:i,Jc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Qc:" ",td:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.c_(new Date(1e3*i.ld))}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.ad?new Date(1e3*t.ld):new Date(Date.UTC(t.ad.year,t.ad.month-1,t.ad.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.ld,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).ld);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).ld-(s||Zi(i.time).ld),s=Zi(i.time).ld,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.ld-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.ld),s)}}(t,i)}static _d(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 as=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function os(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new as(e,s,n)}const _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.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.wd=null,this.gd=!1,this.bd=null,this.Md=null,this.yd=!1,this.Sd=!1,this.xd=!1,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Id=0,this.Vd=!1,this.Ld=!1,this.Ad=!1,this.Ed=0,this.Bd=null,this.Od=!cs(),this.Wd=t=>{this.zd(t)},this.$d=t=>{if(this.Hd(t)){const i=this.Nd(t);if(++this.fd,this.vd&&this.fd>1){const{Ud:s}=this.qd(ws(t),this.md);s<30&&!this.xd&&this.jd(i,this.Xd.Yd),this.Gd()}}else{const i=this.Nd(t);if(++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}}},this.Qd=t,this.Xd=i,this.Ps=s,this.tp()}m(){null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Td&&(this.Td(),this.Td=null),this.ip(),this.Jd()}sp(t){this.kd&&this.kd();const i=this.np.bind(this);if(this.kd=()=>{this.Qd.removeEventListener("mousemove",i)},this.Qd.addEventListener("mousemove",i),this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.ep),this.Od=!0}Jd(){null!==this.dd&&clearTimeout(this.dd),this.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Gd(){null!==this.vd&&clearTimeout(this.vd),this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}np(t){if(this.Ad||null!==this.Md)return;if(this.Hd(t))return;const i=this.Nd(t);this.Kd(i,this.Xd.rp),this.Od=!0}hp(t){const i=bs(t.changedTouches,l(this.Bd));if(null===i)return;if(this.Ed=gs(t),null!==this.Fd)return;if(this.Ld)return;this.Vd=!0;const s=this.qd(ws(i),l(this.Md)),{lp:n,ap:e,Ud:r}=s;if(this.yd||!(r<5)){if(!this.yd){const t=.5*n,i=e>=t&&!this.Ps.op(),s=t>e&&!this.Ps._p();i||s||(this.Ld=!0),this.yd=!0,this.xd=!0,this.ip(),this.Gd()}if(!this.Ld){const s=this.Nd(t,i);this.jd(s,this.Xd.up),ms(t)}}}cp(t){if(0!==t.button)return;const i=this.qd(ws(t),l(this.bd)),{Ud:s}=i;if(s>=5&&(this.Sd=!0,this.Jd()),this.Sd){const i=this.Nd(t);this.Kd(i,this.Xd.dp)}}qd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{lp:s,ap:n,Ud:s+n}}pp(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.ip(),this.Md=null,this.Rd&&(this.Rd(),this.Rd=null);const s=this.Nd(t,i);if(this.jd(s,this.Xd.fp),++this.fd,this.vd&&this.fd>1){const{Ud:t}=this.qd(ws(i),this.md);t<30&&!this.xd&&this.jd(s,this.Xd.Yd),this.Gd()}else this.xd||(this.jd(s,this.Xd.vp),this.Xd.vp&&ms(t));0===this.fd&&ms(t),0===t.touches.length&&this.gd&&(this.gd=!1,ms(t))}zd(t){if(0!==t.button)return;const i=this.Nd(t);if(this.bd=null,this.Ad=!1,this.Dd&&(this.Dd(),this.Dd=null),us()){this.Qd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Wd)}if(!this.Hd(t))if(this.Kd(i,this.Xd.mp),++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}else this.Sd||this.Kd(i,this.Xd.wp)}ip(){null!==this.wd&&(clearTimeout(this.wd),this.wd=null)}gp(t){if(null!==this.Bd)return;const i=t.changedTouches[0];this.Bd=i.identifier,this.Ed=gs(t);const s=this.Qd.ownerDocument.documentElement;this.xd=!1,this.yd=!1,this.Ld=!1,this.Md=ws(i),this.Rd&&(this.Rd(),this.Rd=null);{const i=this.hp.bind(this),n=this.pp.bind(this);this.Rd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.ip(),this.wd=setTimeout(this.bp.bind(this,t),240)}const n=this.Nd(t,i);this.jd(n,this.Xd.Mp),this.vd||(this.fd=0,this.vd=setTimeout(this.Gd.bind(this),500),this.md=ws(i))}yp(t){if(0!==t.button)return;const i=this.Qd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Wd),this.Sd=!1,this.bd=ws(t),this.Dd&&(this.Dd(),this.Dd=null);{const t=this.cp.bind(this),s=this.zd.bind(this);this.Dd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ad=!0,this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.Sp),this.dd||(this.ud=0,this.dd=setTimeout(this.Jd.bind(this),500),this.pd=ws(t))}tp(){this.Qd.addEventListener("mouseenter",this.sp.bind(this)),this.Qd.addEventListener("touchcancel",this.ip.bind(this));{const t=this.Qd.ownerDocument,i=t=>{this.Xd.xp&&(t.composed&&this.Qd.contains(t.composedPath()[0])||t.target&&this.Qd.contains(t.target)||this.Xd.xp())};this.Pd=()=>{t.removeEventListener("touchstart",i)},this.Cd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Td=()=>{this.Qd.removeEventListener("dblclick",this.$d)},this.Qd.addEventListener("dblclick",this.$d)),this.Qd.addEventListener("mouseleave",this.Cp.bind(this)),this.Qd.addEventListener("touchstart",this.gp.bind(this),{passive:!0}),ps(this.Qd),this.Qd.addEventListener("mousedown",this.yp.bind(this)),this.Pp(),this.Qd.addEventListener("touchmove",()=>{},{passive:!1})}Pp(){void 0===this.Xd.Tp&&void 0===this.Xd.kp&&void 0===this.Xd.Dp||(this.Qd.addEventListener("touchstart",t=>this.Rp(t.touches),{passive:!0}),this.Qd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Fd&&void 0!==this.Xd.kp){const i=vs(t.touches[0],t.touches[1])/this.Id;this.Xd.kp(this.Fd,i),ms(t)}},{passive:!1}),this.Qd.addEventListener("touchend",t=>{this.Rp(t.touches)}))}Rp(t){1===t.length&&(this.Vd=!1),2!==t.length||this.Vd||this.gd?this.Fp():this.Ip(t)}Ip(t){const i=this.Qd.getBoundingClientRect()||{left:0,top:0};this.Fd={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Id=vs(t[0],t[1]),void 0!==this.Xd.Tp&&this.Xd.Tp(),this.ip()}Fp(){null!==this.Fd&&(this.Fd=null,void 0!==this.Xd.Dp&&this.Xd.Dp())}Cp(t){if(this.kd&&this.kd(),this.Hd(t))return;if(!this.Od)return;const i=this.Nd(t);this.Kd(i,this.Xd.Vp),this.Od=!cs()}bp(t){const i=bs(t.touches,l(this.Bd));if(null===i)return;const s=this.Nd(t,i);this.jd(s,this.Xd.Lp),this.xd=!0,this.gd=!0}Hd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ed+500}jd(t,i){i&&i.call(this.Xd,t)}Kd(t,i){i&&i.call(this.Xd,t)}Nd(t,i){const s=i||t,n=this.Qd.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,Ap:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ep:t.type,Bp:s.target,o_:t.view,Op:()=>{"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.zp=null,this.$p=!0,this.Hp=null,this.Np=t,this.Up=t.qp()[i],this.jp=t.qp()[s],this.Yp=document.createElement("tr"),this.Yp.style.height="1px",this.Xp=document.createElement("td"),this.Xp.style.position="relative",this.Xp.style.padding="0",this.Xp.style.margin="0",this.Xp.setAttribute("colspan","3"),this.Gp(),this.Yp.appendChild(this.Xp),this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(this.Wp=null,this.zp=null)}m(){null!==this.zp&&this.zp.m()}Zp(){return this.Yp}Jp(){return ns({width:this.Up.Jp().width,height:1})}Qp(){return ns({width:this.Up.Qp().width,height:1*window.devicePixelRatio})}tf(t,i,s){const n=this.Qp();t.fillStyle=this.Np.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Gp(),this.Np.W().layout.panes.enableResize!==this.$p&&(this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(null!==this.Wp&&(this.Xp.removeChild(this.Wp.if),this.Xp.removeChild(this.Wp.sf),this.Wp=null),null!==this.zp&&(this.zp.m(),this.zp=null)))}Kp(){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.Xp.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.Xp.appendChild(s);const e={ep:this.nf.bind(this),Vp:this.ef.bind(this),Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this)};this.zp=new fs(s,e,{op:()=>!1,_p:()=>!0}),this.Wp={sf:s,if:t}}Gp(){this.Xp.style.background=this.Np.W().layout.panes.separatorColor}nf(t){null!==this.Wp&&(this.Wp.sf.style.backgroundColor=this.Np.W().layout.panes.separatorHoverColor)}ef(t){null!==this.Wp&&null===this.Hp&&(this.Wp.sf.style.backgroundColor="")}rf(t){if(null===this.Wp)return;const i=this.Up.af().Lo()+this.jp.af().Lo(),s=i/(this.Up.Jp().height+this.jp.Jp().height),n=30*s;i<=2*n||(this.Hp={_f:t.pageY,uf:this.Up.af().Lo(),cf:i-n,df:i,pf:s,ff:n},this.Wp.if.style.display="block")}hf(t){const i=this.Hp;if(null===i)return;const s=(t.pageY-i._f)*i.pf,n=Xt(i.uf+s,i.ff,i.cf);this.Up.af().Ao(n),this.jp.af().Ao(i.df-n),this.Np.ti().Ah()}lf(t){null!==this.Hp&&null!==this.Wp&&(this.Hp=null,this.Wp.if.style.display="none")}}function ys(t,i){return t.vf-i.vf}function Ss(t,i,s){const n=(t.vf-i.vf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=0,this.Sf=0,this.xf=t,this.Cf=i,this.Pf=s,this.Mn=n}Tf(t,i){if(null!==this.mf){if(this.mf.gt===i)return void(this.mf.vf=t);if(Math.abs(this.mf.vf-t)<this.Mn)return}this.bf=this.gf,this.gf=this.wf,this.wf=this.mf,this.mf={gt:i,vf:t}}oe(t,i){if(null===this.mf||null===this.wf)return;if(i-this.mf.gt>50)return;let s=0;const n=Ss(this.mf,this.wf,this.Cf),e=ys(this.mf,this.wf),r=[n],h=[e];if(s+=e,null!==this.gf){const t=Ss(this.wf,this.gf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);if(r.push(t),h.push(i),s+=i,null!==this.bf){const t=Ss(this.gf,this.bf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.gf,this.bf);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.xf||(this.Mf={vf:t,gt:i},this.Sf=l,this.yf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Pf))}Iu(t){const i=l(this.Mf),s=t-i.gt;return i.vf+this.Sf*(Math.pow(this.Pf,s)-1)/Math.log(this.Pf)}Fu(t){return null===this.Mf||this.kf(t)===this.yf}kf(t){const i=t-l(this.Mf).gt;return Math.min(i,this.yf)}}class Cs{constructor(t,i){this.Df=void 0,this.Rf=void 0,this.Ff=void 0,this.vs=!1,this.If=t,this.Vf=i,this.Lf()}Tt(){this.Lf()}Af(){this.Df&&this.If.removeChild(this.Df),this.Rf&&this.If.removeChild(this.Rf),this.Df=void 0,this.Rf=void 0}Ef(){return this.vs!==this.Bf()||this.Ff!==this.Of()}Of(){return this.Vf.ti().Ki().tt(this.Vf.W().layout.textColor)>160?"dark":"light"}Bf(){return this.Vf.W().layout.attributionLogo}Wf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Lf(){this.Ef()&&(this.Af(),this.vs=this.Bf(),this.vs&&(this.Ff=this.Of(),this.Rf=document.createElement("style"),this.Rf.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.Df=document.createElement("a"),this.Df.href=`https://pipsend.com${this.Wf()}`,this.Df.title="Powered by Pipsend Charts",this.Df.id="pipsend-attr-logo",this.Df.target="_blank",this.Df.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.Df.toggleAttribute("data-dark","dark"===this.Ff),this.If.appendChild(this.Rf),this.If.appendChild(this.Df)))}}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.nh&&t.nh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function Rs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Fs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],a=t[r-1],o=a.qt(n,!1),_=l.$i(),u=a.$i();if(1===i?_>u-o:_<u+o){const n=u-o*i;l.Hi(n);const r=n-i*o/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-o-_:_-(u+o)}}class Vs{constructor(t,i,s,n){this.Yi=null,this.zf=null,this.$f=!1,this.Hf=new it(200),this.Nf=null,this.Uf=0,this.qf=!1,this.jf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Xf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Pt=t,this.Ps=i,this.ya=i.layout,this.tc=s,this.Gf="left"===n,this.Kf=Fs("normal",n),this.Zf=Fs("top",n),this.Jf=Fs("bottom",n),this.Xp=document.createElement("div"),this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Xp.style.width="25px",this.Xp.style.left="0",this.Xp.style.position="relative",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.tv=Ps(this.Xp,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const r=this.tv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),xp:this.iv.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this),Zd:this.sv.bind(this),Yd:this.sv.bind(this),ep:this.nv.bind(this),Vp:this.ef.bind(this)};this.zp=new fs(this.tv.canvasElement,h,{op:()=>!this.Ps.handleScroll.vertTouchDrag,_p:()=>!0})}m(){this.zp.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Yi&&this.Yi.eo().u(this),this.Yi=null}Zp(){return this.Xp}P(){return this.ya.fontSize}ev(){const t=this.tc.W();return this.Nf!==t.T&&(this.Hf.Vn(),this.Nf=t.T),t}rv(){if(null===this.Yi)return 0;let t=0;const i=this.ev(),s=l(this.Qf.canvasElement.getContext("2d",{colorSpace:this.Pt.Yf().W().layout.colorSpace}));s.save();const n=this.Yi.Il();s.font=this.hv(),n.length>0&&(t=Math.max(this.Hf.Ii(s,n[0].Jl),this.Hf.Ii(s,n[n.length-1].Jl)));const e=this.lv();for(let i=e.length;i--;){const n=this.Hf.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.zf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.zf.height-2,r);t=Math.max(t,this.Hf.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Hf.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const a=t||34;return ds(Math.ceil(i.S+i.C+i.V+i.L+5+a))}av(t){null!==this.zf&&es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`)}ov(){return l(this.zf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.eo().u(this),this.Yi=t,t.eo().i(this.ca.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt.af();this.Pt.Yf().ti().Jo(t,l(this.$t()))}_v(t){if(null===this.zf)return;const i={colorSpace:this.Pt.Yf().W().layout.colorSpace};if(1!==t){this.uv(),this.Qf.applySuggestedBitmapSize();const t=os(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)}),this.Pt.pv(t,this.Jf),this.fv(t),this.Pt.pv(t,this.Kf),this.vv(t))}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.mv(s),this.Pt.pv(s,this.Zf))}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Il()}rf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!0,i.qo(s,this.Yi,t.localY)}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af(),n=this.Yi;i.jo(s,n,t.localY)}iv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Yf().ti(),i=this.Pt.af(),s=this.Yi;this.$f&&(this.$f=!1,t.Yo(i,s))}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!1,i.Yo(s,this.Yi)}sv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}nv(t){if(null===this.Yi)return;!this.Pt.Yf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Ia()||this.wv(1)}ef(t){this.wv(0)}lv(){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.af(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.af().Ft()),t}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.af().ti(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.zf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.ev().S*s));let e;e=this.Gf?i.width-n:0,t.fillRect(e,0,n,i.height)}fv(t){if(null===this.zf||null===this.Yi)return;const i=this.Yi.Il(),s=this.Yi.W(),n=this.ev(),e=this.Gf?this.zf.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)),a=Math.floor(.5*h),o=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-a,o,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.hv(),t.fillStyle=s.textColor??this.ya.textColor,t.textAlign=this.Gf?"right":"left",t.textBaseline="middle";const r=this.Gf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.Hf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}uv(){if(null===this.zf||null===this.Yi)return;let t=this.zf.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt.af(),e=this.ev();this.Yi===n.qn()&&this.Pt.af().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.gv(i,e,t)}gv(t,i,s){if(null===this.zf)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.zf.height-t&&n<this.zf.height+t&&s.Hi(this.zf.height-t)}Is(n,1,this.zf.height,i),Is(e,-1,this.zf.height,i)}vv(t){if(null===this.zf)return;const i=this.lv(),s=this.ev(),n=this.Gf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Hf,n)}})}mv(t){if(null===this.zf||null===this.Yi)return;const i=this.Pt.Yf().ti(),s=[],n=this.Pt.af(),e=i.dc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.ev(),h=this.Gf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Hf,h)})})}wv(t){this.Xp.style.cursor=1===t?"ns-resize":"default"}ca(){const t=this.rv();this.Uf<t&&this.Pt.Yf().ti().Ah(),this.Uf=t}hv(){return g(this.ya.fontSize,this.ya.fontFamily)}}function Ls(t,i){return t.tl?.(i)??[]}function As(t,i){return t.$s?.(i)??[]}function Es(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Zh?.(i)??[]}class Os{constructor(t,i){this.zf=ns({width:0,height:0}),this.bv=null,this.Mv=null,this.yv=null,this.Sv=null,this.xv=!1,this.Cv=new o,this.Pv=new o,this.Tv=0,this.kv=!1,this.Dv=null,this.Rv=!1,this.Fv=null,this.Iv=null,this.qf=!1,this.jf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Xf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Vf=t,this.Vv=i,this.Vv.s_().i(this.Lv.bind(this),this,!0),this.Av=document.createElement("td"),this.Av.style.padding="0",this.Av.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.Av.appendChild(s),this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.tv=Ps(s,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Yp=document.createElement("tr"),this.Yp.appendChild(this.Ev),this.Yp.appendChild(this.Av),this.Yp.appendChild(this.Bv),this.Ov(),this.zp=new fs(this.tv.canvasElement,this,{op:()=>null===this.Dv&&!this.Vf.W().handleScroll.vertTouchDrag,_p:()=>null===this.Dv&&!this.Vf.W().handleScroll.horzTouchDrag})}m(){null!==this.bv&&this.bv.m(),null!==this.Mv&&this.Mv.m(),this.yv=null,this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Vv&&(this.Vv.s_().u(this),this.Vv.m()),this.zp.m()}af(){return l(this.Vv)}Wv(t){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=t,null!==this.Vv&&this.Vv.s_().i(Os.prototype.Lv.bind(this),this,!0),this.Ov(),this.Vf.qp().indexOf(this)===this.Vf.qp().length-1?(this.yv=this.yv??new Cs(this.Av,this.Vf),this.yv.Tt()):(this.yv?.Af(),this.yv=null)}Yf(){return this.Vf}Zp(){return this.Yp}Ov(){if(null!==this.Vv&&(this.zv(),0!==this.ss().Xs().length)){if(null!==this.bv){const t=this.Vv.No();this.bv.us(l(t))}if(null!==this.Mv){const t=this.Vv.Uo();this.Mv.us(l(t))}}}$v(){null!==this.bv&&this.bv.Tt(),null!==this.Mv&&this.Mv.Tt()}Lo(){return null!==this.Vv?this.Vv.Lo():0}Ao(t){this.Vv&&this.Vv.Ao(t)}ep(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}Sp(t){this.Hv(),this.Uv(),this.Nv(t.localX,t.localY,t)}rp(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}wp(t){null!==this.Vv&&(this.Hv(),this.qv(t))}Zd(t){null!==this.Vv&&this.jv(this.Pv,t)}Yd(t){this.Zd(t)}dp(t){this.Hv(),this.Yv(t),this.Nv(t.localX,t.localY,t)}mp(t){null!==this.Vv&&(this.Hv(),this.kv=!1,this.Xv(t))}vp(t){null!==this.Vv&&this.qv(t)}Lp(t){if(this.kv=!0,null===this.Dv){const i={x:t.localX,y:t.localY};this.Gv(i,i,t)}}Vp(t){null!==this.Vv&&(this.Hv(),this.Vv.ti()._c(null),this.Kv())}Zv(){return this.Cv}Jv(){return this.Pv}Tp(){this.Tv=1,this.ss().ln()}kp(t,i){if(!this.Vf.W().handleScale.pinch)return;const s=5*(i-this.Tv);this.Tv=i,this.ss().Sc(t.ut,s)}Mp(t){this.kv=!1,this.Rv=null!==this.Dv,this.Uv();const i=this.ss().dc();null!==this.Dv&&i.It()&&(this.Fv={x:i.ni(),y:i.ei()},this.Dv={x:t.localX,y:t.localY})}up(t){if(null===this.Vv)return;const i=t.localX,s=t.localY;if(null!==this.Dv){this.Rv=!1;const n=l(this.Fv),e=n.x+(i-this.Dv.x),r=n.y+(s-this.Dv.y);return void this.Nv(e,r,t)}this.Yv(t)}fp(t){0===this.Yf().W().trackingMode.exitMode&&(this.Rv=!0),this.Qv(),this.Xv(t)}Xn(t,i){const s=this.Vv;return null===s?null:Si(s,t,i)}tm(t,i){l("left"===i?this.bv:this.Mv).av(ns({width:t,height:this.zf.height}))}Jp(){return this.zf}av(t){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Av.style.width=t.width+"px",this.Av.style.height=t.height+"px")}im(){const t=l(this.Vv);t.Ho(t.No()),t.Ho(t.Uo());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ho(s),i.zs()}for(const i of t.e_())i.zs()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;null!==t&&t.drawImage(n,i,s)}}_v(t){if(0===t)return;if(null===this.Vv)return;t>1&&this.im(),null!==this.bv&&this.bv._v(t),null!==this.Mv&&this.Mv._v(t);const i={colorSpace:this.Vf.W().layout.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const t=os(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t)}),this.Vv&&(this.sm(t,Ls),this.nm(t),this.sm(t,As),this.sm(t,Es)))}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.rm(s),this.sm(s,Bs),this.sm(s,Es))}hm(){return this.bv}lm(){return this.Mv}pv(t,i){this.sm(t,i)}Lv(){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=null}qv(t){this.jv(this.Cv,t)}jv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().pu(s),{x:s,y:n},i)}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}nm(t){const i=l(this.Vv),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}rm(t){this.am(t,As,Ds,this.ss().dc())}sm(t,i){const s=l(this.Vv),n=s.Ft(),e=s.e_();for(const s of e)this.am(t,i,ks,s);for(const s of n)this.am(t,i,ks,s);for(const s of e)this.am(t,i,Ds,s);for(const s of n)this.am(t,i,Ds,s)}am(t,i,s,n){const e=l(this.Vv),r=e.ti().oc(),h=null!==r&&r.r_===n,a=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Rs(i,i=>s(i,t,h,a),n,e)}zv(){if(null===this.Vv)return;const t=this.Vf,i=this.Vv.No().W().visible,s=this.Vv.Uo().W().visible;i||null===this.bv||(this.Ev.removeChild(this.bv.Zp()),this.bv.m(),this.bv=null),s||null===this.Mv||(this.Bv.removeChild(this.Mv.Zp()),this.Mv.m(),this.Mv=null);const n=t.ti().Lc();i&&null===this.bv&&(this.bv=new Vs(this,t.W(),n,"left"),this.Ev.appendChild(this.bv.Zp())),s&&null===this.Mv&&(this.Mv=new Vs(this,t.W(),n,"right"),this.Bv.appendChild(this.Mv.Zp()))}om(t){return t.Ap&&this.kv||null!==this.Dv}_m(t){return Math.max(0,Math.min(t,this.zf.width-1))}um(t){return Math.max(0,Math.min(t,this.zf.height-1))}Nv(t,i,s){this.ss().Rc(this._m(t),this.um(i),s,l(this.Vv))}Kv(){this.ss().Ic()}Qv(){this.Rv&&(this.Dv=null,this.Kv())}Gv(t,i,s){this.Dv=t,this.Rv=!1,this.Nv(i.x,i.y,s);const n=this.ss().dc();this.Fv={x:n.ni(),y:n.ei()}}ss(){return this.Vf.ti()}Xv(t){if(!this.xv)return;const i=this.ss(),s=this.af();if(i.Ko(s,s.ks()),this.Sv=null,this.xv=!1,i.Tc(),null!==this.Iv){const t=performance.now(),s=i.At();this.Iv.oe(s.Mu(),t),this.Iv.Fu(t)||i.un(this.Iv)}}Hv(){this.Dv=null}Uv(){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().At().Gi()}Yv(t){if(null===this.Vv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.Vf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Ap)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Ap))return;const h=this.Vv.ks(),l=performance.now();if(null!==this.Sv||this.om(t)||(this.Sv={x:t.clientX,y:t.clientY,ld:l,dm:t.localX,pm:t.localY}),null!==this.Sv&&!this.xv&&(this.Sv.x!==t.clientX||this.Sv.y!==t.clientY)){if(t.Ap&&r.touch||!t.Ap&&r.mouse){const t=s.gu();this.Iv=new xs(.2/t,7/t,.997,15/t),this.Iv.Tf(s.Mu(),this.Sv.ld)}else this.Iv=null;h.Gi()||i.Xo(this.Vv,h,t.localY),i.Cc(t.localX),this.xv=!0}this.xv&&(h.Gi()||i.Go(this.Vv,h,t.localY),i.Pc(t.localX),null!==this.Iv&&this.Iv.Tf(s.Mu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.zf=ns({width:0,height:0}),this.jf=()=>this._v(3),this.Gf="left"===t,this.tc=s.Lc,this.Ps=i,this.fm=n,this.vm=e,this.Xp=document.createElement("div"),this.Xp.style.width="25px",this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf)}m(){this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Xp}Jp(){return this.zf}av(t){es(this.zf,t)||(this.zf=t,this.Qf.resizeCanvasElement(t),this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.xt=!0)}_v(t){if(t<3&&!this.xt)return;if(0===this.zf.width||0===this.zf.height)return;this.xt=!1,this.Qf.applySuggestedBitmapSize();const i=os(this.Qf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)})}Qp(){return this.Qf.bitmapSize}tf(t,i,s){const n=this.Qp();n.width>0&&n.height>0&&t.drawImage(this.Qf.canvasElement,i,s)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.fm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.tc.W().S*s),r=Math.floor(this.tc.W().S*n),h=this.Gf?i.width-e:0;t.fillRect(h,0,e,r)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.vm())}}function zs(t){return i=>i.nl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.wm=null,this.gm=null,this.M=null,this.bm=!1,this.zf=ns({width:0,height:0}),this.Mm=new o,this.Hf=new it(5),this.qf=!1,this.jf=()=>{this.qf||this.Vf.ti().ar()},this.Xf=()=>{this.qf||this.Vf.ti().ar()},this.Vf=t,this.u_=i,this.Ps=t.W().layout,this.Df=document.createElement("tr"),this.ym=document.createElement("td"),this.ym.style.padding="0",this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.Xp=document.createElement("td"),this.Xp.style.height="25px",this.Xp.style.padding="0",this.xm=document.createElement("div"),this.xm.style.width="100%",this.xm.style.height="100%",this.xm.style.position="relative",this.xm.style.overflow="hidden",this.Xp.appendChild(this.xm),this.Qf=Ps(this.xm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const s=this.Qf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.tv=Ps(this.xm,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Df.appendChild(this.ym),this.Df.appendChild(this.Xp),this.Df.appendChild(this.Sm),this.Cm(),this.Vf.ti().Vo().i(this.Cm.bind(this),this),this.zp=new fs(this.tv.canvasElement,this,{op:()=>!0,_p:()=>!this.Vf.W().handleScroll.horzTouchDrag})}m(){this.zp.m(),null!==this.wm&&this.wm.m(),null!==this.gm&&this.gm.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Df}Pm(){return this.wm}Tm(){return this.gm}Sp(t){if(this.bm)return;this.bm=!0;const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.yc(t.localX)}Mp(t){this.Sp(t)}xp(){const t=this.Vf.ti();!t.At().Gi()&&this.bm&&(this.bm=!1,this.Vf.W().handleScale.axisPressedMouseMove.time&&t.Dc())}dp(t){const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.kc(t.localX)}up(t){this.dp(t)}mp(){this.bm=!1;const t=this.Vf.ti();t.At().Gi()&&!this.Vf.W().handleScale.axisPressedMouseMove.time||t.Dc()}fp(){this.mp()}Zd(){this.Vf.W().handleScale.axisDoubleClickReset.time&&this.Vf.ti().dn()}Yd(){this.Zd()}ep(){this.Vf.ti().W().handleScale.axisPressedMouseMove.time&&this.wv(1)}Vp(){this.wv(0)}Jp(){return this.zf}km(){return this.Mm}Dm(t,i,s){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.Mm.p(t)),null!==this.wm&&this.wm.av(ns({width:i,height:t.height})),null!==this.gm&&this.gm.av(ns({width:s,height:t.height}))}Rm(){const t=this.Fm();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Im)}Tt(){this.Vf.ti().At().Il()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}_v(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const s=os(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t),this.Vm(s,Ns)}),this.fv(s),this.Vm(s,$s)),null!==this.wm&&this.wm._v(t),null!==this.gm&&this.gm._v(t)}this.tv.applySuggestedBitmapSize();const s=os(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Lm([...this.Vf.ti().Xs(),this.Vf.ti().dc()],s),this.Vm(s,Hs))}Vm(t,i){const s=this.Vf.ti().Xs();for(const n of s)Rs(i,i=>ks(i,t,!1,void 0),n,void 0);for(const n of s)Rs(i,i=>Ds(i,t,!1,void 0),n,void 0)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.Vf.ti().Nc())}dv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Vf.W().timeScale.borderVisible){t.fillStyle=this.Am();const n=Math.max(1,Math.floor(this.Fm().S*s));t.fillRect(0,0,i.width,n)}}fv(t){const i=this.Vf.ti().At(),s=i.Il();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Fm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Am(),t.fillStyle=this.Am();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.hv();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.Vf.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.Hf.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.zf.width&&(i-=Math.abs(this.zf.width-(r+n))),i}Lm(t,i){const s=this.Fm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Am(){return this.Vf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}hv(){return g(this.$(),this.Ps.fontFamily)}Bm(){return g(this.$(),this.Ps.fontFamily,"bold")}Fm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Im:0});const t=this.M,i=this.hv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.A=3*s/12,t.I=3*s/12,t.Qi=9*s/12,t.B=0,t.Im=4*s/12,t.Ji.Vn()}return this.M}wv(t){this.Xp.style.cursor=1===t?"ew-resize":"default"}Cm(){const t=this.Vf.ti(),i=t.W();i.leftPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Zp()),this.wm.m(),this.wm=null),i.rightPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Zp()),this.gm.m(),this.gm=null);const s={Lc:this.Vf.ti().Lc()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Nc();i.leftPriceScale.visible&&null===this.wm&&(this.wm=new Ws("left",i,s,n,e),this.ym.appendChild(this.wm.Zp())),i.rightPriceScale.visible&&null===this.gm&&(this.gm=new Ws("right",i,s,n,e),this.Sm.appendChild(this.gm.Zp()))}}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.Om=[],this.Wm=[],this.zm=0,this.na=0,this.yo=0,this.$m=0,this.Hm=0,this.Nm=null,this.Um=!1,this.Cv=new o,this.Pv=new o,this.Zu=new o,this.qm=null,this.jm=null,this.If=t,this.Ps=i,this.u_=s,this.Df=document.createElement("div"),this.Df.classList.add("tv-lightweight-charts"),this.Df.style.overflow="hidden",this.Df.style.direction="ltr",this.Df.style.width="100%",this.Df.style.height="100%",(n=this.Df).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Ym=document.createElement("table"),this.Ym.setAttribute("cellspacing","0"),this.Df.appendChild(this.Ym),this.Xm=this.Gm.bind(this),Ys(this.Ps)&&this.Km(!0),this.ss=new Ei(this.Qu.bind(this),this.Ps,s),this.ti().fc().i(this.Zm.bind(this),this),this.Jm=new Us(this,this.u_),this.Ym.appendChild(this.Jm.Zp());const e=i.autoSize&&this.Qm();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.tw(r,h),this.iw(),t.appendChild(this.Df),this.sw(),this.ss.At().Au().i(this.ss.Ah.bind(this.ss),this),this.ss.Vo().i(this.ss.Ah.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}qp(){return this.Om}nw(){return this.Jm}m(){this.Km(!1),0!==this.zm&&window.cancelAnimationFrame(this.zm),this.ss.fc().u(this),this.ss.At().Au().u(this),this.ss.Vo().u(this),this.ss.m();for(const t of this.Om)this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();this.Om=[];for(const t of this.Wm)this.ew(t);this.Wm=[],l(this.Jm).m(),null!==this.Df.parentElement&&this.Df.parentElement.removeChild(this.Df),this.Zu.m(),this.Cv.m(),this.Pv.m(),this.rw()}tw(t,i,s=!1){if(this.na===i&&this.yo===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.na=n.height,this.yo=n.width;const e=this.na+"px",r=this.yo+"px";l(this.Df).style.height=e,l(this.Df).style.width=r,this.Ym.style.height=e,this.Ym.style.width=r,s?this.hw(Y.bn(),performance.now()):this.ss.Ah()}_v(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Om.length;i++)this.Om[i]._v(t.rn(i).sn);this.Ps.timeScale.visible&&this.Jm._v(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Km(s),t.layout?.panes&&this.lw(),this.sw(),this.aw(t)}Zv(){return this.Cv}Jv(){return this.Pv}fc(){return this.Zu}ow(t=!1){null!==this.Nm&&(this.hw(this.Nm,performance.now()),this.Nm=null);const i=this._w(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this._w(n,t),s}uw(t){if("left"===t&&!this.cw())return 0;if("right"===t&&!this.dw())return 0;if(0===this.Om.length)return 0;return l("left"===t?this.Om[0].hm():this.Om[0].lm()).ov()}pw(){return this.Ps.autoSize&&null!==this.qm}sf(){return this.Df}fw(t){this.jm=t,this.jm?this.sf().style.setProperty("cursor",t):this.sf().style.removeProperty("cursor")}mw(){return this.jm}ww(t){return h(this.Om[t]).Jp()}lw(){this.Wm.forEach(t=>{t.Tt()})}aw(t){(void 0!==t.autoSize||!this.qm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.qm&&this.Qm(),!1===t.autoSize&&null!==this.qm&&this.rw(),t.autoSize||void 0===t.width&&void 0===t.height||this.tw(t.width||this.yo,t.height||this.na))}_w(t,i){let s=0,n=0;const e=this.Om[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Om.length;r++){const h=this.Om[r],a=l("left"===s?h.hm():h.lm()),o=a.Qp();if(null!==t&&a.tf(t,n,e,i),e+=o.height,r<this.Om.length-1){const i=this.Wm[r],s=i.Qp();null!==t&&i.tf(t,n,e),e+=s.height}}};if(this.cw()){r("left",0);s+=l(e.hm()).Qp().width}for(let e=0;e<this.Om.length;e++){const r=this.Om[e],h=r.Qp();if(null!==t&&r.tf(t,s,n,i),n+=h.height,e<this.Om.length-1){const i=this.Wm[e],r=i.Qp();null!==t&&i.tf(t,s,n),n+=r.height}}if(s+=e.Qp().width,this.dw()){r("right",s);s+=l(e.lm()).Qp().width}const h=(i,s,n)=>{l("left"===i?this.Jm.Pm():this.Jm.Tm()).tf(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Jm.Qp();if(null!==t){let r=0;this.cw()&&(h("left",r,n),r=l(e.hm()).Qp().width),this.Jm.tf(t,r,n,i),r+=s.width,this.dw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}gw(){let t=0,i=0,s=0;for(const n of this.Om)this.cw()&&(i=Math.max(i,l(n.hm()).rv(),this.Ps.leftPriceScale.minimumWidth)),this.dw()&&(s=Math.max(s,l(n.lm()).rv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Lo();i=ds(i),s=ds(s);const n=this.yo,e=this.na,r=Math.max(n-i-s,0),h=1*this.Wm.length,a=this.Ps.timeScale.visible;let o=a?Math.max(this.Jm.Rm(),this.Ps.timeScale.minimumHeight):0;var _;o=(_=o)+_%2;const u=h+o,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Om.length;++t){const n=this.Om[t];n.Wv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Om.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Lo()*d*f)/f,e=Math.max(h,2),p+=e,n.av(ns({width:r,height:e})),this.cw()&&n.tm(i,"left"),this.dw()&&n.tm(s,"right"),n.af()&&this.ss.vc(n.af(),e)}this.Jm.Dm(ns({width:a?r:0,height:o}),a?i:0,a?s:0),this.ss.Eo(r),this.$m!==i&&(this.$m=i),this.Hm!==s&&(this.Hm=s)}Km(t){t?this.Df.addEventListener("wheel",this.Xm,{passive:!1}):this.Df.removeEventListener("wheel",this.Xm)}bw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Gm(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.bw(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.Df.getBoundingClientRect().left;this.ti().Sc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().xc(-80*s)}hw(t,i){const s=t.en();3===s&&this.Mw(),3!==s&&2!==s||(this.yw(t),this.Sw(t,i),this.Jm.Tt(),this.Om.forEach(t=>{t.$v()}),3===this.Nm?.en()&&(this.Nm.mn(t),this.Mw(),this.yw(this.Nm),this.Sw(this.Nm,i),t=this.Nm,this.Nm=null)),this._v(t)}Sw(t,i){for(const s of t.vn())this.wn(s,i)}yw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qo()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Bu();break;case 1:s.Ou(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.xu();break;case 5:t.Ht.Fu(i)||s.fn(t.Ht.Iu(i))}}Qu(t){null!==this.Nm?this.Nm.mn(t):this.Nm=t,this.Um||(this.Um=!0,this.zm=window.requestAnimationFrame(t=>{if(this.Um=!1,this.zm=0,null!==this.Nm){const i=this.Nm;this.Nm=null,this.hw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Fu(t)){this.ti().un(s.Ht);break}}}))}Mw(){this.iw()}ew(t){this.Ym.removeChild(t.Zp()),t.m()}iw(){const t=this.ss.qs(),i=t.length,s=this.Om.length;for(let t=i;t<s;t++){const t=h(this.Om.pop());this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();const i=this.Wm.pop();void 0!==i&&this.ew(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Zv().i(this.xw.bind(this,i),this),i.Jv().i(this.Cw.bind(this,i),this),this.Om.push(i),n>0){const t=new Ms(this,n-1,n);this.Wm.push(t),this.Ym.insertBefore(t.Zp(),this.Jm.Zp())}this.Ym.insertBefore(i.Zp(),this.Jm.Zp())}for(let s=0;s<i;s++){const i=t[s],n=this.Om[s];n.af()!==i?n.Wv(i):n.Ov()}this.sw(),this.gw()}Pw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.At().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti().oc(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,a=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,o=this.Tw(n);return{kw:r,Re:t??void 0,Dw:i??void 0,Rw:-1!==o?o:void 0,Fw:l,Iw:e,Vw:a,Lw:s??void 0}}Tw(t){let i=-1;if(t)i=this.Om.indexOf(t);else{const t=this.ti().dc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}xw(t,i,s,n){this.Cv.p(()=>this.Pw(i,s,n,t))}Cw(t,i,s,n){this.Pv.p(()=>this.Pw(i,s,n,t))}Zm(t,i,s){this.fw(this.ti().oc()?.a_??null),this.Zu.p(()=>this.Pw(t,i,s))}sw(){const t=this.Ps.timeScale.visible?"":"none";this.Jm.Zp().style.display=t}cw(){return this.Om[0].af().No().W().visible}dw(){return this.Om[0].af().Uo().W().visible}Qm(){return"ResizeObserver"in window&&(this.qm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.tw(i.contentRect.width,i.contentRect.height)}),this.qm.observe(this.If,{box:"border-box"}),!0)}rw(){null!==this.qm&&this.qm.disconnect(),this.qm=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Xs(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 Ks(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw:n};return void 0!==s.color&&(r.R=s.color),r}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw: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={Re:i,gt:t,Ht:[e,e,e,e],kw: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={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),e}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function sn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),a=Math.min(...r),o=r[r.length-1],_=[o,l,a,o],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,kw:n,ne:d,R:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Aw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Xs(t)}(n,h)?en({gt:i,Re:s,kw: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(Ks),Line:rn(Ks),Custom:rn(sn)}[t]}function ln(t){return{Re:0,Ew:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Bw:i.key(t[0].gt),Ow:i.key(t[t.length-1].gt)}}function on(t){let i;return t.forEach(t=>{void 0===i&&(i=t.kw)}),h(i)}class _n{constructor(t){this.Ww=new Map,this.zw=new Map,this.$w=new Map,this.Hw=[],this.u_=t}m(){this.Ww.clear(),this.zw.clear(),this.$w.clear(),this.Hw=[]}Nw(t,i){let s=0!==this.Ww.size,n=!1;const e=this.zw.get(t);if(void 0!==e)if(1===this.zw.size)s=!1,n=!0,this.Ww.clear();else for(const i of this.Hw)i.pointData.Ew.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=hn(t.Rr()),l=t.pl(),a=t.vl();r=i.map((i,r)=>{const o=e(i.time),_=this.u_.key(o);let u=this.Ww.get(_);void 0===u&&(u=ln(o),this.Ww.set(_,u),n=!0);const c=h(o,u.Re,i,s[r],l,a);return u.Ew.set(t,c),c})}s&&this.Uw(),this.qw(t,r);let h=-1;if(n){const t=[];this.Ww.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:on(i.Ew)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.jw(t)}return this.Yw(t,h,function(t,i,s){const n=an(t,s),e=an(i,s);if(void 0!==n&&void 0!==e)return{Xw:!1,Oh:n.Ow>=e.Ow&&n.Bw>=e.Bw}}(this.zw.get(t),e,this.u_))}Bc(t){return this.Nw(t,[])}Gw(t,i,s){const n=i;!function(t){void 0===t.kw&&(t.kw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.$w.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ww.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=ln(e),this.Ww.set(this.u_.key(e),h));const a=hn(t.Rr()),o=t.pl(),_=t.vl(),u=a(e,h.Re,i,n.kw,o,_);h.Ew.set(t,u),s?this.Kw(t,u,h.Re):this.Zw(t,u);const c={Oh:nn(u),Xw:s};if(!l)return this.Yw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:on(h.Ew)},p=yt(this.Hw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Hw.splice(p,0,d);for(let t=p;t<this.Hw.length;++t)un(this.Hw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Hw,p),this.Yw(t,p,c)}Jw(t,i){const s=this.zw.get(t);if(void 0===s||i<=0)return[[],this.Qw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.$w.delete(t):this.$w.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ww.get(this.u_.key(i.gt));if(s&&(s.Ew.delete(t),0===s.Ew.size)){this.Ww.delete(this.u_.key(s.Uh)),this.Hw.splice(s.Re,1);for(let t=s.Re;t<this.Hw.length;++t)un(this.Hw[t].pointData,t)}}return[n,this.Yw(t,this.Hw.length-1,{Xw:!1,Oh:!1})]}Zw(t,i){let s=this.zw.get(t);void 0===s&&(s=[],this.zw.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.$w.set(t,i.gt)}Kw(t,i,s){const n=this.zw.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);nn(i)?n[e]=i:n.splice(e,1)}qw(t,i){0!==i.length?(this.zw.set(t,i.filter(nn)),this.$w.set(t,i[i.length-1].gt)):(this.zw.delete(t),this.$w.delete(t))}Uw(){for(const t of this.Hw)0===t.pointData.Ew.size&&this.Ww.delete(this.u_.key(t.time))}jw(t){let i=-1;for(let s=0;s<this.Hw.length&&s<t.length;++s){const n=this.Hw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.Hw.length!==t.length&&(i=Math.min(this.Hw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Hw=t,i}tg(){if(0===this.zw.size)return null;let t=0;return this.zw.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Yw(t,i,s){const n=this.Qw();if(-1!==i)this.zw.forEach((i,e)=>{n.zo.set(e,{ne:i,ig:e===t?s:void 0})}),this.zw.has(t)||n.zo.set(t,{ne:[],ig:s}),n.At.sg=this.Hw,n.At.ng=i;else{const i=this.zw.get(t);n.zo.set(t,{ne:i||[],ig:s})}return n}Qw(){return{zo:new Map,At:{cu:this.tg()}}}}function un(t,i){t.Re=i,t.Ew.forEach(t=>{t.Re=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.qh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);if(!s)return{from:r,to:h};let l=r,a=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(a=h+1),{from:l,to:a}}class fn{constructor(t,i,s){this.eg=!0,this.rg=!0,this.hg=!0,this.lg=[],this.ag=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.eg=!0,"data"===t&&(this.rg=!0),"options"===t&&(this.hg=!0)}Dt(){return this.Qn.It()?(this._g(),null===this.ag?null:this.ug):null}cg(){const t=this.Qn.Fh();this.lg=this.lg.map(i=>{const s=t.Ir(i.gt);return null===s?i:{...i,...s}})}dg(){this.ag=null}_g(){this.rg&&(this.pg(),this.rg=!1),this.hg&&(this.cg(),this.hg=!1),this.eg&&(this.fg(),this.eg=!1)}fg(){const t=this.Qn.$t(),i=this.te.At();if(this.dg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Or())return;const n=this.Qn.Bt();null!==n&&(this.ag=pn(this.lg,s,this.og),this.vg(t,i,n.Ht),this.mg())}}class vn{constructor(t,i){this.wg=t,this.Yi=i}et(t,i,s){this.wg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.ug=new vn(this.eh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),gg:i.ne}))}vg(t,i){i.du(this.lg,m(this.ag))}mg(){this.eh.update({bars:this.lg.map(wn),barSpacing:this.te.At().gu(),visibleRange:this.ag},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.gg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=a(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function yn(t){const i=Mn(t);return void 0!==t.R&&(i.color=t.R),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.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function Pn(t){const i=Cn(t);return void 0!==t.R&&(i.color=t.R),i}function Tn(t){const i=Cn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function kn(t){return{Area:Sn,Line:yn,Baseline:xn,Histogram:yn,Bar:Pn,Candlestick:Tn,Custom:Dn}[t]}function Dn(t){const i=t.kw;return{...t.ne,time:i}}const Rn={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},Fn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},In={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},Vn={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 An(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:In,crosshair:Rn,grid:Fn,overlayPriceScales:{...Vn},leftPriceScale:{...Vn,visible:!1},rightPriceScale:{...Vn,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 En{constructor(t,i,s){this.Np=t,this.bg=i,this.Mg=s??0}applyOptions(t){this.Np.ti().uc(this.bg,t,this.Mg)}options(){return this.Yi().W()}width(){return j(this.bg)?this.Np.uw(this.bg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Ha(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().ta()){const n=this.Yi().vo(),e=Bi(n);s=ai(s,this.Yi().sa()),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.Np.ti().cc(this.bg,this.Mg)).$t}}class Bn{constructor(t,i,s,n){this.Np=t,this.Pt=s,this.yg=i,this.Sg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Np.ti(),s=i.qc(this.Pt);i.wc(s,t)}getStretchFactor(){return this.Pt.Lo()}setStretchFactor(t){this.Pt.Ao(t),this.Np.ti().Ah()}paneIndex(){return this.Np.ti().qc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Np.qp().length,"Invalid pane index"),this.Np.ti().bc(i,t))}getSeries(){return this.Pt.zo().map(t=>this.yg(t))??[]}getHTMLElement(){const t=this.Np.qp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Zp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.Sg,requestUpdate:()=>this.Pt.ti().Ah()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Io(t))throw new Error(`Cannot find price scale with id: ${t}`);return new En(this.Np,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Oo(t)}preserveEmptyPane(){return this.Pt.Wo()}addCustomSeries(t,i={},s=0){return this.Sg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.Sg.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()}xg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.Cg=new o,this.Qn=t,this.Pg=i,this.Tg=s,this.u_=e,this.Sg=n,this.kg=r}m(){this.Cg.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 Ci(t.from,t.to)).k_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const a={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(a.from=n.kw,a.to=e.kw),a}setData(t){this.u_,this.Qn.Rr(),this.Pg.Dg(this.Qn,t),this.Rg("full")}update(t,i=!1){this.Qn.Rr(),this.Pg.Fg(this.Qn,t,i),this.Rg("update")}pop(t=1){const i=this.Pg.Ig(this.Qn,t);0!==i.length&&this.Rg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Cg.i(t)}unsubscribeDataChanged(t){this.Cg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Tg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.zh(i);return new Wn(s)}removePriceLine(t){this.Qn.$h(t.xg())}priceLines(){return this.Qn.Hh().map(t=>new Wn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.Sg,series:this,requestUpdate:()=>this.Qn.ti().Ah(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Ah()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.kg(i)}moveToPane(t){this.Qn.ti().$c(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.zo().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Rg(t){this.Cg.v()&&this.Cg.p(t)}}class $n{constructor(t,i,s){this.Vg=new o,this.O_=new o,this.Mm=new o,this.ss=t,this.ph=t.At(),this.Jm=i,this.ph.Vu().i(this.Lg.bind(this)),this.ph.Lu().i(this.Ag.bind(this)),this.Jm.km().i(this.Eg.bind(this)),this.u_=s}m(){this.ph.Vu().u(this),this.ph.Lu().u(this),this.Jm.km().u(this),this.Vg.m(),this.O_.m(),this.Mm.m()}scrollPosition(){return this.ph.Mu()}scrollToPosition(t,i){i?this.ph.Ru(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Du()}getVisibleRange(){const t=this.ph.ru();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph.ou(i);this.ss.Wc(s)}getVisibleLogicalRange(){const t=this.ph.eu();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Wc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Bu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.pu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.iu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.pu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Jm.Jp().width}height(){return this.Jm.Jp().height}subscribeVisibleTimeRangeChange(t){this.Vg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Vg._(t)}subscribeVisibleLogicalRangeChange(t){this.O_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.O_._(t)}subscribeSizeChange(t){this.Mm.i(t)}unsubscribeSizeChange(t){this.Mm._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.gu()}}Lg(){this.Vg.v()&&this.Vg.p(this.getVisibleRange())}Ag(){this.O_.v()&&this.O_.p(this.getVisibleLogicalRange())}Eg(t){this.Mm.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.Og=new Map,this.Wg=new o,this.zg=new o,this.$g=new o,this.Yu=new WeakMap,this.Hg=new _n(i);const n=void 0===s?f(An()):_(f(An()),Hn(s));this.Ng=i,this.Np=new js(t,n,i),this.Np.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ug(t()))},this),this.Np.Jv().i(t=>{this.zg.v()&&this.zg.p(this.Ug(t()))},this),this.Np.fc().i(t=>{this.$g.v()&&this.$g.p(this.Ug(t()))},this);const e=this.Np.ti();this.qg=new $n(e,this.Np.nw(),this.Ng)}remove(){this.Np.Zv().u(this),this.Np.Jv().u(this),this.Np.fc().u(this),this.qg.m(),this.Np.m(),this.Bg.clear(),this.Og.clear(),this.Wg.m(),this.zg.m(),this.$g.m(),this.Hg.m()}resize(t,i,s){this.autoSizeActive()||this.Np.tw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},jg:bn,Yg:t}))(a(t));return this.Xg(n,i,s)}addSeries(t,i={},s=0){return this.Xg(t,i,s)}removeSeries(t){const i=h(this.Bg.get(t)),s=this.Hg.Bc(i);this.Np.ti().Bc(i),this.Gg(s),this.Bg.delete(t),this.Og.delete(i)}Dg(t,i){this.Gg(this.Hg.Nw(t,i))}Fg(t,i,s){this.Gg(this.Hg.Gw(t,i,s))}Ig(t,i){const[s,n]=this.Hg.Jw(t,i);return 0!==s.length&&this.Gg(n),s}subscribeClick(t){this.Wg.i(t)}unsubscribeClick(t){this.Wg._(t)}subscribeCrosshairMove(t){this.$g.i(t)}unsubscribeCrosshairMove(t){this.$g._(t)}subscribeDblClick(t){this.zg.i(t)}unsubscribeDblClick(t){this.zg._(t)}priceScale(t,i=0){return new En(this.Np,t,i)}timeScale(){return this.qg}applyOptions(t){this.Np.lr(Hn(t))}options(){return this.Np.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Np.ti().W().crosshair.mode,this.Np.lr({crosshair:{mode:2}})),n=this.Np.ow(t)}finally{i||void 0===s||this.Np.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Np.ti().jc();return i.Oo(t),this.Kg(i)}removePane(t){this.Np.ti().mc(t)}swapPanes(t,i){this.Np.ti().gc(t,i)}autoSizeActive(){return this.Np.pw()}chartElement(){return this.Np.sf()}panes(){return this.Np.ti().qs().map(t=>this.Kg(t))}paneSize(t=0){const i=this.Np.ww(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.Np.ti().Nn(n);null!==e&&this.Np.ti().Fc(t,i,e)}clearCrosshairPosition(){this.Np.ti().Ic(!0)}horzBehaviour(){return this.Ng}Xg(i,s={},n=0){r(void 0!==i.jg),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),h=i.jg,l=new Ut(this.Np.ti(),i.type,e,h,i.Yg);this.Np.ti().Ac(l,n);const a=new zn(l,this,this,this,this.Ng,t=>this.Kg(t));return this.Bg.set(a,l),this.Og.set(l,a),a}Gg(t){const i=this.Np.ti();i.Vc(t.At.cu,t.At.sg,t.At.ng),t.zo.forEach((t,i)=>i.lt(t.ne,t.ig)),i.At().K_(),i.wu()}Zg(t){return h(this.Og.get(t))}Ug(t){const i=new Map;t.Iw.forEach((t,s)=>{const n=s.Rr(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Zg(s),e)});const s=void 0!==t.Fw&&this.Og.has(t.Fw)?this.Zg(t.Fw):void 0;return{time:t.kw,logical:t.Re,point:t.Dw,paneIndex:t.Rw,hoveredSeries:s,hoveredObjectId:t.Vw,seriesData:i,sourceEvent:t.Lw}}Kg(t){let i=this.Yu.get(t);return i||(i=new Bn(this.Np,t=>this.Zg(t),t,this),this.Yu.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._d(i))}function Yn(){return ss}function Xn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Jg: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=Xn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.Jg)}function Kn(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=Xn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.Jg,l=n.logicalToCoordinate(h);return null===l?null:l}class Zn extends fn{constructor(t,i){super(t,i,!0)}vg(t,i,s){i.du(this.lg,m(this.ag)),t.qa(this.lg,s,m(this.ag))}Qg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.tb(i.Re,s,t,i)})}}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:a,verticalPixelRatio:o}=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*a,s.ct*o),l.lineTo(n.ut*a,n.ct*o),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*a,_.ct*o);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*a,d.ct*o);break;case 1:l.lineTo(d.ut*a,i[h-1].ct*o),n!==u&&(e(n,d),l.lineTo(d.ut*a,i[h-1].ct*o)),l.lineTo(d.ut*a,d.ct*o);break;case 2:{const[t,s]=se(i,h-1,h);l.bezierCurveTo(t.ut*a,t.ct*o,s.ut*a,s.ct*o,d.ut*a,d.ct*o);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*a,d.ct*o))}(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,ib:e,sb:r,dt:h,Kt:l,nb:a}=this.ht;if(null===s)return;const o=t.context;o.lineCap="butt",o.lineWidth=h*t.verticalPixelRatio,n(o,l),o.lineJoin="round";const _=this.eb.bind(this);void 0!==r&&Jn(t,i,r,s,e,_,ne),a&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let a=null;const o=Math.max(1,Math.floor(r))%2/2,_=s*h+o;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==a&&(l.beginPath(),null!==a&&l.fill(),l.fillStyle=i,a=i);const s=Math.round(n.ut*r)+o,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,a,s,_)}}class re extends ee{eb(t,i){return i.wt}}class he extends Zn{constructor(){super(...arguments),this.ug=new re}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.W(),i={_t:this.lg,Kt:t.lineStyle,sb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,nb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.ag,ib:this.te.At().gu()};this.ug.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},jg:(t,i)=>new he(t,i)};function ae(t,i){return t.weight>i.weight?t:i}function oe(t){return t}class _e{constructor(){this.rb=new o,this.hb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.rb.p(this.lb)),this.lb=0}ab(){return this.rb}m(){this.rb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.hb(),t=>(t>this.lb&&(this.lb=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(ae,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t%120==0?10:t%60==0?9:t%36==0?8:t%12==0?7:t%6==0?6:t%3==0?5:t%1==0?4:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(oe(t[n].time));this.lb=t[t.length-1].time,this.hb()}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{oe:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),_b:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({oe:t,_e:i,_b:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({oe:t,_e:i,_b:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ab().i(n)}}function 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,ib:e,dt:r,Kt:h,sb:l}=this.ht,a=this.ht.ub??(this.ht.cb?0:t.mediaSize.height);if(null===s)return;const o=t.context;o.lineCap="butt",o.lineJoin="round",o.lineWidth=r,n(o,h),o.lineWidth=1,Jn(t,i,l,s,e,this.pb.bind(this),we.bind(null,a))}}class be{fb(t,i){const s=this.mb,{wb:n,gb:e,bb:r,Mb:h,ub:l,yb:a,Sb:o}=i;if(void 0===this.xb||void 0===s||s.wb!==n||s.gb!==e||s.bb!==r||s.Mb!==h||s.ub!==l||s.yb!==a||s.Sb!==o){const{verticalPixelRatio:s}=t,_=l||a>0?s:1,u=a*_,c=o===t.bitmapSize.height?o:o*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.xb=p,this.mb=i}return this.xb}}class Me extends ge{constructor(){super(...arguments),this.Cb=new be}pb(t,i){const s=this.ht;return this.Cb.fb(t,{wb:i.yr,gb:i.Sr,bb:i.Cr,Mb:i.Pr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class ye extends ee{constructor(){super(...arguments),this.Pb=new be}eb(t,i){const s=this.ht;return this.Pb.fb(t,{wb:i.br,gb:i.br,bb:i.Mr,Mb:i.Mr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class Se extends Zn{constructor(t,i){super(t,i),this.ug=new x,this.Tb=new Me,this.kb=new ye,this.ug.nt([this.Tb,this.kb])}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.Bt();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.At().gu();if(null===this.ag||0===this.lg.length)return;let e,r;if(i.relativeGradient){e=this.lg[this.ag.from].ct,r=this.lg[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const i=this.lg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Tb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineType,ub:s,yb:e,Sb:r,cb:!1,ot:this.ag,ib:n}),this.kb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineVisible?i.lineType:void 0,nb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,ub:s,yb:e,Sb:r,ot:this.ag,ib: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},jg:(t,i)=>new Se(t,i)};class Ce extends ge{constructor(){super(...arguments),this.Cb=new be}pb(t,i){return this.Cb.fb(t,{wb:i.wr,gb:"",bb:"",Mb:i.gr,yb:this.ht?.yb??0,Sb:t.bitmapSize.height})}}class Pe extends Zn{constructor(t,i){super(t,i),this.ug=new x,this.Db=new Ce,this.Rb=new re,this.ug.nt([this.Db,this.Rb])}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.W();if(null===this.ag||0===this.lg.length)return;let i;if(t.relativeGradient){i=this.lg[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const s=this.lg[t];s.ct<i&&(i=s.ct)}}this.Db.lt({sb:t.lineType,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ub:null,yb:i,cb:t.invertFilledArea,ot:this.ag,ib:this.te.At().gu()}),this.Rb.lt({sb:t.lineVisible?t.lineType:void 0,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.ag,ib:this.te.At().gu(),nb: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},jg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0,this.Ib=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Fb=this.Vb(i),this.Fb>=2){Math.max(1,Math.floor(i))%2!=this.Fb%2&&this.Fb--}this.Ib=this.Yt.Lb?Math.min(this.Fb,Math.floor(i)):this.Fb;let n=null;const e=this.Ib<=this.Fb&&this.Yt.gu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ib),a=Math.round(h.ut*i),o=a-l,_=this.Ib,u=o+_-1,c=Math.min(h.Ga,h.Ka),d=Math.max(h.Ga,h.Ka),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Ib);t.fillRect(o,p,_,v);const m=Math.ceil(1.5*this.Fb);if(e){if(this.Yt.Ab){const i=a-m;let n=Math.max(p,Math.round(h.Xa*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,o-i,e-n+1)}const i=a+m;let n=Math.max(p,Math.round(h.Za*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).gu,t)))}}class De extends fn{constructor(t,i){super(t,i,!1)}vg(t,i,s){i.du(this.lg,m(this.ag)),t.Ya(this.lg,s,m(this.ag))}Eb(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Xa:NaN,Ga:NaN,Ka:NaN,Za:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>this.tb(i.Re,i,t))}}class Re extends De{constructor(){super(...arguments),this.ug=new ke}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t,{Ht:i})}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Ab:t.openVisible,Lb:t.thinBars,ot:this.ag})}}const Fe={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},jg:(t,i)=>new Re(t,i)};class Ie extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Fb=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.gu,i),this.Fb>=2){Math.floor(i)%2!=this.Fb%2&&this.Fb--}const s=this.Yt.Ks;this.Yt.Bb&&this.Ob(t,s,this.Yt.ot),this.Yt.Mi&&this.dv(t,s,this.Yt.ot);const n=this.Wb(i);(!this.Yt.Mi||this.Fb>2*n)&&this.zb(t,s,this.Yt.ot)}Ob(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.gu*e));l=Math.max(Math.floor(e),Math.min(l,this.Fb));const a=Math.floor(.5*l);let o=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.Xa,s.Za)*r),u=Math.round(Math.max(s.Xa,s.Za)*r),c=Math.round(s.Ga*r),d=Math.round(s.Ka*r);let p=Math.round(e*s.ut)-a;const f=p+l-1;null!==o&&(p=Math.max(o+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),o=f}}Wb(t){let i=Math.floor(1*t);this.Fb<=2*i&&(i=Math.floor(.5*(this.Fb-1)));const s=Math.max(Math.floor(t),i);return this.Fb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}dv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);let a=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 o=Math.round(s.ut*e)-Math.floor(.5*this.Fb);const _=o+this.Fb-1,u=Math.round(Math.min(s.Xa,s.Za)*r),c=Math.round(Math.max(s.Xa,s.Za)*r);if(null!==a&&(o=Math.max(a+1,o),o=Math.min(o,_)),this.Yt.gu*e>2*l)I(n,o,u,_-o+1,c-u+1,l);else{const t=_-o+1;n.fillRect(o,u,t,c-u+1)}a=_}}zb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let a=Math.round(Math.min(s.Xa,s.Za)*r),o=Math.round(Math.max(s.Xa,s.Za)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Fb),u=_+this.Fb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,a+=l,u-=l,o-=l),a>o||n.fillRect(_,a,u-_+1,o-a+1)}}}class Ve extends De{constructor(){super(...arguments),this.ug=new Ie}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t,{Ht:i})}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Bb:t.wickVisible,Mi:t.borderVisible,ot:this.ag})}}const Le={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},jg:(t,i)=>new Ve(t,i)};class Ae extends C{constructor(){super(...arguments),this.Yt=null,this.$b=[]}lt(t){this.Yt=t,this.$b=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.$b.length||this.Hb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Nb*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.$b[i-this.Yt.ot.from],a=Math.round(h.ct*s);let o,_;t.fillStyle=h.dr,a<=e?(o=a,_=r):(o=e,_=a-Math.floor(n/2)+n),t.fillRect(l.qh,o,l.yi-l.qh+1,_-o)}}Hb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.$b=[]);const i=Math.ceil(this.Yt.gu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.gu*t)-i;this.$b=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.$b[i-this.Yt.ot.from]={qh:r,yi:h,Ub: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.$b[t-this.Yt.ot.from],n=this.$b[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.Ub>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.gu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.Ub>i.ee?i.yi-=1:i.qh+=1)}}}class Ee extends Zn{constructor(){super(...arguments),this.ug=new Ae}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t={_t:this.lg,gu:this.te.At().gu(),ot:this.ag,Nb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this.ug.lt(t)}}const Be={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},jg:(t,i)=>new Ee(t,i)};class Oe{constructor(t,i){this.Pt=t,this.qb=i,this.jb()}detach(){this.Pt.detachPrimitive(this.qb)}getPane(){return this.Pt}applyOptions(t){this.qb.lr?.(t)}jb(){this.Pt.attachPrimitive(this.qb)}}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.Yb=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.Xb(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.Gb),i.restore(),e+=t.lineHeight*t.Pu}})}Xb(t,i){const s=this.Kb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Kb(t){let i=this.Yb.get(t);return void 0===i&&(i=new Map,this.Yb.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,Gb:0,Pu: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.Zb=[new He(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Zb}attached({requestUpdate:t}){this.Jb=t}detached(){this.Jb=void 0}lr(t){this.Ps=je({...this.Ps,...t}),this.Jb&&this.Jb()}}function Xe(t,i){return new Oe(t,new Ye(i))}const Ge={alpha:1,padding:0};class Ke{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Qb(this.Yt,t.mediaSize);s&&this.Yt.tM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.tM,s.ut,s.ct,s.ts,s.qt))})}Qb(t,i){const{maxHeight:s,maxWidth:n,iM:e,sM:r,padding:h}=t,l=Math.round(i.width/2),a=Math.round(i.height/2),o=h??0;let _=i.width-2*o,u=i.height-2*o;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:a-.5*v,qt:v,ts:f}}}class Ze{constructor(t){this.nM=null,this.eM=0,this.rM=0,this.Ps=t,this.M=Je(this.Ps,this.nM,this.eM,this.rM)}hM(t){void 0!==t.lM&&(this.eM=t.lM),void 0!==t.aM&&(this.rM=t.aM),void 0!==t.oM&&(this.nM=t.oM),this.Tt()}_M(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Je(this.Ps,this.nM,this.eM,this.rM)}renderer(){return new Ke(this.M)}}function Je(t,i,s,n){return{...t,tM:i,sM:s,iM:n}}function Qe(t){return{...Ge,...t}}class tr{constructor(t,i){this.uM=null,this.cM=t,this.Ps=Qe(i),this.Zb=[new Ze(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt())}paneViews(){return this.Zb}attached(t){const{requestUpdate:i}=t;this.dM=i,this.uM=new Image,this.uM.onload=()=>{const t=this.uM?.naturalHeight??1,i=this.uM?.naturalWidth??1;this.Zb.forEach(s=>s.hM({aM:t,lM:i,oM:this.uM})),this.dM&&this.dM()},this.uM.src=this.cM}detached(){this.dM=void 0,this.uM=null}lr(t){this.Ps=Qe({...this.Ps,...t}),this.pM(),this.Jb&&this.Jb()}Jb(){this.dM&&this.dM()}pM(){this.Zb.forEach(t=>t._M(this.Ps))}}function ir(t,i,s){return new Oe(t,new tr(i,s))}class sr{constructor(t,i){this.Qn=t,this._h=i,this.jb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}jb(){this.Qn.attachPrimitive(this._h)}}const nr={autoScale:!0,zOrder:"normal"};function er(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function rr(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":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 ar(t,i,s){return i?t:s?Math.ceil(t/2):0}function or(t,i,s,n){const e=(rr("arrowUp",n)-1)/2*s.fM,r=(Kt(n/2)-1)/2*s.fM;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=(Kt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&r>=(t?s:s-h)-2&&r<=(t?s+h:s)+2)return!0;return(()=>{if(e<i-h-3||e>i+h+3||r<(t?s-h-3:s)||r>(t?s:s+h+3))return!1;const n=Math.abs(e-i);return Math.abs(r-s)+3>=n/2})()}function ur(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,a=s+l*n,o=a-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),o),t.quadraticCurveTo(i,a,i+(r?h:-h),o),t.lineTo(i-_,s)}function cr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class dr{constructor(){this.Yt=null,this.Wn=new it,this.vM=new it,this.$=-1,this.H="",this.Nf="",this.mM="",this.wM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Nf=g(t,i),this.mM=g(t,i,"600"),this.Wn.Vn(),this.vM.Vn()),this.wM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&fr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.gM;if(t.font=r?this.mM:this.Nf,void 0!==e.hi){const i=r?this.vM:this.Wn;e.hi.ts=i.Ii(t,e.hi.bM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.gM){const t=void 0!==e.hi?e.hi.ts:0;e.gM.ts=Math.max(t+2*e.gM.MM,e.gM.qt),e.gM.qh=e.ut-e.gM.ts/2}pr(e,t,i,s)}}}}function pr(t,i,s,n){void 0===t.gM?(i.fillStyle=t.R,void 0!==t.hi&&cr(i,t.hi.bM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Or)return;switch(t.yM){case"arrowDown":return void or(!1,i,s,t.Or);case"arrowUp":return void or(!0,i,s,t.Or);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.fM,0,2*Math.PI,!1),t.fill()}(i,s,t.Or);case"square":return void function(t,i,s){const n=rr("square",s),e=(n-1)*i.fM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.fM,n*i.fM)}(i,s,t.Or);case"tag":return}t.yM}(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,fM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Or)return;(function(t,i){const s=i.SM,n=i.xM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.CM-i.qt/2)*n),l=Math.round((i.CM+i.qt/2)*n),a=Math.round(i.ut*s),o=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.PM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-o)),c="none"!==i.TM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+o,h),"up"===i.TM&&ur(t,a,h,_,u,!0),t.lineTo(r-o,h),t.arcTo(r,h,r,h+o,o),t.lineTo(r,l-o),t.arcTo(r,l,r-o,l,o),"down"===i.TM&&ur(t,a,l,_,u,!1),t.lineTo(e+o,l),t.arcTo(e,l,e,l-o,o),t.lineTo(e,h+o),t.arcTo(e,h,e+o,h,o)):L(t,e,h,r-e,l-h,[o,o,o,o]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,CM:t.ct,ts:i.ts,qt:i.qt,PM:i.PM,TM:i.TM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,SM:n,xM:e}),void 0!==t.hi&&(s.fillStyle=t.kM??"#FFFFFF",cr(s,t.hi.bM,t.hi.ut,t.hi.ct,n,e))}(t,t.gM,i,s,n)}function fr(t,i,s){return void 0!==t.gM?0!==t.Or&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.TM?i-r-s.PM:i-r,l="down"===s.TM?i+r+s.PM:i+r,a=t-s.ts/2;return n>=a&&n<=a+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.gM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Or)return!1;switch(t.yM){case"arrowDown":return _r(!0,t.ut,t.ct,t.Or,i,s);case"arrowUp":return _r(!1,t.ut,t.ct,t.Or,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.Or,i,s);case"square":return function(t,i,s,n,e){const r=rr("square",s),h=(r-1)/2,l=t-h,a=i-h;return n>=l&&n<=l+r&&e>=a&&e<=a+r}(t.ut,t.ct,t.Or,i,s);case"tag":return!1}}(t,i,s)}function vr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function mr(t,i,s,n,e,r,h,a,o){const _=function(t,i,s){if(vr(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,o);if(void 0===_)return;const c=vr(i.position),d=a.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),a=Math.round(7*h),o=vr(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(o?0:n.DM)-a-_,o||(n.DM+=l+a+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(o?0:n.RM)+a+_,o||(n.RM+=l+a+r)}const d={qt:l,PM:a,TM:u,vt:i.borderRadius??6,MM:9*h,qh:0,ts:0};t.Or=l,t.ct=c,t.gM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=hr(d.options().barSpacing)*p,v=f/2;t.Or=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.DM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.DM+=1.2*e),void(c||(n.DM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}}}class wr{constructor(t,i,s){this.FM=[],this.xt=!0,this.IM=!0,this.Jt=new dr,this.be=t,this.Vf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.VM();const t=this.Vf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}LM(t){this.FM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.IM=!0)}AM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}VM(){const t=this.Vf.timeScale(),i=this.FM;this.IM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Or:0,yM:t.shape,R:t.color,Gn:t.id,EM:t.EM,hi:void 0,kM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,gM:void 0})),this.IM=!1);const s=this.Vf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const a=lr(t.options().barSpacing),o={DM:a,RM:a};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.DM=a,o.RM=a,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={bM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&mr(_,e,u,o,s.fontSize,a,this.be,this.Vf,r)}this.xt=!1}}function gr(t){return{...nr,...t}}class br{constructor(t){this.eh=null,this.FM=[],this.BM=[],this.OM=null,this.be=null,this.Vf=null,this.WM=!0,this.zM=null,this.$M=null,this.HM=null,this.NM=!0,this.Ps=gr(t)}attached(t){this.UM(),this.Vf=t.chart,this.be=t.series,this.eh=new wr(this.be,l(this.Vf),this.Ps),this.dM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Rg(t)),this.NM=!0,this.Jb()}Jb(){this.dM&&this.dM()}detached(){this.be&&this.OM&&this.be.unsubscribeDataChanged(this.OM),this.Vf=null,this.be=null,this.eh=null,this.OM=null}LM(t){this.NM=!0,this.FM=t,this.UM(),this.WM=!0,this.$M=null,this.Jb()}qM(){return this.FM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.jM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.YM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=gr({...this.Ps,...t}),this.Jb&&this.Jb()}YM(){const t=l(this.Vf).timeScale().options().barSpacing;if(this.WM||t!==this.HM){if(this.HM=t,this.FM.length>0){const i=lr(t),s=1.5*hr(t)+2*i,n=this.XM();this.zM={above:ar(s,n.aboveBar,n.inBar),below:ar(s,n.belowBar,n.inBar)}}else this.zM=null;this.WM=!1}return this.zM}XM(){return null===this.$M&&(this.$M=this.FM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.$M}UM(){if(!this.NM||!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.BM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.BM=this.FM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),a={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,EM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,kw: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{...a,position:i.position,price:i.price}}return{...a,position:i.position,price:i.price}}),this.NM=!1}jM(t){this.eh&&(this.UM(),this.eh.LM(this.BM),this.eh.AM(this.Ps),this.eh.Tt(t))}Rg(t){this.NM=!0,this.Jb()}}class Mr extends sr{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.LM(t)}markers(){return this._h.qM()}}function yr(t,i,s){const n=new Mr(t,new br(s??{}));return i&&n.setMarkers(i),n}class Sr{constructor(t){this.FM=new Map,this.GM=t}KM(t,i,s){if(this.ZM(i),void 0!==s){const n=window.setTimeout(()=>{this.FM.delete(i),this.JM()},s),e={...t,QM:n,ty:Date.now()+s};this.FM.set(i,e)}else this.FM.set(i,{...t,QM:void 0,ty:void 0});this.JM()}ZM(t){const i=this.FM.get(t);i&&void 0!==i.QM&&window.clearTimeout(i.QM),this.FM.delete(t),this.JM()}iy(){for(const[t]of this.FM)this.ZM(t)}sy(){const t=Date.now(),i=[];for(const[s,n]of this.FM)!n.ty||n.ty>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.ZM(s);return i}ny(t){this.GM=t}JM(){this.GM&&this.GM()}}const xr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Cr{constructor(t,i,s,n){this.Yt=t,this.ey=i,this.hy=s,this.ly=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.oy(e._y);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e._y&&(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._y)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e._y-7*e._y*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e._y)*t.verticalPixelRatio),i.stroke())})})}oy(t){return 0===t?this.ey:t>0?this.ly:this.hy}}class Pr{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,_y: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 Cr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Tr(t,i){return"Line"===i||"Area"===i}class kr{constructor(t){this.Vf=void 0,this.be=void 0,this.Zb=[],this.u_=null,this.uy=new Map,this.py=new Sr(()=>this.Jb()),this.Ps={...xr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Jb()}LM(t){this.py.iy();const i=this.u_;i&&t.forEach(t=>{this.py.KM(t,i.key(t.time))})}qM(){return this.py.sy()}Jb(){this.dM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Vf=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Zb=[new Pr(this.be,this.Vf.timeScale(),this.Ps)],this.dM=n,this.Jb()}detached(){this.Vf=void 0,this.be=void 0,this.dM=void 0}Yf(){return h(this.Vf)}zo(){return h(this.be)}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.qM()))}paneViews(){return this.Zb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.uy.clear();const s=this.u_;s&&t.forEach(t=>{Gs(t)&&Tr(0,i)&&this.uy.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Xs(t)&&this.uy.delete(n),Gs(t)&&Tr(0,s)){const i=this.uy.get(n);i&&this.py.KM({time:t.time,value:t.value,sign:Dr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}vy(){this.py.iy()}}function Dr(t,i){return t===i?0:t-i>0?1:-1}class Rr extends sr{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.qM()}setMarkers(t){return this._h.LM(t)}clearMarkers(){return this._h.vy()}}function Fr(t,i={}){return new Rr(t,new kr(i))}class Ir{constructor(t,i){this.my=null,this.wy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.my=yr(t)}addPosition(t){this.wy.push(t),this.gy()}addPositions(t){this.wy.push(...t),this.gy()}setPositions(t){this.wy=[...t],this.gy()}closePosition(t,i,s){const n=this.wy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.gy())}removePosition(t){this.wy=this.wy.filter(i=>i.id!==t),this.gy()}clearPositions(){this.wy=[],this.gy()}getPositions(){return this.wy}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.gy()}by(){const t=[];for(const i of this.wy){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}gy(){if(this.my){const t=this.by();this.my.setMarkers(t)}}detach(){this.my&&(this.my.detach(),this.my=null),this.wy=[]}}function Vr(t,i,s){const n=new Ir(t,s);return i&&i.length>0&&n.setPositions(i),n}const Lr=new WeakMap;function Ar(t){return"string"==typeof t?t:String(t)}function Er(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Ar(t.time),t.volume);Lr.set(t,s)}function Br(t,i){return Lr.get(t)?.get(Ar(i))}function Or(t){const i=Lr.get(t);return void 0!==i&&i.size>0}const Wr="rgba(0, 0, 0, 0)";function zr(t){switch(t.seriesType()){case"Candlestick":return $r(t,{upColor:Wr,downColor:Wr,borderVisible:!1,wickVisible:!1});case"Bar":return $r(t,{upColor:Wr,downColor:Wr});case"Line":return $r(t,{color:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return $r(t,{lineColor:Wr,topColor:Wr,bottomColor:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return $r(t,{topLineColor:Wr,topFillColor1:Wr,topFillColor2:Wr,bottomLineColor:Wr,bottomFillColor1:Wr,bottomFillColor2:Wr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return $r(t,{color:Wr});default:return $r(t,{visible:!1})}}function $r(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 Hr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Nr(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 Ur(t,i="close"){const s=[];for(const n of t)if(null!=n)if("close"in n)switch(i){case"open":s.push(n.open);break;case"high":s.push(n.high);break;case"low":s.push(n.low);break;case"hl2":s.push((n.high+n.low)/2);break;case"hlc3":s.push((n.high+n.low+n.close)/3);break;case"ohlc4":s.push((n.open+n.high+n.low+n.close)/4);break;default:s.push(n.close)}else s.push("value"in n?n.value:0);else s.push(0);return s}function qr(t,i){let s=[];return n=>{for(const i of s)try{t.removePriceLine(i)}catch(t){}s=n.filter(t=>null!=t).map(s=>{const n={price:s,color:i,lineWidth:1,lineStyle:2,axisLabelVisible:!1,title:""};return t.createPriceLine(n)})}}function jr(t){return null==t?void 0:t.time}function Yr(t){const{r_:i,Yf:s,My:n,yy:e,Sy:r,Jl:h}=t,l=t.xy??[];let a=t.W,o=[],_=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=jr(s[s.length-1])===jr(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===o.length)o=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;o.length>0&&jr(o[o.length-1])===jr(t)?o[o.length-1]=t:o.push(t)}if(0===o.length)return;const s=e(o,a);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&o.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(a),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=a;a={...a,...t},void 0!==r&&r(a),l.some(t=>i[t]!==a[t])&&(_=new Map,d("full"))},options:()=>({...a}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,o=[]}},recalculate:()=>d("full")};return f}function Xr(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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"SMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy: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??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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"EMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Sy: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=Ur(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=Yr({r_:t,Yf:i,My:[e],Jl:"WMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}}function Zr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Bollinger Bands",W:n,xy:["period","stdDev"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Cy:[],Py:[],Ty:[]};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 a=0;for(let t=0;t<i;t++)a+=n[l-t];const o=a/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-o,2);const u=Math.sqrt(_/i),c=o+u*s,d=o-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:o}),h.push({time:i,value:d})}}return{Cy:e,Py:r,Ty:h}})(t,i.period??20,i.stdDev??2);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function Jr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Keltner Channels",W:n,xy:["period","atrPeriod","multiplier","source"],yy:(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{Cy:[],Py:[],Ty:[]};const r=Ur(t,i.source??"close"),h=[],l=2/(s+1);let a=0;for(let t=0;t<s;t++)a+=r[t];h.push(a/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const o=[];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?o.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):o.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=o[t];_[n-1]=u/n;for(let t=n;t<o.length;t++)_[t]=(_[t-1]*(n-1)+o[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 a=h[i],o=l*e;d.push({time:r.time,value:a}),c.push({time:r.time,value:a+o}),p.push({time:r.time,value:a-o})}return{Cy:c,Py:d,Ty:p}})(t,i);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function Qr(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"Donchian Channels",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{Cy:[],Py:[],Ty:[]};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 a=t[r];void 0!==a.time&&h!==-1/0&&l!==1/0&&(s.push({time:a.time,value:h}),e.push({time:a.time,value:l}),n.push({time:a.time,value:(h+l)/2}))}return{Cy:s,Py:n,Ty:e}})(t,i.period??20);return[[r,s.Cy],[h,s.Py],[l,s.Ty]]},Sy: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,...a}}function th(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 a=h.close>=r.close,o=a?r.low:r.high,_=a?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&&(o+=u*(_-o),a?(o=Math.min(o,c.low,t[r-2]?t[r-2].low:c.low),h.low<o?(a=!1,o=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(o=Math.max(o,c.high,t[r-2]?t[r-2].high:c.high),h.high>o?(a=!0,o=_,_=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=o,t.color=a?n:e,l.push(t)}}return l},h=Yr({r_:t,Yf:i,My:[e],Jl:"Parabolic SAR",W:n,xy:["step","maxStep","colorUp","colorDown"],yy:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}}function ih(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.ky,i.Dy-1,i.Ry))}}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 sh(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),a=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"VWAP",W:n,xy:["anchorPeriod","bandMultiplier"],yy:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Or(t))return{Fy:e,Cy:r,Ty:h};let l=null,a=0,o=0,_=0;for(const u of i){const i=ih(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,a=0,o=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=Br(t,u.time)??0;if(a+=d,o+=c*d,_+=c*c*d,0===a)continue;const p=o/a;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/a-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{Fy:e,Cy:r,Ty:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.Fy],[h,n.Cy],[l,n.Ty]]},Sy: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,...a}}function nh(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 a=[];let o=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?(o=f<o||l.close>o?f:o,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>o&&(u=!0)):(o=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:o,m.color=u?n:e,a.push(m)}return a},h=Yr({r_:t,Yf:i,My:[e],Jl:"SuperTrend",xy:["period","multiplier","colorUp","colorDown"],W:n,yy:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}}class eh{constructor(t,i,s,n){this.Vf=t,this.be=i,this.I_=s,this.Iy=n}draw(t){const i=this.Iy();if(!i.It||i.Vy<=0)return;const s=this.I_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Vf.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],a=e.timeToCoordinate(h.gt),o=e.timeToCoordinate(l.gt);if(null===a||null===o)continue;const _=this.be.priceToCoordinate(h.Ly),u=this.be.priceToCoordinate(h.Ay),c=this.be.priceToCoordinate(l.Ly),d=this.be.priceToCoordinate(l.Ay);if(null===_||null===u||null===c||null===d)continue;const p=h.Ly>=h.Ay;n.fillStyle=this.Ey(p?i.By:i.Oy,i.Vy),n.beginPath(),n.moveTo(a*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class rh{constructor(t,i,s,n){this.Jt=new eh(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function hh(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 lh(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),a=r(n.colorSpanA),o=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new rh(i,t,()=>u,()=>({By:c.cloudBullishColor??"#089981",Oy:c.cloudBearishColor??"#F23645",Vy:c.cloudOpacity??.15,It: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=[],a=[],o=[],_=[],u=[];if(!t||t.length<e)return{Wy:h,rh:l,Ly:a,Ay:o,zy:_,$y: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 a=(i.get(l)??0)+1;i.set(l,a),a>n&&(n=a,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 a=t[i];if(void 0===a.time)continue;const o=hh(t,i,s),u=hh(t,i,n);null!==o&&h.push({time:a.time,value:o}),null!==u&&l.push({time:a.time,value:u}),null!==o&&null!==u&&p.set(i+r,(o+u)/2);const c=hh(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 a?a.close:a.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&&a.push({time:i,value:s}),void 0!==n&&o.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Ly:s,Ay:n};u.push(t)}}return{Wy:h,rh:l,Ly:a,Ay:o,zy:_,$y:u}},v=Yr({r_:t,Yf:i,My:[h,l,a,o,_],Jl:"Ichimoku",W:n,xy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],yy:(t,i)=>{c=i;const s=f(t,i);return u=s.$y,[[h,s.Wy],[l,s.rh],[a,s.Ly],[o,s.Ay],[_,i.showLagging??1?s.zy:[]]]},Sy:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),a.applyOptions({color:t.colorSpanA,lineWidth:s}),o.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:a,spanB:o,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}}function ah(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)],a=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],o=Yr({r_:t,Yf:i,My:[h,...l,...a],Jl:"Pivot Points",W:n,xy:["pivotPeriod"],yy:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{Hy:s,Ny:n,Uy:e};let r=null,h=-1/0,l=1/0,a=0,o=null;for(const _ of t){const t=ih(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+a)/3,s=h-l;o={qy:i,jy:[2*i-l,i+s,h+2*(i-l)],Yy:[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),a="close"in _?_.close:_.value,null!==o&&void 0!==_.time){s.push({time:_.time,value:o.qy});for(let t=0;t<3;t++)n[t].push({time:_.time,value:o.jy[t]}),e[t].push({time:_.time,value:o.Yy[t]})}}return{Hy:s,Ny:n,Uy:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.Hy]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Ny[t]:[]]),e.push([a[t],t<n?s.Uy[t]:[]]);return e},Sy: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}),a[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:a,...o}}function oh(t){return null!=t&&"number"==typeof t.close}function _h(t){const i=[];let s=null,n=null;for(const e of t){if(!oh(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 uh(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=zr(t):i||null===h||(h(),h=null)},a=Yr({r_:t,Yf:i,My:[r],Jl:"Heikin Ashi",W:n,xy:[],yy:t=>[[r,_h(t)]],Sy: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{zo:r,options:a.options,applyOptions:a.applyOptions,recalculate:a.recalculate,remove:()=>{a.remove();try{l(!1)}catch(t){}}}}function ch(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:Hr(0,100)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=qr(r,n.levelColor),a=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Ur(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 a=0===l?100:h/l,o=100-100/(1+a);t[i]&&t[i].time&&e.push({time:t[i].time,value:o});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,a=0===l?100:h/l,o=100-100/(1+a),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:o})}return e},o=Yr({r_:t,Yf:i,My:[r],Jl:"RSI",W:n,xy:["period","source"],yy:(t,i)=>[[r,a(t,i.period??14,i.source??"close")]],Sy: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,...o}}function dh(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(Be,{color:n.colorHistogramUp},e),a=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},o=Yr({r_:t,Yf:i,My:[r,h,l],Jl:"MACD",W:n,xy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],yy:(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{Xy:[],Gy:[],Ky:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=a(r,s),l=a(r,n),o=[],_=n-s;for(let t=0;t<l.length;t++)o.push(h[t+_]-l[t]);const u=a(o,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=o[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Xy:c,Gy:d,Ky:p}})(t,i);return[[r,s.Xy],[h,s.Gy],[l,s.Ky]]},Sy: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,...o}}function ph(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=Hr(0,100),h=i.addSeries(le,{color:n.colorK,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorD,autoscaleInfoProvider:r},e),a=Nr(i,h,e);i.priceScale(h.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const o=qr(h,n.levelColor),_=Yr({r_:t,Yf:i,My:[h,l],Jl:"Stochastic",W:n,xy:["kPeriod","dPeriod"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Zy:[],Jy:[]};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,a=i-1+e;t[a]&&t[a].time&&r.push({time:t[a].time,value:l})}return{Zy:e,Jy:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Zy],[l,s.Jy]]},Sy: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}),o([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:l,..._}}function fh(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=Yr({r_:t,Yf:i,My:[e],Jl:"ATR",W:n,xy:["period"],yy:(t,i)=>[[e,r(t,i.period??14)]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function vh(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Be,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Nr(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||!Or(t))return[];const e=[];for(const r of n){const n=Br(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},a=Yr({r_:t,Yf:i,My:[r],Jl:"Volume",W:n,xy:["colorUp","colorDown"],yy:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...a}}function mh(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||!Or(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=Br(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=Yr({r_:t,Yf:i,My:[e],Jl:"OBV",W:n,yy:()=>[[e,r()]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}}function wh(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=Hr(0,100),h=i.addSeries(le,{color:n.colorADX,autoscaleInfoProvider:r},e),l=i.addSeries(le,{color:n.colorPlusDI,autoscaleInfoProvider:r},e),a=i.addSeries(le,{color:n.colorMinusDI,autoscaleInfoProvider:r},e),o=Nr(i,h,e);i.priceScale(h.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=qr(h,n.levelColor),u=Yr({r_:t,Yf:i,My:[h,l,a],Jl:"ADX",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Qy:[],tS:[],iS:[]};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,a=h.low-r.low;n.push(l>a&&l>0?l:0),e.push(a>l&&a>0?a: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 a=[],o=[],_=[],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(o.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;a.push({time:m.time,value:t/i})}else if(u.length>i){const t=a[a.length-1].value;a.push({time:m.time,value:(t*(i-1)+v)/i})}}return{Qy:a,tS:o,iS:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Qy],[l,n?s.tS:[]],[a,n?s.iS:[]]]},Sy: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}),a.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:l,minusDI:a,...u}}function gh(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=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(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 a=l/i,o=0===a?0:(s[e]-h)/(.015*a);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:o})}return n},o=Yr({r_:t,Yf:i,My:[r],Jl:"CCI",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??20)]],Sy: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,...o}}function bh(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:Hr(-100,0)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(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,a=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:a})}return s},o=Yr({r_:t,Yf:i,My:[r],Jl:"Williams %R",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??14)]],Sy: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,...o}}function Mh(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:Hr(0,100)},e),h=Nr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=qr(r,n.levelColor),a=(i,s)=>{if(!i||i.length<s+1||!Or(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,a=(h.high+h.low+h.close)/3,o=l*(Br(t,r.time)??0);n.push(l>a?o:0),e.push(l<a?o: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 a=0===l?100:100-100/(1+h/l),o=i[t+1];o&&void 0!==o.time&&r.push({time:o.time,value:a})}return r},o=Yr({r_:t,Yf:i,My:[r],Jl:"MFI",W:n,xy:["period"],yy:(t,i)=>[[r,a(t,i.period??14)]],Sy: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,...o}}class yh{constructor(t){this.sS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.sS.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.nS(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}nS(t,i,s,n){const e=i.eS||i.startTime,r=i.rS||i.endTime,h=i.R||i.color,l=i.Vy||i.opacity;if(!i||!e||!r)return;const a=this.sS.getChart().timeScale(),o=a.timeToCoordinate(e),_=a.timeToCoordinate(r);if(null===o||null===_)return;const u=o*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this.hS(h,l),t.fillRect(u,d,c-u,p-d)}hS(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Sh{constructor(t){this.Jt=new yh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const xh=[{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 Ch{constructor(t,i,s={}){this.lS=[],this.qb=null,this.eh=null,this.Vf=t,this.be=i,this.Ps={sessions:s.sessions||xh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.aS(),this.Ps.enabled&&this.oS()}aS(){this.eh=new Sh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}oS(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this._S()}),this._S()}_S(){this.uS();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.cS(s),this.dM()}cS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.dS(i,t);this.Ps.showOverlaps&&this.pS(t)}}dS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.fS(i);this.vS(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.mS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.mS(s,n[n.length-1].time,t)}pS(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.wS(e,r);h&&this.gS(h,t)}}wS(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{oe:s,_e:n}:null}gS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.fS(i);r>=t.oe&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.bS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.bS(s,n[n.length-1].time)}mS(t,i,s){if(!t||!i)return void console.warn("Invalid session box times:",{startTime:t,endTime:i,session:s.name});const n={an:"session",eS:t,rS:i,R:s.color,Vy:s.opacity,MS:s.name};this.lS.push(n)}bS(t,i){const s={an:"overlap",eS:t,rS:i,R:this.Ps.overlapColor,Vy:this.Ps.overlapOpacity,MS:"Overlap"};this.lS.push(s)}vS(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}fS(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}uS(){this.lS=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this._S():this.uS(),this.dM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this._S(),this.dM()}disable(){this.Ps.enabled=!1,this.uS(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.uS(),this.dM()}getSessionBoxes(){return this.lS}getChart(){return this.Vf}getSeries(){return this.be}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Ph(t,i,s){return new Ch(t,i,s)}class Th{constructor(t){this.sS=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.sS.getProfileData();if(!s||0===s.bins.length)return;const n=this.sS.options(),e=this.sS.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let a=0;for(const t of s.bins)t.volume>a&&(a=t.volume);if(0!==a){for(const r of s.bins)this.yS(i,r,l,h,a,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.SS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.xS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}yS(t,i,s,n,e,r,h,l,a,o){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*a,v=Math.min(c,d)*o,m=_*a,w=p*o,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.hS(M,y),t.fillRect(f,v,m,w)}SS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const a=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,a),t.lineTo(e*r,a),t.stroke(),t.setLineDash([])}xS(t,i,s,n,e,r,h,l){const a=e.priceToCoordinate(i);if(null!==a){const i=a*l;t.strokeStyle=this.hS(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 o=e.priceToCoordinate(s);if(null!==o){const i=o*l;t.strokeStyle=this.hS(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([])}hS(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class kh{constructor(t){this.Jt=new Th(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Dh{constructor(t,i,s={}){this.CS=null,this.PS=new Map,this.qb=null,this.eh=null,this.Vf=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.aS(),this.oS()}aS(){this.eh=new kh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}oS(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.TS()}),this.TS()}setVolumeData(t){this.PS=t,this.TS()}addVolumeData(t,i){this.PS.set(t,i),this.TS()}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);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.PS.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 a=h[0];for(const t of h)t.volume>a.volume&&(a=t);const o=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<o))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.CS={bins:h,binSize:r,poc:a.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.dM()}getProfileData(){return this.CS}applyOptions(t){this.Ps={...this.Ps,...t},this.TS(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.CS=null,this.PS.clear(),this.dM()}getChart(){return this.Vf}getSeries(){return this.be}options(){return this.Ps}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}function Rh(t,i,s){return new Dh(t,i,s)}function Fh(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.kS=new Map,this.DS=null,this.RS=null,this.FS=null,this.IS=null,this.VS=null,this.LS=null,this.AS=0,this.ES=null,this.Mg=void 0,this.Vf=t,this.Df=i,this.BS=t=>this.OS(t),this.WS=t=>this.zS(t),this.$S=t=>this.HS(t),this.NS=t=>this.US(t),this.qS=()=>this.jS(),this.YS=t=>{"Escape"===t.key&&this.jS()},this.Vf.subscribeCrosshairMove(this.BS),this.Df.addEventListener("pointerdown",this.WS),this.Df.addEventListener("pointermove",this.$S),this.Df.addEventListener("pointerup",this.NS),this.Df.addEventListener("pointercancel",this.qS),document.addEventListener("keydown",this.YS)}XS(t){this.kS.set(t.id(),t)}GS(t){const i=t.id();this.DS===i&&this.KS(null),this.FS===t&&this.jS(),this.kS.delete(i)}Gi(){return 0===this.kS.size}m(){this.Vf.unsubscribeCrosshairMove(this.BS),this.Df.removeEventListener("pointerdown",this.WS),this.Df.removeEventListener("pointermove",this.$S),this.Df.removeEventListener("pointerup",this.NS),this.Df.removeEventListener("pointercancel",this.qS),document.removeEventListener("keydown",this.YS),this.kS.clear()}OS(t){if(this.ES=t.point?{ut:t.point.x,ct:t.point.y}:null,this.Mg=t.paneIndex,null!==this.FS)return;const i=this.ZS(t.hoveredObjectId),s=null===i?null:this.kS.get(i.gl)??null;this.KS(s?s.id():null),this.JS(s,null===s?null:i?.QS??null),this.tx()}zS(t){const i=null===this.DS?null:this.kS.get(this.DS)??null;i&&(this.VS={ut:t.clientX,ct:t.clientY},this.LS=i,i.isDraggable()&&(this.FS=i,this.IS=t.pointerId,this.Df.setPointerCapture(t.pointerId),i.beginDrag(),this.AS=this.ix(i,t),this.tx(),t.preventDefault(),t.stopPropagation()))}HS(t){if(null===this.FS)return;if(!this.sx(t))return void this.jS();const i=this.nx(t);null!==i&&this.FS.dragTo(i),t.preventDefault(),t.stopPropagation()}US(t){const i=this.FS,s=this.LS,n=this.VS;this.hx(),this.LS=null,this.VS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.FS=null,this.AS=0,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.tx();null!==s&&!e&&s.isClickable()&&s.click()}jS(){if(null===this.FS)return;const t=this.FS;this.FS=null,this.AS=0,this.hx(),t.cancelDrag(),this.tx()}sx(t){const i=this.Df.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}hx(){null!==this.IS&&(this.Df.hasPointerCapture(this.IS)&&this.Df.releasePointerCapture(this.IS),this.IS=null)}nx(t){const i=this.FS;if(null===i)return null;const s=this.lx(i,t);return null===s?null:i.priceAt(s-this.AS)}lx(t,i){const s=this.Vf.panes()[t.paneIndex()],n=s?s.getHTMLElement():null;return n?i.clientY-n.getBoundingClientRect().top:null!==this.ES&&this.Mg===t.paneIndex()?this.ES.ct:null}ix(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.lx(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}ZS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,QS:null}:{gl:t.slice(0,i),QS:t.slice(i+1)}}JS(t,i){this.RS!==i&&(this.RS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}KS(t){this.DS!==t&&(null!==this.DS&&this.kS.get(this.DS)?.setHovered(!1),this.DS=t,this.RS=null,null!==t&&this.kS.get(t)?.setHovered(!0))}tx(){if(null!==this.FS)return void this.Vf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.DS?null:this.kS.get(this.DS);t?this.Vf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Vf.chartElement().style.removeProperty("cursor")}}const Vh=new WeakMap;function Lh(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}function Ah(t,i){const s=Vh.get(t);s&&(s.GS(i),s.Gi()&&(s.m(),Vh.delete(t)))}let Eh=0;class Bh{constructor(t,i,s){this.sr=null,this.ox=!1,this._x="",this.ux=null,this.Vf=t,this.be=i,this.Ma="pipsend-trading-line-"+Eh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.vx(),(this.Ps.draggable||this.Ps.onClick)&&Lh(this.Vf)?.XS(this)}id(){return this.Ma}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.ox!==t&&this.sr&&(this.ox=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this._x}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.ux=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.mx(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.ux=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.ux;this.ux=null,null!==t&&t!==this.Ps.price&&(this.mx(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._x=t.color),!this.sr)return;const i={title:this.wx()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.ox||(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.mx(t)}remove(){Ah(this.Vf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}wx(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}vx(){this._x=this.Ps.color,this.sr=this.be.createPriceLine({id:this.Ma,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.wx()})}mx(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.wx()})}}function Oh(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 Bh(i,t,r)}class Wh{constructor(t,i){this.If=null,this.gx=null,this.bx=null,this.Mx={},this.Vf=t,this.be=i,this.yx()}yx(){this.If=this.Vf.chartElement()}Sx(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.If?(this.gx=t,this.Mx=i||{},new Promise(t=>{this.If.style.cursor="crosshair",this.bx=i=>{const s=this.Sx(i),n=this.xx(s);this.disableClickToCreate(),t(n)},this.If.addEventListener("click",this.bx)})):Promise.resolve(null)}disableClickToCreate(){this.If&&this.bx&&(this.If.removeEventListener("click",this.bx),this.If.style.cursor="default"),this.gx=null,this.bx=null,this.Mx={}}xx(t){if(!this.gx)return null;let i;switch(this.gx){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.Mx};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.Mx};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.Mx};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.Mx};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.Mx};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.Mx};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.Mx};break;default:return null}return new Bh(this.Vf,this.be,i)}getCreationMode(){return this.gx}isCreating(){return null!==this.gx}}function zh(t,i){return new Wh(t,i)}class $h{constructor(){this.Cx=[],this.Px=new Map,this.Tx=new Map,this.xt=!0}XS(t){this.Px.has(t)||(this.Cx.push(t),this.Px.set(t,[]),this.xt=!0)}GS(t){const i=this.Cx.indexOf(t);-1!==i&&this.Cx.splice(i,1),this.Px.delete(t),this.xt=!0}Gi(){return 0===this.Cx.length}kx(t,i){this.Px.set(t,i),this.xt=!0}Dx(t,i){return this.xt&&this.Rx(),this.Tx.get(Hh(t,i))??0}Rx(){const t=new Map,i=[];for(const s of this.Cx)for(const n of this.Px.get(s)??[]){const e=Nh(n.qt),r=n.qt;let h=n.ct;for(const t of[...i].sort(Uh))Math.abs(h-t.ct)<e&&(h=t.ct+e);let l=h-n.ct;l>r&&(l=0),i.push({ct:n.ct+l,qt:n.qt}),t.set(Hh(s,n.sn),l)}this.Tx=t,this.xt=!1}}function Hh(t,i){return`${t}:${i}`}function Nh(t){return Math.max(9,Math.round(.4*t))}function Uh(t,i){return t.ct-i.ct}const qh=new WeakMap;const jh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},Yh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},Xh=["takeProfit","entry","stopLoss"];class Gh{constructor(){this.Yt=null,this.Fx=[],this.Ix=0,this.Nf="",this.xa=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.Fx)if(s.Vx&&t>=s.Lx&&t<=s.Ax&&Math.abs(i-s.Ex)<=s.qt/2)return{sn:s.sn,QS:"close"};for(const s of this.Fx)if(t>=s.Bx&&t<=s.Ox&&Math.abs(i-s.Ex)<=s.qt/2)return{sn:s.sn,QS:"body"};for(const t of this.Fx)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,QS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.hw(t))}hw(t){const i=this.Yt;if(this.Fx=[],null===i||0===i.Wx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Nf!==i.T&&(this.Nf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.Ix=Math.max(0,n.width-i.Mu);const e=i.zx?this.Ix:n.width;for(const s of i.Wx)this.Fx.push(this.$x(t,i,s,e));i.zx&&i.Wx.length>1&&this.Hx(t,i),s.restore()}$x(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Nx,a=0===s.Ux.length?0:Math.max(this.Wn.Ii(e,s.Ux)+2*i.MM,.85*l),o=this.Wn.Ii(e,s.hi)+2*i.MM,_=s.Vx?l:0,u=a+o+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.qx,f=p-l/2;this.jx(t,s,d,c,n),this.Yx(t,i,s,{qh:d,Xx:f,ts:u,qt:l});let v=d;return a>0&&(this.Gx(t,i,s,{qh:v,Xx:f,ts:a,qt:l}),v+=a,this.Kx(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.kM??s.R,e.fillText(s.hi,v+o/2,p),e.restore(),v+=o,s.Vx&&(this.Kx(e,s.R,v,f,l,r,h),this.Zx(t,i,s,{qh:v,Xx:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Ex:p,qt:l,Bx:d,Ox:c,Lx:v,Ax:v+_,Vx:s.Vx}}jx(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,o=Math.max(1,Math.round(i.dt*a)),_=Math.round(i.ct*a)-Math.floor(o/2);h.save(),h.strokeStyle=i.R,h.lineWidth=o,n(h,i.Kt),h.beginPath(),0!==i.qx?(h.moveTo(0,_),h.lineTo(Math.round(r*l),_)):(h.moveTo(0,_),h.lineTo(Math.round(Math.max(0,s-8)*l),_),r>e+8&&(h.moveTo(Math.round((e+8)*l),_),h.lineTo(Math.round(r*l),_))),h.stroke(),h.restore()}Yx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Jx===s.sn,a=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),Kh(e,n,i.Qx,r,h),e.fillStyle=this.xa.X(i.Z,i.tC),e.fill(),e.lineWidth=a,e.strokeStyle=s.R,e.stroke(),e.restore()}Gx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.iC){const t=i.Wt;e.save(),Kh(e,{qh:n.qh+t,Xx:n.Xx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Qx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.iC?i.sC:s.R,e.fillText(s.Ux,n.qh+n.ts/2,n.Xx+n.qt/2),e.restore()}Kx(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.xa.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}Zx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Jx===s.sn&&"close"===i.nC){e.save();const t=i.Wt;Kh(e,{qh:n.qh,Xx:n.Xx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Qx-t),r,h,"right"),e.fillStyle=this.xa.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,a=(n.Xx+n.qt/2)*h,o=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-o,a-o),e.lineTo(l+o,a+o),e.moveTo(l+o,a-o),e.lineTo(l-o,a+o),e.stroke(),e.restore()}Hx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Wx.find(t=>"entry"===t.sn)??i.Wx[0],h=i.Wx.map(t=>t.ct),l=Math.round(this.Ix*n);s.save(),s.setLineDash([]),s.strokeStyle=r.R,s.lineWidth=Math.max(1,Math.floor(n)),s.beginPath(),s.moveTo(l,Math.round(Math.min(...h)*e)),s.lineTo(l,Math.round(Math.max(...h)*e)),s.stroke();for(const t of i.Wx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.xa.X(i.Z,i.tC),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function Kh(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.Xx*e),a=Math.round(i.ts*n),o=Math.round(i.qt*e),_=Math.min(s*n,a/2,o/2);L(t,h,l,a,o,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class Zh{constructor(){this.Jt=new Gh,this.Yt=null}Tt(t){this.Yt=t}renderer(){return null===this.Yt?null:(this.Jt.lt(this.Yt),this.Jt)}zOrder(){return"top"}Xn(t,i){return null===this.Yt?null:this.Jt.Xn(t,i)}}class Jh{constructor(t){this.Qt=t}coordinate(){return this.eC()?.Li??-1e3}text(){return this.eC()?.hi??""}textColor(){return this.eC()?.kM??"#FFFFFF"}backColor(){return this.eC()?.R??"#000000"}visible(){return null!==this.eC()}eC(){return this.Qt()}}let Qh=0;class tl{constructor(t,i,s){this.eh=new Zh,this.xa=new S([]),this.rC=!1,this.hC=null,this.RS=null,this.lC=null,this.ux=null,this.Vf=t,this.be=i,this.Ma="pipsend-position-line-"+Qh++,this.Ps=s,this.Ff={...Yh,...s.theme},this.Zb=[this.eh],this.aC=Xh.map(t=>new Jh(()=>this.oC(t))),this._C=function(t,i){let s=qh.get(t);return s||(s=new $h,qh.set(t,s)),s.XS(i),s}(this.Vf,this.Ma),this.be.attachPrimitive(this),Lh(this.Vf)?.XS(this)}attached(t){this.dM=t.requestUpdate,this.rC=!0,this.requestUpdate()}detached(){this.rC=!1,this.dM=void 0}paneViews(){return this.Zb}priceAxisViews(){return this.aC}updateAllViews(){this.eh.Tt(this.uC())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.cC(s.sn);return null===n?null:{externalId:`${this.Ma}#${s.sn}:${s.QS}`,zOrder:"top",cursorStyle:"close"===s.QS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.Ma}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.hC===n&&this.RS===e||(this.hC=n,this.RS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.hC&&"close"!==this.RS&&(this.cC(this.hC)?.draggable??!0)}isClickable(){return"close"===this.RS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}dragAnchorY(){if(null===this.lC)return null;const t=this.cC(this.lC)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.lC=this.hC,null===this.lC)return;const t=this.cC(this.lC)?.price??null;this.ux=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.lC,t)}dragTo(t){null!==this.lC&&(this.dC(this.lC,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.lC,t))}commitDrag(){const t=this.lC;if(this.lC=null,this.ux=null,null===t)return;const i=this.cC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.lC,i=this.ux;if(this.lC=null,this.ux=null,null===t)return;null!==i&&i!==this.cC(t)?.price&&(this.dC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.cC(t)?.price??0)}click(){const t=this.hC;if(null===t)return;if("close"===this.RS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.cC(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.lC,s=null===i?void 0:this.cC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=il(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=il(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.cC(i);null!==t&&(t.price=s)}t.theme&&(this.Ff={...this.Ff,...t.theme}),this.requestUpdate()}setPrice(t,i){this.lC!==t&&this.dC(t,i)}setText(t,i){const s=this.cC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of Xh){const s=this.cC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){Ah(this.Vf,this),function(t,i){const s=qh.get(t);s&&(s.GS(i),s.Gi()&&qh.delete(t))}(this.Vf,this.Ma),this.be.detachPrimitive(this)}requestUpdate(){this.dM&&this.dM()}oC(t){const i=this.cC(t);if(null===i||!isFinite(i.price)||!1===this.Ps.visible||!1===i.axisLabelVisible)return null;const s=this.be.priceToCoordinate(i.price);if(null===s)return null;const n=i.color??jh[t];return{Li:s,hi:this.be.priceFormatter().format(i.price),R:n,kM:this.xa.K(n).J}}cC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}dC(t,i){const s=this.cC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}uC(){if(!this.rC||!1===this.Ps.visible)return null;const t=this.Vf.options().layout,i=this.Ff.fontSize??t.fontSize,s=i+2*this.Ff.paddingY,n=[],e=[];for(const t of Xh){const i=this.cC(t);if(null===i||!isFinite(i.price))continue;const r=this.be.priceToCoordinate(i.price);if(null===r)continue;const h="entry"===t;e.push({sn:t,ct:r,qt:s}),n.push({sn:t,ct:r,qx:0,R:i.color??jh[t],hi:i.formatText?i.formatText(i.price):i.text??"",Ux:i.badge??"",iC:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),Vx:i.closable??!0,pC:i.draggable??!0})}if(0===n.length)return this._C.kx(this.Ma,[]),null;this._C.kx(this.Ma,e);for(const t of n)t.qx=this._C.Dx(this.Ma,t.sn);return{Wx:n,Z:this.Ff.background??(r=t.background,"solid"===r.type?r.color:r.topColor),kM:this.Ff.textColor,sC:this.Ff.badgeTextColor,Qx:this.Ff.borderRadius,Wt:this.Ff.borderWidth,MM:this.Ff.paddingX,Nx:this.Ff.paddingY,tC:this.Ff.backgroundOpacity,T:g(i,this.Ff.fontFamily??t.fontFamily),P:i,zx:!1!==this.Ps.connectorVisible&&n.length>1,Mu:this.Ps.rightOffset??56,Jx:this.hC,nC:this.RS};var r}}function il(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}function sl(t,i,s){return new tl(i,t,s)}const nl=new Set(["line","body","stroke","center","move"]);function el(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?nl.has(n)?"move":"grab":void 0}}function rl(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var hl;function ll(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.ky;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Dy,t.day=i.day??i.Ry,t}return t}function al(t,i){const s={};return s.price=t,s.time=i,s}function ol(t){if(!t)return al(0,null);return al(t.price??t.bt??0,ll(t.time??t.gt??null))}function _l(t,i="time"){return t?t[i]??null:null}function ul(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"}(hl||(hl={}));class cl{constructor(t,i,s={}){this._state=hl.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.fC(),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}fC(){return`${this._type}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}get id(){return this._id}get type(){return this._type}isComplete(){return!0}_registerOptions(t){this._ownOptions=t}options(){return{...this._ownOptions??this._options}}applyOptions(t){null!==this._ownOptions&&Object.assign(this._ownOptions,t),this._options={...this._options,...t},void 0!==t.visible&&(this._visible=t.visible),void 0!==t.locked&&(this._locked=t.locked),this._update()}show(){this._visible=!0,this._update()}hide(){this._visible=!1,this._update()}lock(){this._locked=!0}unlock(){this._locked=!1}isLocked(){return this._locked}isVisible(){return this._visible}series(){return this._series}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 dl=new WeakMap;function pl(t,i){dl.set(t,i)}function fl(t){const i=!0===dl.get(t);return i&&dl.set(t,!1),i}function vl(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 a=t.measureText(l).width/s+10,o=r-a,_=e.ct-8.5;t.fillStyle=e.Ot,t.beginPath(),t.rect(o*s,_*n,a*s,17*n),t.fill(),t.fillStyle=e.kM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(o+5)*s,e.ct*n),t.restore()}var ml;!function(t){t.vC="idle",t.mC="waiting_first_point",t.wC="waiting_second_point",t.gC="completed"}(ml||(ml={}));class wl{constructor(t,i,s={}){this.Vv=ml.vC,this.bC=null,this.bx=null,this.np=null,this.Vf=t,this.be=i,this.MC=s}yC(){this.Vv===ml.vC&&(this.Vv=ml.mC,this.bC=null,this.SC(),this.xC())}CC(){this.Vv=ml.vC,this.bC=null,this.PC(),this.TC(),this.MC.kC&&this.MC.kC()}DC(){return this.Vv}RC(){return this.Vv===ml.mC||this.Vv===ml.wC}SC(){this.bx=t=>{this.FC(t)},this.Vf.subscribeClick(this.bx)}xC(){this.np=t=>{this.IC(t)},this.Vf.subscribeCrosshairMove(this.np)}PC(){this.bx&&(this.Vf.unsubscribeClick(this.bx),this.bx=null)}TC(){this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null)}FC(t){if(!t.point)return;if(fl(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===ml.mC?(this.bC=n,this.Vv=ml.wC,this.MC.VC&&this.MC.VC(n)):this.Vv===ml.wC&&this.bC&&(this.Vv=ml.gC,this.MC.LC&&this.MC.LC(n),this.MC.AC&&this.MC.AC(this.bC,n),this.PC(),this.TC(),this.Vv=ml.vC,this.bC=null)}IC(t){if(!t.point)return;if(this.Vv!==ml.wC)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.MC.EC&&this.MC.EC(n)}m(){this.CC()}}class gl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class bl{constructor(t){this.BC=t,this.Jt=new gl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ml extends cl{constructor(t,i){super(t,"trend-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null,this.jC=!1,this.YC=null,this.XC=null,this.GC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.GC),this.aS(),this.GC.interactive?this.KC():this.jC=!0}KC(){const t=new wl(this._chart,this._series,{VC:t=>{this.GC.point1Time=t.gt,this.GC.point1Price=t.bt,this.dM()},LC:t=>{this.GC.point2Time=t.gt,this.GC.point2Price=t.bt,this.jC=!0,this.dM(),this.GC.onUpdate&&this.GC.onUpdate()},EC:t=>{this.GC.point1Time&&!this.jC&&(this.XC=t,this.dM())},AC:()=>{this.jC=!0}});this.YC=t,t.yC()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new bl(this)}QC(){if(!this.GC.point1Time||!this.GC.point2Time)return null;const t=Kn(this._chart,this._series,this.GC.point1Time)??0,i=this._series.priceToCoordinate(this.GC.point1Price)??0,s=Kn(this._chart,this._series,this.GC.point2Time)??0,n=this._series.priceToCoordinate(this.GC.point2Price)??0;if(!this.GC.extendLeft&&!this.GC.extendRight)return{tP:t,iP:i,sP:s,nP:n};if(s===t)return{tP:t,iP:i,sP:s,nP:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{tP:this.GC.extendLeft?0:t,iP:this.GC.extendLeft?i-r*t:i,sP:this.GC.extendRight?e:s,nP:this.GC.extendRight?i+r*(e-t):n}}eP(){const t=this.QC();if(null===t)return null;const i=t.sP>=t.tP?t.nP:t.iP,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.GC.point2Price??this.GC.point1Price??null}drawToCanvas(t,i,s){if(!this.jC&&this.GC.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.GC.point1Time||!this.GC.point2Time)return;const n=(Kn(this._chart,this._series,this.GC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.GC.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.GC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.GC.point2Price)??0)*s,l=this.GC.lineColor,a=this.WC?this.GC.lineWidth+1:this.GC.lineWidth;t.strokeStyle=l,t.lineWidth=a*i,"dashed"===this.GC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.GC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const o=this.QC();if(null===o)return;t.moveTo(o.tP*i,o.iP*s),t.lineTo(o.sP*i,o.nP*s),t.stroke(),t.setLineDash([]),!this.WC&&!this.zC||this.isLocked()||(this.hP(t,n,e,i,l),this.hP(t,r,h,i,l));const _=this.eP();if(!1!==this.GC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&vl(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}rP(t,i,s){if(!this.GC.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.GC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.GC.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s;t.strokeStyle=this.GC.lineColor,t.lineWidth=this.GC.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.hP(t,n,e,i,this.GC.lineColor),t.globalAlpha=.5,this.hP(t,r,h,i,this.GC.lineColor),t.globalAlpha=1}hP(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.GC.lineColor=t,this.dM()}color(){return this.GC.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}isHovered(){return this.zC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.QC();if(null===s)return!1;return this.lP(t,i,s.tP,s.iP,s.sP,s.nP)<=8}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.GC.point1Time||!this.GC.point2Time)return null;const s=Kn(this._chart,this._series,this.GC.point1Time)??0,n=this._series.priceToCoordinate(this.GC.point1Price)??0,e=Kn(this._chart,this._series,this.GC.point2Time)??0,r=this._series.priceToCoordinate(this.GC.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.lP(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,"line"===t&&(this.UC={gt:this.GC.point1Time,bt:this.GC.point1Price},this.qC={gt:this.GC.point2Time,bt:this.GC.point2Price})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null}updateDrag(t,i){if(this.$C&&this.HC){if("point1"===this.HC)this.GC.point1Time=t,this.GC.point1Price=i;else if("point2"===this.HC)this.GC.point2Time=t,this.GC.point2Price=i;else if("line"===this.HC&&this.UC&&this.qC){const s=rl(this.NC,t,i);this.GC.point1Time=this.UC.gt+s.gt,this.GC.point1Price=this.UC.bt+s.bt,this.GC.point2Time=this.qC.gt+s.gt,this.GC.point2Price=this.qC.bt+s.bt}this.dM(),this.GC.onUpdate&&this.GC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[al(this.GC.point1Price??0,ll(this.GC.point1Time)),al(this.GC.point2Price??0,ll(this.GC.point2Time))],style:{lineColor:this.GC.lineColor,lineWidth:this.GC.lineWidth,lineStyle:this.GC.lineStyle,extendLeft:this.GC.extendLeft,extendRight:this.GC.extendRight}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return this.jC}remove(){this.YC&&(this.YC.m(),this.YC=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GC.onRemove&&this.GC.onRemove()}}function yl(t,i){return new Ml(t,i)}class Sl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class xl{constructor(t){this.BC=t,this.Jt=new Sl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Cl extends cl{constructor(t,i){super(t,"horizontal-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.aP=0,this.oP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.oP),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new xl(this)}_P(){return void 0===this.oP.startTime?0:Kn(this._chart,this._series,this.oP.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.oP.price)return;const n=(this._series.priceToCoordinate(this.oP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this._P()*i,h=this.oP.lineColor,l=this.WC?this.oP.lineWidth+1:this.oP.lineWidth;t.strokeStyle=h,t.lineWidth=l*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(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.oP.showPriceLabel&&vl(t,this._series,i,s,{bt:this.oP.price,ct:n/s,Ot:h}),this.oP.showLabel&&(this.WC||this.zC)&&this.uP(t,n,i,s,h)}uP(t,i,s,n,e){const r=this.oP.labelText||this.oP.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const a=t.measureText(r).width,o=l,_=10*s,u=i-o/2-h;t.fillStyle=e,t.fillRect(_,u,a+2*h,o+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.oP.lineColor=t,this.dM()}color(){return this.oP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.oP.price)return!1;const s=this._series.priceToCoordinate(this.oP.price)??0;return!(t<this._P()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.$C=!0,this.NC=i,this.aP=this.oP.price??0}stopDrag(){this.$C=!1,this.NC=null}updateDrag(t,i){this.$C&&(this.oP.price=this.aP+rl(this.NC,t,i).bt,this.dM(),this.oP.onUpdate&&this.oP.onUpdate())}getPrice(){return this.oP.price}setPrice(t){this.oP.price=t,this.dM()}setLabel(t){this.oP.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[al(this.oP.price??0,ll(this.oP.startTime))],style:{lineColor:this.oP.lineColor,lineWidth:this.oP.lineWidth,lineStyle:this.oP.lineStyle,showLabel:this.oP.showLabel,labelText:this.oP.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.oP.onRemove&&this.oP.onRemove()}}function Pl(t,i){return new Cl(t,i)}class Tl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.BC=t,this.Jt=new Tl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends cl{constructor(t,i){super(t,"cross-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.cP=0,this.aP=0,this.dP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.dP),this.aS()}aS(){this.eh=new kl(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}pP(){if(void 0===this.dP.time||void 0===this.dP.price)return null;const t=Kn(this._chart,this._series,this.dP.time),i=this._series.priceToCoordinate(this.dP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.pP();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,a=n.ct*s,o=this.dP.lineColor,_=this.WC||this.zC&&!this.isLocked(),u=_?this.dP.lineWidth+1:this.dP.lineWidth;t.strokeStyle=o,t.lineWidth=u*i,"dashed"===this.dP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.dP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,a),t.lineTo(r,a),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.dP.showPriceLabel&&void 0!==this.dP.price&&vl(t,this._series,i,s,{bt:this.dP.price,ct:n.ct,Ot:o}),_&&!this.isLocked()&&(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,a,5*i,0,2*Math.PI),t.fill(),t.stroke())}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.pP();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.$C=!0,this.NC=i,this.cP=this.dP.time,this.aP=this.dP.price??0}updateDrag(t,i){if(!this.$C)return;const s=rl(this.NC,t,i);this.dP.time=this.cP+s.gt,this.dP.price=this.aP+s.bt,this.dM(),this.dP.onUpdate&&this.dP.onUpdate()}stopDrag(){this.$C=!1,this.NC=null}setColor(t){this.dP.lineColor=t,this.dM()}color(){return this.dP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}remove(){if(this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.dP.onRemove&&this.dP.onRemove()}_serializeShape(){return{type:"crossLine",points:[al(this.dP.price??0,ll(this.dP.time))],style:{lineColor:this.dP.lineColor,lineWidth:this.dP.lineWidth,lineStyle:this.dP.lineStyle}}}}function Rl(t,i){return new Dl(t,i)}class Fl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Il{constructor(t){this.BC=t,this.Jt=new Fl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vl extends cl{constructor(t,i){super(t,"polygon",i),this.I_=[],this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.fP=null,this.jC=!1,this.XC=null,this.bx=null,this.vP=null,this.mP=null,this.wP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.wP),this.I_=[...i.points??[]],this.aS(),this.wP.interactive?this.gP():this.jC=this.I_.length>=3}aS(){this.eh=new Il(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.I_.length>=3&&this.bP(t.point.x,t.point.y)?this.MP():(this.I_.push({time:s,price:i}),this.dM()))},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={time:s,price:i},this.dM())},this.mP=t=>{"Enter"===t.key&&this.I_.length>=3?this.MP():"Escape"===t.key&&(this.I_=[],this.MP())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP),document.addEventListener("keydown",this.mP)}bP(t,i){const s=this.I_[0],n=Kn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Vl.yP&&Math.abs(i-e)<=Vl.yP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.wP.onComplete&&this.wP.onComplete(),this.wP.onUpdate&&this.wP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null),this.mP&&(document.removeEventListener("keydown",this.mP),this.mP=null)}xP(){const t=[...this.I_];return this.jC||null===this.XC||t.push(this.XC),this.CP(t)}CP(t){const i=[];for(const s of t){const t=Kn(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.xP();if(n.length<2)return;const e=this.wP.borderColor,r=this.WC?this.wP.borderWidth+1:this.wP.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.jC&&(t.closePath(),this.wP.fillOpacity>0&&(t.fillStyle=this.Ey(this.wP.fillColor,this.wP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.jC?"dashed"===this.wP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.wP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked())for(const n of this.PP())this.TP(t,n.ut*i,n.ct*s,i,e)}PP(){return this.CP(this.I_)}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){const s=this.PP();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.PP();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.$C=!0,this.HC=t,this.NC=i,this.fP=this.I_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.$C&&null!==this.HC&&null!==this.fP){if("shape"===this.HC){const s=rl(this.NC,t,i);this.I_=this.fP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.HC;this.I_[s]&&(this.I_[s]={time:t,price:i})}this.dM(),this.wP.onUpdate&&this.wP.onUpdate()}}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.fP=null}setColor(t){this.wP.borderColor=t,this.wP.fillColor=t,this.dM()}color(){return this.wP.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}points(){return this.I_}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.wP.onRemove&&this.wP.onRemove()}_serializeShape(){return{type:"polygon",points:this.I_.map(t=>al(t.price,ll(t.time))),style:{fillColor:this.wP.fillColor,fillOpacity:this.wP.fillOpacity,borderColor:this.wP.borderColor,borderWidth:this.wP.borderWidth,borderStyle:this.wP.borderStyle}}}}function Ll(t,i){return new Vl(t,i)}Vl.yP=12;class Al{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.BC=t,this.Jt=new Al(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends cl{constructor(t,i){super(t,"parallel-channel",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.jC=!1,this.ud=0,this.XC=null,this.bx=null,this.vP=null,this.DP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.DP),this.aS(),this.DP.interactive?this.gP():this.jC=!0}aS(){this.eh=new El(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.ud)this.DP.point1Time=s,this.DP.point1Price=i;else{if(1!==this.ud)return this.DP.channelWidth=i-this.RP(s),void this.MP();this.DP.point2Time=s,this.DP.point2Price=i}this.ud++,this.dM()}},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={gt:s,bt:i},2===this.ud&&(this.DP.channelWidth=i-this.RP(s)),this.dM())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.DP.onComplete&&this.DP.onComplete(),this.DP.onUpdate&&this.DP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null)}RP(t){const i=this.DP.point1Time,s=this.DP.point2Time,n=this.DP.point1Price,e=this.DP.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)}kS(){const t=this.DP,i=this.jC?t.point2Time:t.point2Time??this.XC?.gt,s=this.jC?t.point2Price:t.point2Price??this.XC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Kn(this._chart,this._series,t.point1Time),e=Kn(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,a=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,a=r+(h-r)/(e-n)*(t-n)}const o=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+o),u=this._series.priceToCoordinate(this._series.coordinateToPrice(a)+o);return null===_||null===u?null:{tP:n,sP:l,FP:r,IP:a,VP:_,LP:u}}drawToCanvas(t,i,s){const n=this.kS();if(null===n)return;const e=this.DP,r=e.lineColor,h=this.WC?e.lineWidth+1:e.lineWidth,l=i,a=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Ey(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.tP*l,n.FP*a),t.lineTo(n.sP*l,n.IP*a),t.lineTo(n.sP*l,n.LP*a),t.lineTo(n.tP*l,n.VP*a),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.jC?"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.tP*l,n.FP*a),t.lineTo(n.sP*l,n.IP*a),0!==(e.channelWidth??0)&&(t.moveTo(n.tP*l,n.VP*a),t.lineTo(n.sP*l,n.LP*a)),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked()&&(this.TP(t,n.tP*l,n.FP*a,l,r),this.TP(t,n.sP*l,n.IP*a,l,r),0!==(e.channelWidth??0))){const i=(n.tP+n.sP)/2,s=(n.VP+n.LP)/2;this.TP(t,i*l,s*a,l,r)}if(!1!==e.showPriceLabel&&this.jC){const i=this._series.coordinateToPrice(n.IP);null!==i&&vl(t,this._series,l,a,{bt:i,ct:n.IP,Ot:r})}}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}AP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.hypot(t-s,i-n);let o=((t-s)*h+(i-n)*l)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(t-(s+o*h),i-(n+o*l))}hitTest(t,i){const s=this.kS();if(null===s)return!1;return this.AP(t,i,s.tP,s.FP,s.sP,s.IP)<=8||this.AP(t,i,s.tP,s.VP,s.sP,s.LP)<=8}hitTestEndpoint(t,i){const s=this.kS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.tP,s.FP))return"point1";if(n(s.sP,s.IP))return"point2";if(0!==(this.DP.channelWidth??0)){if(n((s.tP+s.sP)/2,(s.VP+s.LP)/2))return"width"}return null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,this.kP={EP:{gt:this.DP.point1Time,bt:this.DP.point1Price},BP:{gt:this.DP.point2Time,bt:this.DP.point2Price},ts:this.DP.channelWidth??0}}updateDrag(t,i){if(!this.$C||null===this.HC||null===this.kP)return;const s=this.DP;if("point1"===this.HC)s.point1Time=t,s.point1Price=i;else if("point2"===this.HC)s.point2Time=t,s.point2Price=i;else if("width"===this.HC)s.channelWidth=i-this.RP(t);else{const n=rl(this.NC,t,i);s.point1Time=this.kP.EP.gt+n.gt,s.point1Price=this.kP.EP.bt+n.bt,s.point2Time=this.kP.BP.gt+n.gt,s.point2Price=this.kP.BP.bt+n.bt,s.channelWidth=this.kP.ts}this.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}setColor(t){this.DP.lineColor=t,this.DP.fillColor=t,this.dM()}color(){return this.DP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.DP.onRemove&&this.DP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[al(this.DP.point1Price??0,ll(this.DP.point1Time)),al(this.DP.point2Price??0,ll(this.DP.point2Time))],style:{lineColor:this.DP.lineColor,lineWidth:this.DP.lineWidth,lineStyle:this.DP.lineStyle,fillColor:this.DP.fillColor,fillOpacity:this.DP.fillOpacity,extendRight:this.DP.extendRight},extra:{channelWidth:this.DP.channelWidth}}}}function Ol(t,i){return new Bl(t,i)}class Wl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.BC=t,this.Jt=new Wl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class $l extends cl{constructor(t,i){super(t,"pitchfork",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.jC=!1,this.ud=0,this.XC=null,this.bx=null,this.vP=null,this.OP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.OP),this.aS(),this.OP.interactive?this.gP():this.jC=!0}aS(){this.eh=new zl(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.OC&&this.OC()}_update(){this.dM()}gP(){this.bx=t=>{if(!t.point||fl(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.ud)this.OP.pivotTime=s,this.OP.pivotPrice=i;else{if(1!==this.ud)return this.OP.lowerTime=s,this.OP.lowerPrice=i,this.ud++,void this.MP();this.OP.upperTime=s,this.OP.upperPrice=i}this.ud++,this.dM()}},this.vP=t=>{if(!t.point||this.jC)return;const i=this._series.coordinateToPrice(t.point.y),s=Gn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.XC={gt:s,bt:i},this.dM())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.vP)}MP(){this.jC=!0,this.XC=null,this.SP(),this.dM(),this.OP.onComplete&&this.OP.onComplete(),this.OP.onUpdate&&this.OP.onUpdate()}SP(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.vP&&(this._chart.unsubscribeCrosshairMove(this.vP),this.vP=null)}WP(t,i){if(void 0===t||void 0===i)return null;const s=Kn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}zP(){const t=this.OP,i=this.WP(t.pivotTime,t.pivotPrice),s=this.WP(t.upperTime,t.upperPrice),n=this.jC?this.WP(t.lowerTime,t.lowerPrice):this.WP(t.lowerTime,t.lowerPrice)??(null!==this.XC&&this.ud>=2?this.WP(this.XC.gt,this.XC.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{Hy:i,$P:e,Cy:s,Ty:n,HP:l(i),NP:l(s),UP:l(n)}}drawToCanvas(t,i,s){const n=this.zP();if(null===n)return void this.qP(t,i,s);const e=this.OP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Ey(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.lineTo(n.UP.ut*h,n.UP.ct*l),t.lineTo(n.Ty.ut*h,n.Ty.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.WC?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.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.Ty.ut*h,n.Ty.ct*l),t.moveTo(n.Hy.ut*h,n.Hy.ct*l),t.lineTo(n.HP.ut*h,n.HP.ct*l),t.moveTo(n.Cy.ut*h,n.Cy.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.moveTo(n.Ty.ut*h,n.Ty.ct*l),t.lineTo(n.UP.ut*h,n.UP.ct*l),t.stroke(),t.setLineDash([]);if((this.WC||this.zC||!this.jC)&&!this.isLocked())for(const i of[n.Hy,n.Cy,n.Ty])this.TP(t,i.ut*h,i.ct*l,h,r)}qP(t,i,s){const n=this.OP,e=this.WP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.WP(n.upperTime,n.upperPrice)??(null!==this.XC?this.WP(this.XC.gt,this.XC.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.TP(t,e.ut*i,e.ct*s,i,h)}TP(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()}Ey(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}JC(t,i){if(!this.isVisible()||!this.jC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}AP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.hypot(t-s,i-n);let o=((t-s)*h+(i-n)*l)/a;return o=Math.max(0,Math.min(1,o)),Math.hypot(t-(s+o*h),i-(n+o*l))}hitTest(t,i){const s=this.zP();if(null===s)return!1;return[[s.Hy,s.HP],[s.Cy,s.NP],[s.Ty,s.UP],[s.Cy,s.Ty]].some(([s,n])=>this.AP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.zP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.Hy)?"pivot":n(s.Cy)?"upper":n(s.Ty)?"lower":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,this.kP=[{gt:this.OP.pivotTime,bt:this.OP.pivotPrice},{gt:this.OP.upperTime,bt:this.OP.upperPrice},{gt:this.OP.lowerTime,bt:this.OP.lowerPrice}]}updateDrag(t,i){if(!this.$C||null===this.HC||null===this.kP)return;const s=this.OP;if("pivot"===this.HC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.HC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.HC)s.lowerTime=t,s.lowerPrice=i;else{const n=rl(this.NC,t,i),[e,r,h]=this.kP;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.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}setColor(t){this.OP.lineColor=t,this.OP.fillColor=t,this.dM()}color(){return this.OP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isComplete(){return this.jC}remove(){if(this.SP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.OC=null,this.OP.onRemove&&this.OP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[al(this.OP.pivotPrice??0,ll(this.OP.pivotTime)),al(this.OP.upperPrice??0,ll(this.OP.upperTime)),al(this.OP.lowerPrice??0,ll(this.OP.lowerTime))],style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,lineStyle:this.OP.lineStyle,fillColor:this.OP.fillColor,fillOpacity:this.OP.fillOpacity}}}}function Hl(t,i){return new $l(t,i)}class Nl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ul{constructor(t){this.BC=t,this.Jt=new Nl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ql extends cl{constructor(t,i){super(t,"vertical-line",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.NC=null,this.cP=0,this.jP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.jP),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ul(this)}drawToCanvas(t,i,s){if(void 0===this.jP.time)return;const n=(Kn(this._chart,this._series,this.jP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.jP.lineColor,h=this.WC||this.zC&&!this.isLocked()?this.jP.lineWidth+1:this.jP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.jP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.jP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.jP.showLabel&&(this.WC||this.zC)&&this.jP.labelText&&this.uP(t,n,i,s,r)}uP(t,i,s,n,e){const r=this.jP.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const a=t.measureText(r).width,o=l,_=i-a/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,a+2*h,o+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.jP.lineColor=t,this.dM()}color(){return this.jP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.jP.time)return!1;const s=Kn(this._chart,this._series,this.jP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.$C=!0,this.NC=i,this.cP=this.jP.time}stopDrag(){this.$C=!1,this.NC=null}updateDrag(t,i){this.$C&&(this.jP.time=this.cP+rl(this.NC,t,i).gt,this.dM(),this.jP.onUpdate&&this.jP.onUpdate())}getTime(){return this.jP.time}setTime(t){this.jP.time=t,this.dM()}setLabel(t){this.jP.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[al(0,ll(this.jP.time))],style:{lineColor:this.jP.lineColor,lineWidth:this.jP.lineWidth,lineStyle:this.jP.lineStyle,showLabel:this.jP.showLabel,labelText:this.jP.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.jP.onRemove&&this.jP.onRemove()}}function jl(t,i){return new ql(t,i)}const Yl=[{YP:0,Jl:"0.0%"},{YP:.236,Jl:"23.6%"},{YP:.382,Jl:"38.2%"},{YP:.5,Jl:"50.0%"},{YP:.618,Jl:"61.8%"},{YP:.786,Jl:"78.6%"},{YP:1,Jl:"100.0%"}],Xl=[...Yl,{YP:1.272,Jl:"127.2%"},{YP:1.414,Jl:"141.4%"},{YP:1.618,Jl:"161.8%"},{YP:2,Jl:"200.0%"},{YP:2.618,Jl:"261.8%"}];class Gl{constructor(t=!1){this.XP=t?Xl:Yl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.XP.map(({YP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{YP:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.XP=t}getRatios(){return[...this.XP]}getRatioValues(){return this.XP.map(t=>t.YP)}useStandardRatios(){this.XP=Yl}useExtendedRatios(){this.XP=Xl}}class Kl{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zl{constructor(t){this.BC=t,this.Jt=new Kl(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}function Jl(t){return{YP:t,Jl:`${(100*t).toFixed(1)}%`}}class Ql extends cl{constructor(t,i){super(t,"fibonacci-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.GP=null,this.jC=!1,this.WC=!1,this.zC=!1,this.XC=null,this.$C=!1,this.KP=null,this.np=null,this.ZP={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.ZP),this.JP=new Gl(this.ZP.useExtended),void 0!==this.ZP.levels&&this.ZP.levels.length>0&&this.JP.updateRatios(this.ZP.levels.map(Jl)),this.aS(),this.ZP.interactive?this.KC():(this.jC=!0,this.QP())}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Zl(this)}drawToCanvas(t,i,s){if(!this.jC&&this.ZP.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.Xb||!this.ZP.point1Time||!this.ZP.point2Time)return;const n=(Kn(this._chart,this._series,this.ZP.point1Time)??0)*i,e=(Kn(this._chart,this._series,this.ZP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.WC?2:this.ZP.lineWidth;this.Xb.levels.forEach(n=>{this.$x(t,n,r,h,i,s,l)}),!this.WC&&!this.zC||this.isLocked()||(this.hP(t,n,(this._series.priceToCoordinate(this.ZP.point1Price)??0)*s,i),this.hP(t,e,(this._series.priceToCoordinate(this.ZP.point2Price)??0)*s,i))}$x(t,i,s,n,e,r,h=1){const l=i.ratio??i.YP,a=i.price??i.bt;if(void 0===l||void 0===a)return;const o=(this._series.priceToCoordinate(a)??0)*r;let _=this.ZP.levelColors?.[l.toString()]||this.ZP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,o),t.lineTo(n,o),t.stroke(),this.ZP.showLabels&&this.uP(t,i,s,n,o,e,_)}uP(t,i,s,n,e,r,h){const l=i.label??i.Jl,a=i.price??i.bt,o=`${l} ${this.JP.formatPrice(a)}`;t.font=11*r+"px sans-serif";const _=t.measureText(o),u=4*r,c="right"===this.ZP.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.ZP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(o,c,d)}QP(){this.ZP.point1Time&&this.ZP.point1Price&&this.ZP.point2Time&&this.ZP.point2Price&&(this.Xb=this.JP.calculateLevels(this.ZP.point1Time,this.ZP.point1Price,this.ZP.point2Time,this.ZP.point2Price),this.ZP.onUpdate&&this.Xb&&this.ZP.onUpdate(this.Xb))}updatePoints(t,i,s,n){this.ZP.point1Time=t,this.ZP.point1Price=i,this.ZP.point2Time=s,this.ZP.point2Price=n,this.QP(),this.dM()}getMetrics(){return this.Xb}getLevels(){return this.Xb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.JP.getRatioValues();return{type:"fibRetracement",points:[al(this.ZP.point1Price??0,ll(this.ZP.point1Time)),al(this.ZP.point2Price??0,ll(this.ZP.point2Time))],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,showLabels:this.ZP.showLabels,labelPosition:this.ZP.labelPosition,levelColors:this.ZP.levelColors},extra:{levels:t,useExtended:this.ZP.useExtended}}}useExtendedLevels(t){this.ZP.useExtended=t,t?this.JP.useExtendedRatios():this.JP.useStandardRatios(),this.QP(),this.dM()}KC(){this.GP=new wl(this._chart,this._series,{VC:t=>{this.ZP.point1Time=t.gt,this.ZP.point1Price=t.bt,this.dM()},LC:t=>{this.ZP.point2Time=t.gt,this.ZP.point2Price=t.bt},AC:(t,i)=>{this.ZP.point1Time=t.gt,this.ZP.point1Price=t.bt,this.ZP.point2Time=i.gt,this.ZP.point2Price=i.bt,this.jC=!0,this.XC=null,this.QP(),this.tT(),this.dM()},EC:t=>{this.XC=t,this.dM()}}),this.GP.yC()}rP(t,i,s){if(!this.ZP.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.ZP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ZP.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s,l=this.JP.calculateLevels(this.ZP.point1Time,this.ZP.point1Price,this.XC.gt,this.XC.bt),a=Math.min(n,r),o=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.YP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.ZP.levelColors?.[e.toString()]||this.ZP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.ZP.lineWidth*i,t.beginPath(),t.moveTo(a,h),t.lineTo(o,h),t.stroke(),this.ZP.showLabels){const s=`${n.label??n.Jl} ${this.JP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.ZP.labelPosition?o+_:a-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.ZP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.hP(t,n,e,i),t.globalAlpha=.6,this.hP(t,r,h,i),t.globalAlpha=1}hP(t,i,s,n){const e=this.ZP.lineColor,r=this.WC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.WC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}tT(){this.np=t=>{this.iT(t)},this._chart.subscribeCrosshairMove(this.np)}sT(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}iT(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.WC||!this.$C)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.KP?(this.ZP.point1Time=i,this.ZP.point1Price=s):"point2"===this.KP&&(this.ZP.point2Time=i,this.ZP.point2Price=s),this.QP(),this.dM())}startDrag(t){this.$C=!0,this.KP=t}stopDrag(){this.$C=!1,this.KP=null}updateDrag(t,i){this.$C&&this.KP&&("point1"===this.KP?(this.ZP.point1Time=t,this.ZP.point1Price=i):(this.ZP.point2Time=t,this.ZP.point2Price=i),this.QP(),this.dM())}hitTestEndpoint(t,i){if(!this.jC||!this.ZP.point1Time||!this.ZP.point2Time)return null;const s=Kn(this._chart,this._series,this.ZP.point1Time)??0,n=this._series.priceToCoordinate(this.ZP.point1Price)??0,e=Kn(this._chart,this._series,this.ZP.point2Time)??0,r=this._series.priceToCoordinate(this.ZP.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.ZP={...this.ZP,...t},void 0!==t.levels&&t.levels.length>0?this.JP.updateRatios(t.levels.map(Jl)):void 0!==t.useExtended&&(t.useExtended?this.JP.useExtendedRatios():this.JP.useStandardRatios()),super.applyOptions(t),this.QP(),this.dM()}options(){return{...this.ZP,levels:this.JP.getRatioValues()}}setColor(t){this.ZP.lineColor=t,this.dM()}color(){return this.ZP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isSelected(){return this.WC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.jC||!this.ZP.point1Time||!this.ZP.point2Time)return!1;const s=Kn(this._chart,this._series,this.ZP.point1Time)??0,n=Kn(this._chart,this._series,this.ZP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Xb)return!1;for(const t of this.Xb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.jC}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GP&&(this.GP.m(),this.GP=null),this.sT(),this.ZP.onRemove&&this.ZP.onRemove()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.ZP.onRemove&&this.ZP.onRemove()}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.QP(),this.dM()}}function ta(t,i){return new Ql(t,i)}class ia{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class sa{constructor(t){this.BC=t,this.Jt=new ia(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class na extends cl{constructor(t,i){super(t,"fibonacci-extension",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.ZP={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.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new sa(this)}getPoint1(){return this.ZP.point1}getPoint2(){return this.ZP.point2}getPoint3(){return this.ZP.point3}getLevels(){return this.ZP.levels||[]}getOptions(){return this.ZP}setPoint1(t){this.ZP.point1=t,this.dM()}setPoint2(t){this.ZP.point2=t,this.dM()}setPoint3(t){this.ZP.point3=t,this.dM()}isComplete(){return!!(this.ZP.point1&&this.ZP.point2&&this.ZP.point3)}setColor(t){this.ZP.lineColor=t,this.dM()}color(){return this.ZP.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.ZP.point1,this.ZP.point2,this.ZP.point3];for(const n of s){const s=Kn(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.nT();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.ZP.point1,n=this.ZP.point2,e=this.ZP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Kn(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=Kn(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=Kn(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.$C=!0,this.HC=t}stopDrag(){this.$C=!1,this.HC=null}updateDrag(t,i){if(!this.$C||!this.HC)return;const s={time:t,price:i};switch(this.HC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.ZP.onUpdate&&this.ZP.onUpdate()}nT(){if(!this.isComplete())return[];const t=this.ZP.point1,i=this.ZP.point2,s=this.ZP.point3,n=i.price-t.price;return(this.ZP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.nT()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.ZP.point1,e=this.ZP.point2,r=this.ZP.point3,h=this.WC||this.zC&&!this.isLocked(),l=(Kn(this._chart,this._series,n.time)??0)*i,a=(this._series.priceToCoordinate(n.price)??0)*s,o=(Kn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Kn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.ZP.lineColor||"#787B86",t.lineWidth=(this.ZP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,a),t.lineTo(o,_),t.stroke(),t.beginPath(),t.moveTo(o,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const a=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.ZP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.ZP.extendLines?(t.moveTo(0,a),t.lineTo(p,a)):(t.moveTo(u,a),t.lineTo(p,a)),t.stroke(),this.ZP.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,a)}}const f=(h?6:4)*i,v=[{ut:l,ct:a,Jl:"A"},{ut:o,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[ol(this.ZP.point1),ol(this.ZP.point2),ol(this.ZP.point3)],style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,showLabels:this.ZP.showLabels,extendLines:this.ZP.extendLines},extra:{levels:(this.ZP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null)}}function ea(t,i){return new na(t,i)}class ra{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ha{constructor(t){this.BC=t,this.Jt=new ra(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const la=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class aa extends cl{constructor(t,i){super(t,"fibonacci-fan",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this.rT={levels:la,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.aS(),this.rT.interactive&&!this.rT.point1Time&&this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.rT.point1Time?(this.rT.point2Time=i,this.rT.point2Price=s,this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.rT.onUpdate&&this.rT.onUpdate()):(this.rT.point1Time=i,this.rT.point1Price=s,this.dM()))},this.np=t=>{if(this.eT&&this.rT.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ha(this)}drawToCanvas(t,i,s){const n=this.rT.point1Time,e=this.rT.point1Price,r=this.eT&&this.XC?this.XC.gt:this.rT.point2Time,h=this.eT&&this.XC?this.XC.bt:this.rT.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Kn(this._chart,this._series,n)??0)*i,a=(this._series.priceToCoordinate(e)??0)*s,o=(Kn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.WC?this.rT.lineWidth+1:this.rT.lineWidth;if(this.hT(t,l,a,o,_,"#2962FF",u*i),this.rT.levels)for(const n of this.rT.levels)this.lT(t,l,a,o,_,n,i,s,undefined,u);!this.WC&&!this.zC||this.eT||this.isLocked()||(this.hP(t,l,a,i,"#2962ff"),this.hP(t,o,_,i,"#2962ff"))}lT(t,i,s,n,e,r,h,l,a,o){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.rT.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=a||r.color;this.hT(t,i,s,c,d,p,o*h),this.rT.showLabels&&!this.eT&&this.uP(t,_,u,r.label,h,p)}hT(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()}hP(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()}uP(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 a=t.measureText(n).width,o=h;t.fillStyle=r,t.fillRect(i+l,s-o-l,a+2*l,o+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-o-l+l)}setColor(t){const i=this.rT.levels??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.rT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.rT.point1Time||!this.rT.point2Time)return!1;const s=Kn(this._chart,this._series,this.rT.point1Time)??0,n=this._series.priceToCoordinate(this.rT.point1Price)??0,e=Kn(this._chart,this._series,this.rT.point2Time)??0,r=this._series.priceToCoordinate(this.rT.point2Price)??0;if(this.lP(t,i,s,n,e,r)<=8)return!0;if(this.rT.levels)for(const h of this.rT.levels){const l=n+(r-n)*h.level,a=e;if(this.lP(t,i,s,n,a,l)<=8)return!0}return!1}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.rT.point1Time||!this.rT.point2Time)return null;const s=Kn(this._chart,this._series,this.rT.point1Time)??0,n=this._series.priceToCoordinate(this.rT.point1Price)??0,e=Kn(this._chart,this._series,this.rT.point2Time)??0,r=this._series.priceToCoordinate(this.rT.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.$C=!0,this.HC=t}stopDrag(){this.$C=!1,this.HC=null}updateDrag(t,i){this.$C&&this.HC&&("point1"===this.HC?(this.rT.point1Time=t,this.rT.point1Price=i):"point2"===this.HC&&(this.rT.point2Time=t,this.rT.point2Price=i),this.dM(),this.rT.onUpdate&&this.rT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[al(this.rT.point1Price??0,ll(this.rT.point1Time)),al(this.rT.point2Price??0,ll(this.rT.point2Time))],style:{lineWidth:this.rT.lineWidth,showLabels:this.rT.showLabels,extendLines:this.rT.extendLines},extra:{levels:(this.rT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.rT.onRemove&&this.rT.onRemove()}}function oa(t,i){return new aa(t,i)}class _a{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ua{constructor(t){this.BC=t,this.Jt=new _a(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ca extends cl{constructor(t,i){super(t,"rectangle",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this.aT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.aT),this.aS(),!this.aT.interactive||this.aT.time1&&this.aT.time2||this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.aT.time1?(this.aT.time2=i,this.aT.price2=s,this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.aT.onUpdate&&this.aT.onUpdate()):(this.aT.time1=i,this.aT.price1=s,this.dM()))},this.np=t=>{if(this.eT&&this.aT.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ua(this)}drawToCanvas(t,i,s){const n=this.aT.time1,e=this.aT.price1,r=this.eT&&this.XC?this.XC.gt:this.aT.time2,h=this.eT&&this.XC?this.XC.bt:this.aT.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Kn(this._chart,this._series,n)??0)*i,a=(this._series.priceToCoordinate(e)??0)*s,o=(Kn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,o),c=Math.max(l,o),d=Math.min(a,_),p=Math.max(a,_),f=c-u,v=p-d;if(this.aT.fillOpacity>0){const i=this.hS(this.aT.fillColor,this.eT?.1:this.aT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.aT.borderColor,w=this.WC?this.aT.borderWidth+1:this.aT.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.aT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.aT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.WC&&!this.zC||this.eT||this.isLocked()||this.oT(t,u,d,c,p,i,m),this.aT.showLabel&&this.aT.labelText&&!this.eT&&this.uP(t,u,d,c,p,i,s,m)}oT(t,i,s,n,e,r,h){const l=8*r,a=[{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 a)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}uP(t,i,s,n,e,r,h,l){const a=6*r,o=12*r;t.font=`${o}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.aT.labelText).width,u=o;let c=i+a,d=s+a;switch(this.aT.labelPosition){case"top-right":c=n-_-2*a,d=s+a;break;case"bottom-left":c=i+a,d=e-u-2*a;break;case"bottom-right":c=n-_-2*a,d=e-u-2*a;break;case"center":c=(i+n)/2-_/2-a,d=(s+e)/2-u/2-a}t.fillStyle=l,t.fillRect(c,d,_+2*a,u+2*a),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.aT.labelText,c+a,d+a)}hS(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.aT.borderColor=t,this.aT.fillColor=t,this.dM()}color(){return this.aT.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.aT.time1||!this.aT.time2)return!1;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=Kn(this._chart,this._series,this.aT.time2)??0,r=this._series.priceToCoordinate(this.aT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),a=Math.min(n,r),o=Math.max(n,r);return t>=h&&t<=l&&i>=a&&i<=o}hitTestEndpoint(t,i){if(!this.aT.time1||!this.aT.time2)return null;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=Kn(this._chart,this._series,this.aT.time2)??0,r=this._series.priceToCoordinate(this.aT.price2)??0,h=Math.min(s,e),l=Math.max(s,e),a=Math.min(n,r),o=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner4":t>=h&&t<=l&&i>=a&&i<=o?"body":null}startDrag(t,i){this.$C=!0,this.HC=t,this.NC=i,"body"===t&&(this.UC={gt:this.aT.time1,bt:this.aT.price1},this.qC={gt:this.aT.time2,bt:this.aT.price2})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.UC=null,this.qC=null}updateDrag(t,i){if(!this.$C||!this.HC)return;const s=Kn(this._chart,this._series,this.aT.time1)??0,n=this._series.priceToCoordinate(this.aT.price1)??0,e=s<(Kn(this._chart,this._series,this.aT.time2)??0),r=n<(this._series.priceToCoordinate(this.aT.price2)??0);if("body"===this.HC&&this.UC&&this.qC){const s=rl(this.NC,t,i);this.aT.time1=this.UC.gt+s.gt,this.aT.price1=this.UC.bt+s.bt,this.aT.time2=this.qC.gt+s.gt,this.aT.price2=this.qC.bt+s.bt}else switch(this.HC){case"corner1":e&&r?(this.aT.time1=t,this.aT.price1=i):!e&&r?(this.aT.time2=t,this.aT.price1=i):e&&!r?(this.aT.time1=t,this.aT.price2=i):(this.aT.time2=t,this.aT.price2=i);break;case"corner2":e&&r?(this.aT.time2=t,this.aT.price1=i):!e&&r?(this.aT.time1=t,this.aT.price1=i):e&&!r?(this.aT.time2=t,this.aT.price2=i):(this.aT.time1=t,this.aT.price2=i);break;case"corner3":e&&r?(this.aT.time1=t,this.aT.price2=i):!e&&r?(this.aT.time2=t,this.aT.price2=i):e&&!r?(this.aT.time1=t,this.aT.price1=i):(this.aT.time2=t,this.aT.price1=i);break;case"corner4":e&&r?(this.aT.time2=t,this.aT.price2=i):!e&&r?(this.aT.time1=t,this.aT.price2=i):e&&!r?(this.aT.time2=t,this.aT.price1=i):(this.aT.time1=t,this.aT.price1=i)}this.dM(),this.aT.onUpdate&&this.aT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[al(this.aT.price1??0,ll(this.aT.time1)),al(this.aT.price2??0,ll(this.aT.time2))],style:{fillColor:this.aT.fillColor,fillOpacity:this.aT.fillOpacity,borderColor:this.aT.borderColor,borderWidth:this.aT.borderWidth,borderStyle:this.aT.borderStyle,showLabel:this.aT.showLabel,labelText:this.aT.labelText,labelPosition:this.aT.labelPosition}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.aT.onRemove&&this.aT.onRemove()}}function da(t,i){return new ca(t,i)}class pa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class fa{constructor(t){this.BC=t,this.Jt=new pa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class va extends cl{constructor(t,i){super(t,"circle",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.eT=!1,this.bx=null,this.np=null,this.XC=null,this._T={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this._T),this.aS(),this._T.interactive&&!this._T.centerTime&&this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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._T.centerTime){const t=this._chart.timeScale().timeToCoordinate(this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=Kn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this._T.radiusTime=Math.abs(e-t),this._T.radiusPrice=Math.abs(r-n),this.eT=!1,this.XC=null,this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this._T.onUpdate&&this._T.onUpdate()}else this._T.centerTime=i,this._T.centerPrice=s,this.dM()},this.np=t=>{if(this.eT&&this._T.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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new fa(this)}drawToCanvas(t,i,s){if(!this._T.centerTime||void 0===this._T.centerPrice)return;const n=(Kn(this._chart,this._series,this._T.centerTime)??0)*i,e=(this._series.priceToCoordinate(this._T.centerPrice)??0)*s;let r,h;if(this.eT&&this.XC){const t=(Kn(this._chart,this._series,this.XC.gt)??0)*i,l=(this._series.priceToCoordinate(this.XC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this._T.radiusTime||void 0===this._T.radiusPrice)return;r=this._T.radiusTime*i,h=this._T.radiusPrice*s}if(this._T.fillOpacity>0){const i=this.hS(this._T.fillColor,this.eT?.05:this._T.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this._T.borderColor,a=this.WC?this._T.borderWidth+1:this._T.borderWidth;t.strokeStyle=l,t.lineWidth=a*i,"dashed"===this._T.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this._T.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.WC&&!this.zC||this.eT||this.isLocked()||this.uT(t,n,e,i,l),!this.WC&&!this.zC||this.eT||this.isLocked()||this.cT(t,n,e,r,h,i,l),this._T.showLabel&&this._T.labelText&&!this.eT&&this.uP(t,n,e,i,l)}uT(t,i,s,n,e){const r=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r/2,0,2*Math.PI),t.fill(),t.stroke()}cT(t,i,s,n,e,r,h){const l=8*r,a=[{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 a)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}uP(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._T.labelText).width,a=h,o=i-l/2-r,_=s-a/2-r;t.fillStyle=e,t.fillRect(o,_,l+2*r,a+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this._T.labelText,o+r,_+r)}hS(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._T.borderColor=t,this._T.fillColor=t,this.dM()}color(){return this._T.borderColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this._T.centerTime||void 0===this._T.radiusTime)return!1;const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=(t-s)/this._T.radiusTime,r=(i-n)/this._T.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this._T.centerTime||void 0===this._T.radiusTime)return null;const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=this._T.radiusTime,r=this._T.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.$C=!0,this.HC=t,this.NC=i,this.kP="center"===t?{gt:this._T.centerTime,bt:this._T.centerPrice}:null}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C&&this.HC){if("center"===this.HC&&this.kP){const s=rl(this.NC,t,i);this._T.centerTime=this.kP.gt+s.gt,this._T.centerPrice=this.kP.bt+s.bt}else if("edge"===this.HC){const s=Kn(this._chart,this._series,this._T.centerTime)??0,n=this._series.priceToCoordinate(this._T.centerPrice)??0,e=Kn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this._T.radiusTime=Math.abs(e-s),this._T.radiusPrice=Math.abs(r-n)}this.dM(),this._T.onUpdate&&this._T.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[al(this._T.centerPrice??0,ll(this._T.centerTime))],style:{fillColor:this._T.fillColor,fillOpacity:this._T.fillOpacity,borderColor:this._T.borderColor,borderWidth:this._T.borderWidth,borderStyle:this._T.borderStyle,showLabel:this._T.showLabel,labelText:this._T.labelText},extra:{radiusTime:this._T.radiusTime,radiusPrice:this._T.radiusPrice}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this._T.onRemove&&this._T.onRemove()}}function ma(t,i){return new va(t,i)}class wa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ga{constructor(t){this.BC=t,this.Jt=new wa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ba extends cl{constructor(t,i){super(t,"arrow",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.dT=-1,this.eT=!1,this.bx=null,this.pT=null,this.np=null,this.XC=null,this.fT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.fT),this.aS(),!this.fT.interactive||this.fT.points&&0!==this.fT.points.length||this.KC()}KC(){this.eT=!0,this.bx=t=>{if(!t.point)return;if(fl(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.fT.points||(this.fT.points=[]),this.fT.points.push({time:i,price:s}),this.dM(),this.fT.onUpdate&&this.fT.onUpdate())},this.np=t=>{if(this.eT)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.XC={gt:i,bt:s},this.dM())}else this.XC=null,this.dM()},this.pT=t=>{this.eT&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.bx),this._chart.subscribeCrosshairMove(this.np);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.pT)}finishDrawing(){if(this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.pT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.pT),this.pT=null}this.eT=!1,this.XC=null,this.dM(),this.fT.onComplete&&this.fT.onComplete()}isDrawing(){return this.eT}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ga(this)}drawToCanvas(t,i,s){if(!this.fT.points||0===this.fT.points.length)return;const n=this.fT.lineColor,e=this.WC||this.zC&&!this.isLocked()?this.fT.lineWidth+1:this.fT.lineWidth,r=[];for(const t of this.fT.points)try{let n=Kn(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.eT)return;let h=null;if(this.eT&&this.XC&&this.fT.points.length>0){h={ut:(Kn(this._chart,this._series,this.XC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.XC.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.fT.showArrowHead&&r.length>1&&this.vT(t,r[r.length-2],r[r.length-1],i,n),this.fT.showCircles)for(let s=0;s<r.length;s++)this.mT(t,r[s].ut,r[s].ct,i,n,0===s)}vT(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)},a={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(a.ut,a.ct),t.closePath(),t.fill()}mT(t,i,s,n,e,r){const h=this.fT.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.fT.lineColor=t,this.dM()}color(){return this.fT.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.fT.points||0===this.fT.points.length)return!1;for(let s=0;s<this.fT.points.length-1;s++)try{const n=this.fT.points[s],e=this.fT.points[s+1];let r=Kn(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=Kn(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),a=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===a)continue;if(this.lP(t,i,r,l,h,a)<=8)return!0}catch{continue}for(const s of this.fT.points)try{let n=Kn(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}lP(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;if(0===a)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let o=((t-s)*h+(i-n)*l)/a;o=Math.max(0,Math.min(1,o));const _=s+o*h,u=n+o*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.fT.points||0===this.fT.points.length)return null;for(let s=0;s<this.fT.points.length;s++)try{const n=this.fT.points[s];let e=Kn(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.$C=!0,this.dT=t}stopDrag(){this.$C=!1,this.dT=-1}updateDrag(t,i){this.$C&&-1!==this.dT&&this.fT.points&&this.dT>=0&&this.dT<this.fT.points.length&&(this.fT.points[this.dT]={time:t,price:i},this.dM(),this.fT.onUpdate&&this.fT.onUpdate())}getPoints(){return this.fT.points||[]}addPoint(t){this.fT.points||(this.fT.points=[]),this.fT.points.push(t),this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.fT.points||[]).map(t=>ol(t)),style:{lineColor:this.fT.lineColor,lineWidth:this.fT.lineWidth,showArrowHead:this.fT.showArrowHead,showCircles:this.fT.showCircles,circleRadius:this.fT.circleRadius}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!this.eT}remove(){if(this.bx&&(this._chart.unsubscribeClick(this.bx),this.bx=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.pT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.pT),this.pT=null}this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.fT.onRemove&&this.fT.onRemove()}}function Ma(t,i){return new ba(t,i)}class ya{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Sa{constructor(t){this.BC=t,this.Jt=new ya(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class xa extends cl{constructor(t,i){super(t,"brush",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.wT=!1,this.eT=!1,this.gT=[],this.bT=!1,this.Df=null,this.IS=null,this.WS=null,this.$S=null,this.NS=null,this.MT=void 0,this.BS=null,this.$C=!1,this.NC=null,this.fP=null,this.yT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.yT),this.aS(),0===(this.yT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.wT)return;const t=this._chart.chartElement();t&&(this.Df=t,this.wT=!0,this.WS=t=>this.zS(t),this.$S=t=>this.HS(t),this.NS=()=>this.US(),this.BS=t=>{this.MT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.BS),t.addEventListener("pointerdown",this.WS,!0),t.addEventListener("pointermove",this.$S,!0),t.addEventListener("pointerup",this.NS,!0),t.addEventListener("pointercancel",this.NS,!0))}stopDrawingMode(){if(!this.wT)return;this.ST(),this.wT=!1;const t=this.Df;t&&(this.WS&&t.removeEventListener("pointerdown",this.WS,!0),this.$S&&t.removeEventListener("pointermove",this.$S,!0),this.NS&&(t.removeEventListener("pointerup",this.NS,!0),t.removeEventListener("pointercancel",this.NS,!0))),this.BS&&(this._chart.unsubscribeCrosshairMove(this.BS),this.BS=null),this.WS=null,this.$S=null,this.NS=null,this.Df=null}isDrawingModeActive(){return this.wT}zS(t){if(this.xT())return;const i=this.CT(t,!1);null!==i&&(this.eT=!0,this.gT=[i],this.IS=t.pointerId,pl(this._chart,!0),this.Df?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.PT())}HS(t){if(!this.eT)return;const i=this.CT(t,!0);if(null===i)return;const s=this.gT[this.gT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.yT.sampleDistance??4)||(this.gT.push(i),t.preventDefault(),t.stopPropagation(),this.PT())}US(){this.eT&&this.ST()}ST(){if(!this.eT)return;this.eT=!1,this.hx();const t=[];for(const i of this.gT){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.gT=[],t.length<2?this.dM():(this.yT.points=t,this.stopDrawingMode(),this.dM(),this.yT.onUpdate&&this.yT.onUpdate(),this.yT.onComplete&&this.yT.onComplete())}xT(){const t=this.MT;return"string"==typeof t&&t.split("#")[0]!==this.id}hx(){null!==this.IS&&(this.Df&&this.Df.hasPointerCapture(this.IS)&&this.Df.releasePointerCapture(this.IS),this.IS=null)}CT(t,i){const s=this.TT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Xx;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}TT(){const t=this.kT();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,Xx:i.top,ts:n,qt:i.height}}kT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}PT(){this.bT||(this.bT=!0,requestAnimationFrame(()=>{this.bT=!1,this.dM()}))}drawToCanvas(t,i,s){const n=this.eT?this.gT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.DT(i,s);if(0===n.length)return;const e=this.WC;if(t.strokeStyle=this.yT.color,t.lineWidth=(this.yT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.yT.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.zC||this.isLocked()||(this.hP(t,n[0],i),this.hP(t,n[n.length-1],i))}hP(t,i,s){t.fillStyle=this.yT.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()}DT(t,i){const s=this.yT.points??[],n=[];for(const e of s){const s=Kn(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.DT(1,1);for(let n=1;n<s.length;n++)if(Ca(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.$C=!0,this.NC=i,this.fP=(this.yT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.fP;if(!this.$C||null===s||!this.yT.points)return;const n=rl(this.NC,t,i);this.yT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.dM(),this.yT.onUpdate&&this.yT.onUpdate()}stopDrag(){this.$C=!1,this.NC=null,this.fP=null}setColor(t){this.yT.color=t,this.dM()}color(){return this.yT.color??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}aS(){this.eh=new Sa(this);const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):null}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.stopDrawingMode(),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null),this.eh=null,this.yT.onRemove&&this.yT.onRemove()}_serializeShape(){return{type:"brush",points:(this.yT.points??[]).map(ol),style:{color:this.yT.color,lineWidth:this.yT.lineWidth,smoothing:this.yT.smoothing}}}getPoints(){return this.yT.points??[]}}function Ca(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 Pa(t,i={}){return new xa(t,i)}class Ta{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ka{constructor(t){this.BC=t,this.Jt=new Ta(t)}renderer(){return this.BC.isComplete()?this.Jt:null}}class Da extends cl{constructor(t,i){super(t,"text-tool",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.RT=!1,this.FT=null,this.IT={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.IT),this.aS(),this.VT()}VT(){const t=t=>{if(!this.RT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.IT.text&&""!==this.IT.text.trim()&&"Type here..."!==this.IT.text||this.remove())};this.FT=t,this._chart.subscribeClick(t)}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new ka(this)}getTime(){return this.IT.time}getPrice(){return this.IT.price}getText(){return this.IT.text||""}getOptions(){return this.IT}setPosition(t,i){this.IT.time=t,this.IT.price=i,this._update()}setText(t){this.IT.text=t,this._update(),this.IT.onTextChange&&this.IT.onTextChange(t)}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}isComplete(){return!(!this.IT.time||void 0===this.IT.price)}setColor(t){this.IT.textColor=t,this.IT.borderColor=t,this.dM()}color(){return this.IT.textColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this._update())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this._update())}isHovered(){return this.zC}setEditing(t){this.RT!==t&&(this.RT=t,this._update())}isEditing(){return this.RT}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.IT.time,n=this.IT.price,e=Kn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.IT.fontSize||14,l=this.IT.padding||8,a=this.IT.text||"",o=.6*h,_=Math.min(a.length*o,this.IT.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.IT.time,n=this.IT.price,e=Kn(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.$C=!0,this.HC=t,this.NC=i,this.kP={gt:this.IT.time,bt:this.IT.price}}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C){if("body"===this.HC&&this.kP){const s=rl(this.NC,t,i);this.setPosition(this.kP.gt+s.gt,this.kP.bt+s.bt)}else this.setPosition(t,i);this.IT.onUpdate&&this.IT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.IT.time,e=this.IT.price,r=this.IT.text||"",h=(Kn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,a=(this.IT.fontSize||14)*i,o=(this.IT.padding||8)*i,_=(this.IT.maxWidth||200)*i;t.font=`${a}px ${this.IT.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*o,v=1.2*a,m=c.length*v+2*o,w=this.IT.backgroundOpacity||.8,g=this.IT.backgroundColor||"#2962FF";t.fillStyle=this.hS(g,w),t.fillRect(h,l,f,m),(this.WC||this.zC)&&(t.strokeStyle=this.IT.borderColor??"#FFFFFF",t.lineWidth=(this.IT.borderWidth||1)*i*(this.WC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.IT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+o;if("center"===this.IT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.IT.textAlign){n=h+f-t.measureText(s).width-o}const e=l+o+i*v;t.fillText(s,n,e)}if((this.WC||this.zC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.IT.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()}}hS(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:[al(this.IT.price??0,ll(this.IT.time))],style:{fontSize:this.IT.fontSize,fontFamily:this.IT.fontFamily,textColor:this.IT.textColor,backgroundColor:this.IT.backgroundColor,backgroundOpacity:this.IT.backgroundOpacity,padding:this.IT.padding,borderColor:this.IT.borderColor,borderWidth:this.IT.borderWidth,textAlign:this.IT.textAlign,maxWidth:this.IT.maxWidth},extra:{text:this.IT.text}}}remove(){this.FT&&(this._chart.unsubscribeClick(this.FT),this.FT=null),this.qb&&this._series&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.IT.onRemove&&this.IT.onRemove()}}function Ra(t,i){return new Da(t,i)}class Fa{constructor(t){this.LT=t}calculatePips(t,i){return Math.abs(i-t)/this.LT.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.LT={...this.LT,...t}}getPipConfig(){return{...this.LT}}}function Ia(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 Va(t,i){return"number"==typeof t?Ia(t):void 0!==i?Ia(i):{pipValue:.1,decimals:1}}class La{constructor(t){this.LT=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.LT.pipValue,timeDifference:this.AT(t,s),barCount:e}}AT(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.LT={...this.LT,...t}}getPipConfig(){return{...this.LT}}}class Aa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ea{constructor(t){this.BC=t,this.Jt=new Aa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class Ba extends cl{constructor(t,i){super(t,"ruler-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.GP=null,this.jC=!1,this.WC=!1,this.zC=!1,this.XC=null,this.$C=!1,this.KP=null,this.np=null,this.ET={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.ET);const s=this.ET.pipConfig||Va(this.ET.symbol||"DEFAULT");this.JP=new La(s),this.aS(),this.ET.interactive?this.KC():this.ET.point1Time&&this.ET.point2Time&&(this.jC=!0,this.QP())}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ea(this)}KC(){this.GP=new wl(this._chart,this._series,{VC:t=>{this.ET.point1Time=t.gt,this.ET.point1Price=t.bt,this.dM()},LC:t=>{this.ET.point2Time=t.gt,this.ET.point2Price=t.bt},AC:(t,i)=>{this.ET.point1Time=t.gt,this.ET.point1Price=t.bt,this.ET.point2Time=i.gt,this.ET.point2Price=i.bt,this.jC=!0,this.XC=null,this.QP(),this.tT(),this.dM()},EC:t=>{this.XC=t,this.dM()}}),this.GP.yC()}drawToCanvas(t,i,s){if(!this.jC&&this.ET.point1Time&&this.XC)return void this.rP(t,i,s);if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return;const n=(Kn(this._chart,this._series,this.ET.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ET.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.ET.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.ET.point2Price)??0)*s;(this.WC||this.zC&&!this.isLocked())&&(t.strokeStyle=this.ET.selectionColor,t.lineWidth=this.ET.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.BT(t,n,e,r,h,i),this.hP(t,n,e,i),this.hP(t,r,h,i),this.ET.showLabel&&this.Xb&&this.uP(t,n,e,r,h,i,s)}BT(t,i,s,n,e,r){const h=this.ET.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.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()}hP(t,i,s,n){const e=this.WC?this.ET.selectionColor:this.ET.lineColor,r=this.WC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.WC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}rP(t,i,s){if(!this.ET.point1Time||!this.XC)return;const n=(Kn(this._chart,this._series,this.ET.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ET.point1Price)??0)*s,r=(Kn(this._chart,this._series,this.XC.gt)??0)*i,h=(this._series.priceToCoordinate(this.XC.bt)??0)*s;t.strokeStyle=this.ET.lineColor,t.lineWidth=this.ET.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.hP(t,n,e,i),t.globalAlpha=.5,this.hP(t,r,h,i),t.globalAlpha=1}uP(t,i,s,n,e,r,h){if(!this.Xb)return;const l=(i+n)/2,a=(s+e)/2,o=this.ET.measure??"both",_=[];"time"!==o&&(_.push(this.JP.formatPips(this.Xb.pips)),_.push(this.JP.formatPercent(this.Xb.pricePercent))),"price"!==o&&_.push(this.JP.formatBarCount(this.Xb.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.ET.labelBackgroundColor,t.fillRect(l-d/2,a-p/2,d,p),t.fillStyle=this.ET.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,a)}QP(){if(!this.ET.point1Time||!this.ET.point2Time||void 0===this.ET.point1Price||void 0===this.ET.point2Price)return;const t=this.OT();this.Xb=this.JP.calculateMetrics(this.ET.point1Time,this.ET.point1Price,this.ET.point2Time,this.ET.point2Price,t),this.ET.onUpdate&&this.Xb&&this.ET.onUpdate(this.Xb)}OT(){if(!this.ET.point1Time||!this.ET.point2Time)return 0;const t=Kn(this._chart,this._series,this.ET.point1Time),i=Kn(this._chart,this._series,this.ET.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.ET.point1Time=t,this.ET.point1Price=i,this.ET.point2Time=s,this.ET.point2Price=n,this.QP(),this.dM()}getMetrics(){return this.Xb}remove(){this.destroy()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.GP&&(this.GP.m(),this.GP=null),this.sT(),this.ET.onRemove&&this.ET.onRemove()}tT(){this.np=t=>{this.iT(t)},this._chart.subscribeCrosshairMove(this.np)}sT(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}iT(t){if(!t.point)return;const i=Gn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.WC||!this.$C)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.KP?(this.ET.point1Time=i,this.ET.point1Price=s):"point2"===this.KP&&(this.ET.point2Time=i,this.ET.point2Price=s),this.QP(),this.dM())}startDrag(t){this.$C=!0,this.KP=t}stopDrag(){this.$C=!1,this.KP=null}updateDrag(t,i){this.$C&&this.KP&&("point1"===this.KP?(this.ET.point1Time=t,this.ET.point1Price=i):(this.ET.point2Time=t,this.ET.point2Price=i),this.QP(),this.dM())}hitTestEndpoint(t,i){if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return null;const s=Kn(this._chart,this._series,this.ET.point1Time)??0,n=this._series.priceToCoordinate(this.ET.point1Price)??0,e=Kn(this._chart,this._series,this.ET.point2Time)??0,r=this._series.priceToCoordinate(this.ET.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}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.QP(),this.dM()}_serializeShape(){return{type:"ruler",points:[al(this.ET.point1Price??0,ll(this.ET.point1Time)),al(this.ET.point2Price??0,ll(this.ET.point2Time))],style:{lineColor:this.ET.lineColor,lineWidth:this.ET.lineWidth,showLabel:this.ET.showLabel,labelBackgroundColor:this.ET.labelBackgroundColor,labelTextColor:this.ET.labelTextColor,selectionColor:this.ET.selectionColor,selectionLineWidth:this.ET.selectionLineWidth},extra:{symbol:this.ET.symbol,pipConfig:this.ET.pipConfig,measure:this.ET.measure}}}setColor(t){this.ET.lineColor=t,this.dM()}color(){return this.ET.lineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}isSelected(){return this.WC}isComplete(){return this.jC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.jC||!this.ET.point1Time||!this.ET.point2Time)return!1;const s=Kn(this._chart,this._series,this.ET.point1Time)??0,n=this._series.priceToCoordinate(this.ET.point1Price)??0,e=Kn(this._chart,this._series,this.ET.point2Time)??0,r=this._series.priceToCoordinate(this.ET.point2Price)??0;return this.WT(t,i,s,n,e,r)<=(this.WC?12:8)}WT(t,i,s,n,e,r){const h=e-s,l=r-n,a=h*h+l*l;let o,_,u=-1;0!==a&&(u=((t-s)*h+(i-n)*l)/a),u<0?(o=s,_=n):u>1?(o=e,_=r):(o=s+u*h,_=n+u*l);const c=t-o,d=i-_;return Math.sqrt(c*c+d*d)}}function Oa(t,i){return new Ba(t,i)}class Wa{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class za{constructor(t){this.BC=t,this.Jt=new Wa(t)}renderer(){return this.BC.isVisible()?this.Jt:null}}class $a extends cl{constructor(t,i){super(t,"position-tool",i),this.qb=null,this.OC=null,this.Xb=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.HC=null,this.NC=null,this.kP=null,this.zT=null,this.$T=null,this.HT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.HT);const s=this.HT.pipConfig||Va(this.HT.entryPrice);this.JP=new Fa(s),this.aS(),this.QP()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new za(this)}drawToCanvas(t,i,s){if(this.zT&&this.HT.takeProfit){const n=this._chart.timeScale();this.NT(t,this.zT,i,s,n),(this.zC||this.WC)&&this.uP(t,this.zT,"profit",i,s,n)}if(this.$T&&this.HT.stopLoss){const n=this._chart.timeScale();if(this.NT(t,this.$T,i,s,n),this.zC||this.WC){const n=this._chart.timeScale();this.uP(t,this.$T,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.UT(t,i,s,n),this.HT.takeProfit){const n=this._chart.timeScale();this.hP(t,this.HT.takeProfit,this.HT.profitColor,i,s,n)}if(this.HT.stopLoss){const n=this._chart.timeScale();this.hP(t,this.HT.stopLoss,this.HT.lossColor,i,s,n)}}NT(t,i,s,n,e){const r=(Kn(this._chart,this._series,this.HT.entryTime)??0)*s;let h;if(this.HT.endTime)h=(Kn(this._chart,this._series,this.HT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.qT)??0)*n,a=(this._series.priceToCoordinate(i.jT)??0)*n;t.fillStyle=this.hS(i.R,.15),t.fillRect(r,Math.min(l,a),h-r,Math.abs(a-l)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(r,a),t.lineTo(h,a),t.stroke()}UT(t,i,s,n){const e=(Kn(this._chart,this._series,this.HT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.HT.entryPrice)??0)*s;let h;if(this.HT.endTime)h=(Kn(this._chart,this._series,this.HT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.HT.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.HT.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,a),t.stroke(),t.setLineDash([]),!this.WC&&!this.zC||this.isLocked())t.fillStyle=this.HT.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)}}QP(){this.HT.stopLoss&&this.HT.takeProfit&&(this.Xb=this.JP.calculateMetrics(this.HT.entryPrice,this.HT.stopLoss,this.HT.takeProfit,this.HT.quantity),this.YT(),this.HT.onUpdate&&this.Xb&&this.HT.onUpdate(this.Xb))}YT(){const t=this.XT();this.HT.takeProfit&&(this.zT={GT:this.HT.entryTime,KT:t,qT:this.HT.entryPrice,jT:this.HT.takeProfit,R:this.HT.profitColor,Vy:this.HT.opacity}),this.HT.stopLoss&&(this.$T={GT:this.HT.entryTime,KT:t,qT:this.HT.entryPrice,jT:this.HT.stopLoss,R:this.HT.lossColor,Vy:this.HT.opacity})}XT(){this._chart.timeScale().getVisibleLogicalRange();return this.HT.entryTime}uP(t,i,s,n,e,r){if(!this.Xb)return;const h=(Kn(this._chart,this._series,this.HT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.jT)??0)*e,a="profit"===s,o=a?this.Xb.takeProfitPips:this.Xb.stopLossPips,_=a?this.HT.takeProfit:this.HT.stopLoss,u=this.Xb.riskRewardRatio,c=a?`Objetivo: ${_?.toFixed(5)} (${o.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${o.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.R,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}hP(t,i,s,n,e,r){const h=(Kn(this._chart,this._series,this.HT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,a=s;let o;if(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(h,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this.HT.endTime)o=(Kn(this._chart,this._series,this.HT.endTime)??0)*n;else{o=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-_/2,l-_/2,_,_),t.strokeRect(o-_/2,l-_/2,_,_)}hS(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.HT={...this.HT,...t},this.QP(),this._update()}getMetrics(){return this.Xb}setStopLoss(t){this.HT.stopLoss=t,this.QP(),this._update()}setTakeProfit(t){this.HT.takeProfit=t,this.QP(),this._update()}setEntryPrice(t){this.HT.entryPrice=t,this.QP(),this._update()}_serializeShape(){return{type:"position",points:[al(this.HT.entryPrice,ll(this.HT.entryTime))],style:{profitColor:this.HT.profitColor,lossColor:this.HT.lossColor,entryLineColor:this.HT.entryLineColor,opacity:this.HT.opacity,showTooltips:this.HT.showTooltips},extra:{endTime:ll(this.HT.endTime),stopLoss:this.HT.stopLoss,takeProfit:this.HT.takeProfit,quantity:this.HT.quantity,pipConfig:this.HT.pipConfig}}}setColor(t){this.HT.entryLineColor=t,this.dM()}color(){return this.HT.entryLineColor??""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):this.hitTest(t,i)?el(this.id,"body",!1):null}hitTest(t,i){if(!this.HT.stopLoss&&!this.HT.takeProfit)return!1;const s=Kn(this._chart,this._series,this.HT.entryTime)??0;let n;if(this.HT.endTime)n=Kn(this._chart,this._series,this.HT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.HT.takeProfit&&this.HT.stopLoss){const e=this._series.priceToCoordinate(this.HT.takeProfit)??0,r=this._series.priceToCoordinate(this.HT.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=h&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Kn(this._chart,this._series,this.HT.entryTime)??0;let n;if(this.HT.endTime)n=Kn(this._chart,this._series,this.HT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.HT.takeProfit){const n=this._series.priceToCoordinate(this.HT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.HT.stopLoss){const n=this._series.priceToCoordinate(this.HT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.HT.takeProfit){const s=this._series.priceToCoordinate(this.HT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.HT.stopLoss){const s=this._series.priceToCoordinate(this.HT.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.HT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.HT.takeProfit&&this.HT.stopLoss){const e=this._series.priceToCoordinate(this.HT.takeProfit)??0,r=this._series.priceToCoordinate(this.HT.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.$C=!0,this.HC=t,this.NC=i,"move"===t&&(this.kP={ZT:this.HT.entryPrice,JT:this.HT.entryTime??null,rS:this.HT.endTime??null,QT:this.HT.takeProfit??null,tk:this.HT.stopLoss??null})}stopDrag(){this.$C=!1,this.HC=null,this.NC=null,this.kP=null}updateDrag(t,i){if(this.$C&&this.HC){if("entry"===this.HC)this.HT.entryPrice=i;else if("move"===this.HC){if(this.kP){const s=rl(this.NC,t,i),n=this.kP;this.HT.entryPrice=n.ZT+s.bt,null!==n.QT&&(this.HT.takeProfit=n.QT+s.bt),null!==n.tk&&(this.HT.stopLoss=n.tk+s.bt),null!==n.JT&&(this.HT.entryTime=this.ik(n.JT,s.gt)),null!==n.rS&&(this.HT.endTime=this.ik(n.rS,s.gt))}}else"tp"===this.HC||"tp-right"===this.HC?(this.HT.takeProfit=i,"tp-right"===this.HC?this.HT.endTime=t:this.HT.entryTime=t):"sl"!==this.HC&&"sl-right"!==this.HC||(this.HT.stopLoss=i,"sl-right"===this.HC?this.HT.endTime=t:this.HT.entryTime=t);this.QP(),this.dM()}}ik(t,i){return t+i}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.HT.onRemove&&this.HT.onRemove()}}function Ha(t,i){return new $a(t,i)}class Na{constructor(t){this.BC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.BC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ua{constructor(t){this.BC=t,this.Jt=new Na(t)}renderer(){return this.BC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class qa extends cl{constructor(t,i){super(t,"gantt",i),this.qb=null,this.OC=null,this.eh=null,this.WC=!1,this.zC=!1,this.$C=!1,this.sk=-1,this.NC=null,this.kP=null,this.nk=-1,this.ek={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.ek),this.aS()}aS(){this.eh=this.ZC();const t={attached:t=>{this.OC=t.requestUpdate},detached:()=>{this.OC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.JC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}ZC(){return new Ua(this)}drawToCanvas(t,i,s){if(!this.ek.segments||0===this.ek.segments.length)return;const n=50*s,e=this.ek.rowHeight*s,r=this.ek.rowSpacing*s;this.ek.showGrid&&this.nm(t,n,e,r,i,s),this.ek.segments.forEach((s,h)=>{const l=(Kn(this._chart,this._series,s.startTime)??0)*i,a=(Kn(this._chart,this._series,s.endTime)??0)*i,o=n+s.level*(e+r),_=h===this.nk||this.zC&&!this.isLocked();this.rk(t,l,a,o,e,s,_,i)})}nm(t,i,s,n,e,r){if(!this.ek.segments)return;const h=Math.max(...this.ek.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()}}rk(t,i,s,n,e,r,h,l){const a=s-i,o=this.hS(r.color,h?this.ek.fillOpacity+.2:this.ek.fillOpacity);t.fillStyle=o,t.fillRect(i,n,a,e),t.strokeStyle=r.color;const _=this.ek.borderWidth+(this.WC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,a,e),this.ek.showLabels&&r.label&&this.uP(t,i,n,a,e,r.label,l)}uP(t,i,s,n,e,r,h){const l=11*h,a=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let o=r;const _=n-2*a;let u=t.measureText(o).width;if(u>_&&_>0){for(;u>_&&o.length>0;)o=o.slice(0,-1),u=t.measureText(o+"...").width;o+="..."}t.fillText(o,i+a,s+e/2)}hS(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.ek.segments||(this.ek.segments=[]),this.ek.segments.push(t),this.dM(),this.ek.onUpdate&&this.ek.onUpdate()}removeSegment(t){this.ek.segments&&t>=0&&t<this.ek.segments.length&&(this.ek.segments.splice(t,1),this.dM(),this.ek.onUpdate&&this.ek.onUpdate())}getSegments(){return this.ek.segments||[]}setColor(t){const i=this.ek.segments??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.ek.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.WC!==t&&(this.WC=t,this.dM())}isSelected(){return this.WC}setHovered(t){this.zC!==t&&(this.zC=t,this.dM())}isHovered(){return this.zC}JC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?el(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.ek.segments?.[this.nk];s&&(this.$C=!0,this.sk=this.nk,this.NC=i,this.kP={eS:s.startTime,rS:s.endTime})}updateDrag(t,i){const s=this.ek.segments?.[this.sk];if(!this.$C||!this.kP||!s)return;const n=rl(this.NC,t,i);s.startTime=this.kP.eS+n.gt,s.endTime=this.kP.rS+n.gt,this.dM(),this.ek.onUpdate&&this.ek.onUpdate()}stopDrag(){this.$C=!1,this.sk=-1,this.NC=null,this.kP=null}hitTest(t,i){if(!this.ek.segments||0===this.ek.segments.length)return!1;const s=this.ek.rowHeight,n=this.ek.rowSpacing;for(let e=0;e<this.ek.segments.length;e++){const r=this.ek.segments[e],h=Kn(this._chart,this._series,r.startTime)??0,l=Kn(this._chart,this._series,r.endTime)??0,a=50+r.level*(s+n);if(t>=h&&t<=l&&i>=a&&i<=a+s)return this.nk=e,!0}return this.nk=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.ek.rowHeight,rowSpacing:this.ek.rowSpacing,fillOpacity:this.ek.fillOpacity,borderWidth:this.ek.borderWidth,showLabels:this.ek.showLabels,showGrid:this.ek.showGrid},extra:{segments:(this.ek.segments||[]).map(t=>({eS:ll(t.startTime),rS:ll(t.endTime),sn:t.level,Jl:t.label,R:t.color,hk:t.category}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.OC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.ek.onRemove&&this.ek.onRemove()}}function ja(t,i){return new qa(t,i)}class Ya{constructor(t,i,s={}){this.lk=[],this.ak=[],this._k=[],this.uk=!1,this.ck=new Map,this.dk=null,this.pk=null,this.fk=null,this.bx=null,this.vk=null,this.np=null,this.mk=null,this.wk=null,this.gk=null,this.bk=null,this.Mk=null,this.IS=null,this.yk=!1,this.Sk=null,this.xk=null,this.Ck=new o,this.$C=!1,this.Pk=null,this.Tk=new Set,this.kk=null,this.Dk=new o,this.Vf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Rk()}startDrawing(t){this.fk=t,this.Fk()}activeDrawingType(){return this.fk}stopDrawing(){this.fk=null}addTool(t,i){const s=i??t.id;return this.ck.set(s,t),t.isComplete()||this.Tk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Tk.size>0}cancelPendingDrawings(){if(0===this.Tk.size)return 0;let t=0;for(const i of Array.from(this.Tk)){const s=this.ck.get(i);s&&(this.dk===i&&this.Ik(null),s.remove(),this.ck.delete(i),t++)}return this.Tk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Dk.i(t)}unsubscribeDrawingCompleted(t){this.Dk._(t)}Vk(){0!==this.Tk.size&&null===this.kk&&(this.kk=setTimeout(()=>{this.kk=null;for(const t of Array.from(this.Tk)){const i=this.ck.get(t);i?i.isComplete()&&(this.Tk.delete(t),this.Dk.p(t)):this.Tk.delete(t)}},0))}removeTool(t){const i=this.ck.get(t);return!!i&&(this.dk===t&&this.Ik(null),i.remove(),this.ck.delete(t),this.Tk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.ck.has(t)&&(this.Ik(t),!0)}Ik(t){if(this.dk===t)return;const i=null===this.dk?void 0:this.ck.get(this.dk);i&&i.setSelected(!1),this.dk=t;const s=null===t?void 0:this.ck.get(t);s&&s.setSelected(!0),this.Lk()}recordChange(){this.uk||(this.lk.push(this._k),this.lk.length>100&&this.lk.shift(),this.ak=[],this._k=this.serializeAll())}canUndo(){return this.lk.length>0}canRedo(){return this.ak.length>0}undo(){const t=this.lk.pop();return void 0!==t&&(this.ak.push(this._k),this.Ak(t),!0)}redo(){const t=this.ak.pop();return void 0!==t&&(this.lk.push(this._k),this.Ak(t),!0)}Ak(t){this.uk=!0;try{this.restoreAll({chart:this.Vf,series:this.be},t,!0),this._k=t}finally{this.uk=!1}}subscribeSelectionChanged(t){this.Ck.i(t)}unsubscribeSelectionChanged(t){this.Ck._(t)}selectionBounds(){if(null===this.dk)return null;const t=this.ck.get(this.dk);return t?this.Ek(t):null}Ek(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=Kn(this.Vf,i,t.time),a=i.priceToCoordinate(t.price);null!==s&&null!==a&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,a),h=Math.max(h,a))}if(!l)return null;const a=this.Bk(t);return{left:n+a.ut,right:r+a.ut,top:e+a.ct,bottom:h+a.ct}}Bk(t){const i=this.Vf.chartElement(),s=this.Ok(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}}Lk(){this.Ck.p({id:this.dk,bounds:this.selectionBounds()})}deselectAll(){this.Fk()}deleteSelected(){if(this.dk){const t=this.ck.get(this.dk);return(!t||!t.isLocked())&&this.removeTool(this.dk)}return!1}getSelectedToolId(){return this.dk}getAllTools(){return new Map(this.ck)}getTool(t){return this.ck.get(t)}clearAll(){this.Ik(null),this.ck.forEach(t=>t.remove()),this.ck.clear(),this.Tk.clear(),this.recordChange()}getToolCount(){return this.ck.size}isToolSelected(t){return this.dk===t}serializeAll(){const t=[];for(const i of this.ck.values())t.push(i.serialize());return t}restoreTool(t,i){const s=Ya.Wk(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 Wk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({zk:_l(n[t]),$k:ul(n[t],"price")??0});switch(s){case"trendLine":return yl(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,...e});case"horizontalLine":return Pl(t,{price:h(0).$k,startTime:h(0).zk??void 0,...e});case"parallelChannel":return Ol(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,channelWidth:r?.channelWidth,...e});case"pitchfork":return Hl(t,{pivotTime:h(0).zk,pivotPrice:h(0).$k,upperTime:h(1).zk,upperPrice:h(1).$k,lowerTime:h(2).zk,lowerPrice:h(2).$k,...e});case"polygon":return Ll(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).zk,s.price=h(i).$k,s}),...e});case"crossLine":return Rl(t,{time:h(0).zk,price:h(0).$k,...e});case"verticalLine":return jl(t,{time:h(0).zk,...e});case"fibRetracement":return ta(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return ea(t,{point1:i.zk?{time:i.zk,price:i.$k}:void 0,point2:s.zk?{time:s.zk,price:s.$k}:void 0,point3:n.zk?{time:n.zk,price:n.$k}:void 0,levels:r?.levels,...e})}case"fibFan":return oa(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,levels:r?.levels,...e});case"rectangle":return da(t,{time1:h(0).zk,price1:h(0).$k,time2:h(1).zk,price2:h(1).$k,...e});case"circle":return ma(t,{centerTime:h(0).zk,centerPrice:h(0).$k,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Ma(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Pa(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Ra(t,{time:h(0).zk,price:h(0).$k,text:r?.text,...e});case"ruler":return Oa(t,{point1Time:h(0).zk,point1Price:h(0).$k,point2Time:h(1).zk,point2Price:h(1).$k,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return Ha(t,{entryPrice:h(0).$k,entryTime:h(0).zk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return ja(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.kk&&(clearTimeout(this.kk),this.kk=null),this.Dk.m(),this.Ck.m(),this.clearAll(),this.Hk(),this.lk=[],this.ak=[],this._k=[]}Rk(){this.bx=t=>{this.FC(t)},this.Vf.subscribeClick(this.bx),this.np=t=>{this.IC(t)},this.Vf.subscribeCrosshairMove(this.np);const t=this.Vf.chartElement();t&&(this.mk=t=>this.Nk(t),this.wk=t=>this.Uk(t),this.gk=t=>this.Uk(t),this.bk=t=>this.qk(t),t.addEventListener("pointerdown",this.mk),t.addEventListener("pointerup",this.wk),t.addEventListener("pointercancel",this.gk),t.addEventListener("lostpointercapture",this.bk)),_s&&(this.Mk=t=>this.Uk(t),window.addEventListener("pointerup",this.Mk)),this.Ps.enableKeyboardShortcuts&&(this.vk=t=>{this.jk(t)},document.addEventListener("keydown",this.vk))}Hk(){this.bx&&(this.Vf.unsubscribeClick(this.bx),this.bx=null),this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null);const t=this.Vf.chartElement();t&&(this.mk&&(t.removeEventListener("pointerdown",this.mk),this.mk=null),this.wk&&(t.removeEventListener("pointerup",this.wk),this.wk=null),this.gk&&(t.removeEventListener("pointercancel",this.gk),this.gk=null),this.bk&&(t.removeEventListener("lostpointercapture",this.bk),this.bk=null)),this.Mk&&(window.removeEventListener("pointerup",this.Mk),this.Mk=null),this.vk&&(document.removeEventListener("keydown",this.vk),this.vk=null)}FC(t){if(this.Vk(),!t.point)return;if(this.yk)return void(this.yk=!1);if(this.$C)return;const i=this.Yk(t.hoveredObjectId);i?this.selectTool(i):this.Fk()}IC(t){if(this.Sk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.$C&&this.Pk){const i=this.ck.get(this.Pk);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.Yk(t.hoveredObjectId);if(this.pk&&this.pk!==i){const t=this.ck.get(this.pk);t&&t.setHovered(!1)}if(i){const t=this.ck.get(i);t&&t.setHovered(!0)}this.pk=i}Yk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.ck)if(s.id===i)return t;return null}Nk(t){if(this.$C)return;pl(this.Vf,!1);const i=this.Vf.chartElement();if(!i)return;const s=null!==this.pk&&null!==this.Sk?{Xk:this.pk,Dw:this.Sk}:this.Gk(t);if(null===s)return;const{Xk:n,Dw:e}=s,r=this.ck.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Kk(r,e.ut,e.ct);if(null!==h&&null!==l){pl(this.Vf,!0),this.selectTool(n),this.$C=!0,this.yk=!0,this.Pk=n,this.IS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.IS=null}r.startDrag(h,l),this.Zk()}}Uk(t){if(!this.$C||null===this.Pk)return;if(t&&null!==this.IS&&t.pointerId!==this.IS)return;const i=this.Pk;this.$C=!1,this.Pk=null;try{const t=this.ck.get(i);t&&t.stopDrag()}finally{this.hx(),this.Jk()}this.recordChange()}qk(t){null!==this.IS&&t.pointerId!==this.IS||(this.IS=null,this.Uk())}Ok(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Gk(t){for(const[i,s]of this.ck){if(!s.isVisible()||s.isLocked())continue;const n=this.Ok(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{Xk:i,Dw:r}}return null}hx(){if(null===this.IS)return;const t=this.Vf.chartElement();t&&t.hasPointerCapture(this.IS)&&t.releasePointerCapture(this.IS),this.IS=null}Zk(){if(null!==this.xk)return;const t=this.Vf.options();this.xk={Qk:f(t.handleScroll),tD:f(t.handleScale)},this.Vf.applyOptions({handleScroll:!1,handleScale:!1})}Jk(){const t=this.xk;this.xk=null,null!==t&&this.Vf.applyOptions({handleScroll:t.Qk,handleScale:t.tD})}jk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Vk(),"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const s=t.metaKey||t.ctrlKey;if(s&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}s&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.cancelPendingDrawings(),this.Uk(),this.Fk(),this.stopDrawing(),t.preventDefault())}Kk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Gn(this.Vf,t.series(),i)}}Fk(){this.Ik(null)}}const Xa={...t,color:"#2196f3"};function Ga(){return"2.3.4"}export{Te as AreaSeries,ba as ArrowTool,Fe as BarSeries,xe as BaselineSeries,xa as BrushTool,Le as CandlestickSeries,va as CircleTool,Li as ColorType,Dl as CrossLineTool,U as CrosshairMode,xh as DEFAULT_SESSIONS,Bh as DraggablePriceLine,Ya as DrawingToolsManager,Xl as EXTENDED_FIBONACCI_RATIOS,Gl as FibonacciCalculator,na as FibonacciExtensionTool,aa as FibonacciFanTool,Ql as FibonacciTool,qa as GanttTool,Be as HistogramSeries,Cl as HorizontalLineTool,Wh as InteractiveLineManager,Ii as LastPriceAnimationMode,le as LineSeries,s as LineStyle,i as LineType,xt as MismatchDirection,Bl as ParallelChannelTool,$l as PitchforkTool,Vl as PolygonTool,Fa as PositionCalculator,tl as PositionLine,Ir as PositionMarkersManager,$a as PositionTool,Vi as PriceLineSource,di as PriceScaleMode,ca as RectangleTool,La as RulerCalculator,Ba as RulerTool,Yl as STANDARD_FIBONACCI_RATIOS,Da as TextTool,Ai as TickMarkType,Fi as TrackingModeExitMode,Ch as TradingSessionsIndicator,Ml as TrendLineTool,ql as VerticalLineTool,Dh as VolumeProfileIndicator,wh as applyADX,fh as applyATR,Zr as applyBollingerBands,gh as applyCCI,Qr as applyDonchianChannels,Gr as applyEMA,uh as applyHeikinAshi,lh as applyIchimoku,Jr as applyKeltnerChannels,dh as applyMACD,Mh as applyMFI,mh as applyOBV,th as applyParabolicSAR,ah as applyPivotPoints,ch as applyRSI,Xr as applySMA,ph as applyStochastic,nh as applySuperTrend,sh as applyVWAP,vh as applyVolume,Kr as applyWMA,bh as applyWilliamsR,_h as calculateHeikinAshi,Ia as calculatePipConfig,Kn as coordinateFromTime,Ma as createArrowTool,Pa as createBrushTool,jn as createChart,qn as createChartEx,ma as createCircleTool,Rl as createCrossLineTool,ea as createFibonacciExtensionTool,oa as createFibonacciFanTool,ta as createFibonacciTool,ja as createGanttTool,Pl as createHorizontalLineTool,ir as createImageWatermark,zh as createInteractiveLineManager,me as createOptionsChart,Ol as createParallelChannelTool,Hl as createPitchforkTool,Ll as createPolygonTool,sl as createPositionLine,Vr as createPositionMarkers,Ha as createPositionTool,da as createRectangleTool,Oa as createRulerTool,yr as createSeriesMarkers,Ra as createTextTool,Xe as createTextWatermark,Oh as createTradingLine,Ph as createTradingSessionsIndicator,yl as createTrendLineTool,Fr as createUpDownMarkers,jl as createVerticalLineTool,Rh as createVolumeProfileIndicator,pe as createYieldCurveChart,Xa as customSeriesDefaultOptions,Yn as defaultHorzScaleBehavior,Va as getPipConfig,zr as hideSeriesPaint,Oi as isBusinessDay,Wi as isUTCTimestamp,Er as setSeriesVolumes,Fh as setVolumeProfileData,Gn as timeFromCoordinate,Ga as version};
|