@pipsend/charts 2.3.4 → 2.3.10
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 +49 -35
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +49 -35
- package/dist/pipsend-charts.standalone.development.mjs +49 -35
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +27 -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.10
|
|
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)}Ir(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Vr=[],this.Lr=new Map,this.Ar=new Map,this.Er=[]}Br(){return this.Or()>0?this.Vr[this.Vr.length-1]:null}Wr(){return this.Or()>0?this.zr(0):null}Gs(){return this.Or()>0?this.zr(this.Vr.length-1):null}Or(){return this.Vr.length}Gi(){return 0===this.Or()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Vr}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Ar.clear(),this.Lr.clear(),this.Vr=t,this.Er=t.map(t=>t.Re)}Yr(){return this.Er}zr(t){return this.Vr[t].Re}Nr(t){return this.Vr[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Vr.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Vr.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Vr.length||t<this.Vr[i].Re?null:i}Zr(t){return yt(this.Vr,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Vr,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Vr[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(o,a,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Lr.get(s);void 0===u&&(u=new Map,this.Lr.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(o);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.ah=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.ah?.rh===t)return this.ah.hh;const i=t.map(t=>new Rt(t));return this.ah={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Vt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}function At(t){return{hi:t.text(),Li:t.coordinate(),Vi:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),It:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Et{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...At(this.dh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=At(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Li=n.Li,s.Vi=n.Vi,t.hi=n.hi,t.It=n.It,t.mi=n.mi}}class Ot extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new Lt(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new Lt(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.oh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new at(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().At().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().At().Pe(),e=this.Bt();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Br();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Fh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Ih(l),ze:s.Vh(l,e.Ht),R:o.dr,Li:a,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Lh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Ah()),this.ti().Eh(this),this.ti().Bh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Oh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Eh(this),this.ti().Bh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Eh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Eh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Bt(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.It()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ol(),Nt:this.al(),Wt:this._l(),Ot:this.ul(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}cl(t){this.kh.push(new Ot(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.It())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=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.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Il(),Pl:(this.Pt.ti().At().Il()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Vl:4,Ll:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Ll)+i.Vl;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Vl)-i.Ll;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function 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.Vl+s;return{Vl:n,Ll:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Al=t,this.El=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Al))this.Bl=[2,2.5,2];else{this.Bl=[];for(let t=this.Al;1!==t;){if(t%2==0)this.Bl.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Bl.push(2,2.5),t/=5}if(this.Bl.length>100)throw new Error("something wrong with base")}}}Ol(t,i,s){const n=0===this.Al?0:1/this.Al;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.El[0];for(;;){const t=Gt(e,n,1e-14)&&e>n+1e-14,i=Gt(e,s*h,1e-14),l=Gt(e,1,1e-14);if(!(t&&i&&l))break;e/=h,h=this.El[++r%this.El.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Bl.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Bl[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Bl[++r%this.Bl.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Al=i,this.zl=s,this.$l=n}Ol(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Al,[2,2.5,2]),r=new _i(this.Al,[2,2,2.5]),h=new _i(this.Al,[2.5,2,2]),l=[];return l.push(e.Ol(t,i,n),r.Ol(t,i,n),h.Ol(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Wl=[]);const _=this.Ol(o,a);if(this.ql(i,_,o,a,h,l),t.jl()&&this.Yl(_,a,o)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Il(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.ceil(2.5*this.Ul())}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.io()&&(i=this.Ol(c*a,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.so(t,s,e,r),o=this.so(t,n,-r,-e),a=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<a/2&&h.shift(),h.length>0&&o.Tl-h[h.length-1].Tl<a/2&&h.pop(),h.unshift(l),h.push(o)}so(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.Ol(o,l)),_=this.zl(i+e,t),u=_-_%a,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=o(this.Yi.tr());return this.Yi.io()&&(n=oi(n,this.Yi.no())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.eo=0,this.ro=null,this.Je=null,this.ho=null,this.lo={oo:!1,ao:null},this._o=!1,this.uo=0,this.co=0,this.do=new a,this.po=new a,this.fo=[],this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.Mo=null,this.ll=fi,this.yo=ai(null),this.So=t,this.Ps=i,this.xo=s,this.Co=n,this.Po=e,this.To=new ui(this,100,this.ko.bind(this),this.Do.bind(this))}gl(){return this.So}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.Ro({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Fo(),this.wo=null}}Io(){return this.Ps.autoScale}Vo(){return this._o}io(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Lo(){return 3===this.Ps.mode}no(){return this.yo}se(){return{nn:this.Ps.autoScale,Ao:this.Ps.invertScale,se:this.Ps.mode}}Ro(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.lo.oo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.yo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.yo),null!==s&&this.Eo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Eo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.bl(),n&&(3===i.se||this.Lo())&&this.bl(),void 0!==t.Ao&&i.Ao!==t.Ao&&(this.Ps.invertScale=t.Ao,this.Bo()),this.po.p(i,this.se())}Oo(){return this.po}P(){return this.xo.fontSize}qt(){return this.eo}Wo(t){this.eo!==t&&(this.eo=t,this.Fo(),this.wo=null)}zo(){if(this.ro)return this.ro;const t=this.qt()-this.$o()-this.Ho();return this.ro=t,t}tr(){return this.No(),this.Je}Eo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.wo=null,this.Je=t)}Uo(t){this.Eo(t),this.qo(null!==t)}Gi(){return this.No(),0===this.eo||!this.Je||this.Je.Gi()}jo(t){return this.Ao()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Lo()&&(t=ni(t,i)),this.Do(t,i)}Yo(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.eo-1-o;e.ct=u}}Go(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,o=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),o=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=a?c:this.eo-1-c;e.Ko=p,c=n+_*(l-r),p=a?c:this.eo-1-c,e.Zo=p,c=n+_*(o-r),p=a?c:this.eo-1-c,e.Jo=p,c=n+_*(u-r),p=a?c:this.eo-1-c,e.Qo=p}}Ds(t,i){const s=this.ko(t,i);return this.ta(s,i)}ta(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Lo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.fo}Ft(){return this.mo||(this.mo=ci(this.fo)),this.mo}ia(t){-1===this.fo.indexOf(t)&&(this.fo.push(t),this.bl(),this.sa())}na(t){const i=this.fo.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.fo.splice(i,1),0===this.fo.length&&(this.Ro({nn:!0}),this.Eo(null)),this.bl(),this.sa()}Bt(){let t=null;for(const i of this.fo){const s=i.Bt();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Ao(){return this.Ps.invertScale}Il(){const t=null===this.Bt();if(null!==this.wo&&(t||this.wo.ea===t))return this.wo.Il;this.To.Nl();const i=this.To.Il();return this.wo={Il:i,ea:t},this.do.p(),i}ra(){return this.do}ha(t){this.Oe()||this.Lo()||null===this.bo&&null===this.ho&&(this.Gi()||(this.bo=this.eo-t,this.ho=l(this.tr()).Ue()))}la(t){if(this.Oe()||this.Lo())return;if(null===this.bo)return;this.Ro({nn:!1}),(t=this.eo-t)<0&&(t=0);let i=(this.bo+.2*(this.eo-1))/(t+.2*(this.eo-1));const s=l(this.ho).Ue();i=Math.max(i,.1),s.Xe(i),this.Eo(s)}oa(){this.Oe()||this.Lo()||(this.bo=null,this.ho=null)}aa(t){this.Io()||null===this.Mo&&null===this.ho&&(this.Gi()||(this.Mo=t,this.ho=l(this.tr()).Ue()))}_a(t){if(this.Io())return;if(null===this.Mo)return;const i=l(this.tr()).Ye()/(this.zo()-1);let s=t-this.Mo;this.Ao()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Eo(e,!0),this.wo=null}ua(){this.Io()||null!==this.Mo&&(this.Mo=null,this.ho=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.ca(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.da(t);case 3:return this.hl().formatTickmarks(t);default:return this.pa(t)}}Ih(t){return this.er(t,l(this.vo).hl())}Vh(t,i){return t=ii(t,i),this.ca(t,pi)}fa(){return this.fo}va(t){this.lo={ao:t,oo:!1}}zs(){this.fo.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Io()}Xl(){return this.P()/2}bl(){this.wo=null;let t=1/0;this.vo=null;for(const i of this.fo)i.ls()<t&&(t=i.ls(),this.vo=i);let i=100;null!==this.vo&&(i=Math.round(this.vo.rh())),this.ll=fi,this.Oe()?(this.ll=pi,i=100):this.Lo()?(this.ll=new Z(100,1),i=100):null!==this.vo&&(this.ll=this.vo.hl()),this.To=new ui(this,i,this.ko.bind(this),this.Do.bind(this)),this.To.Nl()}sa(){this.mo=null}ma(){return null===this.vo||this.Oe()||this.Lo()?1:1/this.vo.rh()}Ki(){return this.Po}qo(t){this._o=t}$o(){return this.Ao()?this.Ps.scaleMargins.bottom*this.qt()+this.co:this.Ps.scaleMargins.top*this.qt()+this.uo}Ho(){return this.Ao()?this.Ps.scaleMargins.top*this.qt()+this.uo:this.Ps.scaleMargins.bottom*this.qt()+this.co}No(){this.lo.oo||(this.lo.oo=!0,this.wa())}Fo(){this.ro=null}Do(t,i){if(this.No(),this.Gi())return 0;t=this.io()&&t?ri(t,this.yo):t;const s=l(this.tr()),n=this.Ho()+(this.zo()-1)*(t-s.qe())/s.Ye();return this.jo(n)}ko(t,i){if(this.No(),this.Gi())return 0;const s=this.jo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.Ho())/(this.zo()-1));return this.io()?hi(e,this.yo):e}Bo(){this.wo=null,this.To.Nl()}wa(){if(this.Vo()&&!this.Io())return;const t=this.lo.ao;if(null===t)return;let i=null;const s=this.fa();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.yo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this.uo&&e===this.co||(this.uo=n,this.co=e,this.wo=null,this.Fo()),null!==i){if(i.qe()===i.je()){const t=5*this.ma();this.io()&&(i=oi(i,this.yo)),i=new dt(i.qe()-t,i.je()+t),this.io()&&(i=li(i,this.yo))}if(this.io()){const t=oi(i,this.yo),s=ai(t);if(r=s,h=this.yo,r.Vl!==h.Vl||r.Ll!==h.Ll){const n=null!==this.ho?oi(this.ho,this.yo):null;this.yo=s,i=li(t,s),null!==n&&(this.ho=li(n,s))}}this.Eo(i)}else null===this.Je&&(this.Eo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Oe()?ii:this.Lo()?ni:this.io()?t=>ri(t,this.yo):null}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}ba(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.ga(t,this.Co.priceFormatter,i)}pa(t,i){const s=this.Co.priceFormatter;return this.ba(t,this.Co.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ca(t,i){return this.ga(t,this.Co.percentageFormatter,i)}da(t,i){const s=this.Co.percentageFormatter;return this.ba(t,this.Co.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.fo=[],this.Ma=new Map,this.eo=0,this.ya=0,this.Sa=1,this.mo=null,this.xa=!1,this.Ca=new a,this.kh=[],this.ph=t,this.ss=i,this.Pa=new Qt(this);const s=i.W();this.Ta=this.ka("left",s.leftPriceScale),this.Da=this.ka("right",s.rightPriceScale),this.Ta.Oo().i(this.Ra.bind(this,this.Ta),this),this.Da.Oo().i(this.Ra.bind(this,this.Da),this),this.Fa(s)}Fa(t){if(t.leftPriceScale&&this.Ta.lr(t.leftPriceScale),t.rightPriceScale&&this.Da.lr(t.rightPriceScale),t.localization&&(this.Ta.bl(),this.Da.bl()),t.overlayPriceScales){const i=Array.from(this.Ma.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Ia(t){switch(t){case"left":return this.Ta;case"right":return this.Da}return this.Ma.has(t)?h(this.Ma.get(t))[0].$t():null}m(){this.ti().Va().u(this),this.Ta.Oo().u(this),this.Da.Oo().u(this),this.fo.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Ca.p()}La(){return this.Sa}Aa(t){this.Sa=t}ti(){return this.ss}ts(){return this.ya}qt(){return this.eo}Ea(t){this.ya=t,this.Ba()}Wo(t){this.eo=t,this.Ta.Wo(t),this.Da.Wo(t),this.fo.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Wo(t)}}),this.Ba()}Oa(t){this.xa=t}Wa(){return this.xa}za(){return this.fo.filter(mi)}yl(){return this.fo}Un(t){const i=t.$t();return null===i||this.Ta!==i&&this.Da!==i}ia(t,i,s){this.$a(t,i,s?t.ls():this.fo.length)}na(t,i){const s=this.fo.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.fo.splice(s,1),i||this.fo.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Ma.has(n)){const i=h(this.Ma.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Ma.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.na(t),this.Ha(e)),this.mo=null}jn(t){return t===this.Ta?"left":t===this.Da?"right":"overlay"}Na(){return this.Ta}Ua(){return this.Da}qa(t,i){t.ha(i)}ja(t,i){t.la(i),this.Ba()}Ya(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Ba()}Ka(t){t.ua()}Ba(){this.fo.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Da.yl().length?t=this.Da:this.ss.W().leftPriceScale.visible&&0!==this.Ta.yl().length?t=this.Ta:0!==this.fo.length&&(t=this.fo[0].$t()),null===t&&(t=this.Da),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Da:this.ss.W().leftPriceScale.visible&&(t=this.Ta),t}Ha(t){null!==t&&t.Io()&&this.Za(t)}Ja(t){const i=this.ph.Pe();t.Ro({nn:!0}),null!==i&&t.va(i),this.Ba()}Qa(){this.Za(this.Ta),this.Za(this.Da)}t_(){this.Ha(this.Ta),this.Ha(this.Da),this.fo.forEach(t=>{this.Un(t)&&this.Ha(t.$t())}),this.Ba(),this.ss.ar()}Ft(){return null===this.mo&&(this.mo=ci(this.fo)),this.mo}i_(t,i){i=Xt(i,0,this.fo.length-1);const s=this.fo.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.fo.splice(s,1),this.fo.splice(i,0,t),this.fo.forEach((t,i)=>t._s(i)),this.mo=null;for(const t of[this.Ta,this.Da])t.sa(),t.bl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}s_(){return this.Ca}n_(){return this.Pa}cl(t){this.kh.push(new It(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Za(t){const i=t.fa();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.va(i)}t.zs()}$a(t,i,s){let n=this.Ia(i);if(null===n&&(n=this.ka(i,this.ss.W().overlayPriceScales)),this.fo.splice(s,0,t),!j(i)){const s=this.Ma.get(i)||[];s.push(t),this.Ma.set(i,s)}t._s(s),n.ia(t),t.us(n),this.Ha(n),this.mo=null}Ra(t,i,s){i.se!==s.se&&this.Za(t)}ka(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Wo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},o_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{a_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,a_:n.a_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.In=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.In){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,En:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(t,i){this.M_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}y_(t,i,s,n,e){const r=Math.ceil(i/t);return null!==this.Fn&&this.Fn.S_===r&&e===this.Fn.x_&&s===this.Fn.C_||(this.Fn={x_:e,C_:s,Il:this.P_(r,s,n),S_:r}),this.Fn.Il}M_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}P_(t,i,s){let n=[];const e=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=n;n=[];const r=s.length;let l=0;const o=h(this.m_.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.w_)return s}for(;l<r;l++)e(s[l])&&n.push(s[l])}return n}}class ki{constructor(t){this.T_=t}k_(){return null===this.T_?null:new Ci(Math.floor(this.T_.qh()),Math.ceil(this.T_.yi()))}D_(){return this.T_}static R_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.ya=0,this.F_=null,this.I_=[],this.Mo=null,this.bo=null,this.V_=new Ti,this.L_=new Map,this.A_=ki.R_(),this.E_=!0,this.B_=new a,this.O_=new a,this.W_=new a,this.z_=null,this.H_=null,this.N_=new Map,this.U_=-1,this.q_=[],this.Ps=i,this.Co=s,this.j_=i.rightOffset,this.Y_=i.barSpacing,this.ss=t,this.X_(i),this.u_=n,this.G_(),this.V_.g_(i.uniformDistribution),this.K_()}W(){return this.Ps}Z_(t){_(this.Co,t),this.J_(),this.G_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.Q_(),this.Ps.fixRightEdge&&this.tu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.X_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.Y_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.K_(),this.J_(),this.G_(),this.W_.p()}Rs(t){return this.I_[t]?.time??null}ns(t){return this.I_[t]??null}iu(t,i){if(this.I_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.I_[this.I_.length-1].time))return i?this.I_.length-1:null;const s=yt(this.I_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.I_[s].time)?i?s:null:s}Gi(){return 0===this.ya||0===this.I_.length||null===this.F_}su(){return this.I_.length>0}Pe(){return this.nu(),this.A_.k_()}eu(){return this.nu(),this.A_.D_()}ru(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.hu(i)}hu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.lu()),e=l(this.ou());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}au(t){return{from:l(this.iu(t.from,!0)),to:l(this.iu(t.to,!0))}}ts(){return this.ya}Ea(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.eu(),s=this.ya;if(this.ya=t,this.E_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.Y_*t/s;this.Y_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.j_-=Math.round(i/this.Y_)+1,this.E_=!0}this._u(),this.uu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.cu()+this.j_-t;return this.ya-(i+.5)*this.Y_-1}du(t,i){const s=this.cu(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.j_-n,r=this.ya-(e+.5)*this.Y_-1;t[i].ut=r}}pu(t,i){const s=Math.ceil(this.fu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.vu(s)?this.mu(s):s}fn(t){this.E_=!0,this.j_=t,this.uu(),this.ss.wu(),this.ss.ar()}gu(){return this.Y_}pn(t){const i=this.Y_;if(this.bu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.j_*i/this.Y_;this.j_=t}this.uu(),this.ss.wu(),this.ss.ar()}Mu(){return this.j_}Il(){if(this.Gi())return null;if(null!==this.H_)return this.H_;const t=this.Y_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.V_.y_(t,i,this.Ps.ignoreWhitespaceIndices,this.N_,this.U_),o=this.lu()+s,a=this.ou()-s,_=this.yu(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.q_.length?(s=this.q_[d],s.coord=this.jt(t.index),s.label=this.Su(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.Su(t),weight:t.weight},this.q_.push(s)),this.Y_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.q_.length=d,this.H_=this.q_,this.q_}xu(){let t;this.E_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.gu():this.Ps.rightOffset,this.fn(t)}Cu(t){this.E_=!0,this.F_=t,this.uu(),this.Q_()}Pu(t,i){const s=this.fu(t),n=this.gu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.Mu()+(s-this.fu(t)))}ha(t){this.Mo&&this.ua(),null===this.bo&&null===this.z_&&(this.Gi()||(this.bo=t,this.Tu()))}la(t){if(null===this.z_)return;const i=Xt(this.ya-t,0,this.ya),s=Xt(this.ya-l(this.bo),0,this.ya);0!==i&&0!==s&&this.pn(this.z_.gu*i/s)}oa(){null!==this.bo&&(this.bo=null,this.ku())}aa(t){null===this.Mo&&null===this.z_&&(this.Gi()||(this.Mo=t,this.Tu()))}_a(t){if(null===this.Mo)return;const i=(this.Mo-t)/this.gu();this.j_=l(this.z_).Mu+i,this.E_=!0,this.uu()}ua(){null!==this.Mo&&(this.Mo=null,this.ku())}Du(){this.Ru(this.Ps.rightOffset)}Ru(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.j_,n=performance.now();this.ss.un({Fu:t=>(t-n)/i>=1,Iu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.E_=!0,this.I_=t,this.V_.b_(t,i),this.uu()}Vu(){return this.B_}Lu(){return this.O_}Au(){return this.W_}cu(){return this.F_||0}Eu(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.bu((this.ya-n)/s),this.j_=t.yi()-this.cu(),i&&(this.j_=n?n/this.gu():this.Ps.rightOffset),this.uu(),this.E_=!0,this.ss.wu(),this.ss.ar()}Bu(){const t=this.lu(),i=this.ou();null!==t&&null!==i&&this.Eu(new Ci(t,i),!0)}Ou(t){const i=new Ci(t.from,t.to);this.Eu(i)}es(t){return void 0!==this.Co.timeFormatter?this.Co.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}K_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.N_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.N_.set(t,!0);this.U_++}yu(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}lu(){return 0===this.I_.length?null:0}ou(){return 0===this.I_.length?null:this.I_.length-1}Wu(t){return(this.ya-1-t)/this.Y_}fu(t){const i=this.Wu(t),s=this.cu()+this.j_-i;return Math.round(1e6*s)/1e6}bu(t){const i=this.Y_;this.Y_=t,this._u(),i!==this.Y_&&(this.E_=!0,this.zu())}nu(){if(!this.E_)return;if(this.E_=!1,this.Gi())return void this.$u(ki.R_());const t=this.cu(),i=this.ya/this.Y_,s=this.j_+t,n=new Ci(s-i+1,s);this.$u(new ki(n))}_u(){const t=Xt(this.Y_,this.Hu(),this.Nu());this.Y_!==t&&(this.Y_=t,this.E_=!0)}Nu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.ya}Hu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.I_.length?this.ya/this.I_.length:this.Ps.minBarSpacing}uu(){const t=this.Uu();null!==t&&this.j_<t&&(this.j_=t,this.E_=!0);const i=this.qu();this.j_>i&&(this.j_=i,this.E_=!0)}Uu(){const t=this.lu(),i=this.F_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.ya/this.Y_:Math.min(2,this.I_.length))}qu(){return this.Ps.fixRightEdge?0:this.ya/this.Y_-Math.min(2,this.I_.length)}Tu(){this.z_={gu:this.gu(),Mu:this.Mu()}}ku(){this.z_=null}Su(t){let i=this.L_.get(t.weight);return void 0===i&&(i=new xi(t=>this.ju(t),this.u_),this.L_.set(t.weight,i)),i.c_(t)}ju(t){return this.u_.formatTickmark(t,this.Co)}$u(t){const i=this.A_;this.A_=t,Pi(i.k_(),this.A_.k_())||this.B_.p(),Pi(i.D_(),this.A_.D_())||this.O_.p(),this.zu()}zu(){this.H_=null}J_(){this.zu(),this.L_.clear()}G_(){this.u_.updateFormatter(this.Co)}Q_(){if(!this.Ps.fixLeftEdge)return;const t=this.lu();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.j_-s-1;this.fn(t)}this._u()}tu(){this.uu(),this._u()}vu(t){return!this.Ps.ignoreWhitespaceIndices||(this.N_.get(t)||!1)}mu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.ou();for(;s;){const t=i.next().value;if(this.N_.get(t))return t;if(t<0||t>s)break}return t}X_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.Y_);this.ss.fn(i)}}}var Fi,Ii,Vi,Li,Ai;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Ei{constructor(t,i,s){this.Yu=[],this.Xu=[],this.ya=0,this.Gu=null,this.Ku=new a,this.Zu=new a,this.Ju=null,this.Qu=t,this.Ps=i,this.u_=s,this.Po=new S(this.Ps.layout.colorParsers),this.tc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.sc=new Yt(i.crosshair),i.addDefaultPane&&(this.nc(0),this.Yu[0].Aa(2)),this.ec=this.rc(0),this.hc=this.rc(1)}Ah(){this.lc(Y.bn())}ar(){this.lc(Y.gn())}Jh(){this.lc(new Y(1))}Eh(t){const i=this.oc(t);this.lc(i)}ac(){return this.Gu}_c(t){if(this.Gu?.r_===t?.r_&&this.Gu?.h_?.Gn===t?.h_?.Gn)return;const i=this.Gu;this.Gu=t,null!==i&&this.Eh(i.r_),null!==t&&t.r_!==i?.r_&&this.Eh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Yu.forEach(i=>i.Fa(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.Z_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Ku.p(),this.ec=this.rc(0),this.hc=this.rc(1),this.Ah()}uc(t,i,s=0){const n=this.Yu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fa({leftPriceScale:i}),this.Ku.p(),void this.Ah();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fa({rightPriceScale:i}),this.Ku.p(),void this.Ah();const e=this.cc(t,s);null!==e&&(e.$t.lr(i),this.Ku.p())}cc(t,i){const s=this.Yu[i];if(void 0===s)return null;const n=s.Ia(t);return null!==n?{Us:s,$t:n}:null}At(){return this.ph}qs(){return this.Yu}dc(){return this.Ct}fc(){return this.Zu}vc(t,i){t.Wo(i),this.wu()}Ea(t){this.ya=t,this.ph.Ea(this.ya),this.Yu.forEach(i=>i.Ea(t)),this.wu()}mc(t){1!==this.Yu.length&&(r(t>=0&&t<this.Yu.length,"Invalid pane index"),this.Yu.splice(t,1),this.Ah())}wc(t,i){if(this.Yu.length<2)return;r(t>=0&&t<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu.reduce((t,i)=>t+i.La(),0),e=this.Yu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Yu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.Aa(i*l);let a=i-o,_=this.Yu.length-1;for(const t of this.Yu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.Aa(s)}this.Ah()}gc(t,i){r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index");const s=this.Yu[t],n=this.Yu[i];this.Yu[t]=n,this.Yu[i]=s,this.Ah()}bc(t,i){if(r(t>=0&&t<this.Yu.length&&i>=0&&i<this.Yu.length,"Invalid pane index"),t===i)return;const[s]=this.Yu.splice(t,1);this.Yu.splice(i,0,s),this.Ah()}qa(t,i,s){t.qa(i,s)}ja(t,i,s){t.ja(i,s),this.Bh(),this.lc(this.Mc(t,2))}Ya(t,i){t.Ya(i),this.lc(this.Mc(t,2))}Xa(t,i,s){i.Io()||t.Xa(i,s)}Ga(t,i,s){i.Io()||(t.Ga(i,s),this.Bh(),this.lc(this.Mc(t,2)))}Ka(t,i){i.Io()||(t.Ka(i),this.lc(this.Mc(t,2)))}Ja(t,i){t.Ja(i),this.lc(this.Mc(t,2))}yc(t){this.ph.ha(t)}Sc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Pu(t,i),this.wu()}xc(t){this.Cc(0),this.Pc(t),this.Tc()}kc(t){this.ph.la(t),this.wu()}Dc(){this.ph.oa(),this.ar()}Cc(t){this.ph.aa(t)}Pc(t){this.ph._a(t),this.wu()}Tc(){this.ph.ua(),this.ar()}Xs(){return this.Xu}Rc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.ph.pu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const o=n.ks(),a=o.Bt();if(null!==a&&(r=o.Ds(i,a)),r=this.sc.Ml(r,h,n),this.Ct.Es(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this._c(e&&{r_:e.r_,h_:e.h_,o_:e.o_||null}),this.Zu.p(this.Ct.Lt(),{x:t,y:i},s)}}Fc(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.ph.iu(i,!0),o=this.ph.jt(l(h));this.Rc(o,r,null,s,!0)}Ic(t){this.dc().Os(),this.Jh(),t||this.Zu.p(null,null,null)}Bh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Rc(i,s,null,t)}this.Ct.zs()}Vc(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.cu(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),o=null!==t&&t>r&&!l,a=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.ph.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.ph.fn(this.ph.Mu()-i)}}this.ph.Cu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Yu.find(i=>i.Ft().includes(t));return void 0===i?null:i}wu(){this.Yu.forEach(t=>t.t_()),this.Bh()}m(){this.Yu.forEach(t=>t.m()),this.Yu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Lc(){return this.tc}Yn(){return this.tc.W()}Va(){return this.Ku}Ac(t,i){const s=this.nc(i);this.Ec(t,s),this.Xu.push(t),1===this.Xu.length?this.Ah():this.ar()}Bc(t){const i=this.Nn(t),s=this.Xu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Xu.splice(s,1),n.na(t),t.m&&t.m(),this.ph.K_();const e=this.Yu.length;this.Oc(n),this.Yu.length<e&&this.Ah()}Lh(t,i){const s=l(this.Nn(t));s.na(t,!0),s.ia(t,i,!0)}Bu(){const t=Y.gn();t.hn(),this.lc(t)}Wc(t){const i=Y.gn();i._n(t),this.lc(i)}dn(){const t=Y.gn();t.dn(),this.lc(t)}pn(t){const i=Y.gn();i.pn(t),this.lc(i)}fn(t){const i=Y.gn();i.fn(t),this.lc(i)}un(t){const i=Y.gn();i.un(t),this.lc(i)}ln(){const t=Y.gn();t.ln(),this.lc(t)}zc(){return this.Ps.rightPriceScale.visible?"right":"left"}$c(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Hc(t))return;const s=l(this.Nn(t));s.na(t);const n=this.nc(i);this.Ec(t,n),0===s.yl().length&&this.Oc(s),this.Ah()}Nc(){return this.hc}q(){return this.ec}Ut(t){const i=this.hc,s=this.ec;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Ju||this.Ju.wr!==s||this.Ju.gr!==i)this.Ju={wr:s,gr:i,Uc:new Map};else{const i=this.Ju.Uc.get(t);if(void 0!==i)return i}const n=this.Po.it(s,i,t/100);return this.Ju.Uc.set(t,n),n}qc(t){return this.Yu.indexOf(t)}Ki(){return this.Po}jc(){return this.Yc()}Yc(t){const i=new wi(this.ph,this);this.Yu.push(i);const s=t??this.Yu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.lc(n),i}nc(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Yu.length,t))<this.Yu.length?this.Yu[t]:this.Yc(t)}Hc(t){return this.Yu.findIndex(i=>i.za().includes(t))}Mc(t,i){const s=new Y(i);if(null!==t){const n=this.Yu.indexOf(t);s.tn(n,{sn:i})}return s}oc(t,i){return void 0===i&&(i=2),this.Mc(this.Nn(t),i)}lc(t){this.Qu&&this.Qu(t),this.Yu.forEach(t=>t.n_()._r().Tt())}Ec(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.zc();i.ia(t,n),j(n)||t.lr(t.W())}rc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Oc(t){!t.Wa()&&0===t.yl().length&&this.Yu.length>1&&this.Yu.splice(this.qc(t),1)}}function Bi(t){if(t>=1)return 0;let i=0;for(;i<8;i++){const s=Math.round(t);if(Math.abs(s-t)<1e-8)return i;t*=10}return i}function Oi(t){return!u(t)&&!d(t)}function Wi(t){return u(t)}!function(t){t[t.Disabled=0]="Disabled",t[t.Continuous=1]="Continuous",t[t.OnDataUpdate=2]="OnDataUpdate"}(Ii||(Ii={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Vi||(Vi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Li||(Li={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Ai||(Ai={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>K(zi(t),4))(t)).replace(/yy/g,(t=>K(zi(t)%100,2))(t)).replace(/MMMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"long"}))(t,s)).replace(/MMM/g,((t,i)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(i,{month:"short"}))(t,s)).replace(/MM/g,(t=>K((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>K((t=>t.getUTCDate())(t),2))(t))}class Hi{constructor(t="yyyy-MM-dd",i="default"){this.Xc=t,this.Gc=i}c_(t){return $i(t,this.Xc,this.Gc)}}class Ni{constructor(t){this.Kc=t||"%h:%m:%s"}c_(t){return this.Kc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Zc:"yyyy-MM-dd",Jc:"%h:%m:%s",Qc:" ",td:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.sd=new Hi(i.Zc,i.td),this.nd=new Ni(i.Jc),this.ed=i.Qc}c_(t){return`${this.sd.c_(t)}${this.ed}${this.nd.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{rd:(Gi=1,1e3*Gi),hd:10},{rd:Yi(1),hd:20},{rd:Yi(5),hd:21},{rd:Yi(30),hd:22},{rd:ji(1),hd:30},{rd:ji(3),hd:31},{rd:ji(6),hd:32},{rd:ji(12),hd:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].rd)!==Math.floor(t.getTime()/Xi[s].rd))return Xi[s].hd;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!Oi(i))throw new Error("time must be of type BusinessDay");const s=new Date(Date.UTC(i.year,i.month-1,i.day,0,0,0,0));return{ld:Math.round(s.getTime()/1e3),od:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{ld:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}class ss{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Oi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"ld"in t?t.ld:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.od?new Date(1e3*i.ld).getTime():new Date(Date.UTC(i.od.year,i.od.month-1,i.od.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.ad=new qi({Zc:i,Jc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",Qc:" ",td:t.locale}):this.ad=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this.ad.c_(new Date(1e3*i.ld))}formatTickmark(t,i){const s=function(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.od?new Date(1e3*t.ld):new Date(Date.UTC(t.od.year,t.od.month-1,t.od.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.ld,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).ld);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).ld-(s||Zi(i.time).ld),s=Zi(i.time).ld,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.ld-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.ld),s)}}(t,i)}static _d(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function ns(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function es(t,i){return t.width===i.width&&t.height===i.height}var rs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var hs=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=ns({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return ns({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=ns(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;es(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=ns(this._transformBitmapSize(t,this._canvasElementClientSize)),n=es(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&es(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=ls(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new rs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=ls(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return ns({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):ns({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=ns({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function ls(t){return t.ownerDocument.defaultView}var 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.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.wd=null,this.gd=!1,this.bd=null,this.Md=null,this.yd=!1,this.Sd=!1,this.xd=!1,this.Cd=null,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Id=0,this.Vd=!1,this.Ld=!1,this.Ad=!1,this.Ed=0,this.Bd=null,this.Od=!cs(),this.Wd=t=>{this.zd(t)},this.$d=t=>{if(this.Hd(t)){const i=this.Nd(t);if(++this.fd,this.vd&&this.fd>1){const{Ud:s}=this.qd(ws(t),this.md);s<30&&!this.xd&&this.jd(i,this.Xd.Yd),this.Gd()}}else{const i=this.Nd(t);if(++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}}},this.Qd=t,this.Xd=i,this.Ps=s,this.tp()}m(){null!==this.Cd&&(this.Cd(),this.Cd=null),null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.kd&&(this.kd(),this.kd=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Td&&(this.Td(),this.Td=null),this.ip(),this.Jd()}sp(t){this.kd&&this.kd();const i=this.np.bind(this);if(this.kd=()=>{this.Qd.removeEventListener("mousemove",i)},this.Qd.addEventListener("mousemove",i),this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.ep),this.Od=!0}Jd(){null!==this.dd&&clearTimeout(this.dd),this.ud=0,this.dd=null,this.pd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Gd(){null!==this.vd&&clearTimeout(this.vd),this.fd=0,this.vd=null,this.md={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}np(t){if(this.Ad||null!==this.Md)return;if(this.Hd(t))return;const i=this.Nd(t);this.Kd(i,this.Xd.rp),this.Od=!0}hp(t){const i=bs(t.changedTouches,l(this.Bd));if(null===i)return;if(this.Ed=gs(t),null!==this.Fd)return;if(this.Ld)return;this.Vd=!0;const s=this.qd(ws(i),l(this.Md)),{lp:n,op:e,Ud:r}=s;if(this.yd||!(r<5)){if(!this.yd){const t=.5*n,i=e>=t&&!this.Ps.ap(),s=t>e&&!this.Ps._p();i||s||(this.Ld=!0),this.yd=!0,this.xd=!0,this.ip(),this.Gd()}if(!this.Ld){const s=this.Nd(t,i);this.jd(s,this.Xd.up),ms(t)}}}cp(t){if(0!==t.button)return;const i=this.qd(ws(t),l(this.bd)),{Ud:s}=i;if(s>=5&&(this.Sd=!0,this.Jd()),this.Sd){const i=this.Nd(t);this.Kd(i,this.Xd.dp)}}qd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{lp:s,op:n,Ud:s+n}}pp(t){let i=bs(t.changedTouches,l(this.Bd));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Bd=null,this.Ed=gs(t),this.ip(),this.Md=null,this.Rd&&(this.Rd(),this.Rd=null);const s=this.Nd(t,i);if(this.jd(s,this.Xd.fp),++this.fd,this.vd&&this.fd>1){const{Ud:t}=this.qd(ws(i),this.md);t<30&&!this.xd&&this.jd(s,this.Xd.Yd),this.Gd()}else this.xd||(this.jd(s,this.Xd.vp),this.Xd.vp&&ms(t));0===this.fd&&ms(t),0===t.touches.length&&this.gd&&(this.gd=!1,ms(t))}zd(t){if(0!==t.button)return;const i=this.Nd(t);if(this.bd=null,this.Ad=!1,this.Dd&&(this.Dd(),this.Dd=null),us()){this.Qd.ownerDocument.documentElement.removeEventListener("mouseleave",this.Wd)}if(!this.Hd(t))if(this.Kd(i,this.Xd.mp),++this.ud,this.dd&&this.ud>1){const{Ud:s}=this.qd(ws(t),this.pd);s<5&&!this.Sd&&this.Kd(i,this.Xd.Zd),this.Jd()}else this.Sd||this.Kd(i,this.Xd.wp)}ip(){null!==this.wd&&(clearTimeout(this.wd),this.wd=null)}gp(t){if(null!==this.Bd)return;const i=t.changedTouches[0];this.Bd=i.identifier,this.Ed=gs(t);const s=this.Qd.ownerDocument.documentElement;this.xd=!1,this.yd=!1,this.Ld=!1,this.Md=ws(i),this.Rd&&(this.Rd(),this.Rd=null);{const i=this.hp.bind(this),n=this.pp.bind(this);this.Rd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.ip(),this.wd=setTimeout(this.bp.bind(this,t),240)}const n=this.Nd(t,i);this.jd(n,this.Xd.Mp),this.vd||(this.fd=0,this.vd=setTimeout(this.Gd.bind(this),500),this.md=ws(i))}yp(t){if(0!==t.button)return;const i=this.Qd.ownerDocument.documentElement;us()&&i.addEventListener("mouseleave",this.Wd),this.Sd=!1,this.bd=ws(t),this.Dd&&(this.Dd(),this.Dd=null);{const t=this.cp.bind(this),s=this.zd.bind(this);this.Dd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ad=!0,this.Hd(t))return;const s=this.Nd(t);this.Kd(s,this.Xd.Sp),this.dd||(this.ud=0,this.dd=setTimeout(this.Jd.bind(this),500),this.pd=ws(t))}tp(){this.Qd.addEventListener("mouseenter",this.sp.bind(this)),this.Qd.addEventListener("touchcancel",this.ip.bind(this));{const t=this.Qd.ownerDocument,i=t=>{this.Xd.xp&&(t.composed&&this.Qd.contains(t.composedPath()[0])||t.target&&this.Qd.contains(t.target)||this.Xd.xp())};this.Pd=()=>{t.removeEventListener("touchstart",i)},this.Cd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}cs()&&(this.Td=()=>{this.Qd.removeEventListener("dblclick",this.$d)},this.Qd.addEventListener("dblclick",this.$d)),this.Qd.addEventListener("mouseleave",this.Cp.bind(this)),this.Qd.addEventListener("touchstart",this.gp.bind(this),{passive:!0}),ps(this.Qd),this.Qd.addEventListener("mousedown",this.yp.bind(this)),this.Pp(),this.Qd.addEventListener("touchmove",()=>{},{passive:!1})}Pp(){void 0===this.Xd.Tp&&void 0===this.Xd.kp&&void 0===this.Xd.Dp||(this.Qd.addEventListener("touchstart",t=>this.Rp(t.touches),{passive:!0}),this.Qd.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Fd&&void 0!==this.Xd.kp){const i=vs(t.touches[0],t.touches[1])/this.Id;this.Xd.kp(this.Fd,i),ms(t)}},{passive:!1}),this.Qd.addEventListener("touchend",t=>{this.Rp(t.touches)}))}Rp(t){1===t.length&&(this.Vd=!1),2!==t.length||this.Vd||this.gd?this.Fp():this.Ip(t)}Ip(t){const i=this.Qd.getBoundingClientRect()||{left:0,top:0};this.Fd={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Id=vs(t[0],t[1]),void 0!==this.Xd.Tp&&this.Xd.Tp(),this.ip()}Fp(){null!==this.Fd&&(this.Fd=null,void 0!==this.Xd.Dp&&this.Xd.Dp())}Cp(t){if(this.kd&&this.kd(),this.Hd(t))return;if(!this.Od)return;const i=this.Nd(t);this.Kd(i,this.Xd.Vp),this.Od=!cs()}bp(t){const i=bs(t.touches,l(this.Bd));if(null===i)return;const s=this.Nd(t,i);this.jd(s,this.Xd.Lp),this.xd=!0,this.gd=!0}Hd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:gs(t)<this.Ed+500}jd(t,i){i&&i.call(this.Xd,t)}Kd(t,i){i&&i.call(this.Xd,t)}Nd(t,i){const s=i||t,n=this.Qd.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Ap:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Ep:t.type,Bp:s.target,a_:t.view,Op:()=>{"touchstart"!==t.type&&ms(t)}}}}function vs(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ms(t){t.cancelable&&t.preventDefault()}function ws(t){return{ut:t.pageX,ct:t.pageY}}function gs(t){return t.timeStamp||performance.now()}function bs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ms{constructor(t,i,s){this.Wp=null,this.zp=null,this.$p=!0,this.Hp=null,this.Np=t,this.Up=t.qp()[i],this.jp=t.qp()[s],this.Yp=document.createElement("tr"),this.Yp.style.height="1px",this.Xp=document.createElement("td"),this.Xp.style.position="relative",this.Xp.style.padding="0",this.Xp.style.margin="0",this.Xp.setAttribute("colspan","3"),this.Gp(),this.Yp.appendChild(this.Xp),this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(this.Wp=null,this.zp=null)}m(){null!==this.zp&&this.zp.m()}Zp(){return this.Yp}Jp(){return ns({width:this.Up.Jp().width,height:1})}Qp(){return ns({width:this.Up.Qp().width,height:1*window.devicePixelRatio})}tf(t,i,s){const n=this.Qp();t.fillStyle=this.Np.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Gp(),this.Np.W().layout.panes.enableResize!==this.$p&&(this.$p=this.Np.W().layout.panes.enableResize,this.$p?this.Kp():(null!==this.Wp&&(this.Xp.removeChild(this.Wp.if),this.Xp.removeChild(this.Wp.sf),this.Wp=null),null!==this.zp&&(this.zp.m(),this.zp=null)))}Kp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Xp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Xp.appendChild(s);const e={ep:this.nf.bind(this),Vp:this.ef.bind(this),Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this)};this.zp=new fs(s,e,{ap:()=>!1,_p:()=>!0}),this.Wp={sf:s,if:t}}Gp(){this.Xp.style.background=this.Np.W().layout.panes.separatorColor}nf(t){null!==this.Wp&&(this.Wp.sf.style.backgroundColor=this.Np.W().layout.panes.separatorHoverColor)}ef(t){null!==this.Wp&&null===this.Hp&&(this.Wp.sf.style.backgroundColor="")}rf(t){if(null===this.Wp)return;const i=this.Up.af().La()+this.jp.af().La(),s=i/(this.Up.Jp().height+this.jp.Jp().height),n=30*s;i<=2*n||(this.Hp={_f:t.pageY,uf:this.Up.af().La(),cf:i-n,df:i,pf:s,ff:n},this.Wp.if.style.display="block")}hf(t){const i=this.Hp;if(null===i)return;const s=(t.pageY-i._f)*i.pf,n=Xt(i.uf+s,i.ff,i.cf);this.Up.af().Aa(n),this.jp.af().Aa(i.df-n),this.Np.ti().Ah()}lf(t){null!==this.Hp&&null!==this.Wp&&(this.Hp=null,this.Wp.if.style.display="none")}}function ys(t,i){return t.vf-i.vf}function Ss(t,i,s){const n=(t.vf-i.vf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class xs{constructor(t,i,s,n){this.mf=null,this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=0,this.Sf=0,this.xf=t,this.Cf=i,this.Pf=s,this.Mn=n}Tf(t,i){if(null!==this.mf){if(this.mf.gt===i)return void(this.mf.vf=t);if(Math.abs(this.mf.vf-t)<this.Mn)return}this.bf=this.gf,this.gf=this.wf,this.wf=this.mf,this.mf={gt:i,vf:t}}ae(t,i){if(null===this.mf||null===this.wf)return;if(i-this.mf.gt>50)return;let s=0;const n=Ss(this.mf,this.wf,this.Cf),e=ys(this.mf,this.wf),r=[n],h=[e];if(s+=e,null!==this.gf){const t=Ss(this.wf,this.gf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.wf,this.gf);if(r.push(t),h.push(i),s+=i,null!==this.bf){const t=Ss(this.gf,this.bf,this.Cf);if(Math.sign(t)===Math.sign(n)){const i=ys(this.gf,this.bf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.xf||(this.Mf={vf:t,gt:i},this.Sf=l,this.yf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Pf))}Iu(t){const i=l(this.Mf),s=t-i.gt;return i.vf+this.Sf*(Math.pow(this.Pf,s)-1)/Math.log(this.Pf)}Fu(t){return null===this.Mf||this.kf(t)===this.yf}kf(t){const i=t-l(this.Mf).gt;return Math.min(i,this.yf)}}class Cs{constructor(t,i){this.Df=void 0,this.Rf=void 0,this.Ff=void 0,this.vs=!1,this.If=t,this.Vf=i,this.Lf()}Tt(){this.Lf()}Af(){this.Df&&this.If.removeChild(this.Df),this.Rf&&this.If.removeChild(this.Rf),this.Df=void 0,this.Rf=void 0}Ef(){return this.vs!==this.Bf()||this.Ff!==this.Of()}Of(){return this.Vf.ti().Ki().tt(this.Vf.W().layout.textColor)>160?"dark":"light"}Bf(){return this.Vf.W().layout.attributionLogo}Wf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Lf(){this.Ef()&&(this.Af(),this.vs=this.Bf(),this.vs&&(this.Ff=this.Of(),this.Rf=document.createElement("style"),this.Rf.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.Df=document.createElement("a"),this.Df.href=`https://pipsend.com${this.Wf()}`,this.Df.title="Powered by Pipsend Charts",this.Df.id="pipsend-attr-logo",this.Df.target="_blank",this.Df.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.Df.toggleAttribute("data-dark","dark"===this.Ff),this.If.appendChild(this.Rf),this.If.appendChild(this.Df)))}}function Ps(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new hs(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function Ts(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function ks(t,i,s,n){t.nh&&t.nh(i,s,n)}function Ds(t,i,s,n){t.et(i,s,n)}function Rs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Fs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Is(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],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.zf=null,this.$f=!1,this.Hf=new it(200),this.Nf=null,this.Uf=0,this.qf=!1,this.jf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Xf=()=>{this.qf||this.Pt.Yf().ti().ar()},this.Pt=t,this.Ps=i,this.xo=i.layout,this.tc=s,this.Gf="left"===n,this.Kf=Fs("normal",n),this.Zf=Fs("top",n),this.Jf=Fs("bottom",n),this.Xp=document.createElement("div"),this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Xp.style.width="25px",this.Xp.style.left="0",this.Xp.style.position="relative",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const e=this.Qf.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.tv=Ps(this.Xp,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const r=this.tv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={Sp:this.rf.bind(this),Mp:this.rf.bind(this),dp:this.hf.bind(this),up:this.hf.bind(this),xp:this.iv.bind(this),mp:this.lf.bind(this),fp:this.lf.bind(this),Zd:this.sv.bind(this),Yd:this.sv.bind(this),ep:this.nv.bind(this),Vp:this.ef.bind(this)};this.zp=new fs(this.tv.canvasElement,h,{ap:()=>!this.Ps.handleScroll.vertTouchDrag,_p:()=>!0})}m(){this.zp.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Yi&&this.Yi.ra().u(this),this.Yi=null}Zp(){return this.Xp}P(){return this.xo.fontSize}ev(){const t=this.tc.W();return this.Nf!==t.T&&(this.Hf.Vn(),this.Nf=t.T),t}rv(){if(null===this.Yi)return 0;let t=0;const i=this.ev(),s=l(this.Qf.canvasElement.getContext("2d",{colorSpace:this.Pt.Yf().W().layout.colorSpace}));s.save();const n=this.Yi.Il();s.font=this.hv(),n.length>0&&(t=Math.max(this.Hf.Ii(s,n[0].Jl),this.Hf.Ii(s,n[n.length-1].Jl)));const e=this.lv();for(let i=e.length;i--;){const n=this.Hf.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.zf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.zf.height-2,r);t=Math.max(t,this.Hf.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Hf.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ds(Math.ceil(i.S+i.C+i.V+i.L+5+o))}ov(t){null!==this.zf&&es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`)}av(){return l(this.zf).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ra().u(this),this.Yi=t,t.ra().i(this.do.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt.af();this.Pt.Yf().ti().Ja(t,l(this.$t()))}_v(t){if(null===this.zf)return;const i={colorSpace:this.Pt.Yf().W().layout.colorSpace};if(1!==t){this.uv(),this.Qf.applySuggestedBitmapSize();const t=as(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)}),this.Pt.pv(t,this.Jf),this.fv(t),this.Pt.pv(t,this.Kf),this.vv(t))}this.tv.applySuggestedBitmapSize();const s=as(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.mv(s),this.Pt.pv(s,this.Zf))}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Il()}rf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!0,i.qa(s,this.Yi,t.localY)}hf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af(),n=this.Yi;i.ja(s,n,t.localY)}iv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Yf().ti(),i=this.Pt.af(),s=this.Yi;this.$f&&(this.$f=!1,t.Ya(i,s))}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Yf().ti(),s=this.Pt.af();this.$f=!1,i.Ya(s,this.Yi)}sv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}nv(t){if(null===this.Yi)return;!this.Pt.Yf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Lo()||this.wv(1)}ef(t){this.wv(0)}lv(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt.af(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.af().Ft()),t}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.af().ti(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.zf||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.ev().S*s));let e;e=this.Gf?i.width-n:0,t.fillRect(e,0,n,i.height)}fv(t){if(null===this.zf||null===this.Yi)return;const i=this.Yi.Il(),s=this.Yi.W(),n=this.ev(),e=this.Gf?this.zf.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.hv(),t.fillStyle=s.textColor??this.xo.textColor,t.textAlign=this.Gf?"right":"left",t.textBaseline="middle";const r=this.Gf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.Hf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}uv(){if(null===this.zf||null===this.Yi)return;let t=this.zf.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt.af(),e=this.ev();this.Yi===n.qn()&&this.Pt.af().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.gv(i,e,t)}gv(t,i,s){if(null===this.zf)return;const n=t.filter(t=>t.Li()<=s),e=t.filter(t=>t.Li()>s);n.sort((t,i)=>i.Li()-t.Li()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Li()-i.Li());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Li();n>-t&&n<t&&s.Hi(t),n>this.zf.height-t&&n<this.zf.height+t&&s.Hi(this.zf.height-t)}Is(n,1,this.zf.height,i),Is(e,-1,this.zf.height,i)}vv(t){if(null===this.zf)return;const i=this.lv(),s=this.ev(),n=this.Gf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Hf,n)}})}mv(t){if(null===this.zf||null===this.Yi)return;const i=this.Pt.Yf().ti(),s=[],n=this.Pt.af(),e=i.dc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.ev(),h=this.Gf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Hf,h)})})}wv(t){this.Xp.style.cursor=1===t?"ns-resize":"default"}do(){const t=this.rv();this.Uf<t&&this.Pt.Yf().ti().Ah(),this.Uf=t}hv(){return g(this.xo.fontSize,this.xo.fontFamily)}}function Ls(t,i){return t.tl?.(i)??[]}function As(t,i){return t.$s?.(i)??[]}function Es(t,i){return t.cs?.(i)??[]}function Bs(t,i){return t.Zh?.(i)??[]}class Os{constructor(t,i){this.zf=ns({width:0,height:0}),this.bv=null,this.Mv=null,this.yv=null,this.Sv=null,this.xv=!1,this.Cv=new a,this.Pv=new a,this.Tv=0,this.kv=!1,this.Dv=null,this.Rv=!1,this.Fv=null,this.Iv=null,this.qf=!1,this.jf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Xf=()=>{this.qf||null===this.Vv||this.ss().ar()},this.Vf=t,this.Vv=i,this.Vv.s_().i(this.Lv.bind(this),this,!0),this.Av=document.createElement("td"),this.Av.style.padding="0",this.Av.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Av.appendChild(s),this.Qf=Ps(s,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const n=this.Qf.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.tv=Ps(s,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Yp=document.createElement("tr"),this.Yp.appendChild(this.Ev),this.Yp.appendChild(this.Av),this.Yp.appendChild(this.Bv),this.Ov(),this.zp=new fs(this.tv.canvasElement,this,{ap:()=>null===this.Dv&&!this.Vf.W().handleScroll.vertTouchDrag,_p:()=>null===this.Dv&&!this.Vf.W().handleScroll.horzTouchDrag})}m(){null!==this.bv&&this.bv.m(),null!==this.Mv&&this.Mv.m(),this.yv=null,this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose(),null!==this.Vv&&(this.Vv.s_().u(this),this.Vv.m()),this.zp.m()}af(){return l(this.Vv)}Wv(t){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=t,null!==this.Vv&&this.Vv.s_().i(Os.prototype.Lv.bind(this),this,!0),this.Ov(),this.Vf.qp().indexOf(this)===this.Vf.qp().length-1?(this.yv=this.yv??new Cs(this.Av,this.Vf),this.yv.Tt()):(this.yv?.Af(),this.yv=null)}Yf(){return this.Vf}Zp(){return this.Yp}Ov(){if(null!==this.Vv&&(this.zv(),0!==this.ss().Xs().length)){if(null!==this.bv){const t=this.Vv.Na();this.bv.us(l(t))}if(null!==this.Mv){const t=this.Vv.Ua();this.Mv.us(l(t))}}}$v(){null!==this.bv&&this.bv.Tt(),null!==this.Mv&&this.Mv.Tt()}La(){return null!==this.Vv?this.Vv.La():0}Aa(t){this.Vv&&this.Vv.Aa(t)}ep(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}Sp(t){this.Hv(),this.Uv(),this.Nv(t.localX,t.localY,t)}rp(t){if(!this.Vv)return;this.Hv();const i=t.localX,s=t.localY;this.Nv(i,s,t)}wp(t){null!==this.Vv&&(this.Hv(),this.qv(t))}Zd(t){null!==this.Vv&&this.jv(this.Pv,t)}Yd(t){this.Zd(t)}dp(t){this.Hv(),this.Yv(t),this.Nv(t.localX,t.localY,t)}mp(t){null!==this.Vv&&(this.Hv(),this.kv=!1,this.Xv(t))}vp(t){null!==this.Vv&&this.qv(t)}Lp(t){if(this.kv=!0,null===this.Dv){const i={x:t.localX,y:t.localY};this.Gv(i,i,t)}}Vp(t){null!==this.Vv&&(this.Hv(),this.Vv.ti()._c(null),this.Kv())}Zv(){return this.Cv}Jv(){return this.Pv}Tp(){this.Tv=1,this.ss().ln()}kp(t,i){if(!this.Vf.W().handleScale.pinch)return;const s=5*(i-this.Tv);this.Tv=i,this.ss().Sc(t.ut,s)}Mp(t){this.kv=!1,this.Rv=null!==this.Dv,this.Uv();const i=this.ss().dc();null!==this.Dv&&i.It()&&(this.Fv={x:i.ni(),y:i.ei()},this.Dv={x:t.localX,y:t.localY})}up(t){if(null===this.Vv)return;const i=t.localX,s=t.localY;if(null!==this.Dv){this.Rv=!1;const n=l(this.Fv),e=n.x+(i-this.Dv.x),r=n.y+(s-this.Dv.y);return void this.Nv(e,r,t)}this.Yv(t)}fp(t){0===this.Yf().W().trackingMode.exitMode&&(this.Rv=!0),this.Qv(),this.Xv(t)}Xn(t,i){const s=this.Vv;return null===s?null:Si(s,t,i)}tm(t,i){l("left"===i?this.bv:this.Mv).ov(ns({width:t,height:this.zf.height}))}Jp(){return this.zf}ov(t){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Av.style.width=t.width+"px",this.Av.style.height=t.height+"px")}im(){const t=l(this.Vv);t.Ha(t.Na()),t.Ha(t.Ua());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ha(s),i.zs()}for(const i of t.e_())i.zs()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;null!==t&&t.drawImage(n,i,s)}}_v(t){if(0===t)return;if(null===this.Vv)return;t>1&&this.im(),null!==this.bv&&this.bv._v(t),null!==this.Mv&&this.Mv._v(t);const i={colorSpace:this.Vf.W().layout.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const t=as(this.Qf,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.cv(t)}),this.Vv&&(this.sm(t,Ls),this.nm(t),this.sm(t,As),this.sm(t,Es)))}this.tv.applySuggestedBitmapSize();const s=as(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.rm(s),this.sm(s,Bs),this.sm(s,Es))}hm(){return this.bv}lm(){return this.Mv}pv(t,i){this.sm(t,i)}Lv(){null!==this.Vv&&this.Vv.s_().u(this),this.Vv=null}qv(t){this.jv(this.Cv,t)}jv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().pu(s),{x:s,y:n},i)}cv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Nc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}nm(t){const i=l(this.Vv),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}rm(t){this.om(t,As,Ds,this.ss().dc())}sm(t,i){const s=l(this.Vv),n=s.Ft(),e=s.e_();for(const s of e)this.om(t,i,ks,s);for(const s of n)this.om(t,i,ks,s);for(const s of e)this.om(t,i,Ds,s);for(const s of n)this.om(t,i,Ds,s)}om(t,i,s,n){const e=l(this.Vv),r=e.ti().ac(),h=null!==r&&r.r_===n,o=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Rs(i,i=>s(i,t,h,o),n,e)}zv(){if(null===this.Vv)return;const t=this.Vf,i=this.Vv.Na().W().visible,s=this.Vv.Ua().W().visible;i||null===this.bv||(this.Ev.removeChild(this.bv.Zp()),this.bv.m(),this.bv=null),s||null===this.Mv||(this.Bv.removeChild(this.Mv.Zp()),this.Mv.m(),this.Mv=null);const n=t.ti().Lc();i&&null===this.bv&&(this.bv=new Vs(this,t.W(),n,"left"),this.Ev.appendChild(this.bv.Zp())),s&&null===this.Mv&&(this.Mv=new Vs(this,t.W(),n,"right"),this.Bv.appendChild(this.Mv.Zp()))}am(t){return t.Ap&&this.kv||null!==this.Dv}_m(t){return Math.max(0,Math.min(t,this.zf.width-1))}um(t){return Math.max(0,Math.min(t,this.zf.height-1))}Nv(t,i,s){this.ss().Rc(this._m(t),this.um(i),s,l(this.Vv))}Kv(){this.ss().Ic()}Qv(){this.Rv&&(this.Dv=null,this.Kv())}Gv(t,i,s){this.Dv=t,this.Rv=!1,this.Nv(i.x,i.y,s);const n=this.ss().dc();this.Fv={x:n.ni(),y:n.ei()}}ss(){return this.Vf.ti()}Xv(t){if(!this.xv)return;const i=this.ss(),s=this.af();if(i.Ka(s,s.ks()),this.Sv=null,this.xv=!1,i.Tc(),null!==this.Iv){const t=performance.now(),s=i.At();this.Iv.ae(s.Mu(),t),this.Iv.Fu(t)||i.un(this.Iv)}}Hv(){this.Dv=null}Uv(){if(!this.Vv)return;if(this.ss().ln(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)l(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Vv.ks().Gi()&&this.ss().At().Gi()}Yv(t){if(null===this.Vv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.Vf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Ap)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Ap))return;const h=this.Vv.ks(),l=performance.now();if(null!==this.Sv||this.am(t)||(this.Sv={x:t.clientX,y:t.clientY,ld:l,dm:t.localX,pm:t.localY}),null!==this.Sv&&!this.xv&&(this.Sv.x!==t.clientX||this.Sv.y!==t.clientY)){if(t.Ap&&r.touch||!t.Ap&&r.mouse){const t=s.gu();this.Iv=new xs(.2/t,7/t,.997,15/t),this.Iv.Tf(s.Mu(),this.Sv.ld)}else this.Iv=null;h.Gi()||i.Xa(this.Vv,h,t.localY),i.Cc(t.localX),this.xv=!0}this.xv&&(h.Gi()||i.Ga(this.Vv,h,t.localY),i.Pc(t.localX),null!==this.Iv&&this.Iv.Tf(s.Mu(),l))}}class Ws{constructor(t,i,s,n,e){this.xt=!0,this.zf=ns({width:0,height:0}),this.jf=()=>this._v(3),this.Gf="left"===t,this.tc=s.Lc,this.Ps=i,this.fm=n,this.vm=e,this.Xp=document.createElement("div"),this.Xp.style.width="25px",this.Xp.style.height="100%",this.Xp.style.overflow="hidden",this.Qf=Ps(this.Xp,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf)}m(){this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Xp}Jp(){return this.zf}ov(t){es(this.zf,t)||(this.zf=t,this.Qf.resizeCanvasElement(t),this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.xt=!0)}_v(t){if(t<3&&!this.xt)return;if(0===this.zf.width||0===this.zf.height)return;this.xt=!1,this.Qf.applySuggestedBitmapSize();const i=as(this.Qf,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t)})}Qp(){return this.Qf.bitmapSize}tf(t,i,s){const n=this.Qp();n.width>0&&n.height>0&&t.drawImage(this.Qf.canvasElement,i,s)}dv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.fm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.tc.W().S*s),r=Math.floor(this.tc.W().S*n),h=this.Gf?i.width-e:0;t.fillRect(h,0,e,r)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.vm())}}function zs(t){return i=>i.nl?.(t)??[]}const $s=zs("normal"),Hs=zs("top"),Ns=zs("bottom");class Us{constructor(t,i){this.wm=null,this.gm=null,this.M=null,this.bm=!1,this.zf=ns({width:0,height:0}),this.Mm=new a,this.Hf=new it(5),this.qf=!1,this.jf=()=>{this.qf||this.Vf.ti().ar()},this.Xf=()=>{this.qf||this.Vf.ti().ar()},this.Vf=t,this.u_=i,this.Ps=t.W().layout,this.Df=document.createElement("tr"),this.ym=document.createElement("td"),this.ym.style.padding="0",this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.Xp=document.createElement("td"),this.Xp.style.height="25px",this.Xp.style.padding="0",this.xm=document.createElement("div"),this.xm.style.width="100%",this.xm.style.height="100%",this.xm.style.position="relative",this.xm.style.overflow="hidden",this.Xp.appendChild(this.xm),this.Qf=Ps(this.xm,ns({width:16,height:16})),this.Qf.subscribeSuggestedBitmapSizeChanged(this.jf);const s=this.Qf.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.tv=Ps(this.xm,ns({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Xf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Df.appendChild(this.ym),this.Df.appendChild(this.Xp),this.Df.appendChild(this.Sm),this.Cm(),this.Vf.ti().Va().i(this.Cm.bind(this),this),this.zp=new fs(this.tv.canvasElement,this,{ap:()=>!0,_p:()=>!this.Vf.W().handleScroll.horzTouchDrag})}m(){this.zp.m(),null!==this.wm&&this.wm.m(),null!==this.gm&&this.gm.m(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Xf),Ts(this.tv.canvasElement),this.tv.dispose(),this.Qf.unsubscribeSuggestedBitmapSizeChanged(this.jf),Ts(this.Qf.canvasElement),this.Qf.dispose()}Zp(){return this.Df}Pm(){return this.wm}Tm(){return this.gm}Sp(t){if(this.bm)return;this.bm=!0;const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.yc(t.localX)}Mp(t){this.Sp(t)}xp(){const t=this.Vf.ti();!t.At().Gi()&&this.bm&&(this.bm=!1,this.Vf.W().handleScale.axisPressedMouseMove.time&&t.Dc())}dp(t){const i=this.Vf.ti();!i.At().Gi()&&this.Vf.W().handleScale.axisPressedMouseMove.time&&i.kc(t.localX)}up(t){this.dp(t)}mp(){this.bm=!1;const t=this.Vf.ti();t.At().Gi()&&!this.Vf.W().handleScale.axisPressedMouseMove.time||t.Dc()}fp(){this.mp()}Zd(){this.Vf.W().handleScale.axisDoubleClickReset.time&&this.Vf.ti().dn()}Yd(){this.Zd()}ep(){this.Vf.ti().W().handleScale.axisPressedMouseMove.time&&this.wv(1)}Vp(){this.wv(0)}Jp(){return this.zf}km(){return this.Mm}Dm(t,i,s){es(this.zf,t)||(this.zf=t,this.qf=!0,this.Qf.resizeCanvasElement(t),this.tv.resizeCanvasElement(t),this.qf=!1,this.Xp.style.width=`${t.width}px`,this.Xp.style.height=`${t.height}px`,this.Mm.p(t)),null!==this.wm&&this.wm.ov(ns({width:i,height:t.height})),null!==this.gm&&this.gm.ov(ns({width:s,height:t.height}))}Rm(){const t=this.Fm();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Im)}Tt(){this.Vf.ti().At().Il()}Qp(){return this.Qf.bitmapSize}tf(t,i,s,n){const e=this.Qp();if(e.width>0&&e.height>0&&(t.drawImage(this.Qf.canvasElement,i,s),n)){const n=this.tv.canvasElement;t.drawImage(n,i,s)}}_v(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.Qf.applySuggestedBitmapSize();const s=as(this.Qf,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.cv(t),this.dv(t),this.Vm(s,Ns)}),this.fv(s),this.Vm(s,$s)),null!==this.wm&&this.wm._v(t),null!==this.gm&&this.gm._v(t)}this.tv.applySuggestedBitmapSize();const s=as(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Lm([...this.Vf.ti().Xs(),this.Vf.ti().dc()],s),this.Vm(s,Hs))}Vm(t,i){const s=this.Vf.ti().Xs();for(const n of s)Rs(i,i=>ks(i,t,!1,void 0),n,void 0);for(const n of s)Rs(i,i=>Ds(i,t,!1,void 0),n,void 0)}cv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.Vf.ti().Nc())}dv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Vf.W().timeScale.borderVisible){t.fillStyle=this.Am();const n=Math.max(1,Math.floor(this.Fm().S*s));t.fillRect(0,0,i.width,n)}}fv(t){const i=this.Vf.ti().At(),s=i.Il();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Fm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Am(),t.fillStyle=this.Am();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.hv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Em(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Vf.W().timeScale.allowBoldLabels&&(t.font=this.Bm());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Em(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Em(t,i,s){const n=this.Hf.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.zf.width&&(i-=Math.abs(this.zf.width-(r+n))),i}Lm(t,i){const s=this.Fm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Am(){return this.Vf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}hv(){return g(this.$(),this.Ps.fontFamily)}Bm(){return g(this.$(),this.Ps.fontFamily,"bold")}Fm(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Im:0});const t=this.M,i=this.hv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.A=3*s/12,t.I=3*s/12,t.Qi=9*s/12,t.B=0,t.Im=4*s/12,t.Ji.Vn()}return this.M}wv(t){this.Xp.style.cursor=1===t?"ew-resize":"default"}Cm(){const t=this.Vf.ti(),i=t.W();i.leftPriceScale.visible||null===this.wm||(this.ym.removeChild(this.wm.Zp()),this.wm.m(),this.wm=null),i.rightPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Zp()),this.gm.m(),this.gm=null);const s={Lc:this.Vf.ti().Lc()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Nc();i.leftPriceScale.visible&&null===this.wm&&(this.wm=new Ws("left",i,s,n,e),this.ym.appendChild(this.wm.Zp())),i.rightPriceScale.visible&&null===this.gm&&(this.gm=new Ws("right",i,s,n,e),this.Sm.appendChild(this.gm.Zp()))}}const qs=!!_s&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!_s&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class js{constructor(t,i,s){var n;this.Om=[],this.Wm=[],this.zm=0,this.eo=0,this.ya=0,this.$m=0,this.Hm=0,this.Nm=null,this.Um=!1,this.Cv=new a,this.Pv=new a,this.Zu=new a,this.qm=null,this.jm=null,this.If=t,this.Ps=i,this.u_=s,this.Df=document.createElement("div"),this.Df.classList.add("tv-lightweight-charts"),this.Df.style.overflow="hidden",this.Df.style.direction="ltr",this.Df.style.width="100%",this.Df.style.height="100%",(n=this.Df).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Ym=document.createElement("table"),this.Ym.setAttribute("cellspacing","0"),this.Df.appendChild(this.Ym),this.Xm=this.Gm.bind(this),Ys(this.Ps)&&this.Km(!0),this.ss=new Ei(this.Qu.bind(this),this.Ps,s),this.ti().fc().i(this.Zm.bind(this),this),this.Jm=new Us(this,this.u_),this.Ym.appendChild(this.Jm.Zp());const e=i.autoSize&&this.Qm();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.tw(r,h),this.iw(),t.appendChild(this.Df),this.sw(),this.ss.At().Au().i(this.ss.Ah.bind(this.ss),this),this.ss.Va().i(this.ss.Ah.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}qp(){return this.Om}nw(){return this.Jm}m(){this.Km(!1),0!==this.zm&&window.cancelAnimationFrame(this.zm),this.ss.fc().u(this),this.ss.At().Au().u(this),this.ss.Va().u(this),this.ss.m();for(const t of this.Om)this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();this.Om=[];for(const t of this.Wm)this.ew(t);this.Wm=[],l(this.Jm).m(),null!==this.Df.parentElement&&this.Df.parentElement.removeChild(this.Df),this.Zu.m(),this.Cv.m(),this.Pv.m(),this.rw()}tw(t,i,s=!1){if(this.eo===i&&this.ya===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.eo=n.height,this.ya=n.width;const e=this.eo+"px",r=this.ya+"px";l(this.Df).style.height=e,l(this.Df).style.width=r,this.Ym.style.height=e,this.Ym.style.width=r,s?this.hw(Y.bn(),performance.now()):this.ss.Ah()}_v(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Om.length;i++)this.Om[i]._v(t.rn(i).sn);this.Ps.timeScale.visible&&this.Jm._v(t.en())}lr(t){const i=Ys(this.Ps);this.ss.lr(t);const s=Ys(this.Ps);s!==i&&this.Km(s),t.layout?.panes&&this.lw(),this.sw(),this.ow(t)}Zv(){return this.Cv}Jv(){return this.Pv}fc(){return this.Zu}aw(t=!1){null!==this.Nm&&(this.hw(this.Nm,performance.now()),this.Nm=null);const i=this._w(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this._w(n,t),s}uw(t){if("left"===t&&!this.cw())return 0;if("right"===t&&!this.dw())return 0;if(0===this.Om.length)return 0;return l("left"===t?this.Om[0].hm():this.Om[0].lm()).av()}pw(){return this.Ps.autoSize&&null!==this.qm}sf(){return this.Df}fw(t){this.jm=t,this.jm?this.sf().style.setProperty("cursor",t):this.sf().style.removeProperty("cursor")}mw(){return this.jm}ww(t){return h(this.Om[t]).Jp()}lw(){this.Wm.forEach(t=>{t.Tt()})}ow(t){(void 0!==t.autoSize||!this.qm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.qm&&this.Qm(),!1===t.autoSize&&null!==this.qm&&this.rw(),t.autoSize||void 0===t.width&&void 0===t.height||this.tw(t.width||this.ya,t.height||this.eo))}_w(t,i){let s=0,n=0;const e=this.Om[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Om.length;r++){const h=this.Om[r],o=l("left"===s?h.hm():h.lm()),a=o.Qp();if(null!==t&&o.tf(t,n,e,i),e+=a.height,r<this.Om.length-1){const i=this.Wm[r],s=i.Qp();null!==t&&i.tf(t,n,e),e+=s.height}}};if(this.cw()){r("left",0);s+=l(e.hm()).Qp().width}for(let e=0;e<this.Om.length;e++){const r=this.Om[e],h=r.Qp();if(null!==t&&r.tf(t,s,n,i),n+=h.height,e<this.Om.length-1){const i=this.Wm[e],r=i.Qp();null!==t&&i.tf(t,s,n),n+=r.height}}if(s+=e.Qp().width,this.dw()){r("right",s);s+=l(e.lm()).Qp().width}const h=(i,s,n)=>{l("left"===i?this.Jm.Pm():this.Jm.Tm()).tf(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Jm.Qp();if(null!==t){let r=0;this.cw()&&(h("left",r,n),r=l(e.hm()).Qp().width),this.Jm.tf(t,r,n,i),r+=s.width,this.dw()&&h("right",r,n)}n+=s.height}return ns({width:s,height:n})}gw(){let t=0,i=0,s=0;for(const n of this.Om)this.cw()&&(i=Math.max(i,l(n.hm()).rv(),this.Ps.leftPriceScale.minimumWidth)),this.dw()&&(s=Math.max(s,l(n.lm()).rv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.La();i=ds(i),s=ds(s);const n=this.ya,e=this.eo,r=Math.max(n-i-s,0),h=1*this.Wm.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Jm.Rm(),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.Om.length;++t){const n=this.Om[t];n.Wv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Om.length-1?Math.ceil((c-p)*f)/f:Math.round(n.La()*d*f)/f,e=Math.max(h,2),p+=e,n.ov(ns({width:r,height:e})),this.cw()&&n.tm(i,"left"),this.dw()&&n.tm(s,"right"),n.af()&&this.ss.vc(n.af(),e)}this.Jm.Dm(ns({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ea(r),this.$m!==i&&(this.$m=i),this.Hm!==s&&(this.Hm=s)}Km(t){t?this.Df.addEventListener("wheel",this.Xm,{passive:!1}):this.Df.removeEventListener("wheel",this.Xm)}bw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return qs?1/window.devicePixelRatio:1}Gm(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.bw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.Df.getBoundingClientRect().left;this.ti().Sc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().xc(-80*s)}hw(t,i){const s=t.en();3===s&&this.Mw(),3!==s&&2!==s||(this.yw(t),this.Sw(t,i),this.Jm.Tt(),this.Om.forEach(t=>{t.$v()}),3===this.Nm?.en()&&(this.Nm.mn(t),this.Mw(),this.yw(this.Nm),this.Sw(this.Nm,i),t=this.Nm,this.Nm=null)),this._v(t)}Sw(t,i){for(const s of t.vn())this.wn(s,i)}yw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qa()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Bu();break;case 1:s.Ou(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.xu();break;case 5:t.Ht.Fu(i)||s.fn(t.Ht.Iu(i))}}Qu(t){null!==this.Nm?this.Nm.mn(t):this.Nm=t,this.Um||(this.Um=!0,this.zm=window.requestAnimationFrame(t=>{if(this.Um=!1,this.zm=0,null!==this.Nm){const i=this.Nm;this.Nm=null,this.hw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Fu(t)){this.ti().un(s.Ht);break}}}))}Mw(){this.iw()}ew(t){this.Ym.removeChild(t.Zp()),t.m()}iw(){const t=this.ss.qs(),i=t.length,s=this.Om.length;for(let t=i;t<s;t++){const t=h(this.Om.pop());this.Ym.removeChild(t.Zp()),t.Zv().u(this),t.Jv().u(this),t.m();const i=this.Wm.pop();void 0!==i&&this.ew(i)}for(let n=s;n<i;n++){const i=new Os(this,t[n]);if(i.Zv().i(this.xw.bind(this,i),this),i.Jv().i(this.Cw.bind(this,i),this),this.Om.push(i),n>0){const t=new Ms(this,n-1,n);this.Wm.push(t),this.Ym.insertBefore(t.Zp(),this.Jm.Zp())}this.Ym.insertBefore(i.Zp(),this.Jm.Zp())}for(let s=0;s<i;s++){const i=t[s],n=this.Om[s];n.af()!==i?n.Wv(i):n.Ov()}this.sw(),this.gw()}Pw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.At().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti().ac(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,o=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,a=this.Tw(n);return{kw:r,Re:t??void 0,Dw:i??void 0,Rw:-1!==a?a:void 0,Fw:l,Iw:e,Vw:o,Lw:s??void 0}}Tw(t){let i=-1;if(t)i=this.Om.indexOf(t);else{const t=this.ti().dc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}xw(t,i,s,n){this.Cv.p(()=>this.Pw(i,s,n,t))}Cw(t,i,s,n){this.Pv.p(()=>this.Pw(i,s,n,t))}Zm(t,i,s){this.fw(this.ti().ac()?.o_??null),this.Zu.p(()=>this.Pw(t,i,s))}sw(){const t=this.Ps.timeScale.visible?"":"none";this.Jm.Zp().style.display=t}cw(){return this.Om[0].af().Na().W().visible}dw(){return this.Om[0].af().Ua().W().visible}Qm(){return"ResizeObserver"in window&&(this.qm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.tw(i.contentRect.width,i.contentRect.height)}),this.qm.observe(this.If,{box:"border-box"}),!0)}rw(){null!==this.qm&&this.qm.disconnect(),this.qm=null}}function Ys(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Xs(t){return void 0===t.open&&void 0===t.value}function Gs(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Ks(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw:n};return void 0!==s.color&&(r.R=s.color),r}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],kw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function Qs(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),e}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],kw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function sn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),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:_,kw:n,ne:d,R:c}}function nn(t){return void 0!==t.Ht}function en(t,i){return void 0!==i.customValues&&(t.Aw=i.customValues),t}function rn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Xs(t)}(n,h)?en({gt:i,Re:s,kw:e},n):en(t(i,s,n,e,r),n)}function hn(t){return{Candlestick:rn(tn),Bar:rn(Qs),Area:rn(Zs),Baseline:rn(Js),Histogram:rn(Ks),Line:rn(Ks),Custom:rn(sn)}[t]}function ln(t){return{Re:0,Ew:new Map,Uh:t}}function on(t,i){if(void 0!==t&&0!==t.length)return{Bw:i.key(t[0].gt),Ow:i.key(t[t.length-1].gt)}}function an(t){let i;return t.forEach(t=>{void 0===i&&(i=t.kw)}),h(i)}class _n{constructor(t){this.Ww=new Map,this.zw=new Map,this.$w=new Map,this.Hw=[],this.u_=t}m(){this.Ww.clear(),this.zw.clear(),this.$w.clear(),this.Hw=[]}Nw(t,i){let s=0!==this.Ww.size,n=!1;const e=this.zw.get(t);if(void 0!==e)if(1===this.zw.size)s=!1,n=!0,this.Ww.clear();else for(const i of this.Hw)i.pointData.Ew.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=hn(t.Rr()),l=t.pl(),o=t.vl();r=i.map((i,r)=>{const a=e(i.time),_=this.u_.key(a);let u=this.Ww.get(_);void 0===u&&(u=ln(a),this.Ww.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Ew.set(t,c),c})}s&&this.Uw(),this.qw(t,r);let h=-1;if(n){const t=[];this.Ww.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:an(i.Ew)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.jw(t)}return this.Yw(t,h,function(t,i,s){const n=on(t,s),e=on(i,s);if(void 0!==n&&void 0!==e)return{Xw:!1,Oh:n.Ow>=e.Ow&&n.Bw>=e.Bw}}(this.zw.get(t),e,this.u_))}Bc(t){return this.Nw(t,[])}Gw(t,i,s){const n=i;!function(t){void 0===t.kw&&(t.kw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.$w.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.Ww.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=ln(e),this.Ww.set(this.u_.key(e),h));const o=hn(t.Rr()),a=t.pl(),_=t.vl(),u=o(e,h.Re,i,n.kw,a,_);h.Ew.set(t,u),s?this.Kw(t,u,h.Re):this.Zw(t,u);const c={Oh:nn(u),Xw:s};if(!l)return this.Yw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:an(h.Ew)},p=yt(this.Hw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Hw.splice(p,0,d);for(let t=p;t<this.Hw.length;++t)un(this.Hw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Hw,p),this.Yw(t,p,c)}Jw(t,i){const s=this.zw.get(t);if(void 0===s||i<=0)return[[],this.Qw()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.$w.delete(t):this.$w.set(t,s[s.length-1].gt);for(const i of n){const s=this.Ww.get(this.u_.key(i.gt));if(s&&(s.Ew.delete(t),0===s.Ew.size)){this.Ww.delete(this.u_.key(s.Uh)),this.Hw.splice(s.Re,1);for(let t=s.Re;t<this.Hw.length;++t)un(this.Hw[t].pointData,t)}}return[n,this.Yw(t,this.Hw.length-1,{Xw:!1,Oh:!1})]}Zw(t,i){let s=this.zw.get(t);void 0===s&&(s=[],this.zw.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?nn(i)&&s.push(i):nn(i)?s[s.length-1]=i:s.splice(-1,1),this.$w.set(t,i.gt)}Kw(t,i,s){const n=this.zw.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);nn(i)?n[e]=i:n.splice(e,1)}qw(t,i){0!==i.length?(this.zw.set(t,i.filter(nn)),this.$w.set(t,i[i.length-1].gt)):(this.zw.delete(t),this.$w.delete(t))}Uw(){for(const t of this.Hw)0===t.pointData.Ew.size&&this.Ww.delete(this.u_.key(t.time))}jw(t){let i=-1;for(let s=0;s<this.Hw.length&&s<t.length;++s){const n=this.Hw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,un(e.pointData,s)}if(-1===i&&this.Hw.length!==t.length&&(i=Math.min(this.Hw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)un(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Hw=t,i}tg(){if(0===this.zw.size)return null;let t=0;return this.zw.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Yw(t,i,s){const n=this.Qw();if(-1!==i)this.zw.forEach((i,e)=>{n.za.set(e,{ne:i,ig:e===t?s:void 0})}),this.zw.has(t)||n.za.set(t,{ne:[],ig:s}),n.At.sg=this.Hw,n.At.ng=i;else{const i=this.zw.get(t);n.za.set(t,{ne:i||[],ig:s})}return n}Qw(){return{za:new Map,At:{cu:this.tg()}}}}function un(t,i){t.Re=i,t.Ew.forEach(t=>{t.Re=i})}function cn(t,i){return t.gt<i}function dn(t,i){return i<t.gt}function pn(t,i,s){const n=i.qh(),e=i.yi(),r=yt(t,n,cn),h=St(t,e,dn);if(!s)return{from:r,to:h};let l=r,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.eg=!0,this.rg=!0,this.hg=!0,this.lg=[],this.og=null,this.Qn=t,this.te=i,this.ag=s}Tt(t){this.eg=!0,"data"===t&&(this.rg=!0),"options"===t&&(this.hg=!0)}Dt(){return this.Qn.It()?(this._g(),null===this.og?null:this.ug):null}cg(){const t=this.Qn.Fh();this.lg=this.lg.map(i=>{const s=t.Ir(i.gt);return null===s?i:{...i,...s}})}dg(){this.og=null}_g(){this.rg&&(this.pg(),this.rg=!1),this.hg&&(this.cg(),this.hg=!1),this.eg&&(this.fg(),this.eg=!1)}fg(){const t=this.Qn.$t(),i=this.te.At();if(this.dg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Or())return;const n=this.Qn.Bt();null!==n&&(this.og=pn(this.lg,s,this.ag),this.vg(t,i,n.Ht),this.mg())}}class vn{constructor(t,i){this.wg=t,this.Yi=i}et(t,i,s){this.wg.draw(t,this.Yi,i,s)}}class mn extends fn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.ug=new vn(this.eh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),gg:i.ne}))}vg(t,i){i.du(this.lg,m(this.og))}mg(){this.eh.update({bars:this.lg.map(wn),barSpacing:this.te.At().gu(),visibleRange:this.og},this.Qn.W())}}function wn(t){return{x:t.ut,time:t.gt,originalData:t.gg,barColor:t.dr}}const gn={color:"#2196f3"},bn=(t,i,s)=>{const n=o(s);return new mn(t,i,n)};function Mn(t){const i={value:t.Ht[3],time:t.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function yn(t){const i=Mn(t);return void 0!==t.R&&(i.color=t.R),i}function Sn(t){const i=Mn(t);return void 0!==t.wt&&(i.lineColor=t.wt),void 0!==t.wr&&(i.topColor=t.wr),void 0!==t.gr&&(i.bottomColor=t.gr),i}function xn(t){const i=Mn(t);return void 0!==t.br&&(i.topLineColor=t.br),void 0!==t.Mr&&(i.bottomLineColor=t.Mr),void 0!==t.yr&&(i.topFillColor1=t.yr),void 0!==t.Sr&&(i.topFillColor2=t.Sr),void 0!==t.Cr&&(i.bottomFillColor1=t.Cr),void 0!==t.Pr&&(i.bottomFillColor2=t.Pr),i}function Cn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.kw};return void 0!==t.Aw&&(i.customValues=t.Aw),i}function Pn(t){const i=Cn(t);return void 0!==t.R&&(i.color=t.R),i}function Tn(t){const i=Cn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function kn(t){return{Area:Sn,Line:yn,Baseline:xn,Histogram:yn,Bar:Pn,Candlestick:Tn,Custom:Dn}[t]}function Dn(t){const i=t.kw;return{...t.ne,time:i}}const Rn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},Fn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},In={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},Vn={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0,ensureEdgeTickMarksVisible:!1},Ln={rightOffset:0,barSpacing:6,minBarSpacing:.5,maxBarSpacing:0,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0,ignoreWhitespaceIndices:!1};function An(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:In,crosshair:Rn,grid:Fn,overlayPriceScales:{...Vn},leftPriceScale:{...Vn,visible:!1},rightPriceScale:{...Vn,visible:!0},timeScale:Ln,localization:{locale:_s?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class En{constructor(t,i,s){this.Np=t,this.bg=i,this.Mg=s??0}applyOptions(t){this.Np.ti().uc(this.bg,t,this.Mg)}options(){return this.Yi().W()}width(){return j(this.bg)?this.Np.uw(this.bg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Uo(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().io()){const n=this.Yi().ma(),e=Bi(n);s=oi(s,this.Yi().no()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Np.ti().cc(this.bg,this.Mg)).$t}}class Bn{constructor(t,i,s,n){this.Np=t,this.Pt=s,this.yg=i,this.Sg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Np.ti(),s=i.qc(this.Pt);i.wc(s,t)}getStretchFactor(){return this.Pt.La()}setStretchFactor(t){this.Pt.Aa(t),this.Np.ti().Ah()}paneIndex(){return this.Np.ti().qc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Np.qp().length,"Invalid pane index"),this.Np.ti().bc(i,t))}getSeries(){return this.Pt.za().map(t=>this.yg(t))??[]}getHTMLElement(){const t=this.Np.qp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Zp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.Sg,requestUpdate:()=>this.Pt.ti().Ah()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Ia(t))throw new Error(`Cannot find price scale with id: ${t}`);return new En(this.Np,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Oa(t)}preserveEmptyPane(){return this.Pt.Wa()}addCustomSeries(t,i={},s=0){return this.Sg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.Sg.addSeries(t,i,this.paneIndex())}}const On={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Wn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}xg(){return this.sr}}class zn{constructor(t,i,s,n,e,r){this.Cg=new a,this.Qn=t,this.Pg=i,this.Tg=s,this.u_=e,this.Sg=n,this.kg=r}m(){this.Cg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.Bt();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Bt();return null===i?null:this.Qn.$t().Ds(t,i.Ht)}barsInLogicalRange(t){if(null===t)return null;const i=new ki(new Ci(t.from,t.to)).k_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const 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.kw,o.to=e.kw),o}setData(t){this.u_,this.Qn.Rr(),this.Pg.Dg(this.Qn,t),this.Rg("full")}update(t,i=!1){this.Qn.Rr(),this.Pg.Fg(this.Qn,t,i),this.Rg("update")}pop(t=1){const i=this.Pg.Ig(this.Qn,t);0!==i.length&&this.Rg("update");const s=kn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return kn(this.seriesType())(s)}data(){const t=kn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Cg.i(t)}unsubscribeDataChanged(t){this.Cg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Tg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(On),t),s=this.Qn.zh(i);return new Wn(s)}removePriceLine(t){this.Qn.$h(t.xg())}priceLines(){return this.Qn.Hh().map(t=>new Wn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.Sg,series:this,requestUpdate:()=>this.Qn.ti().Ah(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Ah()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.kg(i)}moveToPane(t){this.Qn.ti().$c(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.za().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Rg(t){this.Cg.v()&&this.Cg.p(t)}}class $n{constructor(t,i,s){this.Vg=new a,this.O_=new a,this.Mm=new a,this.ss=t,this.ph=t.At(),this.Jm=i,this.ph.Vu().i(this.Lg.bind(this)),this.ph.Lu().i(this.Ag.bind(this)),this.Jm.km().i(this.Eg.bind(this)),this.u_=s}m(){this.ph.Vu().u(this),this.ph.Lu().u(this),this.Jm.km().u(this),this.Vg.m(),this.O_.m(),this.Mm.m()}scrollPosition(){return this.ph.Mu()}scrollToPosition(t,i){i?this.ph.Ru(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Du()}getVisibleRange(){const t=this.ph.ru();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph.au(i);this.ss.Wc(s)}getVisibleLogicalRange(){const t=this.ph.eu();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.Wc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Bu()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.pu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.iu(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.pu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Jm.Jp().width}height(){return this.Jm.Jp().height}subscribeVisibleTimeRangeChange(t){this.Vg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Vg._(t)}subscribeVisibleLogicalRangeChange(t){this.O_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.O_._(t)}subscribeSizeChange(t){this.Mm.i(t)}unsubscribeSizeChange(t){this.Mm._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.gu()}}Lg(){this.Vg.v()&&this.Vg.p(this.getVisibleRange())}Ag(){this.O_.v()&&this.O_.p(this.getVisibleLogicalRange())}Eg(t){this.Mm.p(t.width,t.height)}}function Hn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Nn{constructor(t,i,s){this.Bg=new Map,this.Og=new Map,this.Wg=new a,this.zg=new a,this.$g=new a,this.Yu=new WeakMap,this.Hg=new _n(i);const n=void 0===s?f(An()):_(f(An()),Hn(s));this.Ng=i,this.Np=new js(t,n,i),this.Np.Zv().i(t=>{this.Wg.v()&&this.Wg.p(this.Ug(t()))},this),this.Np.Jv().i(t=>{this.zg.v()&&this.zg.p(this.Ug(t()))},this),this.Np.fc().i(t=>{this.$g.v()&&this.$g.p(this.Ug(t()))},this);const e=this.Np.ti();this.qg=new $n(e,this.Np.nw(),this.Ng)}remove(){this.Np.Zv().u(this),this.Np.Jv().u(this),this.Np.fc().u(this),this.qg.m(),this.Np.m(),this.Bg.clear(),this.Og.clear(),this.Wg.m(),this.zg.m(),this.$g.m(),this.Hg.m()}resize(t,i,s){this.autoSizeActive()||this.Np.tw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...gn,...t.defaultOptions()},jg:bn,Yg:t}))(o(t));return this.Xg(n,i,s)}addSeries(t,i={},s=0){return this.Xg(t,i,s)}removeSeries(t){const i=h(this.Bg.get(t)),s=this.Hg.Bc(i);this.Np.ti().Bc(i),this.Gg(s),this.Bg.delete(t),this.Og.delete(i)}Dg(t,i){this.Gg(this.Hg.Nw(t,i))}Fg(t,i,s){this.Gg(this.Hg.Gw(t,i,s))}Ig(t,i){const[s,n]=this.Hg.Jw(t,i);return 0!==s.length&&this.Gg(n),s}subscribeClick(t){this.Wg.i(t)}unsubscribeClick(t){this.Wg._(t)}subscribeCrosshairMove(t){this.$g.i(t)}unsubscribeCrosshairMove(t){this.$g._(t)}subscribeDblClick(t){this.zg.i(t)}unsubscribeDblClick(t){this.zg._(t)}priceScale(t,i=0){return new En(this.Np,t,i)}timeScale(){return this.qg}applyOptions(t){this.Np.lr(Hn(t))}options(){return this.Np.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Np.ti().W().crosshair.mode,this.Np.lr({crosshair:{mode:2}})),n=this.Np.aw(t)}finally{i||void 0===s||this.Np.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Np.ti().jc();return i.Oa(t),this.Kg(i)}removePane(t){this.Np.ti().mc(t)}swapPanes(t,i){this.Np.ti().gc(t,i)}autoSizeActive(){return this.Np.pw()}chartElement(){return this.Np.sf()}panes(){return this.Np.ti().qs().map(t=>this.Kg(t))}paneSize(t=0){const i=this.Np.ww(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Bg.get(s);if(void 0===n)return;const e=this.Np.ti().Nn(n);null!==e&&this.Np.ti().Fc(t,i,e)}clearCrosshairPosition(){this.Np.ti().Ic(!0)}horzBehaviour(){return this.Ng}Xg(i,s={},n=0){r(void 0!==i.jg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Bi(i.minMove))}(s.priceFormat),"Candlestick"===i.type&&function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(s);const e=_(f(t),f(i.defaultOptions),s),h=i.jg,l=new Ut(this.Np.ti(),i.type,e,h,i.Yg);this.Np.ti().Ac(l,n);const o=new zn(l,this,this,this,this.Ng,t=>this.Kg(t));return this.Bg.set(o,l),this.Og.set(l,o),o}Gg(t){const i=this.Np.ti();i.Vc(t.At.cu,t.At.sg,t.At.ng),t.za.forEach((t,i)=>i.lt(t.ne,t.ig)),i.At().K_(),i.wu()}Zg(t){return h(this.Og.get(t))}Ug(t){const i=new Map;t.Iw.forEach((t,s)=>{const n=s.Rr(),e=kn(n)(t);if("Custom"!==n)r(Gs(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Zg(s),e)});const s=void 0!==t.Fw&&this.Og.has(t.Fw)?this.Zg(t.Fw):void 0;return{time:t.kw,logical:t.Re,point:t.Dw,paneIndex:t.Rw,hoveredSeries:s,hoveredObjectId:t.Vw,seriesData:i,sourceEvent:t.Lw}}Kg(t){let i=this.Yu.get(t);return i||(i=new Bn(this.Np,t=>this.Zg(t),t,this),this.Yu.set(t,i)),i}}function Un(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function qn(t,i,s){const n=Un(t),e=new Nn(n,i,s);return i.setOptions(e.options()),e}function jn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Jg:n.time-h.time}}function 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.Kl;return Math.round(h.gt+l*h.Jg)}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.Kl+(s-r.gt)/r.Jg,l=n.logicalToCoordinate(h);return null===l?null:l}class Gn extends fn{constructor(t,i){super(t,i,!0)}vg(t,i,s){i.du(this.lg,m(this.og)),t.Yo(this.lg,s,m(this.og))}Qg(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.tb(i.Re,s,t,i)})}}function 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,ib:e,sb:r,dt:h,Kt:l,nb: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.eb.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{eb(t,i){return i.wt}}class ee extends Gn{constructor(){super(...arguments),this.ug=new ne}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.W(),i={_t:this.lg,Kt:t.lineStyle,sb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,nb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.og,ib:this.te.At().gu()};this.ug.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},jg:(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.rb=new a,this.hb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.rb.p(this.lb)),this.lb=0}ob(){return this.rb}m(){this.rb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.hb(),t=>(t>this.lb&&(this.lb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.ab(t)}formatTickmark(t){return this.ab(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.lb=t[t.length-1].time,this.hb()}ab(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),_b:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,_b:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,_b:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ob().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,ib:e,dt:r,Kt:h,sb:l}=this.ht,o=this.ht.ub??(this.ht.cb?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.pb.bind(this),pe.bind(null,o))}}class ve{fb(t,i){const s=this.mb,{wb:n,gb:e,bb:r,Mb:h,ub:l,yb:o,Sb:a}=i;if(void 0===this.xb||void 0===s||s.wb!==n||s.gb!==e||s.bb!==r||s.Mb!==h||s.ub!==l||s.yb!==o||s.Sb!==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.xb=p,this.mb=i}return this.xb}}class me extends fe{constructor(){super(...arguments),this.Cb=new ve}pb(t,i){const s=this.ht;return this.Cb.fb(t,{wb:i.yr,gb:i.Sr,bb:i.Cr,Mb:i.Pr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class we extends se{constructor(){super(...arguments),this.Pb=new ve}eb(t,i){const s=this.ht;return this.Pb.fb(t,{wb:i.br,gb:i.br,bb:i.Mr,Mb:i.Mr,ub:s.ub,yb:s.yb??0,Sb:s.Sb??t.bitmapSize.height})}}class ge extends Gn{constructor(t,i){super(t,i),this.ug=new x,this.Tb=new me,this.kb=new we,this.ug.nt([this.Tb,this.kb])}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.Bt();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.At().gu();if(null===this.og||0===this.lg.length)return;let e,r;if(i.relativeGradient){e=this.lg[this.og.from].ct,r=this.lg[this.og.from].ct;for(let t=this.og.from;t<this.og.to;t++){const i=this.lg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Tb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineType,ub:s,yb:e,Sb:r,cb:!1,ot:this.og,ib:n}),this.kb.lt({_t:this.lg,dt:i.lineWidth,Kt:i.lineStyle,sb:i.lineVisible?i.lineType:void 0,nb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,ub:s,yb:e,Sb:r,ot:this.og,ib: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},jg:(t,i)=>new ge(t,i)};class Me extends fe{constructor(){super(...arguments),this.Cb=new ve}pb(t,i){return this.Cb.fb(t,{wb:i.wr,gb:"",bb:"",Mb:i.gr,yb:this.ht?.yb??0,Sb:t.bitmapSize.height})}}class ye extends Gn{constructor(t,i){super(t,i),this.ug=new x,this.Db=new Me,this.Rb=new ne,this.ug.nt([this.Db,this.Rb])}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t=this.Qn.W();if(null===this.og||0===this.lg.length)return;let i;if(t.relativeGradient){i=this.lg[this.og.from].ct;for(let t=this.og.from;t<this.og.to;t++){const s=this.lg[t];s.ct<i&&(i=s.ct)}}this.Db.lt({sb:t.lineType,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ub:null,yb:i,cb:t.invertFilledArea,ot:this.og,ib:this.te.At().gu()}),this.Rb.lt({sb:t.lineVisible?t.lineType:void 0,_t:this.lg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.og,ib:this.te.At().gu(),nb: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},jg:(t,i)=>new ye(t,i)};class xe extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0,this.Ib=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Fb=this.Vb(i),this.Fb>=2){Math.max(1,Math.floor(i))%2!=this.Fb%2&&this.Fb--}this.Ib=this.Yt.Lb?Math.min(this.Fb,Math.floor(i)):this.Fb;let n=null;const e=this.Ib<=this.Fb&&this.Yt.gu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ib),o=Math.round(h.ut*i),a=o-l,_=this.Ib,u=a+_-1,c=Math.min(h.Zo,h.Jo),d=Math.max(h.Zo,h.Jo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Ib);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Fb);if(e){if(this.Yt.Ab){const i=o-m;let n=Math.max(p,Math.round(h.Ko*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Qo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Vb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).gu,t)))}}class Ce extends fn{constructor(t,i){super(t,i,!1)}vg(t,i,s){i.du(this.lg,m(this.og)),t.Go(this.lg,s,m(this.og))}Eb(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Ko:NaN,Zo:NaN,Jo:NaN,Qo:NaN}}pg(){const t=this.Qn.Fh();this.lg=this.Qn.Ks().Ur().map(i=>this.tb(i.Re,i,t))}}class Pe extends Ce{constructor(){super(...arguments),this.ug=new xe}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t,{Ht:i})}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Ab:t.openVisible,Lb:t.thinBars,ot:this.og})}}const Te={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},jg:(t,i)=>new Pe(t,i)};class ke extends C{constructor(){super(...arguments),this.Yt=null,this.Fb=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Fb=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.gu,i),this.Fb>=2){Math.floor(i)%2!=this.Fb%2&&this.Fb--}const s=this.Yt.Ks;this.Yt.Bb&&this.Ob(t,s,this.Yt.ot),this.Yt.Mi&&this.dv(t,s,this.Yt.ot);const n=this.Wb(i);(!this.Yt.Mi||this.Fb>2*n)&&this.zb(t,s,this.Yt.ot)}Ob(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.gu*e));l=Math.max(Math.floor(e),Math.min(l,this.Fb));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Ko,s.Qo)*r),u=Math.round(Math.max(s.Ko,s.Qo)*r),c=Math.round(s.Zo*r),d=Math.round(s.Jo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}Wb(t){let i=Math.floor(1*t);this.Fb<=2*i&&(i=Math.floor(.5*(this.Fb-1)));const s=Math.max(Math.floor(t),i);return this.Fb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}dv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);let 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.Fb);const _=a+this.Fb-1,u=Math.round(Math.min(s.Ko,s.Qo)*r),c=Math.round(Math.max(s.Ko,s.Qo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.gu*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=_}}zb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.Wb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Ko,s.Qo)*r),a=Math.round(Math.max(s.Ko,s.Qo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Fb),u=_+this.Fb-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.ug=new ke}tb(t,i,s){return{...this.Eb(t,i,s),...s.Fr(t,{Ht:i})}}mg(){const t=this.Qn.W();this.ug.lt({Ks:this.lg,gu:this.te.At().gu(),Bb:t.wickVisible,Mi:t.borderVisible,ot:this.og})}}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"},jg:(t,i)=>new De(t,i)};class Fe extends C{constructor(){super(...arguments),this.Yt=null,this.$b=[]}lt(t){this.Yt=t,this.$b=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.$b.length||this.Hb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Nb*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.$b[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.qh,a,l.yi-l.qh+1,_-a)}}Hb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.$b=[]);const i=Math.ceil(this.Yt.gu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.gu*t)-i;this.$b=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.$b[i-this.Yt.ot.from]={qh:r,yi:h,Ub:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.$b[t-this.Yt.ot.from],n=this.$b[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.Ub>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.gu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.$b[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.Ub>i.ee?i.yi-=1:i.qh+=1)}}}class Ie extends Gn{constructor(){super(...arguments),this.ug=new Fe}tb(t,i,s,n){return{...this.Qg(t,i),...s.Fr(t,{Ht:n})}}mg(){const t={_t:this.lg,gu:this.te.At().gu(),ot:this.og,Nb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this.ug.lt(t)}}const Ve={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},jg:(t,i)=>new Ie(t,i)};class Le{constructor(t,i){this.Pt=t,this.qb=i,this.jb()}detach(){this.Pt.detachPrimitive(this.qb)}getPane(){return this.Pt}applyOptions(t){this.qb.lr?.(t)}jb(){this.Pt.attachPrimitive(this.qb)}}const 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.Yb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Xb(i,t.text);e>s.width?t.Pu=s.width/e:t.Pu=1,n+=t.lineHeight*t.Pu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Pu,t.Pu),i.fillText(t.text,0,t.Gb),i.restore(),e+=t.lineHeight*t.Pu}})}Xb(t,i){const s=this.Kb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Kb(t){let i=this.Yb.get(t);return void 0===i&&(i=new Map,this.Yb.set(t,i)),i}}class 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,Gb:0,Pu: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.Zb=[new Oe(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Zb}attached({requestUpdate:t}){this.Jb=t}detached(){this.Jb=void 0}lr(t){this.Ps=He({...this.Ps,...t}),this.Jb&&this.Jb()}}const Ue={alpha:1,padding:0};class qe{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.Qb(this.Yt,t.mediaSize);s&&this.Yt.tM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.tM,s.ut,s.ct,s.ts,s.qt))})}Qb(t,i){const{maxHeight:s,maxWidth:n,iM:e,sM:r,padding:h}=t,l=Math.round(i.width/2),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.nM=null,this.eM=0,this.rM=0,this.Ps=t,this.M=Ye(this.Ps,this.nM,this.eM,this.rM)}hM(t){void 0!==t.lM&&(this.eM=t.lM),void 0!==t.oM&&(this.rM=t.oM),void 0!==t.aM&&(this.nM=t.aM),this.Tt()}_M(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Ye(this.Ps,this.nM,this.eM,this.rM)}renderer(){return new qe(this.M)}}function Ye(t,i,s,n){return{...t,tM:i,sM:s,iM:n}}function Xe(t){return{...Ue,...t}}class Ge{constructor(t,i){this.uM=null,this.cM=t,this.Ps=Xe(i),this.Zb=[new je(this.Ps)]}updateAllViews(){this.Zb.forEach(t=>t.Tt())}paneViews(){return this.Zb}attached(t){const{requestUpdate:i}=t;this.dM=i,this.uM=new Image,this.uM.onload=()=>{const t=this.uM?.naturalHeight??1,i=this.uM?.naturalWidth??1;this.Zb.forEach(s=>s.hM({oM:t,lM:i,aM:this.uM})),this.dM&&this.dM()},this.uM.src=this.cM}detached(){this.dM=void 0,this.uM=null}lr(t){this.Ps=Xe({...this.Ps,...t}),this.pM(),this.Jb&&this.Jb()}Jb(){this.dM&&this.dM()}pM(){this.Zb.forEach(t=>t._M(this.Ps))}}class Ke{constructor(t,i){this.Qn=t,this._h=i,this.jb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}jb(){this.Qn.attachPrimitive(this._h)}}const 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.fM,r=(Kt(n/2)-1)/2*s.fM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function 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.vM=new it,this.$=-1,this.H="",this.Nf="",this.mM="",this.wM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Nf=g(t,i),this.mM=g(t,i,"600"),this.Wn.Vn(),this.vM.Vn()),this.wM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&ar(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.wM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.gM;if(t.font=r?this.mM:this.Nf,void 0!==e.hi){const i=r?this.vM:this.Wn;e.hi.ts=i.Ii(t,e.hi.bM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.gM){const t=void 0!==e.hi?e.hi.ts:0;e.gM.ts=Math.max(t+2*e.gM.MM,e.gM.qt),e.gM.qh=e.ut-e.gM.ts/2}or(e,t,i,s)}}}}function or(t,i,s,n){void 0===t.gM?(i.fillStyle=t.R,void 0!==t.hi&&hr(i,t.hi.bM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Or)return;switch(t.yM){case"arrowDown":return void nr(!1,i,s,t.Or);case"arrowUp":return void nr(!0,i,s,t.Or);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.fM,0,2*Math.PI,!1),t.fill()}(i,s,t.Or);case"square":return void function(t,i,s){const n=Qe("square",s),e=(n-1)*i.fM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.fM,n*i.fM)}(i,s,t.Or);case"tag":return}t.yM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,fM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Or)return;(function(t,i){const s=i.SM,n=i.xM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.CM-i.qt/2)*n),l=Math.round((i.CM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.PM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.TM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.TM&&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.TM&&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,CM:t.ct,ts:i.ts,qt:i.qt,PM:i.PM,TM:i.TM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,SM:n,xM:e}),void 0!==t.hi&&(s.fillStyle=t.kM??"#FFFFFF",hr(s,t.hi.bM,t.hi.ut,t.hi.ct,n,e))}(t,t.gM,i,s,n)}function ar(t,i,s){return void 0!==t.gM?0!==t.Or&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.TM?i-r-s.PM:i-r,l="down"===s.TM?i+r+s.PM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.gM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Or)return!1;switch(t.yM){case"arrowDown":return er(!0,t.ut,t.ct,t.Or,i,s);case"arrowUp":return er(!1,t.ut,t.ct,t.Or,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.Or,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.Or,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.DM)-o-_,a||(n.DM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.RM)+o+_,a||(n.RM+=l+o+r)}const d={qt:l,PM:o,TM:u,vt:i.borderRadius??6,MM:9*h,qh:0,ts:0};t.Or=l,t.ct=c,t.gM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=tr(d.options().barSpacing)*p,v=f/2;t.Or=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.DM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.DM+=1.2*e),void(c||(n.DM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}}}class cr{constructor(t,i,s){this.FM=[],this.xt=!0,this.IM=!0,this.Jt=new lr,this.be=t,this.Vf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.VM();const t=this.Vf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}LM(t){this.FM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.IM=!0)}AM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}VM(){const t=this.Vf.timeScale(),i=this.FM;this.IM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Or:0,yM:t.shape,R:t.color,Gn:t.id,EM:t.EM,hi:void 0,kM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,gM:void 0})),this.IM=!1);const s=this.Vf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=ir(t.options().barSpacing),a={DM:o,RM: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.DM=o,a.RM=o,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={bM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&ur(_,e,u,a,s.fontSize,o,this.be,this.Vf,r)}this.xt=!1}}function dr(t){return{...Ze,...t}}class pr{constructor(t){this.eh=null,this.FM=[],this.BM=[],this.OM=null,this.be=null,this.Vf=null,this.WM=!0,this.zM=null,this.$M=null,this.HM=null,this.NM=!0,this.Ps=dr(t)}attached(t){this.UM(),this.Vf=t.chart,this.be=t.series,this.eh=new cr(this.be,l(this.Vf),this.Ps),this.dM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Rg(t)),this.NM=!0,this.Jb()}Jb(){this.dM&&this.dM()}detached(){this.be&&this.OM&&this.be.unsubscribeDataChanged(this.OM),this.Vf=null,this.be=null,this.eh=null,this.OM=null}LM(t){this.NM=!0,this.FM=t,this.UM(),this.WM=!0,this.$M=null,this.Jb()}qM(){return this.FM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.jM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.YM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=dr({...this.Ps,...t}),this.Jb&&this.Jb()}YM(){const t=l(this.Vf).timeScale().options().barSpacing;if(this.WM||t!==this.HM){if(this.HM=t,this.FM.length>0){const i=ir(t),s=1.5*tr(t)+2*i,n=this.XM();this.zM={above:sr(s,n.aboveBar,n.inBar),below:sr(s,n.belowBar,n.inBar)}}else this.zM=null;this.WM=!1}return this.zM}XM(){return null===this.$M&&(this.$M=this.FM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.$M}UM(){if(!this.NM||!this.Vf||!this.be)return;const t=this.Vf.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.BM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.BM=this.FM.map((i,n)=>{const e=t.timeToIndex(i.time,!0),r=e<s?1:-1,h=l(this.be).dataByIndex(e,r),o={time:t.timeToIndex(l(h).time,!1),position:i.position,shape:i.shape,color:i.color,id:i.id,EM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,kw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.NM=!1}jM(t){this.eh&&(this.UM(),this.eh.LM(this.BM),this.eh.AM(this.Ps),this.eh.Tt(t))}Rg(t){this.NM=!0,this.Jb()}}class fr extends Ke{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.LM(t)}markers(){return this._h.qM()}}function vr(t,i,s){const n=new fr(t,new pr(s??{}));return i&&n.setMarkers(i),n}class mr{constructor(t){this.FM=new Map,this.GM=t}KM(t,i,s){if(this.ZM(i),void 0!==s){const n=window.setTimeout(()=>{this.FM.delete(i),this.JM()},s),e={...t,QM:n,ty:Date.now()+s};this.FM.set(i,e)}else this.FM.set(i,{...t,QM:void 0,ty:void 0});this.JM()}ZM(t){const i=this.FM.get(t);i&&void 0!==i.QM&&window.clearTimeout(i.QM),this.FM.delete(t),this.JM()}iy(){for(const[t]of this.FM)this.ZM(t)}sy(){const t=Date.now(),i=[];for(const[s,n]of this.FM)!n.ty||n.ty>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.ZM(s);return i}ny(t){this.GM=t}JM(){this.GM&&this.GM()}}const wr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class gr{constructor(t,i,s,n){this.Yt=t,this.ey=i,this.hy=s,this.ly=n}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=Math.max(1,Math.floor(t.horizontalPixelRatio))%2/2,n=4*t.verticalPixelRatio+s;this.Yt.forEach(e=>{const r=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const h=this.oy(e._y);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e._y&&(i.strokeStyle=h,i.lineWidth=Math.floor(2*t.horizontalPixelRatio),i.beginPath(),i.moveTo((e.ut-4.7)*t.horizontalPixelRatio+s,(e.ct-7*e._y)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e._y-7*e._y*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e._y)*t.verticalPixelRatio),i.stroke())})})}oy(t){return 0===t?this.ey:t>0?this.ly:this.hy}}class br{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,_y:t.sign}}).filter(v)}renderer(){const t=function(t,i){return function(t,i){return"Area"===i}(0,i)?t.lineColor:t.color}(this.be.options(),this.be.seriesType());return new gr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Mr(t,i){return"Line"===i||"Area"===i}class yr{constructor(t){this.Vf=void 0,this.be=void 0,this.Zb=[],this.u_=null,this.uy=new Map,this.py=new mr(()=>this.Jb()),this.Ps={...wr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Jb()}LM(t){this.py.iy();const i=this.u_;i&&t.forEach(t=>{this.py.KM(t,i.key(t.time))})}qM(){return this.py.sy()}Jb(){this.dM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Vf=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Zb=[new br(this.be,this.Vf.timeScale(),this.Ps)],this.dM=n,this.Jb()}detached(){this.Vf=void 0,this.be=void 0,this.dM=void 0}Yf(){return h(this.Vf)}za(){return h(this.be)}updateAllViews(){this.Zb.forEach(t=>t.Tt(this.qM()))}paneViews(){return this.Zb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.uy.clear();const s=this.u_;s&&t.forEach(t=>{Gs(t)&&Mr(0,i)&&this.uy.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Xs(t)&&this.uy.delete(n),Gs(t)&&Mr(0,s)){const i=this.uy.get(n);i&&this.py.KM({time:t.time,value:t.value,sign:Sr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}vy(){this.py.iy()}}function Sr(t,i){return t===i?0:t-i>0?1:-1}class xr extends Ke{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.qM()}setMarkers(t){return this._h.LM(t)}clearMarkers(){return this._h.vy()}}class Cr{constructor(t,i){this.my=null,this.wy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.my=vr(t)}addPosition(t){this.wy.push(t),this.gy()}addPositions(t){this.wy.push(...t),this.gy()}setPositions(t){this.wy=[...t],this.gy()}closePosition(t,i,s){const n=this.wy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.gy())}removePosition(t){this.wy=this.wy.filter(i=>i.id!==t),this.gy()}clearPositions(){this.wy=[],this.gy()}getPositions(){return this.wy}applyOptions(t){t.longColors&&(this.Ps.longColors={...this.Ps.longColors,...t.longColors}),t.shortColors&&(this.Ps.shortColors={...this.Ps.shortColors,...t.shortColors}),void 0!==t.defaultSize&&(this.Ps.defaultSize=t.defaultSize),void 0!==t.entryOffset&&(this.Ps.entryOffset=t.entryOffset),void 0!==t.exitOffset&&(this.Ps.exitOffset=t.exitOffset),this.gy()}by(){const t=[];for(const i of this.wy){const s="long"===i.type,n=i.size??this.Ps.defaultSize,e=i.color?.entry??(s?this.Ps.longColors.entry:this.Ps.shortColors.entry),r=i.color?.exit??(s?this.Ps.longColors.exit:this.Ps.shortColors.exit),h={time:i.entry.time,position:"atPriceMiddle",price:i.entry.price+this.Ps.entryOffset,shape:s?"arrowUp":"arrowDown",color:e,size:n};if(i.text?.entry&&(h.text=i.text.entry),i.id&&(h.id=`${i.id}-entry`),t.push(h),i.exit){const e={time:i.exit.time,position:"atPriceMiddle",price:i.exit.price+this.Ps.exitOffset,shape:s?"arrowDown":"arrowUp",color:r,size:n};i.text?.exit&&(e.text=i.text.exit),i.id&&(e.id=`${i.id}-exit`),t.push(e)}}return t}gy(){if(this.my){const t=this.by();this.my.setMarkers(t)}}detach(){this.my&&(this.my.detach(),this.my=null),this.wy=[]}}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{r_:i,Yf:s,My:n,yy:e,Sy:r,Jl:h}=t,l=t.xy??[];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.Cy,i.Py-1,i.Ty))}}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.Vf=t,this.be=i,this.I_=s,this.ky=n}draw(t){const i=this.ky();if(!i.It||i.Dy<=0)return;const s=this.I_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Vf.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Ry),u=this.be.priceToCoordinate(h.Fy),c=this.be.priceToCoordinate(l.Ry),d=this.be.priceToCoordinate(l.Fy);if(null===_||null===u||null===c||null===d)continue;const p=h.Ry>=h.Fy;n.fillStyle=this.Iy(p?i.Vy:i.Ly,i.Dy),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()}})}Iy(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.Ay=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ay.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.Ey(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}Ey(t,i,s,n){const e=i.By||i.startTime,r=i.Oy||i.endTime,h=i.R||i.color,l=i.Dy||i.opacity;if(!i||!e||!r)return;const o=this.Ay.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.Wy(h,l),t.fillRect(u,d,c-u,p-d)}Wy(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.zy=[],this.qb=null,this.eh=null,this.Vf=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.$y(),this.Ps.enabled&&this.Hy()}$y(){this.eh=new jr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}Hy(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Ny()}),this.Ny()}Ny(){this.Uy();const t=this.Vf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);this.qy(s),this.dM()}qy(t){if(0!==t.length){for(const i of this.Ps.sessions)this.jy(i,t);this.Ps.showOverlaps&&this.Yy(t)}}jy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Xy(i);this.Gy(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Ky(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.Ky(s,n[n.length-1].time,t)}Yy(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.Zy(e,r);h&&this.Jy(h,t)}}Zy(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}Jy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Xy(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Qy(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.Qy(s,n[n.length-1].time)}Ky(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",By:t,Oy:i,R:s.color,Dy:s.opacity,tS:s.name};this.zy.push(n)}Qy(t,i){const s={an:"overlap",By:t,Oy:i,R:this.Ps.overlapColor,Dy:this.Ps.overlapOpacity,tS:"Overlap"};this.zy.push(s)}Gy(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}Xy(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}Uy(){this.zy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Ny():this.Uy(),this.dM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Ny(),this.dM()}disable(){this.Ps.enabled=!1,this.Uy(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.Uy(),this.dM()}getSessionBoxes(){return this.zy}getChart(){return this.Vf}getSeries(){return this.be}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}class Gr{constructor(t){this.Ay=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ay.getProfileData();if(!s||0===s.bins.length)return;const n=this.Ay.options(),e=this.Ay.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.iS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.sS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.nS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}iS(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.Wy(M,y),t.fillRect(f,v,m,w)}sS(t,i,s,n,e,r,h){const l=n.priceToCoordinate(i);if(null===l)return;const 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([])}nS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Wy(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.Wy(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([])}Wy(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.eS=null,this.rS=new Map,this.qb=null,this.eh=null,this.Vf=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.$y(),this.Hy()}$y(){this.eh=new Kr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.qb=t,this.be.attachPrimitive(t)}Hy(){this.Vf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.hS()}),this.hS()}setVolumeData(t){this.rS=t,this.hS()}addVolumeData(t,i){this.rS.set(t,i),this.hS()}hS(){const t=this.Vf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);if(0===s.length)return;let n=1/0,e=-1/0;for(const t of s){const i=t.low||t.value||t.close,s=t.high||t.value||t.close;i<n&&(n=i),s>e&&(e=s)}const r=(e-n)/this.Ps.numberOfBins,h=[];for(let t=0;t<this.Ps.numberOfBins;t++)h.push({priceLevel:n+(t+.5)*r,volume:0,percentage:0});let l=0;for(const t of s){const i=t.close||t.value,s=this.rS.get(t.time)||1,e=Math.floor((i-n)/r);h[Math.max(0,Math.min(this.Ps.numberOfBins-1,e))].volume+=s,l+=s}for(const t of h)t.percentage=l>0?t.volume/l*100:0;let o=h[0];for(const t of h)t.volume>o.volume&&(o=t);const a=l*this.Ps.valueAreaPercentage,_=[...h].sort((t,i)=>i.volume-t.volume);let u=0;const c=[];for(const t of _){if(!(u<a))break;c.push(t),u+=t.volume}let d=-1/0,p=1/0;for(const t of c)t.priceLevel>d&&(d=t.priceLevel),t.priceLevel<p&&(p=t.priceLevel);this.eS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.dM()}getProfileData(){return this.eS}applyOptions(t){this.Ps={...this.Ps,...t},this.hS(),this.dM()}remove(){this.qb&&this.be&&this.be.detachPrimitive(this.qb),this.eS=null,this.rS.clear(),this.dM()}getChart(){return this.Vf}getSeries(){return this.be}options(){return this.Ps}dM(){this.qb&&this.qb.updateAllViews?.(),this.Vf.timeScale().applyOptions({})}}class Jr{constructor(t,i){this.lS=new Map,this.oS=null,this.aS=null,this._S=null,this.uS=null,this.cS=null,this.dS=null,this.pS=0,this.fS=null,this.Mg=void 0,this.Vf=t,this.Df=i,this.vS=t=>this.mS(t),this.wS=t=>this.gS(t),this.bS=t=>this.MS(t),this.yS=t=>this.SS(t),this.xS=()=>this.CS(),this.PS=t=>{"Escape"===t.key&&this.CS()},this.Vf.subscribeCrosshairMove(this.vS),this.Df.addEventListener("pointerdown",this.wS),this.Df.addEventListener("pointermove",this.bS),this.Df.addEventListener("pointerup",this.yS),this.Df.addEventListener("pointercancel",this.xS),document.addEventListener("keydown",this.PS)}TS(t){this.lS.set(t.id(),t)}kS(t){const i=t.id();this.oS===i&&this.DS(null),this._S===t&&this.CS(),this.lS.delete(i)}Gi(){return 0===this.lS.size}m(){this.Vf.unsubscribeCrosshairMove(this.vS),this.Df.removeEventListener("pointerdown",this.wS),this.Df.removeEventListener("pointermove",this.bS),this.Df.removeEventListener("pointerup",this.yS),this.Df.removeEventListener("pointercancel",this.xS),document.removeEventListener("keydown",this.PS),this.lS.clear()}mS(t){if(this.fS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.Mg=t.paneIndex,null!==this._S)return;const i=this.RS(t.hoveredObjectId),s=null===i?null:this.lS.get(i.gl)??null;this.DS(s?s.id():null),this.FS(s,null===s?null:i?.IS??null),this.VS()}gS(t){const i=null===this.oS?null:this.lS.get(this.oS)??null;i&&(this.cS={ut:t.clientX,ct:t.clientY},this.dS=i,i.isDraggable()&&(this._S=i,this.uS=t.pointerId,this.Df.setPointerCapture(t.pointerId),i.beginDrag(),this.pS=this.LS(i,t),this.VS(),t.preventDefault(),t.stopPropagation()))}MS(t){if(null===this._S)return;if(!this.AS(t))return void this.CS();const i=this.ES(t);null!==i&&this._S.dragTo(i),t.preventDefault(),t.stopPropagation()}SS(t){const i=this._S,s=this.dS,n=this.cS;this.BS(),this.dS=null,this.cS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this._S=null,this.pS=0,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.VS();null!==s&&!e&&s.isClickable()&&s.click()}CS(){if(null===this._S)return;const t=this._S;this._S=null,this.pS=0,this.BS(),t.cancelDrag(),this.VS()}AS(t){const i=this.Df.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}BS(){null!==this.uS&&(this.Df.hasPointerCapture(this.uS)&&this.Df.releasePointerCapture(this.uS),this.uS=null)}ES(t){const i=this._S;if(null===i)return null;const s=this.OS(i,t);return null===s?null:i.priceAt(s-this.pS)}OS(t,i){const s=this.Vf.panes()[t.paneIndex()],n=s?s.getHTMLElement():null;return n?i.clientY-n.getBoundingClientRect().top:null!==this.fS&&this.Mg===t.paneIndex()?this.fS.ct:null}LS(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.OS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}RS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,IS:null}:{gl:t.slice(0,i),IS:t.slice(i+1)}}FS(t,i){this.aS!==i&&(this.aS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}DS(t){this.oS!==t&&(null!==this.oS&&this.lS.get(this.oS)?.setHovered(!1),this.oS=t,this.aS=null,null!==t&&this.lS.get(t)?.setHovered(!0))}VS(){if(null!==this._S)return void this.Vf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.oS?null:this.lS.get(this.oS);t?this.Vf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Vf.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.kS(i),s.Gi()&&(s.m(),Qr.delete(t)))}let sh=0;class nh{constructor(t,i,s){this.sr=null,this.WS=!1,this.zS="",this.$S=null,this.Vf=t,this.be=i,this.So="pipsend-trading-line-"+sh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.HS(),(this.Ps.draggable||this.Ps.onClick)&&th(this.Vf)?.TS(this)}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.WS!==t&&this.sr&&(this.WS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.zS}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.$S=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.NS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.$S=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.$S;this.$S=null,null!==t&&t!==this.Ps.price&&(this.NS(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.zS=t.color),!this.sr)return;const i={title:this.US()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.WS||(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.NS(t)}remove(){ih(this.Vf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}US(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}HS(){this.zS=this.Ps.color,this.sr=this.be.createPriceLine({id:this.So,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.US()})}NS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.US()})}}class eh{constructor(t,i){this.If=null,this.qS=null,this.jS=null,this.YS={},this.Vf=t,this.be=i,this.XS()}XS(){this.If=this.Vf.chartElement()}GS(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.If?(this.qS=t,this.YS=i||{},new Promise(t=>{this.If.style.cursor="crosshair",this.jS=i=>{const s=this.GS(i),n=this.KS(s);this.disableClickToCreate(),t(n)},this.If.addEventListener("click",this.jS)})):Promise.resolve(null)}disableClickToCreate(){this.If&&this.jS&&(this.If.removeEventListener("click",this.jS),this.If.style.cursor="default"),this.qS=null,this.jS=null,this.YS={}}KS(t){if(!this.qS)return null;let i;switch(this.qS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.YS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.YS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.YS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.YS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.YS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.YS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.YS};break;default:return null}return new nh(this.Vf,this.be,i)}getCreationMode(){return this.qS}isCreating(){return null!==this.qS}}class rh{constructor(){this.ZS=[],this.JS=new Map,this.QS=new Map,this.xt=!0}TS(t){this.JS.has(t)||(this.ZS.push(t),this.JS.set(t,[]),this.xt=!0)}kS(t){const i=this.ZS.indexOf(t);-1!==i&&this.ZS.splice(i,1),this.JS.delete(t),this.xt=!0}Gi(){return 0===this.ZS.length}tx(t,i){this.JS.set(t,i),this.xt=!0}ix(t,i){return this.xt&&this.sx(),this.QS.get(hh(t,i))??0}sx(){const t=new Map,i=[];for(const s of this.ZS)for(const n of this.JS.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.QS=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.nx=[],this.hx=0,this.Nf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.nx)if(s.lx&&t>=s.ox&&t<=s._x&&Math.abs(i-s.ux)<=s.qt/2)return{sn:s.sn,IS:"close"};for(const s of this.nx)if(t>=s.vx&&t<=s.mx&&Math.abs(i-s.ux)<=s.qt/2)return{sn:s.sn,IS:"body"};for(const t of this.nx)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,IS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.hw(t))}hw(t){const i=this.Yt;if(this.nx=[],null===i||0===i.wx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Nf!==i.T&&(this.Nf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.hx=Math.max(0,n.width-i.Mu);const e=i.gx?this.hx:n.width;for(const s of i.wx)this.nx.push(this.bx(t,i,s,e));i.gx&&i.wx.length>1&&this.Mx(t,i),s.restore()}bx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.yx,o=0===s.Sx.length?0:Math.max(this.Wn.Ii(e,s.Sx)+2*i.MM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.MM,_=s.lx?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.xx,f=p-l/2;this.Cx(t,s,d,c,n),this.Px(t,i,s,{qh:d,Tx:f,ts:u,qt:l});let v=d;return o>0&&(this.kx(t,i,s,{qh:v,Tx:f,ts:o,qt:l}),v+=o,this.Dx(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.kM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.lx&&(this.Dx(e,s.R,v,f,l,r,h),this.Rx(t,i,s,{qh:v,Tx:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,ux:p,qt:l,vx:d,mx:c,ox:v,_x:v+_,lx:s.lx}}Cx(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.xx?(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()}Px(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Fx===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),ph(e,n,i.Ix,r,h),e.fillStyle=this.Po.X(i.Z,i.Vx),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}kx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Lx){const t=i.Wt;e.save(),ph(e,{qh:n.qh+t,Tx:n.Tx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Ix-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Lx?i.Ax:s.R,e.fillText(s.Sx,n.qh+n.ts/2,n.Tx+n.qt/2),e.restore()}Dx(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.Po.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}Rx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Fx===s.sn&&"close"===i.Ex){e.save();const t=i.Wt;ph(e,{qh:n.qh,Tx:n.Tx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Ix-t),r,h,"right"),e.fillStyle=this.Po.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,o=(n.Tx+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()}Mx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.wx.find(t=>"entry"===t.sn)??i.wx[0],h=i.wx.map(t=>t.ct),l=Math.round(this.hx*n);s.save(),s.setLineDash([]),s.strokeStyle=r.R,s.lineWidth=Math.max(1,Math.floor(n)),s.beginPath(),s.moveTo(l,Math.round(Math.min(...h)*e)),s.lineTo(l,Math.round(Math.max(...h)*e)),s.stroke();for(const t of i.wx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.Po.X(i.Z,i.Vx),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.qh*n),l=Math.round(i.Tx*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.Bx()?.Li??-1e3}text(){return this.Bx()?.hi??""}textColor(){return this.Bx()?.kM??"#FFFFFF"}backColor(){return this.Bx()?.R??"#000000"}visible(){return null!==this.Bx()}Bx(){return this.Qt()}}let mh=0;class wh{constructor(t,i,s){this.eh=new fh,this.Po=new S([]),this.Ox=!1,this.Wx=null,this.aS=null,this.zx=null,this.$S=null,this.Vf=t,this.be=i,this.So="pipsend-position-line-"+mh++,this.Ps=s,this.Ff={...uh,...s.theme},this.Zb=[this.eh],this.$x=ch.map(t=>new vh(()=>this.Hx(t))),this.Nx=function(t,i){let s=ah.get(t);return s||(s=new rh,ah.set(t,s)),s.TS(i),s}(this.Vf,this.So),this.be.attachPrimitive(this),th(this.Vf)?.TS(this)}attached(t){this.dM=t.requestUpdate,this.Ox=!0,this.requestUpdate()}detached(){this.Ox=!1,this.dM=void 0}paneViews(){return this.Zb}priceAxisViews(){return this.$x}updateAllViews(){this.eh.Tt(this.Ux())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.qx(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.IS}`,zOrder:"top",cursorStyle:"close"===s.IS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.Wx===n&&this.aS===e||(this.Wx=n,this.aS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Wx&&"close"!==this.aS&&(this.qx(this.Wx)?.draggable??!0)}isClickable(){return"close"===this.aS||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}dragAnchorY(){if(null===this.zx)return null;const t=this.qx(this.zx)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.zx=this.Wx,null===this.zx)return;const t=this.qx(this.zx)?.price??null;this.$S=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.zx,t)}dragTo(t){null!==this.zx&&(this.jx(this.zx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.zx,t))}commitDrag(){const t=this.zx;if(this.zx=null,this.$S=null,null===t)return;const i=this.qx(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.zx,i=this.$S;if(this.zx=null,this.$S=null,null===t)return;null!==i&&i!==this.qx(t)?.price&&(this.jx(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.qx(t)?.price??0)}click(){const t=this.Wx;if(null===t)return;if("close"===this.aS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.qx(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.zx,s=null===i?void 0:this.qx(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.qx(i);null!==t&&(t.price=s)}t.theme&&(this.Ff={...this.Ff,...t.theme}),this.requestUpdate()}setPrice(t,i){this.zx!==t&&this.jx(t,i)}setText(t,i){const s=this.qx(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of ch){const s=this.qx(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){ih(this.Vf,this),function(t,i){const s=ah.get(t);s&&(s.kS(i),s.Gi()&&ah.delete(t))}(this.Vf,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.dM&&this.dM()}Hx(t){const i=this.qx(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,kM:this.Po.K(n).J}}qx(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}jx(t,i){const s=this.qx(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}Ux(){if(!this.Ox||!1===this.Ps.visible)return null;const t=this.Vf.options().layout,i=this.Ff.fontSize??t.fontSize,s=i+2*this.Ff.paddingY,n=[],e=[];for(const t of ch){const i=this.qx(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,xx:0,R:i.color??_h[t],hi:i.formatText?i.formatText(i.price):i.text??"",Sx:i.badge??"",Lx:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),lx:i.closable??!0,Yx:i.draggable??!0})}if(0===n.length)return this.Nx.tx(this.So,[]),null;this.Nx.tx(this.So,e);for(const t of n)t.xx=this.Nx.ix(this.So,t.sn);return{wx:n,Z:this.Ff.background??(r=t.background,"solid"===r.type?r.color:r.topColor),kM:this.Ff.textColor,Ax:this.Ff.badgeTextColor,Ix:this.Ff.borderRadius,Wt:this.Ff.borderWidth,MM:this.Ff.paddingX,yx:this.Ff.paddingY,Vx:this.Ff.backgroundOpacity,T:g(i,this.Ff.fontFamily??t.fontFamily),P:i,gx:!1!==this.Ps.connectorVisible&&n.length>1,Mu:this.Ps.rightOffset??56,Fx:this.Wx,Ex:this.aS};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.Cy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Py,t.day=i.day??i.Ty,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.Xx(),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}Xx(){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.kM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Lh;!function(t){t.Gx="idle",t.Kx="waiting_first_point",t.Zx="waiting_second_point",t.Jx="completed"}(Lh||(Lh={}));class Ah{constructor(t,i,s={}){this.Vv=Lh.Gx,this.Qx=null,this.jS=null,this.np=null,this.Vf=t,this.be=i,this.tC=s}iC(){this.Vv===Lh.Gx&&(this.Vv=Lh.Kx,this.Qx=null,this.sC(),this.nC())}eC(){this.Vv=Lh.Gx,this.Qx=null,this.rC(),this.hC(),this.tC.lC&&this.tC.lC()}oC(){return this.Vv}aC(){return this.Vv===Lh.Kx||this.Vv===Lh.Zx}sC(){this.jS=t=>{this._C(t)},this.Vf.subscribeClick(this.jS)}nC(){this.np=t=>{this.uC(t)},this.Vf.subscribeCrosshairMove(this.np)}rC(){this.jS&&(this.Vf.unsubscribeClick(this.jS),this.jS=null)}hC(){this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null)}_C(t){if(!t.point)return;if(Ih(this.Vf))return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.Vf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Vv===Lh.Kx?(this.Qx=n,this.Vv=Lh.Zx,this.tC.cC&&this.tC.cC(n)):this.Vv===Lh.Zx&&this.Qx&&(this.Vv=Lh.Jx,this.tC.dC&&this.tC.dC(n),this.tC.pC&&this.tC.pC(this.Qx,n),this.rC(),this.hC(),this.Vv=Lh.Gx,this.Qx=null)}uC(t){if(!t.point)return;if(this.Vv!==Lh.Zx)return;const i=this.be.coordinateToPrice(t.point.y),s=Yn(this.Vf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.tC.fC&&this.tC.fC(n)}m(){this.eC()}}class Eh{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Bh{constructor(t){this.vC=t,this.Jt=new Eh(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Oh extends Dh{constructor(t,i){super(t,"trend-line",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.SC=null,this.xC=null,this.CC=!1,this.PC=null,this.TC=null,this.kC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.kC),this.$y(),this.kC.interactive?this.DC():this.CC=!0}DC(){const t=new Ah(this._chart,this._series,{cC:t=>{this.kC.point1Time=t.gt,this.kC.point1Price=t.bt,this.dM()},dC:t=>{this.kC.point2Time=t.gt,this.kC.point2Price=t.bt,this.CC=!0,this.dM(),this.kC.onUpdate&&this.kC.onUpdate()},fC:t=>{this.kC.point1Time&&!this.CC&&(this.TC=t,this.dM())},pC:()=>{this.CC=!0}});this.PC=t,t.iC()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new Bh(this)}IC(){if(!this.kC.point1Time||!this.kC.point2Time)return null;const t=Xn(this._chart,this._series,this.kC.point1Time)??0,i=this._series.priceToCoordinate(this.kC.point1Price)??0,s=Xn(this._chart,this._series,this.kC.point2Time)??0,n=this._series.priceToCoordinate(this.kC.point2Price)??0;if(!this.kC.extendLeft&&!this.kC.extendRight)return{VC:t,LC:i,AC:s,EC:n};if(s===t)return{VC:t,LC:i,AC:s,EC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{VC:this.kC.extendLeft?0:t,LC:this.kC.extendLeft?i-r*t:i,AC:this.kC.extendRight?e:s,EC:this.kC.extendRight?i+r*(e-t):n}}BC(){const t=this.IC();if(null===t)return null;const i=t.AC>=t.VC?t.EC:t.LC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.kC.point2Price??this.kC.point1Price??null}drawToCanvas(t,i,s){if(!this.CC&&this.kC.point1Time&&this.TC)return void this.OC(t,i,s);if(!this.kC.point1Time||!this.kC.point2Time)return;const n=(Xn(this._chart,this._series,this.kC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.kC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.kC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.kC.point2Price)??0)*s,l=this.kC.lineColor,o=this.wC?this.kC.lineWidth+1:this.kC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.kC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.kC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.IC();if(null===a)return;t.moveTo(a.VC*i,a.LC*s),t.lineTo(a.AC*i,a.EC*s),t.stroke(),t.setLineDash([]),!this.wC&&!this.gC||this.isLocked()||(this.WC(t,n,e,i,l),this.WC(t,r,h,i,l));const _=this.BC();if(!1!==this.kC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Vh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}OC(t,i,s){if(!this.kC.point1Time||!this.TC)return;const n=(Xn(this._chart,this._series,this.kC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.kC.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.TC.gt)??0)*i,h=(this._series.priceToCoordinate(this.TC.bt)??0)*s;t.strokeStyle=this.kC.lineColor,t.lineWidth=this.kC.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.WC(t,n,e,i,this.kC.lineColor),t.globalAlpha=.5,this.WC(t,r,h,i,this.kC.lineColor),t.globalAlpha=1}WC(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.kC.lineColor=t,this.dM()}color(){return this.kC.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}isHovered(){return this.gC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}FC(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.IC();if(null===s)return!1;return this.zC(t,i,s.VC,s.LC,s.AC,s.EC)<=8}zC(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.kC.point1Time||!this.kC.point2Time)return null;const s=Xn(this._chart,this._series,this.kC.point1Time)??0,n=this._series.priceToCoordinate(this.kC.point1Price)??0,e=Xn(this._chart,this._series,this.kC.point2Time)??0,r=this._series.priceToCoordinate(this.kC.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.zC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.bC=!0,this.MC=t,this.yC=i,"line"===t&&(this.SC={gt:this.kC.point1Time,bt:this.kC.point1Price},this.xC={gt:this.kC.point2Time,bt:this.kC.point2Price})}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.SC=null,this.xC=null}updateDrag(t,i){if(this.bC&&this.MC){if("point1"===this.MC)this.kC.point1Time=t,this.kC.point1Price=i;else if("point2"===this.MC)this.kC.point2Time=t,this.kC.point2Price=i;else if("line"===this.MC&&this.SC&&this.xC){const s=yh(this.yC,t,i);this.kC.point1Time=this.SC.gt+s.gt,this.kC.point1Price=this.SC.bt+s.bt,this.kC.point2Time=this.xC.gt+s.gt,this.kC.point2Price=this.xC.bt+s.bt}this.dM(),this.kC.onUpdate&&this.kC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Ch(this.kC.point1Price??0,xh(this.kC.point1Time)),Ch(this.kC.point2Price??0,xh(this.kC.point2Time))],style:{lineColor:this.kC.lineColor,lineWidth:this.kC.lineWidth,lineStyle:this.kC.lineStyle,extendLeft:this.kC.extendLeft,extendRight:this.kC.extendRight}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return this.CC}remove(){this.PC&&(this.PC.m(),this.PC=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.kC.onRemove&&this.kC.onRemove()}}function Wh(t,i){return new Oh(t,i)}class zh{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class $h{constructor(t){this.vC=t,this.Jt=new zh(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Hh extends Dh{constructor(t,i){super(t,"horizontal-line",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.yC=null,this.$C=0,this.HC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.HC),this.$y()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new $h(this)}NC(){return void 0===this.HC.startTime?0:Xn(this._chart,this._series,this.HC.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.HC.price)return;const n=(this._series.priceToCoordinate(this.HC.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.NC()*i,h=this.HC.lineColor,l=this.wC?this.HC.lineWidth+1:this.HC.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.HC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.HC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.HC.showPriceLabel&&Vh(t,this._series,i,s,{bt:this.HC.price,ct:n/s,Ot:h}),this.HC.showLabel&&(this.wC||this.gC)&&this.UC(t,n,i,s,h)}UC(t,i,s,n,e){const r=this.HC.labelText||this.HC.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.HC.lineColor=t,this.dM()}color(){return this.HC.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.HC.price)return!1;const s=this._series.priceToCoordinate(this.HC.price)??0;return!(t<this.NC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.bC=!0,this.yC=i,this.$C=this.HC.price??0}stopDrag(){this.bC=!1,this.yC=null}updateDrag(t,i){this.bC&&(this.HC.price=this.$C+yh(this.yC,t,i).bt,this.dM(),this.HC.onUpdate&&this.HC.onUpdate())}getPrice(){return this.HC.price}setPrice(t){this.HC.price=t,this.dM()}setLabel(t){this.HC.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Ch(this.HC.price??0,xh(this.HC.startTime))],style:{lineColor:this.HC.lineColor,lineWidth:this.HC.lineWidth,lineStyle:this.HC.lineStyle,showLabel:this.HC.showLabel,labelText:this.HC.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.HC.onRemove&&this.HC.onRemove()}}function Nh(t,i){return new Hh(t,i)}class Uh{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class qh{constructor(t){this.vC=t,this.Jt=new Uh(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class jh extends Dh{constructor(t,i){super(t,"cross-line",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.yC=null,this.qC=0,this.$C=0,this.jC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.jC),this.$y()}$y(){this.eh=new qh(this);const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.mC&&this.mC()}_update(){this.dM()}YC(){if(void 0===this.jC.time||void 0===this.jC.price)return null;const t=Xn(this._chart,this._series,this.jC.time),i=this._series.priceToCoordinate(this.jC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.YC();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.jC.lineColor,_=this.wC||this.gC&&!this.isLocked(),u=_?this.jC.lineWidth+1:this.jC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.jC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.jC.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.jC.showPriceLabel&&void 0!==this.jC.price&&Vh(t,this._series,i,s,{bt:this.jC.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())}FC(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.YC();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.bC=!0,this.yC=i,this.qC=this.jC.time,this.$C=this.jC.price??0}updateDrag(t,i){if(!this.bC)return;const s=yh(this.yC,t,i);this.jC.time=this.qC+s.gt,this.jC.price=this.$C+s.bt,this.dM(),this.jC.onUpdate&&this.jC.onUpdate()}stopDrag(){this.bC=!1,this.yC=null}setColor(t){this.jC.lineColor=t,this.dM()}color(){return this.jC.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}remove(){if(this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.mC=null,this.jC.onRemove&&this.jC.onRemove()}_serializeShape(){return{type:"crossLine",points:[Ch(this.jC.price??0,xh(this.jC.time))],style:{lineColor:this.jC.lineColor,lineWidth:this.jC.lineWidth,lineStyle:this.jC.lineStyle}}}}function Yh(t,i){return new jh(t,i)}class Xh{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Gh{constructor(t){this.vC=t,this.Jt=new Xh(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Kh extends Dh{constructor(t,i){super(t,"polygon",i),this.I_=[],this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.XC=null,this.CC=!1,this.TC=null,this.jS=null,this.GC=null,this.KC=null,this.ZC={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.ZC),this.I_=[...i.points??[]],this.$y(),this.ZC.interactive?this.JC():this.CC=this.I_.length>=3}$y(){this.eh=new Gh(this);const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.mC&&this.mC()}_update(){this.dM()}JC(){this.jS=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.I_.length>=3&&this.QC(t.point.x,t.point.y)?this.tP():(this.I_.push({time:s,price:i}),this.dM()))},this.GC=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.TC={time:s,price:i},this.dM())},this.KC=t=>{"Enter"===t.key&&this.I_.length>=3?this.tP():"Escape"===t.key&&(this.I_=[],this.tP())},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.GC),document.addEventListener("keydown",this.KC)}QC(t,i){const s=this.I_[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.iP&&Math.abs(i-e)<=Kh.iP)}tP(){this.CC=!0,this.TC=null,this.sP(),this.dM(),this.ZC.onComplete&&this.ZC.onComplete(),this.ZC.onUpdate&&this.ZC.onUpdate()}sP(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.GC&&(this._chart.unsubscribeCrosshairMove(this.GC),this.GC=null),this.KC&&(document.removeEventListener("keydown",this.KC),this.KC=null)}nP(){const t=[...this.I_];return this.CC||null===this.TC||t.push(this.TC),this.eP(t)}eP(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.nP();if(n.length<2)return;const e=this.ZC.borderColor,r=this.wC?this.ZC.borderWidth+1:this.ZC.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.ZC.fillOpacity>0&&(t.fillStyle=this.Iy(this.ZC.fillColor,this.ZC.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.CC?"dashed"===this.ZC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.ZC.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.wC||this.gC||!this.CC)&&!this.isLocked())for(const n of this.rP())this.hP(t,n.ut*i,n.ct*s,i,e)}rP(){return this.eP(this.I_)}hP(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()}Iy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}FC(t,i){if(!this.isVisible()||!this.CC)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.rP();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.rP();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.bC=!0,this.MC=t,this.yC=i,this.XC=this.I_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.bC&&null!==this.MC&&null!==this.XC){if("shape"===this.MC){const s=yh(this.yC,t,i);this.I_=this.XC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.MC;this.I_[s]&&(this.I_[s]={time:t,price:i})}this.dM(),this.ZC.onUpdate&&this.ZC.onUpdate()}}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.XC=null}setColor(t){this.ZC.borderColor=t,this.ZC.fillColor=t,this.dM()}color(){return this.ZC.borderColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}points(){return this.I_}isComplete(){return this.CC}remove(){if(this.sP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.mC=null,this.ZC.onRemove&&this.ZC.onRemove()}_serializeShape(){return{type:"polygon",points:this.I_.map(t=>Ch(t.price,xh(t.time))),style:{fillColor:this.ZC.fillColor,fillOpacity:this.ZC.fillOpacity,borderColor:this.ZC.borderColor,borderWidth:this.ZC.borderWidth,borderStyle:this.ZC.borderStyle}}}}function Zh(t,i){return new Kh(t,i)}Kh.iP=12;class Jh{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Qh{constructor(t){this.vC=t,this.Jt=new Jh(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class tl extends Dh{constructor(t,i){super(t,"parallel-channel",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.lP=null,this.CC=!1,this.ud=0,this.TC=null,this.jS=null,this.GC=null,this.oP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.oP),this.$y(),this.oP.interactive?this.JC():this.CC=!0}$y(){this.eh=new Qh(this);const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.mC&&this.mC()}_update(){this.dM()}JC(){this.jS=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.ud)this.oP.point1Time=s,this.oP.point1Price=i;else{if(1!==this.ud)return this.oP.channelWidth=i-this.aP(s),void this.tP();this.oP.point2Time=s,this.oP.point2Price=i}this.ud++,this.dM()}},this.GC=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.TC={gt:s,bt:i},2===this.ud&&(this.oP.channelWidth=i-this.aP(s)),this.dM())},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.GC)}tP(){this.CC=!0,this.TC=null,this.sP(),this.dM(),this.oP.onComplete&&this.oP.onComplete(),this.oP.onUpdate&&this.oP.onUpdate()}sP(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.GC&&(this._chart.unsubscribeCrosshairMove(this.GC),this.GC=null)}aP(t){const i=this.oP.point1Time,s=this.oP.point2Time,n=this.oP.point1Price,e=this.oP.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)}lS(){const t=this.oP,i=this.CC?t.point2Time:t.point2Time??this.TC?.gt,s=this.CC?t.point2Price:t.point2Price??this.TC?.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:{VC:n,AC:l,_P:r,uP:o,cP:_,dP:u}}drawToCanvas(t,i,s){const n=this.lS();if(null===n)return;const e=this.oP,r=e.lineColor,h=this.wC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Iy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.VC*l,n._P*o),t.lineTo(n.AC*l,n.uP*o),t.lineTo(n.AC*l,n.dP*o),t.lineTo(n.VC*l,n.cP*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.VC*l,n._P*o),t.lineTo(n.AC*l,n.uP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.VC*l,n.cP*o),t.lineTo(n.AC*l,n.dP*o)),t.stroke(),t.setLineDash([]);if((this.wC||this.gC||!this.CC)&&!this.isLocked()&&(this.hP(t,n.VC*l,n._P*o,l,r),this.hP(t,n.AC*l,n.uP*o,l,r),0!==(e.channelWidth??0))){const i=(n.VC+n.AC)/2,s=(n.cP+n.dP)/2;this.hP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.CC){const i=this._series.coordinateToPrice(n.uP);null!==i&&Vh(t,this._series,l,o,{bt:i,ct:n.uP,Ot:r})}}hP(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()}Iy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}FC(t,i){if(!this.isVisible()||!this.CC)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}pP(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.lS();if(null===s)return!1;return this.pP(t,i,s.VC,s._P,s.AC,s.uP)<=8||this.pP(t,i,s.VC,s.cP,s.AC,s.dP)<=8}hitTestEndpoint(t,i){const s=this.lS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.VC,s._P))return"point1";if(n(s.AC,s.uP))return"point2";if(0!==(this.oP.channelWidth??0)){if(n((s.VC+s.AC)/2,(s.cP+s.dP)/2))return"width"}return null}startDrag(t,i){this.bC=!0,this.MC=t,this.yC=i,this.lP={fP:{gt:this.oP.point1Time,bt:this.oP.point1Price},vP:{gt:this.oP.point2Time,bt:this.oP.point2Price},ts:this.oP.channelWidth??0}}updateDrag(t,i){if(!this.bC||null===this.MC||null===this.lP)return;const s=this.oP;if("point1"===this.MC)s.point1Time=t,s.point1Price=i;else if("point2"===this.MC)s.point2Time=t,s.point2Price=i;else if("width"===this.MC)s.channelWidth=i-this.aP(t);else{const n=yh(this.yC,t,i);s.point1Time=this.lP.fP.gt+n.gt,s.point1Price=this.lP.fP.bt+n.bt,s.point2Time=this.lP.vP.gt+n.gt,s.point2Price=this.lP.vP.bt+n.bt,s.channelWidth=this.lP.ts}this.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.lP=null}setColor(t){this.oP.lineColor=t,this.oP.fillColor=t,this.dM()}color(){return this.oP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}isComplete(){return this.CC}remove(){if(this.sP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.mC=null,this.oP.onRemove&&this.oP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Ch(this.oP.point1Price??0,xh(this.oP.point1Time)),Ch(this.oP.point2Price??0,xh(this.oP.point2Time))],style:{lineColor:this.oP.lineColor,lineWidth:this.oP.lineWidth,lineStyle:this.oP.lineStyle,fillColor:this.oP.fillColor,fillOpacity:this.oP.fillOpacity,extendRight:this.oP.extendRight},extra:{channelWidth:this.oP.channelWidth}}}}function il(t,i){return new tl(t,i)}class sl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class nl{constructor(t){this.vC=t,this.Jt=new sl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class el extends Dh{constructor(t,i){super(t,"pitchfork",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.lP=null,this.CC=!1,this.ud=0,this.TC=null,this.jS=null,this.GC=null,this.mP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.mP),this.$y(),this.mP.interactive?this.JC():this.CC=!0}$y(){this.eh=new nl(this);const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}dM(){this.mC&&this.mC()}_update(){this.dM()}JC(){this.jS=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.ud)this.mP.pivotTime=s,this.mP.pivotPrice=i;else{if(1!==this.ud)return this.mP.lowerTime=s,this.mP.lowerPrice=i,this.ud++,void this.tP();this.mP.upperTime=s,this.mP.upperPrice=i}this.ud++,this.dM()}},this.GC=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.TC={gt:s,bt:i},this.dM())},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.GC)}tP(){this.CC=!0,this.TC=null,this.sP(),this.dM(),this.mP.onComplete&&this.mP.onComplete(),this.mP.onUpdate&&this.mP.onUpdate()}sP(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.GC&&(this._chart.unsubscribeCrosshairMove(this.GC),this.GC=null)}wP(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}}gP(){const t=this.mP,i=this.wP(t.pivotTime,t.pivotPrice),s=this.wP(t.upperTime,t.upperPrice),n=this.CC?this.wP(t.lowerTime,t.lowerPrice):this.wP(t.lowerTime,t.lowerPrice)??(null!==this.TC&&this.ud>=2?this.wP(this.TC.gt,this.TC.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{bP:i,MP:e,yP:s,SP:n,xP:l(i),CP:l(s),PP:l(n)}}drawToCanvas(t,i,s){const n=this.gP();if(null===n)return void this.TP(t,i,s);const e=this.mP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Iy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.yP.ut*h,n.yP.ct*l),t.lineTo(n.CP.ut*h,n.CP.ct*l),t.lineTo(n.PP.ut*h,n.PP.ct*l),t.lineTo(n.SP.ut*h,n.SP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.wC?e.lineWidth+1:e.lineWidth)*h,"dashed"===e.lineStyle?t.setLineDash([10*h,5*h]):"dotted"===e.lineStyle&&t.setLineDash([2*h,3*h]),t.beginPath(),t.moveTo(n.yP.ut*h,n.yP.ct*l),t.lineTo(n.SP.ut*h,n.SP.ct*l),t.moveTo(n.bP.ut*h,n.bP.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.moveTo(n.SP.ut*h,n.SP.ct*l),t.lineTo(n.PP.ut*h,n.PP.ct*l),t.stroke(),t.setLineDash([]);if((this.wC||this.gC||!this.CC)&&!this.isLocked())for(const i of[n.bP,n.yP,n.SP])this.hP(t,i.ut*h,i.ct*l,h,r)}TP(t,i,s){const n=this.mP,e=this.wP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.wP(n.upperTime,n.upperPrice)??(null!==this.TC?this.wP(this.TC.gt,this.TC.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.hP(t,e.ut*i,e.ct*s,i,h)}hP(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()}Iy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}FC(t,i){if(!this.isVisible()||!this.CC)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}pP(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.gP();if(null===s)return!1;return[[s.bP,s.xP],[s.yP,s.CP],[s.SP,s.PP],[s.yP,s.SP]].some(([s,n])=>this.pP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.gP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.bP)?"pivot":n(s.yP)?"upper":n(s.SP)?"lower":null}startDrag(t,i){this.bC=!0,this.MC=t,this.yC=i,this.lP=[{gt:this.mP.pivotTime,bt:this.mP.pivotPrice},{gt:this.mP.upperTime,bt:this.mP.upperPrice},{gt:this.mP.lowerTime,bt:this.mP.lowerPrice}]}updateDrag(t,i){if(!this.bC||null===this.MC||null===this.lP)return;const s=this.mP;if("pivot"===this.MC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.MC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.MC)s.lowerTime=t,s.lowerPrice=i;else{const n=yh(this.yC,t,i),[e,r,h]=this.lP;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.dM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.lP=null}setColor(t){this.mP.lineColor=t,this.mP.fillColor=t,this.dM()}color(){return this.mP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}isComplete(){return this.CC}remove(){if(this.sP(),this.qb){try{this._series.detachPrimitive(this.qb)}catch(t){}this.qb=null}this.mC=null,this.mP.onRemove&&this.mP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Ch(this.mP.pivotPrice??0,xh(this.mP.pivotTime)),Ch(this.mP.upperPrice??0,xh(this.mP.upperTime)),Ch(this.mP.lowerPrice??0,xh(this.mP.lowerTime))],style:{lineColor:this.mP.lineColor,lineWidth:this.mP.lineWidth,lineStyle:this.mP.lineStyle,fillColor:this.mP.fillColor,fillOpacity:this.mP.fillOpacity}}}}function rl(t,i){return new el(t,i)}class hl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ll{constructor(t){this.vC=t,this.Jt=new hl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ol extends Dh{constructor(t,i){super(t,"vertical-line",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.yC=null,this.qC=0,this.kP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.kP),this.$y()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new ll(this)}drawToCanvas(t,i,s){if(void 0===this.kP.time)return;const n=(Xn(this._chart,this._series,this.kP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.kP.lineColor,h=this.wC||this.gC&&!this.isLocked()?this.kP.lineWidth+1:this.kP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.kP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.kP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.kP.showLabel&&(this.wC||this.gC)&&this.kP.labelText&&this.UC(t,n,i,s,r)}UC(t,i,s,n,e){const r=this.kP.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.kP.lineColor=t,this.dM()}color(){return this.kP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.kP.time)return!1;const s=Xn(this._chart,this._series,this.kP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.bC=!0,this.yC=i,this.qC=this.kP.time}stopDrag(){this.bC=!1,this.yC=null}updateDrag(t,i){this.bC&&(this.kP.time=this.qC+yh(this.yC,t,i).gt,this.dM(),this.kP.onUpdate&&this.kP.onUpdate())}getTime(){return this.kP.time}setTime(t){this.kP.time=t,this.dM()}setLabel(t){this.kP.labelText=t,this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Ch(0,xh(this.kP.time))],style:{lineColor:this.kP.lineColor,lineWidth:this.kP.lineWidth,lineStyle:this.kP.lineStyle,showLabel:this.kP.showLabel,labelText:this.kP.labelText}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.kP.onRemove&&this.kP.onRemove()}}function al(t,i){return new ol(t,i)}const _l=[{DP:0,Jl:"0.0%"},{DP:.236,Jl:"23.6%"},{DP:.382,Jl:"38.2%"},{DP:.5,Jl:"50.0%"},{DP:.618,Jl:"61.8%"},{DP:.786,Jl:"78.6%"},{DP:1,Jl:"100.0%"}],ul=[..._l,{DP:1.272,Jl:"127.2%"},{DP:1.414,Jl:"141.4%"},{DP:1.618,Jl:"161.8%"},{DP:2,Jl:"200.0%"},{DP:2.618,Jl:"261.8%"}];class cl{constructor(t=!1){this.RP=t?ul:_l}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.RP.map(({DP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{DP:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.RP=t}getRatios(){return[...this.RP]}getRatioValues(){return this.RP.map(t=>t.DP)}useStandardRatios(){this.RP=_l}useExtendedRatios(){this.RP=ul}}class dl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class pl{constructor(t){this.vC=t,this.Jt=new dl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}}function fl(t){return{DP:t,Jl:`${(100*t).toFixed(1)}%`}}class vl extends Dh{constructor(t,i){super(t,"fibonacci-tool",i),this.qb=null,this.mC=null,this.Xb=null,this.eh=null,this.FP=null,this.CC=!1,this.wC=!1,this.gC=!1,this.TC=null,this.bC=!1,this.IP=null,this.np=null,this.VP={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.VP),this.LP=new cl(this.VP.useExtended),void 0!==this.VP.levels&&this.VP.levels.length>0&&this.LP.updateRatios(this.VP.levels.map(fl)),this.$y(),this.VP.interactive?this.DC():(this.CC=!0,this.AP())}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new pl(this)}drawToCanvas(t,i,s){if(!this.CC&&this.VP.point1Time&&this.TC)return void this.OC(t,i,s);if(!this.Xb||!this.VP.point1Time||!this.VP.point2Time)return;const n=(Xn(this._chart,this._series,this.VP.point1Time)??0)*i,e=(Xn(this._chart,this._series,this.VP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.wC?2:this.VP.lineWidth;this.Xb.levels.forEach(n=>{this.bx(t,n,r,h,i,s,l)}),!this.wC&&!this.gC||this.isLocked()||(this.WC(t,n,(this._series.priceToCoordinate(this.VP.point1Price)??0)*s,i),this.WC(t,e,(this._series.priceToCoordinate(this.VP.point2Price)??0)*s,i))}bx(t,i,s,n,e,r,h=1){const l=i.ratio??i.DP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.VP.levelColors?.[l.toString()]||this.VP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.VP.showLabels&&this.UC(t,i,s,n,a,e,_)}UC(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.LP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.VP.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.VP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}AP(){this.VP.point1Time&&this.VP.point1Price&&this.VP.point2Time&&this.VP.point2Price&&(this.Xb=this.LP.calculateLevels(this.VP.point1Time,this.VP.point1Price,this.VP.point2Time,this.VP.point2Price),this.VP.onUpdate&&this.Xb&&this.VP.onUpdate(this.Xb))}updatePoints(t,i,s,n){this.VP.point1Time=t,this.VP.point1Price=i,this.VP.point2Time=s,this.VP.point2Price=n,this.AP(),this.dM()}getMetrics(){return this.Xb}getLevels(){return this.Xb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.LP.getRatioValues();return{type:"fibRetracement",points:[Ch(this.VP.point1Price??0,xh(this.VP.point1Time)),Ch(this.VP.point2Price??0,xh(this.VP.point2Time))],style:{lineColor:this.VP.lineColor,lineWidth:this.VP.lineWidth,showLabels:this.VP.showLabels,labelPosition:this.VP.labelPosition,levelColors:this.VP.levelColors},extra:{levels:t,useExtended:this.VP.useExtended}}}useExtendedLevels(t){this.VP.useExtended=t,t?this.LP.useExtendedRatios():this.LP.useStandardRatios(),this.AP(),this.dM()}DC(){this.FP=new Ah(this._chart,this._series,{cC:t=>{this.VP.point1Time=t.gt,this.VP.point1Price=t.bt,this.dM()},dC:t=>{this.VP.point2Time=t.gt,this.VP.point2Price=t.bt},pC:(t,i)=>{this.VP.point1Time=t.gt,this.VP.point1Price=t.bt,this.VP.point2Time=i.gt,this.VP.point2Price=i.bt,this.CC=!0,this.TC=null,this.AP(),this.EP(),this.dM()},fC:t=>{this.TC=t,this.dM()}}),this.FP.iC()}OC(t,i,s){if(!this.VP.point1Time||!this.TC)return;const n=(Xn(this._chart,this._series,this.VP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.VP.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.TC.gt)??0)*i,h=(this._series.priceToCoordinate(this.TC.bt)??0)*s,l=this.LP.calculateLevels(this.VP.point1Time,this.VP.point1Price,this.TC.gt,this.TC.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.DP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.VP.levelColors?.[e.toString()]||this.VP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.VP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.VP.showLabels){const s=`${n.label??n.Jl} ${this.LP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.VP.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.VP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.WC(t,n,e,i),t.globalAlpha=.6,this.WC(t,r,h,i),t.globalAlpha=1}WC(t,i,s,n){const e=this.VP.lineColor,r=this.wC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.wC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}EP(){this.np=t=>{this.BP(t)},this._chart.subscribeCrosshairMove(this.np)}OP(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}BP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.wC||!this.bC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.IP?(this.VP.point1Time=i,this.VP.point1Price=s):"point2"===this.IP&&(this.VP.point2Time=i,this.VP.point2Price=s),this.AP(),this.dM())}startDrag(t){this.bC=!0,this.IP=t}stopDrag(){this.bC=!1,this.IP=null}updateDrag(t,i){this.bC&&this.IP&&("point1"===this.IP?(this.VP.point1Time=t,this.VP.point1Price=i):(this.VP.point2Time=t,this.VP.point2Price=i),this.AP(),this.dM())}hitTestEndpoint(t,i){if(!this.CC||!this.VP.point1Time||!this.VP.point2Time)return null;const s=Xn(this._chart,this._series,this.VP.point1Time)??0,n=this._series.priceToCoordinate(this.VP.point1Price)??0,e=Xn(this._chart,this._series,this.VP.point2Time)??0,r=this._series.priceToCoordinate(this.VP.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.VP={...this.VP,...t},void 0!==t.levels&&t.levels.length>0?this.LP.updateRatios(t.levels.map(fl)):void 0!==t.useExtended&&(t.useExtended?this.LP.useExtendedRatios():this.LP.useStandardRatios()),super.applyOptions(t),this.AP(),this.dM()}options(){return{...this.VP,levels:this.LP.getRatioValues()}}setColor(t){this.VP.lineColor=t,this.dM()}color(){return this.VP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}isSelected(){return this.wC}FC(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.CC||!this.VP.point1Time||!this.VP.point2Time)return!1;const s=Xn(this._chart,this._series,this.VP.point1Time)??0,n=Xn(this._chart,this._series,this.VP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Xb)return!1;for(const t of this.Xb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.CC}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.FP&&(this.FP.m(),this.FP=null),this.OP(),this.VP.onRemove&&this.VP.onRemove()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.VP.onRemove&&this.VP.onRemove()}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.AP(),this.dM()}}function ml(t,i){return new vl(t,i)}class wl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class gl{constructor(t){this.vC=t,this.Jt=new wl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}}class bl extends Dh{constructor(t,i){super(t,"fibonacci-extension",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.VP={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.$y()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new gl(this)}getPoint1(){return this.VP.point1}getPoint2(){return this.VP.point2}getPoint3(){return this.VP.point3}getLevels(){return this.VP.levels||[]}getOptions(){return this.VP}setPoint1(t){this.VP.point1=t,this.dM()}setPoint2(t){this.VP.point2=t,this.dM()}setPoint3(t){this.VP.point3=t,this.dM()}isComplete(){return!!(this.VP.point1&&this.VP.point2&&this.VP.point3)}setColor(t){this.VP.lineColor=t,this.dM()}color(){return this.VP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.VP.point1,this.VP.point2,this.VP.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.WP();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.VP.point1,n=this.VP.point2,e=this.VP.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.bC=!0,this.MC=t}stopDrag(){this.bC=!1,this.MC=null}updateDrag(t,i){if(!this.bC||!this.MC)return;const s={time:t,price:i};switch(this.MC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.VP.onUpdate&&this.VP.onUpdate()}WP(){if(!this.isComplete())return[];const t=this.VP.point1,i=this.VP.point2,s=this.VP.point3,n=i.price-t.price;return(this.VP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.WP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.VP.point1,e=this.VP.point2,r=this.VP.point3,h=this.wC||this.gC&&!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.VP.lineColor||"#787B86",t.lineWidth=(this.VP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.VP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.VP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.VP.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Jl:"A"},{ut:a,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[Ph(this.VP.point1),Ph(this.VP.point2),Ph(this.VP.point3)],style:{lineColor:this.VP.lineColor,lineWidth:this.VP.lineWidth,showLabels:this.VP.showLabels,extendLines:this.VP.extendLines},extra:{levels:(this.VP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null)}}function Ml(t,i){return new bl(t,i)}class yl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Sl{constructor(t){this.vC=t,this.Jt=new yl(t)}renderer(){return this.vC.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.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.zP=!1,this.jS=null,this.np=null,this.TC=null,this.$P={levels:xl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.$y(),this.$P.interactive&&!this.$P.point1Time&&this.DC()}DC(){this.zP=!0,this.jS=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.$P.point1Time?(this.$P.point2Time=i,this.$P.point2Price=s,this.zP=!1,this.TC=null,this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.$P.onUpdate&&this.$P.onUpdate()):(this.$P.point1Time=i,this.$P.point1Price=s,this.dM()))},this.np=t=>{if(this.zP&&this.$P.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.TC={gt:i,bt:s},this.dM())}else this.TC=null,this.dM()},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.np)}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new Sl(this)}drawToCanvas(t,i,s){const n=this.$P.point1Time,e=this.$P.point1Price,r=this.zP&&this.TC?this.TC.gt:this.$P.point2Time,h=this.zP&&this.TC?this.TC.bt:this.$P.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.wC?this.$P.lineWidth+1:this.$P.lineWidth;if(this.HP(t,l,o,a,_,"#2962FF",u*i),this.$P.levels)for(const n of this.$P.levels)this.NP(t,l,o,a,_,n,i,s,undefined,u);!this.wC&&!this.gC||this.zP||this.isLocked()||(this.WC(t,l,o,i,"#2962ff"),this.WC(t,a,_,i,"#2962ff"))}NP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.$P.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.HP(t,i,s,c,d,p,a*h),this.$P.showLabels&&!this.zP&&this.UC(t,_,u,r.label,h,p)}HP(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()}WC(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()}UC(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.$P.levels??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.$P.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.$P.point1Time||!this.$P.point2Time)return!1;const s=Xn(this._chart,this._series,this.$P.point1Time)??0,n=this._series.priceToCoordinate(this.$P.point1Price)??0,e=Xn(this._chart,this._series,this.$P.point2Time)??0,r=this._series.priceToCoordinate(this.$P.point2Price)??0;if(this.zC(t,i,s,n,e,r)<=8)return!0;if(this.$P.levels)for(const h of this.$P.levels){const l=n+(r-n)*h.level,o=e;if(this.zC(t,i,s,n,o,l)<=8)return!0}return!1}zC(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.$P.point1Time||!this.$P.point2Time)return null;const s=Xn(this._chart,this._series,this.$P.point1Time)??0,n=this._series.priceToCoordinate(this.$P.point1Price)??0,e=Xn(this._chart,this._series,this.$P.point2Time)??0,r=this._series.priceToCoordinate(this.$P.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.bC=!0,this.MC=t}stopDrag(){this.bC=!1,this.MC=null}updateDrag(t,i){this.bC&&this.MC&&("point1"===this.MC?(this.$P.point1Time=t,this.$P.point1Price=i):"point2"===this.MC&&(this.$P.point2Time=t,this.$P.point2Price=i),this.dM(),this.$P.onUpdate&&this.$P.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Ch(this.$P.point1Price??0,xh(this.$P.point1Time)),Ch(this.$P.point2Price??0,xh(this.$P.point2Time))],style:{lineWidth:this.$P.lineWidth,showLabels:this.$P.showLabels,extendLines:this.$P.extendLines},extra:{levels:(this.$P.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return!this.zP}remove(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.$P.onRemove&&this.$P.onRemove()}}function Pl(t,i){return new Cl(t,i)}class Tl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.vC=t,this.Jt=new Tl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Dl extends Dh{constructor(t,i){super(t,"rectangle",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.SC=null,this.xC=null,this.zP=!1,this.jS=null,this.np=null,this.TC=null,this.UP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.UP),this.$y(),!this.UP.interactive||this.UP.time1&&this.UP.time2||this.DC()}DC(){this.zP=!0,this.jS=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.UP.time1?(this.UP.time2=i,this.UP.price2=s,this.zP=!1,this.TC=null,this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.UP.onUpdate&&this.UP.onUpdate()):(this.UP.time1=i,this.UP.price1=s,this.dM()))},this.np=t=>{if(this.zP&&this.UP.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.TC={gt:i,bt:s},this.dM())}else this.TC=null,this.dM()},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.np)}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new kl(this)}drawToCanvas(t,i,s){const n=this.UP.time1,e=this.UP.price1,r=this.zP&&this.TC?this.TC.gt:this.UP.time2,h=this.zP&&this.TC?this.TC.bt:this.UP.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.UP.fillOpacity>0){const i=this.Wy(this.UP.fillColor,this.zP?.1:this.UP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.UP.borderColor,w=this.wC?this.UP.borderWidth+1:this.UP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.UP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.UP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.wC&&!this.gC||this.zP||this.isLocked()||this.qP(t,u,d,c,p,i,m),this.UP.showLabel&&this.UP.labelText&&!this.zP&&this.UC(t,u,d,c,p,i,s,m)}qP(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)}UC(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.UP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.UP.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.UP.labelText,c+o,d+o)}Wy(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.UP.borderColor=t,this.UP.fillColor=t,this.dM()}color(){return this.UP.borderColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.UP.time1||!this.UP.time2)return!1;const s=Xn(this._chart,this._series,this.UP.time1)??0,n=this._series.priceToCoordinate(this.UP.price1)??0,e=Xn(this._chart,this._series,this.UP.time2)??0,r=this._series.priceToCoordinate(this.UP.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.UP.time1||!this.UP.time2)return null;const s=Xn(this._chart,this._series,this.UP.time1)??0,n=this._series.priceToCoordinate(this.UP.price1)??0,e=Xn(this._chart,this._series,this.UP.time2)??0,r=this._series.priceToCoordinate(this.UP.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.bC=!0,this.MC=t,this.yC=i,"body"===t&&(this.SC={gt:this.UP.time1,bt:this.UP.price1},this.xC={gt:this.UP.time2,bt:this.UP.price2})}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.SC=null,this.xC=null}updateDrag(t,i){if(!this.bC||!this.MC)return;const s=Xn(this._chart,this._series,this.UP.time1)??0,n=this._series.priceToCoordinate(this.UP.price1)??0,e=s<(Xn(this._chart,this._series,this.UP.time2)??0),r=n<(this._series.priceToCoordinate(this.UP.price2)??0);if("body"===this.MC&&this.SC&&this.xC){const s=yh(this.yC,t,i);this.UP.time1=this.SC.gt+s.gt,this.UP.price1=this.SC.bt+s.bt,this.UP.time2=this.xC.gt+s.gt,this.UP.price2=this.xC.bt+s.bt}else switch(this.MC){case"corner1":e&&r?(this.UP.time1=t,this.UP.price1=i):!e&&r?(this.UP.time2=t,this.UP.price1=i):e&&!r?(this.UP.time1=t,this.UP.price2=i):(this.UP.time2=t,this.UP.price2=i);break;case"corner2":e&&r?(this.UP.time2=t,this.UP.price1=i):!e&&r?(this.UP.time1=t,this.UP.price1=i):e&&!r?(this.UP.time2=t,this.UP.price2=i):(this.UP.time1=t,this.UP.price2=i);break;case"corner3":e&&r?(this.UP.time1=t,this.UP.price2=i):!e&&r?(this.UP.time2=t,this.UP.price2=i):e&&!r?(this.UP.time1=t,this.UP.price1=i):(this.UP.time2=t,this.UP.price1=i);break;case"corner4":e&&r?(this.UP.time2=t,this.UP.price2=i):!e&&r?(this.UP.time1=t,this.UP.price2=i):e&&!r?(this.UP.time2=t,this.UP.price1=i):(this.UP.time1=t,this.UP.price1=i)}this.dM(),this.UP.onUpdate&&this.UP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Ch(this.UP.price1??0,xh(this.UP.time1)),Ch(this.UP.price2??0,xh(this.UP.time2))],style:{fillColor:this.UP.fillColor,fillOpacity:this.UP.fillOpacity,borderColor:this.UP.borderColor,borderWidth:this.UP.borderWidth,borderStyle:this.UP.borderStyle,showLabel:this.UP.showLabel,labelText:this.UP.labelText,labelPosition:this.UP.labelPosition}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return!this.zP}remove(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.UP.onRemove&&this.UP.onRemove()}}function Rl(t,i){return new Dl(t,i)}class Fl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Il{constructor(t){this.vC=t,this.Jt=new Fl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Vl extends Dh{constructor(t,i){super(t,"circle",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.lP=null,this.zP=!1,this.jS=null,this.np=null,this.TC=null,this.jP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.jP),this.$y(),this.jP.interactive&&!this.jP.centerTime&&this.DC()}DC(){this.zP=!0,this.jS=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.jP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.jP.centerTime)??0,n=this._series.priceToCoordinate(this.jP.centerPrice)??0,e=Xn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.jP.radiusTime=Math.abs(e-t),this.jP.radiusPrice=Math.abs(r-n),this.zP=!1,this.TC=null,this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.dM(),this.jP.onUpdate&&this.jP.onUpdate()}else this.jP.centerTime=i,this.jP.centerPrice=s,this.dM()},this.np=t=>{if(this.zP&&this.jP.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.TC={gt:i,bt:s},this.dM())}else this.TC=null,this.dM()},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.np)}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new Il(this)}drawToCanvas(t,i,s){if(!this.jP.centerTime||void 0===this.jP.centerPrice)return;const n=(Xn(this._chart,this._series,this.jP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.jP.centerPrice)??0)*s;let r,h;if(this.zP&&this.TC){const t=(Xn(this._chart,this._series,this.TC.gt)??0)*i,l=(this._series.priceToCoordinate(this.TC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.jP.radiusTime||void 0===this.jP.radiusPrice)return;r=this.jP.radiusTime*i,h=this.jP.radiusPrice*s}if(this.jP.fillOpacity>0){const i=this.Wy(this.jP.fillColor,this.zP?.05:this.jP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.jP.borderColor,o=this.wC?this.jP.borderWidth+1:this.jP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.jP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.jP.borderStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.stroke(),t.setLineDash([]),!this.wC&&!this.gC||this.zP||this.isLocked()||this.YP(t,n,e,i,l),!this.wC&&!this.gC||this.zP||this.isLocked()||this.XP(t,n,e,r,h,i,l),this.jP.showLabel&&this.jP.labelText&&!this.zP&&this.UC(t,n,e,i,l)}YP(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()}XP(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)}UC(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.jP.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.jP.labelText,a+r,_+r)}Wy(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.jP.borderColor=t,this.jP.fillColor=t,this.dM()}color(){return this.jP.borderColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.jP.centerTime||void 0===this.jP.radiusTime)return!1;const s=Xn(this._chart,this._series,this.jP.centerTime)??0,n=this._series.priceToCoordinate(this.jP.centerPrice)??0,e=(t-s)/this.jP.radiusTime,r=(i-n)/this.jP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.jP.centerTime||void 0===this.jP.radiusTime)return null;const s=Xn(this._chart,this._series,this.jP.centerTime)??0,n=this._series.priceToCoordinate(this.jP.centerPrice)??0,e=this.jP.radiusTime,r=this.jP.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.bC=!0,this.MC=t,this.yC=i,this.lP="center"===t?{gt:this.jP.centerTime,bt:this.jP.centerPrice}:null}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.lP=null}updateDrag(t,i){if(this.bC&&this.MC){if("center"===this.MC&&this.lP){const s=yh(this.yC,t,i);this.jP.centerTime=this.lP.gt+s.gt,this.jP.centerPrice=this.lP.bt+s.bt}else if("edge"===this.MC){const s=Xn(this._chart,this._series,this.jP.centerTime)??0,n=this._series.priceToCoordinate(this.jP.centerPrice)??0,e=Xn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.jP.radiusTime=Math.abs(e-s),this.jP.radiusPrice=Math.abs(r-n)}this.dM(),this.jP.onUpdate&&this.jP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Ch(this.jP.centerPrice??0,xh(this.jP.centerTime))],style:{fillColor:this.jP.fillColor,fillOpacity:this.jP.fillOpacity,borderColor:this.jP.borderColor,borderWidth:this.jP.borderWidth,borderStyle:this.jP.borderStyle,showLabel:this.jP.showLabel,labelText:this.jP.labelText},extra:{radiusTime:this.jP.radiusTime,radiusPrice:this.jP.radiusPrice}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return!this.zP}remove(){this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.jP.onRemove&&this.jP.onRemove()}}function Ll(t,i){return new Vl(t,i)}class Al{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.vC=t,this.Jt=new Al(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Bl extends Dh{constructor(t,i){super(t,"arrow",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.GP=-1,this.zP=!1,this.jS=null,this.KP=null,this.np=null,this.TC=null,this.ZP={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.ZP),this.$y(),!this.ZP.interactive||this.ZP.points&&0!==this.ZP.points.length||this.DC()}DC(){this.zP=!0,this.jS=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.points||(this.ZP.points=[]),this.ZP.points.push({time:i,price:s}),this.dM(),this.ZP.onUpdate&&this.ZP.onUpdate())},this.np=t=>{if(this.zP)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.TC={gt:i,bt:s},this.dM())}else this.TC=null,this.dM()},this.KP=t=>{this.zP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.jS),this._chart.subscribeCrosshairMove(this.np);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.KP)}finishDrawing(){if(this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.KP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.KP),this.KP=null}this.zP=!1,this.TC=null,this.dM(),this.ZP.onComplete&&this.ZP.onComplete()}isDrawing(){return this.zP}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new El(this)}drawToCanvas(t,i,s){if(!this.ZP.points||0===this.ZP.points.length)return;const n=this.ZP.lineColor,e=this.wC||this.gC&&!this.isLocked()?this.ZP.lineWidth+1:this.ZP.lineWidth,r=[];for(const t of this.ZP.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.zP)return;let h=null;if(this.zP&&this.TC&&this.ZP.points.length>0){h={ut:(Xn(this._chart,this._series,this.TC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.TC.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.ZP.showArrowHead&&r.length>1&&this.JP(t,r[r.length-2],r[r.length-1],i,n),this.ZP.showCircles)for(let s=0;s<r.length;s++)this.QP(t,r[s].ut,r[s].ct,i,n,0===s)}JP(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()}QP(t,i,s,n,e,r){const h=this.ZP.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.ZP.lineColor=t,this.dM()}color(){return this.ZP.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.points||0===this.ZP.points.length)return!1;for(let s=0;s<this.ZP.points.length-1;s++)try{const n=this.ZP.points[s],e=this.ZP.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.zC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.ZP.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}zC(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.points||0===this.ZP.points.length)return null;for(let s=0;s<this.ZP.points.length;s++)try{const n=this.ZP.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.bC=!0,this.GP=t}stopDrag(){this.bC=!1,this.GP=-1}updateDrag(t,i){this.bC&&-1!==this.GP&&this.ZP.points&&this.GP>=0&&this.GP<this.ZP.points.length&&(this.ZP.points[this.GP]={time:t,price:i},this.dM(),this.ZP.onUpdate&&this.ZP.onUpdate())}getPoints(){return this.ZP.points||[]}addPoint(t){this.ZP.points||(this.ZP.points=[]),this.ZP.points.push(t),this.dM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.ZP.points||[]).map(t=>Ph(t)),style:{lineColor:this.ZP.lineColor,lineWidth:this.ZP.lineWidth,showArrowHead:this.ZP.showArrowHead,showCircles:this.ZP.showCircles,circleRadius:this.ZP.circleRadius}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return!this.zP}remove(){if(this.jS&&(this._chart.unsubscribeClick(this.jS),this.jS=null),this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null),this.KP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.KP),this.KP=null}this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.ZP.onRemove&&this.ZP.onRemove()}}function Ol(t,i){return new Bl(t,i)}class Wl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class zl{constructor(t){this.vC=t,this.Jt=new Wl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class $l extends Dh{constructor(t,i){super(t,"brush",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.tT=!1,this.zP=!1,this.iT=[],this.sT=!1,this.Df=null,this.uS=null,this.wS=null,this.bS=null,this.yS=null,this.nT=void 0,this.vS=null,this.bC=!1,this.yC=null,this.XC=null,this.eT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.eT),this.$y(),0===(this.eT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.tT)return;const t=this._chart.chartElement();t&&(this.Df=t,this.tT=!0,this.wS=t=>this.gS(t),this.bS=t=>this.MS(t),this.yS=()=>this.SS(),this.vS=t=>{this.nT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.vS),t.addEventListener("pointerdown",this.wS,!0),t.addEventListener("pointermove",this.bS,!0),t.addEventListener("pointerup",this.yS,!0),t.addEventListener("pointercancel",this.yS,!0))}stopDrawingMode(){if(!this.tT)return;this.rT(),this.tT=!1;const t=this.Df;t&&(this.wS&&t.removeEventListener("pointerdown",this.wS,!0),this.bS&&t.removeEventListener("pointermove",this.bS,!0),this.yS&&(t.removeEventListener("pointerup",this.yS,!0),t.removeEventListener("pointercancel",this.yS,!0))),this.vS&&(this._chart.unsubscribeCrosshairMove(this.vS),this.vS=null),this.wS=null,this.bS=null,this.yS=null,this.Df=null}isDrawingModeActive(){return this.tT}gS(t){if(this.hT())return;const i=this.lT(t,!1);null!==i&&(this.zP=!0,this.iT=[i],this.uS=t.pointerId,Fh(this._chart,!0),this.Df?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.oT())}MS(t){if(!this.zP)return;const i=this.lT(t,!0);if(null===i)return;const s=this.iT[this.iT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.eT.sampleDistance??4)||(this.iT.push(i),t.preventDefault(),t.stopPropagation(),this.oT())}SS(){this.zP&&this.rT()}rT(){if(!this.zP)return;this.zP=!1,this.BS();const t=[];for(const i of this.iT){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.iT=[],t.length<2?this.dM():(this.eT.points=t,this.stopDrawingMode(),this.dM(),this.eT.onUpdate&&this.eT.onUpdate(),this.eT.onComplete&&this.eT.onComplete())}hT(){const t=this.nT;return"string"==typeof t&&t.split("#")[0]!==this.id}BS(){null!==this.uS&&(this.Df&&this.Df.hasPointerCapture(this.uS)&&this.Df.releasePointerCapture(this.uS),this.uS=null)}lT(t,i){const s=this.aT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Tx;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}aT(){const t=this._T();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,Tx:i.top,ts:n,qt:i.height}}_T(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}oT(){this.sT||(this.sT=!0,requestAnimationFrame(()=>{this.sT=!1,this.dM()}))}drawToCanvas(t,i,s){const n=this.zP?this.iT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.uT(i,s);if(0===n.length)return;const e=this.wC;if(t.strokeStyle=this.eT.color,t.lineWidth=(this.eT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.eT.smoothing&&n.length>2){for(let i=1;i<n.length-1;i++){const s=(n[i].ut+n[i+1].ut)/2,e=(n[i].ct+n[i+1].ct)/2;t.quadraticCurveTo(n[i].ut,n[i].ct,s,e)}t.lineTo(n[n.length-1].ut,n[n.length-1].ct)}else for(let i=1;i<n.length;i++)t.lineTo(n[i].ut,n[i].ct);t.stroke(),!e&&!this.gC||this.isLocked()||(this.WC(t,n[0],i),this.WC(t,n[n.length-1],i))}WC(t,i,s){t.fillStyle=this.eT.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()}uT(t,i){const s=this.eT.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.uT(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.bC=!0,this.yC=i,this.XC=(this.eT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.XC;if(!this.bC||null===s||!this.eT.points)return;const n=yh(this.yC,t,i);this.eT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.dM(),this.eT.onUpdate&&this.eT.onUpdate()}stopDrag(){this.bC=!1,this.yC=null,this.XC=null}setColor(t){this.eT.color=t,this.dM()}color(){return this.eT.color??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}$y(){this.eh=new zl(this);const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}FC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Mh(this.id,s,!this.isLocked()):null}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.stopDrawingMode(),this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null),this.eh=null,this.eT.onRemove&&this.eT.onRemove()}_serializeShape(){return{type:"brush",points:(this.eT.points??[]).map(Ph),style:{color:this.eT.color,lineWidth:this.eT.lineWidth,smoothing:this.eT.smoothing}}}getPoints(){return this.eT.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.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ql{constructor(t){this.vC=t,this.Jt=new Ul(t)}renderer(){return this.vC.isComplete()?this.Jt:null}}class jl extends Dh{constructor(t,i){super(t,"text-tool",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.lP=null,this.cT=!1,this.dT=null,this.pT={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.pT),this.$y(),this.fT()}fT(){const t=t=>{if(!this.cT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.pT.text&&""!==this.pT.text.trim()&&"Type here..."!==this.pT.text||this.remove())};this.dT=t,this._chart.subscribeClick(t)}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new ql(this)}getTime(){return this.pT.time}getPrice(){return this.pT.price}getText(){return this.pT.text||""}getOptions(){return this.pT}setPosition(t,i){this.pT.time=t,this.pT.price=i,this._update()}setText(t){this.pT.text=t,this._update(),this.pT.onTextChange&&this.pT.onTextChange(t)}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}isComplete(){return!(!this.pT.time||void 0===this.pT.price)}setColor(t){this.pT.textColor=t,this.pT.borderColor=t,this.dM()}color(){return this.pT.textColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this._update())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this._update())}isHovered(){return this.gC}setEditing(t){this.cT!==t&&(this.cT=t,this._update())}isEditing(){return this.cT}FC(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.pT.time,n=this.pT.price,e=Xn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.pT.fontSize||14,l=this.pT.padding||8,o=this.pT.text||"",a=.6*h,_=Math.min(o.length*a,this.pT.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.pT.time,n=this.pT.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.bC=!0,this.MC=t,this.yC=i,this.lP={gt:this.pT.time,bt:this.pT.price}}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.lP=null}updateDrag(t,i){if(this.bC){if("body"===this.MC&&this.lP){const s=yh(this.yC,t,i);this.setPosition(this.lP.gt+s.gt,this.lP.bt+s.bt)}else this.setPosition(t,i);this.pT.onUpdate&&this.pT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.pT.time,e=this.pT.price,r=this.pT.text||"",h=(Xn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.pT.fontSize||14)*i,a=(this.pT.padding||8)*i,_=(this.pT.maxWidth||200)*i;t.font=`${o}px ${this.pT.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.pT.backgroundOpacity||.8,g=this.pT.backgroundColor||"#2962FF";t.fillStyle=this.Wy(g,w),t.fillRect(h,l,f,m),(this.wC||this.gC)&&(t.strokeStyle=this.pT.borderColor??"#FFFFFF",t.lineWidth=(this.pT.borderWidth||1)*i*(this.wC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.pT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.pT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.pT.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.wC||this.gC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.pT.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()}}Wy(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.pT.price??0,xh(this.pT.time))],style:{fontSize:this.pT.fontSize,fontFamily:this.pT.fontFamily,textColor:this.pT.textColor,backgroundColor:this.pT.backgroundColor,backgroundOpacity:this.pT.backgroundOpacity,padding:this.pT.padding,borderColor:this.pT.borderColor,borderWidth:this.pT.borderWidth,textAlign:this.pT.textAlign,maxWidth:this.pT.maxWidth},extra:{text:this.pT.text}}}remove(){this.dT&&(this._chart.unsubscribeClick(this.dT),this.dT=null),this.qb&&this._series&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.pT.onRemove&&this.pT.onRemove()}}function Yl(t,i){return new jl(t,i)}class Xl{constructor(t){this.vT=t}calculatePips(t,i){return Math.abs(i-t)/this.vT.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.vT={...this.vT,...t}}getPipConfig(){return{...this.vT}}}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.vT=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.vT.pipValue,timeDifference:this.mT(t,s),barCount:e}}mT(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.vT={...this.vT,...t}}getPipConfig(){return{...this.vT}}}class Jl{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ql{constructor(t){this.vC=t,this.Jt=new Jl(t)}renderer(){return this.vC.isVisible()?this.Jt:null}}class to extends Dh{constructor(t,i){super(t,"ruler-tool",i),this.qb=null,this.mC=null,this.Xb=null,this.eh=null,this.FP=null,this.CC=!1,this.wC=!1,this.gC=!1,this.TC=null,this.bC=!1,this.IP=null,this.np=null,this.wT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.wT);const s=this.wT.pipConfig||Kl(this.wT.symbol||"DEFAULT");this.LP=new Zl(s),this.$y(),this.wT.interactive?this.DC():this.wT.point1Time&&this.wT.point2Time&&(this.CC=!0,this.AP())}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new Ql(this)}DC(){this.FP=new Ah(this._chart,this._series,{cC:t=>{this.wT.point1Time=t.gt,this.wT.point1Price=t.bt,this.dM()},dC:t=>{this.wT.point2Time=t.gt,this.wT.point2Price=t.bt},pC:(t,i)=>{this.wT.point1Time=t.gt,this.wT.point1Price=t.bt,this.wT.point2Time=i.gt,this.wT.point2Price=i.bt,this.CC=!0,this.TC=null,this.AP(),this.EP(),this.dM()},fC:t=>{this.TC=t,this.dM()}}),this.FP.iC()}drawToCanvas(t,i,s){if(!this.CC&&this.wT.point1Time&&this.TC)return void this.OC(t,i,s);if(!this.CC||!this.wT.point1Time||!this.wT.point2Time)return;const n=(Xn(this._chart,this._series,this.wT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.wT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.wT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.wT.point2Price)??0)*s;(this.wC||this.gC&&!this.isLocked())&&(t.strokeStyle=this.wT.selectionColor,t.lineWidth=this.wT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.wT.lineColor,t.lineWidth=this.wT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.gT(t,n,e,r,h,i),this.WC(t,n,e,i),this.WC(t,r,h,i),this.wT.showLabel&&this.Xb&&this.UC(t,n,e,r,h,i,s)}gT(t,i,s,n,e,r){const h=this.wT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.wT.lineColor,t.lineWidth=this.wT.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()}WC(t,i,s,n){const e=this.wC?this.wT.selectionColor:this.wT.lineColor,r=this.wC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.wC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}OC(t,i,s){if(!this.wT.point1Time||!this.TC)return;const n=(Xn(this._chart,this._series,this.wT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.wT.point1Price)??0)*s,r=(Xn(this._chart,this._series,this.TC.gt)??0)*i,h=(this._series.priceToCoordinate(this.TC.bt)??0)*s;t.strokeStyle=this.wT.lineColor,t.lineWidth=this.wT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.WC(t,n,e,i),t.globalAlpha=.5,this.WC(t,r,h,i),t.globalAlpha=1}UC(t,i,s,n,e,r,h){if(!this.Xb)return;const l=(i+n)/2,o=(s+e)/2,a=this.wT.measure??"both",_=[];"time"!==a&&(_.push(this.LP.formatPips(this.Xb.pips)),_.push(this.LP.formatPercent(this.Xb.pricePercent))),"price"!==a&&_.push(this.LP.formatBarCount(this.Xb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.wT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.wT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}AP(){if(!this.wT.point1Time||!this.wT.point2Time||void 0===this.wT.point1Price||void 0===this.wT.point2Price)return;const t=this.bT();this.Xb=this.LP.calculateMetrics(this.wT.point1Time,this.wT.point1Price,this.wT.point2Time,this.wT.point2Price,t),this.wT.onUpdate&&this.Xb&&this.wT.onUpdate(this.Xb)}bT(){if(!this.wT.point1Time||!this.wT.point2Time)return 0;const t=Xn(this._chart,this._series,this.wT.point1Time),i=Xn(this._chart,this._series,this.wT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.wT.point1Time=t,this.wT.point1Price=i,this.wT.point2Time=s,this.wT.point2Price=n,this.AP(),this.dM()}getMetrics(){return this.Xb}remove(){this.destroy()}destroy(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.FP&&(this.FP.m(),this.FP=null),this.OP(),this.wT.onRemove&&this.wT.onRemove()}EP(){this.np=t=>{this.BP(t)},this._chart.subscribeCrosshairMove(this.np)}OP(){this.np&&(this._chart.unsubscribeCrosshairMove(this.np),this.np=null)}BP(t){if(!t.point)return;const i=Yn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.wC||!this.bC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.IP?(this.wT.point1Time=i,this.wT.point1Price=s):"point2"===this.IP&&(this.wT.point2Time=i,this.wT.point2Price=s),this.AP(),this.dM())}startDrag(t){this.bC=!0,this.IP=t}stopDrag(){this.bC=!1,this.IP=null}updateDrag(t,i){this.bC&&this.IP&&("point1"===this.IP?(this.wT.point1Time=t,this.wT.point1Price=i):(this.wT.point2Time=t,this.wT.point2Price=i),this.AP(),this.dM())}hitTestEndpoint(t,i){if(!this.CC||!this.wT.point1Time||!this.wT.point2Time)return null;const s=Xn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Xn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.AP(),this.dM()}_serializeShape(){return{type:"ruler",points:[Ch(this.wT.point1Price??0,xh(this.wT.point1Time)),Ch(this.wT.point2Price??0,xh(this.wT.point2Time))],style:{lineColor:this.wT.lineColor,lineWidth:this.wT.lineWidth,showLabel:this.wT.showLabel,labelBackgroundColor:this.wT.labelBackgroundColor,labelTextColor:this.wT.labelTextColor,selectionColor:this.wT.selectionColor,selectionLineWidth:this.wT.selectionLineWidth},extra:{symbol:this.wT.symbol,pipConfig:this.wT.pipConfig,measure:this.wT.measure}}}setColor(t){this.wT.lineColor=t,this.dM()}color(){return this.wT.lineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}isSelected(){return this.wC}isComplete(){return this.CC}FC(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.CC||!this.wT.point1Time||!this.wT.point2Time)return!1;const s=Xn(this._chart,this._series,this.wT.point1Time)??0,n=this._series.priceToCoordinate(this.wT.point1Price)??0,e=Xn(this._chart,this._series,this.wT.point2Time)??0,r=this._series.priceToCoordinate(this.wT.point2Price)??0;return this.MT(t,i,s,n,e,r)<=(this.wC?12:8)}MT(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.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class no{constructor(t){this.vC=t,this.Jt=new so(t)}renderer(){return this.vC.isVisible()?this.Jt:null}}class eo extends Dh{constructor(t,i){super(t,"position-tool",i),this.qb=null,this.mC=null,this.Xb=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.MC=null,this.yC=null,this.lP=null,this.yT=null,this.ST=null,this.xT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.xT);const s=this.xT.pipConfig||Kl(this.xT.entryPrice);this.LP=new Xl(s),this.$y(),this.AP()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new no(this)}drawToCanvas(t,i,s){if(this.yT&&this.xT.takeProfit){const n=this._chart.timeScale();this.CT(t,this.yT,i,s,n),(this.gC||this.wC)&&this.UC(t,this.yT,"profit",i,s,n)}if(this.ST&&this.xT.stopLoss){const n=this._chart.timeScale();if(this.CT(t,this.ST,i,s,n),this.gC||this.wC){const n=this._chart.timeScale();this.UC(t,this.ST,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.PT(t,i,s,n),this.xT.takeProfit){const n=this._chart.timeScale();this.WC(t,this.xT.takeProfit,this.xT.profitColor,i,s,n)}if(this.xT.stopLoss){const n=this._chart.timeScale();this.WC(t,this.xT.stopLoss,this.xT.lossColor,i,s,n)}}CT(t,i,s,n,e){const r=(Xn(this._chart,this._series,this.xT.entryTime)??0)*s;let h;if(this.xT.endTime)h=(Xn(this._chart,this._series,this.xT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.TT)??0)*n,o=(this._series.priceToCoordinate(i.kT)??0)*n;t.fillStyle=this.Wy(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()}PT(t,i,s,n){const e=(Xn(this._chart,this._series,this.xT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.xT.entryPrice)??0)*s;let h;if(this.xT.endTime)h=(Xn(this._chart,this._series,this.xT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.xT.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.xT.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.wC&&!this.gC||this.isLocked())t.fillStyle=this.xT.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)}}AP(){this.xT.stopLoss&&this.xT.takeProfit&&(this.Xb=this.LP.calculateMetrics(this.xT.entryPrice,this.xT.stopLoss,this.xT.takeProfit,this.xT.quantity),this.DT(),this.xT.onUpdate&&this.Xb&&this.xT.onUpdate(this.Xb))}DT(){const t=this.RT();this.xT.takeProfit&&(this.yT={FT:this.xT.entryTime,IT:t,TT:this.xT.entryPrice,kT:this.xT.takeProfit,R:this.xT.profitColor,Dy:this.xT.opacity}),this.xT.stopLoss&&(this.ST={FT:this.xT.entryTime,IT:t,TT:this.xT.entryPrice,kT:this.xT.stopLoss,R:this.xT.lossColor,Dy:this.xT.opacity})}RT(){this._chart.timeScale().getVisibleLogicalRange();return this.xT.entryTime}UC(t,i,s,n,e,r){if(!this.Xb)return;const h=(Xn(this._chart,this._series,this.xT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.kT)??0)*e,o="profit"===s,a=o?this.Xb.takeProfitPips:this.Xb.stopLossPips,_=o?this.xT.takeProfit:this.xT.stopLoss,u=this.Xb.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)}WC(t,i,s,n,e,r){const h=(Xn(this._chart,this._series,this.xT.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.xT.endTime)a=(Xn(this._chart,this._series,this.xT.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,_,_)}Wy(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.xT={...this.xT,...t},this.AP(),this._update()}getMetrics(){return this.Xb}setStopLoss(t){this.xT.stopLoss=t,this.AP(),this._update()}setTakeProfit(t){this.xT.takeProfit=t,this.AP(),this._update()}setEntryPrice(t){this.xT.entryPrice=t,this.AP(),this._update()}_serializeShape(){return{type:"position",points:[Ch(this.xT.entryPrice,xh(this.xT.entryTime))],style:{profitColor:this.xT.profitColor,lossColor:this.xT.lossColor,entryLineColor:this.xT.entryLineColor,opacity:this.xT.opacity,showTooltips:this.xT.showTooltips},extra:{endTime:xh(this.xT.endTime),stopLoss:this.xT.stopLoss,takeProfit:this.xT.takeProfit,quantity:this.xT.quantity,pipConfig:this.xT.pipConfig}}}setColor(t){this.xT.entryLineColor=t,this.dM()}color(){return this.xT.entryLineColor??""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.xT.stopLoss&&!this.xT.takeProfit)return!1;const s=Xn(this._chart,this._series,this.xT.entryTime)??0;let n;if(this.xT.endTime)n=Xn(this._chart,this._series,this.xT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.xT.takeProfit&&this.xT.stopLoss){const e=this._series.priceToCoordinate(this.xT.takeProfit)??0,r=this._series.priceToCoordinate(this.xT.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.xT.entryTime)??0;let n;if(this.xT.endTime)n=Xn(this._chart,this._series,this.xT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.xT.takeProfit){const n=this._series.priceToCoordinate(this.xT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.xT.stopLoss){const n=this._series.priceToCoordinate(this.xT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.xT.takeProfit){const s=this._series.priceToCoordinate(this.xT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.xT.stopLoss){const s=this._series.priceToCoordinate(this.xT.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.xT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.xT.takeProfit&&this.xT.stopLoss){const e=this._series.priceToCoordinate(this.xT.takeProfit)??0,r=this._series.priceToCoordinate(this.xT.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.bC=!0,this.MC=t,this.yC=i,"move"===t&&(this.lP={VT:this.xT.entryPrice,LT:this.xT.entryTime??null,Oy:this.xT.endTime??null,AT:this.xT.takeProfit??null,ET:this.xT.stopLoss??null})}stopDrag(){this.bC=!1,this.MC=null,this.yC=null,this.lP=null}updateDrag(t,i){if(this.bC&&this.MC){if("entry"===this.MC)this.xT.entryPrice=i;else if("move"===this.MC){if(this.lP){const s=yh(this.yC,t,i),n=this.lP;this.xT.entryPrice=n.VT+s.bt,null!==n.AT&&(this.xT.takeProfit=n.AT+s.bt),null!==n.ET&&(this.xT.stopLoss=n.ET+s.bt),null!==n.LT&&(this.xT.entryTime=this.BT(n.LT,s.gt)),null!==n.Oy&&(this.xT.endTime=this.BT(n.Oy,s.gt))}}else"tp"===this.MC||"tp-right"===this.MC?(this.xT.takeProfit=i,"tp-right"===this.MC?this.xT.endTime=t:this.xT.entryTime=t):"sl"!==this.MC&&"sl-right"!==this.MC||(this.xT.stopLoss=i,"sl-right"===this.MC?this.xT.endTime=t:this.xT.entryTime=t);this.AP(),this.dM()}}BT(t,i){return t+i}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.xT.onRemove&&this.xT.onRemove()}}function ro(t,i){return new eo(t,i)}class ho{constructor(t){this.vC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.vC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class lo{constructor(t){this.vC=t,this.Jt=new ho(t)}renderer(){return this.vC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class oo extends Dh{constructor(t,i){super(t,"gantt",i),this.qb=null,this.mC=null,this.eh=null,this.wC=!1,this.gC=!1,this.bC=!1,this.OT=-1,this.yC=null,this.lP=null,this.WT=-1,this.zT={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.zT),this.$y()}$y(){this.eh=this.RC();const t={attached:t=>{this.mC=t.requestUpdate},detached:()=>{this.mC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.FC(t,i)};this.qb=t,this._series.attachPrimitive(t),this.dM()}RC(){return new lo(this)}drawToCanvas(t,i,s){if(!this.zT.segments||0===this.zT.segments.length)return;const n=50*s,e=this.zT.rowHeight*s,r=this.zT.rowSpacing*s;this.zT.showGrid&&this.nm(t,n,e,r,i,s),this.zT.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.WT||this.gC&&!this.isLocked();this.$T(t,l,o,a,e,s,_,i)})}nm(t,i,s,n,e,r){if(!this.zT.segments)return;const h=Math.max(...this.zT.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()}}$T(t,i,s,n,e,r,h,l){const o=s-i,a=this.Wy(r.color,h?this.zT.fillOpacity+.2:this.zT.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.zT.borderWidth+(this.wC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.zT.showLabels&&r.label&&this.UC(t,i,n,o,e,r.label,l)}UC(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)}Wy(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.zT.segments||(this.zT.segments=[]),this.zT.segments.push(t),this.dM(),this.zT.onUpdate&&this.zT.onUpdate()}removeSegment(t){this.zT.segments&&t>=0&&t<this.zT.segments.length&&(this.zT.segments.splice(t,1),this.dM(),this.zT.onUpdate&&this.zT.onUpdate())}getSegments(){return this.zT.segments||[]}setColor(t){const i=this.zT.segments??[];for(const s of i)s.color=t;this.dM()}color(){const t=this.zT.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.wC!==t&&(this.wC=t,this.dM())}isSelected(){return this.wC}setHovered(t){this.gC!==t&&(this.gC=t,this.dM())}isHovered(){return this.gC}FC(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.zT.segments?.[this.WT];s&&(this.bC=!0,this.OT=this.WT,this.yC=i,this.lP={By:s.startTime,Oy:s.endTime})}updateDrag(t,i){const s=this.zT.segments?.[this.OT];if(!this.bC||!this.lP||!s)return;const n=yh(this.yC,t,i);s.startTime=this.lP.By+n.gt,s.endTime=this.lP.Oy+n.gt,this.dM(),this.zT.onUpdate&&this.zT.onUpdate()}stopDrag(){this.bC=!1,this.OT=-1,this.yC=null,this.lP=null}hitTest(t,i){if(!this.zT.segments||0===this.zT.segments.length)return!1;const s=this.zT.rowHeight,n=this.zT.rowSpacing;for(let e=0;e<this.zT.segments.length;e++){const r=this.zT.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.WT=e,!0}return this.WT=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.zT.rowHeight,rowSpacing:this.zT.rowSpacing,fillOpacity:this.zT.fillOpacity,borderWidth:this.zT.borderWidth,showLabels:this.zT.showLabels,showGrid:this.zT.showGrid},extra:{segments:(this.zT.segments||[]).map(t=>({By:xh(t.startTime),Oy:xh(t.endTime),sn:t.level,Jl:t.label,R:t.color,HT:t.category}))}}}dM(){this.qb&&this.qb.updateAllViews?.(),this.mC?.()}_update(){this.dM()}remove(){this.qb&&(this._series.detachPrimitive(this.qb),this.qb=null,this.eh=null),this.zT.onRemove&&this.zT.onRemove()}}function ao(t,i){return new oo(t,i)}class _o{constructor(t,i,s={}){this.NT=[],this.UT=[],this.qT=[],this.jT=!1,this.YT=new Map,this.XT=null,this.GT=null,this.KT=null,this.jS=null,this.ZT=null,this.np=null,this.JT=null,this.QT=null,this.tk=null,this.ik=null,this.sk=null,this.uS=null,this.nk=!1,this.ek=null,this.rk=null,this.hk=new a,this.bC=!1,this.lk=null,this.ak=new Set,this._k=null,this.uk=new a,this.Vf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.ck()}startDrawing(t){this.KT=t,this.dk()}activeDrawingType(){return this.KT}stopDrawing(){this.KT=null}addTool(t,i){const s=i??t.id;return this.YT.set(s,t),t.isComplete()||this.ak.add(s),this.recordChange(),s}hasPendingDrawing(){return this.ak.size>0}cancelPendingDrawings(){if(0===this.ak.size)return 0;let t=0;for(const i of Array.from(this.ak)){const s=this.YT.get(i);s&&(this.XT===i&&this.pk(null),s.remove(),this.YT.delete(i),t++)}return this.ak.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.uk.i(t)}unsubscribeDrawingCompleted(t){this.uk._(t)}fk(){0!==this.ak.size&&null===this._k&&(this._k=setTimeout(()=>{this._k=null;for(const t of Array.from(this.ak)){const i=this.YT.get(t);i?i.isComplete()&&(this.ak.delete(t),this.uk.p(t)):this.ak.delete(t)}},0))}removeTool(t){const i=this.YT.get(t);return!!i&&(this.XT===t&&this.pk(null),i.remove(),this.YT.delete(t),this.ak.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.YT.has(t)&&(this.pk(t),!0)}pk(t){if(this.XT===t)return;const i=null===this.XT?void 0:this.YT.get(this.XT);i&&i.setSelected(!1),this.XT=t;const s=null===t?void 0:this.YT.get(t);s&&s.setSelected(!0),this.vk()}recordChange(){this.jT||(this.NT.push(this.qT),this.NT.length>100&&this.NT.shift(),this.UT=[],this.qT=this.serializeAll())}canUndo(){return this.NT.length>0}canRedo(){return this.UT.length>0}undo(){const t=this.NT.pop();return void 0!==t&&(this.UT.push(this.qT),this.mk(t),!0)}redo(){const t=this.UT.pop();return void 0!==t&&(this.NT.push(this.qT),this.mk(t),!0)}mk(t){this.jT=!0;try{this.restoreAll({chart:this.Vf,series:this.be},t,!0),this.qT=t}finally{this.jT=!1}}subscribeSelectionChanged(t){this.hk.i(t)}unsubscribeSelectionChanged(t){this.hk._(t)}selectionBounds(){if(null===this.XT)return null;const t=this.YT.get(this.XT);return t?this.wk(t):null}wk(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.Vf,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.gk(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}gk(t){const i=this.Vf.chartElement(),s=this.bk(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}}vk(){this.hk.p({id:this.XT,bounds:this.selectionBounds()})}deselectAll(){this.dk()}deleteSelected(){if(this.XT){const t=this.YT.get(this.XT);return(!t||!t.isLocked())&&this.removeTool(this.XT)}return!1}getSelectedToolId(){return this.XT}getAllTools(){return new Map(this.YT)}getTool(t){return this.YT.get(t)}clearAll(){this.pk(null),this.YT.forEach(t=>t.remove()),this.YT.clear(),this.ak.clear(),this.recordChange()}getToolCount(){return this.YT.size}isToolSelected(t){return this.XT===t}serializeAll(){const t=[];for(const i of this.YT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=_o.Mk(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 Mk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({yk:Th(n[t]),Sk:kh(n[t],"price")??0});switch(s){case"trendLine":return Wh(t,{point1Time:h(0).yk,point1Price:h(0).Sk,point2Time:h(1).yk,point2Price:h(1).Sk,...e});case"horizontalLine":return Nh(t,{price:h(0).Sk,startTime:h(0).yk??void 0,...e});case"parallelChannel":return il(t,{point1Time:h(0).yk,point1Price:h(0).Sk,point2Time:h(1).yk,point2Price:h(1).Sk,channelWidth:r?.channelWidth,...e});case"pitchfork":return rl(t,{pivotTime:h(0).yk,pivotPrice:h(0).Sk,upperTime:h(1).yk,upperPrice:h(1).Sk,lowerTime:h(2).yk,lowerPrice:h(2).Sk,...e});case"polygon":return Zh(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).yk,s.price=h(i).Sk,s}),...e});case"crossLine":return Yh(t,{time:h(0).yk,price:h(0).Sk,...e});case"verticalLine":return al(t,{time:h(0).yk,...e});case"fibRetracement":return ml(t,{point1Time:h(0).yk,point1Price:h(0).Sk,point2Time:h(1).yk,point2Price:h(1).Sk,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.yk?{time:i.yk,price:i.Sk}:void 0,point2:s.yk?{time:s.yk,price:s.Sk}:void 0,point3:n.yk?{time:n.yk,price:n.Sk}:void 0,levels:r?.levels,...e})}case"fibFan":return Pl(t,{point1Time:h(0).yk,point1Price:h(0).Sk,point2Time:h(1).yk,point2Price:h(1).Sk,levels:r?.levels,...e});case"rectangle":return Rl(t,{time1:h(0).yk,price1:h(0).Sk,time2:h(1).yk,price2:h(1).Sk,...e});case"circle":return Ll(t,{centerTime:h(0).yk,centerPrice:h(0).Sk,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).yk,price:h(0).Sk,text:r?.text,...e});case"ruler":return io(t,{point1Time:h(0).yk,point1Price:h(0).Sk,point2Time:h(1).yk,point2Price:h(1).Sk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ro(t,{entryPrice:h(0).Sk,entryTime:h(0).yk,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._k&&(clearTimeout(this._k),this._k=null),this.uk.m(),this.hk.m(),this.clearAll(),this.xk(),this.NT=[],this.UT=[],this.qT=[]}ck(){this.jS=t=>{this._C(t)},this.Vf.subscribeClick(this.jS),this.np=t=>{this.uC(t)},this.Vf.subscribeCrosshairMove(this.np);const t=this.Vf.chartElement();t&&(this.JT=t=>this.Ck(t),this.QT=t=>this.Pk(t),this.tk=t=>this.Pk(t),this.ik=t=>this.Tk(t),t.addEventListener("pointerdown",this.JT),t.addEventListener("pointerup",this.QT),t.addEventListener("pointercancel",this.tk),t.addEventListener("lostpointercapture",this.ik)),_s&&(this.sk=t=>this.Pk(t),window.addEventListener("pointerup",this.sk)),this.Ps.enableKeyboardShortcuts&&(this.ZT=t=>{this.kk(t)},document.addEventListener("keydown",this.ZT))}xk(){this.jS&&(this.Vf.unsubscribeClick(this.jS),this.jS=null),this.np&&(this.Vf.unsubscribeCrosshairMove(this.np),this.np=null);const t=this.Vf.chartElement();t&&(this.JT&&(t.removeEventListener("pointerdown",this.JT),this.JT=null),this.QT&&(t.removeEventListener("pointerup",this.QT),this.QT=null),this.tk&&(t.removeEventListener("pointercancel",this.tk),this.tk=null),this.ik&&(t.removeEventListener("lostpointercapture",this.ik),this.ik=null)),this.sk&&(window.removeEventListener("pointerup",this.sk),this.sk=null),this.ZT&&(document.removeEventListener("keydown",this.ZT),this.ZT=null)}_C(t){if(this.fk(),!t.point)return;if(this.nk)return void(this.nk=!1);if(this.bC)return;const i=this.Dk(t.hoveredObjectId);i?this.selectTool(i):this.dk()}uC(t){if(this.ek=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.bC&&this.lk){const i=this.YT.get(this.lk);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Yn(this.Vf,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.Dk(t.hoveredObjectId);if(this.GT&&this.GT!==i){const t=this.YT.get(this.GT);t&&t.setHovered(!1)}if(i){const t=this.YT.get(i);t&&t.setHovered(!0)}this.GT=i}Dk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.YT)if(s.id===i)return t;return null}Ck(t){if(this.bC)return;Fh(this.Vf,!1);const i=this.Vf.chartElement();if(!i)return;const s=null!==this.GT&&null!==this.ek?{Rk:this.GT,Dw:this.ek}:this.Fk(t);if(null===s)return;const{Rk:n,Dw:e}=s,r=this.YT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Ik(r,e.ut,e.ct);if(null!==h&&null!==l){Fh(this.Vf,!0),this.selectTool(n),this.bC=!0,this.nk=!0,this.lk=n,this.uS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.uS=null}r.startDrag(h,l),this.Vk()}}Pk(t){if(!this.bC||null===this.lk)return;if(t&&null!==this.uS&&t.pointerId!==this.uS)return;const i=this.lk;this.bC=!1,this.lk=null;try{const t=this.YT.get(i);t&&t.stopDrag()}finally{this.BS(),this.Lk()}this.recordChange()}Tk(t){null!==this.uS&&t.pointerId!==this.uS||(this.uS=null,this.Pk())}bk(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Fk(t){for(const[i,s]of this.YT){if(!s.isVisible()||s.isLocked())continue;const n=this.bk(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{Rk:i,Dw:r}}return null}BS(){if(null===this.uS)return;const t=this.Vf.chartElement();t&&t.hasPointerCapture(this.uS)&&t.releasePointerCapture(this.uS),this.uS=null}Vk(){if(null!==this.rk)return;const t=this.Vf.options();this.rk={Ak:f(t.handleScroll),Ek:f(t.handleScale)},this.Vf.applyOptions({handleScroll:!1,handleScale:!1})}Lk(){const t=this.rk;this.rk=null,null!==t&&this.Vf.applyOptions({handleScroll:t.Ak,handleScale:t.Ek})}kk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.fk(),"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.Pk(),this.dk(),this.stopDrawing(),t.preventDefault())}Ik(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Yn(this.Vf,t.series(),i)}}dk(){this.pk(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({r_:t,Yf:i,My:[h,l,o],Jl:"ADX",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Bk:[],Ok:[],Wk:[]};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{Bk:o,Ok:a,Wk:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Bk],[l,n?s.Ok:[]],[o,n?s.Wk:[]]]},Sy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),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({r_:t,Yf:i,My:[e],Jl:"ATR",W:n,xy:["period"],yy:(t,i)=>[[e,r(t,i.period??14)]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},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({r_:t,Yf:i,My:[r,h,l],Jl:"Bollinger Bands",W:n,xy:["period","stdDev"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{yP:[],zk:[],SP:[]};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{yP:e,zk:r,SP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.yP],[h,s.zk],[l,s.SP]]},Sy:t=>{const i=t.lineWidth??1;r.applyOptions({color:t.colorUpper,lineWidth:i}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min(i+1,4)}),l.applyOptions({color:t.colorLower,lineWidth:i})}});return{upper:r,middle:h,lower:l,...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({r_:t,Yf:i,My:[r],Jl:"CCI",W:n,xy:["period"],yy:(t,i)=>[[r,o(t,i.period??20)]],Sy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...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({r_:t,Yf:i,My:[r,h,l],Jl:"Donchian Channels",W:n,xy:["period"],yy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{yP:[],zk:[],SP:[]};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{yP:s,zk:n,SP:e}})(t,i.period??20);return[[r,s.yP],[h,s.zk],[l,s.SP]]},Sy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:i,lineStyle:s,visible:t.showMiddle??!0}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...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({r_:t,Yf:i,My:[e],Jl:"EMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},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({r_:t,Yf:i,My:[r],Jl:"Heikin Ashi",W:n,xy:[],yy:t=>[[r,Ur(t)]],Sy:t=>{r.applyOptions({upColor:t.upColor,downColor:t.downColor,borderVisible:t.borderVisible,borderUpColor:t.borderUpColor,borderDownColor:t.borderDownColor,wickVisible:t.wickVisible,wickUpColor:t.wickUpColor,wickDownColor:t.wickDownColor}),l(!0===t.hideSource)}});return{za: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,()=>({Vy:c.cloudBullishColor??"#089981",Ly:c.cloudBearishColor??"#F23645",Dy: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{$k:h,rh:l,Ry:o,Fy:a,Hk:_,Nk: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,Ry:s,Fy:n};u.push(t)}}return{$k:h,rh:l,Ry:o,Fy:a,Hk:_,Nk:u}},v=Or({r_:t,Yf:i,My:[h,l,o,a,_],Jl:"Ichimoku",W:n,xy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],yy:(t,i)=>{c=i;const s=f(t,i);return u=s.Nk,[[h,s.$k],[l,s.rh],[o,s.Ry],[a,s.Fy],[_,i.showLagging??1?s.Hk:[]]]},Sy: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({r_:t,Yf:i,My:[r,h,l],Jl:"Keltner Channels",W:n,xy:["period","atrPeriod","multiplier","source"],yy:(t,i)=>{const s=((t,i)=>{const s=i.period??20,n=i.atrPeriod??10,e=i.multiplier??2;if(!t||t.length<Math.max(s,n+1))return{yP:[],zk:[],SP:[]};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{yP:c,zk:d,SP:p}})(t,i);return[[r,s.yP],[h,s.zk],[l,s.SP]]},Sy:t=>{const i=t.lineWidth??1,s=t.lineStyle;r.applyOptions({color:t.colorUpper,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.colorMiddle,lineWidth:Math.min((t.lineWidth??1)+1,4),lineStyle:s}),l.applyOptions({color:t.colorLower,lineWidth:i,lineStyle:s})}});return{upper:r,middle:h,lower:l,...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({r_:t,Yf:i,My:[r,h,l],Jl:"MACD",W:n,xy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],yy:(t,i)=>{const s=((t,i)=>{const s=i.fastPeriod??12,n=i.slowPeriod??26,e=i.signalPeriod??9;if(!t||t.length<n+e)return{Uk:[],qk:[],jk:[]};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{Uk:c,qk:d,jk:p}})(t,i);return[[r,s.Uk],[h,s.qk],[l,s.jk]]},Sy:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),h.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:h,histogram:l,...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({r_:t,Yf:i,My:[r],Jl:"MFI",W:n,xy:["period"],yy:(t,i)=>[[r,o(t,i.period??14)]],Sy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...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({r_:t,Yf:i,My:[e],Jl:"OBV",W:n,yy:()=>[[e,r()]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth})}});return{series:e,...h}},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({r_:t,Yf:i,My:[e],Jl:"Parabolic SAR",W:n,xy:["step","maxStep","colorUp","colorDown"],yy:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({pointMarkersRadius:t.dotSize})}});return{series:e,...h}},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({r_:t,Yf:i,My:[h,...l,...o],Jl:"Pivot Points",W:n,xy:["pivotPeriod"],yy:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{bP:s,Yk:n,Xk: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={Gk:i,Kk:[2*i-l,i+s,h+2*(i-l)],Zk:[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.Gk});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Kk[t]}),e[t].push({time:_.time,value:a.Zk[t]})}}return{bP:s,Yk:n,Xk:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.bP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Yk[t]:[]]),e.push([o[t],t<n?s.Xk[t]:[]]);return e},Sy:t=>{const i=t.lineWidth??1,s=t.lineStyle,n=Math.max(1,Math.min(t.levels??3,3));h.applyOptions({color:t.colorPivot,lineWidth:i,lineStyle:s});for(let e=0;e<3;e++)l[e].applyOptions({color:t.colorResistance,lineWidth:i,lineStyle:s,visible:e<n}),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({r_:t,Yf:i,My:[r],Jl:"RSI",W:n,xy:["period","source"],yy:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],Sy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...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({r_:t,Yf:i,My:[e],Jl:"SMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},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({r_:t,Yf:i,My:[h,l],Jl:"Stochastic",W:n,xy:["kPeriod","dPeriod"],yy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Jk:[],Qk:[]};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{Jk:e,Qk:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Jk],[l,s.Qk]]},Sy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),l.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),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({r_:t,Yf:i,My:[e],Jl:"SuperTrend",xy:["period","multiplier","colorUp","colorDown"],W:n,yy:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Sy:t=>{e.applyOptions({lineWidth:t.lineWidth})}});return{series:e,...h}},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({r_:t,Yf:i,My:[r,h,l],Jl:"VWAP",W:n,xy:["anchorPeriod","bandMultiplier"],yy:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Dr(t))return{tD:e,yP:r,SP: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{tD:e,yP:r,SP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.tD],[h,n.yP],[l,n.SP]]},Sy:t=>{const i=t.lineWidth??2,s=t.lineStyle,n=(t.bandMultiplier??0)>0;r.applyOptions({color:t.color,lineWidth:i,lineStyle:s}),h.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n}),l.applyOptions({color:t.bandColor,lineWidth:1,lineStyle:s,visible:n})}});return{series:r,upper:h,lower:l,...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({r_:t,Yf:i,My:[r],Jl:"Volume",W:n,xy:["colorUp","colorDown"],yy:(t,i)=>[[r,l(i.colorUp??"#26a69a",i.colorDown??"#ef5350")]]});return{series:r,...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({r_:t,Yf:i,My:[e],Jl:"WMA",W:n,xy:["period","source"],yy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Sy:t=>{e.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle})}});return{series:e,...h}},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({r_:t,Yf:i,My:[r],Jl:"Williams %R",W:n,xy:["period"],yy:(t,i)=>[[r,o(t,i.period??14)]],Sy:t=>{r.applyOptions({color:t.color,lineWidth:t.lineWidth,lineStyle:t.lineStyle}),l([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{series:r,...a}},calculateHeikinAshi:Ur,calculatePipConfig:Gl,coordinateFromTime:Xn,createArrowTool:Ol,createBrushTool:Nl,createChart:function(t,i){return qn(t,new ss,ss._d(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.4"}});window.PipsendCharts=co,window.LightweightCharts=co}();
|
|
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)}Ir(t,i){return void 0===i&&null===this.be.Ks().kr(t)?null:this.Fr(t,i)}}function Mt(t,i,s,n,e=0,r=i.length){let h=r-e;for(;0<h;){const r=h>>1,l=e+r;n(i[l],s)===t?(e=l+1,h-=r+1):h=r}return e}const yt=Mt.bind(null,!0),St=Mt.bind(null,!1);var xt;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(xt||(xt={}));const Ct=30;class Pt{constructor(){this.Vr=[],this.Lr=new Map,this.Ar=new Map,this.Er=[]}Br(){return this.Or()>0?this.Vr[this.Vr.length-1]:null}Wr(){return this.Or()>0?this.zr(0):null}Gs(){return this.Or()>0?this.zr(this.Vr.length-1):null}Or(){return this.Vr.length}Gi(){return 0===this.Or()}De(t){return null!==this.$r(t,0)}kr(t){return this.Hr(t)}Hr(t,i=0){const s=this.$r(t,i);return null===s?null:{...this.Nr(s),Re:this.zr(s)}}Ur(){return this.Vr}qr(t,i,s){if(this.Gi())return null;let n=null;for(const e of s){n=Tt(n,this.jr(t,i,e))}return n}lt(t){this.Ar.clear(),this.Lr.clear(),this.Vr=t,this.Er=t.map(t=>t.Re)}Yr(){return this.Er}zr(t){return this.Vr[t].Re}Nr(t){return this.Vr[t]}$r(t,i){const s=this.Xr(t);if(null===s&&0!==i)switch(i){case-1:return this.Gr(t);case 1:return this.Kr(t);default:throw new TypeError("Unknown search mode")}return s}Gr(t){let i=this.Zr(t);return i>0&&(i-=1),i!==this.Vr.length&&this.zr(i)<t?i:null}Kr(t){const i=this.Jr(t);return i!==this.Vr.length&&t<this.zr(i)?i:null}Xr(t){const i=this.Zr(t);return i===this.Vr.length||t<this.Vr[i].Re?null:i}Zr(t){return yt(this.Vr,t,(t,i)=>t.Re<i)}Jr(t){return St(this.Vr,t,(t,i)=>t.Re>i)}Qr(t,i,s){let n=null;for(let e=t;e<i;e++){const t=this.Vr[e].Ht[s];Number.isNaN(t)||(null===n?n={th:t,ih:t}:(t<n.th&&(n.th=t),t>n.ih&&(n.ih=t)))}return n}jr(t,i,s){if(this.Gi())return null;let n=null;const e=l(this.Wr()),r=l(this.Gs()),h=Math.max(t,e),o=Math.min(i,r),a=Math.ceil(h/Ct)*Ct,_=Math.max(a,Math.floor(o/Ct)*Ct);{const t=this.Zr(h),e=this.Jr(Math.min(o,a,i));n=Tt(n,this.Qr(t,e,s))}let u=this.Lr.get(s);void 0===u&&(u=new Map,this.Lr.set(s,u));for(let t=Math.max(a+1,h);t<_;t+=Ct){const i=Math.floor(t/Ct);let e=u.get(i);if(void 0===e){const t=this.Zr(i*Ct),n=this.Jr((i+1)*Ct-1);e=this.Qr(t,n,s),u.set(i,e)}n=Tt(n,e)}{const t=this.Zr(_),i=this.Jr(o);n=Tt(n,this.Qr(t,i,s))}return n}}function Tt(t,i){if(null===t)return i;if(null===i)return t;return{th:Math.min(t.th,i.th),ih:Math.max(t.ih,i.ih)}}const kt={setLineStyle:n};class Dt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Rt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Dt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}class Ft{constructor(t){this.ah=null,this._h=t}uh(){return this._h}zs(){this._h.updateAllViews?.()}$s(){const t=this._h.paneViews?.()??[];if(this.ah?.rh===t)return this.ah.hh;const i=t.map(t=>new Rt(t));return this.ah={rh:t,hh:i},i}Xn(t,i){return this._h.hitTest?.(t,i)??null}}let It=class extends Ft{cs(){return[]}};class Vt{constructor(t){this.sh=t}et(t,i,s){this.sh.draw(t,kt)}nh(t,i,s){this.sh.drawBackground?.(t,kt)}}class Lt{constructor(t){this.Fn=null,this.eh=t}Dt(){const t=this.eh.renderer();if(null===t)return null;if(this.Fn?.rh===t)return this.Fn.hh;const i=new Vt(t);return this.Fn={rh:t,hh:i},i}oh(){return this.eh.zOrder?.()??"normal"}}function At(t){return{hi:t.text(),Li:t.coordinate(),Vi:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),It:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Et{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...At(this.dh)}),this.Jt}}class Bt extends O{constructor(t,i){super(),this.dh=t,this.Yi=i}ji(t,i,s){const n=At(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.Yi.P();s.Di=e,s.Ri=e,s.Li=n.Li,void 0!==n.Vi&&(s.Vi=n.Vi),t.hi=n.hi,t.It=n.It,t.mi=n.mi}}class Ot extends Ft{constructor(t,i){super(t),this.fh=null,this.mh=null,this.wh=null,this.gh=null,this.be=i}ds(){const t=this._h.timeAxisViews?.()??[];if(this.fh?.rh===t)return this.fh.hh;const i=this.be.ti().At(),s=t.map(t=>new Et(t,i));return this.fh={rh:t,hh:s},s}Hs(){const t=this._h.priceAxisViews?.()??[];if(this.mh?.rh===t)return this.mh.hh;const i=this.be.$t(),s=t.map(t=>new Bt(t,i));return this.mh={rh:t,hh:s},s}bh(){const t=this._h.priceAxisPaneViews?.()??[];if(this.wh?.rh===t)return this.wh.hh;const i=t.map(t=>new Lt(t));return this.wh={rh:t,hh:i},i}Mh(){const t=this._h.timeAxisPaneViews?.()??[];if(this.gh?.rh===t)return this.gh.hh;const i=t.map(t=>new Lt(t));return this.gh={rh:t,hh:i},i}yh(t,i){return this._h.autoscaleInfo?.(t,i)??null}}function Wt(t,i,s,n){t.forEach(t=>{i(t).forEach(t=>{t.oh()===s&&n.push(t)})})}function zt(t){return t.$s()}function $t(t){return t.bh()}function Ht(t){return t.Mh()}const Nt=["Area","Line","Baseline"];class Ut extends wt{constructor(t,i,s,n,e){super(t),this.Yt=new Pt,this.rr=new _t(this),this.Sh=[],this.xh=new ht(this),this.Ch=null,this.Ph=null,this.Th=null,this.kh=[],this.Ps=s,this.Dh=i;const r=new ut(this);this.ws=[r],this.hr=new nt(r,this,t),Nt.includes(this.Dh)&&(this.Ch=new at(this)),this.Rh(),this.eh=n(this,this.ti(),e)}m(){null!==this.Th&&clearTimeout(this.Th)}Le(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().At().Gi()||s.Gi()||this.Yt.Gi())return i;const n=this.ti().At().Pe(),e=this.Bt();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Br();if(null===t)return i;r=t,h=t.Re}else{const t=this.Yt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.Yt.kr(t.Re),null===r)return i;h=t.Re}const l=r.Ht[3],o=this.Fh().Fr(h,{Ht:r}),a=s.zt(l,e.Ht);return{ke:!1,bt:l,hi:s.Zi(l,e.Ht),We:s.Ih(l),ze:s.Vh(l,e.Ht),R:o.dr,Li:a,Re:h}}Fh(){return null!==this.Ph||(this.Ph=new bt(this)),this.Ph}W(){return this.Ps}lr(t){const i=t.priceScaleId;void 0!==i&&i!==this.Ps.priceScaleId&&this.ti().Lh(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Ah()),this.ti().Eh(this),this.ti().Bh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Oh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Eh(this),this.ti().Bh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Eh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Eh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Bt(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().At().Pe();if(null===t)return null;const i=t.qh();return this.Yt.Hr(i,1)}Ks(){return this.Yt}jh(t){const i=this.Yt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3]}:i.Ht[3]}Zh(t){const i=[];Wt(this.kh,zt,"top",i);const s=this.Ch;return null!==s&&s.It()?(null===this.Th&&s.xe()&&(this.Th=setTimeout(()=>{this.Th=null,this.ti().Jh()},0)),s.Se(),i.unshift(s),i):i}$s(){const t=[];this.Qh()||t.push(this.xh),t.push(this.eh,this.rr);const i=this.Sh.map(t=>t._r());return t.push(...i),Wt(this.kh,zt,"normal",t),t}tl(){return this.il(zt,"bottom")}sl(t){return this.il($t,t)}nl(t){return this.il(Ht,t)}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}cs(){return[this.hr,...this.Sh.map(t=>t.ur())]}Hs(t,i){if(i!==this.rs&&!this.Qh())return[];const s=[...this.ws];for(const t of this.Sh)s.push(t.cr());return this.kh.forEach(t=>{s.push(...t.Hs())}),s}ds(){const t=[];return this.kh.forEach(i=>{t.push(...i.ds())}),t}yh(t,i){if(void 0!==this.Ps.autoscaleInfoProvider){const s=this.Ps.autoscaleInfoProvider(()=>{const s=this.rl(t,i);return null===s?null:s.Ke()});return pt.Ze(s)}return this.rl(t,i)}rh(){const t=this.Ps.priceFormat;return t.base??1/t.minMove}hl(){return this.ll}zs(){this.eh.Tt();for(const t of this.ws)t.Tt();for(const t of this.Sh)t.Tt();this.rr.Tt(),this.xh.Tt(),this.Ch?.Tt(),this.kh.forEach(t=>t.zs())}$t(){return l(super.$t())}Et(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.Yt.kr(t);if(null===i)return null;return{bt:i.Ht[3],vt:this.ol(),Nt:this.al(),Wt:this._l(),Ot:this.ul(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}cl(t){this.kh.push(new Ot(t,this))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t)}pl(){if("Custom"===this.Dh)return t=>this.eh.fl(t)}vl(){if("Custom"===this.Dh)return t=>this.eh.ml(t)}wl(){return this.Yt.Yr()}Qh(){return!j(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.Yt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.Yt.qr(t,i,s);let e=null!==n?new dt(n.th,n.ih):null,r=null;if("Histogram"===this.Rr()){const t=this.Ps.base,i=new dt(t,t);e=null!==e?e.mn(i):i}return this.kh.forEach(s=>{const n=s.yh(t,i);if(n?.priceRange){const t=new dt(n.priceRange.minValue,n.priceRange.maxValue);e=null!==e?e.mn(t):t}n?.margins&&(r=n.margins)}),new pt(e,r)}ol(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerRadius}return 0}al(){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}_l(){switch(this.Dh){case"Line":case"Area":case"Baseline":return this.Ps.crosshairMarkerBorderWidth}return 0}ul(t){switch(this.Dh){case"Line":case"Area":case"Baseline":{const t=this.Ps.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Fh().Fr(t).dr}Rh(){switch(this.Ps.priceFormat.type){case"custom":{const t=this.Ps.priceFormat.formatter;this.ll={format:t,formatTickmarks:this.Ps.priceFormat.tickmarksFormatter??(i=>i.map(t))};break}case"volume":this.ll=new Q(this.Ps.priceFormat.precision);break;case"percent":this.ll=new J(this.Ps.priceFormat.precision);break;default:{const t=Math.pow(10,this.Ps.priceFormat.precision);this.ll=new Z(t,this.Ps.priceFormat.minMove*t)}}null!==this.rs&&this.rs.bl()}il(t,i){const s=[];return Wt(this.kh,t,i,s),s}}const qt=[3],jt=[0,1,2,3];class Yt{constructor(t){this.Ps=t}Ml(t,i,s){let n=t;if(0===this.Ps.mode)return n;const e=s.ks(),r=e.Bt();if(null===r)return n;const h=e.zt(t,r),l=s.yl().filter(t=>t instanceof Ut).reduce((t,n)=>{if(s.Un(n)||!n.It())return t;const e=n.$t(),r=n.Ks();if(e.Gi()||!r.De(i))return t;const h=r.kr(i);if(null===h)return t;const l=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.Sl){t.strokeStyle=h.xl,n(t,h.Cl),t.beginPath();for(const n of h.Pl){const e=Math.round(n.Tl*s);t.moveTo(e,-r),t.lineTo(e,i.height+r)}t.stroke()}if(h.kl){t.strokeStyle=h.Dl,n(t,h.Rl),t.beginPath();for(const s of h.Fl){const n=Math.round(s.Tl*e);t.moveTo(-r,n),t.lineTo(i.width+r,n)}t.stroke()}})}}class Jt{constructor(t){this.Jt=new Zt,this.xt=!0,this.Pt=t}Tt(){this.xt=!0}Dt(){if(this.xt){const t=this.Pt.ti().W().grid,i={kl:t.horzLines.visible,Sl:t.vertLines.visible,Dl:t.horzLines.color,xl:t.vertLines.color,Rl:t.horzLines.style,Cl:t.vertLines.style,Fl:this.Pt.ks().Il(),Pl:(this.Pt.ti().At().Il()||[]).map(t=>({Tl:t.coord}))};this.Jt.lt(i),this.xt=!1}return this.Jt}}class Qt{constructor(t){this.eh=new Jt(t)}_r(){return this.eh}}const ti={Vl:4,Ll:1e-4};function ii(t,i){const s=100*(t-i)/i;return i<0?-s:s}function si(t,i){const s=ii(t.qe(),i),n=ii(t.je(),i);return new dt(s,n)}function ni(t,i){const s=100*(t-i)/i+100;return i<0?-s:s}function ei(t,i){const s=ni(t.qe(),i),n=ni(t.je(),i);return new dt(s,n)}function ri(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.log10(s+i.Ll)+i.Vl;return t<0?-n:n}function hi(t,i){const s=Math.abs(t);if(s<1e-15)return 0;const n=Math.pow(10,s-i.Vl)-i.Ll;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.je(),i);return new dt(s,n)}function 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.Vl+s;return{Vl:n,Ll:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Al=t,this.El=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Al))this.Bl=[2,2.5,2];else{this.Bl=[];for(let t=this.Al;1!==t;){if(t%2==0)this.Bl.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Bl.push(2,2.5),t/=5}if(this.Bl.length>100)throw new Error("something wrong with base")}}}Ol(t,i,s){const n=0===this.Al?0:1/this.Al;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.El[0];for(;;){const t=Gt(e,n,1e-14)&&e>n+1e-14,i=Gt(e,s*h,1e-14),l=Gt(e,1,1e-14);if(!(t&&i&&l))break;e/=h,h=this.El[++r%this.El.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Bl.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Bl[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Bl[++r%this.Bl.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.Yi=t,this.Al=i,this.zl=s,this.$l=n}Ol(t,i){if(t<i)throw new Error("high < low");const s=this.Yi.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Al,[2,2.5,2]),r=new _i(this.Al,[2,2,2.5]),h=new _i(this.Al,[2.5,2,2]),l=[];return l.push(e.Ol(t,i,n),r.Ol(t,i,n),h.Ol(t,i,n)),function(t){if(t.length<1)throw Error("array is empty");let i=t[0];for(let s=1;s<t.length;++s)t[s]<i&&(i=t[s]);return i}(l)}Nl(){const t=this.Yi,i=t.Bt();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.Yi.W().entireTextOnly?this.Ul()/2:0,h=r,l=s-1-r,o=Math.max(n,e),a=Math.min(n,e);if(o===a)return void(this.Wl=[]);const _=this.Ol(o,a);if(this.ql(i,_,o,a,h,l),t.jl()&&this.Yl(_,a,o)){const t=this.Yi.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.Yi.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Il(){return this.Wl}Ul(){return this.Yi.P()}Hl(){return Math.max(1,Math.ceil(this.Ul()*this.Yi.W().tickMarkSpacing))}ql(t,i,s,n,e,r){const h=this.Wl,l=this.Yi;let o=s%i;o+=o<0?i:0;const a=s>=n?1:-1;let _=null,u=0;for(let c=s-o;c>n;c-=i){const s=this.$l(c,t,!0);null!==_&&Math.abs(s-_)<this.Hl()||(s<e||s>r||(u<h.length?(h[u].Tl=s,h[u].Jl=l.Ql(c),h[u].Kl=c):h.push({Tl:s,Jl:l.Ql(c),Kl:c}),u++,_=s,l.io()&&(i=this.Ol(c*a,n))))}h.length=u}Gl(t,i,s,n,e,r){const h=this.Wl,l=this.so(t,s,e,r),o=this.so(t,n,-r,-e),a=this.$l(0,t,!0)-this.$l(i,t,!0);h.length>0&&h[0].Tl-l.Tl<a/2&&h.shift(),h.length>0&&o.Tl-h[h.length-1].Tl<a/2&&h.pop(),h.unshift(l),h.push(o)}so(t,i,s,n){const e=(s+n)/2,r=this.zl(i+s,t),h=this.zl(i+n,t),l=Math.min(r,h),o=Math.max(r,h),a=Math.max(.1,this.Ol(o,l)),_=this.zl(i+e,t),u=_-_%a,c=this.$l(u,t,!0);return{Jl:this.Yi.Ql(u),Tl:c,Kl:u}}Yl(t,i,s){let n=o(this.Yi.tr());return this.Yi.io()&&(n=oi(n,this.Yi.no())),n.qe()-i<t&&s-n.je()<t}}function ci(t){return t.slice().sort((t,i)=>l(t.ls())-l(i.ls()))}var di;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(di||(di={}));const pi=new J,fi=new Z(100,1);class vi{constructor(t,i,s,n,e){this.eo=0,this.ro=null,this.Je=null,this.ho=null,this.lo={oo:!1,ao:null},this._o=!1,this.uo=0,this.co=0,this.do=new a,this.po=new a,this.fo=[],this.vo=null,this.mo=null,this.wo=null,this.bo=null,this.Mo=null,this.ll=fi,this.yo=ai(null),this.So=t,this.Ps=i,this.xo=s,this.Co=n,this.Po=e,this.To=new ui(this,100,this.ko.bind(this),this.Do.bind(this))}gl(){return this.So}W(){return this.Ps}lr(t){if(_(this.Ps,t),this.bl(),void 0!==t.mode&&this.Ro({se:t.mode}),void 0!==t.scaleMargins){const i=h(t.scaleMargins.top),s=h(t.scaleMargins.bottom);if(i<0||i>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${i}`);if(s<0||s>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${s}`);if(i+s>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${i+s}`);this.Fo(),this.wo=null}void 0!==t.tickMarkSpacing&&(this.wo=null)}Io(){return this.Ps.autoScale}Vo(){return this._o}io(){return 1===this.Ps.mode}Oe(){return 2===this.Ps.mode}Lo(){return 3===this.Ps.mode}no(){return this.yo}se(){return{nn:this.Ps.autoScale,Ao:this.Ps.invertScale,se:this.Ps.mode}}Ro(t){const i=this.se();let s=null;void 0!==t.nn&&(this.Ps.autoScale=t.nn),void 0!==t.se&&(this.Ps.mode=t.se,2!==t.se&&3!==t.se||(this.Ps.autoScale=!0),this.lo.oo=!1),1===i.se&&t.se!==i.se&&(!function(t,i){if(null===t)return!1;const s=hi(t.qe(),i),n=hi(t.je(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.yo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.yo),null!==s&&this.Eo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Eo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.bl(),n&&(3===i.se||this.Lo())&&this.bl(),void 0!==t.Ao&&i.Ao!==t.Ao&&(this.Ps.invertScale=t.Ao,this.Bo()),this.po.p(i,this.se())}Oo(){return this.po}P(){return this.xo.fontSize}qt(){return this.eo}Wo(t){this.eo!==t&&(this.eo=t,this.Fo(),this.wo=null)}zo(){if(this.ro)return this.ro;const t=this.qt()-this.$o()-this.Ho();return this.ro=t,t}tr(){return this.No(),this.Je}Eo(t,i){const s=this.Je;(i||null===s&&null!==t||null!==s&&!s.Ne(t))&&(this.wo=null,this.Je=t)}Uo(t){this.Eo(t),this.qo(null!==t)}Gi(){return this.No(),0===this.eo||!this.Je||this.Je.Gi()}jo(t){return this.Ao()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Lo()&&(t=ni(t,i)),this.Do(t,i)}Yo(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s],h=e.bt;if(isNaN(h))continue;let l=h;null!==d&&(l=d(e.bt,i));const o=n+_*(l-r),u=a?o:this.eo-1-o;e.ct=u}}Go(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.je(),o=this.zo()-1,a=this.Ao(),_=o/(h-r),u=void 0===s?0:s.from,c=void 0===s?t.length:s.to,d=this.Xo();for(let s=u;s<c;s++){const e=t[s];let h=e.Yh,l=e.Xh,o=e.Gh,u=e.Kh;null!==d&&(h=d(e.Yh,i),l=d(e.Xh,i),o=d(e.Gh,i),u=d(e.Kh,i));let c=n+_*(h-r),p=a?c:this.eo-1-c;e.Ko=p,c=n+_*(l-r),p=a?c:this.eo-1-c,e.Zo=p,c=n+_*(o-r),p=a?c:this.eo-1-c,e.Jo=p,c=n+_*(u-r),p=a?c:this.eo-1-c,e.Qo=p}}Ds(t,i){const s=this.ko(t,i);return this.ta(s,i)}ta(t,i){let s=t;return this.Oe()?s=function(t,i){return i<0&&(t=-t),t/100*i+i}(s,i):this.Lo()&&(s=function(t,i){return t-=100,i<0&&(t=-t),t/100*i+i}(s,i)),s}yl(){return this.fo}Ft(){return this.mo||(this.mo=ci(this.fo)),this.mo}ia(t){-1===this.fo.indexOf(t)&&(this.fo.push(t),this.bl(),this.sa())}na(t){const i=this.fo.indexOf(t);if(-1===i)throw new Error("source is not attached to scale");this.fo.splice(i,1),0===this.fo.length&&(this.Ro({nn:!0}),this.Eo(null)),this.bl(),this.sa()}Bt(){let t=null;for(const i of this.fo){const s=i.Bt();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Ao(){return this.Ps.invertScale}Il(){const t=null===this.Bt();if(null!==this.wo&&(t||this.wo.ea===t))return this.wo.Il;this.To.Nl();const i=this.To.Il();return this.wo={Il:i,ea:t},this.do.p(),i}ra(){return this.do}ha(t){this.Oe()||this.Lo()||null===this.bo&&null===this.ho&&(this.Gi()||(this.bo=this.eo-t,this.ho=l(this.tr()).Ue()))}la(t){if(this.Oe()||this.Lo())return;if(null===this.bo)return;this.Ro({nn:!1}),(t=this.eo-t)<0&&(t=0);let i=(this.bo+.2*(this.eo-1))/(t+.2*(this.eo-1));const s=l(this.ho).Ue();i=Math.max(i,.1),s.Xe(i),this.Eo(s)}oa(){this.Oe()||this.Lo()||(this.bo=null,this.ho=null)}aa(t){this.Io()||null===this.Mo&&null===this.ho&&(this.Gi()||(this.Mo=t,this.ho=l(this.tr()).Ue()))}_a(t){if(this.Io())return;if(null===this.Mo)return;const i=l(this.tr()).Ye()/(this.zo()-1);let s=t-this.Mo;this.Ao()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Eo(e,!0),this.wo=null}ua(){this.Io()||null!==this.Mo&&(this.Mo=null,this.ho=null)}hl(){return this.ll||this.bl(),this.ll}Zi(t,i){switch(this.Ps.mode){case 2:return this.ca(ii(t,i));case 3:return this.hl().format(ni(t,i));default:return this.er(t)}}Ql(t){switch(this.Ps.mode){case 2:return this.ca(t);case 3:return this.hl().format(t);default:return this.er(t)}}Zl(t){switch(this.Ps.mode){case 2:return this.da(t);case 3:return this.hl().formatTickmarks(t);default:return this.pa(t)}}Ih(t){return this.er(t,l(this.vo).hl())}Vh(t,i){return t=ii(t,i),this.ca(t,pi)}fa(){return this.fo}va(t){this.lo={ao:t,oo:!1}}zs(){this.fo.forEach(t=>t.zs())}jl(){return this.Ps.ensureEdgeTickMarksVisible&&this.Io()}Xl(){return this.P()/2}bl(){this.wo=null;let t=1/0;this.vo=null;for(const i of this.fo)i.ls()<t&&(t=i.ls(),this.vo=i);let i=100;null!==this.vo&&(i=Math.round(this.vo.rh())),this.ll=fi,this.Oe()?(this.ll=pi,i=100):this.Lo()?(this.ll=new Z(100,1),i=100):null!==this.vo&&(this.ll=this.vo.hl()),this.To=new ui(this,i,this.ko.bind(this),this.Do.bind(this)),this.To.Nl()}sa(){this.mo=null}ma(){return null===this.vo||this.Oe()||this.Lo()?1:1/this.vo.rh()}Ki(){return this.Po}qo(t){this._o=t}$o(){return this.Ao()?this.Ps.scaleMargins.bottom*this.qt()+this.co:this.Ps.scaleMargins.top*this.qt()+this.uo}Ho(){return this.Ao()?this.Ps.scaleMargins.top*this.qt()+this.uo:this.Ps.scaleMargins.bottom*this.qt()+this.co}No(){this.lo.oo||(this.lo.oo=!0,this.wa())}Fo(){this.ro=null}Do(t,i){if(this.No(),this.Gi())return 0;t=this.io()&&t?ri(t,this.yo):t;const s=l(this.tr()),n=this.Ho()+(this.zo()-1)*(t-s.qe())/s.Ye();return this.jo(n)}ko(t,i){if(this.No(),this.Gi())return 0;const s=this.jo(t),n=l(this.tr()),e=n.qe()+n.Ye()*((s-this.Ho())/(this.zo()-1));return this.io()?hi(e,this.yo):e}Bo(){this.wo=null,this.To.Nl()}wa(){if(this.Vo()&&!this.Io())return;const t=this.lo.ao;if(null===t)return;let i=null;const s=this.fa();let n=0,e=0;for(const r of s){if(!r.It())continue;const s=r.Bt();if(null===s)continue;const h=r.yh(t.qh(),t.yi());let o=h&&h.tr();if(null!==o){switch(this.Ps.mode){case 1:o=li(o,this.yo);break;case 2:o=si(o,s.Ht);break;case 3:o=ei(o,s.Ht)}if(i=null===i?o:i.mn(l(o)),null!==h){const t=h.ir();null!==t&&(n=Math.max(n,t.above),e=Math.max(e,t.below))}}}if(this.jl()&&(n=Math.max(n,this.Xl()),e=Math.max(e,this.Xl())),n===this.uo&&e===this.co||(this.uo=n,this.co=e,this.wo=null,this.Fo()),null!==i){if(i.qe()===i.je()){const t=5*this.ma();this.io()&&(i=oi(i,this.yo)),i=new dt(i.qe()-t,i.je()+t),this.io()&&(i=li(i,this.yo))}if(this.io()){const t=oi(i,this.yo),s=ai(t);if(r=s,h=this.yo,r.Vl!==h.Vl||r.Ll!==h.Ll){const n=null!==this.ho?oi(this.ho,this.yo):null;this.yo=s,i=li(t,s),null!==n&&(this.ho=li(n,s))}}this.Eo(i)}else null===this.Je&&(this.Eo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Oe()?ii:this.Lo()?ni:this.io()?t=>ri(t,this.yo):null}ga(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.format(t)):i(t)}ba(t,i,s){return void 0===i?(void 0===s&&(s=this.hl()),s.formatTickmarks(t)):i(t)}er(t,i){return this.ga(t,this.Co.priceFormatter,i)}pa(t,i){const s=this.Co.priceFormatter;return this.ba(t,this.Co.tickmarksPriceFormatter??(s?t=>t.map(s):void 0),i)}ca(t,i){return this.ga(t,this.Co.percentageFormatter,i)}da(t,i){const s=this.Co.percentageFormatter;return this.ba(t,this.Co.tickmarksPercentageFormatter??(s?t=>t.map(s):void 0),i)}}function mi(t){return t instanceof Ut}class wi{constructor(t,i){this.fo=[],this.Ma=new Map,this.eo=0,this.ya=0,this.Sa=1,this.mo=null,this.xa=!1,this.Ca=new a,this.kh=[],this.ph=t,this.ss=i,this.Pa=new Qt(this);const s=i.W();this.Ta=this.ka("left",s.leftPriceScale),this.Da=this.ka("right",s.rightPriceScale),this.Ta.Oo().i(this.Ra.bind(this,this.Ta),this),this.Da.Oo().i(this.Ra.bind(this,this.Da),this),this.Fa(s)}Fa(t){if(t.leftPriceScale&&this.Ta.lr(t.leftPriceScale),t.rightPriceScale&&this.Da.lr(t.rightPriceScale),t.localization&&(this.Ta.bl(),this.Da.bl()),t.overlayPriceScales){const i=Array.from(this.Ma.values());for(const s of i){const i=l(s[0].$t());i.lr(t.overlayPriceScales),t.localization&&i.bl()}}}Ia(t){switch(t){case"left":return this.Ta;case"right":return this.Da}return this.Ma.has(t)?h(this.Ma.get(t))[0].$t():null}m(){this.ti().Va().u(this),this.Ta.Oo().u(this),this.Da.Oo().u(this),this.fo.forEach(t=>{t.m&&t.m()}),this.kh=this.kh.filter(t=>{const i=t.uh();return i.detached&&i.detached(),!1}),this.Ca.p()}La(){return this.Sa}Aa(t){this.Sa=t}ti(){return this.ss}ts(){return this.ya}qt(){return this.eo}Ea(t){this.ya=t,this.Ba()}Wo(t){this.eo=t,this.Ta.Wo(t),this.Da.Wo(t),this.fo.forEach(i=>{if(this.Un(i)){const s=i.$t();null!==s&&s.Wo(t)}}),this.Ba()}Oa(t){this.xa=t}Wa(){return this.xa}za(){return this.fo.filter(mi)}yl(){return this.fo}Un(t){const i=t.$t();return null===i||this.Ta!==i&&this.Da!==i}ia(t,i,s){this.$a(t,i,s?t.ls():this.fo.length)}na(t,i){const s=this.fo.indexOf(t);r(-1!==s,"removeDataSource: invalid data source"),this.fo.splice(s,1),i||this.fo.forEach((t,i)=>t._s(i));const n=l(t.$t()).gl();if(this.Ma.has(n)){const i=h(this.Ma.get(n)),s=i.indexOf(t);-1!==s&&(i.splice(s,1),0===i.length&&this.Ma.delete(n))}const e=t.$t();e&&e.yl().indexOf(t)>=0&&(e.na(t),this.Ha(e)),this.mo=null}jn(t){return t===this.Ta?"left":t===this.Da?"right":"overlay"}Na(){return this.Ta}Ua(){return this.Da}qa(t,i){t.ha(i)}ja(t,i){t.la(i),this.Ba()}Ya(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Ba()}Ka(t){t.ua()}Ba(){this.fo.forEach(t=>{t.zs()})}ks(){let t=null;return this.ss.W().rightPriceScale.visible&&0!==this.Da.yl().length?t=this.Da:this.ss.W().leftPriceScale.visible&&0!==this.Ta.yl().length?t=this.Ta:0!==this.fo.length&&(t=this.fo[0].$t()),null===t&&(t=this.Da),t}qn(){let t=null;return this.ss.W().rightPriceScale.visible?t=this.Da:this.ss.W().leftPriceScale.visible&&(t=this.Ta),t}Ha(t){null!==t&&t.Io()&&this.Za(t)}Ja(t){const i=this.ph.Pe();t.Ro({nn:!0}),null!==i&&t.va(i),this.Ba()}Qa(){this.Za(this.Ta),this.Za(this.Da)}t_(){this.Ha(this.Ta),this.Ha(this.Da),this.fo.forEach(t=>{this.Un(t)&&this.Ha(t.$t())}),this.Ba(),this.ss.ar()}Ft(){return null===this.mo&&(this.mo=ci(this.fo)),this.mo}i_(t,i){i=Xt(i,0,this.fo.length-1);const s=this.fo.indexOf(t);r(-1!==s,"setSeriesOrder: invalid data source"),this.fo.splice(s,1),this.fo.splice(i,0,t),this.fo.forEach((t,i)=>t._s(i)),this.mo=null;for(const t of[this.Ta,this.Da])t.sa(),t.bl();this.ss.ar()}Vt(){return this.Ft().filter(mi)}s_(){return this.Ca}n_(){return this.Pa}cl(t){this.kh.push(new It(t))}dl(t){this.kh=this.kh.filter(i=>i.uh()!==t),t.detached&&t.detached(),this.ss.ar()}e_(){return this.kh}el(t,i){return this.kh.map(s=>s.Xn(t,i)).filter(t=>null!==t)}Za(t){const i=t.fa();if(i&&i.length>0&&!this.ph.Gi()){const i=this.ph.Pe();null!==i&&t.va(i)}t.zs()}$a(t,i,s){let n=this.Ia(i);if(null===n&&(n=this.ka(i,this.ss.W().overlayPriceScales)),this.fo.splice(s,0,t),!j(i)){const s=this.Ma.get(i)||[];s.push(t),this.Ma.set(i,s)}t._s(s),n.ia(t),t.us(n),this.Ha(n),this.mo=null}Ra(t,i,s){i.se!==s.se&&this.Za(t)}ka(t,i){const s={visible:!0,autoScale:!0,...f(i)},n=new vi(t,s,this.ss.W().layout,this.ss.W().localization,this.ss.Ki());return n.Wo(this.qt()),n}}function gi(t,i){return!i||"top"===t&&"top"!==i||"normal"===t&&"bottom"===i}function bi(t){return{r_:t.r_,h_:{Gn:t.l_.externalId},o_:t.l_.cursorStyle}}function Mi(t,i,s,n){for(const e of t){const t=e.Dt(n);if(null!==t&&t.Xn){const n=t.Xn(i,s);if(null!==n)return{a_:e,h_:n}}}return null}function yi(t){return void 0!==t.$s}function Si(t,i,s){const n=[t,...t.Ft()],e=function(t,i,s){let n,e;for(const r of t){const t=r.el?.(i,s)??[];for(const i of t)gi(i.zOrder,n?.zOrder)&&(n=i,e=r)}return n&&e?{l_:n,r_:e}:null}(n,i,s);if("top"===e?.l_.zOrder)return bi(e);for(const r of n){if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&!e.l_.isBackground)return bi(e);if(yi(r)){const n=Mi(r.$s(t),i,s,t);if(null!==n)return{r_:r,a_:n.a_,h_:n.h_}}if(e&&e.r_===r&&"bottom"!==e.l_.zOrder&&e.l_.isBackground)return bi(e)}return e?.l_?bi(e):null}class xi{constructor(t,i,s=50){this.Tn=0,this.kn=1,this.Dn=1,this.Fn=new Map,this.Rn=new Map,this.__=t,this.u_=i,this.In=s}c_(t){const i=t.time,s=this.u_.cacheKey(i),n=this.Fn.get(s);if(void 0!==n)return n.d_;if(this.Tn===this.In){const t=this.Rn.get(this.Dn);this.Rn.delete(this.Dn),this.Fn.delete(h(t)),this.Dn++,this.Tn--}const e=this.__(t);return this.Fn.set(s,{d_:e,En:this.kn}),this.Rn.set(this.kn,s),this.Tn++,this.kn++,e}}class Ci{constructor(t,i){r(t<=i,"right should be >= left"),this.p_=t,this.f_=i}qh(){return this.p_}yi(){return this.f_}v_(){return this.f_-this.p_+1}De(t){return this.p_<=t&&t<=this.f_}Ne(t){return this.p_===t.qh()&&this.f_===t.yi()}}function Pi(t,i){return null===t||null===i?t===i:t.Ne(i)}class Ti{constructor(){this.m_=new Map,this.Fn=null,this.w_=!1}g_(t){this.w_=t,this.Fn=null}b_(){this.Fn=null}M_(t,i){this.y_(i),this.Fn=null;for(let s=i;s<t.length;++s){const i=t[s];let n=this.m_.get(i.timeWeight);void 0===n&&(n=[],this.m_.set(i.timeWeight,n)),n.push({index:s,time:i.time,weight:i.timeWeight,originalTime:i.originalTime})}}S_(t,i,s,n,e,r=()=>!0){const h=Math.ceil(i/t);return null!==this.Fn&&this.Fn.x_===h&&e===this.Fn.C_&&s===this.Fn.P_||(this.Fn={C_:e,P_:s,Il:this.T_(h,s,n,r),x_:h}),this.Fn.Il}y_(t){if(0===t)return void this.m_.clear();const i=[];this.m_.forEach((s,n)=>{t<=s[0].index?i.push(n):s.splice(yt(s,t,i=>i.index<t),1/0)});for(const t of i)this.m_.delete(t)}T_(t,i,s,n){let e=[];const r=t=>!i||s.has(t.index);for(const i of Array.from(this.m_.keys()).sort((t,i)=>i-t)){if(!this.m_.get(i))continue;const s=e;e=[];const l=s.length;let o=0;const a=h(this.m_.get(i)),_=a.length;let u=1/0,c=-1/0;for(let i=0;i<_;i++){const h=a[i];if(!n(h,t))continue;const _=h.index;for(;o<l;){const t=s[o],i=t.index;if(!(i<_&&r(t))){u=i;break}o++,e.push(t),c=i,u=1/0}if(u-_>=t&&_-c>=t&&r(h))e.push(h),c=_;else if(this.w_)return s}for(;o<l;o++)r(s[o])&&e.push(s[o])}return e}}class ki{constructor(t){this.k_=t}D_(){return null===this.k_?null:new Ci(Math.floor(this.k_.qh()),Math.ceil(this.k_.yi()))}R_(){return this.k_}static F_(){return new ki(null)}}function Di(t,i){return t.weight>i.weight?t:i}class Ri{constructor(t,i,s,n){this.ya=0,this.I_=null,this.V_=[],this.Mo=null,this.bo=null,this.L_=new Ti,this.A_=new Map,this.E_=ki.F_(),this.B_=!0,this.O_=new a,this.W_=new a,this.z_=new a,this.H_=null,this.N_=null,this.U_=new Map,this.q_=-1,this.j_=[],this.Ps=i,this.Co=s,this.Y_=i.rightOffset,this.X_=i.barSpacing,this.ss=t,this.G_(i),this.u_=n,this.K_(),this.L_.g_(i.uniformDistribution),this.Z_()}W(){return this.Ps}J_(t){_(this.Co,t),this.Q_(),this.K_()}lr(t,i){_(this.Ps,t),this.Ps.fixLeftEdge&&this.tu(),this.Ps.fixRightEdge&&this.iu(),void 0!==t.barSpacing&&this.ss.pn(t.barSpacing),void 0!==t.rightOffset&&this.ss.fn(t.rightOffset),this.G_(t),void 0===t.minBarSpacing&&void 0===t.maxBarSpacing||this.ss.pn(t.barSpacing??this.X_),void 0!==t.ignoreWhitespaceIndices&&t.ignoreWhitespaceIndices!==this.Ps.ignoreWhitespaceIndices&&this.Z_(),this.Q_(),this.K_(),this.z_.p()}Rs(t){return this.V_[t]?.time??null}ns(t){return this.V_[t]??null}su(t,i){if(this.V_.length<1)return null;if(this.u_.key(t)>this.u_.key(this.V_[this.V_.length-1].time))return i?this.V_.length-1:null;const s=yt(this.V_,this.u_.key(t),(t,i)=>this.u_.key(t.time)<i);return this.u_.key(t)<this.u_.key(this.V_[s].time)?i?s:null:s}Gi(){return 0===this.ya||0===this.V_.length||null===this.I_}nu(){return this.V_.length>0}Pe(){return this.eu(),this.E_.D_()}ru(){return this.eu(),this.E_.R_()}hu(){const t=this.Pe();if(null===t)return null;const i={from:t.qh(),to:t.yi()};return this.lu(i)}lu(t){const i=Math.round(t.from),s=Math.round(t.to),n=l(this.ou()),e=l(this.au());return{from:l(this.ns(Math.max(n,i))),to:l(this.ns(Math.min(e,s)))}}_u(t){return{from:l(this.su(t.from,!0)),to:l(this.su(t.to,!0))}}ts(){return this.ya}Ea(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.ru(),s=this.ya;if(this.ya=t,this.B_=!0,this.Ps.lockVisibleTimeRangeOnResize&&0!==s){const i=this.X_*t/s;this.X_=i}if(this.Ps.fixLeftEdge&&null!==i&&i.qh()<=0){const i=s-t;this.Y_-=Math.round(i/this.X_)+1,this.B_=!0}this.uu(),this.cu()}jt(t){if(this.Gi()||!c(t))return 0;const i=this.du()+this.Y_-t;return this.ya-(i+.5)*this.X_-1}pu(t,i){const s=this.du(),n=void 0===i?0:i.from,e=void 0===i?t.length:i.to;for(let i=n;i<e;i++){const n=t[i].gt,e=s+this.Y_-n,r=this.ya-(e+.5)*this.X_-1;t[i].ut=r}}fu(t,i){const s=Math.ceil(this.vu(t));return i&&this.Ps.ignoreWhitespaceIndices&&!this.mu(s)?this.wu(s):s}fn(t){this.B_=!0,this.Y_=t,this.cu(),this.ss.gu(),this.ss.ar()}bu(){return this.X_}pn(t){const i=this.X_;if(this.Mu(t),void 0!==this.Ps.rightOffsetPixels&&0!==i){const t=this.Y_*i/this.X_;this.Y_=t}this.cu(),this.ss.gu(),this.ss.ar()}yu(){return this.Y_}Il(){if(this.Gi())return null;if(null!==this.N_)return this.N_;const t=this.X_,i=5*(this.ss.W().layout.fontSize+4)/8*(this.Ps.tickMarkMaxCharacterLength||8),s=Math.round(i/t),n=l(this.Pe()),e=Math.max(n.qh(),n.qh()-s),r=Math.max(n.yi(),n.yi()-s),h=this.L_.S_(t,i,this.Ps.ignoreWhitespaceIndices,this.U_,this.q_,(t,i)=>this.u_.allowsTickMark?.(t,i)??!0),o=this.ou()+s,a=this.au()-s,_=this.Su(),u=this.Ps.fixLeftEdge||_,c=this.Ps.fixRightEdge||_;let d=0;for(const t of h){if(!(e<=t.index&&t.index<=r))continue;let s;d<this.j_.length?(s=this.j_[d],s.coord=this.jt(t.index),s.label=this.xu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.jt(t.index),label:this.xu(t),weight:t.weight},this.j_.push(s)),this.X_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.j_.length=d,this.N_=this.j_,this.j_}Cu(){let t;this.B_=!0,this.pn(this.Ps.barSpacing),t=void 0!==this.Ps.rightOffsetPixels?this.Ps.rightOffsetPixels/this.bu():this.Ps.rightOffset,this.fn(t)}Pu(t){this.B_=!0,this.I_=t,this.cu(),this.tu()}Tu(t,i){const s=this.vu(t),n=this.bu(),e=n+i*(n/10);this.pn(e),this.Ps.rightBarStaysOnScroll||this.fn(this.yu()+(s-this.vu(t)))}ha(t){this.Mo&&this.ua(),null===this.bo&&null===this.H_&&(this.Gi()||(this.bo=t,this.ku()))}la(t){if(null===this.H_)return;const i=Xt(this.ya-t,0,this.ya),s=Xt(this.ya-l(this.bo),0,this.ya);0!==i&&0!==s&&this.pn(this.H_.bu*i/s)}oa(){null!==this.bo&&(this.bo=null,this.Du())}aa(t){null===this.Mo&&null===this.H_&&(this.Gi()||(this.Mo=t,this.ku()))}_a(t){if(null===this.Mo)return;const i=(this.Mo-t)/this.bu();this.Y_=l(this.H_).yu+i,this.B_=!0,this.cu()}ua(){null!==this.Mo&&(this.Mo=null,this.Du())}Ru(){this.Fu(this.Ps.rightOffset)}Fu(t,i=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(i)||i<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const s=this.Y_,n=performance.now();this.ss.un({Iu:t=>(t-n)/i>=1,Vu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.B_=!0,this.V_=t,this.L_.M_(t,i),this.cu()}Lu(){return this.O_}Au(){return this.W_}Eu(){return this.z_}du(){return this.I_||0}Bu(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.Mu((this.ya-n)/s),this.Y_=t.yi()-this.du(),i&&(this.Y_=n?n/this.bu():this.Ps.rightOffset),this.cu(),this.B_=!0,this.ss.gu(),this.ss.ar()}Ou(){const t=this.ou(),i=this.au();null!==t&&null!==i&&this.Bu(new Ci(t,i),!0)}Wu(t){const i=new Ci(t.from,t.to);this.Bu(i)}es(t){return void 0!==this.Co.timeFormatter?this.Co.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}Z_(){if(!this.Ps.ignoreWhitespaceIndices)return;this.U_.clear();const t=this.ss.Xs();for(const i of t)for(const t of i.wl())this.U_.set(t,!0);this.q_++}Su(){const t=this.ss.W().handleScroll,i=this.ss.W().handleScale;return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||i.axisDoubleClickReset.time||i.axisPressedMouseMove.time||i.mouseWheel||i.pinch)}ou(){return 0===this.V_.length?null:0}au(){return 0===this.V_.length?null:this.V_.length-1}zu(t){return(this.ya-1-t)/this.X_}vu(t){const i=this.zu(t),s=this.du()+this.Y_-i;return Math.round(1e6*s)/1e6}Mu(t){const i=this.X_;this.X_=t,this.uu(),i!==this.X_&&(this.B_=!0,this.$u())}eu(){if(!this.B_)return;if(this.B_=!1,this.Gi())return void this.Hu(ki.F_());const t=this.du(),i=this.ya/this.X_,s=this.Y_+t,n=new Ci(s-i+1,s);this.Hu(new ki(n))}uu(){const t=Xt(this.X_,this.Nu(),this.Uu());this.X_!==t&&(this.X_=t,this.B_=!0)}Uu(){return this.Ps.maxBarSpacing>0?this.Ps.maxBarSpacing:.5*this.ya}Nu(){return this.Ps.fixLeftEdge&&this.Ps.fixRightEdge&&0!==this.V_.length?this.ya/this.V_.length:this.Ps.minBarSpacing}cu(){const t=this.qu();null!==t&&this.Y_<t&&(this.Y_=t,this.B_=!0);const i=this.ju();this.Y_>i&&(this.Y_=i,this.B_=!0)}qu(){const t=this.ou(),i=this.I_;if(null===t||null===i)return null;return t-i-1+(this.Ps.fixLeftEdge?this.ya/this.X_:Math.min(2,this.V_.length))}ju(){return this.Ps.fixRightEdge?0:this.ya/this.X_-Math.min(2,this.V_.length)}ku(){this.H_={bu:this.bu(),yu:this.yu()}}Du(){this.H_=null}xu(t){let i=this.A_.get(t.weight);return void 0===i&&(i=new xi(t=>this.Yu(t),this.u_),this.A_.set(t.weight,i)),i.c_(t)}Yu(t){return this.u_.formatTickmark(t,this.Co)}Hu(t){const i=this.E_;this.E_=t,Pi(i.D_(),this.E_.D_())||this.O_.p(),Pi(i.R_(),this.E_.R_())||this.W_.p(),this.$u()}$u(){this.N_=null}Q_(){this.$u(),this.A_.clear(),this.L_.b_()}K_(){this.u_.updateFormatter(this.Co)}tu(){if(!this.Ps.fixLeftEdge)return;const t=this.ou();if(null===t)return;const i=this.Pe();if(null===i)return;const s=i.qh()-t;if(s<0){const t=this.Y_-s-1;this.fn(t)}this.uu()}iu(){this.cu(),this.uu()}mu(t){return!this.Ps.ignoreWhitespaceIndices||(this.U_.get(t)||!1)}wu(t){const i=function*(t){const i=Math.round(t),s=i<t;let n=1;for(;;)s?(yield i+n,yield i-n):(yield i-n,yield i+n),n++}(t),s=this.au();for(;s;){const t=i.next().value;if(this.U_.get(t))return t;if(t<0||t>s)break}return t}G_(t){if(void 0!==t.rightOffsetPixels){const i=t.rightOffsetPixels/(t.barSpacing||this.X_);this.ss.fn(i)}}}var Fi,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.Xu=[],this.Gu=[],this.ya=0,this.Ku=null,this.Zu=new a,this.Ju=new a,this.Qu=null,this.tc=t,this.Ps=i,this.u_=s,this.Po=new S(this.Ps.layout.colorParsers),this.sc=new b(this),this.ph=new Ri(this,i.timeScale,this.Ps.localization,s),this.Ct=new q(this,i.crosshair),this.nc=new Yt(i.crosshair),i.addDefaultPane&&(this.ec(0),this.Xu[0].Aa(2)),this.rc=this.hc(0),this.lc=this.hc(1)}Ah(){this.oc(Y.bn())}ar(){this.oc(Y.gn())}Jh(){this.oc(new Y(1))}Eh(t){const i=this.ac(t);this.oc(i)}_c(){return this.Ku}uc(t){if(this.Ku?.r_===t?.r_&&this.Ku?.h_?.Gn===t?.h_?.Gn)return;const i=this.Ku;this.Ku=t,null!==i&&this.Eh(i.r_),null!==t&&t.r_!==i?.r_&&this.Eh(t.r_)}W(){return this.Ps}lr(t){_(this.Ps,t),this.Xu.forEach(i=>i.Fa(t)),void 0!==t.timeScale&&this.ph.lr(t.timeScale),void 0!==t.localization&&this.ph.J_(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Zu.p(),this.rc=this.hc(0),this.lc=this.hc(1),this.Ah()}cc(t,i,s=0){const n=this.Xu[s];if(void 0===n)return;if("left"===t)return _(this.Ps,{leftPriceScale:i}),n.Fa({leftPriceScale:i}),this.Zu.p(),void this.Ah();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fa({rightPriceScale:i}),this.Zu.p(),void this.Ah();const e=this.dc(t,s);null!==e&&(e.$t.lr(i),this.Zu.p())}dc(t,i){const s=this.Xu[i];if(void 0===s)return null;const n=s.Ia(t);return null!==n?{Us:s,$t:n}:null}At(){return this.ph}qs(){return this.Xu}fc(){return this.Ct}vc(){return this.Ju}mc(t,i){t.Wo(i),this.gu()}Ea(t){this.ya=t,this.ph.Ea(this.ya),this.Xu.forEach(i=>i.Ea(t)),this.gu()}wc(t){1!==this.Xu.length&&(r(t>=0&&t<this.Xu.length,"Invalid pane index"),this.Xu.splice(t,1),this.Ah())}gc(t,i){if(this.Xu.length<2)return;r(t>=0&&t<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu.reduce((t,i)=>t+i.La(),0),e=this.Xu.reduce((t,i)=>t+i.qt(),0),h=e-30*(this.Xu.length-1);i=Math.min(h,Math.max(30,i));const l=n/e,o=s.qt();s.Aa(i*l);let a=i-o,_=this.Xu.length-1;for(const t of this.Xu)if(t!==s){const i=Math.min(h,Math.max(30,t.qt()-a/_));a-=t.qt()-i,_-=1;const s=i*l;t.Aa(s)}this.Ah()}bc(t,i){r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index");const s=this.Xu[t],n=this.Xu[i];this.Xu[t]=n,this.Xu[i]=s,this.Ah()}Mc(t,i){if(r(t>=0&&t<this.Xu.length&&i>=0&&i<this.Xu.length,"Invalid pane index"),t===i)return;const[s]=this.Xu.splice(t,1);this.Xu.splice(i,0,s),this.Ah()}qa(t,i,s){t.qa(i,s)}ja(t,i,s){t.ja(i,s),this.Bh(),this.oc(this.yc(t,2))}Ya(t,i){t.Ya(i),this.oc(this.yc(t,2))}Xa(t,i,s){i.Io()||t.Xa(i,s)}Ga(t,i,s){i.Io()||(t.Ga(i,s),this.Bh(),this.oc(this.yc(t,2)))}Ka(t,i){i.Io()||(t.Ka(i),this.oc(this.yc(t,2)))}Ja(t,i){t.Ja(i),this.oc(this.yc(t,2))}Sc(t){this.ph.ha(t)}xc(t,i){const s=this.At();if(s.Gi()||0===i)return;const n=s.ts();t=Math.max(1,Math.min(t,n)),s.Tu(t,i),this.gu()}Cc(t){this.Pc(0),this.Tc(t),this.kc()}Dc(t){this.ph.la(t),this.gu()}Rc(){this.ph.oa(),this.ar()}Pc(t){this.ph.aa(t)}Tc(t){this.ph._a(t),this.gu()}kc(){this.ph.ua(),this.ar()}Xs(){return this.Gu}Fc(t,i,s,n,e){this.Ct.Is(t,i);let r=NaN,h=this.ph.fu(t,!0);const l=this.ph.Pe();null!==l&&(h=Math.min(Math.max(l.qh(),h),l.yi()));const o=n.ks(),a=o.Bt();if(null!==a&&(r=o.Ds(i,a)),r=this.nc.Ml(r,h,n),this.Ct.Es(h,r,n),this.Jh(),!e){const e=Si(n,t,i);this.uc(e&&{r_:e.r_,h_:e.h_,o_:e.o_||null}),this.Ju.p(this.Ct.Lt(),{x:t,y:i},s)}}Ic(t,i,s){const n=s.ks(),e=n.Bt(),r=n.zt(t,l(e)),h=this.ph.su(i,!0),o=this.ph.jt(l(h));this.Fc(o,r,null,s,!0)}Vc(t){this.fc().Os(),this.Jh(),t||this.Ju.p(null,null,null)}Bh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.Ls(),s=this.Ct.As();this.Fc(i,s,null,t)}this.Ct.zs()}Lc(t,i,s){const n=this.ph.Rs(0);void 0!==i&&void 0!==s&&this.ph.Tt(i,s);const e=this.ph.Rs(0),r=this.ph.du(),h=this.ph.Pe();if(null!==h&&null!==n&&null!==e){const i=h.De(r),l=this.u_.key(n)>this.u_.key(e),o=null!==t&&t>r&&!l,a=this.ph.W().allowShiftVisibleRangeOnWhitespaceReplacement,_=i&&(!(void 0===s)||a)&&this.ph.W().shiftVisibleRangeOnNewBar;if(o&&!_){const i=t-r;this.ph.fn(this.ph.yu()-i)}}this.ph.Pu(t)}Wh(t){null!==t&&t.t_()}Nn(t){if(function(t){return t instanceof wi}(t))return t;const i=this.Xu.find(i=>i.Ft().includes(t));return void 0===i?null:i}gu(){this.Xu.forEach(t=>t.t_()),this.Bh()}m(){this.Xu.forEach(t=>t.m()),this.Xu.length=0,this.Ps.localization.priceFormatter=void 0,this.Ps.localization.percentageFormatter=void 0,this.Ps.localization.timeFormatter=void 0}Ac(){return this.sc}Yn(){return this.sc.W()}Va(){return this.Zu}Ec(t,i){const s=this.ec(i);this.Bc(t,s),this.Gu.push(t),1===this.Gu.length?this.Ah():this.ar()}Oc(t){const i=this.Nn(t),s=this.Gu.indexOf(t);r(-1!==s,"Series not found");const n=l(i);this.Gu.splice(s,1),n.na(t),t.m&&t.m(),this.ph.Z_();const e=this.Xu.length;this.Wc(n),this.Xu.length<e&&this.Ah()}Lh(t,i){const s=l(this.Nn(t));s.na(t,!0),s.ia(t,i,!0)}Ou(){const t=Y.gn();t.hn(),this.oc(t)}zc(t){const i=Y.gn();i._n(t),this.oc(i)}dn(){const t=Y.gn();t.dn(),this.oc(t)}pn(t){const i=Y.gn();i.pn(t),this.oc(i)}fn(t){const i=Y.gn();i.fn(t),this.oc(i)}un(t){const i=Y.gn();i.un(t),this.oc(i)}ln(){const t=Y.gn();t.ln(),this.oc(t)}$c(){return this.Ps.rightPriceScale.visible?"right":"left"}Hc(t,i){r(i>=0,"Index should be greater or equal to 0");if(i===this.Nc(t))return;const s=l(this.Nn(t));s.na(t);const n=this.ec(i);this.Bc(t,n),0===s.yl().length&&this.Wc(s),this.Ah()}Uc(){return this.lc}q(){return this.rc}Ut(t){const i=this.lc,s=this.rc;if(i===s)return i;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Qu||this.Qu.wr!==s||this.Qu.gr!==i)this.Qu={wr:s,gr:i,qc:new Map};else{const i=this.Qu.qc.get(t);if(void 0!==i)return i}const n=this.Po.it(s,i,t/100);return this.Qu.qc.set(t,n),n}jc(t){return this.Xu.indexOf(t)}Ki(){return this.Po}Yc(){return this.Xc()}Xc(t){const i=new wi(this.ph,this);this.Xu.push(i);const s=t??this.Xu.length-1,n=Y.bn();return n.tn(s,{sn:0,nn:!0}),this.oc(n),i}ec(t){return r(t>=0,"Index should be greater or equal to 0"),(t=Math.min(this.Xu.length,t))<this.Xu.length?this.Xu[t]:this.Xc(t)}Nc(t){return this.Xu.findIndex(i=>i.za().includes(t))}yc(t,i){const s=new Y(i);if(null!==t){const n=this.Xu.indexOf(t);s.tn(n,{sn:i})}return s}ac(t,i){return void 0===i&&(i=2),this.yc(this.Nn(t),i)}oc(t){this.tc&&this.tc(t),this.Xu.forEach(t=>t.n_()._r().Tt())}Bc(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.$c();i.ia(t,n),j(n)||t.lr(t.W())}hc(t){const i=this.Ps.layout;return"gradient"===i.background.type?0===t?i.background.topColor:i.background.bottomColor:i.background.color}Wc(t){!t.Wa()&&0===t.yl().length&&this.Xu.length>1&&this.Xu.splice(this.jc(t),1)}}function 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.Gc=t,this.Kc=i}c_(t){return $i(t,this.Gc,this.Kc)}}class Ni{constructor(t){this.Zc=t||"%h:%m:%s"}c_(t){return this.Zc.replace("%h",K(t.getUTCHours(),2)).replace("%m",K(t.getUTCMinutes(),2)).replace("%s",K(t.getUTCSeconds(),2))}}const Ui={Jc:"yyyy-MM-dd",Qc:"%h:%m:%s",td:" ",sd:"default"};class qi{constructor(t={}){const i={...Ui,...t};this.nd=new Hi(i.Jc,i.sd),this.ed=new Ni(i.Qc),this.rd=i.td}c_(t){return`${this.nd.c_(t)}${this.rd}${this.ed.c_(t)}`}}function ji(t){return 60*t*60*1e3}function Yi(t){return 60*t*1e3}const Xi=[{hd:(Gi=1,1e3*Gi),ld:10},{hd:Yi(1),ld:20},{hd:Yi(5),ld:21},{hd:Yi(30),ld:22},{hd:ji(1),ld:30},{hd:ji(3),ld:31},{hd:ji(6),ld:32},{hd:ji(12),ld:33}];var Gi;function Ki(t,i){if(t.getUTCFullYear()!==i.getUTCFullYear())return 70;if(t.getUTCMonth()!==i.getUTCMonth())return 60;if(t.getUTCDate()!==i.getUTCDate())return 50;for(let s=Xi.length-1;s>=0;--s)if(Math.floor(i.getTime()/Xi[s].hd)!==Math.floor(t.getTime()/Xi[s].hd))return Xi[s].ld;return 0}function Zi(t){return t}function Ji(t){let i=t;if(d(t)&&(i=ts(t)),!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{od:Math.round(s.getTime()/1e3),ad:i}}function Qi(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{od:t}}function ts(t){const i=new Date(t);if(isNaN(i.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:i.getUTCDate(),month:i.getUTCMonth()+1,year:i.getUTCFullYear()}}function is(t){d(t.time)&&(t.time=ts(t.time))}function ss(t,i,s){switch(t){case 0:case 10:return i?s?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return i?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}class ns{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(is)}(t):is(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Oi(t[0].time)||d(t[0].time)?Ji:Qi}(t))}key(t){return"object"==typeof t&&"od"in t?t.od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i.ad?new Date(1e3*i.od).getTime():new Date(Date.UTC(i.ad.year,i.ad.month-1,i.ad.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?Qi(i):Oi(i)?Ji(i):Ji(ts(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this._d=new qi({Jc:i,Qc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",td:" ",sd:t.locale}):this._d=new Hi(i,t.locale)}formatHorzItem(t){const i=t;return this._d.c_(new Date(1e3*i.od))}allowsTickMark(t,i){const s=this.Ps.timeScale.tickMarkFilter;if(void 0===s)return!0;const n=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible);return s(t.originalTime,n,i)}formatTickmark(t,i){const s=ss(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible),n=this.Ps.timeScale;if(void 0!==n.tickMarkFormatter){const e=n.tickMarkFormatter(t.originalTime,s,i.locale);if(null!==e)return e}return function(t,i,s){const n={};switch(i){case 0:n.year="numeric";break;case 1:n.month="short";break;case 2:n.day="numeric";break;case 3:n.hour12=!1,n.hour="2-digit",n.minute="2-digit";break;case 4:n.hour12=!1,n.hour="2-digit",n.minute="2-digit",n.second="2-digit"}const e=void 0===t.ad?new Date(1e3*t.od):new Date(Date.UTC(t.ad.year,t.ad.month-1,t.ad.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(t.time,s,i.locale)}maxTickMarkWeight(t){let i=t.reduce(Di,t[0]).weight;return i>30&&i<50&&(i=30),i}fillWeightsForPoints(t,i){!function(t,i=0){if(0===t.length)return;let s=0===i?null:t[i-1].time.od,n=null!==s?new Date(1e3*s):null,e=0;for(let r=i;r<t.length;++r){const i=t[r],h=new Date(1e3*Zi(i.time).od);null!==n&&(i.timeWeight=Ki(h,n)),e+=Zi(i.time).od-(s||Zi(i.time).od),s=Zi(i.time).od,n=h}if(0===i&&t.length>1){const i=Math.ceil(e/(t.length-1)),s=new Date(1e3*(t[0].time.od-i));t[0].timeWeight=Ki(new Date(1e3*t[0].time.od),s)}}(t,i)}static ud(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function es(t){var i=t.width,s=t.height;if(i<0)throw new Error("Negative width is not allowed for Size");if(s<0)throw new Error("Negative height is not allowed for Size");return{width:i,height:s}}function rs(t,i){return t.width===i.width&&t.height===i.height}var hs=function(){function t(t){var i=this;this._resolutionListener=function(){return i._onResolutionChanged()},this._resolutionMediaQueryList=null,this._observers=[],this._window=t,this._installResolutionListener()}return t.prototype.dispose=function(){this._uninstallResolutionListener(),this._window=null},Object.defineProperty(t.prototype,"value",{get:function(){return this._window.devicePixelRatio},enumerable:!1,configurable:!0}),t.prototype.subscribe=function(t){var i=this,s={next:t};return this._observers.push(s),{unsubscribe:function(){i._observers=i._observers.filter(function(t){return t!==s})}}},t.prototype._installResolutionListener=function(){if(null!==this._resolutionMediaQueryList)throw new Error("Resolution listener is already installed");var t=this._window.devicePixelRatio;this._resolutionMediaQueryList=this._window.matchMedia("all and (resolution: ".concat(t,"dppx)")),this._resolutionMediaQueryList.addListener(this._resolutionListener)},t.prototype._uninstallResolutionListener=function(){null!==this._resolutionMediaQueryList&&(this._resolutionMediaQueryList.removeListener(this._resolutionListener),this._resolutionMediaQueryList=null)},t.prototype._reinstallResolutionListener=function(){this._uninstallResolutionListener(),this._installResolutionListener()},t.prototype._onResolutionChanged=function(){var t=this;this._observers.forEach(function(i){return i.next(t._window.devicePixelRatio)}),this._reinstallResolutionListener()},t}();var ls=function(){function t(t,i,s){var n;this._canvasElement=null,this._bitmapSizeChangedListeners=[],this._suggestedBitmapSize=null,this._suggestedBitmapSizeChangedListeners=[],this._devicePixelRatioObservable=null,this._canvasElementResizeObserver=null,this._canvasElement=t,this._canvasElementClientSize=es({width:this._canvasElement.clientWidth,height:this._canvasElement.clientHeight}),this._transformBitmapSize=null!=i?i:function(t){return t},this._allowResizeObserver=null===(n=null==s?void 0:s.allowResizeObserver)||void 0===n||n,this._chooseAndInitObserver()}return t.prototype.dispose=function(){var t,i;if(null===this._canvasElement)throw new Error("Object is disposed");null===(t=this._canvasElementResizeObserver)||void 0===t||t.disconnect(),this._canvasElementResizeObserver=null,null===(i=this._devicePixelRatioObservable)||void 0===i||i.dispose(),this._devicePixelRatioObservable=null,this._suggestedBitmapSizeChangedListeners.length=0,this._bitmapSizeChangedListeners.length=0,this._canvasElement=null},Object.defineProperty(t.prototype,"canvasElement",{get:function(){if(null===this._canvasElement)throw new Error("Object is disposed");return this._canvasElement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"canvasElementClientSize",{get:function(){return this._canvasElementClientSize},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bitmapSize",{get:function(){return es({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=es(t),this.canvasElement.style.width="".concat(this._canvasElementClientSize.width,"px"),this.canvasElement.style.height="".concat(this._canvasElementClientSize.height,"px"),this._invalidateBitmapSize()},t.prototype.subscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeBitmapSizeChanged=function(t){this._bitmapSizeChangedListeners=this._bitmapSizeChangedListeners.filter(function(i){return i!==t})},Object.defineProperty(t.prototype,"suggestedBitmapSize",{get:function(){return this._suggestedBitmapSize},enumerable:!1,configurable:!0}),t.prototype.subscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners.push(t)},t.prototype.unsubscribeSuggestedBitmapSizeChanged=function(t){this._suggestedBitmapSizeChangedListeners=this._suggestedBitmapSizeChangedListeners.filter(function(i){return i!==t})},t.prototype.applySuggestedBitmapSize=function(){if(null!==this._suggestedBitmapSize){var t=this._suggestedBitmapSize;this._suggestedBitmapSize=null,this._resizeBitmap(t),this._emitSuggestedBitmapSizeChanged(t,this._suggestedBitmapSize)}},t.prototype._resizeBitmap=function(t){var i=this.bitmapSize;rs(i,t)||(this.canvasElement.width=t.width,this.canvasElement.height=t.height,this._emitBitmapSizeChanged(i,t))},t.prototype._emitBitmapSizeChanged=function(t,i){var s=this;this._bitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._suggestNewBitmapSize=function(t){var i=this._suggestedBitmapSize,s=es(this._transformBitmapSize(t,this._canvasElementClientSize)),n=rs(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&rs(i,n)||(this._suggestedBitmapSize=n,this._emitSuggestedBitmapSizeChanged(i,n))},t.prototype._emitSuggestedBitmapSizeChanged=function(t,i){var s=this;this._suggestedBitmapSizeChangedListeners.forEach(function(n){return n.call(s,t,i)})},t.prototype._chooseAndInitObserver=function(){var t=this;this._allowResizeObserver?new Promise(function(t){var i=new ResizeObserver(function(s){t(s.every(function(t){return"devicePixelContentBoxSize"in t})),i.disconnect()});i.observe(document.body,{box:"device-pixel-content-box"})}).catch(function(){return!1}).then(function(i){return i?t._initResizeObserver():t._initDevicePixelRatioObservable()}):this._initDevicePixelRatioObservable()},t.prototype._initDevicePixelRatioObservable=function(){var t=this;if(null!==this._canvasElement){var i=os(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new hs(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=os(this._canvasElement);if(null!==s){var n=null!==(i=null===(t=this._devicePixelRatioObservable)||void 0===t?void 0:t.value)&&void 0!==i?i:s.devicePixelRatio,e=this._canvasElement.getClientRects(),r=void 0!==e[0]?function(t,i){return es({width:Math.round(t.left*i+t.width*i)-Math.round(t.left*i),height:Math.round(t.top*i+t.height*i)-Math.round(t.top*i)})}(e[0],n):es({width:this._canvasElementClientSize.width*n,height:this._canvasElementClientSize.height*n});this._suggestNewBitmapSize(r)}}},t.prototype._initResizeObserver=function(){var t=this;null!==this._canvasElement&&(this._canvasElementResizeObserver=new ResizeObserver(function(i){var s=i.find(function(i){return i.target===t._canvasElement});if(s&&s.devicePixelContentBoxSize&&s.devicePixelContentBoxSize[0]){var n=s.devicePixelContentBoxSize[0],e=es({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function os(t){return t.ownerDocument.defaultView}var as=function(){function t(t,i,s){if(0===i.width||0===i.height)throw new TypeError("Rendering target could only be created on a media with positive width and height");if(this._mediaSize=i,0===s.width||0===s.height)throw new TypeError("Rendering target could only be created using a bitmap with positive integer width and height");this._bitmapSize=s,this._context=t}return t.prototype.useMediaCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),this._context.scale(this._horizontalPixelRatio,this._verticalPixelRatio),t({context:this._context,mediaSize:this._mediaSize})}finally{this._context.restore()}},t.prototype.useBitmapCoordinateSpace=function(t){try{return this._context.save(),this._context.setTransform(1,0,0,1,0,0),t({context:this._context,mediaSize:this._mediaSize,bitmapSize:this._bitmapSize,horizontalPixelRatio:this._horizontalPixelRatio,verticalPixelRatio:this._verticalPixelRatio})}finally{this._context.restore()}},Object.defineProperty(t.prototype,"_horizontalPixelRatio",{get:function(){return this._bitmapSize.width/this._mediaSize.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_verticalPixelRatio",{get:function(){return this._bitmapSize.height/this._mediaSize.height},enumerable:!1,configurable:!0}),t}();function _s(t,i){var s=t.canvasElementClientSize;if(0===s.width||0===s.height)return null;var n=t.bitmapSize;if(0===n.width||0===n.height)return null;var e=t.canvasElement.getContext("2d",i);return null===e?null:new as(e,s,n)}const us="undefined"!=typeof window;function cs(){return!!us&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ds(){return!!us&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ps(t){return t+t%2}function fs(t){us&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class vs{constructor(t,i,s){this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.gd=null,this.bd=!1,this.Md=null,this.yd=null,this.Sd=!1,this.xd=!1,this.Cd=!1,this.Pd=null,this.Td=null,this.kd=null,this.Dd=null,this.Rd=null,this.Fd=null,this.Id=null,this.Vd=0,this.Ld=!1,this.Ad=!1,this.Ed=!1,this.Bd=0,this.Od=null,this.Wd=!ds(),this.zd=t=>{this.$d(t)},this.Hd=t=>{if(this.Nd(t)){const i=this.Ud(t);if(++this.vd,this.md&&this.vd>1){const{qd:s}=this.jd(gs(t),this.wd);s<30&&!this.Cd&&this.Yd(i,this.Gd.Xd),this.Kd()}}else{const i=this.Ud(t);if(++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}}},this.tp=t,this.Gd=i,this.Ps=s,this.ip()}m(){null!==this.Pd&&(this.Pd(),this.Pd=null),null!==this.Td&&(this.Td(),this.Td=null),null!==this.Dd&&(this.Dd(),this.Dd=null),null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Fd&&(this.Fd(),this.Fd=null),null!==this.kd&&(this.kd(),this.kd=null),this.sp(),this.Qd()}np(t){this.Dd&&this.Dd();const i=this.ep.bind(this);if(this.Dd=()=>{this.tp.removeEventListener("mousemove",i)},this.tp.addEventListener("mousemove",i),this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.rp),this.Wd=!0}Qd(){null!==this.pd&&clearTimeout(this.pd),this.dd=0,this.pd=null,this.fd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}Kd(){null!==this.md&&clearTimeout(this.md),this.vd=0,this.md=null,this.wd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}ep(t){if(this.Ed||null!==this.yd)return;if(this.Nd(t))return;const i=this.Ud(t);this.Zd(i,this.Gd.hp),this.Wd=!0}lp(t){const i=Ms(t.changedTouches,l(this.Od));if(null===i)return;if(this.Bd=bs(t),null!==this.Id)return;if(this.Ad)return;this.Ld=!0;const s=this.jd(gs(i),l(this.yd)),{op:n,ap:e,qd:r}=s;if(this.Sd||!(r<5)){if(!this.Sd){const t=.5*n,i=e>=t&&!this.Ps._p(),s=t>e&&!this.Ps.up();i||s||(this.Ad=!0),this.Sd=!0,this.Cd=!0,this.sp(),this.Kd()}if(!this.Ad){const s=this.Ud(t,i);this.Yd(s,this.Gd.cp),ws(t)}}}dp(t){if(0!==t.button)return;const i=this.jd(gs(t),l(this.Md)),{qd:s}=i;if(s>=5&&(this.xd=!0,this.Qd()),this.xd){const i=this.Ud(t);this.Zd(i,this.Gd.pp)}}jd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{op:s,ap:n,qd:s+n}}fp(t){let i=Ms(t.changedTouches,l(this.Od));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Od=null,this.Bd=bs(t),this.sp(),this.yd=null,this.Fd&&(this.Fd(),this.Fd=null);const s=this.Ud(t,i);if(this.Yd(s,this.Gd.vp),++this.vd,this.md&&this.vd>1){const{qd:t}=this.jd(gs(i),this.wd);t<30&&!this.Cd&&this.Yd(s,this.Gd.Xd),this.Kd()}else this.Cd||(this.Yd(s,this.Gd.mp),this.Gd.mp&&ws(t));0===this.vd&&ws(t),0===t.touches.length&&this.bd&&(this.bd=!1,ws(t))}$d(t){if(0!==t.button)return;const i=this.Ud(t);if(this.Md=null,this.Ed=!1,this.Rd&&(this.Rd(),this.Rd=null),cs()){this.tp.ownerDocument.documentElement.removeEventListener("mouseleave",this.zd)}if(!this.Nd(t))if(this.Zd(i,this.Gd.wp),++this.dd,this.pd&&this.dd>1){const{qd:s}=this.jd(gs(t),this.fd);s<5&&!this.xd&&this.Zd(i,this.Gd.Jd),this.Qd()}else this.xd||this.Zd(i,this.Gd.gp)}sp(){null!==this.gd&&(clearTimeout(this.gd),this.gd=null)}bp(t){if(null!==this.Od)return;const i=t.changedTouches[0];this.Od=i.identifier,this.Bd=bs(t);const s=this.tp.ownerDocument.documentElement;this.Cd=!1,this.Sd=!1,this.Ad=!1,this.yd=gs(i),this.Fd&&(this.Fd(),this.Fd=null);{const i=this.lp.bind(this),n=this.fp.bind(this);this.Fd=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.sp(),this.gd=setTimeout(this.Mp.bind(this,t),240)}const n=this.Ud(t,i);this.Yd(n,this.Gd.yp),this.md||(this.vd=0,this.md=setTimeout(this.Kd.bind(this),500),this.wd=gs(i))}Sp(t){if(0!==t.button)return;const i=this.tp.ownerDocument.documentElement;cs()&&i.addEventListener("mouseleave",this.zd),this.xd=!1,this.Md=gs(t),this.Rd&&(this.Rd(),this.Rd=null);{const t=this.dp.bind(this),s=this.$d.bind(this);this.Rd=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.Ed=!0,this.Nd(t))return;const s=this.Ud(t);this.Zd(s,this.Gd.xp),this.pd||(this.dd=0,this.pd=setTimeout(this.Qd.bind(this),500),this.fd=gs(t))}ip(){this.tp.addEventListener("mouseenter",this.np.bind(this)),this.tp.addEventListener("touchcancel",this.sp.bind(this));{const t=this.tp.ownerDocument,i=t=>{this.Gd.Cp&&(t.composed&&this.tp.contains(t.composedPath()[0])||t.target&&this.tp.contains(t.target)||this.Gd.Cp())};this.Td=()=>{t.removeEventListener("touchstart",i)},this.Pd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}ds()&&(this.kd=()=>{this.tp.removeEventListener("dblclick",this.Hd)},this.tp.addEventListener("dblclick",this.Hd)),this.tp.addEventListener("mouseleave",this.Pp.bind(this)),this.tp.addEventListener("touchstart",this.bp.bind(this),{passive:!0}),fs(this.tp),this.tp.addEventListener("mousedown",this.Sp.bind(this)),this.Tp(),this.tp.addEventListener("touchmove",()=>{},{passive:!1})}Tp(){void 0===this.Gd.kp&&void 0===this.Gd.Dp&&void 0===this.Gd.Rp||(this.tp.addEventListener("touchstart",t=>this.Fp(t.touches),{passive:!0}),this.tp.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Id&&void 0!==this.Gd.Dp){const i=ms(t.touches[0],t.touches[1])/this.Vd;this.Gd.Dp(this.Id,i),ws(t)}},{passive:!1}),this.tp.addEventListener("touchend",t=>{this.Fp(t.touches)}))}Fp(t){1===t.length&&(this.Ld=!1),2!==t.length||this.Ld||this.bd?this.Ip():this.Vp(t)}Vp(t){const i=this.tp.getBoundingClientRect()||{left:0,top:0};this.Id={ut:(t[0].clientX-i.left+(t[1].clientX-i.left))/2,ct:(t[0].clientY-i.top+(t[1].clientY-i.top))/2},this.Vd=ms(t[0],t[1]),void 0!==this.Gd.kp&&this.Gd.kp(),this.sp()}Ip(){null!==this.Id&&(this.Id=null,void 0!==this.Gd.Rp&&this.Gd.Rp())}Pp(t){if(this.Dd&&this.Dd(),this.Nd(t))return;if(!this.Wd)return;const i=this.Ud(t);this.Zd(i,this.Gd.Lp),this.Wd=!ds()}Mp(t){const i=Ms(t.touches,l(this.Od));if(null===i)return;const s=this.Ud(t,i);this.Yd(s,this.Gd.Ap),this.Cd=!0,this.bd=!0}Nd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:bs(t)<this.Bd+500}Yd(t,i){i&&i.call(this.Gd,t)}Zd(t,i){i&&i.call(this.Gd,t)}Ud(t,i){const s=i||t,n=this.tp.getBoundingClientRect()||{left:0,top:0};return{clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,screenX:s.screenX,screenY:s.screenY,localX:s.clientX-n.left,localY:s.clientY-n.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Ep:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Bp:t.type,Op:s.target,a_:t.view,Wp:()=>{"touchstart"!==t.type&&ws(t)}}}}function ms(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ws(t){t.cancelable&&t.preventDefault()}function gs(t){return{ut:t.pageX,ct:t.pageY}}function bs(t){return t.timeStamp||performance.now()}function Ms(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class ys{constructor(t,i,s){this.zp=null,this.$p=null,this.Hp=!0,this.Np=null,this.Up=t,this.qp=t.jp()[i],this.Yp=t.jp()[s],this.Xp=document.createElement("tr"),this.Xp.style.height="1px",this.Gp=document.createElement("td"),this.Gp.style.position="relative",this.Gp.style.padding="0",this.Gp.style.margin="0",this.Gp.setAttribute("colspan","3"),this.Kp(),this.Xp.appendChild(this.Gp),this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(this.zp=null,this.$p=null)}m(){null!==this.$p&&this.$p.m()}Jp(){return this.Xp}Qp(){return es({width:this.qp.Qp().width,height:1})}tf(){return es({width:this.qp.tf().width,height:1*window.devicePixelRatio})}if(t,i,s){const n=this.tf();t.fillStyle=this.Up.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.Kp(),this.Up.W().layout.panes.enableResize!==this.Hp&&(this.Hp=this.Up.W().layout.panes.enableResize,this.Hp?this.Zp():(null!==this.zp&&(this.Gp.removeChild(this.zp.sf),this.Gp.removeChild(this.zp.nf),this.zp=null),null!==this.$p&&(this.$p.m(),this.$p=null)))}Zp(){const t=document.createElement("div"),i=t.style;i.position="fixed",i.display="none",i.zIndex="49",i.top="0",i.left="0",i.width="100%",i.height="100%",i.cursor="row-resize",this.Gp.appendChild(t);const s=document.createElement("div"),n=s.style;n.position="absolute",n.zIndex="50",n.top="-4px",n.height="9px",n.width="100%",n.backgroundColor="",n.cursor="row-resize",this.Gp.appendChild(s);const e={rp:this.ef.bind(this),Lp:this.rf.bind(this),xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),wp:this.af.bind(this),vp:this.af.bind(this)};this.$p=new vs(s,e,{_p:()=>!1,up:()=>!0}),this.zp={nf:s,sf:t}}Kp(){this.Gp.style.background=this.Up.W().layout.panes.separatorColor}ef(t){null!==this.zp&&(this.zp.nf.style.backgroundColor=this.Up.W().layout.panes.separatorHoverColor)}rf(t){null!==this.zp&&null===this.Np&&(this.zp.nf.style.backgroundColor="")}hf(t){if(null===this.zp)return;const i=this.qp._f().La()+this.Yp._f().La(),s=i/(this.qp.Qp().height+this.Yp.Qp().height),n=30*s;i<=2*n||(this.Np={uf:t.pageY,cf:this.qp._f().La(),df:i-n,pf:i,ff:s,vf:n},this.zp.sf.style.display="block")}lf(t){const i=this.Np;if(null===i)return;const s=(t.pageY-i.uf)*i.ff,n=Xt(i.cf+s,i.vf,i.df);this.qp._f().Aa(n),this.Yp._f().Aa(i.pf-n),this.Up.ti().Ah()}af(t){null!==this.Np&&null!==this.zp&&(this.Np=null,this.zp.sf.style.display="none")}}function Ss(t,i){return t.mf-i.mf}function xs(t,i,s){const n=(t.mf-i.mf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class Cs{constructor(t,i,s,n){this.wf=null,this.gf=null,this.bf=null,this.Mf=null,this.yf=null,this.Sf=0,this.xf=0,this.Cf=t,this.Pf=i,this.Tf=s,this.Mn=n}kf(t,i){if(null!==this.wf){if(this.wf.gt===i)return void(this.wf.mf=t);if(Math.abs(this.wf.mf-t)<this.Mn)return}this.Mf=this.bf,this.bf=this.gf,this.gf=this.wf,this.wf={gt:i,mf:t}}ae(t,i){if(null===this.wf||null===this.gf)return;if(i-this.wf.gt>50)return;let s=0;const n=xs(this.wf,this.gf,this.Pf),e=Ss(this.wf,this.gf),r=[n],h=[e];if(s+=e,null!==this.bf){const t=xs(this.gf,this.bf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.gf,this.bf);if(r.push(t),h.push(i),s+=i,null!==this.Mf){const t=xs(this.bf,this.Mf,this.Pf);if(Math.sign(t)===Math.sign(n)){const i=Ss(this.bf,this.Mf);r.push(t),h.push(i),s+=i}}}}let l=0;for(let t=0;t<r.length;++t)l+=h[t]/s*r[t];Math.abs(l)<this.Cf||(this.yf={mf:t,gt:i},this.xf=l,this.Sf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Tf))}Vu(t){const i=l(this.yf),s=t-i.gt;return i.mf+this.xf*(Math.pow(this.Tf,s)-1)/Math.log(this.Tf)}Iu(t){return null===this.yf||this.Df(t)===this.Sf}Df(t){const i=t-l(this.yf).gt;return Math.min(i,this.Sf)}}class Ps{constructor(t,i){this.Rf=void 0,this.Ff=void 0,this.If=void 0,this.vs=!1,this.Vf=t,this.Lf=i,this.Af()}Tt(){this.Af()}Ef(){this.Rf&&this.Vf.removeChild(this.Rf),this.Ff&&this.Vf.removeChild(this.Ff),this.Rf=void 0,this.Ff=void 0}Bf(){return this.vs!==this.Of()||this.If!==this.Wf()}Wf(){return this.Lf.ti().Ki().tt(this.Lf.W().layout.textColor)>160?"dark":"light"}Of(){return this.Lf.W().layout.attributionLogo}zf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Af(){this.Bf()&&(this.Ef(),this.vs=this.Of(),this.vs&&(this.If=this.Wf(),this.Ff=document.createElement("style"),this.Ff.innerText="a#pipsend-attr-logo{--fill:#13d3c9;position:absolute;left:10px;bottom:10px;height:24px;width:46px;margin:0;padding:0;border:0;z-index:3;opacity:0.8;transition:opacity 0.3s;}a#pipsend-attr-logo:hover{opacity:1;}a#pipsend-attr-logo[data-dark]{--fill:#13d3c9;}",this.Rf=document.createElement("a"),this.Rf.href=`https://pipsend.com${this.zf()}`,this.Rf.title="Powered by Pipsend Charts",this.Rf.id="pipsend-attr-logo",this.Rf.target="_blank",this.Rf.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 155.89"><g><circle cx="220.68" cy="77.94" r="32.86" style="fill: var(--fill);"/><path d="M138.84,77.94c0,12.01-3.69,23.15-10,32.37h42.32v-.22c-6.21-9.17-9.84-20.24-9.84-32.15s3.63-22.97,9.84-32.15v-.22h-42.32c6.3,9.22,10,20.36,10,32.37Z" style="fill: var(--fill);"/><path d="M222.06,0H77.94C34.9,0,0,34.9,0,77.94h0c0,43.05,34.9,77.94,77.94,77.94h144.11c43.05,0,77.94-34.9,77.94-77.94h0C300,34.9,265.1,0,222.06,0ZM279.4,77.94c0,31.75-25.74,57.49-57.49,57.49H78.09c-31.75,0-57.49-25.74-57.49-57.49h0c0-31.75,25.74-57.49,57.49-57.49h143.82c31.75,0,57.49,25.74,57.49,57.49h0Z" style="fill: var(--fill);"/><circle cx="79.33" cy="77.94" r="32.86" style="fill: var(--fill);"/></g></svg>',this.Rf.toggleAttribute("data-dark","dark"===this.If),this.Vf.appendChild(this.Ff),this.Vf.appendChild(this.Rf)))}}function Ts(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new ls(s,(e={options:{allowResizeObserver:!0},transform:(t,i)=>({width:Math.max(t.width,i.width),height:Math.max(t.height,i.height)})}).transform,e.options);var e;return n.resizeCanvasElement(i),n}function ks(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function Ds(t,i,s,n){t.nh&&t.nh(i,s,n)}function Rs(t,i,s,n){t.et(i,s,n)}function Fs(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Is(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Vs(t,i,s,n){if(!t.length)return;let e=0;const r=t[0].qt(n,!0);let h=1===i?s/2-(t[0].$i()-r/2):t[0].$i()-r/2-s/2;h=Math.max(0,h);for(let r=1;r<t.length;r++){const l=t[r],o=t[r-1],a=o.qt(n,!1),_=l.$i(),u=o.$i();if(1===i?_>u-a:_<u+a){const n=u-a*i;l.Hi(n);const r=n-i*a/2;if((1===i?r<0:r>s)&&h>0){const n=1===i?-1-r:r-s,l=Math.min(n,h);for(let s=e;s<t.length;s++)t[s].Hi(t[s].$i()+i*l);h-=l}}else e=r,h=1===i?u-a-_:_-(u+a)}}class Ls{constructor(t,i,s,n){this.Yi=null,this.$f=null,this.Hf=!1,this.Nf=new it(200),this.Uf=null,this.qf=0,this.jf=!1,this.Yf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Gf=()=>{this.jf||this.Pt.Xf().ti().ar()},this.Pt=t,this.Ps=i,this.xo=i.layout,this.sc=s,this.Kf="left"===n,this.Zf=Is("normal",n),this.Jf=Is("top",n),this.Qf=Is("bottom",n),this.Gp=document.createElement("div"),this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.Gp.style.width="25px",this.Gp.style.left="0",this.Gp.style.position="relative",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const e=this.tv.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.iv=Ts(this.Gp,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const r=this.iv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={xp:this.hf.bind(this),yp:this.hf.bind(this),pp:this.lf.bind(this),cp:this.lf.bind(this),Cp:this.sv.bind(this),wp:this.af.bind(this),vp:this.af.bind(this),Jd:this.nv.bind(this),Xd:this.nv.bind(this),rp:this.ev.bind(this),Lp:this.rf.bind(this)};this.$p=new vs(this.iv.canvasElement,h,{_p:()=>!this.Ps.handleScroll.vertTouchDrag,up:()=>!0})}m(){this.$p.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Yi&&this.Yi.ra().u(this),this.Yi=null}Jp(){return this.Gp}P(){return this.xo.fontSize}rv(){const t=this.sc.W();return this.Uf!==t.T&&(this.Nf.Vn(),this.Uf=t.T),t}hv(){if(null===this.Yi)return 0;let t=0;const i=this.rv(),s=l(this.tv.canvasElement.getContext("2d",{colorSpace:this.Pt.Xf().W().layout.colorSpace}));s.save();const n=this.Yi.Il();s.font=this.lv(),n.length>0&&(t=Math.max(this.Nf.Ii(s,n[0].Jl),this.Nf.Ii(s,n[n.length-1].Jl)));const e=this.ov();for(let i=e.length;i--;){const n=this.Nf.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.Yi.Bt();if(null!==r&&null!==this.$f&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.Yi.Ds(1,r),n=this.Yi.Ds(this.$f.height-2,r);t=Math.max(t,this.Nf.Ii(s,this.Yi.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.Nf.Ii(s,this.Yi.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ps(Math.ceil(i.S+i.C+i.V+i.L+5+o))}av(t){null!==this.$f&&rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`)}_v(){return l(this.$f).width}us(t){this.Yi!==t&&(null!==this.Yi&&this.Yi.ra().u(this),this.Yi=t,t.ra().i(this.do.bind(this),this))}$t(){return this.Yi}Vn(){const t=this.Pt._f();this.Pt.Xf().ti().Ja(t,l(this.$t()))}uv(t){if(null===this.$f)return;const i={colorSpace:this.Pt.Xf().W().layout.colorSpace};if(1!==t){this.cv(),this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)}),this.Pt.fv(t,this.Qf),this.vv(t),this.Pt.fv(t,this.Zf),this.mv(t))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.wv(s),this.Pt.fv(s,this.Jf))}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.Yi?.Il()}hf(t){if(null===this.Yi||this.Yi.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!0,i.qa(s,this.Yi,t.localY)}lf(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f(),n=this.Yi;i.ja(s,n,t.localY)}sv(){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Xf().ti(),i=this.Pt._f(),s=this.Yi;this.Hf&&(this.Hf=!1,t.Ya(i,s))}af(t){if(null===this.Yi||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Xf().ti(),s=this.Pt._f();this.Hf=!1,i.Ya(s,this.Yi)}nv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}ev(t){if(null===this.Yi)return;!this.Pt.Xf().ti().W().handleScale.axisPressedMouseMove.price||this.Yi.Oe()||this.Yi.Lo()||this.gv(1)}rf(t){this.gv(0)}ov(){const t=[],i=null===this.Yi?void 0:this.Yi;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt._f(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt._f().Ft()),t}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt._f().ti(),r=e.q(),h=e.Uc();r===h?V(t,0,0,s,n,r):E(t,0,0,s,n,r,h)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.$f||null===this.Yi||!this.Yi.W().borderVisible)return;t.fillStyle=this.Yi.W().borderColor;const n=Math.max(1,Math.floor(this.rv().S*s));let e;e=this.Kf?i.width-n:0,t.fillRect(e,0,n,i.height)}vv(t){if(null===this.$f||null===this.Yi)return;const i=this.Yi.Il(),s=this.Yi.W(),n=this.rv(),e=this.Kf?this.$f.width-n.C:0;s.borderVisible&&s.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:h})=>{t.fillStyle=s.borderColor;const l=Math.max(1,Math.floor(h)),o=Math.floor(.5*h),a=Math.round(n.C*r);t.beginPath();for(const s of i)t.rect(Math.floor(e*r),Math.round(s.Tl*h)-o,a,l);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{t.font=this.lv(),t.fillStyle=s.textColor??this.xo.textColor,t.textAlign=this.Kf?"right":"left",t.textBaseline="middle";const r=this.Kf?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.Nf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}cv(){if(null===this.$f||null===this.Yi)return;let t=this.$f.height/2;const i=[],s=this.Yi.Ft().slice(),n=this.Pt._f(),e=this.rv();this.Yi===n.qn()&&this.Pt._f().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.Yi.yl()[0],h=this.Yi;s.forEach(s=>{const e=s.Hs(n,h);e.forEach(t=>{t.Hi(null),t.Ni()&&i.push(t)}),r===s&&e.length>0&&(t=e[0].Li())}),i.forEach(t=>t.Hi(t.Li()));this.Yi.W().alignLabels&&this.bv(i,e,t)}bv(t,i,s){if(null===this.$f)return;const n=t.filter(t=>t.Li()<=s),e=t.filter(t=>t.Li()>s);n.sort((t,i)=>i.Li()-t.Li()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Li()-i.Li());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Li();n>-t&&n<t&&s.Hi(t),n>this.$f.height-t&&n<this.$f.height+t&&s.Hi(this.$f.height-t)}Vs(n,1,this.$f.height,i),Vs(e,-1,this.$f.height,i)}mv(t){if(null===this.$f)return;const i=this.ov(),s=this.rv(),n=this.Kf?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.Yi)).et(t,s,this.Nf,n)}})}wv(t){if(null===this.$f||null===this.Yi)return;const i=this.Pt.Xf().ti(),s=[],n=this.Pt._f(),e=i.fc().Hs(n,this.Yi);e.length&&s.push(e);const r=this.rv(),h=this.Kf?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.Yi)).et(t,r,this.Nf,h)})})}gv(t){this.Gp.style.cursor=1===t?"ns-resize":"default"}do(){const t=this.hv();this.qf<t&&this.Pt.Xf().ti().Ah(),this.qf=t}lv(){return g(this.xo.fontSize,this.xo.fontFamily)}}function As(t,i){return t.tl?.(i)??[]}function Es(t,i){return t.$s?.(i)??[]}function Bs(t,i){return t.cs?.(i)??[]}function Os(t,i){return t.Zh?.(i)??[]}class Ws{constructor(t,i){this.$f=es({width:0,height:0}),this.Mv=null,this.yv=null,this.Sv=null,this.xv=null,this.Cv=!1,this.Pv=new a,this.Tv=new a,this.kv=0,this.Dv=!1,this.Rv=null,this.Fv=!1,this.Iv=null,this.Vv=null,this.jf=!1,this.Yf=()=>{this.jf||null===this.Lv||this.ss().ar()},this.Gf=()=>{this.jf||null===this.Lv||this.ss().ar()},this.Lf=t,this.Lv=i,this.Lv.s_().i(this.Av.bind(this),this,!0),this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Ev.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Ov=document.createElement("td"),this.Ov.style.padding="0",this.Ev.appendChild(s),this.tv=Ts(s,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const n=this.tv.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.iv=Ts(s,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const e=this.iv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Xp=document.createElement("tr"),this.Xp.appendChild(this.Bv),this.Xp.appendChild(this.Ev),this.Xp.appendChild(this.Ov),this.Wv(),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>null===this.Rv&&!this.Lf.W().handleScroll.vertTouchDrag,up:()=>null===this.Rv&&!this.Lf.W().handleScroll.horzTouchDrag})}m(){null!==this.Mv&&this.Mv.m(),null!==this.yv&&this.yv.m(),this.Sv=null,this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose(),null!==this.Lv&&(this.Lv.s_().u(this),this.Lv.m()),this.$p.m()}_f(){return l(this.Lv)}zv(t){null!==this.Lv&&this.Lv.s_().u(this),this.Lv=t,null!==this.Lv&&this.Lv.s_().i(Ws.prototype.Av.bind(this),this,!0),this.Wv(),this.Lf.jp().indexOf(this)===this.Lf.jp().length-1?(this.Sv=this.Sv??new Ps(this.Ev,this.Lf),this.Sv.Tt()):(this.Sv?.Ef(),this.Sv=null)}Xf(){return this.Lf}Jp(){return this.Xp}Wv(){if(null!==this.Lv&&(this.$v(),0!==this.ss().Xs().length)){if(null!==this.Mv){const t=this.Lv.Na();this.Mv.us(l(t))}if(null!==this.yv){const t=this.Lv.Ua();this.yv.us(l(t))}}}Hv(){null!==this.Mv&&this.Mv.Tt(),null!==this.yv&&this.yv.Tt()}La(){return null!==this.Lv?this.Lv.La():0}Aa(t){this.Lv&&this.Lv.Aa(t)}rp(t){if(!this.Lv)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}xp(t){this.Nv(),this.qv(),this.Uv(t.localX,t.localY,t)}hp(t){if(!this.Lv)return;this.Nv();const i=t.localX,s=t.localY;this.Uv(i,s,t)}gp(t){null!==this.Lv&&(this.Nv(),this.jv(t))}Jd(t){null!==this.Lv&&this.Yv(this.Tv,t)}Xd(t){this.Jd(t)}pp(t){this.Nv(),this.Xv(t),this.Uv(t.localX,t.localY,t)}wp(t){null!==this.Lv&&(this.Nv(),this.Dv=!1,this.Gv(t))}mp(t){null!==this.Lv&&this.jv(t)}Ap(t){if(this.Dv=!0,null===this.Rv){const i={x:t.localX,y:t.localY};this.Kv(i,i,t)}}Lp(t){null!==this.Lv&&(this.Nv(),this.Lv.ti().uc(null),this.Zv())}Jv(){return this.Pv}Qv(){return this.Tv}kp(){this.kv=1,this.ss().ln()}Dp(t,i){if(!this.Lf.W().handleScale.pinch)return;const s=5*(i-this.kv);this.kv=i,this.ss().xc(t.ut,s)}yp(t){this.Dv=!1,this.Fv=null!==this.Rv,this.qv();const i=this.ss().fc();null!==this.Rv&&i.It()&&(this.Iv={x:i.ni(),y:i.ei()},this.Rv={x:t.localX,y:t.localY})}cp(t){if(null===this.Lv)return;const i=t.localX,s=t.localY;if(null!==this.Rv){this.Fv=!1;const n=l(this.Iv),e=n.x+(i-this.Rv.x),r=n.y+(s-this.Rv.y);return void this.Uv(e,r,t)}this.Xv(t)}vp(t){0===this.Xf().W().trackingMode.exitMode&&(this.Fv=!0),this.tm(),this.Gv(t)}Xn(t,i){const s=this.Lv;return null===s?null:Si(s,t,i)}im(t,i){l("left"===i?this.Mv:this.yv).av(es({width:t,height:this.$f.height}))}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Ev.style.width=t.width+"px",this.Ev.style.height=t.height+"px")}sm(){const t=l(this.Lv);t.Ha(t.Na()),t.Ha(t.Ua());for(const i of t.yl())if(t.Un(i)){const s=i.$t();null!==s&&t.Ha(s),i.zs()}for(const i of t.e_())i.zs()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;null!==t&&t.drawImage(n,i,s)}}uv(t){if(0===t)return;if(null===this.Lv)return;t>1&&this.sm(),null!==this.Mv&&this.Mv.uv(t),null!==this.yv&&this.yv.uv(t);const i={colorSpace:this.Lf.W().layout.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const t=_s(this.tv,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.dv(t)}),this.Lv&&(this.nm(t,As),this.rm(t),this.nm(t,Es),this.nm(t,Bs)))}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.hm(s),this.nm(s,Os),this.nm(s,Bs))}lm(){return this.Mv}om(){return this.yv}fv(t,i){this.nm(t,i)}Av(){null!==this.Lv&&this.Lv.s_().u(this),this.Lv=null}jv(t){this.Yv(this.Pv,t)}Yv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().At().fu(s),{x:s,y:n},i)}dv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.ss(),r=e.q(),h=e.Uc();r===h?V(t,0,0,s,n,h):E(t,0,0,s,n,r,h)}rm(t){const i=l(this.Lv),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}hm(t){this.am(t,Es,Rs,this.ss().fc())}nm(t,i){const s=l(this.Lv),n=s.Ft(),e=s.e_();for(const s of e)this.am(t,i,Ds,s);for(const s of n)this.am(t,i,Ds,s);for(const s of e)this.am(t,i,Rs,s);for(const s of n)this.am(t,i,Rs,s)}am(t,i,s,n){const e=l(this.Lv),r=e.ti()._c(),h=null!==r&&r.r_===n,o=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Fs(i,i=>s(i,t,h,o),n,e)}$v(){if(null===this.Lv)return;const t=this.Lf,i=this.Lv.Na().W().visible,s=this.Lv.Ua().W().visible;i||null===this.Mv||(this.Bv.removeChild(this.Mv.Jp()),this.Mv.m(),this.Mv=null),s||null===this.yv||(this.Ov.removeChild(this.yv.Jp()),this.yv.m(),this.yv=null);const n=t.ti().Ac();i&&null===this.Mv&&(this.Mv=new Ls(this,t.W(),n,"left"),this.Bv.appendChild(this.Mv.Jp())),s&&null===this.yv&&(this.yv=new Ls(this,t.W(),n,"right"),this.Ov.appendChild(this.yv.Jp()))}_m(t){return t.Ep&&this.Dv||null!==this.Rv}um(t){return Math.max(0,Math.min(t,this.$f.width-1))}dm(t){return Math.max(0,Math.min(t,this.$f.height-1))}Uv(t,i,s){this.ss().Fc(this.um(t),this.dm(i),s,l(this.Lv))}Zv(){this.ss().Vc()}tm(){this.Fv&&(this.Rv=null,this.Zv())}Kv(t,i,s){this.Rv=t,this.Fv=!1,this.Uv(i.x,i.y,s);const n=this.ss().fc();this.Iv={x:n.ni(),y:n.ei()}}ss(){return this.Lf.ti()}Gv(t){if(!this.Cv)return;const i=this.ss(),s=this._f();if(i.Ka(s,s.ks()),this.xv=null,this.Cv=!1,i.kc(),null!==this.Vv){const t=performance.now(),s=i.At();this.Vv.ae(s.yu(),t),this.Vv.Iu(t)||i.un(this.Vv)}}Nv(){this.Rv=null}qv(){if(!this.Lv)return;if(this.ss().ln(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)l(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Lv.ks().Gi()&&this.ss().At().Gi()}Xv(t){if(null===this.Lv)return;const i=this.ss(),s=i.At();if(s.Gi())return;const n=this.Lf.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.Ep)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Ep))return;const h=this.Lv.ks(),l=performance.now();if(null!==this.xv||this._m(t)||(this.xv={x:t.clientX,y:t.clientY,od:l,pm:t.localX,fm:t.localY}),null!==this.xv&&!this.Cv&&(this.xv.x!==t.clientX||this.xv.y!==t.clientY)){if(t.Ep&&r.touch||!t.Ep&&r.mouse){const t=s.bu();this.Vv=new Cs(.2/t,7/t,.997,15/t),this.Vv.kf(s.yu(),this.xv.od)}else this.Vv=null;h.Gi()||i.Xa(this.Lv,h,t.localY),i.Pc(t.localX),this.Cv=!0}this.Cv&&(h.Gi()||i.Ga(this.Lv,h,t.localY),i.Tc(t.localX),null!==this.Vv&&this.Vv.kf(s.yu(),l))}}class zs{constructor(t,i,s,n,e){this.xt=!0,this.$f=es({width:0,height:0}),this.Yf=()=>this.uv(3),this.Kf="left"===t,this.sc=s.Ac,this.Ps=i,this.vm=n,this.wm=e,this.Gp=document.createElement("div"),this.Gp.style.width="25px",this.Gp.style.height="100%",this.Gp.style.overflow="hidden",this.tv=Ts(this.Gp,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf)}m(){this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Gp}Qp(){return this.$f}av(t){rs(this.$f,t)||(this.$f=t,this.tv.resizeCanvasElement(t),this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.xt=!0)}uv(t){if(t<3&&!this.xt)return;if(0===this.$f.width||0===this.$f.height)return;this.xt=!1,this.tv.applySuggestedBitmapSize();const i=_s(this.tv,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t)})}tf(){return this.tv.bitmapSize}if(t,i,s){const n=this.tf();n.width>0&&n.height>0&&t.drawImage(this.tv.canvasElement,i,s)}pv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.vm())return;t.fillStyle=this.Ps.timeScale.borderColor;const e=Math.floor(this.sc.W().S*s),r=Math.floor(this.sc.W().S*n),h=this.Kf?i.width-e:0;t.fillRect(h,0,e,r)}dv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.wm())}}function $s(t){return i=>i.nl?.(t)??[]}const Hs=$s("normal"),Ns=$s("top"),Us=$s("bottom");class qs{constructor(t,i){this.gm=null,this.bm=null,this.M=null,this.Mm=!1,this.$f=es({width:0,height:0}),this.ym=new a,this.Nf=new it(5),this.jf=!1,this.Yf=()=>{this.jf||this.Lf.ti().ar()},this.Gf=()=>{this.jf||this.Lf.ti().ar()},this.Lf=t,this.u_=i,this.Ps=t.W().layout,this.Rf=document.createElement("tr"),this.Sm=document.createElement("td"),this.Sm.style.padding="0",this.xm=document.createElement("td"),this.xm.style.padding="0",this.Gp=document.createElement("td"),this.Gp.style.height="25px",this.Gp.style.padding="0",this.Cm=document.createElement("div"),this.Cm.style.width="100%",this.Cm.style.height="100%",this.Cm.style.position="relative",this.Cm.style.overflow="hidden",this.Gp.appendChild(this.Cm),this.tv=Ts(this.Cm,es({width:16,height:16})),this.tv.subscribeSuggestedBitmapSizeChanged(this.Yf);const s=this.tv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.iv=Ts(this.Cm,es({width:16,height:16})),this.iv.subscribeSuggestedBitmapSizeChanged(this.Gf);const n=this.iv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Rf.appendChild(this.Sm),this.Rf.appendChild(this.Gp),this.Rf.appendChild(this.xm),this.Pm(),this.Lf.ti().Va().i(this.Pm.bind(this),this),this.$p=new vs(this.iv.canvasElement,this,{_p:()=>!0,up:()=>!this.Lf.W().handleScroll.horzTouchDrag})}m(){this.$p.m(),null!==this.gm&&this.gm.m(),null!==this.bm&&this.bm.m(),this.iv.unsubscribeSuggestedBitmapSizeChanged(this.Gf),ks(this.iv.canvasElement),this.iv.dispose(),this.tv.unsubscribeSuggestedBitmapSizeChanged(this.Yf),ks(this.tv.canvasElement),this.tv.dispose()}Jp(){return this.Rf}Tm(){return this.gm}km(){return this.bm}xp(t){if(this.Mm)return;this.Mm=!0;const i=this.Lf.ti();!i.At().Gi()&&this.Lf.W().handleScale.axisPressedMouseMove.time&&i.Sc(t.localX)}yp(t){this.xp(t)}Cp(){const t=this.Lf.ti();!t.At().Gi()&&this.Mm&&(this.Mm=!1,this.Lf.W().handleScale.axisPressedMouseMove.time&&t.Rc())}pp(t){const i=this.Lf.ti();!i.At().Gi()&&this.Lf.W().handleScale.axisPressedMouseMove.time&&i.Dc(t.localX)}cp(t){this.pp(t)}wp(){this.Mm=!1;const t=this.Lf.ti();t.At().Gi()&&!this.Lf.W().handleScale.axisPressedMouseMove.time||t.Rc()}vp(){this.wp()}Jd(){this.Lf.W().handleScale.axisDoubleClickReset.time&&this.Lf.ti().dn()}Xd(){this.Jd()}rp(){this.Lf.ti().W().handleScale.axisPressedMouseMove.time&&this.gv(1)}Lp(){this.gv(0)}Qp(){return this.$f}Dm(){return this.ym}Rm(t,i,s){rs(this.$f,t)||(this.$f=t,this.jf=!0,this.tv.resizeCanvasElement(t),this.iv.resizeCanvasElement(t),this.jf=!1,this.Gp.style.width=`${t.width}px`,this.Gp.style.height=`${t.height}px`,this.ym.p(t)),null!==this.gm&&this.gm.av(es({width:i,height:t.height})),null!==this.bm&&this.bm.av(es({width:s,height:t.height}))}Fm(){const t=this.Im();return Math.ceil(t.S+t.C+t.P+t.A+t.I+t.Vm)}Tt(){this.Lf.ti().At().Il()}tf(){return this.tv.bitmapSize}if(t,i,s,n){const e=this.tf();if(e.width>0&&e.height>0&&(t.drawImage(this.tv.canvasElement,i,s),n)){const n=this.iv.canvasElement;t.drawImage(n,i,s)}}uv(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.tv.applySuggestedBitmapSize();const s=_s(this.tv,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.dv(t),this.pv(t),this.Lm(s,Us)}),this.vv(s),this.Lm(s,Hs)),null!==this.gm&&this.gm.uv(t),null!==this.bm&&this.bm.uv(t)}this.iv.applySuggestedBitmapSize();const s=_s(this.iv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Am([...this.Lf.ti().Xs(),this.Lf.ti().fc()],s),this.Lm(s,Ns))}Lm(t,i){const s=this.Lf.ti().Xs();for(const n of s)Fs(i,i=>Ds(i,t,!1,void 0),n,void 0);for(const n of s)Fs(i,i=>Rs(i,t,!1,void 0),n,void 0)}dv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.Lf.ti().Uc())}pv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Lf.W().timeScale.borderVisible){t.fillStyle=this.Em();const n=Math.max(1,Math.floor(this.Im().S*s));t.fillRect(0,0,i.width,n)}}vv(t){const i=this.Lf.ti().At(),s=i.Il();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Im(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.Em(),t.fillStyle=this.Em();const r=Math.max(1,Math.floor(i)),h=Math.floor(.5*i);t.beginPath();const l=Math.round(e.C*n);for(let n=s.length;n--;){const e=Math.round(s[n].coord*i);t.rect(e-h,0,r,l)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const i=e.S+e.C+e.A+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.lv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.Bm(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Lf.W().timeScale.allowBoldLabels&&(t.font=this.Om());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Bm(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Bm(t,i,s){const n=this.Nf.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.$f.width&&(i-=Math.abs(this.$f.width-(r+n))),i}Am(t,i){const s=this.Im();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}Em(){return this.Lf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}lv(){return g(this.$(),this.Ps.fontFamily)}Om(){return g(this.$(),this.Ps.fontFamily,"bold")}Im(){null===this.M&&(this.M={S:1,B:NaN,A:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Vm:0});const t=this.M,i=this.lv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.A=3*s/12,t.I=3*s/12,t.Qi=9*s/12,t.B=0,t.Vm=4*s/12,t.Ji.Vn()}return this.M}gv(t){this.Gp.style.cursor=1===t?"ew-resize":"default"}Pm(){const t=this.Lf.ti(),i=t.W();i.leftPriceScale.visible||null===this.gm||(this.Sm.removeChild(this.gm.Jp()),this.gm.m(),this.gm=null),i.rightPriceScale.visible||null===this.bm||(this.xm.removeChild(this.bm.Jp()),this.bm.m(),this.bm=null);const s={Ac:this.Lf.ti().Ac()},n=()=>i.leftPriceScale.borderVisible&&t.At().W().borderVisible,e=()=>t.Uc();i.leftPriceScale.visible&&null===this.gm&&(this.gm=new zs("left",i,s,n,e),this.Sm.appendChild(this.gm.Jp())),i.rightPriceScale.visible&&null===this.bm&&(this.bm=new zs("right",i,s,n,e),this.xm.appendChild(this.bm.Jp()))}}const js=!!us&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!us&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class Ys{constructor(t,i,s){var n;this.Wm=[],this.zm=[],this.$m=0,this.eo=0,this.ya=0,this.Hm=0,this.Nm=0,this.Um=null,this.qm=!1,this.Pv=new a,this.Tv=new a,this.Ju=new a,this.jm=null,this.Ym=null,this.Vf=t,this.Ps=i,this.u_=s,this.Rf=document.createElement("div"),this.Rf.classList.add("tv-lightweight-charts"),this.Rf.style.overflow="hidden",this.Rf.style.direction="ltr",this.Rf.style.width="100%",this.Rf.style.height="100%",(n=this.Rf).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Xm=document.createElement("table"),this.Xm.setAttribute("cellspacing","0"),this.Rf.appendChild(this.Xm),this.Gm=this.Km.bind(this),Xs(this.Ps)&&this.Zm(!0),this.ss=new Ei(this.tc.bind(this),this.Ps,s),this.ti().vc().i(this.Jm.bind(this),this),this.Qm=new qs(this,this.u_),this.Xm.appendChild(this.Qm.Jp());const e=i.autoSize&&this.tw();let r=this.Ps.width,h=this.Ps.height;if(e||0===r||0===h){const i=t.getBoundingClientRect();r=r||i.width,h=h||i.height}this.iw(r,h),this.sw(),t.appendChild(this.Rf),this.nw(),this.ss.At().Eu().i(this.ss.Ah.bind(this.ss),this),this.ss.Va().i(this.ss.Ah.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}jp(){return this.Wm}ew(){return this.Qm}m(){this.Zm(!1),0!==this.$m&&window.cancelAnimationFrame(this.$m),this.ss.vc().u(this),this.ss.At().Eu().u(this),this.ss.Va().u(this),this.ss.m();for(const t of this.Wm)this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();this.Wm=[];for(const t of this.zm)this.rw(t);this.zm=[],l(this.Qm).m(),null!==this.Rf.parentElement&&this.Rf.parentElement.removeChild(this.Rf),this.Ju.m(),this.Pv.m(),this.Tv.m(),this.hw()}iw(t,i,s=!1){if(this.eo===i&&this.ya===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return es({width:i-i%2,height:s-s%2})}(es({width:t,height:i}));this.eo=n.height,this.ya=n.width;const e=this.eo+"px",r=this.ya+"px";l(this.Rf).style.height=e,l(this.Rf).style.width=r,this.Xm.style.height=e,this.Xm.style.width=r,s?this.lw(Y.bn(),performance.now()):this.ss.Ah()}uv(t){void 0===t&&(t=Y.bn());for(let i=0;i<this.Wm.length;i++)this.Wm[i].uv(t.rn(i).sn);this.Ps.timeScale.visible&&this.Qm.uv(t.en())}lr(t){const i=Xs(this.Ps);this.ss.lr(t);const s=Xs(this.Ps);s!==i&&this.Zm(s),t.layout?.panes&&this.ow(),this.nw(),this.aw(t)}Jv(){return this.Pv}Qv(){return this.Tv}vc(){return this.Ju}_w(t=!1){null!==this.Um&&(this.lw(this.Um,performance.now()),this.Um=null);const i=this.uw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.uw(n,t),s}cw(t){if("left"===t&&!this.dw())return 0;if("right"===t&&!this.pw())return 0;if(0===this.Wm.length)return 0;return l("left"===t?this.Wm[0].lm():this.Wm[0].om())._v()}fw(){return this.Ps.autoSize&&null!==this.jm}nf(){return this.Rf}mw(t){this.Ym=t,this.Ym?this.nf().style.setProperty("cursor",t):this.nf().style.removeProperty("cursor")}ww(){return this.Ym}gw(t){return h(this.Wm[t]).Qp()}ow(){this.zm.forEach(t=>{t.Tt()})}aw(t){(void 0!==t.autoSize||!this.jm||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.jm&&this.tw(),!1===t.autoSize&&null!==this.jm&&this.hw(),t.autoSize||void 0===t.width&&void 0===t.height||this.iw(t.width||this.ya,t.height||this.eo))}uw(t,i){let s=0,n=0;const e=this.Wm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Wm.length;r++){const h=this.Wm[r],o=l("left"===s?h.lm():h.om()),a=o.tf();if(null!==t&&o.if(t,n,e,i),e+=a.height,r<this.Wm.length-1){const i=this.zm[r],s=i.tf();null!==t&&i.if(t,n,e),e+=s.height}}};if(this.dw()){r("left",0);s+=l(e.lm()).tf().width}for(let e=0;e<this.Wm.length;e++){const r=this.Wm[e],h=r.tf();if(null!==t&&r.if(t,s,n,i),n+=h.height,e<this.Wm.length-1){const i=this.zm[e],r=i.tf();null!==t&&i.if(t,s,n),n+=r.height}}if(s+=e.tf().width,this.pw()){r("right",s);s+=l(e.om()).tf().width}const h=(i,s,n)=>{l("left"===i?this.Qm.Tm():this.Qm.km()).if(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.Qm.tf();if(null!==t){let r=0;this.dw()&&(h("left",r,n),r=l(e.lm()).tf().width),this.Qm.if(t,r,n,i),r+=s.width,this.pw()&&h("right",r,n)}n+=s.height}return es({width:s,height:n})}bw(){let t=0,i=0,s=0;for(const n of this.Wm)this.dw()&&(i=Math.max(i,l(n.lm()).hv(),this.Ps.leftPriceScale.minimumWidth)),this.pw()&&(s=Math.max(s,l(n.om()).hv(),this.Ps.rightPriceScale.minimumWidth)),t+=n.La();i=ps(i),s=ps(s);const n=this.ya,e=this.eo,r=Math.max(n-i-s,0),h=1*this.zm.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.Qm.Fm(),this.Ps.timeScale.minimumHeight):0;var _;a=(_=a)+_%2;const u=h+a,c=e<u?0:e-u,d=c/t;let p=0;const f=window.devicePixelRatio||1;for(let t=0;t<this.Wm.length;++t){const n=this.Wm[t];n.zv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Wm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.La()*d*f)/f,e=Math.max(h,2),p+=e,n.av(es({width:r,height:e})),this.dw()&&n.im(i,"left"),this.pw()&&n.im(s,"right"),n._f()&&this.ss.mc(n._f(),e)}this.Qm.Rm(es({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ea(r),this.Hm!==i&&(this.Hm=i),this.Nm!==s&&(this.Nm=s)}Zm(t){t?this.Rf.addEventListener("wheel",this.Gm,{passive:!1}):this.Rf.removeEventListener("wheel",this.Gm)}Mw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return js?1/window.devicePixelRatio:1}Km(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.Mw(t),s=i*t.deltaX/100,n=-i*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==n&&this.Ps.handleScale.mouseWheel){const i=Math.sign(n)*Math.min(1,Math.abs(n)),s=t.clientX-this.Rf.getBoundingClientRect().left;this.ti().xc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Cc(-80*s)}lw(t,i){const s=t.en();3===s&&this.yw(),3!==s&&2!==s||(this.Sw(t),this.xw(t,i),this.Qm.Tt(),this.Wm.forEach(t=>{t.Hv()}),3===this.Um?.en()&&(this.Um.mn(t),this.yw(),this.Sw(this.Um),this.xw(this.Um,i),t=this.Um,this.Um=null)),this.uv(t)}xw(t,i){for(const s of t.vn())this.wn(s,i)}Sw(t){const i=this.ss.qs();for(let s=0;s<i.length;s++)t.rn(s).nn&&i[s].Qa()}wn(t,i){const s=this.ss.At();switch(t.an){case 0:s.Ou();break;case 1:s.Wu(t.Ht);break;case 2:s.pn(t.Ht);break;case 3:s.fn(t.Ht);break;case 4:s.Cu();break;case 5:t.Ht.Iu(i)||s.fn(t.Ht.Vu(i))}}tc(t){null!==this.Um?this.Um.mn(t):this.Um=t,this.qm||(this.qm=!0,this.$m=window.requestAnimationFrame(t=>{if(this.qm=!1,this.$m=0,null!==this.Um){const i=this.Um;this.Um=null,this.lw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Iu(t)){this.ti().un(s.Ht);break}}}))}yw(){this.sw()}rw(t){this.Xm.removeChild(t.Jp()),t.m()}sw(){const t=this.ss.qs(),i=t.length,s=this.Wm.length;for(let t=i;t<s;t++){const t=h(this.Wm.pop());this.Xm.removeChild(t.Jp()),t.Jv().u(this),t.Qv().u(this),t.m();const i=this.zm.pop();void 0!==i&&this.rw(i)}for(let n=s;n<i;n++){const i=new Ws(this,t[n]);if(i.Jv().i(this.Cw.bind(this,i),this),i.Qv().i(this.Pw.bind(this,i),this),this.Wm.push(i),n>0){const t=new ys(this,n-1,n);this.zm.push(t),this.Xm.insertBefore(t.Jp(),this.Qm.Jp())}this.Xm.insertBefore(i.Jp(),this.Qm.Jp())}for(let s=0;s<i;s++){const i=t[s],n=this.Wm[s];n._f()!==i?n.zv(i):n.Wv()}this.nw(),this.bw()}Tw(t,i,s,n){const e=new Map;if(null!==t){this.ss.Xs().forEach(i=>{const s=i.Ks().Hr(t);null!==s&&e.set(i,s)})}let r;if(null!==t){const i=this.ss.At().ns(t)?.originalTime;void 0!==i&&(r=i)}const h=this.ti()._c(),l=null!==h&&h.r_ instanceof Ut?h.r_:void 0,o=null!==h&&void 0!==h.h_?h.h_.Gn:void 0,a=this.kw(n);return{Dw:r,Re:t??void 0,Rw:i??void 0,Fw:-1!==a?a:void 0,Iw:l,Vw:e,Lw:o,Aw:s??void 0}}kw(t){let i=-1;if(t)i=this.Wm.indexOf(t);else{const t=this.ti().fc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Cw(t,i,s,n){this.Pv.p(()=>this.Tw(i,s,n,t))}Pw(t,i,s,n){this.Tv.p(()=>this.Tw(i,s,n,t))}Jm(t,i,s){this.mw(this.ti()._c()?.o_??null),this.Ju.p(()=>this.Tw(t,i,s))}nw(){const t=this.Ps.timeScale.visible?"":"none";this.Qm.Jp().style.display=t}dw(){return this.Wm[0]._f().Na().W().visible}pw(){return this.Wm[0]._f().Ua().W().visible}tw(){return"ResizeObserver"in window&&(this.jm=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.iw(i.contentRect.width,i.contentRect.height)}),this.jm.observe(this.Vf,{box:"border-box"}),!0)}hw(){null!==this.jm&&this.jm.disconnect(),this.jm=null}}function Xs(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Gs(t){return void 0===t.open&&void 0===t.value}function Ks(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function Zs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.color&&(r.R=s.color),r}function Js(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.lineColor&&(r.wt=s.lineColor),void 0!==s.topColor&&(r.wr=s.topColor),void 0!==s.bottomColor&&(r.gr=s.bottomColor),r}function Qs(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Dw:n};return void 0!==s.topLineColor&&(r.br=s.topLineColor),void 0!==s.bottomLineColor&&(r.Mr=s.bottomLineColor),void 0!==s.topFillColor1&&(r.yr=s.topFillColor1),void 0!==s.topFillColor2&&(r.Sr=s.topFillColor2),void 0!==s.bottomFillColor1&&(r.Cr=s.bottomFillColor1),void 0!==s.bottomFillColor2&&(r.Pr=s.bottomFillColor2),r}function tn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),e}function sn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Dw:n};return void 0!==s.color&&(e.R=s.color),void 0!==s.borderColor&&(e.Nt=s.borderColor),void 0!==s.wickColor&&(e.mr=s.wickColor),e}function nn(t,i,s,n,e){const r=h(e)(s),l=Math.max(...r),o=Math.min(...r),a=r[r.length-1],_=[a,l,o,a],{time:u,color:c,...d}=s;return{Re:i,gt:t,Ht:_,Dw:n,ne:d,R:c}}function en(t){return void 0!==t.Ht}function rn(t,i){return void 0!==i.customValues&&(t.Ew=i.customValues),t}function hn(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Gs(t)}(n,h)?rn({gt:i,Re:s,Dw:e},n):rn(t(i,s,n,e,r),n)}function ln(t){return{Candlestick:hn(sn),Bar:hn(tn),Area:hn(Js),Baseline:hn(Qs),Histogram:hn(Zs),Line:hn(Zs),Custom:hn(nn)}[t]}function on(t){return{Re:0,Bw:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Ow:i.key(t[0].gt),Ww:i.key(t[t.length-1].gt)}}function _n(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Dw)}),h(i)}class un{constructor(t){this.zw=new Map,this.$w=new Map,this.Hw=new Map,this.Nw=[],this.u_=t}m(){this.zw.clear(),this.$w.clear(),this.Hw.clear(),this.Nw=[]}Uw(t,i){let s=0!==this.zw.size,n=!1;const e=this.$w.get(t);if(void 0!==e)if(1===this.$w.size)s=!1,n=!0,this.zw.clear();else for(const i of this.Nw)i.pointData.Bw.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=ln(t.Rr()),l=t.pl(),o=t.vl();r=i.map((i,r)=>{const a=e(i.time),_=this.u_.key(a);let u=this.zw.get(_);void 0===u&&(u=on(a),this.zw.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.Bw.set(t,c),c})}s&&this.qw(),this.jw(t,r);let h=-1;if(n){const t=[];this.zw.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:_n(i.Bw)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.Yw(t)}return this.Xw(t,h,function(t,i,s){const n=an(t,s),e=an(i,s);if(void 0!==n&&void 0!==e)return{Gw:!1,Oh:n.Ww>=e.Ww&&n.Ow>=e.Ow}}(this.$w.get(t),e,this.u_))}Oc(t){return this.Uw(t,[])}Kw(t,i,s){const n=i;!function(t){void 0===t.Dw&&(t.Dw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.Hw.get(t);if(!s&&void 0!==r&&this.u_.key(e)<this.u_.key(r))throw new Error(`Cannot update oldest data, last time=${r}, new time=${e}`);let h=this.zw.get(this.u_.key(e));if(s&&void 0===h)throw new Error("Cannot update non-existing data point when historicalUpdate is true");const l=void 0===h;void 0===h&&(h=on(e),this.zw.set(this.u_.key(e),h));const o=ln(t.Rr()),a=t.pl(),_=t.vl(),u=o(e,h.Re,i,n.Dw,a,_);h.Bw.set(t,u),s?this.Zw(t,u,h.Re):this.Jw(t,u);const c={Oh:en(u),Gw:s};if(!l)return this.Xw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:_n(h.Bw)},p=yt(this.Nw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.Nw.splice(p,0,d);for(let t=p;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t);return this.u_.fillWeightsForPoints(this.Nw,p),this.Xw(t,p,c)}Qw(t,i){const s=this.$w.get(t);if(void 0===s||i<=0)return[[],this.tg()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.Hw.delete(t):this.Hw.set(t,s[s.length-1].gt);for(const i of n){const s=this.zw.get(this.u_.key(i.gt));if(s&&(s.Bw.delete(t),0===s.Bw.size)){this.zw.delete(this.u_.key(s.Uh)),this.Nw.splice(s.Re,1);for(let t=s.Re;t<this.Nw.length;++t)cn(this.Nw[t].pointData,t)}}return[n,this.Xw(t,this.Nw.length-1,{Gw:!1,Oh:!1})]}Jw(t,i){let s=this.$w.get(t);void 0===s&&(s=[],this.$w.set(t,s));const n=0!==s.length?s[s.length-1]:null;null===n||this.u_.key(i.gt)>this.u_.key(n.gt)?en(i)&&s.push(i):en(i)?s[s.length-1]=i:s.splice(-1,1),this.Hw.set(t,i.gt)}Zw(t,i,s){const n=this.$w.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);en(i)?n[e]=i:n.splice(e,1)}jw(t,i){0!==i.length?(this.$w.set(t,i.filter(en)),this.Hw.set(t,i[i.length-1].gt)):(this.$w.delete(t),this.Hw.delete(t))}qw(){for(const t of this.Nw)0===t.pointData.Bw.size&&this.zw.delete(this.u_.key(t.time))}Yw(t){let i=-1;for(let s=0;s<this.Nw.length&&s<t.length;++s){const n=this.Nw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,cn(e.pointData,s)}if(-1===i&&this.Nw.length!==t.length&&(i=Math.min(this.Nw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)cn(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.Nw=t,i}ig(){if(0===this.$w.size)return null;let t=0;return this.$w.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Xw(t,i,s){const n=this.tg();if(-1!==i)this.$w.forEach((i,e)=>{n.za.set(e,{ne:i,sg:e===t?s:void 0})}),this.$w.has(t)||n.za.set(t,{ne:[],sg:s}),n.At.ng=this.Nw,n.At.eg=i;else{const i=this.$w.get(t);n.za.set(t,{ne:i||[],sg:s})}return n}tg(){return{za:new Map,At:{du:this.ig()}}}}function cn(t,i){t.Re=i,t.Bw.forEach(t=>{t.Re=i})}function dn(t,i){return t.gt<i}function pn(t,i){return i<t.gt}function fn(t,i,s){const n=i.qh(),e=i.yi(),r=yt(t,n,dn),h=St(t,e,pn);if(!s)return{from:r,to:h};let l=r,o=h;return r>0&&r<t.length&&t[r].gt>=n&&(l=r-1),h>0&&h<t.length&&t[h-1].gt<=e&&(o=h+1),{from:l,to:o}}class vn{constructor(t,i,s){this.rg=!0,this.hg=!0,this.lg=!0,this.og=[],this.ag=null,this.Qn=t,this.te=i,this._g=s}Tt(t){this.rg=!0,"data"===t&&(this.hg=!0),"options"===t&&(this.lg=!0)}Dt(){return this.Qn.It()?(this.ug(),null===this.ag?null:this.cg):null}dg(){const t=this.Qn.Fh();this.og=this.og.map(i=>{const s=t.Ir(i.gt);return null===s?i:{...i,...s}})}pg(){this.ag=null}ug(){this.hg&&(this.fg(),this.hg=!1),this.lg&&(this.dg(),this.lg=!1),this.rg&&(this.vg(),this.rg=!1)}vg(){const t=this.Qn.$t(),i=this.te.At();if(this.pg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Or())return;const n=this.Qn.Bt();null!==n&&(this.ag=fn(this.og,s,this._g),this.mg(t,i,n.Ht),this.wg())}}class mn{constructor(t,i){this.gg=t,this.Yi=i}et(t,i,s){this.gg.draw(t,this.Yi,i,s)}}class wn extends vn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.cg=new mn(this.eh.renderer(),i=>{const s=t.Bt();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),bg:i.ne}))}mg(t,i){i.pu(this.og,m(this.ag))}wg(){this.eh.update({bars:this.og.map(gn),barSpacing:this.te.At().bu(),visibleRange:this.ag},this.Qn.W())}}function gn(t){return{x:t.ut,time:t.gt,originalData:t.bg,barColor:t.dr}}const bn={color:"#2196f3"},Mn=(t,i,s)=>{const n=o(s);return new wn(t,i,n)};function yn(t){const i={value:t.Ht[3],time:t.Dw};return void 0!==t.Ew&&(i.customValues=t.Ew),i}function Sn(t){const i=yn(t);return void 0!==t.R&&(i.color=t.R),i}function xn(t){const i=yn(t);return void 0!==t.wt&&(i.lineColor=t.wt),void 0!==t.wr&&(i.topColor=t.wr),void 0!==t.gr&&(i.bottomColor=t.gr),i}function Cn(t){const i=yn(t);return void 0!==t.br&&(i.topLineColor=t.br),void 0!==t.Mr&&(i.bottomLineColor=t.Mr),void 0!==t.yr&&(i.topFillColor1=t.yr),void 0!==t.Sr&&(i.topFillColor2=t.Sr),void 0!==t.Cr&&(i.bottomFillColor1=t.Cr),void 0!==t.Pr&&(i.bottomFillColor2=t.Pr),i}function Pn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Dw};return void 0!==t.Ew&&(i.customValues=t.Ew),i}function Tn(t){const i=Pn(t);return void 0!==t.R&&(i.color=t.R),i}function kn(t){const i=Pn(t),{R:s,Nt:n,mr:e}=t;return void 0!==s&&(i.color=s),void 0!==n&&(i.borderColor=n),void 0!==e&&(i.wickColor=e),i}function Dn(t){return{Area:xn,Line:Sn,Baseline:Cn,Histogram:Sn,Bar:Tn,Candlestick:kn,Custom:Rn}[t]}function Rn(t){const i=t.Dw;return{...t.ne,time:i}}const Fn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},In={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},Vn={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:w,panes:{enableResize:!0,separatorColor:"#E0E3EB",separatorHoverColor:"rgba(178, 181, 189, 0.2)"},attributionLogo:!0,colorSpace:"srgb",colorParsers:[]},Ln={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0,ensureEdgeTickMarksVisible:!1,tickMarkSpacing:2.5},An={rightOffset:0,barSpacing:6,minBarSpacing:.5,maxBarSpacing:0,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0,ignoreWhitespaceIndices:!1};function En(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:Vn,crosshair:Fn,grid:In,overlayPriceScales:{...Ln},leftPriceScale:{...Ln,visible:!1},rightPriceScale:{...Ln,visible:!0},timeScale:An,localization:{locale:us?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class Bn{constructor(t,i,s){this.Up=t,this.Mg=i,this.yg=s??0}applyOptions(t){this.Up.ti().cc(this.Mg,t,this.yg)}options(){return this.Yi().W()}width(){return j(this.Mg)?this.Up.cw(this.Mg):0}setVisibleRange(t){this.setAutoScale(!1),this.Yi().Uo(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.Yi().tr();if(null===s)return null;if(this.Yi().io()){const n=this.Yi().ma(),e=Bi(n);s=oi(s,this.Yi().no()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.je()/n)*n).toFixed(e))}else t=s.qe(),i=s.je();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}Yi(){return l(this.Up.ti().dc(this.Mg,this.yg)).$t}}class On{constructor(t,i,s,n){this.Up=t,this.Pt=s,this.Sg=i,this.xg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Up.ti(),s=i.jc(this.Pt);i.gc(s,t)}getStretchFactor(){return this.Pt.La()}setStretchFactor(t){this.Pt.Aa(t),this.Up.ti().Ah()}paneIndex(){return this.Up.ti().jc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Up.jp().length,"Invalid pane index"),this.Up.ti().Mc(i,t))}getSeries(){return this.Pt.za().map(t=>this.Sg(t))??[]}getHTMLElement(){const t=this.Up.jp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].Jp():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.xg,requestUpdate:()=>this.Pt.ti().Ah()})}detachPrimitive(t){this.Pt.dl(t)}priceScale(t){if(null===this.Pt.Ia(t))throw new Error(`Cannot find price scale with id: ${t}`);return new Bn(this.Up,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Oa(t)}preserveEmptyPane(){return this.Pt.Wa()}addCustomSeries(t,i={},s=0){return this.xg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.xg.addSeries(t,i,this.paneIndex())}}const Wn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class zn{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Cg(){return this.sr}}class $n{constructor(t,i,s,n,e,r){this.Pg=new a,this.Qn=t,this.Tg=i,this.kg=s,this.u_=e,this.xg=n,this.Dg=r}m(){this.Pg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.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)).D_(),s=this.Qn.Ks();if(s.Gi())return null;const n=s.Hr(i.qh(),1),e=s.Hr(i.yi(),-1),r=l(s.Wr()),h=l(s.Gs());if(null!==n&&null!==e&&n.Re>e.Re)return{barsBefore:t.from-r,barsAfter:h-t.to};const o={barsBefore:null===n||n.Re===r?t.from-r:n.Re-r,barsAfter:null===e||e.Re===h?h-t.to:h-e.Re};return null!==n&&null!==e&&(o.from=n.Dw,o.to=e.Dw),o}setData(t){this.u_,this.Qn.Rr(),this.Tg.Rg(this.Qn,t),this.Fg("full")}update(t,i=!1){this.Qn.Rr(),this.Tg.Ig(this.Qn,t,i),this.Fg("update")}pop(t=1){const i=this.Tg.Vg(this.Qn,t);0!==i.length&&this.Fg("update");const s=Dn(this.seriesType());return i.map(t=>s(t))}dataByIndex(t,i){const s=this.Qn.Ks().Hr(t,i);if(null===s)return null;return Dn(this.seriesType())(s)}data(){const t=Dn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Pg.i(t)}unsubscribeDataChanged(t){this.Pg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.kg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(Wn),t),s=this.Qn.zh(i);return new zn(s)}removePriceLine(t){this.Qn.$h(t.Cg())}priceLines(){return this.Qn.Hh().map(t=>new zn(t))}seriesType(){return this.Qn.Rr()}lastValueData(t){const i=this.Qn.Te(t);return i.ke?{noData:!0}:{noData:!1,price:i.bt,color:i.R}}attachPrimitive(t){this.Qn.cl(t),t.attached&&t.attached({chart:this.xg,series:this,requestUpdate:()=>this.Qn.ti().Ah(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Ah()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Dg(i)}moveToPane(t){this.Qn.ti().Hc(this.Qn,t)}seriesOrder(){const t=this.Qn.ti().Nn(this.Qn);return null===t?-1:t.za().indexOf(this.Qn)}setSeriesOrder(t){const i=this.Qn.ti().Nn(this.Qn);null!==i&&i.i_(this.Qn,t)}Fg(t){this.Pg.v()&&this.Pg.p(t)}}class Hn{constructor(t,i,s){this.Lg=new a,this.W_=new a,this.ym=new a,this.ss=t,this.ph=t.At(),this.Qm=i,this.ph.Lu().i(this.Ag.bind(this)),this.ph.Au().i(this.Eg.bind(this)),this.Qm.Dm().i(this.Bg.bind(this)),this.u_=s}m(){this.ph.Lu().u(this),this.ph.Au().u(this),this.Qm.Dm().u(this),this.Lg.m(),this.W_.m(),this.ym.m()}scrollPosition(){return this.ph.yu()}scrollToPosition(t,i){i?this.ph.Fu(t,1e3):this.ss.fn(t)}scrollToRealTime(){this.ph.Ru()}getVisibleRange(){const t=this.ph.hu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const i={from:this.u_.convertHorzItemToInternal(t.from),to:this.u_.convertHorzItemToInternal(t.to)},s=this.ph._u(i);this.ss.zc(s)}getVisibleLogicalRange(){const t=this.ph.ru();return null===t?null:{from:t.qh(),to:t.yi()}}setVisibleLogicalRange(t){r(t.from<=t.to,"The from index cannot be after the to index."),this.ss.zc(t)}resetTimeScale(){this.ss.dn()}fitContent(){this.ss.Ou()}logicalToCoordinate(t){const i=this.ss.At();return i.Gi()?null:i.jt(t)}coordinateToLogical(t){return this.ph.Gi()?null:this.ph.fu(t)}timeToIndex(t,i){const s=this.u_.convertHorzItemToInternal(t);return this.ph.su(s,i)}timeToCoordinate(t){const i=this.timeToIndex(t,!1);return null===i?null:this.ph.jt(i)}coordinateToTime(t){const i=this.ss.At(),s=i.fu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.Qm.Qp().width}height(){return this.Qm.Qp().height}subscribeVisibleTimeRangeChange(t){this.Lg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Lg._(t)}subscribeVisibleLogicalRangeChange(t){this.W_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.W_._(t)}subscribeSizeChange(t){this.ym.i(t)}unsubscribeSizeChange(t){this.ym._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.bu()}}Ag(){this.Lg.v()&&this.Lg.p(this.getVisibleRange())}Eg(){this.W_.v()&&this.W_.p(this.getVisibleLogicalRange())}Bg(t){this.ym.p(t.width,t.height)}}function Nn(t){return function(t){if(p(t.handleScale)){const i=t.handleScale;t.handleScale={axisDoubleClickReset:{time:i,price:i},axisPressedMouseMove:{time:i,price:i},mouseWheel:i,pinch:i}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:i,axisDoubleClickReset:s}=t.handleScale;p(i)&&(t.handleScale.axisPressedMouseMove={time:i,price:i}),p(s)&&(t.handleScale.axisDoubleClickReset={time:s,price:s})}const i=t.handleScroll;p(i)&&(t.handleScroll={horzTouchDrag:i,vertTouchDrag:i,mouseWheel:i,pressedMouseMove:i})}(t),t}class Un{constructor(t,i,s){this.Og=new Map,this.Wg=new Map,this.zg=new a,this.$g=new a,this.Hg=new a,this.Xu=new WeakMap,this.Ng=new un(i);const n=void 0===s?f(En()):_(f(En()),Nn(s));this.Ug=i,this.Up=new Ys(t,n,i),this.Up.Jv().i(t=>{this.zg.v()&&this.zg.p(this.qg(t()))},this),this.Up.Qv().i(t=>{this.$g.v()&&this.$g.p(this.qg(t()))},this),this.Up.vc().i(t=>{this.Hg.v()&&this.Hg.p(this.qg(t()))},this);const e=this.Up.ti();this.jg=new Hn(e,this.Up.ew(),this.Ug)}remove(){this.Up.Jv().u(this),this.Up.Qv().u(this),this.Up.vc().u(this),this.jg.m(),this.Up.m(),this.Og.clear(),this.Wg.clear(),this.zg.m(),this.$g.m(),this.Hg.m(),this.Ng.m()}resize(t,i,s){this.autoSizeActive()||this.Up.iw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...bn,...t.defaultOptions()},Yg:Mn,Xg:t}))(o(t));return this.Gg(n,i,s)}addSeries(t,i={},s=0){return this.Gg(t,i,s)}removeSeries(t){const i=h(this.Og.get(t)),s=this.Ng.Oc(i);this.Up.ti().Oc(i),this.Kg(s),this.Og.delete(t),this.Wg.delete(i)}Rg(t,i){this.Kg(this.Ng.Uw(t,i))}Ig(t,i,s){this.Kg(this.Ng.Kw(t,i,s))}Vg(t,i){const[s,n]=this.Ng.Qw(t,i);return 0!==s.length&&this.Kg(n),s}subscribeClick(t){this.zg.i(t)}unsubscribeClick(t){this.zg._(t)}subscribeCrosshairMove(t){this.Hg.i(t)}unsubscribeCrosshairMove(t){this.Hg._(t)}subscribeDblClick(t){this.$g.i(t)}unsubscribeDblClick(t){this.$g._(t)}priceScale(t,i=0){return new Bn(this.Up,t,i)}timeScale(){return this.jg}applyOptions(t){this.Up.lr(Nn(t))}options(){return this.Up.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Up.ti().W().crosshair.mode,this.Up.lr({crosshair:{mode:2}})),n=this.Up._w(t)}finally{i||void 0===s||this.Up.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Up.ti().Yc();return i.Oa(t),this.Zg(i)}removePane(t){this.Up.ti().wc(t)}swapPanes(t,i){this.Up.ti().bc(t,i)}autoSizeActive(){return this.Up.fw()}chartElement(){return this.Up.nf()}panes(){return this.Up.ti().qs().map(t=>this.Zg(t))}paneSize(t=0){const i=this.Up.gw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Og.get(s);if(void 0===n)return;const e=this.Up.ti().Nn(n);null!==e&&this.Up.ti().Ic(t,i,e)}clearCrosshairPosition(){this.Up.ti().Vc(!0)}horzBehaviour(){return this.Ug}Gg(i,s={},n=0){r(void 0!==i.Yg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=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.Yg,l=new Ut(this.Up.ti(),i.type,e,h,i.Xg);this.Up.ti().Ec(l,n);const o=new $n(l,this,this,this,this.Ug,t=>this.Zg(t));return this.Og.set(o,l),this.Wg.set(l,o),o}Kg(t){const i=this.Up.ti();i.Lc(t.At.du,t.At.ng,t.At.eg),t.za.forEach((t,i)=>i.lt(t.ne,t.sg)),i.At().Z_(),i.gu()}Jg(t){return h(this.Wg.get(t))}qg(t){const i=new Map;t.Vw.forEach((t,s)=>{const n=s.Rr(),e=Dn(n)(t);if("Custom"!==n)r(Ks(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.Jg(s),e)});const s=void 0!==t.Iw&&this.Wg.has(t.Iw)?this.Jg(t.Iw):void 0;return{time:t.Dw,logical:t.Re,point:t.Rw,paneIndex:t.Fw,hoveredSeries:s,hoveredObjectId:t.Lw,seriesData:i,sourceEvent:t.Aw}}Zg(t){let i=this.Xu.get(t);return i||(i=new On(this.Up,t=>this.Jg(t),t,this),this.Xu.set(t,i)),i}}function qn(t){if(d(t)){const i=document.getElementById(t);return r(null!==i,`Cannot find element in DOM with id=${t}`),i}return t}function jn(t,i,s){const n=qn(t),e=new Un(n,i,s);return i.setOptions(e.options()),e}function Yn(t,i){const s=t.timeScale(),n=i.dataByIndex(Number.MAX_SAFE_INTEGER,-1);if(!n||"number"!=typeof n.time)return null;const e=s.timeToCoordinate(n.time);if(null===e)return null;const r=s.coordinateToLogical(e);if(null===r)return null;const h=i.dataByIndex(r-1,-1);return!h||"number"!=typeof h.time||h.time>=n.time?null:{gt:n.time,Kl:r,Qg:n.time-h.time}}function Xn(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=Yn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.Qg)}function Gn(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=Yn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.Qg,l=n.logicalToCoordinate(h);return null===l?null:l}class Kn extends vn{constructor(t,i){super(t,i,!0)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Yo(this.og,s,m(this.ag))}tb(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.ib(i.Re,s,t,i)})}}function Zn(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]=ie(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 Jn=6;function Qn(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function te(t,i){return{ut:t.ut/i,ct:t.ct/i}}function ie(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=te(Qn(t[s],t[n]),Jn),{ut:r.ut+h.ut,ct:r.ct+h.ct}),Qn(t[s],te(Qn(t[e],t[i]),Jn))]}function se(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class ne extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,nb:r,dt:h,Kt:l,eb:o}=this.ht;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineWidth=h*t.verticalPixelRatio,n(a,l),a.lineJoin="round";const _=this.rb.bind(this);void 0!==r&&Zn(t,i,r,s,e,_,se),o&&function(t,i,s,n,e){if(n.to-n.from<=0)return;const{horizontalPixelRatio:r,verticalPixelRatio:h,context:l}=t;let o=null;const a=Math.max(1,Math.floor(r))%2/2,_=s*h+a;for(let s=n.to-1;s>=n.from;--s){const n=i[s];if(n){const i=e(t,n);i!==o&&(null!==o&&l.fill(),l.beginPath(),l.fillStyle=i,o=i);const s=Math.round(n.ut*r)+a,u=n.ct*h;l.moveTo(s,u),l.arc(s,u,_,0,2*Math.PI)}}l.fill()}(t,i,o,s,_)}}class ee extends ne{rb(t,i){return i.wt}}class re extends Kn{constructor(){super(...arguments),this.cg=new ee}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W(),i={_t:this.og,Kt:t.lineStyle,nb:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.ag,sb:this.te.At().bu()};this.cg.lt(i)}}const he={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new re(t,i)};function le(t,i){return t.weight>i.weight?t:i}function oe(t){return t}class ae{constructor(){this.hb=new a,this.lb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.hb.p(this.ob)),this.ob=0}ab(){return this.hb}m(){this.hb.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.lb(),t=>(t>this.ob&&(this.ob=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this._b(t)}formatTickmark(t){return this._b(t.time)}maxTickMarkWeight(t){return t.reduce(le,t[0]).weight}fillWeightsForPoints(t,i){const s=t=>t%120==0?10:t%60==0?9:t%36==0?8:t%12==0?7:t%6==0?6:t%3==0?5:t%1==0?4:0;for(let n=i;n<t.length;++n)t[n].timeWeight=s(oe(t[n].time));this.ob=t[t.length-1].time,this.lb()}_b(t){if(this.Ps.localization?.timeFormatter)return this.Ps.localization.timeFormatter(t);if(t<12)return`${t}M`;const i=Math.floor(t/12),s=t%12;return 0===s?`${i}Y`:`${i}Y${s}M`}}const _e={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},ue={lastValueVisible:!1,priceLineVisible:!1};class ce extends Un{constructor(t,i){const s=_(_e,i||{}),n=new ae;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={...ue,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(he);let s;function n(n){const e=function(t,i){return{ae:Math.max(0,t.startTimeRange),_e:Math.max(0,t.minimumTimeRange,i||0),ub:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,ub:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,ub:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.ab().i(n)}}function de(t,i){return t.weight>i.weight?t:i}class pe{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(de,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 fe(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 ve extends C{constructor(){super(...arguments),this.ht=null}lt(t){this.ht=t}rt(t){if(null===this.ht)return;const{_t:i,ot:s,sb:e,dt:r,Kt:h,nb:l}=this.ht,o=this.ht.cb??(this.ht.pb?0:t.mediaSize.height);if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,n(a,h),a.lineWidth=1,Zn(t,i,l,s,e,this.fb.bind(this),fe.bind(null,o))}}class me{mb(t,i){const s=this.wb,{gb:n,bb:e,Mb:r,yb:h,cb:l,Sb:o,xb:a}=i;if(void 0===this.Cb||void 0===s||s.gb!==n||s.bb!==e||s.Mb!==r||s.yb!==h||s.cb!==l||s.Sb!==o||s.xb!==a){const{verticalPixelRatio:s}=t,_=l||o>0?s:1,u=o*_,c=a===t.bitmapSize.height?a:a*_,d=(l??0)*_,p=t.context.createLinearGradient(0,u,0,c);if(p.addColorStop(0,n),null!=l){const t=Xt((d-u)/(c-u),0,1);p.addColorStop(t,e),p.addColorStop(t,r)}p.addColorStop(1,h),this.Cb=p,this.wb=i}return this.Cb}}class we extends ve{constructor(){super(...arguments),this.Pb=new me}fb(t,i){const s=this.ht;return this.Pb.mb(t,{gb:i.yr,bb:i.Sr,Mb:i.Cr,yb:i.Pr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class ge extends ne{constructor(){super(...arguments),this.Tb=new me}rb(t,i){const s=this.ht;return this.Tb.mb(t,{gb:i.br,bb:i.br,Mb:i.Mr,yb:i.Mr,cb:s.cb,Sb:s.Sb??0,xb:s.xb??t.bitmapSize.height})}}class be extends Kn{constructor(t,i){super(t,i),this.cg=new x,this.kb=new we,this.Db=new ge,this.cg.nt([this.kb,this.Db])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.Bt();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.At().bu();if(null===this.ag||0===this.og.length)return;let e,r;if(i.relativeGradient){e=this.og[this.ag.from].ct,r=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const i=this.og[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.kb.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineType,cb:s,Sb:e,xb:r,pb:!1,ot:this.ag,sb:n}),this.Db.lt({_t:this.og,dt:i.lineWidth,Kt:i.lineStyle,nb:i.lineVisible?i.lineType:void 0,eb:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,cb:s,Sb:e,xb:r,ot:this.ag,sb:n})}}const Me={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new be(t,i)};class ye extends ve{constructor(){super(...arguments),this.Pb=new me}fb(t,i){return this.Pb.mb(t,{gb:i.wr,bb:"",Mb:"",yb:i.gr,Sb:this.ht?.Sb??0,xb:t.bitmapSize.height})}}class Se extends Kn{constructor(t,i){super(t,i),this.cg=new x,this.Rb=new ye,this.Fb=new ee,this.cg.nt([this.Rb,this.Fb])}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t=this.Qn.W();if(null===this.ag||0===this.og.length)return;let i;if(t.relativeGradient){i=this.og[this.ag.from].ct;for(let t=this.ag.from;t<this.ag.to;t++){const s=this.og[t];s.ct<i&&(i=s.ct)}}this.Rb.lt({nb:t.lineType,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,cb:null,Sb:i,pb:t.invertFilledArea,ot:this.ag,sb:this.te.At().bu()}),this.Fb.lt({nb:t.lineVisible?t.lineType:void 0,_t:this.og,Kt:t.lineStyle,dt:t.lineWidth,ot:this.ag,sb:this.te.At().bu(),eb:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const xe={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Yg:(t,i)=>new Se(t,i)};class Ce extends C{constructor(){super(...arguments),this.Yt=null,this.Ib=0,this.Vb=0}lt(t){this.Yt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;if(this.Ib=this.Lb(i),this.Ib>=2){Math.max(1,Math.floor(i))%2!=this.Ib%2&&this.Ib--}this.Vb=this.Yt.Ab?Math.min(this.Ib,Math.floor(i)):this.Ib;let n=null;const e=this.Vb<=this.Ib&&this.Yt.bu>=Math.floor(1.5*i);for(let r=this.Yt.ot.from;r<this.Yt.ot.to;++r){const h=this.Yt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Vb),o=Math.round(h.ut*i),a=o-l,_=this.Vb,u=a+_-1,c=Math.min(h.Zo,h.Jo),d=Math.max(h.Zo,h.Jo),p=Math.round(c*s)-l,f=Math.round(d*s)+l,v=Math.max(f-p,this.Vb);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Ib);if(e){if(this.Yt.Eb){const i=o-m;let n=Math.max(p,Math.round(h.Ko*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(i,n,a-i,e-n+1)}const i=o+m;let n=Math.max(p,Math.round(h.Qo*s)-l),e=n+_-1;e>p+v-1&&(e=p+v-1,n=e-_+1),t.fillRect(u+1,n,i-u,e-n+1)}}}Lb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.Yt).bu,t)))}}class Pe extends vn{constructor(t,i){super(t,i,!1)}mg(t,i,s){i.pu(this.og,m(this.ag)),t.Go(this.og,s,m(this.ag))}Bb(t,i,s){return{gt:t,Yh:i.Ht[0],Xh:i.Ht[1],Gh:i.Ht[2],Kh:i.Ht[3],ut:NaN,Ko:NaN,Zo:NaN,Jo:NaN,Qo:NaN}}fg(){const t=this.Qn.Fh();this.og=this.Qn.Ks().Ur().map(i=>this.ib(i.Re,i,t))}}class Te extends Pe{constructor(){super(...arguments),this.cg=new Ce}ib(t,i,s){return{...this.Bb(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.At().bu(),Eb:t.openVisible,Ab:t.thinBars,ot:this.ag})}}const ke={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},Yg:(t,i)=>new Te(t,i)};class De extends C{constructor(){super(...arguments),this.Yt=null,this.Ib=0}lt(t){this.Yt=t}rt(t){if(null===this.Yt||0===this.Yt.Ks.length||null===this.Yt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Ib=function(t,i){if(t>=2.5&&t<=4)return Math.floor(3*i);const s=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),n=Math.floor(t*s*i),e=Math.floor(t*i),r=Math.min(n,e);return Math.max(Math.floor(i),r)}(this.Yt.bu,i),this.Ib>=2){Math.floor(i)%2!=this.Ib%2&&this.Ib--}const s=this.Yt.Ks;this.Yt.Ob&&this.Wb(t,s,this.Yt.ot),this.Yt.Mi&&this.pv(t,s,this.Yt.ot);const n=this.zb(i);(!this.Yt.Mi||this.Ib>2*n)&&this.$b(t,s,this.Yt.ot)}Wb(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.Yt.bu*e));l=Math.max(Math.floor(e),Math.min(l,this.Ib));const o=Math.floor(.5*l);let a=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.vr!==h&&(n.fillStyle=s.vr,h=s.vr);const _=Math.round(Math.min(s.Ko,s.Qo)*r),u=Math.round(Math.max(s.Ko,s.Qo)*r),c=Math.round(s.Zo*r),d=Math.round(s.Jo*r);let p=Math.round(e*s.ut)-o;const f=p+l-1;null!==a&&(p=Math.max(a+1,p),p=Math.min(p,f));const v=f-p+1;n.fillRect(p,c,v,_-c),n.fillRect(p,u+1,v,d-u),a=f}}zb(t){let i=Math.floor(1*t);this.Ib<=2*i&&(i=Math.floor(.5*(this.Ib-1)));const s=Math.max(Math.floor(t),i);return this.Ib<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}pv(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);let o=null;for(let t=s.from;t<s.to;t++){const s=i[t];s.pr!==h&&(n.fillStyle=s.pr,h=s.pr);let a=Math.round(s.ut*e)-Math.floor(.5*this.Ib);const _=a+this.Ib-1,u=Math.round(Math.min(s.Ko,s.Qo)*r),c=Math.round(Math.max(s.Ko,s.Qo)*r);if(null!==o&&(a=Math.max(o+1,a),a=Math.min(a,_)),this.Yt.bu*e>2*l)I(n,a,u,_-a+1,c-u+1,l);else{const t=_-a+1;n.fillRect(a,u,t,c-u+1)}o=_}}$b(t,i,s){if(null===this.Yt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.zb(e);for(let t=s.from;t<s.to;t++){const s=i[t];let o=Math.round(Math.min(s.Ko,s.Qo)*r),a=Math.round(Math.max(s.Ko,s.Qo)*r),_=Math.round(s.ut*e)-Math.floor(.5*this.Ib),u=_+this.Ib-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.Yt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class Re extends Pe{constructor(){super(...arguments),this.cg=new De}ib(t,i,s){return{...this.Bb(t,i,s),...s.Fr(t,{Ht:i})}}wg(){const t=this.Qn.W();this.cg.lt({Ks:this.og,bu:this.te.At().bu(),Ob:t.wickVisible,Mi:t.borderVisible,ot:this.ag})}}const Fe={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},Yg:(t,i)=>new Re(t,i)};class Ie extends C{constructor(){super(...arguments),this.Yt=null,this.Hb=[]}lt(t){this.Yt=t,this.Hb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return;this.Hb.length||this.Nb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.Yt.Ub*s)-Math.floor(n/2),r=e+n;for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const h=this.Yt._t[i],l=this.Hb[i-this.Yt.ot.from],o=Math.round(h.ct*s);let a,_;t.fillStyle=h.dr,o<=e?(a=o,_=r):(a=e,_=o-Math.floor(n/2)+n),t.fillRect(l.qh,a,l.yi-l.qh+1,_-a)}}Nb(t){if(null===this.Yt||0===this.Yt._t.length||null===this.Yt.ot)return void(this.Hb=[]);const i=Math.ceil(this.Yt.bu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.Yt.bu*t)-i;this.Hb=new Array(this.Yt.ot.to-this.Yt.ot.from);for(let i=this.Yt.ot.from;i<this.Yt.ot.to;i++){const n=this.Yt._t[i],e=Math.round(n.ut*t);let r,h;if(s%2){const t=(s-1)/2;r=e-t,h=e+t}else{const t=s/2;r=e-t,h=e+t-1}this.Hb[i-this.Yt.ot.from]={qh:r,yi:h,qb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.Yt.ot.from+1;t<this.Yt.ot.to;t++){const s=this.Hb[t-this.Yt.ot.from],n=this.Hb[t-this.Yt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.qb>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.Yt.bu*t);for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi<i.qh&&(i.yi=i.qh);const s=i.yi-i.qh+1;n=Math.min(s,n)}if(i>0&&n<4)for(let t=this.Yt.ot.from;t<this.Yt.ot.to;t++){const i=this.Hb[t-this.Yt.ot.from];i.yi-i.qh+1>n&&(i.qb>i.ee?i.yi-=1:i.qh+=1)}}}class Ve extends Kn{constructor(){super(...arguments),this.cg=new Ie}ib(t,i,s,n){return{...this.tb(t,i),...s.Fr(t,{Ht:n})}}wg(){const t={_t:this.og,bu:this.te.At().bu(),ot:this.ag,Ub:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Bt()).Ht)};this.cg.lt(t)}}const Le={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},Yg:(t,i)=>new Ve(t,i)};class Ae{constructor(t,i){this.Pt=t,this.jb=i,this.Yb()}detach(){this.Pt.detachPrimitive(this.jb)}getPane(){return this.Pt}applyOptions(t){this.jb.lr?.(t)}Yb(){this.Pt.attachPrimitive(this.jb)}}const Ee={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},Be={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class Oe{constructor(t){this.Xb=new Map,this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.Yt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.Yt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.Gb(i,t.text);e>s.width?t.Tu=s.width/e:t.Tu=1,n+=t.lineHeight*t.Tu}let e=0;switch(this.Yt.vertAlign){case"top":e=0;break;case"center":e=Math.max((s.height-n)/2,0);break;case"bottom":e=Math.max(s.height-n,0)}for(const t of this.Yt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.Yt.horzAlign){case"left":i.textAlign="left",n=t.lineHeight/2;break;case"center":i.textAlign="center",n=s.width/2;break;case"right":i.textAlign="right",n=s.width-1-t.lineHeight/2}i.translate(n,e),i.textBaseline="top",i.font=t.T,i.scale(t.Tu,t.Tu),i.fillText(t.text,0,t.Kb),i.restore(),e+=t.lineHeight*t.Tu}})}Gb(t,i){const s=this.Zb(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}Zb(t){let i=this.Xb.get(t);return void 0===i&&(i=new Map,this.Xb.set(t,i)),i}}class We{constructor(t){this.Ps=$e(t)}Tt(t){this.Ps=$e(t)}renderer(){return new Oe(this.Ps)}}function ze(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,Kb:0,Tu:0}}function $e(t){return{...t,lines:t.lines.map(ze)}}function He(t){return{...Be,...t}}function Ne(t){return{...Ee,...t,lines:t.lines?.map(He)??[]}}class Ue{constructor(t){this.Ps=Ne(t),this.Jb=[new We(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.Jb}attached({requestUpdate:t}){this.Qb=t}detached(){this.Qb=void 0}lr(t){this.Ps=Ne({...this.Ps,...t}),this.Qb&&this.Qb()}}const qe={alpha:1,padding:0};class je{constructor(t){this.Yt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.tM(this.Yt,t.mediaSize);s&&this.Yt.iM&&(i.globalAlpha=this.Yt.alpha??1,i.drawImage(this.Yt.iM,s.ut,s.ct,s.ts,s.qt))})}tM(t,i){const{maxHeight:s,maxWidth:n,sM:e,nM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class Ye{constructor(t){this.eM=null,this.rM=0,this.hM=0,this.Ps=t,this.M=Xe(this.Ps,this.eM,this.rM,this.hM)}lM(t){void 0!==t.oM&&(this.rM=t.oM),void 0!==t.aM&&(this.hM=t.aM),void 0!==t._M&&(this.eM=t._M),this.Tt()}uM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Xe(this.Ps,this.eM,this.rM,this.hM)}renderer(){return new je(this.M)}}function Xe(t,i,s,n){return{...t,iM:i,nM:s,sM:n}}function Ge(t){return{...qe,...t}}class Ke{constructor(t,i){this.cM=null,this.dM=t,this.Ps=Ge(i),this.Jb=[new Ye(this.Ps)]}updateAllViews(){this.Jb.forEach(t=>t.Tt())}paneViews(){return this.Jb}attached(t){const{requestUpdate:i}=t;this.pM=i,this.cM=new Image,this.cM.onload=()=>{const t=this.cM?.naturalHeight??1,i=this.cM?.naturalWidth??1;this.Jb.forEach(s=>s.lM({aM:t,oM:i,_M:this.cM})),this.pM&&this.pM()},this.cM.src=this.dM}detached(){this.pM=void 0,this.cM=null}lr(t){this.Ps=Ge({...this.Ps,...t}),this.fM(),this.Qb&&this.Qb()}Qb(){this.pM&&this.pM()}fM(){this.Jb.forEach(t=>t.uM(this.Ps))}}class Ze{constructor(t,i){this.Qn=t,this._h=i,this.Yb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}Yb(){this.Qn.attachPrimitive(this._h)}}const Je={autoScale:!0,zOrder:"normal"};function Qe(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function tr(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return Qe(i,1);case"circle":return Qe(i,.8);case"square":return Qe(i,.7)}}function ir(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(Qe(t,1))}function sr(t){return Math.max(Qe(t,.1),3)}function nr(t,i,s){return i?t:s?Math.ceil(t/2):0}function er(t,i,s,n){const e=(tr("arrowUp",n)-1)/2*s.vM,r=(Kt(n/2)-1)/2*s.vM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function rr(t,i,s,n,e,r){const h=(tr("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 hr(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 lr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class or{constructor(){this.Yt=null,this.Wn=new it,this.mM=new it,this.$=-1,this.H="",this.Uf="",this.wM="",this.gM="normal"}lt(t){this.Yt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Uf=g(t,i),this.wM=g(t,i,"600"),this.Wn.Vn(),this.mM.Vn()),this.gM=s}Xn(t,i){if(null===this.Yt||null===this.Yt.ot)return null;for(let s=this.Yt.ot.from;s<this.Yt.ot.to;s++){const n=this.Yt._t[s];if(n&&_r(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.gM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.Yt&&null!==this.Yt.ot){t.textBaseline="middle";for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=this.Yt._t[n],r=void 0!==e.bM;if(t.font=r?this.wM:this.Uf,void 0!==e.hi){const i=r?this.mM:this.Wn;e.hi.ts=i.Ii(t,e.hi.MM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.bM){const t=void 0!==e.hi?e.hi.ts:0;e.bM.ts=Math.max(t+2*e.bM.yM,e.bM.qt),e.bM.qh=e.ut-e.bM.ts/2}ar(e,t,i,s)}}}}function ar(t,i,s,n){void 0===t.bM?(i.fillStyle=t.R,void 0!==t.hi&&lr(i,t.hi.MM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Or)return;switch(t.SM){case"arrowDown":return void er(!1,i,s,t.Or);case"arrowUp":return void er(!0,i,s,t.Or);case"circle":return void function(t,i,s){const n=(tr("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.vM,0,2*Math.PI,!1),t.fill()}(i,s,t.Or);case"square":return void function(t,i,s){const n=tr("square",s),e=(n-1)*i.vM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.vM,n*i.vM)}(i,s,t.Or);case"tag":return}t.SM}(t,i,function(t,i,s){const n=Math.max(1,Math.floor(i))%2/2;return{ut:Math.round(t.ut*i)+n,ct:t.ct*s,vM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Or)return;(function(t,i){const s=i.xM,n=i.CM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.PM-i.qt/2)*n),l=Math.round((i.PM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.TM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.kM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.kM&&hr(t,o,h,_,u,!0),t.lineTo(r-a,h),t.arcTo(r,h,r,h+a,a),t.lineTo(r,l-a),t.arcTo(r,l,r-a,l,a),"down"===i.kM&&hr(t,o,l,_,u,!1),t.lineTo(e+a,l),t.arcTo(e,l,e,l-a,a),t.lineTo(e,h+a),t.arcTo(e,h,e+a,h,a)):L(t,e,h,r-e,l-h,[a,a,a,a]),t.closePath(),t.fillStyle=i.le,t.fill(),void 0!==i.Nt&&i.Wt>0&&(t.lineWidth=Math.max(1,Math.round(i.Wt*s)),t.strokeStyle=i.Nt,t.stroke()),t.restore()})(s,{ut:t.ut,PM:t.ct,ts:i.ts,qt:i.qt,TM:i.TM,kM:i.kM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,xM:n,CM:e}),void 0!==t.hi&&(s.fillStyle=t.DM??"#FFFFFF",lr(s,t.hi.MM,t.hi.ut,t.hi.ct,n,e))}(t,t.bM,i,s,n)}function _r(t,i,s){return void 0!==t.bM?0!==t.Or&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.kM?i-r-s.TM:i-r,l="down"===s.kM?i+r+s.TM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.bM,i,s):!(void 0===t.hi||!function(t,i,s,n,e,r){const h=n/2;return e>=t&&e<=t+s&&r>=i-h&&r<=i+h}(t.hi.ut,t.hi.ct,t.hi.ts,t.hi.qt,i,s))||function(t,i,s){if(0===t.Or)return!1;switch(t.SM){case"arrowDown":return rr(!0,t.ut,t.ct,t.Or,i,s);case"arrowUp":return rr(!1,t.ut,t.ct,t.Or,i,s);case"circle":return function(t,i,s,n,e){const r=2+tr("circle",s)/2,h=t-n,l=i-e;return Math.sqrt(h*h+l*l)<=r}(t.ut,t.ct,t.Or,i,s);case"square":return function(t,i,s,n,e){const r=tr("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.Or,i,s);case"tag":return!1}}(t,i,s)}function ur(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function cr(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(ur(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=ur(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=ur(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.RM)-o-_,a||(n.RM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.FM)+o+_,a||(n.FM+=l+o+r)}const d={qt:l,TM:o,kM:u,vt:i.borderRadius??6,yM:9*h,qh:0,ts:0};t.Or=l,t.ct=c,t.bM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=ir(d.options().barSpacing)*p,v=f/2;t.Or=f;switch(i.position){case"inBar":case"atPriceMiddle":return t.ct=l(h.priceToCoordinate(_)),void(void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e));case"aboveBar":case"atPriceTop":{const i=c?0:n.RM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.RM+=1.2*e),void(c||(n.RM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.FM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.FM+=1.2*e),void(c||(n.FM+=f+r))}}}class dr{constructor(t,i,s){this.IM=[],this.xt=!0,this.VM=!0,this.Jt=new or,this.be=t,this.Lf=i,this.Yt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.LM();const t=this.Lf.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.Yt),this.Jt}AM(t){this.IM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.VM=!0)}EM(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}LM(){const t=this.Lf.timeScale(),i=this.IM;this.VM&&(this.Yt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Or:0,SM:t.shape,R:t.color,Gn:t.id,BM:t.BM,hi:void 0,DM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,bM:void 0})),this.VM=!1);const s=this.Lf.options().layout;this.Yt.ot=null;const n=t.getVisibleLogicalRange();if(null===n)return;const e=new Ci(Math.floor(n.from),Math.ceil(n.to));if(null===this.be.dataByIndex(0,1))return;if(0===this.Yt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=sr(t.options().barSpacing),a={RM:o,FM:o};this.Yt.ot=fn(this.Yt._t,e,!0);for(let n=this.Yt.ot.from;n<this.Yt.ot.to;n++){const e=i[n];e.time!==h&&(a.RM=o,a.FM=o,h=e.time);const _=this.Yt._t[n];_.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(_.hi={MM:e.text,ut:0,ct:0,ts:0,qt:0});const u=this.be.dataByIndex(e.time,0);null!==u&&cr(_,e,u,a,s.fontSize,o,this.be,this.Lf,r)}this.xt=!1}}function pr(t){return{...Je,...t}}class fr{constructor(t){this.eh=null,this.IM=[],this.OM=[],this.WM=null,this.be=null,this.Lf=null,this.zM=!0,this.$M=null,this.HM=null,this.NM=null,this.UM=!0,this.Ps=pr(t)}attached(t){this.qM(),this.Lf=t.chart,this.be=t.series,this.eh=new dr(this.be,l(this.Lf),this.Ps),this.pM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Fg(t)),this.UM=!0,this.Qb()}Qb(){this.pM&&this.pM()}detached(){this.be&&this.WM&&this.be.unsubscribeDataChanged(this.WM),this.Lf=null,this.be=null,this.eh=null,this.WM=null}AM(t){this.UM=!0,this.IM=t,this.qM(),this.zM=!0,this.HM=null,this.Qb()}jM(){return this.IM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.YM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.XM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=pr({...this.Ps,...t}),this.Qb&&this.Qb()}XM(){const t=l(this.Lf).timeScale().options().barSpacing;if(this.zM||t!==this.NM){if(this.NM=t,this.IM.length>0){const i=sr(t),s=1.5*ir(t)+2*i,n=this.GM();this.$M={above:nr(s,n.aboveBar,n.inBar),below:nr(s,n.belowBar,n.inBar)}}else this.$M=null;this.zM=!1}return this.$M}GM(){return null===this.HM&&(this.HM=this.IM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.HM}qM(){if(!this.UM||!this.Lf||!this.be)return;const t=this.Lf.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.OM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.OM=this.IM.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,BM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Dw:i.time};if("atPriceTop"===i.position||"atPriceBottom"===i.position||"atPriceMiddle"===i.position){if(void 0===i.price)throw new Error(`Price is required for position ${i.position}`);return{...o,position:i.position,price:i.price}}return{...o,position:i.position,price:i.price}}),this.UM=!1}YM(t){this.eh&&(this.qM(),this.eh.AM(this.OM),this.eh.EM(this.Ps),this.eh.Tt(t))}Fg(t){this.UM=!0,this.Qb()}}class vr extends Ze{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.AM(t)}markers(){return this._h.jM()}}function mr(t,i,s){const n=new vr(t,new fr(s??{}));return i&&n.setMarkers(i),n}class wr{constructor(t){this.IM=new Map,this.KM=t}ZM(t,i,s){if(this.JM(i),void 0!==s){const n=window.setTimeout(()=>{this.IM.delete(i),this.QM()},s),e={...t,ty:n,iy:Date.now()+s};this.IM.set(i,e)}else this.IM.set(i,{...t,ty:void 0,iy:void 0});this.QM()}JM(t){const i=this.IM.get(t);i&&void 0!==i.ty&&window.clearTimeout(i.ty),this.IM.delete(t),this.QM()}sy(){for(const[t]of this.IM)this.JM(t)}ny(){const t=Date.now(),i=[];for(const[s,n]of this.IM)!n.iy||n.iy>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.JM(s);return i}ey(t){this.KM=t}QM(){this.KM&&this.KM()}}const gr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class br{constructor(t,i,s,n){this.Yt=t,this.hy=i,this.ly=s,this.oy=n}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=Math.max(1,Math.floor(t.horizontalPixelRatio))%2/2,n=4*t.verticalPixelRatio+s;this.Yt.forEach(e=>{const r=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const h=this._y(e.uy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.uy&&(i.strokeStyle=h,i.lineWidth=Math.floor(2*t.horizontalPixelRatio),i.beginPath(),i.moveTo((e.ut-4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.uy-7*e.uy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.uy)*t.verticalPixelRatio),i.stroke())})})}_y(t){return 0===t?this.hy:t>0?this.oy:this.ly}}class Mr{constructor(t,i,s){this.Yt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.Yt=t.map(t=>{const i=this.be.priceToCoordinate(t.value);if(null===i)return null;return{ut:l(this.ph.timeToCoordinate(t.time)),ct:i,uy:t.sign}}).filter(v)}renderer(){const t=function(t,i){return function(t,i){return"Area"===i}(0,i)?t.lineColor:t.color}(this.be.options(),this.be.seriesType());return new br(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function yr(t,i){return"Line"===i||"Area"===i}class Sr{constructor(t){this.Lf=void 0,this.be=void 0,this.Jb=[],this.u_=null,this.py=new Map,this.vy=new wr(()=>this.Qb()),this.Ps={...gr,...t}}lr(t){this.Ps={...this.Ps,...t},this.Qb()}AM(t){this.vy.sy();const i=this.u_;i&&t.forEach(t=>{this.vy.ZM(t,i.key(t.time))})}jM(){return this.vy.ny()}Qb(){this.pM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Lf=i,this.be=s,this.u_=e;const r=this.be.seriesType();if("Area"!==r&&"Line"!==r)throw new Error("UpDownMarkersPrimitive is only supported for Area and Line series types");this.Jb=[new Mr(this.be,this.Lf.timeScale(),this.Ps)],this.pM=n,this.Qb()}detached(){this.Lf=void 0,this.be=void 0,this.pM=void 0}Xf(){return h(this.Lf)}za(){return h(this.be)}updateAllViews(){this.Jb.forEach(t=>t.Tt(this.jM()))}paneViews(){return this.Jb}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.py.clear();const s=this.u_;s&&t.forEach(t=>{Ks(t)&&yr(0,i)&&this.py.set(s.key(t.time),t.value)}),h(this.be).setData(t)}Tt(t,i){if(!this.be||!this.u_)throw new Error("Primitive not attached to series");const s=this.be.seriesType(),n=this.u_.key(t.time);if(Gs(t)&&this.py.delete(n),Ks(t)&&yr(0,s)){const i=this.py.get(n);i&&this.vy.ZM({time:t.time,value:t.value,sign:xr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}my(){this.vy.sy()}}function xr(t,i){return t===i?0:t-i>0?1:-1}class Cr extends Ze{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.jM()}setMarkers(t){return this._h.AM(t)}clearMarkers(){return this._h.my()}}class Pr{constructor(t,i){this.wy=null,this.gy=[],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.wy=mr(t)}addPosition(t){this.gy.push(t),this.by()}addPositions(t){this.gy.push(...t),this.by()}setPositions(t){this.gy=[...t],this.by()}closePosition(t,i,s){const n=this.gy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.by())}removePosition(t){this.gy=this.gy.filter(i=>i.id!==t),this.by()}clearPositions(){this.gy=[],this.by()}getPositions(){return this.gy}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.by()}My(){const t=[];for(const i of this.gy){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}by(){if(this.wy){const t=this.My();this.wy.setMarkers(t)}}detach(){this.wy&&(this.wy.detach(),this.wy=null),this.gy=[]}}const Tr=new WeakMap;function kr(t){return"string"==typeof t?t:String(t)}function Dr(t,i){return Tr.get(t)?.get(kr(i))}function Rr(t){const i=Tr.get(t);return void 0!==i&&i.size>0}const Fr="rgba(0, 0, 0, 0)";function Ir(t){switch(t.seriesType()){case"Candlestick":return Vr(t,{upColor:Fr,downColor:Fr,borderVisible:!1,wickVisible:!1});case"Bar":return Vr(t,{upColor:Fr,downColor:Fr});case"Line":return Vr(t,{color:Fr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Vr(t,{lineColor:Fr,topColor:Fr,bottomColor:Fr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Vr(t,{topLineColor:Fr,topFillColor1:Fr,topFillColor2:Fr,bottomLineColor:Fr,bottomFillColor1:Fr,bottomFillColor2:Fr,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Vr(t,{color:Fr});default:return Vr(t,{visible:!1})}}function Vr(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 Lr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function Ar(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 Er(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 Br(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 Or(t){return null==t?void 0:t.time}function Wr(t){const{r_:i,Xf:s,yy:n,Sy:e,xy:r,Jl:h}=t,l=t.Cy??[];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=Or(s[s.length-1])===Or(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&&Or(a[a.length-1])===Or(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 zr(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.Py,i.Ty-1,i.ky))}}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 $r{constructor(t,i,s,n){this.Lf=t,this.be=i,this.V_=s,this.Dy=n}draw(t){const i=this.Dy();if(!i.It||i.Ry<=0)return;const s=this.V_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Lf.timeScale();for(let r=1;r<s.length;r++){const h=s[r-1],l=s[r],o=e.timeToCoordinate(h.gt),a=e.timeToCoordinate(l.gt);if(null===o||null===a)continue;const _=this.be.priceToCoordinate(h.Fy),u=this.be.priceToCoordinate(h.Iy),c=this.be.priceToCoordinate(l.Fy),d=this.be.priceToCoordinate(l.Iy);if(null===_||null===u||null===c||null===d)continue;const p=h.Fy>=h.Iy;n.fillStyle=this.Vy(p?i.Ly:i.Ay,i.Ry),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()}})}Vy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Hr{constructor(t,i,s,n){this.Jt=new $r(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function Nr(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 Ur(t){return null!=t&&"number"==typeof t.close}function qr(t){const i=[];let s=null,n=null;for(const e of t){if(!Ur(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 jr{constructor(t){this.Ey=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ey.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.By(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}By(t,i,s,n){const e=i.Oy||i.startTime,r=i.Wy||i.endTime,h=i.R||i.color,l=i.Ry||i.opacity;if(!i||!e||!r)return;const o=this.Ey.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.zy(h,l),t.fillRect(u,d,c-u,p-d)}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Yr{constructor(t){this.Jt=new jr(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const Xr=[{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 Gr{constructor(t,i,s={}){this.$y=[],this.jb=null,this.eh=null,this.Lf=t,this.be=i,this.Ps={sessions:s.sessions||Xr,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.Hy(),this.Ps.enabled&&this.Ny()}Hy(){this.eh=new Yr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}Ny(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Uy()}),this.Uy()}Uy(){this.qy();const t=this.Lf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);this.jy(s),this.pM()}jy(t){if(0!==t.length){for(const i of this.Ps.sessions)this.Yy(i,t);this.Ps.showOverlaps&&this.Xy(t)}}Yy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Gy(i);this.Ky(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.Zy(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.Zy(s,n[n.length-1].time,t)}Xy(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.Jy(e,r);h&&this.Qy(h,t)}}Jy(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}Qy(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Gy(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.tS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.tS(s,n[n.length-1].time)}Zy(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",Oy:t,Wy:i,R:s.color,Ry:s.opacity,iS:s.name};this.$y.push(n)}tS(t,i){const s={an:"overlap",Oy:t,Wy:i,R:this.Ps.overlapColor,Ry:this.Ps.overlapOpacity,iS:"Overlap"};this.$y.push(s)}Ky(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}Gy(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}qy(){this.$y=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Uy():this.qy(),this.pM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Uy(),this.pM()}disable(){this.Ps.enabled=!1,this.qy(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.qy(),this.pM()}getSessionBoxes(){return this.$y}getChart(){return this.Lf}getSeries(){return this.be}pM(){this.jb&&this.jb.updateAllViews?.(),this.Lf.timeScale().applyOptions({})}}class Kr{constructor(t){this.Ey=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Ey.getProfileData();if(!s||0===s.bins.length)return;const n=this.Ey.options(),e=this.Ey.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.sS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.nS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.eS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}sS(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.zy(M,y),t.fillRect(f,v,m,w)}nS(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([])}eS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.zy(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.zy(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([])}zy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Zr{constructor(t){this.Jt=new Kr(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class Jr{constructor(t,i,s={}){this.rS=null,this.hS=new Map,this.jb=null,this.eh=null,this.Lf=t,this.be=i,this.Ps={numberOfBins:s.numberOfBins||24,valueAreaPercentage:s.valueAreaPercentage||.7,showPOC:s.showPOC??!0,showValueArea:s.showValueArea??!0,profileColor:s.profileColor||"#2962FF",pocColor:s.pocColor||"#FF6B00",valueAreaColor:s.valueAreaColor||"#089981",opacity:s.opacity||.3,width:s.width||100,position:s.position||"right"},this.Hy(),this.Ny()}Hy(){this.eh=new Zr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}Ny(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.lS()}),this.lS()}setVolumeData(t){this.hS=t,this.lS()}addVolumeData(t,i){this.hS.set(t,i),this.lS()}lS(){const t=this.Lf.timeScale().getVisibleLogicalRange();if(!t)return;const i=this.be.data();if(!i||0===i.length)return;const s=i.filter((i,s)=>s>=t.from&&s<=t.to);if(0===s.length)return;let n=1/0,e=-1/0;for(const t of s){const i=t.low||t.value||t.close,s=t.high||t.value||t.close;i<n&&(n=i),s>e&&(e=s)}const r=(e-n)/this.Ps.numberOfBins,h=[];for(let t=0;t<this.Ps.numberOfBins;t++)h.push({priceLevel:n+(t+.5)*r,volume:0,percentage:0});let l=0;for(const t of s){const i=t.close||t.value,s=this.hS.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.rS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.pM()}getProfileData(){return this.rS}applyOptions(t){this.Ps={...this.Ps,...t},this.lS(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.rS=null,this.hS.clear(),this.pM()}getChart(){return this.Lf}getSeries(){return this.be}options(){return this.Ps}pM(){this.jb&&this.jb.updateAllViews?.(),this.Lf.timeScale().applyOptions({})}}class Qr{constructor(t,i){this.oS=new Map,this.aS=null,this._S=null,this.uS=null,this.cS=null,this.dS=null,this.pS=null,this.fS=0,this.vS=null,this.yg=void 0,this.Lf=t,this.Rf=i,this.mS=t=>this.wS(t),this.gS=t=>this.bS(t),this.MS=t=>this.yS(t),this.SS=t=>this.xS(t),this.CS=()=>this.PS(),this.TS=t=>{"Escape"===t.key&&this.PS()},this.Lf.subscribeCrosshairMove(this.mS),this.Rf.addEventListener("pointerdown",this.gS),this.Rf.addEventListener("pointermove",this.MS),this.Rf.addEventListener("pointerup",this.SS),this.Rf.addEventListener("pointercancel",this.CS),document.addEventListener("keydown",this.TS)}kS(t){this.oS.set(t.id(),t)}DS(t){const i=t.id();this.aS===i&&this.RS(null),this.uS===t&&this.PS(),this.oS.delete(i)}Gi(){return 0===this.oS.size}m(){this.Lf.unsubscribeCrosshairMove(this.mS),this.Rf.removeEventListener("pointerdown",this.gS),this.Rf.removeEventListener("pointermove",this.MS),this.Rf.removeEventListener("pointerup",this.SS),this.Rf.removeEventListener("pointercancel",this.CS),document.removeEventListener("keydown",this.TS),this.oS.clear()}wS(t){if(this.vS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.yg=t.paneIndex,null!==this.uS)return;const i=this.FS(t.hoveredObjectId),s=null===i?null:this.oS.get(i.gl)??null;this.RS(s?s.id():null),this.IS(s,null===s?null:i?.VS??null),this.LS()}bS(t){const i=null===this.aS?null:this.oS.get(this.aS)??null;i&&(this.dS={ut:t.clientX,ct:t.clientY},this.pS=i,i.isDraggable()&&(this.uS=i,this.cS=t.pointerId,this.Rf.setPointerCapture(t.pointerId),i.beginDrag(),this.fS=this.AS(i,t),this.LS(),t.preventDefault(),t.stopPropagation()))}yS(t){if(null===this.uS)return;if(!this.ES(t))return void this.PS();const i=this.BS(t);null!==i&&this.uS.dragTo(i),t.preventDefault(),t.stopPropagation()}xS(t){const i=this.uS,s=this.pS,n=this.dS;this.OS(),this.pS=null,this.dS=null;const e=null!==n&&(Math.abs(t.clientX-n.ut)>4||Math.abs(t.clientY-n.ct)>4);if(null!==i)return this.uS=null,this.fS=0,e?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),void this.LS();null!==s&&!e&&s.isClickable()&&s.click()}PS(){if(null===this.uS)return;const t=this.uS;this.uS=null,this.fS=0,this.OS(),t.cancelDrag(),this.LS()}ES(t){const i=this.Rf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}OS(){null!==this.cS&&(this.Rf.hasPointerCapture(this.cS)&&this.Rf.releasePointerCapture(this.cS),this.cS=null)}BS(t){const i=this.uS;if(null===i)return null;const s=this.WS(i,t);return null===s?null:i.priceAt(s-this.fS)}WS(t,i){const s=this.Lf.panes()[t.paneIndex()],n=s?s.getHTMLElement():null;return n?i.clientY-n.getBoundingClientRect().top:null!==this.vS&&this.yg===t.paneIndex()?this.vS.ct:null}AS(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.WS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}FS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,VS:null}:{gl:t.slice(0,i),VS:t.slice(i+1)}}IS(t,i){this._S!==i&&(this._S=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}RS(t){this.aS!==t&&(null!==this.aS&&this.oS.get(this.aS)?.setHovered(!1),this.aS=t,this._S=null,null!==t&&this.oS.get(t)?.setHovered(!0))}LS(){if(null!==this.uS)return void this.Lf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.aS?null:this.oS.get(this.aS);t?this.Lf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Lf.chartElement().style.removeProperty("cursor")}}const th=new WeakMap;function ih(t){const i=t.chartElement();if(!i)return null;let s=th.get(t);return s||(s=new Qr(t,i),th.set(t,s)),s}function sh(t,i){const s=th.get(t);s&&(s.DS(i),s.Gi()&&(s.m(),th.delete(t)))}let nh=0;class eh{constructor(t,i,s){this.sr=null,this.zS=!1,this.$S="",this.HS=null,this.Lf=t,this.be=i,this.So="pipsend-trading-line-"+nh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.NS(),(this.Ps.draggable||this.Ps.onClick)&&ih(this.Lf)?.kS(this)}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}isDraggable(){return!0===this.Ps.draggable}isClickable(){return void 0!==this.Ps.onClick}setHovered(t){this.zS!==t&&this.sr&&(this.zS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.$S}))}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.HS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.US(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.HS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.HS;this.HS=null,null!==t&&t!==this.Ps.price&&(this.US(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.$S=t.color),!this.sr)return;const i={title:this.qS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.zS||(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.US(t)}remove(){sh(this.Lf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}qS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}NS(){this.$S=this.Ps.color,this.sr=this.be.createPriceLine({id:this.So,price:this.Ps.price,color:this.Ps.color,lineWidth:this.Ps.lineWidth,lineStyle:this.Ps.lineStyle,axisLabelVisible:this.Ps.axisLabelVisible,title:this.qS()})}US(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.qS()})}}class rh{constructor(t,i){this.Vf=null,this.jS=null,this.YS=null,this.XS={},this.Lf=t,this.be=i,this.GS()}GS(){this.Vf=this.Lf.chartElement()}KS(t){const i=this.be.getPane().getHTMLElement();if(!i)return 0;const s=t.clientY-i.getBoundingClientRect().top,n=this.be.coordinateToPrice(s);return null===n?0:n}enableClickToCreate(t,i){return this.Vf?(this.jS=t,this.XS=i||{},new Promise(t=>{this.Vf.style.cursor="crosshair",this.YS=i=>{const s=this.KS(i),n=this.ZS(s);this.disableClickToCreate(),t(n)},this.Vf.addEventListener("click",this.YS)})):Promise.resolve(null)}disableClickToCreate(){this.Vf&&this.YS&&(this.Vf.removeEventListener("click",this.YS),this.Vf.style.cursor="default"),this.jS=null,this.YS=null,this.XS={}}ZS(t){if(!this.jS)return null;let i;switch(this.jS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.XS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.XS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.XS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.XS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.XS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.XS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.XS};break;default:return null}return new eh(this.Lf,this.be,i)}getCreationMode(){return this.jS}isCreating(){return null!==this.jS}}class hh{constructor(){this.JS=[],this.QS=new Map,this.tx=new Map,this.xt=!0}kS(t){this.QS.has(t)||(this.JS.push(t),this.QS.set(t,[]),this.xt=!0)}DS(t){const i=this.JS.indexOf(t);-1!==i&&this.JS.splice(i,1),this.QS.delete(t),this.xt=!0}Gi(){return 0===this.JS.length}ix(t,i){this.QS.set(t,i),this.xt=!0}sx(t,i){return this.xt&&this.nx(),this.tx.get(lh(t,i))??0}nx(){const t=new Map,i=[];for(const s of this.JS)for(const n of this.QS.get(s)??[]){const e=oh(n.qt),r=n.qt;let h=n.ct;for(const t of[...i].sort(ah))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(lh(s,n.sn),l)}this.tx=t,this.xt=!1}}function lh(t,i){return`${t}:${i}`}function oh(t){return Math.max(9,Math.round(.4*t))}function ah(t,i){return t.ct-i.ct}const _h=new WeakMap;const uh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},ch={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},dh=["takeProfit","entry","stopLoss"];class ph{constructor(){this.Yt=null,this.hx=[],this.lx=0,this.Uf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i){for(const s of this.hx)if(s.ox&&t>=s._x&&t<=s.ux&&Math.abs(i-s.vx)<=s.qt/2)return{sn:s.sn,VS:"close"};for(const s of this.hx)if(t>=s.mx&&t<=s.wx&&Math.abs(i-s.vx)<=s.qt/2)return{sn:s.sn,VS:"body"};for(const t of this.hx)if(Math.abs(i-t.ct)<=8)return{sn:t.sn,VS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.lw(t))}lw(t){const i=this.Yt;if(this.hx=[],null===i||0===i.gx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Uf!==i.T&&(this.Uf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.lx=Math.max(0,n.width-i.yu);const e=i.bx?this.lx:n.width;for(const s of i.gx)this.hx.push(this.Mx(t,i,s,e));i.bx&&i.gx.length>1&&this.yx(t,i),s.restore()}Mx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Sx,o=0===s.xx.length?0:Math.max(this.Wn.Ii(e,s.xx)+2*i.yM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.yM,_=s.ox?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Cx,f=p-l/2;this.Px(t,s,d,c,n),this.Tx(t,i,s,{qh:d,kx:f,ts:u,qt:l});let v=d;return o>0&&(this.Dx(t,i,s,{qh:v,kx:f,ts:o,qt:l}),v+=o,this.Rx(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.DM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.ox&&(this.Rx(e,s.R,v,f,l,r,h),this.Fx(t,i,s,{qh:v,kx:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,vx:p,qt:l,mx:d,wx:c,_x:v,ux:v+_,ox:s.ox}}Px(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.Cx?(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()}Tx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Ix===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),fh(e,n,i.Vx,r,h),e.fillStyle=this.Po.X(i.Z,i.Lx),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}Dx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Ax){const t=i.Wt;e.save(),fh(e,{qh:n.qh+t,kx:n.kx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Vx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Ax?i.Ex:s.R,e.fillText(s.xx,n.qh+n.ts/2,n.kx+n.qt/2),e.restore()}Rx(t,i,s,n,e,r,h){const l=Math.max(1,Math.floor(r));t.save(),t.setLineDash([]),t.fillStyle=this.Po.X(i,.4),t.fillRect(Math.round(s*r),Math.round(n*h),l,Math.round(e*h)),t.restore()}Fx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Ix===s.sn&&"close"===i.Bx){e.save();const t=i.Wt;fh(e,{qh:n.qh,kx:n.kx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Vx-t),r,h,"right"),e.fillStyle=this.Po.X(s.R,.25),e.fill(),e.restore()}const l=(n.qh+n.ts/2)*r,o=(n.kx+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()}yx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.gx.find(t=>"entry"===t.sn)??i.gx[0],h=i.gx.map(t=>t.ct),l=Math.round(this.lx*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.gx)s.beginPath(),s.arc(l,Math.round(t.ct*e),4.5*n,0,2*Math.PI),s.fillStyle="entry"===t.sn?r.R:this.Po.X(i.Z,i.Lx),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function fh(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.kx*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 vh{constructor(){this.Jt=new ph,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 mh{constructor(t){this.Qt=t}coordinate(){return this.Ox()?.Li??-1e3}text(){return this.Ox()?.hi??""}textColor(){return this.Ox()?.DM??"#FFFFFF"}backColor(){return this.Ox()?.R??"#000000"}visible(){return null!==this.Ox()}Ox(){return this.Qt()}}let wh=0;class gh{constructor(t,i,s){this.eh=new vh,this.Po=new S([]),this.Wx=!1,this.zx=null,this._S=null,this.$x=null,this.HS=null,this.Lf=t,this.be=i,this.So="pipsend-position-line-"+wh++,this.Ps=s,this.If={...ch,...s.theme},this.Jb=[this.eh],this.Hx=dh.map(t=>new mh(()=>this.Nx(t))),this.Ux=function(t,i){let s=_h.get(t);return s||(s=new hh,_h.set(t,s)),s.kS(i),s}(this.Lf,this.So),this.be.attachPrimitive(this),ih(this.Lf)?.kS(this)}attached(t){this.pM=t.requestUpdate,this.Wx=!0,this.requestUpdate()}detached(){this.Wx=!1,this.pM=void 0}paneViews(){return this.Jb}priceAxisViews(){return this.Hx}updateAllViews(){this.eh.Tt(this.qx())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.jx(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.VS}`,zOrder:"top",cursorStyle:"close"===s.VS?"pointer":n.draggable??1?"ns-resize":void 0}}id(){return this.So}paneIndex(){try{return this.be.getPane().paneIndex()}catch(t){return 0}}setHoveredPart(t){const[i,s]=null===t?[null,null]:t.split(":"),n=i??null,e=s??null;this.zx===n&&this._S===e||(this.zx=n,this._S=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.zx&&"close"!==this._S&&(this.jx(this.zx)?.draggable??!0)}isClickable(){return"close"===this._S||void 0!==this.Ps.onClick}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}dragAnchorY(){if(null===this.$x)return null;const t=this.jx(this.$x)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.$x=this.zx,null===this.$x)return;const t=this.jx(this.$x)?.price??null;this.HS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.$x,t)}dragTo(t){null!==this.$x&&(this.Yx(this.$x,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.$x,t))}commitDrag(){const t=this.$x;if(this.$x=null,this.HS=null,null===t)return;const i=this.jx(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.$x,i=this.HS;if(this.$x=null,this.HS=null,null===t)return;null!==i&&i!==this.jx(t)?.price&&(this.Yx(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.jx(t)?.price??0)}click(){const t=this.zx;if(null===t)return;if("close"===this._S)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.jx(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.$x,s=null===i?void 0:this.jx(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=bh(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=bh(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.jx(i);null!==t&&(t.price=s)}t.theme&&(this.If={...this.If,...t.theme}),this.requestUpdate()}setPrice(t,i){this.$x!==t&&this.Yx(t,i)}setText(t,i){const s=this.jx(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of dh){const s=this.jx(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){sh(this.Lf,this),function(t,i){const s=_h.get(t);s&&(s.DS(i),s.Gi()&&_h.delete(t))}(this.Lf,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.pM&&this.pM()}Nx(t){const i=this.jx(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??uh[t];return{Li:s,hi:this.be.priceFormatter().format(i.price),R:n,DM:this.Po.K(n).J}}jx(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}Yx(t,i){const s=this.jx(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}qx(){if(!this.Wx||!1===this.Ps.visible)return null;const t=this.Lf.options().layout,i=this.If.fontSize??t.fontSize,s=i+2*this.If.paddingY,n=[],e=[];for(const t of dh){const i=this.jx(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,Cx:0,R:i.color??uh[t],hi:i.formatText?i.formatText(i.price):i.text??"",xx:i.badge??"",Ax:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),ox:i.closable??!0,Xx:i.draggable??!0})}if(0===n.length)return this.Ux.ix(this.So,[]),null;this.Ux.ix(this.So,e);for(const t of n)t.Cx=this.Ux.sx(this.So,t.sn);return{gx:n,Z:this.If.background??(r=t.background,"solid"===r.type?r.color:r.topColor),DM:this.If.textColor,Ex:this.If.badgeTextColor,Vx:this.If.borderRadius,Wt:this.If.borderWidth,yM:this.If.paddingX,Sx:this.If.paddingY,Lx:this.If.backgroundOpacity,T:g(i,this.If.fontFamily??t.fontFamily),P:i,bx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,Ix:this.zx,Bx:this._S};var r}}function bh(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}const Mh=new Set(["line","body","stroke","center","move"]);function yh(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?Mh.has(n)?"move":"grab":void 0}}function Sh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var xh;function Ch(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.Py;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Ty,t.day=i.day??i.ky,t}return t}function Ph(t,i){const s={};return s.price=t,s.time=i,s}function Th(t){if(!t)return Ph(0,null);return Ph(t.price??t.bt??0,Ch(t.time??t.gt??null))}function kh(t,i="time"){return t?t[i]??null:null}function Dh(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"}(xh||(xh={}));class Rh{constructor(t,i,s={}){this._state=xh.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.Gx(),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}Gx(){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 Fh=new WeakMap;function Ih(t,i){Fh.set(t,i)}function Vh(t){const i=!0===Fh.get(t);return i&&Fh.set(t,!1),i}function Lh(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.DM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var Ah;!function(t){t.Kx="idle",t.Zx="waiting_first_point",t.Jx="waiting_second_point",t.Qx="completed"}(Ah||(Ah={}));class Eh{constructor(t,i,s={}){this.Lv=Ah.Kx,this.tC=null,this.YS=null,this.ep=null,this.Lf=t,this.be=i,this.iC=s}sC(){this.Lv===Ah.Kx&&(this.Lv=Ah.Zx,this.tC=null,this.nC(),this.eC())}rC(){this.Lv=Ah.Kx,this.tC=null,this.hC(),this.lC(),this.iC.oC&&this.iC.oC()}aC(){return this.Lv}_C(){return this.Lv===Ah.Zx||this.Lv===Ah.Jx}nC(){this.YS=t=>{this.uC(t)},this.Lf.subscribeClick(this.YS)}eC(){this.ep=t=>{this.cC(t)},this.Lf.subscribeCrosshairMove(this.ep)}hC(){this.YS&&(this.Lf.unsubscribeClick(this.YS),this.YS=null)}lC(){this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null)}uC(t){if(!t.point)return;if(Vh(this.Lf))return;const i=this.be.coordinateToPrice(t.point.y),s=Xn(this.Lf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Lv===Ah.Zx?(this.tC=n,this.Lv=Ah.Jx,this.iC.dC&&this.iC.dC(n)):this.Lv===Ah.Jx&&this.tC&&(this.Lv=Ah.Qx,this.iC.pC&&this.iC.pC(n),this.iC.fC&&this.iC.fC(this.tC,n),this.hC(),this.lC(),this.Lv=Ah.Kx,this.tC=null)}cC(t){if(!t.point)return;if(this.Lv!==Ah.Jx)return;const i=this.be.coordinateToPrice(t.point.y),s=Xn(this.Lf,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.iC.vC&&this.iC.vC(n)}m(){this.rC()}}class Bh{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Oh{constructor(t){this.mC=t,this.Jt=new Bh(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Wh extends Rh{constructor(t,i){super(t,"trend-line",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.xC=null,this.CC=null,this.PC=!1,this.TC=null,this.kC=null,this.DC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.DC),this.Hy(),this.DC.interactive?this.RC():this.PC=!0}RC(){const t=new Eh(this._chart,this._series,{dC:t=>{this.DC.point1Time=t.gt,this.DC.point1Price=t.bt,this.pM()},pC:t=>{this.DC.point2Time=t.gt,this.DC.point2Price=t.bt,this.PC=!0,this.pM(),this.DC.onUpdate&&this.DC.onUpdate()},vC:t=>{this.DC.point1Time&&!this.PC&&(this.kC=t,this.pM())},fC:()=>{this.PC=!0}});this.TC=t,t.sC()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new Oh(this)}VC(){if(!this.DC.point1Time||!this.DC.point2Time)return null;const t=Gn(this._chart,this._series,this.DC.point1Time)??0,i=this._series.priceToCoordinate(this.DC.point1Price)??0,s=Gn(this._chart,this._series,this.DC.point2Time)??0,n=this._series.priceToCoordinate(this.DC.point2Price)??0;if(!this.DC.extendLeft&&!this.DC.extendRight)return{LC:t,AC:i,EC:s,BC:n};if(s===t)return{LC:t,AC:i,EC:s,BC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{LC:this.DC.extendLeft?0:t,AC:this.DC.extendLeft?i-r*t:i,EC:this.DC.extendRight?e:s,BC:this.DC.extendRight?i+r*(e-t):n}}OC(){const t=this.VC();if(null===t)return null;const i=t.EC>=t.LC?t.BC:t.AC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.DC.point2Price??this.DC.point1Price??null}drawToCanvas(t,i,s){if(!this.PC&&this.DC.point1Time&&this.kC)return void this.WC(t,i,s);if(!this.DC.point1Time||!this.DC.point2Time)return;const n=(Gn(this._chart,this._series,this.DC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.DC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.DC.point2Price)??0)*s,l=this.DC.lineColor,o=this.gC?this.DC.lineWidth+1:this.DC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.DC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.DC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.VC();if(null===a)return;t.moveTo(a.LC*i,a.AC*s),t.lineTo(a.EC*i,a.BC*s),t.stroke(),t.setLineDash([]),!this.gC&&!this.bC||this.isLocked()||(this.zC(t,n,e,i,l),this.zC(t,r,h,i,l));const _=this.OC();if(!1!==this.DC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Lh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}WC(t,i,s){if(!this.DC.point1Time||!this.kC)return;const n=(Gn(this._chart,this._series,this.DC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.DC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.kC.gt)??0)*i,h=(this._series.priceToCoordinate(this.kC.bt)??0)*s;t.strokeStyle=this.DC.lineColor,t.lineWidth=this.DC.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.zC(t,n,e,i,this.DC.lineColor),t.globalAlpha=.5,this.zC(t,r,h,i,this.DC.lineColor),t.globalAlpha=1}zC(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.DC.lineColor=t,this.pM()}color(){return this.DC.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}isHovered(){return this.bC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){const s=this.VC();if(null===s)return!1;return this.$C(t,i,s.LC,s.AC,s.EC,s.BC)<=8}$C(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.DC.point1Time||!this.DC.point2Time)return null;const s=Gn(this._chart,this._series,this.DC.point1Time)??0,n=this._series.priceToCoordinate(this.DC.point1Price)??0,e=Gn(this._chart,this._series,this.DC.point2Time)??0,r=this._series.priceToCoordinate(this.DC.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.$C(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.MC=!0,this.yC=t,this.SC=i,"line"===t&&(this.xC={gt:this.DC.point1Time,bt:this.DC.point1Price},this.CC={gt:this.DC.point2Time,bt:this.DC.point2Price})}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.xC=null,this.CC=null}updateDrag(t,i){if(this.MC&&this.yC){if("point1"===this.yC)this.DC.point1Time=t,this.DC.point1Price=i;else if("point2"===this.yC)this.DC.point2Time=t,this.DC.point2Price=i;else if("line"===this.yC&&this.xC&&this.CC){const s=Sh(this.SC,t,i);this.DC.point1Time=this.xC.gt+s.gt,this.DC.point1Price=this.xC.bt+s.bt,this.DC.point2Time=this.CC.gt+s.gt,this.DC.point2Price=this.CC.bt+s.bt}this.pM(),this.DC.onUpdate&&this.DC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Ph(this.DC.point1Price??0,Ch(this.DC.point1Time)),Ph(this.DC.point2Price??0,Ch(this.DC.point2Time))],style:{lineColor:this.DC.lineColor,lineWidth:this.DC.lineWidth,lineStyle:this.DC.lineStyle,extendLeft:this.DC.extendLeft,extendRight:this.DC.extendRight}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return this.PC}remove(){this.TC&&(this.TC.m(),this.TC=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.DC.onRemove&&this.DC.onRemove()}}function zh(t,i){return new Wh(t,i)}class $h{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Hh{constructor(t){this.mC=t,this.Jt=new $h(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Nh extends Rh{constructor(t,i){super(t,"horizontal-line",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.SC=null,this.HC=0,this.NC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.NC),this.Hy()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new Hh(this)}UC(){return void 0===this.NC.startTime?0:Gn(this._chart,this._series,this.NC.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.NC.price)return;const n=(this._series.priceToCoordinate(this.NC.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.UC()*i,h=this.NC.lineColor,l=this.gC?this.NC.lineWidth+1:this.NC.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.NC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.NC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.NC.showPriceLabel&&Lh(t,this._series,i,s,{bt:this.NC.price,ct:n/s,Ot:h}),this.NC.showLabel&&(this.gC||this.bC)&&this.qC(t,n,i,s,h)}qC(t,i,s,n,e){const r=this.NC.labelText||this.NC.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.NC.lineColor=t,this.pM()}color(){return this.NC.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.NC.price)return!1;const s=this._series.priceToCoordinate(this.NC.price)??0;return!(t<this.UC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.MC=!0,this.SC=i,this.HC=this.NC.price??0}stopDrag(){this.MC=!1,this.SC=null}updateDrag(t,i){this.MC&&(this.NC.price=this.HC+Sh(this.SC,t,i).bt,this.pM(),this.NC.onUpdate&&this.NC.onUpdate())}getPrice(){return this.NC.price}setPrice(t){this.NC.price=t,this.pM()}setLabel(t){this.NC.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Ph(this.NC.price??0,Ch(this.NC.startTime))],style:{lineColor:this.NC.lineColor,lineWidth:this.NC.lineWidth,lineStyle:this.NC.lineStyle,showLabel:this.NC.showLabel,labelText:this.NC.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.NC.onRemove&&this.NC.onRemove()}}function Uh(t,i){return new Nh(t,i)}class qh{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class jh{constructor(t){this.mC=t,this.Jt=new qh(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Yh extends Rh{constructor(t,i){super(t,"cross-line",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.SC=null,this.jC=0,this.HC=0,this.YC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.YC),this.Hy()}Hy(){this.eh=new jh(this);const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.wC&&this.wC()}_update(){this.pM()}XC(){if(void 0===this.YC.time||void 0===this.YC.price)return null;const t=Gn(this._chart,this._series,this.YC.time),i=this._series.priceToCoordinate(this.YC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.XC();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.YC.lineColor,_=this.gC||this.bC&&!this.isLocked(),u=_?this.YC.lineWidth+1:this.YC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.YC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.YC.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.YC.showPriceLabel&&void 0!==this.YC.price&&Lh(t,this._series,i,s,{bt:this.YC.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())}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){const s=this.XC();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.MC=!0,this.SC=i,this.jC=this.YC.time,this.HC=this.YC.price??0}updateDrag(t,i){if(!this.MC)return;const s=Sh(this.SC,t,i);this.YC.time=this.jC+s.gt,this.YC.price=this.HC+s.bt,this.pM(),this.YC.onUpdate&&this.YC.onUpdate()}stopDrag(){this.MC=!1,this.SC=null}setColor(t){this.YC.lineColor=t,this.pM()}color(){return this.YC.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}remove(){if(this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.wC=null,this.YC.onRemove&&this.YC.onRemove()}_serializeShape(){return{type:"crossLine",points:[Ph(this.YC.price??0,Ch(this.YC.time))],style:{lineColor:this.YC.lineColor,lineWidth:this.YC.lineWidth,lineStyle:this.YC.lineStyle}}}}function Xh(t,i){return new Yh(t,i)}class Gh{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Kh{constructor(t){this.mC=t,this.Jt=new Gh(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Zh extends Rh{constructor(t,i){super(t,"polygon",i),this.V_=[],this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.GC=null,this.PC=!1,this.kC=null,this.YS=null,this.KC=null,this.ZC=null,this.JC={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.JC),this.V_=[...i.points??[]],this.Hy(),this.JC.interactive?this.QC():this.PC=this.V_.length>=3}Hy(){this.eh=new Kh(this);const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.wC&&this.wC()}_update(){this.pM()}QC(){this.YS=t=>{if(!t.point||Vh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.V_.length>=3&&this.tP(t.point.x,t.point.y)?this.iP():(this.V_.push({time:s,price:i}),this.pM()))},this.KC=t=>{if(!t.point||this.PC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.kC={time:s,price:i},this.pM())},this.ZC=t=>{"Enter"===t.key&&this.V_.length>=3?this.iP():"Escape"===t.key&&(this.V_=[],this.iP())},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.KC),document.addEventListener("keydown",this.ZC)}tP(t,i){const s=this.V_[0],n=Gn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=Zh.sP&&Math.abs(i-e)<=Zh.sP)}iP(){this.PC=!0,this.kC=null,this.nP(),this.pM(),this.JC.onComplete&&this.JC.onComplete(),this.JC.onUpdate&&this.JC.onUpdate()}nP(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.KC&&(this._chart.unsubscribeCrosshairMove(this.KC),this.KC=null),this.ZC&&(document.removeEventListener("keydown",this.ZC),this.ZC=null)}eP(){const t=[...this.V_];return this.PC||null===this.kC||t.push(this.kC),this.rP(t)}rP(t){const i=[];for(const s of t){const t=Gn(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.eP();if(n.length<2)return;const e=this.JC.borderColor,r=this.gC?this.JC.borderWidth+1:this.JC.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.PC&&(t.closePath(),this.JC.fillOpacity>0&&(t.fillStyle=this.Vy(this.JC.fillColor,this.JC.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.PC?"dashed"===this.JC.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.JC.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.gC||this.bC||!this.PC)&&!this.isLocked())for(const n of this.hP())this.lP(t,n.ut*i,n.ct*s,i,e)}hP(){return this.rP(this.V_)}lP(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()}Vy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}IC(t,i){if(!this.isVisible()||!this.PC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){const s=this.hP();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.hP();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.MC=!0,this.yC=t,this.SC=i,this.GC=this.V_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.MC&&null!==this.yC&&null!==this.GC){if("shape"===this.yC){const s=Sh(this.SC,t,i);this.V_=this.GC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.yC;this.V_[s]&&(this.V_[s]={time:t,price:i})}this.pM(),this.JC.onUpdate&&this.JC.onUpdate()}}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.GC=null}setColor(t){this.JC.borderColor=t,this.JC.fillColor=t,this.pM()}color(){return this.JC.borderColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}points(){return this.V_}isComplete(){return this.PC}remove(){if(this.nP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.wC=null,this.JC.onRemove&&this.JC.onRemove()}_serializeShape(){return{type:"polygon",points:this.V_.map(t=>Ph(t.price,Ch(t.time))),style:{fillColor:this.JC.fillColor,fillOpacity:this.JC.fillOpacity,borderColor:this.JC.borderColor,borderWidth:this.JC.borderWidth,borderStyle:this.JC.borderStyle}}}}function Jh(t,i){return new Zh(t,i)}Zh.sP=12;class Qh{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class tl{constructor(t){this.mC=t,this.Jt=new Qh(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class il extends Rh{constructor(t,i){super(t,"parallel-channel",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.oP=null,this.PC=!1,this.dd=0,this.kC=null,this.YS=null,this.KC=null,this.aP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.aP),this.Hy(),this.aP.interactive?this.QC():this.PC=!0}Hy(){this.eh=new tl(this);const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.wC&&this.wC()}_update(){this.pM()}QC(){this.YS=t=>{if(!t.point||Vh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.aP.point1Time=s,this.aP.point1Price=i;else{if(1!==this.dd)return this.aP.channelWidth=i-this._P(s),void this.iP();this.aP.point2Time=s,this.aP.point2Price=i}this.dd++,this.pM()}},this.KC=t=>{if(!t.point||this.PC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.kC={gt:s,bt:i},2===this.dd&&(this.aP.channelWidth=i-this._P(s)),this.pM())},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.KC)}iP(){this.PC=!0,this.kC=null,this.nP(),this.pM(),this.aP.onComplete&&this.aP.onComplete(),this.aP.onUpdate&&this.aP.onUpdate()}nP(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.KC&&(this._chart.unsubscribeCrosshairMove(this.KC),this.KC=null)}_P(t){const i=this.aP.point1Time,s=this.aP.point2Time,n=this.aP.point1Price,e=this.aP.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)}oS(){const t=this.aP,i=this.PC?t.point2Time:t.point2Time??this.kC?.gt,s=this.PC?t.point2Price:t.point2Price??this.kC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Gn(this._chart,this._series,t.point1Time),e=Gn(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:{LC:n,EC:l,uP:r,cP:o,dP:_,pP:u}}drawToCanvas(t,i,s){const n=this.oS();if(null===n)return;const e=this.aP,r=e.lineColor,h=this.gC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.Vy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.LC*l,n.uP*o),t.lineTo(n.EC*l,n.cP*o),t.lineTo(n.EC*l,n.pP*o),t.lineTo(n.LC*l,n.dP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.PC?"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.LC*l,n.uP*o),t.lineTo(n.EC*l,n.cP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.LC*l,n.dP*o),t.lineTo(n.EC*l,n.pP*o)),t.stroke(),t.setLineDash([]);if((this.gC||this.bC||!this.PC)&&!this.isLocked()&&(this.lP(t,n.LC*l,n.uP*o,l,r),this.lP(t,n.EC*l,n.cP*o,l,r),0!==(e.channelWidth??0))){const i=(n.LC+n.EC)/2,s=(n.dP+n.pP)/2;this.lP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.PC){const i=this._series.coordinateToPrice(n.cP);null!==i&&Lh(t,this._series,l,o,{bt:i,ct:n.cP,Ot:r})}}lP(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()}Vy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}IC(t,i){if(!this.isVisible()||!this.PC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}fP(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.oS();if(null===s)return!1;return this.fP(t,i,s.LC,s.uP,s.EC,s.cP)<=8||this.fP(t,i,s.LC,s.dP,s.EC,s.pP)<=8}hitTestEndpoint(t,i){const s=this.oS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.LC,s.uP))return"point1";if(n(s.EC,s.cP))return"point2";if(0!==(this.aP.channelWidth??0)){if(n((s.LC+s.EC)/2,(s.dP+s.pP)/2))return"width"}return null}startDrag(t,i){this.MC=!0,this.yC=t,this.SC=i,this.oP={vP:{gt:this.aP.point1Time,bt:this.aP.point1Price},mP:{gt:this.aP.point2Time,bt:this.aP.point2Price},ts:this.aP.channelWidth??0}}updateDrag(t,i){if(!this.MC||null===this.yC||null===this.oP)return;const s=this.aP;if("point1"===this.yC)s.point1Time=t,s.point1Price=i;else if("point2"===this.yC)s.point2Time=t,s.point2Price=i;else if("width"===this.yC)s.channelWidth=i-this._P(t);else{const n=Sh(this.SC,t,i);s.point1Time=this.oP.vP.gt+n.gt,s.point1Price=this.oP.vP.bt+n.bt,s.point2Time=this.oP.mP.gt+n.gt,s.point2Price=this.oP.mP.bt+n.bt,s.channelWidth=this.oP.ts}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.oP=null}setColor(t){this.aP.lineColor=t,this.aP.fillColor=t,this.pM()}color(){return this.aP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}isComplete(){return this.PC}remove(){if(this.nP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.wC=null,this.aP.onRemove&&this.aP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Ph(this.aP.point1Price??0,Ch(this.aP.point1Time)),Ph(this.aP.point2Price??0,Ch(this.aP.point2Time))],style:{lineColor:this.aP.lineColor,lineWidth:this.aP.lineWidth,lineStyle:this.aP.lineStyle,fillColor:this.aP.fillColor,fillOpacity:this.aP.fillOpacity,extendRight:this.aP.extendRight},extra:{channelWidth:this.aP.channelWidth}}}}function sl(t,i){return new il(t,i)}class nl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class el{constructor(t){this.mC=t,this.Jt=new nl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class rl extends Rh{constructor(t,i){super(t,"pitchfork",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.oP=null,this.PC=!1,this.dd=0,this.kC=null,this.YS=null,this.KC=null,this.wP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.wP),this.Hy(),this.wP.interactive?this.QC():this.PC=!0}Hy(){this.eh=new el(this);const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.wC&&this.wC()}_update(){this.pM()}QC(){this.YS=t=>{if(!t.point||Vh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.dd)this.wP.pivotTime=s,this.wP.pivotPrice=i;else{if(1!==this.dd)return this.wP.lowerTime=s,this.wP.lowerPrice=i,this.dd++,void this.iP();this.wP.upperTime=s,this.wP.upperPrice=i}this.dd++,this.pM()}},this.KC=t=>{if(!t.point||this.PC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.kC={gt:s,bt:i},this.pM())},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.KC)}iP(){this.PC=!0,this.kC=null,this.nP(),this.pM(),this.wP.onComplete&&this.wP.onComplete(),this.wP.onUpdate&&this.wP.onUpdate()}nP(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.KC&&(this._chart.unsubscribeCrosshairMove(this.KC),this.KC=null)}gP(t,i){if(void 0===t||void 0===i)return null;const s=Gn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}bP(){const t=this.wP,i=this.gP(t.pivotTime,t.pivotPrice),s=this.gP(t.upperTime,t.upperPrice),n=this.PC?this.gP(t.lowerTime,t.lowerPrice):this.gP(t.lowerTime,t.lowerPrice)??(null!==this.kC&&this.dd>=2?this.gP(this.kC.gt,this.kC.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{MP:i,yP:e,SP:s,xP:n,CP:l(i),PP:l(s),TP:l(n)}}drawToCanvas(t,i,s){const n=this.bP();if(null===n)return void this.kP(t,i,s);const e=this.wP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Vy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.SP.ut*h,n.SP.ct*l),t.lineTo(n.PP.ut*h,n.PP.ct*l),t.lineTo(n.TP.ut*h,n.TP.ct*l),t.lineTo(n.xP.ut*h,n.xP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.gC?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.SP.ut*h,n.SP.ct*l),t.lineTo(n.xP.ut*h,n.xP.ct*l),t.moveTo(n.MP.ut*h,n.MP.ct*l),t.lineTo(n.CP.ut*h,n.CP.ct*l),t.moveTo(n.SP.ut*h,n.SP.ct*l),t.lineTo(n.PP.ut*h,n.PP.ct*l),t.moveTo(n.xP.ut*h,n.xP.ct*l),t.lineTo(n.TP.ut*h,n.TP.ct*l),t.stroke(),t.setLineDash([]);if((this.gC||this.bC||!this.PC)&&!this.isLocked())for(const i of[n.MP,n.SP,n.xP])this.lP(t,i.ut*h,i.ct*l,h,r)}kP(t,i,s){const n=this.wP,e=this.gP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.gP(n.upperTime,n.upperPrice)??(null!==this.kC?this.gP(this.kC.gt,this.kC.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.lP(t,e.ut*i,e.ct*s,i,h)}lP(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()}Vy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}IC(t,i){if(!this.isVisible()||!this.PC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}fP(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.bP();if(null===s)return!1;return[[s.MP,s.CP],[s.SP,s.PP],[s.xP,s.TP],[s.SP,s.xP]].some(([s,n])=>this.fP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.bP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.MP)?"pivot":n(s.SP)?"upper":n(s.xP)?"lower":null}startDrag(t,i){this.MC=!0,this.yC=t,this.SC=i,this.oP=[{gt:this.wP.pivotTime,bt:this.wP.pivotPrice},{gt:this.wP.upperTime,bt:this.wP.upperPrice},{gt:this.wP.lowerTime,bt:this.wP.lowerPrice}]}updateDrag(t,i){if(!this.MC||null===this.yC||null===this.oP)return;const s=this.wP;if("pivot"===this.yC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.yC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.yC)s.lowerTime=t,s.lowerPrice=i;else{const n=Sh(this.SC,t,i),[e,r,h]=this.oP;s.pivotTime=e.gt+n.gt,s.pivotPrice=e.bt+n.bt,s.upperTime=r.gt+n.gt,s.upperPrice=r.bt+n.bt,s.lowerTime=h.gt+n.gt,s.lowerPrice=h.bt+n.bt}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.oP=null}setColor(t){this.wP.lineColor=t,this.wP.fillColor=t,this.pM()}color(){return this.wP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}isComplete(){return this.PC}remove(){if(this.nP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.wC=null,this.wP.onRemove&&this.wP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Ph(this.wP.pivotPrice??0,Ch(this.wP.pivotTime)),Ph(this.wP.upperPrice??0,Ch(this.wP.upperTime)),Ph(this.wP.lowerPrice??0,Ch(this.wP.lowerTime))],style:{lineColor:this.wP.lineColor,lineWidth:this.wP.lineWidth,lineStyle:this.wP.lineStyle,fillColor:this.wP.fillColor,fillOpacity:this.wP.fillOpacity}}}}function hl(t,i){return new rl(t,i)}class ll{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ol{constructor(t){this.mC=t,this.Jt=new ll(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class al extends Rh{constructor(t,i){super(t,"vertical-line",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.SC=null,this.jC=0,this.DP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.DP),this.Hy()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new ol(this)}drawToCanvas(t,i,s){if(void 0===this.DP.time)return;const n=(Gn(this._chart,this._series,this.DP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.DP.lineColor,h=this.gC||this.bC&&!this.isLocked()?this.DP.lineWidth+1:this.DP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.DP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.DP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.DP.showLabel&&(this.gC||this.bC)&&this.DP.labelText&&this.qC(t,n,i,s,r)}qC(t,i,s,n,e){const r=this.DP.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.DP.lineColor=t,this.pM()}color(){return this.DP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(void 0===this.DP.time)return!1;const s=Gn(this._chart,this._series,this.DP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.MC=!0,this.SC=i,this.jC=this.DP.time}stopDrag(){this.MC=!1,this.SC=null}updateDrag(t,i){this.MC&&(this.DP.time=this.jC+Sh(this.SC,t,i).gt,this.pM(),this.DP.onUpdate&&this.DP.onUpdate())}getTime(){return this.DP.time}setTime(t){this.DP.time=t,this.pM()}setLabel(t){this.DP.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Ph(0,Ch(this.DP.time))],style:{lineColor:this.DP.lineColor,lineWidth:this.DP.lineWidth,lineStyle:this.DP.lineStyle,showLabel:this.DP.showLabel,labelText:this.DP.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.DP.onRemove&&this.DP.onRemove()}}function _l(t,i){return new al(t,i)}const ul=[{RP:0,Jl:"0.0%"},{RP:.236,Jl:"23.6%"},{RP:.382,Jl:"38.2%"},{RP:.5,Jl:"50.0%"},{RP:.618,Jl:"61.8%"},{RP:.786,Jl:"78.6%"},{RP:1,Jl:"100.0%"}],cl=[...ul,{RP:1.272,Jl:"127.2%"},{RP:1.414,Jl:"141.4%"},{RP:1.618,Jl:"161.8%"},{RP:2,Jl:"200.0%"},{RP:2.618,Jl:"261.8%"}];class dl{constructor(t=!1){this.FP=t?cl:ul}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.FP.map(({RP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{RP:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.FP=t}getRatios(){return[...this.FP]}getRatioValues(){return this.FP.map(t=>t.RP)}useStandardRatios(){this.FP=ul}useExtendedRatios(){this.FP=cl}}class pl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class fl{constructor(t){this.mC=t,this.Jt=new pl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}}function vl(t){return{RP:t,Jl:`${(100*t).toFixed(1)}%`}}class ml extends Rh{constructor(t,i){super(t,"fibonacci-tool",i),this.jb=null,this.wC=null,this.Gb=null,this.eh=null,this.IP=null,this.PC=!1,this.gC=!1,this.bC=!1,this.kC=null,this.MC=!1,this.VP=null,this.ep=null,this.LP={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.LP),this.AP=new dl(this.LP.useExtended),void 0!==this.LP.levels&&this.LP.levels.length>0&&this.AP.updateRatios(this.LP.levels.map(vl)),this.Hy(),this.LP.interactive?this.RC():(this.PC=!0,this.EP())}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new fl(this)}drawToCanvas(t,i,s){if(!this.PC&&this.LP.point1Time&&this.kC)return void this.WC(t,i,s);if(!this.Gb||!this.LP.point1Time||!this.LP.point2Time)return;const n=(Gn(this._chart,this._series,this.LP.point1Time)??0)*i,e=(Gn(this._chart,this._series,this.LP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.gC?2:this.LP.lineWidth;this.Gb.levels.forEach(n=>{this.Mx(t,n,r,h,i,s,l)}),!this.gC&&!this.bC||this.isLocked()||(this.zC(t,n,(this._series.priceToCoordinate(this.LP.point1Price)??0)*s,i),this.zC(t,e,(this._series.priceToCoordinate(this.LP.point2Price)??0)*s,i))}Mx(t,i,s,n,e,r,h=1){const l=i.ratio??i.RP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.LP.levelColors?.[l.toString()]||this.LP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.LP.showLabels&&this.qC(t,i,s,n,a,e,_)}qC(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.AP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.LP.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.LP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}EP(){this.LP.point1Time&&this.LP.point1Price&&this.LP.point2Time&&this.LP.point2Price&&(this.Gb=this.AP.calculateLevels(this.LP.point1Time,this.LP.point1Price,this.LP.point2Time,this.LP.point2Price),this.LP.onUpdate&&this.Gb&&this.LP.onUpdate(this.Gb))}updatePoints(t,i,s,n){this.LP.point1Time=t,this.LP.point1Price=i,this.LP.point2Time=s,this.LP.point2Price=n,this.EP(),this.pM()}getMetrics(){return this.Gb}getLevels(){return this.Gb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.AP.getRatioValues();return{type:"fibRetracement",points:[Ph(this.LP.point1Price??0,Ch(this.LP.point1Time)),Ph(this.LP.point2Price??0,Ch(this.LP.point2Time))],style:{lineColor:this.LP.lineColor,lineWidth:this.LP.lineWidth,showLabels:this.LP.showLabels,labelPosition:this.LP.labelPosition,levelColors:this.LP.levelColors},extra:{levels:t,useExtended:this.LP.useExtended}}}useExtendedLevels(t){this.LP.useExtended=t,t?this.AP.useExtendedRatios():this.AP.useStandardRatios(),this.EP(),this.pM()}RC(){this.IP=new Eh(this._chart,this._series,{dC:t=>{this.LP.point1Time=t.gt,this.LP.point1Price=t.bt,this.pM()},pC:t=>{this.LP.point2Time=t.gt,this.LP.point2Price=t.bt},fC:(t,i)=>{this.LP.point1Time=t.gt,this.LP.point1Price=t.bt,this.LP.point2Time=i.gt,this.LP.point2Price=i.bt,this.PC=!0,this.kC=null,this.EP(),this.BP(),this.pM()},vC:t=>{this.kC=t,this.pM()}}),this.IP.sC()}WC(t,i,s){if(!this.LP.point1Time||!this.kC)return;const n=(Gn(this._chart,this._series,this.LP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.LP.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.kC.gt)??0)*i,h=(this._series.priceToCoordinate(this.kC.bt)??0)*s,l=this.AP.calculateLevels(this.LP.point1Time,this.LP.point1Price,this.kC.gt,this.kC.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.RP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.LP.levelColors?.[e.toString()]||this.LP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.LP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.LP.showLabels){const s=`${n.label??n.Jl} ${this.AP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.LP.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.LP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.zC(t,n,e,i),t.globalAlpha=.6,this.zC(t,r,h,i),t.globalAlpha=1}zC(t,i,s,n){const e=this.LP.lineColor,r=this.gC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.gC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}BP(){this.ep=t=>{this.OP(t)},this._chart.subscribeCrosshairMove(this.ep)}WP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}OP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.gC||!this.MC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.VP?(this.LP.point1Time=i,this.LP.point1Price=s):"point2"===this.VP&&(this.LP.point2Time=i,this.LP.point2Price=s),this.EP(),this.pM())}startDrag(t){this.MC=!0,this.VP=t}stopDrag(){this.MC=!1,this.VP=null}updateDrag(t,i){this.MC&&this.VP&&("point1"===this.VP?(this.LP.point1Time=t,this.LP.point1Price=i):(this.LP.point2Time=t,this.LP.point2Price=i),this.EP(),this.pM())}hitTestEndpoint(t,i){if(!this.PC||!this.LP.point1Time||!this.LP.point2Time)return null;const s=Gn(this._chart,this._series,this.LP.point1Time)??0,n=this._series.priceToCoordinate(this.LP.point1Price)??0,e=Gn(this._chart,this._series,this.LP.point2Time)??0,r=this._series.priceToCoordinate(this.LP.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.LP={...this.LP,...t},void 0!==t.levels&&t.levels.length>0?this.AP.updateRatios(t.levels.map(vl)):void 0!==t.useExtended&&(t.useExtended?this.AP.useExtendedRatios():this.AP.useStandardRatios()),super.applyOptions(t),this.EP(),this.pM()}options(){return{...this.LP,levels:this.AP.getRatioValues()}}setColor(t){this.LP.lineColor=t,this.pM()}color(){return this.LP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}isSelected(){return this.gC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.PC||!this.LP.point1Time||!this.LP.point2Time)return!1;const s=Gn(this._chart,this._series,this.LP.point1Time)??0,n=Gn(this._chart,this._series,this.LP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.Gb)return!1;for(const t of this.Gb.levels){const s=t.price??t.bt;if(void 0===s)continue;const n=this._series.priceToCoordinate(s)??0;if(Math.abs(i-n)<=8)return!0}return!1}isComplete(){return this.PC}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.IP&&(this.IP.m(),this.IP=null),this.WP(),this.LP.onRemove&&this.LP.onRemove()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.LP.onRemove&&this.LP.onRemove()}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.EP(),this.pM()}}function wl(t,i){return new ml(t,i)}class gl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class bl{constructor(t){this.mC=t,this.Jt=new gl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}}class Ml extends Rh{constructor(t,i){super(t,"fibonacci-extension",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.LP={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.Hy()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new bl(this)}getPoint1(){return this.LP.point1}getPoint2(){return this.LP.point2}getPoint3(){return this.LP.point3}getLevels(){return this.LP.levels||[]}getOptions(){return this.LP}setPoint1(t){this.LP.point1=t,this.pM()}setPoint2(t){this.LP.point2=t,this.pM()}setPoint3(t){this.LP.point3=t,this.pM()}isComplete(){return!!(this.LP.point1&&this.LP.point2&&this.LP.point3)}setColor(t){this.LP.lineColor=t,this.pM()}color(){return this.LP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.LP.point1,this.LP.point2,this.LP.point3];for(const n of s){const s=Gn(this._chart,this._series,n.time)??0,e=this._series.priceToCoordinate(n.price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-e,2))<=10)return!0}const n=this.zP();for(const t of n){const s=this._series.priceToCoordinate(t.bt)??0;if(Math.abs(i-s)<=10)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.LP.point1,n=this.LP.point2,e=this.LP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Gn(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=Gn(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=Gn(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.MC=!0,this.yC=t}stopDrag(){this.MC=!1,this.yC=null}updateDrag(t,i){if(!this.MC||!this.yC)return;const s={time:t,price:i};switch(this.yC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.LP.onUpdate&&this.LP.onUpdate()}zP(){if(!this.isComplete())return[];const t=this.LP.point1,i=this.LP.point2,s=this.LP.point3,n=i.price-t.price;return(this.LP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.zP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.LP.point1,e=this.LP.point2,r=this.LP.point3,h=this.gC||this.bC&&!this.isLocked(),l=(Gn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Gn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Gn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.LP.lineColor||"#787B86",t.lineWidth=(this.LP.lineWidth||1)*i*(h?1.5:1),t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(l,o),t.lineTo(a,_),t.stroke(),t.beginPath(),t.moveTo(a,_),t.lineTo(u,c),t.stroke(),t.setLineDash([]);const d=this.getExtensionLevels(),p=t.canvas.width;for(const n of d){const e=n.bt??n.price,r=n.R??n.color,l=n.Jl??n.label;if(null==e)continue;const o=(this._series.priceToCoordinate(e)??0)*s;if(t.strokeStyle=r,t.lineWidth=(this.LP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.LP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.LP.showLabels){const s=`${l} (${e.toFixed(5)})`;t.font=12*i+"px Arial",t.fillStyle=r,t.textAlign="left",t.textBaseline="middle";const n=5*i,h=Math.max(u,10*i)+n;t.fillText(s,h,o)}}const f=(h?6:4)*i,v=[{ut:l,ct:o,Jl:"A"},{ut:a,ct:_,Jl:"B"},{ut:u,ct:c,Jl:"C"}];for(const s of v)t.fillStyle="#2962FF",t.beginPath(),t.arc(s.ut,s.ct,f,0,2*Math.PI),t.fill(),t.fillStyle="#ffffff",t.beginPath(),t.arc(s.ut,s.ct,f-2*i,0,2*Math.PI),t.fill(),h&&(t.fillStyle="#2962FF",t.font=`bold ${10*i}px Arial`,t.textAlign="center",t.textBaseline="middle",t.fillText(s.Jl,s.ut,s.ct))}isVisible(){return this._visible}_serializeShape(){return{type:"fibExtension",points:[Th(this.LP.point1),Th(this.LP.point2),Th(this.LP.point3)],style:{lineColor:this.LP.lineColor,lineWidth:this.LP.lineWidth,showLabels:this.LP.showLabels,extendLines:this.LP.extendLines},extra:{levels:(this.LP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null)}}function yl(t,i){return new Ml(t,i)}class Sl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class xl{constructor(t){this.mC=t,this.Jt=new Sl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const Cl=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Pl extends Rh{constructor(t,i){super(t,"fibonacci-fan",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.$P=!1,this.YS=null,this.ep=null,this.kC=null,this.HP={levels:Cl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.Hy(),this.HP.interactive&&!this.HP.point1Time&&this.RC()}RC(){this.$P=!0,this.YS=t=>{if(!t.point)return;if(Vh(this._chart))return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.HP.point1Time?(this.HP.point2Time=i,this.HP.point2Price=s,this.$P=!1,this.kC=null,this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.HP.onUpdate&&this.HP.onUpdate()):(this.HP.point1Time=i,this.HP.point1Price=s,this.pM()))},this.ep=t=>{if(this.$P&&this.HP.point1Time)if(t.point){const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kC={gt:i,bt:s},this.pM())}else this.kC=null,this.pM()},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new xl(this)}drawToCanvas(t,i,s){const n=this.HP.point1Time,e=this.HP.point1Price,r=this.$P&&this.kC?this.kC.gt:this.HP.point2Time,h=this.$P&&this.kC?this.kC.bt:this.HP.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Gn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Gn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.gC?this.HP.lineWidth+1:this.HP.lineWidth;if(this.NP(t,l,o,a,_,"#2962FF",u*i),this.HP.levels)for(const n of this.HP.levels)this.UP(t,l,o,a,_,n,i,s,undefined,u);!this.gC&&!this.bC||this.$P||this.isLocked()||(this.zC(t,l,o,i,"#2962ff"),this.zC(t,a,_,i,"#2962ff"))}UP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.HP.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.NP(t,i,s,c,d,p,a*h),this.HP.showLabels&&!this.$P&&this.qC(t,_,u,r.label,h,p)}NP(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()}zC(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()}qC(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.HP.levels??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.HP.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.HP.point1Time||!this.HP.point2Time)return!1;const s=Gn(this._chart,this._series,this.HP.point1Time)??0,n=this._series.priceToCoordinate(this.HP.point1Price)??0,e=Gn(this._chart,this._series,this.HP.point2Time)??0,r=this._series.priceToCoordinate(this.HP.point2Price)??0;if(this.$C(t,i,s,n,e,r)<=8)return!0;if(this.HP.levels)for(const h of this.HP.levels){const l=n+(r-n)*h.level,o=e;if(this.$C(t,i,s,n,o,l)<=8)return!0}return!1}$C(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.HP.point1Time||!this.HP.point2Time)return null;const s=Gn(this._chart,this._series,this.HP.point1Time)??0,n=this._series.priceToCoordinate(this.HP.point1Price)??0,e=Gn(this._chart,this._series,this.HP.point2Time)??0,r=this._series.priceToCoordinate(this.HP.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.MC=!0,this.yC=t}stopDrag(){this.MC=!1,this.yC=null}updateDrag(t,i){this.MC&&this.yC&&("point1"===this.yC?(this.HP.point1Time=t,this.HP.point1Price=i):"point2"===this.yC&&(this.HP.point2Time=t,this.HP.point2Price=i),this.pM(),this.HP.onUpdate&&this.HP.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Ph(this.HP.point1Price??0,Ch(this.HP.point1Time)),Ph(this.HP.point2Price??0,Ch(this.HP.point2Time))],style:{lineWidth:this.HP.lineWidth,showLabels:this.HP.showLabels,extendLines:this.HP.extendLines},extra:{levels:(this.HP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return!this.$P}remove(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.HP.onRemove&&this.HP.onRemove()}}function Tl(t,i){return new Pl(t,i)}class kl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Dl{constructor(t){this.mC=t,this.Jt=new kl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Rl extends Rh{constructor(t,i){super(t,"rectangle",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.xC=null,this.CC=null,this.$P=!1,this.YS=null,this.ep=null,this.kC=null,this.qP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.qP),this.Hy(),!this.qP.interactive||this.qP.time1&&this.qP.time2||this.RC()}RC(){this.$P=!0,this.YS=t=>{if(!t.point)return;if(Vh(this._chart))return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.qP.time1?(this.qP.time2=i,this.qP.price2=s,this.$P=!1,this.kC=null,this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.qP.onUpdate&&this.qP.onUpdate()):(this.qP.time1=i,this.qP.price1=s,this.pM()))},this.ep=t=>{if(this.$P&&this.qP.time1)if(t.point){const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kC={gt:i,bt:s},this.pM())}else this.kC=null,this.pM()},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new Dl(this)}drawToCanvas(t,i,s){const n=this.qP.time1,e=this.qP.price1,r=this.$P&&this.kC?this.kC.gt:this.qP.time2,h=this.$P&&this.kC?this.kC.bt:this.qP.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Gn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Gn(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.qP.fillOpacity>0){const i=this.zy(this.qP.fillColor,this.$P?.1:this.qP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.qP.borderColor,w=this.gC?this.qP.borderWidth+1:this.qP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.qP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.qP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.gC&&!this.bC||this.$P||this.isLocked()||this.jP(t,u,d,c,p,i,m),this.qP.showLabel&&this.qP.labelText&&!this.$P&&this.qC(t,u,d,c,p,i,s,m)}jP(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)}qC(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.qP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.qP.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.qP.labelText,c+o,d+o)}zy(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.pM()}color(){return this.qP.borderColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.qP.time1||!this.qP.time2)return!1;const s=Gn(this._chart,this._series,this.qP.time1)??0,n=this._series.priceToCoordinate(this.qP.price1)??0,e=Gn(this._chart,this._series,this.qP.time2)??0,r=this._series.priceToCoordinate(this.qP.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.qP.time1||!this.qP.time2)return null;const s=Gn(this._chart,this._series,this.qP.time1)??0,n=this._series.priceToCoordinate(this.qP.price1)??0,e=Gn(this._chart,this._series,this.qP.time2)??0,r=this._series.priceToCoordinate(this.qP.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.MC=!0,this.yC=t,this.SC=i,"body"===t&&(this.xC={gt:this.qP.time1,bt:this.qP.price1},this.CC={gt:this.qP.time2,bt:this.qP.price2})}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.xC=null,this.CC=null}updateDrag(t,i){if(!this.MC||!this.yC)return;const s=Gn(this._chart,this._series,this.qP.time1)??0,n=this._series.priceToCoordinate(this.qP.price1)??0,e=s<(Gn(this._chart,this._series,this.qP.time2)??0),r=n<(this._series.priceToCoordinate(this.qP.price2)??0);if("body"===this.yC&&this.xC&&this.CC){const s=Sh(this.SC,t,i);this.qP.time1=this.xC.gt+s.gt,this.qP.price1=this.xC.bt+s.bt,this.qP.time2=this.CC.gt+s.gt,this.qP.price2=this.CC.bt+s.bt}else switch(this.yC){case"corner1":e&&r?(this.qP.time1=t,this.qP.price1=i):!e&&r?(this.qP.time2=t,this.qP.price1=i):e&&!r?(this.qP.time1=t,this.qP.price2=i):(this.qP.time2=t,this.qP.price2=i);break;case"corner2":e&&r?(this.qP.time2=t,this.qP.price1=i):!e&&r?(this.qP.time1=t,this.qP.price1=i):e&&!r?(this.qP.time2=t,this.qP.price2=i):(this.qP.time1=t,this.qP.price2=i);break;case"corner3":e&&r?(this.qP.time1=t,this.qP.price2=i):!e&&r?(this.qP.time2=t,this.qP.price2=i):e&&!r?(this.qP.time1=t,this.qP.price1=i):(this.qP.time2=t,this.qP.price1=i);break;case"corner4":e&&r?(this.qP.time2=t,this.qP.price2=i):!e&&r?(this.qP.time1=t,this.qP.price2=i):e&&!r?(this.qP.time2=t,this.qP.price1=i):(this.qP.time1=t,this.qP.price1=i)}this.pM(),this.qP.onUpdate&&this.qP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Ph(this.qP.price1??0,Ch(this.qP.time1)),Ph(this.qP.price2??0,Ch(this.qP.time2))],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,labelPosition:this.qP.labelPosition}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return!this.$P}remove(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.qP.onRemove&&this.qP.onRemove()}}function Fl(t,i){return new Rl(t,i)}class Il{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Vl{constructor(t){this.mC=t,this.Jt=new Il(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ll extends Rh{constructor(t,i){super(t,"circle",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.oP=null,this.$P=!1,this.YS=null,this.ep=null,this.kC=null,this.YP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.YP),this.Hy(),this.YP.interactive&&!this.YP.centerTime&&this.RC()}RC(){this.$P=!0,this.YS=t=>{if(!t.point)return;if(Vh(this._chart))return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.YP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.YP.centerTime)??0,n=this._series.priceToCoordinate(this.YP.centerPrice)??0,e=Gn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.YP.radiusTime=Math.abs(e-t),this.YP.radiusPrice=Math.abs(r-n),this.$P=!1,this.kC=null,this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.YP.onUpdate&&this.YP.onUpdate()}else this.YP.centerTime=i,this.YP.centerPrice=s,this.pM()},this.ep=t=>{if(this.$P&&this.YP.centerTime)if(t.point){const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kC={gt:i,bt:s},this.pM())}else this.kC=null,this.pM()},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new Vl(this)}drawToCanvas(t,i,s){if(!this.YP.centerTime||void 0===this.YP.centerPrice)return;const n=(Gn(this._chart,this._series,this.YP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.YP.centerPrice)??0)*s;let r,h;if(this.$P&&this.kC){const t=(Gn(this._chart,this._series,this.kC.gt)??0)*i,l=(this._series.priceToCoordinate(this.kC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.YP.radiusTime||void 0===this.YP.radiusPrice)return;r=this.YP.radiusTime*i,h=this.YP.radiusPrice*s}if(this.YP.fillOpacity>0){const i=this.zy(this.YP.fillColor,this.$P?.05:this.YP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.YP.borderColor,o=this.gC?this.YP.borderWidth+1:this.YP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.YP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.YP.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.gC&&!this.bC||this.$P||this.isLocked()||this.XP(t,n,e,i,l),!this.gC&&!this.bC||this.$P||this.isLocked()||this.GP(t,n,e,r,h,i,l),this.YP.showLabel&&this.YP.labelText&&!this.$P&&this.qC(t,n,e,i,l)}XP(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()}GP(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)}qC(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.YP.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.YP.labelText,a+r,_+r)}zy(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.YP.borderColor=t,this.YP.fillColor=t,this.pM()}color(){return this.YP.borderColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.YP.centerTime||void 0===this.YP.radiusTime)return!1;const s=Gn(this._chart,this._series,this.YP.centerTime)??0,n=this._series.priceToCoordinate(this.YP.centerPrice)??0,e=(t-s)/this.YP.radiusTime,r=(i-n)/this.YP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.YP.centerTime||void 0===this.YP.radiusTime)return null;const s=Gn(this._chart,this._series,this.YP.centerTime)??0,n=this._series.priceToCoordinate(this.YP.centerPrice)??0,e=this.YP.radiusTime,r=this.YP.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.MC=!0,this.yC=t,this.SC=i,this.oP="center"===t?{gt:this.YP.centerTime,bt:this.YP.centerPrice}:null}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.oP=null}updateDrag(t,i){if(this.MC&&this.yC){if("center"===this.yC&&this.oP){const s=Sh(this.SC,t,i);this.YP.centerTime=this.oP.gt+s.gt,this.YP.centerPrice=this.oP.bt+s.bt}else if("edge"===this.yC){const s=Gn(this._chart,this._series,this.YP.centerTime)??0,n=this._series.priceToCoordinate(this.YP.centerPrice)??0,e=Gn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.YP.radiusTime=Math.abs(e-s),this.YP.radiusPrice=Math.abs(r-n)}this.pM(),this.YP.onUpdate&&this.YP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Ph(this.YP.centerPrice??0,Ch(this.YP.centerTime))],style:{fillColor:this.YP.fillColor,fillOpacity:this.YP.fillOpacity,borderColor:this.YP.borderColor,borderWidth:this.YP.borderWidth,borderStyle:this.YP.borderStyle,showLabel:this.YP.showLabel,labelText:this.YP.labelText},extra:{radiusTime:this.YP.radiusTime,radiusPrice:this.YP.radiusPrice}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return!this.$P}remove(){this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.YP.onRemove&&this.YP.onRemove()}}function Al(t,i){return new Ll(t,i)}class El{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Bl{constructor(t){this.mC=t,this.Jt=new El(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Ol extends Rh{constructor(t,i){super(t,"arrow",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.KP=-1,this.$P=!1,this.YS=null,this.ZP=null,this.ep=null,this.kC=null,this.JP={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.JP),this.Hy(),!this.JP.interactive||this.JP.points&&0!==this.JP.points.length||this.RC()}RC(){this.$P=!0,this.YS=t=>{if(!t.point)return;if(Vh(this._chart))return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.JP.points||(this.JP.points=[]),this.JP.points.push({time:i,price:s}),this.pM(),this.JP.onUpdate&&this.JP.onUpdate())},this.ep=t=>{if(this.$P)if(t.point){const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.kC={gt:i,bt:s},this.pM())}else this.kC=null,this.pM()},this.ZP=t=>{this.$P&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.YS),this._chart.subscribeCrosshairMove(this.ep);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.ZP)}finishDrawing(){if(this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.ZP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.ZP),this.ZP=null}this.$P=!1,this.kC=null,this.pM(),this.JP.onComplete&&this.JP.onComplete()}isDrawing(){return this.$P}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new Bl(this)}drawToCanvas(t,i,s){if(!this.JP.points||0===this.JP.points.length)return;const n=this.JP.lineColor,e=this.gC||this.bC&&!this.isLocked()?this.JP.lineWidth+1:this.JP.lineWidth,r=[];for(const t of this.JP.points)try{let n=Gn(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.$P)return;let h=null;if(this.$P&&this.kC&&this.JP.points.length>0){h={ut:(Gn(this._chart,this._series,this.kC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.kC.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.JP.showArrowHead&&r.length>1&&this.QP(t,r[r.length-2],r[r.length-1],i,n),this.JP.showCircles)for(let s=0;s<r.length;s++)this.tT(t,r[s].ut,r[s].ct,i,n,0===s)}QP(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()}tT(t,i,s,n,e,r){const h=this.JP.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.JP.lineColor=t,this.pM()}color(){return this.JP.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.JP.points||0===this.JP.points.length)return!1;for(let s=0;s<this.JP.points.length-1;s++)try{const n=this.JP.points[s],e=this.JP.points[s+1];let r=Gn(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=Gn(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.$C(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.JP.points)try{let n=Gn(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}$C(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.JP.points||0===this.JP.points.length)return null;for(let s=0;s<this.JP.points.length;s++)try{const n=this.JP.points[s];let e=Gn(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.MC=!0,this.KP=t}stopDrag(){this.MC=!1,this.KP=-1}updateDrag(t,i){this.MC&&-1!==this.KP&&this.JP.points&&this.KP>=0&&this.KP<this.JP.points.length&&(this.JP.points[this.KP]={time:t,price:i},this.pM(),this.JP.onUpdate&&this.JP.onUpdate())}getPoints(){return this.JP.points||[]}addPoint(t){this.JP.points||(this.JP.points=[]),this.JP.points.push(t),this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.JP.points||[]).map(t=>Th(t)),style:{lineColor:this.JP.lineColor,lineWidth:this.JP.lineWidth,showArrowHead:this.JP.showArrowHead,showCircles:this.JP.showCircles,circleRadius:this.JP.circleRadius}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return!this.$P}remove(){if(this.YS&&(this._chart.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.ZP){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.ZP),this.ZP=null}this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.JP.onRemove&&this.JP.onRemove()}}function Wl(t,i){return new Ol(t,i)}class zl{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class $l{constructor(t){this.mC=t,this.Jt=new zl(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Hl extends Rh{constructor(t,i){super(t,"brush",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.iT=!1,this.$P=!1,this.sT=[],this.nT=!1,this.Rf=null,this.cS=null,this.gS=null,this.MS=null,this.SS=null,this.eT=void 0,this.mS=null,this.MC=!1,this.SC=null,this.GC=null,this.rT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.rT),this.Hy(),0===(this.rT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.iT)return;const t=this._chart.chartElement();t&&(this.Rf=t,this.iT=!0,this.gS=t=>this.bS(t),this.MS=t=>this.yS(t),this.SS=()=>this.xS(),this.mS=t=>{this.eT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.mS),t.addEventListener("pointerdown",this.gS,!0),t.addEventListener("pointermove",this.MS,!0),t.addEventListener("pointerup",this.SS,!0),t.addEventListener("pointercancel",this.SS,!0))}stopDrawingMode(){if(!this.iT)return;this.hT(),this.iT=!1;const t=this.Rf;t&&(this.gS&&t.removeEventListener("pointerdown",this.gS,!0),this.MS&&t.removeEventListener("pointermove",this.MS,!0),this.SS&&(t.removeEventListener("pointerup",this.SS,!0),t.removeEventListener("pointercancel",this.SS,!0))),this.mS&&(this._chart.unsubscribeCrosshairMove(this.mS),this.mS=null),this.gS=null,this.MS=null,this.SS=null,this.Rf=null}isDrawingModeActive(){return this.iT}bS(t){if(this.lT())return;const i=this.oT(t,!1);null!==i&&(this.$P=!0,this.sT=[i],this.cS=t.pointerId,Ih(this._chart,!0),this.Rf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.aT())}yS(t){if(!this.$P)return;const i=this.oT(t,!0);if(null===i)return;const s=this.sT[this.sT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.rT.sampleDistance??4)||(this.sT.push(i),t.preventDefault(),t.stopPropagation(),this.aT())}xS(){this.$P&&this.hT()}hT(){if(!this.$P)return;this.$P=!1,this.OS();const t=[];for(const i of this.sT){const s=Xn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.sT=[],t.length<2?this.pM():(this.rT.points=t,this.stopDrawingMode(),this.pM(),this.rT.onUpdate&&this.rT.onUpdate(),this.rT.onComplete&&this.rT.onComplete())}lT(){const t=this.eT;return"string"==typeof t&&t.split("#")[0]!==this.id}OS(){null!==this.cS&&(this.Rf&&this.Rf.hasPointerCapture(this.cS)&&this.Rf.releasePointerCapture(this.cS),this.cS=null)}oT(t,i){const s=this._T();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.kx;return i?{ut:Math.max(0,Math.min(s.ts,n)),ct:Math.max(0,Math.min(s.qt,e))}:n<0||n>s.ts||e<0||e>s.qt?null:{ut:n,ct:e}}_T(){const t=this.uT();if(null===t)return null;const i=t.getBoundingClientRect();let s=0,n=i.width;const e=this._chart.timeScale().width();return e>0&&(s=this._chart.priceScale("left").width(),n=e),{qh:i.left+s,kx:i.top,ts:n,qt:i.height}}uT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}aT(){this.nT||(this.nT=!0,requestAnimationFrame(()=>{this.nT=!1,this.pM()}))}drawToCanvas(t,i,s){const n=this.$P?this.sT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.cT(i,s);if(0===n.length)return;const e=this.gC;if(t.strokeStyle=this.rT.color,t.lineWidth=(this.rT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.rT.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.bC||this.isLocked()||(this.zC(t,n[0],i),this.zC(t,n[n.length-1],i))}zC(t,i,s){t.fillStyle=this.rT.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()}cT(t,i){const s=this.rT.points??[],n=[];for(const e of s){const s=Gn(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.cT(1,1);for(let n=1;n<s.length;n++)if(Nl(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.MC=!0,this.SC=i,this.GC=(this.rT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.GC;if(!this.MC||null===s||!this.rT.points)return;const n=Sh(this.SC,t,i);this.rT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.pM(),this.rT.onUpdate&&this.rT.onUpdate()}stopDrag(){this.MC=!1,this.SC=null,this.GC=null}setColor(t){this.rT.color=t,this.pM()}color(){return this.rT.color??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}Hy(){this.eh=new $l(this);const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):null}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.stopDrawingMode(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null),this.eh=null,this.rT.onRemove&&this.rT.onRemove()}_serializeShape(){return{type:"brush",points:(this.rT.points??[]).map(Th),style:{color:this.rT.color,lineWidth:this.rT.lineWidth,smoothing:this.rT.smoothing}}}getPoints(){return this.rT.points??[]}}function Nl(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 Ul(t,i={}){return new Hl(t,i)}class ql{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class jl{constructor(t){this.mC=t,this.Jt=new ql(t)}renderer(){return this.mC.isComplete()?this.Jt:null}}class Yl extends Rh{constructor(t,i){super(t,"text-tool",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.oP=null,this.dT=!1,this.pT=null,this.fT={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.fT),this.Hy(),this.vT()}vT(){const t=t=>{if(!this.dT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.fT.text&&""!==this.fT.text.trim()&&"Type here..."!==this.fT.text||this.remove())};this.pT=t,this._chart.subscribeClick(t)}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new jl(this)}getTime(){return this.fT.time}getPrice(){return this.fT.price}getText(){return this.fT.text||""}getOptions(){return this.fT}setPosition(t,i){this.fT.time=t,this.fT.price=i,this._update()}setText(t){this.fT.text=t,this._update(),this.fT.onTextChange&&this.fT.onTextChange(t)}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}isComplete(){return!(!this.fT.time||void 0===this.fT.price)}setColor(t){this.fT.textColor=t,this.fT.borderColor=t,this.pM()}color(){return this.fT.textColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this._update())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this._update())}isHovered(){return this.bC}setEditing(t){this.dT!==t&&(this.dT=t,this._update())}isEditing(){return this.dT}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.fT.time,n=this.fT.price,e=Gn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.fT.fontSize||14,l=this.fT.padding||8,o=this.fT.text||"",a=.6*h,_=Math.min(o.length*a,this.fT.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.fT.time,n=this.fT.price,e=Gn(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.MC=!0,this.yC=t,this.SC=i,this.oP={gt:this.fT.time,bt:this.fT.price}}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.oP=null}updateDrag(t,i){if(this.MC){if("body"===this.yC&&this.oP){const s=Sh(this.SC,t,i);this.setPosition(this.oP.gt+s.gt,this.oP.bt+s.bt)}else this.setPosition(t,i);this.fT.onUpdate&&this.fT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.fT.time,e=this.fT.price,r=this.fT.text||"",h=(Gn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.fT.fontSize||14)*i,a=(this.fT.padding||8)*i,_=(this.fT.maxWidth||200)*i;t.font=`${o}px ${this.fT.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.fT.backgroundOpacity||.8,g=this.fT.backgroundColor||"#2962FF";t.fillStyle=this.zy(g,w),t.fillRect(h,l,f,m),(this.gC||this.bC)&&(t.strokeStyle=this.fT.borderColor??"#FFFFFF",t.lineWidth=(this.fT.borderWidth||1)*i*(this.gC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.fT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.fT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.fT.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.gC||this.bC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.fT.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()}}zy(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:[Ph(this.fT.price??0,Ch(this.fT.time))],style:{fontSize:this.fT.fontSize,fontFamily:this.fT.fontFamily,textColor:this.fT.textColor,backgroundColor:this.fT.backgroundColor,backgroundOpacity:this.fT.backgroundOpacity,padding:this.fT.padding,borderColor:this.fT.borderColor,borderWidth:this.fT.borderWidth,textAlign:this.fT.textAlign,maxWidth:this.fT.maxWidth},extra:{text:this.fT.text}}}remove(){this.pT&&(this._chart.unsubscribeClick(this.pT),this.pT=null),this.jb&&this._series&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.fT.onRemove&&this.fT.onRemove()}}function Xl(t,i){return new Yl(t,i)}class Gl{constructor(t){this.mT=t}calculatePips(t,i){return Math.abs(i-t)/this.mT.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.mT={...this.mT,...t}}getPipConfig(){return{...this.mT}}}function Kl(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 Zl(t,i){return"number"==typeof t?Kl(t):void 0!==i?Kl(i):{pipValue:.1,decimals:1}}class Jl{constructor(t){this.mT=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.mT.pipValue,timeDifference:this.wT(t,s),barCount:e}}wT(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.mT={...this.mT,...t}}getPipConfig(){return{...this.mT}}}class Ql{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class to{constructor(t){this.mC=t,this.Jt=new Ql(t)}renderer(){return this.mC.isVisible()?this.Jt:null}}class io extends Rh{constructor(t,i){super(t,"ruler-tool",i),this.jb=null,this.wC=null,this.Gb=null,this.eh=null,this.IP=null,this.PC=!1,this.gC=!1,this.bC=!1,this.kC=null,this.MC=!1,this.VP=null,this.ep=null,this.gT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.gT);const s=this.gT.pipConfig||Zl(this.gT.symbol||"DEFAULT");this.AP=new Jl(s),this.Hy(),this.gT.interactive?this.RC():this.gT.point1Time&&this.gT.point2Time&&(this.PC=!0,this.EP())}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new to(this)}RC(){this.IP=new Eh(this._chart,this._series,{dC:t=>{this.gT.point1Time=t.gt,this.gT.point1Price=t.bt,this.pM()},pC:t=>{this.gT.point2Time=t.gt,this.gT.point2Price=t.bt},fC:(t,i)=>{this.gT.point1Time=t.gt,this.gT.point1Price=t.bt,this.gT.point2Time=i.gt,this.gT.point2Price=i.bt,this.PC=!0,this.kC=null,this.EP(),this.BP(),this.pM()},vC:t=>{this.kC=t,this.pM()}}),this.IP.sC()}drawToCanvas(t,i,s){if(!this.PC&&this.gT.point1Time&&this.kC)return void this.WC(t,i,s);if(!this.PC||!this.gT.point1Time||!this.gT.point2Time)return;const n=(Gn(this._chart,this._series,this.gT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.gT.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.gT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.gT.point2Price)??0)*s;(this.gC||this.bC&&!this.isLocked())&&(t.strokeStyle=this.gT.selectionColor,t.lineWidth=this.gT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.gT.lineColor,t.lineWidth=this.gT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.bT(t,n,e,r,h,i),this.zC(t,n,e,i),this.zC(t,r,h,i),this.gT.showLabel&&this.Gb&&this.qC(t,n,e,r,h,i,s)}bT(t,i,s,n,e,r){const h=this.gT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.gT.lineColor,t.lineWidth=this.gT.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()}zC(t,i,s,n){const e=this.gC?this.gT.selectionColor:this.gT.lineColor,r=this.gC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.gC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}WC(t,i,s){if(!this.gT.point1Time||!this.kC)return;const n=(Gn(this._chart,this._series,this.gT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.gT.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.kC.gt)??0)*i,h=(this._series.priceToCoordinate(this.kC.bt)??0)*s;t.strokeStyle=this.gT.lineColor,t.lineWidth=this.gT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.zC(t,n,e,i),t.globalAlpha=.5,this.zC(t,r,h,i),t.globalAlpha=1}qC(t,i,s,n,e,r,h){if(!this.Gb)return;const l=(i+n)/2,o=(s+e)/2,a=this.gT.measure??"both",_=[];"time"!==a&&(_.push(this.AP.formatPips(this.Gb.pips)),_.push(this.AP.formatPercent(this.Gb.pricePercent))),"price"!==a&&_.push(this.AP.formatBarCount(this.Gb.barCount));const u=_.join(" | ");t.font=12*r+"px sans-serif";const c=6*r,d=t.measureText(u).width+2*c,p=12*r+2*c;t.fillStyle=this.gT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.gT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}EP(){if(!this.gT.point1Time||!this.gT.point2Time||void 0===this.gT.point1Price||void 0===this.gT.point2Price)return;const t=this.MT();this.Gb=this.AP.calculateMetrics(this.gT.point1Time,this.gT.point1Price,this.gT.point2Time,this.gT.point2Price,t),this.gT.onUpdate&&this.Gb&&this.gT.onUpdate(this.Gb)}MT(){if(!this.gT.point1Time||!this.gT.point2Time)return 0;const t=Gn(this._chart,this._series,this.gT.point1Time),i=Gn(this._chart,this._series,this.gT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.gT.point1Time=t,this.gT.point1Price=i,this.gT.point2Time=s,this.gT.point2Price=n,this.EP(),this.pM()}getMetrics(){return this.Gb}remove(){this.destroy()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.IP&&(this.IP.m(),this.IP=null),this.WP(),this.gT.onRemove&&this.gT.onRemove()}BP(){this.ep=t=>{this.OP(t)},this._chart.subscribeCrosshairMove(this.ep)}WP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}OP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.gC||!this.MC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.VP?(this.gT.point1Time=i,this.gT.point1Price=s):"point2"===this.VP&&(this.gT.point2Time=i,this.gT.point2Price=s),this.EP(),this.pM())}startDrag(t){this.MC=!0,this.VP=t}stopDrag(){this.MC=!1,this.VP=null}updateDrag(t,i){this.MC&&this.VP&&("point1"===this.VP?(this.gT.point1Time=t,this.gT.point1Price=i):(this.gT.point2Time=t,this.gT.point2Price=i),this.EP(),this.pM())}hitTestEndpoint(t,i){if(!this.PC||!this.gT.point1Time||!this.gT.point2Time)return null;const s=Gn(this._chart,this._series,this.gT.point1Time)??0,n=this._series.priceToCoordinate(this.gT.point1Price)??0,e=Gn(this._chart,this._series,this.gT.point2Time)??0,r=this._series.priceToCoordinate(this.gT.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.EP(),this.pM()}_serializeShape(){return{type:"ruler",points:[Ph(this.gT.point1Price??0,Ch(this.gT.point1Time)),Ph(this.gT.point2Price??0,Ch(this.gT.point2Time))],style:{lineColor:this.gT.lineColor,lineWidth:this.gT.lineWidth,showLabel:this.gT.showLabel,labelBackgroundColor:this.gT.labelBackgroundColor,labelTextColor:this.gT.labelTextColor,selectionColor:this.gT.selectionColor,selectionLineWidth:this.gT.selectionLineWidth},extra:{symbol:this.gT.symbol,pipConfig:this.gT.pipConfig,measure:this.gT.measure}}}setColor(t){this.gT.lineColor=t,this.pM()}color(){return this.gT.lineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}isSelected(){return this.gC}isComplete(){return this.PC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.PC||!this.gT.point1Time||!this.gT.point2Time)return!1;const s=Gn(this._chart,this._series,this.gT.point1Time)??0,n=this._series.priceToCoordinate(this.gT.point1Price)??0,e=Gn(this._chart,this._series,this.gT.point2Time)??0,r=this._series.priceToCoordinate(this.gT.point2Price)??0;return this.yT(t,i,s,n,e,r)<=(this.gC?12:8)}yT(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 so(t,i){return new io(t,i)}class no{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class eo{constructor(t){this.mC=t,this.Jt=new no(t)}renderer(){return this.mC.isVisible()?this.Jt:null}}class ro extends Rh{constructor(t,i){super(t,"position-tool",i),this.jb=null,this.wC=null,this.Gb=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.yC=null,this.SC=null,this.oP=null,this.ST=null,this.xT=null,this.CT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.CT);const s=this.CT.pipConfig||Zl(this.CT.entryPrice);this.AP=new Gl(s),this.Hy(),this.EP()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new eo(this)}drawToCanvas(t,i,s){if(this.ST&&this.CT.takeProfit){const n=this._chart.timeScale();this.PT(t,this.ST,i,s,n),(this.bC||this.gC)&&this.qC(t,this.ST,"profit",i,s,n)}if(this.xT&&this.CT.stopLoss){const n=this._chart.timeScale();if(this.PT(t,this.xT,i,s,n),this.bC||this.gC){const n=this._chart.timeScale();this.qC(t,this.xT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.TT(t,i,s,n),this.CT.takeProfit){const n=this._chart.timeScale();this.zC(t,this.CT.takeProfit,this.CT.profitColor,i,s,n)}if(this.CT.stopLoss){const n=this._chart.timeScale();this.zC(t,this.CT.stopLoss,this.CT.lossColor,i,s,n)}}PT(t,i,s,n,e){const r=(Gn(this._chart,this._series,this.CT.entryTime)??0)*s;let h;if(this.CT.endTime)h=(Gn(this._chart,this._series,this.CT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.kT)??0)*n,o=(this._series.priceToCoordinate(i.DT)??0)*n;t.fillStyle=this.zy(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()}TT(t,i,s,n){const e=(Gn(this._chart,this._series,this.CT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.CT.entryPrice)??0)*s;let h;if(this.CT.endTime)h=(Gn(this._chart,this._series,this.CT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.CT.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.CT.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.gC&&!this.bC||this.isLocked())t.fillStyle=this.CT.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)}}EP(){this.CT.stopLoss&&this.CT.takeProfit&&(this.Gb=this.AP.calculateMetrics(this.CT.entryPrice,this.CT.stopLoss,this.CT.takeProfit,this.CT.quantity),this.RT(),this.CT.onUpdate&&this.Gb&&this.CT.onUpdate(this.Gb))}RT(){const t=this.FT();this.CT.takeProfit&&(this.ST={IT:this.CT.entryTime,VT:t,kT:this.CT.entryPrice,DT:this.CT.takeProfit,R:this.CT.profitColor,Ry:this.CT.opacity}),this.CT.stopLoss&&(this.xT={IT:this.CT.entryTime,VT:t,kT:this.CT.entryPrice,DT:this.CT.stopLoss,R:this.CT.lossColor,Ry:this.CT.opacity})}FT(){this._chart.timeScale().getVisibleLogicalRange();return this.CT.entryTime}qC(t,i,s,n,e,r){if(!this.Gb)return;const h=(Gn(this._chart,this._series,this.CT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.DT)??0)*e,o="profit"===s,a=o?this.Gb.takeProfitPips:this.Gb.stopLossPips,_=o?this.CT.takeProfit:this.CT.stopLoss,u=this.Gb.riskRewardRatio,c=o?`Objetivo: ${_?.toFixed(5)} (${a.toFixed(1)} pips) 1:${u.toFixed(2)}`:`P/G Abertura: ${_?.toFixed(5)} (${a.toFixed(1)} pips)`;t.font=11*n+'px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const d=6*n,p=t.measureText(c).width+2*d,f=20*n,v=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)}zC(t,i,s,n,e,r){const h=(Gn(this._chart,this._series,this.CT.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.CT.endTime)a=(Gn(this._chart,this._series,this.CT.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,_,_)}zy(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.CT={...this.CT,...t},this.EP(),this._update()}getMetrics(){return this.Gb}setStopLoss(t){this.CT.stopLoss=t,this.EP(),this._update()}setTakeProfit(t){this.CT.takeProfit=t,this.EP(),this._update()}setEntryPrice(t){this.CT.entryPrice=t,this.EP(),this._update()}_serializeShape(){return{type:"position",points:[Ph(this.CT.entryPrice,Ch(this.CT.entryTime))],style:{profitColor:this.CT.profitColor,lossColor:this.CT.lossColor,entryLineColor:this.CT.entryLineColor,opacity:this.CT.opacity,showTooltips:this.CT.showTooltips},extra:{endTime:Ch(this.CT.endTime),stopLoss:this.CT.stopLoss,takeProfit:this.CT.takeProfit,quantity:this.CT.quantity,pipConfig:this.CT.pipConfig}}}setColor(t){this.CT.entryLineColor=t,this.pM()}color(){return this.CT.entryLineColor??""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):this.hitTest(t,i)?yh(this.id,"body",!1):null}hitTest(t,i){if(!this.CT.stopLoss&&!this.CT.takeProfit)return!1;const s=Gn(this._chart,this._series,this.CT.entryTime)??0;let n;if(this.CT.endTime)n=Gn(this._chart,this._series,this.CT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.CT.takeProfit&&this.CT.stopLoss){const e=this._series.priceToCoordinate(this.CT.takeProfit)??0,r=this._series.priceToCoordinate(this.CT.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=Gn(this._chart,this._series,this.CT.entryTime)??0;let n;if(this.CT.endTime)n=Gn(this._chart,this._series,this.CT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.CT.takeProfit){const n=this._series.priceToCoordinate(this.CT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.CT.stopLoss){const n=this._series.priceToCoordinate(this.CT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.CT.takeProfit){const s=this._series.priceToCoordinate(this.CT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.CT.stopLoss){const s=this._series.priceToCoordinate(this.CT.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.CT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.CT.takeProfit&&this.CT.stopLoss){const e=this._series.priceToCoordinate(this.CT.takeProfit)??0,r=this._series.priceToCoordinate(this.CT.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.MC=!0,this.yC=t,this.SC=i,"move"===t&&(this.oP={LT:this.CT.entryPrice,AT:this.CT.entryTime??null,Wy:this.CT.endTime??null,ET:this.CT.takeProfit??null,BT:this.CT.stopLoss??null})}stopDrag(){this.MC=!1,this.yC=null,this.SC=null,this.oP=null}updateDrag(t,i){if(this.MC&&this.yC){if("entry"===this.yC)this.CT.entryPrice=i;else if("move"===this.yC){if(this.oP){const s=Sh(this.SC,t,i),n=this.oP;this.CT.entryPrice=n.LT+s.bt,null!==n.ET&&(this.CT.takeProfit=n.ET+s.bt),null!==n.BT&&(this.CT.stopLoss=n.BT+s.bt),null!==n.AT&&(this.CT.entryTime=this.OT(n.AT,s.gt)),null!==n.Wy&&(this.CT.endTime=this.OT(n.Wy,s.gt))}}else"tp"===this.yC||"tp-right"===this.yC?(this.CT.takeProfit=i,"tp-right"===this.yC?this.CT.endTime=t:this.CT.entryTime=t):"sl"!==this.yC&&"sl-right"!==this.yC||(this.CT.stopLoss=i,"sl-right"===this.yC?this.CT.endTime=t:this.CT.entryTime=t);this.EP(),this.pM()}}OT(t,i){return t+i}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.CT.onRemove&&this.CT.onRemove()}}function ho(t,i){return new ro(t,i)}class lo{constructor(t){this.mC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.mC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class oo{constructor(t){this.mC=t,this.Jt=new lo(t)}renderer(){return this.mC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class ao extends Rh{constructor(t,i){super(t,"gantt",i),this.jb=null,this.wC=null,this.eh=null,this.gC=!1,this.bC=!1,this.MC=!1,this.WT=-1,this.SC=null,this.oP=null,this.zT=-1,this.$T={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.$T),this.Hy()}Hy(){this.eh=this.FC();const t={attached:t=>{this.wC=t.requestUpdate},detached:()=>{this.wC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.IC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}FC(){return new oo(this)}drawToCanvas(t,i,s){if(!this.$T.segments||0===this.$T.segments.length)return;const n=50*s,e=this.$T.rowHeight*s,r=this.$T.rowSpacing*s;this.$T.showGrid&&this.rm(t,n,e,r,i,s),this.$T.segments.forEach((s,h)=>{const l=(Gn(this._chart,this._series,s.startTime)??0)*i,o=(Gn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.zT||this.bC&&!this.isLocked();this.HT(t,l,o,a,e,s,_,i)})}rm(t,i,s,n,e,r){if(!this.$T.segments)return;const h=Math.max(...this.$T.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()}}HT(t,i,s,n,e,r,h,l){const o=s-i,a=this.zy(r.color,h?this.$T.fillOpacity+.2:this.$T.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.$T.borderWidth+(this.gC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.$T.showLabels&&r.label&&this.qC(t,i,n,o,e,r.label,l)}qC(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)}zy(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.$T.segments||(this.$T.segments=[]),this.$T.segments.push(t),this.pM(),this.$T.onUpdate&&this.$T.onUpdate()}removeSegment(t){this.$T.segments&&t>=0&&t<this.$T.segments.length&&(this.$T.segments.splice(t,1),this.pM(),this.$T.onUpdate&&this.$T.onUpdate())}getSegments(){return this.$T.segments||[]}setColor(t){const i=this.$T.segments??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.$T.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.gC!==t&&(this.gC=t,this.pM())}isSelected(){return this.gC}setHovered(t){this.bC!==t&&(this.bC=t,this.pM())}isHovered(){return this.bC}IC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?yh(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.$T.segments?.[this.zT];s&&(this.MC=!0,this.WT=this.zT,this.SC=i,this.oP={Oy:s.startTime,Wy:s.endTime})}updateDrag(t,i){const s=this.$T.segments?.[this.WT];if(!this.MC||!this.oP||!s)return;const n=Sh(this.SC,t,i);s.startTime=this.oP.Oy+n.gt,s.endTime=this.oP.Wy+n.gt,this.pM(),this.$T.onUpdate&&this.$T.onUpdate()}stopDrag(){this.MC=!1,this.WT=-1,this.SC=null,this.oP=null}hitTest(t,i){if(!this.$T.segments||0===this.$T.segments.length)return!1;const s=this.$T.rowHeight,n=this.$T.rowSpacing;for(let e=0;e<this.$T.segments.length;e++){const r=this.$T.segments[e],h=Gn(this._chart,this._series,r.startTime)??0,l=Gn(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.zT=e,!0}return this.zT=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.$T.rowHeight,rowSpacing:this.$T.rowSpacing,fillOpacity:this.$T.fillOpacity,borderWidth:this.$T.borderWidth,showLabels:this.$T.showLabels,showGrid:this.$T.showGrid},extra:{segments:(this.$T.segments||[]).map(t=>({Oy:Ch(t.startTime),Wy:Ch(t.endTime),sn:t.level,Jl:t.label,R:t.color,NT:t.category}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.wC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.$T.onRemove&&this.$T.onRemove()}}function _o(t,i){return new ao(t,i)}class uo{constructor(t,i,s={}){this.UT=[],this.qT=[],this.jT=[],this.YT=!1,this.XT=new Map,this.GT=null,this.KT=null,this.ZT=null,this.YS=null,this.JT=null,this.ep=null,this.QT=null,this.tk=null,this.ik=null,this.sk=null,this.nk=null,this.cS=null,this.ek=!1,this.rk=null,this.hk=null,this.lk=new a,this.MC=!1,this.ak=null,this._k=new Set,this.uk=null,this.ck=new a,this.Lf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.dk()}startDrawing(t){this.ZT=t,this.pk()}activeDrawingType(){return this.ZT}stopDrawing(){this.ZT=null}addTool(t,i){const s=i??t.id;return this.XT.set(s,t),t.isComplete()||this._k.add(s),this.recordChange(),s}hasPendingDrawing(){return this._k.size>0}cancelPendingDrawings(){if(0===this._k.size)return 0;let t=0;for(const i of Array.from(this._k)){const s=this.XT.get(i);s&&(this.GT===i&&this.fk(null),s.remove(),this.XT.delete(i),t++)}return this._k.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.ck.i(t)}unsubscribeDrawingCompleted(t){this.ck._(t)}vk(){0!==this._k.size&&null===this.uk&&(this.uk=setTimeout(()=>{this.uk=null;for(const t of Array.from(this._k)){const i=this.XT.get(t);i?i.isComplete()&&(this._k.delete(t),this.ck.p(t)):this._k.delete(t)}},0))}removeTool(t){const i=this.XT.get(t);return!!i&&(this.GT===t&&this.fk(null),i.remove(),this.XT.delete(t),this._k.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.XT.has(t)&&(this.fk(t),!0)}fk(t){if(this.GT===t)return;const i=null===this.GT?void 0:this.XT.get(this.GT);i&&i.setSelected(!1),this.GT=t;const s=null===t?void 0:this.XT.get(t);s&&s.setSelected(!0),this.mk()}recordChange(){this.YT||(this.UT.push(this.jT),this.UT.length>100&&this.UT.shift(),this.qT=[],this.jT=this.serializeAll())}canUndo(){return this.UT.length>0}canRedo(){return this.qT.length>0}undo(){const t=this.UT.pop();return void 0!==t&&(this.qT.push(this.jT),this.wk(t),!0)}redo(){const t=this.qT.pop();return void 0!==t&&(this.UT.push(this.jT),this.wk(t),!0)}wk(t){this.YT=!0;try{this.restoreAll({chart:this.Lf,series:this.be},t,!0),this.jT=t}finally{this.YT=!1}}subscribeSelectionChanged(t){this.lk.i(t)}unsubscribeSelectionChanged(t){this.lk._(t)}selectionBounds(){if(null===this.GT)return null;const t=this.XT.get(this.GT);return t?this.gk(t):null}gk(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=Gn(this.Lf,i,t.time),o=i.priceToCoordinate(t.price);null!==s&&null!==o&&(l=!0,n=Math.min(n,s),r=Math.max(r,s),e=Math.min(e,o),h=Math.max(h,o))}if(!l)return null;const o=this.bk(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}bk(t){const i=this.Lf.chartElement(),s=this.Mk(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}}mk(){this.lk.p({id:this.GT,bounds:this.selectionBounds()})}deselectAll(){this.pk()}deleteSelected(){if(this.GT){const t=this.XT.get(this.GT);return(!t||!t.isLocked())&&this.removeTool(this.GT)}return!1}getSelectedToolId(){return this.GT}getAllTools(){return new Map(this.XT)}getTool(t){return this.XT.get(t)}clearAll(){this.fk(null),this.XT.forEach(t=>t.remove()),this.XT.clear(),this._k.clear(),this.recordChange()}getToolCount(){return this.XT.size}isToolSelected(t){return this.GT===t}serializeAll(){const t=[];for(const i of this.XT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=uo.yk(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 yk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({Sk:kh(n[t]),xk:Dh(n[t],"price")??0});switch(s){case"trendLine":return zh(t,{point1Time:h(0).Sk,point1Price:h(0).xk,point2Time:h(1).Sk,point2Price:h(1).xk,...e});case"horizontalLine":return Uh(t,{price:h(0).xk,startTime:h(0).Sk??void 0,...e});case"parallelChannel":return sl(t,{point1Time:h(0).Sk,point1Price:h(0).xk,point2Time:h(1).Sk,point2Price:h(1).xk,channelWidth:r?.channelWidth,...e});case"pitchfork":return hl(t,{pivotTime:h(0).Sk,pivotPrice:h(0).xk,upperTime:h(1).Sk,upperPrice:h(1).xk,lowerTime:h(2).Sk,lowerPrice:h(2).xk,...e});case"polygon":return Jh(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).Sk,s.price=h(i).xk,s}),...e});case"crossLine":return Xh(t,{time:h(0).Sk,price:h(0).xk,...e});case"verticalLine":return _l(t,{time:h(0).Sk,...e});case"fibRetracement":return wl(t,{point1Time:h(0).Sk,point1Price:h(0).xk,point2Time:h(1).Sk,point2Price:h(1).xk,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return yl(t,{point1:i.Sk?{time:i.Sk,price:i.xk}:void 0,point2:s.Sk?{time:s.Sk,price:s.xk}:void 0,point3:n.Sk?{time:n.Sk,price:n.xk}:void 0,levels:r?.levels,...e})}case"fibFan":return Tl(t,{point1Time:h(0).Sk,point1Price:h(0).xk,point2Time:h(1).Sk,point2Price:h(1).xk,levels:r?.levels,...e});case"rectangle":return Fl(t,{time1:h(0).Sk,price1:h(0).xk,time2:h(1).Sk,price2:h(1).xk,...e});case"circle":return Al(t,{centerTime:h(0).Sk,centerPrice:h(0).xk,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Wl(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Ul(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return Xl(t,{time:h(0).Sk,price:h(0).xk,text:r?.text,...e});case"ruler":return so(t,{point1Time:h(0).Sk,point1Price:h(0).xk,point2Time:h(1).Sk,point2Price:h(1).xk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ho(t,{entryPrice:h(0).xk,entryTime:h(0).Sk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return _o(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.uk&&(clearTimeout(this.uk),this.uk=null),this.ck.m(),this.lk.m(),this.clearAll(),this.Ck(),this.UT=[],this.qT=[],this.jT=[]}dk(){this.YS=t=>{this.uC(t)},this.Lf.subscribeClick(this.YS),this.ep=t=>{this.cC(t)},this.Lf.subscribeCrosshairMove(this.ep);const t=this.Lf.chartElement();t&&(this.QT=t=>this.Pk(t),this.tk=t=>this.Tk(t),this.ik=t=>this.Tk(t),this.sk=t=>this.kk(t),t.addEventListener("pointerdown",this.QT),t.addEventListener("pointerup",this.tk),t.addEventListener("pointercancel",this.ik),t.addEventListener("lostpointercapture",this.sk)),us&&(this.nk=t=>this.Tk(t),window.addEventListener("pointerup",this.nk)),this.Ps.enableKeyboardShortcuts&&(this.JT=t=>{this.Dk(t)},document.addEventListener("keydown",this.JT))}Ck(){this.YS&&(this.Lf.unsubscribeClick(this.YS),this.YS=null),this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null);const t=this.Lf.chartElement();t&&(this.QT&&(t.removeEventListener("pointerdown",this.QT),this.QT=null),this.tk&&(t.removeEventListener("pointerup",this.tk),this.tk=null),this.ik&&(t.removeEventListener("pointercancel",this.ik),this.ik=null),this.sk&&(t.removeEventListener("lostpointercapture",this.sk),this.sk=null)),this.nk&&(window.removeEventListener("pointerup",this.nk),this.nk=null),this.JT&&(document.removeEventListener("keydown",this.JT),this.JT=null)}uC(t){if(this.vk(),!t.point)return;if(this.ek)return void(this.ek=!1);if(this.MC)return;const i=this.Rk(t.hoveredObjectId);i?this.selectTool(i):this.pk()}cC(t){if(this.rk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.MC&&this.ak){const i=this.XT.get(this.ak);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Xn(this.Lf,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.Rk(t.hoveredObjectId);if(this.KT&&this.KT!==i){const t=this.XT.get(this.KT);t&&t.setHovered(!1)}if(i){const t=this.XT.get(i);t&&t.setHovered(!0)}this.KT=i}Rk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.XT)if(s.id===i)return t;return null}Pk(t){if(this.MC)return;Ih(this.Lf,!1);const i=this.Lf.chartElement();if(!i)return;const s=null!==this.KT&&null!==this.rk?{Fk:this.KT,Rw:this.rk}:this.Ik(t);if(null===s)return;const{Fk:n,Rw:e}=s,r=this.XT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Vk(r,e.ut,e.ct);if(null!==h&&null!==l){Ih(this.Lf,!0),this.selectTool(n),this.MC=!0,this.ek=!0,this.ak=n,this.cS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.cS=null}r.startDrag(h,l),this.Lk()}}Tk(t){if(!this.MC||null===this.ak)return;if(t&&null!==this.cS&&t.pointerId!==this.cS)return;const i=this.ak;this.MC=!1,this.ak=null;try{const t=this.XT.get(i);t&&t.stopDrag()}finally{this.OS(),this.Ak()}this.recordChange()}kk(t){null!==this.cS&&t.pointerId!==this.cS||(this.cS=null,this.Tk())}Mk(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Ik(t){for(const[i,s]of this.XT){if(!s.isVisible()||s.isLocked())continue;const n=this.Mk(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{Fk:i,Rw:r}}return null}OS(){if(null===this.cS)return;const t=this.Lf.chartElement();t&&t.hasPointerCapture(this.cS)&&t.releasePointerCapture(this.cS),this.cS=null}Lk(){if(null!==this.hk)return;const t=this.Lf.options();this.hk={Ek:f(t.handleScroll),Bk:f(t.handleScale)},this.Lf.applyOptions({handleScroll:!1,handleScale:!1})}Ak(){const t=this.hk;this.hk=null,null!==t&&this.Lf.applyOptions({handleScroll:t.Ek,handleScale:t.Bk})}Dk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.vk(),"Delete"!==t.key&&"Backspace"!==t.key||this.deleteSelected()&&t.preventDefault();const s=t.metaKey||t.ctrlKey;if(s&&"z"===t.key.toLowerCase()){return void((t.shiftKey?this.redo():this.undo())&&t.preventDefault())}s&&"y"===t.key.toLowerCase()?this.redo()&&t.preventDefault():"Escape"===t.key&&(this.cancelPendingDrawings(),this.Tk(),this.pk(),this.stopDrawing(),t.preventDefault())}Vk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Xn(this.Lf,t.series(),i)}}pk(){this.fk(null)}}const co={...t,color:"#2196f3"};var po=Object.freeze({__proto__:null,AreaSeries:xe,ArrowTool:Ol,BarSeries:ke,BaselineSeries:Me,BrushTool:Hl,CandlestickSeries:Fe,CircleTool:Ll,get ColorType(){return Li},CrossLineTool:Yh,get CrosshairMode(){return U},DEFAULT_SESSIONS:Xr,DraggablePriceLine:eh,DrawingToolsManager:uo,EXTENDED_FIBONACCI_RATIOS:cl,FibonacciCalculator:dl,FibonacciExtensionTool:Ml,FibonacciFanTool:Pl,FibonacciTool:ml,GanttTool:ao,HistogramSeries:Le,HorizontalLineTool:Nh,InteractiveLineManager:rh,get LastPriceAnimationMode(){return Ii},LineSeries:he,get LineStyle(){return s},get LineType(){return i},get MismatchDirection(){return xt},ParallelChannelTool:il,PitchforkTool:rl,PolygonTool:Zh,PositionCalculator:Gl,PositionLine:gh,PositionMarkersManager:Pr,PositionTool:ro,get PriceLineSource(){return Vi},get PriceScaleMode(){return di},RectangleTool:Rl,RulerCalculator:Jl,RulerTool:io,STANDARD_FIBONACCI_RATIOS:ul,TextTool:Yl,get TickMarkType(){return Ai},get TrackingModeExitMode(){return Fi},TradingSessionsIndicator:Gr,TrendLineTool:Wh,VerticalLineTool:al,VolumeProfileIndicator:Jr,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=Lr(0,100),h=i.addSeries(he,{color:n.colorADX,autoscaleInfoProvider:r},e),l=Ar(i,h,e),o=i.addSeries(he,{color:n.colorPlusDI,autoscaleInfoProvider:r},l),a=i.addSeries(he,{color:n.colorMinusDI,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=Br(h,n.levelColor),u=Wr({r_:t,Xf:i,yy:[h,o,a],Jl:"ADX",W:n,Cy:["period"],Sy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{Ok:[],Wk:[],zk:[]};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{Ok:o,Wk:a,zk:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Ok],[o,n?s.Wk:[]],[a,n?s.zk:[]]]},xy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorADX,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorPlusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),a.applyOptions({color:t.colorMinusDI,lineWidth:i,lineStyle:s,visible:t.showDI??!0}),_("number"==typeof t.threshold?[t.threshold]:[])}});return{adx:h,plusDI:o,minusDI:a,...u}},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(he,{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=Wr({r_:t,Xf:i,yy:[e],Jl:"ATR",W:n,Cy:["period"],Sy:(t,i)=>[[e,r(t,i.period??14)]],xy: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(he,{color:n.colorUpper},e),h=i.addSeries(he,{color:n.colorMiddle},e),l=i.addSeries(he,{color:n.colorLower},e),o=Wr({r_:t,Xf:i,yy:[r,h,l],Jl:"Bollinger Bands",W:n,Cy:["period","stdDev"],Sy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{SP:[],$k:[],xP:[]};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{SP:e,$k:r,xP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.SP],[h,s.$k],[l,s.xP]]},xy: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(he,{color:n.color,lineWidth:n.lineWidth},e),h=Ar(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Br(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=Wr({r_:t,Xf:i,yy:[r],Jl:"CCI",W:n,Cy:["period"],Sy:(t,i)=>[[r,o(t,i.period??20)]],xy: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(he,{color:n.colorUpper},e),h=i.addSeries(he,{color:n.colorMiddle},e),l=i.addSeries(he,{color:n.colorLower},e),o=Wr({r_:t,Xf:i,yy:[r,h,l],Jl:"Donchian Channels",W:n,Cy:["period"],Sy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{SP:[],$k:[],xP:[]};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{SP:s,$k:n,xP:e}})(t,i.period??20);return[[r,s.SP],[h,s.$k],[l,s.xP]]},xy: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(he,{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=Er(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=Wr({r_:t,Xf:i,yy:[e],Jl:"EMA",W:n,Cy:["period","source"],Sy:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],xy: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(Fe,{upColor:n.upColor,downColor:n.downColor,borderVisible:n.borderVisible,borderUpColor:n.borderUpColor,borderDownColor:n.borderDownColor,wickVisible:n.wickVisible,wickUpColor:n.wickUpColor,wickDownColor:n.wickDownColor,priceScaleId:e.priceScaleId,priceFormat:e.priceFormat,lastValueVisible:e.lastValueVisible,priceLineVisible:e.priceLineVisible},n.paneIndex);let h=null;const l=i=>{i&&null===h?h=Ir(t):i||null===h||(h(),h=null)},o=Wr({r_:t,Xf:i,yy:[r],Jl:"Heikin Ashi",W:n,Cy:[],Sy:t=>[[r,qr(t)]],xy: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{za: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(he,{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 Hr(i,t,()=>u,()=>({Ly:c.cloudBullishColor??"#089981",Ay:c.cloudBearishColor??"#F23645",Ry: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{Hk:h,rh:l,Fy:o,Iy:a,Nk:_,Uk: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=Nr(t,i,s),u=Nr(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=Nr(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,Fy:s,Iy:n};u.push(t)}}return{Hk:h,rh:l,Fy:o,Iy:a,Nk:_,Uk:u}},v=Wr({r_:t,Xf:i,yy:[h,l,o,a,_],Jl:"Ichimoku",W:n,Cy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],Sy:(t,i)=>{c=i;const s=f(t,i);return u=s.Uk,[[h,s.Hk],[l,s.rh],[o,s.Fy],[a,s.Iy],[_,i.showLagging??1?s.Nk:[]]]},xy: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(he,{color:n.colorUpper},e),h=i.addSeries(he,{color:n.colorMiddle},e),l=i.addSeries(he,{color:n.colorLower},e),o=Wr({r_:t,Xf:i,yy:[r,h,l],Jl:"Keltner Channels",W:n,Cy:["period","atrPeriod","multiplier","source"],Sy:(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{SP:[],$k:[],xP:[]};const r=Er(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{SP:c,$k:d,xP:p}})(t,i);return[[r,s.SP],[h,s.$k],[l,s.xP]]},xy: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(he,{color:n.colorMACD},e),h=Ar(i,r,e),l=i.addSeries(he,{color:n.colorSignal},h),o=i.addSeries(Le,{color:n.colorHistogramUp},h),a=(t,i)=>{const s=[],n=2/(i+1);let e=0;for(let s=0;s<i;s++)e+=t[s];s.push(e/i);for(let e=i;e<t.length;e++)s.push((t[e]-s[s.length-1])*n+s[s.length-1]);return s},_=Wr({r_:t,Xf:i,yy:[r,l,o],Jl:"MACD",W:n,Cy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],Sy:(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{qk:[],jk:[],Yk:[]};const r=[];for(const i of t)"close"in i?r.push(i.close):"value"in i?r.push(i.value):r.push(0);const h=a(r,s),l=a(r,n),o=[],_=n-s;for(let t=0;t<l.length;t++)o.push(h[t+_]-l[t]);const u=a(o,e),c=[],d=[],p=[],f=n-1;for(let s=e-1;s<u.length;s++){const n=f+s;if(t[n]&&t[n].time){const e=t[n].time,r=o[s],h=u[s],l=r-h;c.push({time:e,value:r}),d.push({time:e,value:h}),p.push({time:e,value:l,color:l>=0?i.colorHistogramUp:i.colorHistogramDown})}}return{qk:c,jk:d,Yk:p}})(t,i);return[[r,s.qk],[l,s.jk],[o,s.Yk]]},xy:t=>{const i=t.lineWidth??2;r.applyOptions({color:t.colorMACD,lineWidth:i}),l.applyOptions({color:t.colorSignal,lineWidth:i})}});return{macd:r,signal:l,histogram:o,..._}},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(he,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Lr(0,100)},e),h=Ar(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Br(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Rr(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*(Dr(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=Wr({r_:t,Xf:i,yy:[r],Jl:"MFI",W:n,Cy:["period"],Sy:(t,i)=>[[r,o(t,i.period??14)]],xy: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(he,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!Rr(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=Dr(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=Wr({r_:t,Xf:i,yy:[e],Jl:"OBV",W:n,Sy:()=>[[e,r()]],xy: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(he,{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=Wr({r_:t,Xf:i,yy:[e],Jl:"Parabolic SAR",W:n,Cy:["step","maxStep","colorUp","colorDown"],Sy:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],xy: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(he,{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=Wr({r_:t,Xf:i,yy:[h,...l,...o],Jl:"Pivot Points",W:n,Cy:["pivotPeriod"],Sy:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{MP:s,Xk:n,Gk:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=zr(_.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={Kk:i,Zk:[2*i-l,i+s,h+2*(i-l)],Jk:[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.Kk});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.Zk[t]}),e[t].push({time:_.time,value:a.Jk[t]})}}return{MP:s,Xk:n,Gk:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.MP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Xk[t]:[]]),e.push([o[t],t<n?s.Gk[t]:[]]);return e},xy: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(he,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Lr(0,100)},e),h=Ar(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Br(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Er(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=Wr({r_:t,Xf:i,yy:[r],Jl:"RSI",W:n,Cy:["period","source"],Sy:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],xy: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(he,{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=Er(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=Wr({r_:t,Xf:i,yy:[e],Jl:"SMA",W:n,Cy:["period","source"],Sy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],xy: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=Lr(0,100),h=i.addSeries(he,{color:n.colorK,autoscaleInfoProvider:r},e),l=Ar(i,h,e),o=i.addSeries(he,{color:n.colorD,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=Br(h,n.levelColor),_=Wr({r_:t,Xf:i,yy:[h,o],Jl:"Stochastic",W:n,Cy:["kPeriod","dPeriod"],Sy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{Qk:[],tD:[]};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{Qk:e,tD:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.Qk],[o,s.tD]]},xy:t=>{const i=t.lineWidth??2,s=t.lineStyle;h.applyOptions({color:t.colorK,lineWidth:i,lineStyle:s}),o.applyOptions({color:t.colorD,lineWidth:i,lineStyle:s}),a([t.overbought,t.oversold].filter(t=>"number"==typeof t))}});return{k:h,d:o,..._}},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(he,{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=Wr({r_:t,Xf:i,yy:[e],Jl:"SuperTrend",Cy:["period","multiplier","colorUp","colorDown"],W:n,Sy:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],xy: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(he,{color:n.color},e),h=i.addSeries(he,{color:n.bandColor},e),l=i.addSeries(he,{color:n.bandColor},e),o=Wr({r_:t,Xf:i,yy:[r,h,l],Jl:"VWAP",W:n,Cy:["anchorPeriod","bandMultiplier"],Sy:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Rr(t))return{iD:e,SP:r,xP:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=zr(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=Dr(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{iD:e,SP:r,xP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.iD],[h,n.SP],[l,n.xP]]},xy: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(Le,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=Ar(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||!Rr(t))return[];const e=[];for(const r of n){const n=Dr(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=Wr({r_:t,Xf:i,yy:[r],Jl:"Volume",W:n,Cy:["colorUp","colorDown"],Sy:(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(he,{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=Er(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=Wr({r_:t,Xf:i,yy:[e],Jl:"WMA",W:n,Cy:["period","source"],Sy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],xy: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(he,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Lr(-100,0)},e),h=Ar(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Br(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=Wr({r_:t,Xf:i,yy:[r],Jl:"Williams %R",W:n,Cy:["period"],Sy:(t,i)=>[[r,o(t,i.period??14)]],xy: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:qr,calculatePipConfig:Kl,coordinateFromTime:Gn,createArrowTool:Wl,createBrushTool:Ul,createChart:function(t,i){return jn(t,new ns,ns.ud(i))},createChartEx:jn,createCircleTool:Al,createCrossLineTool:Xh,createFibonacciExtensionTool:yl,createFibonacciFanTool:Tl,createFibonacciTool:wl,createGanttTool:_o,createHorizontalLineTool:Uh,createImageWatermark:function(t,i,s){return new Ae(t,new Ke(i,s))},createInteractiveLineManager:function(t,i){return new rh(t,i)},createOptionsChart:function(t,i){return jn(t,new pe,i)},createParallelChannelTool:sl,createPitchforkTool:hl,createPolygonTool:Jh,createPositionLine:function(t,i,s){return new gh(i,t,s)},createPositionMarkers:function(t,i,s){const n=new Pr(t,s);return i&&i.length>0&&n.setPositions(i),n},createPositionTool:ho,createRectangleTool:Fl,createRulerTool:so,createSeriesMarkers:mr,createTextTool:Xl,createTextWatermark:function(t,i){return new Ae(t,new Ue(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 eh(i,t,r)},createTradingSessionsIndicator:function(t,i,s){return new Gr(t,i,s)},createTrendLineTool:zh,createUpDownMarkers:function(t,i={}){return new Cr(t,new Sr(i))},createVerticalLineTool:_l,createVolumeProfileIndicator:function(t,i,s){return new Jr(t,i,s)},createYieldCurveChart:function(t,i){const s=qn(t);return new ce(s,i)},customSeriesDefaultOptions:co,defaultHorzScaleBehavior:function(){return ns},getPipConfig:Zl,hideSeriesPaint:Ir,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(kr(t.time),t.volume);Tr.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:Xn,version:function(){return"2.3.10"}});window.PipsendCharts=po,window.LightweightCharts=po}();
|