@pipsend/charts 2.3.0 → 2.3.1
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 +201 -14
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +201 -14
- package/dist/pipsend-charts.standalone.development.mjs +201 -14
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +14 -0
- package/package.json +1 -83
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.3.
|
|
3
|
+
* Pipsend Charts v2.3.1
|
|
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
|
-
!function(){"use strict";const t={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var i,s;function n(t,i){const s={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}function e(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(s,i+e),t.lineTo(n,i+e),t.stroke()}function r(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function h(t){if(void 0===t)throw new Error("Value is undefined");return t}function l(t){if(null===t)throw new Error("Value is null");return t}function o(t){return l(h(t))}!function(t){t[t.Simple=0]="Simple",t[t.WithSteps=1]="WithSteps",t[t.Curved=2]="Curved"}(i||(i={})),function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(s||(s={}));class a{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",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,o,a,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(o-e)),M(r+s*(a-r)),(c=h+s*(_-h),c<=0||c>1?Math.min(Math.max(c,0),1):Math.round(1e4*c)/1e4)];var c;return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}G(t){const i=this.j.get(t);if(i)return i;const s=function(t){const i=document.createElement("div");i.style.display="none",document.body.appendChild(i),i.style.color=t;const s=window.getComputedStyle(i).color;return document.body.removeChild(i),s}(t),n=s.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/);if(!n){if(this.Y.length)for(const i of this.Y){const s=i(t);if(s)return this.j.set(t,s),s}throw new Error(`Failed to parse color: ${t}`)}const e=[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10),n[4]?parseFloat(n[4]):1];return this.j.set(t,e),e}}class x{constructor(){this.st=[]}nt(t){this.st=t}et(t,i,s){this.st.forEach(n=>{n.et(t,i,s)})}}class C{et(t,i,s){t.useBitmapCoordinateSpace(t=>this.rt(t,i,s))}}class P extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.ht||null===this.ht.ot)return;const n=this.ht.ot,e=this.ht,r=Math.max(1,Math.floor(i))%2/2,h=h=>{t.beginPath();for(let l=n.to-1;l>=n.from;--l){const n=e._t[l],o=Math.round(n.ut*i)+r,a=n.ct*s,_=h*s+r;t.moveTo(o,a),t.arc(o,a,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.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 o=Math.round(this.Yt.ut*s),a=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,o,0,i.height)),l&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,a,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",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],o=""){if(t.save(),!h||!o||o===r)return L(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const a=h/2;var _;L(t,i+a,s+a,n-h,e-h,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==o&&(t.lineWidth=h,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function 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),o=l.oi;return l.ai?A(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):A(h,o.fi,o.ui,o.ci,o.di,r,o.pi,[0,o.vt,o.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.ai?o.yi-o.pi:0,o.ui,o.pi,o.Si-o.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.ai?"right":"left",t.textBaseline="middle",t.fillStyle=e,t.fillText(this.Yt.hi,s.Ci,(s.ui+s.Si)/2+s.Pi)})}li(t,i,s,n){const{context:e,bitmapSize:r,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.A+this.ri.Di,c=i.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+a,M=Math.max(1,Math.floor(o));let y=Math.round(g*o);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(a*l),P=this.ri.Vi??this.ri.Li,T=Math.round(P*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,I=R?r.width-S:S;let V,L,A;return R?(V=I-x,L=I-C,A=F-a-d-_):(V=I+x,L=I+C,A=F+a+d),{ai:R,oi:{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/o,Si:D/o,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 o=this.Yt.Li,a=Math.floor(o-r)+.5;a<0?(o+=Math.abs(0-a),a=Math.floor(o-r)+.5):a+e>h&&(o-=Math.abs(h-(a+e)),a=Math.floor(o-r)+.5);const _=a+e,u=Math.ceil(0+i.S+i.C+i.A+i.P+i.I);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(a*s),h=Math.round(0*n),o=Math.round(_*s),c=Math.round(u*n),d=Math.round(2*s);if(t.beginPath(),t.moveTo(r,h),t.lineTo(r,c-d),t.arcTo(r,c,r+d,c,d),t.lineTo(o-d,c),t.arcTo(o,c,o,c-d,d),t.lineTo(o,h),t.fill(),e.mi){const r=Math.round(e.Li*s),l=h,o=Math.round((l+i.C)*n);t.fillStyle=e.R;const a=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,a,o-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.A+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(a+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={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,o=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.At().jt(t),this.Pt=s;const a=null!==o?o.Bt():null;return null!==o&&null!==a?(this.ps=i,this.Ss=o.zt(i,a)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||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 o=Math.max(2,1.5*n.he)*i;t.arc(h,l,o,0,2*Math.PI,!1),t.fill(),t.fillStyle=n.le,t.beginPath(),t.arc(h,l,n.vt*i,0,2*Math.PI,!1),t.fill(),t.lineWidth=e,t.strokeStyle=n.oe,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const ot=[{ae:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{ae:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{ae:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class at{constructor(t){this.Jt=new lt,this.xt=!0,this.me=!0,this.we=performance.now(),this.ge=this.we-1,this.be=t}Me(){this.ge=this.we-1,this.Tt()}ye(){if(this.Tt(),2===this.be.W().lastPriceAnimation){const t=performance.now(),i=this.ge-t;if(i>0)return void(i<650&&(this.ge+=2600));this.we=t,this.ge=t+2600}}Tt(){this.xt=!0}Se(){this.me=!0}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,oe:l.oe,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.oe=i.oe,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 ot)if(s>=t.ae&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.ae)/(n._e-n.ae);return{le:this.Ve(i,e,n.de,n.pe),oe:this.Ve(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,o=n.ce,l+(o-l)*h)};var h,l,o}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.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,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Ee(o,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Be(o,r,h,l),i.It=i.hi.length>0);const a=n.Le(o.R),_=this.Qt.ti().Ki().K(a);s.Z=_.Z,s.Li=o.Li,i.Nt=n.ti().Ut(o.Li/n.$t().qt()),t.Nt=a,t.R=_.J,i.R=_.J}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 o=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.R=a,i.R=a,s.Li=l}er(t){const i=this.be.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)),a=o(h.Ht[0])<=o(h.Ht[3]);return{dr:h.R??(a?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,a=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=o(c.Ht[0])<=o(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:a),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Ir=[],this.Vr=new Map,this.Lr=new Map,this.Ar=[]}Er(){return this.Br()>0?this.Ir[this.Ir.length-1]:null}Or(){return this.Br()>0?this.Wr(0):null}Gs(){return this.Br()>0?this.Wr(this.Ir.length-1):null}Br(){return this.Ir.length}Gi(){return 0===this.Br()}De(t){return null!==this.zr(t,0)}kr(t){return this.$r(t)}$r(t,i=0){const s=this.zr(t,i);return null===s?null:{...this.Hr(s),Re:this.Wr(s)}}Nr(){return this.Ir}Ur(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.qr(t,i,e))}return n}lt(t){this.Lr.clear(),this.Vr.clear(),this.Ir=t,this.Ar=t.map(t=>t.Re)}jr(){return this.Ar}Wr(t){return this.Ir[t].Re}Hr(t){return this.Ir[t]}zr(t,i){const s=this.Yr(t);if(null===s&&0!==i)switch(i){case-1:return this.Xr(t);case 1:return this.Gr(t);default:throw new TypeError("Unknown search mode")}return s}Xr(t){let i=this.Kr(t);return i>0&&(i-=1),i!==this.Ir.length&&this.Wr(i)<t?i:null}Gr(t){const i=this.Zr(t);return i!==this.Ir.length&&t<this.Wr(i)?i:null}Yr(t){const i=this.Kr(t);return i===this.Ir.length||t<this.Ir[i].Re?null:i}Kr(t){return yt(this.Ir,t,(t,i)=>t.Re<i)}Zr(t){return St(this.Ir,t,(t,i)=>t.Re>i)}Jr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Ir[e].Ht[s];Number.isNaN(t)||(null===n?n={Qr:t,th:t}:(t<n.Qr&&(n.Qr=t),t>n.th&&(n.th=t)))}return n}qr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Or()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Kr(h),e=this.Zr(Math.min(o,a,i));n=Tt(n,this.Jr(t,e,s))}let u=this.Vr.get(s);void 0===u&&(u=new Map,this.Vr.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Kr(i*Ct),n=this.Zr((i+1)*Ct-1);e=this.Jr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Kr(_),i=this.Zr(o);n=Tt(n,this.Jr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{Qr:Math.min(t.Qr,i.Qr),th:Math.max(t.th,i.th)}}const kt={setLineStyle:n};class Dt{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Fn?.eh===t)return this.Fn.rh;const i=new Dt(t);return this.Fn={eh:t,rh:i},i}hh(){return this.nh.zOrder?.()??"normal"}}class Ft{constructor(t){this.oh=null,this.ah=t}_h(){return this.ah}zs(){this.ah.updateAllViews?.()}$s(){const t=this.ah.paneViews?.()??[];if(this.oh?.eh===t)return this.oh.rh;const i=t.map(t=>new Rt(t));return this.oh={eh:t,rh:i},i}Xn(t,i){return this.ah.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Fn?.eh===t)return this.Fn.rh;const i=new Vt(t);return this.Fn={eh:t,rh:i},i}hh(){return this.nh.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.uh=t,this.dh=i}Dt(){return this.Jt.lt({ts:this.dh.ts(),...At(this.uh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.uh=t,this.Yi=i}ji(t,i,s){const n=At(this.uh);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.ph=null,this.fh=null,this.mh=null,this.wh=null,this.be=i}ds(){const t=this.ah.timeAxisViews?.()??[];if(this.ph?.eh===t)return this.ph.rh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.ph={eh:t,rh:s},s}Hs(){const t=this.ah.priceAxisViews?.()??[];if(this.fh?.eh===t)return this.fh.rh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.fh={eh:t,rh:s},s}gh(){const t=this.ah.priceAxisPaneViews?.()??[];if(this.mh?.eh===t)return this.mh.rh;const i=t.map(t=>new Lt(t));return this.mh={eh:t,rh:i},i}bh(){const t=this.ah.timeAxisPaneViews?.()??[];if(this.wh?.eh===t)return this.wh.rh;const i=t.map(t=>new Lt(t));return this.wh={eh:t,rh:i},i}Mh(t,i){return this.ah.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.hh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.gh()}function Ht(t){return t.bh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.yh=[],this.Sh=new ht(this),this.xh=null,this.Ch=null,this.Ph=null,this.Th=[],this.Ps=s,this.kh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.kh)&&(this.xh=new at(this)),this.Dh(),this.nh=n(this,this.ti(),e)}m(){null!==this.Ph&&clearTimeout(this.Ph)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().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.Er();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.$r(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Rh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Fh(l),ze:s.Ih(l,e.Ht),R:o.dr,Li:a,Re:h}}Rh(){return null!==this.Ch||(this.Ch=new bt(this)),this.Ch}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Vh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Dh(),this.ti().Lh()),this.ti().Ah(this),this.ti().Eh(),this.nh.Tt("options")}lt(t,i){this.Yt.lt(t),this.nh.Tt("data"),null!==this.xh&&(i&&i.Bh?this.xh.ye():0===t.length&&this.xh.Me());const s=this.ti().Nn(this);this.ti().Oh(s),this.ti().Ah(this),this.ti().Eh(),this.ti().ar()}Wh(t){const i=new mt(this,t);return this.yh.push(i),this.ti().Ah(this),i}zh(t){const i=this.yh.indexOf(t);-1!==i&&this.yh.splice(i,1),this.ti().Ah(this)}$h(){return this.yh}Rr(){return this.kh}Bt(){const t=this.Hh();return null===t?null:{Ht:t.Ht[3],Nh:t.gt}}Hh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.Uh();return this.Yt.$r(i,1)}Ks(){return this.Yt}qh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.kh||"Candlestick"===this.kh||"Custom"===this.kh?{jh:i.Ht[0],Yh:i.Ht[1],Xh:i.Ht[2],Gh:i.Ht[3]}:i.Ht[3]}Kh(t){const i=[];Wt(this.Th,zt,"top",i);const s=this.xh;return null!==s&&s.It()?(null===this.Ph&&s.xe()&&(this.Ph=setTimeout(()=>{this.Ph=null,this.ti().Zh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Jh()||t.push(this.Sh),t.push(this.nh,this.rr);const i=this.yh.map(t=>t._r());return t.push(...i),Wt(this.Th,zt,"normal",t),t}Qh(){return this.tl(zt,"bottom")}il(t){return this.tl($t,t)}sl(t){return this.tl(Ht,t)}nl(t,i){return this.Th.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.yh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Jh())return[];const s=[...this.ws];for(const t of this.yh)s.push(t.cr());return this.Th.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.Th.forEach(i=>{t.push(...i.ds())}),t}Mh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.el(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.el(t,i)}eh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}rl(){return this.hl}zs(){this.nh.Tt();for(const t of this.ws)t.Tt();for(const t of this.yh)t.Tt();this.rr.Tt(),this.Sh.Tt(),this.xh?.Tt(),this.Th.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ll(),Nt:this.ol(),Wt:this.al(),Ot:this._l(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}ul(t){this.Th.push(new Ot(t,this))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t)}dl(){if("Custom"===this.kh)return t=>this.nh.pl(t)}fl(){if("Custom"===this.kh)return t=>this.nh.vl(t)}ml(){return this.Yt.jr()}Jh(){return!j(this.$t().wl())}el(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh||"Histogram"===this.kh?[3]:[2,1],n=this.Yt.Ur(t,i,s);let e=null!==n?new dt(n.Qr,n.th):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.Th.forEach(s=>{const n=s.Mh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ll(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}ol(){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}al(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}_l(t){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Rh().Fr(t).dr}Dh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.hl={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.hl=new Q(this.Ps.priceFormat.precision);break;case"percent":this.hl=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.hl=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.gl()}tl(t,i){const s=[];return Wt(this.Th,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}bl(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.Ml().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.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=o(n.Bt()),a=3===this.Ps.mode?jt:qt;return t.concat(a.map(t=>e.zt(h.Ht[t],l.Ht)))},[]);if(0===l.length)return n;l.sort((t,i)=>Math.abs(t-h)-Math.abs(i-h));const a=l[0];return n=e.Ds(a,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.yl){t.strokeStyle=h.Sl,n(t,h.xl),t.beginPath();for(const n of h.Cl){const e=Math.round(n.Pl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.Tl){t.strokeStyle=h.kl,n(t,h.Dl),t.beginPath();for(const s of h.Rl){const n=Math.round(s.Pl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={Tl:t.horzLines.visible,yl:t.vertLines.visible,kl:t.horzLines.color,Sl:t.vertLines.color,Dl:t.horzLines.style,xl:t.vertLines.style,Rl:this.Pt.ks().Fl(),Cl:(this.Pt.ti().At().Fl()||[]).map(t=>({Pl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.nh=new Jt(t)}_r(){return this.nh}}const ti={Il:4,Vl: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.Vl)+i.Il;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Il)-i.Vl;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.je(),i);return new dt(s,n)}function ai(t){if(null===t)return ti;const i=Math.abs(t.je()-t.qe());if(i>=1||i<1e-15)return ti;const s=Math.ceil(Math.abs(Math.log10(i))),n=ti.Il+s;return{Il:n,Vl:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Ll=t,this.Al=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Ll))this.El=[2,2.5,2];else{this.El=[];for(let t=this.Ll;1!==t;){if(t%2==0)this.El.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.El.push(2,2.5),t/=5}if(this.El.length>100)throw new Error("something wrong with base")}}}Bl(t,i,s){const n=0===this.Ll?0:1/this.Ll;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.Al[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.Al[++r%this.Al.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.El.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.El[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.El[++r%this.El.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Ol=[],this.Yi=t,this.Ll=i,this.Wl=s,this.zl=n}Bl(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.$l()/s,e=new _i(this.Ll,[2,2.5,2]),r=new _i(this.Ll,[2,2,2.5]),h=new _i(this.Ll,[2.5,2,2]),l=[];return l.push(e.Bl(t,i,n),r.Bl(t,i,n),h.Bl(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Hl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Ol=[]);const s=t.qt(),n=this.Wl(s-1,i),e=this.Wl(0,i),r=this.Yi.W().entireTextOnly?this.Nl()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Ol=[]);const _=this.Bl(o,a);if(this.Ul(i,_,o,a,h,l),t.ql()&&this.jl(_,a,o)){const t=this.Yi.Yl();this.Xl(i,_,h,l,t,2*t)}const u=this.Ol.map(t=>t.Gl),c=this.Yi.Kl(u);for(let t=0;t<this.Ol.length;t++)this.Ol[t].Zl=c[t]}Fl(){return this.Ol}Nl(){return this.Yi.P()}$l(){return Math.ceil(2.5*this.Nl())}Ul(t,i,s,n,e,r){const h=this.Ol,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.zl(c,t,!0);null!==_&&Math.abs(s-_)<this.$l()||(s<e||s>r||(u<h.length?(h[u].Pl=s,h[u].Zl=l.Jl(c),h[u].Gl=c):h.push({Pl:s,Zl:l.Jl(c),Gl:c}),u++,_=s,l.Ql()&&(i=this.Bl(c*a,n))))}h.length=u}Xl(t,i,s,n,e,r){const h=this.Ol,l=this.io(t,s,e,r),o=this.io(t,n,-r,-e),a=this.zl(0,t,!0)-this.zl(i,t,!0);h.length>0&&h[0].Pl-l.Pl<a/2&&h.shift(),h.length>0&&o.Pl-h[h.length-1].Pl<a/2&&h.pop(),h.unshift(l),h.push(o)}io(t,i,s,n){const e=(s+n)/2,r=this.Wl(i+s,t),h=this.Wl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.Bl(o,l)),_=this.Wl(i+e,t),u=_-_%a,c=this.zl(u,t,!0);return{Zl:this.Yi.Jl(u),Pl:c,Gl:u}}jl(t,i,s){let n=o(this.Yi.tr());return this.Yi.Ql()&&(n=oi(n,this.Yi.so())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.no=0,this.eo=null,this.Je=null,this.ro=null,this.ho={lo:!1,oo:null},this.ao=!1,this._o=0,this.uo=0,this.co=new a,this.do=new a,this.po=[],this.fo=null,this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.hl=fi,this.Mo=ai(null),this.yo=t,this.Ps=i,this.So=s,this.xo=n,this.Co=e,this.Po=new ui(this,100,this.To.bind(this),this.ko.bind(this))}wl(){return this.yo}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.gl(),void 0!==t.mode&&this.Do({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Ro(),this.mo=null}}Fo(){return this.Ps.autoScale}Io(){return this.ao}Ql(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Vo(){return 3===this.Ps.mode}so(){return this.Mo}se(){return{nn:this.Ps.autoScale,Lo:this.Ps.invertScale,se:this.Ps.mode}}Do(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.ho.lo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.Mo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.Mo),null!==s&&this.Ao(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.Mo),null!==s&&this.Ao(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.gl(),n&&(3===i.se||this.Vo())&&this.gl(),void 0!==t.Lo&&i.Lo!==t.Lo&&(this.Ps.invertScale=t.Lo,this.Eo()),this.do.p(i,this.se())}Bo(){return this.do}P(){return this.So.fontSize}qt(){return this.no}Oo(t){this.no!==t&&(this.no=t,this.Ro(),this.mo=null)}Wo(){if(this.eo)return this.eo;const t=this.qt()-this.zo()-this.$o();return this.eo=t,t}tr(){return this.Ho(),this.Je}Ao(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.mo=null,this.Je=t)}No(t){this.Ao(t),this.Uo(null!==t)}Gi(){return this.Ho(),0===this.no||!this.Je||this.Je.Gi()}qo(t){return this.Lo()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Vo()&&(t=ni(t,i)),this.ko(t,i)}jo(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.no-1-o;e.ct=u}}Xo(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s];let h=e.jh,l=e.Yh,o=e.Xh,u=e.Gh;null!==d&&(h=d(e.jh,i),l=d(e.Yh,i),o=d(e.Xh,i),u=d(e.Gh,i));let c=n+_*(h-r),p=a?c:this.no-1-c;e.Go=p,c=n+_*(l-r),p=a?c:this.no-1-c,e.Ko=p,c=n+_*(o-r),p=a?c:this.no-1-c,e.Zo=p,c=n+_*(u-r),p=a?c:this.no-1-c,e.Jo=p}}Ds(t,i){const s=this.To(t,i);return this.Qo(s,i)}Qo(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Vo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}Ml(){return this.po}Ft(){return this.vo||(this.vo=ci(this.po)),this.vo}ta(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.gl(),this.ia())}sa(t){const i=this.po.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.po.splice(i,1),0===this.po.length&&(this.Do({nn:!0}),this.Ao(null)),this.gl(),this.ia()}Bt(){let t=null;for(const i of this.po){const s=i.Bt();null!==s&&((null===t||s.Nh<t.Nh)&&(t=s))}return null===t?null:t.Ht}Lo(){return this.Ps.invertScale}Fl(){const t=null===this.Bt();if(null!==this.mo&&(t||this.mo.na===t))return this.mo.Fl;this.Po.Hl();const i=this.Po.Fl();return this.mo={Fl:i,na:t},this.co.p(),i}ea(){return this.co}ra(t){this.Oe()||this.Vo()||null===this.wo&&null===this.ro&&(this.Gi()||(this.wo=this.no-t,this.ro=l(this.tr()).Ue()))}ha(t){if(this.Oe()||this.Vo())return;if(null===this.wo)return;this.Do({nn:!1}),(t=this.no-t)<0&&(t=0);let i=(this.wo+.2*(this.no-1))/(t+.2*(this.no-1));const s=l(this.ro).Ue();i=Math.max(i,.1),s.Xe(i),this.Ao(s)}la(){this.Oe()||this.Vo()||(this.wo=null,this.ro=null)}oa(t){this.Fo()||null===this.bo&&null===this.ro&&(this.Gi()||(this.bo=t,this.ro=l(this.tr()).Ue()))}aa(t){if(this.Fo())return;if(null===this.bo)return;const i=l(this.tr()).Ye()/(this.Wo()-1);let s=t-this.bo;this.Lo()&&(s*=-1);const n=s*i,e=l(this.ro).Ue();e.Ge(n),this.Ao(e,!0),this.mo=null}_a(){this.Fo()||null!==this.bo&&(this.bo=null,this.ro=null)}rl(){return this.hl||this.gl(),this.hl}Zi(t,i){switch(this.Ps.mode){case 2:return this.ua(ii(t,i));case 3:return this.rl().format(ni(t,i));default:return this.er(t)}}Jl(t){switch(this.Ps.mode){case 2:return this.ua(t);case 3:return this.rl().format(t);default:return this.er(t)}}Kl(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.rl().formatTickmarks(t);default:return this.da(t)}}Fh(t){return this.er(t,l(this.fo).rl())}Ih(t,i){return t=ii(t,i),this.ua(t,pi)}pa(){return this.po}fa(t){this.ho={oo:t,lo:!1}}zs(){this.po.forEach(t=>t.zs())}ql(){return this.Ps.ensureEdgeTickMarksVisible&&this.Fo()}Yl(){return this.P()/2}gl(){this.mo=null;let t=1/0;this.fo=null;for(const i of this.po)i.ls()<t&&(t=i.ls(),this.fo=i);let i=100;null!==this.fo&&(i=Math.round(this.fo.eh())),this.hl=fi,this.Oe()?(this.hl=pi,i=100):this.Vo()?(this.hl=new Z(100,1),i=100):null!==this.fo&&(this.hl=this.fo.rl()),this.Po=new ui(this,i,this.To.bind(this),this.ko.bind(this)),this.Po.Hl()}ia(){this.vo=null}va(){return null===this.fo||this.Oe()||this.Vo()?1:1/this.fo.eh()}Ki(){return this.Co}Uo(t){this.ao=t}zo(){return this.Lo()?this.Ps.scaleMargins.bottom*this.qt()+this.uo:this.Ps.scaleMargins.top*this.qt()+this._o}$o(){return this.Lo()?this.Ps.scaleMargins.top*this.qt()+this._o:this.Ps.scaleMargins.bottom*this.qt()+this.uo}Ho(){this.ho.lo||(this.ho.lo=!0,this.ma())}Ro(){this.eo=null}ko(t,i){if(this.Ho(),this.Gi())return 0;t=this.Ql()&&t?ri(t,this.Mo):t;const s=l(this.tr()),n=this.$o()+(this.Wo()-1)*(t-s.qe())/s.Ye();return this.qo(n)}To(t,i){if(this.Ho(),this.Gi())return 0;const s=this.qo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.$o())/(this.Wo()-1));return this.Ql()?hi(e,this.Mo):e}Eo(){this.mo=null,this.Po.Hl()}ma(){if(this.Io()&&!this.Fo())return;const t=this.ho.oo;if(null===t)return;let i=null;const s=this.pa();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.Mh(t.Uh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.Mo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.ql()&&(n=Math.max(n,this.Yl()),e=Math.max(e,this.Yl())),n===this._o&&e===this.uo||(this._o=n,this.uo=e,this.mo=null,this.Ro()),null!==i){if(i.qe()===i.je()){const t=5*this.va();this.Ql()&&(i=oi(i,this.Mo)),i=new dt(i.qe()-t,i.je()+t),this.Ql()&&(i=li(i,this.Mo))}if(this.Ql()){const t=oi(i,this.Mo),s=ai(t);if(r=s,h=this.Mo,r.Il!==h.Il||r.Vl!==h.Vl){const n=null!==this.ro?oi(this.ro,this.Mo):null;this.Mo=s,i=li(t,s),null!==n&&(this.ro=li(n,s))}}this.Ao(i)}else null===this.Je&&(this.Ao(new dt(-.5,.5)),this.Mo=ai(null));var r,h}Yo(){return this.Oe()?ii:this.Vo()?ni:this.Ql()?t=>ri(t,this.Mo):null}wa(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.format(t)):i(t)}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.wa(t,this.xo.priceFormatter,i)}da(t,i){const s=this.xo.priceFormatter;return this.ga(t,this.xo.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ua(t,i){return this.wa(t,this.xo.percentageFormatter,i)}ca(t,i){const s=this.xo.percentageFormatter;return this.ga(t,this.xo.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.po=[],this.ba=new Map,this.no=0,this.Ma=0,this.ya=1,this.vo=null,this.Sa=!1,this.xa=new a,this.Th=[],this.dh=t,this.ss=i,this.Ca=new Qt(this);const s=i.W();this.Pa=this.Ta("left",s.leftPriceScale),this.ka=this.Ta("right",s.rightPriceScale),this.Pa.Bo().i(this.Da.bind(this,this.Pa),this),this.ka.Bo().i(this.Da.bind(this,this.ka),this),this.Ra(s)}Ra(t){if(t.leftPriceScale&&this.Pa.lr(t.leftPriceScale),t.rightPriceScale&&this.ka.lr(t.rightPriceScale),t.localization&&(this.Pa.gl(),this.ka.gl()),t.overlayPriceScales){const i=Array.from(this.ba.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.gl()}}}Fa(t){switch(t){case"left":return this.Pa;case"right":return this.ka}return this.ba.has(t)?h(this.ba.get(t))[0].$t():null}m(){this.ti().Ia().u(this),this.Pa.Bo().u(this),this.ka.Bo().u(this),this.po.forEach(t=>{t.m&&t.m()}),this.Th=this.Th.filter(t=>{const i=t._h();return i.detached&&i.detached(),!1}),this.xa.p()}Va(){return this.ya}La(t){this.ya=t}ti(){return this.ss}ts(){return this.Ma}qt(){return this.no}Aa(t){this.Ma=t,this.Ea()}Oo(t){this.no=t,this.Pa.Oo(t),this.ka.Oo(t),this.po.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Oo(t)}}),this.Ea()}Ba(t){this.Sa=t}Oa(){return this.Sa}Wa(){return this.po.filter(mi)}Ml(){return this.po}Un(t){const i=t.$t();return null===i||this.Pa!==i&&this.ka!==i}ta(t,i,s){this.za(t,i,s?t.ls():this.po.length)}sa(t,i){const s=this.po.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.po.splice(s,1),i||this.po.forEach((t,i)=>t._s(i));const n=l(t.$t()).wl();if(this.ba.has(n)){const i=h(this.ba.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.ba.delete(n))}const e=t.$t();e&&e.Ml().indexOf(t)>=0&&(e.sa(t),this.$a(e)),this.vo=null}jn(t){return t===this.Pa?"left":t===this.ka?"right":"overlay"}Ha(){return this.Pa}Na(){return this.ka}Ua(t,i){t.ra(i)}qa(t,i){t.ha(i),this.Ea()}ja(t){t.la()}Ya(t,i){t.oa(i)}Xa(t,i){t.aa(i),this.Ea()}Ga(t){t._a()}Ea(){this.po.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.ka.Ml().length?t=this.ka:this.ss.W().leftPriceScale.visible&&0!==this.Pa.Ml().length?t=this.Pa:0!==this.po.length&&(t=this.po[0].$t()),null===t&&(t=this.ka),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.ka:this.ss.W().leftPriceScale.visible&&(t=this.Pa),t}$a(t){null!==t&&t.Fo()&&this.Ka(t)}Za(t){const i=this.dh.Pe();t.Do({nn:!0}),null!==i&&t.fa(i),this.Ea()}Ja(){this.Ka(this.Pa),this.Ka(this.ka)}Qa(){this.$a(this.Pa),this.$a(this.ka),this.po.forEach(t=>{this.Un(t)&&this.$a(t.$t())}),this.Ea(),this.ss.ar()}Ft(){return null===this.vo&&(this.vo=ci(this.po)),this.vo}t_(t,i){i=Xt(i,0,this.po.length-1);const s=this.po.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.po.splice(s,1),this.po.splice(i,0,t),this.po.forEach((t,i)=>t._s(i)),this.vo=null;for(const t of[this.Pa,this.ka])t.ia(),t.gl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}i_(){return this.xa}s_(){return this.Ca}ul(t){this.Th.push(new It(t))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t),t.detached&&t.detached(),this.ss.ar()}n_(){return this.Th}nl(t,i){return this.Th.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Ka(t){const i=t.pa();if(i&&i.length>0&&!this.dh.Gi()){const i=this.dh.Pe();null!==i&&t.fa(i)}t.zs()}za(t,i,s){let n=this.Fa(i);if(null===n&&(n=this.Ta(i,this.ss.W().overlayPriceScales)),this.po.splice(s,0,t),!j(i)){const s=this.ba.get(i)||[];s.push(t),this.ba.set(i,s)}t._s(s),n.ta(t),t.us(n),this.$a(n),this.vo=null}Da(t,i,s){i.se!==s.se&&this.Ka(t)}Ta(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Oo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{e_:t.e_,r_:{Gn:t.h_.externalId},l_:t.h_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{o_:e,r_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.nl?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{h_:n,e_:e}:null}(n,i,s);if("top"===e?.h_.zOrder)return bi(e);for(const r of n){if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&!e.h_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{e_:r,o_:n.o_,r_:n.r_}}if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&e.h_.isBackground)return bi(e)}return e?.h_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.a_=t,this.__=i,this.In=s}u_(t){const i=t.time,s=this.__.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.c_;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.a_(t);return this.Fn.set(s,{c_: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.d_=t,this.p_=i}Uh(){return this.d_}yi(){return this.p_}f_(){return this.p_-this.d_+1}De(t){return this.d_<=t&&t<=this.p_}Ne(t){return this.d_===t.Uh()&&this.p_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.v_=new Map,this.Fn=null,this.m_=!1}w_(t){this.m_=t,this.Fn=null}g_(t,i){this.b_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.v_.get(i.timeWeight);void 0===n&&(n=[],this.v_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}M_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Fn&&this.Fn.y_===r&&e===this.Fn.S_&&s===this.Fn.x_||(this.Fn={S_:e,x_:s,Fl:this.C_(r,s,n),y_:r}),this.Fn.Fl}b_(t){if(0===t)return void this.v_.clear();const i=[];this.v_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.v_.delete(t)}C_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.v_.keys()).sort((t,i)=>i-t)){if(!this.v_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const o=h(this.v_.get(i)),a=o.length;let _=1/0,u=-1/0;for(let i=0;i<a;i++){const h=o[i],a=h.index;for(;l<r;){const t=s[l],i=t.index;if(!(i<a&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-a>=t&&a-u>=t&&e(h))n.push(h),u=a;else if(this.m_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.P_=t}T_(){return null===this.P_?null:new Ci(Math.floor(this.P_.Uh()),Math.ceil(this.P_.yi()))}k_(){return this.P_}static D_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.Ma=0,this.R_=null,this.F_=[],this.bo=null,this.wo=null,this.I_=new Ti,this.V_=new Map,this.L_=ki.D_(),this.A_=!0,this.E_=new a,this.B_=new a,this.O_=new a,this.W_=null,this.z_=null,this.H_=new Map,this.N_=-1,this.U_=[],this.Ps=i,this.xo=s,this.q_=i.rightOffset,this.j_=i.barSpacing,this.ss=t,this.Y_(i),this.__=n,this.X_(),this.I_.w_(i.uniformDistribution),this.G_()}W(){return this.Ps}K_(t){_(this.xo,t),this.Z_(),this.X_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.J_(),this.Ps.fixRightEdge&&this.Q_(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.Y_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.j_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.G_(),this.Z_(),this.X_(),this.O_.p()}Rs(t){return this.F_[t]?.time??null}ns(t){return this.F_[t]??null}tu(t,i){if(this.F_.length<1)return null;if(this.__.key(t)>this.__.key(this.F_[this.F_.length-1].time))return i?this.F_.length-1:null;const s=yt(this.F_,this.__.key(t),(t,i)=>this.__.key(t.time)<i);return this.__.key(t)<this.__.key(this.F_[s].time)?i?s:null:s}Gi(){return 0===this.Ma||0===this.F_.length||null===this.R_}iu(){return this.F_.length>0}Pe(){return this.su(),this.L_.T_()}nu(){return this.su(),this.L_.k_()}eu(){const t=this.Pe();if(null===t)return null;const i={from:t.Uh(),to:t.yi()};return this.ru(i)}ru(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.hu()),e=l(this.lu());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.tu(t.from,!0)),to:l(this.tu(t.to,!0))}}ts(){return this.Ma}Aa(t){if(!isFinite(t)||t<=0)return;if(this.Ma===t)return;const i=this.nu(),s=this.Ma;if(this.Ma=t,this.A_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.j_*t/s;this.j_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.Uh()<=0){const i=s-t;this.q_-=Math.round(i/this.j_)+1,this.A_=!0}this.au(),this._u()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.uu()+this.q_-t;return this.Ma-(i+.5)*this.j_-1}cu(t,i){const s=this.uu(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.q_-n,r=this.Ma-(e+.5)*this.j_-1;t[i].ut=r}}du(t,i){const s=Math.ceil(this.pu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.fu(s)?this.vu(s):s}fn(t){this.A_=!0,this.q_=t,this._u(),this.ss.mu(),this.ss.ar()}wu(){return this.j_}pn(t){const i=this.j_;if(this.gu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.q_*i/this.j_;this.q_=t}this._u(),this.ss.mu(),this.ss.ar()}bu(){return this.q_}Fl(){if(this.Gi())return null;if(null!==this.z_)return this.z_;const t=this.j_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.Uh(),n.Uh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.I_.M_(t,i,this.Ps.ignoreWhitespaceIndices,this.H_,this.N_),o=this.hu()+s,a=this.lu()-s,_=this.Mu(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.U_.length?(s=this.U_[d],s.coord=this.jt(t.index),s.label=this.yu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.yu(t),weight:t.weight},this.U_.push(s)),this.j_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.U_.length=d,this.z_=this.U_,this.U_}Su(){let t;this.A_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.wu():this.Ps.rightOffset,this.fn(t)}xu(t){this.A_=!0,this.R_=t,this._u(),this.J_()}Cu(t,i){const s=this.pu(t),n=this.wu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.bu()+(s-this.pu(t)))}ra(t){this.bo&&this._a(),null===this.wo&&null===this.W_&&(this.Gi()||(this.wo=t,this.Pu()))}ha(t){if(null===this.W_)return;const i=Xt(this.Ma-t,0,this.Ma),s=Xt(this.Ma-l(this.wo),0,this.Ma);0!==i&&0!==s&&this.pn(this.W_.wu*i/s)}la(){null!==this.wo&&(this.wo=null,this.Tu())}oa(t){null===this.bo&&null===this.W_&&(this.Gi()||(this.bo=t,this.Pu()))}aa(t){if(null===this.bo)return;const i=(this.bo-t)/this.wu();this.q_=l(this.W_).bu+i,this.A_=!0,this._u()}_a(){null!==this.bo&&(this.bo=null,this.Tu())}ku(){this.Du(this.Ps.rightOffset)}Du(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.q_,n=performance.now();this.ss.un({Ru:t=>(t-n)/i>=1,Fu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.A_=!0,this.F_=t,this.I_.g_(t,i),this._u()}Iu(){return this.E_}Vu(){return this.B_}Lu(){return this.O_}uu(){return this.R_||0}Au(t,i){const s=t.f_(),n=i&&this.Ps.rightOffsetPixels||0;this.gu((this.Ma-n)/s),this.q_=t.yi()-this.uu(),i&&(this.q_=n?n/this.wu():this.Ps.rightOffset),this._u(),this.A_=!0,this.ss.mu(),this.ss.ar()}Eu(){const t=this.hu(),i=this.lu();null!==t&&null!==i&&this.Au(new Ci(t,i),!0)}Bu(t){const i=new Ci(t.from,t.to);this.Au(i)}es(t){return void 0!==this.xo.timeFormatter?this.xo.timeFormatter(t.originalTime):this.__.formatHorzItem(t.time)}G_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.H_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.ml())this.H_.set(t,!0);this.N_++}Mu(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}hu(){return 0===this.F_.length?null:0}lu(){return 0===this.F_.length?null:this.F_.length-1}Ou(t){return(this.Ma-1-t)/this.j_}pu(t){const i=this.Ou(t),s=this.uu()+this.q_-i;return Math.round(1e6*s)/1e6}gu(t){const i=this.j_;this.j_=t,this.au(),i!==this.j_&&(this.A_=!0,this.Wu())}su(){if(!this.A_)return;if(this.A_=!1,this.Gi())return void this.zu(ki.D_());const t=this.uu(),i=this.Ma/this.j_,s=this.q_+t,n=new Ci(s-i+1,s);this.zu(new ki(n))}au(){const t=Xt(this.j_,this.$u(),this.Hu());this.j_!==t&&(this.j_=t,this.A_=!0)}Hu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.Ma}$u(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.F_.length?this.Ma/this.F_.length:this.Ps.minBarSpacing}_u(){const t=this.Nu();null!==t&&this.q_<t&&(this.q_=t,this.A_=!0);const i=this.Uu();this.q_>i&&(this.q_=i,this.A_=!0)}Nu(){const t=this.hu(),i=this.R_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.Ma/this.j_:Math.min(2,this.F_.length))}Uu(){return this.Ps.fixRightEdge?0:this.Ma/this.j_-Math.min(2,this.F_.length)}Pu(){this.W_={wu:this.wu(),bu:this.bu()}}Tu(){this.W_=null}yu(t){let i=this.V_.get(t.weight);return void 0===i&&(i=new xi(t=>this.qu(t),this.__),this.V_.set(t.weight,i)),i.u_(t)}qu(t){return this.__.formatTickmark(t,this.xo)}zu(t){const i=this.L_;this.L_=t,Pi(i.T_(),this.L_.T_())||this.E_.p(),Pi(i.k_(),this.L_.k_())||this.B_.p(),this.Wu()}Wu(){this.z_=null}Z_(){this.Wu(),this.V_.clear()}X_(){this.__.updateFormatter(this.xo)}J_(){if(!this.Ps.fixLeftEdge)return;const t=this.hu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.Uh()-t;if(s<0){const t=this.q_-s-1;this.fn(t)}this.au()}Q_(){this._u(),this.au()}fu(t){return!this.Ps.ignoreWhitespaceIndices||(this.H_.get(t)||!1)}vu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.lu();for(;s;){const t=i.next().value;if(this.H_.get(t))return t;if(t<0||t>s)break}return t}Y_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.j_);this.ss.fn(i)}}}var 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.ju=[],this.Yu=[],this.Ma=0,this.Xu=null,this.Gu=new a,this.Ku=new a,this.Zu=null,this.Ju=t,this.Ps=i,this.__=s,this.Co=new S(this.Ps.layout.colorParsers),this.Qu=new b(this),this.dh=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.tc=new Yt(i.crosshair),i.addDefaultPane&&(this.sc(0),this.ju[0].La(2)),this.nc=this.ec(0),this.rc=this.ec(1)}Lh(){this.hc(Y.bn())}ar(){this.hc(Y.gn())}Zh(){this.hc(new Y(1))}Ah(t){const i=this.lc(t);this.hc(i)}oc(){return this.Xu}ac(t){if(this.Xu?.e_===t?.e_&&this.Xu?.r_?.Gn===t?.r_?.Gn)return;const i=this.Xu;this.Xu=t,null!==i&&this.Ah(i.e_),null!==t&&t.e_!==i?.e_&&this.Ah(t.e_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.ju.forEach(i=>i.Ra(t)),void 0!==t.timeScale&&this.dh.lr(t.timeScale),void 0!==t.localization&&this.dh.K_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Gu.p(),this.nc=this.ec(0),this.rc=this.ec(1),this.Lh()}_c(t,i,s=0){const n=this.ju[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Ra({leftPriceScale:i}),this.Gu.p(),void this.Lh();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Ra({rightPriceScale:i}),this.Gu.p(),void this.Lh();const e=this.uc(t,s);null!==e&&(e.$t.lr(i),this.Gu.p())}uc(t,i){const s=this.ju[i];if(void 0===s)return null;const n=s.Fa(t);return null!==n?{Us:s,$t:n}:null}At(){return this.dh}qs(){return this.ju}cc(){return this.Ct}dc(){return this.Ku}fc(t,i){t.Oo(i),this.mu()}Aa(t){this.Ma=t,this.dh.Aa(this.Ma),this.ju.forEach(i=>i.Aa(t)),this.mu()}vc(t){1!==this.ju.length&&(r(t>=0&&t<this.ju.length,"Invalid pane index"),this.ju.splice(t,1),this.Lh())}mc(t,i){if(this.ju.length<2)return;r(t>=0&&t<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju.reduce((t,i)=>t+i.Va(),0),e=this.ju.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.ju.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.La(i*l);let a=i-o,_=this.ju.length-1;for(const t of this.ju)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.La(s)}this.Lh()}wc(t,i){r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju[i];this.ju[t]=n,this.ju[i]=s,this.Lh()}gc(t,i){if(r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index"),t===i)return;const[s]=this.ju.splice(t,1);this.ju.splice(i,0,s),this.Lh()}Ua(t,i,s){t.Ua(i,s)}qa(t,i,s){t.qa(i,s),this.Eh(),this.hc(this.bc(t,2))}ja(t,i){t.ja(i),this.hc(this.bc(t,2))}Ya(t,i,s){i.Fo()||t.Ya(i,s)}Xa(t,i,s){i.Fo()||(t.Xa(i,s),this.Eh(),this.hc(this.bc(t,2)))}Ga(t,i){i.Fo()||(t.Ga(i),this.hc(this.bc(t,2)))}Za(t,i){t.Za(i),this.hc(this.bc(t,2))}Mc(t){this.dh.ra(t)}yc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Cu(t,i),this.mu()}Sc(t){this.xc(0),this.Cc(t),this.Pc()}Tc(t){this.dh.ha(t),this.mu()}kc(){this.dh.la(),this.ar()}xc(t){this.dh.oa(t)}Cc(t){this.dh.aa(t),this.mu()}Pc(){this.dh._a(),this.ar()}Xs(){return this.Yu}Dc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.dh.du(t,!0);const l=this.dh.Pe();null!==l&&(h=Math.min(Math.max(l.Uh(),h),l.yi()));const o=n.ks(),a=o.Bt();if(null!==a&&(r=o.Ds(i,a)),r=this.tc.bl(r,h,n),this.Ct.Es(h,r,n),this.Zh(),!e){const e=Si(n,t,i);this.ac(e&&{e_:e.e_,r_:e.r_,l_:e.l_||null}),this.Ku.p(this.Ct.Lt(),{x:t,y:i},s)}}Rc(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.dh.tu(i,!0),o=this.dh.jt(l(h));this.Dc(o,r,null,s,!0)}Fc(t){this.cc().Os(),this.Zh(),t||this.Ku.p(null,null,null)}Eh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Dc(i,s,null,t)}this.Ct.zs()}Ic(t,i,s){const n=this.dh.Rs(0);void 0!==i&&void 0!==s&&this.dh.Tt(i,s);const e=this.dh.Rs(0),r=this.dh.uu(),h=this.dh.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.__.key(n)>this.__.key(e),o=null!==t&&t>r&&!l,a=this.dh.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.dh.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.dh.fn(this.dh.bu()-i)}}this.dh.xu(t)}Oh(t){null!==t&&t.Qa()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.ju.find(i=>i.Ft().includes(t));return void 0===i?null:i}mu(){this.ju.forEach(t=>t.Qa()),this.Eh()}m(){this.ju.forEach(t=>t.m()),this.ju.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Vc(){return this.Qu}Yn(){return this.Qu.W()}Ia(){return this.Gu}Lc(t,i){const s=this.sc(i);this.Ac(t,s),this.Yu.push(t),1===this.Yu.length?this.Lh():this.ar()}Ec(t){const i=this.Nn(t),s=this.Yu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Yu.splice(s,1),n.sa(t),t.m&&t.m(),this.dh.G_();const e=this.ju.length;this.Bc(n),this.ju.length<e&&this.Lh()}Vh(t,i){const s=l(this.Nn(t));s.sa(t,!0),s.ta(t,i,!0)}Eu(){const t=Y.gn();t.hn(),this.hc(t)}Oc(t){const i=Y.gn();i._n(t),this.hc(i)}dn(){const t=Y.gn();t.dn(),this.hc(t)}pn(t){const i=Y.gn();i.pn(t),this.hc(i)}fn(t){const i=Y.gn();i.fn(t),this.hc(i)}un(t){const i=Y.gn();i.un(t),this.hc(i)}ln(){const t=Y.gn();t.ln(),this.hc(t)}Wc(){return this.Ps.rightPriceScale.visible?"right":"left"}zc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.$c(t))return;const s=l(this.Nn(t));s.sa(t);const n=this.sc(i);this.Ac(t,n),0===s.Ml().length&&this.Bc(s),this.Lh()}Hc(){return this.rc}q(){return this.nc}Ut(t){const i=this.rc,s=this.nc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Zu||this.Zu.wr!==s||this.Zu.gr!==i)this.Zu={wr:s,gr:i,Nc:new Map};else{const i=this.Zu.Nc.get(t);if(void 0!==i)return i}const n=this.Co.it(s,i,t/100);return this.Zu.Nc.set(t,n),n}Uc(t){return this.ju.indexOf(t)}Ki(){return this.Co}qc(){return this.jc()}jc(t){const i=new wi(this.dh,this);this.ju.push(i);const s=t??this.ju.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.hc(n),i}sc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.ju.length,t))<this.ju.length?this.ju[t]:this.jc(t)}$c(t){return this.ju.findIndex(i=>i.Wa().includes(t))}bc(t,i){const s=new Y(i);if(null!==t){const n=this.ju.indexOf(t);s.tn(n,{sn:i})}return s}lc(t,i){return void 0===i&&(i=2),this.bc(this.Nn(t),i)}hc(t){this.Ju&&this.Ju(t),this.ju.forEach(t=>t.s_()._r().Tt())}Ac(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.Wc();i.ta(t,n),j(n)||t.lr(t.W())}ec(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Bc(t){!t.Oa()&&0===t.Ml().length&&this.ju.length>1&&this.ju.splice(this.Uc(t),1)}}function Bi(t){if(t>=1)return 0;let i=0;for(;i<8;i++){const s=Math.round(t);if(Math.abs(s-t)<1e-8)return i;t*=10}return i}function 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.Yc=t,this.Xc=i}u_(t){return $i(t,this.Yc,this.Xc)}}class Ni{constructor(t){this.Gc=t||"%h:%m:%s"}u_(t){return this.Gc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Kc:"yyyy-MM-dd",Zc:"%h:%m:%s",Jc:" ",Qc:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.td=new Hi(i.Kc,i.Qc),this.sd=new Ni(i.Zc),this.nd=i.Jc}u_(t){return`${this.td.u_(t)}${this.nd}${this.sd.u_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{ed:(Gi=1,1e3*Gi),rd:10},{ed:Yi(1),rd:20},{ed:Yi(5),rd:21},{ed:Yi(30),rd:22},{ed:ji(1),rd:30},{ed:ji(3),rd:31},{ed:ji(6),rd:32},{ed:ji(12),rd:33}];var Gi;function 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].ed)!==Math.floor(t.getTime()/Xi[s].ed))return Xi[s].rd;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Oi(i))throw new Error("time must be of type BusinessDay");const s=new Date(Date.UTC(i.year,i.month-1,i.day,0,0,0,0));return{hd:Math.round(s.getTime()/1e3),ld:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{hd:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}class ss{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Oi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"hd"in t?t.hd:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ld?new Date(1e3*i.hd).getTime():new Date(Date.UTC(i.ld.year,i.ld.month-1,i.ld.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Oi(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this.od=new qi({Kc:i,Zc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Jc:" ",Qc:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.u_(new Date(1e3*i.hd))}formatTickmark(t,i){const s=function(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.ld?new Date(1e3*t.hd):new Date(Date.UTC(t.ld.year,t.ld.month-1,t.ld.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.hd,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).hd);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).hd-(s||Zi(i.time).hd),s=Zi(i.time).hd,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.hd-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.hd),s)}}(t,i)}static ad(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function ns(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function es(t,i){return t.width===i.width&&t.height===i.height}var rs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var hs=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=ns({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return ns({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=ns(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;es(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=ns(this._transformBitmapSize(t,this._canvasElementClientSize)),n=es(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&es(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=ls(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new rs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=ls(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return ns({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):ns({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=ns({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function ls(t){return t.ownerDocument.defaultView}var os=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function as(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new os(e,s,n)}const _s="undefined"!=typeof window;function us(){return!!_s&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function cs(){return!!_s&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ds(t){return t+t%2}function ps(t){_s&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class fs{constructor(t,i,s){this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.md=null,this.wd=!1,this.gd=null,this.bd=null,this.Md=!1,this.yd=!1,this.Sd=!1,this.xd=null,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=0,this.Id=!1,this.Vd=!1,this.Ld=!1,this.Ad=0,this.Ed=null,this.Bd=!cs(),this.Od=t=>{this.Wd(t)},this.zd=t=>{if(this.$d(t)){const i=this.Hd(t);if(++this.pd,this.fd&&this.pd>1){const{Nd:s}=this.Ud(ws(t),this.vd);s<30&&!this.Sd&&this.qd(i,this.Yd.jd),this.Xd()}}else{const i=this.Hd(t);if(++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Kd),this.Zd()}}},this.Jd=t,this.Yd=i,this.Ps=s,this.Qd()}m(){null!==this.xd&&(this.xd(),this.xd=null),null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),this.tp(),this.Zd()}ip(t){this.Td&&this.Td();const i=this.sp.bind(this);if(this.Td=()=>{this.Jd.removeEventListener("mousemove",i)},this.Jd.addEventListener("mousemove",i),this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.np),this.Bd=!0}Zd(){null!==this.ud&&clearTimeout(this.ud),this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Xd(){null!==this.fd&&clearTimeout(this.fd),this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}sp(t){if(this.Ld||null!==this.bd)return;if(this.$d(t))return;const i=this.Hd(t);this.Gd(i,this.Yd.ep),this.Bd=!0}rp(t){const i=bs(t.changedTouches,l(this.Ed));if(null===i)return;if(this.Ad=gs(t),null!==this.Rd)return;if(this.Vd)return;this.Id=!0;const s=this.Ud(ws(i),l(this.bd)),{hp:n,lp:e,Nd:r}=s;if(this.Md||!(r<5)){if(!this.Md){const t=.5*n,i=e>=t&&!this.Ps.op(),s=t>e&&!this.Ps.ap();i||s||(this.Vd=!0),this.Md=!0,this.Sd=!0,this.tp(),this.Xd()}if(!this.Vd){const s=this.Hd(t,i);this.qd(s,this.Yd._p),ms(t)}}}up(t){if(0!==t.button)return;const i=this.Ud(ws(t),l(this.gd)),{Nd:s}=i;if(s>=5&&(this.yd=!0,this.Zd()),this.yd){const i=this.Hd(t);this.Gd(i,this.Yd.cp)}}Ud(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{hp:s,lp:n,Nd:s+n}}dp(t){let i=bs(t.changedTouches,l(this.Ed));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ed=null,this.Ad=gs(t),this.tp(),this.bd=null,this.Dd&&(this.Dd(),this.Dd=null);const s=this.Hd(t,i);if(this.qd(s,this.Yd.pp),++this.pd,this.fd&&this.pd>1){const{Nd:t}=this.Ud(ws(i),this.vd);t<30&&!this.Sd&&this.qd(s,this.Yd.jd),this.Xd()}else this.Sd||(this.qd(s,this.Yd.fp),this.Yd.fp&&ms(t));0===this.pd&&ms(t),0===t.touches.length&&this.wd&&(this.wd=!1,ms(t))}Wd(t){if(0!==t.button)return;const i=this.Hd(t);if(this.gd=null,this.Ld=!1,this.kd&&(this.kd(),this.kd=null),us()){this.Jd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Od)}if(!this.$d(t))if(this.Gd(i,this.Yd.vp),++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Kd),this.Zd()}else this.yd||this.Gd(i,this.Yd.mp)}tp(){null!==this.md&&(clearTimeout(this.md),this.md=null)}wp(t){if(null!==this.Ed)return;const i=t.changedTouches[0];this.Ed=i.identifier,this.Ad=gs(t);const s=this.Jd.ownerDocument.documentElement;this.Sd=!1,this.Md=!1,this.Vd=!1,this.bd=ws(i),this.Dd&&(this.Dd(),this.Dd=null);{const i=this.rp.bind(this),n=this.dp.bind(this);this.Dd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.tp(),this.md=setTimeout(this.gp.bind(this,t),240)}const n=this.Hd(t,i);this.qd(n,this.Yd.bp),this.fd||(this.pd=0,this.fd=setTimeout(this.Xd.bind(this),500),this.vd=ws(i))}Mp(t){if(0!==t.button)return;const i=this.Jd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Od),this.yd=!1,this.gd=ws(t),this.kd&&(this.kd(),this.kd=null);{const t=this.up.bind(this),s=this.Wd.bind(this);this.kd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ld=!0,this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.yp),this.ud||(this._d=0,this.ud=setTimeout(this.Zd.bind(this),500),this.dd=ws(t))}Qd(){this.Jd.addEventListener("mouseenter",this.ip.bind(this)),this.Jd.addEventListener("touchcancel",this.tp.bind(this));{const t=this.Jd.ownerDocument,i=t=>{this.Yd.Sp&&(t.composed&&this.Jd.contains(t.composedPath()[0])||t.target&&this.Jd.contains(t.target)||this.Yd.Sp())};this.Cd=()=>{t.removeEventListener("touchstart",i)},this.xd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Pd=()=>{this.Jd.removeEventListener("dblclick",this.zd)},this.Jd.addEventListener("dblclick",this.zd)),this.Jd.addEventListener("mouseleave",this.xp.bind(this)),this.Jd.addEventListener("touchstart",this.wp.bind(this),{passive:!0}),ps(this.Jd),this.Jd.addEventListener("mousedown",this.Mp.bind(this)),this.Cp(),this.Jd.addEventListener("touchmove",()=>{},{passive:!1})}Cp(){void 0===this.Yd.Pp&&void 0===this.Yd.Tp&&void 0===this.Yd.kp||(this.Jd.addEventListener("touchstart",t=>this.Dp(t.touches),{passive:!0}),this.Jd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Rd&&void 0!==this.Yd.Tp){const i=vs(t.touches[0],t.touches[1])/this.Fd;this.Yd.Tp(this.Rd,i),ms(t)}},{passive:!1}),this.Jd.addEventListener("touchend",t=>{this.Dp(t.touches)}))}Dp(t){1===t.length&&(this.Id=!1),2!==t.length||this.Id||this.wd?this.Rp():this.Fp(t)}Fp(t){const i=this.Jd.getBoundingClientRect()||{left:0,top:0};this.Rd={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.Fd=vs(t[0],t[1]),void 0!==this.Yd.Pp&&this.Yd.Pp(),this.tp()}Rp(){null!==this.Rd&&(this.Rd=null,void 0!==this.Yd.kp&&this.Yd.kp())}xp(t){if(this.Td&&this.Td(),this.$d(t))return;if(!this.Bd)return;const i=this.Hd(t);this.Gd(i,this.Yd.Ip),this.Bd=!cs()}gp(t){const i=bs(t.touches,l(this.Ed));if(null===i)return;const s=this.Hd(t,i);this.qd(s,this.Yd.Vp),this.Sd=!0,this.wd=!0}$d(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ad+500}qd(t,i){i&&i.call(this.Yd,t)}Gd(t,i){i&&i.call(this.Yd,t)}Hd(t,i){const s=i||t,n=this.Jd.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Lp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ap:t.type,Ep:s.target,o_:t.view,Bp:()=>{"touchstart"!==t.type&&ms(t)}}}}function vs(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ms(t){t.cancelable&&t.preventDefault()}function ws(t){return{ut:t.pageX,ct:t.pageY}}function gs(t){return t.timeStamp||performance.now()}function bs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ms{constructor(t,i,s){this.Op=null,this.Wp=null,this.zp=!0,this.$p=null,this.Hp=t,this.Np=t.Up()[i],this.qp=t.Up()[s],this.jp=document.createElement("tr"),this.jp.style.height="1px",this.Yp=document.createElement("td"),this.Yp.style.position="relative",this.Yp.style.padding="0",this.Yp.style.margin="0",this.Yp.setAttribute("colspan","3"),this.Xp(),this.jp.appendChild(this.Yp),this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(this.Op=null,this.Wp=null)}m(){null!==this.Wp&&this.Wp.m()}Kp(){return this.jp}Zp(){return ns({width:this.Np.Zp().width,height:1})}Jp(){return ns({width:this.Np.Jp().width,height:1*window.devicePixelRatio})}Qp(t,i,s){const n=this.Jp();t.fillStyle=this.Hp.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Xp(),this.Hp.W().layout.panes.enableResize!==this.zp&&(this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(null!==this.Op&&(this.Yp.removeChild(this.Op.tf),this.Yp.removeChild(this.Op.if),this.Op=null),null!==this.Wp&&(this.Wp.m(),this.Wp=null)))}Gp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Yp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Yp.appendChild(s);const e={np:this.sf.bind(this),Ip:this.nf.bind(this),yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this)};this.Wp=new fs(s,e,{op:()=>!1,ap:()=>!0}),this.Op={if:s,tf:t}}Xp(){this.Yp.style.background=this.Hp.W().layout.panes.separatorColor}sf(t){null!==this.Op&&(this.Op.if.style.backgroundColor=this.Hp.W().layout.panes.separatorHoverColor)}nf(t){null!==this.Op&&null===this.$p&&(this.Op.if.style.backgroundColor="")}ef(t){if(null===this.Op)return;const i=this.Np.lf().Va()+this.qp.lf().Va(),s=i/(this.Np.Zp().height+this.qp.Zp().height),n=30*s;i<=2*n||(this.$p={af:t.pageY,_f:this.Np.lf().Va(),uf:i-n,cf:i,df:s,pf:n},this.Op.tf.style.display="block")}rf(t){const i=this.$p;if(null===i)return;const s=(t.pageY-i.af)*i.df,n=Xt(i._f+s,i.pf,i.uf);this.Np.lf().La(n),this.qp.lf().La(i.cf-n),this.Hp.ti().Lh()}hf(t){null!==this.$p&&null!==this.Op&&(this.$p=null,this.Op.tf.style.display="none")}}function ys(t,i){return t.ff-i.ff}function Ss(t,i,s){const n=(t.ff-i.ff)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.vf=null,this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=0,this.yf=0,this.Sf=t,this.xf=i,this.Cf=s,this.Mn=n}Pf(t,i){if(null!==this.vf){if(this.vf.gt===i)return void(this.vf.ff=t);if(Math.abs(this.vf.ff-t)<this.Mn)return}this.gf=this.wf,this.wf=this.mf,this.mf=this.vf,this.vf={gt:i,ff:t}}ae(t,i){if(null===this.vf||null===this.mf)return;if(i-this.vf.gt>50)return;let s=0;const n=Ss(this.vf,this.mf,this.xf),e=ys(this.vf,this.mf),r=[n],h=[e];if(s+=e,null!==this.wf){const t=Ss(this.mf,this.wf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.mf,this.wf);if(r.push(t),h.push(i),s+=i,null!==this.gf){const t=Ss(this.wf,this.gf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.Sf||(this.bf={ff:t,gt:i},this.yf=l,this.Mf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Cf))}Fu(t){const i=l(this.bf),s=t-i.gt;return i.ff+this.yf*(Math.pow(this.Cf,s)-1)/Math.log(this.Cf)}Ru(t){return null===this.bf||this.Tf(t)===this.Mf}Tf(t){const i=t-l(this.bf).gt;return Math.min(i,this.Mf)}}class Cs{constructor(t,i){this.kf=void 0,this.Df=void 0,this.Rf=void 0,this.vs=!1,this.Ff=t,this.If=i,this.Vf()}Tt(){this.Vf()}Lf(){this.kf&&this.Ff.removeChild(this.kf),this.Df&&this.Ff.removeChild(this.Df),this.kf=void 0,this.Df=void 0}Af(){return this.vs!==this.Ef()||this.Rf!==this.Bf()}Bf(){return this.If.ti().Ki().tt(this.If.W().layout.textColor)>160?"dark":"light"}Ef(){return this.If.W().layout.attributionLogo}Of(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Vf(){this.Af()&&(this.Lf(),this.vs=this.Ef(),this.vs&&(this.Rf=this.Bf(),this.Df=document.createElement("style"),this.Df.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.kf=document.createElement("a"),this.kf.href=`https://pipsend.com${this.Of()}`,this.kf.title="Powered by Pipsend Charts",this.kf.id="pipsend-attr-logo",this.kf.target="_blank",this.kf.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.kf.toggleAttribute("data-dark","dark"===this.Rf),this.Ff.appendChild(this.Df),this.Ff.appendChild(this.kf)))}}function Ps(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new hs(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function Ts(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function ks(t,i,s,n){t.sh&&t.sh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function 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()?.wl()??"")!==i?[]:s.il?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],o=t[r-1],a=o.qt(n,!1),_=l.$i(),u=o.$i();if(1===i?_>u-a:_<u+a){const n=u-a*i;l.Hi(n);const r=n-i*a/2;if((1===i?r<0:r>s)&&h>0){const n=1===i?-1-r:r-s,l=Math.min(n,h);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);h-=l}}else e=r,h=1===i?u-a-_:_-(u+a)}}class Vs{constructor(t,i,s,n){this.Yi=null,this.Wf=null,this.zf=!1,this.$f=new it(200),this.Hf=null,this.Nf=0,this.Uf=!1,this.qf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Yf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Pt=t,this.Ps=i,this.So=i.layout,this.Qu=s,this.Xf="left"===n,this.Gf=Fs("normal",n),this.Kf=Fs("top",n),this.Zf=Fs("bottom",n),this.Yp=document.createElement("div"),this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Yp.style.width="25px",this.Yp.style.left="0",this.Yp.style.position="relative",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const e=this.Jf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.Qf=Ps(this.Yp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const r=this.Qf.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),Sp:this.tv.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this),Kd:this.iv.bind(this),jd:this.iv.bind(this),np:this.sv.bind(this),Ip:this.nf.bind(this)};this.Wp=new fs(this.Qf.canvasElement,h,{op:()=>!this.Ps.handleScroll.vertTouchDrag,ap:()=>!0})}m(){this.Wp.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Yi&&this.Yi.ea().u(this),this.Yi=null}Kp(){return this.Yp}P(){return this.So.fontSize}nv(){const t=this.Qu.W();return this.Hf!==t.T&&(this.$f.Vn(),this.Hf=t.T),t}ev(){if(null===this.Yi)return 0;let t=0;const i=this.nv(),s=l(this.Jf.canvasElement.getContext("2d",{colorSpace:this.Pt.jf().W().layout.colorSpace}));s.save();const n=this.Yi.Fl();s.font=this.rv(),n.length>0&&(t=Math.max(this.$f.Ii(s,n[0].Zl),this.$f.Ii(s,n[n.length-1].Zl)));const e=this.hv();for(let i=e.length;i--;){const n=this.$f.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.Wf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.Wf.height-2,r);t=Math.max(t,this.$f.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.$f.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ds(Math.ceil(i.S+i.C+i.V+i.L+5+o))}lv(t){null!==this.Wf&&es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`)}ov(){return l(this.Wf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ea().u(this),this.Yi=t,t.ea().i(this.co.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt.lf();this.Pt.jf().ti().Za(t,l(this.$t()))}av(t){if(null===this.Wf)return;const i={colorSpace:this.Pt.jf().W().layout.colorSpace};if(1!==t){this._v(),this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)}),this.Pt.dv(t,this.Zf),this.pv(t),this.Pt.dv(t,this.Gf),this.fv(t))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.vv(s),this.Pt.dv(s,this.Kf))}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Fl()}ef(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!0,i.Ua(s,this.Yi,t.localY)}rf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf(),n=this.Yi;i.qa(s,n,t.localY)}tv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.jf().ti(),i=this.Pt.lf(),s=this.Yi;this.zf&&(this.zf=!1,t.ja(i,s))}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!1,i.ja(s,this.Yi)}iv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}sv(t){if(null===this.Yi)return;!this.Pt.jf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Vo()||this.mv(1)}nf(t){this.mv(0)}hv(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt.lf(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.lf().Ft()),t}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.lf().ti(),r=e.q(),h=e.Hc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.Wf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.nv().S*s));let e;e=this.Xf?i.width-n:0,t.fillRect(e,0,n,i.height)}pv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Yi.Fl(),s=this.Yi.W(),n=this.nv(),e=this.Xf?this.Wf.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Pl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.rv(),t.fillStyle=s.textColor??this.So.textColor,t.textAlign=this.Xf?"right":"left",t.textBaseline="middle";const r=this.Xf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.$f.Fi(t,i.Zl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Zl,r,n.Pl+h[s])}})}_v(){if(null===this.Wf||null===this.Yi)return;let t=this.Wf.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt.lf(),e=this.nv();this.Yi===n.qn()&&this.Pt.lf().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.Ml()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.wv(i,e,t)}wv(t,i,s){if(null===this.Wf)return;const n=t.filter(t=>t.Li()<=s),e=t.filter(t=>t.Li()>s);n.sort((t,i)=>i.Li()-t.Li()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Li()-i.Li());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Li();n>-t&&n<t&&s.Hi(t),n>this.Wf.height-t&&n<this.Wf.height+t&&s.Hi(this.Wf.height-t)}Is(n,1,this.Wf.height,i),Is(e,-1,this.Wf.height,i)}fv(t){if(null===this.Wf)return;const i=this.hv(),s=this.nv(),n=this.Xf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.$f,n)}})}vv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Pt.jf().ti(),s=[],n=this.Pt.lf(),e=i.cc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.nv(),h=this.Xf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.$f,h)})})}mv(t){this.Yp.style.cursor=1===t?"ns-resize":"default"}co(){const t=this.ev();this.Nf<t&&this.Pt.jf().ti().Lh(),this.Nf=t}rv(){return g(this.So.fontSize,this.So.fontFamily)}}function Ls(t,i){return t.Qh?.(i)??[]}function As(t,i){return t.$s?.(i)??[]}function Es(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Kh?.(i)??[]}class Os{constructor(t,i){this.Wf=ns({width:0,height:0}),this.gv=null,this.bv=null,this.Mv=null,this.yv=null,this.Sv=!1,this.xv=new a,this.Cv=new a,this.Pv=0,this.Tv=!1,this.kv=null,this.Dv=!1,this.Rv=null,this.Fv=null,this.Uf=!1,this.qf=()=>{this.Uf||null===this.Iv||this.ss().ar()},this.Yf=()=>{this.Uf||null===this.Iv||this.ss().ar()},this.If=t,this.Iv=i,this.Iv.i_().i(this.Vv.bind(this),this,!0),this.Lv=document.createElement("td"),this.Lv.style.padding="0",this.Lv.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Av=document.createElement("td"),this.Av.style.padding="0",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Lv.appendChild(s),this.Jf=Ps(s,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const n=this.Jf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.jp=document.createElement("tr"),this.jp.appendChild(this.Av),this.jp.appendChild(this.Lv),this.jp.appendChild(this.Ev),this.Bv(),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>null===this.kv&&!this.If.W().handleScroll.vertTouchDrag,ap:()=>null===this.kv&&!this.If.W().handleScroll.horzTouchDrag})}m(){null!==this.gv&&this.gv.m(),null!==this.bv&&this.bv.m(),this.Mv=null,this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Iv&&(this.Iv.i_().u(this),this.Iv.m()),this.Wp.m()}lf(){return l(this.Iv)}Ov(t){null!==this.Iv&&this.Iv.i_().u(this),this.Iv=t,null!==this.Iv&&this.Iv.i_().i(Os.prototype.Vv.bind(this),this,!0),this.Bv(),this.If.Up().indexOf(this)===this.If.Up().length-1?(this.Mv=this.Mv??new Cs(this.Lv,this.If),this.Mv.Tt()):(this.Mv?.Lf(),this.Mv=null)}jf(){return this.If}Kp(){return this.jp}Bv(){if(null!==this.Iv&&(this.Wv(),0!==this.ss().Xs().length)){if(null!==this.gv){const t=this.Iv.Ha();this.gv.us(l(t))}if(null!==this.bv){const t=this.Iv.Na();this.bv.us(l(t))}}}zv(){null!==this.gv&&this.gv.Tt(),null!==this.bv&&this.bv.Tt()}Va(){return null!==this.Iv?this.Iv.Va():0}La(t){this.Iv&&this.Iv.La(t)}np(t){if(!this.Iv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}yp(t){this.$v(),this.Nv(),this.Hv(t.localX,t.localY,t)}ep(t){if(!this.Iv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}mp(t){null!==this.Iv&&(this.$v(),this.Uv(t))}Kd(t){null!==this.Iv&&this.qv(this.Cv,t)}jd(t){this.Kd(t)}cp(t){this.$v(),this.jv(t),this.Hv(t.localX,t.localY,t)}vp(t){null!==this.Iv&&(this.$v(),this.Tv=!1,this.Yv(t))}fp(t){null!==this.Iv&&this.Uv(t)}Vp(t){if(this.Tv=!0,null===this.kv){const i={x:t.localX,y:t.localY};this.Xv(i,i,t)}}Ip(t){null!==this.Iv&&(this.$v(),this.Iv.ti().ac(null),this.Gv())}Kv(){return this.xv}Zv(){return this.Cv}Pp(){this.Pv=1,this.ss().ln()}Tp(t,i){if(!this.If.W().handleScale.pinch)return;const s=5*(i-this.Pv);this.Pv=i,this.ss().yc(t.ut,s)}bp(t){this.Tv=!1,this.Dv=null!==this.kv,this.Nv();const i=this.ss().cc();null!==this.kv&&i.It()&&(this.Rv={x:i.ni(),y:i.ei()},this.kv={x:t.localX,y:t.localY})}_p(t){if(null===this.Iv)return;const i=t.localX,s=t.localY;if(null!==this.kv){this.Dv=!1;const n=l(this.Rv),e=n.x+(i-this.kv.x),r=n.y+(s-this.kv.y);return void this.Hv(e,r,t)}this.jv(t)}pp(t){0===this.jf().W().trackingMode.exitMode&&(this.Dv=!0),this.Jv(),this.Yv(t)}Xn(t,i){const s=this.Iv;return null===s?null:Si(s,t,i)}Qv(t,i){l("left"===i?this.gv:this.bv).lv(ns({width:t,height:this.Wf.height}))}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Lv.style.width=t.width+"px",this.Lv.style.height=t.height+"px")}tm(){const t=l(this.Iv);t.$a(t.Ha()),t.$a(t.Na());for(const i of t.Ml())if(t.Un(i)){const s=i.$t();null!==s&&t.$a(s),i.zs()}for(const i of t.n_())i.zs()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;null!==t&&t.drawImage(n,i,s)}}av(t){if(0===t)return;if(null===this.Iv)return;t>1&&this.tm(),null!==this.gv&&this.gv.av(t),null!==this.bv&&this.bv.av(t);const i={colorSpace:this.If.W().layout.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t)}),this.Iv&&(this.im(t,Ls),this.sm(t),this.im(t,As),this.im(t,Es)))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.nm(s),this.im(s,Bs),this.im(s,Es))}rm(){return this.gv}hm(){return this.bv}dv(t,i){this.im(t,i)}Vv(){null!==this.Iv&&this.Iv.i_().u(this),this.Iv=null}Uv(t){this.qv(this.xv,t)}qv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().du(s),{x:s,y:n},i)}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Hc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}sm(t){const i=l(this.Iv),s=i.s_()._r().Dt(i);null!==s&&s.et(t,!1)}nm(t){this.lm(t,As,Ds,this.ss().cc())}im(t,i){const s=l(this.Iv),n=s.Ft(),e=s.n_();for(const s of e)this.lm(t,i,ks,s);for(const s of n)this.lm(t,i,ks,s);for(const s of e)this.lm(t,i,Ds,s);for(const s of n)this.lm(t,i,Ds,s)}lm(t,i,s,n){const e=l(this.Iv),r=e.ti().oc(),h=null!==r&&r.e_===n,o=null!==r&&h&&void 0!==r.r_?r.r_.Kn:void 0;Rs(i,i=>s(i,t,h,o),n,e)}Wv(){if(null===this.Iv)return;const t=this.If,i=this.Iv.Ha().W().visible,s=this.Iv.Na().W().visible;i||null===this.gv||(this.Av.removeChild(this.gv.Kp()),this.gv.m(),this.gv=null),s||null===this.bv||(this.Ev.removeChild(this.bv.Kp()),this.bv.m(),this.bv=null);const n=t.ti().Vc();i&&null===this.gv&&(this.gv=new Vs(this,t.W(),n,"left"),this.Av.appendChild(this.gv.Kp())),s&&null===this.bv&&(this.bv=new Vs(this,t.W(),n,"right"),this.Ev.appendChild(this.bv.Kp()))}om(t){return t.Lp&&this.Tv||null!==this.kv}am(t){return Math.max(0,Math.min(t,this.Wf.width-1))}_m(t){return Math.max(0,Math.min(t,this.Wf.height-1))}Hv(t,i,s){this.ss().Dc(this.am(t),this._m(i),s,l(this.Iv))}Gv(){this.ss().Fc()}Jv(){this.Dv&&(this.kv=null,this.Gv())}Xv(t,i,s){this.kv=t,this.Dv=!1,this.Hv(i.x,i.y,s);const n=this.ss().cc();this.Rv={x:n.ni(),y:n.ei()}}ss(){return this.If.ti()}Yv(t){if(!this.Sv)return;const i=this.ss(),s=this.lf();if(i.Ga(s,s.ks()),this.yv=null,this.Sv=!1,i.Pc(),null!==this.Fv){const t=performance.now(),s=i.At();this.Fv.ae(s.bu(),t),this.Fv.Ru(t)||i.un(this.Fv)}}$v(){this.kv=null}Nv(){if(!this.Iv)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.Iv.ks().Gi()&&this.ss().At().Gi()}jv(t){if(null===this.Iv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.If.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Lp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Lp))return;const h=this.Iv.ks(),l=performance.now();if(null!==this.yv||this.om(t)||(this.yv={x:t.clientX,y:t.clientY,hd:l,um:t.localX,dm:t.localY}),null!==this.yv&&!this.Sv&&(this.yv.x!==t.clientX||this.yv.y!==t.clientY)){if(t.Lp&&r.touch||!t.Lp&&r.mouse){const t=s.wu();this.Fv=new xs(.2/t,7/t,.997,15/t),this.Fv.Pf(s.bu(),this.yv.hd)}else this.Fv=null;h.Gi()||i.Ya(this.Iv,h,t.localY),i.xc(t.localX),this.Sv=!0}this.Sv&&(h.Gi()||i.Xa(this.Iv,h,t.localY),i.Cc(t.localX),null!==this.Fv&&this.Fv.Pf(s.bu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.Wf=ns({width:0,height:0}),this.qf=()=>this.av(3),this.Xf="left"===t,this.Qu=s.Vc,this.Ps=i,this.pm=n,this.fm=e,this.Yp=document.createElement("div"),this.Yp.style.width="25px",this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf)}m(){this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Kp(){return this.Yp}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Jf.resizeCanvasElement(t),this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.xt=!0)}av(t){if(t<3&&!this.xt)return;if(0===this.Wf.width||0===this.Wf.height)return;this.xt=!1,this.Jf.applySuggestedBitmapSize();const i=as(this.Jf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)})}Jp(){return this.Jf.bitmapSize}Qp(t,i,s){const n=this.Jp();n.width>0&&n.height>0&&t.drawImage(this.Jf.canvasElement,i,s)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.pm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.Qu.W().S*s),r=Math.floor(this.Qu.W().S*n),h=this.Xf?i.width-e:0;t.fillRect(h,0,e,r)}uv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.fm())}}function zs(t){return i=>i.sl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.vm=null,this.wm=null,this.M=null,this.gm=!1,this.Wf=ns({width:0,height:0}),this.bm=new a,this.$f=new it(5),this.Uf=!1,this.qf=()=>{this.Uf||this.If.ti().ar()},this.Yf=()=>{this.Uf||this.If.ti().ar()},this.If=t,this.__=i,this.Ps=t.W().layout,this.kf=document.createElement("tr"),this.Mm=document.createElement("td"),this.Mm.style.padding="0",this.ym=document.createElement("td"),this.ym.style.padding="0",this.Yp=document.createElement("td"),this.Yp.style.height="25px",this.Yp.style.padding="0",this.Sm=document.createElement("div"),this.Sm.style.width="100%",this.Sm.style.height="100%",this.Sm.style.position="relative",this.Sm.style.overflow="hidden",this.Yp.appendChild(this.Sm),this.Jf=Ps(this.Sm,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const s=this.Jf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Qf=Ps(this.Sm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.kf.appendChild(this.Mm),this.kf.appendChild(this.Yp),this.kf.appendChild(this.ym),this.xm(),this.If.ti().Ia().i(this.xm.bind(this),this),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>!0,ap:()=>!this.If.W().handleScroll.horzTouchDrag})}m(){this.Wp.m(),null!==this.vm&&this.vm.m(),null!==this.wm&&this.wm.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Kp(){return this.kf}Cm(){return this.vm}Pm(){return this.wm}yp(t){if(this.gm)return;this.gm=!0;const i=this.If.ti();!i.At().Gi()&&this.If.W().handleScale.axisPressedMouseMove.time&&i.Mc(t.localX)}bp(t){this.yp(t)}Sp(){const t=this.If.ti();!t.At().Gi()&&this.gm&&(this.gm=!1,this.If.W().handleScale.axisPressedMouseMove.time&&t.kc())}cp(t){const i=this.If.ti();!i.At().Gi()&&this.If.W().handleScale.axisPressedMouseMove.time&&i.Tc(t.localX)}_p(t){this.cp(t)}vp(){this.gm=!1;const t=this.If.ti();t.At().Gi()&&!this.If.W().handleScale.axisPressedMouseMove.time||t.kc()}pp(){this.vp()}Kd(){this.If.W().handleScale.axisDoubleClickReset.time&&this.If.ti().dn()}jd(){this.Kd()}np(){this.If.ti().W().handleScale.axisPressedMouseMove.time&&this.mv(1)}Ip(){this.mv(0)}Zp(){return this.Wf}Tm(){return this.bm}km(t,i,s){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.bm.p(t)),null!==this.vm&&this.vm.lv(ns({width:i,height:t.height})),null!==this.wm&&this.wm.lv(ns({width:s,height:t.height}))}Dm(){const t=this.Rm();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Fm)}Tt(){this.If.ti().At().Fl()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}av(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const s=as(this.Jf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t),this.Im(s,Ns)}),this.pv(s),this.Im(s,$s)),null!==this.vm&&this.vm.av(t),null!==this.wm&&this.wm.av(t)}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Vm([...this.If.ti().Xs(),this.If.ti().cc()],s),this.Im(s,Hs))}Im(t,i){const s=this.If.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)}uv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.If.ti().Hc())}cv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.If.W().timeScale.borderVisible){t.fillStyle=this.Lm();const n=Math.max(1,Math.floor(this.Rm().S*s));t.fillRect(0,0,i.width,n)}}pv(t){const i=this.If.ti().At(),s=i.Fl();if(!s||0===s.length)return;const n=this.__.maxTickMarkWeight(s),e=this.Rm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Lm(),t.fillStyle=this.Lm();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.rv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Am(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.If.W().timeScale.allowBoldLabels&&(t.font=this.Em());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Am(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Am(t,i,s){const n=this.$f.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.Wf.width&&(i-=Math.abs(this.Wf.width-(r+n))),i}Vm(t,i){const s=this.Rm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Lm(){return this.If.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}rv(){return g(this.$(),this.Ps.fontFamily)}Em(){return g(this.$(),this.Ps.fontFamily,"bold")}Rm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Fm:0});const t=this.M,i=this.rv();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.Fm=4*s/12,t.Ji.Vn()}return this.M}mv(t){this.Yp.style.cursor=1===t?"ew-resize":"default"}xm(){const t=this.If.ti(),i=t.W();i.leftPriceScale.visible||null===this.vm||(this.Mm.removeChild(this.vm.Kp()),this.vm.m(),this.vm=null),i.rightPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Kp()),this.wm.m(),this.wm=null);const s={Vc:this.If.ti().Vc()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Hc();i.leftPriceScale.visible&&null===this.vm&&(this.vm=new Ws("left",i,s,n,e),this.Mm.appendChild(this.vm.Kp())),i.rightPriceScale.visible&&null===this.wm&&(this.wm=new Ws("right",i,s,n,e),this.ym.appendChild(this.wm.Kp()))}}const qs=!!_s&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!_s&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class js{constructor(t,i,s){var n;this.Bm=[],this.Om=[],this.Wm=0,this.no=0,this.Ma=0,this.zm=0,this.$m=0,this.Hm=null,this.Nm=!1,this.xv=new a,this.Cv=new a,this.Ku=new a,this.Um=null,this.qm=null,this.Ff=t,this.Ps=i,this.__=s,this.kf=document.createElement("div"),this.kf.classList.add("tv-lightweight-charts"),this.kf.style.overflow="hidden",this.kf.style.direction="ltr",this.kf.style.width="100%",this.kf.style.height="100%",(n=this.kf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.jm=document.createElement("table"),this.jm.setAttribute("cellspacing","0"),this.kf.appendChild(this.jm),this.Ym=this.Xm.bind(this),Ys(this.Ps)&&this.Gm(!0),this.ss=new Ei(this.Ju.bind(this),this.Ps,s),this.ti().dc().i(this.Km.bind(this),this),this.Zm=new Us(this,this.__),this.jm.appendChild(this.Zm.Kp());const e=i.autoSize&&this.Jm();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.Qm(r,h),this.tw(),t.appendChild(this.kf),this.iw(),this.ss.At().Lu().i(this.ss.Lh.bind(this.ss),this),this.ss.Ia().i(this.ss.Lh.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}Up(){return this.Bm}sw(){return this.Zm}m(){this.Gm(!1),0!==this.Wm&&window.cancelAnimationFrame(this.Wm),this.ss.dc().u(this),this.ss.At().Lu().u(this),this.ss.Ia().u(this),this.ss.m();for(const t of this.Bm)this.jm.removeChild(t.Kp()),t.Kv().u(this),t.Zv().u(this),t.m();this.Bm=[];for(const t of this.Om)this.nw(t);this.Om=[],l(this.Zm).m(),null!==this.kf.parentElement&&this.kf.parentElement.removeChild(this.kf),this.Ku.m(),this.xv.m(),this.Cv.m(),this.ew()}Qm(t,i,s=!1){if(this.no===i&&this.Ma===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return ns({width:i-i%2,height:s-s%2})}(ns({width:t,height:i}));this.no=n.height,this.Ma=n.width;const e=this.no+"px",r=this.Ma+"px";l(this.kf).style.height=e,l(this.kf).style.width=r,this.jm.style.height=e,this.jm.style.width=r,s?this.rw(Y.bn(),performance.now()):this.ss.Lh()}av(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Bm.length;i++)this.Bm[i].av(t.rn(i).sn);this.Ps.timeScale.visible&&this.Zm.av(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Gm(s),t.layout?.panes&&this.hw(),this.iw(),this.lw(t)}Kv(){return this.xv}Zv(){return this.Cv}dc(){return this.Ku}ow(t=!1){null!==this.Hm&&(this.rw(this.Hm,performance.now()),this.Hm=null);const i=this.aw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.aw(n,t),s}_w(t){if("left"===t&&!this.uw())return 0;if("right"===t&&!this.cw())return 0;if(0===this.Bm.length)return 0;return l("left"===t?this.Bm[0].rm():this.Bm[0].hm()).ov()}dw(){return this.Ps.autoSize&&null!==this.Um}if(){return this.kf}pw(t){this.qm=t,this.qm?this.if().style.setProperty("cursor",t):this.if().style.removeProperty("cursor")}fw(){return this.qm}mw(t){return h(this.Bm[t]).Zp()}hw(){this.Om.forEach(t=>{t.Tt()})}lw(t){(void 0!==t.autoSize||!this.Um||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.Um&&this.Jm(),!1===t.autoSize&&null!==this.Um&&this.ew(),t.autoSize||void 0===t.width&&void 0===t.height||this.Qm(t.width||this.Ma,t.height||this.no))}aw(t,i){let s=0,n=0;const e=this.Bm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Bm.length;r++){const h=this.Bm[r],o=l("left"===s?h.rm():h.hm()),a=o.Jp();if(null!==t&&o.Qp(t,n,e,i),e+=a.height,r<this.Bm.length-1){const i=this.Om[r],s=i.Jp();null!==t&&i.Qp(t,n,e),e+=s.height}}};if(this.uw()){r("left",0);s+=l(e.rm()).Jp().width}for(let e=0;e<this.Bm.length;e++){const r=this.Bm[e],h=r.Jp();if(null!==t&&r.Qp(t,s,n,i),n+=h.height,e<this.Bm.length-1){const i=this.Om[e],r=i.Jp();null!==t&&i.Qp(t,s,n),n+=r.height}}if(s+=e.Jp().width,this.cw()){r("right",s);s+=l(e.hm()).Jp().width}const h=(i,s,n)=>{l("left"===i?this.Zm.Cm():this.Zm.Pm()).Qp(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Zm.Jp();if(null!==t){let r=0;this.uw()&&(h("left",r,n),r=l(e.rm()).Jp().width),this.Zm.Qp(t,r,n,i),r+=s.width,this.cw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}ww(){let t=0,i=0,s=0;for(const n of this.Bm)this.uw()&&(i=Math.max(i,l(n.rm()).ev(),this.Ps.leftPriceScale.minimumWidth)),this.cw()&&(s=Math.max(s,l(n.hm()).ev(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Va();i=ds(i),s=ds(s);const n=this.Ma,e=this.no,r=Math.max(n-i-s,0),h=1*this.Om.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Zm.Dm(),this.Ps.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=h+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Bm.length;++t){const n=this.Bm[t];n.Ov(this.ss.qs()[t]);let e=0,h=0;h=t===this.Bm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Va()*d*f)/f,e=Math.max(h,2),p+=e,n.lv(ns({width:r,height:e})),this.uw()&&n.Qv(i,"left"),this.cw()&&n.Qv(s,"right"),n.lf()&&this.ss.fc(n.lf(),e)}this.Zm.km(ns({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Aa(r),this.zm!==i&&(this.zm=i),this.$m!==s&&(this.$m=s)}Gm(t){t?this.kf.addEventListener("wheel",this.Ym,{passive:!1}):this.kf.removeEventListener("wheel",this.Ym)}gw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Xm(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.gw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.kf.getBoundingClientRect().left;this.ti().yc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Sc(-80*s)}rw(t,i){const s=t.en();3===s&&this.bw(),3!==s&&2!==s||(this.Mw(t),this.yw(t,i),this.Zm.Tt(),this.Bm.forEach(t=>{t.zv()}),3===this.Hm?.en()&&(this.Hm.mn(t),this.bw(),this.Mw(this.Hm),this.yw(this.Hm,i),t=this.Hm,this.Hm=null)),this.av(t)}yw(t,i){for(const s of t.vn())this.wn(s,i)}Mw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Ja()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Eu();break;case 1:s.Bu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Su();break;case 5:t.Ht.Ru(i)||s.fn(t.Ht.Fu(i))}}Ju(t){null!==this.Hm?this.Hm.mn(t):this.Hm=t,this.Nm||(this.Nm=!0,this.Wm=window.requestAnimationFrame(t=>{if(this.Nm=!1,this.Wm=0,null!==this.Hm){const i=this.Hm;this.Hm=null,this.rw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Ru(t)){this.ti().un(s.Ht);break}}}))}bw(){this.tw()}nw(t){this.jm.removeChild(t.Kp()),t.m()}tw(){const t=this.ss.qs(),i=t.length,s=this.Bm.length;for(let t=i;t<s;t++){const t=h(this.Bm.pop());this.jm.removeChild(t.Kp()),t.Kv().u(this),t.Zv().u(this),t.m();const i=this.Om.pop();void 0!==i&&this.nw(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Kv().i(this.Sw.bind(this,i),this),i.Zv().i(this.xw.bind(this,i),this),this.Bm.push(i),n>0){const t=new Ms(this,n-1,n);this.Om.push(t),this.jm.insertBefore(t.Kp(),this.Zm.Kp())}this.jm.insertBefore(i.Kp(),this.Zm.Kp())}for(let s=0;s<i;s++){const i=t[s],n=this.Bm[s];n.lf()!==i?n.Ov(i):n.Bv()}this.iw(),this.ww()}Cw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().$r(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.e_ instanceof Ut?h.e_:void 0,o=null!==h&&void 0!==h.r_?h.r_.Gn:void 0,a=this.Pw(n);return{Tw:r,Re:t??void 0,kw:i??void 0,Dw:-1!==a?a:void 0,Rw:l,Fw:e,Iw:o,Vw:s??void 0}}Pw(t){let i=-1;if(t)i=this.Bm.indexOf(t);else{const t=this.ti().cc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Sw(t,i,s,n){this.xv.p(()=>this.Cw(i,s,n,t))}xw(t,i,s,n){this.Cv.p(()=>this.Cw(i,s,n,t))}Km(t,i,s){this.pw(this.ti().oc()?.l_??null),this.Ku.p(()=>this.Cw(t,i,s))}iw(){const t=this.Ps.timeScale.visible?"":"none";this.Zm.Kp().style.display=t}uw(){return this.Bm[0].lf().Ha().W().visible}cw(){return this.Bm[0].lf().Na().W().visible}Jm(){return"ResizeObserver"in window&&(this.Um=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.Qm(i.contentRect.width,i.contentRect.height)}),this.Um.observe(this.Ff,{box:"border-box"}),!0)}ew(){null!==this.Um&&this.Um.disconnect(),this.Um=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function 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],Tw: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],Tw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function Qs(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw: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],Tw: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),o=Math.min(...r),a=r[r.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,Tw:n,ne:d,R:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Lw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Xs(t)}(n,h)?en({gt:i,Re:s,Tw:e},n):en(t(i,s,n,e,r),n)}function hn(t){return{Candlestick:rn(tn),Bar:rn(Qs),Area:rn(Zs),Baseline:rn(Js),Histogram:rn(Ks),Line:rn(Ks),Custom:rn(sn)}[t]}function ln(t){return{Re:0,Aw:new Map,Nh:t}}function on(t,i){if(void 0!==t&&0!==t.length)return{Ew:i.key(t[0].gt),Bw:i.key(t[t.length-1].gt)}}function an(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Tw)}),h(i)}class _n{constructor(t){this.Ow=new Map,this.Ww=new Map,this.zw=new Map,this.$w=[],this.__=t}m(){this.Ow.clear(),this.Ww.clear(),this.zw.clear(),this.$w=[]}Hw(t,i){let s=0!==this.Ow.size,n=!1;const e=this.Ww.get(t);if(void 0!==e)if(1===this.Ww.size)s=!1,n=!0,this.Ow.clear();else for(const i of this.$w)i.pointData.Aw.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.__.createConverterToInternalObj(i),h=hn(t.Rr()),l=t.dl(),o=t.fl();r=i.map((i,r)=>{const a=e(i.time),_=this.__.key(a);let u=this.Ow.get(_);void 0===u&&(u=ln(a),this.Ow.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Aw.set(t,c),c})}s&&this.Nw(),this.Uw(t,r);let h=-1;if(n){const t=[];this.Ow.forEach(i=>{t.push({timeWeight:0,time:i.Nh,pointData:i,originalTime:an(i.Aw)})}),t.sort((t,i)=>this.__.key(t.time)-this.__.key(i.time)),h=this.qw(t)}return this.jw(t,h,function(t,i,s){const n=on(t,s),e=on(i,s);if(void 0!==n&&void 0!==e)return{Yw:!1,Bh:n.Bw>=e.Bw&&n.Ew>=e.Ew}}(this.Ww.get(t),e,this.__))}Ec(t){return this.Hw(t,[])}Xw(t,i,s){const n=i;!function(t){void 0===t.Tw&&(t.Tw=t.time)}(n),this.__.preprocessData(i);const e=this.__.createConverterToInternalObj([i])(i.time),r=this.zw.get(t);if(!s&&void 0!==r&&this.__.key(e)<this.__.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ow.get(this.__.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=ln(e),this.Ow.set(this.__.key(e),h));const o=hn(t.Rr()),a=t.dl(),_=t.fl(),u=o(e,h.Re,i,n.Tw,a,_);h.Aw.set(t,u),s?this.Gw(t,u,h.Re):this.Kw(t,u);const c={Bh:nn(u),Yw:s};if(!l)return this.jw(t,-1,c);const d={timeWeight:0,time:h.Nh,pointData:h,originalTime:an(h.Aw)},p=yt(this.$w,this.__.key(d.time),(t,i)=>this.__.key(t.time)<i);this.$w.splice(p,0,d);for(let t=p;t<this.$w.length;++t)un(this.$w[t].pointData,t);return this.__.fillWeightsForPoints(this.$w,p),this.jw(t,p,c)}Zw(t,i){const s=this.Ww.get(t);if(void 0===s||i<=0)return[[],this.Jw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.zw.delete(t):this.zw.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ow.get(this.__.key(i.gt));if(s&&(s.Aw.delete(t),0===s.Aw.size)){this.Ow.delete(this.__.key(s.Nh)),this.$w.splice(s.Re,1);for(let t=s.Re;t<this.$w.length;++t)un(this.$w[t].pointData,t)}}return[n,this.jw(t,this.$w.length-1,{Yw:!1,Bh:!1})]}Kw(t,i){let s=this.Ww.get(t);void 0===s&&(s=[],this.Ww.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.__.key(i.gt)>this.__.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.zw.set(t,i.gt)}Gw(t,i,s){const n=this.Ww.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);nn(i)?n[e]=i:n.splice(e,1)}Uw(t,i){0!==i.length?(this.Ww.set(t,i.filter(nn)),this.zw.set(t,i[i.length-1].gt)):(this.Ww.delete(t),this.zw.delete(t))}Nw(){for(const t of this.$w)0===t.pointData.Aw.size&&this.Ow.delete(this.__.key(t.time))}qw(t){let i=-1;for(let s=0;s<this.$w.length&&s<t.length;++s){const n=this.$w[s],e=t[s];if(this.__.key(n.time)!==this.__.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.$w.length!==t.length&&(i=Math.min(this.$w.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.__.fillWeightsForPoints(t,i),this.$w=t,i}Qw(){if(0===this.Ww.size)return null;let t=0;return this.Ww.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}jw(t,i,s){const n=this.Jw();if(-1!==i)this.Ww.forEach((i,e)=>{n.Wa.set(e,{ne:i,tg:e===t?s:void 0})}),this.Ww.has(t)||n.Wa.set(t,{ne:[],tg:s}),n.At.ig=this.$w,n.At.sg=i;else{const i=this.Ww.get(t);n.Wa.set(t,{ne:i||[],tg:s})}return n}Jw(){return{Wa:new Map,At:{uu:this.Qw()}}}}function un(t,i){t.Re=i,t.Aw.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.Uh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);if(!s)return{from:r,to:h};let l=r,o=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(o=h+1),{from:l,to:o}}class fn{constructor(t,i,s){this.ng=!0,this.eg=!0,this.rg=!0,this.hg=[],this.lg=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.ng=!0,"data"===t&&(this.eg=!0),"options"===t&&(this.rg=!0)}Dt(){return this.Qn.It()?(this.ag(),null===this.lg?null:this._g):null}ug(){this.hg=this.hg.map(t=>({...t,...this.Qn.Rh().Fr(t.gt)}))}cg(){this.lg=null}ag(){this.eg&&(this.dg(),this.eg=!1),this.rg&&(this.ug(),this.rg=!1),this.ng&&(this.pg(),this.ng=!1)}pg(){const t=this.Qn.$t(),i=this.te.At();if(this.cg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Br())return;const n=this.Qn.Bt();null!==n&&(this.lg=pn(this.hg,s,this.og),this.fg(t,i,n.Ht),this.vg())}}class vn{constructor(t,i){this.mg=t,this.Yi=i}et(t,i,s){this.mg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.nh=s,this._g=new vn(this.nh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}pl(t){return this.nh.priceValueBuilder(t)}vl(t){return this.nh.isWhitespace(t)}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re),wg:i.ne}))}fg(t,i){i.cu(this.hg,m(this.lg))}vg(){this.nh.update({bars:this.hg.map(wn),barSpacing:this.te.At().wu(),visibleRange:this.lg},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.wg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=o(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),i}function yn(t){const i=Mn(t);return void 0!==t.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.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),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.Tw;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.Hp=t,this.gg=i,this.bg=s??0}applyOptions(t){this.Hp.ti()._c(this.gg,t,this.bg)}options(){return this.Yi().W()}width(){return j(this.gg)?this.Hp._w(this.gg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().No(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().Ql()){const n=this.Yi().va(),e=Bi(n);s=oi(s,this.Yi().so()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Hp.ti().uc(this.gg,this.bg)).$t}}class Bn{constructor(t,i,s,n){this.Hp=t,this.Pt=s,this.Mg=i,this.yg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Hp.ti(),s=i.Uc(this.Pt);i.mc(s,t)}getStretchFactor(){return this.Pt.Va()}setStretchFactor(t){this.Pt.La(t),this.Hp.ti().Lh()}paneIndex(){return this.Hp.ti().Uc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Hp.Up().length,"Invalid pane index"),this.Hp.ti().gc(i,t))}getSeries(){return this.Pt.Wa().map(t=>this.Mg(t))??[]}getHTMLElement(){const t=this.Hp.Up();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Kp():null}attachPrimitive(t){this.Pt.ul(t),t.attached&&t.attached({chart:this.yg,requestUpdate:()=>this.Pt.ti().Lh()})}detachPrimitive(t){this.Pt.cl(t)}priceScale(t){if(null===this.Pt.Fa(t))throw new Error(`Cannot find price scale with id: ${t}`);return new En(this.Hp,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Ba(t)}preserveEmptyPane(){return this.Pt.Oa()}addCustomSeries(t,i={},s=0){return this.yg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.yg.addSeries(t,i,this.paneIndex())}}const On={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Wn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Sg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.xg=new a,this.Qn=t,this.Cg=i,this.Pg=s,this.__=e,this.yg=n,this.Tg=r}m(){this.xg.m()}priceFormatter(){return this.Qn.rl()}priceToCoordinate(t){const i=this.Qn.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)).T_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.$r(i.Uh(),1),e=s.$r(i.yi(),-1),r=l(s.Or()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(o.from=n.Tw,o.to=e.Tw),o}setData(t){this.__,this.Qn.Rr(),this.Cg.kg(this.Qn,t),this.Dg("full")}update(t,i=!1){this.Qn.Rr(),this.Cg.Rg(this.Qn,t,i),this.Dg("update")}pop(t=1){const i=this.Cg.Fg(this.Qn,t);0!==i.length&&this.Dg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().$r(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Ks().Nr().map(i=>t(i))}subscribeDataChanged(t){this.xg.i(t)}unsubscribeDataChanged(t){this.xg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Pg.priceScale(this.Qn.$t().wl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.Wh(i);return new Wn(s)}removePriceLine(t){this.Qn.zh(t.Sg())}priceLines(){return this.Qn.$h().map(t=>new Wn(t))}seriesType(){return this.Qn.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.ul(t),t.attached&&t.attached({chart:this.yg,series:this,requestUpdate:()=>this.Qn.ti().Lh(),horzScaleBehavior:this.__})}detachPrimitive(t){this.Qn.cl(t),t.detached&&t.detached(),this.Qn.ti().Lh()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Tg(i)}moveToPane(t){this.Qn.ti().zc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.Wa().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.t_(this.Qn,t)}Dg(t){this.xg.v()&&this.xg.p(t)}}class $n{constructor(t,i,s){this.Ig=new a,this.B_=new a,this.bm=new a,this.ss=t,this.dh=t.At(),this.Zm=i,this.dh.Iu().i(this.Vg.bind(this)),this.dh.Vu().i(this.Lg.bind(this)),this.Zm.Tm().i(this.Ag.bind(this)),this.__=s}m(){this.dh.Iu().u(this),this.dh.Vu().u(this),this.Zm.Tm().u(this),this.Ig.m(),this.B_.m(),this.bm.m()}scrollPosition(){return this.dh.bu()}scrollToPosition(t,i){i?this.dh.Du(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.dh.ku()}getVisibleRange(){const t=this.dh.eu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.__.convertHorzItemToInternal(t.from),to:this.__.convertHorzItemToInternal(t.to)},s=this.dh.ou(i);this.ss.Oc(s)}getVisibleLogicalRange(){const t=this.dh.nu();return null===t?null:{from:t.Uh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Oc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Eu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.dh.Gi()?null:this.dh.du(t)}timeToIndex(t,i){const s=this.__.convertHorzItemToInternal(t);return this.dh.tu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.dh.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.du(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Zm.Zp().width}height(){return this.Zm.Zp().height}subscribeVisibleTimeRangeChange(t){this.Ig.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Ig._(t)}subscribeVisibleLogicalRangeChange(t){this.B_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.B_._(t)}subscribeSizeChange(t){this.bm.i(t)}unsubscribeSizeChange(t){this.bm._(t)}applyOptions(t){this.dh.lr(t)}options(){return{...f(this.dh.W()),barSpacing:this.dh.wu()}}Vg(){this.Ig.v()&&this.Ig.p(this.getVisibleRange())}Lg(){this.B_.v()&&this.B_.p(this.getVisibleLogicalRange())}Ag(t){this.bm.p(t.width,t.height)}}function Hn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Nn{constructor(t,i,s){this.Eg=new Map,this.Bg=new Map,this.Og=new a,this.Wg=new a,this.zg=new a,this.ju=new WeakMap,this.$g=new _n(i);const n=void 0===s?f(An()):_(f(An()),Hn(s));this.Hg=i,this.Hp=new js(t,n,i),this.Hp.Kv().i(t=>{this.Og.v()&&this.Og.p(this.Ng(t()))},this),this.Hp.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ng(t()))},this),this.Hp.dc().i(t=>{this.zg.v()&&this.zg.p(this.Ng(t()))},this);const e=this.Hp.ti();this.Ug=new $n(e,this.Hp.sw(),this.Hg)}remove(){this.Hp.Kv().u(this),this.Hp.Zv().u(this),this.Hp.dc().u(this),this.Ug.m(),this.Hp.m(),this.Eg.clear(),this.Bg.clear(),this.Og.m(),this.Wg.m(),this.zg.m(),this.$g.m()}resize(t,i,s){this.autoSizeActive()||this.Hp.Qm(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},qg:bn,jg:t}))(o(t));return this.Yg(n,i,s)}addSeries(t,i={},s=0){return this.Yg(t,i,s)}removeSeries(t){const i=h(this.Eg.get(t)),s=this.$g.Ec(i);this.Hp.ti().Ec(i),this.Xg(s),this.Eg.delete(t),this.Bg.delete(i)}kg(t,i){this.Xg(this.$g.Hw(t,i))}Rg(t,i,s){this.Xg(this.$g.Xw(t,i,s))}Fg(t,i){const[s,n]=this.$g.Zw(t,i);return 0!==s.length&&this.Xg(n),s}subscribeClick(t){this.Og.i(t)}unsubscribeClick(t){this.Og._(t)}subscribeCrosshairMove(t){this.zg.i(t)}unsubscribeCrosshairMove(t){this.zg._(t)}subscribeDblClick(t){this.Wg.i(t)}unsubscribeDblClick(t){this.Wg._(t)}priceScale(t,i=0){return new En(this.Hp,t,i)}timeScale(){return this.Ug}applyOptions(t){this.Hp.lr(Hn(t))}options(){return this.Hp.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Hp.ti().W().crosshair.mode,this.Hp.lr({crosshair:{mode:2}})),n=this.Hp.ow(t)}finally{i||void 0===s||this.Hp.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Hp.ti().qc();return i.Ba(t),this.Gg(i)}removePane(t){this.Hp.ti().vc(t)}swapPanes(t,i){this.Hp.ti().wc(t,i)}autoSizeActive(){return this.Hp.dw()}chartElement(){return this.Hp.if()}panes(){return this.Hp.ti().qs().map(t=>this.Gg(t))}paneSize(t=0){const i=this.Hp.mw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Eg.get(s);if(void 0===n)return;const e=this.Hp.ti().Nn(n);null!==e&&this.Hp.ti().Rc(t,i,e)}clearCrosshairPosition(){this.Hp.ti().Fc(!0)}horzBehaviour(){return this.Hg}Yg(i,s={},n=0){r(void 0!==i.qg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=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.qg,l=new Ut(this.Hp.ti(),i.type,e,h,i.jg);this.Hp.ti().Lc(l,n);const o=new zn(l,this,this,this,this.Hg,t=>this.Gg(t));return this.Eg.set(o,l),this.Bg.set(l,o),o}Xg(t){const i=this.Hp.ti();i.Ic(t.At.uu,t.At.ig,t.At.sg),t.Wa.forEach((t,i)=>i.lt(t.ne,t.tg)),i.At().G_(),i.mu()}Kg(t){return h(this.Bg.get(t))}Ng(t){const i=new Map;t.Fw.forEach((t,s)=>{const n=s.Rr(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.fl();r(!t||!1===t(e))}i.set(this.Kg(s),e)});const s=void 0!==t.Rw&&this.Bg.has(t.Rw)?this.Kg(t.Rw):void 0;return{time:t.Tw,logical:t.Re,point:t.kw,paneIndex:t.Dw,hoveredSeries:s,hoveredObjectId:t.Iw,seriesData:i,sourceEvent:t.Vw}}Gg(t){let i=this.ju.get(t);return i||(i=new Bn(this.Hp,t=>this.Kg(t),t,this),this.ju.set(t,i)),i}}function Un(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function qn(t,i,s){const n=Un(t),e=new Nn(n,i,s);return i.setOptions(e.options()),e}function jn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Gl:r,Zg:n.time-h.time}}function Yn(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=jn(t,i);if(null===h)return null;const l=r-h.Gl;return Math.round(h.gt+l*h.Zg)}function Xn(t,i,s){if(null==s)return null;const n=t.timeScale(),e=n.timeToCoordinate(s);if(null!==e)return e;if("number"!=typeof s)return null;const r=jn(t,i);if(null===r)return null;const h=r.Gl+(s-r.gt)/r.Zg,l=n.logicalToCoordinate(h);return null===l?null:l}class Gn extends fn{constructor(t,i){super(t,i,!0)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.jo(this.hg,s,m(this.lg))}Jg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>{const s=i.Ht[3];return this.Qg(i.Re,s,t)})}}function Kn(t,i,s,n,e,r,h){if(0===i.length||n.from>=i.length||n.to<=0)return;const{context:l,horizontalPixelRatio:o,verticalPixelRatio:a}=t,_=i[n.from];let u=r(t,_),c=_;if(n.to-n.from<2){const i=e/2;l.beginPath();const s={ut:_.ut-i,ct:_.ct},n={ut:_.ut+i,ct:_.ct};l.moveTo(s.ut*o,s.ct*a),l.lineTo(n.ut*o,n.ct*a),h(t,u,s,n)}else{const e=(i,s)=>{h(t,u,c,s),l.beginPath(),u=i,c=s};let d=c;l.beginPath(),l.moveTo(_.ut*o,_.ct*a);for(let h=n.from+1;h<n.to;++h){d=i[h];const n=r(t,d);switch(s){case 0:l.lineTo(d.ut*o,d.ct*a);break;case 1:l.lineTo(d.ut*o,i[h-1].ct*a),n!==u&&(e(n,d),l.lineTo(d.ut*o,i[h-1].ct*a)),l.lineTo(d.ut*o,d.ct*a);break;case 2:{const[t,s]=te(i,h-1,h);l.bezierCurveTo(t.ut*o,t.ct*a,s.ut*o,s.ct*a,d.ut*o,d.ct*a);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*o,d.ct*a))}(c!==d||c===d&&1===s)&&h(t,u,c,d)}}const Zn=6;function Jn(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function Qn(t,i){return{ut:t.ut/i,ct:t.ct/i}}function te(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=Qn(Jn(t[s],t[n]),Zn),{ut:r.ut+h.ut,ct:r.ct+h.ct}),Jn(t[s],Qn(Jn(t[e],t[i]),Zn))]}function ie(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class se extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,tb:e,ib:r,dt:h,Kt:l,sb:o}=this.ht;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=h*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.nb.bind(this);void 0!==r&&Kn(t,i,r,s,e,_,ie),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let o=null;const a=Math.max(1,Math.floor(r))%2/2,_=s*h+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(l.beginPath(),null!==o&&l.fill(),l.fillStyle=i,o=i);const s=Math.round(n.ut*r)+a,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class ne extends se{nb(t,i){return i.wt}}class ee extends Gn{constructor(){super(...arguments),this._g=new ne}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t=this.Qn.W(),i={_t:this.hg,Kt:t.lineStyle,ib:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.lg,tb:this.te.At().wu()};this._g.lt(i)}}const re={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ee(t,i)};function he(t,i){return t.weight>i.weight?t:i}function le(t){return t}class oe{constructor(){this.eb=new a,this.rb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.eb.p(this.hb)),this.hb=0}lb(){return this.eb}m(){this.eb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.rb(),t=>(t>this.hb&&(this.hb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.ob(t)}formatTickmark(t){return this.ob(t.time)}maxTickMarkWeight(t){return t.reduce(he,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(le(t[n].time));this.hb=t[t.length-1].time,this.rb()}ob(t){if(this.Ps.localization?.timeFormatter)return this.Ps.localization.timeFormatter(t);if(t<12)return`${t}M`;const i=Math.floor(t/12),s=t%12;return 0===s?`${i}Y`:`${i}Y${s}M`}}const ae={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},_e={lastValueVisible:!1,priceLineVisible:!1};class ue extends Nn{constructor(t,i){const s=_(ae,i||{}),n=new oe;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={..._e,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(re);let s;function n(n){const e=function(t,i){return{ae:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),ab:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ab:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ab:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.lb().i(n)}}function ce(t,i){return t.weight>i.weight?t:i}class de{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(ce,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 pe(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 fe extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,tb:e,dt:r,Kt:h,ib:l}=this.ht,o=this.ht._b??(this.ht.ub?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,n(a,h),a.lineWidth=1,Kn(t,i,l,s,e,this.cb.bind(this),pe.bind(null,o))}}class ve{pb(t,i){const s=this.fb,{mb:n,wb:e,gb:r,bb:h,_b:l,Mb:o,yb:a}=i;if(void 0===this.Sb||void 0===s||s.mb!==n||s.wb!==e||s.gb!==r||s.bb!==h||s._b!==l||s.Mb!==o||s.yb!==a){const{verticalPixelRatio:s}=t,_=l||o>0?s:1,u=o*_,c=a===t.bitmapSize.height?a:a*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Sb=p,this.fb=i}return this.Sb}}class me extends fe{constructor(){super(...arguments),this.xb=new ve}cb(t,i){const s=this.ht;return this.xb.pb(t,{mb:i.yr,wb:i.Sr,gb:i.Cr,bb:i.Pr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class we extends se{constructor(){super(...arguments),this.Cb=new ve}nb(t,i){const s=this.ht;return this.Cb.pb(t,{mb:i.br,wb:i.br,gb:i.Mr,bb:i.Mr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class ge extends Gn{constructor(t,i){super(t,i),this._g=new x,this.Pb=new me,this.Tb=new we,this._g.nt([this.Pb,this.Tb])}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){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().wu();if(null===this.lg||0===this.hg.length)return;let e,r;if(i.relativeGradient){e=this.hg[this.lg.from].ct,r=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const i=this.hg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Pb.lt({_t:this.hg,dt:i.lineWidth,Kt:i.lineStyle,ib:i.lineType,_b:s,Mb:e,yb:r,ub:!1,ot:this.lg,tb:n}),this.Tb.lt({_t:this.hg,dt:i.lineWidth,Kt:i.lineStyle,ib:i.lineVisible?i.lineType:void 0,sb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,_b:s,Mb:e,yb:r,ot:this.lg,tb:n})}}const be={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ge(t,i)};class Me extends fe{constructor(){super(...arguments),this.xb=new ve}cb(t,i){return this.xb.pb(t,{mb:i.wr,wb:"",gb:"",bb:i.gr,Mb:this.ht?.Mb??0,yb:t.bitmapSize.height})}}class ye extends Gn{constructor(t,i){super(t,i),this._g=new x,this.kb=new Me,this.Db=new ne,this._g.nt([this.kb,this.Db])}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t=this.Qn.W();if(null===this.lg||0===this.hg.length)return;let i;if(t.relativeGradient){i=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const s=this.hg[t];s.ct<i&&(i=s.ct)}}this.kb.lt({ib:t.lineType,_t:this.hg,Kt:t.lineStyle,dt:t.lineWidth,_b:null,Mb:i,ub:t.invertFilledArea,ot:this.lg,tb:this.te.At().wu()}),this.Db.lt({ib:t.lineVisible?t.lineType:void 0,_t:this.hg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.lg,tb:this.te.At().wu(),sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const Se={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ye(t,i)};class xe extends C{constructor(){super(...arguments),this.Yt=null,this.Rb=0,this.Fb=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.Rb=this.Ib(i),this.Rb>=2){Math.max(1,Math.floor(i))%2!=this.Rb%2&&this.Rb--}this.Fb=this.Yt.Vb?Math.min(this.Rb,Math.floor(i)):this.Rb;let n=null;const e=this.Fb<=this.Rb&&this.Yt.wu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Fb),o=Math.round(h.ut*i),a=o-l,_=this.Fb,u=a+_-1,c=Math.min(h.Ko,h.Zo),d=Math.max(h.Ko,h.Zo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Fb);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Rb);if(e){if(this.Yt.Lb){const i=o-m;let n=Math.max(p,Math.round(h.Go*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Jo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Ib(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).wu,t)))}}class Ce extends fn{constructor(t,i){super(t,i,!1)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.Xo(this.hg,s,m(this.lg))}Ab(t,i,s){return{gt:t,jh:i.Ht[0],Yh:i.Ht[1],Xh:i.Ht[2],Gh:i.Ht[3],ut:NaN,Go:NaN,Ko:NaN,Zo:NaN,Jo:NaN}}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>this.Qg(i.Re,i,t))}}class Pe extends Ce{constructor(){super(...arguments),this._g=new xe}Qg(t,i,s){return{...this.Ab(t,i,s),...s.Fr(t)}}vg(){const t=this.Qn.W();this._g.lt({Ks:this.hg,wu:this.te.At().wu(),Lb:t.openVisible,Vb:t.thinBars,ot:this.lg})}}const Te={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},qg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Rb=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.Rb=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.wu,i),this.Rb>=2){Math.floor(i)%2!=this.Rb%2&&this.Rb--}const s=this.Yt.Ks;this.Yt.Eb&&this.Bb(t,s,this.Yt.ot),this.Yt.Mi&&this.cv(t,s,this.Yt.ot);const n=this.Ob(i);(!this.Yt.Mi||this.Rb>2*n)&&this.Wb(t,s,this.Yt.ot)}Bb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.wu*e));l=Math.max(Math.floor(e),Math.min(l,this.Rb));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Go,s.Jo)*r),u=Math.round(Math.max(s.Go,s.Jo)*r),c=Math.round(s.Ko*r),d=Math.round(s.Zo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}Ob(t){let i=Math.floor(1*t);this.Rb<=2*i&&(i=Math.floor(.5*(this.Rb-1)));const s=Math.max(Math.floor(t),i);return this.Rb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}cv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.pr!==h&&(n.fillStyle=s.pr,h=s.pr);let a=Math.round(s.ut*e)-Math.floor(.5*this.Rb);const _=a+this.Rb-1,u=Math.round(Math.min(s.Go,s.Jo)*r),c=Math.round(Math.max(s.Go,s.Jo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.wu*e>2*l)I(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Go,s.Jo)*r),a=Math.round(Math.max(s.Go,s.Jo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Rb),u=_+this.Rb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class De extends Ce{constructor(){super(...arguments),this._g=new ke}Qg(t,i,s){return{...this.Ab(t,i,s),...s.Fr(t)}}vg(){const t=this.Qn.W();this._g.lt({Ks:this.hg,wu:this.te.At().wu(),Eb:t.wickVisible,Mi:t.borderVisible,ot:this.lg})}}const Re={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},qg:(t,i)=>new De(t,i)};class Fe extends C{constructor(){super(...arguments),this.Yt=null,this.zb=[]}lt(t){this.Yt=t,this.zb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.zb.length||this.$b(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Hb*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.zb[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.Uh,a,l.yi-l.Uh+1,_-a)}}$b(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.zb=[]);const i=Math.ceil(this.Yt.wu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.wu*t)-i;this.zb=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.zb[i-this.Yt.ot.from]={Uh:r,yi:h,Nb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.zb[t-this.Yt.ot.from],n=this.zb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.Uh-n.yi!==i+1&&(n.Nb>n.ee?n.yi=s.Uh-i-1:s.Uh=n.yi+i+1))}let n=Math.ceil(this.Yt.wu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi<i.Uh&&(i.yi=i.Uh);const s=i.yi-i.Uh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi-i.Uh+1>n&&(i.Nb>i.ee?i.yi-=1:i.Uh+=1)}}}class Ie extends Gn{constructor(){super(...arguments),this._g=new Fe}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t={_t:this.hg,wu:this.te.At().wu(),ot:this.lg,Hb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this._g.lt(t)}}const Ve={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},qg:(t,i)=>new Ie(t,i)};class Le{constructor(t,i){this.Pt=t,this.Ub=i,this.qb()}detach(){this.Pt.detachPrimitive(this.Ub)}getPane(){return this.Pt}applyOptions(t){this.Ub.lr?.(t)}qb(){this.Pt.attachPrimitive(this.Ub)}}const Ae={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},Ee={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class Be{constructor(t){this.jb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Yb(i,t.text);e>s.width?t.Cu=s.width/e:t.Cu=1,n+=t.lineHeight*t.Cu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Cu,t.Cu),i.fillText(t.text,0,t.Xb),i.restore(),e+=t.lineHeight*t.Cu}})}Yb(t,i){const s=this.Gb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Gb(t){let i=this.jb.get(t);return void 0===i&&(i=new Map,this.jb.set(t,i)),i}}class Oe{constructor(t){this.Ps=ze(t)}Tt(t){this.Ps=ze(t)}renderer(){return new Be(this.Ps)}}function We(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Xb:0,Cu:0}}function ze(t){return{...t,lines:t.lines.map(We)}}function $e(t){return{...Ee,...t}}function He(t){return{...Ae,...t,lines:t.lines?.map($e)??[]}}class Ne{constructor(t){this.Ps=He(t),this.Kb=[new Oe(this.Ps)]}updateAllViews(){this.Kb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Kb}attached({requestUpdate:t}){this.Zb=t}detached(){this.Zb=void 0}lr(t){this.Ps=He({...this.Ps,...t}),this.Zb&&this.Zb()}}const Ue={alpha:1,padding:0};class qe{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Jb(this.Yt,t.mediaSize);s&&this.Yt.Qb&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.Qb,s.ut,s.ct,s.ts,s.qt))})}Jb(t,i){const{maxHeight:s,maxWidth:n,tM:e,iM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class je{constructor(t){this.sM=null,this.nM=0,this.eM=0,this.Ps=t,this.M=Ye(this.Ps,this.sM,this.nM,this.eM)}rM(t){void 0!==t.hM&&(this.nM=t.hM),void 0!==t.lM&&(this.eM=t.lM),void 0!==t.oM&&(this.sM=t.oM),this.Tt()}aM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Ye(this.Ps,this.sM,this.nM,this.eM)}renderer(){return new qe(this.M)}}function Ye(t,i,s,n){return{...t,Qb:i,iM:s,tM:n}}function Xe(t){return{...Ue,...t}}class Ge{constructor(t,i){this._M=null,this.uM=t,this.Ps=Xe(i),this.Kb=[new je(this.Ps)]}updateAllViews(){this.Kb.forEach(t=>t.Tt())}paneViews(){return this.Kb}attached(t){const{requestUpdate:i}=t;this.cM=i,this._M=new Image,this._M.onload=()=>{const t=this._M?.naturalHeight??1,i=this._M?.naturalWidth??1;this.Kb.forEach(s=>s.rM({lM:t,hM:i,oM:this._M})),this.cM&&this.cM()},this._M.src=this.uM}detached(){this.cM=void 0,this._M=null}lr(t){this.Ps=Xe({...this.Ps,...t}),this.dM(),this.Zb&&this.Zb()}Zb(){this.cM&&this.cM()}dM(){this.Kb.forEach(t=>t.aM(this.Ps))}}class Ke{constructor(t,i){this.Qn=t,this.ah=i,this.qb()}detach(){this.Qn.detachPrimitive(this.ah)}getSeries(){return this.Qn}applyOptions(t){this.ah&&this.ah.lr&&this.ah.lr(t)}qb(){this.Qn.attachPrimitive(this.ah)}}const Ze={autoScale:!0,zOrder:"normal"};function Je(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function Qe(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return Je(i,1);case"circle":return Je(i,.8);case"square":return Je(i,.7)}}function tr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(Je(t,1))}function ir(t){return Math.max(Je(t,.1),3)}function sr(t,i,s){return i?t:s?Math.ceil(t/2):0}function nr(t,i,s,n){const e=(Qe("arrowUp",n)-1)/2*s.pM,r=(Kt(n/2)-1)/2*s.pM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function er(t,i,s,n,e,r){const h=(Qe("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 rr(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,o=s+l*n,a=o-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),a),t.quadraticCurveTo(i,o,i+(r?h:-h),a),t.lineTo(i-_,s)}function hr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class lr{constructor(){this.Yt=null,this.Wn=new it,this.fM=new it,this.$=-1,this.H="",this.Hf="",this.vM="",this.mM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Hf=g(t,i),this.vM=g(t,i,"600"),this.Wn.Vn(),this.fM.Vn()),this.mM=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&&ar(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.mM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.mM&&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.wM;if(t.font=r?this.vM:this.Hf,void 0!==e.hi){const i=r?this.fM:this.Wn;e.hi.ts=i.Ii(t,e.hi.gM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.wM){const t=void 0!==e.hi?e.hi.ts:0;e.wM.ts=Math.max(t+2*e.wM.bM,e.wM.qt),e.wM.Uh=e.ut-e.wM.ts/2}or(e,t,i,s)}}}}function or(t,i,s,n){void 0===t.wM?(i.fillStyle=t.R,void 0!==t.hi&&hr(i,t.hi.gM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Br)return;switch(t.MM){case"arrowDown":return void nr(!1,i,s,t.Br);case"arrowUp":return void nr(!0,i,s,t.Br);case"circle":return void function(t,i,s){const n=(Qe("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.pM,0,2*Math.PI,!1),t.fill()}(i,s,t.Br);case"square":return void function(t,i,s){const n=Qe("square",s),e=(n-1)*i.pM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.pM,n*i.pM)}(i,s,t.Br);case"tag":return}t.MM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,pM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Br)return;(function(t,i){const s=i.yM,n=i.SM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.xM-i.qt/2)*n),l=Math.round((i.xM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.CM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.PM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.PM&&rr(t,o,h,_,u,!0),t.lineTo(r-a,h),t.arcTo(r,h,r,h+a,a),t.lineTo(r,l-a),t.arcTo(r,l,r-a,l,a),"down"===i.PM&&rr(t,o,l,_,u,!1),t.lineTo(e+a,l),t.arcTo(e,l,e,l-a,a),t.lineTo(e,h+a),t.arcTo(e,h,e+a,h,a)):L(t,e,h,r-e,l-h,[a,a,a,a]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,xM:t.ct,ts:i.ts,qt:i.qt,CM:i.CM,PM:i.PM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,yM:n,SM:e}),void 0!==t.hi&&(s.fillStyle=t.TM??"#FFFFFF",hr(s,t.hi.gM,t.hi.ut,t.hi.ct,n,e))}(t,t.wM,i,s,n)}function ar(t,i,s){return void 0!==t.wM?0!==t.Br&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.PM?i-r-s.CM:i-r,l="down"===s.PM?i+r+s.CM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.wM,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.Br)return!1;switch(t.MM){case"arrowDown":return er(!0,t.ut,t.ct,t.Br,i,s);case"arrowUp":return er(!1,t.ut,t.ct,t.Br,i,s);case"circle":return function(t,i,s,n,e){const r=2+Qe("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Br,i,s);case"square":return function(t,i,s,n,e){const r=Qe("square",s),h=(r-1)/2,l=t-h,o=i-h;return n>=l&&n<=l+r&&e>=o&&e<=o+r}(t.ut,t.ct,t.Br,i,s);case"tag":return!1}}(t,i,s)}function _r(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function ur(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(_r(i.position)&&void 0!==i.price)return i.price;if("value"in(n=t)&&"number"==typeof n.value)return t.value;var n;if(function(t){return"open"in t&&"high"in t&&"low"in t&&"close"in t}(t)){if("inBar"===i.position)return t.close;if("aboveBar"===i.position)return s?t.low:t.high;if("belowBar"===i.position)return s?t.high:t.low}}(s,i,a);if(void 0===_)return;const c=_r(i.position),d=o.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),o=Math.round(7*h),a=_r(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.kM)-o-_,a||(n.kM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.DM)+o+_,a||(n.DM+=l+o+r)}const d={qt:l,CM:o,PM:u,vt:i.borderRadius??6,bM:9*h,Uh:0,ts:0};t.Br=l,t.ct=c,t.wM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=tr(d.options().barSpacing)*p,v=f/2;t.Br=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.kM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.kM+=1.2*e),void(c||(n.kM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.DM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.DM+=1.2*e),void(c||(n.DM+=f+r))}}}class cr{constructor(t,i,s){this.RM=[],this.xt=!0,this.FM=!0,this.Jt=new lr,this.be=t,this.If=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.IM();const t=this.If.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}VM(t){this.RM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.FM=!0)}LM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}IM(){const t=this.If.timeScale(),i=this.RM;this.FM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Br:0,MM:t.shape,R:t.color,Gn:t.id,AM:t.AM,hi:void 0,TM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,wM:void 0})),this.FM=!1);const s=this.If.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=ir(t.options().barSpacing),a={kM:o,DM:o};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&&(a.kM=o,a.DM=o,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={gM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&ur(_,e,u,a,s.fontSize,o,this.be,this.If,r)}this.xt=!1}}function dr(t){return{...Ze,...t}}class pr{constructor(t){this.nh=null,this.RM=[],this.EM=[],this.BM=null,this.be=null,this.If=null,this.OM=!0,this.WM=null,this.zM=null,this.$M=null,this.HM=!0,this.Ps=dr(t)}attached(t){this.NM(),this.If=t.chart,this.be=t.series,this.nh=new cr(this.be,l(this.If),this.Ps),this.cM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Dg(t)),this.HM=!0,this.Zb()}Zb(){this.cM&&this.cM()}detached(){this.be&&this.BM&&this.be.unsubscribeDataChanged(this.BM),this.If=null,this.be=null,this.nh=null,this.BM=null}VM(t){this.HM=!0,this.RM=t,this.NM(),this.OM=!0,this.zM=null,this.Zb()}UM(){return this.RM}paneViews(){return this.nh?[this.nh]:[]}updateAllViews(){this.qM()}hitTest(t,i){return this.nh?this.nh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.nh){const t=this.jM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=dr({...this.Ps,...t}),this.Zb&&this.Zb()}jM(){const t=l(this.If).timeScale().options().barSpacing;if(this.OM||t!==this.$M){if(this.$M=t,this.RM.length>0){const i=ir(t),s=1.5*tr(t)+2*i,n=this.YM();this.WM={above:sr(s,n.aboveBar,n.inBar),below:sr(s,n.belowBar,n.inBar)}}else this.WM=null;this.OM=!1}return this.WM}YM(){return null===this.zM&&(this.zM=this.RM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.zM}NM(){if(!this.HM||!this.If||!this.be)return;const t=this.If.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.EM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.EM=this.RM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),o={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,AM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Tw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.HM=!1}qM(t){this.nh&&(this.NM(),this.nh.VM(this.EM),this.nh.LM(this.Ps),this.nh.Tt(t))}Dg(t){this.HM=!0,this.Zb()}}class fr extends Ke{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this.ah.VM(t)}markers(){return this.ah.UM()}}function vr(t,i,s){const n=new fr(t,new pr(s??{}));return i&&n.setMarkers(i),n}class mr{constructor(t){this.RM=new Map,this.XM=t}GM(t,i,s){if(this.KM(i),void 0!==s){const n=window.setTimeout(()=>{this.RM.delete(i),this.ZM()},s),e={...t,JM:n,QM:Date.now()+s};this.RM.set(i,e)}else this.RM.set(i,{...t,JM:void 0,QM:void 0});this.ZM()}KM(t){const i=this.RM.get(t);i&&void 0!==i.JM&&window.clearTimeout(i.JM),this.RM.delete(t),this.ZM()}ty(){for(const[t]of this.RM)this.KM(t)}iy(){const t=Date.now(),i=[];for(const[s,n]of this.RM)!n.QM||n.QM>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.KM(s);return i}sy(t){this.XM=t}ZM(){this.XM&&this.XM()}}const wr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class gr{constructor(t,i,s,n){this.Yt=t,this.ny=i,this.ey=s,this.hy=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.ly(e.oy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.oy&&(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.oy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.oy-7*e.oy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.oy)*t.verticalPixelRatio),i.stroke())})})}ly(t){return 0===t?this.ny:t>0?this.hy:this.ey}}class br{constructor(t,i,s){this.Yt=[],this.be=t,this.dh=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.dh.timeToCoordinate(t.time)),ct:i,oy: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 gr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Mr(t,i){return"Line"===i||"Area"===i}class yr{constructor(t){this.If=void 0,this.be=void 0,this.Kb=[],this.__=null,this._y=new Map,this.uy=new mr(()=>this.Zb()),this.Ps={...wr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Zb()}VM(t){this.uy.ty();const i=this.__;i&&t.forEach(t=>{this.uy.GM(t,i.key(t.time))})}UM(){return this.uy.iy()}Zb(){this.cM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.If=i,this.be=s,this.__=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Kb=[new br(this.be,this.If.timeScale(),this.Ps)],this.cM=n,this.Zb()}detached(){this.If=void 0,this.be=void 0,this.cM=void 0}jf(){return h(this.If)}Wa(){return h(this.be)}updateAllViews(){this.Kb.forEach(t=>t.Tt(this.UM()))}paneViews(){return this.Kb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this._y.clear();const s=this.__;s&&t.forEach(t=>{Gs(t)&&Mr(0,i)&&this._y.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.__)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.__.key(t.time);if(Xs(t)&&this._y.delete(n),Gs(t)&&Mr(0,s)){const i=this._y.get(n);i&&this.uy.GM({time:t.time,value:t.value,sign:Sr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}py(){this.uy.ty()}}function Sr(t,i){return t===i?0:t-i>0?1:-1}class xr extends Ke{setData(t){return this.ah.lt(t)}update(t,i){return this.ah.Tt(t,i)}markers(){return this.ah.UM()}setMarkers(t){return this.ah.VM(t)}clearMarkers(){return this.ah.py()}}class Cr{constructor(t,i){this.vy=null,this.my=[],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.vy=vr(t)}addPosition(t){this.my.push(t),this.wy()}addPositions(t){this.my.push(...t),this.wy()}setPositions(t){this.my=[...t],this.wy()}closePosition(t,i,s){const n=this.my.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.wy())}removePosition(t){this.my=this.my.filter(i=>i.id!==t),this.wy()}clearPositions(){this.my=[],this.wy()}getPositions(){return this.my}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.wy()}gy(){const t=[];for(const i of this.my){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}wy(){if(this.vy){const t=this.gy();this.vy.setMarkers(t)}}detach(){this.vy&&(this.vy.detach(),this.vy=null),this.my=[]}}const Pr=new WeakMap;function Tr(t){return"string"==typeof t?t:String(t)}function kr(t,i){return Pr.get(t)?.get(Tr(i))}function Dr(t){const i=Pr.get(t);return void 0!==i&&i.size>0}const Rr="rgba(0, 0, 0, 0)";function Fr(t){switch(t.seriesType()){case"Candlestick":return Ir(t,{upColor:Rr,downColor:Rr,borderVisible:!1,wickVisible:!1});case"Bar":return Ir(t,{upColor:Rr,downColor:Rr});case"Line":return Ir(t,{color:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Ir(t,{lineColor:Rr,topColor:Rr,bottomColor:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Ir(t,{topLineColor:Rr,topFillColor1:Rr,topFillColor2:Rr,bottomLineColor:Rr,bottomFillColor1:Rr,bottomFillColor2:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Ir(t,{color:Rr});default:return Ir(t,{visible:!1})}}function Ir(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 Vr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Lr(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 Ar(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 Er(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 Br(t){return null==t?void 0:t.time}function Or(t){const{e_:i,jf:s,by:n,My:e,yy:r,Zl:h}=t,l=t.Sy??[];let o=t.W,a=[],_=new Map,u=!1;const c=(t,i)=>{if(0===i.length)return;const s=_.get(t),n=i[i.length-1];if(void 0!==s&&s.length>0){const e=i.length===s.length+1,r=i.length===s.length,h=Br(s[s.length-1])===Br(n);if(e||r&&h)return t.update(n),void _.set(t,i)}t.setData(i),_.set(t,i)},d=t=>{if(!u)try{if("full"===t||0===a.length)a=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;a.length>0&&Br(a[a.length-1])===Br(t)?a[a.length-1]=t:a.push(t)}if(0===a.length)return;const s=e(a,o);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&a.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==r&&r(o),l.some(t=>i[t]!==o[t])&&(_=new Map,d("full"))},options:()=>({...o}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,a=[]}},recalculate:()=>d("full")};return f}function Wr(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.xy,i.Cy-1,i.Py))}}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()}`}class zr{constructor(t,i,s,n){this.If=t,this.be=i,this.F_=s,this.Ty=n}draw(t){const i=this.Ty();if(!i.It||i.ky<=0)return;const s=this.F_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.If.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Dy),u=this.be.priceToCoordinate(h.Ry),c=this.be.priceToCoordinate(l.Dy),d=this.be.priceToCoordinate(l.Ry);if(null===_||null===u||null===c||null===d)continue;const p=h.Dy>=h.Ry;n.fillStyle=this.Fy(p?i.Iy:i.Vy,i.ky),n.beginPath(),n.moveTo(o*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class $r{constructor(t,i,s,n){this.Jt=new zr(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function Hr(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 Nr(t){return null!=t&&"number"==typeof t.close}function Ur(t){const i=[];let s=null,n=null;for(const e of t){if(!Nr(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}class qr{constructor(t){this.Ly=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ly.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.Ay(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}Ay(t,i,s,n){const e=i.Ey||i.startTime,r=i.By||i.endTime,h=i.R||i.color,l=i.ky||i.opacity;if(!i||!e||!r)return;const o=this.Ly.getChart().timeScale(),a=o.timeToCoordinate(e),_=o.timeToCoordinate(r);if(null===a||null===_)return;const u=a*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this.Oy(h,l),t.fillRect(u,d,c-u,p-d)}Oy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class jr{constructor(t){this.Jt=new qr(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const Yr=[{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 Xr{constructor(t,i,s={}){this.Wy=[],this.Ub=null,this.nh=null,this.If=t,this.be=i,this.Ps={sessions:s.sessions||Yr,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.zy(),this.Ps.enabled&&this.$y()}zy(){this.nh=new jr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}$y(){this.If.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Hy()}),this.Hy()}Hy(){this.Ny();const t=this.If.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.Uy(s),this.cM()}Uy(t){if(0!==t.length){for(const i of this.Ps.sessions)this.qy(i,t);this.Ps.showOverlaps&&this.jy(t)}}qy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Yy(i);this.Xy(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Gy(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.Gy(s,n[n.length-1].time,t)}jy(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.Ky(e,r);h&&this.Zy(h,t)}}Ky(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{ae:s,_e:n}:null}Zy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Yy(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Jy(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.Jy(s,n[n.length-1].time)}Gy(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",Ey:t,By:i,R:s.color,ky:s.opacity,Qy:s.name};this.Wy.push(n)}Jy(t,i){const s={an:"overlap",Ey:t,By:i,R:this.Ps.overlapColor,ky:this.Ps.overlapOpacity,Qy:"Overlap"};this.Wy.push(s)}Xy(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}Yy(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}Ny(){this.Wy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Hy():this.Ny(),this.cM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Hy(),this.cM()}disable(){this.Ps.enabled=!1,this.Ny(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.Ny(),this.cM()}getSessionBoxes(){return this.Wy}getChart(){return this.If}getSeries(){return this.be}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.If.timeScale().applyOptions({})}}class Gr{constructor(t){this.Ly=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ly.getProfileData();if(!s||0===s.bins.length)return;const n=this.Ly.options(),e=this.Ly.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let o=0;for(const t of s.bins)t.volume>o&&(o=t.volume);if(0!==o){for(const r of s.bins)this.tS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.iS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.sS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}tS(t,i,s,n,e,r,h,l,o,a){const _=i.volume/e*n,u=r.binSize/2,c=l.priceToCoordinate(i.priceLevel+u),d=l.priceToCoordinate(i.priceLevel-u);if(null===c||null===d)return;const p=Math.max(Math.abs(d-c)-1,1),f=s*o,v=Math.min(c,d)*a,m=_*o,w=p*a,g=i.priceLevel>=r.valueAreaLow&&i.priceLevel<=r.valueAreaHigh,b=Math.abs(i.priceLevel-r.poc)<1e-5;let M=h.profileColor||"#2962FF",y=h.opacity||.3;b?(M=h.pocColor||"#FF6B00",y=.6):g&&h.showValueArea&&(M=h.valueAreaColor||"#089981",y=.4),t.fillStyle=this.Oy(M,y),t.fillRect(f,v,m,w)}iS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const o=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,o),t.lineTo(e*r,o),t.stroke(),t.setLineDash([])}sS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Oy(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}const a=e.priceToCoordinate(s);if(null!==a){const i=a*l;t.strokeStyle=this.Oy(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([])}Oy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Kr{constructor(t){this.Jt=new Gr(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Zr{constructor(t,i,s={}){this.nS=null,this.eS=new Map,this.Ub=null,this.nh=null,this.If=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.zy(),this.$y()}zy(){this.nh=new Kr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}$y(){this.If.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.rS()}),this.rS()}setVolumeData(t){this.eS=t,this.rS()}addVolumeData(t,i){this.eS.set(t,i),this.rS()}rS(){const t=this.If.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.eS.get(t.time)||1,e=Math.floor((i-n)/r);h[Math.max(0,Math.min(this.Ps.numberOfBins-1,e))].volume+=s,l+=s}for(const t of h)t.percentage=l>0?t.volume/l*100:0;let o=h[0];for(const t of h)t.volume>o.volume&&(o=t);const a=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<a))break;c.push(t),u+=t.volume}let d=-1/0,p=1/0;for(const t of c)t.priceLevel>d&&(d=t.priceLevel),t.priceLevel<p&&(p=t.priceLevel);this.nS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.cM()}getProfileData(){return this.nS}applyOptions(t){this.Ps={...this.Ps,...t},this.rS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.nS=null,this.eS.clear(),this.cM()}getChart(){return this.If}getSeries(){return this.be}options(){return this.Ps}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.If.timeScale().applyOptions({})}}class Jr{constructor(t,i){this.hS=new Map,this.lS=null,this.oS=null,this.aS=null,this._S=null,this.uS=null,this.cS=null,this.dS=null,this.bg=void 0,this.If=t,this.kf=i,this.pS=t=>this.fS(t),this.vS=t=>this.mS(t),this.wS=t=>this.gS(t),this.bS=t=>this.MS(t),this.yS=()=>this.SS(),this.xS=t=>{"Escape"===t.key&&this.SS()},this.If.subscribeCrosshairMove(this.pS),this.kf.addEventListener("pointerdown",this.vS),this.kf.addEventListener("pointermove",this.wS),this.kf.addEventListener("pointerup",this.bS),this.kf.addEventListener("pointercancel",this.yS),document.addEventListener("keydown",this.xS)}CS(t){this.hS.set(t.id(),t)}PS(t){const i=t.id();this.lS===i&&this.TS(null),this.aS===t&&this.SS(),this.hS.delete(i)}Gi(){return 0===this.hS.size}m(){this.If.unsubscribeCrosshairMove(this.pS),this.kf.removeEventListener("pointerdown",this.vS),this.kf.removeEventListener("pointermove",this.wS),this.kf.removeEventListener("pointerup",this.bS),this.kf.removeEventListener("pointercancel",this.yS),document.removeEventListener("keydown",this.xS),this.hS.clear()}fS(t){if(this.dS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.bg=t.paneIndex,null!==this.aS)return;const i=this.kS(t.hoveredObjectId),s=null===i?null:this.hS.get(i.wl)??null;this.TS(s?s.id():null),this.DS(s,null===s?null:i?.RS??null),this.FS()}mS(t){const i=null===this.lS?null:this.hS.get(this.lS)??null;i&&(this.uS={ut:t.clientX,ct:t.clientY},this.cS=i,i.isDraggable()&&(this.aS=i,this._S=t.pointerId,this.kf.setPointerCapture(t.pointerId),i.beginDrag(),this.FS(),t.preventDefault(),t.stopPropagation()))}gS(t){if(null===this.aS)return;if(!this.IS(t))return void this.SS();const i=this.VS(t);null!==i&&this.aS.dragTo(i),t.preventDefault(),t.stopPropagation()}MS(t){const i=this.aS,s=this.cS,n=this.uS;this.LS(),this.cS=null,this.uS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.aS=null,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.FS();null!==s&&!e&&s.isClickable()&&s.click()}SS(){if(null===this.aS)return;const t=this.aS;this.aS=null,this.LS(),t.cancelDrag(),this.FS()}IS(t){const i=this.kf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}LS(){null!==this._S&&(this.kf.hasPointerCapture(this._S)&&this.kf.releasePointerCapture(this._S),this._S=null)}VS(t){const i=this.aS;if(null===i)return null;const s=this.If.panes()[i.paneIndex()],n=s?s.getHTMLElement():null;return n?i.priceAt(t.clientY-n.getBoundingClientRect().top):null!==this.dS&&this.bg===i.paneIndex()?i.priceAt(this.dS.ct):null}kS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{wl:t,RS:null}:{wl:t.slice(0,i),RS:t.slice(i+1)}}DS(t,i){this.oS!==i&&(this.oS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}TS(t){this.lS!==t&&(null!==this.lS&&this.hS.get(this.lS)?.setHovered(!1),this.lS=t,this.oS=null,null!==t&&this.hS.get(t)?.setHovered(!0))}FS(){if(null!==this.aS)return void this.If.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.lS?null:this.hS.get(this.lS);t?this.If.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.If.chartElement().style.removeProperty("cursor")}}const Qr=new WeakMap;function th(t){const i=t.chartElement();if(!i)return null;let s=Qr.get(t);return s||(s=new Jr(t,i),Qr.set(t,s)),s}function ih(t,i){const s=Qr.get(t);s&&(s.PS(i),s.Gi()&&(s.m(),Qr.delete(t)))}let sh=0;class nh{constructor(t,i,s){this.sr=null,this.AS=!1,this.ES="",this.BS=null,this.If=t,this.be=i,this.yo="pipsend-trading-line-"+sh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.OS(),(this.Ps.draggable||this.Ps.onClick)&&th(this.If)?.CS(this)}id(){return this.yo}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.AS!==t&&this.sr&&(this.AS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.ES}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.BS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.WS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.BS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.BS;this.BS=null,null!==t&&t!==this.Ps.price&&(this.WS(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.ES=t.color),!this.sr)return;const i={title:this.zS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.AS||(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.WS(t)}remove(){ih(this.If,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}zS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}OS(){this.ES=this.Ps.color,this.sr=this.be.createPriceLine({id:this.yo,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.zS()})}WS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.zS()})}}class eh{constructor(t,i){this.Ff=null,this.$S=null,this.HS=null,this.NS={},this.If=t,this.be=i,this.US()}US(){this.Ff=this.If.chartElement()}qS(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.Ff?(this.$S=t,this.NS=i||{},new Promise(t=>{this.Ff.style.cursor="crosshair",this.HS=i=>{const s=this.qS(i),n=this.jS(s);this.disableClickToCreate(),t(n)},this.Ff.addEventListener("click",this.HS)})):Promise.resolve(null)}disableClickToCreate(){this.Ff&&this.HS&&(this.Ff.removeEventListener("click",this.HS),this.Ff.style.cursor="default"),this.$S=null,this.HS=null,this.NS={}}jS(t){if(!this.$S)return null;let i;switch(this.$S){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.NS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.NS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.NS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.NS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.NS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.NS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.NS};break;default:return null}return new nh(this.If,this.be,i)}getCreationMode(){return this.$S}isCreating(){return null!==this.$S}}const rh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},hh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},lh=["takeProfit","entry","stopLoss"];class oh{constructor(){this.Yt=null,this.YS=[],this.XS=0,this.Hf="",this.Co=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.YS)if(s.GS&&t>=s.KS&&t<=s.ZS&&Math.abs(i-s.ct)<=s.qt/2)return{sn:s.sn,RS:"close"};for(const s of this.YS)if(t>=s.JS&&t<=s.QS&&Math.abs(i-s.ct)<=s.qt/2)return{sn:s.sn,RS:"body"};for(const t of this.YS)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,RS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.rw(t))}rw(t){const i=this.Yt;if(this.YS=[],null===i||0===i.tx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Hf!==i.T&&(this.Hf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.XS=Math.max(0,n.width-i.bu);const e=i.ix?this.XS:n.width;for(const s of i.tx)this.YS.push(this.sx(t,i,s,e));i.ix&&i.tx.length>1&&this.nx(t,i),s.restore()}sx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.hx,o=0===s.lx.length?0:Math.max(this.Wn.Ii(e,s.lx)+2*i.bM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.bM,_=s.GS?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct-l/2;this.ox(t,s,d,c,n),this._x(t,i,s,{Uh:d,ux:p,ts:u,qt:l});let f=d;return o>0&&(this.vx(t,i,s,{Uh:f,ux:p,ts:o,qt:l}),f+=o,this.mx(e,s.R,f,p,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.TM??s.R,e.fillText(s.hi,f+a/2,s.ct),e.restore(),f+=a,s.GS&&(this.mx(e,s.R,f,p,l,r,h),this.wx(t,i,s,{Uh:f,ux:p,ts:_,qt:l})),{sn:s.sn,ct:s.ct,qt:l,JS:d,QS:c,KS:f,ZS:f+_,GS:s.GS}}ox(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=Math.max(1,Math.round(i.dt*o)),_=Math.round(i.ct*o)-Math.floor(a/2);h.save(),h.strokeStyle=i.R,h.lineWidth=a,n(h,i.Kt),h.beginPath(),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()}_x(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.gx===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),ah(e,n,i.bx,r,h),e.fillStyle=this.Co.X(i.Z,i.Mx),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}vx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.yx){const t=i.Wt;e.save(),ah(e,{Uh:n.Uh+t,ux:n.ux+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.bx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.yx?i.Sx:s.R,e.fillText(s.lx,n.Uh+n.ts/2,n.ux+n.qt/2),e.restore()}mx(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.Co.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}wx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.gx===s.sn&&"close"===i.xx){e.save();const t=i.Wt;ah(e,{Uh:n.Uh,ux:n.ux+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.bx-t),r,h,"right"),e.fillStyle=this.Co.X(s.R,.25),e.fill(),e.restore()}const l=(n.Uh+n.ts/2)*r,o=(n.ux+n.qt/2)*h,a=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-a,o-a),e.lineTo(l+a,o+a),e.moveTo(l+a,o-a),e.lineTo(l-a,o+a),e.stroke(),e.restore()}nx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.tx.find(t=>"entry"===t.sn)??i.tx[0],h=i.tx.map(t=>t.ct),l=Math.round(this.XS*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.tx)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.Co.X(i.Z,i.Mx),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function ah(t,i,s,n,e,r="all"){const h=Math.round(i.Uh*n),l=Math.round(i.ux*e),o=Math.round(i.ts*n),a=Math.round(i.qt*e),_=Math.min(s*n,o/2,a/2);L(t,h,l,o,a,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class _h{constructor(){this.Jt=new oh,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 uh{constructor(t){this.Qt=t}coordinate(){return this.Cx()?.Li??-1e3}text(){return this.Cx()?.hi??""}textColor(){return this.Cx()?.TM??"#FFFFFF"}backColor(){return this.Cx()?.R??"#000000"}visible(){return null!==this.Cx()}Cx(){return this.Qt()}}let ch=0;class dh{constructor(t,i,s){this.nh=new _h,this.Co=new S([]),this.Px=!1,this.Tx=null,this.oS=null,this.kx=null,this.BS=null,this.If=t,this.be=i,this.yo="pipsend-position-line-"+ch++,this.Ps=s,this.Rf={...hh,...s.theme},this.Kb=[this.nh],this.Dx=lh.map(t=>new uh(()=>this.Rx(t))),this.be.attachPrimitive(this),th(this.If)?.CS(this)}attached(t){this.cM=t.requestUpdate,this.Px=!0,this.requestUpdate()}detached(){this.Px=!1,this.cM=void 0}paneViews(){return this.Kb}priceAxisViews(){return this.Dx}updateAllViews(){this.nh.Tt(this.Fx())}hitTest(t,i){const s=this.nh.Xn(t,i);if(null===s)return null;const n=this.Ix(s.sn);return null===n?null:{externalId:`${this.yo}#${s.sn}:${s.RS}`,zOrder:"top",cursorStyle:"close"===s.RS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.yo}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.Tx===n&&this.oS===e||(this.Tx=n,this.oS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Tx&&"close"!==this.oS&&(this.Ix(this.Tx)?.draggable??!0)}isClickable(){return"close"===this.oS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){if(this.kx=this.Tx,null===this.kx)return;const t=this.Ix(this.kx)?.price??null;this.BS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.kx,t)}dragTo(t){null!==this.kx&&(this.Vx(this.kx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.kx,t))}commitDrag(){const t=this.kx;if(this.kx=null,this.BS=null,null===t)return;const i=this.Ix(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.kx,i=this.BS;if(this.kx=null,this.BS=null,null===t)return;null!==i&&i!==this.Ix(t)?.price&&(this.Vx(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.Ix(t)?.price??0)}click(){const t=this.Tx;if(null===t)return;if("close"===this.oS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.Ix(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.kx,s=null===i?void 0:this.Ix(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=ph(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=ph(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.Ix(i);null!==t&&(t.price=s)}t.theme&&(this.Rf={...this.Rf,...t.theme}),this.requestUpdate()}setPrice(t,i){this.kx!==t&&this.Vx(t,i)}setText(t,i){const s=this.Ix(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of lh){const s=this.Ix(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){ih(this.If,this),this.be.detachPrimitive(this)}requestUpdate(){this.cM&&this.cM()}Rx(t){const i=this.Ix(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??rh[t];return{Li:s,hi:this.be.priceFormatter().format(i.price),R:n,TM:this.Co.K(n).J}}Ix(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}Vx(t,i){const s=this.Ix(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}Fx(){if(!this.Px||!1===this.Ps.visible)return null;const t=[];for(const i of lh){const s=this.Ix(i);if(null===s||!isFinite(s.price))continue;const n=this.be.priceToCoordinate(s.price);if(null===n)continue;const e="entry"===i;t.push({sn:i,ct:n,R:s.color??rh[i],hi:s.formatText?s.formatText(s.price):s.text??"",lx:s.badge??"",yx:s.badgeFilled??e,dt:s.lineWidth??1,Kt:s.lineStyle??(e?0:2),GS:s.closable??!0,Lx:s.draggable??!0})}if(0===t.length)return null;const i=this.If.options().layout,s=this.Rf.fontSize??i.fontSize;return{tx:t,Z:this.Rf.background??(n=i.background,"solid"===n.type?n.color:n.topColor),TM:this.Rf.textColor,Sx:this.Rf.badgeTextColor,bx:this.Rf.borderRadius,Wt:this.Rf.borderWidth,bM:this.Rf.paddingX,hx:this.Rf.paddingY,Mx:this.Rf.backgroundOpacity,T:g(s,this.Rf.fontFamily??i.fontFamily),P:s,ix:!1!==this.Ps.connectorVisible&&t.length>1,bu:this.Ps.rightOffset??56,gx:this.Tx,xx:this.oS};var n}}function ph(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}const fh=new Set(["line","body","stroke","center","move"]);function vh(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?fh.has(n)?"move":"grab":void 0}}function mh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var wh;function gh(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.xy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Cy,t.day=i.day??i.Py,t}return t}function bh(t,i){const s={};return s.price=t,s.time=i,s}function Mh(t){if(!t)return bh(0,null);return bh(t.price??t.bt??0,gh(t.time??t.gt??null))}function yh(t,i="time"){return t?t[i]??null:null}function Sh(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"}(wh||(wh={}));class xh{constructor(t,i,s={}){this._state=wh.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.Ax(),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}Ax(){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 Ch=new WeakMap;function Ph(t,i){Ch.set(t,i)}function Th(t){const i=!0===Ch.get(t);return i&&Ch.set(t,!1),i}function kh(t,i,s,n,e){const r=t.canvas.width/s,h=t.canvas.height/n;if(e.ct<0||e.ct>h)return;let l;try{l=i.priceFormatter().format(e.bt)}catch(t){l=String(e.bt)}t.save(),t.font=11*s+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const o=t.measureText(l).width/s+10,a=r-o,_=e.ct-8.5;t.fillStyle=e.Ot,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.TM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Dh;!function(t){t.Ex="idle",t.Bx="waiting_first_point",t.Ox="waiting_second_point",t.Wx="completed"}(Dh||(Dh={}));class Rh{constructor(t,i,s={}){this.Iv=Dh.Ex,this.zx=null,this.HS=null,this.sp=null,this.If=t,this.be=i,this.$x=s}Hx(){this.Iv===Dh.Ex&&(this.Iv=Dh.Bx,this.zx=null,this.Nx(),this.Ux())}qx(){this.Iv=Dh.Ex,this.zx=null,this.jx(),this.Yx(),this.$x.Xx&&this.$x.Xx()}Gx(){return this.Iv}Kx(){return this.Iv===Dh.Bx||this.Iv===Dh.Ox}Nx(){this.HS=t=>{this.Zx(t)},this.If.subscribeClick(this.HS)}Ux(){this.sp=t=>{this.Jx(t)},this.If.subscribeCrosshairMove(this.sp)}jx(){this.HS&&(this.If.unsubscribeClick(this.HS),this.HS=null)}Yx(){this.sp&&(this.If.unsubscribeCrosshairMove(this.sp),this.sp=null)}Zx(t){if(!t.point)return;if(Th(this.If))return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.If,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Iv===Dh.Bx?(this.zx=n,this.Iv=Dh.Ox,this.$x.Qx&&this.$x.Qx(n)):this.Iv===Dh.Ox&&this.zx&&(this.Iv=Dh.Wx,this.$x.tC&&this.$x.tC(n),this.$x.iC&&this.$x.iC(this.zx,n),this.jx(),this.Yx(),this.Iv=Dh.Ex,this.zx=null)}Jx(t){if(!t.point)return;if(this.Iv!==Dh.Ox)return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.If,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.$x.sC&&this.$x.sC(n)}m(){this.qx()}}class Fh{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ih{constructor(t){this.nC=t,this.Jt=new Fh(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vh extends xh{constructor(t,i){super(t,"trend-line",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this._C=null,this.uC=null,this.cC=!1,this.dC=null,this.pC=null,this.fC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.fC),this.zy(),this.fC.interactive?this.vC():this.cC=!0}vC(){const t=new Rh(this._chart,this._series,{Qx:t=>{this.fC.point1Time=t.gt,this.fC.point1Price=t.bt,this.cM()},tC:t=>{this.fC.point2Time=t.gt,this.fC.point2Price=t.bt,this.cC=!0,this.cM(),this.fC.onUpdate&&this.fC.onUpdate()},sC:t=>{this.fC.point1Time&&!this.cC&&(this.pC=t,this.cM())},iC:()=>{this.cC=!0}});this.dC=t,t.Hx()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Ih(this)}gC(){if(!this.fC.point1Time||!this.fC.point2Time)return null;const t=Xn(this._chart,this._series,this.fC.point1Time)??0,i=this._series.priceToCoordinate(this.fC.point1Price)??0,s=Xn(this._chart,this._series,this.fC.point2Time)??0,n=this._series.priceToCoordinate(this.fC.point2Price)??0;if(!this.fC.extendLeft&&!this.fC.extendRight)return{bC:t,MC:i,yC:s,SC:n};if(s===t)return{bC:t,MC:i,yC:s,SC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{bC:this.fC.extendLeft?0:t,MC:this.fC.extendLeft?i-r*t:i,yC:this.fC.extendRight?e:s,SC:this.fC.extendRight?i+r*(e-t):n}}xC(){const t=this.gC();if(null===t)return null;const i=t.yC>=t.bC?t.SC:t.MC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.fC.point2Price??this.fC.point1Price??null}drawToCanvas(t,i,s){if(!this.cC&&this.fC.point1Time&&this.pC)return void this.CC(t,i,s);if(!this.fC.point1Time||!this.fC.point2Time)return;const n=(Xn(this._chart,this._series,this.fC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.fC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.fC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.fC.point2Price)??0)*s,l=this.fC.lineColor,o=this.rC?this.fC.lineWidth+1:this.fC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.fC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.fC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.gC();if(null===a)return;t.moveTo(a.bC*i,a.MC*s),t.lineTo(a.yC*i,a.SC*s),t.stroke(),t.setLineDash([]),!this.rC&&!this.hC||this.isLocked()||(this.PC(t,n,e,i,l),this.PC(t,r,h,i,l));const _=this.xC();if(!1!==this.fC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&kh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}CC(t,i,s){if(!this.fC.point1Time||!this.pC)return;const n=(Xn(this._chart,this._series,this.fC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.fC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.pC.gt)??0)*i,h=(this._series.priceToCoordinate(this.pC.bt)??0)*s;t.strokeStyle=this.fC.lineColor,t.lineWidth=this.fC.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.PC(t,n,e,i,this.fC.lineColor),t.globalAlpha=.5,this.PC(t,r,h,i,this.fC.lineColor),t.globalAlpha=1}PC(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.fC.lineColor=t,this.cM()}color(){return this.fC.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}isHovered(){return this.hC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){const s=this.gC();if(null===s)return!1;return this.TC(t,i,s.bC,s.MC,s.yC,s.SC)<=8}TC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.fC.point1Time||!this.fC.point2Time)return null;const s=Xn(this._chart,this._series,this.fC.point1Time)??0,n=this._series.priceToCoordinate(this.fC.point1Price)??0,e=Xn(this._chart,this._series,this.fC.point2Time)??0,r=this._series.priceToCoordinate(this.fC.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return"point2";return this.TC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.lC=!0,this.oC=t,this.aC=i,"line"===t&&(this._C={gt:this.fC.point1Time,bt:this.fC.point1Price},this.uC={gt:this.fC.point2Time,bt:this.fC.point2Price})}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this._C=null,this.uC=null}updateDrag(t,i){if(this.lC&&this.oC){if("point1"===this.oC)this.fC.point1Time=t,this.fC.point1Price=i;else if("point2"===this.oC)this.fC.point2Time=t,this.fC.point2Price=i;else if("line"===this.oC&&this._C&&this.uC){const s=mh(this.aC,t,i);this.fC.point1Time=this._C.gt+s.gt,this.fC.point1Price=this._C.bt+s.bt,this.fC.point2Time=this.uC.gt+s.gt,this.fC.point2Price=this.uC.bt+s.bt}this.cM(),this.fC.onUpdate&&this.fC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[bh(this.fC.point1Price??0,gh(this.fC.point1Time)),bh(this.fC.point2Price??0,gh(this.fC.point2Time))],style:{lineColor:this.fC.lineColor,lineWidth:this.fC.lineWidth,lineStyle:this.fC.lineStyle,extendLeft:this.fC.extendLeft,extendRight:this.fC.extendRight}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return this.cC}remove(){this.dC&&(this.dC.m(),this.dC=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.fC.onRemove&&this.fC.onRemove()}}function Lh(t,i){return new Vh(t,i)}class Ah{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Eh{constructor(t){this.nC=t,this.Jt=new Ah(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bh extends xh{constructor(t,i){super(t,"horizontal-line",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.aC=null,this.kC=0,this.DC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.DC),this.zy()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Eh(this)}RC(){return void 0===this.DC.startTime?0:Xn(this._chart,this._series,this.DC.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.DC.price)return;const n=(this._series.priceToCoordinate(this.DC.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.RC()*i,h=this.DC.lineColor,l=this.rC?this.DC.lineWidth+1:this.DC.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.DC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.DC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.DC.showPriceLabel&&kh(t,this._series,i,s,{bt:this.DC.price,ct:n/s,Ot:h}),this.DC.showLabel&&(this.rC||this.hC)&&this.FC(t,n,i,s,h)}FC(t,i,s,n,e){const r=this.DC.labelText||this.DC.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=10*s,u=i-a/2-h;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.DC.lineColor=t,this.cM()}color(){return this.DC.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.DC.price)return!1;const s=this._series.priceToCoordinate(this.DC.price)??0;return!(t<this.RC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.lC=!0,this.aC=i,this.kC=this.DC.price??0}stopDrag(){this.lC=!1,this.aC=null}updateDrag(t,i){this.lC&&(this.DC.price=this.kC+mh(this.aC,t,i).bt,this.cM(),this.DC.onUpdate&&this.DC.onUpdate())}getPrice(){return this.DC.price}setPrice(t){this.DC.price=t,this.cM()}setLabel(t){this.DC.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[bh(this.DC.price??0,gh(this.DC.startTime))],style:{lineColor:this.DC.lineColor,lineWidth:this.DC.lineWidth,lineStyle:this.DC.lineStyle,showLabel:this.DC.showLabel,labelText:this.DC.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.DC.onRemove&&this.DC.onRemove()}}function Oh(t,i){return new Bh(t,i)}class Wh{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zh{constructor(t){this.nC=t,this.Jt=new Wh(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class $h extends xh{constructor(t,i){super(t,"cross-line",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.aC=null,this.IC=0,this.kC=0,this.VC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.VC),this.zy()}zy(){this.nh=new zh(this);const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.eC&&this.eC()}_update(){this.cM()}LC(){if(void 0===this.VC.time||void 0===this.VC.price)return null;const t=Xn(this._chart,this._series,this.VC.time),i=this._series.priceToCoordinate(this.VC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.LC();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.VC.lineColor,_=this.rC||this.hC&&!this.isLocked(),u=_?this.VC.lineWidth+1:this.VC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.VC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.VC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(r,o),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.VC.showPriceLabel&&void 0!==this.VC.price&&kh(t,this._series,i,s,{bt:this.VC.price,ct:n.ct,Ot:a}),_&&!this.isLocked()&&(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,o,5*i,0,2*Math.PI),t.fill(),t.stroke())}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){const s=this.LC();if(null===s)return!1;return Math.abs(i-s.ct)<=8||Math.abs(t-s.ut)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.lC=!0,this.aC=i,this.IC=this.VC.time,this.kC=this.VC.price??0}updateDrag(t,i){if(!this.lC)return;const s=mh(this.aC,t,i);this.VC.time=this.IC+s.gt,this.VC.price=this.kC+s.bt,this.cM(),this.VC.onUpdate&&this.VC.onUpdate()}stopDrag(){this.lC=!1,this.aC=null}setColor(t){this.VC.lineColor=t,this.cM()}color(){return this.VC.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}remove(){if(this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.eC=null,this.VC.onRemove&&this.VC.onRemove()}_serializeShape(){return{type:"crossLine",points:[bh(this.VC.price??0,gh(this.VC.time))],style:{lineColor:this.VC.lineColor,lineWidth:this.VC.lineWidth,lineStyle:this.VC.lineStyle}}}}function Hh(t,i){return new $h(t,i)}class Nh{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Uh{constructor(t){this.nC=t,this.Jt=new Nh(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class qh extends xh{constructor(t,i){super(t,"polygon",i),this.F_=[],this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.AC=null,this.cC=!1,this.pC=null,this.HS=null,this.EC=null,this.BC=null,this.OC={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.OC),this.F_=[...i.points??[]],this.zy(),this.OC.interactive?this.WC():this.cC=this.F_.length>=3}zy(){this.nh=new Uh(this);const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.eC&&this.eC()}_update(){this.cM()}WC(){this.HS=t=>{if(!t.point||Th(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.F_.length>=3&&this.zC(t.point.x,t.point.y)?this.$C():(this.F_.push({time:s,price:i}),this.cM()))},this.EC=t=>{if(!t.point||this.cC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.pC={time:s,price:i},this.cM())},this.BC=t=>{"Enter"===t.key&&this.F_.length>=3?this.$C():"Escape"===t.key&&(this.F_=[],this.$C())},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.EC),document.addEventListener("keydown",this.BC)}zC(t,i){const s=this.F_[0],n=Xn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=qh.HC&&Math.abs(i-e)<=qh.HC)}$C(){this.cC=!0,this.pC=null,this.NC(),this.cM(),this.OC.onComplete&&this.OC.onComplete(),this.OC.onUpdate&&this.OC.onUpdate()}NC(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.EC&&(this._chart.unsubscribeCrosshairMove(this.EC),this.EC=null),this.BC&&(document.removeEventListener("keydown",this.BC),this.BC=null)}UC(){const t=[...this.F_];return this.cC||null===this.pC||t.push(this.pC),this.qC(t)}qC(t){const i=[];for(const s of t){const t=Xn(this._chart,this._series,s.time),n=this._series.priceToCoordinate(s.price);null!==t&&null!==n&&i.push({ut:t,ct:n})}return i}drawToCanvas(t,i,s){const n=this.UC();if(n.length<2)return;const e=this.OC.borderColor,r=this.rC?this.OC.borderWidth+1:this.OC.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.cC&&(t.closePath(),this.OC.fillOpacity>0&&(t.fillStyle=this.Fy(this.OC.fillColor,this.OC.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.cC?"dashed"===this.OC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.OC.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.rC||this.hC||!this.cC)&&!this.isLocked())for(const n of this.jC())this.YC(t,n.ut*i,n.ct*s,i,e)}jC(){return this.qC(this.F_)}YC(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}wC(t,i){if(!this.isVisible()||!this.cC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){const s=this.jC();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.jC();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.lC=!0,this.oC=t,this.aC=i,this.AC=this.F_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.lC&&null!==this.oC&&null!==this.AC){if("shape"===this.oC){const s=mh(this.aC,t,i);this.F_=this.AC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.oC;this.F_[s]&&(this.F_[s]={time:t,price:i})}this.cM(),this.OC.onUpdate&&this.OC.onUpdate()}}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.AC=null}setColor(t){this.OC.borderColor=t,this.OC.fillColor=t,this.cM()}color(){return this.OC.borderColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}points(){return this.F_}isComplete(){return this.cC}remove(){if(this.NC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.eC=null,this.OC.onRemove&&this.OC.onRemove()}_serializeShape(){return{type:"polygon",points:this.F_.map(t=>bh(t.price,gh(t.time))),style:{fillColor:this.OC.fillColor,fillOpacity:this.OC.fillOpacity,borderColor:this.OC.borderColor,borderWidth:this.OC.borderWidth,borderStyle:this.OC.borderStyle}}}}function jh(t,i){return new qh(t,i)}qh.HC=12;class Yh{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xh{constructor(t){this.nC=t,this.Jt=new Yh(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Gh extends xh{constructor(t,i){super(t,"parallel-channel",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.XC=null,this.cC=!1,this._d=0,this.pC=null,this.HS=null,this.EC=null,this.GC={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.GC),this.zy(),this.GC.interactive?this.WC():this.cC=!0}zy(){this.nh=new Xh(this);const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.eC&&this.eC()}_update(){this.cM()}WC(){this.HS=t=>{if(!t.point||Th(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.GC.point1Time=s,this.GC.point1Price=i;else{if(1!==this._d)return this.GC.channelWidth=i-this.KC(s),void this.$C();this.GC.point2Time=s,this.GC.point2Price=i}this._d++,this.cM()}},this.EC=t=>{if(!t.point||this.cC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.pC={gt:s,bt:i},2===this._d&&(this.GC.channelWidth=i-this.KC(s)),this.cM())},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.EC)}$C(){this.cC=!0,this.pC=null,this.NC(),this.cM(),this.GC.onComplete&&this.GC.onComplete(),this.GC.onUpdate&&this.GC.onUpdate()}NC(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.EC&&(this._chart.unsubscribeCrosshairMove(this.EC),this.EC=null)}KC(t){const i=this.GC.point1Time,s=this.GC.point2Time,n=this.GC.point1Price,e=this.GC.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)}hS(){const t=this.GC,i=this.cC?t.point2Time:t.point2Time??this.pC?.gt,s=this.cC?t.point2Price:t.point2Price??this.pC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Xn(this._chart,this._series,t.point1Time),e=Xn(this._chart,this._series,i),r=this._series.priceToCoordinate(t.point1Price),h=this._series.priceToCoordinate(s);if(null===n||null===e||null===r||null===h)return null;let l=e,o=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,o=r+(h-r)/(e-n)*(t-n)}const a=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+a),u=this._series.priceToCoordinate(this._series.coordinateToPrice(o)+a);return null===_||null===u?null:{bC:n,yC:l,ZC:r,JC:o,QC:_,tP:u}}drawToCanvas(t,i,s){const n=this.hS();if(null===n)return;const e=this.GC,r=e.lineColor,h=this.rC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Fy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.bC*l,n.ZC*o),t.lineTo(n.yC*l,n.JC*o),t.lineTo(n.yC*l,n.tP*o),t.lineTo(n.bC*l,n.QC*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.cC?"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.bC*l,n.ZC*o),t.lineTo(n.yC*l,n.JC*o),0!==(e.channelWidth??0)&&(t.moveTo(n.bC*l,n.QC*o),t.lineTo(n.yC*l,n.tP*o)),t.stroke(),t.setLineDash([]);if((this.rC||this.hC||!this.cC)&&!this.isLocked()&&(this.YC(t,n.bC*l,n.ZC*o,l,r),this.YC(t,n.yC*l,n.JC*o,l,r),0!==(e.channelWidth??0))){const i=(n.bC+n.yC)/2,s=(n.QC+n.tP)/2;this.YC(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.cC){const i=this._series.coordinateToPrice(n.JC);null!==i&&kh(t,this._series,l,o,{bt:i,ct:n.JC,Ot:r})}}YC(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}wC(t,i){if(!this.isVisible()||!this.cC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}iP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.hS();if(null===s)return!1;return this.iP(t,i,s.bC,s.ZC,s.yC,s.JC)<=8||this.iP(t,i,s.bC,s.QC,s.yC,s.tP)<=8}hitTestEndpoint(t,i){const s=this.hS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.bC,s.ZC))return"point1";if(n(s.yC,s.JC))return"point2";if(0!==(this.GC.channelWidth??0)){if(n((s.bC+s.yC)/2,(s.QC+s.tP)/2))return"width"}return null}startDrag(t,i){this.lC=!0,this.oC=t,this.aC=i,this.XC={sP:{gt:this.GC.point1Time,bt:this.GC.point1Price},nP:{gt:this.GC.point2Time,bt:this.GC.point2Price},ts:this.GC.channelWidth??0}}updateDrag(t,i){if(!this.lC||null===this.oC||null===this.XC)return;const s=this.GC;if("point1"===this.oC)s.point1Time=t,s.point1Price=i;else if("point2"===this.oC)s.point2Time=t,s.point2Price=i;else if("width"===this.oC)s.channelWidth=i-this.KC(t);else{const n=mh(this.aC,t,i);s.point1Time=this.XC.sP.gt+n.gt,s.point1Price=this.XC.sP.bt+n.bt,s.point2Time=this.XC.nP.gt+n.gt,s.point2Price=this.XC.nP.bt+n.bt,s.channelWidth=this.XC.ts}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.XC=null}setColor(t){this.GC.lineColor=t,this.GC.fillColor=t,this.cM()}color(){return this.GC.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}isComplete(){return this.cC}remove(){if(this.NC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.eC=null,this.GC.onRemove&&this.GC.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[bh(this.GC.point1Price??0,gh(this.GC.point1Time)),bh(this.GC.point2Price??0,gh(this.GC.point2Time))],style:{lineColor:this.GC.lineColor,lineWidth:this.GC.lineWidth,lineStyle:this.GC.lineStyle,fillColor:this.GC.fillColor,fillOpacity:this.GC.fillOpacity,extendRight:this.GC.extendRight},extra:{channelWidth:this.GC.channelWidth}}}}function Kh(t,i){return new Gh(t,i)}class Zh{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Jh{constructor(t){this.nC=t,this.Jt=new Zh(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Qh extends xh{constructor(t,i){super(t,"pitchfork",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.XC=null,this.cC=!1,this._d=0,this.pC=null,this.HS=null,this.EC=null,this.eP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.eP),this.zy(),this.eP.interactive?this.WC():this.cC=!0}zy(){this.nh=new Jh(this);const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.eC&&this.eC()}_update(){this.cM()}WC(){this.HS=t=>{if(!t.point||Th(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.eP.pivotTime=s,this.eP.pivotPrice=i;else{if(1!==this._d)return this.eP.lowerTime=s,this.eP.lowerPrice=i,this._d++,void this.$C();this.eP.upperTime=s,this.eP.upperPrice=i}this._d++,this.cM()}},this.EC=t=>{if(!t.point||this.cC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.pC={gt:s,bt:i},this.cM())},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.EC)}$C(){this.cC=!0,this.pC=null,this.NC(),this.cM(),this.eP.onComplete&&this.eP.onComplete(),this.eP.onUpdate&&this.eP.onUpdate()}NC(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.EC&&(this._chart.unsubscribeCrosshairMove(this.EC),this.EC=null)}rP(t,i){if(void 0===t||void 0===i)return null;const s=Xn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}hP(){const t=this.eP,i=this.rP(t.pivotTime,t.pivotPrice),s=this.rP(t.upperTime,t.upperPrice),n=this.cC?this.rP(t.lowerTime,t.lowerPrice):this.rP(t.lowerTime,t.lowerPrice)??(null!==this.pC&&this._d>=2?this.rP(this.pC.gt,this.pC.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{lP:i,oP:e,aP:s,_P:n,uP:l(i),cP:l(s),dP:l(n)}}drawToCanvas(t,i,s){const n=this.hP();if(null===n)return void this.pP(t,i,s);const e=this.eP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Fy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.aP.ut*h,n.aP.ct*l),t.lineTo(n.cP.ut*h,n.cP.ct*l),t.lineTo(n.dP.ut*h,n.dP.ct*l),t.lineTo(n._P.ut*h,n._P.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.rC?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.aP.ut*h,n.aP.ct*l),t.lineTo(n._P.ut*h,n._P.ct*l),t.moveTo(n.lP.ut*h,n.lP.ct*l),t.lineTo(n.uP.ut*h,n.uP.ct*l),t.moveTo(n.aP.ut*h,n.aP.ct*l),t.lineTo(n.cP.ut*h,n.cP.ct*l),t.moveTo(n._P.ut*h,n._P.ct*l),t.lineTo(n.dP.ut*h,n.dP.ct*l),t.stroke(),t.setLineDash([]);if((this.rC||this.hC||!this.cC)&&!this.isLocked())for(const i of[n.lP,n.aP,n._P])this.YC(t,i.ut*h,i.ct*l,h,r)}pP(t,i,s){const n=this.eP,e=this.rP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.rP(n.upperTime,n.upperPrice)??(null!==this.pC?this.rP(this.pC.gt,this.pC.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.YC(t,e.ut*i,e.ct*s,i,h)}YC(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}wC(t,i){if(!this.isVisible()||!this.cC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}iP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.hP();if(null===s)return!1;return[[s.lP,s.uP],[s.aP,s.cP],[s._P,s.dP],[s.aP,s._P]].some(([s,n])=>this.iP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.hP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.lP)?"pivot":n(s.aP)?"upper":n(s._P)?"lower":null}startDrag(t,i){this.lC=!0,this.oC=t,this.aC=i,this.XC=[{gt:this.eP.pivotTime,bt:this.eP.pivotPrice},{gt:this.eP.upperTime,bt:this.eP.upperPrice},{gt:this.eP.lowerTime,bt:this.eP.lowerPrice}]}updateDrag(t,i){if(!this.lC||null===this.oC||null===this.XC)return;const s=this.eP;if("pivot"===this.oC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.oC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.oC)s.lowerTime=t,s.lowerPrice=i;else{const n=mh(this.aC,t,i),[e,r,h]=this.XC;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.XC=null}setColor(t){this.eP.lineColor=t,this.eP.fillColor=t,this.cM()}color(){return this.eP.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}isComplete(){return this.cC}remove(){if(this.NC(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.eC=null,this.eP.onRemove&&this.eP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[bh(this.eP.pivotPrice??0,gh(this.eP.pivotTime)),bh(this.eP.upperPrice??0,gh(this.eP.upperTime)),bh(this.eP.lowerPrice??0,gh(this.eP.lowerTime))],style:{lineColor:this.eP.lineColor,lineWidth:this.eP.lineWidth,lineStyle:this.eP.lineStyle,fillColor:this.eP.fillColor,fillOpacity:this.eP.fillOpacity}}}}function tl(t,i){return new Qh(t,i)}class il{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class sl{constructor(t){this.nC=t,this.Jt=new il(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class nl extends xh{constructor(t,i){super(t,"vertical-line",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.aC=null,this.IC=0,this.fP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.fP),this.zy()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new sl(this)}drawToCanvas(t,i,s){if(void 0===this.fP.time)return;const n=(Xn(this._chart,this._series,this.fP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.fP.lineColor,h=this.rC||this.hC&&!this.isLocked()?this.fP.lineWidth+1:this.fP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.fP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.fP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.fP.showLabel&&(this.rC||this.hC)&&this.fP.labelText&&this.FC(t,n,i,s,r)}FC(t,i,s,n,e){const r=this.fP.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=i-o/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.fP.lineColor=t,this.cM()}color(){return this.fP.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.fP.time)return!1;const s=Xn(this._chart,this._series,this.fP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.lC=!0,this.aC=i,this.IC=this.fP.time}stopDrag(){this.lC=!1,this.aC=null}updateDrag(t,i){this.lC&&(this.fP.time=this.IC+mh(this.aC,t,i).gt,this.cM(),this.fP.onUpdate&&this.fP.onUpdate())}getTime(){return this.fP.time}setTime(t){this.fP.time=t,this.cM()}setLabel(t){this.fP.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[bh(0,gh(this.fP.time))],style:{lineColor:this.fP.lineColor,lineWidth:this.fP.lineWidth,lineStyle:this.fP.lineStyle,showLabel:this.fP.showLabel,labelText:this.fP.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.fP.onRemove&&this.fP.onRemove()}}function el(t,i){return new nl(t,i)}const rl=[{vP:0,Zl:"0.0%"},{vP:.236,Zl:"23.6%"},{vP:.382,Zl:"38.2%"},{vP:.5,Zl:"50.0%"},{vP:.618,Zl:"61.8%"},{vP:.786,Zl:"78.6%"},{vP:1,Zl:"100.0%"}],hl=[...rl,{vP:1.272,Zl:"127.2%"},{vP:1.414,Zl:"141.4%"},{vP:1.618,Zl:"161.8%"},{vP:2,Zl:"200.0%"},{vP:2.618,Zl:"261.8%"}];class ll{constructor(t=!1){this.mP=t?hl:rl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.mP.map(({vP:t,Zl:i})=>{let s;return s=h?n-e*t:n+e*t,{vP:t,bt:s,Zl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.mP=t}getRatios(){return[...this.mP]}getRatioValues(){return this.mP.map(t=>t.vP)}useStandardRatios(){this.mP=rl}useExtendedRatios(){this.mP=hl}}class ol{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class al{constructor(t){this.nC=t,this.Jt=new ol(t)}renderer(){return this.nC.isVisible()?this.Jt:null}}function _l(t){return{vP:t,Zl:`${(100*t).toFixed(1)}%`}}class ul extends xh{constructor(t,i){super(t,"fibonacci-tool",i),this.Ub=null,this.eC=null,this.Yb=null,this.nh=null,this.wP=null,this.cC=!1,this.rC=!1,this.hC=!1,this.pC=null,this.lC=!1,this.gP=null,this.sp=null,this.bP={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.bP),this.MP=new ll(this.bP.useExtended),void 0!==this.bP.levels&&this.bP.levels.length>0&&this.MP.updateRatios(this.bP.levels.map(_l)),this.zy(),this.bP.interactive?this.vC():(this.cC=!0,this.yP())}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new al(this)}drawToCanvas(t,i,s){if(!this.cC&&this.bP.point1Time&&this.pC)return void this.CC(t,i,s);if(!this.Yb||!this.bP.point1Time||!this.bP.point2Time)return;const n=(Xn(this._chart,this._series,this.bP.point1Time)??0)*i,e=(Xn(this._chart,this._series,this.bP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.rC?2:this.bP.lineWidth;this.Yb.levels.forEach(n=>{this.sx(t,n,r,h,i,s,l)}),!this.rC&&!this.hC||this.isLocked()||(this.PC(t,n,(this._series.priceToCoordinate(this.bP.point1Price)??0)*s,i),this.PC(t,e,(this._series.priceToCoordinate(this.bP.point2Price)??0)*s,i))}sx(t,i,s,n,e,r,h=1){const l=i.ratio??i.vP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.bP.levelColors?.[l.toString()]||this.bP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.bP.showLabels&&this.FC(t,i,s,n,a,e,_)}FC(t,i,s,n,e,r,h){const l=i.label??i.Zl,o=i.price??i.bt,a=`${l} ${this.MP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.bP.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.bP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}yP(){this.bP.point1Time&&this.bP.point1Price&&this.bP.point2Time&&this.bP.point2Price&&(this.Yb=this.MP.calculateLevels(this.bP.point1Time,this.bP.point1Price,this.bP.point2Time,this.bP.point2Price),this.bP.onUpdate&&this.Yb&&this.bP.onUpdate(this.Yb))}updatePoints(t,i,s,n){this.bP.point1Time=t,this.bP.point1Price=i,this.bP.point2Time=s,this.bP.point2Price=n,this.yP(),this.cM()}getMetrics(){return this.Yb}getLevels(){return this.Yb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.MP.getRatioValues();return{type:"fibRetracement",points:[bh(this.bP.point1Price??0,gh(this.bP.point1Time)),bh(this.bP.point2Price??0,gh(this.bP.point2Time))],style:{lineColor:this.bP.lineColor,lineWidth:this.bP.lineWidth,showLabels:this.bP.showLabels,labelPosition:this.bP.labelPosition,levelColors:this.bP.levelColors},extra:{levels:t,useExtended:this.bP.useExtended}}}useExtendedLevels(t){this.bP.useExtended=t,t?this.MP.useExtendedRatios():this.MP.useStandardRatios(),this.yP(),this.cM()}vC(){this.wP=new Rh(this._chart,this._series,{Qx:t=>{this.bP.point1Time=t.gt,this.bP.point1Price=t.bt,this.cM()},tC:t=>{this.bP.point2Time=t.gt,this.bP.point2Price=t.bt},iC:(t,i)=>{this.bP.point1Time=t.gt,this.bP.point1Price=t.bt,this.bP.point2Time=i.gt,this.bP.point2Price=i.bt,this.cC=!0,this.pC=null,this.yP(),this.SP(),this.cM()},sC:t=>{this.pC=t,this.cM()}}),this.wP.Hx()}CC(t,i,s){if(!this.bP.point1Time||!this.pC)return;const n=(Xn(this._chart,this._series,this.bP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.bP.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.pC.gt)??0)*i,h=(this._series.priceToCoordinate(this.pC.bt)??0)*s,l=this.MP.calculateLevels(this.bP.point1Time,this.bP.point1Price,this.pC.gt,this.pC.bt),o=Math.min(n,r),a=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.vP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.bP.levelColors?.[e.toString()]||this.bP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.bP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.bP.showLabels){const s=`${n.label??n.Zl} ${this.MP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.bP.labelPosition?a+_:o-e.width-_,c=h;t.fillStyle="rgba(255, 255, 255, 0.8)",t.fillRect(u-_/2,c-11*i/2-_/2,e.width+_,11*i+_),t.fillStyle=l,t.textAlign="right"===this.bP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.PC(t,n,e,i),t.globalAlpha=.6,this.PC(t,r,h,i),t.globalAlpha=1}PC(t,i,s,n){const e=this.bP.lineColor,r=this.rC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.rC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}SP(){this.sp=t=>{this.xP(t)},this._chart.subscribeCrosshairMove(this.sp)}CP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}xP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.rC||!this.lC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.gP?(this.bP.point1Time=i,this.bP.point1Price=s):"point2"===this.gP&&(this.bP.point2Time=i,this.bP.point2Price=s),this.yP(),this.cM())}startDrag(t){this.lC=!0,this.gP=t}stopDrag(){this.lC=!1,this.gP=null}updateDrag(t,i){this.lC&&this.gP&&("point1"===this.gP?(this.bP.point1Time=t,this.bP.point1Price=i):(this.bP.point2Time=t,this.bP.point2Price=i),this.yP(),this.cM())}hitTestEndpoint(t,i){if(!this.cC||!this.bP.point1Time||!this.bP.point2Time)return null;const s=Xn(this._chart,this._series,this.bP.point1Time)??0,n=this._series.priceToCoordinate(this.bP.point1Price)??0,e=Xn(this._chart,this._series,this.bP.point2Time)??0,r=this._series.priceToCoordinate(this.bP.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.bP={...this.bP,...t},void 0!==t.levels&&t.levels.length>0?this.MP.updateRatios(t.levels.map(_l)):void 0!==t.useExtended&&(t.useExtended?this.MP.useExtendedRatios():this.MP.useStandardRatios()),super.applyOptions(t),this.yP(),this.cM()}options(){return{...this.bP,levels:this.MP.getRatioValues()}}setColor(t){this.bP.lineColor=t,this.cM()}color(){return this.bP.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}isSelected(){return this.rC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.cC||!this.bP.point1Time||!this.bP.point2Time)return!1;const s=Xn(this._chart,this._series,this.bP.point1Time)??0,n=Xn(this._chart,this._series,this.bP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Yb)return!1;for(const t of this.Yb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.cC}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.wP&&(this.wP.m(),this.wP=null),this.CP(),this.bP.onRemove&&this.bP.onRemove()}destroy(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.bP.onRemove&&this.bP.onRemove()}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.yP(),this.cM()}}function cl(t,i){return new ul(t,i)}class dl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class pl{constructor(t){this.nC=t,this.Jt=new dl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}}class fl extends xh{constructor(t,i){super(t,"fibonacci-extension",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.bP={levels:[{level:0,color:"#787B86",label:"0%"},{level:.618,color:"#2962FF",label:"61.8%"},{level:1,color:"#787B86",label:"100%"},{level:1.618,color:"#F23645",label:"161.8%"},{level:2.618,color:"#9C27B0",label:"261.8%"}],lineColor:"#787B86",lineWidth:1,showLabels:!0,extendLines:!0,...i},this.zy()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new pl(this)}getPoint1(){return this.bP.point1}getPoint2(){return this.bP.point2}getPoint3(){return this.bP.point3}getLevels(){return this.bP.levels||[]}getOptions(){return this.bP}setPoint1(t){this.bP.point1=t,this.cM()}setPoint2(t){this.bP.point2=t,this.cM()}setPoint3(t){this.bP.point3=t,this.cM()}isComplete(){return!!(this.bP.point1&&this.bP.point2&&this.bP.point3)}setColor(t){this.bP.lineColor=t,this.cM()}color(){return this.bP.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.bP.point1,this.bP.point2,this.bP.point3];for(const n of s){const s=Xn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=10)return!0}const n=this.PP();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.bP.point1,n=this.bP.point2,e=this.bP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Xn(this._chart,this._series,s.time)??0,e=this._series.priceToCoordinate(s.price)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=20)return"point1"}if(n&&n.time&&void 0!==n.price){const s=Xn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=20)return"point2"}if(e&&e.time&&void 0!==e.price){const s=Xn(this._chart,this._series,e.time)??0,n=this._series.priceToCoordinate(e.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=20)return"point3"}return null}startDrag(t){this.lC=!0,this.oC=t}stopDrag(){this.lC=!1,this.oC=null}updateDrag(t,i){if(!this.lC||!this.oC)return;const s={time:t,price:i};switch(this.oC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.bP.onUpdate&&this.bP.onUpdate()}PP(){if(!this.isComplete())return[];const t=this.bP.point1,i=this.bP.point2,s=this.bP.point3,n=i.price-t.price;return(this.bP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Zl:t.label,R:t.color}))}getExtensionLevels(){return this.PP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.bP.point1,e=this.bP.point2,r=this.bP.point3,h=this.rC||this.hC&&!this.isLocked(),l=(Xn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Xn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Xn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.bP.lineColor||"#787B86",t.lineWidth=(this.bP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Zl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.bP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.bP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.bP.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Zl:"A"},{ut:a,ct:_,Zl:"B"},{ut:u,ct:c,Zl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Zl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[Mh(this.bP.point1),Mh(this.bP.point2),Mh(this.bP.point3)],style:{lineColor:this.bP.lineColor,lineWidth:this.bP.lineWidth,showLabels:this.bP.showLabels,extendLines:this.bP.extendLines},extra:{levels:(this.bP.levels||[]).map(t=>({sn:t.level,R:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null)}}function vl(t,i){return new fl(t,i)}class ml{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wl{constructor(t){this.nC=t,this.Jt=new ml(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const gl=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class bl extends xh{constructor(t,i){super(t,"fibonacci-fan",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.TP=!1,this.HS=null,this.sp=null,this.pC=null,this.kP={levels:gl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.zy(),this.kP.interactive&&!this.kP.point1Time&&this.vC()}vC(){this.TP=!0,this.HS=t=>{if(!t.point)return;if(Th(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kP.point1Time?(this.kP.point2Time=i,this.kP.point2Price=s,this.TP=!1,this.pC=null,this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.kP.onUpdate&&this.kP.onUpdate()):(this.kP.point1Time=i,this.kP.point1Price=s,this.cM()))},this.sp=t=>{if(this.TP&&this.kP.point1Time)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.pC={gt:i,bt:s},this.cM())}else this.pC=null,this.cM()},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new wl(this)}drawToCanvas(t,i,s){const n=this.kP.point1Time,e=this.kP.point1Price,r=this.TP&&this.pC?this.pC.gt:this.kP.point2Time,h=this.TP&&this.pC?this.pC.bt:this.kP.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.rC?this.kP.lineWidth+1:this.kP.lineWidth;if(this.DP(t,l,o,a,_,"#2962FF",u*i),this.kP.levels)for(const n of this.kP.levels)this.RP(t,l,o,a,_,n,i,s,undefined,u);!this.rC&&!this.hC||this.TP||this.isLocked()||(this.PC(t,l,o,i,"#2962ff"),this.PC(t,a,_,i,"#2962ff"))}RP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.kP.extendLines){const t=this._chart.chartElement().clientWidth*h,n=_-i,e=u-s,r=Math.sqrt(n*n+e*e);if(r>0){const h=2*t;c=i+n/r*h,d=s+e/r*h}}const p=o||r.color;this.DP(t,i,s,c,d,p,a*h),this.kP.showLabels&&!this.TP&&this.FC(t,_,u,r.label,h,p)}DP(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()}PC(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()}FC(t,i,s,n,e,r){const h=11*e,l=4*e;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(n).width,a=h;t.fillStyle=r,t.fillRect(i+l,s-a-l,o+2*l,a+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-a-l+l)}setColor(t){const i=this.kP.levels??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.kP.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.kP.point1Time||!this.kP.point2Time)return!1;const s=Xn(this._chart,this._series,this.kP.point1Time)??0,n=this._series.priceToCoordinate(this.kP.point1Price)??0,e=Xn(this._chart,this._series,this.kP.point2Time)??0,r=this._series.priceToCoordinate(this.kP.point2Price)??0;if(this.TC(t,i,s,n,e,r)<=8)return!0;if(this.kP.levels)for(const h of this.kP.levels){const l=n+(r-n)*h.level,o=e;if(this.TC(t,i,s,n,o,l)<=8)return!0}return!1}TC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.kP.point1Time||!this.kP.point2Time)return null;const s=Xn(this._chart,this._series,this.kP.point1Time)??0,n=this._series.priceToCoordinate(this.kP.point1Price)??0,e=Xn(this._chart,this._series,this.kP.point2Time)??0,r=this._series.priceToCoordinate(this.kP.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.lC=!0,this.oC=t}stopDrag(){this.lC=!1,this.oC=null}updateDrag(t,i){this.lC&&this.oC&&("point1"===this.oC?(this.kP.point1Time=t,this.kP.point1Price=i):"point2"===this.oC&&(this.kP.point2Time=t,this.kP.point2Price=i),this.cM(),this.kP.onUpdate&&this.kP.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[bh(this.kP.point1Price??0,gh(this.kP.point1Time)),bh(this.kP.point2Price??0,gh(this.kP.point2Time))],style:{lineWidth:this.kP.lineWidth,showLabels:this.kP.showLabels,extendLines:this.kP.extendLines},extra:{levels:(this.kP.levels||[]).map(t=>({sn:t.level,R:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return!this.TP}remove(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.kP.onRemove&&this.kP.onRemove()}}function Ml(t,i){return new bl(t,i)}class yl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Sl{constructor(t){this.nC=t,this.Jt=new yl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class xl extends xh{constructor(t,i){super(t,"rectangle",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this._C=null,this.uC=null,this.TP=!1,this.HS=null,this.sp=null,this.pC=null,this.FP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.FP),this.zy(),!this.FP.interactive||this.FP.time1&&this.FP.time2||this.vC()}vC(){this.TP=!0,this.HS=t=>{if(!t.point)return;if(Th(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.FP.time1?(this.FP.time2=i,this.FP.price2=s,this.TP=!1,this.pC=null,this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.FP.onUpdate&&this.FP.onUpdate()):(this.FP.time1=i,this.FP.price1=s,this.cM()))},this.sp=t=>{if(this.TP&&this.FP.time1)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.pC={gt:i,bt:s},this.cM())}else this.pC=null,this.cM()},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Sl(this)}drawToCanvas(t,i,s){const n=this.FP.time1,e=this.FP.price1,r=this.TP&&this.pC?this.pC.gt:this.FP.time2,h=this.TP&&this.pC?this.pC.bt:this.FP.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,a),c=Math.max(l,a),d=Math.min(o,_),p=Math.max(o,_),f=c-u,v=p-d;if(this.FP.fillOpacity>0){const i=this.Oy(this.FP.fillColor,this.TP?.1:this.FP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.FP.borderColor,w=this.rC?this.FP.borderWidth+1:this.FP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.FP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.FP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.rC&&!this.hC||this.TP||this.isLocked()||this.IP(t,u,d,c,p,i,m),this.FP.showLabel&&this.FP.labelText&&!this.TP&&this.FC(t,u,d,c,p,i,s,m)}IP(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s},{ut:n,ct:s},{ut:i,ct:e},{ut:n,ct:e}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}FC(t,i,s,n,e,r,h,l){const o=6*r,a=12*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.FP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.FP.labelPosition){case"top-right":c=n-_-2*o,d=s+o;break;case"bottom-left":c=i+o,d=e-u-2*o;break;case"bottom-right":c=n-_-2*o,d=e-u-2*o;break;case"center":c=(i+n)/2-_/2-o,d=(s+e)/2-u/2-o}t.fillStyle=l,t.fillRect(c,d,_+2*o,u+2*o),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.FP.labelText,c+o,d+o)}Oy(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.FP.borderColor=t,this.FP.fillColor=t,this.cM()}color(){return this.FP.borderColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.FP.time1||!this.FP.time2)return!1;const s=Xn(this._chart,this._series,this.FP.time1)??0,n=this._series.priceToCoordinate(this.FP.price1)??0,e=Xn(this._chart,this._series,this.FP.time2)??0,r=this._series.priceToCoordinate(this.FP.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r);return t>=h&&t<=l&&i>=o&&i<=a}hitTestEndpoint(t,i){if(!this.FP.time1||!this.FP.time2)return null;const s=Xn(this._chart,this._series,this.FP.time1)??0,n=this._series.priceToCoordinate(this.FP.price1)??0,e=Xn(this._chart,this._series,this.FP.time2)??0,r=this._series.priceToCoordinate(this.FP.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner4":t>=h&&t<=l&&i>=o&&i<=a?"body":null}startDrag(t,i){this.lC=!0,this.oC=t,this.aC=i,"body"===t&&(this._C={gt:this.FP.time1,bt:this.FP.price1},this.uC={gt:this.FP.time2,bt:this.FP.price2})}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this._C=null,this.uC=null}updateDrag(t,i){if(!this.lC||!this.oC)return;const s=Xn(this._chart,this._series,this.FP.time1)??0,n=this._series.priceToCoordinate(this.FP.price1)??0,e=s<(Xn(this._chart,this._series,this.FP.time2)??0),r=n<(this._series.priceToCoordinate(this.FP.price2)??0);if("body"===this.oC&&this._C&&this.uC){const s=mh(this.aC,t,i);this.FP.time1=this._C.gt+s.gt,this.FP.price1=this._C.bt+s.bt,this.FP.time2=this.uC.gt+s.gt,this.FP.price2=this.uC.bt+s.bt}else switch(this.oC){case"corner1":e&&r?(this.FP.time1=t,this.FP.price1=i):!e&&r?(this.FP.time2=t,this.FP.price1=i):e&&!r?(this.FP.time1=t,this.FP.price2=i):(this.FP.time2=t,this.FP.price2=i);break;case"corner2":e&&r?(this.FP.time2=t,this.FP.price1=i):!e&&r?(this.FP.time1=t,this.FP.price1=i):e&&!r?(this.FP.time2=t,this.FP.price2=i):(this.FP.time1=t,this.FP.price2=i);break;case"corner3":e&&r?(this.FP.time1=t,this.FP.price2=i):!e&&r?(this.FP.time2=t,this.FP.price2=i):e&&!r?(this.FP.time1=t,this.FP.price1=i):(this.FP.time2=t,this.FP.price1=i);break;case"corner4":e&&r?(this.FP.time2=t,this.FP.price2=i):!e&&r?(this.FP.time1=t,this.FP.price2=i):e&&!r?(this.FP.time2=t,this.FP.price1=i):(this.FP.time1=t,this.FP.price1=i)}this.cM(),this.FP.onUpdate&&this.FP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[bh(this.FP.price1??0,gh(this.FP.time1)),bh(this.FP.price2??0,gh(this.FP.time2))],style:{fillColor:this.FP.fillColor,fillOpacity:this.FP.fillOpacity,borderColor:this.FP.borderColor,borderWidth:this.FP.borderWidth,borderStyle:this.FP.borderStyle,showLabel:this.FP.showLabel,labelText:this.FP.labelText,labelPosition:this.FP.labelPosition}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return!this.TP}remove(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.FP.onRemove&&this.FP.onRemove()}}function Cl(t,i){return new xl(t,i)}class Pl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Tl{constructor(t){this.nC=t,this.Jt=new Pl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class kl extends xh{constructor(t,i){super(t,"circle",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.XC=null,this.TP=!1,this.HS=null,this.sp=null,this.pC=null,this.VP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.VP),this.zy(),this.VP.interactive&&!this.VP.centerTime&&this.vC()}vC(){this.TP=!0,this.HS=t=>{if(!t.point)return;if(Th(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.VP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.VP.centerTime)??0,n=this._series.priceToCoordinate(this.VP.centerPrice)??0,e=Xn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.VP.radiusTime=Math.abs(e-t),this.VP.radiusPrice=Math.abs(r-n),this.TP=!1,this.pC=null,this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.VP.onUpdate&&this.VP.onUpdate()}else this.VP.centerTime=i,this.VP.centerPrice=s,this.cM()},this.sp=t=>{if(this.TP&&this.VP.centerTime)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.pC={gt:i,bt:s},this.cM())}else this.pC=null,this.cM()},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Tl(this)}drawToCanvas(t,i,s){if(!this.VP.centerTime||void 0===this.VP.centerPrice)return;const n=(Xn(this._chart,this._series,this.VP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.VP.centerPrice)??0)*s;let r,h;if(this.TP&&this.pC){const t=(Xn(this._chart,this._series,this.pC.gt)??0)*i,l=(this._series.priceToCoordinate(this.pC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.VP.radiusTime||void 0===this.VP.radiusPrice)return;r=this.VP.radiusTime*i,h=this.VP.radiusPrice*s}if(this.VP.fillOpacity>0){const i=this.Oy(this.VP.fillColor,this.TP?.05:this.VP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.VP.borderColor,o=this.rC?this.VP.borderWidth+1:this.VP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.VP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.VP.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.rC&&!this.hC||this.TP||this.isLocked()||this.LP(t,n,e,i,l),!this.rC&&!this.hC||this.TP||this.isLocked()||this.AP(t,n,e,r,h,i,l),this.VP.showLabel&&this.VP.labelText&&!this.TP&&this.FC(t,n,e,i,l)}LP(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()}AP(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s-e},{ut:i+n,ct:s},{ut:i,ct:s+e},{ut:i-n,ct:s}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}FC(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.VP.labelText).width,o=h,a=i-l/2-r,_=s-o/2-r;t.fillStyle=e,t.fillRect(a,_,l+2*r,o+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.VP.labelText,a+r,_+r)}Oy(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.VP.borderColor=t,this.VP.fillColor=t,this.cM()}color(){return this.VP.borderColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.VP.centerTime||void 0===this.VP.radiusTime)return!1;const s=Xn(this._chart,this._series,this.VP.centerTime)??0,n=this._series.priceToCoordinate(this.VP.centerPrice)??0,e=(t-s)/this.VP.radiusTime,r=(i-n)/this.VP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.VP.centerTime||void 0===this.VP.radiusTime)return null;const s=Xn(this._chart,this._series,this.VP.centerTime)??0,n=this._series.priceToCoordinate(this.VP.centerPrice)??0,e=this.VP.radiusTime,r=this.VP.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.lC=!0,this.oC=t,this.aC=i,this.XC="center"===t?{gt:this.VP.centerTime,bt:this.VP.centerPrice}:null}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.XC=null}updateDrag(t,i){if(this.lC&&this.oC){if("center"===this.oC&&this.XC){const s=mh(this.aC,t,i);this.VP.centerTime=this.XC.gt+s.gt,this.VP.centerPrice=this.XC.bt+s.bt}else if("edge"===this.oC){const s=Xn(this._chart,this._series,this.VP.centerTime)??0,n=this._series.priceToCoordinate(this.VP.centerPrice)??0,e=Xn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.VP.radiusTime=Math.abs(e-s),this.VP.radiusPrice=Math.abs(r-n)}this.cM(),this.VP.onUpdate&&this.VP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[bh(this.VP.centerPrice??0,gh(this.VP.centerTime))],style:{fillColor:this.VP.fillColor,fillOpacity:this.VP.fillOpacity,borderColor:this.VP.borderColor,borderWidth:this.VP.borderWidth,borderStyle:this.VP.borderStyle,showLabel:this.VP.showLabel,labelText:this.VP.labelText},extra:{radiusTime:this.VP.radiusTime,radiusPrice:this.VP.radiusPrice}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return!this.TP}remove(){this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.VP.onRemove&&this.VP.onRemove()}}function Dl(t,i){return new kl(t,i)}class Rl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Fl{constructor(t){this.nC=t,this.Jt=new Rl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Il extends xh{constructor(t,i){super(t,"arrow",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.EP=-1,this.TP=!1,this.HS=null,this.BP=null,this.sp=null,this.pC=null,this.OP={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.OP),this.zy(),!this.OP.interactive||this.OP.points&&0!==this.OP.points.length||this.vC()}vC(){this.TP=!0,this.HS=t=>{if(!t.point)return;if(Th(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.OP.points||(this.OP.points=[]),this.OP.points.push({time:i,price:s}),this.cM(),this.OP.onUpdate&&this.OP.onUpdate())},this.sp=t=>{if(this.TP)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.pC={gt:i,bt:s},this.cM())}else this.pC=null,this.cM()},this.BP=t=>{this.TP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.HS),this._chart.subscribeCrosshairMove(this.sp);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.BP)}finishDrawing(){if(this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.BP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.BP),this.BP=null}this.TP=!1,this.pC=null,this.cM(),this.OP.onComplete&&this.OP.onComplete()}isDrawing(){return this.TP}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Fl(this)}drawToCanvas(t,i,s){if(!this.OP.points||0===this.OP.points.length)return;const n=this.OP.lineColor,e=this.rC||this.hC&&!this.isLocked()?this.OP.lineWidth+1:this.OP.lineWidth,r=[];for(const t of this.OP.points)try{let n=Xn(this._chart,this._series,t.time);if(null===n){const i=this._chart.timeScale(),s=i.timeToIndex(t.time,!0);null!=s&&(n=i.logicalToCoordinate(s))}if(null==n)continue;const e=this._series.priceToCoordinate(t.price);if(null===e)continue;r.push({ut:n*i,ct:e*s})}catch{continue}if(0===r.length&&!this.TP)return;let h=null;if(this.TP&&this.pC&&this.OP.points.length>0){h={ut:(Xn(this._chart,this._series,this.pC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.pC.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.OP.showArrowHead&&r.length>1&&this.WP(t,r[r.length-2],r[r.length-1],i,n),this.OP.showCircles)for(let s=0;s<r.length;s++)this.zP(t,r[s].ut,r[s].ct,i,n,0===s)}WP(t,i,s,n,e){const r=12*n,h=Math.atan2(s.ct-i.ct,s.ut-i.ut),l={ut:s.ut-r*Math.cos(h-Math.PI/6),ct:s.ct-r*Math.sin(h-Math.PI/6)},o={ut:s.ut-r*Math.cos(h+Math.PI/6),ct:s.ct-r*Math.sin(h+Math.PI/6)};t.fillStyle=e,t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(l.ut,l.ct),t.lineTo(o.ut,o.ct),t.closePath(),t.fill()}zP(t,i,s,n,e,r){const h=this.OP.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.OP.lineColor=t,this.cM()}color(){return this.OP.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.OP.points||0===this.OP.points.length)return!1;for(let s=0;s<this.OP.points.length-1;s++)try{const n=this.OP.points[s],e=this.OP.points[s+1];let r=Xn(this._chart,this._series,n.time);if(null===r){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(r=t.logicalToCoordinate(i))}let h=Xn(this._chart,this._series,e.time);if(null===h){const t=this._chart.timeScale(),i=t.timeToIndex(e.time,!0);null!=i&&(h=t.logicalToCoordinate(i))}const l=this._series.priceToCoordinate(n.price),o=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===o)continue;if(this.TC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.OP.points)try{let n=Xn(this._chart,this._series,s.time);if(null===n){const t=this._chart.timeScale(),i=t.timeToIndex(s.time,!0);null!=i&&(n=t.logicalToCoordinate(i))}const e=this._series.priceToCoordinate(s.price);if(null==n||null===e)continue;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=8)return!0}catch{continue}return!1}TC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.OP.points||0===this.OP.points.length)return null;for(let s=0;s<this.OP.points.length;s++)try{const n=this.OP.points[s];let e=Xn(this._chart,this._series,n.time);if(null===e){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(e=t.logicalToCoordinate(i))}const r=this._series.priceToCoordinate(n.price);if(null==e||null===r)continue;if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return s}catch{continue}return null}startDrag(t){this.lC=!0,this.EP=t}stopDrag(){this.lC=!1,this.EP=-1}updateDrag(t,i){this.lC&&-1!==this.EP&&this.OP.points&&this.EP>=0&&this.EP<this.OP.points.length&&(this.OP.points[this.EP]={time:t,price:i},this.cM(),this.OP.onUpdate&&this.OP.onUpdate())}getPoints(){return this.OP.points||[]}addPoint(t){this.OP.points||(this.OP.points=[]),this.OP.points.push(t),this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.OP.points||[]).map(t=>Mh(t)),style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,showArrowHead:this.OP.showArrowHead,showCircles:this.OP.showCircles,circleRadius:this.OP.circleRadius}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return!this.TP}remove(){if(this.HS&&(this._chart.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.BP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.BP),this.BP=null}this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.OP.onRemove&&this.OP.onRemove()}}function Vl(t,i){return new Il(t,i)}class Ll{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Al{constructor(t){this.nC=t,this.Jt=new Ll(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class El extends xh{constructor(t,i){super(t,"brush",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.$P=!1,this.TP=!1,this.HP=[],this.NP=!1,this.kf=null,this._S=null,this.vS=null,this.wS=null,this.bS=null,this.UP=void 0,this.pS=null,this.lC=!1,this.aC=null,this.AC=null,this.qP={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.qP),this.zy(),0===(this.qP.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.$P)return;const t=this._chart.chartElement();t&&(this.kf=t,this.$P=!0,this.vS=t=>this.mS(t),this.wS=t=>this.gS(t),this.bS=()=>this.MS(),this.pS=t=>{this.UP=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.pS),t.addEventListener("pointerdown",this.vS,!0),t.addEventListener("pointermove",this.wS,!0),t.addEventListener("pointerup",this.bS,!0),t.addEventListener("pointercancel",this.bS,!0))}stopDrawingMode(){if(!this.$P)return;this.jP(),this.$P=!1;const t=this.kf;t&&(this.vS&&t.removeEventListener("pointerdown",this.vS,!0),this.wS&&t.removeEventListener("pointermove",this.wS,!0),this.bS&&(t.removeEventListener("pointerup",this.bS,!0),t.removeEventListener("pointercancel",this.bS,!0))),this.pS&&(this._chart.unsubscribeCrosshairMove(this.pS),this.pS=null),this.vS=null,this.wS=null,this.bS=null,this.kf=null}isDrawingModeActive(){return this.$P}mS(t){if(this.YP())return;const i=this.XP(t);null!==i&&(this.TP=!0,this.HP=[i],this._S=t.pointerId,Ph(this._chart,!0),this.kf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.GP())}gS(t){if(!this.TP)return;const i=this.XP(t);if(null===i)return;const s=this.HP[this.HP.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.qP.sampleDistance??4)||(this.HP.push(i),t.preventDefault(),t.stopPropagation(),this.GP())}MS(){this.TP&&this.jP()}jP(){if(!this.TP)return;this.TP=!1,this.LS();const t=[];for(const i of this.HP){const s=Yn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.HP=[],t.length<2?this.cM():(this.qP.points=t,this.stopDrawingMode(),this.cM(),this.qP.onUpdate&&this.qP.onUpdate(),this.qP.onComplete&&this.qP.onComplete())}YP(){const t=this.UP;return"string"==typeof t&&t.split("#")[0]!==this.id}LS(){null!==this._S&&(this.kf&&this.kf.hasPointerCapture(this._S)&&this.kf.releasePointerCapture(this._S),this._S=null)}XP(t){const i=this.KP();if(null===i)return null;const s=i.getBoundingClientRect();return{ut:t.clientX-s.left,ct:t.clientY-s.top}}KP(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}GP(){this.NP||(this.NP=!0,requestAnimationFrame(()=>{this.NP=!1,this.cM()}))}drawToCanvas(t,i,s){const n=this.TP?this.HP.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.ZP(i,s);if(0===n.length)return;const e=this.rC;if(t.strokeStyle=this.qP.color,t.lineWidth=(this.qP.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.qP.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.hC||this.isLocked()||(this.PC(t,n[0],i),this.PC(t,n[n.length-1],i))}PC(t,i,s){t.fillStyle=this.qP.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()}ZP(t,i){const s=this.qP.points??[],n=[];for(const e of s){const s=Xn(this._chart,this._series,e.time),r=this._series.priceToCoordinate(e.price);null!==s&&null!==r&&n.push({ut:s*t,ct:r*i})}return n}hitTest(t,i){const s=this.ZP(1,1);for(let n=1;n<s.length;n++)if(Bl(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.lC=!0,this.aC=i,this.AC=(this.qP.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.AC;if(!this.lC||null===s||!this.qP.points)return;const n=mh(this.aC,t,i);this.qP.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.cM(),this.qP.onUpdate&&this.qP.onUpdate()}stopDrag(){this.lC=!1,this.aC=null,this.AC=null}setColor(t){this.qP.color=t,this.cM()}color(){return this.qP.color??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}zy(){this.nh=new Al(this);const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.stopDrawingMode(),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null),this.nh=null,this.qP.onRemove&&this.qP.onRemove()}_serializeShape(){return{type:"brush",points:(this.qP.points??[]).map(Mh),style:{color:this.qP.color,lineWidth:this.qP.lineWidth,smoothing:this.qP.smoothing}}}getPoints(){return this.qP.points??[]}}function Bl(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 Ol(t,i={}){return new El(t,i)}class Wl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.nC=t,this.Jt=new Wl(t)}renderer(){return this.nC.isComplete()?this.Jt:null}}class $l extends xh{constructor(t,i){super(t,"text-tool",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.XC=null,this.JP=!1,this.QP=null,this.tT={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.tT),this.zy(),this.iT()}iT(){const t=t=>{if(!this.JP)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.tT.text&&""!==this.tT.text.trim()&&"Type here..."!==this.tT.text||this.remove())};this.QP=t,this._chart.subscribeClick(t)}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new zl(this)}getTime(){return this.tT.time}getPrice(){return this.tT.price}getText(){return this.tT.text||""}getOptions(){return this.tT}setPosition(t,i){this.tT.time=t,this.tT.price=i,this._update()}setText(t){this.tT.text=t,this._update(),this.tT.onTextChange&&this.tT.onTextChange(t)}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}isComplete(){return!(!this.tT.time||void 0===this.tT.price)}setColor(t){this.tT.textColor=t,this.tT.borderColor=t,this.cM()}color(){return this.tT.textColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this._update())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this._update())}isHovered(){return this.hC}setEditing(t){this.JP!==t&&(this.JP=t,this._update())}isEditing(){return this.JP}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.tT.time,n=this.tT.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.tT.fontSize||14,l=this.tT.padding||8,o=this.tT.text||"",a=.6*h,_=Math.min(o.length*a,this.tT.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.tT.time,n=this.tT.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0;return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"anchor":null}startDrag(t,i){this.lC=!0,this.oC=t,this.aC=i,this.XC={gt:this.tT.time,bt:this.tT.price}}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.XC=null}updateDrag(t,i){if(this.lC){if("body"===this.oC&&this.XC){const s=mh(this.aC,t,i);this.setPosition(this.XC.gt+s.gt,this.XC.bt+s.bt)}else this.setPosition(t,i);this.tT.onUpdate&&this.tT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.tT.time,e=this.tT.price,r=this.tT.text||"",h=(Xn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.tT.fontSize||14)*i,a=(this.tT.padding||8)*i,_=(this.tT.maxWidth||200)*i;t.font=`${o}px ${this.tT.fontFamily||"Arial"}`,t.textBaseline="top";const u=r.split(" "),c=[];let d="";for(const i of u){const s=d?`${d} ${i}`:i;t.measureText(s).width>_&&d?(c.push(d),d=i):d=s}d&&c.push(d);let p=0;for(const i of c){const s=t.measureText(i);p=Math.max(p,s.width)}const f=p+2*a,v=1.2*o,m=c.length*v+2*a,w=this.tT.backgroundOpacity||.8,g=this.tT.backgroundColor||"#2962FF";t.fillStyle=this.Oy(g,w),t.fillRect(h,l,f,m),(this.rC||this.hC)&&(t.strokeStyle=this.tT.borderColor??"#FFFFFF",t.lineWidth=(this.tT.borderWidth||1)*i*(this.rC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.tT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.tT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.tT.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.rC||this.hC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.tT.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()}}Oy(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:[bh(this.tT.price??0,gh(this.tT.time))],style:{fontSize:this.tT.fontSize,fontFamily:this.tT.fontFamily,textColor:this.tT.textColor,backgroundColor:this.tT.backgroundColor,backgroundOpacity:this.tT.backgroundOpacity,padding:this.tT.padding,borderColor:this.tT.borderColor,borderWidth:this.tT.borderWidth,textAlign:this.tT.textAlign,maxWidth:this.tT.maxWidth},extra:{text:this.tT.text}}}remove(){this.QP&&(this._chart.unsubscribeClick(this.QP),this.QP=null),this.Ub&&this._series&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.tT.onRemove&&this.tT.onRemove()}}function Hl(t,i){return new $l(t,i)}class Nl{constructor(t){this.sT=t}calculatePips(t,i){return Math.abs(i-t)/this.sT.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.sT={...this.sT,...t}}getPipConfig(){return{...this.sT}}}function Ul(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 ql(t,i){return"number"==typeof t?Ul(t):void 0!==i?Ul(i):{pipValue:.1,decimals:1}}class jl{constructor(t){this.sT=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.sT.pipValue,timeDifference:this.nT(t,s),barCount:e}}nT(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.sT={...this.sT,...t}}getPipConfig(){return{...this.sT}}}class Yl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xl{constructor(t){this.nC=t,this.Jt=new Yl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}}class Gl extends xh{constructor(t,i){super(t,"ruler-tool",i),this.Ub=null,this.eC=null,this.Yb=null,this.nh=null,this.wP=null,this.cC=!1,this.rC=!1,this.hC=!1,this.pC=null,this.lC=!1,this.gP=null,this.sp=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||ql(this.eT.symbol||"DEFAULT");this.MP=new jl(s),this.zy(),this.eT.interactive?this.vC():this.eT.point1Time&&this.eT.point2Time&&(this.cC=!0,this.yP())}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Xl(this)}vC(){this.wP=new Rh(this._chart,this._series,{Qx:t=>{this.eT.point1Time=t.gt,this.eT.point1Price=t.bt,this.cM()},tC:t=>{this.eT.point2Time=t.gt,this.eT.point2Price=t.bt},iC:(t,i)=>{this.eT.point1Time=t.gt,this.eT.point1Price=t.bt,this.eT.point2Time=i.gt,this.eT.point2Price=i.bt,this.cC=!0,this.pC=null,this.yP(),this.SP(),this.cM()},sC:t=>{this.pC=t,this.cM()}}),this.wP.Hx()}drawToCanvas(t,i,s){if(!this.cC&&this.eT.point1Time&&this.pC)return void this.CC(t,i,s);if(!this.cC||!this.eT.point1Time||!this.eT.point2Time)return;const n=(Xn(this._chart,this._series,this.eT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.eT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.eT.point2Price)??0)*s;(this.rC||this.hC&&!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.rT(t,n,e,r,h,i),this.PC(t,n,e,i),this.PC(t,r,h,i),this.eT.showLabel&&this.Yb&&this.FC(t,n,e,r,h,i,s)}rT(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()}PC(t,i,s,n){const e=this.rC?this.eT.selectionColor:this.eT.lineColor,r=this.rC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.rC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}CC(t,i,s){if(!this.eT.point1Time||!this.pC)return;const n=(Xn(this._chart,this._series,this.eT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.eT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.pC.gt)??0)*i,h=(this._series.priceToCoordinate(this.pC.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.PC(t,n,e,i),t.globalAlpha=.5,this.PC(t,r,h,i),t.globalAlpha=1}FC(t,i,s,n,e,r,h){if(!this.Yb)return;const l=(i+n)/2,o=(s+e)/2,a=this.eT.measure??"both",_=[];"time"!==a&&(_.push(this.MP.formatPips(this.Yb.pips)),_.push(this.MP.formatPercent(this.Yb.pricePercent))),"price"!==a&&_.push(this.MP.formatBarCount(this.Yb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.eT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.eT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}yP(){if(!this.eT.point1Time||!this.eT.point2Time||void 0===this.eT.point1Price||void 0===this.eT.point2Price)return;const t=this.hT();this.Yb=this.MP.calculateMetrics(this.eT.point1Time,this.eT.point1Price,this.eT.point2Time,this.eT.point2Price,t),this.eT.onUpdate&&this.Yb&&this.eT.onUpdate(this.Yb)}hT(){if(!this.eT.point1Time||!this.eT.point2Time)return 0;const t=Xn(this._chart,this._series,this.eT.point1Time),i=Xn(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.yP(),this.cM()}getMetrics(){return this.Yb}remove(){this.destroy()}destroy(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.wP&&(this.wP.m(),this.wP=null),this.CP(),this.eT.onRemove&&this.eT.onRemove()}SP(){this.sp=t=>{this.xP(t)},this._chart.subscribeCrosshairMove(this.sp)}CP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}xP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.rC||!this.lC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.gP?(this.eT.point1Time=i,this.eT.point1Price=s):"point2"===this.gP&&(this.eT.point2Time=i,this.eT.point2Price=s),this.yP(),this.cM())}startDrag(t){this.lC=!0,this.gP=t}stopDrag(){this.lC=!1,this.gP=null}updateDrag(t,i){this.lC&&this.gP&&("point1"===this.gP?(this.eT.point1Time=t,this.eT.point1Price=i):(this.eT.point2Time=t,this.eT.point2Price=i),this.yP(),this.cM())}hitTestEndpoint(t,i){if(!this.cC||!this.eT.point1Time||!this.eT.point2Time)return null;const s=Xn(this._chart,this._series,this.eT.point1Time)??0,n=this._series.priceToCoordinate(this.eT.point1Price)??0,e=Xn(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}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.yP(),this.cM()}_serializeShape(){return{type:"ruler",points:[bh(this.eT.point1Price??0,gh(this.eT.point1Time)),bh(this.eT.point2Price??0,gh(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.cM()}color(){return this.eT.lineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}isSelected(){return this.rC}isComplete(){return this.cC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this.cC||!this.eT.point1Time||!this.eT.point2Time)return!1;const s=Xn(this._chart,this._series,this.eT.point1Time)??0,n=this._series.priceToCoordinate(this.eT.point1Price)??0,e=Xn(this._chart,this._series,this.eT.point2Time)??0,r=this._series.priceToCoordinate(this.eT.point2Price)??0;return this.lT(t,i,s,n,e,r)<=(this.rC?12:8)}lT(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;let a,_,u=-1;0!==o&&(u=((t-s)*h+(i-n)*l)/o),u<0?(a=s,_=n):u>1?(a=e,_=r):(a=s+u*h,_=n+u*l);const c=t-a,d=i-_;return Math.sqrt(c*c+d*d)}}function Kl(t,i){return new Gl(t,i)}class Zl{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Jl{constructor(t){this.nC=t,this.Jt=new Zl(t)}renderer(){return this.nC.isVisible()?this.Jt:null}}class Ql extends xh{constructor(t,i){super(t,"position-tool",i),this.Ub=null,this.eC=null,this.Yb=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.oC=null,this.aC=null,this.XC=null,this.oT=null,this.aT=null,this._T={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this._T);const s=this._T.pipConfig||ql(this._T.entryPrice);this.MP=new Nl(s),this.zy(),this.yP()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new Jl(this)}drawToCanvas(t,i,s){if(this.oT&&this._T.takeProfit){const n=this._chart.timeScale();this.uT(t,this.oT,i,s,n),(this.hC||this.rC)&&this.FC(t,this.oT,"profit",i,s,n)}if(this.aT&&this._T.stopLoss){const n=this._chart.timeScale();if(this.uT(t,this.aT,i,s,n),this.hC||this.rC){const n=this._chart.timeScale();this.FC(t,this.aT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.cT(t,i,s,n),this._T.takeProfit){const n=this._chart.timeScale();this.PC(t,this._T.takeProfit,this._T.profitColor,i,s,n)}if(this._T.stopLoss){const n=this._chart.timeScale();this.PC(t,this._T.stopLoss,this._T.lossColor,i,s,n)}}uT(t,i,s,n,e){const r=(Xn(this._chart,this._series,this._T.entryTime)??0)*s;let h;if(this._T.endTime)h=(Xn(this._chart,this._series,this._T.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.dT)??0)*n,o=(this._series.priceToCoordinate(i.pT)??0)*n;t.fillStyle=this.Oy(i.R,.15),t.fillRect(r,Math.min(l,o),h-r,Math.abs(o-l)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(r,o),t.lineTo(h,o),t.stroke()}cT(t,i,s,n){const e=(Xn(this._chart,this._series,this._T.entryTime)??0)*i,r=(this._series.priceToCoordinate(this._T.entryPrice)??0)*s;let h;if(this._T.endTime)h=(Xn(this._chart,this._series,this._T.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this._T.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._T.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const o=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,o),t.stroke(),t.setLineDash([]),!this.rC&&!this.hC||this.isLocked())t.fillStyle=this._T.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)}}yP(){this._T.stopLoss&&this._T.takeProfit&&(this.Yb=this.MP.calculateMetrics(this._T.entryPrice,this._T.stopLoss,this._T.takeProfit,this._T.quantity),this.fT(),this._T.onUpdate&&this.Yb&&this._T.onUpdate(this.Yb))}fT(){const t=this.vT();this._T.takeProfit&&(this.oT={mT:this._T.entryTime,wT:t,dT:this._T.entryPrice,pT:this._T.takeProfit,R:this._T.profitColor,ky:this._T.opacity}),this._T.stopLoss&&(this.aT={mT:this._T.entryTime,wT:t,dT:this._T.entryPrice,pT:this._T.stopLoss,R:this._T.lossColor,ky:this._T.opacity})}vT(){this._chart.timeScale().getVisibleLogicalRange();return this._T.entryTime}FC(t,i,s,n,e,r){if(!this.Yb)return;const h=(Xn(this._chart,this._series,this._T.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.pT)??0)*e,o="profit"===s,a=o?this.Yb.takeProfitPips:this.Yb.stopLossPips,_=o?this._T.takeProfit:this._T.stopLoss,u=this.Yb.riskRewardRatio,c=o?`Objetivo: ${_?.toFixed(5)} (${a.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${a.toFixed(1)} pips)`;t.font=11*n+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const d=6*n,p=t.measureText(c).width+2*d,f=20*n,v=h+8*n,m=l-f/2;t.fillStyle=i.R,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}PC(t,i,s,n,e,r){const h=(Xn(this._chart,this._series,this._T.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,o=s;let a;if(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(h,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this._T.endTime)a=(Xn(this._chart,this._series,this._T.endTime)??0)*n;else{a=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(a-_/2,l-_/2,_,_),t.strokeRect(a-_/2,l-_/2,_,_)}Oy(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._T={...this._T,...t},this.yP(),this._update()}getMetrics(){return this.Yb}setStopLoss(t){this._T.stopLoss=t,this.yP(),this._update()}setTakeProfit(t){this._T.takeProfit=t,this.yP(),this._update()}setEntryPrice(t){this._T.entryPrice=t,this.yP(),this._update()}_serializeShape(){return{type:"position",points:[bh(this._T.entryPrice,gh(this._T.entryTime))],style:{profitColor:this._T.profitColor,lossColor:this._T.lossColor,entryLineColor:this._T.entryLineColor,opacity:this._T.opacity,showTooltips:this._T.showTooltips},extra:{endTime:gh(this._T.endTime),stopLoss:this._T.stopLoss,takeProfit:this._T.takeProfit,quantity:this._T.quantity,pipConfig:this._T.pipConfig}}}setColor(t){this._T.entryLineColor=t,this.cM()}color(){return this._T.entryLineColor??""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):this.hitTest(t,i)?vh(this.id,"body",!1):null}hitTest(t,i){if(!this._T.stopLoss&&!this._T.takeProfit)return!1;const s=Xn(this._chart,this._series,this._T.entryTime)??0;let n;if(this._T.endTime)n=Xn(this._chart,this._series,this._T.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this._T.takeProfit&&this._T.stopLoss){const e=this._series.priceToCoordinate(this._T.takeProfit)??0,r=this._series.priceToCoordinate(this._T.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return!0;const o=8;if(Math.abs(t-s)<=o&&i>=h&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Xn(this._chart,this._series,this._T.entryTime)??0;let n;if(this._T.endTime)n=Xn(this._chart,this._series,this._T.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this._T.takeProfit){const n=this._series.priceToCoordinate(this._T.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this._T.stopLoss){const n=this._series.priceToCoordinate(this._T.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this._T.takeProfit){const s=this._series.priceToCoordinate(this._T.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this._T.stopLoss){const s=this._series.priceToCoordinate(this._T.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._T.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this._T.takeProfit&&this._T.stopLoss){const e=this._series.priceToCoordinate(this._T.takeProfit)??0,r=this._series.priceToCoordinate(this._T.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.lC=!0,this.oC=t,this.aC=i,"move"===t&&(this.XC={gT:this._T.entryPrice,bT:this._T.entryTime??null,By:this._T.endTime??null,MT:this._T.takeProfit??null,yT:this._T.stopLoss??null})}stopDrag(){this.lC=!1,this.oC=null,this.aC=null,this.XC=null}updateDrag(t,i){if(this.lC&&this.oC){if("entry"===this.oC)this._T.entryPrice=i;else if("move"===this.oC){if(this.XC){const s=mh(this.aC,t,i),n=this.XC;this._T.entryPrice=n.gT+s.bt,null!==n.MT&&(this._T.takeProfit=n.MT+s.bt),null!==n.yT&&(this._T.stopLoss=n.yT+s.bt),null!==n.bT&&(this._T.entryTime=this.ST(n.bT,s.gt)),null!==n.By&&(this._T.endTime=this.ST(n.By,s.gt))}}else"tp"===this.oC||"tp-right"===this.oC?(this._T.takeProfit=i,"tp-right"===this.oC?this._T.endTime=t:this._T.entryTime=t):"sl"!==this.oC&&"sl-right"!==this.oC||(this._T.stopLoss=i,"sl-right"===this.oC?this._T.endTime=t:this._T.entryTime=t);this.yP(),this.cM()}}ST(t,i){return t+i}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this._T.onRemove&&this._T.onRemove()}}function to(t,i){return new Ql(t,i)}class io{constructor(t){this.nC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.nC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class so{constructor(t){this.nC=t,this.Jt=new io(t)}renderer(){return this.nC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class no extends xh{constructor(t,i){super(t,"gantt",i),this.Ub=null,this.eC=null,this.nh=null,this.rC=!1,this.hC=!1,this.lC=!1,this.xT=-1,this.aC=null,this.XC=null,this.CT=-1,this.PT={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.PT),this.zy()}zy(){this.nh=this.mC();const t={attached:t=>{this.eC=t.requestUpdate},detached:()=>{this.eC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.wC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}mC(){return new so(this)}drawToCanvas(t,i,s){if(!this.PT.segments||0===this.PT.segments.length)return;const n=50*s,e=this.PT.rowHeight*s,r=this.PT.rowSpacing*s;this.PT.showGrid&&this.sm(t,n,e,r,i,s),this.PT.segments.forEach((s,h)=>{const l=(Xn(this._chart,this._series,s.startTime)??0)*i,o=(Xn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.CT||this.hC&&!this.isLocked();this.TT(t,l,o,a,e,s,_,i)})}sm(t,i,s,n,e,r){if(!this.PT.segments)return;const h=Math.max(...this.PT.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()}}TT(t,i,s,n,e,r,h,l){const o=s-i,a=this.Oy(r.color,h?this.PT.fillOpacity+.2:this.PT.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.PT.borderWidth+(this.rC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.PT.showLabels&&r.label&&this.FC(t,i,n,o,e,r.label,l)}FC(t,i,s,n,e,r,h){const l=11*h,o=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let a=r;const _=n-2*o;let u=t.measureText(a).width;if(u>_&&_>0){for(;u>_&&a.length>0;)a=a.slice(0,-1),u=t.measureText(a+"...").width;a+="..."}t.fillText(a,i+o,s+e/2)}Oy(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.PT.segments||(this.PT.segments=[]),this.PT.segments.push(t),this.cM(),this.PT.onUpdate&&this.PT.onUpdate()}removeSegment(t){this.PT.segments&&t>=0&&t<this.PT.segments.length&&(this.PT.segments.splice(t,1),this.cM(),this.PT.onUpdate&&this.PT.onUpdate())}getSegments(){return this.PT.segments||[]}setColor(t){const i=this.PT.segments??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.PT.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.rC!==t&&(this.rC=t,this.cM())}isSelected(){return this.rC}setHovered(t){this.hC!==t&&(this.hC=t,this.cM())}isHovered(){return this.hC}wC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?vh(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.PT.segments?.[this.CT];s&&(this.lC=!0,this.xT=this.CT,this.aC=i,this.XC={Ey:s.startTime,By:s.endTime})}updateDrag(t,i){const s=this.PT.segments?.[this.xT];if(!this.lC||!this.XC||!s)return;const n=mh(this.aC,t,i);s.startTime=this.XC.Ey+n.gt,s.endTime=this.XC.By+n.gt,this.cM(),this.PT.onUpdate&&this.PT.onUpdate()}stopDrag(){this.lC=!1,this.xT=-1,this.aC=null,this.XC=null}hitTest(t,i){if(!this.PT.segments||0===this.PT.segments.length)return!1;const s=this.PT.rowHeight,n=this.PT.rowSpacing;for(let e=0;e<this.PT.segments.length;e++){const r=this.PT.segments[e],h=Xn(this._chart,this._series,r.startTime)??0,l=Xn(this._chart,this._series,r.endTime)??0,o=50+r.level*(s+n);if(t>=h&&t<=l&&i>=o&&i<=o+s)return this.CT=e,!0}return this.CT=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.PT.rowHeight,rowSpacing:this.PT.rowSpacing,fillOpacity:this.PT.fillOpacity,borderWidth:this.PT.borderWidth,showLabels:this.PT.showLabels,showGrid:this.PT.showGrid},extra:{segments:(this.PT.segments||[]).map(t=>({Ey:gh(t.startTime),By:gh(t.endTime),sn:t.level,Zl:t.label,R:t.color,kT:t.category}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.eC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.PT.onRemove&&this.PT.onRemove()}}function eo(t,i){return new no(t,i)}class ro{constructor(t,i,s={}){this.DT=[],this.RT=[],this.FT=[],this.IT=!1,this.VT=new Map,this.LT=null,this.AT=null,this.ET=null,this.HS=null,this.BT=null,this.sp=null,this.OT=null,this.WT=null,this.zT=null,this.$T=null,this.HT=null,this._S=null,this.NT=!1,this.UT=null,this.qT=null,this.jT=new a,this.lC=!1,this.YT=null,this.XT=new Set,this.GT=null,this.KT=new a,this.If=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.ZT()}startDrawing(t){this.ET=t,this.JT()}activeDrawingType(){return this.ET}stopDrawing(){this.ET=null}addTool(t,i){const s=i??t.id;return this.VT.set(s,t),t.isComplete()||this.XT.add(s),this.recordChange(),s}hasPendingDrawing(){return this.XT.size>0}cancelPendingDrawings(){if(0===this.XT.size)return 0;let t=0;for(const i of Array.from(this.XT)){const s=this.VT.get(i);s&&(this.LT===i&&this.QT(null),s.remove(),this.VT.delete(i),t++)}return this.XT.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.KT.i(t)}unsubscribeDrawingCompleted(t){this.KT._(t)}tk(){0!==this.XT.size&&null===this.GT&&(this.GT=setTimeout(()=>{this.GT=null;for(const t of Array.from(this.XT)){const i=this.VT.get(t);i?i.isComplete()&&(this.XT.delete(t),this.KT.p(t)):this.XT.delete(t)}},0))}removeTool(t){const i=this.VT.get(t);return!!i&&(this.LT===t&&this.QT(null),i.remove(),this.VT.delete(t),this.XT.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.VT.has(t)&&(this.QT(t),!0)}QT(t){if(this.LT===t)return;const i=null===this.LT?void 0:this.VT.get(this.LT);i&&i.setSelected(!1),this.LT=t;const s=null===t?void 0:this.VT.get(t);s&&s.setSelected(!0),this.ik()}recordChange(){this.IT||(this.DT.push(this.FT),this.DT.length>100&&this.DT.shift(),this.RT=[],this.FT=this.serializeAll())}canUndo(){return this.DT.length>0}canRedo(){return this.RT.length>0}undo(){const t=this.DT.pop();return void 0!==t&&(this.RT.push(this.FT),this.sk(t),!0)}redo(){const t=this.RT.pop();return void 0!==t&&(this.DT.push(this.FT),this.sk(t),!0)}sk(t){this.IT=!0;try{this.restoreAll({chart:this.If,series:this.be},t,!0),this.FT=t}finally{this.IT=!1}}subscribeSelectionChanged(t){this.jT.i(t)}unsubscribeSelectionChanged(t){this.jT._(t)}selectionBounds(){if(null===this.LT)return null;const t=this.VT.get(this.LT);return t?this.nk(t):null}nk(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Xn(this.If,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,o),h=Math.max(h,o))}if(!l)return null;const o=this.ek(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}ek(t){const i=this.If.chartElement(),s=this.rk(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}}ik(){this.jT.p({id:this.LT,bounds:this.selectionBounds()})}deselectAll(){this.JT()}deleteSelected(){if(this.LT){const t=this.VT.get(this.LT);return(!t||!t.isLocked())&&this.removeTool(this.LT)}return!1}getSelectedToolId(){return this.LT}getAllTools(){return new Map(this.VT)}getTool(t){return this.VT.get(t)}clearAll(){this.QT(null),this.VT.forEach(t=>t.remove()),this.VT.clear(),this.XT.clear(),this.recordChange()}getToolCount(){return this.VT.size}isToolSelected(t){return this.LT===t}serializeAll(){const t=[];for(const i of this.VT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=ro.hk(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 hk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({lk:yh(n[t]),ak:Sh(n[t],"price")??0});switch(s){case"trendLine":return Lh(t,{point1Time:h(0).lk,point1Price:h(0).ak,point2Time:h(1).lk,point2Price:h(1).ak,...e});case"horizontalLine":return Oh(t,{price:h(0).ak,startTime:h(0).lk??void 0,...e});case"parallelChannel":return Kh(t,{point1Time:h(0).lk,point1Price:h(0).ak,point2Time:h(1).lk,point2Price:h(1).ak,channelWidth:r?.channelWidth,...e});case"pitchfork":return tl(t,{pivotTime:h(0).lk,pivotPrice:h(0).ak,upperTime:h(1).lk,upperPrice:h(1).ak,lowerTime:h(2).lk,lowerPrice:h(2).ak,...e});case"polygon":return jh(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).lk,s.price=h(i).ak,s}),...e});case"crossLine":return Hh(t,{time:h(0).lk,price:h(0).ak,...e});case"verticalLine":return el(t,{time:h(0).lk,...e});case"fibRetracement":return cl(t,{point1Time:h(0).lk,point1Price:h(0).ak,point2Time:h(1).lk,point2Price:h(1).ak,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return vl(t,{point1:i.lk?{time:i.lk,price:i.ak}:void 0,point2:s.lk?{time:s.lk,price:s.ak}:void 0,point3:n.lk?{time:n.lk,price:n.ak}:void 0,levels:r?.levels,...e})}case"fibFan":return Ml(t,{point1Time:h(0).lk,point1Price:h(0).ak,point2Time:h(1).lk,point2Price:h(1).ak,levels:r?.levels,...e});case"rectangle":return Cl(t,{time1:h(0).lk,price1:h(0).ak,time2:h(1).lk,price2:h(1).ak,...e});case"circle":return Dl(t,{centerTime:h(0).lk,centerPrice:h(0).ak,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Vl(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Ol(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Hl(t,{time:h(0).lk,price:h(0).ak,text:r?.text,...e});case"ruler":return Kl(t,{point1Time:h(0).lk,point1Price:h(0).ak,point2Time:h(1).lk,point2Price:h(1).ak,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return to(t,{entryPrice:h(0).ak,entryTime:h(0).lk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return eo(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.GT&&(clearTimeout(this.GT),this.GT=null),this.KT.m(),this.jT.m(),this.clearAll(),this._k(),this.DT=[],this.RT=[],this.FT=[]}ZT(){this.HS=t=>{this.Zx(t)},this.If.subscribeClick(this.HS),this.sp=t=>{this.Jx(t)},this.If.subscribeCrosshairMove(this.sp);const t=this.If.chartElement();t&&(this.OT=t=>this.uk(t),this.WT=t=>this.ck(t),this.zT=t=>this.ck(t),this.$T=t=>this.dk(t),t.addEventListener("pointerdown",this.OT),t.addEventListener("pointerup",this.WT),t.addEventListener("pointercancel",this.zT),t.addEventListener("lostpointercapture",this.$T)),_s&&(this.HT=t=>this.ck(t),window.addEventListener("pointerup",this.HT)),this.Ps.enableKeyboardShortcuts&&(this.BT=t=>{this.pk(t)},document.addEventListener("keydown",this.BT))}_k(){this.HS&&(this.If.unsubscribeClick(this.HS),this.HS=null),this.sp&&(this.If.unsubscribeCrosshairMove(this.sp),this.sp=null);const t=this.If.chartElement();t&&(this.OT&&(t.removeEventListener("pointerdown",this.OT),this.OT=null),this.WT&&(t.removeEventListener("pointerup",this.WT),this.WT=null),this.zT&&(t.removeEventListener("pointercancel",this.zT),this.zT=null),this.$T&&(t.removeEventListener("lostpointercapture",this.$T),this.$T=null)),this.HT&&(window.removeEventListener("pointerup",this.HT),this.HT=null),this.BT&&(document.removeEventListener("keydown",this.BT),this.BT=null)}Zx(t){if(this.tk(),!t.point)return;if(this.NT)return void(this.NT=!1);if(this.lC)return;const i=this.fk(t.hoveredObjectId);i?this.selectTool(i):this.JT()}Jx(t){if(this.UT=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.lC&&this.YT){const i=this.VT.get(this.YT);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Yn(this.If,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.fk(t.hoveredObjectId);if(this.AT&&this.AT!==i){const t=this.VT.get(this.AT);t&&t.setHovered(!1)}if(i){const t=this.VT.get(i);t&&t.setHovered(!0)}this.AT=i}fk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.VT)if(s.id===i)return t;return null}uk(t){if(this.lC)return;Ph(this.If,!1);const i=this.If.chartElement();if(!i)return;const s=null!==this.AT&&null!==this.UT?{vk:this.AT,kw:this.UT}:this.mk(t);if(null===s)return;const{vk:n,kw:e}=s,r=this.VT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.wk(r,e.ut,e.ct);if(null!==h&&null!==l){Ph(this.If,!0),this.selectTool(n),this.lC=!0,this.NT=!0,this.YT=n,this._S=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this._S=null}r.startDrag(h,l),this.gk()}}ck(t){if(!this.lC||null===this.YT)return;if(t&&null!==this._S&&t.pointerId!==this._S)return;const i=this.YT;this.lC=!1,this.YT=null;try{const t=this.VT.get(i);t&&t.stopDrag()}finally{this.LS(),this.bk()}this.recordChange()}dk(t){null!==this._S&&t.pointerId!==this._S||(this._S=null,this.ck())}rk(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}mk(t){for(const[i,s]of this.VT){if(!s.isVisible()||s.isLocked())continue;const n=this.rk(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{vk:i,kw:r}}return null}LS(){if(null===this._S)return;const t=this.If.chartElement();t&&t.hasPointerCapture(this._S)&&t.releasePointerCapture(this._S),this._S=null}gk(){if(null!==this.qT)return;const t=this.If.options();this.qT={Mk:f(t.handleScroll),yk:f(t.handleScale)},this.If.applyOptions({handleScroll:!1,handleScale:!1})}bk(){const t=this.qT;this.qT=null,null!==t&&this.If.applyOptions({handleScroll:t.Mk,handleScale:t.yk})}pk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.tk(),"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.ck(),this.JT(),this.stopDrawing(),t.preventDefault())}wk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Yn(this.If,t.series(),i)}}JT(){this.QT(null)}}const ho={...t,color:"#2196f3"};var lo=Object.freeze({__proto__:null,AreaSeries:Se,ArrowTool:Il,BarSeries:Te,BaselineSeries:be,BrushTool:El,CandlestickSeries:Re,CircleTool:kl,get ColorType(){return Li},CrossLineTool:$h,get CrosshairMode(){return U},DEFAULT_SESSIONS:Yr,DraggablePriceLine:nh,DrawingToolsManager:ro,EXTENDED_FIBONACCI_RATIOS:hl,FibonacciCalculator:ll,FibonacciExtensionTool:fl,FibonacciFanTool:bl,FibonacciTool:ul,GanttTool:no,HistogramSeries:Ve,HorizontalLineTool:Bh,InteractiveLineManager:eh,get LastPriceAnimationMode(){return Ii},LineSeries:re,get LineStyle(){return s},get LineType(){return i},get MismatchDirection(){return xt},ParallelChannelTool:Gh,PitchforkTool:Qh,PolygonTool:qh,PositionCalculator:Nl,PositionLine:dh,PositionMarkersManager:Cr,PositionTool:Ql,get PriceLineSource(){return Vi},get PriceScaleMode(){return di},RectangleTool:xl,RulerCalculator:jl,RulerTool:Gl,STANDARD_FIBONACCI_RATIOS:rl,TextTool:$l,get TickMarkType(){return Ai},get TrackingModeExitMode(){return Fi},TradingSessionsIndicator:Xr,TrendLineTool:Vh,VerticalLineTool:nl,VolumeProfileIndicator:Zr,applyADX:function(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=Vr(0,100),h=i.addSeries(re,{color:n.colorADX,autoscaleInfoProvider:r},e),l=i.addSeries(re,{color:n.colorPlusDI,autoscaleInfoProvider:r},e),o=i.addSeries(re,{color:n.colorMinusDI,autoscaleInfoProvider:r},e),a=Lr(i,h,e);i.priceScale(h.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Er(h,n.levelColor),u=Or({e_:t,jf:i,by:[h,l,o],Zl:"ADX",W:n,Sy:["period"],My:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Sk:[],xk:[],Ck:[]};const s=[],n=[],e=[];for(let i=1;i<t.length;i++){const r=t[i],h=t[i-1];if(!("high"in r)||!("low"in r)||!("close"in h)){s.push(0),n.push(0),e.push(0);continue}s.push(Math.max(r.high-r.low,Math.abs(r.high-h.close),Math.abs(r.low-h.close)));const l=r.high-h.high,o=h.low-r.low;n.push(l>o&&l>0?l:0),e.push(o>l&&o>0?o:0)}let r=0,h=0,l=0;for(let t=0;t<i;t++)r+=s[t],h+=n[t],l+=e[t];const o=[],a=[],_=[],u=[];for(let c=i;c<s.length;c++){r=r-r/i+s[c],h=h-h/i+n[c],l=l-l/i+e[c];const d=0===r?0:h/r*100,p=0===r?0:l/r*100,f=d+p,v=0===f?0:Math.abs(d-p)/f*100;u.push(v);const m=t[c+1];if(m&&void 0!==m.time)if(a.push({time:m.time,value:d}),_.push({time:m.time,value:p}),u.length===i){let t=0;for(const i of u)t+=i;o.push({time:m.time,value:t/i})}else if(u.length>i){const t=o[o.length-1].value;o.push({time:m.time,value:(t*(i-1)+v)/i})}}return{Sk:o,xk:a,Ck:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Sk],[l,n?s.xk:[]],[o,n?s.Ck:[]]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),o.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:l,minusDI:o,...u}},applyATR:function(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(re,{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=Or({e_:t,jf:i,by:[e],Zl:"ATR",W:n,Sy:["period"],My:(t,i)=>[[e,r(t,i.period??14)]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},applyBollingerBands:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Bollinger Bands",W:n,Sy:["period","stdDev"],My:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{aP:[],Pk:[],_P:[]};const n=[];for(const i of t)"close"in i?n.push(i.close):"value"in i?n.push(i.value):n.push(0);const e=[],r=[],h=[];for(let l=i-1;l<n.length;l++){let o=0;for(let t=0;t<i;t++)o+=n[l-t];const a=o/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-a,2);const u=Math.sqrt(_/i),c=a+u*s,d=a-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:a}),h.push({time:i,value:d})}}return{aP:e,Pk:r,_P:h}})(t,i.period??20,i.stdDev??2);return[[r,s.aP],[h,s.Pk],[l,s._P]]},yy:t=>{const i=t.lineWidth??1;r.applyOptions({color:t.colorUpper,lineWidth:i}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:r,middle:h,lower:l,...o}},applyCCI:function(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(re,{color:n.color,lineWidth:n.lineWidth},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(const i of t)"high"in i&&"low"in i&&"close"in i?s.push((i.high+i.low+i.close)/3):s.push("value"in i?i.value:0);const n=[];for(let e=i-1;e<s.length;e++){let r=0;for(let t=0;t<i;t++)r+=s[e-t];const h=r/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-h);const o=l/i,a=0===o?0:(s[e]-h)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=Or({e_:t,jf:i,by:[r],Zl:"CCI",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??20)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applyDonchianChannels:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Donchian Channels",W:n,Sy:["period"],My:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{aP:[],Pk:[],_P:[]};const s=[],n=[],e=[];for(let r=i-1;r<t.length;r++){let h=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[r-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>h&&(h=n),e<l&&(l=e)}const o=t[r];void 0!==o.time&&h!==-1/0&&l!==1/0&&(s.push({time:o.time,value:h}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(h+l)/2}))}return{aP:s,Pk:n,_P:e}})(t,i.period??20);return[[r,s.aP],[h,s.Pk],[l,s._P]]},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}},applyEMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"EMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyHeikinAshi:function(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(Re,{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=Fr(t):i||null===h||(h(),h=null)},o=Or({e_:t,jf:i,by:[r],Zl:"Heikin Ashi",W:n,Sy:[],My:t=>[[r,Ur(t)]],yy:t=>{r.applyOptions({upColor:t.upColor,downColor:t.downColor,borderVisible:t.borderVisible,borderUpColor:t.borderUpColor,borderDownColor:t.borderDownColor,wickVisible:t.wickVisible,wickUpColor:t.wickUpColor,wickDownColor:t.wickDownColor}),l(!0===t.hideSource)}});return{Wa:r,options:o.options,applyOptions:o.applyOptions,recalculate:o.recalculate,remove:()=>{o.remove();try{l(!1)}catch(t){}}}},applyIchimoku:function(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(re,{color:t},e),h=r(n.colorConversion),l=r(n.colorBase),o=r(n.colorSpanA),a=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new $r(i,t,()=>u,()=>({Iy:c.cloudBullishColor??"#089981",Vy:c.cloudBearishColor??"#F23645",ky: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=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{Tk:h,eh:l,Dy:o,Ry:a,kk:_,Dk:u};const c=function(t){if(t.length<3)return null;const i=new Map;let s=null,n=0;for(let e=1;e<t.length;e++){const r=t[e-1].time,h=t[e].time;if("number"!=typeof r||"number"!=typeof h)return null;const l=h-r;if(l<=0)continue;const o=(i.get(l)??0)+1;i.set(l,o),o>n&&(n=o,s=l)}return s}(t),d=i=>{if(i<t.length)return t[i].time;if(null===c)return null;return t[t.length-1].time+c*(i-t.length+1)},p=new Map,f=new Map;for(let i=0;i<t.length;i++){const o=t[i];if(void 0===o.time)continue;const a=Hr(t,i,s),u=Hr(t,i,n);null!==a&&h.push({time:o.time,value:a}),null!==u&&l.push({time:o.time,value:u}),null!==a&&null!==u&&p.set(i+r,(a+u)/2);const c=Hr(t,i,e);null!==c&&f.set(i+r,c);const d=i-r;if(d>=0&&void 0!==t[d].time){const i="close"in o?o.close:o.value;_.push({time:t[d].time,value:i})}}const v=t.length-1+r;for(let t=0;t<=v;t++){const i=d(t);if(null==i)continue;const s=p.get(t),n=f.get(t);if(void 0!==s&&o.push({time:i,value:s}),void 0!==n&&a.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Dy:s,Ry:n};u.push(t)}}return{Tk:h,eh:l,Dy:o,Ry:a,kk:_,Dk:u}},v=Or({e_:t,jf:i,by:[h,l,o,a,_],Zl:"Ichimoku",W:n,Sy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],My:(t,i)=>{c=i;const s=f(t,i);return u=s.Dk,[[h,s.Tk],[l,s.eh],[o,s.Dy],[a,s.Ry],[_,i.showLagging??1?s.kk:[]]]},yy:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),o.applyOptions({color:t.colorSpanA,lineWidth:s}),a.applyOptions({color:t.colorSpanB,lineWidth:s}),_.applyOptions({color:t.colorLagging,lineWidth:s,visible:t.showLagging??!0}),i.timeScale().applyOptions({})}}),m=v.remove;return{conversion:h,base:l,spanA:o,spanB:a,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}},applyKeltnerChannels:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Keltner Channels",W:n,Sy:["period","atrPeriod","multiplier","source"],My:(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{aP:[],Pk:[],_P:[]};const r=Ar(t,i.source??"close"),h=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=r[t];h.push(o/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const a=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?a.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):a.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=a[t];_[n-1]=u/n;for(let t=n;t<a.length;t++)_[t]=(_[t-1]*(n-1)+a[t])/n;const c=[],d=[],p=[];for(let i=0;i<h.length;i++){const n=s-1+i,r=t[n],l=_[n-1];if(!r||void 0===r.time||void 0===l)continue;const o=h[i],a=l*e;d.push({time:r.time,value:o}),c.push({time:r.time,value:o+a}),p.push({time:r.time,value:o-a})}return{aP:c,Pk:d,_P:p}})(t,i);return[[r,s.aP],[h,s.Pk],[l,s._P]]},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min((t.lineWidth??1)+1,4),lineStyle:s}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}},applyMACD:function(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(re,{color:n.colorMACD},e),h=i.addSeries(re,{color:n.colorSignal},e),l=i.addSeries(Ve,{color:n.colorHistogramUp},e),o=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},a=Or({e_:t,jf:i,by:[r,h,l],Zl:"MACD",W:n,Sy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],My:(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{Rk:[],Fk:[],Ik:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=o(r,s),l=o(r,n),a=[],_=n-s;for(let t=0;t<l.length;t++)a.push(h[t+_]-l[t]);const u=o(a,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=a[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Rk:c,Fk:d,Ik:p}})(t,i);return[[r,s.Rk],[h,s.Fk],[l,s.Ik]]},yy:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),h.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:h,histogram:l,...a}},applyMFI:function(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(re,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Vr(0,100)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Dr(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const r=i[s],h=i[s-1];if(!("high"in r)||!("low"in r)||!("close"in r)){n.push(0),e.push(0);continue}const l=(r.high+r.low+r.close)/3,o=(h.high+h.low+h.close)/3,a=l*(kr(t,r.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const r=[];for(let t=s-1;t<n.length;t++){let h=0,l=0;for(let i=0;i<s;i++)h+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+h/l),a=i[t+1];a&&void 0!==a.time&&r.push({time:a.time,value:o})}return r},a=Or({e_:t,jf:i,by:[r],Zl:"MFI",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??14)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applyOBV:function(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(re,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!Dr(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=kr(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=Or({e_:t,jf:i,by:[e],Zl:"OBV",W:n,My:()=>[[e,r()]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},applyParabolicSAR:function(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(re,{color:n.colorUp,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:n.dotSize},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<3)return[];const r=t[0],h=t[1];if(!("high"in r)||!("low"in r))return[];const l=[];let o=h.close>=r.close,a=o?r.low:r.high,_=o?h.high:h.low,u=i;for(let r=1;r<t.length;r++){const h=t[r],c=t[r-1];if("high"in h&&"low"in h&&(a+=u*(_-a),o?(a=Math.min(a,c.low,t[r-2]?t[r-2].low:c.low),h.low<a?(o=!1,a=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(a=Math.max(a,c.high,t[r-2]?t[r-2].high:c.high),h.high>a?(o=!0,a=_,_=h.high,u=i):h.low<_&&(_=h.low,u=Math.min(u+i,s))),void 0!==h.time)){const t={};t.time=h.time,t.value=a,t.color=o?n:e,l.push(t)}}return l},h=Or({e_:t,jf:i,by:[e],Zl:"Parabolic SAR",W:n,Sy:["step","maxStep","colorUp","colorDown"],My:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],yy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}},applyPivotPoints:function(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(re,{color:t},e),h=r(n.colorPivot),l=[r(n.colorResistance),r(n.colorResistance),r(n.colorResistance)],o=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],a=Or({e_:t,jf:i,by:[h,...l,...o],Zl:"Pivot Points",W:n,Sy:["pivotPeriod"],My:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{lP:s,Vk:n,Lk:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=Wr(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+o)/3,s=h-l;a={Ak:i,Ek:[2*i-l,i+s,h+2*(i-l)],Bk:[2*i-h,i-s,l-2*(h-i)]},r=t,h=-1/0,l=1/0}const u="high"in _?_.high:_.value,c="low"in _?_.low:_.value;if(u>h&&(h=u),c<l&&(l=c),o="close"in _?_.close:_.value,null!==a&&void 0!==_.time){s.push({time:_.time,value:a.Ak});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Ek[t]}),e[t].push({time:_.time,value:a.Bk[t]})}}return{lP:s,Vk:n,Lk:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.lP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Vk[t]:[]]),e.push([o[t],t<n?s.Lk[t]:[]]);return e},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));h.applyOptions({color:t.colorPivot,lineWidth:i,lineStyle:s});for(let e=0;e<3;e++)l[e].applyOptions({color:t.colorResistance,lineWidth:i,lineStyle:s,visible:e<n}),o[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:o,...a}},applyRSI:function(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(re,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Vr(0,100)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Er(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Ar(t,s),e=[],r=[];for(let t=1;t<n.length;t++)r.push(n[t]-n[t-1]);let h=0,l=0;for(let t=0;t<i;t++)r[t]>0?h+=r[t]:l+=Math.abs(r[t]);h/=i,l/=i;let o=0===l?100:h/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<r.length;s++){const n=r[s];h=(h*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:h/l,a=100-100/(1+o),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:a})}return e},a=Or({e_:t,jf:i,by:[r],Zl:"RSI",W:n,Sy:["period","source"],My:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applySMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"SMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyStochastic:function(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=Vr(0,100),h=i.addSeries(re,{color:n.colorK,autoscaleInfoProvider:r},e),l=i.addSeries(re,{color:n.colorD,autoscaleInfoProvider:r},e),o=Lr(i,h,e);i.priceScale(h.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Er(h,n.levelColor),_=Or({e_:t,jf:i,by:[h,l],Zl:"Stochastic",W:n,Sy:["kPeriod","dPeriod"],My:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Ok:[],Wk:[]};const n=[];for(let s=i-1;s<t.length;s++){let e=-1/0,r=1/0;for(let n=0;n<i;n++){const i=t[s-n];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[s];if("close"in h){const t=(h.close-r)/(e-r)*100;n.push(t)}}const e=[];for(let s=0;s<n.length;s++){const r=i-1+s;t[r]&&t[r].time&&e.push({time:t[r].time,value:n[s]})}const r=[];if(n.length>=s)for(let e=s-1;e<n.length;e++){let h=0;for(let t=0;t<s;t++)h+=n[e-t];const l=h/s,o=i-1+e;t[o]&&t[o].time&&r.push({time:t[o].time,value:l})}return{Ok:e,Wk:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Ok],[l,s.Wk]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:l,..._}},applySuperTrend:function(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(re,{color:n.colorUp,lineWidth:n.lineWidth},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<i+1)return[];const r=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?r.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):r.push(0)}const h=[];let l=0;for(let t=0;t<i;t++)l+=r[t];h[i-1]=l/i;for(let t=i;t<r.length;t++)h[t]=(h[t-1]*(i-1)+r[t])/i;const o=[];let a=0,_=0,u=!0,c=!1;for(let r=i;r<t.length;r++){const i=t[r],l=t[r-1],d=h[r-1];if(!("high"in i)||!("low"in i)||void 0===d)continue;const p=(i.high+i.low)/2,f=p+s*d,v=p-s*d;if(c?(a=f<a||l.close>a?f:a,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>a&&(u=!0)):(a=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:a,m.color=u?n:e,o.push(m)}return o},h=Or({e_:t,jf:i,by:[e],Zl:"SuperTrend",Sy:["period","multiplier","colorUp","colorDown"],W:n,My:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],yy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}},applyVWAP:function(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(re,{color:n.color},e),h=i.addSeries(re,{color:n.bandColor},e),l=i.addSeries(re,{color:n.bandColor},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"VWAP",W:n,Sy:["anchorPeriod","bandMultiplier"],My:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Dr(t))return{zk:e,aP:r,_P:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=Wr(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,o=0,a=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=kr(t,u.time)??0;if(o+=d,a+=c*d,_+=c*c*d,0===o)continue;const p=a/o;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/o-p*p,0),i=Math.sqrt(t)*n;r.push({time:u.time,value:p+i}),h.push({time:u.time,value:p-i})}}return{zk:e,aP:r,_P:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.zk],[h,n.aP],[l,n._P]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;r.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:r,upper:h,lower:l,...o}},applyVolume:function(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Ve,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Lr(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||!Dr(t))return[];const e=[];for(const r of n){const n=kr(t,r.time);n&&"close"in r&&"open"in r&&e.push({time:r.time,value:n,color:r.close>=r.open?i:s})}return e},o=Or({e_:t,jf:i,by:[r],Zl:"Volume",W:n,Sy:["colorUp","colorDown"],My:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...o}},applyWMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"WMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyWilliamsR:function(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(re,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Vr(-100,0)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(let n=i-1;n<t.length;n++){let e=-1/0,r=1/0;for(let s=0;s<i;s++){const i=t[n-s];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[n];if(!("close"in h)||void 0===h.time)continue;const l=e-r,o=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:o})}return s},a=Or({e_:t,jf:i,by:[r],Zl:"Williams %R",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??14)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},calculateHeikinAshi:Ur,calculatePipConfig:Ul,coordinateFromTime:Xn,createArrowTool:Vl,createBrushTool:Ol,createChart:function(t,i){return qn(t,new ss,ss.ad(i))},createChartEx:qn,createCircleTool:Dl,createCrossLineTool:Hh,createFibonacciExtensionTool:vl,createFibonacciFanTool:Ml,createFibonacciTool:cl,createGanttTool:eo,createHorizontalLineTool:Oh,createImageWatermark:function(t,i,s){return new Le(t,new Ge(i,s))},createInteractiveLineManager:function(t,i){return new eh(t,i)},createOptionsChart:function(t,i){return qn(t,new de,i)},createParallelChannelTool:Kh,createPitchforkTool:tl,createPolygonTool:jh,createPositionLine:function(t,i,s){return new dh(i,t,s)},createPositionMarkers:function(t,i,s){const n=new Cr(t,s);return i&&i.length>0&&n.setPositions(i),n},createPositionTool:to,createRectangleTool:Cl,createRulerTool:Kl,createSeriesMarkers:vr,createTextTool:Hl,createTextWatermark:function(t,i){return new Le(t,new Ne(i))},createTradingLine:function(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 nh(i,t,r)},createTradingSessionsIndicator:function(t,i,s){return new Xr(t,i,s)},createTrendLineTool:Lh,createUpDownMarkers:function(t,i={}){return new xr(t,new yr(i))},createVerticalLineTool:el,createVolumeProfileIndicator:function(t,i,s){return new Zr(t,i,s)},createYieldCurveChart:function(t,i){const s=Un(t);return new ue(s,i)},customSeriesDefaultOptions:ho,defaultHorzScaleBehavior:function(){return ss},getPipConfig:ql,hideSeriesPaint:Fr,isBusinessDay:Oi,isUTCTimestamp:Wi,setSeriesVolumes:function(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Tr(t.time),t.volume);Pr.set(t,s)},setVolumeProfileData:function(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)},timeFromCoordinate:Yn,version:function(){return"2.3.0-dev+202609220108"}});window.PipsendCharts=lo,window.LightweightCharts=lo}();
|
|
8
|
+
!function(){"use strict";const t={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var i,s;function n(t,i){const s={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[i];t.setLineDash(s)}function e(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(s,i+e),t.lineTo(n,i+e),t.stroke()}function r(t,i){if(!t)throw new Error("Assertion failed"+(i?": "+i:""))}function h(t){if(void 0===t)throw new Error("Value is undefined");return t}function l(t){if(null===t)throw new Error("Value is null");return t}function o(t){return l(h(t))}!function(t){t[t.Simple=0]="Simple",t[t.WithSteps=1]="WithSteps",t[t.Curved=2]="Curved"}(i||(i={})),function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(s||(s={}));class a{constructor(){this.t=[]}i(t,i,s){const n={h:t,l:i,o:!0===s};this.t.push(n)}_(t){const i=this.t.findIndex(i=>t===i.h);i>-1&&this.t.splice(i,1)}u(t){this.t=this.t.filter(i=>i.l!==t)}p(t,i,s){const n=[...this.t];this.t=this.t.filter(t=>!t.o),n.forEach(n=>n.h(t,i,s))}v(){return this.t.length>0}m(){this.t=[]}}function _(t,...i){for(const s of i)for(const i in s)void 0!==s[i]&&Object.prototype.hasOwnProperty.call(s,i)&&!["__proto__","constructor","prototype"].includes(i)&&("object"!=typeof s[i]||void 0===t[i]||Array.isArray(s[i])?t[i]=s[i]:_(t[i],s[i]));return t}function u(t){return"number"==typeof t&&isFinite(t)}function c(t){return"number"==typeof t&&t%1==0}function d(t){return"string"==typeof t}function p(t){return"boolean"==typeof t}function f(t){const i=t;if(!i||"object"!=typeof i)return i;let s,n,e;for(n in s=Array.isArray(i)?[]:{},i)i.hasOwnProperty(n)&&(e=i[n],s[n]=e&&"object"==typeof e?f(e):e);return s}function v(t){return null!==t}function m(t){return null===t?void 0:t}const w="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function g(t,i,s){return void 0===i&&(i=w),`${s=void 0!==s?`${s} `:""}${t}px ${i}`}class b{constructor(t){this.M={S:1,C:5,P:NaN,T:"",D:"",R:"",F:"",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,o,a,_]=this.G(i),u=[M(n+s*(l-n)),M(e+s*(o-e)),M(r+s*(a-r)),(c=h+s*(_-h),c<=0||c>1?Math.min(Math.max(c,0),1):Math.round(1e4*c)/1e4)];var c;return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}G(t){const i=this.j.get(t);if(i)return i;const s=function(t){const i=document.createElement("div");i.style.display="none",document.body.appendChild(i),i.style.color=t;const s=window.getComputedStyle(i).color;return document.body.removeChild(i),s}(t),n=s.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/);if(!n){if(this.Y.length)for(const i of this.Y){const s=i(t);if(s)return this.j.set(t,s),s}throw new Error(`Failed to parse color: ${t}`)}const e=[parseInt(n[1],10),parseInt(n[2],10),parseInt(n[3],10),n[4]?parseFloat(n[4]):1];return this.j.set(t,e),e}}class x{constructor(){this.st=[]}nt(t){this.st=t}et(t,i,s){this.st.forEach(n=>{n.et(t,i,s)})}}class C{et(t,i,s){t.useBitmapCoordinateSpace(t=>this.rt(t,i,s))}}class P extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.ht||null===this.ht.ot)return;const n=this.ht.ot,e=this.ht,r=Math.max(1,Math.floor(i))%2/2,h=h=>{t.beginPath();for(let l=n.to-1;l>=n.from;--l){const n=e._t[l],o=Math.round(n.ut*i)+r,a=n.ct*s,_=h*s+r;t.moveTo(o,a),t.arc(o,a,_,0,2*Math.PI)}t.fill()};e.dt>0&&(t.fillStyle=e.ft,h(e.vt+e.dt)),t.fillStyle=e.wt,h(e.vt)}}function T(){return{_t:[{ut:0,ct:0,gt:0,bt:0}],wt:"",ft:"",vt:0,dt:0,ot:null}}const k={from:0,to:1};class D{constructor(t,i,s){this.Mt=new x,this.yt=[],this.St=[],this.xt=!0,this.O=t,this.Ct=i,this.Pt=s,this.Mt.nt(this.yt)}Tt(t){this.kt(),this.xt=!0}Dt(){return this.xt&&(this.Rt(),this.xt=!1),this.Mt}kt(){const t=this.Pt.Ft();t.length!==this.yt.length&&(this.St=t.map(T),this.yt=this.St.map(t=>{const i=new P;return i.lt(t),i}),this.Mt.nt(this.yt))}Rt(){const t=2===this.Ct.W().mode||!this.Ct.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 o=Math.round(this.Yt.ut*s),a=Math.round(this.Yt.ct*r);t.lineCap="butt",h&&o>=0&&(t.lineWidth=Math.floor(this.Yt.Xt.dt*s),t.strokeStyle=this.Yt.Xt.R,t.fillStyle=this.Yt.Xt.R,n(t,this.Yt.Xt.Kt),function(t,i,s,n){t.beginPath();const e=t.lineWidth%2?.5:0;t.moveTo(i+e,s),t.lineTo(i+e,n),t.stroke()}(t,o,0,i.height)),l&&a>=0&&(t.lineWidth=Math.floor(this.Yt.Gt.dt*r),t.strokeStyle=this.Yt.Gt.R,t.fillStyle=this.Yt.Gt.R,n(t,this.Yt.Gt.Kt),e(t,a,0,i.width))}}class F{constructor(t,i){this.xt=!0,this.Zt={Xt:{dt:1,Kt:0,R:"",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],o=""){if(t.save(),!h||!o||o===r)return L(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const a=h/2;var _;L(t,i+a,s+a,n-h,e-h,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==o&&(t.lineWidth=h,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function 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),o=l.oi;return l.ai?A(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):A(h,o.fi,o.ui,o.ci,o.di,r,o.pi,[0,o.vt,o.vt,0],r),this.Yt.mi&&(h.fillStyle=e,h.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.Yt.Mi&&(h.fillStyle=i.F,h.fillRect(l.ai?o.yi-o.pi:0,o.ui,o.pi,o.Si-o.ui)),l});t.useMediaCoordinateSpace(({context:t})=>{const s=h.xi;t.font=i.T,t.textAlign=h.ai?"right":"left",t.textBaseline="middle",t.fillStyle=e,t.fillText(this.Yt.hi,s.Ci,(s.ui+s.Si)/2+s.Pi)})}li(t,i,s,n){const{context:e,bitmapSize:r,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=this.Yt.mi||!this.Yt.Ti?i.C:0,_=this.Yt.ki?i.S:0,u=i.A+this.ri.Di,c=i.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+a,M=Math.max(1,Math.floor(o));let y=Math.round(g*o);y%2!=M%2&&(y+=1);const S=_>0?Math.max(1,Math.floor(_*l)):0,x=Math.round(b*l),C=Math.round(a*l),P=this.ri.Vi??this.ri.Li,T=Math.round(P*o)-Math.floor(.5*o),k=Math.floor(T+M/2-y/2),D=k+y,R="right"===n,F=R?h.width-_:_,I=R?r.width-S:S;let V,L,A;return R?(V=I-x,L=I-C,A=F-a-d-_):(V=I+x,L=I+C,A=F+a+d),{ai:R,oi:{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/o,Si:D/o,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 o=this.Yt.Li,a=Math.floor(o-r)+.5;a<0?(o+=Math.abs(0-a),a=Math.floor(o-r)+.5):a+e>h&&(o-=Math.abs(h-(a+e)),a=Math.floor(o-r)+.5);const _=a+e,u=Math.ceil(0+i.S+i.C+i.A+i.P+i.I);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.Yt);t.fillStyle=e.Z;const r=Math.round(a*s),h=Math.round(0*n),o=Math.round(_*s),c=Math.round(u*n),d=Math.round(2*s);if(t.beginPath(),t.moveTo(r,h),t.lineTo(r,c-d),t.arcTo(r,c,r+d,c,d),t.lineTo(o-d,c),t.arcTo(o,c,o,c-d,d),t.lineTo(o,h),t.fill(),e.mi){const r=Math.round(e.Li*s),l=h,o=Math.round((l+i.C)*n);t.fillStyle=e.R;const a=Math.max(1,Math.floor(s)),_=Math.floor(.5*s);t.fillRect(r-_,l,a,o-l)}}),t.useMediaCoordinateSpace(({context:t})=>{const s=l(this.Yt),e=0+i.S+i.C+i.A+i.P/2;t.font=i.T,t.textAlign="left",t.textBaseline="middle",t.fillStyle=s.R;const r=i.Ji.Fi(t,"Apr0");t.translate(a+n,e+r),t.fillText(s.hi,0,0)})}}class H{constructor(t,i,s){this.xt=!0,this.Jt=new $,this.Zt={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,o=this.js(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.At().jt(t),this.Pt=s;const a=null!==o?o.Bt():null;return null!==o&&null!==a?(this.ps=i,this.Ss=o.zt(i,a)):(this.ps=NaN,this.Ss=NaN),n!==this.ys||e!==this.Ss||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 o=Math.max(2,1.5*n.he)*i;t.arc(h,l,o,0,2*Math.PI,!1),t.fill(),t.fillStyle=n.le,t.beginPath(),t.arc(h,l,n.vt*i,0,2*Math.PI,!1),t.fill(),t.lineWidth=e,t.strokeStyle=n.oe,t.beginPath(),t.arc(h,l,n.vt*i+e/2,0,2*Math.PI,!1),t.stroke()}}const ot=[{ae:0,_e:.25,ue:4,ce:10,de:.25,pe:0,fe:.4,ve:.8},{ae:.25,_e:.525,ue:10,ce:14,de:0,pe:0,fe:.8,ve:0},{ae:.525,_e:1,ue:14,ce:14,de:0,pe:0,fe:0,ve:0}];class at{constructor(t){this.Jt=new lt,this.xt=!0,this.me=!0,this.we=performance.now(),this.ge=this.we-1,this.be=t}Me(){this.ge=this.we-1,this.Tt()}ye(){if(this.Tt(),2===this.be.W().lastPriceAnimation){const t=performance.now(),i=this.ge-t;if(i>0)return void(i<650&&(this.ge+=2600));this.we=t,this.ge=t+2600}}Tt(){this.xt=!0}Se(){this.me=!0}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,oe:l.oe,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.oe=i.oe,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 ot)if(s>=t.ae&&s<=t._e){n=t;break}r(void 0!==n,"Last price animation internal logic error");const e=(s-n.ae)/(n._e-n.ae);return{le:this.Ve(i,e,n.de,n.pe),oe:this.Ve(i,e,n.fe,n.ve),vt:(h=e,l=n.ue,o=n.ce,l+(o-l)*h)};var h,l,o}}class _t extends rt{constructor(t){super(t)}ie(){const t=this.Zn;t.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,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Ee(o,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Be(o,r,h,l),i.It=i.hi.length>0);const a=n.Le(o.R),_=this.Qt.ti().Ki().K(a);s.Z=_.Z,s.Li=o.Li,i.Nt=n.ti().Ut(o.Li/n.$t().qt()),t.Nt=a,t.R=_.J,i.R=_.J}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 o=this.be.ti().Ki().K(n.axisLabelColor||n.color);s.Z=o.Z;const a=n.axisLabelTextColor||o.J;t.R=a,i.R=a,s.Li=l}er(t){const i=this.be.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)),a=o(h.Ht[0])<=o(h.Ht[3]);return{dr:h.R??(a?e:r)}},Candlestick:(t,i,s,n)=>{const e=i.upColor,r=i.downColor,h=i.borderUpColor,a=i.borderDownColor,_=i.wickUpColor,u=i.wickDownColor,c=l(t(s,n)),d=o(c.Ht[0])<=o(c.Ht[3]);return{dr:c.R??(d?e:r),pr:c.Nt??(d?h:a),vr:c.mr??(d?_:u)}},Custom:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color}),Area:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.wt??i.lineColor,wt:e.wt??i.lineColor,wr:e.wr??i.topColor,gr:e.gr??i.bottomColor}},Baseline:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.Ht[3]>=i.baseValue.price?i.topLineColor:i.bottomLineColor,br:e.br??i.topLineColor,Mr:e.Mr??i.bottomLineColor,yr:e.yr??i.topFillColor1,Sr:e.Sr??i.topFillColor2,Cr:e.Cr??i.bottomFillColor1,Pr:e.Pr??i.bottomFillColor2}},Line:(t,i,s,n)=>{const e=l(t(s,n));return{dr:e.R??i.color,wt:e.R??i.color}},Histogram:(t,i,s,n)=>({dr:l(t(s,n)).R??i.color})};class bt{constructor(t){this.Tr=(t,i)=>void 0!==i?i.Ht:this.be.Ks().kr(t),this.be=t,this.Dr=gt[t.Rr()]}Fr(t,i){return this.Dr(this.Tr,this.be.W(),t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Ir=[],this.Vr=new Map,this.Lr=new Map,this.Ar=[]}Er(){return this.Br()>0?this.Ir[this.Ir.length-1]:null}Or(){return this.Br()>0?this.Wr(0):null}Gs(){return this.Br()>0?this.Wr(this.Ir.length-1):null}Br(){return this.Ir.length}Gi(){return 0===this.Br()}De(t){return null!==this.zr(t,0)}kr(t){return this.$r(t)}$r(t,i=0){const s=this.zr(t,i);return null===s?null:{...this.Hr(s),Re:this.Wr(s)}}Nr(){return this.Ir}Ur(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.qr(t,i,e))}return n}lt(t){this.Lr.clear(),this.Vr.clear(),this.Ir=t,this.Ar=t.map(t=>t.Re)}jr(){return this.Ar}Wr(t){return this.Ir[t].Re}Hr(t){return this.Ir[t]}zr(t,i){const s=this.Yr(t);if(null===s&&0!==i)switch(i){case-1:return this.Xr(t);case 1:return this.Gr(t);default:throw new TypeError("Unknown search mode")}return s}Xr(t){let i=this.Kr(t);return i>0&&(i-=1),i!==this.Ir.length&&this.Wr(i)<t?i:null}Gr(t){const i=this.Zr(t);return i!==this.Ir.length&&t<this.Wr(i)?i:null}Yr(t){const i=this.Kr(t);return i===this.Ir.length||t<this.Ir[i].Re?null:i}Kr(t){return yt(this.Ir,t,(t,i)=>t.Re<i)}Zr(t){return St(this.Ir,t,(t,i)=>t.Re>i)}Jr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Ir[e].Ht[s];Number.isNaN(t)||(null===n?n={Qr:t,th:t}:(t<n.Qr&&(n.Qr=t),t>n.th&&(n.th=t)))}return n}qr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Or()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Kr(h),e=this.Zr(Math.min(o,a,i));n=Tt(n,this.Jr(t,e,s))}let u=this.Vr.get(s);void 0===u&&(u=new Map,this.Vr.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Kr(i*Ct),n=this.Zr((i+1)*Ct-1);e=this.Jr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Kr(_),i=this.Zr(o);n=Tt(n,this.Jr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{Qr:Math.min(t.Qr,i.Qr),th:Math.max(t.th,i.th)}}const kt={setLineStyle:n};class Dt{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Fn?.eh===t)return this.Fn.rh;const i=new Dt(t);return this.Fn={eh:t,rh:i},i}hh(){return this.nh.zOrder?.()??"normal"}}class Ft{constructor(t){this.oh=null,this.ah=t}_h(){return this.ah}zs(){this.ah.updateAllViews?.()}$s(){const t=this.ah.paneViews?.()??[];if(this.oh?.eh===t)return this.oh.rh;const i=t.map(t=>new Rt(t));return this.oh={eh:t,rh:i},i}Xn(t,i){return this.ah.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.ih=t}et(t,i,s){this.ih.draw(t,kt)}sh(t,i,s){this.ih.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.nh=t}Dt(){const t=this.nh.renderer();if(null===t)return null;if(this.Fn?.eh===t)return this.Fn.rh;const i=new Vt(t);return this.Fn={eh:t,rh:i},i}hh(){return this.nh.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.uh=t,this.dh=i}Dt(){return this.Jt.lt({ts:this.dh.ts(),...At(this.uh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.uh=t,this.Yi=i}ji(t,i,s){const n=At(this.uh);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.ph=null,this.fh=null,this.mh=null,this.wh=null,this.be=i}ds(){const t=this.ah.timeAxisViews?.()??[];if(this.ph?.eh===t)return this.ph.rh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.ph={eh:t,rh:s},s}Hs(){const t=this.ah.priceAxisViews?.()??[];if(this.fh?.eh===t)return this.fh.rh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.fh={eh:t,rh:s},s}gh(){const t=this.ah.priceAxisPaneViews?.()??[];if(this.mh?.eh===t)return this.mh.rh;const i=t.map(t=>new Lt(t));return this.mh={eh:t,rh:i},i}bh(){const t=this.ah.timeAxisPaneViews?.()??[];if(this.wh?.eh===t)return this.wh.rh;const i=t.map(t=>new Lt(t));return this.wh={eh:t,rh:i},i}Mh(t,i){return this.ah.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.hh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.gh()}function Ht(t){return t.bh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.yh=[],this.Sh=new ht(this),this.xh=null,this.Ch=null,this.Ph=null,this.Th=[],this.Ps=s,this.kh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.kh)&&(this.xh=new at(this)),this.Dh(),this.nh=n(this,this.ti(),e)}m(){null!==this.Ph&&clearTimeout(this.Ph)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().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.Er();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.$r(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Rh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Fh(l),ze:s.Ih(l,e.Ht),R:o.dr,Li:a,Re:h}}Rh(){return null!==this.Ch||(this.Ch=new bt(this)),this.Ch}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Vh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Dh(),this.ti().Lh()),this.ti().Ah(this),this.ti().Eh(),this.nh.Tt("options")}lt(t,i){this.Yt.lt(t),this.nh.Tt("data"),null!==this.xh&&(i&&i.Bh?this.xh.ye():0===t.length&&this.xh.Me());const s=this.ti().Nn(this);this.ti().Oh(s),this.ti().Ah(this),this.ti().Eh(),this.ti().ar()}Wh(t){const i=new mt(this,t);return this.yh.push(i),this.ti().Ah(this),i}zh(t){const i=this.yh.indexOf(t);-1!==i&&this.yh.splice(i,1),this.ti().Ah(this)}$h(){return this.yh}Rr(){return this.kh}Bt(){const t=this.Hh();return null===t?null:{Ht:t.Ht[3],Nh:t.gt}}Hh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.Uh();return this.Yt.$r(i,1)}Ks(){return this.Yt}qh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.kh||"Candlestick"===this.kh||"Custom"===this.kh?{jh:i.Ht[0],Yh:i.Ht[1],Xh:i.Ht[2],Gh:i.Ht[3]}:i.Ht[3]}Kh(t){const i=[];Wt(this.Th,zt,"top",i);const s=this.xh;return null!==s&&s.It()?(null===this.Ph&&s.xe()&&(this.Ph=setTimeout(()=>{this.Ph=null,this.ti().Zh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Jh()||t.push(this.Sh),t.push(this.nh,this.rr);const i=this.yh.map(t=>t._r());return t.push(...i),Wt(this.Th,zt,"normal",t),t}Qh(){return this.tl(zt,"bottom")}il(t){return this.tl($t,t)}sl(t){return this.tl(Ht,t)}nl(t,i){return this.Th.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.yh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Jh())return[];const s=[...this.ws];for(const t of this.yh)s.push(t.cr());return this.Th.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.Th.forEach(i=>{t.push(...i.ds())}),t}Mh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.el(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.el(t,i)}eh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}rl(){return this.hl}zs(){this.nh.Tt();for(const t of this.ws)t.Tt();for(const t of this.yh)t.Tt();this.rr.Tt(),this.Sh.Tt(),this.xh?.Tt(),this.Th.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ll(),Nt:this.ol(),Wt:this.al(),Ot:this._l(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}ul(t){this.Th.push(new Ot(t,this))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t)}dl(){if("Custom"===this.kh)return t=>this.nh.pl(t)}fl(){if("Custom"===this.kh)return t=>this.nh.vl(t)}ml(){return this.Yt.jr()}Jh(){return!j(this.$t().wl())}el(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.kh||"Area"===this.kh||"Baseline"===this.kh||"Histogram"===this.kh?[3]:[2,1],n=this.Yt.Ur(t,i,s);let e=null!==n?new dt(n.Qr,n.th):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.Th.forEach(s=>{const n=s.Mh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ll(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}ol(){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}al(){switch(this.kh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}_l(t){switch(this.kh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Rh().Fr(t).dr}Dh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.hl={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.hl=new Q(this.Ps.priceFormat.precision);break;case"percent":this.hl=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.hl=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.gl()}tl(t,i){const s=[];return Wt(this.Th,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}bl(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.Ml().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.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=o(n.Bt()),a=3===this.Ps.mode?jt:qt;return t.concat(a.map(t=>e.zt(h.Ht[t],l.Ht)))},[]);if(0===l.length)return n;l.sort((t,i)=>Math.abs(t-h)-Math.abs(i-h));const a=l[0];return n=e.Ds(a,r),n}}function Xt(t,i,s){return Math.min(Math.max(t,i),s)}function Gt(t,i,s){return i-t<=s}function Kt(t){const i=Math.ceil(t);return i%2==0?i-1:i}class Zt extends C{constructor(){super(...arguments),this.Yt=null}lt(t){this.Yt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.Yt)return;const r=Math.max(1,Math.floor(s));t.lineWidth=r,function(t,i){t.save(),t.lineWidth%2&&t.translate(.5,.5),i(),t.restore()}(t,()=>{const h=l(this.Yt);if(h.yl){t.strokeStyle=h.Sl,n(t,h.xl),t.beginPath();for(const n of h.Cl){const e=Math.round(n.Pl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.Tl){t.strokeStyle=h.kl,n(t,h.Dl),t.beginPath();for(const s of h.Rl){const n=Math.round(s.Pl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={Tl:t.horzLines.visible,yl:t.vertLines.visible,kl:t.horzLines.color,Sl:t.vertLines.color,Dl:t.horzLines.style,xl:t.vertLines.style,Rl:this.Pt.ks().Fl(),Cl:(this.Pt.ti().At().Fl()||[]).map(t=>({Pl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.nh=new Jt(t)}_r(){return this.nh}}const ti={Il:4,Vl: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.Vl)+i.Il;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Il)-i.Vl;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.je(),i);return new dt(s,n)}function ai(t){if(null===t)return ti;const i=Math.abs(t.je()-t.qe());if(i>=1||i<1e-15)return ti;const s=Math.ceil(Math.abs(Math.log10(i))),n=ti.Il+s;return{Il:n,Vl:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Ll=t,this.Al=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Ll))this.El=[2,2.5,2];else{this.El=[];for(let t=this.Ll;1!==t;){if(t%2==0)this.El.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.El.push(2,2.5),t/=5}if(this.El.length>100)throw new Error("something wrong with base")}}}Bl(t,i,s){const n=0===this.Ll?0:1/this.Ll;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.Al[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.Al[++r%this.Al.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.El.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.El[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.El[++r%this.El.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Ol=[],this.Yi=t,this.Ll=i,this.Wl=s,this.zl=n}Bl(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.$l()/s,e=new _i(this.Ll,[2,2.5,2]),r=new _i(this.Ll,[2,2,2.5]),h=new _i(this.Ll,[2.5,2,2]),l=[];return l.push(e.Bl(t,i,n),r.Bl(t,i,n),h.Bl(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Hl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Ol=[]);const s=t.qt(),n=this.Wl(s-1,i),e=this.Wl(0,i),r=this.Yi.W().entireTextOnly?this.Nl()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Ol=[]);const _=this.Bl(o,a);if(this.Ul(i,_,o,a,h,l),t.ql()&&this.jl(_,a,o)){const t=this.Yi.Yl();this.Xl(i,_,h,l,t,2*t)}const u=this.Ol.map(t=>t.Gl),c=this.Yi.Kl(u);for(let t=0;t<this.Ol.length;t++)this.Ol[t].Zl=c[t]}Fl(){return this.Ol}Nl(){return this.Yi.P()}$l(){return Math.ceil(2.5*this.Nl())}Ul(t,i,s,n,e,r){const h=this.Ol,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.zl(c,t,!0);null!==_&&Math.abs(s-_)<this.$l()||(s<e||s>r||(u<h.length?(h[u].Pl=s,h[u].Zl=l.Jl(c),h[u].Gl=c):h.push({Pl:s,Zl:l.Jl(c),Gl:c}),u++,_=s,l.Ql()&&(i=this.Bl(c*a,n))))}h.length=u}Xl(t,i,s,n,e,r){const h=this.Ol,l=this.io(t,s,e,r),o=this.io(t,n,-r,-e),a=this.zl(0,t,!0)-this.zl(i,t,!0);h.length>0&&h[0].Pl-l.Pl<a/2&&h.shift(),h.length>0&&o.Pl-h[h.length-1].Pl<a/2&&h.pop(),h.unshift(l),h.push(o)}io(t,i,s,n){const e=(s+n)/2,r=this.Wl(i+s,t),h=this.Wl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.Bl(o,l)),_=this.Wl(i+e,t),u=_-_%a,c=this.zl(u,t,!0);return{Zl:this.Yi.Jl(u),Pl:c,Gl:u}}jl(t,i,s){let n=o(this.Yi.tr());return this.Yi.Ql()&&(n=oi(n,this.Yi.so())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.no=0,this.eo=null,this.Je=null,this.ro=null,this.ho={lo:!1,oo:null},this.ao=!1,this._o=0,this.uo=0,this.co=new a,this.do=new a,this.po=[],this.fo=null,this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.hl=fi,this.Mo=ai(null),this.yo=t,this.Ps=i,this.So=s,this.xo=n,this.Co=e,this.Po=new ui(this,100,this.To.bind(this),this.ko.bind(this))}wl(){return this.yo}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.gl(),void 0!==t.mode&&this.Do({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Ro(),this.mo=null}}Fo(){return this.Ps.autoScale}Io(){return this.ao}Ql(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Vo(){return 3===this.Ps.mode}so(){return this.Mo}se(){return{nn:this.Ps.autoScale,Lo:this.Ps.invertScale,se:this.Ps.mode}}Do(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.ho.lo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.Mo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.Mo),null!==s&&this.Ao(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.Mo),null!==s&&this.Ao(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.gl(),n&&(3===i.se||this.Vo())&&this.gl(),void 0!==t.Lo&&i.Lo!==t.Lo&&(this.Ps.invertScale=t.Lo,this.Eo()),this.do.p(i,this.se())}Bo(){return this.do}P(){return this.So.fontSize}qt(){return this.no}Oo(t){this.no!==t&&(this.no=t,this.Ro(),this.mo=null)}Wo(){if(this.eo)return this.eo;const t=this.qt()-this.zo()-this.$o();return this.eo=t,t}tr(){return this.Ho(),this.Je}Ao(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.mo=null,this.Je=t)}No(t){this.Ao(t),this.Uo(null!==t)}Gi(){return this.Ho(),0===this.no||!this.Je||this.Je.Gi()}qo(t){return this.Lo()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Vo()&&(t=ni(t,i)),this.ko(t,i)}jo(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.no-1-o;e.ct=u}}Xo(t,i,s){this.Ho();const n=this.$o(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.Wo()-1,a=this.Lo(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Yo();for(let s=u;s<c;s++){const e=t[s];let h=e.jh,l=e.Yh,o=e.Xh,u=e.Gh;null!==d&&(h=d(e.jh,i),l=d(e.Yh,i),o=d(e.Xh,i),u=d(e.Gh,i));let c=n+_*(h-r),p=a?c:this.no-1-c;e.Go=p,c=n+_*(l-r),p=a?c:this.no-1-c,e.Ko=p,c=n+_*(o-r),p=a?c:this.no-1-c,e.Zo=p,c=n+_*(u-r),p=a?c:this.no-1-c,e.Jo=p}}Ds(t,i){const s=this.To(t,i);return this.Qo(s,i)}Qo(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Vo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}Ml(){return this.po}Ft(){return this.vo||(this.vo=ci(this.po)),this.vo}ta(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.gl(),this.ia())}sa(t){const i=this.po.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.po.splice(i,1),0===this.po.length&&(this.Do({nn:!0}),this.Ao(null)),this.gl(),this.ia()}Bt(){let t=null;for(const i of this.po){const s=i.Bt();null!==s&&((null===t||s.Nh<t.Nh)&&(t=s))}return null===t?null:t.Ht}Lo(){return this.Ps.invertScale}Fl(){const t=null===this.Bt();if(null!==this.mo&&(t||this.mo.na===t))return this.mo.Fl;this.Po.Hl();const i=this.Po.Fl();return this.mo={Fl:i,na:t},this.co.p(),i}ea(){return this.co}ra(t){this.Oe()||this.Vo()||null===this.wo&&null===this.ro&&(this.Gi()||(this.wo=this.no-t,this.ro=l(this.tr()).Ue()))}ha(t){if(this.Oe()||this.Vo())return;if(null===this.wo)return;this.Do({nn:!1}),(t=this.no-t)<0&&(t=0);let i=(this.wo+.2*(this.no-1))/(t+.2*(this.no-1));const s=l(this.ro).Ue();i=Math.max(i,.1),s.Xe(i),this.Ao(s)}la(){this.Oe()||this.Vo()||(this.wo=null,this.ro=null)}oa(t){this.Fo()||null===this.bo&&null===this.ro&&(this.Gi()||(this.bo=t,this.ro=l(this.tr()).Ue()))}aa(t){if(this.Fo())return;if(null===this.bo)return;const i=l(this.tr()).Ye()/(this.Wo()-1);let s=t-this.bo;this.Lo()&&(s*=-1);const n=s*i,e=l(this.ro).Ue();e.Ge(n),this.Ao(e,!0),this.mo=null}_a(){this.Fo()||null!==this.bo&&(this.bo=null,this.ro=null)}rl(){return this.hl||this.gl(),this.hl}Zi(t,i){switch(this.Ps.mode){case 2:return this.ua(ii(t,i));case 3:return this.rl().format(ni(t,i));default:return this.er(t)}}Jl(t){switch(this.Ps.mode){case 2:return this.ua(t);case 3:return this.rl().format(t);default:return this.er(t)}}Kl(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.rl().formatTickmarks(t);default:return this.da(t)}}Fh(t){return this.er(t,l(this.fo).rl())}Ih(t,i){return t=ii(t,i),this.ua(t,pi)}pa(){return this.po}fa(t){this.ho={oo:t,lo:!1}}zs(){this.po.forEach(t=>t.zs())}ql(){return this.Ps.ensureEdgeTickMarksVisible&&this.Fo()}Yl(){return this.P()/2}gl(){this.mo=null;let t=1/0;this.fo=null;for(const i of this.po)i.ls()<t&&(t=i.ls(),this.fo=i);let i=100;null!==this.fo&&(i=Math.round(this.fo.eh())),this.hl=fi,this.Oe()?(this.hl=pi,i=100):this.Vo()?(this.hl=new Z(100,1),i=100):null!==this.fo&&(this.hl=this.fo.rl()),this.Po=new ui(this,i,this.To.bind(this),this.ko.bind(this)),this.Po.Hl()}ia(){this.vo=null}va(){return null===this.fo||this.Oe()||this.Vo()?1:1/this.fo.eh()}Ki(){return this.Co}Uo(t){this.ao=t}zo(){return this.Lo()?this.Ps.scaleMargins.bottom*this.qt()+this.uo:this.Ps.scaleMargins.top*this.qt()+this._o}$o(){return this.Lo()?this.Ps.scaleMargins.top*this.qt()+this._o:this.Ps.scaleMargins.bottom*this.qt()+this.uo}Ho(){this.ho.lo||(this.ho.lo=!0,this.ma())}Ro(){this.eo=null}ko(t,i){if(this.Ho(),this.Gi())return 0;t=this.Ql()&&t?ri(t,this.Mo):t;const s=l(this.tr()),n=this.$o()+(this.Wo()-1)*(t-s.qe())/s.Ye();return this.qo(n)}To(t,i){if(this.Ho(),this.Gi())return 0;const s=this.qo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.$o())/(this.Wo()-1));return this.Ql()?hi(e,this.Mo):e}Eo(){this.mo=null,this.Po.Hl()}ma(){if(this.Io()&&!this.Fo())return;const t=this.ho.oo;if(null===t)return;let i=null;const s=this.pa();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.Mh(t.Uh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.Mo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.ql()&&(n=Math.max(n,this.Yl()),e=Math.max(e,this.Yl())),n===this._o&&e===this.uo||(this._o=n,this.uo=e,this.mo=null,this.Ro()),null!==i){if(i.qe()===i.je()){const t=5*this.va();this.Ql()&&(i=oi(i,this.Mo)),i=new dt(i.qe()-t,i.je()+t),this.Ql()&&(i=li(i,this.Mo))}if(this.Ql()){const t=oi(i,this.Mo),s=ai(t);if(r=s,h=this.Mo,r.Il!==h.Il||r.Vl!==h.Vl){const n=null!==this.ro?oi(this.ro,this.Mo):null;this.Mo=s,i=li(t,s),null!==n&&(this.ro=li(n,s))}}this.Ao(i)}else null===this.Je&&(this.Ao(new dt(-.5,.5)),this.Mo=ai(null));var r,h}Yo(){return this.Oe()?ii:this.Vo()?ni:this.Ql()?t=>ri(t,this.Mo):null}wa(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.format(t)):i(t)}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.rl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.wa(t,this.xo.priceFormatter,i)}da(t,i){const s=this.xo.priceFormatter;return this.ga(t,this.xo.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ua(t,i){return this.wa(t,this.xo.percentageFormatter,i)}ca(t,i){const s=this.xo.percentageFormatter;return this.ga(t,this.xo.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.po=[],this.ba=new Map,this.no=0,this.Ma=0,this.ya=1,this.vo=null,this.Sa=!1,this.xa=new a,this.Th=[],this.dh=t,this.ss=i,this.Ca=new Qt(this);const s=i.W();this.Pa=this.Ta("left",s.leftPriceScale),this.ka=this.Ta("right",s.rightPriceScale),this.Pa.Bo().i(this.Da.bind(this,this.Pa),this),this.ka.Bo().i(this.Da.bind(this,this.ka),this),this.Ra(s)}Ra(t){if(t.leftPriceScale&&this.Pa.lr(t.leftPriceScale),t.rightPriceScale&&this.ka.lr(t.rightPriceScale),t.localization&&(this.Pa.gl(),this.ka.gl()),t.overlayPriceScales){const i=Array.from(this.ba.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.gl()}}}Fa(t){switch(t){case"left":return this.Pa;case"right":return this.ka}return this.ba.has(t)?h(this.ba.get(t))[0].$t():null}m(){this.ti().Ia().u(this),this.Pa.Bo().u(this),this.ka.Bo().u(this),this.po.forEach(t=>{t.m&&t.m()}),this.Th=this.Th.filter(t=>{const i=t._h();return i.detached&&i.detached(),!1}),this.xa.p()}Va(){return this.ya}La(t){this.ya=t}ti(){return this.ss}ts(){return this.Ma}qt(){return this.no}Aa(t){this.Ma=t,this.Ea()}Oo(t){this.no=t,this.Pa.Oo(t),this.ka.Oo(t),this.po.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Oo(t)}}),this.Ea()}Ba(t){this.Sa=t}Oa(){return this.Sa}Wa(){return this.po.filter(mi)}Ml(){return this.po}Un(t){const i=t.$t();return null===i||this.Pa!==i&&this.ka!==i}ta(t,i,s){this.za(t,i,s?t.ls():this.po.length)}sa(t,i){const s=this.po.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.po.splice(s,1),i||this.po.forEach((t,i)=>t._s(i));const n=l(t.$t()).wl();if(this.ba.has(n)){const i=h(this.ba.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.ba.delete(n))}const e=t.$t();e&&e.Ml().indexOf(t)>=0&&(e.sa(t),this.$a(e)),this.vo=null}jn(t){return t===this.Pa?"left":t===this.ka?"right":"overlay"}Ha(){return this.Pa}Na(){return this.ka}Ua(t,i){t.ra(i)}qa(t,i){t.ha(i),this.Ea()}ja(t){t.la()}Ya(t,i){t.oa(i)}Xa(t,i){t.aa(i),this.Ea()}Ga(t){t._a()}Ea(){this.po.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.ka.Ml().length?t=this.ka:this.ss.W().leftPriceScale.visible&&0!==this.Pa.Ml().length?t=this.Pa:0!==this.po.length&&(t=this.po[0].$t()),null===t&&(t=this.ka),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.ka:this.ss.W().leftPriceScale.visible&&(t=this.Pa),t}$a(t){null!==t&&t.Fo()&&this.Ka(t)}Za(t){const i=this.dh.Pe();t.Do({nn:!0}),null!==i&&t.fa(i),this.Ea()}Ja(){this.Ka(this.Pa),this.Ka(this.ka)}Qa(){this.$a(this.Pa),this.$a(this.ka),this.po.forEach(t=>{this.Un(t)&&this.$a(t.$t())}),this.Ea(),this.ss.ar()}Ft(){return null===this.vo&&(this.vo=ci(this.po)),this.vo}t_(t,i){i=Xt(i,0,this.po.length-1);const s=this.po.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.po.splice(s,1),this.po.splice(i,0,t),this.po.forEach((t,i)=>t._s(i)),this.vo=null;for(const t of[this.Pa,this.ka])t.ia(),t.gl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}i_(){return this.xa}s_(){return this.Ca}ul(t){this.Th.push(new It(t))}cl(t){this.Th=this.Th.filter(i=>i._h()!==t),t.detached&&t.detached(),this.ss.ar()}n_(){return this.Th}nl(t,i){return this.Th.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Ka(t){const i=t.pa();if(i&&i.length>0&&!this.dh.Gi()){const i=this.dh.Pe();null!==i&&t.fa(i)}t.zs()}za(t,i,s){let n=this.Fa(i);if(null===n&&(n=this.Ta(i,this.ss.W().overlayPriceScales)),this.po.splice(s,0,t),!j(i)){const s=this.ba.get(i)||[];s.push(t),this.ba.set(i,s)}t._s(s),n.ta(t),t.us(n),this.$a(n),this.vo=null}Da(t,i,s){i.se!==s.se&&this.Ka(t)}Ta(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Oo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{e_:t.e_,r_:{Gn:t.h_.externalId},l_:t.h_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{o_:e,r_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.nl?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{h_:n,e_:e}:null}(n,i,s);if("top"===e?.h_.zOrder)return bi(e);for(const r of n){if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&!e.h_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{e_:r,o_:n.o_,r_:n.r_}}if(e&&e.e_===r&&"bottom"!==e.h_.zOrder&&e.h_.isBackground)return bi(e)}return e?.h_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.a_=t,this.__=i,this.In=s}u_(t){const i=t.time,s=this.__.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.c_;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.a_(t);return this.Fn.set(s,{c_: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.d_=t,this.p_=i}Uh(){return this.d_}yi(){return this.p_}f_(){return this.p_-this.d_+1}De(t){return this.d_<=t&&t<=this.p_}Ne(t){return this.d_===t.Uh()&&this.p_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.v_=new Map,this.Fn=null,this.m_=!1}w_(t){this.m_=t,this.Fn=null}g_(t,i){this.b_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.v_.get(i.timeWeight);void 0===n&&(n=[],this.v_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}M_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Fn&&this.Fn.y_===r&&e===this.Fn.S_&&s===this.Fn.x_||(this.Fn={S_:e,x_:s,Fl:this.C_(r,s,n),y_:r}),this.Fn.Fl}b_(t){if(0===t)return void this.v_.clear();const i=[];this.v_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.v_.delete(t)}C_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.v_.keys()).sort((t,i)=>i-t)){if(!this.v_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const o=h(this.v_.get(i)),a=o.length;let _=1/0,u=-1/0;for(let i=0;i<a;i++){const h=o[i],a=h.index;for(;l<r;){const t=s[l],i=t.index;if(!(i<a&&e(t))){_=i;break}l++,n.push(t),u=i,_=1/0}if(_-a>=t&&a-u>=t&&e(h))n.push(h),u=a;else if(this.m_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.P_=t}T_(){return null===this.P_?null:new Ci(Math.floor(this.P_.Uh()),Math.ceil(this.P_.yi()))}k_(){return this.P_}static D_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.Ma=0,this.R_=null,this.F_=[],this.bo=null,this.wo=null,this.I_=new Ti,this.V_=new Map,this.L_=ki.D_(),this.A_=!0,this.E_=new a,this.B_=new a,this.O_=new a,this.W_=null,this.z_=null,this.H_=new Map,this.N_=-1,this.U_=[],this.Ps=i,this.xo=s,this.q_=i.rightOffset,this.j_=i.barSpacing,this.ss=t,this.Y_(i),this.__=n,this.X_(),this.I_.w_(i.uniformDistribution),this.G_()}W(){return this.Ps}K_(t){_(this.xo,t),this.Z_(),this.X_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.J_(),this.Ps.fixRightEdge&&this.Q_(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.Y_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.j_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.G_(),this.Z_(),this.X_(),this.O_.p()}Rs(t){return this.F_[t]?.time??null}ns(t){return this.F_[t]??null}tu(t,i){if(this.F_.length<1)return null;if(this.__.key(t)>this.__.key(this.F_[this.F_.length-1].time))return i?this.F_.length-1:null;const s=yt(this.F_,this.__.key(t),(t,i)=>this.__.key(t.time)<i);return this.__.key(t)<this.__.key(this.F_[s].time)?i?s:null:s}Gi(){return 0===this.Ma||0===this.F_.length||null===this.R_}iu(){return this.F_.length>0}Pe(){return this.su(),this.L_.T_()}nu(){return this.su(),this.L_.k_()}eu(){const t=this.Pe();if(null===t)return null;const i={from:t.Uh(),to:t.yi()};return this.ru(i)}ru(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.hu()),e=l(this.lu());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}ou(t){return{from:l(this.tu(t.from,!0)),to:l(this.tu(t.to,!0))}}ts(){return this.Ma}Aa(t){if(!isFinite(t)||t<=0)return;if(this.Ma===t)return;const i=this.nu(),s=this.Ma;if(this.Ma=t,this.A_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.j_*t/s;this.j_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.Uh()<=0){const i=s-t;this.q_-=Math.round(i/this.j_)+1,this.A_=!0}this.au(),this._u()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.uu()+this.q_-t;return this.Ma-(i+.5)*this.j_-1}cu(t,i){const s=this.uu(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.q_-n,r=this.Ma-(e+.5)*this.j_-1;t[i].ut=r}}du(t,i){const s=Math.ceil(this.pu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.fu(s)?this.vu(s):s}fn(t){this.A_=!0,this.q_=t,this._u(),this.ss.mu(),this.ss.ar()}wu(){return this.j_}pn(t){const i=this.j_;if(this.gu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.q_*i/this.j_;this.q_=t}this._u(),this.ss.mu(),this.ss.ar()}bu(){return this.q_}Fl(){if(this.Gi())return null;if(null!==this.z_)return this.z_;const t=this.j_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.Uh(),n.Uh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.I_.M_(t,i,this.Ps.ignoreWhitespaceIndices,this.H_,this.N_),o=this.hu()+s,a=this.lu()-s,_=this.Mu(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.U_.length?(s=this.U_[d],s.coord=this.jt(t.index),s.label=this.yu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.yu(t),weight:t.weight},this.U_.push(s)),this.j_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.U_.length=d,this.z_=this.U_,this.U_}Su(){let t;this.A_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.wu():this.Ps.rightOffset,this.fn(t)}xu(t){this.A_=!0,this.R_=t,this._u(),this.J_()}Cu(t,i){const s=this.pu(t),n=this.wu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.bu()+(s-this.pu(t)))}ra(t){this.bo&&this._a(),null===this.wo&&null===this.W_&&(this.Gi()||(this.wo=t,this.Pu()))}ha(t){if(null===this.W_)return;const i=Xt(this.Ma-t,0,this.Ma),s=Xt(this.Ma-l(this.wo),0,this.Ma);0!==i&&0!==s&&this.pn(this.W_.wu*i/s)}la(){null!==this.wo&&(this.wo=null,this.Tu())}oa(t){null===this.bo&&null===this.W_&&(this.Gi()||(this.bo=t,this.Pu()))}aa(t){if(null===this.bo)return;const i=(this.bo-t)/this.wu();this.q_=l(this.W_).bu+i,this.A_=!0,this._u()}_a(){null!==this.bo&&(this.bo=null,this.Tu())}ku(){this.Du(this.Ps.rightOffset)}Du(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.q_,n=performance.now();this.ss.un({Ru:t=>(t-n)/i>=1,Fu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.A_=!0,this.F_=t,this.I_.g_(t,i),this._u()}Iu(){return this.E_}Vu(){return this.B_}Lu(){return this.O_}uu(){return this.R_||0}Au(t,i){const s=t.f_(),n=i&&this.Ps.rightOffsetPixels||0;this.gu((this.Ma-n)/s),this.q_=t.yi()-this.uu(),i&&(this.q_=n?n/this.wu():this.Ps.rightOffset),this._u(),this.A_=!0,this.ss.mu(),this.ss.ar()}Eu(){const t=this.hu(),i=this.lu();null!==t&&null!==i&&this.Au(new Ci(t,i),!0)}Bu(t){const i=new Ci(t.from,t.to);this.Au(i)}es(t){return void 0!==this.xo.timeFormatter?this.xo.timeFormatter(t.originalTime):this.__.formatHorzItem(t.time)}G_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.H_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.ml())this.H_.set(t,!0);this.N_++}Mu(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}hu(){return 0===this.F_.length?null:0}lu(){return 0===this.F_.length?null:this.F_.length-1}Ou(t){return(this.Ma-1-t)/this.j_}pu(t){const i=this.Ou(t),s=this.uu()+this.q_-i;return Math.round(1e6*s)/1e6}gu(t){const i=this.j_;this.j_=t,this.au(),i!==this.j_&&(this.A_=!0,this.Wu())}su(){if(!this.A_)return;if(this.A_=!1,this.Gi())return void this.zu(ki.D_());const t=this.uu(),i=this.Ma/this.j_,s=this.q_+t,n=new Ci(s-i+1,s);this.zu(new ki(n))}au(){const t=Xt(this.j_,this.$u(),this.Hu());this.j_!==t&&(this.j_=t,this.A_=!0)}Hu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.Ma}$u(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.F_.length?this.Ma/this.F_.length:this.Ps.minBarSpacing}_u(){const t=this.Nu();null!==t&&this.q_<t&&(this.q_=t,this.A_=!0);const i=this.Uu();this.q_>i&&(this.q_=i,this.A_=!0)}Nu(){const t=this.hu(),i=this.R_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.Ma/this.j_:Math.min(2,this.F_.length))}Uu(){return this.Ps.fixRightEdge?0:this.Ma/this.j_-Math.min(2,this.F_.length)}Pu(){this.W_={wu:this.wu(),bu:this.bu()}}Tu(){this.W_=null}yu(t){let i=this.V_.get(t.weight);return void 0===i&&(i=new xi(t=>this.qu(t),this.__),this.V_.set(t.weight,i)),i.u_(t)}qu(t){return this.__.formatTickmark(t,this.xo)}zu(t){const i=this.L_;this.L_=t,Pi(i.T_(),this.L_.T_())||this.E_.p(),Pi(i.k_(),this.L_.k_())||this.B_.p(),this.Wu()}Wu(){this.z_=null}Z_(){this.Wu(),this.V_.clear()}X_(){this.__.updateFormatter(this.xo)}J_(){if(!this.Ps.fixLeftEdge)return;const t=this.hu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.Uh()-t;if(s<0){const t=this.q_-s-1;this.fn(t)}this.au()}Q_(){this._u(),this.au()}fu(t){return!this.Ps.ignoreWhitespaceIndices||(this.H_.get(t)||!1)}vu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.lu();for(;s;){const t=i.next().value;if(this.H_.get(t))return t;if(t<0||t>s)break}return t}Y_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.j_);this.ss.fn(i)}}}var 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.ju=[],this.Yu=[],this.Ma=0,this.Xu=null,this.Gu=new a,this.Ku=new a,this.Zu=null,this.Ju=t,this.Ps=i,this.__=s,this.Co=new S(this.Ps.layout.colorParsers),this.Qu=new b(this),this.dh=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.tc=new Yt(i.crosshair),i.addDefaultPane&&(this.sc(0),this.ju[0].La(2)),this.nc=this.ec(0),this.rc=this.ec(1)}Lh(){this.hc(Y.bn())}ar(){this.hc(Y.gn())}Zh(){this.hc(new Y(1))}Ah(t){const i=this.lc(t);this.hc(i)}oc(){return this.Xu}ac(t){if(this.Xu?.e_===t?.e_&&this.Xu?.r_?.Gn===t?.r_?.Gn)return;const i=this.Xu;this.Xu=t,null!==i&&this.Ah(i.e_),null!==t&&t.e_!==i?.e_&&this.Ah(t.e_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.ju.forEach(i=>i.Ra(t)),void 0!==t.timeScale&&this.dh.lr(t.timeScale),void 0!==t.localization&&this.dh.K_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Gu.p(),this.nc=this.ec(0),this.rc=this.ec(1),this.Lh()}_c(t,i,s=0){const n=this.ju[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Ra({leftPriceScale:i}),this.Gu.p(),void this.Lh();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Ra({rightPriceScale:i}),this.Gu.p(),void this.Lh();const e=this.uc(t,s);null!==e&&(e.$t.lr(i),this.Gu.p())}uc(t,i){const s=this.ju[i];if(void 0===s)return null;const n=s.Fa(t);return null!==n?{Us:s,$t:n}:null}At(){return this.dh}qs(){return this.ju}cc(){return this.Ct}dc(){return this.Ku}fc(t,i){t.Oo(i),this.mu()}Aa(t){this.Ma=t,this.dh.Aa(this.Ma),this.ju.forEach(i=>i.Aa(t)),this.mu()}vc(t){1!==this.ju.length&&(r(t>=0&&t<this.ju.length,"Invalid pane index"),this.ju.splice(t,1),this.Lh())}mc(t,i){if(this.ju.length<2)return;r(t>=0&&t<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju.reduce((t,i)=>t+i.Va(),0),e=this.ju.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.ju.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.La(i*l);let a=i-o,_=this.ju.length-1;for(const t of this.ju)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.La(s)}this.Lh()}wc(t,i){r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index");const s=this.ju[t],n=this.ju[i];this.ju[t]=n,this.ju[i]=s,this.Lh()}gc(t,i){if(r(t>=0&&t<this.ju.length&&i>=0&&i<this.ju.length,"Invalid pane index"),t===i)return;const[s]=this.ju.splice(t,1);this.ju.splice(i,0,s),this.Lh()}Ua(t,i,s){t.Ua(i,s)}qa(t,i,s){t.qa(i,s),this.Eh(),this.hc(this.bc(t,2))}ja(t,i){t.ja(i),this.hc(this.bc(t,2))}Ya(t,i,s){i.Fo()||t.Ya(i,s)}Xa(t,i,s){i.Fo()||(t.Xa(i,s),this.Eh(),this.hc(this.bc(t,2)))}Ga(t,i){i.Fo()||(t.Ga(i),this.hc(this.bc(t,2)))}Za(t,i){t.Za(i),this.hc(this.bc(t,2))}Mc(t){this.dh.ra(t)}yc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Cu(t,i),this.mu()}Sc(t){this.xc(0),this.Cc(t),this.Pc()}Tc(t){this.dh.ha(t),this.mu()}kc(){this.dh.la(),this.ar()}xc(t){this.dh.oa(t)}Cc(t){this.dh.aa(t),this.mu()}Pc(){this.dh._a(),this.ar()}Xs(){return this.Yu}Dc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.dh.du(t,!0);const l=this.dh.Pe();null!==l&&(h=Math.min(Math.max(l.Uh(),h),l.yi()));const o=n.ks(),a=o.Bt();if(null!==a&&(r=o.Ds(i,a)),r=this.tc.bl(r,h,n),this.Ct.Es(h,r,n),this.Zh(),!e){const e=Si(n,t,i);this.ac(e&&{e_:e.e_,r_:e.r_,l_:e.l_||null}),this.Ku.p(this.Ct.Lt(),{x:t,y:i},s)}}Rc(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.dh.tu(i,!0),o=this.dh.jt(l(h));this.Dc(o,r,null,s,!0)}Fc(t){this.cc().Os(),this.Zh(),t||this.Ku.p(null,null,null)}Eh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Dc(i,s,null,t)}this.Ct.zs()}Ic(t,i,s){const n=this.dh.Rs(0);void 0!==i&&void 0!==s&&this.dh.Tt(i,s);const e=this.dh.Rs(0),r=this.dh.uu(),h=this.dh.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.__.key(n)>this.__.key(e),o=null!==t&&t>r&&!l,a=this.dh.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.dh.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.dh.fn(this.dh.bu()-i)}}this.dh.xu(t)}Oh(t){null!==t&&t.Qa()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.ju.find(i=>i.Ft().includes(t));return void 0===i?null:i}mu(){this.ju.forEach(t=>t.Qa()),this.Eh()}m(){this.ju.forEach(t=>t.m()),this.ju.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Vc(){return this.Qu}Yn(){return this.Qu.W()}Ia(){return this.Gu}Lc(t,i){const s=this.sc(i);this.Ac(t,s),this.Yu.push(t),1===this.Yu.length?this.Lh():this.ar()}Ec(t){const i=this.Nn(t),s=this.Yu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Yu.splice(s,1),n.sa(t),t.m&&t.m(),this.dh.G_();const e=this.ju.length;this.Bc(n),this.ju.length<e&&this.Lh()}Vh(t,i){const s=l(this.Nn(t));s.sa(t,!0),s.ta(t,i,!0)}Eu(){const t=Y.gn();t.hn(),this.hc(t)}Oc(t){const i=Y.gn();i._n(t),this.hc(i)}dn(){const t=Y.gn();t.dn(),this.hc(t)}pn(t){const i=Y.gn();i.pn(t),this.hc(i)}fn(t){const i=Y.gn();i.fn(t),this.hc(i)}un(t){const i=Y.gn();i.un(t),this.hc(i)}ln(){const t=Y.gn();t.ln(),this.hc(t)}Wc(){return this.Ps.rightPriceScale.visible?"right":"left"}zc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.$c(t))return;const s=l(this.Nn(t));s.sa(t);const n=this.sc(i);this.Ac(t,n),0===s.Ml().length&&this.Bc(s),this.Lh()}Hc(){return this.rc}q(){return this.nc}Ut(t){const i=this.rc,s=this.nc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Zu||this.Zu.wr!==s||this.Zu.gr!==i)this.Zu={wr:s,gr:i,Nc:new Map};else{const i=this.Zu.Nc.get(t);if(void 0!==i)return i}const n=this.Co.it(s,i,t/100);return this.Zu.Nc.set(t,n),n}Uc(t){return this.ju.indexOf(t)}Ki(){return this.Co}qc(){return this.jc()}jc(t){const i=new wi(this.dh,this);this.ju.push(i);const s=t??this.ju.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.hc(n),i}sc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.ju.length,t))<this.ju.length?this.ju[t]:this.jc(t)}$c(t){return this.ju.findIndex(i=>i.Wa().includes(t))}bc(t,i){const s=new Y(i);if(null!==t){const n=this.ju.indexOf(t);s.tn(n,{sn:i})}return s}lc(t,i){return void 0===i&&(i=2),this.bc(this.Nn(t),i)}hc(t){this.Ju&&this.Ju(t),this.ju.forEach(t=>t.s_()._r().Tt())}Ac(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.Wc();i.ta(t,n),j(n)||t.lr(t.W())}ec(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Bc(t){!t.Oa()&&0===t.Ml().length&&this.ju.length>1&&this.ju.splice(this.Uc(t),1)}}function Bi(t){if(t>=1)return 0;let i=0;for(;i<8;i++){const s=Math.round(t);if(Math.abs(s-t)<1e-8)return i;t*=10}return i}function 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.Yc=t,this.Xc=i}u_(t){return $i(t,this.Yc,this.Xc)}}class Ni{constructor(t){this.Gc=t||"%h:%m:%s"}u_(t){return this.Gc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Kc:"yyyy-MM-dd",Zc:"%h:%m:%s",Jc:" ",Qc:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.td=new Hi(i.Kc,i.Qc),this.sd=new Ni(i.Zc),this.nd=i.Jc}u_(t){return`${this.td.u_(t)}${this.nd}${this.sd.u_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{ed:(Gi=1,1e3*Gi),rd:10},{ed:Yi(1),rd:20},{ed:Yi(5),rd:21},{ed:Yi(30),rd:22},{ed:ji(1),rd:30},{ed:ji(3),rd:31},{ed:ji(6),rd:32},{ed:ji(12),rd:33}];var Gi;function 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].ed)!==Math.floor(t.getTime()/Xi[s].ed))return Xi[s].rd;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Oi(i))throw new Error("time must be of type BusinessDay");const s=new Date(Date.UTC(i.year,i.month-1,i.day,0,0,0,0));return{hd:Math.round(s.getTime()/1e3),ld:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{hd:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}class ss{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Oi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"hd"in t?t.hd:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ld?new Date(1e3*i.hd).getTime():new Date(Date.UTC(i.ld.year,i.ld.month-1,i.ld.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Oi(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this.od=new qi({Kc:i,Zc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Jc:" ",Qc:t.locale}):this.od=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.od.u_(new Date(1e3*i.hd))}formatTickmark(t,i){const s=function(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.ld?new Date(1e3*t.hd):new Date(Date.UTC(t.ld.year,t.ld.month-1,t.ld.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.hd,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).hd);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).hd-(s||Zi(i.time).hd),s=Zi(i.time).hd,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.hd-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.hd),s)}}(t,i)}static ad(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function ns(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function es(t,i){return t.width===i.width&&t.height===i.height}var rs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var hs=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=ns({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return ns({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=ns(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;es(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=ns(this._transformBitmapSize(t,this._canvasElementClientSize)),n=es(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&es(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=ls(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new rs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=ls(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return ns({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):ns({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=ns({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function ls(t){return t.ownerDocument.defaultView}var os=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function as(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new os(e,s,n)}const _s="undefined"!=typeof window;function us(){return!!_s&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function cs(){return!!_s&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ds(t){return t+t%2}function ps(t){_s&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class fs{constructor(t,i,s){this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.md=null,this.wd=!1,this.gd=null,this.bd=null,this.Md=!1,this.yd=!1,this.Sd=!1,this.xd=null,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=0,this.Id=!1,this.Vd=!1,this.Ld=!1,this.Ad=0,this.Ed=null,this.Bd=!cs(),this.Od=t=>{this.Wd(t)},this.zd=t=>{if(this.$d(t)){const i=this.Hd(t);if(++this.pd,this.fd&&this.pd>1){const{Nd:s}=this.Ud(ws(t),this.vd);s<30&&!this.Sd&&this.qd(i,this.Yd.jd),this.Xd()}}else{const i=this.Hd(t);if(++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Kd),this.Zd()}}},this.Jd=t,this.Yd=i,this.Ps=s,this.Qd()}m(){null!==this.xd&&(this.xd(),this.xd=null),null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),this.tp(),this.Zd()}ip(t){this.Td&&this.Td();const i=this.sp.bind(this);if(this.Td=()=>{this.Jd.removeEventListener("mousemove",i)},this.Jd.addEventListener("mousemove",i),this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.np),this.Bd=!0}Zd(){null!==this.ud&&clearTimeout(this.ud),this._d=0,this.ud=null,this.dd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Xd(){null!==this.fd&&clearTimeout(this.fd),this.pd=0,this.fd=null,this.vd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}sp(t){if(this.Ld||null!==this.bd)return;if(this.$d(t))return;const i=this.Hd(t);this.Gd(i,this.Yd.ep),this.Bd=!0}rp(t){const i=bs(t.changedTouches,l(this.Ed));if(null===i)return;if(this.Ad=gs(t),null!==this.Rd)return;if(this.Vd)return;this.Id=!0;const s=this.Ud(ws(i),l(this.bd)),{hp:n,lp:e,Nd:r}=s;if(this.Md||!(r<5)){if(!this.Md){const t=.5*n,i=e>=t&&!this.Ps.op(),s=t>e&&!this.Ps.ap();i||s||(this.Vd=!0),this.Md=!0,this.Sd=!0,this.tp(),this.Xd()}if(!this.Vd){const s=this.Hd(t,i);this.qd(s,this.Yd._p),ms(t)}}}up(t){if(0!==t.button)return;const i=this.Ud(ws(t),l(this.gd)),{Nd:s}=i;if(s>=5&&(this.yd=!0,this.Zd()),this.yd){const i=this.Hd(t);this.Gd(i,this.Yd.cp)}}Ud(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{hp:s,lp:n,Nd:s+n}}dp(t){let i=bs(t.changedTouches,l(this.Ed));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ed=null,this.Ad=gs(t),this.tp(),this.bd=null,this.Dd&&(this.Dd(),this.Dd=null);const s=this.Hd(t,i);if(this.qd(s,this.Yd.pp),++this.pd,this.fd&&this.pd>1){const{Nd:t}=this.Ud(ws(i),this.vd);t<30&&!this.Sd&&this.qd(s,this.Yd.jd),this.Xd()}else this.Sd||(this.qd(s,this.Yd.fp),this.Yd.fp&&ms(t));0===this.pd&&ms(t),0===t.touches.length&&this.wd&&(this.wd=!1,ms(t))}Wd(t){if(0!==t.button)return;const i=this.Hd(t);if(this.gd=null,this.Ld=!1,this.kd&&(this.kd(),this.kd=null),us()){this.Jd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Od)}if(!this.$d(t))if(this.Gd(i,this.Yd.vp),++this._d,this.ud&&this._d>1){const{Nd:s}=this.Ud(ws(t),this.dd);s<5&&!this.yd&&this.Gd(i,this.Yd.Kd),this.Zd()}else this.yd||this.Gd(i,this.Yd.mp)}tp(){null!==this.md&&(clearTimeout(this.md),this.md=null)}wp(t){if(null!==this.Ed)return;const i=t.changedTouches[0];this.Ed=i.identifier,this.Ad=gs(t);const s=this.Jd.ownerDocument.documentElement;this.Sd=!1,this.Md=!1,this.Vd=!1,this.bd=ws(i),this.Dd&&(this.Dd(),this.Dd=null);{const i=this.rp.bind(this),n=this.dp.bind(this);this.Dd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.tp(),this.md=setTimeout(this.gp.bind(this,t),240)}const n=this.Hd(t,i);this.qd(n,this.Yd.bp),this.fd||(this.pd=0,this.fd=setTimeout(this.Xd.bind(this),500),this.vd=ws(i))}Mp(t){if(0!==t.button)return;const i=this.Jd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Od),this.yd=!1,this.gd=ws(t),this.kd&&(this.kd(),this.kd=null);{const t=this.up.bind(this),s=this.Wd.bind(this);this.kd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ld=!0,this.$d(t))return;const s=this.Hd(t);this.Gd(s,this.Yd.yp),this.ud||(this._d=0,this.ud=setTimeout(this.Zd.bind(this),500),this.dd=ws(t))}Qd(){this.Jd.addEventListener("mouseenter",this.ip.bind(this)),this.Jd.addEventListener("touchcancel",this.tp.bind(this));{const t=this.Jd.ownerDocument,i=t=>{this.Yd.Sp&&(t.composed&&this.Jd.contains(t.composedPath()[0])||t.target&&this.Jd.contains(t.target)||this.Yd.Sp())};this.Cd=()=>{t.removeEventListener("touchstart",i)},this.xd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Pd=()=>{this.Jd.removeEventListener("dblclick",this.zd)},this.Jd.addEventListener("dblclick",this.zd)),this.Jd.addEventListener("mouseleave",this.xp.bind(this)),this.Jd.addEventListener("touchstart",this.wp.bind(this),{passive:!0}),ps(this.Jd),this.Jd.addEventListener("mousedown",this.Mp.bind(this)),this.Cp(),this.Jd.addEventListener("touchmove",()=>{},{passive:!1})}Cp(){void 0===this.Yd.Pp&&void 0===this.Yd.Tp&&void 0===this.Yd.kp||(this.Jd.addEventListener("touchstart",t=>this.Dp(t.touches),{passive:!0}),this.Jd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Rd&&void 0!==this.Yd.Tp){const i=vs(t.touches[0],t.touches[1])/this.Fd;this.Yd.Tp(this.Rd,i),ms(t)}},{passive:!1}),this.Jd.addEventListener("touchend",t=>{this.Dp(t.touches)}))}Dp(t){1===t.length&&(this.Id=!1),2!==t.length||this.Id||this.wd?this.Rp():this.Fp(t)}Fp(t){const i=this.Jd.getBoundingClientRect()||{left:0,top:0};this.Rd={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.Fd=vs(t[0],t[1]),void 0!==this.Yd.Pp&&this.Yd.Pp(),this.tp()}Rp(){null!==this.Rd&&(this.Rd=null,void 0!==this.Yd.kp&&this.Yd.kp())}xp(t){if(this.Td&&this.Td(),this.$d(t))return;if(!this.Bd)return;const i=this.Hd(t);this.Gd(i,this.Yd.Ip),this.Bd=!cs()}gp(t){const i=bs(t.touches,l(this.Ed));if(null===i)return;const s=this.Hd(t,i);this.qd(s,this.Yd.Vp),this.Sd=!0,this.wd=!0}$d(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ad+500}qd(t,i){i&&i.call(this.Yd,t)}Gd(t,i){i&&i.call(this.Yd,t)}Hd(t,i){const s=i||t,n=this.Jd.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Lp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ap:t.type,Ep:s.target,o_:t.view,Bp:()=>{"touchstart"!==t.type&&ms(t)}}}}function vs(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ms(t){t.cancelable&&t.preventDefault()}function ws(t){return{ut:t.pageX,ct:t.pageY}}function gs(t){return t.timeStamp||performance.now()}function bs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ms{constructor(t,i,s){this.Op=null,this.Wp=null,this.zp=!0,this.$p=null,this.Hp=t,this.Np=t.Up()[i],this.qp=t.Up()[s],this.jp=document.createElement("tr"),this.jp.style.height="1px",this.Yp=document.createElement("td"),this.Yp.style.position="relative",this.Yp.style.padding="0",this.Yp.style.margin="0",this.Yp.setAttribute("colspan","3"),this.Xp(),this.jp.appendChild(this.Yp),this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(this.Op=null,this.Wp=null)}m(){null!==this.Wp&&this.Wp.m()}Kp(){return this.jp}Zp(){return ns({width:this.Np.Zp().width,height:1})}Jp(){return ns({width:this.Np.Jp().width,height:1*window.devicePixelRatio})}Qp(t,i,s){const n=this.Jp();t.fillStyle=this.Hp.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Xp(),this.Hp.W().layout.panes.enableResize!==this.zp&&(this.zp=this.Hp.W().layout.panes.enableResize,this.zp?this.Gp():(null!==this.Op&&(this.Yp.removeChild(this.Op.tf),this.Yp.removeChild(this.Op.if),this.Op=null),null!==this.Wp&&(this.Wp.m(),this.Wp=null)))}Gp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Yp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Yp.appendChild(s);const e={np:this.sf.bind(this),Ip:this.nf.bind(this),yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this)};this.Wp=new fs(s,e,{op:()=>!1,ap:()=>!0}),this.Op={if:s,tf:t}}Xp(){this.Yp.style.background=this.Hp.W().layout.panes.separatorColor}sf(t){null!==this.Op&&(this.Op.if.style.backgroundColor=this.Hp.W().layout.panes.separatorHoverColor)}nf(t){null!==this.Op&&null===this.$p&&(this.Op.if.style.backgroundColor="")}ef(t){if(null===this.Op)return;const i=this.Np.lf().Va()+this.qp.lf().Va(),s=i/(this.Np.Zp().height+this.qp.Zp().height),n=30*s;i<=2*n||(this.$p={af:t.pageY,_f:this.Np.lf().Va(),uf:i-n,cf:i,df:s,pf:n},this.Op.tf.style.display="block")}rf(t){const i=this.$p;if(null===i)return;const s=(t.pageY-i.af)*i.df,n=Xt(i._f+s,i.pf,i.uf);this.Np.lf().La(n),this.qp.lf().La(i.cf-n),this.Hp.ti().Lh()}hf(t){null!==this.$p&&null!==this.Op&&(this.$p=null,this.Op.tf.style.display="none")}}function ys(t,i){return t.ff-i.ff}function Ss(t,i,s){const n=(t.ff-i.ff)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.vf=null,this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=0,this.yf=0,this.Sf=t,this.xf=i,this.Cf=s,this.Mn=n}Pf(t,i){if(null!==this.vf){if(this.vf.gt===i)return void(this.vf.ff=t);if(Math.abs(this.vf.ff-t)<this.Mn)return}this.gf=this.wf,this.wf=this.mf,this.mf=this.vf,this.vf={gt:i,ff:t}}ae(t,i){if(null===this.vf||null===this.mf)return;if(i-this.vf.gt>50)return;let s=0;const n=Ss(this.vf,this.mf,this.xf),e=ys(this.vf,this.mf),r=[n],h=[e];if(s+=e,null!==this.wf){const t=Ss(this.mf,this.wf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.mf,this.wf);if(r.push(t),h.push(i),s+=i,null!==this.gf){const t=Ss(this.wf,this.gf,this.xf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.Sf||(this.bf={ff:t,gt:i},this.yf=l,this.Mf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Cf))}Fu(t){const i=l(this.bf),s=t-i.gt;return i.ff+this.yf*(Math.pow(this.Cf,s)-1)/Math.log(this.Cf)}Ru(t){return null===this.bf||this.Tf(t)===this.Mf}Tf(t){const i=t-l(this.bf).gt;return Math.min(i,this.Mf)}}class Cs{constructor(t,i){this.kf=void 0,this.Df=void 0,this.Rf=void 0,this.vs=!1,this.Ff=t,this.If=i,this.Vf()}Tt(){this.Vf()}Lf(){this.kf&&this.Ff.removeChild(this.kf),this.Df&&this.Ff.removeChild(this.Df),this.kf=void 0,this.Df=void 0}Af(){return this.vs!==this.Ef()||this.Rf!==this.Bf()}Bf(){return this.If.ti().Ki().tt(this.If.W().layout.textColor)>160?"dark":"light"}Ef(){return this.If.W().layout.attributionLogo}Of(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Vf(){this.Af()&&(this.Lf(),this.vs=this.Ef(),this.vs&&(this.Rf=this.Bf(),this.Df=document.createElement("style"),this.Df.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.kf=document.createElement("a"),this.kf.href=`https://pipsend.com${this.Of()}`,this.kf.title="Powered by Pipsend Charts",this.kf.id="pipsend-attr-logo",this.kf.target="_blank",this.kf.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.kf.toggleAttribute("data-dark","dark"===this.Rf),this.Ff.appendChild(this.Df),this.Ff.appendChild(this.kf)))}}function Ps(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new hs(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function Ts(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function ks(t,i,s,n){t.sh&&t.sh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function 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()?.wl()??"")!==i?[]:s.il?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],o=t[r-1],a=o.qt(n,!1),_=l.$i(),u=o.$i();if(1===i?_>u-a:_<u+a){const n=u-a*i;l.Hi(n);const r=n-i*a/2;if((1===i?r<0:r>s)&&h>0){const n=1===i?-1-r:r-s,l=Math.min(n,h);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);h-=l}}else e=r,h=1===i?u-a-_:_-(u+a)}}class Vs{constructor(t,i,s,n){this.Yi=null,this.Wf=null,this.zf=!1,this.$f=new it(200),this.Hf=null,this.Nf=0,this.Uf=!1,this.qf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Yf=()=>{this.Uf||this.Pt.jf().ti().ar()},this.Pt=t,this.Ps=i,this.So=i.layout,this.Qu=s,this.Xf="left"===n,this.Gf=Fs("normal",n),this.Kf=Fs("top",n),this.Zf=Fs("bottom",n),this.Yp=document.createElement("div"),this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Yp.style.width="25px",this.Yp.style.left="0",this.Yp.style.position="relative",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const e=this.Jf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.Qf=Ps(this.Yp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const r=this.Qf.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={yp:this.ef.bind(this),bp:this.ef.bind(this),cp:this.rf.bind(this),_p:this.rf.bind(this),Sp:this.tv.bind(this),vp:this.hf.bind(this),pp:this.hf.bind(this),Kd:this.iv.bind(this),jd:this.iv.bind(this),np:this.sv.bind(this),Ip:this.nf.bind(this)};this.Wp=new fs(this.Qf.canvasElement,h,{op:()=>!this.Ps.handleScroll.vertTouchDrag,ap:()=>!0})}m(){this.Wp.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Yi&&this.Yi.ea().u(this),this.Yi=null}Kp(){return this.Yp}P(){return this.So.fontSize}nv(){const t=this.Qu.W();return this.Hf!==t.T&&(this.$f.Vn(),this.Hf=t.T),t}ev(){if(null===this.Yi)return 0;let t=0;const i=this.nv(),s=l(this.Jf.canvasElement.getContext("2d",{colorSpace:this.Pt.jf().W().layout.colorSpace}));s.save();const n=this.Yi.Fl();s.font=this.rv(),n.length>0&&(t=Math.max(this.$f.Ii(s,n[0].Zl),this.$f.Ii(s,n[n.length-1].Zl)));const e=this.hv();for(let i=e.length;i--;){const n=this.$f.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.Wf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.Wf.height-2,r);t=Math.max(t,this.$f.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.$f.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ds(Math.ceil(i.S+i.C+i.V+i.L+5+o))}lv(t){null!==this.Wf&&es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`)}ov(){return l(this.Wf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ea().u(this),this.Yi=t,t.ea().i(this.co.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt.lf();this.Pt.jf().ti().Za(t,l(this.$t()))}av(t){if(null===this.Wf)return;const i={colorSpace:this.Pt.jf().W().layout.colorSpace};if(1!==t){this._v(),this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)}),this.Pt.dv(t,this.Zf),this.pv(t),this.Pt.dv(t,this.Gf),this.fv(t))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.vv(s),this.Pt.dv(s,this.Kf))}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Fl()}ef(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!0,i.Ua(s,this.Yi,t.localY)}rf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf(),n=this.Yi;i.qa(s,n,t.localY)}tv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.jf().ti(),i=this.Pt.lf(),s=this.Yi;this.zf&&(this.zf=!1,t.ja(i,s))}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.jf().ti(),s=this.Pt.lf();this.zf=!1,i.ja(s,this.Yi)}iv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}sv(t){if(null===this.Yi)return;!this.Pt.jf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Vo()||this.mv(1)}nf(t){this.mv(0)}hv(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt.lf(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.lf().Ft()),t}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.lf().ti(),r=e.q(),h=e.Hc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.Wf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.nv().S*s));let e;e=this.Xf?i.width-n:0,t.fillRect(e,0,n,i.height)}pv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Yi.Fl(),s=this.Yi.W(),n=this.nv(),e=this.Xf?this.Wf.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Pl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.rv(),t.fillStyle=s.textColor??this.So.textColor,t.textAlign=this.Xf?"right":"left",t.textBaseline="middle";const r=this.Xf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.$f.Fi(t,i.Zl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Zl,r,n.Pl+h[s])}})}_v(){if(null===this.Wf||null===this.Yi)return;let t=this.Wf.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt.lf(),e=this.nv();this.Yi===n.qn()&&this.Pt.lf().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.Ml()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.wv(i,e,t)}wv(t,i,s){if(null===this.Wf)return;const n=t.filter(t=>t.Li()<=s),e=t.filter(t=>t.Li()>s);n.sort((t,i)=>i.Li()-t.Li()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Li()-i.Li());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Li();n>-t&&n<t&&s.Hi(t),n>this.Wf.height-t&&n<this.Wf.height+t&&s.Hi(this.Wf.height-t)}Is(n,1,this.Wf.height,i),Is(e,-1,this.Wf.height,i)}fv(t){if(null===this.Wf)return;const i=this.hv(),s=this.nv(),n=this.Xf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.$f,n)}})}vv(t){if(null===this.Wf||null===this.Yi)return;const i=this.Pt.jf().ti(),s=[],n=this.Pt.lf(),e=i.cc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.nv(),h=this.Xf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.$f,h)})})}mv(t){this.Yp.style.cursor=1===t?"ns-resize":"default"}co(){const t=this.ev();this.Nf<t&&this.Pt.jf().ti().Lh(),this.Nf=t}rv(){return g(this.So.fontSize,this.So.fontFamily)}}function Ls(t,i){return t.Qh?.(i)??[]}function As(t,i){return t.$s?.(i)??[]}function Es(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Kh?.(i)??[]}class Os{constructor(t,i){this.Wf=ns({width:0,height:0}),this.gv=null,this.bv=null,this.Mv=null,this.yv=null,this.Sv=!1,this.xv=new a,this.Cv=new a,this.Pv=0,this.Tv=!1,this.kv=null,this.Dv=!1,this.Rv=null,this.Fv=null,this.Uf=!1,this.qf=()=>{this.Uf||null===this.Iv||this.ss().ar()},this.Yf=()=>{this.Uf||null===this.Iv||this.ss().ar()},this.If=t,this.Iv=i,this.Iv.i_().i(this.Vv.bind(this),this,!0),this.Lv=document.createElement("td"),this.Lv.style.padding="0",this.Lv.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Av=document.createElement("td"),this.Av.style.padding="0",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Lv.appendChild(s),this.Jf=Ps(s,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const n=this.Jf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.jp=document.createElement("tr"),this.jp.appendChild(this.Av),this.jp.appendChild(this.Lv),this.jp.appendChild(this.Ev),this.Bv(),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>null===this.kv&&!this.If.W().handleScroll.vertTouchDrag,ap:()=>null===this.kv&&!this.If.W().handleScroll.horzTouchDrag})}m(){null!==this.gv&&this.gv.m(),null!==this.bv&&this.bv.m(),this.Mv=null,this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose(),null!==this.Iv&&(this.Iv.i_().u(this),this.Iv.m()),this.Wp.m()}lf(){return l(this.Iv)}Ov(t){null!==this.Iv&&this.Iv.i_().u(this),this.Iv=t,null!==this.Iv&&this.Iv.i_().i(Os.prototype.Vv.bind(this),this,!0),this.Bv(),this.If.Up().indexOf(this)===this.If.Up().length-1?(this.Mv=this.Mv??new Cs(this.Lv,this.If),this.Mv.Tt()):(this.Mv?.Lf(),this.Mv=null)}jf(){return this.If}Kp(){return this.jp}Bv(){if(null!==this.Iv&&(this.Wv(),0!==this.ss().Xs().length)){if(null!==this.gv){const t=this.Iv.Ha();this.gv.us(l(t))}if(null!==this.bv){const t=this.Iv.Na();this.bv.us(l(t))}}}zv(){null!==this.gv&&this.gv.Tt(),null!==this.bv&&this.bv.Tt()}Va(){return null!==this.Iv?this.Iv.Va():0}La(t){this.Iv&&this.Iv.La(t)}np(t){if(!this.Iv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}yp(t){this.$v(),this.Nv(),this.Hv(t.localX,t.localY,t)}ep(t){if(!this.Iv)return;this.$v();const i=t.localX,s=t.localY;this.Hv(i,s,t)}mp(t){null!==this.Iv&&(this.$v(),this.Uv(t))}Kd(t){null!==this.Iv&&this.qv(this.Cv,t)}jd(t){this.Kd(t)}cp(t){this.$v(),this.jv(t),this.Hv(t.localX,t.localY,t)}vp(t){null!==this.Iv&&(this.$v(),this.Tv=!1,this.Yv(t))}fp(t){null!==this.Iv&&this.Uv(t)}Vp(t){if(this.Tv=!0,null===this.kv){const i={x:t.localX,y:t.localY};this.Xv(i,i,t)}}Ip(t){null!==this.Iv&&(this.$v(),this.Iv.ti().ac(null),this.Gv())}Kv(){return this.xv}Zv(){return this.Cv}Pp(){this.Pv=1,this.ss().ln()}Tp(t,i){if(!this.If.W().handleScale.pinch)return;const s=5*(i-this.Pv);this.Pv=i,this.ss().yc(t.ut,s)}bp(t){this.Tv=!1,this.Dv=null!==this.kv,this.Nv();const i=this.ss().cc();null!==this.kv&&i.It()&&(this.Rv={x:i.ni(),y:i.ei()},this.kv={x:t.localX,y:t.localY})}_p(t){if(null===this.Iv)return;const i=t.localX,s=t.localY;if(null!==this.kv){this.Dv=!1;const n=l(this.Rv),e=n.x+(i-this.kv.x),r=n.y+(s-this.kv.y);return void this.Hv(e,r,t)}this.jv(t)}pp(t){0===this.jf().W().trackingMode.exitMode&&(this.Dv=!0),this.Jv(),this.Yv(t)}Xn(t,i){const s=this.Iv;return null===s?null:Si(s,t,i)}Qv(t,i){l("left"===i?this.gv:this.bv).lv(ns({width:t,height:this.Wf.height}))}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Lv.style.width=t.width+"px",this.Lv.style.height=t.height+"px")}tm(){const t=l(this.Iv);t.$a(t.Ha()),t.$a(t.Na());for(const i of t.Ml())if(t.Un(i)){const s=i.$t();null!==s&&t.$a(s),i.zs()}for(const i of t.n_())i.zs()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;null!==t&&t.drawImage(n,i,s)}}av(t){if(0===t)return;if(null===this.Iv)return;t>1&&this.tm(),null!==this.gv&&this.gv.av(t),null!==this.bv&&this.bv.av(t);const i={colorSpace:this.If.W().layout.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const t=as(this.Jf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.uv(t)}),this.Iv&&(this.im(t,Ls),this.sm(t),this.im(t,As),this.im(t,Es)))}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.nm(s),this.im(s,Bs),this.im(s,Es))}rm(){return this.gv}hm(){return this.bv}dv(t,i){this.im(t,i)}Vv(){null!==this.Iv&&this.Iv.i_().u(this),this.Iv=null}Uv(t){this.qv(this.xv,t)}qv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().du(s),{x:s,y:n},i)}uv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Hc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}sm(t){const i=l(this.Iv),s=i.s_()._r().Dt(i);null!==s&&s.et(t,!1)}nm(t){this.lm(t,As,Ds,this.ss().cc())}im(t,i){const s=l(this.Iv),n=s.Ft(),e=s.n_();for(const s of e)this.lm(t,i,ks,s);for(const s of n)this.lm(t,i,ks,s);for(const s of e)this.lm(t,i,Ds,s);for(const s of n)this.lm(t,i,Ds,s)}lm(t,i,s,n){const e=l(this.Iv),r=e.ti().oc(),h=null!==r&&r.e_===n,o=null!==r&&h&&void 0!==r.r_?r.r_.Kn:void 0;Rs(i,i=>s(i,t,h,o),n,e)}Wv(){if(null===this.Iv)return;const t=this.If,i=this.Iv.Ha().W().visible,s=this.Iv.Na().W().visible;i||null===this.gv||(this.Av.removeChild(this.gv.Kp()),this.gv.m(),this.gv=null),s||null===this.bv||(this.Ev.removeChild(this.bv.Kp()),this.bv.m(),this.bv=null);const n=t.ti().Vc();i&&null===this.gv&&(this.gv=new Vs(this,t.W(),n,"left"),this.Av.appendChild(this.gv.Kp())),s&&null===this.bv&&(this.bv=new Vs(this,t.W(),n,"right"),this.Ev.appendChild(this.bv.Kp()))}om(t){return t.Lp&&this.Tv||null!==this.kv}am(t){return Math.max(0,Math.min(t,this.Wf.width-1))}_m(t){return Math.max(0,Math.min(t,this.Wf.height-1))}Hv(t,i,s){this.ss().Dc(this.am(t),this._m(i),s,l(this.Iv))}Gv(){this.ss().Fc()}Jv(){this.Dv&&(this.kv=null,this.Gv())}Xv(t,i,s){this.kv=t,this.Dv=!1,this.Hv(i.x,i.y,s);const n=this.ss().cc();this.Rv={x:n.ni(),y:n.ei()}}ss(){return this.If.ti()}Yv(t){if(!this.Sv)return;const i=this.ss(),s=this.lf();if(i.Ga(s,s.ks()),this.yv=null,this.Sv=!1,i.Pc(),null!==this.Fv){const t=performance.now(),s=i.At();this.Fv.ae(s.bu(),t),this.Fv.Ru(t)||i.un(this.Fv)}}$v(){this.kv=null}Nv(){if(!this.Iv)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.Iv.ks().Gi()&&this.ss().At().Gi()}jv(t){if(null===this.Iv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.If.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Lp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Lp))return;const h=this.Iv.ks(),l=performance.now();if(null!==this.yv||this.om(t)||(this.yv={x:t.clientX,y:t.clientY,hd:l,um:t.localX,dm:t.localY}),null!==this.yv&&!this.Sv&&(this.yv.x!==t.clientX||this.yv.y!==t.clientY)){if(t.Lp&&r.touch||!t.Lp&&r.mouse){const t=s.wu();this.Fv=new xs(.2/t,7/t,.997,15/t),this.Fv.Pf(s.bu(),this.yv.hd)}else this.Fv=null;h.Gi()||i.Ya(this.Iv,h,t.localY),i.xc(t.localX),this.Sv=!0}this.Sv&&(h.Gi()||i.Xa(this.Iv,h,t.localY),i.Cc(t.localX),null!==this.Fv&&this.Fv.Pf(s.bu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.Wf=ns({width:0,height:0}),this.qf=()=>this.av(3),this.Xf="left"===t,this.Qu=s.Vc,this.Ps=i,this.pm=n,this.fm=e,this.Yp=document.createElement("div"),this.Yp.style.width="25px",this.Yp.style.height="100%",this.Yp.style.overflow="hidden",this.Jf=Ps(this.Yp,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf)}m(){this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Kp(){return this.Yp}Zp(){return this.Wf}lv(t){es(this.Wf,t)||(this.Wf=t,this.Jf.resizeCanvasElement(t),this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.xt=!0)}av(t){if(t<3&&!this.xt)return;if(0===this.Wf.width||0===this.Wf.height)return;this.xt=!1,this.Jf.applySuggestedBitmapSize();const i=as(this.Jf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t)})}Jp(){return this.Jf.bitmapSize}Qp(t,i,s){const n=this.Jp();n.width>0&&n.height>0&&t.drawImage(this.Jf.canvasElement,i,s)}cv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.pm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.Qu.W().S*s),r=Math.floor(this.Qu.W().S*n),h=this.Xf?i.width-e:0;t.fillRect(h,0,e,r)}uv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.fm())}}function zs(t){return i=>i.sl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.vm=null,this.wm=null,this.M=null,this.gm=!1,this.Wf=ns({width:0,height:0}),this.bm=new a,this.$f=new it(5),this.Uf=!1,this.qf=()=>{this.Uf||this.If.ti().ar()},this.Yf=()=>{this.Uf||this.If.ti().ar()},this.If=t,this.__=i,this.Ps=t.W().layout,this.kf=document.createElement("tr"),this.Mm=document.createElement("td"),this.Mm.style.padding="0",this.ym=document.createElement("td"),this.ym.style.padding="0",this.Yp=document.createElement("td"),this.Yp.style.height="25px",this.Yp.style.padding="0",this.Sm=document.createElement("div"),this.Sm.style.width="100%",this.Sm.style.height="100%",this.Sm.style.position="relative",this.Sm.style.overflow="hidden",this.Yp.appendChild(this.Sm),this.Jf=Ps(this.Sm,ns({width:16,height:16})),this.Jf.subscribeSuggestedBitmapSizeChanged(this.qf);const s=this.Jf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Qf=Ps(this.Sm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.kf.appendChild(this.Mm),this.kf.appendChild(this.Yp),this.kf.appendChild(this.ym),this.xm(),this.If.ti().Ia().i(this.xm.bind(this),this),this.Wp=new fs(this.Qf.canvasElement,this,{op:()=>!0,ap:()=>!this.If.W().handleScroll.horzTouchDrag})}m(){this.Wp.m(),null!==this.vm&&this.vm.m(),null!==this.wm&&this.wm.m(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.Yf),Ts(this.Qf.canvasElement),this.Qf.dispose(),this.Jf.unsubscribeSuggestedBitmapSizeChanged(this.qf),Ts(this.Jf.canvasElement),this.Jf.dispose()}Kp(){return this.kf}Cm(){return this.vm}Pm(){return this.wm}yp(t){if(this.gm)return;this.gm=!0;const i=this.If.ti();!i.At().Gi()&&this.If.W().handleScale.axisPressedMouseMove.time&&i.Mc(t.localX)}bp(t){this.yp(t)}Sp(){const t=this.If.ti();!t.At().Gi()&&this.gm&&(this.gm=!1,this.If.W().handleScale.axisPressedMouseMove.time&&t.kc())}cp(t){const i=this.If.ti();!i.At().Gi()&&this.If.W().handleScale.axisPressedMouseMove.time&&i.Tc(t.localX)}_p(t){this.cp(t)}vp(){this.gm=!1;const t=this.If.ti();t.At().Gi()&&!this.If.W().handleScale.axisPressedMouseMove.time||t.kc()}pp(){this.vp()}Kd(){this.If.W().handleScale.axisDoubleClickReset.time&&this.If.ti().dn()}jd(){this.Kd()}np(){this.If.ti().W().handleScale.axisPressedMouseMove.time&&this.mv(1)}Ip(){this.mv(0)}Zp(){return this.Wf}Tm(){return this.bm}km(t,i,s){es(this.Wf,t)||(this.Wf=t,this.Uf=!0,this.Jf.resizeCanvasElement(t),this.Qf.resizeCanvasElement(t),this.Uf=!1,this.Yp.style.width=`${t.width}px`,this.Yp.style.height=`${t.height}px`,this.bm.p(t)),null!==this.vm&&this.vm.lv(ns({width:i,height:t.height})),null!==this.wm&&this.wm.lv(ns({width:s,height:t.height}))}Dm(){const t=this.Rm();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Fm)}Tt(){this.If.ti().At().Fl()}Jp(){return this.Jf.bitmapSize}Qp(t,i,s,n){const e=this.Jp();if(e.width>0&&e.height>0&&(t.drawImage(this.Jf.canvasElement,i,s),n)){const n=this.Qf.canvasElement;t.drawImage(n,i,s)}}av(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Jf.applySuggestedBitmapSize();const s=as(this.Jf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.uv(t),this.cv(t),this.Im(s,Ns)}),this.pv(s),this.Im(s,$s)),null!==this.vm&&this.vm.av(t),null!==this.wm&&this.wm.av(t)}this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Vm([...this.If.ti().Xs(),this.If.ti().cc()],s),this.Im(s,Hs))}Im(t,i){const s=this.If.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)}uv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.If.ti().Hc())}cv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.If.W().timeScale.borderVisible){t.fillStyle=this.Lm();const n=Math.max(1,Math.floor(this.Rm().S*s));t.fillRect(0,0,i.width,n)}}pv(t){const i=this.If.ti().At(),s=i.Fl();if(!s||0===s.length)return;const n=this.__.maxTickMarkWeight(s),e=this.Rm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Lm(),t.fillStyle=this.Lm();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.rv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Am(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.If.W().timeScale.allowBoldLabels&&(t.font=this.Em());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Am(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Am(t,i,s){const n=this.$f.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.Wf.width&&(i-=Math.abs(this.Wf.width-(r+n))),i}Vm(t,i){const s=this.Rm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Lm(){return this.If.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}rv(){return g(this.$(),this.Ps.fontFamily)}Em(){return g(this.$(),this.Ps.fontFamily,"bold")}Rm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Fm:0});const t=this.M,i=this.rv();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.Fm=4*s/12,t.Ji.Vn()}return this.M}mv(t){this.Yp.style.cursor=1===t?"ew-resize":"default"}xm(){const t=this.If.ti(),i=t.W();i.leftPriceScale.visible||null===this.vm||(this.Mm.removeChild(this.vm.Kp()),this.vm.m(),this.vm=null),i.rightPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Kp()),this.wm.m(),this.wm=null);const s={Vc:this.If.ti().Vc()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Hc();i.leftPriceScale.visible&&null===this.vm&&(this.vm=new Ws("left",i,s,n,e),this.Mm.appendChild(this.vm.Kp())),i.rightPriceScale.visible&&null===this.wm&&(this.wm=new Ws("right",i,s,n,e),this.ym.appendChild(this.wm.Kp()))}}const qs=!!_s&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!_s&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class js{constructor(t,i,s){var n;this.Bm=[],this.Om=[],this.Wm=0,this.no=0,this.Ma=0,this.zm=0,this.$m=0,this.Hm=null,this.Nm=!1,this.xv=new a,this.Cv=new a,this.Ku=new a,this.Um=null,this.qm=null,this.Ff=t,this.Ps=i,this.__=s,this.kf=document.createElement("div"),this.kf.classList.add("tv-lightweight-charts"),this.kf.style.overflow="hidden",this.kf.style.direction="ltr",this.kf.style.width="100%",this.kf.style.height="100%",(n=this.kf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.jm=document.createElement("table"),this.jm.setAttribute("cellspacing","0"),this.kf.appendChild(this.jm),this.Ym=this.Xm.bind(this),Ys(this.Ps)&&this.Gm(!0),this.ss=new Ei(this.Ju.bind(this),this.Ps,s),this.ti().dc().i(this.Km.bind(this),this),this.Zm=new Us(this,this.__),this.jm.appendChild(this.Zm.Kp());const e=i.autoSize&&this.Jm();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.Qm(r,h),this.tw(),t.appendChild(this.kf),this.iw(),this.ss.At().Lu().i(this.ss.Lh.bind(this.ss),this),this.ss.Ia().i(this.ss.Lh.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}Up(){return this.Bm}sw(){return this.Zm}m(){this.Gm(!1),0!==this.Wm&&window.cancelAnimationFrame(this.Wm),this.ss.dc().u(this),this.ss.At().Lu().u(this),this.ss.Ia().u(this),this.ss.m();for(const t of this.Bm)this.jm.removeChild(t.Kp()),t.Kv().u(this),t.Zv().u(this),t.m();this.Bm=[];for(const t of this.Om)this.nw(t);this.Om=[],l(this.Zm).m(),null!==this.kf.parentElement&&this.kf.parentElement.removeChild(this.kf),this.Ku.m(),this.xv.m(),this.Cv.m(),this.ew()}Qm(t,i,s=!1){if(this.no===i&&this.Ma===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return ns({width:i-i%2,height:s-s%2})}(ns({width:t,height:i}));this.no=n.height,this.Ma=n.width;const e=this.no+"px",r=this.Ma+"px";l(this.kf).style.height=e,l(this.kf).style.width=r,this.jm.style.height=e,this.jm.style.width=r,s?this.rw(Y.bn(),performance.now()):this.ss.Lh()}av(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Bm.length;i++)this.Bm[i].av(t.rn(i).sn);this.Ps.timeScale.visible&&this.Zm.av(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Gm(s),t.layout?.panes&&this.hw(),this.iw(),this.lw(t)}Kv(){return this.xv}Zv(){return this.Cv}dc(){return this.Ku}ow(t=!1){null!==this.Hm&&(this.rw(this.Hm,performance.now()),this.Hm=null);const i=this.aw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.aw(n,t),s}_w(t){if("left"===t&&!this.uw())return 0;if("right"===t&&!this.cw())return 0;if(0===this.Bm.length)return 0;return l("left"===t?this.Bm[0].rm():this.Bm[0].hm()).ov()}dw(){return this.Ps.autoSize&&null!==this.Um}if(){return this.kf}pw(t){this.qm=t,this.qm?this.if().style.setProperty("cursor",t):this.if().style.removeProperty("cursor")}fw(){return this.qm}mw(t){return h(this.Bm[t]).Zp()}hw(){this.Om.forEach(t=>{t.Tt()})}lw(t){(void 0!==t.autoSize||!this.Um||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.Um&&this.Jm(),!1===t.autoSize&&null!==this.Um&&this.ew(),t.autoSize||void 0===t.width&&void 0===t.height||this.Qm(t.width||this.Ma,t.height||this.no))}aw(t,i){let s=0,n=0;const e=this.Bm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Bm.length;r++){const h=this.Bm[r],o=l("left"===s?h.rm():h.hm()),a=o.Jp();if(null!==t&&o.Qp(t,n,e,i),e+=a.height,r<this.Bm.length-1){const i=this.Om[r],s=i.Jp();null!==t&&i.Qp(t,n,e),e+=s.height}}};if(this.uw()){r("left",0);s+=l(e.rm()).Jp().width}for(let e=0;e<this.Bm.length;e++){const r=this.Bm[e],h=r.Jp();if(null!==t&&r.Qp(t,s,n,i),n+=h.height,e<this.Bm.length-1){const i=this.Om[e],r=i.Jp();null!==t&&i.Qp(t,s,n),n+=r.height}}if(s+=e.Jp().width,this.cw()){r("right",s);s+=l(e.hm()).Jp().width}const h=(i,s,n)=>{l("left"===i?this.Zm.Cm():this.Zm.Pm()).Qp(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Zm.Jp();if(null!==t){let r=0;this.uw()&&(h("left",r,n),r=l(e.rm()).Jp().width),this.Zm.Qp(t,r,n,i),r+=s.width,this.cw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}ww(){let t=0,i=0,s=0;for(const n of this.Bm)this.uw()&&(i=Math.max(i,l(n.rm()).ev(),this.Ps.leftPriceScale.minimumWidth)),this.cw()&&(s=Math.max(s,l(n.hm()).ev(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Va();i=ds(i),s=ds(s);const n=this.Ma,e=this.no,r=Math.max(n-i-s,0),h=1*this.Om.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Zm.Dm(),this.Ps.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=h+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Bm.length;++t){const n=this.Bm[t];n.Ov(this.ss.qs()[t]);let e=0,h=0;h=t===this.Bm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Va()*d*f)/f,e=Math.max(h,2),p+=e,n.lv(ns({width:r,height:e})),this.uw()&&n.Qv(i,"left"),this.cw()&&n.Qv(s,"right"),n.lf()&&this.ss.fc(n.lf(),e)}this.Zm.km(ns({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Aa(r),this.zm!==i&&(this.zm=i),this.$m!==s&&(this.$m=s)}Gm(t){t?this.kf.addEventListener("wheel",this.Ym,{passive:!1}):this.kf.removeEventListener("wheel",this.Ym)}gw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Xm(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.gw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.kf.getBoundingClientRect().left;this.ti().yc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Sc(-80*s)}rw(t,i){const s=t.en();3===s&&this.bw(),3!==s&&2!==s||(this.Mw(t),this.yw(t,i),this.Zm.Tt(),this.Bm.forEach(t=>{t.zv()}),3===this.Hm?.en()&&(this.Hm.mn(t),this.bw(),this.Mw(this.Hm),this.yw(this.Hm,i),t=this.Hm,this.Hm=null)),this.av(t)}yw(t,i){for(const s of t.vn())this.wn(s,i)}Mw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Ja()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Eu();break;case 1:s.Bu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Su();break;case 5:t.Ht.Ru(i)||s.fn(t.Ht.Fu(i))}}Ju(t){null!==this.Hm?this.Hm.mn(t):this.Hm=t,this.Nm||(this.Nm=!0,this.Wm=window.requestAnimationFrame(t=>{if(this.Nm=!1,this.Wm=0,null!==this.Hm){const i=this.Hm;this.Hm=null,this.rw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Ru(t)){this.ti().un(s.Ht);break}}}))}bw(){this.tw()}nw(t){this.jm.removeChild(t.Kp()),t.m()}tw(){const t=this.ss.qs(),i=t.length,s=this.Bm.length;for(let t=i;t<s;t++){const t=h(this.Bm.pop());this.jm.removeChild(t.Kp()),t.Kv().u(this),t.Zv().u(this),t.m();const i=this.Om.pop();void 0!==i&&this.nw(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Kv().i(this.Sw.bind(this,i),this),i.Zv().i(this.xw.bind(this,i),this),this.Bm.push(i),n>0){const t=new Ms(this,n-1,n);this.Om.push(t),this.jm.insertBefore(t.Kp(),this.Zm.Kp())}this.jm.insertBefore(i.Kp(),this.Zm.Kp())}for(let s=0;s<i;s++){const i=t[s],n=this.Bm[s];n.lf()!==i?n.Ov(i):n.Bv()}this.iw(),this.ww()}Cw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().$r(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.e_ instanceof Ut?h.e_:void 0,o=null!==h&&void 0!==h.r_?h.r_.Gn:void 0,a=this.Pw(n);return{Tw:r,Re:t??void 0,kw:i??void 0,Dw:-1!==a?a:void 0,Rw:l,Fw:e,Iw:o,Vw:s??void 0}}Pw(t){let i=-1;if(t)i=this.Bm.indexOf(t);else{const t=this.ti().cc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Sw(t,i,s,n){this.xv.p(()=>this.Cw(i,s,n,t))}xw(t,i,s,n){this.Cv.p(()=>this.Cw(i,s,n,t))}Km(t,i,s){this.pw(this.ti().oc()?.l_??null),this.Ku.p(()=>this.Cw(t,i,s))}iw(){const t=this.Ps.timeScale.visible?"":"none";this.Zm.Kp().style.display=t}uw(){return this.Bm[0].lf().Ha().W().visible}cw(){return this.Bm[0].lf().Na().W().visible}Jm(){return"ResizeObserver"in window&&(this.Um=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.Qm(i.contentRect.width,i.contentRect.height)}),this.Um.observe(this.Ff,{box:"border-box"}),!0)}ew(){null!==this.Um&&this.Um.disconnect(),this.Um=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function 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],Tw: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],Tw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Tw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function Qs(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Tw: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],Tw: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),o=Math.min(...r),a=r[r.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,Tw:n,ne:d,R:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Lw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Xs(t)}(n,h)?en({gt:i,Re:s,Tw:e},n):en(t(i,s,n,e,r),n)}function hn(t){return{Candlestick:rn(tn),Bar:rn(Qs),Area:rn(Zs),Baseline:rn(Js),Histogram:rn(Ks),Line:rn(Ks),Custom:rn(sn)}[t]}function ln(t){return{Re:0,Aw:new Map,Nh:t}}function on(t,i){if(void 0!==t&&0!==t.length)return{Ew:i.key(t[0].gt),Bw:i.key(t[t.length-1].gt)}}function an(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Tw)}),h(i)}class _n{constructor(t){this.Ow=new Map,this.Ww=new Map,this.zw=new Map,this.$w=[],this.__=t}m(){this.Ow.clear(),this.Ww.clear(),this.zw.clear(),this.$w=[]}Hw(t,i){let s=0!==this.Ow.size,n=!1;const e=this.Ww.get(t);if(void 0!==e)if(1===this.Ww.size)s=!1,n=!0,this.Ow.clear();else for(const i of this.$w)i.pointData.Aw.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.__.createConverterToInternalObj(i),h=hn(t.Rr()),l=t.dl(),o=t.fl();r=i.map((i,r)=>{const a=e(i.time),_=this.__.key(a);let u=this.Ow.get(_);void 0===u&&(u=ln(a),this.Ow.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Aw.set(t,c),c})}s&&this.Nw(),this.Uw(t,r);let h=-1;if(n){const t=[];this.Ow.forEach(i=>{t.push({timeWeight:0,time:i.Nh,pointData:i,originalTime:an(i.Aw)})}),t.sort((t,i)=>this.__.key(t.time)-this.__.key(i.time)),h=this.qw(t)}return this.jw(t,h,function(t,i,s){const n=on(t,s),e=on(i,s);if(void 0!==n&&void 0!==e)return{Yw:!1,Bh:n.Bw>=e.Bw&&n.Ew>=e.Ew}}(this.Ww.get(t),e,this.__))}Ec(t){return this.Hw(t,[])}Xw(t,i,s){const n=i;!function(t){void 0===t.Tw&&(t.Tw=t.time)}(n),this.__.preprocessData(i);const e=this.__.createConverterToInternalObj([i])(i.time),r=this.zw.get(t);if(!s&&void 0!==r&&this.__.key(e)<this.__.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ow.get(this.__.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=ln(e),this.Ow.set(this.__.key(e),h));const o=hn(t.Rr()),a=t.dl(),_=t.fl(),u=o(e,h.Re,i,n.Tw,a,_);h.Aw.set(t,u),s?this.Gw(t,u,h.Re):this.Kw(t,u);const c={Bh:nn(u),Yw:s};if(!l)return this.jw(t,-1,c);const d={timeWeight:0,time:h.Nh,pointData:h,originalTime:an(h.Aw)},p=yt(this.$w,this.__.key(d.time),(t,i)=>this.__.key(t.time)<i);this.$w.splice(p,0,d);for(let t=p;t<this.$w.length;++t)un(this.$w[t].pointData,t);return this.__.fillWeightsForPoints(this.$w,p),this.jw(t,p,c)}Zw(t,i){const s=this.Ww.get(t);if(void 0===s||i<=0)return[[],this.Jw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.zw.delete(t):this.zw.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ow.get(this.__.key(i.gt));if(s&&(s.Aw.delete(t),0===s.Aw.size)){this.Ow.delete(this.__.key(s.Nh)),this.$w.splice(s.Re,1);for(let t=s.Re;t<this.$w.length;++t)un(this.$w[t].pointData,t)}}return[n,this.jw(t,this.$w.length-1,{Yw:!1,Bh:!1})]}Kw(t,i){let s=this.Ww.get(t);void 0===s&&(s=[],this.Ww.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.__.key(i.gt)>this.__.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.zw.set(t,i.gt)}Gw(t,i,s){const n=this.Ww.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);nn(i)?n[e]=i:n.splice(e,1)}Uw(t,i){0!==i.length?(this.Ww.set(t,i.filter(nn)),this.zw.set(t,i[i.length-1].gt)):(this.Ww.delete(t),this.zw.delete(t))}Nw(){for(const t of this.$w)0===t.pointData.Aw.size&&this.Ow.delete(this.__.key(t.time))}qw(t){let i=-1;for(let s=0;s<this.$w.length&&s<t.length;++s){const n=this.$w[s],e=t[s];if(this.__.key(n.time)!==this.__.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.$w.length!==t.length&&(i=Math.min(this.$w.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.__.fillWeightsForPoints(t,i),this.$w=t,i}Qw(){if(0===this.Ww.size)return null;let t=0;return this.Ww.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}jw(t,i,s){const n=this.Jw();if(-1!==i)this.Ww.forEach((i,e)=>{n.Wa.set(e,{ne:i,tg:e===t?s:void 0})}),this.Ww.has(t)||n.Wa.set(t,{ne:[],tg:s}),n.At.ig=this.$w,n.At.sg=i;else{const i=this.Ww.get(t);n.Wa.set(t,{ne:i||[],tg:s})}return n}Jw(){return{Wa:new Map,At:{uu:this.Qw()}}}}function un(t,i){t.Re=i,t.Aw.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.Uh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);if(!s)return{from:r,to:h};let l=r,o=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(o=h+1),{from:l,to:o}}class fn{constructor(t,i,s){this.ng=!0,this.eg=!0,this.rg=!0,this.hg=[],this.lg=null,this.Qn=t,this.te=i,this.og=s}Tt(t){this.ng=!0,"data"===t&&(this.eg=!0),"options"===t&&(this.rg=!0)}Dt(){return this.Qn.It()?(this.ag(),null===this.lg?null:this._g):null}ug(){this.hg=this.hg.map(t=>({...t,...this.Qn.Rh().Fr(t.gt)}))}cg(){this.lg=null}ag(){this.eg&&(this.dg(),this.eg=!1),this.rg&&(this.ug(),this.rg=!1),this.ng&&(this.pg(),this.ng=!1)}pg(){const t=this.Qn.$t(),i=this.te.At();if(this.cg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Br())return;const n=this.Qn.Bt();null!==n&&(this.lg=pn(this.hg,s,this.og),this.fg(t,i,n.Ht),this.vg())}}class vn{constructor(t,i){this.mg=t,this.Yi=i}et(t,i,s){this.mg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.nh=s,this._g=new vn(this.nh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}pl(t){return this.nh.priceValueBuilder(t)}vl(t){return this.nh.isWhitespace(t)}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re),wg:i.ne}))}fg(t,i){i.cu(this.hg,m(this.lg))}vg(){this.nh.update({bars:this.hg.map(wn),barSpacing:this.te.At().wu(),visibleRange:this.lg},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.wg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=o(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),i}function yn(t){const i=Mn(t);return void 0!==t.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.Tw};return void 0!==t.Lw&&(i.customValues=t.Lw),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.Tw;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.Hp=t,this.gg=i,this.bg=s??0}applyOptions(t){this.Hp.ti()._c(this.gg,t,this.bg)}options(){return this.Yi().W()}width(){return j(this.gg)?this.Hp._w(this.gg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().No(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().Ql()){const n=this.Yi().va(),e=Bi(n);s=oi(s,this.Yi().so()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Hp.ti().uc(this.gg,this.bg)).$t}}class Bn{constructor(t,i,s,n){this.Hp=t,this.Pt=s,this.Mg=i,this.yg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Hp.ti(),s=i.Uc(this.Pt);i.mc(s,t)}getStretchFactor(){return this.Pt.Va()}setStretchFactor(t){this.Pt.La(t),this.Hp.ti().Lh()}paneIndex(){return this.Hp.ti().Uc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Hp.Up().length,"Invalid pane index"),this.Hp.ti().gc(i,t))}getSeries(){return this.Pt.Wa().map(t=>this.Mg(t))??[]}getHTMLElement(){const t=this.Hp.Up();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Kp():null}attachPrimitive(t){this.Pt.ul(t),t.attached&&t.attached({chart:this.yg,requestUpdate:()=>this.Pt.ti().Lh()})}detachPrimitive(t){this.Pt.cl(t)}priceScale(t){if(null===this.Pt.Fa(t))throw new Error(`Cannot find price scale with id: ${t}`);return new En(this.Hp,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Ba(t)}preserveEmptyPane(){return this.Pt.Oa()}addCustomSeries(t,i={},s=0){return this.yg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.yg.addSeries(t,i,this.paneIndex())}}const On={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Wn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Sg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.xg=new a,this.Qn=t,this.Cg=i,this.Pg=s,this.__=e,this.yg=n,this.Tg=r}m(){this.xg.m()}priceFormatter(){return this.Qn.rl()}priceToCoordinate(t){const i=this.Qn.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)).T_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.$r(i.Uh(),1),e=s.$r(i.yi(),-1),r=l(s.Or()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(o.from=n.Tw,o.to=e.Tw),o}setData(t){this.__,this.Qn.Rr(),this.Cg.kg(this.Qn,t),this.Dg("full")}update(t,i=!1){this.Qn.Rr(),this.Cg.Rg(this.Qn,t,i),this.Dg("update")}pop(t=1){const i=this.Cg.Fg(this.Qn,t);0!==i.length&&this.Dg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().$r(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Ks().Nr().map(i=>t(i))}subscribeDataChanged(t){this.xg.i(t)}unsubscribeDataChanged(t){this.xg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Pg.priceScale(this.Qn.$t().wl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.Wh(i);return new Wn(s)}removePriceLine(t){this.Qn.zh(t.Sg())}priceLines(){return this.Qn.$h().map(t=>new Wn(t))}seriesType(){return this.Qn.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.ul(t),t.attached&&t.attached({chart:this.yg,series:this,requestUpdate:()=>this.Qn.ti().Lh(),horzScaleBehavior:this.__})}detachPrimitive(t){this.Qn.cl(t),t.detached&&t.detached(),this.Qn.ti().Lh()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Tg(i)}moveToPane(t){this.Qn.ti().zc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.Wa().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.t_(this.Qn,t)}Dg(t){this.xg.v()&&this.xg.p(t)}}class $n{constructor(t,i,s){this.Ig=new a,this.B_=new a,this.bm=new a,this.ss=t,this.dh=t.At(),this.Zm=i,this.dh.Iu().i(this.Vg.bind(this)),this.dh.Vu().i(this.Lg.bind(this)),this.Zm.Tm().i(this.Ag.bind(this)),this.__=s}m(){this.dh.Iu().u(this),this.dh.Vu().u(this),this.Zm.Tm().u(this),this.Ig.m(),this.B_.m(),this.bm.m()}scrollPosition(){return this.dh.bu()}scrollToPosition(t,i){i?this.dh.Du(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.dh.ku()}getVisibleRange(){const t=this.dh.eu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.__.convertHorzItemToInternal(t.from),to:this.__.convertHorzItemToInternal(t.to)},s=this.dh.ou(i);this.ss.Oc(s)}getVisibleLogicalRange(){const t=this.dh.nu();return null===t?null:{from:t.Uh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Oc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Eu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.dh.Gi()?null:this.dh.du(t)}timeToIndex(t,i){const s=this.__.convertHorzItemToInternal(t);return this.dh.tu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.dh.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.du(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Zm.Zp().width}height(){return this.Zm.Zp().height}subscribeVisibleTimeRangeChange(t){this.Ig.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Ig._(t)}subscribeVisibleLogicalRangeChange(t){this.B_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.B_._(t)}subscribeSizeChange(t){this.bm.i(t)}unsubscribeSizeChange(t){this.bm._(t)}applyOptions(t){this.dh.lr(t)}options(){return{...f(this.dh.W()),barSpacing:this.dh.wu()}}Vg(){this.Ig.v()&&this.Ig.p(this.getVisibleRange())}Lg(){this.B_.v()&&this.B_.p(this.getVisibleLogicalRange())}Ag(t){this.bm.p(t.width,t.height)}}function Hn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Nn{constructor(t,i,s){this.Eg=new Map,this.Bg=new Map,this.Og=new a,this.Wg=new a,this.zg=new a,this.ju=new WeakMap,this.$g=new _n(i);const n=void 0===s?f(An()):_(f(An()),Hn(s));this.Hg=i,this.Hp=new js(t,n,i),this.Hp.Kv().i(t=>{this.Og.v()&&this.Og.p(this.Ng(t()))},this),this.Hp.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ng(t()))},this),this.Hp.dc().i(t=>{this.zg.v()&&this.zg.p(this.Ng(t()))},this);const e=this.Hp.ti();this.Ug=new $n(e,this.Hp.sw(),this.Hg)}remove(){this.Hp.Kv().u(this),this.Hp.Zv().u(this),this.Hp.dc().u(this),this.Ug.m(),this.Hp.m(),this.Eg.clear(),this.Bg.clear(),this.Og.m(),this.Wg.m(),this.zg.m(),this.$g.m()}resize(t,i,s){this.autoSizeActive()||this.Hp.Qm(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},qg:bn,jg:t}))(o(t));return this.Yg(n,i,s)}addSeries(t,i={},s=0){return this.Yg(t,i,s)}removeSeries(t){const i=h(this.Eg.get(t)),s=this.$g.Ec(i);this.Hp.ti().Ec(i),this.Xg(s),this.Eg.delete(t),this.Bg.delete(i)}kg(t,i){this.Xg(this.$g.Hw(t,i))}Rg(t,i,s){this.Xg(this.$g.Xw(t,i,s))}Fg(t,i){const[s,n]=this.$g.Zw(t,i);return 0!==s.length&&this.Xg(n),s}subscribeClick(t){this.Og.i(t)}unsubscribeClick(t){this.Og._(t)}subscribeCrosshairMove(t){this.zg.i(t)}unsubscribeCrosshairMove(t){this.zg._(t)}subscribeDblClick(t){this.Wg.i(t)}unsubscribeDblClick(t){this.Wg._(t)}priceScale(t,i=0){return new En(this.Hp,t,i)}timeScale(){return this.Ug}applyOptions(t){this.Hp.lr(Hn(t))}options(){return this.Hp.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Hp.ti().W().crosshair.mode,this.Hp.lr({crosshair:{mode:2}})),n=this.Hp.ow(t)}finally{i||void 0===s||this.Hp.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Hp.ti().qc();return i.Ba(t),this.Gg(i)}removePane(t){this.Hp.ti().vc(t)}swapPanes(t,i){this.Hp.ti().wc(t,i)}autoSizeActive(){return this.Hp.dw()}chartElement(){return this.Hp.if()}panes(){return this.Hp.ti().qs().map(t=>this.Gg(t))}paneSize(t=0){const i=this.Hp.mw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Eg.get(s);if(void 0===n)return;const e=this.Hp.ti().Nn(n);null!==e&&this.Hp.ti().Rc(t,i,e)}clearCrosshairPosition(){this.Hp.ti().Fc(!0)}horzBehaviour(){return this.Hg}Yg(i,s={},n=0){r(void 0!==i.qg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=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.qg,l=new Ut(this.Hp.ti(),i.type,e,h,i.jg);this.Hp.ti().Lc(l,n);const o=new zn(l,this,this,this,this.Hg,t=>this.Gg(t));return this.Eg.set(o,l),this.Bg.set(l,o),o}Xg(t){const i=this.Hp.ti();i.Ic(t.At.uu,t.At.ig,t.At.sg),t.Wa.forEach((t,i)=>i.lt(t.ne,t.tg)),i.At().G_(),i.mu()}Kg(t){return h(this.Bg.get(t))}Ng(t){const i=new Map;t.Fw.forEach((t,s)=>{const n=s.Rr(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.fl();r(!t||!1===t(e))}i.set(this.Kg(s),e)});const s=void 0!==t.Rw&&this.Bg.has(t.Rw)?this.Kg(t.Rw):void 0;return{time:t.Tw,logical:t.Re,point:t.kw,paneIndex:t.Dw,hoveredSeries:s,hoveredObjectId:t.Iw,seriesData:i,sourceEvent:t.Vw}}Gg(t){let i=this.ju.get(t);return i||(i=new Bn(this.Hp,t=>this.Kg(t),t,this),this.ju.set(t,i)),i}}function Un(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function qn(t,i,s){const n=Un(t),e=new Nn(n,i,s);return i.setOptions(e.options()),e}function jn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Gl:r,Zg:n.time-h.time}}function Yn(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=jn(t,i);if(null===h)return null;const l=r-h.Gl;return Math.round(h.gt+l*h.Zg)}function Xn(t,i,s){if(null==s)return null;const n=t.timeScale(),e=n.timeToCoordinate(s);if(null!==e)return e;if("number"!=typeof s)return null;const r=jn(t,i);if(null===r)return null;const h=r.Gl+(s-r.gt)/r.Zg,l=n.logicalToCoordinate(h);return null===l?null:l}class Gn extends fn{constructor(t,i){super(t,i,!0)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.jo(this.hg,s,m(this.lg))}Jg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>{const s=i.Ht[3];return this.Qg(i.Re,s,t)})}}function Kn(t,i,s,n,e,r,h){if(0===i.length||n.from>=i.length||n.to<=0)return;const{context:l,horizontalPixelRatio:o,verticalPixelRatio:a}=t,_=i[n.from];let u=r(t,_),c=_;if(n.to-n.from<2){const i=e/2;l.beginPath();const s={ut:_.ut-i,ct:_.ct},n={ut:_.ut+i,ct:_.ct};l.moveTo(s.ut*o,s.ct*a),l.lineTo(n.ut*o,n.ct*a),h(t,u,s,n)}else{const e=(i,s)=>{h(t,u,c,s),l.beginPath(),u=i,c=s};let d=c;l.beginPath(),l.moveTo(_.ut*o,_.ct*a);for(let h=n.from+1;h<n.to;++h){d=i[h];const n=r(t,d);switch(s){case 0:l.lineTo(d.ut*o,d.ct*a);break;case 1:l.lineTo(d.ut*o,i[h-1].ct*a),n!==u&&(e(n,d),l.lineTo(d.ut*o,i[h-1].ct*a)),l.lineTo(d.ut*o,d.ct*a);break;case 2:{const[t,s]=te(i,h-1,h);l.bezierCurveTo(t.ut*o,t.ct*a,s.ut*o,s.ct*a,d.ut*o,d.ct*a);break}}1!==s&&n!==u&&(e(n,d),l.moveTo(d.ut*o,d.ct*a))}(c!==d||c===d&&1===s)&&h(t,u,c,d)}}const Zn=6;function Jn(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function Qn(t,i){return{ut:t.ut/i,ct:t.ct/i}}function te(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=Qn(Jn(t[s],t[n]),Zn),{ut:r.ut+h.ut,ct:r.ct+h.ct}),Jn(t[s],Qn(Jn(t[e],t[i]),Zn))]}function ie(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class se extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,tb:e,ib:r,dt:h,Kt:l,sb:o}=this.ht;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=h*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.nb.bind(this);void 0!==r&&Kn(t,i,r,s,e,_,ie),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let o=null;const a=Math.max(1,Math.floor(r))%2/2,_=s*h+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(l.beginPath(),null!==o&&l.fill(),l.fillStyle=i,o=i);const s=Math.round(n.ut*r)+a,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class ne extends se{nb(t,i){return i.wt}}class ee extends Gn{constructor(){super(...arguments),this._g=new ne}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t=this.Qn.W(),i={_t:this.hg,Kt:t.lineStyle,ib:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.lg,tb:this.te.At().wu()};this._g.lt(i)}}const re={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ee(t,i)};function he(t,i){return t.weight>i.weight?t:i}function le(t){return t}class oe{constructor(){this.eb=new a,this.rb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.eb.p(this.hb)),this.hb=0}lb(){return this.eb}m(){this.eb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.rb(),t=>(t>this.hb&&(this.hb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.ob(t)}formatTickmark(t){return this.ob(t.time)}maxTickMarkWeight(t){return t.reduce(he,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(le(t[n].time));this.hb=t[t.length-1].time,this.rb()}ob(t){if(this.Ps.localization?.timeFormatter)return this.Ps.localization.timeFormatter(t);if(t<12)return`${t}M`;const i=Math.floor(t/12),s=t%12;return 0===s?`${i}Y`:`${i}Y${s}M`}}const ae={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},_e={lastValueVisible:!1,priceLineVisible:!1};class ue extends Nn{constructor(t,i){const s=_(ae,i||{}),n=new oe;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={..._e,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(re);let s;function n(n){const e=function(t,i){return{ae:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),ab:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ab:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ab:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.lb().i(n)}}function ce(t,i){return t.weight>i.weight?t:i}class de{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(ce,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 pe(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 fe extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,tb:e,dt:r,Kt:h,ib:l}=this.ht,o=this.ht._b??(this.ht.ub?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,n(a,h),a.lineWidth=1,Kn(t,i,l,s,e,this.cb.bind(this),pe.bind(null,o))}}class ve{pb(t,i){const s=this.fb,{mb:n,wb:e,gb:r,bb:h,_b:l,Mb:o,yb:a}=i;if(void 0===this.Sb||void 0===s||s.mb!==n||s.wb!==e||s.gb!==r||s.bb!==h||s._b!==l||s.Mb!==o||s.yb!==a){const{verticalPixelRatio:s}=t,_=l||o>0?s:1,u=o*_,c=a===t.bitmapSize.height?a:a*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Sb=p,this.fb=i}return this.Sb}}class me extends fe{constructor(){super(...arguments),this.xb=new ve}cb(t,i){const s=this.ht;return this.xb.pb(t,{mb:i.yr,wb:i.Sr,gb:i.Cr,bb:i.Pr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class we extends se{constructor(){super(...arguments),this.Cb=new ve}nb(t,i){const s=this.ht;return this.Cb.pb(t,{mb:i.br,wb:i.br,gb:i.Mr,bb:i.Mr,_b:s._b,Mb:s.Mb??0,yb:s.yb??t.bitmapSize.height})}}class ge extends Gn{constructor(t,i){super(t,i),this._g=new x,this.Pb=new me,this.Tb=new we,this._g.nt([this.Pb,this.Tb])}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){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().wu();if(null===this.lg||0===this.hg.length)return;let e,r;if(i.relativeGradient){e=this.hg[this.lg.from].ct,r=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const i=this.hg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Pb.lt({_t:this.hg,dt:i.lineWidth,Kt:i.lineStyle,ib:i.lineType,_b:s,Mb:e,yb:r,ub:!1,ot:this.lg,tb:n}),this.Tb.lt({_t:this.hg,dt:i.lineWidth,Kt:i.lineStyle,ib:i.lineVisible?i.lineType:void 0,sb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,_b:s,Mb:e,yb:r,ot:this.lg,tb:n})}}const be={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ge(t,i)};class Me extends fe{constructor(){super(...arguments),this.xb=new ve}cb(t,i){return this.xb.pb(t,{mb:i.wr,wb:"",gb:"",bb:i.gr,Mb:this.ht?.Mb??0,yb:t.bitmapSize.height})}}class ye extends Gn{constructor(t,i){super(t,i),this._g=new x,this.kb=new Me,this.Db=new ne,this._g.nt([this.kb,this.Db])}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t=this.Qn.W();if(null===this.lg||0===this.hg.length)return;let i;if(t.relativeGradient){i=this.hg[this.lg.from].ct;for(let t=this.lg.from;t<this.lg.to;t++){const s=this.hg[t];s.ct<i&&(i=s.ct)}}this.kb.lt({ib:t.lineType,_t:this.hg,Kt:t.lineStyle,dt:t.lineWidth,_b:null,Mb:i,ub:t.invertFilledArea,ot:this.lg,tb:this.te.At().wu()}),this.Db.lt({ib:t.lineVisible?t.lineType:void 0,_t:this.hg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.lg,tb:this.te.At().wu(),sb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const Se={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},qg:(t,i)=>new ye(t,i)};class xe extends C{constructor(){super(...arguments),this.Yt=null,this.Rb=0,this.Fb=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.Rb=this.Ib(i),this.Rb>=2){Math.max(1,Math.floor(i))%2!=this.Rb%2&&this.Rb--}this.Fb=this.Yt.Vb?Math.min(this.Rb,Math.floor(i)):this.Rb;let n=null;const e=this.Fb<=this.Rb&&this.Yt.wu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Fb),o=Math.round(h.ut*i),a=o-l,_=this.Fb,u=a+_-1,c=Math.min(h.Ko,h.Zo),d=Math.max(h.Ko,h.Zo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Fb);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Rb);if(e){if(this.Yt.Lb){const i=o-m;let n=Math.max(p,Math.round(h.Go*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Jo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Ib(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).wu,t)))}}class Ce extends fn{constructor(t,i){super(t,i,!1)}fg(t,i,s){i.cu(this.hg,m(this.lg)),t.Xo(this.hg,s,m(this.lg))}Ab(t,i,s){return{gt:t,jh:i.Ht[0],Yh:i.Ht[1],Xh:i.Ht[2],Gh:i.Ht[3],ut:NaN,Go:NaN,Ko:NaN,Zo:NaN,Jo:NaN}}dg(){const t=this.Qn.Rh();this.hg=this.Qn.Ks().Nr().map(i=>this.Qg(i.Re,i,t))}}class Pe extends Ce{constructor(){super(...arguments),this._g=new xe}Qg(t,i,s){return{...this.Ab(t,i,s),...s.Fr(t)}}vg(){const t=this.Qn.W();this._g.lt({Ks:this.hg,wu:this.te.At().wu(),Lb:t.openVisible,Vb:t.thinBars,ot:this.lg})}}const Te={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},qg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Rb=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.Rb=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.wu,i),this.Rb>=2){Math.floor(i)%2!=this.Rb%2&&this.Rb--}const s=this.Yt.Ks;this.Yt.Eb&&this.Bb(t,s,this.Yt.ot),this.Yt.Mi&&this.cv(t,s,this.Yt.ot);const n=this.Ob(i);(!this.Yt.Mi||this.Rb>2*n)&&this.Wb(t,s,this.Yt.ot)}Bb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.wu*e));l=Math.max(Math.floor(e),Math.min(l,this.Rb));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Go,s.Jo)*r),u=Math.round(Math.max(s.Go,s.Jo)*r),c=Math.round(s.Ko*r),d=Math.round(s.Zo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}Ob(t){let i=Math.floor(1*t);this.Rb<=2*i&&(i=Math.floor(.5*(this.Rb-1)));const s=Math.max(Math.floor(t),i);return this.Rb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}cv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.pr!==h&&(n.fillStyle=s.pr,h=s.pr);let a=Math.round(s.ut*e)-Math.floor(.5*this.Rb);const _=a+this.Rb-1,u=Math.round(Math.min(s.Go,s.Jo)*r),c=Math.round(Math.max(s.Go,s.Jo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.wu*e>2*l)I(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Ob(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Go,s.Jo)*r),a=Math.round(Math.max(s.Go,s.Jo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Rb),u=_+this.Rb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class De extends Ce{constructor(){super(...arguments),this._g=new ke}Qg(t,i,s){return{...this.Ab(t,i,s),...s.Fr(t)}}vg(){const t=this.Qn.W();this._g.lt({Ks:this.hg,wu:this.te.At().wu(),Eb:t.wickVisible,Mi:t.borderVisible,ot:this.lg})}}const Re={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},qg:(t,i)=>new De(t,i)};class Fe extends C{constructor(){super(...arguments),this.Yt=null,this.zb=[]}lt(t){this.Yt=t,this.zb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.zb.length||this.$b(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Hb*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.zb[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.Uh,a,l.yi-l.Uh+1,_-a)}}$b(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.zb=[]);const i=Math.ceil(this.Yt.wu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.wu*t)-i;this.zb=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.zb[i-this.Yt.ot.from]={Uh:r,yi:h,Nb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.zb[t-this.Yt.ot.from],n=this.zb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.Uh-n.yi!==i+1&&(n.Nb>n.ee?n.yi=s.Uh-i-1:s.Uh=n.yi+i+1))}let n=Math.ceil(this.Yt.wu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi<i.Uh&&(i.yi=i.Uh);const s=i.yi-i.Uh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.zb[t-this.Yt.ot.from];i.yi-i.Uh+1>n&&(i.Nb>i.ee?i.yi-=1:i.Uh+=1)}}}class Ie extends Gn{constructor(){super(...arguments),this._g=new Fe}Qg(t,i,s){return{...this.Jg(t,i),...s.Fr(t)}}vg(){const t={_t:this.hg,wu:this.te.At().wu(),ot:this.lg,Hb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this._g.lt(t)}}const Ve={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},qg:(t,i)=>new Ie(t,i)};class Le{constructor(t,i){this.Pt=t,this.Ub=i,this.qb()}detach(){this.Pt.detachPrimitive(this.Ub)}getPane(){return this.Pt}applyOptions(t){this.Ub.lr?.(t)}qb(){this.Pt.attachPrimitive(this.Ub)}}const Ae={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},Ee={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class Be{constructor(t){this.jb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Yb(i,t.text);e>s.width?t.Cu=s.width/e:t.Cu=1,n+=t.lineHeight*t.Cu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Cu,t.Cu),i.fillText(t.text,0,t.Xb),i.restore(),e+=t.lineHeight*t.Cu}})}Yb(t,i){const s=this.Gb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Gb(t){let i=this.jb.get(t);return void 0===i&&(i=new Map,this.jb.set(t,i)),i}}class Oe{constructor(t){this.Ps=ze(t)}Tt(t){this.Ps=ze(t)}renderer(){return new Be(this.Ps)}}function We(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Xb:0,Cu:0}}function ze(t){return{...t,lines:t.lines.map(We)}}function $e(t){return{...Ee,...t}}function He(t){return{...Ae,...t,lines:t.lines?.map($e)??[]}}class Ne{constructor(t){this.Ps=He(t),this.Kb=[new Oe(this.Ps)]}updateAllViews(){this.Kb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Kb}attached({requestUpdate:t}){this.Zb=t}detached(){this.Zb=void 0}lr(t){this.Ps=He({...this.Ps,...t}),this.Zb&&this.Zb()}}const Ue={alpha:1,padding:0};class qe{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Jb(this.Yt,t.mediaSize);s&&this.Yt.Qb&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.Qb,s.ut,s.ct,s.ts,s.qt))})}Jb(t,i){const{maxHeight:s,maxWidth:n,tM:e,iM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class je{constructor(t){this.sM=null,this.nM=0,this.eM=0,this.Ps=t,this.M=Ye(this.Ps,this.sM,this.nM,this.eM)}rM(t){void 0!==t.hM&&(this.nM=t.hM),void 0!==t.lM&&(this.eM=t.lM),void 0!==t.oM&&(this.sM=t.oM),this.Tt()}aM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Ye(this.Ps,this.sM,this.nM,this.eM)}renderer(){return new qe(this.M)}}function Ye(t,i,s,n){return{...t,Qb:i,iM:s,tM:n}}function Xe(t){return{...Ue,...t}}class Ge{constructor(t,i){this._M=null,this.uM=t,this.Ps=Xe(i),this.Kb=[new je(this.Ps)]}updateAllViews(){this.Kb.forEach(t=>t.Tt())}paneViews(){return this.Kb}attached(t){const{requestUpdate:i}=t;this.cM=i,this._M=new Image,this._M.onload=()=>{const t=this._M?.naturalHeight??1,i=this._M?.naturalWidth??1;this.Kb.forEach(s=>s.rM({lM:t,hM:i,oM:this._M})),this.cM&&this.cM()},this._M.src=this.uM}detached(){this.cM=void 0,this._M=null}lr(t){this.Ps=Xe({...this.Ps,...t}),this.dM(),this.Zb&&this.Zb()}Zb(){this.cM&&this.cM()}dM(){this.Kb.forEach(t=>t.aM(this.Ps))}}class Ke{constructor(t,i){this.Qn=t,this.ah=i,this.qb()}detach(){this.Qn.detachPrimitive(this.ah)}getSeries(){return this.Qn}applyOptions(t){this.ah&&this.ah.lr&&this.ah.lr(t)}qb(){this.Qn.attachPrimitive(this.ah)}}const Ze={autoScale:!0,zOrder:"normal"};function Je(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function Qe(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return Je(i,1);case"circle":return Je(i,.8);case"square":return Je(i,.7)}}function tr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(Je(t,1))}function ir(t){return Math.max(Je(t,.1),3)}function sr(t,i,s){return i?t:s?Math.ceil(t/2):0}function nr(t,i,s,n){const e=(Qe("arrowUp",n)-1)/2*s.pM,r=(Kt(n/2)-1)/2*s.pM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function er(t,i,s,n,e,r){const h=(Qe("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 rr(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,o=s+l*n,a=o-l*h,_=r?-e:e;t.lineTo(i+_,s),t.lineTo(i+(r?-h:h),a),t.quadraticCurveTo(i,o,i+(r?h:-h),a),t.lineTo(i-_,s)}function hr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class lr{constructor(){this.Yt=null,this.Wn=new it,this.fM=new it,this.$=-1,this.H="",this.Hf="",this.vM="",this.mM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Hf=g(t,i),this.vM=g(t,i,"600"),this.Wn.Vn(),this.fM.Vn()),this.mM=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&&ar(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.mM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.mM&&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.wM;if(t.font=r?this.vM:this.Hf,void 0!==e.hi){const i=r?this.fM:this.Wn;e.hi.ts=i.Ii(t,e.hi.gM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.wM){const t=void 0!==e.hi?e.hi.ts:0;e.wM.ts=Math.max(t+2*e.wM.bM,e.wM.qt),e.wM.Uh=e.ut-e.wM.ts/2}or(e,t,i,s)}}}}function or(t,i,s,n){void 0===t.wM?(i.fillStyle=t.R,void 0!==t.hi&&hr(i,t.hi.gM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Br)return;switch(t.MM){case"arrowDown":return void nr(!1,i,s,t.Br);case"arrowUp":return void nr(!0,i,s,t.Br);case"circle":return void function(t,i,s){const n=(Qe("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.pM,0,2*Math.PI,!1),t.fill()}(i,s,t.Br);case"square":return void function(t,i,s){const n=Qe("square",s),e=(n-1)*i.pM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.pM,n*i.pM)}(i,s,t.Br);case"tag":return}t.MM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,pM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Br)return;(function(t,i){const s=i.yM,n=i.SM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.xM-i.qt/2)*n),l=Math.round((i.xM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.CM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.PM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.PM&&rr(t,o,h,_,u,!0),t.lineTo(r-a,h),t.arcTo(r,h,r,h+a,a),t.lineTo(r,l-a),t.arcTo(r,l,r-a,l,a),"down"===i.PM&&rr(t,o,l,_,u,!1),t.lineTo(e+a,l),t.arcTo(e,l,e,l-a,a),t.lineTo(e,h+a),t.arcTo(e,h,e+a,h,a)):L(t,e,h,r-e,l-h,[a,a,a,a]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,xM:t.ct,ts:i.ts,qt:i.qt,CM:i.CM,PM:i.PM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,yM:n,SM:e}),void 0!==t.hi&&(s.fillStyle=t.TM??"#FFFFFF",hr(s,t.hi.gM,t.hi.ut,t.hi.ct,n,e))}(t,t.wM,i,s,n)}function ar(t,i,s){return void 0!==t.wM?0!==t.Br&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.PM?i-r-s.CM:i-r,l="down"===s.PM?i+r+s.CM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.wM,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.Br)return!1;switch(t.MM){case"arrowDown":return er(!0,t.ut,t.ct,t.Br,i,s);case"arrowUp":return er(!1,t.ut,t.ct,t.Br,i,s);case"circle":return function(t,i,s,n,e){const r=2+Qe("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Br,i,s);case"square":return function(t,i,s,n,e){const r=Qe("square",s),h=(r-1)/2,l=t-h,o=i-h;return n>=l&&n<=l+r&&e>=o&&e<=o+r}(t.ut,t.ct,t.Br,i,s);case"tag":return!1}}(t,i,s)}function _r(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function ur(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(_r(i.position)&&void 0!==i.price)return i.price;if("value"in(n=t)&&"number"==typeof n.value)return t.value;var n;if(function(t){return"open"in t&&"high"in t&&"low"in t&&"close"in t}(t)){if("inBar"===i.position)return t.close;if("aboveBar"===i.position)return s?t.low:t.high;if("belowBar"===i.position)return s?t.high:t.low}}(s,i,a);if(void 0===_)return;const c=_r(i.position),d=o.timeScale(),p=u(i.size)?Math.max(i.size,0):1;if("tag"===i.shape){return void function(t,i,s,n,e,r,h){const l=Math.round((e+10)*h),o=Math.round(7*h),a=_r(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.kM)-o-_,a||(n.kM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.DM)+o+_,a||(n.DM+=l+o+r)}const d={qt:l,CM:o,PM:u,vt:i.borderRadius??6,bM:9*h,Uh:0,ts:0};t.Br=l,t.ct=c,t.wM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=tr(d.options().barSpacing)*p,v=f/2;t.Br=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.kM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.kM+=1.2*e),void(c||(n.kM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.DM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.DM+=1.2*e),void(c||(n.DM+=f+r))}}}class cr{constructor(t,i,s){this.RM=[],this.xt=!0,this.FM=!0,this.Jt=new lr,this.be=t,this.If=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.IM();const t=this.If.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}VM(t){this.RM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.FM=!0)}LM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}IM(){const t=this.If.timeScale(),i=this.RM;this.FM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Br:0,MM:t.shape,R:t.color,Gn:t.id,AM:t.AM,hi:void 0,TM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,wM:void 0})),this.FM=!1);const s=this.If.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=ir(t.options().barSpacing),a={kM:o,DM:o};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&&(a.kM=o,a.DM=o,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={gM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&ur(_,e,u,a,s.fontSize,o,this.be,this.If,r)}this.xt=!1}}function dr(t){return{...Ze,...t}}class pr{constructor(t){this.nh=null,this.RM=[],this.EM=[],this.BM=null,this.be=null,this.If=null,this.OM=!0,this.WM=null,this.zM=null,this.$M=null,this.HM=!0,this.Ps=dr(t)}attached(t){this.NM(),this.If=t.chart,this.be=t.series,this.nh=new cr(this.be,l(this.If),this.Ps),this.cM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Dg(t)),this.HM=!0,this.Zb()}Zb(){this.cM&&this.cM()}detached(){this.be&&this.BM&&this.be.unsubscribeDataChanged(this.BM),this.If=null,this.be=null,this.nh=null,this.BM=null}VM(t){this.HM=!0,this.RM=t,this.NM(),this.OM=!0,this.zM=null,this.Zb()}UM(){return this.RM}paneViews(){return this.nh?[this.nh]:[]}updateAllViews(){this.qM()}hitTest(t,i){return this.nh?this.nh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.nh){const t=this.jM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=dr({...this.Ps,...t}),this.Zb&&this.Zb()}jM(){const t=l(this.If).timeScale().options().barSpacing;if(this.OM||t!==this.$M){if(this.$M=t,this.RM.length>0){const i=ir(t),s=1.5*tr(t)+2*i,n=this.YM();this.WM={above:sr(s,n.aboveBar,n.inBar),below:sr(s,n.belowBar,n.inBar)}}else this.WM=null;this.OM=!1}return this.WM}YM(){return null===this.zM&&(this.zM=this.RM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.zM}NM(){if(!this.HM||!this.If||!this.be)return;const t=this.If.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.EM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.EM=this.RM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),o={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,AM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Tw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.HM=!1}qM(t){this.nh&&(this.NM(),this.nh.VM(this.EM),this.nh.LM(this.Ps),this.nh.Tt(t))}Dg(t){this.HM=!0,this.Zb()}}class fr extends Ke{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this.ah.VM(t)}markers(){return this.ah.UM()}}function vr(t,i,s){const n=new fr(t,new pr(s??{}));return i&&n.setMarkers(i),n}class mr{constructor(t){this.RM=new Map,this.XM=t}GM(t,i,s){if(this.KM(i),void 0!==s){const n=window.setTimeout(()=>{this.RM.delete(i),this.ZM()},s),e={...t,JM:n,QM:Date.now()+s};this.RM.set(i,e)}else this.RM.set(i,{...t,JM:void 0,QM:void 0});this.ZM()}KM(t){const i=this.RM.get(t);i&&void 0!==i.JM&&window.clearTimeout(i.JM),this.RM.delete(t),this.ZM()}ty(){for(const[t]of this.RM)this.KM(t)}iy(){const t=Date.now(),i=[];for(const[s,n]of this.RM)!n.QM||n.QM>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.KM(s);return i}sy(t){this.XM=t}ZM(){this.XM&&this.XM()}}const wr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class gr{constructor(t,i,s,n){this.Yt=t,this.ny=i,this.ey=s,this.hy=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.ly(e.oy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.oy&&(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.oy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.oy-7*e.oy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.oy)*t.verticalPixelRatio),i.stroke())})})}ly(t){return 0===t?this.ny:t>0?this.hy:this.ey}}class br{constructor(t,i,s){this.Yt=[],this.be=t,this.dh=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.dh.timeToCoordinate(t.time)),ct:i,oy: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 gr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Mr(t,i){return"Line"===i||"Area"===i}class yr{constructor(t){this.If=void 0,this.be=void 0,this.Kb=[],this.__=null,this._y=new Map,this.uy=new mr(()=>this.Zb()),this.Ps={...wr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Zb()}VM(t){this.uy.ty();const i=this.__;i&&t.forEach(t=>{this.uy.GM(t,i.key(t.time))})}UM(){return this.uy.iy()}Zb(){this.cM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.If=i,this.be=s,this.__=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Kb=[new br(this.be,this.If.timeScale(),this.Ps)],this.cM=n,this.Zb()}detached(){this.If=void 0,this.be=void 0,this.cM=void 0}jf(){return h(this.If)}Wa(){return h(this.be)}updateAllViews(){this.Kb.forEach(t=>t.Tt(this.UM()))}paneViews(){return this.Kb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this._y.clear();const s=this.__;s&&t.forEach(t=>{Gs(t)&&Mr(0,i)&&this._y.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.__)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.__.key(t.time);if(Xs(t)&&this._y.delete(n),Gs(t)&&Mr(0,s)){const i=this._y.get(n);i&&this.uy.GM({time:t.time,value:t.value,sign:Sr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}py(){this.uy.ty()}}function Sr(t,i){return t===i?0:t-i>0?1:-1}class xr extends Ke{setData(t){return this.ah.lt(t)}update(t,i){return this.ah.Tt(t,i)}markers(){return this.ah.UM()}setMarkers(t){return this.ah.VM(t)}clearMarkers(){return this.ah.py()}}class Cr{constructor(t,i){this.vy=null,this.my=[],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.vy=vr(t)}addPosition(t){this.my.push(t),this.wy()}addPositions(t){this.my.push(...t),this.wy()}setPositions(t){this.my=[...t],this.wy()}closePosition(t,i,s){const n=this.my.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.wy())}removePosition(t){this.my=this.my.filter(i=>i.id!==t),this.wy()}clearPositions(){this.my=[],this.wy()}getPositions(){return this.my}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.wy()}gy(){const t=[];for(const i of this.my){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}wy(){if(this.vy){const t=this.gy();this.vy.setMarkers(t)}}detach(){this.vy&&(this.vy.detach(),this.vy=null),this.my=[]}}const Pr=new WeakMap;function Tr(t){return"string"==typeof t?t:String(t)}function kr(t,i){return Pr.get(t)?.get(Tr(i))}function Dr(t){const i=Pr.get(t);return void 0!==i&&i.size>0}const Rr="rgba(0, 0, 0, 0)";function Fr(t){switch(t.seriesType()){case"Candlestick":return Ir(t,{upColor:Rr,downColor:Rr,borderVisible:!1,wickVisible:!1});case"Bar":return Ir(t,{upColor:Rr,downColor:Rr});case"Line":return Ir(t,{color:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Ir(t,{lineColor:Rr,topColor:Rr,bottomColor:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Ir(t,{topLineColor:Rr,topFillColor1:Rr,topFillColor2:Rr,bottomLineColor:Rr,bottomFillColor1:Rr,bottomFillColor2:Rr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Ir(t,{color:Rr});default:return Ir(t,{visible:!1})}}function Ir(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 Vr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Lr(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 Ar(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 Er(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 Br(t){return null==t?void 0:t.time}function Or(t){const{e_:i,jf:s,by:n,My:e,yy:r,Zl:h}=t,l=t.Sy??[];let o=t.W,a=[],_=new Map,u=!1;const c=(t,i)=>{if(0===i.length)return;const s=_.get(t),n=i[i.length-1];if(void 0!==s&&s.length>0){const e=i.length===s.length+1,r=i.length===s.length,h=Br(s[s.length-1])===Br(n);if(e||r&&h)return t.update(n),void _.set(t,i)}t.setData(i),_.set(t,i)},d=t=>{if(!u)try{if("full"===t||0===a.length)a=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;a.length>0&&Br(a[a.length-1])===Br(t)?a[a.length-1]=t:a.push(t)}if(0===a.length)return;const s=e(a,o);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&a.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==r&&r(o),l.some(t=>i[t]!==o[t])&&(_=new Map,d("full"))},options:()=>({...o}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,a=[]}},recalculate:()=>d("full")};return f}function Wr(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.xy,i.Cy-1,i.Py))}}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()}`}class zr{constructor(t,i,s,n){this.If=t,this.be=i,this.F_=s,this.Ty=n}draw(t){const i=this.Ty();if(!i.It||i.ky<=0)return;const s=this.F_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.If.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Dy),u=this.be.priceToCoordinate(h.Ry),c=this.be.priceToCoordinate(l.Dy),d=this.be.priceToCoordinate(l.Ry);if(null===_||null===u||null===c||null===d)continue;const p=h.Dy>=h.Ry;n.fillStyle=this.Fy(p?i.Iy:i.Vy,i.ky),n.beginPath(),n.moveTo(o*t.horizontalPixelRatio,_*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,c*t.verticalPixelRatio),n.lineTo(a*t.horizontalPixelRatio,d*t.verticalPixelRatio),n.lineTo(o*t.horizontalPixelRatio,u*t.verticalPixelRatio),n.closePath(),n.fill()}})}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class $r{constructor(t,i,s,n){this.Jt=new zr(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function Hr(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 Nr(t){return null!=t&&"number"==typeof t.close}function Ur(t){const i=[];let s=null,n=null;for(const e of t){if(!Nr(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}class qr{constructor(t){this.Ly=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ly.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.Ay(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}Ay(t,i,s,n){const e=i.Ey||i.startTime,r=i.By||i.endTime,h=i.R||i.color,l=i.ky||i.opacity;if(!i||!e||!r)return;const o=this.Ly.getChart().timeScale(),a=o.timeToCoordinate(e),_=o.timeToCoordinate(r);if(null===a||null===_)return;const u=a*s,c=_*s,d=0*n,p=t.canvas.height/n*n;t.fillStyle=this.Oy(h,l),t.fillRect(u,d,c-u,p-d)}Oy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class jr{constructor(t){this.Jt=new qr(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const Yr=[{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 Xr{constructor(t,i,s={}){this.Wy=[],this.Ub=null,this.nh=null,this.If=t,this.be=i,this.Ps={sessions:s.sessions||Yr,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.zy(),this.Ps.enabled&&this.$y()}zy(){this.nh=new jr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}$y(){this.If.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Hy()}),this.Hy()}Hy(){this.Ny();const t=this.If.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.Uy(s),this.cM()}Uy(t){if(0!==t.length){for(const i of this.Ps.sessions)this.qy(i,t);this.Ps.showOverlaps&&this.jy(t)}}qy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Yy(i);this.Xy(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Gy(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.Gy(s,n[n.length-1].time,t)}jy(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.Ky(e,r);h&&this.Zy(h,t)}}Ky(t,i){const s=Math.max(t.startHour,i.startHour),n=Math.min(t.endHour,i.endHour);return s<n?{ae:s,_e:n}:null}Zy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Yy(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Jy(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.Jy(s,n[n.length-1].time)}Gy(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",Ey:t,By:i,R:s.color,ky:s.opacity,Qy:s.name};this.Wy.push(n)}Jy(t,i){const s={an:"overlap",Ey:t,By:i,R:this.Ps.overlapColor,ky:this.Ps.overlapOpacity,Qy:"Overlap"};this.Wy.push(s)}Xy(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}Yy(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}Ny(){this.Wy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Hy():this.Ny(),this.cM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Hy(),this.cM()}disable(){this.Ps.enabled=!1,this.Ny(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.Ny(),this.cM()}getSessionBoxes(){return this.Wy}getChart(){return this.If}getSeries(){return this.be}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.If.timeScale().applyOptions({})}}class Gr{constructor(t){this.Ly=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ly.getProfileData();if(!s||0===s.bins.length)return;const n=this.Ly.options(),e=this.Ly.getSeries(),r=i.canvas.width/t.horizontalPixelRatio,h=Math.min(n.width||100,.2*r),l="right"===n.position?r-h:0;let o=0;for(const t of s.bins)t.volume>o&&(o=t.volume);if(0!==o){for(const r of s.bins)this.tS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.iS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.sS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}tS(t,i,s,n,e,r,h,l,o,a){const _=i.volume/e*n,u=r.binSize/2,c=l.priceToCoordinate(i.priceLevel+u),d=l.priceToCoordinate(i.priceLevel-u);if(null===c||null===d)return;const p=Math.max(Math.abs(d-c)-1,1),f=s*o,v=Math.min(c,d)*a,m=_*o,w=p*a,g=i.priceLevel>=r.valueAreaLow&&i.priceLevel<=r.valueAreaHigh,b=Math.abs(i.priceLevel-r.poc)<1e-5;let M=h.profileColor||"#2962FF",y=h.opacity||.3;b?(M=h.pocColor||"#FF6B00",y=.6):g&&h.showValueArea&&(M=h.valueAreaColor||"#089981",y=.4),t.fillStyle=this.Oy(M,y),t.fillRect(f,v,m,w)}iS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const o=l*h;t.strokeStyle=s,t.lineWidth=2*Math.min(r,h),t.setLineDash([5*r,3*r]),t.beginPath(),t.moveTo(0,o),t.lineTo(e*r,o),t.stroke(),t.setLineDash([])}sS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Oy(n,.5),t.lineWidth=1*Math.min(h,l),t.setLineDash([3*h,2*h]),t.beginPath(),t.moveTo(0,i),t.lineTo(r*h,i),t.stroke()}const a=e.priceToCoordinate(s);if(null!==a){const i=a*l;t.strokeStyle=this.Oy(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([])}Oy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Kr{constructor(t){this.Jt=new Gr(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Zr{constructor(t,i,s={}){this.nS=null,this.eS=new Map,this.Ub=null,this.nh=null,this.If=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.zy(),this.$y()}zy(){this.nh=new Kr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.nh?[this.nh]:[],updateAllViews:()=>{this.nh}};this.Ub=t,this.be.attachPrimitive(t)}$y(){this.If.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.rS()}),this.rS()}setVolumeData(t){this.eS=t,this.rS()}addVolumeData(t,i){this.eS.set(t,i),this.rS()}rS(){const t=this.If.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.eS.get(t.time)||1,e=Math.floor((i-n)/r);h[Math.max(0,Math.min(this.Ps.numberOfBins-1,e))].volume+=s,l+=s}for(const t of h)t.percentage=l>0?t.volume/l*100:0;let o=h[0];for(const t of h)t.volume>o.volume&&(o=t);const a=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<a))break;c.push(t),u+=t.volume}let d=-1/0,p=1/0;for(const t of c)t.priceLevel>d&&(d=t.priceLevel),t.priceLevel<p&&(p=t.priceLevel);this.nS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.cM()}getProfileData(){return this.nS}applyOptions(t){this.Ps={...this.Ps,...t},this.rS(),this.cM()}remove(){this.Ub&&this.be&&this.be.detachPrimitive(this.Ub),this.nS=null,this.eS.clear(),this.cM()}getChart(){return this.If}getSeries(){return this.be}options(){return this.Ps}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.If.timeScale().applyOptions({})}}class Jr{constructor(t,i){this.hS=new Map,this.lS=null,this.oS=null,this.aS=null,this._S=null,this.uS=null,this.cS=null,this.dS=0,this.pS=null,this.bg=void 0,this.If=t,this.kf=i,this.fS=t=>this.vS(t),this.mS=t=>this.wS(t),this.gS=t=>this.bS(t),this.MS=t=>this.yS(t),this.SS=()=>this.xS(),this.CS=t=>{"Escape"===t.key&&this.xS()},this.If.subscribeCrosshairMove(this.fS),this.kf.addEventListener("pointerdown",this.mS),this.kf.addEventListener("pointermove",this.gS),this.kf.addEventListener("pointerup",this.MS),this.kf.addEventListener("pointercancel",this.SS),document.addEventListener("keydown",this.CS)}PS(t){this.hS.set(t.id(),t)}TS(t){const i=t.id();this.lS===i&&this.kS(null),this.aS===t&&this.xS(),this.hS.delete(i)}Gi(){return 0===this.hS.size}m(){this.If.unsubscribeCrosshairMove(this.fS),this.kf.removeEventListener("pointerdown",this.mS),this.kf.removeEventListener("pointermove",this.gS),this.kf.removeEventListener("pointerup",this.MS),this.kf.removeEventListener("pointercancel",this.SS),document.removeEventListener("keydown",this.CS),this.hS.clear()}vS(t){if(this.pS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.bg=t.paneIndex,null!==this.aS)return;const i=this.DS(t.hoveredObjectId),s=null===i?null:this.hS.get(i.wl)??null;this.kS(s?s.id():null),this.RS(s,null===s?null:i?.FS??null),this.IS()}wS(t){const i=null===this.lS?null:this.hS.get(this.lS)??null;i&&(this.uS={ut:t.clientX,ct:t.clientY},this.cS=i,i.isDraggable()&&(this.aS=i,this._S=t.pointerId,this.kf.setPointerCapture(t.pointerId),i.beginDrag(),this.dS=this.VS(i,t),this.IS(),t.preventDefault(),t.stopPropagation()))}bS(t){if(null===this.aS)return;if(!this.LS(t))return void this.xS();const i=this.AS(t);null!==i&&this.aS.dragTo(i),t.preventDefault(),t.stopPropagation()}yS(t){const i=this.aS,s=this.cS,n=this.uS;this.ES(),this.cS=null,this.uS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.aS=null,this.dS=0,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.IS();null!==s&&!e&&s.isClickable()&&s.click()}xS(){if(null===this.aS)return;const t=this.aS;this.aS=null,this.dS=0,this.ES(),t.cancelDrag(),this.IS()}LS(t){const i=this.kf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}ES(){null!==this._S&&(this.kf.hasPointerCapture(this._S)&&this.kf.releasePointerCapture(this._S),this._S=null)}AS(t){const i=this.aS;if(null===i)return null;const s=this.BS(i,t);return null===s?null:i.priceAt(s-this.dS)}BS(t,i){const s=this.If.panes()[t.paneIndex()],n=s?s.getHTMLElement():null;return n?i.clientY-n.getBoundingClientRect().top:null!==this.pS&&this.bg===t.paneIndex()?this.pS.ct:null}VS(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.BS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}DS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{wl:t,FS:null}:{wl:t.slice(0,i),FS:t.slice(i+1)}}RS(t,i){this.oS!==i&&(this.oS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}kS(t){this.lS!==t&&(null!==this.lS&&this.hS.get(this.lS)?.setHovered(!1),this.lS=t,this.oS=null,null!==t&&this.hS.get(t)?.setHovered(!0))}IS(){if(null!==this.aS)return void this.If.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.lS?null:this.hS.get(this.lS);t?this.If.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.If.chartElement().style.removeProperty("cursor")}}const Qr=new WeakMap;function th(t){const i=t.chartElement();if(!i)return null;let s=Qr.get(t);return s||(s=new Jr(t,i),Qr.set(t,s)),s}function ih(t,i){const s=Qr.get(t);s&&(s.TS(i),s.Gi()&&(s.m(),Qr.delete(t)))}let sh=0;class nh{constructor(t,i,s){this.sr=null,this.OS=!1,this.WS="",this.zS=null,this.If=t,this.be=i,this.yo="pipsend-trading-line-"+sh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.$S(),(this.Ps.draggable||this.Ps.onClick)&&th(this.If)?.PS(this)}id(){return this.yo}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.OS!==t&&this.sr&&(this.OS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.WS}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.zS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.HS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.zS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.zS;this.zS=null,null!==t&&t!==this.Ps.price&&(this.HS(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.WS=t.color),!this.sr)return;const i={title:this.NS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.OS||(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.HS(t)}remove(){ih(this.If,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}NS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}$S(){this.WS=this.Ps.color,this.sr=this.be.createPriceLine({id:this.yo,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.NS()})}HS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.NS()})}}class eh{constructor(t,i){this.Ff=null,this.US=null,this.qS=null,this.jS={},this.If=t,this.be=i,this.YS()}YS(){this.Ff=this.If.chartElement()}XS(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.Ff?(this.US=t,this.jS=i||{},new Promise(t=>{this.Ff.style.cursor="crosshair",this.qS=i=>{const s=this.XS(i),n=this.GS(s);this.disableClickToCreate(),t(n)},this.Ff.addEventListener("click",this.qS)})):Promise.resolve(null)}disableClickToCreate(){this.Ff&&this.qS&&(this.Ff.removeEventListener("click",this.qS),this.Ff.style.cursor="default"),this.US=null,this.qS=null,this.jS={}}GS(t){if(!this.US)return null;let i;switch(this.US){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.jS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.jS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.jS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.jS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.jS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.jS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.jS};break;default:return null}return new nh(this.If,this.be,i)}getCreationMode(){return this.US}isCreating(){return null!==this.US}}class rh{constructor(){this.KS=[],this.ZS=new Map,this.JS=new Map,this.xt=!0}PS(t){this.ZS.has(t)||(this.KS.push(t),this.ZS.set(t,[]),this.xt=!0)}TS(t){const i=this.KS.indexOf(t);-1!==i&&this.KS.splice(i,1),this.ZS.delete(t),this.xt=!0}Gi(){return 0===this.KS.length}QS(t,i){this.ZS.set(t,i),this.xt=!0}tx(t,i){return this.xt&&this.ix(),this.JS.get(hh(t,i))??0}ix(){const t=new Map,i=[];for(const s of this.KS)for(const n of this.ZS.get(s)??[]){const e=lh(n.qt),r=n.qt;let h=n.ct;for(const t of[...i].sort(oh))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.JS=t,this.xt=!1}}function hh(t,i){return`${t}:${i}`}function lh(t){return Math.max(9,Math.round(.4*t))}function oh(t,i){return t.ct-i.ct}const ah=new WeakMap;const _h={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},uh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},ch=["takeProfit","entry","stopLoss"];class dh{constructor(){this.Yt=null,this.sx=[],this.nx=0,this.Hf="",this.Co=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.sx)if(s.hx&&t>=s.lx&&t<=s.ox&&Math.abs(i-s._x)<=s.qt/2)return{sn:s.sn,FS:"close"};for(const s of this.sx)if(t>=s.ux&&t<=s.vx&&Math.abs(i-s._x)<=s.qt/2)return{sn:s.sn,FS:"body"};for(const t of this.sx)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,FS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.rw(t))}rw(t){const i=this.Yt;if(this.sx=[],null===i||0===i.mx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Hf!==i.T&&(this.Hf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.nx=Math.max(0,n.width-i.bu);const e=i.wx?this.nx:n.width;for(const s of i.mx)this.sx.push(this.gx(t,i,s,e));i.wx&&i.mx.length>1&&this.bx(t,i),s.restore()}gx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Mx,o=0===s.yx.length?0:Math.max(this.Wn.Ii(e,s.yx)+2*i.bM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.bM,_=s.hx?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Sx,f=p-l/2;this.xx(t,s,d,c,n),this.Cx(t,i,s,{Uh:d,Px:f,ts:u,qt:l});let v=d;return o>0&&(this.Tx(t,i,s,{Uh:v,Px:f,ts:o,qt:l}),v+=o,this.kx(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.TM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.hx&&(this.kx(e,s.R,v,f,l,r,h),this.Dx(t,i,s,{Uh:v,Px:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,_x:p,qt:l,ux:d,vx:c,lx:v,ox:v+_,hx:s.hx}}xx(t,i,s,e,r){const{context:h,horizontalPixelRatio:l,verticalPixelRatio:o}=t,a=Math.max(1,Math.round(i.dt*o)),_=Math.round(i.ct*o)-Math.floor(a/2);h.save(),h.strokeStyle=i.R,h.lineWidth=a,n(h,i.Kt),h.beginPath(),0!==i.Sx?(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()}Cx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Rx===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),ph(e,n,i.Fx,r,h),e.fillStyle=this.Co.X(i.Z,i.Ix),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}Tx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Vx){const t=i.Wt;e.save(),ph(e,{Uh:n.Uh+t,Px:n.Px+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Fx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Vx?i.Lx:s.R,e.fillText(s.yx,n.Uh+n.ts/2,n.Px+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.Co.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}Dx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Rx===s.sn&&"close"===i.Ax){e.save();const t=i.Wt;ph(e,{Uh:n.Uh,Px:n.Px+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Fx-t),r,h,"right"),e.fillStyle=this.Co.X(s.R,.25),e.fill(),e.restore()}const l=(n.Uh+n.ts/2)*r,o=(n.Px+n.qt/2)*h,a=3.5*r;e.save(),e.setLineDash([]),e.lineCap="round",e.lineWidth=Math.max(1,Math.round(1.4*r)),e.strokeStyle=s.R,e.beginPath(),e.moveTo(l-a,o-a),e.lineTo(l+a,o+a),e.moveTo(l+a,o-a),e.lineTo(l-a,o+a),e.stroke(),e.restore()}bx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.mx.find(t=>"entry"===t.sn)??i.mx[0],h=i.mx.map(t=>t.ct),l=Math.round(this.nx*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.mx)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.Co.X(i.Z,i.Ix),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function ph(t,i,s,n,e,r="all"){const h=Math.round(i.Uh*n),l=Math.round(i.Px*e),o=Math.round(i.ts*n),a=Math.round(i.qt*e),_=Math.min(s*n,o/2,a/2);L(t,h,l,o,a,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class fh{constructor(){this.Jt=new dh,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 vh{constructor(t){this.Qt=t}coordinate(){return this.Ex()?.Li??-1e3}text(){return this.Ex()?.hi??""}textColor(){return this.Ex()?.TM??"#FFFFFF"}backColor(){return this.Ex()?.R??"#000000"}visible(){return null!==this.Ex()}Ex(){return this.Qt()}}let mh=0;class wh{constructor(t,i,s){this.nh=new fh,this.Co=new S([]),this.Bx=!1,this.Ox=null,this.oS=null,this.Wx=null,this.zS=null,this.If=t,this.be=i,this.yo="pipsend-position-line-"+mh++,this.Ps=s,this.Rf={...uh,...s.theme},this.Kb=[this.nh],this.zx=ch.map(t=>new vh(()=>this.$x(t))),this.Hx=function(t,i){let s=ah.get(t);return s||(s=new rh,ah.set(t,s)),s.PS(i),s}(this.If,this.yo),this.be.attachPrimitive(this),th(this.If)?.PS(this)}attached(t){this.cM=t.requestUpdate,this.Bx=!0,this.requestUpdate()}detached(){this.Bx=!1,this.cM=void 0}paneViews(){return this.Kb}priceAxisViews(){return this.zx}updateAllViews(){this.nh.Tt(this.Nx())}hitTest(t,i){const s=this.nh.Xn(t,i);if(null===s)return null;const n=this.Ux(s.sn);return null===n?null:{externalId:`${this.yo}#${s.sn}:${s.FS}`,zOrder:"top",cursorStyle:"close"===s.FS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.yo}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.Ox===n&&this.oS===e||(this.Ox=n,this.oS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Ox&&"close"!==this.oS&&(this.Ux(this.Ox)?.draggable??!0)}isClickable(){return"close"===this.oS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}dragAnchorY(){if(null===this.Wx)return null;const t=this.Ux(this.Wx)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.Wx=this.Ox,null===this.Wx)return;const t=this.Ux(this.Wx)?.price??null;this.zS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.Wx,t)}dragTo(t){null!==this.Wx&&(this.qx(this.Wx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.Wx,t))}commitDrag(){const t=this.Wx;if(this.Wx=null,this.zS=null,null===t)return;const i=this.Ux(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.Wx,i=this.zS;if(this.Wx=null,this.zS=null,null===t)return;null!==i&&i!==this.Ux(t)?.price&&(this.qx(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.Ux(t)?.price??0)}click(){const t=this.Ox;if(null===t)return;if("close"===this.oS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.Ux(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.Wx,s=null===i?void 0:this.Ux(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=gh(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=gh(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.Ux(i);null!==t&&(t.price=s)}t.theme&&(this.Rf={...this.Rf,...t.theme}),this.requestUpdate()}setPrice(t,i){this.Wx!==t&&this.qx(t,i)}setText(t,i){const s=this.Ux(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of ch){const s=this.Ux(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){ih(this.If,this),function(t,i){const s=ah.get(t);s&&(s.TS(i),s.Gi()&&ah.delete(t))}(this.If,this.yo),this.be.detachPrimitive(this)}requestUpdate(){this.cM&&this.cM()}$x(t){const i=this.Ux(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??_h[t];return{Li:s,hi:this.be.priceFormatter().format(i.price),R:n,TM:this.Co.K(n).J}}Ux(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}qx(t,i){const s=this.Ux(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}Nx(){if(!this.Bx||!1===this.Ps.visible)return null;const t=this.If.options().layout,i=this.Rf.fontSize??t.fontSize,s=i+2*this.Rf.paddingY,n=[],e=[];for(const t of ch){const i=this.Ux(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,Sx:0,R:i.color??_h[t],hi:i.formatText?i.formatText(i.price):i.text??"",yx:i.badge??"",Vx:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),hx:i.closable??!0,jx:i.draggable??!0})}if(0===n.length)return this.Hx.QS(this.yo,[]),null;this.Hx.QS(this.yo,e);for(const t of n)t.Sx=this.Hx.tx(this.yo,t.sn);return{mx:n,Z:this.Rf.background??(r=t.background,"solid"===r.type?r.color:r.topColor),TM:this.Rf.textColor,Lx:this.Rf.badgeTextColor,Fx:this.Rf.borderRadius,Wt:this.Rf.borderWidth,bM:this.Rf.paddingX,Mx:this.Rf.paddingY,Ix:this.Rf.backgroundOpacity,T:g(i,this.Rf.fontFamily??t.fontFamily),P:i,wx:!1!==this.Ps.connectorVisible&&n.length>1,bu:this.Ps.rightOffset??56,Rx:this.Ox,Ax:this.oS};var r}}function gh(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}const bh=new Set(["line","body","stroke","center","move"]);function Mh(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?bh.has(n)?"move":"grab":void 0}}function yh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var Sh;function xh(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.xy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Cy,t.day=i.day??i.Py,t}return t}function Ch(t,i){const s={};return s.price=t,s.time=i,s}function Ph(t){if(!t)return Ch(0,null);return Ch(t.price??t.bt??0,xh(t.time??t.gt??null))}function Th(t,i="time"){return t?t[i]??null:null}function kh(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"}(Sh||(Sh={}));class Dh{constructor(t,i,s={}){this._state=Sh.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.Yx(),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}Yx(){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 Rh=new WeakMap;function Fh(t,i){Rh.set(t,i)}function Ih(t){const i=!0===Rh.get(t);return i&&Rh.set(t,!1),i}function Vh(t,i,s,n,e){const r=t.canvas.width/s,h=t.canvas.height/n;if(e.ct<0||e.ct>h)return;let l;try{l=i.priceFormatter().format(e.bt)}catch(t){l=String(e.bt)}t.save(),t.font=11*s+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const o=t.measureText(l).width/s+10,a=r-o,_=e.ct-8.5;t.fillStyle=e.Ot,t.beginPath(),t.rect(a*s,_*n,o*s,17*n),t.fill(),t.fillStyle=e.TM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Lh;!function(t){t.Xx="idle",t.Gx="waiting_first_point",t.Kx="waiting_second_point",t.Zx="completed"}(Lh||(Lh={}));class Ah{constructor(t,i,s={}){this.Iv=Lh.Xx,this.Jx=null,this.qS=null,this.sp=null,this.If=t,this.be=i,this.Qx=s}tC(){this.Iv===Lh.Xx&&(this.Iv=Lh.Gx,this.Jx=null,this.iC(),this.sC())}nC(){this.Iv=Lh.Xx,this.Jx=null,this.eC(),this.rC(),this.Qx.hC&&this.Qx.hC()}lC(){return this.Iv}oC(){return this.Iv===Lh.Gx||this.Iv===Lh.Kx}iC(){this.qS=t=>{this.aC(t)},this.If.subscribeClick(this.qS)}sC(){this.sp=t=>{this._C(t)},this.If.subscribeCrosshairMove(this.sp)}eC(){this.qS&&(this.If.unsubscribeClick(this.qS),this.qS=null)}rC(){this.sp&&(this.If.unsubscribeCrosshairMove(this.sp),this.sp=null)}aC(t){if(!t.point)return;if(Ih(this.If))return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.If,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Iv===Lh.Gx?(this.Jx=n,this.Iv=Lh.Kx,this.Qx.uC&&this.Qx.uC(n)):this.Iv===Lh.Kx&&this.Jx&&(this.Iv=Lh.Zx,this.Qx.cC&&this.Qx.cC(n),this.Qx.dC&&this.Qx.dC(this.Jx,n),this.eC(),this.rC(),this.Iv=Lh.Xx,this.Jx=null)}_C(t){if(!t.point)return;if(this.Iv!==Lh.Kx)return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.If,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Qx.pC&&this.Qx.pC(n)}m(){this.nC()}}class Eh{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Bh{constructor(t){this.fC=t,this.Jt=new Eh(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Oh extends Dh{constructor(t,i){super(t,"trend-line",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.yC=null,this.SC=null,this.xC=!1,this.CC=null,this.PC=null,this.TC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.TC),this.zy(),this.TC.interactive?this.kC():this.xC=!0}kC(){const t=new Ah(this._chart,this._series,{uC:t=>{this.TC.point1Time=t.gt,this.TC.point1Price=t.bt,this.cM()},cC:t=>{this.TC.point2Time=t.gt,this.TC.point2Price=t.bt,this.xC=!0,this.cM(),this.TC.onUpdate&&this.TC.onUpdate()},pC:t=>{this.TC.point1Time&&!this.xC&&(this.PC=t,this.cM())},dC:()=>{this.xC=!0}});this.CC=t,t.tC()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new Bh(this)}FC(){if(!this.TC.point1Time||!this.TC.point2Time)return null;const t=Xn(this._chart,this._series,this.TC.point1Time)??0,i=this._series.priceToCoordinate(this.TC.point1Price)??0,s=Xn(this._chart,this._series,this.TC.point2Time)??0,n=this._series.priceToCoordinate(this.TC.point2Price)??0;if(!this.TC.extendLeft&&!this.TC.extendRight)return{IC:t,VC:i,LC:s,AC:n};if(s===t)return{IC:t,VC:i,LC:s,AC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{IC:this.TC.extendLeft?0:t,VC:this.TC.extendLeft?i-r*t:i,LC:this.TC.extendRight?e:s,AC:this.TC.extendRight?i+r*(e-t):n}}EC(){const t=this.FC();if(null===t)return null;const i=t.LC>=t.IC?t.AC:t.VC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.TC.point2Price??this.TC.point1Price??null}drawToCanvas(t,i,s){if(!this.xC&&this.TC.point1Time&&this.PC)return void this.BC(t,i,s);if(!this.TC.point1Time||!this.TC.point2Time)return;const n=(Xn(this._chart,this._series,this.TC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.TC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.TC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.TC.point2Price)??0)*s,l=this.TC.lineColor,o=this.mC?this.TC.lineWidth+1:this.TC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.TC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.TC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.FC();if(null===a)return;t.moveTo(a.IC*i,a.VC*s),t.lineTo(a.LC*i,a.AC*s),t.stroke(),t.setLineDash([]),!this.mC&&!this.wC||this.isLocked()||(this.OC(t,n,e,i,l),this.OC(t,r,h,i,l));const _=this.EC();if(!1!==this.TC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Vh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}BC(t,i,s){if(!this.TC.point1Time||!this.PC)return;const n=(Xn(this._chart,this._series,this.TC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.TC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.PC.gt)??0)*i,h=(this._series.priceToCoordinate(this.PC.bt)??0)*s;t.strokeStyle=this.TC.lineColor,t.lineWidth=this.TC.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.OC(t,n,e,i,this.TC.lineColor),t.globalAlpha=.5,this.OC(t,r,h,i,this.TC.lineColor),t.globalAlpha=1}OC(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.TC.lineColor=t,this.cM()}color(){return this.TC.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}isHovered(){return this.wC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){const s=this.FC();if(null===s)return!1;return this.WC(t,i,s.IC,s.VC,s.LC,s.AC)<=8}WC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.TC.point1Time||!this.TC.point2Time)return null;const s=Xn(this._chart,this._series,this.TC.point1Time)??0,n=this._series.priceToCoordinate(this.TC.point1Price)??0,e=Xn(this._chart,this._series,this.TC.point2Time)??0,r=this._series.priceToCoordinate(this.TC.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.WC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.gC=!0,this.bC=t,this.MC=i,"line"===t&&(this.yC={gt:this.TC.point1Time,bt:this.TC.point1Price},this.SC={gt:this.TC.point2Time,bt:this.TC.point2Price})}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.yC=null,this.SC=null}updateDrag(t,i){if(this.gC&&this.bC){if("point1"===this.bC)this.TC.point1Time=t,this.TC.point1Price=i;else if("point2"===this.bC)this.TC.point2Time=t,this.TC.point2Price=i;else if("line"===this.bC&&this.yC&&this.SC){const s=yh(this.MC,t,i);this.TC.point1Time=this.yC.gt+s.gt,this.TC.point1Price=this.yC.bt+s.bt,this.TC.point2Time=this.SC.gt+s.gt,this.TC.point2Price=this.SC.bt+s.bt}this.cM(),this.TC.onUpdate&&this.TC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Ch(this.TC.point1Price??0,xh(this.TC.point1Time)),Ch(this.TC.point2Price??0,xh(this.TC.point2Time))],style:{lineColor:this.TC.lineColor,lineWidth:this.TC.lineWidth,lineStyle:this.TC.lineStyle,extendLeft:this.TC.extendLeft,extendRight:this.TC.extendRight}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return this.xC}remove(){this.CC&&(this.CC.m(),this.CC=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.TC.onRemove&&this.TC.onRemove()}}function Wh(t,i){return new Oh(t,i)}class zh{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class $h{constructor(t){this.fC=t,this.Jt=new zh(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Hh extends Dh{constructor(t,i){super(t,"horizontal-line",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.MC=null,this.zC=0,this.$C={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.$C),this.zy()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new $h(this)}HC(){return void 0===this.$C.startTime?0:Xn(this._chart,this._series,this.$C.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.$C.price)return;const n=(this._series.priceToCoordinate(this.$C.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.HC()*i,h=this.$C.lineColor,l=this.mC?this.$C.lineWidth+1:this.$C.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.$C.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.$C.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.$C.showPriceLabel&&Vh(t,this._series,i,s,{bt:this.$C.price,ct:n/s,Ot:h}),this.$C.showLabel&&(this.mC||this.wC)&&this.NC(t,n,i,s,h)}NC(t,i,s,n,e){const r=this.$C.labelText||this.$C.price.toFixed(4),h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=10*s,u=i-a/2-h;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.$C.lineColor=t,this.cM()}color(){return this.$C.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.$C.price)return!1;const s=this._series.priceToCoordinate(this.$C.price)??0;return!(t<this.HC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.gC=!0,this.MC=i,this.zC=this.$C.price??0}stopDrag(){this.gC=!1,this.MC=null}updateDrag(t,i){this.gC&&(this.$C.price=this.zC+yh(this.MC,t,i).bt,this.cM(),this.$C.onUpdate&&this.$C.onUpdate())}getPrice(){return this.$C.price}setPrice(t){this.$C.price=t,this.cM()}setLabel(t){this.$C.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Ch(this.$C.price??0,xh(this.$C.startTime))],style:{lineColor:this.$C.lineColor,lineWidth:this.$C.lineWidth,lineStyle:this.$C.lineStyle,showLabel:this.$C.showLabel,labelText:this.$C.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.$C.onRemove&&this.$C.onRemove()}}function Nh(t,i){return new Hh(t,i)}class Uh{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class qh{constructor(t){this.fC=t,this.Jt=new Uh(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class jh extends Dh{constructor(t,i){super(t,"cross-line",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.MC=null,this.UC=0,this.zC=0,this.qC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.qC),this.zy()}zy(){this.nh=new qh(this);const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.vC&&this.vC()}_update(){this.cM()}jC(){if(void 0===this.qC.time||void 0===this.qC.price)return null;const t=Xn(this._chart,this._series,this.qC.time),i=this._series.priceToCoordinate(this.qC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.jC();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.qC.lineColor,_=this.mC||this.wC&&!this.isLocked(),u=_?this.qC.lineWidth+1:this.qC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.qC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.qC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(r,o),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.qC.showPriceLabel&&void 0!==this.qC.price&&Vh(t,this._series,i,s,{bt:this.qC.price,ct:n.ct,Ot:a}),_&&!this.isLocked()&&(t.fillStyle=a,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(l,o,5*i,0,2*Math.PI),t.fill(),t.stroke())}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){const s=this.jC();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.gC=!0,this.MC=i,this.UC=this.qC.time,this.zC=this.qC.price??0}updateDrag(t,i){if(!this.gC)return;const s=yh(this.MC,t,i);this.qC.time=this.UC+s.gt,this.qC.price=this.zC+s.bt,this.cM(),this.qC.onUpdate&&this.qC.onUpdate()}stopDrag(){this.gC=!1,this.MC=null}setColor(t){this.qC.lineColor=t,this.cM()}color(){return this.qC.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}remove(){if(this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.vC=null,this.qC.onRemove&&this.qC.onRemove()}_serializeShape(){return{type:"crossLine",points:[Ch(this.qC.price??0,xh(this.qC.time))],style:{lineColor:this.qC.lineColor,lineWidth:this.qC.lineWidth,lineStyle:this.qC.lineStyle}}}}function Yh(t,i){return new jh(t,i)}class Xh{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Gh{constructor(t){this.fC=t,this.Jt=new Xh(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Kh extends Dh{constructor(t,i){super(t,"polygon",i),this.F_=[],this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.YC=null,this.xC=!1,this.PC=null,this.qS=null,this.XC=null,this.GC=null,this.KC={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.KC),this.F_=[...i.points??[]],this.zy(),this.KC.interactive?this.ZC():this.xC=this.F_.length>=3}zy(){this.nh=new Gh(this);const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.vC&&this.vC()}_update(){this.cM()}ZC(){this.qS=t=>{if(!t.point||Ih(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.F_.length>=3&&this.JC(t.point.x,t.point.y)?this.QC():(this.F_.push({time:s,price:i}),this.cM()))},this.XC=t=>{if(!t.point||this.xC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.PC={time:s,price:i},this.cM())},this.GC=t=>{"Enter"===t.key&&this.F_.length>=3?this.QC():"Escape"===t.key&&(this.F_=[],this.QC())},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.XC),document.addEventListener("keydown",this.GC)}JC(t,i){const s=this.F_[0],n=Xn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Kh.tP&&Math.abs(i-e)<=Kh.tP)}QC(){this.xC=!0,this.PC=null,this.iP(),this.cM(),this.KC.onComplete&&this.KC.onComplete(),this.KC.onUpdate&&this.KC.onUpdate()}iP(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.XC&&(this._chart.unsubscribeCrosshairMove(this.XC),this.XC=null),this.GC&&(document.removeEventListener("keydown",this.GC),this.GC=null)}sP(){const t=[...this.F_];return this.xC||null===this.PC||t.push(this.PC),this.nP(t)}nP(t){const i=[];for(const s of t){const t=Xn(this._chart,this._series,s.time),n=this._series.priceToCoordinate(s.price);null!==t&&null!==n&&i.push({ut:t,ct:n})}return i}drawToCanvas(t,i,s){const n=this.sP();if(n.length<2)return;const e=this.KC.borderColor,r=this.mC?this.KC.borderWidth+1:this.KC.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.xC&&(t.closePath(),this.KC.fillOpacity>0&&(t.fillStyle=this.Fy(this.KC.fillColor,this.KC.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.xC?"dashed"===this.KC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.KC.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.mC||this.wC||!this.xC)&&!this.isLocked())for(const n of this.eP())this.rP(t,n.ut*i,n.ct*s,i,e)}eP(){return this.nP(this.F_)}rP(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}RC(t,i){if(!this.isVisible()||!this.xC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){const s=this.eP();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.eP();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.gC=!0,this.bC=t,this.MC=i,this.YC=this.F_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.gC&&null!==this.bC&&null!==this.YC){if("shape"===this.bC){const s=yh(this.MC,t,i);this.F_=this.YC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.bC;this.F_[s]&&(this.F_[s]={time:t,price:i})}this.cM(),this.KC.onUpdate&&this.KC.onUpdate()}}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.YC=null}setColor(t){this.KC.borderColor=t,this.KC.fillColor=t,this.cM()}color(){return this.KC.borderColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}points(){return this.F_}isComplete(){return this.xC}remove(){if(this.iP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.vC=null,this.KC.onRemove&&this.KC.onRemove()}_serializeShape(){return{type:"polygon",points:this.F_.map(t=>Ch(t.price,xh(t.time))),style:{fillColor:this.KC.fillColor,fillOpacity:this.KC.fillOpacity,borderColor:this.KC.borderColor,borderWidth:this.KC.borderWidth,borderStyle:this.KC.borderStyle}}}}function Zh(t,i){return new Kh(t,i)}Kh.tP=12;class Jh{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Qh{constructor(t){this.fC=t,this.Jt=new Jh(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class tl extends Dh{constructor(t,i){super(t,"parallel-channel",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.hP=null,this.xC=!1,this._d=0,this.PC=null,this.qS=null,this.XC=null,this.lP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.lP),this.zy(),this.lP.interactive?this.ZC():this.xC=!0}zy(){this.nh=new Qh(this);const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.vC&&this.vC()}_update(){this.cM()}ZC(){this.qS=t=>{if(!t.point||Ih(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.lP.point1Time=s,this.lP.point1Price=i;else{if(1!==this._d)return this.lP.channelWidth=i-this.oP(s),void this.QC();this.lP.point2Time=s,this.lP.point2Price=i}this._d++,this.cM()}},this.XC=t=>{if(!t.point||this.xC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.PC={gt:s,bt:i},2===this._d&&(this.lP.channelWidth=i-this.oP(s)),this.cM())},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.XC)}QC(){this.xC=!0,this.PC=null,this.iP(),this.cM(),this.lP.onComplete&&this.lP.onComplete(),this.lP.onUpdate&&this.lP.onUpdate()}iP(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.XC&&(this._chart.unsubscribeCrosshairMove(this.XC),this.XC=null)}oP(t){const i=this.lP.point1Time,s=this.lP.point2Time,n=this.lP.point1Price,e=this.lP.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)}hS(){const t=this.lP,i=this.xC?t.point2Time:t.point2Time??this.PC?.gt,s=this.xC?t.point2Price:t.point2Price??this.PC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Xn(this._chart,this._series,t.point1Time),e=Xn(this._chart,this._series,i),r=this._series.priceToCoordinate(t.point1Price),h=this._series.priceToCoordinate(s);if(null===n||null===e||null===r||null===h)return null;let l=e,o=h;if(t.extendRight&&l!==n){const t=this._chart.chartElement().clientWidth;l=t,o=r+(h-r)/(e-n)*(t-n)}const a=t.channelWidth??0,_=this._series.priceToCoordinate(t.point1Price+a),u=this._series.priceToCoordinate(this._series.coordinateToPrice(o)+a);return null===_||null===u?null:{IC:n,LC:l,aP:r,_P:o,uP:_,cP:u}}drawToCanvas(t,i,s){const n=this.hS();if(null===n)return;const e=this.lP,r=e.lineColor,h=this.mC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Fy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.IC*l,n.aP*o),t.lineTo(n.LC*l,n._P*o),t.lineTo(n.LC*l,n.cP*o),t.lineTo(n.IC*l,n.uP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.xC?"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.IC*l,n.aP*o),t.lineTo(n.LC*l,n._P*o),0!==(e.channelWidth??0)&&(t.moveTo(n.IC*l,n.uP*o),t.lineTo(n.LC*l,n.cP*o)),t.stroke(),t.setLineDash([]);if((this.mC||this.wC||!this.xC)&&!this.isLocked()&&(this.rP(t,n.IC*l,n.aP*o,l,r),this.rP(t,n.LC*l,n._P*o,l,r),0!==(e.channelWidth??0))){const i=(n.IC+n.LC)/2,s=(n.uP+n.cP)/2;this.rP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.xC){const i=this._series.coordinateToPrice(n._P);null!==i&&Vh(t,this._series,l,o,{bt:i,ct:n._P,Ot:r})}}rP(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}RC(t,i){if(!this.isVisible()||!this.xC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}dP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.hS();if(null===s)return!1;return this.dP(t,i,s.IC,s.aP,s.LC,s._P)<=8||this.dP(t,i,s.IC,s.uP,s.LC,s.cP)<=8}hitTestEndpoint(t,i){const s=this.hS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.IC,s.aP))return"point1";if(n(s.LC,s._P))return"point2";if(0!==(this.lP.channelWidth??0)){if(n((s.IC+s.LC)/2,(s.uP+s.cP)/2))return"width"}return null}startDrag(t,i){this.gC=!0,this.bC=t,this.MC=i,this.hP={pP:{gt:this.lP.point1Time,bt:this.lP.point1Price},fP:{gt:this.lP.point2Time,bt:this.lP.point2Price},ts:this.lP.channelWidth??0}}updateDrag(t,i){if(!this.gC||null===this.bC||null===this.hP)return;const s=this.lP;if("point1"===this.bC)s.point1Time=t,s.point1Price=i;else if("point2"===this.bC)s.point2Time=t,s.point2Price=i;else if("width"===this.bC)s.channelWidth=i-this.oP(t);else{const n=yh(this.MC,t,i);s.point1Time=this.hP.pP.gt+n.gt,s.point1Price=this.hP.pP.bt+n.bt,s.point2Time=this.hP.fP.gt+n.gt,s.point2Price=this.hP.fP.bt+n.bt,s.channelWidth=this.hP.ts}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.hP=null}setColor(t){this.lP.lineColor=t,this.lP.fillColor=t,this.cM()}color(){return this.lP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}isComplete(){return this.xC}remove(){if(this.iP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.vC=null,this.lP.onRemove&&this.lP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Ch(this.lP.point1Price??0,xh(this.lP.point1Time)),Ch(this.lP.point2Price??0,xh(this.lP.point2Time))],style:{lineColor:this.lP.lineColor,lineWidth:this.lP.lineWidth,lineStyle:this.lP.lineStyle,fillColor:this.lP.fillColor,fillOpacity:this.lP.fillOpacity,extendRight:this.lP.extendRight},extra:{channelWidth:this.lP.channelWidth}}}}function il(t,i){return new tl(t,i)}class sl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class nl{constructor(t){this.fC=t,this.Jt=new sl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class el extends Dh{constructor(t,i){super(t,"pitchfork",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.hP=null,this.xC=!1,this._d=0,this.PC=null,this.qS=null,this.XC=null,this.vP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.vP),this.zy(),this.vP.interactive?this.ZC():this.xC=!0}zy(){this.nh=new nl(this);const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}cM(){this.vC&&this.vC()}_update(){this.cM()}ZC(){this.qS=t=>{if(!t.point||Ih(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this._d)this.vP.pivotTime=s,this.vP.pivotPrice=i;else{if(1!==this._d)return this.vP.lowerTime=s,this.vP.lowerPrice=i,this._d++,void this.QC();this.vP.upperTime=s,this.vP.upperPrice=i}this._d++,this.cM()}},this.XC=t=>{if(!t.point||this.xC)return;const i=this._series.coordinateToPrice(t.point.y),s=Yn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.PC={gt:s,bt:i},this.cM())},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.XC)}QC(){this.xC=!0,this.PC=null,this.iP(),this.cM(),this.vP.onComplete&&this.vP.onComplete(),this.vP.onUpdate&&this.vP.onUpdate()}iP(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.XC&&(this._chart.unsubscribeCrosshairMove(this.XC),this.XC=null)}mP(t,i){if(void 0===t||void 0===i)return null;const s=Xn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}wP(){const t=this.vP,i=this.mP(t.pivotTime,t.pivotPrice),s=this.mP(t.upperTime,t.upperPrice),n=this.xC?this.mP(t.lowerTime,t.lowerPrice):this.mP(t.lowerTime,t.lowerPrice)??(null!==this.PC&&this._d>=2?this.mP(this.PC.gt,this.PC.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{gP:i,bP:e,MP:s,yP:n,SP:l(i),xP:l(s),CP:l(n)}}drawToCanvas(t,i,s){const n=this.wP();if(null===n)return void this.PP(t,i,s);const e=this.vP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Fy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.MP.ut*h,n.MP.ct*l),t.lineTo(n.xP.ut*h,n.xP.ct*l),t.lineTo(n.CP.ut*h,n.CP.ct*l),t.lineTo(n.yP.ut*h,n.yP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.mC?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.MP.ut*h,n.MP.ct*l),t.lineTo(n.yP.ut*h,n.yP.ct*l),t.moveTo(n.gP.ut*h,n.gP.ct*l),t.lineTo(n.SP.ut*h,n.SP.ct*l),t.moveTo(n.MP.ut*h,n.MP.ct*l),t.lineTo(n.xP.ut*h,n.xP.ct*l),t.moveTo(n.yP.ut*h,n.yP.ct*l),t.lineTo(n.CP.ut*h,n.CP.ct*l),t.stroke(),t.setLineDash([]);if((this.mC||this.wC||!this.xC)&&!this.isLocked())for(const i of[n.gP,n.MP,n.yP])this.rP(t,i.ut*h,i.ct*l,h,r)}PP(t,i,s){const n=this.vP,e=this.mP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.mP(n.upperTime,n.upperPrice)??(null!==this.PC?this.mP(this.PC.gt,this.PC.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.rP(t,e.ut*i,e.ct*s,i,h)}rP(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()}Fy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}RC(t,i){if(!this.isVisible()||!this.xC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}dP(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.hypot(t-s,i-n);let a=((t-s)*h+(i-n)*l)/o;return a=Math.max(0,Math.min(1,a)),Math.hypot(t-(s+a*h),i-(n+a*l))}hitTest(t,i){const s=this.wP();if(null===s)return!1;return[[s.gP,s.SP],[s.MP,s.xP],[s.yP,s.CP],[s.MP,s.yP]].some(([s,n])=>this.dP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.wP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.gP)?"pivot":n(s.MP)?"upper":n(s.yP)?"lower":null}startDrag(t,i){this.gC=!0,this.bC=t,this.MC=i,this.hP=[{gt:this.vP.pivotTime,bt:this.vP.pivotPrice},{gt:this.vP.upperTime,bt:this.vP.upperPrice},{gt:this.vP.lowerTime,bt:this.vP.lowerPrice}]}updateDrag(t,i){if(!this.gC||null===this.bC||null===this.hP)return;const s=this.vP;if("pivot"===this.bC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.bC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.bC)s.lowerTime=t,s.lowerPrice=i;else{const n=yh(this.MC,t,i),[e,r,h]=this.hP;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.cM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.hP=null}setColor(t){this.vP.lineColor=t,this.vP.fillColor=t,this.cM()}color(){return this.vP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}isComplete(){return this.xC}remove(){if(this.iP(),this.Ub){try{this._series.detachPrimitive(this.Ub)}catch(t){}this.Ub=null}this.vC=null,this.vP.onRemove&&this.vP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Ch(this.vP.pivotPrice??0,xh(this.vP.pivotTime)),Ch(this.vP.upperPrice??0,xh(this.vP.upperTime)),Ch(this.vP.lowerPrice??0,xh(this.vP.lowerTime))],style:{lineColor:this.vP.lineColor,lineWidth:this.vP.lineWidth,lineStyle:this.vP.lineStyle,fillColor:this.vP.fillColor,fillOpacity:this.vP.fillOpacity}}}}function rl(t,i){return new el(t,i)}class hl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ll{constructor(t){this.fC=t,this.Jt=new hl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ol extends Dh{constructor(t,i){super(t,"vertical-line",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.MC=null,this.UC=0,this.TP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.TP),this.zy()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new ll(this)}drawToCanvas(t,i,s){if(void 0===this.TP.time)return;const n=(Xn(this._chart,this._series,this.TP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.TP.lineColor,h=this.mC||this.wC&&!this.isLocked()?this.TP.lineWidth+1:this.TP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.TP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.TP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.TP.showLabel&&(this.mC||this.wC)&&this.TP.labelText&&this.NC(t,n,i,s,r)}NC(t,i,s,n,e){const r=this.TP.labelText,h=6*s,l=12*s;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(r).width,a=l,_=i-o/2-h,u=10*n;t.fillStyle=e,t.fillRect(_,u,o+2*h,a+2*h),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(r,_+h,u+h)}setColor(t){this.TP.lineColor=t,this.cM()}color(){return this.TP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.TP.time)return!1;const s=Xn(this._chart,this._series,this.TP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.gC=!0,this.MC=i,this.UC=this.TP.time}stopDrag(){this.gC=!1,this.MC=null}updateDrag(t,i){this.gC&&(this.TP.time=this.UC+yh(this.MC,t,i).gt,this.cM(),this.TP.onUpdate&&this.TP.onUpdate())}getTime(){return this.TP.time}setTime(t){this.TP.time=t,this.cM()}setLabel(t){this.TP.labelText=t,this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Ch(0,xh(this.TP.time))],style:{lineColor:this.TP.lineColor,lineWidth:this.TP.lineWidth,lineStyle:this.TP.lineStyle,showLabel:this.TP.showLabel,labelText:this.TP.labelText}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.TP.onRemove&&this.TP.onRemove()}}function al(t,i){return new ol(t,i)}const _l=[{kP:0,Zl:"0.0%"},{kP:.236,Zl:"23.6%"},{kP:.382,Zl:"38.2%"},{kP:.5,Zl:"50.0%"},{kP:.618,Zl:"61.8%"},{kP:.786,Zl:"78.6%"},{kP:1,Zl:"100.0%"}],ul=[..._l,{kP:1.272,Zl:"127.2%"},{kP:1.414,Zl:"141.4%"},{kP:1.618,Zl:"161.8%"},{kP:2,Zl:"200.0%"},{kP:2.618,Zl:"261.8%"}];class cl{constructor(t=!1){this.DP=t?ul:_l}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.DP.map(({kP:t,Zl:i})=>{let s;return s=h?n-e*t:n+e*t,{kP:t,bt:s,Zl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.DP=t}getRatios(){return[...this.DP]}getRatioValues(){return this.DP.map(t=>t.kP)}useStandardRatios(){this.DP=_l}useExtendedRatios(){this.DP=ul}}class dl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class pl{constructor(t){this.fC=t,this.Jt=new dl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}}function fl(t){return{kP:t,Zl:`${(100*t).toFixed(1)}%`}}class vl extends Dh{constructor(t,i){super(t,"fibonacci-tool",i),this.Ub=null,this.vC=null,this.Yb=null,this.nh=null,this.RP=null,this.xC=!1,this.mC=!1,this.wC=!1,this.PC=null,this.gC=!1,this.FP=null,this.sp=null,this.IP={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.IP),this.VP=new cl(this.IP.useExtended),void 0!==this.IP.levels&&this.IP.levels.length>0&&this.VP.updateRatios(this.IP.levels.map(fl)),this.zy(),this.IP.interactive?this.kC():(this.xC=!0,this.LP())}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new pl(this)}drawToCanvas(t,i,s){if(!this.xC&&this.IP.point1Time&&this.PC)return void this.BC(t,i,s);if(!this.Yb||!this.IP.point1Time||!this.IP.point2Time)return;const n=(Xn(this._chart,this._series,this.IP.point1Time)??0)*i,e=(Xn(this._chart,this._series,this.IP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.mC?2:this.IP.lineWidth;this.Yb.levels.forEach(n=>{this.gx(t,n,r,h,i,s,l)}),!this.mC&&!this.wC||this.isLocked()||(this.OC(t,n,(this._series.priceToCoordinate(this.IP.point1Price)??0)*s,i),this.OC(t,e,(this._series.priceToCoordinate(this.IP.point2Price)??0)*s,i))}gx(t,i,s,n,e,r,h=1){const l=i.ratio??i.kP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.IP.levelColors?.[l.toString()]||this.IP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.IP.showLabels&&this.NC(t,i,s,n,a,e,_)}NC(t,i,s,n,e,r,h){const l=i.label??i.Zl,o=i.price??i.bt,a=`${l} ${this.VP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.IP.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.IP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}LP(){this.IP.point1Time&&this.IP.point1Price&&this.IP.point2Time&&this.IP.point2Price&&(this.Yb=this.VP.calculateLevels(this.IP.point1Time,this.IP.point1Price,this.IP.point2Time,this.IP.point2Price),this.IP.onUpdate&&this.Yb&&this.IP.onUpdate(this.Yb))}updatePoints(t,i,s,n){this.IP.point1Time=t,this.IP.point1Price=i,this.IP.point2Time=s,this.IP.point2Price=n,this.LP(),this.cM()}getMetrics(){return this.Yb}getLevels(){return this.Yb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.VP.getRatioValues();return{type:"fibRetracement",points:[Ch(this.IP.point1Price??0,xh(this.IP.point1Time)),Ch(this.IP.point2Price??0,xh(this.IP.point2Time))],style:{lineColor:this.IP.lineColor,lineWidth:this.IP.lineWidth,showLabels:this.IP.showLabels,labelPosition:this.IP.labelPosition,levelColors:this.IP.levelColors},extra:{levels:t,useExtended:this.IP.useExtended}}}useExtendedLevels(t){this.IP.useExtended=t,t?this.VP.useExtendedRatios():this.VP.useStandardRatios(),this.LP(),this.cM()}kC(){this.RP=new Ah(this._chart,this._series,{uC:t=>{this.IP.point1Time=t.gt,this.IP.point1Price=t.bt,this.cM()},cC:t=>{this.IP.point2Time=t.gt,this.IP.point2Price=t.bt},dC:(t,i)=>{this.IP.point1Time=t.gt,this.IP.point1Price=t.bt,this.IP.point2Time=i.gt,this.IP.point2Price=i.bt,this.xC=!0,this.PC=null,this.LP(),this.AP(),this.cM()},pC:t=>{this.PC=t,this.cM()}}),this.RP.tC()}BC(t,i,s){if(!this.IP.point1Time||!this.PC)return;const n=(Xn(this._chart,this._series,this.IP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.IP.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.PC.gt)??0)*i,h=(this._series.priceToCoordinate(this.PC.bt)??0)*s,l=this.VP.calculateLevels(this.IP.point1Time,this.IP.point1Price,this.PC.gt,this.PC.bt),o=Math.min(n,r),a=Math.max(n,r);t.setLineDash([5*i,5*i]),t.globalAlpha=.7,l.levels.forEach(n=>{const e=n.ratio??n.kP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.IP.levelColors?.[e.toString()]||this.IP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.IP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.IP.showLabels){const s=`${n.label??n.Zl} ${this.VP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.IP.labelPosition?a+_:o-e.width-_,c=h;t.fillStyle="rgba(255, 255, 255, 0.8)",t.fillRect(u-_/2,c-11*i/2-_/2,e.width+_,11*i+_),t.fillStyle=l,t.textAlign="right"===this.IP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.OC(t,n,e,i),t.globalAlpha=.6,this.OC(t,r,h,i),t.globalAlpha=1}OC(t,i,s,n){const e=this.IP.lineColor,r=this.mC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.mC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}AP(){this.sp=t=>{this.EP(t)},this._chart.subscribeCrosshairMove(this.sp)}BP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}EP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.mC||!this.gC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.FP?(this.IP.point1Time=i,this.IP.point1Price=s):"point2"===this.FP&&(this.IP.point2Time=i,this.IP.point2Price=s),this.LP(),this.cM())}startDrag(t){this.gC=!0,this.FP=t}stopDrag(){this.gC=!1,this.FP=null}updateDrag(t,i){this.gC&&this.FP&&("point1"===this.FP?(this.IP.point1Time=t,this.IP.point1Price=i):(this.IP.point2Time=t,this.IP.point2Price=i),this.LP(),this.cM())}hitTestEndpoint(t,i){if(!this.xC||!this.IP.point1Time||!this.IP.point2Time)return null;const s=Xn(this._chart,this._series,this.IP.point1Time)??0,n=this._series.priceToCoordinate(this.IP.point1Price)??0,e=Xn(this._chart,this._series,this.IP.point2Time)??0,r=this._series.priceToCoordinate(this.IP.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.IP={...this.IP,...t},void 0!==t.levels&&t.levels.length>0?this.VP.updateRatios(t.levels.map(fl)):void 0!==t.useExtended&&(t.useExtended?this.VP.useExtendedRatios():this.VP.useStandardRatios()),super.applyOptions(t),this.LP(),this.cM()}options(){return{...this.IP,levels:this.VP.getRatioValues()}}setColor(t){this.IP.lineColor=t,this.cM()}color(){return this.IP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}isSelected(){return this.mC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.xC||!this.IP.point1Time||!this.IP.point2Time)return!1;const s=Xn(this._chart,this._series,this.IP.point1Time)??0,n=Xn(this._chart,this._series,this.IP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Yb)return!1;for(const t of this.Yb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.xC}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.RP&&(this.RP.m(),this.RP=null),this.BP(),this.IP.onRemove&&this.IP.onRemove()}destroy(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.IP.onRemove&&this.IP.onRemove()}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.LP(),this.cM()}}function ml(t,i){return new vl(t,i)}class wl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class gl{constructor(t){this.fC=t,this.Jt=new wl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}}class bl extends Dh{constructor(t,i){super(t,"fibonacci-extension",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.IP={levels:[{level:0,color:"#787B86",label:"0%"},{level:.618,color:"#2962FF",label:"61.8%"},{level:1,color:"#787B86",label:"100%"},{level:1.618,color:"#F23645",label:"161.8%"},{level:2.618,color:"#9C27B0",label:"261.8%"}],lineColor:"#787B86",lineWidth:1,showLabels:!0,extendLines:!0,...i},this.zy()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new gl(this)}getPoint1(){return this.IP.point1}getPoint2(){return this.IP.point2}getPoint3(){return this.IP.point3}getLevels(){return this.IP.levels||[]}getOptions(){return this.IP}setPoint1(t){this.IP.point1=t,this.cM()}setPoint2(t){this.IP.point2=t,this.cM()}setPoint3(t){this.IP.point3=t,this.cM()}isComplete(){return!!(this.IP.point1&&this.IP.point2&&this.IP.point3)}setColor(t){this.IP.lineColor=t,this.cM()}color(){return this.IP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.IP.point1,this.IP.point2,this.IP.point3];for(const n of s){const s=Xn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=10)return!0}const n=this.OP();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.IP.point1,n=this.IP.point2,e=this.IP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Xn(this._chart,this._series,s.time)??0,e=this._series.priceToCoordinate(s.price)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=20)return"point1"}if(n&&n.time&&void 0!==n.price){const s=Xn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=20)return"point2"}if(e&&e.time&&void 0!==e.price){const s=Xn(this._chart,this._series,e.time)??0,n=this._series.priceToCoordinate(e.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=20)return"point3"}return null}startDrag(t){this.gC=!0,this.bC=t}stopDrag(){this.gC=!1,this.bC=null}updateDrag(t,i){if(!this.gC||!this.bC)return;const s={time:t,price:i};switch(this.bC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.IP.onUpdate&&this.IP.onUpdate()}OP(){if(!this.isComplete())return[];const t=this.IP.point1,i=this.IP.point2,s=this.IP.point3,n=i.price-t.price;return(this.IP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Zl:t.label,R:t.color}))}getExtensionLevels(){return this.OP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.IP.point1,e=this.IP.point2,r=this.IP.point3,h=this.mC||this.wC&&!this.isLocked(),l=(Xn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Xn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Xn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.IP.lineColor||"#787B86",t.lineWidth=(this.IP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Zl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.IP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.IP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.IP.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Zl:"A"},{ut:a,ct:_,Zl:"B"},{ut:u,ct:c,Zl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Zl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[Ph(this.IP.point1),Ph(this.IP.point2),Ph(this.IP.point3)],style:{lineColor:this.IP.lineColor,lineWidth:this.IP.lineWidth,showLabels:this.IP.showLabels,extendLines:this.IP.extendLines},extra:{levels:(this.IP.levels||[]).map(t=>({sn:t.level,R:t.color,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null)}}function Ml(t,i){return new bl(t,i)}class yl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Sl{constructor(t){this.fC=t,this.Jt=new yl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const xl=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Cl extends Dh{constructor(t,i){super(t,"fibonacci-fan",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.WP=!1,this.qS=null,this.sp=null,this.PC=null,this.zP={levels:xl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.zy(),this.zP.interactive&&!this.zP.point1Time&&this.kC()}kC(){this.WP=!0,this.qS=t=>{if(!t.point)return;if(Ih(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.zP.point1Time?(this.zP.point2Time=i,this.zP.point2Price=s,this.WP=!1,this.PC=null,this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.zP.onUpdate&&this.zP.onUpdate()):(this.zP.point1Time=i,this.zP.point1Price=s,this.cM()))},this.sp=t=>{if(this.WP&&this.zP.point1Time)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.PC={gt:i,bt:s},this.cM())}else this.PC=null,this.cM()},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new Sl(this)}drawToCanvas(t,i,s){const n=this.zP.point1Time,e=this.zP.point1Price,r=this.WP&&this.PC?this.PC.gt:this.zP.point2Time,h=this.WP&&this.PC?this.PC.bt:this.zP.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.mC?this.zP.lineWidth+1:this.zP.lineWidth;if(this.$P(t,l,o,a,_,"#2962FF",u*i),this.zP.levels)for(const n of this.zP.levels)this.HP(t,l,o,a,_,n,i,s,undefined,u);!this.mC&&!this.wC||this.WP||this.isLocked()||(this.OC(t,l,o,i,"#2962ff"),this.OC(t,a,_,i,"#2962ff"))}HP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.zP.extendLines){const t=this._chart.chartElement().clientWidth*h,n=_-i,e=u-s,r=Math.sqrt(n*n+e*e);if(r>0){const h=2*t;c=i+n/r*h,d=s+e/r*h}}const p=o||r.color;this.$P(t,i,s,c,d,p,a*h),this.zP.showLabels&&!this.WP&&this.NC(t,_,u,r.label,h,p)}$P(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()}OC(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()}NC(t,i,s,n,e,r){const h=11*e,l=4*e;t.font=`${h}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const o=t.measureText(n).width,a=h;t.fillStyle=r,t.fillRect(i+l,s-a-l,o+2*l,a+2*l),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(n,i+2*l,s-a-l+l)}setColor(t){const i=this.zP.levels??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.zP.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.zP.point1Time||!this.zP.point2Time)return!1;const s=Xn(this._chart,this._series,this.zP.point1Time)??0,n=this._series.priceToCoordinate(this.zP.point1Price)??0,e=Xn(this._chart,this._series,this.zP.point2Time)??0,r=this._series.priceToCoordinate(this.zP.point2Price)??0;if(this.WC(t,i,s,n,e,r)<=8)return!0;if(this.zP.levels)for(const h of this.zP.levels){const l=n+(r-n)*h.level,o=e;if(this.WC(t,i,s,n,o,l)<=8)return!0}return!1}WC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.zP.point1Time||!this.zP.point2Time)return null;const s=Xn(this._chart,this._series,this.zP.point1Time)??0,n=this._series.priceToCoordinate(this.zP.point1Price)??0,e=Xn(this._chart,this._series,this.zP.point2Time)??0,r=this._series.priceToCoordinate(this.zP.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.gC=!0,this.bC=t}stopDrag(){this.gC=!1,this.bC=null}updateDrag(t,i){this.gC&&this.bC&&("point1"===this.bC?(this.zP.point1Time=t,this.zP.point1Price=i):"point2"===this.bC&&(this.zP.point2Time=t,this.zP.point2Price=i),this.cM(),this.zP.onUpdate&&this.zP.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Ch(this.zP.point1Price??0,xh(this.zP.point1Time)),Ch(this.zP.point2Price??0,xh(this.zP.point2Time))],style:{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,Zl:t.label}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return!this.WP}remove(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.zP.onRemove&&this.zP.onRemove()}}function Pl(t,i){return new Cl(t,i)}class Tl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.fC=t,this.Jt=new Tl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends Dh{constructor(t,i){super(t,"rectangle",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.yC=null,this.SC=null,this.WP=!1,this.qS=null,this.sp=null,this.PC=null,this.NP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.NP),this.zy(),!this.NP.interactive||this.NP.time1&&this.NP.time2||this.kC()}kC(){this.WP=!0,this.qS=t=>{if(!t.point)return;if(Ih(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.NP.time1?(this.NP.time2=i,this.NP.price2=s,this.WP=!1,this.PC=null,this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.NP.onUpdate&&this.NP.onUpdate()):(this.NP.time1=i,this.NP.price1=s,this.cM()))},this.sp=t=>{if(this.WP&&this.NP.time1)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.PC={gt:i,bt:s},this.cM())}else this.PC=null,this.cM()},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new kl(this)}drawToCanvas(t,i,s){const n=this.NP.time1,e=this.NP.price1,r=this.WP&&this.PC?this.PC.gt:this.NP.time2,h=this.WP&&this.PC?this.PC.bt:this.NP.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Xn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Xn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=Math.min(l,a),c=Math.max(l,a),d=Math.min(o,_),p=Math.max(o,_),f=c-u,v=p-d;if(this.NP.fillOpacity>0){const i=this.Oy(this.NP.fillColor,this.WP?.1:this.NP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.NP.borderColor,w=this.mC?this.NP.borderWidth+1:this.NP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.NP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.NP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.mC&&!this.wC||this.WP||this.isLocked()||this.UP(t,u,d,c,p,i,m),this.NP.showLabel&&this.NP.labelText&&!this.WP&&this.NC(t,u,d,c,p,i,s,m)}UP(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s},{ut:n,ct:s},{ut:i,ct:e},{ut:n,ct:e}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}NC(t,i,s,n,e,r,h,l){const o=6*r,a=12*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.NP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.NP.labelPosition){case"top-right":c=n-_-2*o,d=s+o;break;case"bottom-left":c=i+o,d=e-u-2*o;break;case"bottom-right":c=n-_-2*o,d=e-u-2*o;break;case"center":c=(i+n)/2-_/2-o,d=(s+e)/2-u/2-o}t.fillStyle=l,t.fillRect(c,d,_+2*o,u+2*o),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.NP.labelText,c+o,d+o)}Oy(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.NP.borderColor=t,this.NP.fillColor=t,this.cM()}color(){return this.NP.borderColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.NP.time1||!this.NP.time2)return!1;const s=Xn(this._chart,this._series,this.NP.time1)??0,n=this._series.priceToCoordinate(this.NP.price1)??0,e=Xn(this._chart,this._series,this.NP.time2)??0,r=this._series.priceToCoordinate(this.NP.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r);return t>=h&&t<=l&&i>=o&&i<=a}hitTestEndpoint(t,i){if(!this.NP.time1||!this.NP.time2)return null;const s=Xn(this._chart,this._series,this.NP.time1)??0,n=this._series.priceToCoordinate(this.NP.price1)??0,e=Xn(this._chart,this._series,this.NP.time2)??0,r=this._series.priceToCoordinate(this.NP.price2)??0,h=Math.min(s,e),l=Math.max(s,e),o=Math.min(n,r),a=Math.max(n,r),_=10;return Math.abs(t-h)<=_&&Math.abs(i-o)<=_?"corner1":Math.abs(t-l)<=_&&Math.abs(i-o)<=_?"corner2":Math.abs(t-h)<=_&&Math.abs(i-a)<=_?"corner3":Math.abs(t-l)<=_&&Math.abs(i-a)<=_?"corner4":t>=h&&t<=l&&i>=o&&i<=a?"body":null}startDrag(t,i){this.gC=!0,this.bC=t,this.MC=i,"body"===t&&(this.yC={gt:this.NP.time1,bt:this.NP.price1},this.SC={gt:this.NP.time2,bt:this.NP.price2})}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.yC=null,this.SC=null}updateDrag(t,i){if(!this.gC||!this.bC)return;const s=Xn(this._chart,this._series,this.NP.time1)??0,n=this._series.priceToCoordinate(this.NP.price1)??0,e=s<(Xn(this._chart,this._series,this.NP.time2)??0),r=n<(this._series.priceToCoordinate(this.NP.price2)??0);if("body"===this.bC&&this.yC&&this.SC){const s=yh(this.MC,t,i);this.NP.time1=this.yC.gt+s.gt,this.NP.price1=this.yC.bt+s.bt,this.NP.time2=this.SC.gt+s.gt,this.NP.price2=this.SC.bt+s.bt}else switch(this.bC){case"corner1":e&&r?(this.NP.time1=t,this.NP.price1=i):!e&&r?(this.NP.time2=t,this.NP.price1=i):e&&!r?(this.NP.time1=t,this.NP.price2=i):(this.NP.time2=t,this.NP.price2=i);break;case"corner2":e&&r?(this.NP.time2=t,this.NP.price1=i):!e&&r?(this.NP.time1=t,this.NP.price1=i):e&&!r?(this.NP.time2=t,this.NP.price2=i):(this.NP.time1=t,this.NP.price2=i);break;case"corner3":e&&r?(this.NP.time1=t,this.NP.price2=i):!e&&r?(this.NP.time2=t,this.NP.price2=i):e&&!r?(this.NP.time1=t,this.NP.price1=i):(this.NP.time2=t,this.NP.price1=i);break;case"corner4":e&&r?(this.NP.time2=t,this.NP.price2=i):!e&&r?(this.NP.time1=t,this.NP.price2=i):e&&!r?(this.NP.time2=t,this.NP.price1=i):(this.NP.time1=t,this.NP.price1=i)}this.cM(),this.NP.onUpdate&&this.NP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Ch(this.NP.price1??0,xh(this.NP.time1)),Ch(this.NP.price2??0,xh(this.NP.time2))],style:{fillColor:this.NP.fillColor,fillOpacity:this.NP.fillOpacity,borderColor:this.NP.borderColor,borderWidth:this.NP.borderWidth,borderStyle:this.NP.borderStyle,showLabel:this.NP.showLabel,labelText:this.NP.labelText,labelPosition:this.NP.labelPosition}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return!this.WP}remove(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.NP.onRemove&&this.NP.onRemove()}}function Rl(t,i){return new Dl(t,i)}class Fl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Il{constructor(t){this.fC=t,this.Jt=new Fl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vl extends Dh{constructor(t,i){super(t,"circle",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.hP=null,this.WP=!1,this.qS=null,this.sp=null,this.PC=null,this.qP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.qP),this.zy(),this.qP.interactive&&!this.qP.centerTime&&this.kC()}kC(){this.WP=!0,this.qS=t=>{if(!t.point)return;if(Ih(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.qP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.qP.centerTime)??0,n=this._series.priceToCoordinate(this.qP.centerPrice)??0,e=Xn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.qP.radiusTime=Math.abs(e-t),this.qP.radiusPrice=Math.abs(r-n),this.WP=!1,this.PC=null,this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.cM(),this.qP.onUpdate&&this.qP.onUpdate()}else this.qP.centerTime=i,this.qP.centerPrice=s,this.cM()},this.sp=t=>{if(this.WP&&this.qP.centerTime)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.PC={gt:i,bt:s},this.cM())}else this.PC=null,this.cM()},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.sp)}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new Il(this)}drawToCanvas(t,i,s){if(!this.qP.centerTime||void 0===this.qP.centerPrice)return;const n=(Xn(this._chart,this._series,this.qP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.qP.centerPrice)??0)*s;let r,h;if(this.WP&&this.PC){const t=(Xn(this._chart,this._series,this.PC.gt)??0)*i,l=(this._series.priceToCoordinate(this.PC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.qP.radiusTime||void 0===this.qP.radiusPrice)return;r=this.qP.radiusTime*i,h=this.qP.radiusPrice*s}if(this.qP.fillOpacity>0){const i=this.Oy(this.qP.fillColor,this.WP?.05:this.qP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.qP.borderColor,o=this.mC?this.qP.borderWidth+1:this.qP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.qP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.qP.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.mC&&!this.wC||this.WP||this.isLocked()||this.jP(t,n,e,i,l),!this.mC&&!this.wC||this.WP||this.isLocked()||this.YP(t,n,e,r,h,i,l),this.qP.showLabel&&this.qP.labelText&&!this.WP&&this.NC(t,n,e,i,l)}jP(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()}YP(t,i,s,n,e,r,h){const l=8*r,o=[{ut:i,ct:s-e},{ut:i+n,ct:s},{ut:i,ct:s+e},{ut:i-n,ct:s}];t.fillStyle=h,t.strokeStyle="#ffffff",t.lineWidth=2*r;for(const i of o)t.fillRect(i.ut-l/2,i.ct-l/2,l,l),t.strokeRect(i.ut-l/2,i.ct-l/2,l,l)}NC(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.qP.labelText).width,o=h,a=i-l/2-r,_=s-o/2-r;t.fillStyle=e,t.fillRect(a,_,l+2*r,o+2*r),t.fillStyle="#ffffff",t.textBaseline="top",t.fillText(this.qP.labelText,a+r,_+r)}Oy(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.qP.borderColor=t,this.qP.fillColor=t,this.cM()}color(){return this.qP.borderColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.qP.centerTime||void 0===this.qP.radiusTime)return!1;const s=Xn(this._chart,this._series,this.qP.centerTime)??0,n=this._series.priceToCoordinate(this.qP.centerPrice)??0,e=(t-s)/this.qP.radiusTime,r=(i-n)/this.qP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.qP.centerTime||void 0===this.qP.radiusTime)return null;const s=Xn(this._chart,this._series,this.qP.centerTime)??0,n=this._series.priceToCoordinate(this.qP.centerPrice)??0,e=this.qP.radiusTime,r=this.qP.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.gC=!0,this.bC=t,this.MC=i,this.hP="center"===t?{gt:this.qP.centerTime,bt:this.qP.centerPrice}:null}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.hP=null}updateDrag(t,i){if(this.gC&&this.bC){if("center"===this.bC&&this.hP){const s=yh(this.MC,t,i);this.qP.centerTime=this.hP.gt+s.gt,this.qP.centerPrice=this.hP.bt+s.bt}else if("edge"===this.bC){const s=Xn(this._chart,this._series,this.qP.centerTime)??0,n=this._series.priceToCoordinate(this.qP.centerPrice)??0,e=Xn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.qP.radiusTime=Math.abs(e-s),this.qP.radiusPrice=Math.abs(r-n)}this.cM(),this.qP.onUpdate&&this.qP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Ch(this.qP.centerPrice??0,xh(this.qP.centerTime))],style:{fillColor:this.qP.fillColor,fillOpacity:this.qP.fillOpacity,borderColor:this.qP.borderColor,borderWidth:this.qP.borderWidth,borderStyle:this.qP.borderStyle,showLabel:this.qP.showLabel,labelText:this.qP.labelText},extra:{radiusTime:this.qP.radiusTime,radiusPrice:this.qP.radiusPrice}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return!this.WP}remove(){this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.qP.onRemove&&this.qP.onRemove()}}function Ll(t,i){return new Vl(t,i)}class Al{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.fC=t,this.Jt=new Al(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends Dh{constructor(t,i){super(t,"arrow",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.XP=-1,this.WP=!1,this.qS=null,this.GP=null,this.sp=null,this.PC=null,this.KP={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.KP),this.zy(),!this.KP.interactive||this.KP.points&&0!==this.KP.points.length||this.kC()}kC(){this.WP=!0,this.qS=t=>{if(!t.point)return;if(Ih(this._chart))return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.KP.points||(this.KP.points=[]),this.KP.points.push({time:i,price:s}),this.cM(),this.KP.onUpdate&&this.KP.onUpdate())},this.sp=t=>{if(this.WP)if(t.point){const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.PC={gt:i,bt:s},this.cM())}else this.PC=null,this.cM()},this.GP=t=>{this.WP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.qS),this._chart.subscribeCrosshairMove(this.sp);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.GP)}finishDrawing(){if(this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.GP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.GP),this.GP=null}this.WP=!1,this.PC=null,this.cM(),this.KP.onComplete&&this.KP.onComplete()}isDrawing(){return this.WP}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new El(this)}drawToCanvas(t,i,s){if(!this.KP.points||0===this.KP.points.length)return;const n=this.KP.lineColor,e=this.mC||this.wC&&!this.isLocked()?this.KP.lineWidth+1:this.KP.lineWidth,r=[];for(const t of this.KP.points)try{let n=Xn(this._chart,this._series,t.time);if(null===n){const i=this._chart.timeScale(),s=i.timeToIndex(t.time,!0);null!=s&&(n=i.logicalToCoordinate(s))}if(null==n)continue;const e=this._series.priceToCoordinate(t.price);if(null===e)continue;r.push({ut:n*i,ct:e*s})}catch{continue}if(0===r.length&&!this.WP)return;let h=null;if(this.WP&&this.PC&&this.KP.points.length>0){h={ut:(Xn(this._chart,this._series,this.PC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.PC.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.KP.showArrowHead&&r.length>1&&this.ZP(t,r[r.length-2],r[r.length-1],i,n),this.KP.showCircles)for(let s=0;s<r.length;s++)this.JP(t,r[s].ut,r[s].ct,i,n,0===s)}ZP(t,i,s,n,e){const r=12*n,h=Math.atan2(s.ct-i.ct,s.ut-i.ut),l={ut:s.ut-r*Math.cos(h-Math.PI/6),ct:s.ct-r*Math.sin(h-Math.PI/6)},o={ut:s.ut-r*Math.cos(h+Math.PI/6),ct:s.ct-r*Math.sin(h+Math.PI/6)};t.fillStyle=e,t.beginPath(),t.moveTo(s.ut,s.ct),t.lineTo(l.ut,l.ct),t.lineTo(o.ut,o.ct),t.closePath(),t.fill()}JP(t,i,s,n,e,r){const h=this.KP.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.KP.lineColor=t,this.cM()}color(){return this.KP.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.KP.points||0===this.KP.points.length)return!1;for(let s=0;s<this.KP.points.length-1;s++)try{const n=this.KP.points[s],e=this.KP.points[s+1];let r=Xn(this._chart,this._series,n.time);if(null===r){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(r=t.logicalToCoordinate(i))}let h=Xn(this._chart,this._series,e.time);if(null===h){const t=this._chart.timeScale(),i=t.timeToIndex(e.time,!0);null!=i&&(h=t.logicalToCoordinate(i))}const l=this._series.priceToCoordinate(n.price),o=this._series.priceToCoordinate(e.price);if(null==r||null===l||null==h||null===o)continue;if(this.WC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.KP.points)try{let n=Xn(this._chart,this._series,s.time);if(null===n){const t=this._chart.timeScale(),i=t.timeToIndex(s.time,!0);null!=i&&(n=t.logicalToCoordinate(i))}const e=this._series.priceToCoordinate(s.price);if(null==n||null===e)continue;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-e,2))<=8)return!0}catch{continue}return!1}WC(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;if(0===o)return Math.sqrt((t-s)*(t-s)+(i-n)*(i-n));let a=((t-s)*h+(i-n)*l)/o;a=Math.max(0,Math.min(1,a));const _=s+a*h,u=n+a*l;return Math.sqrt((t-_)*(t-_)+(i-u)*(i-u))}hitTestEndpoint(t,i){if(!this.KP.points||0===this.KP.points.length)return null;for(let s=0;s<this.KP.points.length;s++)try{const n=this.KP.points[s];let e=Xn(this._chart,this._series,n.time);if(null===e){const t=this._chart.timeScale(),i=t.timeToIndex(n.time,!0);null!=i&&(e=t.logicalToCoordinate(i))}const r=this._series.priceToCoordinate(n.price);if(null==e||null===r)continue;if(Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10)return s}catch{continue}return null}startDrag(t){this.gC=!0,this.XP=t}stopDrag(){this.gC=!1,this.XP=-1}updateDrag(t,i){this.gC&&-1!==this.XP&&this.KP.points&&this.XP>=0&&this.XP<this.KP.points.length&&(this.KP.points[this.XP]={time:t,price:i},this.cM(),this.KP.onUpdate&&this.KP.onUpdate())}getPoints(){return this.KP.points||[]}addPoint(t){this.KP.points||(this.KP.points=[]),this.KP.points.push(t),this.cM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.KP.points||[]).map(t=>Ph(t)),style:{lineColor:this.KP.lineColor,lineWidth:this.KP.lineWidth,showArrowHead:this.KP.showArrowHead,showCircles:this.KP.showCircles,circleRadius:this.KP.circleRadius}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return!this.WP}remove(){if(this.qS&&(this._chart.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null),this.GP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.GP),this.GP=null}this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.KP.onRemove&&this.KP.onRemove()}}function Ol(t,i){return new Bl(t,i)}class Wl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.fC=t,this.Jt=new Wl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class $l extends Dh{constructor(t,i){super(t,"brush",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.QP=!1,this.WP=!1,this.tT=[],this.iT=!1,this.kf=null,this._S=null,this.mS=null,this.gS=null,this.MS=null,this.sT=void 0,this.fS=null,this.gC=!1,this.MC=null,this.YC=null,this.nT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.nT),this.zy(),0===(this.nT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.QP)return;const t=this._chart.chartElement();t&&(this.kf=t,this.QP=!0,this.mS=t=>this.wS(t),this.gS=t=>this.bS(t),this.MS=()=>this.yS(),this.fS=t=>{this.sT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.fS),t.addEventListener("pointerdown",this.mS,!0),t.addEventListener("pointermove",this.gS,!0),t.addEventListener("pointerup",this.MS,!0),t.addEventListener("pointercancel",this.MS,!0))}stopDrawingMode(){if(!this.QP)return;this.eT(),this.QP=!1;const t=this.kf;t&&(this.mS&&t.removeEventListener("pointerdown",this.mS,!0),this.gS&&t.removeEventListener("pointermove",this.gS,!0),this.MS&&(t.removeEventListener("pointerup",this.MS,!0),t.removeEventListener("pointercancel",this.MS,!0))),this.fS&&(this._chart.unsubscribeCrosshairMove(this.fS),this.fS=null),this.mS=null,this.gS=null,this.MS=null,this.kf=null}isDrawingModeActive(){return this.QP}wS(t){if(this.rT())return;const i=this.hT(t);null!==i&&(this.WP=!0,this.tT=[i],this._S=t.pointerId,Fh(this._chart,!0),this.kf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.lT())}bS(t){if(!this.WP)return;const i=this.hT(t);if(null===i)return;const s=this.tT[this.tT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.nT.sampleDistance??4)||(this.tT.push(i),t.preventDefault(),t.stopPropagation(),this.lT())}yS(){this.WP&&this.eT()}eT(){if(!this.WP)return;this.WP=!1,this.ES();const t=[];for(const i of this.tT){const s=Yn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.tT=[],t.length<2?this.cM():(this.nT.points=t,this.stopDrawingMode(),this.cM(),this.nT.onUpdate&&this.nT.onUpdate(),this.nT.onComplete&&this.nT.onComplete())}rT(){const t=this.sT;return"string"==typeof t&&t.split("#")[0]!==this.id}ES(){null!==this._S&&(this.kf&&this.kf.hasPointerCapture(this._S)&&this.kf.releasePointerCapture(this._S),this._S=null)}hT(t){const i=this.oT();if(null===i)return null;const s=i.getBoundingClientRect();return{ut:t.clientX-s.left,ct:t.clientY-s.top}}oT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}lT(){this.iT||(this.iT=!0,requestAnimationFrame(()=>{this.iT=!1,this.cM()}))}drawToCanvas(t,i,s){const n=this.WP?this.tT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.aT(i,s);if(0===n.length)return;const e=this.mC;if(t.strokeStyle=this.nT.color,t.lineWidth=(this.nT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.nT.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.wC||this.isLocked()||(this.OC(t,n[0],i),this.OC(t,n[n.length-1],i))}OC(t,i,s){t.fillStyle=this.nT.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()}aT(t,i){const s=this.nT.points??[],n=[];for(const e of s){const s=Xn(this._chart,this._series,e.time),r=this._series.priceToCoordinate(e.price);null!==s&&null!==r&&n.push({ut:s*t,ct:r*i})}return n}hitTest(t,i){const s=this.aT(1,1);for(let n=1;n<s.length;n++)if(Hl(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.gC=!0,this.MC=i,this.YC=(this.nT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.YC;if(!this.gC||null===s||!this.nT.points)return;const n=yh(this.MC,t,i);this.nT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.cM(),this.nT.onUpdate&&this.nT.onUpdate()}stopDrag(){this.gC=!1,this.MC=null,this.YC=null}setColor(t){this.nT.color=t,this.cM()}color(){return this.nT.color??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}zy(){this.nh=new zl(this);const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.stopDrawingMode(),this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null),this.nh=null,this.nT.onRemove&&this.nT.onRemove()}_serializeShape(){return{type:"brush",points:(this.nT.points??[]).map(Ph),style:{color:this.nT.color,lineWidth:this.nT.lineWidth,smoothing:this.nT.smoothing}}}getPoints(){return this.nT.points??[]}}function Hl(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 Nl(t,i={}){return new $l(t,i)}class Ul{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ql{constructor(t){this.fC=t,this.Jt=new Ul(t)}renderer(){return this.fC.isComplete()?this.Jt:null}}class jl extends Dh{constructor(t,i){super(t,"text-tool",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.hP=null,this._T=!1,this.uT=null,this.cT={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.cT),this.zy(),this.dT()}dT(){const t=t=>{if(!this._T)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.cT.text&&""!==this.cT.text.trim()&&"Type here..."!==this.cT.text||this.remove())};this.uT=t,this._chart.subscribeClick(t)}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new ql(this)}getTime(){return this.cT.time}getPrice(){return this.cT.price}getText(){return this.cT.text||""}getOptions(){return this.cT}setPosition(t,i){this.cT.time=t,this.cT.price=i,this._update()}setText(t){this.cT.text=t,this._update(),this.cT.onTextChange&&this.cT.onTextChange(t)}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}isComplete(){return!(!this.cT.time||void 0===this.cT.price)}setColor(t){this.cT.textColor=t,this.cT.borderColor=t,this.cM()}color(){return this.cT.textColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this._update())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this._update())}isHovered(){return this.wC}setEditing(t){this._T!==t&&(this._T=t,this._update())}isEditing(){return this._T}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.cT.time,n=this.cT.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.cT.fontSize||14,l=this.cT.padding||8,o=this.cT.text||"",a=.6*h,_=Math.min(o.length*a,this.cT.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.cT.time,n=this.cT.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0;return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"anchor":null}startDrag(t,i){this.gC=!0,this.bC=t,this.MC=i,this.hP={gt:this.cT.time,bt:this.cT.price}}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.hP=null}updateDrag(t,i){if(this.gC){if("body"===this.bC&&this.hP){const s=yh(this.MC,t,i);this.setPosition(this.hP.gt+s.gt,this.hP.bt+s.bt)}else this.setPosition(t,i);this.cT.onUpdate&&this.cT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.cT.time,e=this.cT.price,r=this.cT.text||"",h=(Xn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.cT.fontSize||14)*i,a=(this.cT.padding||8)*i,_=(this.cT.maxWidth||200)*i;t.font=`${o}px ${this.cT.fontFamily||"Arial"}`,t.textBaseline="top";const u=r.split(" "),c=[];let d="";for(const i of u){const s=d?`${d} ${i}`:i;t.measureText(s).width>_&&d?(c.push(d),d=i):d=s}d&&c.push(d);let p=0;for(const i of c){const s=t.measureText(i);p=Math.max(p,s.width)}const f=p+2*a,v=1.2*o,m=c.length*v+2*a,w=this.cT.backgroundOpacity||.8,g=this.cT.backgroundColor||"#2962FF";t.fillStyle=this.Oy(g,w),t.fillRect(h,l,f,m),(this.mC||this.wC)&&(t.strokeStyle=this.cT.borderColor??"#FFFFFF",t.lineWidth=(this.cT.borderWidth||1)*i*(this.mC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.cT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.cT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.cT.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.mC||this.wC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.cT.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()}}Oy(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:[Ch(this.cT.price??0,xh(this.cT.time))],style:{fontSize:this.cT.fontSize,fontFamily:this.cT.fontFamily,textColor:this.cT.textColor,backgroundColor:this.cT.backgroundColor,backgroundOpacity:this.cT.backgroundOpacity,padding:this.cT.padding,borderColor:this.cT.borderColor,borderWidth:this.cT.borderWidth,textAlign:this.cT.textAlign,maxWidth:this.cT.maxWidth},extra:{text:this.cT.text}}}remove(){this.uT&&(this._chart.unsubscribeClick(this.uT),this.uT=null),this.Ub&&this._series&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.cT.onRemove&&this.cT.onRemove()}}function Yl(t,i){return new jl(t,i)}class Xl{constructor(t){this.pT=t}calculatePips(t,i){return Math.abs(i-t)/this.pT.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.pT={...this.pT,...t}}getPipConfig(){return{...this.pT}}}function Gl(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 Kl(t,i){return"number"==typeof t?Gl(t):void 0!==i?Gl(i):{pipValue:.1,decimals:1}}class Zl{constructor(t){this.pT=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.pT.pipValue,timeDifference:this.fT(t,s),barCount:e}}fT(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.pT={...this.pT,...t}}getPipConfig(){return{...this.pT}}}class Jl{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ql{constructor(t){this.fC=t,this.Jt=new Jl(t)}renderer(){return this.fC.isVisible()?this.Jt:null}}class to extends Dh{constructor(t,i){super(t,"ruler-tool",i),this.Ub=null,this.vC=null,this.Yb=null,this.nh=null,this.RP=null,this.xC=!1,this.mC=!1,this.wC=!1,this.PC=null,this.gC=!1,this.FP=null,this.sp=null,this.vT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.vT);const s=this.vT.pipConfig||Kl(this.vT.symbol||"DEFAULT");this.VP=new Zl(s),this.zy(),this.vT.interactive?this.kC():this.vT.point1Time&&this.vT.point2Time&&(this.xC=!0,this.LP())}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new Ql(this)}kC(){this.RP=new Ah(this._chart,this._series,{uC:t=>{this.vT.point1Time=t.gt,this.vT.point1Price=t.bt,this.cM()},cC:t=>{this.vT.point2Time=t.gt,this.vT.point2Price=t.bt},dC:(t,i)=>{this.vT.point1Time=t.gt,this.vT.point1Price=t.bt,this.vT.point2Time=i.gt,this.vT.point2Price=i.bt,this.xC=!0,this.PC=null,this.LP(),this.AP(),this.cM()},pC:t=>{this.PC=t,this.cM()}}),this.RP.tC()}drawToCanvas(t,i,s){if(!this.xC&&this.vT.point1Time&&this.PC)return void this.BC(t,i,s);if(!this.xC||!this.vT.point1Time||!this.vT.point2Time)return;const n=(Xn(this._chart,this._series,this.vT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.vT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.vT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.vT.point2Price)??0)*s;(this.mC||this.wC&&!this.isLocked())&&(t.strokeStyle=this.vT.selectionColor,t.lineWidth=this.vT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.vT.lineColor,t.lineWidth=this.vT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.mT(t,n,e,r,h,i),this.OC(t,n,e,i),this.OC(t,r,h,i),this.vT.showLabel&&this.Yb&&this.NC(t,n,e,r,h,i,s)}mT(t,i,s,n,e,r){const h=this.vT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.vT.lineColor,t.lineWidth=this.vT.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()}OC(t,i,s,n){const e=this.mC?this.vT.selectionColor:this.vT.lineColor,r=this.mC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.mC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}BC(t,i,s){if(!this.vT.point1Time||!this.PC)return;const n=(Xn(this._chart,this._series,this.vT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.vT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.PC.gt)??0)*i,h=(this._series.priceToCoordinate(this.PC.bt)??0)*s;t.strokeStyle=this.vT.lineColor,t.lineWidth=this.vT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.OC(t,n,e,i),t.globalAlpha=.5,this.OC(t,r,h,i),t.globalAlpha=1}NC(t,i,s,n,e,r,h){if(!this.Yb)return;const l=(i+n)/2,o=(s+e)/2,a=this.vT.measure??"both",_=[];"time"!==a&&(_.push(this.VP.formatPips(this.Yb.pips)),_.push(this.VP.formatPercent(this.Yb.pricePercent))),"price"!==a&&_.push(this.VP.formatBarCount(this.Yb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.vT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.vT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}LP(){if(!this.vT.point1Time||!this.vT.point2Time||void 0===this.vT.point1Price||void 0===this.vT.point2Price)return;const t=this.wT();this.Yb=this.VP.calculateMetrics(this.vT.point1Time,this.vT.point1Price,this.vT.point2Time,this.vT.point2Price,t),this.vT.onUpdate&&this.Yb&&this.vT.onUpdate(this.Yb)}wT(){if(!this.vT.point1Time||!this.vT.point2Time)return 0;const t=Xn(this._chart,this._series,this.vT.point1Time),i=Xn(this._chart,this._series,this.vT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.vT.point1Time=t,this.vT.point1Price=i,this.vT.point2Time=s,this.vT.point2Price=n,this.LP(),this.cM()}getMetrics(){return this.Yb}remove(){this.destroy()}destroy(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.RP&&(this.RP.m(),this.RP=null),this.BP(),this.vT.onRemove&&this.vT.onRemove()}AP(){this.sp=t=>{this.EP(t)},this._chart.subscribeCrosshairMove(this.sp)}BP(){this.sp&&(this._chart.unsubscribeCrosshairMove(this.sp),this.sp=null)}EP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.mC||!this.gC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.FP?(this.vT.point1Time=i,this.vT.point1Price=s):"point2"===this.FP&&(this.vT.point2Time=i,this.vT.point2Price=s),this.LP(),this.cM())}startDrag(t){this.gC=!0,this.FP=t}stopDrag(){this.gC=!1,this.FP=null}updateDrag(t,i){this.gC&&this.FP&&("point1"===this.FP?(this.vT.point1Time=t,this.vT.point1Price=i):(this.vT.point2Time=t,this.vT.point2Price=i),this.LP(),this.cM())}hitTestEndpoint(t,i){if(!this.xC||!this.vT.point1Time||!this.vT.point2Time)return null;const s=Xn(this._chart,this._series,this.vT.point1Time)??0,n=this._series.priceToCoordinate(this.vT.point1Price)??0,e=Xn(this._chart,this._series,this.vT.point2Time)??0,r=this._series.priceToCoordinate(this.vT.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.LP(),this.cM()}_serializeShape(){return{type:"ruler",points:[Ch(this.vT.point1Price??0,xh(this.vT.point1Time)),Ch(this.vT.point2Price??0,xh(this.vT.point2Time))],style:{lineColor:this.vT.lineColor,lineWidth:this.vT.lineWidth,showLabel:this.vT.showLabel,labelBackgroundColor:this.vT.labelBackgroundColor,labelTextColor:this.vT.labelTextColor,selectionColor:this.vT.selectionColor,selectionLineWidth:this.vT.selectionLineWidth},extra:{symbol:this.vT.symbol,pipConfig:this.vT.pipConfig,measure:this.vT.measure}}}setColor(t){this.vT.lineColor=t,this.cM()}color(){return this.vT.lineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}isSelected(){return this.mC}isComplete(){return this.xC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.xC||!this.vT.point1Time||!this.vT.point2Time)return!1;const s=Xn(this._chart,this._series,this.vT.point1Time)??0,n=this._series.priceToCoordinate(this.vT.point1Price)??0,e=Xn(this._chart,this._series,this.vT.point2Time)??0,r=this._series.priceToCoordinate(this.vT.point2Price)??0;return this.gT(t,i,s,n,e,r)<=(this.mC?12:8)}gT(t,i,s,n,e,r){const h=e-s,l=r-n,o=h*h+l*l;let a,_,u=-1;0!==o&&(u=((t-s)*h+(i-n)*l)/o),u<0?(a=s,_=n):u>1?(a=e,_=r):(a=s+u*h,_=n+u*l);const c=t-a,d=i-_;return Math.sqrt(c*c+d*d)}}function io(t,i){return new to(t,i)}class so{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class no{constructor(t){this.fC=t,this.Jt=new so(t)}renderer(){return this.fC.isVisible()?this.Jt:null}}class eo extends Dh{constructor(t,i){super(t,"position-tool",i),this.Ub=null,this.vC=null,this.Yb=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.bC=null,this.MC=null,this.hP=null,this.bT=null,this.MT=null,this.yT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.yT);const s=this.yT.pipConfig||Kl(this.yT.entryPrice);this.VP=new Xl(s),this.zy(),this.LP()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new no(this)}drawToCanvas(t,i,s){if(this.bT&&this.yT.takeProfit){const n=this._chart.timeScale();this.ST(t,this.bT,i,s,n),(this.wC||this.mC)&&this.NC(t,this.bT,"profit",i,s,n)}if(this.MT&&this.yT.stopLoss){const n=this._chart.timeScale();if(this.ST(t,this.MT,i,s,n),this.wC||this.mC){const n=this._chart.timeScale();this.NC(t,this.MT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.xT(t,i,s,n),this.yT.takeProfit){const n=this._chart.timeScale();this.OC(t,this.yT.takeProfit,this.yT.profitColor,i,s,n)}if(this.yT.stopLoss){const n=this._chart.timeScale();this.OC(t,this.yT.stopLoss,this.yT.lossColor,i,s,n)}}ST(t,i,s,n,e){const r=(Xn(this._chart,this._series,this.yT.entryTime)??0)*s;let h;if(this.yT.endTime)h=(Xn(this._chart,this._series,this.yT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.CT)??0)*n,o=(this._series.priceToCoordinate(i.PT)??0)*n;t.fillStyle=this.Oy(i.R,.15),t.fillRect(r,Math.min(l,o),h-r,Math.abs(o-l)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(r,o),t.lineTo(h,o),t.stroke()}xT(t,i,s,n){const e=(Xn(this._chart,this._series,this.yT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.yT.entryPrice)??0)*s;let h;if(this.yT.endTime)h=(Xn(this._chart,this._series,this.yT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.yT.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.yT.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const o=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(e,0),t.lineTo(e,o),t.stroke(),t.setLineDash([]),!this.mC&&!this.wC||this.isLocked())t.fillStyle=this.yT.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)}}LP(){this.yT.stopLoss&&this.yT.takeProfit&&(this.Yb=this.VP.calculateMetrics(this.yT.entryPrice,this.yT.stopLoss,this.yT.takeProfit,this.yT.quantity),this.TT(),this.yT.onUpdate&&this.Yb&&this.yT.onUpdate(this.Yb))}TT(){const t=this.kT();this.yT.takeProfit&&(this.bT={DT:this.yT.entryTime,RT:t,CT:this.yT.entryPrice,PT:this.yT.takeProfit,R:this.yT.profitColor,ky:this.yT.opacity}),this.yT.stopLoss&&(this.MT={DT:this.yT.entryTime,RT:t,CT:this.yT.entryPrice,PT:this.yT.stopLoss,R:this.yT.lossColor,ky:this.yT.opacity})}kT(){this._chart.timeScale().getVisibleLogicalRange();return this.yT.entryTime}NC(t,i,s,n,e,r){if(!this.Yb)return;const h=(Xn(this._chart,this._series,this.yT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.PT)??0)*e,o="profit"===s,a=o?this.Yb.takeProfitPips:this.Yb.stopLossPips,_=o?this.yT.takeProfit:this.yT.stopLoss,u=this.Yb.riskRewardRatio,c=o?`Objetivo: ${_?.toFixed(5)} (${a.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${a.toFixed(1)} pips)`;t.font=11*n+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const d=6*n,p=t.measureText(c).width+2*d,f=20*n,v=h+8*n,m=l-f/2;t.fillStyle=i.R,t.fillRect(v,m,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,v+d,l)}OC(t,i,s,n,e,r){const h=(Xn(this._chart,this._series,this.yT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i)??0)*e,o=s;let a;if(t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(h,l,5*n,0,2*Math.PI),t.fill(),t.stroke(),this.yT.endTime)a=(Xn(this._chart,this._series,this.yT.endTime)??0)*n;else{a=this._chart.chartElement().clientWidth*n-10*n}const _=8*n,u=s;t.fillStyle=u,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(a-_/2,l-_/2,_,_),t.strokeRect(a-_/2,l-_/2,_,_)}Oy(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.yT={...this.yT,...t},this.LP(),this._update()}getMetrics(){return this.Yb}setStopLoss(t){this.yT.stopLoss=t,this.LP(),this._update()}setTakeProfit(t){this.yT.takeProfit=t,this.LP(),this._update()}setEntryPrice(t){this.yT.entryPrice=t,this.LP(),this._update()}_serializeShape(){return{type:"position",points:[Ch(this.yT.entryPrice,xh(this.yT.entryTime))],style:{profitColor:this.yT.profitColor,lossColor:this.yT.lossColor,entryLineColor:this.yT.entryLineColor,opacity:this.yT.opacity,showTooltips:this.yT.showTooltips},extra:{endTime:xh(this.yT.endTime),stopLoss:this.yT.stopLoss,takeProfit:this.yT.takeProfit,quantity:this.yT.quantity,pipConfig:this.yT.pipConfig}}}setColor(t){this.yT.entryLineColor=t,this.cM()}color(){return this.yT.entryLineColor??""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):this.hitTest(t,i)?Mh(this.id,"body",!1):null}hitTest(t,i){if(!this.yT.stopLoss&&!this.yT.takeProfit)return!1;const s=Xn(this._chart,this._series,this.yT.entryTime)??0;let n;if(this.yT.endTime)n=Xn(this._chart,this._series,this.yT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.yT.takeProfit&&this.yT.stopLoss){const e=this._series.priceToCoordinate(this.yT.takeProfit)??0,r=this._series.priceToCoordinate(this.yT.stopLoss)??0,h=Math.min(e,r),l=Math.max(e,r);if(t>=s&&t<=n&&i>=h&&i<=l)return!0;const o=8;if(Math.abs(t-s)<=o&&i>=h&&i<=l)return!0}return!1}hitTestEndpoint(t,i){const s=Xn(this._chart,this._series,this.yT.entryTime)??0;let n;if(this.yT.endTime)n=Xn(this._chart,this._series,this.yT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.yT.takeProfit){const n=this._series.priceToCoordinate(this.yT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.yT.stopLoss){const n=this._series.priceToCoordinate(this.yT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.yT.takeProfit){const s=this._series.priceToCoordinate(this.yT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.yT.stopLoss){const s=this._series.priceToCoordinate(this.yT.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.yT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.yT.takeProfit&&this.yT.stopLoss){const e=this._series.priceToCoordinate(this.yT.takeProfit)??0,r=this._series.priceToCoordinate(this.yT.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.gC=!0,this.bC=t,this.MC=i,"move"===t&&(this.hP={FT:this.yT.entryPrice,IT:this.yT.entryTime??null,By:this.yT.endTime??null,VT:this.yT.takeProfit??null,LT:this.yT.stopLoss??null})}stopDrag(){this.gC=!1,this.bC=null,this.MC=null,this.hP=null}updateDrag(t,i){if(this.gC&&this.bC){if("entry"===this.bC)this.yT.entryPrice=i;else if("move"===this.bC){if(this.hP){const s=yh(this.MC,t,i),n=this.hP;this.yT.entryPrice=n.FT+s.bt,null!==n.VT&&(this.yT.takeProfit=n.VT+s.bt),null!==n.LT&&(this.yT.stopLoss=n.LT+s.bt),null!==n.IT&&(this.yT.entryTime=this.AT(n.IT,s.gt)),null!==n.By&&(this.yT.endTime=this.AT(n.By,s.gt))}}else"tp"===this.bC||"tp-right"===this.bC?(this.yT.takeProfit=i,"tp-right"===this.bC?this.yT.endTime=t:this.yT.entryTime=t):"sl"!==this.bC&&"sl-right"!==this.bC||(this.yT.stopLoss=i,"sl-right"===this.bC?this.yT.endTime=t:this.yT.entryTime=t);this.LP(),this.cM()}}AT(t,i){return t+i}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.yT.onRemove&&this.yT.onRemove()}}function ro(t,i){return new eo(t,i)}class ho{constructor(t){this.fC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.fC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class lo{constructor(t){this.fC=t,this.Jt=new ho(t)}renderer(){return this.fC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class oo extends Dh{constructor(t,i){super(t,"gantt",i),this.Ub=null,this.vC=null,this.nh=null,this.mC=!1,this.wC=!1,this.gC=!1,this.ET=-1,this.MC=null,this.hP=null,this.BT=-1,this.OT={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.OT),this.zy()}zy(){this.nh=this.DC();const t={attached:t=>{this.vC=t.requestUpdate},detached:()=>{this.vC=null},updateAllViews:()=>{},paneViews:()=>this.nh?[this.nh]:[],hitTest:(t,i)=>this.RC(t,i)};this.Ub=t,this._series.attachPrimitive(t),this.cM()}DC(){return new lo(this)}drawToCanvas(t,i,s){if(!this.OT.segments||0===this.OT.segments.length)return;const n=50*s,e=this.OT.rowHeight*s,r=this.OT.rowSpacing*s;this.OT.showGrid&&this.sm(t,n,e,r,i,s),this.OT.segments.forEach((s,h)=>{const l=(Xn(this._chart,this._series,s.startTime)??0)*i,o=(Xn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.BT||this.wC&&!this.isLocked();this.WT(t,l,o,a,e,s,_,i)})}sm(t,i,s,n,e,r){if(!this.OT.segments)return;const h=Math.max(...this.OT.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()}}WT(t,i,s,n,e,r,h,l){const o=s-i,a=this.Oy(r.color,h?this.OT.fillOpacity+.2:this.OT.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.OT.borderWidth+(this.mC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.OT.showLabels&&r.label&&this.NC(t,i,n,o,e,r.label,l)}NC(t,i,s,n,e,r,h){const l=11*h,o=6*h;t.font=`${l}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle="#ffffff",t.textBaseline="middle";let a=r;const _=n-2*o;let u=t.measureText(a).width;if(u>_&&_>0){for(;u>_&&a.length>0;)a=a.slice(0,-1),u=t.measureText(a+"...").width;a+="..."}t.fillText(a,i+o,s+e/2)}Oy(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.OT.segments||(this.OT.segments=[]),this.OT.segments.push(t),this.cM(),this.OT.onUpdate&&this.OT.onUpdate()}removeSegment(t){this.OT.segments&&t>=0&&t<this.OT.segments.length&&(this.OT.segments.splice(t,1),this.cM(),this.OT.onUpdate&&this.OT.onUpdate())}getSegments(){return this.OT.segments||[]}setColor(t){const i=this.OT.segments??[];for(const s of i)s.color=t;this.cM()}color(){const t=this.OT.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.mC!==t&&(this.mC=t,this.cM())}isSelected(){return this.mC}setHovered(t){this.wC!==t&&(this.wC=t,this.cM())}isHovered(){return this.wC}RC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.OT.segments?.[this.BT];s&&(this.gC=!0,this.ET=this.BT,this.MC=i,this.hP={Ey:s.startTime,By:s.endTime})}updateDrag(t,i){const s=this.OT.segments?.[this.ET];if(!this.gC||!this.hP||!s)return;const n=yh(this.MC,t,i);s.startTime=this.hP.Ey+n.gt,s.endTime=this.hP.By+n.gt,this.cM(),this.OT.onUpdate&&this.OT.onUpdate()}stopDrag(){this.gC=!1,this.ET=-1,this.MC=null,this.hP=null}hitTest(t,i){if(!this.OT.segments||0===this.OT.segments.length)return!1;const s=this.OT.rowHeight,n=this.OT.rowSpacing;for(let e=0;e<this.OT.segments.length;e++){const r=this.OT.segments[e],h=Xn(this._chart,this._series,r.startTime)??0,l=Xn(this._chart,this._series,r.endTime)??0,o=50+r.level*(s+n);if(t>=h&&t<=l&&i>=o&&i<=o+s)return this.BT=e,!0}return this.BT=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.OT.rowHeight,rowSpacing:this.OT.rowSpacing,fillOpacity:this.OT.fillOpacity,borderWidth:this.OT.borderWidth,showLabels:this.OT.showLabels,showGrid:this.OT.showGrid},extra:{segments:(this.OT.segments||[]).map(t=>({Ey:xh(t.startTime),By:xh(t.endTime),sn:t.level,Zl:t.label,R:t.color,zT:t.category}))}}}cM(){this.Ub&&this.Ub.updateAllViews?.(),this.vC?.()}_update(){this.cM()}remove(){this.Ub&&(this._series.detachPrimitive(this.Ub),this.Ub=null,this.nh=null),this.OT.onRemove&&this.OT.onRemove()}}function ao(t,i){return new oo(t,i)}class _o{constructor(t,i,s={}){this.$T=[],this.HT=[],this.NT=[],this.UT=!1,this.qT=new Map,this.jT=null,this.YT=null,this.XT=null,this.qS=null,this.GT=null,this.sp=null,this.KT=null,this.ZT=null,this.JT=null,this.QT=null,this.tk=null,this._S=null,this.ik=!1,this.sk=null,this.nk=null,this.ek=new a,this.gC=!1,this.rk=null,this.hk=new Set,this.lk=null,this.ak=new a,this.If=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this._k()}startDrawing(t){this.XT=t,this.uk()}activeDrawingType(){return this.XT}stopDrawing(){this.XT=null}addTool(t,i){const s=i??t.id;return this.qT.set(s,t),t.isComplete()||this.hk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.hk.size>0}cancelPendingDrawings(){if(0===this.hk.size)return 0;let t=0;for(const i of Array.from(this.hk)){const s=this.qT.get(i);s&&(this.jT===i&&this.ck(null),s.remove(),this.qT.delete(i),t++)}return this.hk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.ak.i(t)}unsubscribeDrawingCompleted(t){this.ak._(t)}dk(){0!==this.hk.size&&null===this.lk&&(this.lk=setTimeout(()=>{this.lk=null;for(const t of Array.from(this.hk)){const i=this.qT.get(t);i?i.isComplete()&&(this.hk.delete(t),this.ak.p(t)):this.hk.delete(t)}},0))}removeTool(t){const i=this.qT.get(t);return!!i&&(this.jT===t&&this.ck(null),i.remove(),this.qT.delete(t),this.hk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.qT.has(t)&&(this.ck(t),!0)}ck(t){if(this.jT===t)return;const i=null===this.jT?void 0:this.qT.get(this.jT);i&&i.setSelected(!1),this.jT=t;const s=null===t?void 0:this.qT.get(t);s&&s.setSelected(!0),this.pk()}recordChange(){this.UT||(this.$T.push(this.NT),this.$T.length>100&&this.$T.shift(),this.HT=[],this.NT=this.serializeAll())}canUndo(){return this.$T.length>0}canRedo(){return this.HT.length>0}undo(){const t=this.$T.pop();return void 0!==t&&(this.HT.push(this.NT),this.fk(t),!0)}redo(){const t=this.HT.pop();return void 0!==t&&(this.$T.push(this.NT),this.fk(t),!0)}fk(t){this.UT=!0;try{this.restoreAll({chart:this.If,series:this.be},t,!0),this.NT=t}finally{this.UT=!1}}subscribeSelectionChanged(t){this.ek.i(t)}unsubscribeSelectionChanged(t){this.ek._(t)}selectionBounds(){if(null===this.jT)return null;const t=this.qT.get(this.jT);return t?this.vk(t):null}vk(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Xn(this.If,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,o),h=Math.max(h,o))}if(!l)return null;const o=this.mk(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}mk(t){const i=this.If.chartElement(),s=this.wk(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}}pk(){this.ek.p({id:this.jT,bounds:this.selectionBounds()})}deselectAll(){this.uk()}deleteSelected(){if(this.jT){const t=this.qT.get(this.jT);return(!t||!t.isLocked())&&this.removeTool(this.jT)}return!1}getSelectedToolId(){return this.jT}getAllTools(){return new Map(this.qT)}getTool(t){return this.qT.get(t)}clearAll(){this.ck(null),this.qT.forEach(t=>t.remove()),this.qT.clear(),this.hk.clear(),this.recordChange()}getToolCount(){return this.qT.size}isToolSelected(t){return this.jT===t}serializeAll(){const t=[];for(const i of this.qT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=_o.gk(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 gk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({bk:Th(n[t]),Mk:kh(n[t],"price")??0});switch(s){case"trendLine":return Wh(t,{point1Time:h(0).bk,point1Price:h(0).Mk,point2Time:h(1).bk,point2Price:h(1).Mk,...e});case"horizontalLine":return Nh(t,{price:h(0).Mk,startTime:h(0).bk??void 0,...e});case"parallelChannel":return il(t,{point1Time:h(0).bk,point1Price:h(0).Mk,point2Time:h(1).bk,point2Price:h(1).Mk,channelWidth:r?.channelWidth,...e});case"pitchfork":return rl(t,{pivotTime:h(0).bk,pivotPrice:h(0).Mk,upperTime:h(1).bk,upperPrice:h(1).Mk,lowerTime:h(2).bk,lowerPrice:h(2).Mk,...e});case"polygon":return Zh(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).bk,s.price=h(i).Mk,s}),...e});case"crossLine":return Yh(t,{time:h(0).bk,price:h(0).Mk,...e});case"verticalLine":return al(t,{time:h(0).bk,...e});case"fibRetracement":return ml(t,{point1Time:h(0).bk,point1Price:h(0).Mk,point2Time:h(1).bk,point2Price:h(1).Mk,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return Ml(t,{point1:i.bk?{time:i.bk,price:i.Mk}:void 0,point2:s.bk?{time:s.bk,price:s.Mk}:void 0,point3:n.bk?{time:n.bk,price:n.Mk}:void 0,levels:r?.levels,...e})}case"fibFan":return Pl(t,{point1Time:h(0).bk,point1Price:h(0).Mk,point2Time:h(1).bk,point2Price:h(1).Mk,levels:r?.levels,...e});case"rectangle":return Rl(t,{time1:h(0).bk,price1:h(0).Mk,time2:h(1).bk,price2:h(1).Mk,...e});case"circle":return Ll(t,{centerTime:h(0).bk,centerPrice:h(0).Mk,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Ol(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Nl(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Yl(t,{time:h(0).bk,price:h(0).Mk,text:r?.text,...e});case"ruler":return io(t,{point1Time:h(0).bk,point1Price:h(0).Mk,point2Time:h(1).bk,point2Price:h(1).Mk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ro(t,{entryPrice:h(0).Mk,entryTime:h(0).bk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return ao(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.lk&&(clearTimeout(this.lk),this.lk=null),this.ak.m(),this.ek.m(),this.clearAll(),this.yk(),this.$T=[],this.HT=[],this.NT=[]}_k(){this.qS=t=>{this.aC(t)},this.If.subscribeClick(this.qS),this.sp=t=>{this._C(t)},this.If.subscribeCrosshairMove(this.sp);const t=this.If.chartElement();t&&(this.KT=t=>this.Sk(t),this.ZT=t=>this.xk(t),this.JT=t=>this.xk(t),this.QT=t=>this.Ck(t),t.addEventListener("pointerdown",this.KT),t.addEventListener("pointerup",this.ZT),t.addEventListener("pointercancel",this.JT),t.addEventListener("lostpointercapture",this.QT)),_s&&(this.tk=t=>this.xk(t),window.addEventListener("pointerup",this.tk)),this.Ps.enableKeyboardShortcuts&&(this.GT=t=>{this.Pk(t)},document.addEventListener("keydown",this.GT))}yk(){this.qS&&(this.If.unsubscribeClick(this.qS),this.qS=null),this.sp&&(this.If.unsubscribeCrosshairMove(this.sp),this.sp=null);const t=this.If.chartElement();t&&(this.KT&&(t.removeEventListener("pointerdown",this.KT),this.KT=null),this.ZT&&(t.removeEventListener("pointerup",this.ZT),this.ZT=null),this.JT&&(t.removeEventListener("pointercancel",this.JT),this.JT=null),this.QT&&(t.removeEventListener("lostpointercapture",this.QT),this.QT=null)),this.tk&&(window.removeEventListener("pointerup",this.tk),this.tk=null),this.GT&&(document.removeEventListener("keydown",this.GT),this.GT=null)}aC(t){if(this.dk(),!t.point)return;if(this.ik)return void(this.ik=!1);if(this.gC)return;const i=this.Tk(t.hoveredObjectId);i?this.selectTool(i):this.uk()}_C(t){if(this.sk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.gC&&this.rk){const i=this.qT.get(this.rk);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Yn(this.If,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.Tk(t.hoveredObjectId);if(this.YT&&this.YT!==i){const t=this.qT.get(this.YT);t&&t.setHovered(!1)}if(i){const t=this.qT.get(i);t&&t.setHovered(!0)}this.YT=i}Tk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.qT)if(s.id===i)return t;return null}Sk(t){if(this.gC)return;Fh(this.If,!1);const i=this.If.chartElement();if(!i)return;const s=null!==this.YT&&null!==this.sk?{kk:this.YT,kw:this.sk}:this.Dk(t);if(null===s)return;const{kk:n,kw:e}=s,r=this.qT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Rk(r,e.ut,e.ct);if(null!==h&&null!==l){Fh(this.If,!0),this.selectTool(n),this.gC=!0,this.ik=!0,this.rk=n,this._S=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this._S=null}r.startDrag(h,l),this.Fk()}}xk(t){if(!this.gC||null===this.rk)return;if(t&&null!==this._S&&t.pointerId!==this._S)return;const i=this.rk;this.gC=!1,this.rk=null;try{const t=this.qT.get(i);t&&t.stopDrag()}finally{this.ES(),this.Ik()}this.recordChange()}Ck(t){null!==this._S&&t.pointerId!==this._S||(this._S=null,this.xk())}wk(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Dk(t){for(const[i,s]of this.qT){if(!s.isVisible()||s.isLocked())continue;const n=this.wk(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{kk:i,kw:r}}return null}ES(){if(null===this._S)return;const t=this.If.chartElement();t&&t.hasPointerCapture(this._S)&&t.releasePointerCapture(this._S),this._S=null}Fk(){if(null!==this.nk)return;const t=this.If.options();this.nk={Vk:f(t.handleScroll),Lk:f(t.handleScale)},this.If.applyOptions({handleScroll:!1,handleScale:!1})}Ik(){const t=this.nk;this.nk=null,null!==t&&this.If.applyOptions({handleScroll:t.Vk,handleScale:t.Lk})}Pk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.dk(),"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.xk(),this.uk(),this.stopDrawing(),t.preventDefault())}Rk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Yn(this.If,t.series(),i)}}uk(){this.ck(null)}}const uo={...t,color:"#2196f3"};var co=Object.freeze({__proto__:null,AreaSeries:Se,ArrowTool:Bl,BarSeries:Te,BaselineSeries:be,BrushTool:$l,CandlestickSeries:Re,CircleTool:Vl,get ColorType(){return Li},CrossLineTool:jh,get CrosshairMode(){return U},DEFAULT_SESSIONS:Yr,DraggablePriceLine:nh,DrawingToolsManager:_o,EXTENDED_FIBONACCI_RATIOS:ul,FibonacciCalculator:cl,FibonacciExtensionTool:bl,FibonacciFanTool:Cl,FibonacciTool:vl,GanttTool:oo,HistogramSeries:Ve,HorizontalLineTool:Hh,InteractiveLineManager:eh,get LastPriceAnimationMode(){return Ii},LineSeries:re,get LineStyle(){return s},get LineType(){return i},get MismatchDirection(){return xt},ParallelChannelTool:tl,PitchforkTool:el,PolygonTool:Kh,PositionCalculator:Xl,PositionLine:wh,PositionMarkersManager:Cr,PositionTool:eo,get PriceLineSource(){return Vi},get PriceScaleMode(){return di},RectangleTool:Dl,RulerCalculator:Zl,RulerTool:to,STANDARD_FIBONACCI_RATIOS:_l,TextTool:jl,get TickMarkType(){return Ai},get TrackingModeExitMode(){return Fi},TradingSessionsIndicator:Xr,TrendLineTool:Oh,VerticalLineTool:ol,VolumeProfileIndicator:Zr,applyADX:function(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=Vr(0,100),h=i.addSeries(re,{color:n.colorADX,autoscaleInfoProvider:r},e),l=i.addSeries(re,{color:n.colorPlusDI,autoscaleInfoProvider:r},e),o=i.addSeries(re,{color:n.colorMinusDI,autoscaleInfoProvider:r},e),a=Lr(i,h,e);i.priceScale(h.options().priceScaleId??"right",a).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Er(h,n.levelColor),u=Or({e_:t,jf:i,by:[h,l,o],Zl:"ADX",W:n,Sy:["period"],My:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Ak:[],Ek:[],Bk:[]};const s=[],n=[],e=[];for(let i=1;i<t.length;i++){const r=t[i],h=t[i-1];if(!("high"in r)||!("low"in r)||!("close"in h)){s.push(0),n.push(0),e.push(0);continue}s.push(Math.max(r.high-r.low,Math.abs(r.high-h.close),Math.abs(r.low-h.close)));const l=r.high-h.high,o=h.low-r.low;n.push(l>o&&l>0?l:0),e.push(o>l&&o>0?o:0)}let r=0,h=0,l=0;for(let t=0;t<i;t++)r+=s[t],h+=n[t],l+=e[t];const o=[],a=[],_=[],u=[];for(let c=i;c<s.length;c++){r=r-r/i+s[c],h=h-h/i+n[c],l=l-l/i+e[c];const d=0===r?0:h/r*100,p=0===r?0:l/r*100,f=d+p,v=0===f?0:Math.abs(d-p)/f*100;u.push(v);const m=t[c+1];if(m&&void 0!==m.time)if(a.push({time:m.time,value:d}),_.push({time:m.time,value:p}),u.length===i){let t=0;for(const i of u)t+=i;o.push({time:m.time,value:t/i})}else if(u.length>i){const t=o[o.length-1].value;o.push({time:m.time,value:(t*(i-1)+v)/i})}}return{Ak:o,Ek:a,Bk:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Ak],[l,n?s.Ek:[]],[o,n?s.Bk:[]]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),o.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:l,minusDI:o,...u}},applyATR:function(t,i,s={}){const n={paneIndex:s.paneIndex??6,period:s.period??14,color:s.color??"#FF9800",lineWidth:s.lineWidth??2},e=i.addSeries(re,{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=Or({e_:t,jf:i,by:[e],Zl:"ATR",W:n,Sy:["period"],My:(t,i)=>[[e,r(t,i.period??14)]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},applyBollingerBands:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Bollinger Bands",W:n,Sy:["period","stdDev"],My:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{MP:[],Ok:[],yP:[]};const n=[];for(const i of t)"close"in i?n.push(i.close):"value"in i?n.push(i.value):n.push(0);const e=[],r=[],h=[];for(let l=i-1;l<n.length;l++){let o=0;for(let t=0;t<i;t++)o+=n[l-t];const a=o/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-a,2);const u=Math.sqrt(_/i),c=a+u*s,d=a-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:a}),h.push({time:i,value:d})}}return{MP:e,Ok:r,yP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.MP],[h,s.Ok],[l,s.yP]]},yy:t=>{const i=t.lineWidth??1;r.applyOptions({color:t.colorUpper,lineWidth:i}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:r,middle:h,lower:l,...o}},applyCCI:function(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(re,{color:n.color,lineWidth:n.lineWidth},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(const i of t)"high"in i&&"low"in i&&"close"in i?s.push((i.high+i.low+i.close)/3):s.push("value"in i?i.value:0);const n=[];for(let e=i-1;e<s.length;e++){let r=0;for(let t=0;t<i;t++)r+=s[e-t];const h=r/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-h);const o=l/i,a=0===o?0:(s[e]-h)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=Or({e_:t,jf:i,by:[r],Zl:"CCI",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??20)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applyDonchianChannels:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Donchian Channels",W:n,Sy:["period"],My:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{MP:[],Ok:[],yP:[]};const s=[],n=[],e=[];for(let r=i-1;r<t.length;r++){let h=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[r-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>h&&(h=n),e<l&&(l=e)}const o=t[r];void 0!==o.time&&h!==-1/0&&l!==1/0&&(s.push({time:o.time,value:h}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(h+l)/2}))}return{MP:s,Ok:n,yP:e}})(t,i.period??20);return[[r,s.MP],[h,s.Ok],[l,s.yP]]},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}},applyEMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"EMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyHeikinAshi:function(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(Re,{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=Fr(t):i||null===h||(h(),h=null)},o=Or({e_:t,jf:i,by:[r],Zl:"Heikin Ashi",W:n,Sy:[],My:t=>[[r,Ur(t)]],yy:t=>{r.applyOptions({upColor:t.upColor,downColor:t.downColor,borderVisible:t.borderVisible,borderUpColor:t.borderUpColor,borderDownColor:t.borderDownColor,wickVisible:t.wickVisible,wickUpColor:t.wickUpColor,wickDownColor:t.wickDownColor}),l(!0===t.hideSource)}});return{Wa:r,options:o.options,applyOptions:o.applyOptions,recalculate:o.recalculate,remove:()=>{o.remove();try{l(!1)}catch(t){}}}},applyIchimoku:function(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(re,{color:t},e),h=r(n.colorConversion),l=r(n.colorBase),o=r(n.colorSpanA),a=r(n.colorSpanB),_=r(n.colorLagging);let u=[],c=n;const d=new $r(i,t,()=>u,()=>({Iy:c.cloudBullishColor??"#089981",Vy:c.cloudBearishColor??"#F23645",ky: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=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{Wk:h,eh:l,Dy:o,Ry:a,zk:_,$k:u};const c=function(t){if(t.length<3)return null;const i=new Map;let s=null,n=0;for(let e=1;e<t.length;e++){const r=t[e-1].time,h=t[e].time;if("number"!=typeof r||"number"!=typeof h)return null;const l=h-r;if(l<=0)continue;const o=(i.get(l)??0)+1;i.set(l,o),o>n&&(n=o,s=l)}return s}(t),d=i=>{if(i<t.length)return t[i].time;if(null===c)return null;return t[t.length-1].time+c*(i-t.length+1)},p=new Map,f=new Map;for(let i=0;i<t.length;i++){const o=t[i];if(void 0===o.time)continue;const a=Hr(t,i,s),u=Hr(t,i,n);null!==a&&h.push({time:o.time,value:a}),null!==u&&l.push({time:o.time,value:u}),null!==a&&null!==u&&p.set(i+r,(a+u)/2);const c=Hr(t,i,e);null!==c&&f.set(i+r,c);const d=i-r;if(d>=0&&void 0!==t[d].time){const i="close"in o?o.close:o.value;_.push({time:t[d].time,value:i})}}const v=t.length-1+r;for(let t=0;t<=v;t++){const i=d(t);if(null==i)continue;const s=p.get(t),n=f.get(t);if(void 0!==s&&o.push({time:i,value:s}),void 0!==n&&a.push({time:i,value:n}),void 0!==s&&void 0!==n){const t={gt:i,Dy:s,Ry:n};u.push(t)}}return{Wk:h,eh:l,Dy:o,Ry:a,zk:_,$k:u}},v=Or({e_:t,jf:i,by:[h,l,o,a,_],Zl:"Ichimoku",W:n,Sy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],My:(t,i)=>{c=i;const s=f(t,i);return u=s.$k,[[h,s.Wk],[l,s.eh],[o,s.Dy],[a,s.Ry],[_,i.showLagging??1?s.zk:[]]]},yy:t=>{c=t;const s=t.lineWidth??1;h.applyOptions({color:t.colorConversion,lineWidth:s}),l.applyOptions({color:t.colorBase,lineWidth:s}),o.applyOptions({color:t.colorSpanA,lineWidth:s}),a.applyOptions({color:t.colorSpanB,lineWidth:s}),_.applyOptions({color:t.colorLagging,lineWidth:s,visible:t.showLagging??!0}),i.timeScale().applyOptions({})}}),m=v.remove;return{conversion:h,base:l,spanA:o,spanB:a,lagging:_,...v,remove:()=>{try{t.detachPrimitive(p)}catch(t){}u=[],m()}}},applyKeltnerChannels:function(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(re,{color:n.colorUpper},e),h=i.addSeries(re,{color:n.colorMiddle},e),l=i.addSeries(re,{color:n.colorLower},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"Keltner Channels",W:n,Sy:["period","atrPeriod","multiplier","source"],My:(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{MP:[],Ok:[],yP:[]};const r=Ar(t,i.source??"close"),h=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=r[t];h.push(o/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const a=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?a.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):a.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=a[t];_[n-1]=u/n;for(let t=n;t<a.length;t++)_[t]=(_[t-1]*(n-1)+a[t])/n;const c=[],d=[],p=[];for(let i=0;i<h.length;i++){const n=s-1+i,r=t[n],l=_[n-1];if(!r||void 0===r.time||void 0===l)continue;const o=h[i],a=l*e;d.push({time:r.time,value:o}),c.push({time:r.time,value:o+a}),p.push({time:r.time,value:o-a})}return{MP:c,Ok:d,yP:p}})(t,i);return[[r,s.MP],[h,s.Ok],[l,s.yP]]},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min((t.lineWidth??1)+1,4),lineStyle:s}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...o}},applyMACD:function(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(re,{color:n.colorMACD},e),h=i.addSeries(re,{color:n.colorSignal},e),l=i.addSeries(Ve,{color:n.colorHistogramUp},e),o=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},a=Or({e_:t,jf:i,by:[r,h,l],Zl:"MACD",W:n,Sy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],My:(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{Hk:[],Nk:[],Uk:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=o(r,s),l=o(r,n),a=[],_=n-s;for(let t=0;t<l.length;t++)a.push(h[t+_]-l[t]);const u=o(a,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=a[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{Hk:c,Nk:d,Uk:p}})(t,i);return[[r,s.Hk],[h,s.Nk],[l,s.Uk]]},yy:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),h.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:h,histogram:l,...a}},applyMFI:function(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(re,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Vr(0,100)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Dr(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const r=i[s],h=i[s-1];if(!("high"in r)||!("low"in r)||!("close"in r)){n.push(0),e.push(0);continue}const l=(r.high+r.low+r.close)/3,o=(h.high+h.low+h.close)/3,a=l*(kr(t,r.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const r=[];for(let t=s-1;t<n.length;t++){let h=0,l=0;for(let i=0;i<s;i++)h+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+h/l),a=i[t+1];a&&void 0!==a.time&&r.push({time:a.time,value:o})}return r},a=Or({e_:t,jf:i,by:[r],Zl:"MFI",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??14)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applyOBV:function(t,i,s={}){const n={paneIndex:s.paneIndex??5,color:s.color??"#2196F3",lineWidth:s.lineWidth??2,data:s.data},e=i.addSeries(re,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!Dr(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=kr(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=Or({e_:t,jf:i,by:[e],Zl:"OBV",W:n,My:()=>[[e,r()]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},applyParabolicSAR:function(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(re,{color:n.colorUp,lineVisible:!1,pointMarkersVisible:!0,pointMarkersRadius:n.dotSize},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<3)return[];const r=t[0],h=t[1];if(!("high"in r)||!("low"in r))return[];const l=[];let o=h.close>=r.close,a=o?r.low:r.high,_=o?h.high:h.low,u=i;for(let r=1;r<t.length;r++){const h=t[r],c=t[r-1];if("high"in h&&"low"in h&&(a+=u*(_-a),o?(a=Math.min(a,c.low,t[r-2]?t[r-2].low:c.low),h.low<a?(o=!1,a=_,_=h.low,u=i):h.high>_&&(_=h.high,u=Math.min(u+i,s))):(a=Math.max(a,c.high,t[r-2]?t[r-2].high:c.high),h.high>a?(o=!0,a=_,_=h.high,u=i):h.low<_&&(_=h.low,u=Math.min(u+i,s))),void 0!==h.time)){const t={};t.time=h.time,t.value=a,t.color=o?n:e,l.push(t)}}return l},h=Or({e_:t,jf:i,by:[e],Zl:"Parabolic SAR",W:n,Sy:["step","maxStep","colorUp","colorDown"],My:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],yy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}},applyPivotPoints:function(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(re,{color:t},e),h=r(n.colorPivot),l=[r(n.colorResistance),r(n.colorResistance),r(n.colorResistance)],o=[r(n.colorSupport),r(n.colorSupport),r(n.colorSupport)],a=Or({e_:t,jf:i,by:[h,...l,...o],Zl:"Pivot Points",W:n,Sy:["pivotPeriod"],My:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{gP:s,qk:n,jk:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=Wr(_.time,i);if(null===t)continue;if(null===r)r=t;else if(t!==r){const i=(h+l+o)/3,s=h-l;a={Yk:i,Xk:[2*i-l,i+s,h+2*(i-l)],Gk:[2*i-h,i-s,l-2*(h-i)]},r=t,h=-1/0,l=1/0}const u="high"in _?_.high:_.value,c="low"in _?_.low:_.value;if(u>h&&(h=u),c<l&&(l=c),o="close"in _?_.close:_.value,null!==a&&void 0!==_.time){s.push({time:_.time,value:a.Yk});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Xk[t]}),e[t].push({time:_.time,value:a.Gk[t]})}}return{gP:s,qk:n,jk:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.gP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.qk[t]:[]]),e.push([o[t],t<n?s.jk[t]:[]]);return e},yy:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));h.applyOptions({color:t.colorPivot,lineWidth:i,lineStyle:s});for(let e=0;e<3;e++)l[e].applyOptions({color:t.colorResistance,lineWidth:i,lineStyle:s,visible:e<n}),o[e].applyOptions({color:t.colorSupport,lineWidth:i,lineStyle:s,visible:e<n})}});return{pivot:h,resistances:l,supports:o,...a}},applyRSI:function(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(re,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Vr(0,100)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Er(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Ar(t,s),e=[],r=[];for(let t=1;t<n.length;t++)r.push(n[t]-n[t-1]);let h=0,l=0;for(let t=0;t<i;t++)r[t]>0?h+=r[t]:l+=Math.abs(r[t]);h/=i,l/=i;let o=0===l?100:h/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<r.length;s++){const n=r[s];h=(h*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:h/l,a=100-100/(1+o),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:a})}return e},a=Or({e_:t,jf:i,by:[r],Zl:"RSI",W:n,Sy:["period","source"],My:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},applySMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"SMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyStochastic:function(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=Vr(0,100),h=i.addSeries(re,{color:n.colorK,autoscaleInfoProvider:r},e),l=i.addSeries(re,{color:n.colorD,autoscaleInfoProvider:r},e),o=Lr(i,h,e);i.priceScale(h.options().priceScaleId??"right",o).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Er(h,n.levelColor),_=Or({e_:t,jf:i,by:[h,l],Zl:"Stochastic",W:n,Sy:["kPeriod","dPeriod"],My:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Kk:[],Zk:[]};const n=[];for(let s=i-1;s<t.length;s++){let e=-1/0,r=1/0;for(let n=0;n<i;n++){const i=t[s-n];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[s];if("close"in h){const t=(h.close-r)/(e-r)*100;n.push(t)}}const e=[];for(let s=0;s<n.length;s++){const r=i-1+s;t[r]&&t[r].time&&e.push({time:t[r].time,value:n[s]})}const r=[];if(n.length>=s)for(let e=s-1;e<n.length;e++){let h=0;for(let t=0;t<s;t++)h+=n[e-t];const l=h/s,o=i-1+e;t[o]&&t[o].time&&r.push({time:t[o].time,value:l})}return{Kk:e,Zk:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Kk],[l,s.Zk]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:l,..._}},applySuperTrend:function(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(re,{color:n.colorUp,lineWidth:n.lineWidth},n.paneIndex),r=(t,i,s,n,e)=>{if(!t||t.length<i+1)return[];const r=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?r.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):r.push(0)}const h=[];let l=0;for(let t=0;t<i;t++)l+=r[t];h[i-1]=l/i;for(let t=i;t<r.length;t++)h[t]=(h[t-1]*(i-1)+r[t])/i;const o=[];let a=0,_=0,u=!0,c=!1;for(let r=i;r<t.length;r++){const i=t[r],l=t[r-1],d=h[r-1];if(!("high"in i)||!("low"in i)||void 0===d)continue;const p=(i.high+i.low)/2,f=p+s*d,v=p-s*d;if(c?(a=f<a||l.close>a?f:a,_=v>_||l.close<_?v:_,u&&i.close<_?u=!1:!u&&i.close>a&&(u=!0)):(a=f,_=v,u=i.close>=p,c=!0),void 0===i.time)continue;const m={};m.time=i.time,m.value=u?_:a,m.color=u?n:e,o.push(m)}return o},h=Or({e_:t,jf:i,by:[e],Zl:"SuperTrend",Sy:["period","multiplier","colorUp","colorDown"],W:n,My:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],yy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}},applyVWAP:function(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(re,{color:n.color},e),h=i.addSeries(re,{color:n.bandColor},e),l=i.addSeries(re,{color:n.bandColor},e),o=Or({e_:t,jf:i,by:[r,h,l],Zl:"VWAP",W:n,Sy:["anchorPeriod","bandMultiplier"],My:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Dr(t))return{Jk:e,MP:r,yP:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=Wr(u.time,s);if(null===i||void 0===u.time)continue;i!==l&&(l=i,o=0,a=0,_=0);const c="high"in u&&"low"in u&&"close"in u?(u.high+u.low+u.close)/3:u.value,d=kr(t,u.time)??0;if(o+=d,a+=c*d,_+=c*c*d,0===o)continue;const p=a/o;if(e.push({time:u.time,value:p}),n>0){const t=Math.max(_/o-p*p,0),i=Math.sqrt(t)*n;r.push({time:u.time,value:p+i}),h.push({time:u.time,value:p-i})}}return{Jk:e,MP:r,yP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.Jk],[h,n.MP],[l,n.yP]]},yy:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;r.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:r,upper:h,lower:l,...o}},applyVolume:function(t,i,s={}){const n={paneIndex:s.paneIndex??3,colorUp:s.colorUp??"#26a69a",colorDown:s.colorDown??"#ef5350"},e=n.paneIndex,r=i.addSeries(Ve,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Lr(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||!Dr(t))return[];const e=[];for(const r of n){const n=kr(t,r.time);n&&"close"in r&&"open"in r&&e.push({time:r.time,value:n,color:r.close>=r.open?i:s})}return e},o=Or({e_:t,jf:i,by:[r],Zl:"Volume",W:n,Sy:["colorUp","colorDown"],My:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...o}},applyWMA:function(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(re,{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=Ar(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=Or({e_:t,jf:i,by:[e],Zl:"WMA",W:n,Sy:["period","source"],My:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],yy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},applyWilliamsR:function(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(re,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Vr(-100,0)},e),h=Lr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Er(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(let n=i-1;n<t.length;n++){let e=-1/0,r=1/0;for(let s=0;s<i;s++){const i=t[n-s];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[n];if(!("close"in h)||void 0===h.time)continue;const l=e-r,o=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:o})}return s},a=Or({e_:t,jf:i,by:[r],Zl:"Williams %R",W:n,Sy:["period"],My:(t,i)=>[[r,o(t,i.period??14)]],yy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},calculateHeikinAshi:Ur,calculatePipConfig:Gl,coordinateFromTime:Xn,createArrowTool:Ol,createBrushTool:Nl,createChart:function(t,i){return qn(t,new ss,ss.ad(i))},createChartEx:qn,createCircleTool:Ll,createCrossLineTool:Yh,createFibonacciExtensionTool:Ml,createFibonacciFanTool:Pl,createFibonacciTool:ml,createGanttTool:ao,createHorizontalLineTool:Nh,createImageWatermark:function(t,i,s){return new Le(t,new Ge(i,s))},createInteractiveLineManager:function(t,i){return new eh(t,i)},createOptionsChart:function(t,i){return qn(t,new de,i)},createParallelChannelTool:il,createPitchforkTool:rl,createPolygonTool:Zh,createPositionLine:function(t,i,s){return new wh(i,t,s)},createPositionMarkers:function(t,i,s){const n=new Cr(t,s);return i&&i.length>0&&n.setPositions(i),n},createPositionTool:ro,createRectangleTool:Rl,createRulerTool:io,createSeriesMarkers:vr,createTextTool:Yl,createTextWatermark:function(t,i){return new Le(t,new Ne(i))},createTradingLine:function(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 nh(i,t,r)},createTradingSessionsIndicator:function(t,i,s){return new Xr(t,i,s)},createTrendLineTool:Wh,createUpDownMarkers:function(t,i={}){return new xr(t,new yr(i))},createVerticalLineTool:al,createVolumeProfileIndicator:function(t,i,s){return new Zr(t,i,s)},createYieldCurveChart:function(t,i){const s=Un(t);return new ue(s,i)},customSeriesDefaultOptions:uo,defaultHorzScaleBehavior:function(){return ss},getPipConfig:Kl,hideSeriesPaint:Fr,isBusinessDay:Oi,isUTCTimestamp:Wi,setSeriesVolumes:function(t,i){const s=new Map;for(const t of i)null!=t&&"time"in t&&"volume"in t&&s.set(Tr(t.time),t.volume);Pr.set(t,s)},setVolumeProfileData:function(t,i){const s=new Map;for(const t of i)s.set(t.time,t.volume);t.setVolumeData(s)},timeFromCoordinate:Yn,version:function(){return"2.3.1"}});window.PipsendCharts=co,window.LightweightCharts=co}();
|