@pipsend/charts 2.3.10 → 2.3.12
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 +133 -14
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +133 -14
- package/dist/pipsend-charts.standalone.development.mjs +133 -14
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +19 -8
- package/package.json +83 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.3.
|
|
3
|
+
* Pipsend Charts v2.3.12
|
|
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,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}();
|
|
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=!1,this.vS=0,this.mS=null,this.yg=void 0,this.Lf=t,this.Rf=i,this.wS=t=>this.gS(t),this.bS=t=>this.MS(t),this.yS=t=>this.SS(t),this.xS=t=>this.CS(t),this.PS=()=>this.TS(),this.kS=t=>{"Escape"===t.key&&this.TS()},this.Lf.subscribeCrosshairMove(this.wS),this.Rf.addEventListener("pointerdown",this.bS),this.Rf.addEventListener("pointermove",this.yS),this.Rf.addEventListener("pointerup",this.xS),this.Rf.addEventListener("pointercancel",this.PS),document.addEventListener("keydown",this.kS)}DS(t){this.oS.set(t.id(),t)}RS(t){const i=t.id();this.aS===i&&this.FS(null),this.uS===t&&this.TS(),this.oS.delete(i)}Gi(){return 0===this.oS.size}m(){this.Lf.unsubscribeCrosshairMove(this.wS),this.Rf.removeEventListener("pointerdown",this.bS),this.Rf.removeEventListener("pointermove",this.yS),this.Rf.removeEventListener("pointerup",this.xS),this.Rf.removeEventListener("pointercancel",this.PS),document.removeEventListener("keydown",this.kS),this.oS.clear()}gS(t){if(this.mS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.yg=t.paneIndex,null!==this.uS)return;const i=this.IS(t.hoveredObjectId),s=null===i?null:this.oS.get(i.gl)??null;this.FS(s?s.id():null),this.VS(s,null===s?null:i?.LS??null),this.AS()}MS(t){this.fS="mouse"!==t.pointerType;let i=this.fS||null===this.aS?null:this.oS.get(this.aS)??null;null===i&&(i=this.ES(t)),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.vS=this.BS(i,t),this.AS(),t.preventDefault(),t.stopPropagation())):this.OS()}SS(t){if(null===this.uS)return;if(!this.WS(t))return void this.TS();const i=this.zS(t);null!==i&&this.uS.dragTo(i),t.preventDefault(),t.stopPropagation()}CS(t){const i=this.uS,s=this.fS,n=this.pS,e=this.dS;this.$S(),this.pS=null,this.dS=null;const r=s?12:4,h=null!==e&&(Math.abs(t.clientX-e.ut)>r||Math.abs(t.clientY-e.ct)>r);if(null!==i)return this.uS=null,this.vS=0,h?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),this.OS(s),void this.AS();null!==n&&!h&&n.isClickable()&&n.click(),this.OS(s)}OS(t=this.fS){if(!t||null===this.aS)return;const i=this.oS.get(this.aS)??null;this.FS(null),this.VS(i,null),this.AS()}TS(){if(null===this.uS)return;const t=this.uS;this.uS=null,this.vS=0,this.$S(),t.cancelDrag(),this.AS()}WS(t){const i=this.Rf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}$S(){null!==this.cS&&(this.Rf.hasPointerCapture(this.cS)&&this.Rf.releasePointerCapture(this.cS),this.cS=null)}zS(t){const i=this.uS;if(null===i)return null;const s=this.HS(i,t);return null===s?null:i.priceAt(s-this.vS)}ES(t){for(const i of this.oS.values()){if(!i.hitTestAt)continue;const s=this.NS(i);if(null===s)continue;const n=s.getBoundingClientRect(),e="mouse"===t.pointerType?0:12,r=this.IS(i.hitTestAt(t.clientX-n.left,t.clientY-n.top,e));if(null!==r)return this.FS(i.id()),this.VS(i,r.LS),i}return null}NS(t){const i=this.Lf.panes()[t.paneIndex()];return i?i.getHTMLElement():null}HS(t,i){const s=this.NS(t);return s?i.clientY-s.getBoundingClientRect().top:null!==this.mS&&this.yg===t.paneIndex()?this.mS.ct:null}BS(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.HS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}IS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,LS:null}:{gl:t.slice(0,i),LS:t.slice(i+1)}}VS(t,i){this._S!==i&&(this._S=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}FS(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))}AS(){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.RS(i),s.Gi()&&(s.m(),th.delete(t)))}let nh=0;class eh{constructor(t,i,s){this.sr=null,this.US=!1,this.qS="",this.jS=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.YS(),(this.Ps.draggable||this.Ps.onClick)&&ih(this.Lf)?.DS(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.US!==t&&this.sr&&(this.US=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.qS}))}hitTestAt(t,i,s=0){const n=this.be.priceToCoordinate(this.Ps.price);return null!==n&&Math.abs(i-n)<=8+s?this.So:null}priceAt(t){const i=this.be.coordinateToPrice(t);return null===i?null:i}beginDrag(){this.jS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.XS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.jS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.jS;this.jS=null,null!==t&&t!==this.Ps.price&&(this.XS(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.qS=t.color),!this.sr)return;const i={title:this.GS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.US||(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.XS(t)}remove(){sh(this.Lf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}GS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}YS(){this.qS=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.GS()})}XS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.GS()})}}class rh{constructor(t,i){this.Vf=null,this.KS=null,this.ZS=null,this.JS={},this.Lf=t,this.be=i,this.QS()}QS(){this.Vf=this.Lf.chartElement()}tx(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.KS=t,this.JS=i||{},new Promise(t=>{this.Vf.style.cursor="crosshair",this.ZS=i=>{const s=this.tx(i),n=this.ix(s);this.disableClickToCreate(),t(n)},this.Vf.addEventListener("click",this.ZS)})):Promise.resolve(null)}disableClickToCreate(){this.Vf&&this.ZS&&(this.Vf.removeEventListener("click",this.ZS),this.Vf.style.cursor="default"),this.KS=null,this.ZS=null,this.JS={}}ix(t){if(!this.KS)return null;let i;switch(this.KS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.JS};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.JS};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.JS};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.JS};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.JS};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.JS};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.JS};break;default:return null}return new eh(this.Lf,this.be,i)}getCreationMode(){return this.KS}isCreating(){return null!==this.KS}}class hh{constructor(){this.sx=[],this.nx=new Map,this.hx=new Map,this.xt=!0}DS(t){this.nx.has(t)||(this.sx.push(t),this.nx.set(t,[]),this.xt=!0)}RS(t){const i=this.sx.indexOf(t);-1!==i&&this.sx.splice(i,1),this.nx.delete(t),this.xt=!0}Gi(){return 0===this.sx.length}lx(t,i){this.nx.set(t,i),this.xt=!0}ox(t,i){return this.xt&&this._x(),this.hx.get(lh(t,i))??0}_x(){const t=new Map,i=[];for(const s of this.sx)for(const n of this.nx.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.hx=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.ux=[],this.vx=0,this.Uf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.Yt=t}Xn(t,i,s=0){for(const n of this.ux)if(n.mx&&t>=n.wx-s&&t<=n.gx+s&&Math.abs(i-n.bx)<=n.qt/2+s)return{sn:n.sn,LS:"close"};for(const n of this.ux)if(t>=n.Mx-s&&t<=n.yx+s&&Math.abs(i-n.bx)<=n.qt/2+s)return{sn:n.sn,LS:"body"};for(const t of this.ux)if(Math.abs(i-t.ct)<=8+s)return{sn:t.sn,LS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.lw(t))}lw(t){const i=this.Yt;if(this.ux=[],null===i||0===i.Sx.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.vx=Math.max(0,n.width-i.yu);const e=i.xx?this.vx:n.width;for(const s of i.Sx)this.ux.push(this.Cx(t,i,s,e));i.xx&&i.Sx.length>1&&this.Px(t,i),s.restore()}Cx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Tx,o=0===s.kx.length?0:Math.max(this.Wn.Ii(e,s.kx)+2*i.yM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.yM,_=s.mx?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Dx,f=p-l/2;this.Rx(t,s,d,c,n),this.Fx(t,i,s,{qh:d,Ix:f,ts:u,qt:l});let v=d;return o>0&&(this.Vx(t,i,s,{qh:v,Ix:f,ts:o,qt:l}),v+=o,this.Lx(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.mx&&(this.Lx(e,s.R,v,f,l,r,h),this.Ax(t,i,s,{qh:v,Ix:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,bx:p,qt:l,Mx:d,yx:c,wx:v,gx:v+_,mx:s.mx}}Rx(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.Dx?(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()}Fx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Ex===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),fh(e,n,i.Bx,r,h),e.fillStyle=this.Po.X(i.Z,i.Ox),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}Vx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Wx){const t=i.Wt;e.save(),fh(e,{qh:n.qh+t,Ix:n.Ix+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Bx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Wx?i.zx:s.R,e.fillText(s.kx,n.qh+n.ts/2,n.Ix+n.qt/2),e.restore()}Lx(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()}Ax(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Ex===s.sn&&"close"===i.$x){e.save();const t=i.Wt;fh(e,{qh:n.qh,Ix:n.Ix+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Bx-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.Ix+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()}Px(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Sx.find(t=>"entry"===t.sn)??i.Sx[0],h=i.Sx.map(t=>t.ct),l=Math.round(this.vx*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.Sx)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.Ox),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.Ix*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,s=0){return null===this.Yt?null:this.Jt.Xn(t,i,s)}}class mh{constructor(t){this.Qt=t}coordinate(){return this.Hx()?.Li??-1e3}text(){return this.Hx()?.hi??""}textColor(){return this.Hx()?.DM??"#FFFFFF"}backColor(){return this.Hx()?.R??"#000000"}visible(){return null!==this.Hx()}Hx(){return this.Qt()}}let wh=0;class gh{constructor(t,i,s){this.eh=new vh,this.Po=new S([]),this.Nx=!1,this.Ux=null,this._S=null,this.qx=null,this.jS=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.jx=dh.map(t=>new mh(()=>this.Yx(t))),this.Xx=function(t,i){let s=_h.get(t);return s||(s=new hh,_h.set(t,s)),s.DS(i),s}(this.Lf,this.So),this.be.attachPrimitive(this),ih(this.Lf)?.DS(this)}attached(t){this.pM=t.requestUpdate,this.Nx=!0,this.requestUpdate()}detached(){this.Nx=!1,this.pM=void 0}paneViews(){return this.Jb}priceAxisViews(){return this.jx}updateAllViews(){this.eh.Tt(this.Gx())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.Kx(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.LS}`,zOrder:"top",cursorStyle:"close"===s.LS?"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.Ux===n&&this._S===e||(this.Ux=n,this._S=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Ux&&"close"!==this._S&&(this.Kx(this.Ux)?.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}hitTestAt(t,i,s=0){const n=this.eh.Xn(t,i,s);return null===n||null===this.Kx(n.sn)?null:`${this.So}#${n.sn}:${n.LS}`}dragAnchorY(){if(null===this.qx)return null;const t=this.Kx(this.qx)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.qx=this.Ux,null===this.qx)return;const t=this.Kx(this.qx)?.price??null;this.jS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.qx,t)}dragTo(t){null!==this.qx&&(this.Zx(this.qx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.qx,t))}commitDrag(){const t=this.qx;if(this.qx=null,this.jS=null,null===t)return;const i=this.Kx(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.qx,i=this.jS;if(this.qx=null,this.jS=null,null===t)return;null!==i&&i!==this.Kx(t)?.price&&(this.Zx(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.Kx(t)?.price??0)}click(){const t=this.Ux;if(null===t)return;if("close"===this._S)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.Kx(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.qx,s=null===i?void 0:this.Kx(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.Kx(i);null!==t&&(t.price=s)}t.theme&&(this.If={...this.If,...t.theme}),this.requestUpdate()}setPrice(t,i){this.qx!==t&&this.Zx(t,i)}setText(t,i){const s=this.Kx(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of dh){const s=this.Kx(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.RS(i),s.Gi()&&_h.delete(t))}(this.Lf,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.pM&&this.pM()}Yx(t){const i=this.Kx(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}}Kx(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}Zx(t,i){const s=this.Kx(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}Gx(){if(!this.Nx||!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.Kx(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,Dx:0,R:i.color??uh[t],hi:i.formatText?i.formatText(i.price):i.text??"",kx:i.badge??"",Wx:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),mx:i.closable??!0,Jx:i.draggable??!0})}if(0===n.length)return this.Xx.lx(this.So,[]),null;this.Xx.lx(this.So,e);for(const t of n)t.Dx=this.Xx.ox(this.So,t.sn);return{Sx:n,Z:this.If.background??(r=t.background,"solid"===r.type?r.color:r.topColor),DM:this.If.textColor,zx:this.If.badgeTextColor,Bx:this.If.borderRadius,Wt:this.If.borderWidth,yM:this.If.paddingX,Tx:this.If.paddingY,Ox:this.If.backgroundOpacity,T:g(i,this.If.fontFamily??t.fontFamily),P:i,xx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,Ex:this.Ux,$x: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.Qx(),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}Qx(){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.tC="idle",t.iC="waiting_first_point",t.sC="waiting_second_point",t.nC="completed"}(Ah||(Ah={}));class Eh{constructor(t,i,s={}){this.Lv=Ah.tC,this.eC=null,this.ZS=null,this.ep=null,this.Lf=t,this.be=i,this.rC=s}hC(){this.Lv===Ah.tC&&(this.Lv=Ah.iC,this.eC=null,this.lC(),this.oC())}aC(){this.Lv=Ah.tC,this.eC=null,this._C(),this.uC(),this.rC.cC&&this.rC.cC()}dC(){return this.Lv}pC(){return this.Lv===Ah.iC||this.Lv===Ah.sC}lC(){this.ZS=t=>{this.fC(t)},this.Lf.subscribeClick(this.ZS)}oC(){this.ep=t=>{this.vC(t)},this.Lf.subscribeCrosshairMove(this.ep)}_C(){this.ZS&&(this.Lf.unsubscribeClick(this.ZS),this.ZS=null)}uC(){this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null)}fC(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.iC?(this.eC=n,this.Lv=Ah.sC,this.rC.mC&&this.rC.mC(n)):this.Lv===Ah.sC&&this.eC&&(this.Lv=Ah.nC,this.rC.wC&&this.rC.wC(n),this.rC.gC&&this.rC.gC(this.eC,n),this._C(),this.uC(),this.Lv=Ah.tC,this.eC=null)}vC(t){if(!t.point)return;if(this.Lv!==Ah.sC)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.rC.bC&&this.rC.bC(n)}m(){this.aC()}}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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.kC=null,this.DC=null,this.RC=!1,this.FC=null,this.IC=null,this.VC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.VC),this.Hy(),this.VC.interactive?this.LC():this.RC=!0}LC(){const t=new Eh(this._chart,this._series,{mC:t=>{this.VC.point1Time=t.gt,this.VC.point1Price=t.bt,this.pM()},wC:t=>{this.VC.point2Time=t.gt,this.VC.point2Price=t.bt,this.RC=!0,this.pM(),this.VC.onUpdate&&this.VC.onUpdate()},bC:t=>{this.VC.point1Time&&!this.RC&&(this.IC=t,this.pM())},gC:()=>{this.RC=!0}});this.FC=t,t.hC()}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new Oh(this)}BC(){if(!this.VC.point1Time||!this.VC.point2Time)return null;const t=Gn(this._chart,this._series,this.VC.point1Time)??0,i=this._series.priceToCoordinate(this.VC.point1Price)??0,s=Gn(this._chart,this._series,this.VC.point2Time)??0,n=this._series.priceToCoordinate(this.VC.point2Price)??0;if(!this.VC.extendLeft&&!this.VC.extendRight)return{OC:t,WC:i,zC:s,$C:n};if(s===t)return{OC:t,WC:i,zC:s,$C:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{OC:this.VC.extendLeft?0:t,WC:this.VC.extendLeft?i-r*t:i,zC:this.VC.extendRight?e:s,$C:this.VC.extendRight?i+r*(e-t):n}}HC(){const t=this.BC();if(null===t)return null;const i=t.zC>=t.OC?t.$C:t.WC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.VC.point2Price??this.VC.point1Price??null}drawToCanvas(t,i,s){if(!this.RC&&this.VC.point1Time&&this.IC)return void this.NC(t,i,s);if(!this.VC.point1Time||!this.VC.point2Time)return;const n=(Gn(this._chart,this._series,this.VC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.VC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.VC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.VC.point2Price)??0)*s,l=this.VC.lineColor,o=this.SC?this.VC.lineWidth+1:this.VC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.VC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.VC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.BC();if(null===a)return;t.moveTo(a.OC*i,a.WC*s),t.lineTo(a.zC*i,a.$C*s),t.stroke(),t.setLineDash([]),!this.SC&&!this.xC||this.isLocked()||(this.UC(t,n,e,i,l),this.UC(t,r,h,i,l));const _=this.HC();if(!1!==this.VC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Lh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}NC(t,i,s){if(!this.VC.point1Time||!this.IC)return;const n=(Gn(this._chart,this._series,this.VC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.VC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.IC.gt)??0)*i,h=(this._series.priceToCoordinate(this.IC.bt)??0)*s;t.strokeStyle=this.VC.lineColor,t.lineWidth=this.VC.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.UC(t,n,e,i,this.VC.lineColor),t.globalAlpha=.5,this.UC(t,r,h,i,this.VC.lineColor),t.globalAlpha=1}UC(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.VC.lineColor=t,this.pM()}color(){return this.VC.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}isHovered(){return this.xC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}EC(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.BC();if(null===s)return!1;return this.qC(t,i,s.OC,s.WC,s.zC,s.$C)<=8}qC(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.VC.point1Time||!this.VC.point2Time)return null;const s=Gn(this._chart,this._series,this.VC.point1Time)??0,n=this._series.priceToCoordinate(this.VC.point1Price)??0,e=Gn(this._chart,this._series,this.VC.point2Time)??0,r=this._series.priceToCoordinate(this.VC.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.qC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.CC=!0,this.PC=t,this.TC=i,"line"===t&&(this.kC={gt:this.VC.point1Time,bt:this.VC.point1Price},this.DC={gt:this.VC.point2Time,bt:this.VC.point2Price})}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.kC=null,this.DC=null}updateDrag(t,i){if(this.CC&&this.PC){if("point1"===this.PC)this.VC.point1Time=t,this.VC.point1Price=i;else if("point2"===this.PC)this.VC.point2Time=t,this.VC.point2Price=i;else if("line"===this.PC&&this.kC&&this.DC){const s=Sh(this.TC,t,i);this.VC.point1Time=this.kC.gt+s.gt,this.VC.point1Price=this.kC.bt+s.bt,this.VC.point2Time=this.DC.gt+s.gt,this.VC.point2Price=this.DC.bt+s.bt}this.pM(),this.VC.onUpdate&&this.VC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Ph(this.VC.point1Price??0,Ch(this.VC.point1Time)),Ph(this.VC.point2Price??0,Ch(this.VC.point2Time))],style:{lineColor:this.VC.lineColor,lineWidth:this.VC.lineWidth,lineStyle:this.VC.lineStyle,extendLeft:this.VC.extendLeft,extendRight:this.VC.extendRight}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return this.RC}remove(){this.FC&&(this.FC.m(),this.FC=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.VC.onRemove&&this.VC.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.TC=null,this.jC=0,this.YC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.YC),this.Hy()}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new Hh(this)}XC(){return void 0===this.YC.startTime?0:Gn(this._chart,this._series,this.YC.startTime)??0}drawToCanvas(t,i,s){if(void 0===this.YC.price)return;const n=(this._series.priceToCoordinate(this.YC.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.XC()*i,h=this.YC.lineColor,l=this.SC?this.YC.lineWidth+1:this.YC.lineWidth;t.strokeStyle=h,t.lineWidth=l*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(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.YC.showPriceLabel&&Lh(t,this._series,i,s,{bt:this.YC.price,ct:n/s,Ot:h}),this.YC.showLabel&&(this.SC||this.xC)&&this.GC(t,n,i,s,h)}GC(t,i,s,n,e){const r=this.YC.labelText||this.YC.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.YC.lineColor=t,this.pM()}color(){return this.YC.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.YC.price)return!1;const s=this._series.priceToCoordinate(this.YC.price)??0;return!(t<this.XC()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.CC=!0,this.TC=i,this.jC=this.YC.price??0}stopDrag(){this.CC=!1,this.TC=null}updateDrag(t,i){this.CC&&(this.YC.price=this.jC+Sh(this.TC,t,i).bt,this.pM(),this.YC.onUpdate&&this.YC.onUpdate())}getPrice(){return this.YC.price}setPrice(t){this.YC.price=t,this.pM()}setLabel(t){this.YC.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Ph(this.YC.price??0,Ch(this.YC.startTime))],style:{lineColor:this.YC.lineColor,lineWidth:this.YC.lineWidth,lineStyle:this.YC.lineStyle,showLabel:this.YC.showLabel,labelText:this.YC.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.YC.onRemove&&this.YC.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.TC=null,this.KC=0,this.jC=0,this.ZC={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.ZC),this.Hy()}Hy(){this.eh=new jh(this);const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.yC&&this.yC()}_update(){this.pM()}JC(){if(void 0===this.ZC.time||void 0===this.ZC.price)return null;const t=Gn(this._chart,this._series,this.ZC.time),i=this._series.priceToCoordinate(this.ZC.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.JC();if(null===n)return;const e=this._chart.chartElement(),r=e.clientWidth*i,h=e.clientHeight*s,l=n.ut*i,o=n.ct*s,a=this.ZC.lineColor,_=this.SC||this.xC&&!this.isLocked(),u=_?this.ZC.lineWidth+1:this.ZC.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.ZC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.ZC.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.ZC.showPriceLabel&&void 0!==this.ZC.price&&Lh(t,this._series,i,s,{bt:this.ZC.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())}EC(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.JC();if(null===s)return!1;return Math.abs(i-s.ct)<=8||Math.abs(t-s.ut)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.CC=!0,this.TC=i,this.KC=this.ZC.time,this.jC=this.ZC.price??0}updateDrag(t,i){if(!this.CC)return;const s=Sh(this.TC,t,i);this.ZC.time=this.KC+s.gt,this.ZC.price=this.jC+s.bt,this.pM(),this.ZC.onUpdate&&this.ZC.onUpdate()}stopDrag(){this.CC=!1,this.TC=null}setColor(t){this.ZC.lineColor=t,this.pM()}color(){return this.ZC.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}remove(){if(this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.yC=null,this.ZC.onRemove&&this.ZC.onRemove()}_serializeShape(){return{type:"crossLine",points:[Ph(this.ZC.price??0,Ch(this.ZC.time))],style:{lineColor:this.ZC.lineColor,lineWidth:this.ZC.lineWidth,lineStyle:this.ZC.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.QC=null,this.RC=!1,this.IC=null,this.ZS=null,this.tP=null,this.iP=null,this.sP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.sP),this.V_=[...i.points??[]],this.Hy(),this.sP.interactive?this.nP():this.RC=this.V_.length>=3}Hy(){this.eh=new Kh(this);const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.yC&&this.yC()}_update(){this.pM()}nP(){this.ZS=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.eP(t.point.x,t.point.y)?this.rP():(this.V_.push({time:s,price:i}),this.pM()))},this.tP=t=>{if(!t.point||this.RC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.IC={time:s,price:i},this.pM())},this.iP=t=>{"Enter"===t.key&&this.V_.length>=3?this.rP():"Escape"===t.key&&(this.V_=[],this.rP())},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.tP),document.addEventListener("keydown",this.iP)}eP(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.hP&&Math.abs(i-e)<=Zh.hP)}rP(){this.RC=!0,this.IC=null,this.lP(),this.pM(),this.sP.onComplete&&this.sP.onComplete(),this.sP.onUpdate&&this.sP.onUpdate()}lP(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.tP&&(this._chart.unsubscribeCrosshairMove(this.tP),this.tP=null),this.iP&&(document.removeEventListener("keydown",this.iP),this.iP=null)}oP(){const t=[...this.V_];return this.RC||null===this.IC||t.push(this.IC),this.aP(t)}aP(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.oP();if(n.length<2)return;const e=this.sP.borderColor,r=this.SC?this.sP.borderWidth+1:this.sP.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.RC&&(t.closePath(),this.sP.fillOpacity>0&&(t.fillStyle=this.Vy(this.sP.fillColor,this.sP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.RC?"dashed"===this.sP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.sP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.SC||this.xC||!this.RC)&&!this.isLocked())for(const n of this._P())this.uP(t,n.ut*i,n.ct*s,i,e)}_P(){return this.aP(this.V_)}uP(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})`}EC(t,i){if(!this.isVisible()||!this.RC)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._P();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._P();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.CC=!0,this.PC=t,this.TC=i,this.QC=this.V_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.CC&&null!==this.PC&&null!==this.QC){if("shape"===this.PC){const s=Sh(this.TC,t,i);this.V_=this.QC.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.PC;this.V_[s]&&(this.V_[s]={time:t,price:i})}this.pM(),this.sP.onUpdate&&this.sP.onUpdate()}}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.QC=null}setColor(t){this.sP.borderColor=t,this.sP.fillColor=t,this.pM()}color(){return this.sP.borderColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}points(){return this.V_}isComplete(){return this.RC}remove(){if(this.lP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.yC=null,this.sP.onRemove&&this.sP.onRemove()}_serializeShape(){return{type:"polygon",points:this.V_.map(t=>Ph(t.price,Ch(t.time))),style:{fillColor:this.sP.fillColor,fillOpacity:this.sP.fillOpacity,borderColor:this.sP.borderColor,borderWidth:this.sP.borderWidth,borderStyle:this.sP.borderStyle}}}}function Jh(t,i){return new Zh(t,i)}Zh.hP=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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.cP=null,this.RC=!1,this.dd=0,this.IC=null,this.ZS=null,this.tP=null,this.dP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.dP),this.Hy(),this.dP.interactive?this.nP():this.RC=!0}Hy(){this.eh=new tl(this);const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.yC&&this.yC()}_update(){this.pM()}nP(){this.ZS=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.dP.point1Time=s,this.dP.point1Price=i;else{if(1!==this.dd)return this.dP.channelWidth=i-this.pP(s),void this.rP();this.dP.point2Time=s,this.dP.point2Price=i}this.dd++,this.pM()}},this.tP=t=>{if(!t.point||this.RC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.IC={gt:s,bt:i},2===this.dd&&(this.dP.channelWidth=i-this.pP(s)),this.pM())},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.tP)}rP(){this.RC=!0,this.IC=null,this.lP(),this.pM(),this.dP.onComplete&&this.dP.onComplete(),this.dP.onUpdate&&this.dP.onUpdate()}lP(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.tP&&(this._chart.unsubscribeCrosshairMove(this.tP),this.tP=null)}pP(t){const i=this.dP.point1Time,s=this.dP.point2Time,n=this.dP.point1Price,e=this.dP.point2Price;if(void 0===i||void 0===n)return 0;if(void 0===s||void 0===e||s===i)return n;return n+(e-n)/(s-i)*(t-i)}oS(){const t=this.dP,i=this.RC?t.point2Time:t.point2Time??this.IC?.gt,s=this.RC?t.point2Price:t.point2Price??this.IC?.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:{OC:n,zC:l,fP:r,vP:o,mP:_,wP:u}}drawToCanvas(t,i,s){const n=this.oS();if(null===n)return;const e=this.dP,r=e.lineColor,h=this.SC?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.OC*l,n.fP*o),t.lineTo(n.zC*l,n.vP*o),t.lineTo(n.zC*l,n.wP*o),t.lineTo(n.OC*l,n.mP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.RC?"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.OC*l,n.fP*o),t.lineTo(n.zC*l,n.vP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.OC*l,n.mP*o),t.lineTo(n.zC*l,n.wP*o)),t.stroke(),t.setLineDash([]);if((this.SC||this.xC||!this.RC)&&!this.isLocked()&&(this.uP(t,n.OC*l,n.fP*o,l,r),this.uP(t,n.zC*l,n.vP*o,l,r),0!==(e.channelWidth??0))){const i=(n.OC+n.zC)/2,s=(n.mP+n.wP)/2;this.uP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.RC){const i=this._series.coordinateToPrice(n.vP);null!==i&&Lh(t,this._series,l,o,{bt:i,ct:n.vP,Ot:r})}}uP(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})`}EC(t,i){if(!this.isVisible()||!this.RC)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}gP(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.gP(t,i,s.OC,s.fP,s.zC,s.vP)<=8||this.gP(t,i,s.OC,s.mP,s.zC,s.wP)<=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.OC,s.fP))return"point1";if(n(s.zC,s.vP))return"point2";if(0!==(this.dP.channelWidth??0)){if(n((s.OC+s.zC)/2,(s.mP+s.wP)/2))return"width"}return null}startDrag(t,i){this.CC=!0,this.PC=t,this.TC=i,this.cP={bP:{gt:this.dP.point1Time,bt:this.dP.point1Price},MP:{gt:this.dP.point2Time,bt:this.dP.point2Price},ts:this.dP.channelWidth??0}}updateDrag(t,i){if(!this.CC||null===this.PC||null===this.cP)return;const s=this.dP;if("point1"===this.PC)s.point1Time=t,s.point1Price=i;else if("point2"===this.PC)s.point2Time=t,s.point2Price=i;else if("width"===this.PC)s.channelWidth=i-this.pP(t);else{const n=Sh(this.TC,t,i);s.point1Time=this.cP.bP.gt+n.gt,s.point1Price=this.cP.bP.bt+n.bt,s.point2Time=this.cP.MP.gt+n.gt,s.point2Price=this.cP.MP.bt+n.bt,s.channelWidth=this.cP.ts}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.cP=null}setColor(t){this.dP.lineColor=t,this.dP.fillColor=t,this.pM()}color(){return this.dP.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}isComplete(){return this.RC}remove(){if(this.lP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.yC=null,this.dP.onRemove&&this.dP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Ph(this.dP.point1Price??0,Ch(this.dP.point1Time)),Ph(this.dP.point2Price??0,Ch(this.dP.point2Time))],style:{lineColor:this.dP.lineColor,lineWidth:this.dP.lineWidth,lineStyle:this.dP.lineStyle,fillColor:this.dP.fillColor,fillOpacity:this.dP.fillOpacity,extendRight:this.dP.extendRight},extra:{channelWidth:this.dP.channelWidth}}}}function 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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.cP=null,this.RC=!1,this.dd=0,this.IC=null,this.ZS=null,this.tP=null,this.yP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.yP),this.Hy(),this.yP.interactive?this.nP():this.RC=!0}Hy(){this.eh=new el(this);const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.yC&&this.yC()}_update(){this.pM()}nP(){this.ZS=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.yP.pivotTime=s,this.yP.pivotPrice=i;else{if(1!==this.dd)return this.yP.lowerTime=s,this.yP.lowerPrice=i,this.dd++,void this.rP();this.yP.upperTime=s,this.yP.upperPrice=i}this.dd++,this.pM()}},this.tP=t=>{if(!t.point||this.RC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.IC={gt:s,bt:i},this.pM())},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.tP)}rP(){this.RC=!0,this.IC=null,this.lP(),this.pM(),this.yP.onComplete&&this.yP.onComplete(),this.yP.onUpdate&&this.yP.onUpdate()}lP(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.tP&&(this._chart.unsubscribeCrosshairMove(this.tP),this.tP=null)}SP(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}}xP(){const t=this.yP,i=this.SP(t.pivotTime,t.pivotPrice),s=this.SP(t.upperTime,t.upperPrice),n=this.RC?this.SP(t.lowerTime,t.lowerPrice):this.SP(t.lowerTime,t.lowerPrice)??(null!==this.IC&&this.dd>=2?this.SP(this.IC.gt,this.IC.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{CP:i,PP:e,TP:s,kP:n,DP:l(i),RP:l(s),FP:l(n)}}drawToCanvas(t,i,s){const n=this.xP();if(null===n)return void this.IP(t,i,s);const e=this.yP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.Vy(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.TP.ut*h,n.TP.ct*l),t.lineTo(n.RP.ut*h,n.RP.ct*l),t.lineTo(n.FP.ut*h,n.FP.ct*l),t.lineTo(n.kP.ut*h,n.kP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.SC?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.TP.ut*h,n.TP.ct*l),t.lineTo(n.kP.ut*h,n.kP.ct*l),t.moveTo(n.CP.ut*h,n.CP.ct*l),t.lineTo(n.DP.ut*h,n.DP.ct*l),t.moveTo(n.TP.ut*h,n.TP.ct*l),t.lineTo(n.RP.ut*h,n.RP.ct*l),t.moveTo(n.kP.ut*h,n.kP.ct*l),t.lineTo(n.FP.ut*h,n.FP.ct*l),t.stroke(),t.setLineDash([]);if((this.SC||this.xC||!this.RC)&&!this.isLocked())for(const i of[n.CP,n.TP,n.kP])this.uP(t,i.ut*h,i.ct*l,h,r)}IP(t,i,s){const n=this.yP,e=this.SP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.SP(n.upperTime,n.upperPrice)??(null!==this.IC?this.SP(this.IC.gt,this.IC.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.uP(t,e.ut*i,e.ct*s,i,h)}uP(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})`}EC(t,i){if(!this.isVisible()||!this.RC)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}gP(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.xP();if(null===s)return!1;return[[s.CP,s.DP],[s.TP,s.RP],[s.kP,s.FP],[s.TP,s.kP]].some(([s,n])=>this.gP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.xP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.CP)?"pivot":n(s.TP)?"upper":n(s.kP)?"lower":null}startDrag(t,i){this.CC=!0,this.PC=t,this.TC=i,this.cP=[{gt:this.yP.pivotTime,bt:this.yP.pivotPrice},{gt:this.yP.upperTime,bt:this.yP.upperPrice},{gt:this.yP.lowerTime,bt:this.yP.lowerPrice}]}updateDrag(t,i){if(!this.CC||null===this.PC||null===this.cP)return;const s=this.yP;if("pivot"===this.PC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.PC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.PC)s.lowerTime=t,s.lowerPrice=i;else{const n=Sh(this.TC,t,i),[e,r,h]=this.cP;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.CC=!1,this.PC=null,this.TC=null,this.cP=null}setColor(t){this.yP.lineColor=t,this.yP.fillColor=t,this.pM()}color(){return this.yP.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}isComplete(){return this.RC}remove(){if(this.lP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.yC=null,this.yP.onRemove&&this.yP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Ph(this.yP.pivotPrice??0,Ch(this.yP.pivotTime)),Ph(this.yP.upperPrice??0,Ch(this.yP.upperTime)),Ph(this.yP.lowerPrice??0,Ch(this.yP.lowerTime))],style:{lineColor:this.yP.lineColor,lineWidth:this.yP.lineWidth,lineStyle:this.yP.lineStyle,fillColor:this.yP.fillColor,fillOpacity:this.yP.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.TC=null,this.KC=0,this.VP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.VP),this.Hy()}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new ol(this)}drawToCanvas(t,i,s){if(void 0===this.VP.time)return;const n=(Gn(this._chart,this._series,this.VP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.VP.lineColor,h=this.SC||this.xC&&!this.isLocked()?this.VP.lineWidth+1:this.VP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.VP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.VP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.VP.showLabel&&(this.SC||this.xC)&&this.VP.labelText&&this.GC(t,n,i,s,r)}GC(t,i,s,n,e){const r=this.VP.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.VP.lineColor=t,this.pM()}color(){return this.VP.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.VP.time)return!1;const s=Gn(this._chart,this._series,this.VP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.CC=!0,this.TC=i,this.KC=this.VP.time}stopDrag(){this.CC=!1,this.TC=null}updateDrag(t,i){this.CC&&(this.VP.time=this.KC+Sh(this.TC,t,i).gt,this.pM(),this.VP.onUpdate&&this.VP.onUpdate())}getTime(){return this.VP.time}setTime(t){this.VP.time=t,this.pM()}setLabel(t){this.VP.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Ph(0,Ch(this.VP.time))],style:{lineColor:this.VP.lineColor,lineWidth:this.VP.lineWidth,lineStyle:this.VP.lineStyle,showLabel:this.VP.showLabel,labelText:this.VP.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.VP.onRemove&&this.VP.onRemove()}}function _l(t,i){return new al(t,i)}const ul=[{LP:0,Jl:"0.0%"},{LP:.236,Jl:"23.6%"},{LP:.382,Jl:"38.2%"},{LP:.5,Jl:"50.0%"},{LP:.618,Jl:"61.8%"},{LP:.786,Jl:"78.6%"},{LP:1,Jl:"100.0%"}],cl=[...ul,{LP:1.272,Jl:"127.2%"},{LP:1.414,Jl:"141.4%"},{LP:1.618,Jl:"161.8%"},{LP:2,Jl:"200.0%"},{LP:2.618,Jl:"261.8%"}];class dl{constructor(t=!1){this.AP=t?cl:ul}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.AP.map(({LP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{LP: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.AP=t}getRatios(){return[...this.AP]}getRatioValues(){return this.AP.map(t=>t.LP)}useStandardRatios(){this.AP=ul}useExtendedRatios(){this.AP=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{LP:t,Jl:`${(100*t).toFixed(1)}%`}}class ml extends Rh{constructor(t,i){super(t,"fibonacci-tool",i),this.jb=null,this.yC=null,this.Gb=null,this.eh=null,this.EP=null,this.RC=!1,this.SC=!1,this.xC=!1,this.IC=null,this.CC=!1,this.BP=null,this.ep=null,this.OP={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.OP),this.WP=new dl(this.OP.useExtended),void 0!==this.OP.levels&&this.OP.levels.length>0&&this.WP.updateRatios(this.OP.levels.map(vl)),this.Hy(),this.OP.interactive?this.LC():(this.RC=!0,this.zP())}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new fl(this)}drawToCanvas(t,i,s){if(!this.RC&&this.OP.point1Time&&this.IC)return void this.NC(t,i,s);if(!this.Gb||!this.OP.point1Time||!this.OP.point2Time)return;const n=(Gn(this._chart,this._series,this.OP.point1Time)??0)*i,e=(Gn(this._chart,this._series,this.OP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.SC?2:this.OP.lineWidth;this.Gb.levels.forEach(n=>{this.Cx(t,n,r,h,i,s,l)}),!this.SC&&!this.xC||this.isLocked()||(this.UC(t,n,(this._series.priceToCoordinate(this.OP.point1Price)??0)*s,i),this.UC(t,e,(this._series.priceToCoordinate(this.OP.point2Price)??0)*s,i))}Cx(t,i,s,n,e,r,h=1){const l=i.ratio??i.LP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.OP.levelColors?.[l.toString()]||this.OP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.OP.showLabels&&this.GC(t,i,s,n,a,e,_)}GC(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.WP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.OP.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.OP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}zP(){this.OP.point1Time&&this.OP.point1Price&&this.OP.point2Time&&this.OP.point2Price&&(this.Gb=this.WP.calculateLevels(this.OP.point1Time,this.OP.point1Price,this.OP.point2Time,this.OP.point2Price),this.OP.onUpdate&&this.Gb&&this.OP.onUpdate(this.Gb))}updatePoints(t,i,s,n){this.OP.point1Time=t,this.OP.point1Price=i,this.OP.point2Time=s,this.OP.point2Price=n,this.zP(),this.pM()}getMetrics(){return this.Gb}getLevels(){return this.Gb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.WP.getRatioValues();return{type:"fibRetracement",points:[Ph(this.OP.point1Price??0,Ch(this.OP.point1Time)),Ph(this.OP.point2Price??0,Ch(this.OP.point2Time))],style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,showLabels:this.OP.showLabels,labelPosition:this.OP.labelPosition,levelColors:this.OP.levelColors},extra:{levels:t,useExtended:this.OP.useExtended}}}useExtendedLevels(t){this.OP.useExtended=t,t?this.WP.useExtendedRatios():this.WP.useStandardRatios(),this.zP(),this.pM()}LC(){this.EP=new Eh(this._chart,this._series,{mC:t=>{this.OP.point1Time=t.gt,this.OP.point1Price=t.bt,this.pM()},wC:t=>{this.OP.point2Time=t.gt,this.OP.point2Price=t.bt},gC:(t,i)=>{this.OP.point1Time=t.gt,this.OP.point1Price=t.bt,this.OP.point2Time=i.gt,this.OP.point2Price=i.bt,this.RC=!0,this.IC=null,this.zP(),this.$P(),this.pM()},bC:t=>{this.IC=t,this.pM()}}),this.EP.hC()}NC(t,i,s){if(!this.OP.point1Time||!this.IC)return;const n=(Gn(this._chart,this._series,this.OP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.OP.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.IC.gt)??0)*i,h=(this._series.priceToCoordinate(this.IC.bt)??0)*s,l=this.WP.calculateLevels(this.OP.point1Time,this.OP.point1Price,this.IC.gt,this.IC.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.LP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.OP.levelColors?.[e.toString()]||this.OP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.OP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.OP.showLabels){const s=`${n.label??n.Jl} ${this.WP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.OP.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.OP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.UC(t,n,e,i),t.globalAlpha=.6,this.UC(t,r,h,i),t.globalAlpha=1}UC(t,i,s,n){const e=this.OP.lineColor,r=this.SC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.SC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}$P(){this.ep=t=>{this.HP(t)},this._chart.subscribeCrosshairMove(this.ep)}NP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}HP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.SC||!this.CC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.BP?(this.OP.point1Time=i,this.OP.point1Price=s):"point2"===this.BP&&(this.OP.point2Time=i,this.OP.point2Price=s),this.zP(),this.pM())}startDrag(t){this.CC=!0,this.BP=t}stopDrag(){this.CC=!1,this.BP=null}updateDrag(t,i){this.CC&&this.BP&&("point1"===this.BP?(this.OP.point1Time=t,this.OP.point1Price=i):(this.OP.point2Time=t,this.OP.point2Price=i),this.zP(),this.pM())}hitTestEndpoint(t,i){if(!this.RC||!this.OP.point1Time||!this.OP.point2Time)return null;const s=Gn(this._chart,this._series,this.OP.point1Time)??0,n=this._series.priceToCoordinate(this.OP.point1Price)??0,e=Gn(this._chart,this._series,this.OP.point2Time)??0,r=this._series.priceToCoordinate(this.OP.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.OP={...this.OP,...t},void 0!==t.levels&&t.levels.length>0?this.WP.updateRatios(t.levels.map(vl)):void 0!==t.useExtended&&(t.useExtended?this.WP.useExtendedRatios():this.WP.useStandardRatios()),super.applyOptions(t),this.zP(),this.pM()}options(){return{...this.OP,levels:this.WP.getRatioValues()}}setColor(t){this.OP.lineColor=t,this.pM()}color(){return this.OP.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}isSelected(){return this.SC}EC(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.RC||!this.OP.point1Time||!this.OP.point2Time)return!1;const s=Gn(this._chart,this._series,this.OP.point1Time)??0,n=Gn(this._chart,this._series,this.OP.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.RC}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.EP&&(this.EP.m(),this.EP=null),this.NP(),this.OP.onRemove&&this.OP.onRemove()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.OP.onRemove&&this.OP.onRemove()}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.zP(),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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.OP={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.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new bl(this)}getPoint1(){return this.OP.point1}getPoint2(){return this.OP.point2}getPoint3(){return this.OP.point3}getLevels(){return this.OP.levels||[]}getOptions(){return this.OP}setPoint1(t){this.OP.point1=t,this.pM()}setPoint2(t){this.OP.point2=t,this.pM()}setPoint3(t){this.OP.point3=t,this.pM()}isComplete(){return!!(this.OP.point1&&this.OP.point2&&this.OP.point3)}setColor(t){this.OP.lineColor=t,this.pM()}color(){return this.OP.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.OP.point1,this.OP.point2,this.OP.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.UP();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.OP.point1,n=this.OP.point2,e=this.OP.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.CC=!0,this.PC=t}stopDrag(){this.CC=!1,this.PC=null}updateDrag(t,i){if(!this.CC||!this.PC)return;const s={time:t,price:i};switch(this.PC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.OP.onUpdate&&this.OP.onUpdate()}UP(){if(!this.isComplete())return[];const t=this.OP.point1,i=this.OP.point2,s=this.OP.point3,n=i.price-t.price;return(this.OP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.UP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.OP.point1,e=this.OP.point2,r=this.OP.point3,h=this.SC||this.xC&&!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.OP.lineColor||"#787B86",t.lineWidth=(this.OP.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.OP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.OP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.OP.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.OP.point1),Th(this.OP.point2),Th(this.OP.point3)],style:{lineColor:this.OP.lineColor,lineWidth:this.OP.lineWidth,showLabels:this.OP.showLabels,extendLines:this.OP.extendLines},extra:{levels:(this.OP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}remove(){this.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.qP=!1,this.ZS=null,this.ep=null,this.IC=null,this.jP={levels:Cl,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.Hy(),this.jP.interactive&&!this.jP.point1Time&&this.LC()}LC(){this.qP=!0,this.ZS=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.point1Time?(this.jP.point2Time=i,this.jP.point2Price=s,this.qP=!1,this.IC=null,this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.jP.onUpdate&&this.jP.onUpdate()):(this.jP.point1Time=i,this.jP.point1Price=s,this.pM()))},this.ep=t=>{if(this.qP&&this.jP.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.IC={gt:i,bt:s},this.pM())}else this.IC=null,this.pM()},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new xl(this)}drawToCanvas(t,i,s){const n=this.jP.point1Time,e=this.jP.point1Price,r=this.qP&&this.IC?this.IC.gt:this.jP.point2Time,h=this.qP&&this.IC?this.IC.bt:this.jP.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.SC?this.jP.lineWidth+1:this.jP.lineWidth;if(this.YP(t,l,o,a,_,"#2962FF",u*i),this.jP.levels)for(const n of this.jP.levels)this.XP(t,l,o,a,_,n,i,s,undefined,u);!this.SC&&!this.xC||this.qP||this.isLocked()||(this.UC(t,l,o,i,"#2962ff"),this.UC(t,a,_,i,"#2962ff"))}XP(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.jP.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.YP(t,i,s,c,d,p,a*h),this.jP.showLabels&&!this.qP&&this.GC(t,_,u,r.label,h,p)}YP(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()}UC(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()}GC(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.jP.levels??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.jP.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.point1Time||!this.jP.point2Time)return!1;const s=Gn(this._chart,this._series,this.jP.point1Time)??0,n=this._series.priceToCoordinate(this.jP.point1Price)??0,e=Gn(this._chart,this._series,this.jP.point2Time)??0,r=this._series.priceToCoordinate(this.jP.point2Price)??0;if(this.qC(t,i,s,n,e,r)<=8)return!0;if(this.jP.levels)for(const h of this.jP.levels){const l=n+(r-n)*h.level,o=e;if(this.qC(t,i,s,n,o,l)<=8)return!0}return!1}qC(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.point1Time||!this.jP.point2Time)return null;const s=Gn(this._chart,this._series,this.jP.point1Time)??0,n=this._series.priceToCoordinate(this.jP.point1Price)??0,e=Gn(this._chart,this._series,this.jP.point2Time)??0,r=this._series.priceToCoordinate(this.jP.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.CC=!0,this.PC=t}stopDrag(){this.CC=!1,this.PC=null}updateDrag(t,i){this.CC&&this.PC&&("point1"===this.PC?(this.jP.point1Time=t,this.jP.point1Price=i):"point2"===this.PC&&(this.jP.point2Time=t,this.jP.point2Price=i),this.pM(),this.jP.onUpdate&&this.jP.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Ph(this.jP.point1Price??0,Ch(this.jP.point1Time)),Ph(this.jP.point2Price??0,Ch(this.jP.point2Time))],style:{lineWidth:this.jP.lineWidth,showLabels:this.jP.showLabels,extendLines:this.jP.extendLines},extra:{levels:(this.jP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return!this.qP}remove(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=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.jP.onRemove&&this.jP.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.kC=null,this.DC=null,this.qP=!1,this.ZS=null,this.ep=null,this.IC=null,this.GP={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.GP),this.Hy(),!this.GP.interactive||this.GP.time1&&this.GP.time2||this.LC()}LC(){this.qP=!0,this.ZS=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.GP.time1?(this.GP.time2=i,this.GP.price2=s,this.qP=!1,this.IC=null,this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.GP.onUpdate&&this.GP.onUpdate()):(this.GP.time1=i,this.GP.price1=s,this.pM()))},this.ep=t=>{if(this.qP&&this.GP.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.IC={gt:i,bt:s},this.pM())}else this.IC=null,this.pM()},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new Dl(this)}drawToCanvas(t,i,s){const n=this.GP.time1,e=this.GP.price1,r=this.qP&&this.IC?this.IC.gt:this.GP.time2,h=this.qP&&this.IC?this.IC.bt:this.GP.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.GP.fillOpacity>0){const i=this.zy(this.GP.fillColor,this.qP?.1:this.GP.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.GP.borderColor,w=this.SC?this.GP.borderWidth+1:this.GP.borderWidth;t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.GP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.GP.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([]),!this.SC&&!this.xC||this.qP||this.isLocked()||this.KP(t,u,d,c,p,i,m),this.GP.showLabel&&this.GP.labelText&&!this.qP&&this.GC(t,u,d,c,p,i,s,m)}KP(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)}GC(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.GP.labelText).width,u=a;let c=i+o,d=s+o;switch(this.GP.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.GP.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.GP.borderColor=t,this.GP.fillColor=t,this.pM()}color(){return this.GP.borderColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.GP.time1||!this.GP.time2)return!1;const s=Gn(this._chart,this._series,this.GP.time1)??0,n=this._series.priceToCoordinate(this.GP.price1)??0,e=Gn(this._chart,this._series,this.GP.time2)??0,r=this._series.priceToCoordinate(this.GP.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.GP.time1||!this.GP.time2)return null;const s=Gn(this._chart,this._series,this.GP.time1)??0,n=this._series.priceToCoordinate(this.GP.price1)??0,e=Gn(this._chart,this._series,this.GP.time2)??0,r=this._series.priceToCoordinate(this.GP.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.CC=!0,this.PC=t,this.TC=i,"body"===t&&(this.kC={gt:this.GP.time1,bt:this.GP.price1},this.DC={gt:this.GP.time2,bt:this.GP.price2})}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.kC=null,this.DC=null}updateDrag(t,i){if(!this.CC||!this.PC)return;const s=Gn(this._chart,this._series,this.GP.time1)??0,n=this._series.priceToCoordinate(this.GP.price1)??0,e=s<(Gn(this._chart,this._series,this.GP.time2)??0),r=n<(this._series.priceToCoordinate(this.GP.price2)??0);if("body"===this.PC&&this.kC&&this.DC){const s=Sh(this.TC,t,i);this.GP.time1=this.kC.gt+s.gt,this.GP.price1=this.kC.bt+s.bt,this.GP.time2=this.DC.gt+s.gt,this.GP.price2=this.DC.bt+s.bt}else switch(this.PC){case"corner1":e&&r?(this.GP.time1=t,this.GP.price1=i):!e&&r?(this.GP.time2=t,this.GP.price1=i):e&&!r?(this.GP.time1=t,this.GP.price2=i):(this.GP.time2=t,this.GP.price2=i);break;case"corner2":e&&r?(this.GP.time2=t,this.GP.price1=i):!e&&r?(this.GP.time1=t,this.GP.price1=i):e&&!r?(this.GP.time2=t,this.GP.price2=i):(this.GP.time1=t,this.GP.price2=i);break;case"corner3":e&&r?(this.GP.time1=t,this.GP.price2=i):!e&&r?(this.GP.time2=t,this.GP.price2=i):e&&!r?(this.GP.time1=t,this.GP.price1=i):(this.GP.time2=t,this.GP.price1=i);break;case"corner4":e&&r?(this.GP.time2=t,this.GP.price2=i):!e&&r?(this.GP.time1=t,this.GP.price2=i):e&&!r?(this.GP.time2=t,this.GP.price1=i):(this.GP.time1=t,this.GP.price1=i)}this.pM(),this.GP.onUpdate&&this.GP.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Ph(this.GP.price1??0,Ch(this.GP.time1)),Ph(this.GP.price2??0,Ch(this.GP.time2))],style:{fillColor:this.GP.fillColor,fillOpacity:this.GP.fillOpacity,borderColor:this.GP.borderColor,borderWidth:this.GP.borderWidth,borderStyle:this.GP.borderStyle,showLabel:this.GP.showLabel,labelText:this.GP.labelText,labelPosition:this.GP.labelPosition}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return!this.qP}remove(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=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.GP.onRemove&&this.GP.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.cP=null,this.qP=!1,this.ZS=null,this.ep=null,this.IC=null,this.ZP={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.ZP),this.Hy(),this.ZP.interactive&&!this.ZP.centerTime&&this.LC()}LC(){this.qP=!0,this.ZS=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.ZP.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.ZP.centerTime)??0,n=this._series.priceToCoordinate(this.ZP.centerPrice)??0,e=Gn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.ZP.radiusTime=Math.abs(e-t),this.ZP.radiusPrice=Math.abs(r-n),this.qP=!1,this.IC=null,this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.ZP.onUpdate&&this.ZP.onUpdate()}else this.ZP.centerTime=i,this.ZP.centerPrice=s,this.pM()},this.ep=t=>{if(this.qP&&this.ZP.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.IC={gt:i,bt:s},this.pM())}else this.IC=null,this.pM()},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.ep)}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new Vl(this)}drawToCanvas(t,i,s){if(!this.ZP.centerTime||void 0===this.ZP.centerPrice)return;const n=(Gn(this._chart,this._series,this.ZP.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.ZP.centerPrice)??0)*s;let r,h;if(this.qP&&this.IC){const t=(Gn(this._chart,this._series,this.IC.gt)??0)*i,l=(this._series.priceToCoordinate(this.IC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.ZP.radiusTime||void 0===this.ZP.radiusPrice)return;r=this.ZP.radiusTime*i,h=this.ZP.radiusPrice*s}if(this.ZP.fillOpacity>0){const i=this.zy(this.ZP.fillColor,this.qP?.05:this.ZP.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.ZP.borderColor,o=this.SC?this.ZP.borderWidth+1:this.ZP.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.ZP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.ZP.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.SC&&!this.xC||this.qP||this.isLocked()||this.JP(t,n,e,i,l),!this.SC&&!this.xC||this.qP||this.isLocked()||this.QP(t,n,e,r,h,i,l),this.ZP.showLabel&&this.ZP.labelText&&!this.qP&&this.GC(t,n,e,i,l)}JP(t,i,s,n,e){const r=8*n;t.fillStyle=e,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(i,s,r/2,0,2*Math.PI),t.fill(),t.stroke()}QP(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)}GC(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.ZP.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.ZP.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.ZP.borderColor=t,this.ZP.fillColor=t,this.pM()}color(){return this.ZP.borderColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.ZP.centerTime||void 0===this.ZP.radiusTime)return!1;const s=Gn(this._chart,this._series,this.ZP.centerTime)??0,n=this._series.priceToCoordinate(this.ZP.centerPrice)??0,e=(t-s)/this.ZP.radiusTime,r=(i-n)/this.ZP.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.ZP.centerTime||void 0===this.ZP.radiusTime)return null;const s=Gn(this._chart,this._series,this.ZP.centerTime)??0,n=this._series.priceToCoordinate(this.ZP.centerPrice)??0,e=this.ZP.radiusTime,r=this.ZP.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.CC=!0,this.PC=t,this.TC=i,this.cP="center"===t?{gt:this.ZP.centerTime,bt:this.ZP.centerPrice}:null}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.cP=null}updateDrag(t,i){if(this.CC&&this.PC){if("center"===this.PC&&this.cP){const s=Sh(this.TC,t,i);this.ZP.centerTime=this.cP.gt+s.gt,this.ZP.centerPrice=this.cP.bt+s.bt}else if("edge"===this.PC){const s=Gn(this._chart,this._series,this.ZP.centerTime)??0,n=this._series.priceToCoordinate(this.ZP.centerPrice)??0,e=Gn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.ZP.radiusTime=Math.abs(e-s),this.ZP.radiusPrice=Math.abs(r-n)}this.pM(),this.ZP.onUpdate&&this.ZP.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Ph(this.ZP.centerPrice??0,Ch(this.ZP.centerTime))],style:{fillColor:this.ZP.fillColor,fillOpacity:this.ZP.fillOpacity,borderColor:this.ZP.borderColor,borderWidth:this.ZP.borderWidth,borderStyle:this.ZP.borderStyle,showLabel:this.ZP.showLabel,labelText:this.ZP.labelText},extra:{radiusTime:this.ZP.radiusTime,radiusPrice:this.ZP.radiusPrice}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return!this.qP}remove(){this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=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.ZP.onRemove&&this.ZP.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.tT=-1,this.qP=!1,this.ZS=null,this.iT=null,this.ep=null,this.IC=null,this.sT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.sT),this.Hy(),!this.sT.interactive||this.sT.points&&0!==this.sT.points.length||this.LC()}LC(){this.qP=!0,this.ZS=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.sT.points||(this.sT.points=[]),this.sT.points.push({time:i,price:s}),this.pM(),this.sT.onUpdate&&this.sT.onUpdate())},this.ep=t=>{if(this.qP)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.IC={gt:i,bt:s},this.pM())}else this.IC=null,this.pM()},this.iT=t=>{this.qP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.ZS),this._chart.subscribeCrosshairMove(this.ep);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.iT)}finishDrawing(){if(this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.iT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.iT),this.iT=null}this.qP=!1,this.IC=null,this.pM(),this.sT.onComplete&&this.sT.onComplete()}isDrawing(){return this.qP}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new Bl(this)}drawToCanvas(t,i,s){if(!this.sT.points||0===this.sT.points.length)return;const n=this.sT.lineColor,e=this.SC||this.xC&&!this.isLocked()?this.sT.lineWidth+1:this.sT.lineWidth,r=[];for(const t of this.sT.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.qP)return;let h=null;if(this.qP&&this.IC&&this.sT.points.length>0){h={ut:(Gn(this._chart,this._series,this.IC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.IC.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.sT.showArrowHead&&r.length>1&&this.nT(t,r[r.length-2],r[r.length-1],i,n),this.sT.showCircles)for(let s=0;s<r.length;s++)this.eT(t,r[s].ut,r[s].ct,i,n,0===s)}nT(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()}eT(t,i,s,n,e,r){const h=this.sT.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.sT.lineColor=t,this.pM()}color(){return this.sT.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.sT.points||0===this.sT.points.length)return!1;for(let s=0;s<this.sT.points.length-1;s++)try{const n=this.sT.points[s],e=this.sT.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.qC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this.sT.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}qC(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.sT.points||0===this.sT.points.length)return null;for(let s=0;s<this.sT.points.length;s++)try{const n=this.sT.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.CC=!0,this.tT=t}stopDrag(){this.CC=!1,this.tT=-1}updateDrag(t,i){this.CC&&-1!==this.tT&&this.sT.points&&this.tT>=0&&this.tT<this.sT.points.length&&(this.sT.points[this.tT]={time:t,price:i},this.pM(),this.sT.onUpdate&&this.sT.onUpdate())}getPoints(){return this.sT.points||[]}addPoint(t){this.sT.points||(this.sT.points=[]),this.sT.points.push(t),this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.sT.points||[]).map(t=>Th(t)),style:{lineColor:this.sT.lineColor,lineWidth:this.sT.lineWidth,showArrowHead:this.sT.showArrowHead,showCircles:this.sT.showCircles,circleRadius:this.sT.circleRadius}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return!this.qP}remove(){if(this.ZS&&(this._chart.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.iT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.iT),this.iT=null}this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.sT.onRemove&&this.sT.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.rT=!1,this.qP=!1,this.hT=[],this.lT=!1,this.Rf=null,this.cS=null,this.bS=null,this.yS=null,this.xS=null,this.oT=void 0,this.wS=null,this.CC=!1,this.TC=null,this.QC=null,this.aT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.aT),this.Hy(),0===(this.aT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.rT)return;const t=this._chart.chartElement();t&&(this.Rf=t,this.rT=!0,this.bS=t=>this.MS(t),this.yS=t=>this.SS(t),this.xS=()=>this.CS(),this.wS=t=>{this.oT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.wS),t.addEventListener("pointerdown",this.bS,!0),t.addEventListener("pointermove",this.yS,!0),t.addEventListener("pointerup",this.xS,!0),t.addEventListener("pointercancel",this.xS,!0))}stopDrawingMode(){if(!this.rT)return;this._T(),this.rT=!1;const t=this.Rf;t&&(this.bS&&t.removeEventListener("pointerdown",this.bS,!0),this.yS&&t.removeEventListener("pointermove",this.yS,!0),this.xS&&(t.removeEventListener("pointerup",this.xS,!0),t.removeEventListener("pointercancel",this.xS,!0))),this.wS&&(this._chart.unsubscribeCrosshairMove(this.wS),this.wS=null),this.bS=null,this.yS=null,this.xS=null,this.Rf=null}isDrawingModeActive(){return this.rT}MS(t){if(this.uT())return;const i=this.cT(t,!1);null!==i&&(this.qP=!0,this.hT=[i],this.cS=t.pointerId,Ih(this._chart,!0),this.Rf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.dT())}SS(t){if(!this.qP)return;const i=this.cT(t,!0);if(null===i)return;const s=this.hT[this.hT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.aT.sampleDistance??4)||(this.hT.push(i),t.preventDefault(),t.stopPropagation(),this.dT())}CS(){this.qP&&this._T()}_T(){if(!this.qP)return;this.qP=!1,this.$S();const t=[];for(const i of this.hT){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.hT=[],t.length<2?this.pM():(this.aT.points=t,this.stopDrawingMode(),this.pM(),this.aT.onUpdate&&this.aT.onUpdate(),this.aT.onComplete&&this.aT.onComplete())}uT(){const t=this.oT;return"string"==typeof t&&t.split("#")[0]!==this.id}$S(){null!==this.cS&&(this.Rf&&this.Rf.hasPointerCapture(this.cS)&&this.Rf.releasePointerCapture(this.cS),this.cS=null)}cT(t,i){const s=this.pT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Ix;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}}pT(){const t=this.fT();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,Ix:i.top,ts:n,qt:i.height}}fT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}dT(){this.lT||(this.lT=!0,requestAnimationFrame(()=>{this.lT=!1,this.pM()}))}drawToCanvas(t,i,s){const n=this.qP?this.hT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.vT(i,s);if(0===n.length)return;const e=this.SC;if(t.strokeStyle=this.aT.color,t.lineWidth=(this.aT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.aT.smoothing&&n.length>2){for(let i=1;i<n.length-1;i++){const s=(n[i].ut+n[i+1].ut)/2,e=(n[i].ct+n[i+1].ct)/2;t.quadraticCurveTo(n[i].ut,n[i].ct,s,e)}t.lineTo(n[n.length-1].ut,n[n.length-1].ct)}else for(let i=1;i<n.length;i++)t.lineTo(n[i].ut,n[i].ct);t.stroke(),!e&&!this.xC||this.isLocked()||(this.UC(t,n[0],i),this.UC(t,n[n.length-1],i))}UC(t,i,s){t.fillStyle=this.aT.color,t.strokeStyle="#ffffff",t.lineWidth=2*s,t.beginPath(),t.arc(i.ut,i.ct,5*s,0,2*Math.PI),t.fill(),t.stroke()}vT(t,i){const s=this.aT.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.vT(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.CC=!0,this.TC=i,this.QC=(this.aT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.QC;if(!this.CC||null===s||!this.aT.points)return;const n=Sh(this.TC,t,i);this.aT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.pM(),this.aT.onUpdate&&this.aT.onUpdate()}stopDrag(){this.CC=!1,this.TC=null,this.QC=null}setColor(t){this.aT.color=t,this.pM()}color(){return this.aT.color??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}Hy(){this.eh=new $l(this);const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}EC(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.yC?.()}_update(){this.pM()}remove(){this.stopDrawingMode(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null),this.eh=null,this.aT.onRemove&&this.aT.onRemove()}_serializeShape(){return{type:"brush",points:(this.aT.points??[]).map(Th),style:{color:this.aT.color,lineWidth:this.aT.lineWidth,smoothing:this.aT.smoothing}}}getPoints(){return this.aT.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.cP=null,this.mT=!1,this.wT=null,this.gT={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.gT),this.Hy(),this.bT()}bT(){const t=t=>{if(!this.mT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.gT.text&&""!==this.gT.text.trim()&&"Type here..."!==this.gT.text||this.remove())};this.wT=t,this._chart.subscribeClick(t)}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new jl(this)}getTime(){return this.gT.time}getPrice(){return this.gT.price}getText(){return this.gT.text||""}getOptions(){return this.gT}setPosition(t,i){this.gT.time=t,this.gT.price=i,this._update()}setText(t){this.gT.text=t,this._update(),this.gT.onTextChange&&this.gT.onTextChange(t)}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}isComplete(){return!(!this.gT.time||void 0===this.gT.price)}setColor(t){this.gT.textColor=t,this.gT.borderColor=t,this.pM()}color(){return this.gT.textColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this._update())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this._update())}isHovered(){return this.xC}setEditing(t){this.mT!==t&&(this.mT=t,this._update())}isEditing(){return this.mT}EC(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.gT.time,n=this.gT.price,e=Gn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.gT.fontSize||14,l=this.gT.padding||8,o=this.gT.text||"",a=.6*h,_=Math.min(o.length*a,this.gT.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.gT.time,n=this.gT.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.CC=!0,this.PC=t,this.TC=i,this.cP={gt:this.gT.time,bt:this.gT.price}}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.cP=null}updateDrag(t,i){if(this.CC){if("body"===this.PC&&this.cP){const s=Sh(this.TC,t,i);this.setPosition(this.cP.gt+s.gt,this.cP.bt+s.bt)}else this.setPosition(t,i);this.gT.onUpdate&&this.gT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.gT.time,e=this.gT.price,r=this.gT.text||"",h=(Gn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.gT.fontSize||14)*i,a=(this.gT.padding||8)*i,_=(this.gT.maxWidth||200)*i;t.font=`${o}px ${this.gT.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.gT.backgroundOpacity||.8,g=this.gT.backgroundColor||"#2962FF";t.fillStyle=this.zy(g,w),t.fillRect(h,l,f,m),(this.SC||this.xC)&&(t.strokeStyle=this.gT.borderColor??"#FFFFFF",t.lineWidth=(this.gT.borderWidth||1)*i*(this.SC?2:1),t.strokeRect(h,l,f,m)),t.fillStyle=this.gT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=h+a;if("center"===this.gT.textAlign){n=h+(f-t.measureText(s).width)/2}else if("right"===this.gT.textAlign){n=h+f-t.measureText(s).width-a}const e=l+a+i*v;t.fillText(s,n,e)}if((this.SC||this.xC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.gT.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.gT.price??0,Ch(this.gT.time))],style:{fontSize:this.gT.fontSize,fontFamily:this.gT.fontFamily,textColor:this.gT.textColor,backgroundColor:this.gT.backgroundColor,backgroundOpacity:this.gT.backgroundOpacity,padding:this.gT.padding,borderColor:this.gT.borderColor,borderWidth:this.gT.borderWidth,textAlign:this.gT.textAlign,maxWidth:this.gT.maxWidth},extra:{text:this.gT.text}}}remove(){this.wT&&(this._chart.unsubscribeClick(this.wT),this.wT=null),this.jb&&this._series&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.gT.onRemove&&this.gT.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.yT(t,s),barCount:e}}yT(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.yC=null,this.Gb=null,this.eh=null,this.EP=null,this.RC=!1,this.SC=!1,this.xC=!1,this.IC=null,this.CC=!1,this.BP=null,this.ep=null,this.ST={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.ST);const s=this.ST.pipConfig||Zl(this.ST.symbol||"DEFAULT");this.WP=new Jl(s),this.Hy(),this.ST.interactive?this.LC():this.ST.point1Time&&this.ST.point2Time&&(this.RC=!0,this.zP())}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new to(this)}LC(){this.EP=new Eh(this._chart,this._series,{mC:t=>{this.ST.point1Time=t.gt,this.ST.point1Price=t.bt,this.pM()},wC:t=>{this.ST.point2Time=t.gt,this.ST.point2Price=t.bt},gC:(t,i)=>{this.ST.point1Time=t.gt,this.ST.point1Price=t.bt,this.ST.point2Time=i.gt,this.ST.point2Price=i.bt,this.RC=!0,this.IC=null,this.zP(),this.$P(),this.pM()},bC:t=>{this.IC=t,this.pM()}}),this.EP.hC()}drawToCanvas(t,i,s){if(!this.RC&&this.ST.point1Time&&this.IC)return void this.NC(t,i,s);if(!this.RC||!this.ST.point1Time||!this.ST.point2Time)return;const n=(Gn(this._chart,this._series,this.ST.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ST.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.ST.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.ST.point2Price)??0)*s;(this.SC||this.xC&&!this.isLocked())&&(t.strokeStyle=this.ST.selectionColor,t.lineWidth=this.ST.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.ST.lineColor,t.lineWidth=this.ST.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.xT(t,n,e,r,h,i),this.UC(t,n,e,i),this.UC(t,r,h,i),this.ST.showLabel&&this.Gb&&this.GC(t,n,e,r,h,i,s)}xT(t,i,s,n,e,r){const h=this.ST.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.ST.lineColor,t.lineWidth=this.ST.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()}UC(t,i,s,n){const e=this.SC?this.ST.selectionColor:this.ST.lineColor,r=this.SC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.SC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}NC(t,i,s){if(!this.ST.point1Time||!this.IC)return;const n=(Gn(this._chart,this._series,this.ST.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.ST.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.IC.gt)??0)*i,h=(this._series.priceToCoordinate(this.IC.bt)??0)*s;t.strokeStyle=this.ST.lineColor,t.lineWidth=this.ST.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.UC(t,n,e,i),t.globalAlpha=.5,this.UC(t,r,h,i),t.globalAlpha=1}GC(t,i,s,n,e,r,h){if(!this.Gb)return;const l=(i+n)/2,o=(s+e)/2,a=this.ST.measure??"both",_=[];"time"!==a&&(_.push(this.WP.formatPips(this.Gb.pips)),_.push(this.WP.formatPercent(this.Gb.pricePercent))),"price"!==a&&_.push(this.WP.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.ST.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.ST.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}zP(){if(!this.ST.point1Time||!this.ST.point2Time||void 0===this.ST.point1Price||void 0===this.ST.point2Price)return;const t=this.CT();this.Gb=this.WP.calculateMetrics(this.ST.point1Time,this.ST.point1Price,this.ST.point2Time,this.ST.point2Price,t),this.ST.onUpdate&&this.Gb&&this.ST.onUpdate(this.Gb)}CT(){if(!this.ST.point1Time||!this.ST.point2Time)return 0;const t=Gn(this._chart,this._series,this.ST.point1Time),i=Gn(this._chart,this._series,this.ST.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.ST.point1Time=t,this.ST.point1Price=i,this.ST.point2Time=s,this.ST.point2Price=n,this.zP(),this.pM()}getMetrics(){return this.Gb}remove(){this.destroy()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.EP&&(this.EP.m(),this.EP=null),this.NP(),this.ST.onRemove&&this.ST.onRemove()}$P(){this.ep=t=>{this.HP(t)},this._chart.subscribeCrosshairMove(this.ep)}NP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}HP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.SC||!this.CC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.BP?(this.ST.point1Time=i,this.ST.point1Price=s):"point2"===this.BP&&(this.ST.point2Time=i,this.ST.point2Price=s),this.zP(),this.pM())}startDrag(t){this.CC=!0,this.BP=t}stopDrag(){this.CC=!1,this.BP=null}updateDrag(t,i){this.CC&&this.BP&&("point1"===this.BP?(this.ST.point1Time=t,this.ST.point1Price=i):(this.ST.point2Time=t,this.ST.point2Price=i),this.zP(),this.pM())}hitTestEndpoint(t,i){if(!this.RC||!this.ST.point1Time||!this.ST.point2Time)return null;const s=Gn(this._chart,this._series,this.ST.point1Time)??0,n=this._series.priceToCoordinate(this.ST.point1Price)??0,e=Gn(this._chart,this._series,this.ST.point2Time)??0,r=this._series.priceToCoordinate(this.ST.point2Price)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"point1";return Math.sqrt(Math.pow(t-e,2)+Math.pow(i-r,2))<=10?"point2":null}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.zP(),this.pM()}_serializeShape(){return{type:"ruler",points:[Ph(this.ST.point1Price??0,Ch(this.ST.point1Time)),Ph(this.ST.point2Price??0,Ch(this.ST.point2Time))],style:{lineColor:this.ST.lineColor,lineWidth:this.ST.lineWidth,showLabel:this.ST.showLabel,labelBackgroundColor:this.ST.labelBackgroundColor,labelTextColor:this.ST.labelTextColor,selectionColor:this.ST.selectionColor,selectionLineWidth:this.ST.selectionLineWidth},extra:{symbol:this.ST.symbol,pipConfig:this.ST.pipConfig,measure:this.ST.measure}}}setColor(t){this.ST.lineColor=t,this.pM()}color(){return this.ST.lineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}isSelected(){return this.SC}isComplete(){return this.RC}EC(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.RC||!this.ST.point1Time||!this.ST.point2Time)return!1;const s=Gn(this._chart,this._series,this.ST.point1Time)??0,n=this._series.priceToCoordinate(this.ST.point1Price)??0,e=Gn(this._chart,this._series,this.ST.point2Time)??0,r=this._series.priceToCoordinate(this.ST.point2Price)??0;return this.PT(t,i,s,n,e,r)<=(this.SC?12:8)}PT(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.yC=null,this.Gb=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.PC=null,this.TC=null,this.cP=null,this.TT=null,this.kT=null,this.DT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.DT);const s=this.DT.pipConfig||Zl(this.DT.entryPrice);this.WP=new Gl(s),this.Hy(),this.zP()}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new eo(this)}drawToCanvas(t,i,s){if(this.TT&&this.DT.takeProfit){const n=this._chart.timeScale();this.RT(t,this.TT,i,s,n),(this.xC||this.SC)&&this.GC(t,this.TT,"profit",i,s,n)}if(this.kT&&this.DT.stopLoss){const n=this._chart.timeScale();if(this.RT(t,this.kT,i,s,n),this.xC||this.SC){const n=this._chart.timeScale();this.GC(t,this.kT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.FT(t,i,s,n),this.DT.takeProfit){const n=this._chart.timeScale();this.UC(t,this.DT.takeProfit,this.DT.profitColor,i,s,n)}if(this.DT.stopLoss){const n=this._chart.timeScale();this.UC(t,this.DT.stopLoss,this.DT.lossColor,i,s,n)}}RT(t,i,s,n,e){const r=(Gn(this._chart,this._series,this.DT.entryTime)??0)*s;let h;if(this.DT.endTime)h=(Gn(this._chart,this._series,this.DT.endTime)??0)*s;else{h=this._chart.chartElement().clientWidth*s}const l=(this._series.priceToCoordinate(i.IT)??0)*n,o=(this._series.priceToCoordinate(i.VT)??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()}FT(t,i,s,n){const e=(Gn(this._chart,this._series,this.DT.entryTime)??0)*i,r=(this._series.priceToCoordinate(this.DT.entryPrice)??0)*s;let h;if(this.DT.endTime)h=(Gn(this._chart,this._series,this.DT.endTime)??0)*i;else{h=this._chart.chartElement().clientWidth*i}const l=this.DT.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.DT.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.SC&&!this.xC||this.isLocked())t.fillStyle=this.DT.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)}}zP(){this.DT.stopLoss&&this.DT.takeProfit&&(this.Gb=this.WP.calculateMetrics(this.DT.entryPrice,this.DT.stopLoss,this.DT.takeProfit,this.DT.quantity),this.LT(),this.DT.onUpdate&&this.Gb&&this.DT.onUpdate(this.Gb))}LT(){const t=this.AT();this.DT.takeProfit&&(this.TT={ET:this.DT.entryTime,BT:t,IT:this.DT.entryPrice,VT:this.DT.takeProfit,R:this.DT.profitColor,Ry:this.DT.opacity}),this.DT.stopLoss&&(this.kT={ET:this.DT.entryTime,BT:t,IT:this.DT.entryPrice,VT:this.DT.stopLoss,R:this.DT.lossColor,Ry:this.DT.opacity})}AT(){this._chart.timeScale().getVisibleLogicalRange();return this.DT.entryTime}GC(t,i,s,n,e,r){if(!this.Gb)return;const h=(Gn(this._chart,this._series,this.DT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.VT)??0)*e,o="profit"===s,a=o?this.Gb.takeProfitPips:this.Gb.stopLossPips,_=o?this.DT.takeProfit:this.DT.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)}UC(t,i,s,n,e,r){const h=(Gn(this._chart,this._series,this.DT.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.DT.endTime)a=(Gn(this._chart,this._series,this.DT.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.DT={...this.DT,...t},this.zP(),this._update()}getMetrics(){return this.Gb}setStopLoss(t){this.DT.stopLoss=t,this.zP(),this._update()}setTakeProfit(t){this.DT.takeProfit=t,this.zP(),this._update()}setEntryPrice(t){this.DT.entryPrice=t,this.zP(),this._update()}_serializeShape(){return{type:"position",points:[Ph(this.DT.entryPrice,Ch(this.DT.entryTime))],style:{profitColor:this.DT.profitColor,lossColor:this.DT.lossColor,entryLineColor:this.DT.entryLineColor,opacity:this.DT.opacity,showTooltips:this.DT.showTooltips},extra:{endTime:Ch(this.DT.endTime),stopLoss:this.DT.stopLoss,takeProfit:this.DT.takeProfit,quantity:this.DT.quantity,pipConfig:this.DT.pipConfig}}}setColor(t){this.DT.entryLineColor=t,this.pM()}color(){return this.DT.entryLineColor??""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.DT.stopLoss&&!this.DT.takeProfit)return!1;const s=Gn(this._chart,this._series,this.DT.entryTime)??0;let n;if(this.DT.endTime)n=Gn(this._chart,this._series,this.DT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.DT.takeProfit&&this.DT.stopLoss){const e=this._series.priceToCoordinate(this.DT.takeProfit)??0,r=this._series.priceToCoordinate(this.DT.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.DT.entryTime)??0;let n;if(this.DT.endTime)n=Gn(this._chart,this._series,this.DT.endTime)??0;else{n=this._chart.chartElement().clientWidth}if(this.DT.takeProfit){const n=this._series.priceToCoordinate(this.DT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.DT.stopLoss){const n=this._series.priceToCoordinate(this.DT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.DT.takeProfit){const s=this._series.priceToCoordinate(this.DT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.DT.stopLoss){const s=this._series.priceToCoordinate(this.DT.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.DT.entryPrice)??0;if(t>=s&&t<=n&&Math.abs(i-e)<=8)return"entry";if(this.DT.takeProfit&&this.DT.stopLoss){const e=this._series.priceToCoordinate(this.DT.takeProfit)??0,r=this._series.priceToCoordinate(this.DT.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.CC=!0,this.PC=t,this.TC=i,"move"===t&&(this.cP={OT:this.DT.entryPrice,WT:this.DT.entryTime??null,Wy:this.DT.endTime??null,zT:this.DT.takeProfit??null,$T:this.DT.stopLoss??null})}stopDrag(){this.CC=!1,this.PC=null,this.TC=null,this.cP=null}updateDrag(t,i){if(this.CC&&this.PC){if("entry"===this.PC)this.DT.entryPrice=i;else if("move"===this.PC){if(this.cP){const s=Sh(this.TC,t,i),n=this.cP;this.DT.entryPrice=n.OT+s.bt,null!==n.zT&&(this.DT.takeProfit=n.zT+s.bt),null!==n.$T&&(this.DT.stopLoss=n.$T+s.bt),null!==n.WT&&(this.DT.entryTime=this.HT(n.WT,s.gt)),null!==n.Wy&&(this.DT.endTime=this.HT(n.Wy,s.gt))}}else"tp"===this.PC||"tp-right"===this.PC?(this.DT.takeProfit=i,"tp-right"===this.PC?this.DT.endTime=t:this.DT.entryTime=t):"sl"!==this.PC&&"sl-right"!==this.PC||(this.DT.stopLoss=i,"sl-right"===this.PC?this.DT.endTime=t:this.DT.entryTime=t);this.zP(),this.pM()}}HT(t,i){return t+i}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.DT.onRemove&&this.DT.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.yC=null,this.eh=null,this.SC=!1,this.xC=!1,this.CC=!1,this.NT=-1,this.TC=null,this.cP=null,this.UT=-1,this.qT={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.qT),this.Hy()}Hy(){this.eh=this.AC();const t={attached:t=>{this.yC=t.requestUpdate},detached:()=>{this.yC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.EC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}AC(){return new oo(this)}drawToCanvas(t,i,s){if(!this.qT.segments||0===this.qT.segments.length)return;const n=50*s,e=this.qT.rowHeight*s,r=this.qT.rowSpacing*s;this.qT.showGrid&&this.rm(t,n,e,r,i,s),this.qT.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.UT||this.xC&&!this.isLocked();this.jT(t,l,o,a,e,s,_,i)})}rm(t,i,s,n,e,r){if(!this.qT.segments)return;const h=Math.max(...this.qT.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()}}jT(t,i,s,n,e,r,h,l){const o=s-i,a=this.zy(r.color,h?this.qT.fillOpacity+.2:this.qT.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.qT.borderWidth+(this.SC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.qT.showLabels&&r.label&&this.GC(t,i,n,o,e,r.label,l)}GC(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.qT.segments||(this.qT.segments=[]),this.qT.segments.push(t),this.pM(),this.qT.onUpdate&&this.qT.onUpdate()}removeSegment(t){this.qT.segments&&t>=0&&t<this.qT.segments.length&&(this.qT.segments.splice(t,1),this.pM(),this.qT.onUpdate&&this.qT.onUpdate())}getSegments(){return this.qT.segments||[]}setColor(t){const i=this.qT.segments??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.qT.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.SC!==t&&(this.SC=t,this.pM())}isSelected(){return this.SC}setHovered(t){this.xC!==t&&(this.xC=t,this.pM())}isHovered(){return this.xC}EC(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.qT.segments?.[this.UT];s&&(this.CC=!0,this.NT=this.UT,this.TC=i,this.cP={Oy:s.startTime,Wy:s.endTime})}updateDrag(t,i){const s=this.qT.segments?.[this.NT];if(!this.CC||!this.cP||!s)return;const n=Sh(this.TC,t,i);s.startTime=this.cP.Oy+n.gt,s.endTime=this.cP.Wy+n.gt,this.pM(),this.qT.onUpdate&&this.qT.onUpdate()}stopDrag(){this.CC=!1,this.NT=-1,this.TC=null,this.cP=null}hitTest(t,i){if(!this.qT.segments||0===this.qT.segments.length)return!1;const s=this.qT.rowHeight,n=this.qT.rowSpacing;for(let e=0;e<this.qT.segments.length;e++){const r=this.qT.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.UT=e,!0}return this.UT=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.qT.rowHeight,rowSpacing:this.qT.rowSpacing,fillOpacity:this.qT.fillOpacity,borderWidth:this.qT.borderWidth,showLabels:this.qT.showLabels,showGrid:this.qT.showGrid},extra:{segments:(this.qT.segments||[]).map(t=>({Oy:Ch(t.startTime),Wy:Ch(t.endTime),sn:t.level,Jl:t.label,R:t.color,YT:t.category}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.yC?.()}_update(){this.pM()}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.qT.onRemove&&this.qT.onRemove()}}function _o(t,i){return new ao(t,i)}class uo{constructor(t,i,s={}){this.XT=[],this.GT=[],this.KT=[],this.ZT=!1,this.JT=new Map,this.QT=null,this.tk=null,this.ik=null,this.ZS=null,this.sk=null,this.ep=null,this.nk=null,this.ek=null,this.rk=null,this.hk=null,this.lk=null,this.ak=null,this.cS=null,this._k=!1,this.uk=null,this.ck=null,this.dk=new a,this.CC=!1,this.pk=null,this.fk=new Set,this.vk=null,this.mk=new a,this.Lf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.wk()}startDrawing(t){this.ik=t,this.gk()}activeDrawingType(){return this.ik}stopDrawing(){this.ik=null}addTool(t,i){const s=i??t.id;return this.JT.set(s,t),t.isComplete()||this.fk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.fk.size>0}cancelPendingDrawings(){if(0===this.fk.size)return 0;let t=0;for(const i of Array.from(this.fk)){const s=this.JT.get(i);s&&(this.QT===i&&this.bk(null),s.remove(),this.JT.delete(i),t++)}return this.fk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.mk.i(t)}unsubscribeDrawingCompleted(t){this.mk._(t)}Mk(){0!==this.fk.size&&null===this.vk&&(this.vk=setTimeout(()=>{this.vk=null;for(const t of Array.from(this.fk)){const i=this.JT.get(t);i?i.isComplete()&&(this.fk.delete(t),this.mk.p(t)):this.fk.delete(t)}},0))}removeTool(t){const i=this.JT.get(t);return!!i&&(this.QT===t&&this.bk(null),i.remove(),this.JT.delete(t),this.fk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.JT.has(t)&&(this.bk(t),!0)}bk(t){if(this.QT===t)return;const i=null===this.QT?void 0:this.JT.get(this.QT);i&&i.setSelected(!1),this.QT=t;const s=null===t?void 0:this.JT.get(t);s&&s.setSelected(!0),this.yk()}recordChange(){this.ZT||(this.XT.push(this.KT),this.XT.length>100&&this.XT.shift(),this.GT=[],this.KT=this.serializeAll())}canUndo(){return this.XT.length>0}canRedo(){return this.GT.length>0}undo(){const t=this.XT.pop();return void 0!==t&&(this.GT.push(this.KT),this.Sk(t),!0)}redo(){const t=this.GT.pop();return void 0!==t&&(this.XT.push(this.KT),this.Sk(t),!0)}Sk(t){this.ZT=!0;try{this.restoreAll({chart:this.Lf,series:this.be},t,!0),this.KT=t}finally{this.ZT=!1}}subscribeSelectionChanged(t){this.dk.i(t)}unsubscribeSelectionChanged(t){this.dk._(t)}selectionBounds(){if(null===this.QT)return null;const t=this.JT.get(this.QT);return t?this.xk(t):null}xk(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.Ck(t);return{left:n+o.ut,right:r+o.ut,top:e+o.ct,bottom:h+o.ct}}Ck(t){const i=this.Lf.chartElement(),s=this.NS(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}}yk(){this.dk.p({id:this.QT,bounds:this.selectionBounds()})}deselectAll(){this.gk()}deleteSelected(){if(this.QT){const t=this.JT.get(this.QT);return(!t||!t.isLocked())&&this.removeTool(this.QT)}return!1}getSelectedToolId(){return this.QT}getAllTools(){return new Map(this.JT)}getTool(t){return this.JT.get(t)}clearAll(){this.bk(null),this.JT.forEach(t=>t.remove()),this.JT.clear(),this.fk.clear(),this.recordChange()}getToolCount(){return this.JT.size}isToolSelected(t){return this.QT===t}serializeAll(){const t=[];for(const i of this.JT.values())t.push(i.serialize());return t}restoreTool(t,i){const s=uo.Pk(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 Pk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({Tk:kh(n[t]),kk:Dh(n[t],"price")??0});switch(s){case"trendLine":return zh(t,{point1Time:h(0).Tk,point1Price:h(0).kk,point2Time:h(1).Tk,point2Price:h(1).kk,...e});case"horizontalLine":return Uh(t,{price:h(0).kk,startTime:h(0).Tk??void 0,...e});case"parallelChannel":return sl(t,{point1Time:h(0).Tk,point1Price:h(0).kk,point2Time:h(1).Tk,point2Price:h(1).kk,channelWidth:r?.channelWidth,...e});case"pitchfork":return hl(t,{pivotTime:h(0).Tk,pivotPrice:h(0).kk,upperTime:h(1).Tk,upperPrice:h(1).kk,lowerTime:h(2).Tk,lowerPrice:h(2).kk,...e});case"polygon":return Jh(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).Tk,s.price=h(i).kk,s}),...e});case"crossLine":return Xh(t,{time:h(0).Tk,price:h(0).kk,...e});case"verticalLine":return _l(t,{time:h(0).Tk,...e});case"fibRetracement":return wl(t,{point1Time:h(0).Tk,point1Price:h(0).kk,point2Time:h(1).Tk,point2Price:h(1).kk,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.Tk?{time:i.Tk,price:i.kk}:void 0,point2:s.Tk?{time:s.Tk,price:s.kk}:void 0,point3:n.Tk?{time:n.Tk,price:n.kk}:void 0,levels:r?.levels,...e})}case"fibFan":return Tl(t,{point1Time:h(0).Tk,point1Price:h(0).kk,point2Time:h(1).Tk,point2Price:h(1).kk,levels:r?.levels,...e});case"rectangle":return Fl(t,{time1:h(0).Tk,price1:h(0).kk,time2:h(1).Tk,price2:h(1).kk,...e});case"circle":return Al(t,{centerTime:h(0).Tk,centerPrice:h(0).kk,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).Tk,price:h(0).kk,text:r?.text,...e});case"ruler":return so(t,{point1Time:h(0).Tk,point1Price:h(0).kk,point2Time:h(1).Tk,point2Price:h(1).kk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return ho(t,{entryPrice:h(0).kk,entryTime:h(0).Tk,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.vk&&(clearTimeout(this.vk),this.vk=null),this.mk.m(),this.dk.m(),this.clearAll(),this.Dk(),this.XT=[],this.GT=[],this.KT=[]}wk(){this.ZS=t=>{this.fC(t)},this.Lf.subscribeClick(this.ZS),this.ep=t=>{this.vC(t)},this.Lf.subscribeCrosshairMove(this.ep);const t=this.Lf.chartElement();t&&(this.nk=t=>this.Rk(t),this.ek=t=>this.Fk(t),this.rk=t=>this.Ik(t),this.hk=t=>this.Fk(t),this.lk=t=>this.Vk(t),t.addEventListener("pointerdown",this.nk),t.addEventListener("pointerup",this.ek),t.addEventListener("pointermove",this.rk),t.addEventListener("pointercancel",this.hk),t.addEventListener("lostpointercapture",this.lk)),us&&(this.ak=t=>this.Fk(t),window.addEventListener("pointerup",this.ak)),this.Ps.enableKeyboardShortcuts&&(this.sk=t=>{this.Lk(t)},document.addEventListener("keydown",this.sk))}Dk(){this.ZS&&(this.Lf.unsubscribeClick(this.ZS),this.ZS=null),this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null);const t=this.Lf.chartElement();t&&(this.nk&&(t.removeEventListener("pointerdown",this.nk),this.nk=null),this.ek&&(t.removeEventListener("pointerup",this.ek),this.ek=null),this.rk&&(t.removeEventListener("pointermove",this.rk),this.rk=null),this.hk&&(t.removeEventListener("pointercancel",this.hk),this.hk=null),this.lk&&(t.removeEventListener("lostpointercapture",this.lk),this.lk=null)),this.ak&&(window.removeEventListener("pointerup",this.ak),this.ak=null),this.sk&&(document.removeEventListener("keydown",this.sk),this.sk=null)}fC(t){if(this.Mk(),!t.point)return;if(this._k)return void(this._k=!1);if(this.CC)return;const i=this.Ak(t.hoveredObjectId);i?this.selectTool(i):this.gk()}vC(t){if(this.uk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.CC&&this.pk){const i=this.JT.get(this.pk);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.Ak(t.hoveredObjectId);if(this.tk&&this.tk!==i){const t=this.JT.get(this.tk);t&&t.setHovered(!1)}if(i){const t=this.JT.get(i);t&&t.setHovered(!0)}this.tk=i}Ak(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.JT)if(s.id===i)return t;return null}Rk(t){if(this.CC)return;Ih(this.Lf,!1);const i=this.Lf.chartElement();if(!i)return;const s=null!==this.tk&&null!==this.uk?{Ek:this.tk,Rw:this.uk}:this.Bk(t);if(null===s)return;const{Ek:n,Rw:e}=s,r=this.JT.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Ok(r,e.ut,e.ct);if(null!==h&&null!==l){Ih(this.Lf,!0),this.selectTool(n),this.CC=!0,this._k=!0,this.pk=n,this.cS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.cS=null}r.startDrag(h,l),this.Wk()}}Ik(t){if(!this.CC||null===this.pk||"mouse"===t.pointerType)return;if(null!==this.cS&&t.pointerId!==this.cS)return;const i=this.JT.get(this.pk);if(!i)return;const s=this.NS(i);if(null===s)return;const n=s.getBoundingClientRect(),e=i.series(),r=e.coordinateToPrice(t.clientY-n.top),h=Xn(this.Lf,e,t.clientX-n.left);null!==r&&null!==h&&(i.updateDrag(h,r),t.preventDefault())}Fk(t){if(!this.CC||null===this.pk)return;if(t&&null!==this.cS&&t.pointerId!==this.cS)return;const i=this.pk;this.CC=!1,this.pk=null;try{const t=this.JT.get(i);t&&t.stopDrag()}finally{this.$S(),this.zk()}this.recordChange()}Vk(t){null!==this.cS&&t.pointerId!==this.cS||(this.cS=null,this.Fk())}NS(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Bk(t){for(const[i,s]of this.JT){if(!s.isVisible()||s.isLocked())continue;const n=this.NS(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{Ek:i,Rw:r}}return null}$S(){if(null===this.cS)return;const t=this.Lf.chartElement();t&&t.hasPointerCapture(this.cS)&&t.releasePointerCapture(this.cS),this.cS=null}Wk(){if(null!==this.ck)return;const t=this.Lf.options();this.ck={$k:f(t.handleScroll),Hk:f(t.handleScale)},this.Lf.applyOptions({handleScroll:!1,handleScale:!1})}zk(){const t=this.ck;this.ck=null,null!==t&&this.Lf.applyOptions({handleScroll:t.$k,handleScale:t.Hk})}Lk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Mk(),"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.Fk(),this.gk(),this.stopDrawing(),t.preventDefault())}Ok(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Xn(this.Lf,t.series(),i)}}gk(){this.bk(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{Nk:[],Uk:[],qk:[]};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{Nk:o,Uk:a,qk:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.Nk],[o,n?s.Uk:[]],[a,n?s.qk:[]]]},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{TP:[],jk:[],kP:[]};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{TP:e,jk:r,kP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.TP],[h,s.jk],[l,s.kP]]},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{TP:[],jk:[],kP:[]};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{TP:s,jk:n,kP:e}})(t,i.period??20);return[[r,s.TP],[h,s.jk],[l,s.kP]]},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{Yk:h,rh:l,Fy:o,Iy:a,Xk:_,Gk: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{Yk:h,rh:l,Fy:o,Iy:a,Xk:_,Gk: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.Gk,[[h,s.Yk],[l,s.rh],[o,s.Fy],[a,s.Iy],[_,i.showLagging??1?s.Xk:[]]]},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{TP:[],jk:[],kP:[]};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{TP:c,jk:d,kP:p}})(t,i);return[[r,s.TP],[h,s.jk],[l,s.kP]]},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{Kk:[],Zk:[],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=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{Kk:c,Zk:d,Jk:p}})(t,i);return[[r,s.Kk],[l,s.Zk],[o,s.Jk]]},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{CP:s,Qk:n,tD: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={iD:i,sD:[2*i-l,i+s,h+2*(i-l)],nD:[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.iD});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.sD[t]}),e[t].push({time:_.time,value:a.nD[t]})}}return{CP:s,Qk:n,tD:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.CP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.Qk[t]:[]]),e.push([o[t],t<n?s.tD[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{eD:[],rD:[]};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{eD:e,rD:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.eD],[o,s.rD]]},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{hD:e,TP:r,kP: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{hD:e,TP:r,kP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.hD],[h,n.TP],[l,n.kP]]},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.12"}});window.PipsendCharts=po,window.LightweightCharts=po}();
|