@pipsend/charts 2.3.18 → 2.3.20
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 +185 -116
- package/dist/pipsend-charts.production.mjs +2 -2
- package/dist/pipsend-charts.standalone.development.js +185 -115
- package/dist/pipsend-charts.standalone.development.mjs +185 -116
- package/dist/pipsend-charts.standalone.production.js +2 -2
- package/dist/pipsend-charts.standalone.production.mjs +2 -2
- package/dist/typings.d.ts +34 -6
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @license
|
|
3
|
-
* Pipsend Charts v2.3.
|
|
3
|
+
* Pipsend Charts v2.3.20-dev+202610211649
|
|
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.Bt(s),l=i.Ot();!t&&null!==h&&i.It()&&null!==l?(r.wt=h.Et,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 B(t,i,s,n,e,r,h){t.save(),t.globalCompositeOperation="copy";const l=t.createLinearGradient(0,0,0,e);l.addColorStop(0,r),l.addColorStop(1,h),t.fillStyle=l,t.fillRect(i,s,n,e),t.restore()}class O{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 E{constructor(t){this.Ai={Li:0,Z:"#000",Ri:0,Di:0},this.Bi={hi:"",It:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Oi={hi:"",It:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Ei=new(t||O)(this.Bi,this.Ai),this.Wi=new(t||O)(this.Oi,this.Ai)}hi(){return this.zi(),this.Bi.hi}Li(){return this.zi(),this.Ai.Li}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Ei.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.Bi.It||this.Oi.It}Ui(){return this.zi(),this.Bi.It}Dt(t){return this.zi(),this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Oi.mi=this.Oi.mi&&t.W().ticksVisible,this.Ei.lt(this.Bi,this.Ai),this.Wi.lt(this.Oi,this.Ai),this.Ei}qi(){return this.zi(),this.Ei.lt(this.Bi,this.Ai),this.Wi.lt(this.Oi,this.Ai),this.Wi}zi(){this.xt&&(this.Bi.mi=!0,this.Oi.mi=!1,this.ji(this.Bi,this.Oi,this.Ai))}}class W extends E{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.Ot();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.Ot());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}Bs(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Os(t,i,s)}Lt(){return this.fs}ni(){return this.ys}ei(){return this.Ss}It(){return this.vs}Es(){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}Os(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.Ot():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,Bn:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.On=null,this.M=null,this.En="right",this.Wn=t}zn(t,i,s){this.On=t,this.M=i,this.En=s}et(t){null!==this.M&&null!==this.On&&this.On.et(t,this.M,this.Wn,this.En)}}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.Ot();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.Ot();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 E{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.Be(o,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Oe(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}Oe(t,i,s,n){let e="";const r=this.Qt.Ae();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Ee()?t.We:t.ze),e.trim()}Be(t,i,s){return i?s?this.Qt.$t().Ee()?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 E{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.Ot();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.Ot();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.Br=[]}Or(){return this.Er()>0?this.Vr[this.Vr.length-1]:null}Wr(){return this.Er()>0?this.zr(0):null}Gs(){return this.Er()>0?this.zr(this.Vr.length-1):null}Er(){return this.Vr.length}Gi(){return 0===this.Er()}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.Br=t.map(t=>t.Re)}Yr(){return this.Br}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 Bt{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 Ot extends E{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 Et 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 Bt(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 Ot(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.Ot();if(null===n||null===e)return i;let r,h;if(t){const t=this.Yt.Or();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().Bh(this),this.ti().Oh(),this.eh.Tt("options")}lt(t,i){this.Yt.lt(t),this.eh.Tt("data"),null!==this.Ch&&(i&&i.Eh?this.Ch.ye():0===t.length&&this.Ch.Me());const s=this.ti().Nn(this);this.ti().Wh(s),this.ti().Bh(this),this.ti().Oh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Bh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Bh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Ot(){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())}Bt(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(),Et:this.ul(t)}}Ae(){return this.Ps.title}It(){return this.Ps.visible}cl(t){this.kh.push(new Et(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.Ot();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.Ot()),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.Bl=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.Ol=[2,2.5,2];else{this.Ol=[];for(let t=this.Al;1!==t;){if(t%2==0)this.Ol.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Ol.push(2,2.5),t/=5}if(this.Ol.length>100)throw new Error("something wrong with base")}}}El(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.Bl[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.Bl[++r%this.Bl.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.Ol.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.Ol[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.Ol[++r%this.Ol.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}El(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.El(t,i,n),r.El(t,i,n),h.El(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.Ot();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.El(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.El(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.El(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}Ee(){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.Bo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Bo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Ee())&&this.bl(),n&&(3===i.se||this.Lo())&&this.bl(),void 0!==t.Ao&&i.Ao!==t.Ao&&(this.Ps.invertScale=t.Ao,this.Oo()),this.po.p(i,this.se())}Eo(){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}Bo(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.Bo(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.Ee()?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.Ee()?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.Bo(null)),this.bl(),this.sa()}Ot(){let t=null;for(const i of this.fo){const s=i.Ot();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.Ot();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.Ee()||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.Ee()||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.Bo(s)}oa(){this.Ee()||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.Bo(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.Ee()?(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.Ee()||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}Oo(){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.Ot();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){const t=this.io(),s=t?oi(i,this.yo):i,n=this.Ee()||this.Lo()?0:10*this.ma();if(s.qe()===s.je()||s.Ye()<n){const e=Math.max(5*this.ma(),n/2),r=(s.qe()+s.je())/2,h=new dt(r-e,r+e);i=t?li(h,this.yo):h}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.Bo(i)}else null===this.Je&&(this.Bo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Ee()?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.Eo().i(this.Ra.bind(this,this.Ta),this),this.Da.Eo().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.Eo().u(this),this.Da.Eo().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}Ba(t){this.ya=t,this.Oa()}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.Oa()}Ea(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.Oa()}Ya(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Oa()}Ka(t){t.ua()}Oa(){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.Oa()}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.Oa(),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,Bn: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.B_=ki.F_(),this.O_=!0,this.E_=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.B_.D_()}ru(){return this.eu(),this.B_.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}Ba(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.ru(),s=this.ya;if(this.ya=t,this.O_=!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.O_=!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.O_=!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.O_=!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.O_=!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.O_=!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.O_=!0,this.V_=t,this.L_.M_(t,i),this.cu()}Lu(){return this.E_}Au(){return this.W_}Bu(){return this.z_}du(){return this.I_||0}Ou(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.O_=!0,this.ss.gu(),this.ss.ar()}Eu(){const t=this.ou(),i=this.au();null!==t&&null!==i&&this.Ou(new Ci(t,i),!0)}Wu(t){const i=new Ci(t.from,t.to);this.Ou(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.O_=!0,this.$u())}eu(){if(!this.O_)return;if(this.O_=!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.O_=!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.O_=!0);const i=this.ju();this.Y_>i&&(this.Y_=i,this.O_=!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.B_;this.B_=t,Pi(i.D_(),this.B_.D_())||this.E_.p(),Pi(i.R_(),this.B_.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 Bi{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))}Bh(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.Bh(i.r_),null!==t&&t.r_!==i?.r_&&this.Bh(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()}Ba(t){this.ya=t,this.ph.Ba(this.ya),this.Xu.forEach(i=>i.Ba(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.Oh(),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.Oh(),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.Ot();if(null!==a&&(r=o.Ds(i,a)),r=this.nc.Ml(r,h,n),this.Ct.Bs(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.Ot(),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().Es(),this.Jh(),t||this.Ju.p(null,null,null)}Oh(){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.Oh()}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}Bc(t,i){const s=this.ec(i);this.Oc(t,s),this.Gu.push(t),1===this.Gu.length?this.Ah():this.ar()}Ec(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)}Eu(){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.Oc(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())}Oc(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 Oi(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 Ei(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)),!Ei(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:Ei(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):Ei(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.Bd=!1,this.Od=0,this.Ed=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.Bd||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.Ed));if(null===i)return;if(this.Od=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.Ed));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Ed=null,this.Od=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.Bd=!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.Ed)return;const i=t.changedTouches[0];this.Ed=i.identifier,this.Od=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.Bd=!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.Ed));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.Od+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,Bp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Op:t.type,Ep: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()}Bf(){this.Rf&&this.Vf.removeChild(this.Rf),this.Ff&&this.Vf.removeChild(this.Ff),this.Rf=void 0,this.Ff=void 0}Of(){return this.vs!==this.Ef()||this.If!==this.Wf()}Wf(){return this.Lf.ti().Ki().tt(this.Lf.W().layout.textColor)>160?"dark":"light"}Ef(){return this.Lf.W().layout.attributionLogo}zf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Af(){this.Of()&&(this.Bf(),this.vs=this.Ef(),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.Ot();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.Ee()||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):B(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 Bs(t,i){return t.$s?.(i)??[]}function Os(t,i){return t.cs?.(i)??[]}function Es(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.Bv=document.createElement("td"),this.Bv.style.padding="0",this.Bv.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.Ov=document.createElement("td"),this.Ov.style.padding="0",this.Ev=document.createElement("td"),this.Ev.style.padding="0",this.Bv.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.Ov),this.Xp.appendChild(this.Bv),this.Xp.appendChild(this.Ev),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.Bv,this.Lf),this.Sv.Tt()):(this.Sv?.Bf(),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.Bv.style.width=t.width+"px",this.Bv.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,Bs),this.nm(t,Os)))}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,Es),this.nm(s,Os))}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):B(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,Bs,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.Ov.removeChild(this.Mv.Jp()),this.Mv.m(),this.Mv=null),s||null===this.yv||(this.Ev.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.Ov.appendChild(this.Mv.Jp())),s&&null===this.yv&&(this.yv=new Ls(this,t.W(),n,"right"),this.Ev.appendChild(this.yv.Jp()))}_m(t){return t.Bp&&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.Bp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.Bp))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.Bp&&r.touch||!t.Bp&&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.Bm();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.Bm(),t.fillStyle=this.Bm();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.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Lf.W().timeScale.allowBoldLabels&&(t.font=this.Em());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.Om(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}Om(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)}Bm(){return this.Lf.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}lv(){return g(this.$(),this.Ps.fontFamily)}Em(){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 Bi(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().Bu().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().Bu().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.Ba(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.Eu();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.Bw=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,Ow:new Map,Uh:t}}function an(t,i){if(void 0!==t&&0!==t.length)return{Ew: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.Ow.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.Ow.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.Ow)})}),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,Eh:n.Ww>=e.Ww&&n.Ew>=e.Ew}}(this.$w.get(t),e,this.u_))}Ec(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.Ow.set(t,u),s?this.Zw(t,u,h.Re):this.Jw(t,u);const c={Eh:en(u),Gw:s};if(!l)return this.Xw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:_n(h.Ow)},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.Ow.delete(t),0===s.Ow.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,Eh:!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.Ow.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.Ow.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().Er())return;const n=this.Qn.Ot();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.Ot();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.Bw&&(i.customValues=t.Bw),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.Bw&&(i.customValues=t.Bw),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 Bn(){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 On{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=Oi(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 En{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 On(this.Up,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Ea(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.Ot();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Ot();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.Bg.bind(this)),this.Qm.Dm().i(this.Og.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.Eu()}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())}Bg(){this.W_.v()&&this.W_.p(this.getVisibleLogicalRange())}Og(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.Eg=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(Bn()):_(f(Bn()),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.Eg.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.Eg.get(t)),s=this.Ng.Ec(i);this.Up.ti().Ec(i),this.Kg(s),this.Eg.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 On(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.Ea(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.Eg.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=Oi(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().Bc(l,n);const o=new $n(l,this,this,this,this.Ug,t=>this.Zg(t));return this.Eg.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 En(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.Ot();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.Bb){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))}Ob(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.Ob(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(),Bb: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.Eb&&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.Ob(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.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.Ot()).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 Be={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},Oe={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class Ee{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 Ee(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{...Oe,...t}}function Ne(t){return{...Be,...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":case"xcross":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){return Math.max(sr(t),10)}function er(t,i,s){return i?t:s?Math.ceil(t/2):0}function rr(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 hr(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 lr(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 or(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class ar{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&&ur(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}_r(e,t,i,s)}}}}function _r(t,i,s,n){void 0===t.bM?(i.fillStyle=t.R,void 0!==t.hi&&or(i,t.hi.MM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Er)return;switch(t.SM){case"arrowDown":return void rr(!1,i,s,t.Er);case"arrowUp":return void rr(!0,i,s,t.Er);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.Er);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.Er);case"xcross":return void function(t,i,s){const n=(tr("xcross",s)-1)/2*i.vM;t.save(),t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1,Math.round(1.5*i.vM)),t.lineCap="round",t.beginPath(),t.moveTo(i.ut-n,i.ct-n),t.lineTo(i.ut+n,i.ct+n),t.moveTo(i.ut+n,i.ct-n),t.lineTo(i.ut-n,i.ct+n),t.stroke(),t.restore()}(i,s,t.Er);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.Er)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&&lr(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&&lr(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",or(s,t.hi.MM,t.hi.ut,t.hi.ct,n,e))}(t,t.bM,i,s,n)}function ur(t,i,s){return void 0!==t.bM?0!==t.Er&&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.Er)return!1;switch(t.SM){case"arrowDown":return hr(!0,t.ut,t.ct,t.Er,i,s);case"arrowUp":return hr(!1,t.ut,t.ct,t.Er,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.Er,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.Er,i,s);case"xcross":return function(t,i,s,n,e){const r=2+tr("xcross",s)/2;return Math.abs(n-t)<=r&&Math.abs(e-i)<=r}(t.ut,t.ct,t.Er,i,s);case"tag":return!1}}(t,i,s)}function cr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function dr(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(cr(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=cr(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=cr(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.Er=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.Er=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 pr{constructor(t,i,s){this.IM=[],this.xt=!0,this.VM=!0,this.Jt=new ar,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)}BM(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,Er:0,SM:t.shape,R:t.color,Gn:t.id,OM:t.OM,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=nr(t.options().barSpacing),_={RM:a,FM:a};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&&(_.RM=a,_.FM=a,h=e.time);const u=this.Yt._t[n];u.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(u.hi={MM:e.text,ut:0,ct:0,ts:0,qt:0});const c=this.be.dataByIndex(e.time,0);null!==c&&dr(u,e,c,_,s.fontSize,o,this.be,this.Lf,r)}this.xt=!1}}function fr(t){return{...Je,...t}}class vr{constructor(t){this.eh=null,this.IM=[],this.EM=[],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=fr(t)}attached(t){this.qM(),this.Lf=t.chart,this.be=t.series,this.eh=new pr(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=fr({...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)+i+nr(t),n=this.GM();this.$M={above:er(s,n.aboveBar,n.inBar),below:er(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.EM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.EM=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,OM: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.EM),this.eh.BM(this.Ps),this.eh.Tt(t))}Fg(t){this.UM=!0,this.Qb()}}class mr 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 wr(t,i,s){const n=new mr(t,new vr(s??{}));return i&&n.setMarkers(i),n}class gr{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 br={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Mr{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 yr{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 Mr(this.Yt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Sr(t,i){return"Line"===i||"Area"===i}class xr{constructor(t){this.Lf=void 0,this.be=void 0,this.Jb=[],this.u_=null,this.py=new Map,this.vy=new gr(()=>this.Qb()),this.Ps={...br,...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 yr(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)&&Sr(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)&&Sr(0,s)){const i=this.py.get(n);i&&this.vy.ZM({time:t.time,value:t.value,sign:Cr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}my(){this.vy.sy()}}function Cr(t,i){return t===i?0:t-i>0?1:-1}class Pr 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()}}const Tr={position:"bottom",offset:4,fontSize:11,fontFamily:"",color:"#787B86"};class kr{constructor(t){this.Yt=t}draw(t){const{_t:i,mf:s,wy:n}=this.Yt;0!==i.length&&t.useMediaCoordinateSpace(({context:t,mediaSize:e})=>{const r="top"===s?n:e.height-n;t.save(),t.textAlign="center",t.textBaseline="top"===s?"top":"bottom";for(const s of i)s.ut<-100||s.ut>e.width+100||(t.font=s.T,t.fillStyle=s.R,t.fillText(s.hi,s.ut,r));t.restore()})}}class Dr{constructor(){this.Yt={_t:[],mf:"bottom",wy:0}}Tt(t){this.Yt=t}zOrder(){return"top"}renderer(){return new kr(this.Yt)}}class Rr{constructor(t){this.Lf=null,this.pM=null,this.j_=[],this.eh=new Dr,this.Ps={...Tr,...t}}attached(t){this.Lf=t.chart,this.pM=t.requestUpdate,this.pM()}detached(){this.Lf=null,this.pM=null}gy(t){this.j_=t.slice(),this.pM?.()}by(){return this.j_}lr(t){this.Ps={...this.Ps,...t},this.pM?.()}updateAllViews(){const t=this.Lf,i=this.Ps;if(null===t)return void this.eh.Tt({_t:[],mf:i.position,wy:i.offset});const s=t.timeScale(),n=i.fontFamily||t.options().layout.fontFamily,e=[];for(const t of this.j_){const r=s.timeToCoordinate(t.time);null!==r&&e.push({ut:r,hi:t.text,R:t.color??i.color,T:g(t.size??i.fontSize,n)})}this.eh.Tt({_t:e,mf:i.position,wy:i.offset})}paneViews(){return[this.eh]}}class Fr extends Ze{setLabels(t){this._h.gy(t)}labels(){return this._h.by()}}class Ir{constructor(t,i){this.My=null,this.yy=[],this.Ps={longColors:{entry:i?.longColors?.entry??"#26a69a",exit:i?.longColors?.exit??"#ef5350"},shortColors:{entry:i?.shortColors?.entry??"#ef5350",exit:i?.shortColors?.exit??"#26a69a"},defaultSize:i?.defaultSize??1,entryOffset:i?.entryOffset??0,exitOffset:i?.exitOffset??0},this.My=wr(t)}addPosition(t){this.yy.push(t),this.Sy()}addPositions(t){this.yy.push(...t),this.Sy()}setPositions(t){this.yy=[...t],this.Sy()}closePosition(t,i,s){const n=this.yy.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.Sy())}removePosition(t){this.yy=this.yy.filter(i=>i.id!==t),this.Sy()}clearPositions(){this.yy=[],this.Sy()}getPositions(){return this.yy}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.Sy()}xy(){const t=[];for(const i of this.yy){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}Sy(){if(this.My){const t=this.xy();this.My.setMarkers(t)}}detach(){this.My&&(this.My.detach(),this.My=null),this.yy=[]}}const Vr=new WeakMap;function Lr(t){return"string"==typeof t?t:String(t)}function Ar(t,i){return Vr.get(t)?.get(Lr(i))}function Br(t){const i=Vr.get(t);return void 0!==i&&i.size>0}const Or="rgba(0, 0, 0, 0)";function Er(t){switch(t.seriesType()){case"Candlestick":return Wr(t,{upColor:Or,downColor:Or,borderVisible:!1,wickVisible:!1});case"Bar":return Wr(t,{upColor:Or,downColor:Or});case"Line":return Wr(t,{color:Or,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Wr(t,{lineColor:Or,topColor:Or,bottomColor:Or,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Wr(t,{topLineColor:Or,topFillColor1:Or,topFillColor2:Or,bottomLineColor:Or,bottomFillColor1:Or,bottomFillColor2:Or,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Wr(t,{color:Or});default:return Wr(t,{visible:!1})}}function Wr(t,i){const s={...i,lastValueVisible:!1,priceLineVisible:!1},n=t.options(),e={};for(const t of Object.keys(s))e[t]=n[t];return t.applyOptions(s),()=>{t.applyOptions(e)}}function zr(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function $r(t,i,s){const n=t.panes();for(const t of n)if(-1!==t.getSeries().indexOf(i))return t.paneIndex();return Math.min(s,Math.max(n.length-1,0))}function Hr(t,i="close"){const s=[];for(const n of t)if(null!=n)if("close"in n)switch(i){case"open":s.push(n.open);break;case"high":s.push(n.high);break;case"low":s.push(n.low);break;case"hl2":s.push((n.high+n.low)/2);break;case"hlc3":s.push((n.high+n.low+n.close)/3);break;case"ohlc4":s.push((n.open+n.high+n.low+n.close)/4);break;default:s.push(n.close)}else s.push("value"in n?n.value:0);else s.push(0);return s}function Nr(t,i){let s=[];return n=>{for(const i of s)try{t.removePriceLine(i)}catch(t){}s=n.filter(t=>null!=t).map(s=>{const n={price:s,color:i,lineWidth:1,lineStyle:2,axisLabelVisible:!1,title:""};return t.createPriceLine(n)})}}function Ur(t){return null==t?void 0:t.time}function qr(t){const{r_:i,Xf:s,Cy:n,Py:e,Ty:r,Jl:h}=t,l=t.ky??[];let o=t.W,a=[],_=new Map,u=!1;const c=(t,i)=>{if(0===i.length)return;const s=_.get(t),n=i[i.length-1];if(void 0!==s&&s.length>0){const e=i.length===s.length+1,r=i.length===s.length,h=Ur(s[s.length-1])===Ur(n);if(e||r&&h)return t.update(n),void _.set(t,i)}t.setData(i),_.set(t,i)},d=t=>{if(!u)try{if("full"===t||0===a.length)a=i.data();else{const t=function(t){return t.dataByIndex(Number.MAX_SAFE_INTEGER,-1)}(i);if(null===t)return;a.length>0&&Ur(a[a.length-1])===Ur(t)?a[a.length-1]=t:a.push(t)}if(0===a.length)return;const s=e(a,o);for(const[t,i]of s)c(t,i);s.every(([,t])=>0===t.length)&&a.length}catch(t){console.error(`Error calculating ${h}:`,t)}},p=t=>d(t);i.subscribeDataChanged(p),void 0!==r&&r(o),d("full");const f={applyOptions:t=>{if(u||null==t)return;const i=o;o={...o,...t},void 0!==r&&r(o),l.some(t=>i[t]!==o[t])&&(_=new Map,d("full"))},options:()=>({...o}),remove:()=>{if(!u){u=!0,i.unsubscribeDataChanged(p);for(const t of n)try{s.removeSeries(t)}catch(t){}_=new Map,a=[]}},recalculate:()=>d("full")};return f}function jr(t,i){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.Dy,i.Ry-1,i.Fy))}}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 Yr{constructor(t,i,s,n){this.Lf=t,this.be=i,this.V_=s,this.Iy=n}draw(t){const i=this.Iy();if(!i.It||i.Vy<=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.Ly),u=this.be.priceToCoordinate(h.Ay),c=this.be.priceToCoordinate(l.Ly),d=this.be.priceToCoordinate(l.Ay);if(null===_||null===u||null===c||null===d)continue;const p=h.Ly>=h.Ay;n.fillStyle=this.By(p?i.Oy:i.Ey,i.Vy),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()}})}By(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Xr{constructor(t,i,s,n){this.Jt=new Yr(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function Gr(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 Kr(t){return null!=t&&"number"==typeof t.close}function Zr(t){const i=[];let s=null,n=null;for(const e of t){if(!Kr(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.Wy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Wy.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.zy(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}zy(t,i,s,n){const e=i.$y||i.startTime,r=i.Hy||i.endTime,h=i.R||i.color,l=i.Vy||i.opacity;if(!i||!e||!r)return;const o=this.Wy.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.Ny(h,l),t.fillRect(u,d,c-u,p-d)}Ny(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Qr{constructor(t){this.Jt=new Jr(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const th=[{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 ih{constructor(t,i,s={}){this.Uy=[],this.jb=null,this.eh=null,this.Lf=t,this.be=i,this.Ps={sessions:s.sessions||th,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.qy(),this.Ps.enabled&&this.jy()}qy(){this.eh=new Qr(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}jy(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Yy()}),this.Yy()}Yy(){this.Xy();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.Gy(s),this.pM()}Gy(t){if(0!==t.length){for(const i of this.Ps.sessions)this.Ky(i,t);this.Ps.showOverlaps&&this.Zy(t)}}Ky(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Jy(i);this.Qy(r,t.startHour,t.endHour)?(s||(s=i),n.push(e)):s&&n.length>0&&(this.tS(s,n[n.length-1].time,t),s=null,n=[])}s&&n.length>0&&this.tS(s,n[n.length-1].time,t)}Zy(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.iS(e,r);h&&this.sS(h,t)}}iS(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}sS(t,i){let s=null,n=[];for(const e of i){const i=e.time,r=this.Jy(i);r>=t.ae&&r<t._e?(s||(s=i),n.push(e)):s&&n.length>0&&(this.nS(s,n[n.length-1].time),s=null,n=[])}s&&n.length>0&&this.nS(s,n[n.length-1].time)}tS(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",$y:t,Hy:i,R:s.color,Vy:s.opacity,eS:s.name};this.Uy.push(n)}nS(t,i){const s={an:"overlap",$y:t,Hy:i,R:this.Ps.overlapColor,Vy:this.Ps.overlapOpacity,eS:"Overlap"};this.Uy.push(s)}Qy(t,i,s){return i<s?t>=i&&t<s:t>=i||t<s}Jy(t){if("number"==typeof t){return new Date(1e3*t).getUTCHours()}if("string"==typeof t){return new Date(t).getUTCHours()}return 0}Xy(){this.Uy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Yy():this.Xy(),this.pM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Yy(),this.pM()}disable(){this.Ps.enabled=!1,this.Xy(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.Xy(),this.pM()}getSessionBoxes(){return this.Uy}getChart(){return this.Lf}getSeries(){return this.be}pM(){this.jb&&this.jb.updateAllViews?.(),this.Lf.timeScale().applyOptions({})}}class sh{constructor(t){this.Wy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Wy.getProfileData();if(!s||0===s.bins.length)return;const n=this.Wy.options(),e=this.Wy.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.rS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this.hS(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.lS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}rS(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.Ny(M,y),t.fillRect(f,v,m,w)}hS(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([])}lS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Ny(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.Ny(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([])}Ny(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class nh{constructor(t){this.Jt=new sh(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class eh{constructor(t,i,s={}){this.oS=null,this.aS=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.qy(),this.jy()}qy(){this.eh=new nh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.jb=t,this.be.attachPrimitive(t)}jy(){this.Lf.timeScale().subscribeVisibleLogicalRangeChange(()=>{this._S()}),this._S()}setVolumeData(t){this.aS=t,this._S()}addVolumeData(t,i){this.aS.set(t,i),this._S()}_S(){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.aS.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.oS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.pM()}getProfileData(){return this.oS}applyOptions(t){this.Ps={...this.Ps,...t},this._S(),this.pM()}remove(){this.jb&&this.be&&this.be.detachPrimitive(this.jb),this.oS=null,this.aS.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 rh{constructor(t,i){this.uS=new Map,this.cS=null,this.dS=null,this.pS=null,this.fS=null,this.vS=null,this.mS=null,this.wS=!1,this.gS=0,this.bS=null,this.yg=void 0,this.Lf=t,this.Rf=i,this.MS=t=>this.yS(t),this.SS=t=>this.xS(t),this.CS=t=>this.PS(t),this.TS=t=>this.kS(t),this.DS=()=>this.RS(),this.FS=t=>{"Escape"===t.key&&this.RS()},this.Lf.subscribeCrosshairMove(this.MS),this.Rf.addEventListener("pointerdown",this.SS),this.Rf.addEventListener("pointermove",this.CS),this.Rf.addEventListener("pointerup",this.TS),this.Rf.addEventListener("pointercancel",this.DS),document.addEventListener("keydown",this.FS)}IS(t){this.uS.set(t.id(),t)}VS(t){const i=t.id();this.cS===i&&this.LS(null),this.pS===t&&this.RS(),this.uS.delete(i)}Gi(){return 0===this.uS.size}m(){this.Lf.unsubscribeCrosshairMove(this.MS),this.Rf.removeEventListener("pointerdown",this.SS),this.Rf.removeEventListener("pointermove",this.CS),this.Rf.removeEventListener("pointerup",this.TS),this.Rf.removeEventListener("pointercancel",this.DS),document.removeEventListener("keydown",this.FS),this.uS.clear()}yS(t){if(this.bS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.yg=t.paneIndex,null!==this.pS)return;const i=this.AS(t.hoveredObjectId),s=null===i?null:this.uS.get(i.gl)??null;this.LS(s?s.id():null),this.BS(s,null===s?null:i?.OS??null),this.ES()}xS(t){this.wS="mouse"!==t.pointerType;let i=this.wS||null===this.cS?null:this.uS.get(this.cS)??null;null===i&&(i=this.WS(t)),i?(this.vS={ut:t.clientX,ct:t.clientY},this.mS=i,i.isDraggable()&&(this.pS=i,this.fS=t.pointerId,this.Rf.setPointerCapture(t.pointerId),i.beginDrag(),this.gS=this.zS(i,t),this.ES(),t.preventDefault(),t.stopPropagation())):this.$S()}PS(t){if(null===this.pS)return;if(!this.HS(t))return void this.RS();const i=this.NS(t);null!==i&&this.pS.dragTo(i),t.preventDefault(),t.stopPropagation()}kS(t){const i=this.pS,s=this.wS,n=this.mS,e=this.vS;this.US(),this.mS=null,this.vS=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.pS=null,this.gS=0,h?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),this.$S(s),void this.ES();null!==n&&!h&&n.isClickable()&&n.click(),this.$S(s)}$S(t=this.wS){if(!t||null===this.cS)return;const i=this.uS.get(this.cS)??null;this.LS(null),this.BS(i,null),this.ES()}RS(){if(null===this.pS)return;const t=this.pS;this.pS=null,this.gS=0,this.US(),t.cancelDrag(),this.ES()}HS(t){const i=this.Rf.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}US(){null!==this.fS&&(this.Rf.hasPointerCapture(this.fS)&&this.Rf.releasePointerCapture(this.fS),this.fS=null)}NS(t){const i=this.pS;if(null===i)return null;const s=this.qS(i,t);return null===s?null:i.priceAt(s-this.gS)}WS(t){for(const i of this.uS.values()){if(!i.hitTestAt)continue;const s=this.jS(i);if(null===s)continue;const n=s.getBoundingClientRect(),e="mouse"===t.pointerType?0:12,r=this.AS(i.hitTestAt(t.clientX-n.left,t.clientY-n.top,e));if(null!==r)return this.LS(i.id()),this.BS(i,r.OS),i}return null}jS(t){const i=this.Lf.panes()[t.paneIndex()];return i?i.getHTMLElement():null}qS(t,i){const s=this.jS(t);return s?i.clientY-s.getBoundingClientRect().top:null!==this.bS&&this.yg===t.paneIndex()?this.bS.ct:null}zS(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.qS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}AS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,OS:null}:{gl:t.slice(0,i),OS:t.slice(i+1)}}BS(t,i){this.dS!==i&&(this.dS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}LS(t){this.cS!==t&&(null!==this.cS&&this.uS.get(this.cS)?.setHovered(!1),this.cS=t,this.dS=null,null!==t&&this.uS.get(t)?.setHovered(!0))}ES(){if(null!==this.pS)return void this.Lf.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.cS?null:this.uS.get(this.cS);t?this.Lf.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Lf.chartElement().style.removeProperty("cursor")}}const hh=new WeakMap;function lh(t){const i=t.chartElement();if(!i)return null;let s=hh.get(t);return s||(s=new rh(t,i),hh.set(t,s)),s}function oh(t,i){const s=hh.get(t);s&&(s.VS(i),s.Gi()&&(s.m(),hh.delete(t)))}let ah=0;class _h{constructor(t,i,s){this.sr=null,this.YS=!1,this.XS="",this.GS=null,this.Lf=t,this.be=i,this.So="pipsend-trading-line-"+ah++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.KS(),(this.Ps.draggable||this.Ps.onClick)&&lh(this.Lf)?.IS(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.YS!==t&&this.sr&&(this.YS=t,this.sr.applyOptions({color:t?this.Ps.hoverColor:this.XS}))}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.GS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.ZS(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.GS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.GS;this.GS=null,null!==t&&t!==this.Ps.price&&(this.ZS(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.XS=t.color),!this.sr)return;const i={title:this.JS()};void 0!==t.price&&(i.price=t.price),void 0===t.color||this.YS||(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.ZS(t)}remove(){oh(this.Lf,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}JS(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}KS(){this.XS=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.JS()})}ZS(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.JS()})}}class uh{constructor(t,i){this.Vf=null,this.QS=null,this.tx=null,this.ix={},this.Lf=t,this.be=i,this.sx()}sx(){this.Vf=this.Lf.chartElement()}nx(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.QS=t,this.ix=i||{},new Promise(t=>{this.Vf.style.cursor="crosshair",this.tx=i=>{const s=this.nx(i),n=this.hx(s);this.disableClickToCreate(),t(n)},this.Vf.addEventListener("click",this.tx)})):Promise.resolve(null)}disableClickToCreate(){this.Vf&&this.tx&&(this.Vf.removeEventListener("click",this.tx),this.Vf.style.cursor="default"),this.QS=null,this.tx=null,this.ix={}}hx(t){if(!this.QS)return null;let i;switch(this.QS){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.ix};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.ix};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.ix};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.ix};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.ix};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.ix};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.ix};break;default:return null}return new _h(this.Lf,this.be,i)}getCreationMode(){return this.QS}isCreating(){return null!==this.QS}}class ch{constructor(){this.lx=[],this.ox=new Map,this._x=new Map,this.xt=!0}IS(t){this.ox.has(t)||(this.lx.push(t),this.ox.set(t,[]),this.xt=!0)}VS(t){const i=this.lx.indexOf(t);-1!==i&&this.lx.splice(i,1),this.ox.delete(t),this.xt=!0}Gi(){return 0===this.lx.length}ux(t,i){const s=this.ox.get(t);this.ox.set(t,i),void 0!==s&&function(t,i){if(t.length!==i.length)return!1;for(let s=0;s<t.length;s++)if(t[s].sn!==i[s].sn||t[s].ct!==i[s].ct||t[s].qt!==i[s].qt)return!1;return!0}(s,i)||(this.xt=!0)}vx(t,i){return this.xt&&this.mx(),this._x.get(dh(t,i))??0}mx(){const t=new Map,i=[];for(const s of this.lx)for(const n of this.ox.get(s)??[]){const e=ph(n.qt),r=n.qt;let h=n.ct;for(const t of i){if(t.ct>=h+e)break;Math.abs(h-t.ct)<e&&(h=t.ct+e)}let l=h-n.ct;l>r&&(l=0),fh(i,{ct:n.ct+l,qt:n.qt}),t.set(dh(s,n.sn),l)}this._x=t,this.xt=!1}}function dh(t,i){return`${t}:${i}`}function ph(t){return Math.max(9,Math.round(.4*t))}function fh(t,i){let s=0,n=t.length;for(;s<n;){const e=s+n>>1;t[e].ct<=i.ct?s=e+1:n=e}t.splice(s,0,i)}const vh=new WeakMap;const mh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},wh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},gh=["takeProfit","entry","stopLoss"];class bh{constructor(){this.Yt=null,this.wx=[],this.gx=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.wx)if(n.bx&&t>=n.Mx-s&&t<=n.yx+s&&Math.abs(i-n.Sx)<=n.qt/2+s)return{sn:n.sn,OS:"close"};for(const n of this.wx)if(t>=n.xx-s&&t<=n.Cx+s&&Math.abs(i-n.Sx)<=n.qt/2+s)return{sn:n.sn,OS:"body"};for(const t of this.wx)if(Math.abs(i-t.ct)<=8+s)return{sn:t.sn,OS:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.lw(t))}lw(t){const i=this.Yt;if(this.wx=[],null===i||0===i.Px.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.gx=Math.max(0,n.width-i.yu);const e=i.Tx?this.gx:n.width;for(const s of i.Px)this.wx.push(this.kx(t,i,s,e));i.Tx&&i.Px.length>1&&this.Dx(t,i),s.restore()}kx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Rx,o=0===s.Fx.length?0:Math.max(this.Wn.Ii(e,s.Fx)+2*i.yM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.yM,_=s.bx?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Ix,f=p-l/2;this.Vx(t,s,d,c,n),this.Lx(t,i,s,{qh:d,Ax:f,ts:u,qt:l});let v=d;return o>0&&(this.Bx(t,i,s,{qh:v,Ax:f,ts:o,qt:l}),v+=o,this.Ox(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.bx&&(this.Ox(e,s.R,v,f,l,r,h),this.Ex(t,i,s,{qh:v,Ax:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Sx:p,qt:l,xx:d,Cx:c,Mx:v,yx:v+_,bx:s.bx}}Vx(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.Ix?(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()}Lx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Wx===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),Mh(e,n,i.zx,r,h),e.fillStyle=this.Po.X(i.Z,i.$x),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}Bx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Hx){const t=i.Wt;e.save(),Mh(e,{qh:n.qh+t,Ax:n.Ax+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.zx-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Hx?i.Nx:s.R,e.fillText(s.Fx,n.qh+n.ts/2,n.Ax+n.qt/2),e.restore()}Ox(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()}Ex(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Wx===s.sn&&"close"===i.Ux){e.save();const t=i.Wt;Mh(e,{qh:n.qh,Ax:n.Ax+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.zx-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.Ax+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()}Dx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Px.find(t=>"entry"===t.sn)??i.Px[0],h=i.Px.map(t=>t.ct),l=Math.round(this.gx*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.Px)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.$x),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function Mh(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.Ax*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 yh{constructor(){this.Jt=new bh,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 Sh{constructor(t){this.Qt=t}coordinate(){return this.qx()?.Li??-1e3}text(){return this.qx()?.hi??""}textColor(){return this.qx()?.DM??"#FFFFFF"}backColor(){return this.qx()?.R??"#000000"}visible(){return null!==this.qx()}qx(){return this.Qt()}}let xh=0;class Ch{constructor(t,i,s){this.eh=new yh,this.Po=new S([]),this.jx=new Map,this.Yx=!1,this.Xx=null,this.dS=null,this.Gx=null,this.GS=null,this.Lf=t,this.be=i,this.So="pipsend-position-line-"+xh++,this.Ps=s,this.If={...wh,...s.theme},this.Jb=[this.eh],this.Kx=gh.map(t=>new Sh(()=>this.Zx(t))),this.Jx=function(t,i){let s=vh.get(t);return s||(s=new ch,vh.set(t,s)),s.IS(i),s}(this.Lf,this.So),this.be.attachPrimitive(this),lh(this.Lf)?.IS(this)}attached(t){this.pM=t.requestUpdate,this.Yx=!0,this.requestUpdate()}detached(){this.Yx=!1,this.pM=void 0}paneViews(){return this.Jb}priceAxisViews(){return this.Kx}updateAllViews(){this.eh.Tt(this.Qx())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.tC(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.OS}`,zOrder:"top",cursorStyle:"close"===s.OS?"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.Xx===n&&this.dS===e||(this.Xx=n,this.dS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Xx&&"close"!==this.dS&&(this.tC(this.Xx)?.draggable??!0)}isClickable(){return"close"===this.dS||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.tC(n.sn)?null:`${this.So}#${n.sn}:${n.OS}`}dragAnchorY(){if(null===this.Gx)return null;const t=this.tC(this.Gx)?.price;if(void 0===t||!isFinite(t))return null;const i=this.be.priceToCoordinate(t);return null===i?null:i}beginDrag(){if(this.Gx=this.Xx,null===this.Gx)return;const t=this.tC(this.Gx)?.price??null;this.GS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.Gx,t)}dragTo(t){null!==this.Gx&&(this.iC(this.Gx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.Gx,t))}commitDrag(){const t=this.Gx;if(this.Gx=null,this.GS=null,null===t)return;const i=this.tC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.Gx,i=this.GS;if(this.Gx=null,this.GS=null,null===t)return;null!==i&&i!==this.tC(t)?.price&&(this.iC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.tC(t)?.price??0)}click(){const t=this.Xx;if(null===t)return;if("close"===this.dS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.tC(t)?.price;void 0!==i&&this.Ps.onClick&&this.Ps.onClick(t,i)}applyOptions(t){const i=this.Gx,s=null===i?void 0:this.tC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=Ph(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=Ph(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.tC(i);null!==t&&(t.price=s)}t.theme&&(this.If={...this.If,...t.theme}),this.requestUpdate()}setPrice(t,i){this.Gx!==t&&this.iC(t,i)}setText(t,i){const s=this.tC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of gh){const s=this.tC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){oh(this.Lf,this),function(t,i){const s=vh.get(t);s&&(s.VS(i),s.Gi()&&vh.delete(t))}(this.Lf,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.pM&&this.pM()}Zx(t){const i=this.tC(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??mh[t],e=this.be.priceFormatter(),r=this.jx.get(t);if(void 0!==r&&r.bt===i.price&&r.R===n&&r.hl===e)return r.Jl.Li!==s&&(r.Jl={...r.Jl,Li:s}),r.Jl;const h={Li:s,hi:e.format(i.price),R:n,DM:this.Po.K(n).J};return this.jx.set(t,{bt:i.price,R:n,hl:e,Jl:h}),h}tC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}iC(t,i){const s=this.tC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}Qx(){if(!this.Yx||!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 gh){const i=this.tC(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,Ix:0,R:i.color??mh[t],hi:i.formatText?i.formatText(i.price):i.text??"",Fx:i.badge??"",Hx:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),bx:i.closable??!0,sC:i.draggable??!0})}if(0===n.length)return this.Jx.ux(this.So,[]),null;this.Jx.ux(this.So,e);for(const t of n)t.Ix=this.Jx.vx(this.So,t.sn);return{Px:n,Z:this.If.background??(r=t.background,"solid"===r.type?r.color:r.topColor),DM:this.If.textColor,Nx:this.If.badgeTextColor,zx:this.If.borderRadius,Wt:this.If.borderWidth,yM:this.If.paddingX,Rx:this.If.paddingY,$x:this.If.backgroundOpacity,T:g(i,this.If.fontFamily??t.fontFamily),P:i,Tx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,Wx:this.Xx,Ux:this.dS};var r}}function Ph(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}const Th=new Set(["line","body","stroke","center","move"]);function kh(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?Th.has(n)?"move":"grab":void 0}}function Dh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var Rh;function Fh(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.Dy;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Ry,t.day=i.day??i.Fy,t}return t}function Ih(t,i){const s={};return s.price=t,s.time=i,s}function Vh(t){if(!t)return Ih(0,null);return Ih(t.price??t.bt??0,Fh(t.time??t.gt??null))}function Lh(t,i="time"){return t?t[i]??null:null}function Ah(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"}(Rh||(Rh={}));class Bh{constructor(t,i,s={}){this._state=Rh.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.nC(),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}nC(){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}selectionBox(){return null}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 Oh=new WeakMap;function Eh(t,i){Oh.set(t,i)}function Wh(t){const i=!0===Oh.get(t);return i&&Oh.set(t,!1),i}function zh(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.Et,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 $h;!function(t){t.eC="idle",t.rC="waiting_first_point",t.hC="waiting_second_point",t.lC="completed"}($h||($h={}));class Hh{constructor(t,i,s={}){this.Lv=$h.eC,this.oC=null,this.tx=null,this.ep=null,this.Lf=t,this.be=i,this.aC=s}_C(){this.Lv===$h.eC&&(this.Lv=$h.rC,this.oC=null,this.uC(),this.cC())}dC(){this.Lv=$h.eC,this.oC=null,this.pC(),this.fC(),this.aC.vC&&this.aC.vC()}mC(){return this.Lv}wC(){return this.Lv===$h.rC||this.Lv===$h.hC}uC(){this.tx=t=>{this.gC(t)},this.Lf.subscribeClick(this.tx)}cC(){this.ep=t=>{this.bC(t)},this.Lf.subscribeCrosshairMove(this.ep)}pC(){this.tx&&(this.Lf.unsubscribeClick(this.tx),this.tx=null)}fC(){this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null)}gC(t){if(!t.point)return;if(Wh(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===$h.rC?(this.oC=n,this.Lv=$h.hC,this.aC.MC&&this.aC.MC(n)):this.Lv===$h.hC&&this.oC&&(this.Lv=$h.lC,this.aC.yC&&this.aC.yC(n),this.aC.SC&&this.aC.SC(this.oC,n),this.pC(),this.fC(),this.Lv=$h.eC,this.oC=null)}bC(t){if(!t.point)return;if(this.Lv!==$h.hC)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.aC.xC&&this.aC.xC(n)}m(){this.dC()}}class Nh{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Uh{constructor(t){this.CC=t,this.Jt=new Nh(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class qh extends Bh{constructor(t,i){super(t,"trend-line",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.IC=null,this.VC=null,this.LC=!1,this.AC=null,this.BC=null,this.OC={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.OC),this.qy(),this.OC.interactive?this.EC():this.LC=!0}EC(){const t=new Hh(this._chart,this._series,{MC:t=>{this.OC.point1Time=t.gt,this.OC.point1Price=t.bt,this.pM()},yC:t=>{this.OC.point2Time=t.gt,this.OC.point2Price=t.bt,this.LC=!0,this.pM(),this.OC.onUpdate&&this.OC.onUpdate()},xC:t=>{this.OC.point1Time&&!this.LC&&(this.BC=t,this.pM())},SC:()=>{this.LC=!0}});this.AC=t,t._C()}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new Uh(this)}$C(){if(!this.OC.point1Time||!this.OC.point2Time)return null;const t=Gn(this._chart,this._series,this.OC.point1Time)??0,i=this._series.priceToCoordinate(this.OC.point1Price)??0,s=Gn(this._chart,this._series,this.OC.point2Time)??0,n=this._series.priceToCoordinate(this.OC.point2Price)??0;if(!this.OC.extendLeft&&!this.OC.extendRight)return{HC:t,NC:i,UC:s,qC:n};if(s===t)return{HC:t,NC:i,UC:s,qC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{HC:this.OC.extendLeft?0:t,NC:this.OC.extendLeft?i-r*t:i,UC:this.OC.extendRight?e:s,qC:this.OC.extendRight?i+r*(e-t):n}}jC(){const t=this.$C();if(null===t)return null;const i=t.UC>=t.HC?t.qC:t.NC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.OC.point2Price??this.OC.point1Price??null}drawToCanvas(t,i,s){if(!this.LC&&this.OC.point1Time&&this.BC)return void this.YC(t,i,s);if(!this.OC.point1Time||!this.OC.point2Time)return;const n=(Gn(this._chart,this._series,this.OC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.OC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.OC.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.OC.point2Price)??0)*s,l=this.OC.lineColor,o=this.TC?this.OC.lineWidth+1:this.OC.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.OC.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.OC.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.$C();if(null===a)return;t.moveTo(a.HC*i,a.NC*s),t.lineTo(a.UC*i,a.qC*s),t.stroke(),t.setLineDash([]),!this.TC&&!this.kC||this.isLocked()||(this.XC(t,n,e,i,l),this.XC(t,r,h,i,l));const _=this.jC();if(!1!==this.OC.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&zh(t,this._series,i,s,{bt:_,ct:n,Et:l})}}YC(t,i,s){if(!this.OC.point1Time||!this.BC)return;const n=(Gn(this._chart,this._series,this.OC.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.OC.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.BC.gt)??0)*i,h=(this._series.priceToCoordinate(this.BC.bt)??0)*s;t.strokeStyle=this.OC.lineColor,t.lineWidth=this.OC.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.XC(t,n,e,i,this.OC.lineColor),t.globalAlpha=.5,this.XC(t,r,h,i,this.OC.lineColor),t.globalAlpha=1}XC(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.OC.lineColor=t,this.pM()}color(){return this.OC.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}isHovered(){return this.kC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){const s=this.$C();if(null===s)return!1;return this.GC(t,i,s.HC,s.NC,s.UC,s.qC)<=8}GC(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.OC.point1Time||!this.OC.point2Time)return null;const s=Gn(this._chart,this._series,this.OC.point1Time)??0,n=this._series.priceToCoordinate(this.OC.point1Price)??0,e=Gn(this._chart,this._series,this.OC.point2Time)??0,r=this._series.priceToCoordinate(this.OC.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.GC(t,i,s,n,e,r)<=10?"line":null}startDrag(t,i){this.DC=!0,this.RC=t,this.FC=i,"line"===t&&(this.IC={gt:this.OC.point1Time,bt:this.OC.point1Price},this.VC={gt:this.OC.point2Time,bt:this.OC.point2Price})}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.IC=null,this.VC=null}updateDrag(t,i){if(this.DC&&this.RC){if("point1"===this.RC)this.OC.point1Time=t,this.OC.point1Price=i;else if("point2"===this.RC)this.OC.point2Time=t,this.OC.point2Price=i;else if("line"===this.RC&&this.IC&&this.VC){const s=Dh(this.FC,t,i);this.OC.point1Time=this.IC.gt+s.gt,this.OC.point1Price=this.IC.bt+s.bt,this.OC.point2Time=this.VC.gt+s.gt,this.OC.point2Price=this.VC.bt+s.bt}this.pM(),this.OC.onUpdate&&this.OC.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Ih(this.OC.point1Price??0,Fh(this.OC.point1Time)),Ih(this.OC.point2Price??0,Fh(this.OC.point2Time))],style:{lineColor:this.OC.lineColor,lineWidth:this.OC.lineWidth,lineStyle:this.OC.lineStyle,extendLeft:this.OC.extendLeft,extendRight:this.OC.extendRight}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return this.LC}remove(){this.AC&&(this.AC.m(),this.AC=null),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.OC.onRemove&&this.OC.onRemove()}}function jh(t,i){return new qh(t,i)}function Yh(t,i,s,n){let e=0,r=null;const h=()=>{null!==r&&(t.unsubscribeClick(r),r=null)};return r=r=>{if(!r.point||Wh(t))return;const l=i.coordinateToPrice(r.point.y),o=Xn(t,i,r.point.x);null!==l&&null!==o&&(e++,e>=s&&h(),n({gt:o,bt:l,ut:r.point.x,ct:r.point.y},e-1))},t.subscribeClick(r),{KC:()=>null!==r,ZC:h}}function Xh(t){const i=t.timeScale();return Math.max(i.width()/5,i.options().barSpacing)}function Gh(t,i){const s=t.timeScale(),n=Math.min(i+Xh(t),s.width()-10);return Math.max(n,i+s.options().barSpacing)}class Kh{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Zh{constructor(t){this.CC=t,this.Jt=new Kh(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Jh extends Bh{constructor(t,i){super(t,"horizontal-line",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.FC=null,this.JC=0,this.QC=null,this.tP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.tP),this.qy(),this.tP.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>this.iP(t)))}iP(t){this.tP.price=t.bt,void 0!==this.tP.startTime&&(this.tP.startTime=t.gt),this.pM()}isComplete(){return!this.QC?.KC()}selectionBox(){const t=void 0===this.tP.price?null:this._series.priceToCoordinate(this.tP.price);return null===t?null:{left:this.sP(),right:this._chart.timeScale().width(),top:t,bottom:t}}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new Zh(this)}sP(){return void 0===this.tP.startTime?0:Gn(this._chart,this._series,this.tP.startTime)??0}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.tP.price)return;const n=(this._series.priceToCoordinate(this.tP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.sP()*i,h=this.tP.lineColor,l=this.TC?this.tP.lineWidth+1:this.tP.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.tP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.tP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.tP.showPriceLabel&&zh(t,this._series,i,s,{bt:this.tP.price,ct:n/s,Et:h}),this.tP.showLabel&&(this.TC||this.kC)&&this.nP(t,n,i,s,h)}nP(t,i,s,n,e){const r=this.tP.labelText||this.tP.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.tP.lineColor=t,this.pM()}color(){return this.tP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.tP.price)return!1;const s=this._series.priceToCoordinate(this.tP.price)??0;return!(t<this.sP()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.DC=!0,this.FC=i,this.JC=this.tP.price??0}stopDrag(){this.DC=!1,this.FC=null}updateDrag(t,i){this.DC&&(this.tP.price=this.JC+Dh(this.FC,t,i).bt,this.pM(),this.tP.onUpdate&&this.tP.onUpdate())}getPrice(){return this.tP.price}setPrice(t){this.tP.price=t,this.pM()}setLabel(t){this.tP.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Ih(this.tP.price??0,Fh(this.tP.startTime))],style:{lineColor:this.tP.lineColor,lineWidth:this.tP.lineWidth,lineStyle:this.tP.lineStyle,showLabel:this.tP.showLabel,labelText:this.tP.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}remove(){this.QC?.ZC(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.tP.onRemove&&this.tP.onRemove()}}function Qh(t,i){return new Jh(t,i)}class tl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class il{constructor(t){this.CC=t,this.Jt=new tl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class sl extends Bh{constructor(t,i){super(t,"cross-line",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.FC=null,this.eP=0,this.JC=0,this.QC=null,this.rP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.rP),this.qy(),this.rP.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>{this.rP.time=t.gt,this.rP.price=t.bt,this.pM()}))}isComplete(){return!this.QC?.KC()}qy(){this.eh=new il(this);const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.PC&&this.PC()}_update(){this.pM()}hP(){if(!this.isComplete()||void 0===this.rP.time||void 0===this.rP.price)return null;const t=Gn(this._chart,this._series,this.rP.time),i=this._series.priceToCoordinate(this.rP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this.hP();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.rP.lineColor,_=this.TC||this.kC&&!this.isLocked(),u=_?this.rP.lineWidth+1:this.rP.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.rP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.rP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(0,o),t.lineTo(r,o),t.moveTo(l,0),t.lineTo(l,h),t.stroke(),t.setLineDash([]),!1!==this.rP.showPriceLabel&&void 0!==this.rP.price&&zh(t,this._series,i,s,{bt:this.rP.price,ct:n.ct,Et: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())}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){const s=this.hP();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.DC=!0,this.FC=i,this.eP=this.rP.time,this.JC=this.rP.price??0}updateDrag(t,i){if(!this.DC)return;const s=Dh(this.FC,t,i);this.rP.time=this.eP+s.gt,this.rP.price=this.JC+s.bt,this.pM(),this.rP.onUpdate&&this.rP.onUpdate()}stopDrag(){this.DC=!1,this.FC=null}setColor(t){this.rP.lineColor=t,this.pM()}color(){return this.rP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}remove(){if(this.QC?.ZC(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.PC=null,this.rP.onRemove&&this.rP.onRemove()}_serializeShape(){return{type:"crossLine",points:[Ih(this.rP.price??0,Fh(this.rP.time))],style:{lineColor:this.rP.lineColor,lineWidth:this.rP.lineWidth,lineStyle:this.rP.lineStyle}}}}function nl(t,i){return new sl(t,i)}class el{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class rl{constructor(t){this.CC=t,this.Jt=new el(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class hl extends Bh{constructor(t,i){super(t,"polygon",i),this.V_=[],this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.lP=null,this.LC=!1,this.BC=null,this.tx=null,this.oP=null,this.aP=null,this._P={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this._P),this.V_=[...i.points??[]],this.qy(),this._P.interactive?this.uP():this.LC=this.V_.length>=3}qy(){this.eh=new rl(this);const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.PC&&this.PC()}_update(){this.pM()}uP(){this.tx=t=>{if(!t.point||Wh(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.cP(t.point.x,t.point.y)?this.dP():(this.V_.push({time:s,price:i}),this.pM()))},this.oP=t=>{if(!t.point||this.LC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.BC={time:s,price:i},this.pM())},this.aP=t=>{"Enter"===t.key&&this.V_.length>=3?this.dP():"Escape"===t.key&&(this.V_=[],this.dP())},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.oP),document.addEventListener("keydown",this.aP)}cP(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)<=hl.pP&&Math.abs(i-e)<=hl.pP)}dP(){this.LC=!0,this.BC=null,this.fP(),this.pM(),this._P.onComplete&&this._P.onComplete(),this._P.onUpdate&&this._P.onUpdate()}fP(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.oP&&(this._chart.unsubscribeCrosshairMove(this.oP),this.oP=null),this.aP&&(document.removeEventListener("keydown",this.aP),this.aP=null)}vP(){const t=[...this.V_];return this.LC||null===this.BC||t.push(this.BC),this.mP(t)}mP(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.vP();if(n.length<2)return;const e=this._P.borderColor,r=this.TC?this._P.borderWidth+1:this._P.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.LC&&(t.closePath(),this._P.fillOpacity>0&&(t.fillStyle=this.By(this._P.fillColor,this._P.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.LC?"dashed"===this._P.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this._P.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.TC||this.kC||!this.LC)&&!this.isLocked())for(const n of this.wP())this.gP(t,n.ut*i,n.ct*s,i,e)}wP(){return this.mP(this.V_)}gP(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()}By(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}zC(t,i){if(!this.isVisible()||!this.LC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){const s=this.wP();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.wP();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.DC=!0,this.RC=t,this.FC=i,this.lP=this.V_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.DC&&null!==this.RC&&null!==this.lP){if("shape"===this.RC){const s=Dh(this.FC,t,i);this.V_=this.lP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.RC;this.V_[s]&&(this.V_[s]={time:t,price:i})}this.pM(),this._P.onUpdate&&this._P.onUpdate()}}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.lP=null}setColor(t){this._P.borderColor=t,this._P.fillColor=t,this.pM()}color(){return this._P.borderColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}points(){return this.V_}isComplete(){return this.LC}remove(){if(this.fP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.PC=null,this._P.onRemove&&this._P.onRemove()}_serializeShape(){return{type:"polygon",points:this.V_.map(t=>Ih(t.price,Fh(t.time))),style:{fillColor:this._P.fillColor,fillOpacity:this._P.fillOpacity,borderColor:this._P.borderColor,borderWidth:this._P.borderWidth,borderStyle:this._P.borderStyle}}}}function ll(t,i){return new hl(t,i)}hl.pP=12;class ol{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class al{constructor(t){this.CC=t,this.Jt=new ol(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class _l extends Bh{constructor(t,i){super(t,"parallel-channel",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.bP=null,this.LC=!1,this.dd=0,this.BC=null,this.tx=null,this.oP=null,this.MP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.MP),this.qy(),this.MP.interactive?this.uP():this.LC=!0}qy(){this.eh=new al(this);const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.PC&&this.PC()}_update(){this.pM()}uP(){this.tx=t=>{if(!t.point||Wh(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.MP.point1Time=s,this.MP.point1Price=i;else{if(1!==this.dd)return this.MP.channelWidth=i-this.yP(s),void this.dP();this.MP.point2Time=s,this.MP.point2Price=i}this.dd++,this.pM()}},this.oP=t=>{if(!t.point||this.LC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.BC={gt:s,bt:i},2===this.dd&&(this.MP.channelWidth=i-this.yP(s)),this.pM())},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.oP)}dP(){this.LC=!0,this.BC=null,this.fP(),this.pM(),this.MP.onComplete&&this.MP.onComplete(),this.MP.onUpdate&&this.MP.onUpdate()}fP(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.oP&&(this._chart.unsubscribeCrosshairMove(this.oP),this.oP=null)}yP(t){const i=this.MP.point1Time,s=this.MP.point2Time,n=this.MP.point1Price,e=this.MP.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)}uS(){const t=this.MP,i=this.LC?t.point2Time:t.point2Time??this.BC?.gt,s=this.LC?t.point2Price:t.point2Price??this.BC?.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:{HC:n,UC:l,SP:r,xP:o,CP:_,PP:u}}drawToCanvas(t,i,s){const n=this.uS();if(null===n)return;const e=this.MP,r=e.lineColor,h=this.TC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.By(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.HC*l,n.SP*o),t.lineTo(n.UC*l,n.xP*o),t.lineTo(n.UC*l,n.PP*o),t.lineTo(n.HC*l,n.CP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.LC?"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.HC*l,n.SP*o),t.lineTo(n.UC*l,n.xP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.HC*l,n.CP*o),t.lineTo(n.UC*l,n.PP*o)),t.stroke(),t.setLineDash([]);if((this.TC||this.kC||!this.LC)&&!this.isLocked()&&(this.gP(t,n.HC*l,n.SP*o,l,r),this.gP(t,n.UC*l,n.xP*o,l,r),0!==(e.channelWidth??0))){const i=(n.HC+n.UC)/2,s=(n.CP+n.PP)/2;this.gP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.LC){const i=this._series.coordinateToPrice(n.xP);null!==i&&zh(t,this._series,l,o,{bt:i,ct:n.xP,Et:r})}}gP(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()}By(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}zC(t,i){if(!this.isVisible()||!this.LC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}TP(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.uS();if(null===s)return!1;return this.TP(t,i,s.HC,s.SP,s.UC,s.xP)<=8||this.TP(t,i,s.HC,s.CP,s.UC,s.PP)<=8}hitTestEndpoint(t,i){const s=this.uS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.HC,s.SP))return"point1";if(n(s.UC,s.xP))return"point2";if(0!==(this.MP.channelWidth??0)){if(n((s.HC+s.UC)/2,(s.CP+s.PP)/2))return"width"}return null}startDrag(t,i){this.DC=!0,this.RC=t,this.FC=i,this.bP={kP:{gt:this.MP.point1Time,bt:this.MP.point1Price},DP:{gt:this.MP.point2Time,bt:this.MP.point2Price},ts:this.MP.channelWidth??0}}updateDrag(t,i){if(!this.DC||null===this.RC||null===this.bP)return;const s=this.MP;if("point1"===this.RC)s.point1Time=t,s.point1Price=i;else if("point2"===this.RC)s.point2Time=t,s.point2Price=i;else if("width"===this.RC)s.channelWidth=i-this.yP(t);else{const n=Dh(this.FC,t,i);s.point1Time=this.bP.kP.gt+n.gt,s.point1Price=this.bP.kP.bt+n.bt,s.point2Time=this.bP.DP.gt+n.gt,s.point2Price=this.bP.DP.bt+n.bt,s.channelWidth=this.bP.ts}this.pM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.bP=null}setColor(t){this.MP.lineColor=t,this.MP.fillColor=t,this.pM()}color(){return this.MP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}isComplete(){return this.LC}remove(){if(this.fP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.PC=null,this.MP.onRemove&&this.MP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Ih(this.MP.point1Price??0,Fh(this.MP.point1Time)),Ih(this.MP.point2Price??0,Fh(this.MP.point2Time))],style:{lineColor:this.MP.lineColor,lineWidth:this.MP.lineWidth,lineStyle:this.MP.lineStyle,fillColor:this.MP.fillColor,fillOpacity:this.MP.fillOpacity,extendRight:this.MP.extendRight},extra:{channelWidth:this.MP.channelWidth}}}}function ul(t,i){return new _l(t,i)}class cl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class dl{constructor(t){this.CC=t,this.Jt=new cl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class pl extends Bh{constructor(t,i){super(t,"pitchfork",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.bP=null,this.LC=!1,this.dd=0,this.BC=null,this.tx=null,this.oP=null,this.RP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.RP),this.qy(),this.RP.interactive?this.uP():this.LC=!0}qy(){this.eh=new dl(this);const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}pM(){this.PC&&this.PC()}_update(){this.pM()}uP(){this.tx=t=>{if(!t.point||Wh(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.RP.pivotTime=s,this.RP.pivotPrice=i;else{if(1!==this.dd)return this.RP.lowerTime=s,this.RP.lowerPrice=i,this.dd++,void this.dP();this.RP.upperTime=s,this.RP.upperPrice=i}this.dd++,this.pM()}},this.oP=t=>{if(!t.point||this.LC)return;const i=this._series.coordinateToPrice(t.point.y),s=Xn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.BC={gt:s,bt:i},this.pM())},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.oP)}dP(){this.LC=!0,this.BC=null,this.fP(),this.pM(),this.RP.onComplete&&this.RP.onComplete(),this.RP.onUpdate&&this.RP.onUpdate()}fP(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.oP&&(this._chart.unsubscribeCrosshairMove(this.oP),this.oP=null)}FP(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}}IP(){const t=this.RP,i=this.FP(t.pivotTime,t.pivotPrice),s=this.FP(t.upperTime,t.upperPrice),n=this.LC?this.FP(t.lowerTime,t.lowerPrice):this.FP(t.lowerTime,t.lowerPrice)??(null!==this.BC&&this.dd>=2?this.FP(this.BC.gt,this.BC.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{VP:i,LP:e,AP:s,BP:n,OP:l(i),EP:l(s),WP:l(n)}}drawToCanvas(t,i,s){const n=this.IP();if(null===n)return void this.zP(t,i,s);const e=this.RP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.By(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.AP.ut*h,n.AP.ct*l),t.lineTo(n.EP.ut*h,n.EP.ct*l),t.lineTo(n.WP.ut*h,n.WP.ct*l),t.lineTo(n.BP.ut*h,n.BP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.TC?e.lineWidth+1:e.lineWidth)*h,"dashed"===e.lineStyle?t.setLineDash([10*h,5*h]):"dotted"===e.lineStyle&&t.setLineDash([2*h,3*h]),t.beginPath(),t.moveTo(n.AP.ut*h,n.AP.ct*l),t.lineTo(n.BP.ut*h,n.BP.ct*l),t.moveTo(n.VP.ut*h,n.VP.ct*l),t.lineTo(n.OP.ut*h,n.OP.ct*l),t.moveTo(n.AP.ut*h,n.AP.ct*l),t.lineTo(n.EP.ut*h,n.EP.ct*l),t.moveTo(n.BP.ut*h,n.BP.ct*l),t.lineTo(n.WP.ut*h,n.WP.ct*l),t.stroke(),t.setLineDash([]);if((this.TC||this.kC||!this.LC)&&!this.isLocked())for(const i of[n.VP,n.AP,n.BP])this.gP(t,i.ut*h,i.ct*l,h,r)}zP(t,i,s){const n=this.RP,e=this.FP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.FP(n.upperTime,n.upperPrice)??(null!==this.BC?this.FP(this.BC.gt,this.BC.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.gP(t,e.ut*i,e.ct*s,i,h)}gP(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()}By(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}zC(t,i){if(!this.isVisible()||!this.LC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}TP(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.IP();if(null===s)return!1;return[[s.VP,s.OP],[s.AP,s.EP],[s.BP,s.WP],[s.AP,s.BP]].some(([s,n])=>this.TP(t,i,s.ut,s.ct,n.ut,n.ct)<=8)}hitTestEndpoint(t,i){const s=this.IP();if(null===s)return null;const n=s=>Math.abs(t-s.ut)<=10&&Math.abs(i-s.ct)<=10;return n(s.VP)?"pivot":n(s.AP)?"upper":n(s.BP)?"lower":null}startDrag(t,i){this.DC=!0,this.RC=t,this.FC=i,this.bP=[{gt:this.RP.pivotTime,bt:this.RP.pivotPrice},{gt:this.RP.upperTime,bt:this.RP.upperPrice},{gt:this.RP.lowerTime,bt:this.RP.lowerPrice}]}updateDrag(t,i){if(!this.DC||null===this.RC||null===this.bP)return;const s=this.RP;if("pivot"===this.RC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.RC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.RC)s.lowerTime=t,s.lowerPrice=i;else{const n=Dh(this.FC,t,i),[e,r,h]=this.bP;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.DC=!1,this.RC=null,this.FC=null,this.bP=null}setColor(t){this.RP.lineColor=t,this.RP.fillColor=t,this.pM()}color(){return this.RP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}isComplete(){return this.LC}remove(){if(this.fP(),this.jb){try{this._series.detachPrimitive(this.jb)}catch(t){}this.jb=null}this.PC=null,this.RP.onRemove&&this.RP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Ih(this.RP.pivotPrice??0,Fh(this.RP.pivotTime)),Ih(this.RP.upperPrice??0,Fh(this.RP.upperTime)),Ih(this.RP.lowerPrice??0,Fh(this.RP.lowerTime))],style:{lineColor:this.RP.lineColor,lineWidth:this.RP.lineWidth,lineStyle:this.RP.lineStyle,fillColor:this.RP.fillColor,fillOpacity:this.RP.fillOpacity}}}}function fl(t,i){return new pl(t,i)}class vl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ml{constructor(t){this.CC=t,this.Jt=new vl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class wl extends Bh{constructor(t,i){super(t,"vertical-line",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.FC=null,this.eP=0,this.QC=null,this.$P={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.$P),this.qy(),this.$P.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>{this.$P.time=t.gt,this.pM()}))}isComplete(){return!this.QC?.KC()}selectionBox(){const t=Gn(this._chart,this._series,this.$P.time);if(null===t)return null;let i;try{i=this._series.getPane().getHeight()/2}catch(t){return null}return{left:t,right:t,top:i,bottom:i}}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new ml(this)}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.$P.time)return;const n=(Gn(this._chart,this._series,this.$P.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.$P.lineColor,h=this.TC||this.kC&&!this.isLocked()?this.$P.lineWidth+1:this.$P.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.$P.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.$P.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.$P.showLabel&&(this.TC||this.kC)&&this.$P.labelText&&this.nP(t,n,i,s,r)}nP(t,i,s,n,e){const r=this.$P.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.$P.lineColor=t,this.pM()}color(){return this.$P.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.$P.time)return!1;const s=Gn(this._chart,this._series,this.$P.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.DC=!0,this.FC=i,this.eP=this.$P.time}stopDrag(){this.DC=!1,this.FC=null}updateDrag(t,i){this.DC&&(this.$P.time=this.eP+Dh(this.FC,t,i).gt,this.pM(),this.$P.onUpdate&&this.$P.onUpdate())}getTime(){return this.$P.time}setTime(t){this.$P.time=t,this.pM()}setLabel(t){this.$P.labelText=t,this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Ih(0,Fh(this.$P.time))],style:{lineColor:this.$P.lineColor,lineWidth:this.$P.lineWidth,lineStyle:this.$P.lineStyle,showLabel:this.$P.showLabel,labelText:this.$P.labelText}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}remove(){this.QC?.ZC(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.$P.onRemove&&this.$P.onRemove()}}function gl(t,i){return new wl(t,i)}const bl=[{HP:0,Jl:"0.0%"},{HP:.236,Jl:"23.6%"},{HP:.382,Jl:"38.2%"},{HP:.5,Jl:"50.0%"},{HP:.618,Jl:"61.8%"},{HP:.786,Jl:"78.6%"},{HP:1,Jl:"100.0%"}],Ml=[...bl,{HP:1.272,Jl:"127.2%"},{HP:1.414,Jl:"141.4%"},{HP:1.618,Jl:"161.8%"},{HP:2,Jl:"200.0%"},{HP:2.618,Jl:"261.8%"}];class yl{constructor(t=!1){this.NP=t?Ml:bl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.NP.map(({HP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{HP: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.NP=t}getRatios(){return[...this.NP]}getRatioValues(){return this.NP.map(t=>t.HP)}useStandardRatios(){this.NP=bl}useExtendedRatios(){this.NP=Ml}}class Sl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class xl{constructor(t){this.CC=t,this.Jt=new Sl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}}function Cl(t){return{HP:t,Jl:`${(100*t).toFixed(1)}%`}}class Pl extends Bh{constructor(t,i){super(t,"fibonacci-tool",i),this.jb=null,this.PC=null,this.Gb=null,this.eh=null,this.UP=null,this.LC=!1,this.TC=!1,this.kC=!1,this.BC=null,this.DC=!1,this.qP=null,this.ep=null,this.jP={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.jP),this.YP=new yl(this.jP.useExtended),void 0!==this.jP.levels&&this.jP.levels.length>0&&this.YP.updateRatios(this.jP.levels.map(Cl)),this.qy(),this.jP.interactive?this.EC():(this.LC=!0,this.XP())}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new xl(this)}drawToCanvas(t,i,s){if(!this.LC&&this.jP.point1Time&&this.BC)return void this.YC(t,i,s);if(!this.Gb||!this.jP.point1Time||!this.jP.point2Time)return;const n=(Gn(this._chart,this._series,this.jP.point1Time)??0)*i,e=(Gn(this._chart,this._series,this.jP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.TC?2:this.jP.lineWidth;this.Gb.levels.forEach(n=>{this.kx(t,n,r,h,i,s,l)}),!this.TC&&!this.kC||this.isLocked()||(this.XC(t,n,(this._series.priceToCoordinate(this.jP.point1Price)??0)*s,i),this.XC(t,e,(this._series.priceToCoordinate(this.jP.point2Price)??0)*s,i))}kx(t,i,s,n,e,r,h=1){const l=i.ratio??i.HP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.jP.levelColors?.[l.toString()]||this.jP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.jP.showLabels&&this.nP(t,i,s,n,a,e,_)}nP(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.YP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.jP.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.jP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}XP(){this.jP.point1Time&&this.jP.point1Price&&this.jP.point2Time&&this.jP.point2Price&&(this.Gb=this.YP.calculateLevels(this.jP.point1Time,this.jP.point1Price,this.jP.point2Time,this.jP.point2Price),this.jP.onUpdate&&this.Gb&&this.jP.onUpdate(this.Gb))}updatePoints(t,i,s,n){this.jP.point1Time=t,this.jP.point1Price=i,this.jP.point2Time=s,this.jP.point2Price=n,this.XP(),this.pM()}getMetrics(){return this.Gb}getLevels(){return this.Gb?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.YP.getRatioValues();return{type:"fibRetracement",points:[Ih(this.jP.point1Price??0,Fh(this.jP.point1Time)),Ih(this.jP.point2Price??0,Fh(this.jP.point2Time))],style:{lineColor:this.jP.lineColor,lineWidth:this.jP.lineWidth,showLabels:this.jP.showLabels,labelPosition:this.jP.labelPosition,levelColors:this.jP.levelColors},extra:{levels:t,useExtended:this.jP.useExtended}}}useExtendedLevels(t){this.jP.useExtended=t,t?this.YP.useExtendedRatios():this.YP.useStandardRatios(),this.XP(),this.pM()}EC(){this.UP=new Hh(this._chart,this._series,{MC:t=>{this.jP.point1Time=t.gt,this.jP.point1Price=t.bt,this.pM()},yC:t=>{this.jP.point2Time=t.gt,this.jP.point2Price=t.bt},SC:(t,i)=>{this.jP.point1Time=t.gt,this.jP.point1Price=t.bt,this.jP.point2Time=i.gt,this.jP.point2Price=i.bt,this.LC=!0,this.BC=null,this.XP(),this.GP(),this.pM()},xC:t=>{this.BC=t,this.pM()}}),this.UP._C()}YC(t,i,s){if(!this.jP.point1Time||!this.BC)return;const n=(Gn(this._chart,this._series,this.jP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.jP.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.BC.gt)??0)*i,h=(this._series.priceToCoordinate(this.BC.bt)??0)*s,l=this.YP.calculateLevels(this.jP.point1Time,this.jP.point1Price,this.BC.gt,this.BC.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.HP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.jP.levelColors?.[e.toString()]||this.jP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.jP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.jP.showLabels){const s=`${n.label??n.Jl} ${this.YP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.jP.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.jP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.XC(t,n,e,i),t.globalAlpha=.6,this.XC(t,r,h,i),t.globalAlpha=1}XC(t,i,s,n){const e=this.jP.lineColor,r=this.TC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.TC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}GP(){this.ep=t=>{this.KP(t)},this._chart.subscribeCrosshairMove(this.ep)}ZP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}KP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.TC||!this.DC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.qP?(this.jP.point1Time=i,this.jP.point1Price=s):"point2"===this.qP&&(this.jP.point2Time=i,this.jP.point2Price=s),this.XP(),this.pM())}startDrag(t){this.DC=!0,this.qP=t}stopDrag(){this.DC=!1,this.qP=null}updateDrag(t,i){this.DC&&this.qP&&("point1"===this.qP?(this.jP.point1Time=t,this.jP.point1Price=i):(this.jP.point2Time=t,this.jP.point2Price=i),this.XP(),this.pM())}hitTestEndpoint(t,i){if(!this.LC||!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;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.jP={...this.jP,...t},void 0!==t.levels&&t.levels.length>0?this.YP.updateRatios(t.levels.map(Cl)):void 0!==t.useExtended&&(t.useExtended?this.YP.useExtendedRatios():this.YP.useStandardRatios()),super.applyOptions(t),this.XP(),this.pM()}options(){return{...this.jP,levels:this.YP.getRatioValues()}}setColor(t){this.jP.lineColor=t,this.pM()}color(){return this.jP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}isSelected(){return this.TC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.LC||!this.jP.point1Time||!this.jP.point2Time)return!1;const s=Gn(this._chart,this._series,this.jP.point1Time)??0,n=Gn(this._chart,this._series,this.jP.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.LC}remove(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.UP&&(this.UP.m(),this.UP=null),this.ZP(),this.jP.onRemove&&this.jP.onRemove()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.jP.onRemove&&this.jP.onRemove()}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.XP(),this.pM()}}function Tl(t,i){return new Pl(t,i)}class kl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Dl{constructor(t){this.CC=t,this.Jt=new kl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}}class Rl extends Bh{constructor(t,i){super(t,"fibonacci-extension",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.QC=null,this.jP={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.qy(),this.jP.interactive&&(this.QC=Yh(this._chart,this._series,3,(t,i)=>{const s={time:t.gt,price:t.bt};0===i?this.setPoint1(s):1===i?this.setPoint2(s):this.setPoint3(s)}))}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new Dl(this)}getPoint1(){return this.jP.point1}getPoint2(){return this.jP.point2}getPoint3(){return this.jP.point3}getLevels(){return this.jP.levels||[]}getOptions(){return this.jP}setPoint1(t){this.jP.point1=t,this.pM()}setPoint2(t){this.jP.point2=t,this.pM()}setPoint3(t){this.jP.point3=t,this.pM()}isComplete(){return!this.QC?.KC()&&!!(this.jP.point1&&this.jP.point2&&this.jP.point3)}setColor(t){this.jP.lineColor=t,this.pM()}color(){return this.jP.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.jP.point1,this.jP.point2,this.jP.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.JP();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.jP.point1,n=this.jP.point2,e=this.jP.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.DC=!0,this.RC=t}stopDrag(){this.DC=!1,this.RC=null}updateDrag(t,i){if(!this.DC||!this.RC)return;const s={time:t,price:i};switch(this.RC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.jP.onUpdate&&this.jP.onUpdate()}JP(){if(!this.isComplete())return[];const t=this.jP.point1,i=this.jP.point2,s=this.jP.point3,n=i.price-t.price;return(this.jP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.JP()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.jP.point1,e=this.jP.point2,r=this.jP.point3,h=this.TC||this.kC&&!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.jP.lineColor||"#787B86",t.lineWidth=(this.jP.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.jP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.jP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.jP.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:[Vh(this.jP.point1),Vh(this.jP.point2),Vh(this.jP.point3)],style:{lineColor:this.jP.lineColor,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.PC?.()}_update(){this.pM()}remove(){this.QC?.ZC(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null)}}function Fl(t,i){return new Rl(t,i)}class Il{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Vl{constructor(t){this.CC=t,this.Jt=new Il(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const Ll=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Al extends Bh{constructor(t,i){super(t,"fibonacci-fan",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.QP=!1,this.tx=null,this.ep=null,this.BC=null,this.tT={levels:Ll,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.qy(),this.tT.interactive&&!this.tT.point1Time&&this.EC()}EC(){this.QP=!0,this.tx=t=>{if(!t.point)return;if(Wh(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.tT.point1Time?(this.tT.point2Time=i,this.tT.point2Price=s,this.QP=!1,this.BC=null,this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.tT.onUpdate&&this.tT.onUpdate()):(this.tT.point1Time=i,this.tT.point1Price=s,this.pM()))},this.ep=t=>{if(this.QP&&this.tT.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.BC={gt:i,bt:s},this.pM())}else this.BC=null,this.pM()},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.ep)}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new Vl(this)}drawToCanvas(t,i,s){const n=this.tT.point1Time,e=this.tT.point1Price,r=this.QP&&this.BC?this.BC.gt:this.tT.point2Time,h=this.QP&&this.BC?this.BC.bt:this.tT.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.TC?this.tT.lineWidth+1:this.tT.lineWidth;if(this.iT(t,l,o,a,_,"#2962FF",u*i),this.tT.levels)for(const n of this.tT.levels)this.sT(t,l,o,a,_,n,i,s,undefined,u);!this.TC&&!this.kC||this.QP||this.isLocked()||(this.XC(t,l,o,i,"#2962ff"),this.XC(t,a,_,i,"#2962ff"))}sT(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.tT.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.iT(t,i,s,c,d,p,a*h),this.tT.showLabels&&!this.QP&&this.nP(t,_,u,r.label,h,p)}iT(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()}XC(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()}nP(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.tT.levels??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.tT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.tT.point1Time||!this.tT.point2Time)return!1;const s=Gn(this._chart,this._series,this.tT.point1Time)??0,n=this._series.priceToCoordinate(this.tT.point1Price)??0,e=Gn(this._chart,this._series,this.tT.point2Time)??0,r=this._series.priceToCoordinate(this.tT.point2Price)??0;if(this.GC(t,i,s,n,e,r)<=8)return!0;if(this.tT.levels)for(const h of this.tT.levels){const l=n+(r-n)*h.level,o=e;if(this.GC(t,i,s,n,o,l)<=8)return!0}return!1}GC(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.tT.point1Time||!this.tT.point2Time)return null;const s=Gn(this._chart,this._series,this.tT.point1Time)??0,n=this._series.priceToCoordinate(this.tT.point1Price)??0,e=Gn(this._chart,this._series,this.tT.point2Time)??0,r=this._series.priceToCoordinate(this.tT.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.DC=!0,this.RC=t}stopDrag(){this.DC=!1,this.RC=null}updateDrag(t,i){this.DC&&this.RC&&("point1"===this.RC?(this.tT.point1Time=t,this.tT.point1Price=i):"point2"===this.RC&&(this.tT.point2Time=t,this.tT.point2Price=i),this.pM(),this.tT.onUpdate&&this.tT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Ih(this.tT.point1Price??0,Fh(this.tT.point1Time)),Ih(this.tT.point2Price??0,Fh(this.tT.point2Time))],style:{lineWidth:this.tT.lineWidth,showLabels:this.tT.showLabels,extendLines:this.tT.extendLines},extra:{levels:(this.tT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return!this.QP}remove(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=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.tT.onRemove&&this.tT.onRemove()}}function Bl(t,i){return new Al(t,i)}class Ol{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.CC=t,this.Jt=new Ol(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Wl extends Bh{constructor(t,i){super(t,"rectangle",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.IC=null,this.VC=null,this.QP=!1,this.tx=null,this.ep=null,this.BC=null,this.nT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.nT),this.qy(),!this.nT.interactive||this.nT.time1&&this.nT.time2||this.EC()}EC(){this.QP=!0,this.tx=t=>{if(!t.point)return;if(Wh(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.nT.time1?(this.nT.time2=i,this.nT.price2=s,this.QP=!1,this.BC=null,this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.nT.onUpdate&&this.nT.onUpdate()):(this.nT.time1=i,this.nT.price1=s,this.pM()))},this.ep=t=>{if(this.QP&&this.nT.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.BC={gt:i,bt:s},this.pM())}else this.BC=null,this.pM()},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.ep)}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new El(this)}drawToCanvas(t,i,s){const n=this.nT.time1,e=this.nT.price1,r=this.QP&&this.BC?this.BC.gt:this.nT.time2,h=this.QP&&this.BC?this.BC.bt:this.nT.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.nT.fillOpacity>0){const i=this.Ny(this.nT.fillColor,this.QP?.1:this.nT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.nT.borderColor,w=this.TC?this.nT.borderWidth+1:this.nT.borderWidth;w>0&&(t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.nT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.nT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([])),!this.TC&&!this.kC||this.QP||this.isLocked()||this.eT(t,u,d,c,p,i,m),this.nT.showLabel&&this.nT.labelText&&!this.QP&&this.nP(t,u,d,c,p,i,s,m)}eT(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)}nP(t,i,s,n,e,r,h,l){const o=6*r,a=(this.nT.labelFontSize??12)*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.nT.labelText).width,u=a,c=(s+e)/2-u/2-o,d=Math.min(n,t.canvas.width);let p=i+o,f=s+o;switch(this.nT.labelPosition){case"top-right":p=d-_-2*o,f=s+o;break;case"bottom-left":p=i+o,f=e-u-2*o;break;case"bottom-right":p=d-_-2*o,f=e-u-2*o;break;case"center":p=(Math.max(i,0)+d)/2-_/2-o,f=c;break;case"left":p=i+o,f=c;break;case"right":p=d-_-2*o,f=c}t.fillStyle=this.nT.labelBackgroundColor??l,t.fillRect(p,f,_+2*o,u+2*o),t.fillStyle=this.nT.labelColor??"#ffffff",t.textBaseline="top",t.fillText(this.nT.labelText,p+o,f+o)}Ny(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.nT.borderColor=t,this.nT.fillColor=t,this.pM()}color(){return this.nT.borderColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.nT.time1||!this.nT.time2)return!1;const s=Gn(this._chart,this._series,this.nT.time1)??0,n=this._series.priceToCoordinate(this.nT.price1)??0,e=Gn(this._chart,this._series,this.nT.time2)??0,r=this._series.priceToCoordinate(this.nT.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.nT.time1||!this.nT.time2)return null;const s=Gn(this._chart,this._series,this.nT.time1)??0,n=this._series.priceToCoordinate(this.nT.price1)??0,e=Gn(this._chart,this._series,this.nT.time2)??0,r=this._series.priceToCoordinate(this.nT.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.DC=!0,this.RC=t,this.FC=i,"body"===t&&(this.IC={gt:this.nT.time1,bt:this.nT.price1},this.VC={gt:this.nT.time2,bt:this.nT.price2})}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.IC=null,this.VC=null}updateDrag(t,i){if(!this.DC||!this.RC)return;const s=Gn(this._chart,this._series,this.nT.time1)??0,n=this._series.priceToCoordinate(this.nT.price1)??0,e=s<(Gn(this._chart,this._series,this.nT.time2)??0),r=n<(this._series.priceToCoordinate(this.nT.price2)??0);if("body"===this.RC&&this.IC&&this.VC){const s=Dh(this.FC,t,i);this.nT.time1=this.IC.gt+s.gt,this.nT.price1=this.IC.bt+s.bt,this.nT.time2=this.VC.gt+s.gt,this.nT.price2=this.VC.bt+s.bt}else switch(this.RC){case"corner1":e&&r?(this.nT.time1=t,this.nT.price1=i):!e&&r?(this.nT.time2=t,this.nT.price1=i):e&&!r?(this.nT.time1=t,this.nT.price2=i):(this.nT.time2=t,this.nT.price2=i);break;case"corner2":e&&r?(this.nT.time2=t,this.nT.price1=i):!e&&r?(this.nT.time1=t,this.nT.price1=i):e&&!r?(this.nT.time2=t,this.nT.price2=i):(this.nT.time1=t,this.nT.price2=i);break;case"corner3":e&&r?(this.nT.time1=t,this.nT.price2=i):!e&&r?(this.nT.time2=t,this.nT.price2=i):e&&!r?(this.nT.time1=t,this.nT.price1=i):(this.nT.time2=t,this.nT.price1=i);break;case"corner4":e&&r?(this.nT.time2=t,this.nT.price2=i):!e&&r?(this.nT.time1=t,this.nT.price2=i):e&&!r?(this.nT.time2=t,this.nT.price1=i):(this.nT.time1=t,this.nT.price1=i)}this.pM(),this.nT.onUpdate&&this.nT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Ih(this.nT.price1??0,Fh(this.nT.time1)),Ih(this.nT.price2??0,Fh(this.nT.time2))],style:{fillColor:this.nT.fillColor,fillOpacity:this.nT.fillOpacity,borderColor:this.nT.borderColor,borderWidth:this.nT.borderWidth,borderStyle:this.nT.borderStyle,showLabel:this.nT.showLabel,labelText:this.nT.labelText,labelPosition:this.nT.labelPosition,labelColor:this.nT.labelColor,labelBackgroundColor:this.nT.labelBackgroundColor,labelFontSize:this.nT.labelFontSize}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return!this.QP}remove(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=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.nT.onRemove&&this.nT.onRemove()}}function zl(t,i){return new Wl(t,i)}class $l{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Hl{constructor(t){this.CC=t,this.Jt=new $l(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Nl extends Bh{constructor(t,i){super(t,"circle",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.bP=null,this.QP=!1,this.tx=null,this.ep=null,this.BC=null,this.rT={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.rT),this.qy(),this.rT.interactive&&!this.rT.centerTime&&this.EC()}EC(){this.QP=!0,this.tx=t=>{if(!t.point)return;if(Wh(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.rT.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.rT.centerTime)??0,n=this._series.priceToCoordinate(this.rT.centerPrice)??0,e=Gn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.rT.radiusTime=Math.abs(e-t),this.rT.radiusPrice=Math.abs(r-n),this.QP=!1,this.BC=null,this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.pM(),this.rT.onUpdate&&this.rT.onUpdate()}else this.rT.centerTime=i,this.rT.centerPrice=s,this.pM()},this.ep=t=>{if(this.QP&&this.rT.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.BC={gt:i,bt:s},this.pM())}else this.BC=null,this.pM()},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.ep)}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new Hl(this)}drawToCanvas(t,i,s){if(!this.rT.centerTime||void 0===this.rT.centerPrice)return;const n=(Gn(this._chart,this._series,this.rT.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.rT.centerPrice)??0)*s;let r,h;if(this.QP&&this.BC){const t=(Gn(this._chart,this._series,this.BC.gt)??0)*i,l=(this._series.priceToCoordinate(this.BC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.rT.radiusTime||void 0===this.rT.radiusPrice)return;r=this.rT.radiusTime*i,h=this.rT.radiusPrice*s}if(this.rT.fillOpacity>0){const i=this.Ny(this.rT.fillColor,this.QP?.05:this.rT.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.rT.borderColor,o=this.TC?this.rT.borderWidth+1:this.rT.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.rT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.rT.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.TC&&!this.kC||this.QP||this.isLocked()||this.hT(t,n,e,i,l),!this.TC&&!this.kC||this.QP||this.isLocked()||this.lT(t,n,e,r,h,i,l),this.rT.showLabel&&this.rT.labelText&&!this.QP&&this.nP(t,n,e,i,l)}hT(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()}lT(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)}nP(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.rT.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.rT.labelText,a+r,_+r)}Ny(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.rT.borderColor=t,this.rT.fillColor=t,this.pM()}color(){return this.rT.borderColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.rT.centerTime||void 0===this.rT.radiusTime)return!1;const s=Gn(this._chart,this._series,this.rT.centerTime)??0,n=this._series.priceToCoordinate(this.rT.centerPrice)??0,e=(t-s)/this.rT.radiusTime,r=(i-n)/this.rT.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.rT.centerTime||void 0===this.rT.radiusTime)return null;const s=Gn(this._chart,this._series,this.rT.centerTime)??0,n=this._series.priceToCoordinate(this.rT.centerPrice)??0,e=this.rT.radiusTime,r=this.rT.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.DC=!0,this.RC=t,this.FC=i,this.bP="center"===t?{gt:this.rT.centerTime,bt:this.rT.centerPrice}:null}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.bP=null}updateDrag(t,i){if(this.DC&&this.RC){if("center"===this.RC&&this.bP){const s=Dh(this.FC,t,i);this.rT.centerTime=this.bP.gt+s.gt,this.rT.centerPrice=this.bP.bt+s.bt}else if("edge"===this.RC){const s=Gn(this._chart,this._series,this.rT.centerTime)??0,n=this._series.priceToCoordinate(this.rT.centerPrice)??0,e=Gn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.rT.radiusTime=Math.abs(e-s),this.rT.radiusPrice=Math.abs(r-n)}this.pM(),this.rT.onUpdate&&this.rT.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Ih(this.rT.centerPrice??0,Fh(this.rT.centerTime))],style:{fillColor:this.rT.fillColor,fillOpacity:this.rT.fillOpacity,borderColor:this.rT.borderColor,borderWidth:this.rT.borderWidth,borderStyle:this.rT.borderStyle,showLabel:this.rT.showLabel,labelText:this.rT.labelText},extra:{radiusTime:this.rT.radiusTime,radiusPrice:this.rT.radiusPrice}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return!this.QP}remove(){this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=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.rT.onRemove&&this.rT.onRemove()}}function Ul(t,i){return new Nl(t,i)}class ql{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class jl{constructor(t){this.CC=t,this.Jt=new ql(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Yl extends Bh{constructor(t,i){super(t,"arrow",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.oT=-1,this.QP=!1,this.tx=null,this.aT=null,this.ep=null,this.BC=null,this._T={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this._T),this.qy(),!this._T.interactive||this._T.points&&0!==this._T.points.length||this.EC()}EC(){this.QP=!0,this.tx=t=>{if(!t.point)return;if(Wh(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._T.points||(this._T.points=[]),this._T.points.push({time:i,price:s}),this.pM(),this._T.onUpdate&&this._T.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.BC={gt:i,bt:s},this.pM())}else this.BC=null,this.pM()},this.aT=t=>{this.QP&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.tx),this._chart.subscribeCrosshairMove(this.ep);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.aT)}finishDrawing(){if(this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.aT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.aT),this.aT=null}this.QP=!1,this.BC=null,this.pM(),this._T.onComplete&&this._T.onComplete()}isDrawing(){return this.QP}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new jl(this)}drawToCanvas(t,i,s){if(!this._T.points||0===this._T.points.length)return;const n=this._T.lineColor,e=this.TC||this.kC&&!this.isLocked()?this._T.lineWidth+1:this._T.lineWidth,r=[];for(const t of this._T.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.BC&&this._T.points.length>0){h={ut:(Gn(this._chart,this._series,this.BC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.BC.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._T.showArrowHead&&r.length>1&&this.uT(t,r[r.length-2],r[r.length-1],i,n),this._T.showCircles)for(let s=0;s<r.length;s++)this.cT(t,r[s].ut,r[s].ct,i,n,0===s)}uT(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()}cT(t,i,s,n,e,r){const h=this._T.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._T.lineColor=t,this.pM()}color(){return this._T.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this._T.points||0===this._T.points.length)return!1;for(let s=0;s<this._T.points.length-1;s++)try{const n=this._T.points[s],e=this._T.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.GC(t,i,r,l,h,o)<=8)return!0}catch{continue}for(const s of this._T.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}GC(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._T.points||0===this._T.points.length)return null;for(let s=0;s<this._T.points.length;s++)try{const n=this._T.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.DC=!0,this.oT=t}stopDrag(){this.DC=!1,this.oT=-1}updateDrag(t,i){this.DC&&-1!==this.oT&&this._T.points&&this.oT>=0&&this.oT<this._T.points.length&&(this._T.points[this.oT]={time:t,price:i},this.pM(),this._T.onUpdate&&this._T.onUpdate())}getPoints(){return this._T.points||[]}addPoint(t){this._T.points||(this._T.points=[]),this._T.points.push(t),this.pM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this._T.points||[]).map(t=>Vh(t)),style:{lineColor:this._T.lineColor,lineWidth:this._T.lineWidth,showArrowHead:this._T.showArrowHead,showCircles:this._T.showCircles,circleRadius:this._T.circleRadius}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return!this.QP}remove(){if(this.tx&&(this._chart.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null),this.aT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.aT),this.aT=null}this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this._T.onRemove&&this._T.onRemove()}}function Xl(t,i){return new Yl(t,i)}class Gl{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Kl{constructor(t){this.CC=t,this.Jt=new Gl(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Zl extends Bh{constructor(t,i){super(t,"brush",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.dT=!1,this.QP=!1,this.pT=[],this.fT=!1,this.Rf=null,this.fS=null,this.SS=null,this.CS=null,this.TS=null,this.vT=void 0,this.MS=null,this.DC=!1,this.FC=null,this.lP=null,this.mT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.mT),this.qy(),0===(this.mT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.dT)return;const t=this._chart.chartElement();t&&(this.Rf=t,this.dT=!0,this.SS=t=>this.xS(t),this.CS=t=>this.PS(t),this.TS=()=>this.kS(),this.MS=t=>{this.vT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.MS),t.addEventListener("pointerdown",this.SS,!0),t.addEventListener("pointermove",this.CS,!0),t.addEventListener("pointerup",this.TS,!0),t.addEventListener("pointercancel",this.TS,!0))}stopDrawingMode(){if(!this.dT)return;this.wT(),this.dT=!1;const t=this.Rf;t&&(this.SS&&t.removeEventListener("pointerdown",this.SS,!0),this.CS&&t.removeEventListener("pointermove",this.CS,!0),this.TS&&(t.removeEventListener("pointerup",this.TS,!0),t.removeEventListener("pointercancel",this.TS,!0))),this.MS&&(this._chart.unsubscribeCrosshairMove(this.MS),this.MS=null),this.SS=null,this.CS=null,this.TS=null,this.Rf=null}isDrawingModeActive(){return this.dT}xS(t){if(this.gT())return;const i=this.bT(t,!1);null!==i&&(this.QP=!0,this.pT=[i],this.fS=t.pointerId,Eh(this._chart,!0),this.Rf?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.MT())}PS(t){if(!this.QP)return;const i=this.bT(t,!0);if(null===i)return;const s=this.pT[this.pT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.mT.sampleDistance??4)||(this.pT.push(i),t.preventDefault(),t.stopPropagation(),this.MT())}kS(){this.QP&&this.wT()}wT(){if(!this.QP)return;this.QP=!1,this.US();const t=[];for(const i of this.pT){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.pT=[],t.length<2?this.pM():(this.mT.points=t,this.stopDrawingMode(),this.pM(),this.mT.onUpdate&&this.mT.onUpdate(),this.mT.onComplete&&this.mT.onComplete())}gT(){const t=this.vT;return"string"==typeof t&&t.split("#")[0]!==this.id}US(){null!==this.fS&&(this.Rf&&this.Rf.hasPointerCapture(this.fS)&&this.Rf.releasePointerCapture(this.fS),this.fS=null)}bT(t,i){const s=this.yT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Ax;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}}yT(){const t=this.ST();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,Ax:i.top,ts:n,qt:i.height}}ST(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}MT(){this.fT||(this.fT=!0,requestAnimationFrame(()=>{this.fT=!1,this.pM()}))}drawToCanvas(t,i,s){const n=this.QP?this.pT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.xT(i,s);if(0===n.length)return;const e=this.TC;if(t.strokeStyle=this.mT.color,t.lineWidth=(this.mT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.mT.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.kC||this.isLocked()||(this.XC(t,n[0],i),this.XC(t,n[n.length-1],i))}XC(t,i,s){t.fillStyle=this.mT.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()}xT(t,i){const s=this.mT.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.xT(1,1);for(let n=1;n<s.length;n++)if(Jl(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.DC=!0,this.FC=i,this.lP=(this.mT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.lP;if(!this.DC||null===s||!this.mT.points)return;const n=Dh(this.FC,t,i);this.mT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.pM(),this.mT.onUpdate&&this.mT.onUpdate()}stopDrag(){this.DC=!1,this.FC=null,this.lP=null}setColor(t){this.mT.color=t,this.pM()}color(){return this.mT.color??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}qy(){this.eh=new Kl(this);const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):null}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}remove(){this.stopDrawingMode(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null),this.eh=null,this.mT.onRemove&&this.mT.onRemove()}_serializeShape(){return{type:"brush",points:(this.mT.points??[]).map(Vh),style:{color:this.mT.color,lineWidth:this.mT.lineWidth,smoothing:this.mT.smoothing}}}getPoints(){return this.mT.points??[]}}function Jl(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 Ql(t,i={}){return new Zl(t,i)}class to{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class io{constructor(t){this.CC=t,this.Jt=new to(t)}renderer(){return this.CC.isComplete()?this.Jt:null}}class so extends Bh{constructor(t,i){super(t,"text-tool",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.RC=null,this.FC=null,this.bP=null,this.CT=!1,this.PT=null,this.QC=null,this.TT={text:"Double-click to edit",fontSize:14,fontFamily:"Arial, sans-serif",textColor:"#FFFFFF",backgroundColor:"#2962FF",backgroundOpacity:.8,padding:8,borderColor:"#2962FF",borderWidth:1,textAlign:"left",maxWidth:200,anchor:"top-left",pointer:!1,borderRadius:0,...i},this._registerOptions(this.TT),this.qy(),this.kT(),this.TT.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>{this.setPosition(t.gt,t.bt),this.TT.onComplete&&this.TT.onComplete()}))}kT(){const t=t=>{if(!this.CT)return;const i=t.point?.x||0,s=t.point?.y||0;this.hitTest(i,s)||(this.setEditing(!1),this.TT.text&&""!==this.TT.text.trim()&&"Type here..."!==this.TT.text||this.remove())};this.PT=t,this._chart.subscribeClick(t)}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new io(this)}getTime(){return this.TT.time}getPrice(){return this.TT.price}getText(){return this.TT.text||""}getOptions(){return this.TT}setPosition(t,i){this.TT.time=t,this.TT.price=i,this._update()}setText(t){this.TT.text=t,this._update(),this.TT.onTextChange&&this.TT.onTextChange(t)}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}isComplete(){return!this.QC?.KC()&&!(!this.TT.time||void 0===this.TT.price)}setColor(t){this.TT.textColor=t,this.TT.borderColor=t,this.pM()}color(){return this.TT.textColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this._update())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this._update())}isHovered(){return this.kC}setEditing(t){this.CT!==t&&(this.CT=t,this._update())}isEditing(){return this.CT}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.TT.time,n=this.TT.price,e=Gn(this._chart,this._series,s)??0,r=this._series.priceToCoordinate(n)??0,h=this.TT.fontSize||14,l=this.TT.padding??8,o=this.TT.text||"",a=.6*h,_=Math.min(o.length*a,this.TT.maxWidth||200)+2*l,u=h+2*l,c=this.DT(u),d=this.RT(e,r,_,u,c),p=d.qh-("left"===this.TT.anchor?c:0),f=d.qh+_+("right"===this.TT.anchor?c:0);return t>=p&&t<=f&&i>=d.Ax&&i<=d.Ax+u}DT(t){const i=this.TT.anchor;return!this.TT.pointer||"left"!==i&&"right"!==i?0:Math.round(.35*t)}RT(t,i,s,n,e){switch(this.TT.anchor){case"left":return{qh:t+e,Ax:i-n/2};case"right":return{qh:t-e-s,Ax:i-n/2};case"center":return{qh:t-s/2,Ax:i-n/2};default:return{qh:t,Ax:i}}}FT(t,i,s,n,e,r,h,l,o){const a=Math.max(0,Math.min(o,n/2,e/2));t.beginPath(),t.moveTo(i+a,s),t.lineTo(i+n-a,s),t.arcTo(i+n,s,i+n,s+a,a),r>0&&"right"===this.TT.anchor&&(t.lineTo(i+n,l-r),t.lineTo(h,l),t.lineTo(i+n,l+r)),t.lineTo(i+n,s+e-a),t.arcTo(i+n,s+e,i+n-a,s+e,a),t.lineTo(i+a,s+e),t.arcTo(i,s+e,i,s+e-a,a),r>0&&"left"===this.TT.anchor&&(t.lineTo(i,l+r),t.lineTo(h,l),t.lineTo(i,l-r)),t.lineTo(i,s+a),t.arcTo(i,s,i+a,s,a),t.closePath()}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.TT.time,n=this.TT.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.DC=!0,this.RC=t,this.FC=i,this.bP={gt:this.TT.time,bt:this.TT.price}}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.bP=null}updateDrag(t,i){if(this.DC){if("body"===this.RC&&this.bP){const s=Dh(this.FC,t,i);this.setPosition(this.bP.gt+s.gt,this.bP.bt+s.bt)}else this.setPosition(t,i);this.TT.onUpdate&&this.TT.onUpdate()}}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.TT.time,e=this.TT.price,r=this.TT.text||"",h=(Gn(this._chart,this._series,n)??0)*i,l=(this._series.priceToCoordinate(e)??0)*s,o=(this.TT.fontSize||14)*i,a=(this.TT.padding??8)*i,_=(this.TT.maxWidth||200)*i;t.font=`${o}px ${this.TT.fontFamily||"Arial"}`,t.textBaseline="top";const u=r.split(" "),c=[];let d="";for(const i of u){const s=d?`${d} ${i}`:i;t.measureText(s).width>_&&d?(c.push(d),d=i):d=s}d&&c.push(d);let p=0;for(const i of c){const s=t.measureText(i);p=Math.max(p,s.width)}const f=p+2*a,v=1.2*o,m=c.length*v+2*a,w=this.DT(m),{qh:g,Ax:b}=this.RT(h,l,f,m,w),M=(this.TT.borderRadius??0)*i,y=this.TT.backgroundOpacity??.8,S=this.TT.backgroundColor||"#2962FF";y>0&&(t.fillStyle=this.Ny(S,y),this.FT(t,g,b,f,m,w,h,l,M),t.fill()),(this.TC||this.kC)&&(t.strokeStyle=this.TT.borderColor??"#FFFFFF",t.lineWidth=(this.TT.borderWidth||1)*i*(this.TC?2:1),this.FT(t,g,b,f,m,w,h,l,M),t.stroke()),t.fillStyle=this.TT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=g+a;if("center"===this.TT.textAlign){n=g+(f-t.measureText(s).width)/2}else if("right"===this.TT.textAlign){n=g+f-t.measureText(s).width-a}const e=b+a+i*v;t.fillText(s,n,e)}if((this.TC||this.kC)&&!this.isLocked()){const s=4*i;t.fillStyle=this.TT.textColor??"#2962ff",t.beginPath(),t.arc(h,l,s,0,2*Math.PI),t.fill(),t.fillStyle="#FFFFFF",t.beginPath(),t.arc(h,l,s-2*i,0,2*Math.PI),t.fill()}}Ny(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:[Ih(this.TT.price??0,Fh(this.TT.time))],style:{fontSize:this.TT.fontSize,fontFamily:this.TT.fontFamily,textColor:this.TT.textColor,backgroundColor:this.TT.backgroundColor,backgroundOpacity:this.TT.backgroundOpacity,padding:this.TT.padding,borderColor:this.TT.borderColor,borderWidth:this.TT.borderWidth,textAlign:this.TT.textAlign,maxWidth:this.TT.maxWidth,anchor:this.TT.anchor,pointer:this.TT.pointer,borderRadius:this.TT.borderRadius},extra:{text:this.TT.text}}}remove(){this.QC?.ZC(),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.TT.onRemove&&this.TT.onRemove()}}function no(t,i){return new so(t,i)}class eo{constructor(t){this.IT=t}calculatePips(t,i){return Math.abs(i-t)/this.IT.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.IT={...this.IT,...t}}getPipConfig(){return{...this.IT}}}function ro(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 ho(t,i){return"number"==typeof t?ro(t):void 0!==i?ro(i):{pipValue:.1,decimals:1}}class lo{constructor(t){this.IT=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.IT.pipValue,timeDifference:this.VT(t,s),barCount:e}}VT(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.IT={...this.IT,...t}}getPipConfig(){return{...this.IT}}}class oo{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ao{constructor(t){this.CC=t,this.Jt=new oo(t)}renderer(){return this.CC.isVisible()?this.Jt:null}}class _o extends Bh{constructor(t,i){super(t,"ruler-tool",i),this.jb=null,this.PC=null,this.Gb=null,this.eh=null,this.UP=null,this.LC=!1,this.TC=!1,this.kC=!1,this.BC=null,this.DC=!1,this.qP=null,this.ep=null,this.LT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.LT);const s=this.LT.pipConfig||ho(this.LT.symbol||"DEFAULT");this.YP=new lo(s),this.qy(),this.LT.interactive?this.EC():this.LT.point1Time&&this.LT.point2Time&&(this.LC=!0,this.XP())}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new ao(this)}EC(){this.UP=new Hh(this._chart,this._series,{MC:t=>{this.LT.point1Time=t.gt,this.LT.point1Price=t.bt,this.pM()},yC:t=>{this.LT.point2Time=t.gt,this.LT.point2Price=t.bt},SC:(t,i)=>{this.LT.point1Time=t.gt,this.LT.point1Price=t.bt,this.LT.point2Time=i.gt,this.LT.point2Price=i.bt,this.LC=!0,this.BC=null,this.XP(),this.GP(),this.pM()},xC:t=>{this.BC=t,this.pM()}}),this.UP._C()}drawToCanvas(t,i,s){if(!this.LC&&this.LT.point1Time&&this.BC)return void this.YC(t,i,s);if(!this.LC||!this.LT.point1Time||!this.LT.point2Time)return;const n=(Gn(this._chart,this._series,this.LT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.LT.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.LT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.LT.point2Price)??0)*s;(this.TC||this.kC&&!this.isLocked())&&(t.strokeStyle=this.LT.selectionColor,t.lineWidth=this.LT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.LT.lineColor,t.lineWidth=this.LT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.AT(t,n,e,r,h,i),this.XC(t,n,e,i),this.XC(t,r,h,i),this.LT.showLabel&&this.Gb&&this.nP(t,n,e,r,h,i,s)}AT(t,i,s,n,e,r){const h=this.LT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.LT.lineColor,t.lineWidth=this.LT.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()}XC(t,i,s,n){const e=this.TC?this.LT.selectionColor:this.LT.lineColor,r=this.TC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.TC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}YC(t,i,s){if(!this.LT.point1Time||!this.BC)return;const n=(Gn(this._chart,this._series,this.LT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.LT.point1Price)??0)*s,r=(Gn(this._chart,this._series,this.BC.gt)??0)*i,h=(this._series.priceToCoordinate(this.BC.bt)??0)*s;t.strokeStyle=this.LT.lineColor,t.lineWidth=this.LT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.XC(t,n,e,i),t.globalAlpha=.5,this.XC(t,r,h,i),t.globalAlpha=1}nP(t,i,s,n,e,r,h){if(!this.Gb)return;const l=(i+n)/2,o=(s+e)/2,a=this.LT.measure??"both",_=[];"time"!==a&&(_.push(this.YP.formatPips(this.Gb.pips)),_.push(this.YP.formatPercent(this.Gb.pricePercent))),"price"!==a&&_.push(this.YP.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.LT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.LT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}XP(){if(!this.LT.point1Time||!this.LT.point2Time||void 0===this.LT.point1Price||void 0===this.LT.point2Price)return;const t=this.BT();this.Gb=this.YP.calculateMetrics(this.LT.point1Time,this.LT.point1Price,this.LT.point2Time,this.LT.point2Price,t),this.LT.onUpdate&&this.Gb&&this.LT.onUpdate(this.Gb)}BT(){if(!this.LT.point1Time||!this.LT.point2Time)return 0;const t=Gn(this._chart,this._series,this.LT.point1Time),i=Gn(this._chart,this._series,this.LT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.LT.point1Time=t,this.LT.point1Price=i,this.LT.point2Time=s,this.LT.point2Price=n,this.XP(),this.pM()}getMetrics(){return this.Gb}remove(){this.destroy()}destroy(){this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.UP&&(this.UP.m(),this.UP=null),this.ZP(),this.LT.onRemove&&this.LT.onRemove()}GP(){this.ep=t=>{this.KP(t)},this._chart.subscribeCrosshairMove(this.ep)}ZP(){this.ep&&(this._chart.unsubscribeCrosshairMove(this.ep),this.ep=null)}KP(t){if(!t.point)return;const i=Xn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.TC||!this.DC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.qP?(this.LT.point1Time=i,this.LT.point1Price=s):"point2"===this.qP&&(this.LT.point2Time=i,this.LT.point2Price=s),this.XP(),this.pM())}startDrag(t){this.DC=!0,this.qP=t}stopDrag(){this.DC=!1,this.qP=null}updateDrag(t,i){this.DC&&this.qP&&("point1"===this.qP?(this.LT.point1Time=t,this.LT.point1Price=i):(this.LT.point2Time=t,this.LT.point2Price=i),this.XP(),this.pM())}hitTestEndpoint(t,i){if(!this.LC||!this.LT.point1Time||!this.LT.point2Time)return null;const s=Gn(this._chart,this._series,this.LT.point1Time)??0,n=this._series.priceToCoordinate(this.LT.point1Price)??0,e=Gn(this._chart,this._series,this.LT.point2Time)??0,r=this._series.priceToCoordinate(this.LT.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.PC?.()}_update(){this.XP(),this.pM()}_serializeShape(){return{type:"ruler",points:[Ih(this.LT.point1Price??0,Fh(this.LT.point1Time)),Ih(this.LT.point2Price??0,Fh(this.LT.point2Time))],style:{lineColor:this.LT.lineColor,lineWidth:this.LT.lineWidth,showLabel:this.LT.showLabel,labelBackgroundColor:this.LT.labelBackgroundColor,labelTextColor:this.LT.labelTextColor,selectionColor:this.LT.selectionColor,selectionLineWidth:this.LT.selectionLineWidth},extra:{symbol:this.LT.symbol,pipConfig:this.LT.pipConfig,measure:this.LT.measure}}}setColor(t){this.LT.lineColor=t,this.pM()}color(){return this.LT.lineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}isSelected(){return this.TC}isComplete(){return this.LC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.LC||!this.LT.point1Time||!this.LT.point2Time)return!1;const s=Gn(this._chart,this._series,this.LT.point1Time)??0,n=this._series.priceToCoordinate(this.LT.point1Price)??0,e=Gn(this._chart,this._series,this.LT.point2Time)??0,r=this._series.priceToCoordinate(this.LT.point2Price)??0;return this.OT(t,i,s,n,e,r)<=(this.TC?12:8)}OT(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 uo(t,i){return new _o(t,i)}class co{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class po{constructor(t){this.CC=t,this.Jt=new co(t)}renderer(){return this.CC.isVisible()?this.Jt:null}}class fo extends Bh{constructor(t,i){super(t,"position-tool",i),this.jb=null,this.PC=null,this.Gb=null,this.eh=null,this.TC=!1,this.kC=!1,this.QC=null,this.DC=!1,this.RC=null,this.FC=null,this.bP=null,this.ET=null,this.WT=null,this.zT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.zT);const s=this.zT.pipConfig||ho(this.zT.entryPrice);this.YP=new eo(s),this.qy(),this.XP(),this.zT.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>this.iP(t)))}iP(t){const i=this.zT,s=t.bt-i.entryPrice;i.entryPrice=t.bt,i.entryTime=t.gt,void 0!==i.stopLoss&&(i.stopLoss+=s),void 0!==i.takeProfit&&(i.takeProfit+=s),i.endTime=Xn(this._chart,this._series,Gh(this._chart,t.ut))??void 0,this.XP(),this.pM()}isComplete(){return!this.QC?.KC()}$T(){const t=Gn(this._chart,this._series,this.zT.entryTime)??0;return{HT:t,NT:Gn(this._chart,this._series,this.zT.endTime)??t+Xh(this._chart)}}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new po(this)}drawToCanvas(t,i,s){if(!this.isComplete())return;if(this.ET&&this.zT.takeProfit){const n=this._chart.timeScale();this.UT(t,this.ET,i,s,n),(this.kC||this.TC)&&this.nP(t,this.ET,"profit",i,s,n)}if(this.WT&&this.zT.stopLoss){const n=this._chart.timeScale();if(this.UT(t,this.WT,i,s,n),this.kC||this.TC){const n=this._chart.timeScale();this.nP(t,this.WT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.qT(t,i,s,n),this.zT.takeProfit){const n=this._chart.timeScale();this.XC(t,this.zT.takeProfit,this.zT.profitColor,i,s,n)}if(this.zT.stopLoss){const n=this._chart.timeScale();this.XC(t,this.zT.stopLoss,this.zT.lossColor,i,s,n)}}UT(t,i,s,n,e){const r=this.$T(),h=r.HT*s,l=r.NT*s,o=(this._series.priceToCoordinate(i.jT)??0)*n,a=(this._series.priceToCoordinate(i.YT)??0)*n;t.fillStyle=this.Ny(i.R,.15),t.fillRect(h,Math.min(o,a),l-h,Math.abs(a-o)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(h,a),t.lineTo(l,a),t.stroke()}qT(t,i,s,n){const e=this.$T(),r=e.HT*i,h=e.NT*i,l=(this._series.priceToCoordinate(this.zT.entryPrice)??0)*s,o=this.zT.entryLineColor;t.strokeStyle=o,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(r,l),t.lineTo(h,l),t.stroke(),t.setLineDash([]),t.strokeStyle=this.zT.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(r,0),t.lineTo(r,a),t.stroke(),t.setLineDash([]),!this.TC&&!this.kC||this.isLocked())t.fillStyle=this.zT.entryLineColor,t.beginPath(),t.arc(r,l,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(r,l,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(h-s/2,l-s/2,s,s),t.strokeRect(h-s/2,l-s/2,s,s)}}XP(){this.zT.stopLoss&&this.zT.takeProfit&&(this.Gb=this.YP.calculateMetrics(this.zT.entryPrice,this.zT.stopLoss,this.zT.takeProfit,this.zT.quantity),this.XT(),this.zT.onUpdate&&this.Gb&&this.zT.onUpdate(this.Gb))}XT(){const t=this.GT();this.zT.takeProfit&&(this.ET={KT:this.zT.entryTime,ZT:t,jT:this.zT.entryPrice,YT:this.zT.takeProfit,R:this.zT.profitColor,Vy:this.zT.opacity}),this.zT.stopLoss&&(this.WT={KT:this.zT.entryTime,ZT:t,jT:this.zT.entryPrice,YT:this.zT.stopLoss,R:this.zT.lossColor,Vy:this.zT.opacity})}GT(){this._chart.timeScale().getVisibleLogicalRange();return this.zT.entryTime}nP(t,i,s,n,e,r){if(!this.Gb)return;const h=(Gn(this._chart,this._series,this.zT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.YT)??0)*e,o="profit"===s,a=o?this.Gb.takeProfitPips:this.Gb.stopLossPips,_=o?this.zT.takeProfit:this.zT.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=3*e,m=h+8*n,w=l<=(this._series.priceToCoordinate(this.zT.entryPrice)??0)*e?l-f-v:l+v;t.fillStyle=i.R,t.fillRect(m,w,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,m+d,w+f/2)}XC(t,i,s,n,e,r){const h=this.$T(),l=h.HT*n,o=h.NT*n,a=(this._series.priceToCoordinate(i)??0)*e,_=s;t.fillStyle=_,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(l,a,5*n,0,2*Math.PI),t.fill(),t.stroke();const u=8*n,c=s;t.fillStyle=c,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-u/2,a-u/2,u,u),t.strokeRect(o-u/2,a-u/2,u,u)}Ny(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.zT={...this.zT,...t},this.XP(),this._update()}getMetrics(){return this.Gb}setStopLoss(t){this.zT.stopLoss=t,this.XP(),this._update()}setTakeProfit(t){this.zT.takeProfit=t,this.XP(),this._update()}setEntryPrice(t){this.zT.entryPrice=t,this.XP(),this._update()}_serializeShape(){return{type:"position",points:[Ih(this.zT.entryPrice,Fh(this.zT.entryTime))],style:{profitColor:this.zT.profitColor,lossColor:this.zT.lossColor,entryLineColor:this.zT.entryLineColor,opacity:this.zT.opacity,showTooltips:this.zT.showTooltips},extra:{endTime:Fh(this.zT.endTime),stopLoss:this.zT.stopLoss,takeProfit:this.zT.takeProfit,quantity:this.zT.quantity,pipConfig:this.zT.pipConfig}}}setColor(t){this.zT.entryLineColor=t,this.pM()}color(){return this.zT.entryLineColor??""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):this.hitTest(t,i)?kh(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||!this.zT.stopLoss&&!this.zT.takeProfit)return!1;const{HT:s,NT:n}=this.$T(),e=Math.min(s,n),r=Math.max(s,n);if(this.zT.takeProfit&&this.zT.stopLoss){const n=this._series.priceToCoordinate(this.zT.takeProfit)??0,h=this._series.priceToCoordinate(this.zT.stopLoss)??0,l=Math.min(n,h),o=Math.max(n,h);if(t>=e&&t<=r&&i>=l&&i<=o)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=l&&i<=o)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const{HT:s,NT:n}=this.$T(),e=Math.min(s,n),r=Math.max(s,n);if(this.zT.takeProfit){const n=this._series.priceToCoordinate(this.zT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.zT.stopLoss){const n=this._series.priceToCoordinate(this.zT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.zT.takeProfit){const s=this._series.priceToCoordinate(this.zT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.zT.stopLoss){const s=this._series.priceToCoordinate(this.zT.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const h=this._series.priceToCoordinate(this.zT.entryPrice)??0;if(t>=e&&t<=r&&Math.abs(i-h)<=8)return"entry";if(this.zT.takeProfit&&this.zT.stopLoss){const s=this._series.priceToCoordinate(this.zT.takeProfit)??0,n=this._series.priceToCoordinate(this.zT.stopLoss)??0,h=Math.min(s,n),l=Math.max(s,n);if(t>=e&&t<=r&&i>=h&&i<=l)return"move"}return null}startDrag(t,i){this.DC=!0,this.RC=t,this.FC=i,"move"===t&&(this.bP={JT:this.zT.entryPrice,QT:this.zT.entryTime??null,Hy:this.zT.endTime??null,tk:this.zT.takeProfit??null,ik:this.zT.stopLoss??null})}stopDrag(){this.DC=!1,this.RC=null,this.FC=null,this.bP=null}updateDrag(t,i){if(this.DC&&this.RC){if("entry"===this.RC)this.zT.entryPrice=i;else if("move"===this.RC){if(this.bP){const s=Dh(this.FC,t,i),n=this.bP;this.zT.entryPrice=n.JT+s.bt,null!==n.tk&&(this.zT.takeProfit=n.tk+s.bt),null!==n.ik&&(this.zT.stopLoss=n.ik+s.bt),null!==n.QT&&(this.zT.entryTime=this.sk(n.QT,s.gt)),null!==n.Hy&&(this.zT.endTime=this.sk(n.Hy,s.gt))}}else"tp"===this.RC||"tp-right"===this.RC?(this.zT.takeProfit=i,"tp-right"===this.RC?this.zT.endTime=t:this.zT.entryTime=t):"sl"!==this.RC&&"sl-right"!==this.RC||(this.zT.stopLoss=i,"sl-right"===this.RC?this.zT.endTime=t:this.zT.entryTime=t);this.XP(),this.pM()}}sk(t,i){return t+i}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}remove(){this.QC?.ZC(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.zT.onRemove&&this.zT.onRemove()}}function vo(t,i){return new fo(t,i)}class mo{constructor(t){this.CC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.CC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wo{constructor(t){this.CC=t,this.Jt=new mo(t)}renderer(){return this.CC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class go extends Bh{constructor(t,i){super(t,"gantt",i),this.jb=null,this.PC=null,this.eh=null,this.TC=!1,this.kC=!1,this.DC=!1,this.nk=-1,this.FC=null,this.bP=null,this.ek=-1,this.QC=null,this.rk={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this.rk),this.qy(),this.rk.interactive&&(this.QC=Yh(this._chart,this._series,1,t=>this.iP(t)))}iP(t){const i=this.rk.segments??[],s=Xn(this._chart,this._series,Gh(this._chart,t.ut))??t.gt,n=this.rk.rowHeight+this.rk.rowSpacing,e=Math.max(0,Math.floor((t.ct-50)/n)),r=i.length>0?e-i[0].level:0;for(const n of i)n.startTime=t.gt,n.endTime=s,n.level=Math.max(0,n.level+r);this.pM()}isComplete(){return!this.QC?.KC()}selectionBox(){const t=this.rk.segments??[];if(0===t.length)return null;const i=this.rk.rowHeight,s=i+this.rk.rowSpacing,n={left:1/0,top:1/0,right:-1/0,bottom:-1/0};for(const e of t){const t=50+e.level*s;n.left=Math.min(n.left,Gn(this._chart,this._series,e.startTime)??0),n.right=Math.max(n.right,Gn(this._chart,this._series,e.endTime)??0),n.top=Math.min(n.top,t),n.bottom=Math.max(n.bottom,t+i)}return n}qy(){this.eh=this.WC();const t={attached:t=>{this.PC=t.requestUpdate},detached:()=>{this.PC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.zC(t,i)};this.jb=t,this._series.attachPrimitive(t),this.pM()}WC(){return new wo(this)}drawToCanvas(t,i,s){if(!this.isComplete()||!this.rk.segments||0===this.rk.segments.length)return;const n=50*s,e=this.rk.rowHeight*s,r=this.rk.rowSpacing*s;this.rk.showGrid&&this.rm(t,n,e,r,i,s),this.rk.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.ek||this.kC&&!this.isLocked();this.hk(t,l,o,a,e,s,_,i)})}rm(t,i,s,n,e,r){if(!this.rk.segments)return;const h=Math.max(...this.rk.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()}}hk(t,i,s,n,e,r,h,l){const o=s-i,a=this.Ny(r.color,h?this.rk.fillOpacity+.2:this.rk.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this.rk.borderWidth+(this.TC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this.rk.showLabels&&r.label&&this.nP(t,i,n,o,e,r.label,l)}nP(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)}Ny(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.rk.segments||(this.rk.segments=[]),this.rk.segments.push(t),this.pM(),this.rk.onUpdate&&this.rk.onUpdate()}removeSegment(t){this.rk.segments&&t>=0&&t<this.rk.segments.length&&(this.rk.segments.splice(t,1),this.pM(),this.rk.onUpdate&&this.rk.onUpdate())}getSegments(){return this.rk.segments||[]}setColor(t){const i=this.rk.segments??[];for(const s of i)s.color=t;this.pM()}color(){const t=this.rk.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.TC!==t&&(this.TC=t,this.pM())}isSelected(){return this.TC}setHovered(t){this.kC!==t&&(this.kC=t,this.pM())}isHovered(){return this.kC}zC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?kh(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this.rk.segments?.[this.ek];s&&(this.DC=!0,this.nk=this.ek,this.FC=i,this.bP={$y:s.startTime,Hy:s.endTime})}updateDrag(t,i){const s=this.rk.segments?.[this.nk];if(!this.DC||!this.bP||!s)return;const n=Dh(this.FC,t,i);s.startTime=this.bP.$y+n.gt,s.endTime=this.bP.Hy+n.gt,this.pM(),this.rk.onUpdate&&this.rk.onUpdate()}stopDrag(){this.DC=!1,this.nk=-1,this.FC=null,this.bP=null}hitTest(t,i){if(!this.isComplete()||!this.rk.segments||0===this.rk.segments.length)return!1;const s=this.rk.rowHeight,n=this.rk.rowSpacing;for(let e=0;e<this.rk.segments.length;e++){const r=this.rk.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.ek=e,!0}return this.ek=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this.rk.rowHeight,rowSpacing:this.rk.rowSpacing,fillOpacity:this.rk.fillOpacity,borderWidth:this.rk.borderWidth,showLabels:this.rk.showLabels,showGrid:this.rk.showGrid},extra:{segments:(this.rk.segments||[]).map(t=>({$y:Fh(t.startTime),Hy:Fh(t.endTime),sn:t.level,Jl:t.label,R:t.color,lk:t.category}))}}}pM(){this.jb&&this.jb.updateAllViews?.(),this.PC?.()}_update(){this.pM()}remove(){this.QC?.ZC(),this.jb&&(this._series.detachPrimitive(this.jb),this.jb=null,this.eh=null),this.rk.onRemove&&this.rk.onRemove()}}function bo(t,i){return new go(t,i)}class Mo{constructor(t,i,s={}){this.ak=[],this._k=[],this.uk=[],this.ck=!1,this.dk=new Map,this.pk=null,this.fk=null,this.vk=null,this.tx=null,this.mk=null,this.ep=null,this.wk=null,this.gk=null,this.bk=null,this.Mk=null,this.yk=null,this.Sk=null,this.fS=null,this.xk=!1,this.Ck=null,this.Pk=null,this.Tk=new a,this.DC=!1,this.kk=null,this.Dk=new Set,this.Rk=null,this.Fk=new a,this.Lf=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Ik()}startDrawing(t){this.vk=t,this.Vk()}activeDrawingType(){return this.vk}stopDrawing(){this.vk=null}addTool(t,i){const s=i??t.id;return this.dk.set(s,t),t.isComplete()||this.Dk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Dk.size>0}cancelPendingDrawings(){if(0===this.Dk.size)return 0;let t=0;for(const i of Array.from(this.Dk)){const s=this.dk.get(i);s&&(this.pk===i&&this.Lk(null),s.remove(),this.dk.delete(i),t++)}return this.Dk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Fk.i(t)}unsubscribeDrawingCompleted(t){this.Fk._(t)}Ak(){0!==this.Dk.size&&null===this.Rk&&(this.Rk=setTimeout(()=>{this.Rk=null;const t=[];for(const i of Array.from(this.Dk)){const s=this.dk.get(i);s?s.isComplete()&&(this.Dk.delete(i),t.push(i)):this.Dk.delete(i)}t.length>0&&this.recordChange();for(const i of t)this.Fk.p(i)},0))}removeTool(t){const i=this.dk.get(t);return!!i&&(this.pk===t&&this.Lk(null),i.remove(),this.dk.delete(t),this.Dk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.dk.has(t)&&(this.Lk(t),!0)}Lk(t){if(this.pk===t)return;const i=null===this.pk?void 0:this.dk.get(this.pk);i&&i.setSelected(!1),this.pk=t;const s=null===t?void 0:this.dk.get(t);s&&s.setSelected(!0),this.Bk()}recordChange(){if(this.ck)return;const t=this.serializeAll();JSON.stringify(t)!==JSON.stringify(this.uk)&&(this.ak.push(this.uk),this.ak.length>100&&this.ak.shift(),this._k=[],this.uk=t)}canUndo(){return this.ak.length>0}canRedo(){return this._k.length>0}undo(){const t=this.ak.pop();return void 0!==t&&(this._k.push(this.uk),this.Ok(t),!0)}redo(){const t=this._k.pop();return void 0!==t&&(this.ak.push(this.uk),this.Ok(t),!0)}Ok(t){this.ck=!0;try{this.restoreAll({chart:this.Lf,series:this.be},t,!0),this.uk=t}finally{this.ck=!1}}subscribeSelectionChanged(t){this.Tk.i(t)}unsubscribeSelectionChanged(t){this.Tk._(t)}selectionBounds(){if(null===this.pk)return null;const t=this.dk.get(this.pk);return t?this.Ek(t):null}Ek(t){const i=t.selectionBox()??this.Wk(t);if(null===i)return null;const s=this.zk(t);return{left:i.left+s.ut,right:i.right+s.ut,top:i.top+s.ct,bottom:i.bottom+s.ct}}Wk(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=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))}return l?{left:n,top:e,right:r,bottom:h}:null}zk(t){const i=this.Lf.chartElement(),s=this.jS(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}}Bk(){this.Tk.p({id:this.pk,bounds:this.selectionBounds()})}deselectAll(){this.Vk()}deleteSelected(){if(this.pk){const t=this.dk.get(this.pk);return(!t||!t.isLocked())&&this.removeTool(this.pk)}return!1}getSelectedToolId(){return this.pk}getAllTools(){return new Map(this.dk)}getTool(t){return this.dk.get(t)}clearAll(){this.Lk(null),this.dk.forEach(t=>t.remove()),this.dk.clear(),this.Dk.clear(),this.recordChange()}getToolCount(){return this.dk.size}isToolSelected(t){return this.pk===t}serializeAll(){const t=[];for(const i of this.dk.values())i.isComplete()&&t.push(i.serialize());return t}restoreTool(t,i){const s=Mo.$k(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 $k(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({Hk:Lh(n[t]),Nk:Ah(n[t],"price")??0});switch(s){case"trendLine":return jh(t,{point1Time:h(0).Hk,point1Price:h(0).Nk,point2Time:h(1).Hk,point2Price:h(1).Nk,...e});case"horizontalLine":return Qh(t,{price:h(0).Nk,startTime:h(0).Hk??void 0,...e});case"parallelChannel":return ul(t,{point1Time:h(0).Hk,point1Price:h(0).Nk,point2Time:h(1).Hk,point2Price:h(1).Nk,channelWidth:r?.channelWidth,...e});case"pitchfork":return fl(t,{pivotTime:h(0).Hk,pivotPrice:h(0).Nk,upperTime:h(1).Hk,upperPrice:h(1).Nk,lowerTime:h(2).Hk,lowerPrice:h(2).Nk,...e});case"polygon":return ll(t,{points:n.map((t,i)=>{const s={};return s.time=h(i).Hk,s.price=h(i).Nk,s}),...e});case"crossLine":return nl(t,{time:h(0).Hk,price:h(0).Nk,...e});case"verticalLine":return gl(t,{time:h(0).Hk,...e});case"fibRetracement":return Tl(t,{point1Time:h(0).Hk,point1Price:h(0).Nk,point2Time:h(1).Hk,point2Price:h(1).Nk,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return Fl(t,{point1:i.Hk?{time:i.Hk,price:i.Nk}:void 0,point2:s.Hk?{time:s.Hk,price:s.Nk}:void 0,point3:n.Hk?{time:n.Hk,price:n.Nk}:void 0,levels:r?.levels,...e})}case"fibFan":return Bl(t,{point1Time:h(0).Hk,point1Price:h(0).Nk,point2Time:h(1).Hk,point2Price:h(1).Nk,levels:r?.levels,...e});case"rectangle":return zl(t,{time1:h(0).Hk,price1:h(0).Nk,time2:h(1).Hk,price2:h(1).Nk,...e});case"circle":return Ul(t,{centerTime:h(0).Hk,centerPrice:h(0).Nk,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Xl(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"brush":return Ql(t,{points:n.map(t=>({gt:t.time,bt:t.price})),...e});case"text":return no(t,{time:h(0).Hk,price:h(0).Nk,text:r?.text,...e});case"ruler":return uo(t,{point1Time:h(0).Hk,point1Price:h(0).Nk,point2Time:h(1).Hk,point2Price:h(1).Nk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return vo(t,{entryPrice:h(0).Nk,entryTime:h(0).Hk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return bo(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.Rk&&(clearTimeout(this.Rk),this.Rk=null),this.Fk.m(),this.Tk.m(),this.clearAll(),this.Uk(),this.ak=[],this._k=[],this.uk=[]}Ik(){this.tx=t=>{this.gC(t)},this.Lf.subscribeClick(this.tx),this.ep=t=>{this.bC(t)},this.Lf.subscribeCrosshairMove(this.ep);const t=this.Lf.chartElement();t&&(this.wk=t=>this.qk(t),this.gk=t=>this.jk(t),this.bk=t=>this.Yk(t),this.Mk=t=>this.jk(t),this.yk=t=>this.Xk(t),t.addEventListener("pointerdown",this.wk),t.addEventListener("pointerup",this.gk),t.addEventListener("pointermove",this.bk),t.addEventListener("pointercancel",this.Mk),t.addEventListener("lostpointercapture",this.yk)),us&&(this.Sk=t=>this.jk(t),window.addEventListener("pointerup",this.Sk)),this.Ps.enableKeyboardShortcuts&&(this.mk=t=>{this.Gk(t)},document.addEventListener("keydown",this.mk))}Uk(){this.tx&&(this.Lf.unsubscribeClick(this.tx),this.tx=null),this.ep&&(this.Lf.unsubscribeCrosshairMove(this.ep),this.ep=null);const t=this.Lf.chartElement();t&&(this.wk&&(t.removeEventListener("pointerdown",this.wk),this.wk=null),this.gk&&(t.removeEventListener("pointerup",this.gk),this.gk=null),this.bk&&(t.removeEventListener("pointermove",this.bk),this.bk=null),this.Mk&&(t.removeEventListener("pointercancel",this.Mk),this.Mk=null),this.yk&&(t.removeEventListener("lostpointercapture",this.yk),this.yk=null)),this.Sk&&(window.removeEventListener("pointerup",this.Sk),this.Sk=null),this.mk&&(document.removeEventListener("keydown",this.mk),this.mk=null)}gC(t){if(this.Ak(),!t.point)return;if(this.xk)return void(this.xk=!1);if(this.DC)return;const i=this.Kk(t.hoveredObjectId);i?this.selectTool(i):this.Vk()}bC(t){if(this.Ck=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.DC&&this.kk){const i=this.dk.get(this.kk);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.Kk(t.hoveredObjectId);if(this.fk&&this.fk!==i){const t=this.dk.get(this.fk);t&&t.setHovered(!1)}if(i){const t=this.dk.get(i);t&&t.setHovered(!0)}this.fk=i}Kk(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.dk)if(s.id===i)return t;return null}qk(t){if(this.DC)return;Eh(this.Lf,!1);const i=this.Lf.chartElement();if(!i)return;const s=null!==this.fk&&null!==this.Ck?{Zk:this.fk,Rw:this.Ck}:this.Jk(t);if(null===s)return;const{Zk:n,Rw:e}=s,r=this.dk.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.Qk(r,e.ut,e.ct);if(null!==h&&null!==l){Eh(this.Lf,!0),this.selectTool(n),this.DC=!0,this.xk=!0,this.kk=n,this.fS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.fS=null}r.startDrag(h,l),this.tD()}}Yk(t){if(!this.DC||null===this.kk||"mouse"===t.pointerType)return;if(null!==this.fS&&t.pointerId!==this.fS)return;const i=this.dk.get(this.kk);if(!i)return;const s=this.jS(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())}jk(t){if(!this.DC||null===this.kk)return;if(t&&null!==this.fS&&t.pointerId!==this.fS)return;const i=this.kk;this.DC=!1,this.kk=null;try{const t=this.dk.get(i);t&&t.stopDrag()}finally{this.US(),this.iD()}this.recordChange()}Xk(t){null!==this.fS&&t.pointerId!==this.fS||(this.fS=null,this.jk())}jS(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}Jk(t){for(const[i,s]of this.dk){if(!s.isVisible()||s.isLocked())continue;const n=this.jS(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{Zk:i,Rw:r}}return null}US(){if(null===this.fS)return;const t=this.Lf.chartElement();t&&t.hasPointerCapture(this.fS)&&t.releasePointerCapture(this.fS),this.fS=null}tD(){if(null!==this.Pk)return;const t=this.Lf.options();this.Pk={sD:f(t.handleScroll),nD:f(t.handleScale)},this.Lf.applyOptions({handleScroll:!1,handleScale:!1})}iD(){const t=this.Pk;this.Pk=null,null!==t&&this.Lf.applyOptions({handleScroll:t.sD,handleScale:t.nD})}Gk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Ak(),"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.jk(),this.Vk(),this.stopDrawing(),t.preventDefault())}Qk(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Xn(this.Lf,t.series(),i)}}Vk(){this.Lk(null)}}const yo={...t,color:"#2196f3"};var So=Object.freeze({__proto__:null,AreaSeries:xe,ArrowTool:Yl,BarSeries:ke,BaselineSeries:Me,BrushTool:Zl,CandlestickSeries:Fe,CircleTool:Nl,get ColorType(){return Li},CrossLineTool:sl,get CrosshairMode(){return U},DEFAULT_SESSIONS:th,DraggablePriceLine:_h,DrawingToolsManager:Mo,EXTENDED_FIBONACCI_RATIOS:Ml,FibonacciCalculator:yl,FibonacciExtensionTool:Rl,FibonacciFanTool:Al,FibonacciTool:Pl,GanttTool:go,HistogramSeries:Le,HorizontalLineTool:Jh,InteractiveLineManager:uh,get LastPriceAnimationMode(){return Ii},LineSeries:he,get LineStyle(){return s},get LineType(){return i},get MismatchDirection(){return xt},ParallelChannelTool:_l,PitchforkTool:pl,PolygonTool:hl,PositionCalculator:eo,PositionLine:Ch,PositionMarkersManager:Ir,PositionTool:fo,get PriceLineSource(){return Vi},get PriceScaleMode(){return di},RectangleTool:Wl,RulerCalculator:lo,RulerTool:_o,STANDARD_FIBONACCI_RATIOS:bl,TextTool:so,get TickMarkType(){return Ai},get TrackingModeExitMode(){return Fi},TradingSessionsIndicator:ih,TrendLineTool:qh,VerticalLineTool:wl,VolumeProfileIndicator:eh,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=zr(0,100),h=i.addSeries(he,{color:n.colorADX,autoscaleInfoProvider:r},e),l=$r(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 _=Nr(h,n.levelColor),u=qr({r_:t,Xf:i,Cy:[h,o,a],Jl:"ADX",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{eD:[],rD:[],hD:[]};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{eD:o,rD:a,hD:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.eD],[o,n?s.rD:[]],[a,n?s.hD:[]]]},Ty: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=qr({r_:t,Xf:i,Cy:[e],Jl:"ATR",W:n,ky:["period"],Py:(t,i)=>[[e,r(t,i.period??14)]],Ty: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=qr({r_:t,Xf:i,Cy:[r,h,l],Jl:"Bollinger Bands",W:n,ky:["period","stdDev"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{AP:[],lD:[],BP:[]};const n=[];for(const i of t)"close"in i?n.push(i.close):"value"in i?n.push(i.value):n.push(0);const e=[],r=[],h=[];for(let l=i-1;l<n.length;l++){let o=0;for(let t=0;t<i;t++)o+=n[l-t];const a=o/i;let _=0;for(let t=0;t<i;t++)_+=Math.pow(n[l-t]-a,2);const u=Math.sqrt(_/i),c=a+u*s,d=a-u*s;if(t[l]&&t[l].time){const i=t[l].time;e.push({time:i,value:c}),r.push({time:i,value:a}),h.push({time:i,value:d})}}return{AP:e,lD:r,BP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.AP],[h,s.lD],[l,s.BP]]},Ty: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=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(const i of t)"high"in i&&"low"in i&&"close"in i?s.push((i.high+i.low+i.close)/3):s.push("value"in i?i.value:0);const n=[];for(let e=i-1;e<s.length;e++){let r=0;for(let t=0;t<i;t++)r+=s[e-t];const h=r/i;let l=0;for(let t=0;t<i;t++)l+=Math.abs(s[e-t]-h);const o=l/i,a=0===o?0:(s[e]-h)/(.015*o);t[e]&&void 0!==t[e].time&&n.push({time:t[e].time,value:a})}return n},a=qr({r_:t,Xf:i,Cy:[r],Jl:"CCI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??20)]],Ty: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=qr({r_:t,Xf:i,Cy:[r,h,l],Jl:"Donchian Channels",W:n,ky:["period"],Py:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{AP:[],lD:[],BP:[]};const s=[],n=[],e=[];for(let r=i-1;r<t.length;r++){let h=-1/0,l=1/0;for(let s=0;s<i;s++){const i=t[r-s],n="high"in i?i.high:i.value,e="low"in i?i.low:i.value;n>h&&(h=n),e<l&&(l=e)}const o=t[r];void 0!==o.time&&h!==-1/0&&l!==1/0&&(s.push({time:o.time,value:h}),e.push({time:o.time,value:l}),n.push({time:o.time,value:(h+l)/2}))}return{AP:s,lD:n,BP:e}})(t,i.period??20);return[[r,s.AP],[h,s.lD],[l,s.BP]]},Ty: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=Hr(t,s),e=[],r=2/(i+1);let h=0;for(let t=0;t<i;t++)h+=n[t];h/=i,t[i-1]&&t[i-1].time&&e.push({time:t[i-1].time,value:h});for(let s=i;s<n.length;s++)h=(n[s]-h)*r+h,t[s]&&t[s].time&&e.push({time:t[s].time,value:h});return e},h=qr({r_:t,Xf:i,Cy:[e],Jl:"EMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Ty: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=Er(t),r.setSeriesOrder(t.seriesOrder())):i||null===h||(h(),h=null,r.setSeriesOrder(t.seriesOrder()+1))},o=qr({r_:t,Xf:i,Cy:[r],Jl:"Heikin Ashi",W:n,ky:[],Py:t=>[[r,Zr(t)]],Ty: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{series: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 Xr(i,t,()=>u,()=>({Oy:c.cloudBullishColor??"#089981",Ey:c.cloudBearishColor??"#F23645",Vy:c.cloudOpacity??.15,It:c.showCloud??!0})),p={attached:t=>{},detached:()=>{},paneViews:()=>[d],updateAllViews:()=>{}};t.attachPrimitive(p);const f=(t,i)=>{const s=i.conversionPeriod??9,n=i.basePeriod??26,e=i.spanBPeriod??52,r=i.displacement??26,h=[],l=[],o=[],a=[],_=[],u=[];if(!t||t.length<e)return{oD:h,rh:l,Ly:o,Ay:a,aD:_,_D: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=Gr(t,i,s),u=Gr(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=Gr(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,Ly:s,Ay:n};u.push(t)}}return{oD:h,rh:l,Ly:o,Ay:a,aD:_,_D:u}},v=qr({r_:t,Xf:i,Cy:[h,l,o,a,_],Jl:"Ichimoku",W:n,ky:["conversionPeriod","basePeriod","spanBPeriod","displacement"],Py:(t,i)=>{c=i;const s=f(t,i);return u=s._D,[[h,s.oD],[l,s.rh],[o,s.Ly],[a,s.Ay],[_,i.showLagging??1?s.aD:[]]]},Ty: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=qr({r_:t,Xf:i,Cy:[r,h,l],Jl:"Keltner Channels",W:n,ky:["period","atrPeriod","multiplier","source"],Py:(t,i)=>{const s=((t,i)=>{const s=i.period??20,n=i.atrPeriod??10,e=i.multiplier??2;if(!t||t.length<Math.max(s,n+1))return{AP:[],lD:[],BP:[]};const r=Hr(t,i.source??"close"),h=[],l=2/(s+1);let o=0;for(let t=0;t<s;t++)o+=r[t];h.push(o/s);for(let t=s;t<r.length;t++)h.push((r[t]-h[h.length-1])*l+h[h.length-1]);const a=[];for(let i=1;i<t.length;i++){const s=t[i],n=t[i-1];"high"in s&&"low"in s&&"close"in n?a.push(Math.max(s.high-s.low,Math.abs(s.high-n.close),Math.abs(s.low-n.close))):a.push(0)}const _=[];let u=0;for(let t=0;t<n;t++)u+=a[t];_[n-1]=u/n;for(let t=n;t<a.length;t++)_[t]=(_[t-1]*(n-1)+a[t])/n;const c=[],d=[],p=[];for(let i=0;i<h.length;i++){const n=s-1+i,r=t[n],l=_[n-1];if(!r||void 0===r.time||void 0===l)continue;const o=h[i],a=l*e;d.push({time:r.time,value:o}),c.push({time:r.time,value:o+a}),p.push({time:r.time,value:o-a})}return{AP:c,lD:d,BP:p}})(t,i);return[[r,s.AP],[h,s.lD],[l,s.BP]]},Ty: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=$r(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},_=qr({r_:t,Xf:i,Cy:[r,l,o],Jl:"MACD",W:n,ky:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],Py:(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{uD:[],cD:[],dD:[]};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{uD:c,cD:d,dD:p}})(t,i);return[[r,s.uD],[l,s.cD],[o,s.dD]]},Ty: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:zr(0,100)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!Br(t))return[];const n=[],e=[];for(let s=1;s<i.length;s++){const r=i[s],h=i[s-1];if(!("high"in r)||!("low"in r)||!("close"in r)){n.push(0),e.push(0);continue}const l=(r.high+r.low+r.close)/3,o=(h.high+h.low+h.close)/3,a=l*(Ar(t,r.time)??0);n.push(l>o?a:0),e.push(l<o?a:0)}const r=[];for(let t=s-1;t<n.length;t++){let h=0,l=0;for(let i=0;i<s;i++)h+=n[t-i],l+=e[t-i];const o=0===l?100:100-100/(1+h/l),a=i[t+1];a&&void 0!==a.time&&r.push({time:a.time,value:o})}return r},a=qr({r_:t,Xf:i,Cy:[r],Jl:"MFI",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty: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||!Br(t))return[];const s=[];let n=0;s.push({time:i[0].time,value:n});for(let e=1;e<i.length;e++){const r=i[e],h=i[e-1],l=Ar(t,r.time);l&&"close"in r&&"close"in h&&(r.close>h.close?n+=l:r.close<h.close&&(n-=l),s.push({time:r.time,value:n}))}return s},h=qr({r_:t,Xf:i,Cy:[e],Jl:"OBV",W:n,Py:()=>[[e,r()]],Ty: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=qr({r_:t,Xf:i,Cy:[e],Jl:"Parabolic SAR",W:n,ky:["step","maxStep","colorUp","colorDown"],Py:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty: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=qr({r_:t,Xf:i,Cy:[h,...l,...o],Jl:"Pivot Points",W:n,ky:["pivotPeriod"],Py:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{VP:s,pD:n,fD:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=jr(_.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={vD:i,mD:[2*i-l,i+s,h+2*(i-l)],wD:[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.vD});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.mD[t]}),e[t].push({time:_.time,value:a.wD[t]})}}return{VP:s,pD:n,fD:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.VP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.pD[t]:[]]),e.push([o[t],t<n?s.fD[t]:[]]);return e},Ty: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:zr(0,100)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=Nr(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Hr(t,s),e=[],r=[];for(let t=1;t<n.length;t++)r.push(n[t]-n[t-1]);let h=0,l=0;for(let t=0;t<i;t++)r[t]>0?h+=r[t]:l+=Math.abs(r[t]);h/=i,l/=i;let o=0===l?100:h/l,a=100-100/(1+o);t[i]&&t[i].time&&e.push({time:t[i].time,value:a});for(let s=i;s<r.length;s++){const n=r[s];h=(h*(i-1)+(n>0?n:0))/i,l=(l*(i-1)+(n<0?Math.abs(n):0))/i,o=0===l?100:h/l,a=100-100/(1+o),t[s+1]&&t[s+1].time&&e.push({time:t[s+1].time,value:a})}return e},a=qr({r_:t,Xf:i,Cy:[r],Jl:"RSI",W:n,ky:["period","source"],Py:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],Ty: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=Hr(t,s),e=[];for(let s=i-1;s<n.length;s++){let r=0;for(let t=0;t<i;t++)r+=n[s-t];const h=r/i;t[s]&&t[s].time&&e.push({time:t[s].time,value:h})}return e},h=qr({r_:t,Xf:i,Cy:[e],Jl:"SMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty: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=zr(0,100),h=i.addSeries(he,{color:n.colorK,autoscaleInfoProvider:r},e),l=$r(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=Nr(h,n.levelColor),_=qr({r_:t,Xf:i,Cy:[h,o],Jl:"Stochastic",W:n,ky:["kPeriod","dPeriod"],Py:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{gD:[],bD:[]};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{gD:e,bD:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.gD],[o,s.bD]]},Ty: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=qr({r_:t,Xf:i,Cy:[e],Jl:"SuperTrend",ky:["period","multiplier","colorUp","colorDown"],W:n,Py:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Ty: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=qr({r_:t,Xf:i,Cy:[r,h,l],Jl:"VWAP",W:n,ky:["anchorPeriod","bandMultiplier"],Py:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!Br(t))return{MD:e,AP:r,BP:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=jr(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=Ar(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{MD:e,AP:r,BP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.MD],[h,n.AP],[l,n.BP]]},Ty: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=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.8,bottom:0}});const l=(i,s)=>{const n=t.data();if(!n||0===n.length||!Br(t))return[];const e=[];for(const r of n){const n=Ar(t,r.time);n&&"close"in r&&"open"in r&&e.push({time:r.time,value:n,color:r.close>=r.open?i:s})}return e},o=qr({r_:t,Xf:i,Cy:[r],Jl:"Volume",W:n,ky:["colorUp","colorDown"],Py:(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=Hr(t,s),e=[],r=i*(i+1)/2;for(let s=i-1;s<n.length;s++){let h=0;for(let t=0;t<i;t++){const e=t+1;h+=n[s-i+1+t]*e}const l=h/r;t[s]&&t[s].time&&e.push({time:t[s].time,value:l})}return e},h=qr({r_:t,Xf:i,Cy:[e],Jl:"WMA",W:n,ky:["period","source"],Py:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Ty: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:zr(-100,0)},e),h=$r(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=Nr(r,n.levelColor),o=(t,i)=>{if(!t||t.length<i)return[];const s=[];for(let n=i-1;n<t.length;n++){let e=-1/0,r=1/0;for(let s=0;s<i;s++){const i=t[n-s];"high"in i&&"low"in i&&(e=Math.max(e,i.high),r=Math.min(r,i.low))}const h=t[n];if(!("close"in h)||void 0===h.time)continue;const l=e-r,o=0===l?0:(e-h.close)/l*-100;s.push({time:h.time,value:o})}return s},a=qr({r_:t,Xf:i,Cy:[r],Jl:"Williams %R",W:n,ky:["period"],Py:(t,i)=>[[r,o(t,i.period??14)]],Ty: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:Zr,calculatePipConfig:ro,coordinateFromTime:Gn,createArrowTool:Xl,createBrushTool:Ql,createChart:function(t,i){return jn(t,new ns,ns.ud(i))},createChartEx:jn,createCircleTool:Ul,createCrossLineTool:nl,createFibonacciExtensionTool:Fl,createFibonacciFanTool:Bl,createFibonacciTool:Tl,createGanttTool:bo,createHorizontalLineTool:Qh,createImageWatermark:function(t,i,s){return new Ae(t,new Ke(i,s))},createInteractiveLineManager:function(t,i){return new uh(t,i)},createOptionsChart:function(t,i){return jn(t,new pe,i)},createParallelChannelTool:ul,createPitchforkTool:fl,createPolygonTool:ll,createPositionLine:function(t,i,s){return new Ch(i,t,s)},createPositionMarkers:function(t,i,s){const n=new Ir(t,s);return i&&i.length>0&&n.setPositions(i),n},createPositionTool:vo,createRectangleTool:zl,createRulerTool:uo,createSeriesMarkers:wr,createTextTool:no,createTextWatermark:function(t,i){return new Ae(t,new Ue(i))},createTimeLabels:function(t,i,s){const n=new Fr(t,new Rr(s));return i&&n.setLabels(i),n},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 _h(i,t,r)},createTradingSessionsIndicator:function(t,i,s){return new ih(t,i,s)},createTrendLineTool:jh,createUpDownMarkers:function(t,i={}){return new Pr(t,new xr(i))},createVerticalLineTool:gl,createVolumeProfileIndicator:function(t,i,s){return new eh(t,i,s)},createYieldCurveChart:function(t,i){const s=qn(t);return new ce(s,i)},customSeriesDefaultOptions:yo,defaultHorzScaleBehavior:function(){return ns},getPipConfig:ho,hideSeriesPaint:Er,isBusinessDay:Ei,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(Lr(t.time),t.volume);Vr.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.18-dev+202610170141"}});window.PipsendCharts=So,window.LightweightCharts=So}();
|
|
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,A:0,L: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.L=2.5/12*i,t.I=t.L,t.V=i/12*t.C,t.A=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.Y=new Map,this.j=t,i&&(this.Y=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.Y.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.j.length)for(const i of this.j){const s=i(t);if(s)return this.Y.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.Y.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.At(),n=this.O.Lt();this.kt(),i.forEach((i,e)=>{const r=this.St[e],h=i.Bt(s),l=i.Et();!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.Yt(s),r.ot=k):r.ot=null})}}class R extends C{constructor(t){super(),this.jt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.jt)return;const h=this.jt.Xt.It,l=this.jt.Gt.It;if(!h&&!l)return;const o=Math.round(this.jt.ut*s),a=Math.round(this.jt.ct*r);t.lineCap="butt",h&&o>=0&&(t.lineWidth=Math.floor(this.jt.Xt.dt*s),t.strokeStyle=this.jt.Xt.R,t.fillStyle=this.jt.Xt.R,n(t,this.jt.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.jt.Gt.dt*r),t.strokeStyle=this.jt.Gt.R,t.fillStyle=this.jt.Gt.R,n(t,this.jt.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 A(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 L(t,i,s,n,e,r,h=0,l=[0,0,0,0],o=""){if(t.save(),!h||!o||o===r)return A(t,i,s,n,e,l),t.fillStyle=r,t.fill(),void t.restore();const a=h/2;var _;A(t,i+a,s+a,n-h,e-h,(_=-a,l.map(t=>0===t?t:t+_))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==o&&(t.lineWidth=h,t.strokeStyle=o,t.closePath(),t.stroke()),t.restore()}function B(t,i,s,n,e,r,h){t.save(),t.globalCompositeOperation="copy";const l=t.createLinearGradient(0,0,0,e);l.addColorStop(0,r),l.addColorStop(1,h),t.fillStyle=l,t.fillRect(i,s,n,e),t.restore()}class E{constructor(t,i){this.lt(t,i)}lt(t,i){this.jt=t,this.ri=i}qt(t,i){return this.jt.It?t.P+t.L+t.I:0}et(t,i,s,n){if(!this.jt.It||0===this.jt.hi.length)return;const e=this.jt.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?L(h,o._i,o.ui,o.ci,o.di,r,o.pi,[o.vt,0,0,o.vt],r):L(h,o.fi,o.ui,o.ci,o.di,r,o.pi,[0,o.vt,o.vt,0],r),this.jt.mi&&(h.fillStyle=e,h.fillRect(o.fi,o.wi,o.gi-o.fi,o.bi)),this.jt.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.jt.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.jt.mi||!this.jt.Ti?i.C:0,_=this.jt.ki?i.S:0,u=i.L+this.ri.Di,c=i.I+this.ri.Ri,d=i.V,p=i.A,f=this.jt.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.Ai,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,A,L;return R?(V=I-x,A=I-C,L=F-a-d-_):(V=I+x,A=I+C,L=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:A,bi:M,yi:r.width},xi:{ui:k/o,Si:D/o,Ci:L,Pi:m}}}}class O{constructor(t){this.Li={Ai:0,Z:"#000",Ri:0,Di:0},this.Bi={hi:"",It:!1,mi:!0,Ti:!1,Nt:"",R:"#FFF",Mi:!1,ki:!1},this.Ei={hi:"",It:!1,mi:!1,Ti:!0,Nt:"",R:"#FFF",Mi:!0,ki:!0},this.xt=!0,this.Oi=new(t||E)(this.Bi,this.Li),this.Wi=new(t||E)(this.Ei,this.Li)}hi(){return this.zi(),this.Bi.hi}Ai(){return this.zi(),this.Li.Ai}Tt(){this.xt=!0}qt(t,i=!1){return Math.max(this.Oi.qt(t,i),this.Wi.qt(t,i))}$i(){return this.Li.Vi||0}Hi(t){this.Li.Vi=t}Ni(){return this.zi(),this.Bi.It||this.Ei.It}Ui(){return this.zi(),this.Bi.It}Dt(t){return this.zi(),this.Bi.mi=this.Bi.mi&&t.W().ticksVisible,this.Ei.mi=this.Ei.mi&&t.W().ticksVisible,this.Oi.lt(this.Bi,this.Li),this.Wi.lt(this.Ei,this.Li),this.Oi}qi(){return this.zi(),this.Oi.lt(this.Bi,this.Li),this.Wi.lt(this.Ei,this.Li),this.Wi}zi(){this.xt&&(this.Bi.mi=!0,this.Ei.mi=!1,this.Yi(this.Bi,this.Ei,this.Li))}}class W extends O{constructor(t,i,s){super(),this.Qt=t,this.ji=i,this.Xi=s}Yi(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.ji.Et();if(!this.Qt.It()||this.ji.Gi()||null===e)return;const r=this.ji.Ki().K(n.labelBackgroundColor);s.Z=r.Z,t.R=r.J;const h=2/12*this.ji.P();s.Di=h,s.Ri=h;const l=this.Xi(this.ji);s.Ai=l.Ai,t.hi=this.ji.Zi(l.bt,e),t.It=!0}}const z=/[1-9]/g;class ${constructor(){this.jt=null}lt(t){this.jt=t}et(t,i){if(null===this.jt||!1===this.jt.It||0===this.jt.hi.length)return;const s=t.useMediaCoordinateSpace(({context:t})=>(t.font=i.T,Math.round(i.Ji.Ii(t,l(this.jt).hi,z))));if(s<=0)return;const n=i.Qi,e=s+2*n,r=e/2,h=this.jt.ts;let o=this.jt.Ai,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.L+i.P+i.I);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:s,verticalPixelRatio:n})=>{const e=l(this.jt);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.Ai*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.jt),e=0+i.S+i.C+i.L+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,Ai: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.Lt();if(s.Gi())return;t.ts=s.ts();const n=this.Xi();if(null===n)return;t.Ai=n.Ai;const e=s.ns(this.Ct.At());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,Ai:n};{const t=l(s.Et());return{bt:s.Ds(n,t),Ai:n}}})(()=>this.ps,()=>this.Ss);const s=((t,i)=>()=>{const s=this.ss.Lt().Rs(t()),n=i();return s&&Number.isFinite(n)?{gt:s,Ai: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}As(){return this.xs}Ls(){return this.Cs}Bs(t,i,s){this.gs||(this.gs=!0),this.vs=!0,this.Es(t,i,s)}At(){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()}Ys(t){return t&&!t.ks().Gi()?t.ks():null}Es(t,i,s){this.js(t,i,s)&&this.zs()}js(t,i,s){const n=this.ys,e=this.Ss,r=this.ps,h=this.fs,l=this.Pt,o=this.Ys(s);this.fs=t,this.ys=isNaN(t)?NaN:this.ss.Lt().Yt(t),this.Pt=s;const a=null!==o?o.Et():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 Y(t){return"left"===t||"right"===t}class j{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 j(2)}static bn(){return new j(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.ji=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.ji>0&&this.Mn>0){let t=this.ji;for(;t>1;)t/=10,this.xn++}}Sn(t){const i=this.ji/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.An(t,i,s).width}Fi(t,i,s){const n=this.An(t,i,s);return((n.actualBoundingBoxAscent||0)-(n.actualBoundingBoxDescent||0))/2}An(t,i,s){const n=s||tt,e=String(i).replace(n,"0");if(this.Fn.has(e))return h(this.Fn.get(e)).Ln;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,{Ln:r,Bn:this.kn}),this.Rn[this.kn]=e,this.Tn++,this.kn++),r}}class st{constructor(t){this.En=null,this.M=null,this.On="right",this.Wn=t}zn(t,i,s){this.En=t,this.M=i,this.On=s}et(t){null!==this.M&&null!==this.En&&this.En.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.Yn(i);if("overlay"===s)return null;const n=this.O.jn();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.jt=null}lt(t){this.jt=t}Xn(t,i){if(!this.jt?.It)return null;const{ct:s,dt:n,Gn:e}=this.jt;return i>=s-n-7&&i<=s+n+7?{Kn:this.jt,Gn:e}:null}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:r}){if(null===this.jt)return;if(!1===this.jt.It)return;const h=Math.round(this.jt.ct*r);h<0||h>i.height||(t.lineCap="butt",t.strokeStyle=this.jt.R,t.lineWidth=Math.floor(this.jt.dt*s),n(t,this.jt.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.Et();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.jt=null}lt(t){this.jt=t}ne(){return this.jt}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){const n=this.jt;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().Lt(),i=t.Pe(),s=this.be.Et();if(null===i||null===s)return;const n=this.be.Te(!0);if(n.ke||!i.De(n.Re))return;const e={x:t.Yt(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.Ai,t.R=this.Qn.Ae(s.R),t.dt=i.priceLineWidth,t.Kt=i.priceLineStyle)}}class ut extends O{constructor(t){super(),this.Qt=t}Yi(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.Le(),l=0===e.seriesLastValueMode,o=n.Te(!1);if(o.ke)return;r&&(t.hi=this.Be(o,r,l),t.It=0!==t.hi.length),(h||l)&&(i.hi=this.Ee(o,r,h,l),i.It=i.hi.length>0);const a=n.Ae(o.R),_=this.Qt.ti().Ki().K(a);s.Z=_.Z,s.Ai=o.Ai,i.Nt=n.ti().Ut(o.Ai/n.$t().qt()),t.Nt=a,t.R=_.J,i.R=_.J}Ee(t,i,s,n){let e="";const r=this.Qt.Le();return s&&0!==r.length&&(e+=`${r} `),i&&n&&(e+=this.Qt.$t().Oe()?t.We:t.ze),e.trim()}Be(t,i,s){return i?s?this.Qt.$t().Oe()?t.ze:t.We:t.hi:""}}function ct(t,i,s,n){const e=Number.isFinite(i),r=Number.isFinite(s);return e&&r?t(i,s):e||r?e?i:s:n}class dt{constructor(t,i){this.$e=t,this.He=i}Ne(t){return null!==t&&(this.$e===t.$e&&this.He===t.He)}Ue(){return new dt(this.$e,this.He)}qe(){return this.$e}Ye(){return this.He}je(){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.Ye(),t.Ye(),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}Yi(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.Ai=l}er(t){const i=this.be.Et();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().Lt().Gi()||i.Gi())return null;const s=t.Et();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.Ar=new Map,this.Lr=new Map,this.Br=[]}Er(){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.Yr(t,i,e))}return n}lt(t){this.Lr.clear(),this.Ar.clear(),this.Vr=t,this.Br=t.map(t=>t.Re)}jr(){return this.Br}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}Yr(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.Ar.get(s);void 0===u&&(u=new Map,this.Ar.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 At{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 Lt(t){return{hi:t.text(),Ai:t.coordinate(),Vi:t.fixedCoordinate?.(),R:t.textColor(),Z:t.backColor(),It:t.visible?.()??!0,mi:t.tickVisible?.()??!0}}class Bt{constructor(t,i){this.Jt=new $,this.dh=t,this.ph=i}Dt(){return this.Jt.lt({ts:this.ph.ts(),...Lt(this.dh)}),this.Jt}}class Et extends O{constructor(t,i){super(),this.dh=t,this.ji=i}Yi(t,i,s){const n=Lt(this.dh);s.Z=n.Z,t.R=n.R;const e=2/12*this.ji.P();s.Di=e,s.Ri=e,s.Ai=n.Ai,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().Lt(),s=t.map(t=>new Bt(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 Et(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 At(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 At(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.jt=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)}Ae(t){return this.Ps.priceLineColor||t}Te(t){const i={ke:!0},s=this.$t();if(this.ti().Lt().Gi()||s.Gi()||this.jt.Gi())return i;const n=this.ti().Lt().Pe(),e=this.Et();if(null===n||null===e)return i;let r,h;if(t){const t=this.jt.Er();if(null===t)return i;r=t,h=t.Re}else{const t=this.jt.Hr(n.yi(),-1);if(null===t)return i;if(r=this.jt.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,Ai: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().Ah(this,i),_(this.Ps,t),void 0!==t.priceFormat&&(this.Rh(),this.ti().Lh()),this.ti().Bh(this),this.ti().Eh(),this.eh.Tt("options")}lt(t,i){this.jt.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().Bh(this),this.ti().Eh(),this.ti().ar()}zh(t){const i=new mt(this,t);return this.Sh.push(i),this.ti().Bh(this),i}$h(t){const i=this.Sh.indexOf(t);-1!==i&&this.Sh.splice(i,1),this.ti().Bh(this)}Hh(){return this.Sh}Rr(){return this.Dh}Et(){const t=this.Nh();return null===t?null:{Ht:t.Ht[3],Uh:t.gt}}Nh(){const t=this.ti().Lt().Pe();if(null===t)return null;const i=t.qh();return this.jt.Hr(i,1)}Ks(){return this.jt}Yh(t){const i=this.jt.kr(t);return null===i?null:"Bar"===this.Dh||"Candlestick"===this.Dh||"Custom"===this.Dh?{jh: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())}Bt(t){if(!(("Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh)&&this.Ps.crosshairMarkerVisible))return null;const i=this.jt.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)}}Le(){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.jt.jr()}Qh(){return!Y(this.$t().gl())}rl(t,i){if(!c(t)||!c(i)||this.jt.Gi())return null;const s="Line"===this.Dh||"Area"===this.Dh||"Baseline"===this.Dh||"Histogram"===this.Dh?[3]:[2,1],n=this.jt.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],Yt=[0,1,2,3];class jt{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.Et();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.Et()),a=3===this.Ps.mode?Yt: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.jt=null}lt(t){this.jt=t}rt({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:e}){if(null===this.jt)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.jt);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().Lt().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,Al: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.Ye(),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.Ye(),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.Al)+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.Al;return t<0?-n:n}function li(t,i){if(null===t)return null;const s=ri(t.qe(),i),n=ri(t.Ye(),i);return new dt(s,n)}function oi(t,i){if(null===t)return null;const s=hi(t.qe(),i),n=hi(t.Ye(),i);return new dt(s,n)}function ai(t){if(null===t)return ti;const i=Math.abs(t.Ye()-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,Al:1/Math.pow(10,n)}}class _i{constructor(t,i){if(this.Ll=t,this.Bl=i,function(t){if(t<0)return!1;if(t>1e18)return!0;for(let i=t;i>1;i/=10)if(i%10!=0)return!1;return!0}(this.Ll))this.El=[2,2.5,2];else{this.El=[];for(let t=this.Ll;1!==t;){if(t%2==0)this.El.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.El.push(2,2.5),t/=5}if(this.El.length>100)throw new Error("something wrong with base")}}}Ol(t,i,s){const n=0===this.Ll?0:1/this.Ll;let e=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-i)))),r=0,h=this.Bl[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.Bl[++r%this.Bl.length]}if(e<=n+1e-14&&(e=n),e=Math.max(1,e),this.El.length>0&&(l=e,o=1,a=1e-14,Math.abs(l-o)<a))for(r=0,h=this.El[0];Gt(e,s*h,1e-14)&&e>n+1e-14;)e/=h,h=this.El[++r%this.El.length];var l,o,a;return e}}class ui{constructor(t,i,s,n){this.Wl=[],this.ji=t,this.Ll=i,this.zl=s,this.$l=n}Ol(t,i){if(t<i)throw new Error("high < low");const s=this.ji.qt(),n=(t-i)*this.Hl()/s,e=new _i(this.Ll,[2,2.5,2]),r=new _i(this.Ll,[2,2,2.5]),h=new _i(this.Ll,[2.5,2,2]),l=[];return l.push(e.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.ji,i=t.Et();if(null===i)return void(this.Wl=[]);const s=t.qt(),n=this.zl(s-1,i),e=this.zl(0,i),r=this.ji.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.Yl()&&this.jl(_,a,o)){const t=this.ji.Xl();this.Gl(i,_,h,l,t,2*t)}const u=this.Wl.map(t=>t.Kl),c=this.ji.Zl(u);for(let t=0;t<this.Wl.length;t++)this.Wl[t].Jl=c[t]}Il(){return this.Wl}Ul(){return this.ji.P()}Hl(){return Math.max(1,Math.ceil(this.Ul()*this.ji.W().tickMarkSpacing))}ql(t,i,s,n,e,r){const h=this.Wl,l=this.ji;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.ji.Ql(u),Tl:c,Kl:u}}jl(t,i,s){let n=o(this.ji.tr());return this.ji.io()&&(n=oi(n,this.ji.no())),n.qe()-i<t&&s-n.Ye()<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}Ao(){return 3===this.Ps.mode}no(){return this.yo}se(){return{nn:this.Ps.autoScale,Lo: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.Ye(),i);return isFinite(s)&&isFinite(n)}(this.Je,this.yo)?this.Ps.autoScale=!0:(s=oi(this.Je,this.yo),null!==s&&this.Bo(s))),1===t.se&&t.se!==i.se&&(s=li(this.Je,this.yo),null!==s&&this.Bo(s));const n=i.se!==this.Ps.mode;n&&(2===i.se||this.Oe())&&this.bl(),n&&(3===i.se||this.Ao())&&this.bl(),void 0!==t.Lo&&i.Lo!==t.Lo&&(this.Ps.invertScale=t.Lo,this.Eo()),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}Bo(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.Bo(t),this.qo(null!==t)}Gi(){return this.No(),0===this.eo||!this.Je||this.Je.Gi()}Yo(t){return this.Lo()?t:this.qt()-1-t}zt(t,i){return this.Oe()?t=ii(t,i):this.Ao()&&(t=ni(t,i)),this.Do(t,i)}jo(t,i,s){this.No();const n=this.Ho(),e=l(this.tr()),r=e.qe(),h=e.Ye(),o=this.zo()-1,a=this.Lo(),_=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.Ye(),o=this.zo()-1,a=this.Lo(),_=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.jh,l=e.Xh,o=e.Gh,u=e.Kh;null!==d&&(h=d(e.jh,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.Ao()&&(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.Bo(null)),this.bl(),this.sa()}Et(){let t=null;for(const i of this.fo){const s=i.Et();null!==s&&((null===t||s.Uh<t.Uh)&&(t=s))}return null===t?null:t.Ht}Lo(){return this.Ps.invertScale}Il(){const t=null===this.Et();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.Ao()||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.Ao())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.Bo(s)}oa(){this.Oe()||this.Ao()||(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()).je()/(this.zo()-1);let s=t-this.Mo;this.Lo()&&(s*=-1);const n=s*i,e=l(this.ho).Ue();e.Ge(n),this.Bo(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())}Yl(){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.Ao()?(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.Ao()?1:1/this.vo.rh()}Ki(){return this.Po}qo(t){this._o=t}$o(){return this.Lo()?this.Ps.scaleMargins.bottom*this.qt()+this.co:this.Ps.scaleMargins.top*this.qt()+this.uo}Ho(){return this.Lo()?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.je();return this.Yo(n)}ko(t,i){if(this.No(),this.Gi())return 0;const s=this.Yo(t),n=l(this.tr()),e=n.qe()+n.je()*((s-this.Ho())/(this.zo()-1));return this.io()?hi(e,this.yo):e}Eo(){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.Et();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.Yl()&&(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){const t=this.io(),s=t?oi(i,this.yo):i,n=this.Oe()||this.Ao()?0:10*this.ma();if(s.qe()===s.Ye()||s.je()<n){const e=Math.max(5*this.ma(),n/2),r=(s.qe()+s.Ye())/2,h=new dt(r-e,r+e);i=t?li(h,this.yo):h}if(this.io()){const t=oi(i,this.yo),s=ai(t);if(r=s,h=this.yo,r.Vl!==h.Vl||r.Al!==h.Al){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.Bo(i)}else null===this.Je&&(this.Bo(new dt(-.5,.5)),this.yo=ai(null));var r,h}Xo(){return this.Oe()?ii:this.Ao()?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()}Aa(){return this.Sa}La(t){this.Sa=t}ti(){return this.ss}ts(){return this.ya}qt(){return this.eo}Ba(t){this.ya=t,this.Ea()}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.Ea()}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}Yn(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)}Ya(t,i){t.la(i),this.Ea()}ja(t){t.oa()}Xa(t,i){t.aa(i)}Ga(t,i){t._a(i),this.Ea()}Ka(t){t.ua()}Ea(){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.Ea()}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.Ea(),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),!Y(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,Bn: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.A_=new Ti,this.L_=new Map,this.B_=ki.F_(),this.E_=!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.Y_=[],this.Ps=i,this.Co=s,this.j_=i.rightOffset,this.X_=i.barSpacing,this.ss=t,this.G_(i),this.u_=n,this.K_(),this.A_.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.B_.D_()}ru(){return this.eu(),this.B_.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}Ba(t){if(!isFinite(t)||t<=0)return;if(this.ya===t)return;const i=this.ru(),s=this.ya;if(this.ya=t,this.E_=!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.j_-=Math.round(i/this.X_)+1,this.E_=!0}this.uu(),this.cu()}Yt(t){if(this.Gi()||!c(t))return 0;const i=this.du()+this.j_-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.j_-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.E_=!0,this.j_=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.j_*i/this.X_;this.j_=t}this.cu(),this.ss.gu(),this.ss.ar()}yu(){return this.j_}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.A_.S_(t,i,this.Ps.ignoreWhitespaceIndices,this.U_,this.q_,(t,i)=>this.u_.allowsTickMark?.(t,i,this.V_[t.index-1])??!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.Y_.length?(s=this.Y_[d],s.coord=this.Yt(t.index),s.label=this.xu(t),s.weight=t.weight):(s={needAlignCoordinate:!1,coord:this.Yt(t.index),label:this.xu(t),weight:t.weight},this.Y_.push(s)),this.X_>i/2&&!_?s.needAlignCoordinate=!1:s.needAlignCoordinate=u&&t.index<=o||c&&t.index>=a,d++}return this.Y_.length=d,this.N_=this.Y_,this.Y_}Cu(){let t;this.E_=!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.E_=!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.j_=l(this.H_).yu+i,this.E_=!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.j_,n=performance.now();this.ss.un({Iu:t=>(t-n)/i>=1,Vu:e=>{const r=(e-n)/i;return r>=1?t:s+(t-s)*r}})}Tt(t,i){this.E_=!0,this.V_=t,this.A_.M_(t,i),this.cu()}Au(){return this.O_}Lu(){return this.W_}Bu(){return this.z_}du(){return this.I_||0}Eu(t,i){const s=t.v_(),n=i&&this.Ps.rightOffsetPixels||0;this.Mu((this.ya-n)/s),this.j_=t.yi()-this.du(),i&&(this.j_=n?n/this.bu():this.Ps.rightOffset),this.cu(),this.E_=!0,this.ss.gu(),this.ss.ar()}Ou(){const t=this.ou(),i=this.au();null!==t&&null!==i&&this.Eu(new Ci(t,i),!0)}Wu(t){const i=new Ci(t.from,t.to);this.Eu(i)}es(t){return void 0!==this.Co.timeFormatter?this.Co.timeFormatter(t.originalTime):this.u_.formatHorzItem(t.time)}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.j_-i;return Math.round(1e6*s)/1e6}Mu(t){const i=this.X_;this.X_=t,this.uu(),i!==this.X_&&(this.E_=!0,this.$u())}eu(){if(!this.E_)return;if(this.E_=!1,this.Gi())return void this.Hu(ki.F_());const t=this.du(),i=this.ya/this.X_,s=this.j_+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.E_=!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.j_<t&&(this.j_=t,this.E_=!0);const i=this.Yu();this.j_>i&&(this.j_=i,this.E_=!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))}Yu(){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.L_.get(t.weight);return void 0===i&&(i=new xi(t=>this.ju(t),this.u_),this.L_.set(t.weight,i)),i.c_(t)}ju(t){return this.u_.formatTickmark(t,this.Co)}Hu(t){const i=this.B_;this.B_=t,Pi(i.D_(),this.B_.D_())||this.O_.p(),Pi(i.R_(),this.B_.R_())||this.W_.p(),this.$u()}$u(){this.N_=null}Q_(){this.$u(),this.L_.clear(),this.A_.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.j_-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,Ai,Li;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Fi||(Fi={}));class Bi{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 jt(i.crosshair),i.addDefaultPane&&(this.ec(0),this.Xu[0].La(2)),this.rc=this.hc(0),this.lc=this.hc(1)}Lh(){this.oc(j.bn())}ar(){this.oc(j.gn())}Jh(){this.oc(new j(1))}Bh(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.Bh(i.r_),null!==t&&t.r_!==i?.r_&&this.Bh(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.Lh()}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.Lh();if("right"===t)return _(this.Ps,{rightPriceScale:i}),n.Fa({rightPriceScale:i}),this.Zu.p(),void this.Lh();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}Lt(){return this.ph}qs(){return this.Xu}fc(){return this.Ct}vc(){return this.Ju}mc(t,i){t.Wo(i),this.gu()}Ba(t){this.ya=t,this.ph.Ba(this.ya),this.Xu.forEach(i=>i.Ba(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.Lh())}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.Aa(),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.La(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.La(s)}this.Lh()}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.Lh()}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.Lh()}qa(t,i,s){t.qa(i,s)}Ya(t,i,s){t.Ya(i,s),this.Eh(),this.oc(this.yc(t,2))}ja(t,i){t.ja(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.Eh(),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.Lt();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.Et();if(null!==a&&(r=o.Ds(i,a)),r=this.nc.Ml(r,h,n),this.Ct.Bs(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.At(),{x:t,y:i},s)}}Ic(t,i,s){const n=s.ks(),e=n.Et(),r=n.zt(t,l(e)),h=this.ph.su(i,!0),o=this.ph.Yt(l(h));this.Fc(o,r,null,s,!0)}Vc(t){this.fc().Os(),this.Jh(),t||this.Ju.p(null,null,null)}Eh(){const t=this.Ct.Us();if(null!==t){const i=this.Ct.As(),s=this.Ct.Ls();this.Fc(i,s,null,t)}this.Ct.zs()}Ac(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.Eh()}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}Lc(){return this.sc}jn(){return this.sc.W()}Va(){return this.Zu}Bc(t,i){const s=this.ec(i);this.Ec(t,s),this.Gu.push(t),1===this.Gu.length?this.Lh():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.Lh()}Ah(t,i){const s=l(this.Nn(t));s.na(t,!0),s.ia(t,i,!0)}Ou(){const t=j.gn();t.hn(),this.oc(t)}zc(t){const i=j.gn();i._n(t),this.oc(i)}dn(){const t=j.gn();t.dn(),this.oc(t)}pn(t){const i=j.gn();i.pn(t),this.oc(i)}fn(t){const i=j.gn();i.fn(t),this.oc(i)}un(t){const i=j.gn();i.un(t),this.oc(i)}ln(){const t=j.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.Ec(t,n),0===s.yl().length&&this.Wc(s),this.Lh()}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}Yc(t){return this.Xu.indexOf(t)}Ki(){return this.Po}jc(){return this.Xc()}Xc(t){const i=new wi(this.ph,this);this.Xu.push(i);const s=t??this.Xu.length-1,n=j.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 j(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())}Ec(t,i){const s=t.W().priceScaleId,n=void 0!==s?s:this.$c();i.ia(t,n),Y(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.Yc(t),1)}}function Ei(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"}(Ai||(Ai={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Li||(Li={}));const zi=t=>t.getUTCFullYear();function $i(t,i,s){return i.replace(/yyyy/g,(t=>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)}`}}const Yi=86400,ji=new Map;function Xi(t,i){const s=t.formatToParts(new Date(1e3*i)),n=t=>Number(s.find(i=>i.type===t)?.value??0),e=Date.UTC(n("year"),n("month")-1,n("day"),n("hour")%24,n("minute"),n("second"));return Math.round(e/1e3-i)}function Gi(t,i){if(void 0===t||"UTC"===t)return 0;const s=function(t){let i=ji.get(t);if(void 0===i){let s=null;try{s=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"})}catch(t){s=null}i={c_:s,hd:new Map,ld:new Map},ji.set(t,i)}return i}(t),n=s.c_;if(null===n)return 0;const e=Math.floor(i/Yi);let r=s.hd.get(e);if(void 0===r){const t=Xi(n,e*Yi);r=t===Xi(n,(e+1)*Yi-1)?t:null,s.hd.set(e,r)}if(null!==r)return r;const h=Math.floor(i/900);let l=s.ld.get(h);return void 0===l&&(l=Xi(n,900*h),s.ld.set(h,l)),l}function Ki(t){return 60*t*60*1e3}function Zi(t){return 60*t*1e3}const Ji=[{od:(Qi=1,1e3*Qi),ad:10},{od:Zi(1),ad:20},{od:Zi(5),ad:21},{od:Zi(30),ad:22},{od:Ki(1),ad:30},{od:Ki(3),ad:31},{od:Ki(6),ad:32},{od:Ki(12),ad:33}];var Qi;function ts(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=Ji.length-1;s>=0;--s)if(Math.floor(i.getTime()/Ji[s].od)!==Math.floor(t.getTime()/Ji[s].od))return Ji[s].ad;return 0}function is(t,i){const s=t.time;return void 0===s._d?s.ud+Gi(i,s.ud):s.ud}function ss(t){let i=t;if(d(t)&&(i=es(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{ud:Math.round(s.getTime()/1e3),_d:i}}function ns(t){if(!Wi(t))throw new Error("time must be of type isUTCTimestamp");return{ud:t}}function es(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 rs(t){d(t.time)&&(t.time=es(t.time))}function hs(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 ls{options(){return this.Ps}setOptions(t){this.Ps=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(rs)}(t):rs(t)}createConverterToInternalObj(t){return l(function(t){return 0===t.length?null:Oi(t[0].time)||d(t[0].time)?ss:ns}(t))}key(t){return"object"==typeof t&&"ud"in t?t.ud:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const i=t;return void 0===i._d?new Date(1e3*i.ud).getTime():new Date(Date.UTC(i._d.year,i._d.month-1,i._d.day)).getTime()}convertHorzItemToInternal(t){return Wi(i=t)?ns(i):Oi(i)?ss(i):ss(es(i));var i}updateFormatter(t){if(!this.Ps)return;const i=t.dateFormat;this.Ps.timeScale.timeVisible?this.dd=new qi({Jc:i,Qc:this.Ps.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",td:" ",sd:t.locale}):this.dd=new Hi(i,t.locale)}formatHorzItem(t){return this.dd.c_(new Date(1e3*this.pd(t).ud))}allowsTickMark(t,i,s){const n=this.Ps.timeScale.tickMarkFilter;if(void 0===n)return!0;const e=hs(t.weight,this.Ps.timeScale.timeVisible,this.Ps.timeScale.secondsVisible);return n(t.originalTime,e,i,void 0===s?null:s.originalTime)}formatTickmark(t,i){const s=hs(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._d?new Date(1e3*t.ud):new Date(Date.UTC(t._d.year,t._d.month-1,t._d.day));return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds(),e.getUTCMilliseconds()).toLocaleString(s,n)}(this.pd(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,s){if(0===t.length)return;let n=0===i?null:is(t[i-1],s),e=null!==n?new Date(1e3*n):null,r=0;for(let h=i;h<t.length;++h){const i=t[h],l=is(i,s),o=new Date(1e3*l);null!==e&&(i.timeWeight=ts(o,e)),r+=l-(n||l),n=l,e=o}if(0===i&&t.length>1){const i=Math.ceil(r/(t.length-1)),n=is(t[0],s),e=new Date(1e3*(n-i));t[0].timeWeight=ts(new Date(1e3*n),e)}}(t,i,this.fd())}fd(){return this.Ps?.localization.timeZone}pd(t){if(void 0!==t._d)return t;const i=Gi(this.fd(),t.ud);return 0===i?t:{ud:t.ud+i}}static vd(t){return _({localization:{dateFormat:"dd MMM 'yy"}},t??{})}}function os(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 as(t,i){return t.width===i.width&&t.height===i.height}var _s=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 us=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=os({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 os({width:this.canvasElement.width,height:this.canvasElement.height})},enumerable:!1,configurable:!0}),t.prototype.resizeCanvasElement=function(t){this._canvasElementClientSize=os(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;as(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=os(this._transformBitmapSize(t,this._canvasElementClientSize)),n=as(this.bitmapSize,s)?null:s;null===i&&null===n||null!==i&&null!==n&&as(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=cs(this._canvasElement);if(null===i)throw new Error("No window is associated with the canvas");this._devicePixelRatioObservable=function(t){return new _s(t)}(i),this._devicePixelRatioObservable.subscribe(function(){return t._invalidateBitmapSize()}),this._invalidateBitmapSize()}},t.prototype._invalidateBitmapSize=function(){var t,i;if(null!==this._canvasElement){var s=cs(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 os({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):os({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=os({width:n.inlineSize,height:n.blockSize});t._suggestNewBitmapSize(e)}}),this._canvasElementResizeObserver.observe(this._canvasElement,{box:"device-pixel-content-box"}))},t}();function cs(t){return t.ownerDocument.defaultView}var ds=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 ps(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 ds(e,s,n)}const fs="undefined"!=typeof window;function vs(){return!!fs&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ms(){return!!fs&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function ws(t){return t+t%2}function gs(t){fs&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}class bs{constructor(t,i,s){this.md=0,this.wd=null,this.gd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.bd=0,this.Md=null,this.yd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY},this.Sd=null,this.xd=!1,this.Cd=null,this.Pd=null,this.Td=!1,this.kd=!1,this.Dd=!1,this.Rd=null,this.Fd=null,this.Id=null,this.Vd=null,this.Ad=null,this.Ld=null,this.Bd=null,this.Ed=0,this.Od=!1,this.Wd=!1,this.zd=!1,this.$d=0,this.Hd=null,this.Nd=!ms(),this.Ud=t=>{this.qd(t)},this.Yd=t=>{if(this.jd(t)){const i=this.Xd(t);if(++this.bd,this.Md&&this.bd>1){const{Gd:s}=this.Kd(Ss(t),this.yd);s<30&&!this.Dd&&this.Zd(i,this.Qd.Jd),this.tp()}}else{const i=this.Xd(t);if(++this.md,this.wd&&this.md>1){const{Gd:s}=this.Kd(Ss(t),this.gd);s<5&&!this.kd&&this.ip(i,this.Qd.sp),this.np()}}},this.ep=t,this.Qd=i,this.Ps=s,this.rp()}m(){null!==this.Rd&&(this.Rd(),this.Rd=null),null!==this.Fd&&(this.Fd(),this.Fd=null),null!==this.Vd&&(this.Vd(),this.Vd=null),null!==this.Ad&&(this.Ad(),this.Ad=null),null!==this.Ld&&(this.Ld(),this.Ld=null),null!==this.Id&&(this.Id(),this.Id=null),this.hp(),this.np()}lp(t){this.Vd&&this.Vd();const i=this.op.bind(this);if(this.Vd=()=>{this.ep.removeEventListener("mousemove",i)},this.ep.addEventListener("mousemove",i),this.jd(t))return;const s=this.Xd(t);this.ip(s,this.Qd.ap),this.Nd=!0}np(){null!==this.wd&&clearTimeout(this.wd),this.md=0,this.wd=null,this.gd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}tp(){null!==this.Md&&clearTimeout(this.Md),this.bd=0,this.Md=null,this.yd={ut:Number.NEGATIVE_INFINITY,ct:Number.POSITIVE_INFINITY}}op(t){if(this.zd||null!==this.Pd)return;if(this.jd(t))return;const i=this.Xd(t);this.ip(i,this.Qd._p),this.Nd=!0}up(t){const i=Cs(t.changedTouches,l(this.Hd));if(null===i)return;if(this.$d=xs(t),null!==this.Bd)return;if(this.Wd)return;this.Od=!0;const s=this.Kd(Ss(i),l(this.Pd)),{cp:n,dp:e,Gd:r}=s;if(this.Td||!(r<5)){if(!this.Td){const t=.5*n,i=e>=t&&!this.Ps.pp(),s=t>e&&!this.Ps.fp();i||s||(this.Wd=!0),this.Td=!0,this.Dd=!0,this.hp(),this.tp()}if(!this.Wd){const s=this.Xd(t,i);this.Zd(s,this.Qd.vp),ys(t)}}}mp(t){if(0!==t.button)return;const i=this.Kd(Ss(t),l(this.Cd)),{Gd:s}=i;if(s>=5&&(this.kd=!0,this.np()),this.kd){const i=this.Xd(t);this.ip(i,this.Qd.wp)}}Kd(t,i){const s=Math.abs(i.ut-t.ut),n=Math.abs(i.ct-t.ct);return{cp:s,dp:n,Gd:s+n}}gp(t){let i=Cs(t.changedTouches,l(this.Hd));if(null===i&&0===t.touches.length&&(i=t.changedTouches[0]),null===i)return;this.Hd=null,this.$d=xs(t),this.hp(),this.Pd=null,this.Ld&&(this.Ld(),this.Ld=null);const s=this.Xd(t,i);if(this.Zd(s,this.Qd.bp),++this.bd,this.Md&&this.bd>1){const{Gd:t}=this.Kd(Ss(i),this.yd);t<30&&!this.Dd&&this.Zd(s,this.Qd.Jd),this.tp()}else this.Dd||(this.Zd(s,this.Qd.Mp),this.Qd.Mp&&ys(t));0===this.bd&&ys(t),0===t.touches.length&&this.xd&&(this.xd=!1,ys(t))}qd(t){if(0!==t.button)return;const i=this.Xd(t);if(this.Cd=null,this.zd=!1,this.Ad&&(this.Ad(),this.Ad=null),vs()){this.ep.ownerDocument.documentElement.removeEventListener("mouseleave",this.Ud)}if(!this.jd(t))if(this.ip(i,this.Qd.yp),++this.md,this.wd&&this.md>1){const{Gd:s}=this.Kd(Ss(t),this.gd);s<5&&!this.kd&&this.ip(i,this.Qd.sp),this.np()}else this.kd||this.ip(i,this.Qd.Sp)}hp(){null!==this.Sd&&(clearTimeout(this.Sd),this.Sd=null)}xp(t){if(null!==this.Hd)return;const i=t.changedTouches[0];this.Hd=i.identifier,this.$d=xs(t);const s=this.ep.ownerDocument.documentElement;this.Dd=!1,this.Td=!1,this.Wd=!1,this.Pd=Ss(i),this.Ld&&(this.Ld(),this.Ld=null);{const i=this.up.bind(this),n=this.gp.bind(this);this.Ld=()=>{s.removeEventListener("touchmove",i),s.removeEventListener("touchend",n)},s.addEventListener("touchmove",i,{passive:!1}),s.addEventListener("touchend",n,{passive:!1}),this.hp(),this.Sd=setTimeout(this.Cp.bind(this,t),240)}const n=this.Xd(t,i);this.Zd(n,this.Qd.Pp),this.Md||(this.bd=0,this.Md=setTimeout(this.tp.bind(this),500),this.yd=Ss(i))}Tp(t){if(0!==t.button)return;const i=this.ep.ownerDocument.documentElement;vs()&&i.addEventListener("mouseleave",this.Ud),this.kd=!1,this.Cd=Ss(t),this.Ad&&(this.Ad(),this.Ad=null);{const t=this.mp.bind(this),s=this.qd.bind(this);this.Ad=()=>{i.removeEventListener("mousemove",t),i.removeEventListener("mouseup",s)},i.addEventListener("mousemove",t),i.addEventListener("mouseup",s)}if(this.zd=!0,this.jd(t))return;const s=this.Xd(t);this.ip(s,this.Qd.kp),this.wd||(this.md=0,this.wd=setTimeout(this.np.bind(this),500),this.gd=Ss(t))}rp(){this.ep.addEventListener("mouseenter",this.lp.bind(this)),this.ep.addEventListener("touchcancel",this.hp.bind(this));{const t=this.ep.ownerDocument,i=t=>{this.Qd.Dp&&(t.composed&&this.ep.contains(t.composedPath()[0])||t.target&&this.ep.contains(t.target)||this.Qd.Dp())};this.Fd=()=>{t.removeEventListener("touchstart",i)},this.Rd=()=>{t.removeEventListener("mousedown",i)},t.addEventListener("mousedown",i),t.addEventListener("touchstart",i,{passive:!0})}ms()&&(this.Id=()=>{this.ep.removeEventListener("dblclick",this.Yd)},this.ep.addEventListener("dblclick",this.Yd)),this.ep.addEventListener("mouseleave",this.Rp.bind(this)),this.ep.addEventListener("touchstart",this.xp.bind(this),{passive:!0}),gs(this.ep),this.ep.addEventListener("mousedown",this.Tp.bind(this)),this.Fp(),this.ep.addEventListener("touchmove",()=>{},{passive:!1})}Fp(){void 0===this.Qd.Ip&&void 0===this.Qd.Vp&&void 0===this.Qd.Ap||(this.ep.addEventListener("touchstart",t=>this.Lp(t.touches),{passive:!0}),this.ep.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Bd&&void 0!==this.Qd.Vp){const i=Ms(t.touches[0],t.touches[1])/this.Ed;this.Qd.Vp(this.Bd,i),ys(t)}},{passive:!1}),this.ep.addEventListener("touchend",t=>{this.Lp(t.touches)}))}Lp(t){1===t.length&&(this.Od=!1),2!==t.length||this.Od||this.xd?this.Bp():this.Ep(t)}Ep(t){const i=this.ep.getBoundingClientRect()||{left:0,top:0};this.Bd={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.Ed=Ms(t[0],t[1]),void 0!==this.Qd.Ip&&this.Qd.Ip(),this.hp()}Bp(){null!==this.Bd&&(this.Bd=null,void 0!==this.Qd.Ap&&this.Qd.Ap())}Rp(t){if(this.Vd&&this.Vd(),this.jd(t))return;if(!this.Nd)return;const i=this.Xd(t);this.ip(i,this.Qd.Op),this.Nd=!ms()}Cp(t){const i=Cs(t.touches,l(this.Hd));if(null===i)return;const s=this.Xd(t,i);this.Zd(s,this.Qd.Wp),this.Dd=!0,this.xd=!0}jd(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:xs(t)<this.$d+500}Zd(t,i){i&&i.call(this.Qd,t)}ip(t,i){i&&i.call(this.Qd,t)}Xd(t,i){const s=i||t,n=this.ep.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,zp:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,$p:t.type,Hp:s.target,a_:t.view,Np:()=>{"touchstart"!==t.type&&ys(t)}}}}function Ms(t,i){const s=t.clientX-i.clientX,n=t.clientY-i.clientY;return Math.sqrt(s*s+n*n)}function ys(t){t.cancelable&&t.preventDefault()}function Ss(t){return{ut:t.pageX,ct:t.pageY}}function xs(t){return t.timeStamp||performance.now()}function Cs(t,i){for(let s=0;s<t.length;++s)if(t[s].identifier===i)return t[s];return null}class Ps{constructor(t,i,s){this.Up=null,this.qp=null,this.Yp=!0,this.jp=null,this.Xp=t,this.Gp=t.Kp()[i],this.Zp=t.Kp()[s],this.Jp=document.createElement("tr"),this.Jp.style.height="1px",this.Qp=document.createElement("td"),this.Qp.style.position="relative",this.Qp.style.padding="0",this.Qp.style.margin="0",this.Qp.setAttribute("colspan","3"),this.tf(),this.Jp.appendChild(this.Qp),this.Yp=this.Xp.W().layout.panes.enableResize,this.Yp?this.if():(this.Up=null,this.qp=null)}m(){null!==this.qp&&this.qp.m()}sf(){return this.Jp}nf(){return os({width:this.Gp.nf().width,height:1})}ef(){return os({width:this.Gp.ef().width,height:1*window.devicePixelRatio})}rf(t,i,s){const n=this.ef();t.fillStyle=this.Xp.W().layout.panes.separatorColor,t.fillRect(i,s,n.width,n.height)}Tt(){this.tf(),this.Xp.W().layout.panes.enableResize!==this.Yp&&(this.Yp=this.Xp.W().layout.panes.enableResize,this.Yp?this.if():(null!==this.Up&&(this.Qp.removeChild(this.Up.hf),this.Qp.removeChild(this.Up.lf),this.Up=null),null!==this.qp&&(this.qp.m(),this.qp=null)))}if(){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.Qp.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.Qp.appendChild(s);const e={ap:this.af.bind(this),Op:this._f.bind(this),kp:this.uf.bind(this),Pp:this.uf.bind(this),wp:this.cf.bind(this),vp:this.cf.bind(this),yp:this.df.bind(this),bp:this.df.bind(this)};this.qp=new bs(s,e,{pp:()=>!1,fp:()=>!0}),this.Up={lf:s,hf:t}}tf(){this.Qp.style.background=this.Xp.W().layout.panes.separatorColor}af(t){null!==this.Up&&(this.Up.lf.style.backgroundColor=this.Xp.W().layout.panes.separatorHoverColor)}_f(t){null!==this.Up&&null===this.jp&&(this.Up.lf.style.backgroundColor="")}uf(t){if(null===this.Up)return;const i=this.Gp.pf().Aa()+this.Zp.pf().Aa(),s=i/(this.Gp.nf().height+this.Zp.nf().height),n=30*s;i<=2*n||(this.jp={ff:t.pageY,vf:this.Gp.pf().Aa(),mf:i-n,wf:i,gf:s,bf:n},this.Up.hf.style.display="block")}cf(t){const i=this.jp;if(null===i)return;const s=(t.pageY-i.ff)*i.gf,n=Xt(i.vf+s,i.bf,i.mf);this.Gp.pf().La(n),this.Zp.pf().La(i.wf-n),this.Xp.ti().Lh()}df(t){null!==this.jp&&null!==this.Up&&(this.jp=null,this.Up.hf.style.display="none")}}function Ts(t,i){return t.Mf-i.Mf}function ks(t,i,s){const n=(t.Mf-i.Mf)/(t.gt-i.gt);return Math.sign(n)*Math.min(Math.abs(n),s)}class Ds{constructor(t,i,s,n){this.yf=null,this.Sf=null,this.xf=null,this.Cf=null,this.Pf=null,this.Tf=0,this.kf=0,this.Df=t,this.Rf=i,this.Ff=s,this.Mn=n}If(t,i){if(null!==this.yf){if(this.yf.gt===i)return void(this.yf.Mf=t);if(Math.abs(this.yf.Mf-t)<this.Mn)return}this.Cf=this.xf,this.xf=this.Sf,this.Sf=this.yf,this.yf={gt:i,Mf:t}}ae(t,i){if(null===this.yf||null===this.Sf)return;if(i-this.yf.gt>50)return;let s=0;const n=ks(this.yf,this.Sf,this.Rf),e=Ts(this.yf,this.Sf),r=[n],h=[e];if(s+=e,null!==this.xf){const t=ks(this.Sf,this.xf,this.Rf);if(Math.sign(t)===Math.sign(n)){const i=Ts(this.Sf,this.xf);if(r.push(t),h.push(i),s+=i,null!==this.Cf){const t=ks(this.xf,this.Cf,this.Rf);if(Math.sign(t)===Math.sign(n)){const i=Ts(this.xf,this.Cf);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.Df||(this.Pf={Mf:t,gt:i},this.kf=l,this.Tf=function(t,i){const s=Math.log(i);return Math.log(1*s/-t)/s}(Math.abs(l),this.Ff))}Vu(t){const i=l(this.Pf),s=t-i.gt;return i.Mf+this.kf*(Math.pow(this.Ff,s)-1)/Math.log(this.Ff)}Iu(t){return null===this.Pf||this.Vf(t)===this.Tf}Vf(t){const i=t-l(this.Pf).gt;return Math.min(i,this.Tf)}}class Rs{constructor(t,i){this.Af=void 0,this.Lf=void 0,this.Bf=void 0,this.vs=!1,this.Ef=t,this.Of=i,this.Wf()}Tt(){this.Wf()}zf(){this.Af&&this.Ef.removeChild(this.Af),this.Lf&&this.Ef.removeChild(this.Lf),this.Af=void 0,this.Lf=void 0}$f(){return this.vs!==this.Hf()||this.Bf!==this.Nf()}Nf(){return this.Of.ti().Ki().tt(this.Of.W().layout.textColor)>160?"dark":"light"}Hf(){return this.Of.W().layout.attributionLogo}Uf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}Wf(){this.$f()&&(this.zf(),this.vs=this.Hf(),this.vs&&(this.Bf=this.Nf(),this.Lf=document.createElement("style"),this.Lf.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.Af=document.createElement("a"),this.Af.href=`https://pipsend.com${this.Uf()}`,this.Af.title="Powered by Pipsend Charts",this.Af.id="pipsend-attr-logo",this.Af.target="_blank",this.Af.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.Af.toggleAttribute("data-dark","dark"===this.Bf),this.Ef.appendChild(this.Lf),this.Ef.appendChild(this.Af)))}}function Fs(t,i){const s=l(t.ownerDocument).createElement("canvas");t.appendChild(s);const n=new us(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 Is(t){t.width=1,t.height=1,t.getContext("2d")?.clearRect(0,0,1,1)}function Vs(t,i,s,n){t.nh&&t.nh(i,s,n)}function As(t,i,s,n){t.et(i,s,n)}function Ls(t,i,s,n){const e=t(s,n);for(const t of e){const s=t.Dt(n);null!==s&&i(s)}}function Bs(t,i){return s=>{if(!function(t){return void 0!==t.$t}(s))return[];return(s.$t()?.gl()??"")!==i?[]:s.sl?.(t)??[]}}function Es(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 Os{constructor(t,i,s,n){this.ji=null,this.qf=null,this.Yf=!1,this.jf=new it(200),this.Xf=null,this.Gf=0,this.Kf=!1,this.Zf=()=>{this.Kf||this.Pt.Jf().ti().ar()},this.Qf=()=>{this.Kf||this.Pt.Jf().ti().ar()},this.Pt=t,this.Ps=i,this.xo=i.layout,this.sc=s,this.tv="left"===n,this.iv=Bs("normal",n),this.sv=Bs("top",n),this.nv=Bs("bottom",n),this.Qp=document.createElement("div"),this.Qp.style.height="100%",this.Qp.style.overflow="hidden",this.Qp.style.width="25px",this.Qp.style.left="0",this.Qp.style.position="relative",this.ev=Fs(this.Qp,os({width:16,height:16})),this.ev.subscribeSuggestedBitmapSizeChanged(this.Zf);const e=this.ev.canvasElement;e.style.position="absolute",e.style.zIndex="1",e.style.left="0",e.style.top="0",this.rv=Fs(this.Qp,os({width:16,height:16})),this.rv.subscribeSuggestedBitmapSizeChanged(this.Qf);const r=this.rv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0";const h={kp:this.uf.bind(this),Pp:this.uf.bind(this),wp:this.cf.bind(this),vp:this.cf.bind(this),Dp:this.hv.bind(this),yp:this.df.bind(this),bp:this.df.bind(this),sp:this.lv.bind(this),Jd:this.lv.bind(this),ap:this.ov.bind(this),Op:this._f.bind(this)};this.qp=new bs(this.rv.canvasElement,h,{pp:()=>!this.Ps.handleScroll.vertTouchDrag,fp:()=>!0})}m(){this.qp.m(),this.rv.unsubscribeSuggestedBitmapSizeChanged(this.Qf),Is(this.rv.canvasElement),this.rv.dispose(),this.ev.unsubscribeSuggestedBitmapSizeChanged(this.Zf),Is(this.ev.canvasElement),this.ev.dispose(),null!==this.ji&&this.ji.ra().u(this),this.ji=null}sf(){return this.Qp}P(){return this.xo.fontSize}av(){const t=this.sc.W();return this.Xf!==t.T&&(this.jf.Vn(),this.Xf=t.T),t}_v(){if(null===this.ji)return 0;let t=0;const i=this.av(),s=l(this.ev.canvasElement.getContext("2d",{colorSpace:this.Pt.Jf().W().layout.colorSpace}));s.save();const n=this.ji.Il();s.font=this.uv(),n.length>0&&(t=Math.max(this.jf.Ii(s,n[0].Jl),this.jf.Ii(s,n[n.length-1].Jl)));const e=this.cv();for(let i=e.length;i--;){const n=this.jf.Ii(s,e[i].hi());n>t&&(t=n)}const r=this.ji.Et();if(null!==r&&null!==this.qf&&(2!==(h=this.Ps.crosshair).mode&&h.horzLine.visible&&h.horzLine.labelVisible)){const i=this.ji.Ds(1,r),n=this.ji.Ds(this.qf.height-2,r);t=Math.max(t,this.jf.Ii(s,this.ji.Zi(Math.floor(Math.min(i,n))+.11111111111111,r)),this.jf.Ii(s,this.ji.Zi(Math.ceil(Math.max(i,n))-.11111111111111,r)))}var h;s.restore();const o=t||34;return ws(Math.ceil(i.S+i.C+i.V+i.A+5+o))}dv(t){null!==this.qf&&as(this.qf,t)||(this.qf=t,this.Kf=!0,this.ev.resizeCanvasElement(t),this.rv.resizeCanvasElement(t),this.Kf=!1,this.Qp.style.width=`${t.width}px`,this.Qp.style.height=`${t.height}px`)}pv(){return l(this.qf).width}us(t){this.ji!==t&&(null!==this.ji&&this.ji.ra().u(this),this.ji=t,t.ra().i(this.do.bind(this),this))}$t(){return this.ji}Vn(){const t=this.Pt.pf();this.Pt.Jf().ti().Ja(t,l(this.$t()))}fv(t){if(null===this.qf)return;const i={colorSpace:this.Pt.Jf().W().layout.colorSpace};if(1!==t){this.vv(),this.ev.applySuggestedBitmapSize();const t=ps(this.ev,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mv(t),this.wv(t)}),this.Pt.gv(t,this.nv),this.bv(t),this.Pt.gv(t,this.iv),this.Mv(t))}this.rv.applySuggestedBitmapSize();const s=ps(this.rv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.yv(s),this.Pt.gv(s,this.sv))}ef(){return this.ev.bitmapSize}rf(t,i,s,n){const e=this.ef();if(e.width>0&&e.height>0&&(t.drawImage(this.ev.canvasElement,i,s),n)){const n=this.rv.canvasElement;t.drawImage(n,i,s)}}Tt(){this.ji?.Il()}uf(t){if(null===this.ji||this.ji.Gi()||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Jf().ti(),s=this.Pt.pf();this.Yf=!0,i.qa(s,this.ji,t.localY)}cf(t){if(null===this.ji||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Jf().ti(),s=this.Pt.pf(),n=this.ji;i.Ya(s,n,t.localY)}hv(){if(null===this.ji||!this.Ps.handleScale.axisPressedMouseMove.price)return;const t=this.Pt.Jf().ti(),i=this.Pt.pf(),s=this.ji;this.Yf&&(this.Yf=!1,t.ja(i,s))}df(t){if(null===this.ji||!this.Ps.handleScale.axisPressedMouseMove.price)return;const i=this.Pt.Jf().ti(),s=this.Pt.pf();this.Yf=!1,i.ja(s,this.ji)}lv(t){this.Ps.handleScale.axisDoubleClickReset.price&&this.Vn()}ov(t){if(null===this.ji)return;!this.Pt.Jf().ti().W().handleScale.axisPressedMouseMove.price||this.ji.Oe()||this.ji.Ao()||this.Sv(1)}_f(t){this.Sv(0)}cv(){const t=[],i=null===this.ji?void 0:this.ji;return(s=>{for(let n=0;n<s.length;++n){const e=s[n].Hs(this.Pt.pf(),i);for(let i=0;i<e.length;i++)t.push(e[i])}})(this.Pt.pf().Ft()),t}mv({context:t,bitmapSize:i}){const{width:s,height:n}=i,e=this.Pt.pf().ti(),r=e.q(),h=e.Uc();r===h?V(t,0,0,s,n,r):B(t,0,0,s,n,r,h)}wv({context:t,bitmapSize:i,horizontalPixelRatio:s}){if(null===this.qf||null===this.ji||!this.ji.W().borderVisible)return;t.fillStyle=this.ji.W().borderColor;const n=Math.max(1,Math.floor(this.av().S*s));let e;e=this.tv?i.width-n:0,t.fillRect(e,0,n,i.height)}bv(t){if(null===this.qf||null===this.ji)return;const i=this.ji.Il(),s=this.ji.W(),n=this.av(),e=this.tv?this.qf.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.uv(),t.fillStyle=s.textColor??this.xo.textColor,t.textAlign=this.tv?"right":"left",t.textBaseline="middle";const r=this.tv?Math.round(e-n.V):Math.round(e+n.C+n.V),h=i.map(i=>this.jf.Fi(t,i.Jl));for(let s=i.length;s--;){const n=i[s];t.fillText(n.Jl,r,n.Tl+h[s])}})}vv(){if(null===this.qf||null===this.ji)return;let t=this.qf.height/2;const i=[],s=this.ji.Ft().slice(),n=this.Pt.pf(),e=this.av();this.ji===n.qn()&&this.Pt.pf().Ft().forEach(t=>{n.Un(t)&&s.push(t)});const r=this.ji.yl()[0],h=this.ji;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].Ai())}),i.forEach(t=>t.Hi(t.Ai()));this.ji.W().alignLabels&&this.xv(i,e,t)}xv(t,i,s){if(null===this.qf)return;const n=t.filter(t=>t.Ai()<=s),e=t.filter(t=>t.Ai()>s);n.sort((t,i)=>i.Ai()-t.Ai()),n.length&&e.length&&e.push(n[0]),e.sort((t,i)=>t.Ai()-i.Ai());for(const s of t){const t=Math.floor(s.qt(i)/2),n=s.Ai();n>-t&&n<t&&s.Hi(t),n>this.qf.height-t&&n<this.qf.height+t&&s.Hi(this.qf.height-t)}Es(n,1,this.qf.height,i),Es(e,-1,this.qf.height,i)}Mv(t){if(null===this.qf)return;const i=this.cv(),s=this.av(),n=this.tv?"right":"left";i.forEach(i=>{if(i.Ui()){i.Dt(l(this.ji)).et(t,s,this.jf,n)}})}yv(t){if(null===this.qf||null===this.ji)return;const i=this.Pt.Jf().ti(),s=[],n=this.Pt.pf(),e=i.fc().Hs(n,this.ji);e.length&&s.push(e);const r=this.av(),h=this.tv?"right":"left";s.forEach(i=>{i.forEach(i=>{i.Dt(l(this.ji)).et(t,r,this.jf,h)})})}Sv(t){this.Qp.style.cursor=1===t?"ns-resize":"default"}do(){const t=this._v();this.Gf<t&&this.Pt.Jf().ti().Lh(),this.Gf=t}uv(){return g(this.xo.fontSize,this.xo.fontFamily)}}function Ws(t,i){return t.tl?.(i)??[]}function zs(t,i){return t.$s?.(i)??[]}function $s(t,i){return t.cs?.(i)??[]}function Hs(t,i){return t.Zh?.(i)??[]}class Ns{constructor(t,i){this.qf=os({width:0,height:0}),this.Cv=null,this.Pv=null,this.Tv=null,this.kv=null,this.Dv=!1,this.Rv=new a,this.Fv=new a,this.Iv=0,this.Vv=!1,this.Av=null,this.Lv=!1,this.Bv=null,this.Ev=null,this.Kf=!1,this.Zf=()=>{this.Kf||null===this.Ov||this.ss().ar()},this.Qf=()=>{this.Kf||null===this.Ov||this.ss().ar()},this.Of=t,this.Ov=i,this.Ov.s_().i(this.Wv.bind(this),this,!0),this.zv=document.createElement("td"),this.zv.style.padding="0",this.zv.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.$v=document.createElement("td"),this.$v.style.padding="0",this.Hv=document.createElement("td"),this.Hv.style.padding="0",this.zv.appendChild(s),this.ev=Fs(s,os({width:16,height:16})),this.ev.subscribeSuggestedBitmapSizeChanged(this.Zf);const n=this.ev.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.rv=Fs(s,os({width:16,height:16})),this.rv.subscribeSuggestedBitmapSizeChanged(this.Qf);const e=this.rv.canvasElement;e.style.position="absolute",e.style.zIndex="2",e.style.left="0",e.style.top="0",this.Jp=document.createElement("tr"),this.Jp.appendChild(this.$v),this.Jp.appendChild(this.zv),this.Jp.appendChild(this.Hv),this.Nv(),this.qp=new bs(this.rv.canvasElement,this,{pp:()=>null===this.Av&&!this.Of.W().handleScroll.vertTouchDrag,fp:()=>null===this.Av&&!this.Of.W().handleScroll.horzTouchDrag})}m(){null!==this.Cv&&this.Cv.m(),null!==this.Pv&&this.Pv.m(),this.Tv=null,this.rv.unsubscribeSuggestedBitmapSizeChanged(this.Qf),Is(this.rv.canvasElement),this.rv.dispose(),this.ev.unsubscribeSuggestedBitmapSizeChanged(this.Zf),Is(this.ev.canvasElement),this.ev.dispose(),null!==this.Ov&&(this.Ov.s_().u(this),this.Ov.m()),this.qp.m()}pf(){return l(this.Ov)}Uv(t){null!==this.Ov&&this.Ov.s_().u(this),this.Ov=t,null!==this.Ov&&this.Ov.s_().i(Ns.prototype.Wv.bind(this),this,!0),this.Nv(),this.Of.Kp().indexOf(this)===this.Of.Kp().length-1?(this.Tv=this.Tv??new Rs(this.zv,this.Of),this.Tv.Tt()):(this.Tv?.zf(),this.Tv=null)}Jf(){return this.Of}sf(){return this.Jp}Nv(){if(null!==this.Ov&&(this.qv(),0!==this.ss().Xs().length)){if(null!==this.Cv){const t=this.Ov.Na();this.Cv.us(l(t))}if(null!==this.Pv){const t=this.Ov.Ua();this.Pv.us(l(t))}}}Yv(){null!==this.Cv&&this.Cv.Tt(),null!==this.Pv&&this.Pv.Tt()}Aa(){return null!==this.Ov?this.Ov.Aa():0}La(t){this.Ov&&this.Ov.La(t)}ap(t){if(!this.Ov)return;this.jv();const i=t.localX,s=t.localY;this.Xv(i,s,t)}kp(t){this.jv(),this.Gv(),this.Xv(t.localX,t.localY,t)}_p(t){if(!this.Ov)return;this.jv();const i=t.localX,s=t.localY;this.Xv(i,s,t)}Sp(t){null!==this.Ov&&(this.jv(),this.Kv(t))}sp(t){null!==this.Ov&&this.Zv(this.Fv,t)}Jd(t){this.sp(t)}wp(t){this.jv(),this.Jv(t),this.Xv(t.localX,t.localY,t)}yp(t){null!==this.Ov&&(this.jv(),this.Vv=!1,this.Qv(t))}Mp(t){null!==this.Ov&&this.Kv(t)}Wp(t){if(this.Vv=!0,null===this.Av){const i={x:t.localX,y:t.localY};this.tm(i,i,t)}}Op(t){null!==this.Ov&&(this.jv(),this.Ov.ti().uc(null),this.im())}sm(){return this.Rv}nm(){return this.Fv}Ip(){this.Iv=1,this.ss().ln()}Vp(t,i){if(!this.Of.W().handleScale.pinch)return;const s=5*(i-this.Iv);this.Iv=i,this.ss().xc(t.ut,s)}Pp(t){this.Vv=!1,this.Lv=null!==this.Av,this.Gv();const i=this.ss().fc();null!==this.Av&&i.It()&&(this.Bv={x:i.ni(),y:i.ei()},this.Av={x:t.localX,y:t.localY})}vp(t){if(null===this.Ov)return;const i=t.localX,s=t.localY;if(null!==this.Av){this.Lv=!1;const n=l(this.Bv),e=n.x+(i-this.Av.x),r=n.y+(s-this.Av.y);return void this.Xv(e,r,t)}this.Jv(t)}bp(t){0===this.Jf().W().trackingMode.exitMode&&(this.Lv=!0),this.rm(),this.Qv(t)}Xn(t,i){const s=this.Ov;return null===s?null:Si(s,t,i)}hm(t,i){l("left"===i?this.Cv:this.Pv).dv(os({width:t,height:this.qf.height}))}nf(){return this.qf}dv(t){as(this.qf,t)||(this.qf=t,this.Kf=!0,this.ev.resizeCanvasElement(t),this.rv.resizeCanvasElement(t),this.Kf=!1,this.zv.style.width=t.width+"px",this.zv.style.height=t.height+"px")}lm(){const t=l(this.Ov);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()}ef(){return this.ev.bitmapSize}rf(t,i,s,n){const e=this.ef();if(e.width>0&&e.height>0&&(t.drawImage(this.ev.canvasElement,i,s),n)){const n=this.rv.canvasElement;null!==t&&t.drawImage(n,i,s)}}fv(t){if(0===t)return;if(null===this.Ov)return;t>1&&this.lm(),null!==this.Cv&&this.Cv.fv(t),null!==this.Pv&&this.Pv.fv(t);const i={colorSpace:this.Of.W().layout.colorSpace};if(1!==t){this.ev.applySuggestedBitmapSize();const t=ps(this.ev,i);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mv(t)}),this.Ov&&(this.om(t,Ws),this.am(t),this.om(t,zs),this.om(t,$s)))}this.rv.applySuggestedBitmapSize();const s=ps(this.rv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this._m(s),this.om(s,Hs),this.om(s,$s))}um(){return this.Cv}dm(){return this.Pv}gv(t,i){this.om(t,i)}Wv(){null!==this.Ov&&this.Ov.s_().u(this),this.Ov=null}Kv(t){this.Zv(this.Rv,t)}Zv(t,i){const s=i.localX,n=i.localY;t.v()&&t.p(this.ss().Lt().fu(s),{x:s,y:n},i)}mv({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):B(t,0,0,s,n,r,h)}am(t){const i=l(this.Ov),s=i.n_()._r().Dt(i);null!==s&&s.et(t,!1)}_m(t){this.pm(t,zs,As,this.ss().fc())}om(t,i){const s=l(this.Ov),n=s.Ft(),e=s.e_();for(const s of e)this.pm(t,i,Vs,s);for(const s of n)this.pm(t,i,Vs,s);for(const s of e)this.pm(t,i,As,s);for(const s of n)this.pm(t,i,As,s)}pm(t,i,s,n){const e=l(this.Ov),r=e.ti()._c(),h=null!==r&&r.r_===n,o=null!==r&&h&&void 0!==r.h_?r.h_.Kn:void 0;Ls(i,i=>s(i,t,h,o),n,e)}qv(){if(null===this.Ov)return;const t=this.Of,i=this.Ov.Na().W().visible,s=this.Ov.Ua().W().visible;i||null===this.Cv||(this.$v.removeChild(this.Cv.sf()),this.Cv.m(),this.Cv=null),s||null===this.Pv||(this.Hv.removeChild(this.Pv.sf()),this.Pv.m(),this.Pv=null);const n=t.ti().Lc();i&&null===this.Cv&&(this.Cv=new Os(this,t.W(),n,"left"),this.$v.appendChild(this.Cv.sf())),s&&null===this.Pv&&(this.Pv=new Os(this,t.W(),n,"right"),this.Hv.appendChild(this.Pv.sf()))}fm(t){return t.zp&&this.Vv||null!==this.Av}vm(t){return Math.max(0,Math.min(t,this.qf.width-1))}wm(t){return Math.max(0,Math.min(t,this.qf.height-1))}Xv(t,i,s){this.ss().Fc(this.vm(t),this.wm(i),s,l(this.Ov))}im(){this.ss().Vc()}rm(){this.Lv&&(this.Av=null,this.im())}tm(t,i,s){this.Av=t,this.Lv=!1,this.Xv(i.x,i.y,s);const n=this.ss().fc();this.Bv={x:n.ni(),y:n.ei()}}ss(){return this.Of.ti()}Qv(t){if(!this.Dv)return;const i=this.ss(),s=this.pf();if(i.Ka(s,s.ks()),this.kv=null,this.Dv=!1,i.kc(),null!==this.Ev){const t=performance.now(),s=i.Lt();this.Ev.ae(s.yu(),t),this.Ev.Iu(t)||i.un(this.Ev)}}jv(){this.Av=null}Gv(){if(!this.Ov)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.Ov.ks().Gi()&&this.ss().Lt().Gi()}Jv(t){if(null===this.Ov)return;const i=this.ss(),s=i.Lt();if(s.Gi())return;const n=this.Of.W(),e=n.handleScroll,r=n.kineticScroll;if((!e.pressedMouseMove||t.zp)&&(!e.horzTouchDrag&&!e.vertTouchDrag||!t.zp))return;const h=this.Ov.ks(),l=performance.now();if(null!==this.kv||this.fm(t)||(this.kv={x:t.clientX,y:t.clientY,ud:l,gm:t.localX,bm:t.localY}),null!==this.kv&&!this.Dv&&(this.kv.x!==t.clientX||this.kv.y!==t.clientY)){if(t.zp&&r.touch||!t.zp&&r.mouse){const t=s.bu();this.Ev=new Ds(.2/t,7/t,.997,15/t),this.Ev.If(s.yu(),this.kv.ud)}else this.Ev=null;h.Gi()||i.Xa(this.Ov,h,t.localY),i.Pc(t.localX),this.Dv=!0}this.Dv&&(h.Gi()||i.Ga(this.Ov,h,t.localY),i.Tc(t.localX),null!==this.Ev&&this.Ev.If(s.yu(),l))}}class Us{constructor(t,i,s,n,e){this.xt=!0,this.qf=os({width:0,height:0}),this.Zf=()=>this.fv(3),this.tv="left"===t,this.sc=s.Lc,this.Ps=i,this.Mm=n,this.ym=e,this.Qp=document.createElement("div"),this.Qp.style.width="25px",this.Qp.style.height="100%",this.Qp.style.overflow="hidden",this.ev=Fs(this.Qp,os({width:16,height:16})),this.ev.subscribeSuggestedBitmapSizeChanged(this.Zf)}m(){this.ev.unsubscribeSuggestedBitmapSizeChanged(this.Zf),Is(this.ev.canvasElement),this.ev.dispose()}sf(){return this.Qp}nf(){return this.qf}dv(t){as(this.qf,t)||(this.qf=t,this.ev.resizeCanvasElement(t),this.Qp.style.width=`${t.width}px`,this.Qp.style.height=`${t.height}px`,this.xt=!0)}fv(t){if(t<3&&!this.xt)return;if(0===this.qf.width||0===this.qf.height)return;this.xt=!1,this.ev.applySuggestedBitmapSize();const i=ps(this.ev,{colorSpace:this.Ps.layout.colorSpace});null!==i&&i.useBitmapCoordinateSpace(t=>{this.mv(t),this.wv(t)})}ef(){return this.ev.bitmapSize}rf(t,i,s){const n=this.ef();n.width>0&&n.height>0&&t.drawImage(this.ev.canvasElement,i,s)}wv({context:t,bitmapSize:i,horizontalPixelRatio:s,verticalPixelRatio:n}){if(!this.Mm())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.tv?i.width-e:0;t.fillRect(h,0,e,r)}mv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.ym())}}function qs(t){return i=>i.nl?.(t)??[]}const Ys=qs("normal"),js=qs("top"),Xs=qs("bottom");class Gs{constructor(t,i){this.Sm=null,this.xm=null,this.M=null,this.Cm=!1,this.qf=os({width:0,height:0}),this.Pm=new a,this.jf=new it(5),this.Kf=!1,this.Zf=()=>{this.Kf||this.Of.ti().ar()},this.Qf=()=>{this.Kf||this.Of.ti().ar()},this.Of=t,this.u_=i,this.Ps=t.W().layout,this.Af=document.createElement("tr"),this.Tm=document.createElement("td"),this.Tm.style.padding="0",this.km=document.createElement("td"),this.km.style.padding="0",this.Qp=document.createElement("td"),this.Qp.style.height="25px",this.Qp.style.padding="0",this.Dm=document.createElement("div"),this.Dm.style.width="100%",this.Dm.style.height="100%",this.Dm.style.position="relative",this.Dm.style.overflow="hidden",this.Qp.appendChild(this.Dm),this.ev=Fs(this.Dm,os({width:16,height:16})),this.ev.subscribeSuggestedBitmapSizeChanged(this.Zf);const s=this.ev.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.rv=Fs(this.Dm,os({width:16,height:16})),this.rv.subscribeSuggestedBitmapSizeChanged(this.Qf);const n=this.rv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Af.appendChild(this.Tm),this.Af.appendChild(this.Qp),this.Af.appendChild(this.km),this.Rm(),this.Of.ti().Va().i(this.Rm.bind(this),this),this.qp=new bs(this.rv.canvasElement,this,{pp:()=>!0,fp:()=>!this.Of.W().handleScroll.horzTouchDrag})}m(){this.qp.m(),null!==this.Sm&&this.Sm.m(),null!==this.xm&&this.xm.m(),this.rv.unsubscribeSuggestedBitmapSizeChanged(this.Qf),Is(this.rv.canvasElement),this.rv.dispose(),this.ev.unsubscribeSuggestedBitmapSizeChanged(this.Zf),Is(this.ev.canvasElement),this.ev.dispose()}sf(){return this.Af}Fm(){return this.Sm}Im(){return this.xm}kp(t){if(this.Cm)return;this.Cm=!0;const i=this.Of.ti();!i.Lt().Gi()&&this.Of.W().handleScale.axisPressedMouseMove.time&&i.Sc(t.localX)}Pp(t){this.kp(t)}Dp(){const t=this.Of.ti();!t.Lt().Gi()&&this.Cm&&(this.Cm=!1,this.Of.W().handleScale.axisPressedMouseMove.time&&t.Rc())}wp(t){const i=this.Of.ti();!i.Lt().Gi()&&this.Of.W().handleScale.axisPressedMouseMove.time&&i.Dc(t.localX)}vp(t){this.wp(t)}yp(){this.Cm=!1;const t=this.Of.ti();t.Lt().Gi()&&!this.Of.W().handleScale.axisPressedMouseMove.time||t.Rc()}bp(){this.yp()}sp(){this.Of.W().handleScale.axisDoubleClickReset.time&&this.Of.ti().dn()}Jd(){this.sp()}ap(){this.Of.ti().W().handleScale.axisPressedMouseMove.time&&this.Sv(1)}Op(){this.Sv(0)}nf(){return this.qf}Vm(){return this.Pm}Am(t,i,s){as(this.qf,t)||(this.qf=t,this.Kf=!0,this.ev.resizeCanvasElement(t),this.rv.resizeCanvasElement(t),this.Kf=!1,this.Qp.style.width=`${t.width}px`,this.Qp.style.height=`${t.height}px`,this.Pm.p(t)),null!==this.Sm&&this.Sm.dv(os({width:i,height:t.height})),null!==this.xm&&this.xm.dv(os({width:s,height:t.height}))}Lm(){const t=this.Bm();return Math.ceil(t.S+t.C+t.P+t.L+t.I+t.Em)}Tt(){this.Of.ti().Lt().Il()}ef(){return this.ev.bitmapSize}rf(t,i,s,n){const e=this.ef();if(e.width>0&&e.height>0&&(t.drawImage(this.ev.canvasElement,i,s),n)){const n=this.rv.canvasElement;t.drawImage(n,i,s)}}fv(t){if(0===t)return;const i={colorSpace:this.Ps.colorSpace};if(1!==t){this.ev.applySuggestedBitmapSize();const s=ps(this.ev,i);null!==s&&(s.useBitmapCoordinateSpace(t=>{this.mv(t),this.wv(t),this.Om(s,Xs)}),this.bv(s),this.Om(s,Ys)),null!==this.Sm&&this.Sm.fv(t),null!==this.xm&&this.xm.fv(t)}this.rv.applySuggestedBitmapSize();const s=ps(this.rv,i);null!==s&&(s.useBitmapCoordinateSpace(({context:t,bitmapSize:i})=>{t.clearRect(0,0,i.width,i.height)}),this.Wm([...this.Of.ti().Xs(),this.Of.ti().fc()],s),this.Om(s,js))}Om(t,i){const s=this.Of.ti().Xs();for(const n of s)Ls(i,i=>Vs(i,t,!1,void 0),n,void 0);for(const n of s)Ls(i,i=>As(i,t,!1,void 0),n,void 0)}mv({context:t,bitmapSize:i}){V(t,0,0,i.width,i.height,this.Of.ti().Uc())}wv({context:t,bitmapSize:i,verticalPixelRatio:s}){if(this.Of.W().timeScale.borderVisible){t.fillStyle=this.zm();const n=Math.max(1,Math.floor(this.Bm().S*s));t.fillRect(0,0,i.width,n)}}bv(t){const i=this.Of.ti().Lt(),s=i.Il();if(!s||0===s.length)return;const n=this.u_.maxTickMarkWeight(s),e=this.Bm(),r=i.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:n})=>{t.strokeStyle=this.zm(),t.fillStyle=this.zm();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.L+e.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.N(),t.font=this.uv();for(const e of s)if(e.weight<n){const s=e.needAlignCoordinate?this.$m(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}this.Of.W().timeScale.allowBoldLabels&&(t.font=this.Hm());for(const e of s)if(e.weight>=n){const s=e.needAlignCoordinate?this.$m(t,e.coord,e.label):e.coord;t.fillText(e.label,s,i)}})}$m(t,i,s){const n=this.jf.Ii(t,s),e=n/2,r=Math.floor(i-e)+.5;return r<0?i+=Math.abs(0-r):r+n>this.qf.width&&(i-=Math.abs(this.qf.width-(r+n))),i}Wm(t,i){const s=this.Bm();for(const n of t)for(const t of n.ds())t.Dt().et(i,s)}zm(){return this.Of.W().timeScale.borderColor}N(){return this.Ps.textColor}$(){return this.Ps.fontSize}uv(){return g(this.$(),this.Ps.fontFamily)}Hm(){return g(this.$(),this.Ps.fontFamily,"bold")}Bm(){null===this.M&&(this.M={S:1,B:NaN,L:NaN,I:NaN,Qi:NaN,C:5,P:NaN,T:"",Ji:new it,Em:0});const t=this.M,i=this.uv();if(t.T!==i){const s=this.$();t.P=s,t.T=i,t.L=3*s/12,t.I=3*s/12,t.Qi=9*s/12,t.B=0,t.Em=4*s/12,t.Ji.Vn()}return this.M}Sv(t){this.Qp.style.cursor=1===t?"ew-resize":"default"}Rm(){const t=this.Of.ti(),i=t.W();i.leftPriceScale.visible||null===this.Sm||(this.Tm.removeChild(this.Sm.sf()),this.Sm.m(),this.Sm=null),i.rightPriceScale.visible||null===this.xm||(this.km.removeChild(this.xm.sf()),this.xm.m(),this.xm=null);const s={Lc:this.Of.ti().Lc()},n=()=>i.leftPriceScale.borderVisible&&t.Lt().W().borderVisible,e=()=>t.Uc();i.leftPriceScale.visible&&null===this.Sm&&(this.Sm=new Us("left",i,s,n,e),this.Tm.appendChild(this.Sm.sf())),i.rightPriceScale.visible&&null===this.xm&&(this.xm=new Us("right",i,s,n,e),this.km.appendChild(this.xm.sf()))}}const Ks=!!fs&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!fs&&(navigator?.userAgentData?.platform?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);class Zs{constructor(t,i,s){var n;this.Nm=[],this.Um=[],this.qm=0,this.eo=0,this.ya=0,this.Ym=0,this.jm=0,this.Xm=null,this.Gm=!1,this.Rv=new a,this.Fv=new a,this.Ju=new a,this.Km=null,this.Zm=null,this.Ef=t,this.Ps=i,this.u_=s,this.Af=document.createElement("div"),this.Af.classList.add("tv-lightweight-charts"),this.Af.style.overflow="hidden",this.Af.style.direction="ltr",this.Af.style.width="100%",this.Af.style.height="100%",(n=this.Af).style.userSelect="none",n.style.webkitUserSelect="none",n.style.msUserSelect="none",n.style.MozUserSelect="none",n.style.webkitTapHighlightColor="transparent",this.Jm=document.createElement("table"),this.Jm.setAttribute("cellspacing","0"),this.Af.appendChild(this.Jm),this.Qm=this.tw.bind(this),Js(this.Ps)&&this.iw(!0),this.ss=new Bi(this.tc.bind(this),this.Ps,s),this.ti().vc().i(this.sw.bind(this),this),this.nw=new Gs(this,this.u_),this.Jm.appendChild(this.nw.sf());const e=i.autoSize&&this.ew();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.rw(r,h),this.hw(),t.appendChild(this.Af),this.lw(),this.ss.Lt().Bu().i(this.ss.Lh.bind(this.ss),this),this.ss.Va().i(this.ss.Lh.bind(this.ss),this)}ti(){return this.ss}W(){return this.Ps}Kp(){return this.Nm}ow(){return this.nw}m(){this.iw(!1),0!==this.qm&&window.cancelAnimationFrame(this.qm),this.ss.vc().u(this),this.ss.Lt().Bu().u(this),this.ss.Va().u(this),this.ss.m();for(const t of this.Nm)this.Jm.removeChild(t.sf()),t.sm().u(this),t.nm().u(this),t.m();this.Nm=[];for(const t of this.Um)this.aw(t);this.Um=[],l(this.nw).m(),null!==this.Af.parentElement&&this.Af.parentElement.removeChild(this.Af),this.Ju.m(),this.Rv.m(),this.Fv.m(),this._w()}rw(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 os({width:i-i%2,height:s-s%2})}(os({width:t,height:i}));this.eo=n.height,this.ya=n.width;const e=this.eo+"px",r=this.ya+"px";l(this.Af).style.height=e,l(this.Af).style.width=r,this.Jm.style.height=e,this.Jm.style.width=r,s?this.uw(j.bn(),performance.now()):this.ss.Lh()}fv(t){void 0===t&&(t=j.bn());for(let i=0;i<this.Nm.length;i++)this.Nm[i].fv(t.rn(i).sn);this.Ps.timeScale.visible&&this.nw.fv(t.en())}lr(t){const i=Js(this.Ps);this.ss.lr(t);const s=Js(this.Ps);s!==i&&this.iw(s),t.layout?.panes&&this.cw(),this.lw(),this.dw(t)}sm(){return this.Rv}nm(){return this.Fv}vc(){return this.Ju}pw(t=!1){null!==this.Xm&&(this.uw(this.Xm,performance.now()),this.Xm=null);const i=this.fw(null),s=document.createElement("canvas");s.width=i.width,s.height=i.height;const n=l(s.getContext("2d"));return this.fw(n,t),s}mw(t){if("left"===t&&!this.ww())return 0;if("right"===t&&!this.gw())return 0;if(0===this.Nm.length)return 0;return l("left"===t?this.Nm[0].um():this.Nm[0].dm()).pv()}bw(){return this.Ps.autoSize&&null!==this.Km}lf(){return this.Af}Mw(t){this.Zm=t,this.Zm?this.lf().style.setProperty("cursor",t):this.lf().style.removeProperty("cursor")}yw(){return this.Zm}Sw(t){return h(this.Nm[t]).nf()}cw(){this.Um.forEach(t=>{t.Tt()})}dw(t){(void 0!==t.autoSize||!this.Km||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.Km&&this.ew(),!1===t.autoSize&&null!==this.Km&&this._w(),t.autoSize||void 0===t.width&&void 0===t.height||this.rw(t.width||this.ya,t.height||this.eo))}fw(t,i){let s=0,n=0;const e=this.Nm[0],r=(s,n)=>{let e=0;for(let r=0;r<this.Nm.length;r++){const h=this.Nm[r],o=l("left"===s?h.um():h.dm()),a=o.ef();if(null!==t&&o.rf(t,n,e,i),e+=a.height,r<this.Nm.length-1){const i=this.Um[r],s=i.ef();null!==t&&i.rf(t,n,e),e+=s.height}}};if(this.ww()){r("left",0);s+=l(e.um()).ef().width}for(let e=0;e<this.Nm.length;e++){const r=this.Nm[e],h=r.ef();if(null!==t&&r.rf(t,s,n,i),n+=h.height,e<this.Nm.length-1){const i=this.Um[e],r=i.ef();null!==t&&i.rf(t,s,n),n+=r.height}}if(s+=e.ef().width,this.gw()){r("right",s);s+=l(e.dm()).ef().width}const h=(i,s,n)=>{l("left"===i?this.nw.Fm():this.nw.Im()).rf(l(t),s,n)};if(this.Ps.timeScale.visible){const s=this.nw.ef();if(null!==t){let r=0;this.ww()&&(h("left",r,n),r=l(e.um()).ef().width),this.nw.rf(t,r,n,i),r+=s.width,this.gw()&&h("right",r,n)}n+=s.height}return os({width:s,height:n})}xw(){let t=0,i=0,s=0;for(const n of this.Nm)this.ww()&&(i=Math.max(i,l(n.um())._v(),this.Ps.leftPriceScale.minimumWidth)),this.gw()&&(s=Math.max(s,l(n.dm())._v(),this.Ps.rightPriceScale.minimumWidth)),t+=n.Aa();i=ws(i),s=ws(s);const n=this.ya,e=this.eo,r=Math.max(n-i-s,0),h=1*this.Um.length,o=this.Ps.timeScale.visible;let a=o?Math.max(this.nw.Lm(),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.Nm.length;++t){const n=this.Nm[t];n.Uv(this.ss.qs()[t]);let e=0,h=0;h=t===this.Nm.length-1?Math.ceil((c-p)*f)/f:Math.round(n.Aa()*d*f)/f,e=Math.max(h,2),p+=e,n.dv(os({width:r,height:e})),this.ww()&&n.hm(i,"left"),this.gw()&&n.hm(s,"right"),n.pf()&&this.ss.mc(n.pf(),e)}this.nw.Am(os({width:o?r:0,height:a}),o?i:0,o?s:0),this.ss.Ba(r),this.Ym!==i&&(this.Ym=i),this.jm!==s&&(this.jm=s)}iw(t){t?this.Af.addEventListener("wheel",this.Qm,{passive:!1}):this.Af.removeEventListener("wheel",this.Qm)}Cw(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return Ks?1/window.devicePixelRatio:1}tw(t){if(!(0!==t.deltaX&&this.Ps.handleScroll.mouseWheel||0!==t.deltaY&&this.Ps.handleScale.mouseWheel))return;const i=this.Cw(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.Af.getBoundingClientRect().left;this.ti().xc(s,i)}0!==s&&this.Ps.handleScroll.mouseWheel&&this.ti().Cc(-80*s)}uw(t,i){const s=t.en();3===s&&this.Pw(),3!==s&&2!==s||(this.Tw(t),this.kw(t,i),this.nw.Tt(),this.Nm.forEach(t=>{t.Yv()}),3===this.Xm?.en()&&(this.Xm.mn(t),this.Pw(),this.Tw(this.Xm),this.kw(this.Xm,i),t=this.Xm,this.Xm=null)),this.fv(t)}kw(t,i){for(const s of t.vn())this.wn(s,i)}Tw(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.Lt();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.Xm?this.Xm.mn(t):this.Xm=t,this.Gm||(this.Gm=!0,this.qm=window.requestAnimationFrame(t=>{if(this.Gm=!1,this.qm=0,null!==this.Xm){const i=this.Xm;this.Xm=null,this.uw(i,t);for(const s of i.vn())if(5===s.an&&!s.Ht.Iu(t)){this.ti().un(s.Ht);break}}}))}Pw(){this.hw()}aw(t){this.Jm.removeChild(t.sf()),t.m()}hw(){const t=this.ss.qs(),i=t.length,s=this.Nm.length;for(let t=i;t<s;t++){const t=h(this.Nm.pop());this.Jm.removeChild(t.sf()),t.sm().u(this),t.nm().u(this),t.m();const i=this.Um.pop();void 0!==i&&this.aw(i)}for(let n=s;n<i;n++){const i=new Ns(this,t[n]);if(i.sm().i(this.Dw.bind(this,i),this),i.nm().i(this.Rw.bind(this,i),this),this.Nm.push(i),n>0){const t=new Ps(this,n-1,n);this.Um.push(t),this.Jm.insertBefore(t.sf(),this.nw.sf())}this.Jm.insertBefore(i.sf(),this.nw.sf())}for(let s=0;s<i;s++){const i=t[s],n=this.Nm[s];n.pf()!==i?n.Uv(i):n.Nv()}this.lw(),this.xw()}Fw(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.Lt().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.Iw(n);return{Vw:r,Re:t??void 0,Aw:i??void 0,Lw:-1!==a?a:void 0,Bw:l,Ew:e,Ow:o,Ww:s??void 0}}Iw(t){let i=-1;if(t)i=this.Nm.indexOf(t);else{const t=this.ti().fc().Us();null!==t&&(i=this.ti().qs().indexOf(t))}return i}Dw(t,i,s,n){this.Rv.p(()=>this.Fw(i,s,n,t))}Rw(t,i,s,n){this.Fv.p(()=>this.Fw(i,s,n,t))}sw(t,i,s){this.Mw(this.ti()._c()?.o_??null),this.Ju.p(()=>this.Fw(t,i,s))}lw(){const t=this.Ps.timeScale.visible?"":"none";this.nw.sf().style.display=t}ww(){return this.Nm[0].pf().Na().W().visible}gw(){return this.Nm[0].pf().Ua().W().visible}ew(){return"ResizeObserver"in window&&(this.Km=new ResizeObserver(t=>{const i=t[t.length-1];i&&this.rw(i.contentRect.width,i.contentRect.height)}),this.Km.observe(this.Ef,{box:"border-box"}),!0)}_w(){null!==this.Km&&this.Km.disconnect(),this.Km=null}}function Js(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function Qs(t){return void 0===t.open&&void 0===t.value}function tn(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}function sn(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Vw:n};return void 0!==s.color&&(r.R=s.color),r}function nn(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Vw: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 en(t,i,s,n){const e=s.value,r={Re:i,gt:t,Ht:[e,e,e,e],Vw: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 rn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Vw:n};return void 0!==s.color&&(e.R=s.color),e}function hn(t,i,s,n){const e={Re:i,gt:t,Ht:[s.open,s.high,s.low,s.close],Vw: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 ln(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:_,Vw:n,ne:d,R:c}}function on(t){return void 0!==t.Ht}function an(t,i){return void 0!==i.customValues&&(t.zw=i.customValues),t}function _n(t){return(i,s,n,e,r,h)=>function(t,i){return i?i(t):Qs(t)}(n,h)?an({gt:i,Re:s,Vw:e},n):an(t(i,s,n,e,r),n)}function un(t){return{Candlestick:_n(hn),Bar:_n(rn),Area:_n(nn),Baseline:_n(en),Histogram:_n(sn),Line:_n(sn),Custom:_n(ln)}[t]}function cn(t){return{Re:0,$w:new Map,Uh:t}}function dn(t,i){if(void 0!==t&&0!==t.length)return{Hw:i.key(t[0].gt),Nw:i.key(t[t.length-1].gt)}}function pn(t){let i;return t.forEach(t=>{void 0===i&&(i=t.Vw)}),h(i)}class fn{constructor(t){this.Uw=new Map,this.qw=new Map,this.Yw=new Map,this.jw=[],this.u_=t}Xw(){return this.u_.fillWeightsForPoints(this.jw,0),this.jw}m(){this.Uw.clear(),this.qw.clear(),this.Yw.clear(),this.jw=[]}Gw(t,i){let s=0!==this.Uw.size,n=!1;const e=this.qw.get(t);if(void 0!==e)if(1===this.qw.size)s=!1,n=!0,this.Uw.clear();else for(const i of this.jw)i.pointData.$w.delete(t)&&(n=!0);let r=[];if(0!==i.length){const s=i.map(t=>t.time),e=this.u_.createConverterToInternalObj(i),h=un(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.Uw.get(_);void 0===u&&(u=cn(a),this.Uw.set(_,u),n=!0);const c=h(a,u.Re,i,s[r],l,o);return u.$w.set(t,c),c})}s&&this.Kw(),this.Zw(t,r);let h=-1;if(n){const t=[];this.Uw.forEach(i=>{t.push({timeWeight:0,time:i.Uh,pointData:i,originalTime:pn(i.$w)})}),t.sort((t,i)=>this.u_.key(t.time)-this.u_.key(i.time)),h=this.Jw(t)}return this.Qw(t,h,function(t,i,s){const n=dn(t,s),e=dn(i,s);if(void 0!==n&&void 0!==e)return{tg:!1,Oh:n.Nw>=e.Nw&&n.Hw>=e.Hw}}(this.qw.get(t),e,this.u_))}Oc(t){return this.Gw(t,[])}ig(t,i,s){const n=i;!function(t){void 0===t.Vw&&(t.Vw=t.time)}(n),this.u_.preprocessData(i);const e=this.u_.createConverterToInternalObj([i])(i.time),r=this.Yw.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.Uw.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=cn(e),this.Uw.set(this.u_.key(e),h));const o=un(t.Rr()),a=t.pl(),_=t.vl(),u=o(e,h.Re,i,n.Vw,a,_);h.$w.set(t,u),s?this.sg(t,u,h.Re):this.ng(t,u);const c={Oh:on(u),tg:s};if(!l)return this.Qw(t,-1,c);const d={timeWeight:0,time:h.Uh,pointData:h,originalTime:pn(h.$w)},p=yt(this.jw,this.u_.key(d.time),(t,i)=>this.u_.key(t.time)<i);this.jw.splice(p,0,d);for(let t=p;t<this.jw.length;++t)vn(this.jw[t].pointData,t);return this.u_.fillWeightsForPoints(this.jw,p),this.Qw(t,p,c)}eg(t,i){const s=this.qw.get(t);if(void 0===s||i<=0)return[[],this.rg()];i=Math.min(i,s.length);const n=s.splice(-i).reverse();0===s.length?this.Yw.delete(t):this.Yw.set(t,s[s.length-1].gt);for(const i of n){const s=this.Uw.get(this.u_.key(i.gt));if(s&&(s.$w.delete(t),0===s.$w.size)){this.Uw.delete(this.u_.key(s.Uh)),this.jw.splice(s.Re,1);for(let t=s.Re;t<this.jw.length;++t)vn(this.jw[t].pointData,t)}}return[n,this.Qw(t,this.jw.length-1,{tg:!1,Oh:!1})]}ng(t,i){let s=this.qw.get(t);void 0===s&&(s=[],this.qw.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)?on(i)&&s.push(i):on(i)?s[s.length-1]=i:s.splice(-1,1),this.Yw.set(t,i.gt)}sg(t,i,s){const n=this.qw.get(t);if(void 0===n)return;const e=yt(n,s,(t,i)=>t.Re<i);on(i)?n[e]=i:n.splice(e,1)}Zw(t,i){0!==i.length?(this.qw.set(t,i.filter(on)),this.Yw.set(t,i[i.length-1].gt)):(this.qw.delete(t),this.Yw.delete(t))}Kw(){for(const t of this.jw)0===t.pointData.$w.size&&this.Uw.delete(this.u_.key(t.time))}Jw(t){let i=-1;for(let s=0;s<this.jw.length&&s<t.length;++s){const n=this.jw[s],e=t[s];if(this.u_.key(n.time)!==this.u_.key(e.time)){i=s;break}e.timeWeight=n.timeWeight,vn(e.pointData,s)}if(-1===i&&this.jw.length!==t.length&&(i=Math.min(this.jw.length,t.length)),-1===i)return-1;for(let s=i;s<t.length;++s)vn(t[s].pointData,s);return this.u_.fillWeightsForPoints(t,i),this.jw=t,i}hg(){if(0===this.qw.size)return null;let t=0;return this.qw.forEach(i=>{0!==i.length&&(t=Math.max(t,i[i.length-1].Re))}),t}Qw(t,i,s){const n=this.rg();if(-1!==i)this.qw.forEach((i,e)=>{n.za.set(e,{ne:i,lg:e===t?s:void 0})}),this.qw.has(t)||n.za.set(t,{ne:[],lg:s}),n.Lt.og=this.jw,n.Lt.ag=i;else{const i=this.qw.get(t);n.za.set(t,{ne:i||[],lg:s})}return n}rg(){return{za:new Map,Lt:{du:this.hg()}}}}function vn(t,i){t.Re=i,t.$w.forEach(t=>{t.Re=i})}function mn(t,i){return t.gt<i}function wn(t,i){return i<t.gt}function gn(t,i,s){const n=i.qh(),e=i.yi(),r=yt(t,n,mn),h=St(t,e,wn);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 bn{constructor(t,i,s){this._g=!0,this.ug=!0,this.cg=!0,this.dg=[],this.pg=null,this.Qn=t,this.te=i,this.fg=s}Tt(t){this._g=!0,"data"===t&&(this.ug=!0),"options"===t&&(this.cg=!0)}Dt(){return this.Qn.It()?(this.vg(),null===this.pg?null:this.mg):null}wg(){const t=this.Qn.Fh();this.dg=this.dg.map(i=>{const s=t.Ir(i.gt);return null===s?i:{...i,...s}})}gg(){this.pg=null}vg(){this.ug&&(this.bg(),this.ug=!1),this.cg&&(this.wg(),this.cg=!1),this._g&&(this.Mg(),this._g=!1)}Mg(){const t=this.Qn.$t(),i=this.te.Lt();if(this.gg(),i.Gi()||t.Gi())return;const s=i.Pe();if(null===s)return;if(0===this.Qn.Ks().Or())return;const n=this.Qn.Et();null!==n&&(this.pg=gn(this.dg,s,this.fg),this.yg(t,i,n.Ht),this.Sg())}}class Mn{constructor(t,i){this.xg=t,this.ji=i}et(t,i,s){this.xg.draw(t,this.ji,i,s)}}class yn extends bn{constructor(t,i,s){super(t,i,!1),this.eh=s,this.mg=new Mn(this.eh.renderer(),i=>{const s=t.Et();return null===s?null:t.$t().zt(i,s.Ht)})}fl(t){return this.eh.priceValueBuilder(t)}ml(t){return this.eh.isWhitespace(t)}bg(){const t=this.Qn.Fh();this.dg=this.Qn.Ks().Ur().map(i=>({gt:i.Re,ut:NaN,...t.Fr(i.Re,{Ht:i}),Cg:i.ne}))}yg(t,i){i.pu(this.dg,m(this.pg))}Sg(){this.eh.update({bars:this.dg.map(Sn),barSpacing:this.te.Lt().bu(),visibleRange:this.pg},this.Qn.W())}}function Sn(t){return{x:t.ut,time:t.gt,originalData:t.Cg,barColor:t.dr}}const xn={color:"#2196f3"},Cn=(t,i,s)=>{const n=o(s);return new yn(t,i,n)};function Pn(t){const i={value:t.Ht[3],time:t.Vw};return void 0!==t.zw&&(i.customValues=t.zw),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);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 Dn(t){const i=Pn(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 Rn(t){const i={open:t.Ht[0],high:t.Ht[1],low:t.Ht[2],close:t.Ht[3],time:t.Vw};return void 0!==t.zw&&(i.customValues=t.zw),i}function Fn(t){const i=Rn(t);return void 0!==t.R&&(i.color=t.R),i}function In(t){const i=Rn(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 Vn(t){return{Area:kn,Line:Tn,Baseline:Dn,Histogram:Tn,Bar:Fn,Candlestick:In,Custom:An}[t]}function An(t){const i=t.Vw;return{...t.ne,time:i}}const Ln={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},Bn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},En={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:[]},On={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},Wn={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 zn(){return{addDefaultPane:!0,width:0,height:0,autoSize:!1,layout:En,crosshair:Ln,grid:Bn,overlayPriceScales:{...On},leftPriceScale:{...On,visible:!1},rightPriceScale:{...On,visible:!0},timeScale:Wn,localization:{locale:fs?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 $n{constructor(t,i,s){this.Xp=t,this.Pg=i,this.Tg=s??0}applyOptions(t){this.Xp.ti().cc(this.Pg,t,this.Tg)}options(){return this.ji().W()}width(){return Y(this.Pg)?this.Xp.mw(this.Pg):0}setVisibleRange(t){this.setAutoScale(!1),this.ji().Uo(new dt(t.from,t.to))}getVisibleRange(){let t,i,s=this.ji().tr();if(null===s)return null;if(this.ji().io()){const n=this.ji().ma(),e=Ei(n);s=oi(s,this.ji().no()),t=Number((Math.round(s.qe()/n)*n).toFixed(e)),i=Number((Math.round(s.Ye()/n)*n).toFixed(e))}else t=s.qe(),i=s.Ye();return{from:t,to:i}}setAutoScale(t){this.applyOptions({autoScale:t})}ji(){return l(this.Xp.ti().dc(this.Pg,this.Tg)).$t}}class Hn{constructor(t,i,s,n){this.Xp=t,this.Pt=s,this.kg=i,this.Dg=n}getHeight(){return this.Pt.qt()}setHeight(t){const i=this.Xp.ti(),s=i.Yc(this.Pt);i.gc(s,t)}getStretchFactor(){return this.Pt.Aa()}setStretchFactor(t){this.Pt.La(t),this.Xp.ti().Lh()}paneIndex(){return this.Xp.ti().Yc(this.Pt)}moveTo(t){const i=this.paneIndex();i!==t&&(r(t>=0&&t<this.Xp.Kp().length,"Invalid pane index"),this.Xp.ti().Mc(i,t))}getSeries(){return this.Pt.za().map(t=>this.kg(t))??[]}getHTMLElement(){const t=this.Xp.Kp();return t&&0!==t.length&&t[this.paneIndex()]?t[this.paneIndex()].sf():null}attachPrimitive(t){this.Pt.cl(t),t.attached&&t.attached({chart:this.Dg,requestUpdate:()=>this.Pt.ti().Lh()})}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 $n(this.Xp,t,this.paneIndex())}setPreserveEmptyPane(t){this.Pt.Oa(t)}preserveEmptyPane(){return this.Pt.Wa()}addCustomSeries(t,i={},s=0){return this.Dg.addCustomSeries(t,i,s)}addSeries(t,i={}){return this.Dg.addSeries(t,i,this.paneIndex())}}const Nn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Un{constructor(t){this.sr=t}applyOptions(t){this.sr.lr(t)}options(){return this.sr.W()}Rg(){return this.sr}}class qn{constructor(t,i,s,n,e,r){this.Fg=new a,this.Qn=t,this.Ig=i,this.Vg=s,this.u_=e,this.Dg=n,this.Ag=r}m(){this.Fg.m()}priceFormatter(){return this.Qn.hl()}priceToCoordinate(t){const i=this.Qn.Et();return null===i?null:this.Qn.$t().zt(t,i.Ht)}coordinateToPrice(t){const i=this.Qn.Et();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.Vw,o.to=e.Vw),o}setData(t){this.u_,this.Qn.Rr(),this.Ig.Lg(this.Qn,t),this.Bg("full")}update(t,i=!1){this.Qn.Rr(),this.Ig.Eg(this.Qn,t,i),this.Bg("update")}pop(t=1){const i=this.Ig.Og(this.Qn,t);0!==i.length&&this.Bg("update");const s=Vn(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 Vn(this.seriesType())(s)}data(){const t=Vn(this.seriesType());return this.Qn.Ks().Ur().map(i=>t(i))}subscribeDataChanged(t){this.Fg.i(t)}unsubscribeDataChanged(t){this.Fg._(t)}applyOptions(t){this.Qn.lr(t)}options(){return f(this.Qn.W())}priceScale(){return this.Vg.priceScale(this.Qn.$t().gl(),this.getPane().paneIndex())}createPriceLine(t){const i=_(f(Nn),t),s=this.Qn.zh(i);return new Un(s)}removePriceLine(t){this.Qn.$h(t.Rg())}priceLines(){return this.Qn.Hh().map(t=>new Un(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.Dg,series:this,requestUpdate:()=>this.Qn.ti().Lh(),horzScaleBehavior:this.u_})}detachPrimitive(t){this.Qn.dl(t),t.detached&&t.detached(),this.Qn.ti().Lh()}getPane(){const t=this.Qn,i=l(this.Qn.ti().Nn(t));return this.Ag(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)}Bg(t){this.Fg.v()&&this.Fg.p(t)}}class Yn{constructor(t,i,s){this.Wg=new a,this.W_=new a,this.Pm=new a,this.ss=t,this.ph=t.Lt(),this.nw=i,this.ph.Au().i(this.zg.bind(this)),this.ph.Lu().i(this.$g.bind(this)),this.nw.Vm().i(this.Hg.bind(this)),this.u_=s}m(){this.ph.Au().u(this),this.ph.Lu().u(this),this.nw.Vm().u(this),this.Wg.m(),this.W_.m(),this.Pm.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.Lt();return i.Gi()?null:i.Yt(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.Yt(i)}coordinateToTime(t){const i=this.ss.Lt(),s=i.fu(t),n=i.ns(s);return null===n?null:n.originalTime}width(){return this.nw.nf().width}height(){return this.nw.nf().height}subscribeVisibleTimeRangeChange(t){this.Wg.i(t)}unsubscribeVisibleTimeRangeChange(t){this.Wg._(t)}subscribeVisibleLogicalRangeChange(t){this.W_.i(t)}unsubscribeVisibleLogicalRangeChange(t){this.W_._(t)}subscribeSizeChange(t){this.Pm.i(t)}unsubscribeSizeChange(t){this.Pm._(t)}applyOptions(t){this.ph.lr(t)}options(){return{...f(this.ph.W()),barSpacing:this.ph.bu()}}zg(){this.Wg.v()&&this.Wg.p(this.getVisibleRange())}$g(){this.W_.v()&&this.W_.p(this.getVisibleLogicalRange())}Hg(t){this.Pm.p(t.width,t.height)}}function jn(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 Xn{constructor(t,i,s){this.Ng=new Map,this.Ug=new Map,this.qg=new a,this.Yg=new a,this.jg=new a,this.Xu=new WeakMap,this.Xg=new fn(i);const n=void 0===s?f(zn()):_(f(zn()),jn(s));this.Gg=i,this.Xp=new Zs(t,n,i),this.Xp.sm().i(t=>{this.qg.v()&&this.qg.p(this.Kg(t()))},this),this.Xp.nm().i(t=>{this.Yg.v()&&this.Yg.p(this.Kg(t()))},this),this.Xp.vc().i(t=>{this.jg.v()&&this.jg.p(this.Kg(t()))},this);const e=this.Xp.ti();this.Zg=new Yn(e,this.Xp.ow(),this.Gg)}remove(){this.Xp.sm().u(this),this.Xp.nm().u(this),this.Xp.vc().u(this),this.Zg.m(),this.Xp.m(),this.Ng.clear(),this.Ug.clear(),this.qg.m(),this.Yg.m(),this.jg.m(),this.Xg.m()}resize(t,i,s){this.autoSizeActive()||this.Xp.rw(t,i,s)}addCustomSeries(t,i={},s=0){const n=(t=>({type:"Custom",isBuiltIn:!1,defaultOptions:{...xn,...t.defaultOptions()},Jg:Cn,Qg:t}))(o(t));return this.tb(n,i,s)}addSeries(t,i={},s=0){return this.tb(t,i,s)}removeSeries(t){const i=h(this.Ng.get(t)),s=this.Xg.Oc(i);this.Xp.ti().Oc(i),this.ib(s),this.Ng.delete(t),this.Ug.delete(i)}Lg(t,i){this.ib(this.Xg.Gw(t,i))}Eg(t,i,s){this.ib(this.Xg.ig(t,i,s))}Og(t,i){const[s,n]=this.Xg.eg(t,i);return 0!==s.length&&this.ib(n),s}subscribeClick(t){this.qg.i(t)}unsubscribeClick(t){this.qg._(t)}subscribeCrosshairMove(t){this.jg.i(t)}unsubscribeCrosshairMove(t){this.jg._(t)}subscribeDblClick(t){this.Yg.i(t)}unsubscribeDblClick(t){this.Yg._(t)}priceScale(t,i=0){return new $n(this.Xp,t,i)}timeScale(){return this.Zg}applyOptions(t){const i=this.options().localization.timeZone;if(this.Xp.lr(jn(t)),this.options().localization.timeZone!==i){const t=this.Xp.ti();t.Lt().Tt(this.Xg.Xw(),0),t.Lh()}}options(){return this.Xp.W()}takeScreenshot(t=!1,i=!1){let s,n;try{i||(s=this.Xp.ti().W().crosshair.mode,this.Xp.lr({crosshair:{mode:2}})),n=this.Xp.pw(t)}finally{i||void 0===s||this.Xp.ti().lr({crosshair:{mode:s}})}return n}addPane(t=!1){const i=this.Xp.ti().jc();return i.Oa(t),this.sb(i)}removePane(t){this.Xp.ti().wc(t)}swapPanes(t,i){this.Xp.ti().bc(t,i)}autoSizeActive(){return this.Xp.bw()}chartElement(){return this.Xp.lf()}panes(){return this.Xp.ti().qs().map(t=>this.sb(t))}paneSize(t=0){const i=this.Xp.Sw(t);return{height:i.height,width:i.width}}setCrosshairPosition(t,i,s){const n=this.Ng.get(s);if(void 0===n)return;const e=this.Xp.ti().Nn(n);null!==e&&this.Xp.ti().Ic(t,i,e)}clearCrosshairPosition(){this.Xp.ti().Vc(!0)}horzBehaviour(){return this.Gg}tb(i,s={},n=0){r(void 0!==i.Jg),function(t){if(void 0===t||"custom"===t.type)return;const i=t;void 0!==i.minMove&&void 0===i.precision&&(i.precision=Ei(i.minMove))}(s.priceFormat),"Candlestick"===i.type&&function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(s);const e=_(f(t),f(i.defaultOptions),s),h=i.Jg,l=new Ut(this.Xp.ti(),i.type,e,h,i.Qg);this.Xp.ti().Bc(l,n);const o=new qn(l,this,this,this,this.Gg,t=>this.sb(t));return this.Ng.set(o,l),this.Ug.set(l,o),o}ib(t){const i=this.Xp.ti();i.Ac(t.Lt.du,t.Lt.og,t.Lt.ag),t.za.forEach((t,i)=>i.lt(t.ne,t.lg)),i.Lt().Z_(),i.gu()}nb(t){return h(this.Ug.get(t))}Kg(t){const i=new Map;t.Ew.forEach((t,s)=>{const n=s.Rr(),e=Vn(n)(t);if("Custom"!==n)r(tn(e));else{const t=s.vl();r(!t||!1===t(e))}i.set(this.nb(s),e)});const s=void 0!==t.Bw&&this.Ug.has(t.Bw)?this.nb(t.Bw):void 0;return{time:t.Vw,logical:t.Re,point:t.Aw,paneIndex:t.Lw,hoveredSeries:s,hoveredObjectId:t.Ow,seriesData:i,sourceEvent:t.Ww}}sb(t){let i=this.Xu.get(t);return i||(i=new Hn(this.Xp,t=>this.nb(t),t,this),this.Xu.set(t,i)),i}}function Gn(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 Kn(t,i,s){const n=Gn(t),e=new Xn(n,i,s);return i.setOptions(e.options()),e}function Zn(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,eb:n.time-h.time}}function Jn(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=Zn(t,i);if(null===h)return null;const l=r-h.Kl;return Math.round(h.gt+l*h.eb)}function Qn(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=Zn(t,i);if(null===r)return null;const h=r.Kl+(s-r.gt)/r.eb,l=n.logicalToCoordinate(h);return null===l?null:l}class te extends bn{constructor(t,i){super(t,i,!0)}yg(t,i,s){i.pu(this.dg,m(this.pg)),t.jo(this.dg,s,m(this.pg))}rb(t,i){return{gt:t,bt:i,ut:NaN,ct:NaN}}bg(){const t=this.Qn.Fh();this.dg=this.Qn.Ks().Ur().map(i=>{const s=i.Ht[3];return this.hb(i.Re,s,t,i)})}}function ie(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]=re(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 se=6;function ne(t,i){return{ut:t.ut-i.ut,ct:t.ct-i.ct}}function ee(t,i){return{ut:t.ut/i,ct:t.ct/i}}function re(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=ee(ne(t[s],t[n]),se),{ut:r.ut+h.ut,ct:r.ct+h.ct}),ne(t[s],ee(ne(t[e],t[i]),se))]}function he(t,i){const s=t.context;s.strokeStyle=i,s.stroke()}class le 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,lb:e,ob:r,dt:h,Kt:l,ab: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._b.bind(this);void 0!==r&&ie(t,i,r,s,e,_,he),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 oe extends le{_b(t,i){return i.wt}}class ae extends te{constructor(){super(...arguments),this.mg=new oe}hb(t,i,s,n){return{...this.rb(t,i),...s.Fr(t,{Ht:n})}}Sg(){const t=this.Qn.W(),i={_t:this.dg,Kt:t.lineStyle,ob:t.lineVisible?t.lineType:void 0,dt:t.lineWidth,ab:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,ot:this.pg,lb:this.te.Lt().bu()};this.mg.lt(i)}}const _e={type:"Line",isBuiltIn:!0,defaultOptions:{color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Jg:(t,i)=>new ae(t,i)};function ue(t,i){return t.weight>i.weight?t:i}function ce(t){return t}class de{constructor(){this.ub=new a,this.cb=function(t){let i=!1;return function(...s){i||(i=!0,queueMicrotask(()=>{t(...s),i=!1}))}}(()=>this.ub.p(this.pb)),this.pb=0}fb(){return this.ub}m(){this.ub.m()}options(){return this.Ps}setOptions(t){this.Ps=t}preprocessData(t){}updateFormatter(t){this.Ps&&(this.Ps.localization=t)}createConverterToInternalObj(t){return this.cb(),t=>(t>this.pb&&(this.pb=t),t)}key(t){return t}cacheKey(t){return t}convertHorzItemToInternal(t){return t}formatHorzItem(t){return this.mb(t)}formatTickmark(t){return this.mb(t.time)}maxTickMarkWeight(t){return t.reduce(ue,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(ce(t[n].time));this.pb=t[t.length-1].time,this.cb()}mb(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 pe={yieldCurve:{baseResolution:1,minimumTimeRange:120,startTimeRange:0},timeScale:{ignoreWhitespaceIndices:!0},leftPriceScale:{visible:!0},rightPriceScale:{visible:!1},localization:{priceFormatter:t=>t.toFixed(3)+"%"}},fe={lastValueVisible:!1,priceLineVisible:!1};class ve extends Xn{constructor(t,i){const s=_(pe,i||{}),n=new de;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={...fe,...i};return super.addSeries(t,n,s)}_initWhitespaceSeries(){const t=this.horzBehaviour(),i=this.addSeries(_e);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),wb:Math.max(1,t.baseResolution)}}(t.options().yieldCurve,n),r=(({ae:t,_e:i,wb:s})=>`${t}~${i}~${s}`)(e);r!==s&&(s=r,i.setData(function({ae:t,_e:i,wb:s}){return Array.from({length:Math.floor((i-t)/s)+1},(i,n)=>({time:t+n*s}))}(e)))}n(0),t.fb().i(n)}}function me(t,i){return t.weight>i.weight?t:i}class we{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(me,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 ge(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 be 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,lb:e,dt:r,Kt:h,ob:l}=this.ht,o=this.ht.gb??(this.ht.bb?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,ie(t,i,l,s,e,this.Mb.bind(this),ge.bind(null,o))}}class Me{yb(t,i){const s=this.Sb,{xb:n,Cb:e,Pb:r,Tb:h,gb:l,kb:o,Db:a}=i;if(void 0===this.Rb||void 0===s||s.xb!==n||s.Cb!==e||s.Pb!==r||s.Tb!==h||s.gb!==l||s.kb!==o||s.Db!==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.Rb=p,this.Sb=i}return this.Rb}}class ye extends be{constructor(){super(...arguments),this.Fb=new Me}Mb(t,i){const s=this.ht;return this.Fb.yb(t,{xb:i.yr,Cb:i.Sr,Pb:i.Cr,Tb:i.Pr,gb:s.gb,kb:s.kb??0,Db:s.Db??t.bitmapSize.height})}}class Se extends le{constructor(){super(...arguments),this.Ib=new Me}_b(t,i){const s=this.ht;return this.Ib.yb(t,{xb:i.br,Cb:i.br,Pb:i.Mr,Tb:i.Mr,gb:s.gb,kb:s.kb??0,Db:s.Db??t.bitmapSize.height})}}class xe extends te{constructor(t,i){super(t,i),this.mg=new x,this.Vb=new ye,this.Ab=new Se,this.mg.nt([this.Vb,this.Ab])}hb(t,i,s,n){return{...this.rb(t,i),...s.Fr(t,{Ht:n})}}Sg(){const t=this.Qn.Et();if(null===t)return;const i=this.Qn.W(),s=this.Qn.$t().zt(i.baseValue.price,t.Ht),n=this.te.Lt().bu();if(null===this.pg||0===this.dg.length)return;let e,r;if(i.relativeGradient){e=this.dg[this.pg.from].ct,r=this.dg[this.pg.from].ct;for(let t=this.pg.from;t<this.pg.to;t++){const i=this.dg[t];i.ct<e&&(e=i.ct),i.ct>r&&(r=i.ct)}}this.Vb.lt({_t:this.dg,dt:i.lineWidth,Kt:i.lineStyle,ob:i.lineType,gb:s,kb:e,Db:r,bb:!1,ot:this.pg,lb:n}),this.Ab.lt({_t:this.dg,dt:i.lineWidth,Kt:i.lineStyle,ob:i.lineVisible?i.lineType:void 0,ab:i.pointMarkersVisible?i.pointMarkersRadius||i.lineWidth/2+2:void 0,gb:s,kb:e,Db:r,ot:this.pg,lb:n})}}const Ce={type:"Baseline",isBuiltIn:!0,defaultOptions:{baseValue:{type:"price",price:0},relativeGradient:!1,topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Jg:(t,i)=>new xe(t,i)};class Pe extends be{constructor(){super(...arguments),this.Fb=new Me}Mb(t,i){return this.Fb.yb(t,{xb:i.wr,Cb:"",Pb:"",Tb:i.gr,kb:this.ht?.kb??0,Db:t.bitmapSize.height})}}class Te extends te{constructor(t,i){super(t,i),this.mg=new x,this.Lb=new Pe,this.Bb=new oe,this.mg.nt([this.Lb,this.Bb])}hb(t,i,s,n){return{...this.rb(t,i),...s.Fr(t,{Ht:n})}}Sg(){const t=this.Qn.W();if(null===this.pg||0===this.dg.length)return;let i;if(t.relativeGradient){i=this.dg[this.pg.from].ct;for(let t=this.pg.from;t<this.pg.to;t++){const s=this.dg[t];s.ct<i&&(i=s.ct)}}this.Lb.lt({ob:t.lineType,_t:this.dg,Kt:t.lineStyle,dt:t.lineWidth,gb:null,kb:i,bb:t.invertFilledArea,ot:this.pg,lb:this.te.Lt().bu()}),this.Bb.lt({ob:t.lineVisible?t.lineType:void 0,_t:this.dg,Kt:t.lineStyle,dt:t.lineWidth,ot:this.pg,lb:this.te.Lt().bu(),ab:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}const ke={type:"Area",isBuiltIn:!0,defaultOptions:{topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,relativeGradient:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},Jg:(t,i)=>new Te(t,i)};class De extends C{constructor(){super(...arguments),this.jt=null,this.Eb=0,this.Ob=0}lt(t){this.jt=t}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.jt||0===this.jt.Ks.length||null===this.jt.ot)return;if(this.Eb=this.Wb(i),this.Eb>=2){Math.max(1,Math.floor(i))%2!=this.Eb%2&&this.Eb--}this.Ob=this.jt.zb?Math.min(this.Eb,Math.floor(i)):this.Eb;let n=null;const e=this.Ob<=this.Eb&&this.jt.bu>=Math.floor(1.5*i);for(let r=this.jt.ot.from;r<this.jt.ot.to;++r){const h=this.jt.Ks[r];n!==h.dr&&(t.fillStyle=h.dr,n=h.dr);const l=Math.floor(.5*this.Ob),o=Math.round(h.ut*i),a=o-l,_=this.Ob,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.Ob);t.fillRect(a,p,_,v);const m=Math.ceil(1.5*this.Eb);if(e){if(this.jt.$b){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)}}}Wb(t){const i=Math.floor(t);return Math.max(i,Math.floor(function(t,i){return Math.floor(.3*t*i)}(l(this.jt).bu,t)))}}class Re extends bn{constructor(t,i){super(t,i,!1)}yg(t,i,s){i.pu(this.dg,m(this.pg)),t.Go(this.dg,s,m(this.pg))}Hb(t,i,s){return{gt:t,jh: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}}bg(){const t=this.Qn.Fh();this.dg=this.Qn.Ks().Ur().map(i=>this.hb(i.Re,i,t))}}class Fe extends Re{constructor(){super(...arguments),this.mg=new De}hb(t,i,s){return{...this.Hb(t,i,s),...s.Fr(t,{Ht:i})}}Sg(){const t=this.Qn.W();this.mg.lt({Ks:this.dg,bu:this.te.Lt().bu(),$b:t.openVisible,zb:t.thinBars,ot:this.pg})}}const Ie={type:"Bar",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},Jg:(t,i)=>new Fe(t,i)};class Ve extends C{constructor(){super(...arguments),this.jt=null,this.Eb=0}lt(t){this.jt=t}rt(t){if(null===this.jt||0===this.jt.Ks.length||null===this.jt.ot)return;const{horizontalPixelRatio:i}=t;if(this.Eb=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.jt.bu,i),this.Eb>=2){Math.floor(i)%2!=this.Eb%2&&this.Eb--}const s=this.jt.Ks;this.jt.Nb&&this.Ub(t,s,this.jt.ot),this.jt.Mi&&this.wv(t,s,this.jt.ot);const n=this.qb(i);(!this.jt.Mi||this.Eb>2*n)&&this.Yb(t,s,this.jt.ot)}Ub(t,i,s){if(null===this.jt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="",l=Math.min(Math.floor(e),Math.floor(this.jt.bu*e));l=Math.max(Math.floor(e),Math.min(l,this.Eb));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}}qb(t){let i=Math.floor(1*t);this.Eb<=2*i&&(i=Math.floor(.5*(this.Eb-1)));const s=Math.max(Math.floor(t),i);return this.Eb<=2*s?Math.max(Math.floor(t),Math.floor(1*t)):s}wv(t,i,s){if(null===this.jt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.qb(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.Eb);const _=a+this.Eb-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.jt.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=_}}Yb(t,i,s){if(null===this.jt)return;const{context:n,horizontalPixelRatio:e,verticalPixelRatio:r}=t;let h="";const l=this.qb(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.Eb),u=_+this.Eb-1;if(s.dr!==h){const t=s.dr;n.fillStyle=t,h=t}this.jt.Mi&&(_+=l,o+=l,u-=l,a-=l),o>a||n.fillRect(_,o,u-_+1,a-o+1)}}}class Ae extends Re{constructor(){super(...arguments),this.mg=new Ve}hb(t,i,s){return{...this.Hb(t,i,s),...s.Fr(t,{Ht:i})}}Sg(){const t=this.Qn.W();this.mg.lt({Ks:this.dg,bu:this.te.Lt().bu(),Nb:t.wickVisible,Mi:t.borderVisible,ot:this.pg})}}const Le={type:"Candlestick",isBuiltIn:!0,defaultOptions:{upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},Jg:(t,i)=>new Ae(t,i)};class Be extends C{constructor(){super(...arguments),this.jt=null,this.jb=[]}lt(t){this.jt=t,this.jb=[]}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.jt||0===this.jt._t.length||null===this.jt.ot)return;this.jb.length||this.Xb(i);const n=Math.max(1,Math.floor(s)),e=Math.round(this.jt.Gb*s)-Math.floor(n/2),r=e+n;for(let i=this.jt.ot.from;i<this.jt.ot.to;i++){const h=this.jt._t[i],l=this.jb[i-this.jt.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)}}Xb(t){if(null===this.jt||0===this.jt._t.length||null===this.jt.ot)return void(this.jb=[]);const i=Math.ceil(this.jt.bu*t)<=1?0:Math.max(1,Math.floor(t)),s=Math.round(this.jt.bu*t)-i;this.jb=new Array(this.jt.ot.to-this.jt.ot.from);for(let i=this.jt.ot.from;i<this.jt.ot.to;i++){const n=this.jt._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.jb[i-this.jt.ot.from]={qh:r,yi:h,Kb:e,ee:n.ut*t,gt:n.gt}}for(let t=this.jt.ot.from+1;t<this.jt.ot.to;t++){const s=this.jb[t-this.jt.ot.from],n=this.jb[t-this.jt.ot.from-1];s.gt===n.gt+1&&(s.qh-n.yi!==i+1&&(n.Kb>n.ee?n.yi=s.qh-i-1:s.qh=n.yi+i+1))}let n=Math.ceil(this.jt.bu*t);for(let t=this.jt.ot.from;t<this.jt.ot.to;t++){const i=this.jb[t-this.jt.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.jt.ot.from;t<this.jt.ot.to;t++){const i=this.jb[t-this.jt.ot.from];i.yi-i.qh+1>n&&(i.Kb>i.ee?i.yi-=1:i.qh+=1)}}}class Ee extends te{constructor(){super(...arguments),this.mg=new Be}hb(t,i,s,n){return{...this.rb(t,i),...s.Fr(t,{Ht:n})}}Sg(){const t={_t:this.dg,bu:this.te.Lt().bu(),ot:this.pg,Gb:this.Qn.$t().zt(this.Qn.W().base,l(this.Qn.Et()).Ht)};this.mg.lt(t)}}const Oe={type:"Histogram",isBuiltIn:!0,defaultOptions:{color:"#26a69a",base:0},Jg:(t,i)=>new Ee(t,i)};class We{constructor(t,i){this.Pt=t,this.Zb=i,this.Jb()}detach(){this.Pt.detachPrimitive(this.Zb)}getPane(){return this.Pt}applyOptions(t){this.Zb.lr?.(t)}Jb(){this.Pt.attachPrimitive(this.Zb)}}const ze={visible:!0,horzAlign:"center",vertAlign:"center",lines:[]},$e={color:"rgba(0, 0, 0, 0.5)",fontSize:48,fontFamily:w,fontStyle:"",text:""};class He{constructor(t){this.Qb=new Map,this.jt=t}draw(t){t.useMediaCoordinateSpace(t=>{if(!this.jt.visible)return;const{context:i,mediaSize:s}=t;let n=0;for(const t of this.jt.lines){if(0===t.text.length)continue;i.font=t.T;const e=this.tM(i,t.text);e>s.width?t.Tu=s.width/e:t.Tu=1,n+=t.lineHeight*t.Tu}let e=0;switch(this.jt.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.jt.lines){i.save(),i.fillStyle=t.color;let n=0;switch(this.jt.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.iM),i.restore(),e+=t.lineHeight*t.Tu}})}tM(t,i){const s=this.sM(t.font);let n=s.get(i);return void 0===n&&(n=t.measureText(i).width,s.set(i,n)),n}sM(t){let i=this.Qb.get(t);return void 0===i&&(i=new Map,this.Qb.set(t,i)),i}}class Ne{constructor(t){this.Ps=qe(t)}Tt(t){this.Ps=qe(t)}renderer(){return new He(this.Ps)}}function Ue(t){return{...t,T:g(t.fontSize,t.fontFamily,t.fontStyle),lineHeight:t.lineHeight||1.2*t.fontSize,iM:0,Tu:0}}function qe(t){return{...t,lines:t.lines.map(Ue)}}function Ye(t){return{...$e,...t}}function je(t){return{...ze,...t,lines:t.lines?.map(Ye)??[]}}class Xe{constructor(t){this.Ps=je(t),this.nM=[new Ne(this.Ps)]}updateAllViews(){this.nM.forEach(t=>t.Tt(this.Ps))}paneViews(){return this.nM}attached({requestUpdate:t}){this.eM=t}detached(){this.eM=void 0}lr(t){this.Ps=je({...this.Ps,...t}),this.eM&&this.eM()}}const Ge={alpha:1,padding:0};class Ke{constructor(t){this.jt=t}draw(t){t.useMediaCoordinateSpace(t=>{const i=t.context,s=this.rM(this.jt,t.mediaSize);s&&this.jt.hM&&(i.globalAlpha=this.jt.alpha??1,i.drawImage(this.jt.hM,s.ut,s.ct,s.ts,s.qt))})}rM(t,i){const{maxHeight:s,maxWidth:n,lM:e,oM:r,padding:h}=t,l=Math.round(i.width/2),o=Math.round(i.height/2),a=h??0;let _=i.width-2*a,u=i.height-2*a;s&&(u=Math.min(u,s)),n&&(_=Math.min(_,n));const c=_/r,d=u/e,p=Math.min(c,d),f=r*p,v=e*p;return{ut:l-.5*f,ct:o-.5*v,qt:v,ts:f}}}class Ze{constructor(t){this.aM=null,this._M=0,this.uM=0,this.Ps=t,this.M=Je(this.Ps,this.aM,this._M,this.uM)}cM(t){void 0!==t.dM&&(this._M=t.dM),void 0!==t.pM&&(this.uM=t.pM),void 0!==t.fM&&(this.aM=t.fM),this.Tt()}vM(t){this.Ps=t,this.Tt()}zOrder(){return"bottom"}Tt(){this.M=Je(this.Ps,this.aM,this._M,this.uM)}renderer(){return new Ke(this.M)}}function Je(t,i,s,n){return{...t,hM:i,oM:s,lM:n}}function Qe(t){return{...Ge,...t}}class tr{constructor(t,i){this.mM=null,this.wM=t,this.Ps=Qe(i),this.nM=[new Ze(this.Ps)]}updateAllViews(){this.nM.forEach(t=>t.Tt())}paneViews(){return this.nM}attached(t){const{requestUpdate:i}=t;this.gM=i,this.mM=new Image,this.mM.onload=()=>{const t=this.mM?.naturalHeight??1,i=this.mM?.naturalWidth??1;this.nM.forEach(s=>s.cM({pM:t,dM:i,fM:this.mM})),this.gM&&this.gM()},this.mM.src=this.wM}detached(){this.gM=void 0,this.mM=null}lr(t){this.Ps=Qe({...this.Ps,...t}),this.bM(),this.eM&&this.eM()}eM(){this.gM&&this.gM()}bM(){this.nM.forEach(t=>t.vM(this.Ps))}}class ir{constructor(t,i){this.Qn=t,this._h=i,this.Jb()}detach(){this.Qn.detachPrimitive(this._h)}getSeries(){return this.Qn}applyOptions(t){this._h&&this._h.lr&&this._h.lr(t)}Jb(){this.Qn.attachPrimitive(this._h)}}const sr={autoScale:!0,zOrder:"normal"};function nr(t,i){return Kt(Math.min(Math.max(t,12),30)*i)}function er(t,i){switch(t){case"arrowDown":case"arrowUp":case"tag":return nr(i,1);case"circle":return nr(i,.8);case"square":case"xcross":return nr(i,.7)}}function rr(t){return function(t){const i=Math.ceil(t);return i%2!=0?i-1:i}(nr(t,1))}function hr(t){return Math.max(nr(t,.1),3)}function lr(t){return Math.max(hr(t),10)}function or(t,i,s){return i?t:s?Math.ceil(t/2):0}function ar(t,i,s,n){const e=(er("arrowUp",n)-1)/2*s.MM,r=(Kt(n/2)-1)/2*s.MM;i.beginPath(),t?(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct-e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct+e),i.lineTo(s.ut-r,s.ct+e),i.lineTo(s.ut-r,s.ct)):(i.moveTo(s.ut-e,s.ct),i.lineTo(s.ut,s.ct+e),i.lineTo(s.ut+e,s.ct),i.lineTo(s.ut+r,s.ct),i.lineTo(s.ut+r,s.ct-e),i.lineTo(s.ut-r,s.ct-e),i.lineTo(s.ut-r,s.ct)),i.fill()}function _r(t,i,s,n,e,r){const h=(er("arrowUp",n)-1)/2,l=(Kt(n/2)-1)/2;if(e>=i-l-2&&e<=i+l+2&&r>=(t?s:s-h)-2&&r<=(t?s+h:s)+2)return!0;return(()=>{if(e<i-h-3||e>i+h+3||r<(t?s-h-3:s)||r>(t?s:s+h+3))return!1;const n=Math.abs(e-i);return Math.abs(r-s)+3>=n/2})()}function ur(t,i,s,n,e,r){const h=Math.min(e/3,n/3),l=r?-1:1,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 cr(t,i,s,n,e,r){t.save(),t.scale(e,r),t.fillText(i,s,n),t.restore()}class dr{constructor(){this.jt=null,this.Wn=new it,this.yM=new it,this.$=-1,this.H="",this.Xf="",this.SM="",this.xM="normal"}lt(t){this.jt=t}zn(t,i,s){this.$===t&&this.H===i||(this.$=t,this.H=i,this.Xf=g(t,i),this.SM=g(t,i,"600"),this.Wn.Vn(),this.yM.Vn()),this.xM=s}Xn(t,i){if(null===this.jt||null===this.jt.ot)return null;for(let s=this.jt.ot.from;s<this.jt.ot.to;s++){const n=this.jt._t[s];if(n&&fr(n,t,i))return{zOrder:"normal",externalId:n.Gn??""}}return null}draw(t){"aboveSeries"!==this.xM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}drawBackground(t){"aboveSeries"===this.xM&&t.useBitmapCoordinateSpace(t=>{this.rt(t)})}rt({context:t,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null!==this.jt&&null!==this.jt.ot){t.textBaseline="middle";for(let n=this.jt.ot.from;n<this.jt.ot.to;n++){const e=this.jt._t[n],r=void 0!==e.CM;if(t.font=r?this.SM:this.Xf,void 0!==e.hi){const i=r?this.yM:this.Wn;e.hi.ts=i.Ii(t,e.hi.PM),e.hi.qt=this.$,e.hi.ut=e.ut-e.hi.ts/2}if(void 0!==e.CM){const t=void 0!==e.hi?e.hi.ts:0;e.CM.ts=Math.max(t+2*e.CM.TM,e.CM.qt),e.CM.qh=e.ut-e.CM.ts/2}pr(e,t,i,s)}}}}function pr(t,i,s,n){void 0===t.CM?(i.fillStyle=t.R,void 0!==t.hi&&cr(i,t.hi.PM,t.hi.ut,t.hi.ct,s,n),function(t,i,s){if(0===t.Or)return;switch(t.kM){case"arrowDown":return void ar(!1,i,s,t.Or);case"arrowUp":return void ar(!0,i,s,t.Or);case"circle":return void function(t,i,s){const n=(er("circle",s)-1)/2;t.beginPath(),t.arc(i.ut,i.ct,n*i.MM,0,2*Math.PI,!1),t.fill()}(i,s,t.Or);case"square":return void function(t,i,s){const n=er("square",s),e=(n-1)*i.MM/2,r=i.ut-e,h=i.ct-e;t.fillRect(r,h,n*i.MM,n*i.MM)}(i,s,t.Or);case"xcross":return void function(t,i,s){const n=(er("xcross",s)-1)/2*i.MM;t.save(),t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1,Math.round(1.5*i.MM)),t.lineCap="round",t.beginPath(),t.moveTo(i.ut-n,i.ct-n),t.lineTo(i.ut+n,i.ct+n),t.moveTo(i.ut+n,i.ct-n),t.lineTo(i.ut-n,i.ct+n),t.stroke(),t.restore()}(i,s,t.Or);case"tag":return}t.kM}(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,MM:i}}(t,s,n))):function(t,i,s,n,e){if(0===t.Or)return;(function(t,i){const s=i.DM,n=i.RM,e=Math.round((i.ut-i.ts/2)*s),r=Math.round((i.ut+i.ts/2)*s),h=Math.round((i.FM-i.qt/2)*n),l=Math.round((i.FM+i.qt/2)*n),o=Math.round(i.ut*s),a=Math.min(i.vt*s,(r-e)/2,(l-h)/2),_=i.IM*n,u=Math.min(.62*_,Math.max(0,(r-e)/2-a)),c="none"!==i.VM&&u>0&&_>0;t.save(),t.beginPath(),c?(t.moveTo(e+a,h),"up"===i.VM&&ur(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.VM&&ur(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)):A(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,FM:t.ct,ts:i.ts,qt:i.qt,IM:i.IM,VM:i.VM,vt:i.vt,le:t.R,Nt:t.Nt,Wt:t.Wt??1,DM:n,RM:e}),void 0!==t.hi&&(s.fillStyle=t.AM??"#FFFFFF",cr(s,t.hi.PM,t.hi.ut,t.hi.ct,n,e))}(t,t.CM,i,s,n)}function fr(t,i,s){return void 0!==t.CM?0!==t.Or&&function(t,i,s,n,e){if(s.ts<=0)return!1;const r=s.qt/2,h="up"===s.VM?i-r-s.IM:i-r,l="down"===s.VM?i+r+s.IM:i+r,o=t-s.ts/2;return n>=o&&n<=o+s.ts&&e>=h&&e<=l}(t.ut,t.ct,t.CM,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.kM){case"arrowDown":return _r(!0,t.ut,t.ct,t.Or,i,s);case"arrowUp":return _r(!1,t.ut,t.ct,t.Or,i,s);case"circle":return function(t,i,s,n,e){const r=2+er("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=er("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"xcross":return function(t,i,s,n,e){const r=2+er("xcross",s)/2;return Math.abs(n-t)<=r&&Math.abs(e-i)<=r}(t.ut,t.ct,t.Or,i,s);case"tag":return!1}}(t,i,s)}function vr(t){return"atPriceTop"===t||"atPriceBottom"===t||"atPriceMiddle"===t}function mr(t,i,s,n,e,r,h,o,a){const _=function(t,i,s){if(vr(i.position)&&void 0!==i.price)return i.price;if("value"in(n=t)&&"number"==typeof n.value)return t.value;var n;if(function(t){return"open"in t&&"high"in t&&"low"in t&&"close"in t}(t)){if("inBar"===i.position)return t.close;if("aboveBar"===i.position)return s?t.low:t.high;if("belowBar"===i.position)return s?t.high:t.low}}(s,i,a);if(void 0===_)return;const c=vr(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=vr(i.position),_=l/2;let u="none",c=s;switch(i.position){case"aboveBar":case"atPriceTop":u="down",c=s-(a?0:n.LM)-o-_,a||(n.LM+=l+o+r);break;case"belowBar":case"atPriceBottom":u="up",c=s+(a?0:n.BM)+o+_,a||(n.BM+=l+o+r)}const d={qt:l,IM:o,VM:u,vt:i.borderRadius??6,TM:9*h,qh:0,ts:0};t.Or=l,t.ct=c,t.CM=d,void 0!==t.hi&&(t.hi.ct=c)}(t,i,l(h.priceToCoordinate(_)),n,e,r,p)}const f=rr(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.LM;return t.ct=l(h.priceToCoordinate(_))-v-i,void 0!==t.hi&&(t.hi.ct=t.ct-v-.6*e,n.LM+=1.2*e),void(c||(n.LM+=f+r))}case"belowBar":case"atPriceBottom":{const i=c?0:n.BM;return t.ct=l(h.priceToCoordinate(_))+v+i,void 0!==t.hi&&(t.hi.ct=t.ct+v+r+.6*e,n.BM+=1.2*e),void(c||(n.BM+=f+r))}}}class wr{constructor(t,i,s){this.EM=[],this.xt=!0,this.OM=!0,this.Jt=new dr,this.be=t,this.Of=i,this.jt={_t:[],ot:null},this.Ps=s}renderer(){if(!this.be.options().visible)return null;this.xt&&this.WM();const t=this.Of.options().layout;return this.Jt.zn(t.fontSize,t.fontFamily,this.Ps.zOrder),this.Jt.lt(this.jt),this.Jt}zM(t){this.EM=t,this.Tt("data")}Tt(t){this.xt=!0,"data"===t&&(this.OM=!0)}$M(t){this.xt=!0,this.Ps=t}zOrder(){return"aboveSeries"===this.Ps.zOrder?"top":this.Ps.zOrder}WM(){const t=this.Of.timeScale(),i=this.EM;this.OM&&(this.jt._t=i.map(t=>({gt:t.time,ut:0,ct:0,Or:0,kM:t.shape,R:t.color,Gn:t.id,HM:t.HM,hi:void 0,AM:t.textColor,Nt:t.borderColor,Wt:t.borderWidth,CM:void 0})),this.OM=!1);const s=this.Of.options().layout;this.jt.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.jt._t.length)return;let r=!1;try{r=this.be.priceScale().options().invertScale}catch(t){r=!1}let h=NaN;const o=hr(t.options().barSpacing),a=lr(t.options().barSpacing),_={LM:a,BM:a};this.jt.ot=gn(this.jt._t,e,!0);for(let n=this.jt.ot.from;n<this.jt.ot.to;n++){const e=i[n];e.time!==h&&(_.LM=a,_.BM=a,h=e.time);const u=this.jt._t[n];u.ut=l(t.logicalToCoordinate(e.time)),void 0!==e.text&&e.text.length>0&&(u.hi={PM:e.text,ut:0,ct:0,ts:0,qt:0});const c=this.be.dataByIndex(e.time,0);null!==c&&mr(u,e,c,_,s.fontSize,o,this.be,this.Of,r)}this.xt=!1}}function gr(t){return{...sr,...t}}class br{constructor(t){this.eh=null,this.EM=[],this.NM=[],this.UM=null,this.be=null,this.Of=null,this.qM=!0,this.YM=null,this.jM=null,this.XM=null,this.GM=!0,this.Ps=gr(t)}attached(t){this.KM(),this.Of=t.chart,this.be=t.series,this.eh=new wr(this.be,l(this.Of),this.Ps),this.gM=t.requestUpdate,this.be.subscribeDataChanged(t=>this.Bg(t)),this.GM=!0,this.eM()}eM(){this.gM&&this.gM()}detached(){this.be&&this.UM&&this.be.unsubscribeDataChanged(this.UM),this.Of=null,this.be=null,this.eh=null,this.UM=null}zM(t){this.GM=!0,this.EM=t,this.KM(),this.qM=!0,this.jM=null,this.eM()}ZM(){return this.EM}paneViews(){return this.eh?[this.eh]:[]}updateAllViews(){this.JM()}hitTest(t,i){return this.eh?this.eh.renderer()?.Xn(t,i)??null:null}autoscaleInfo(t,i){if(this.Ps.autoScale&&this.eh){const t=this.QM();if(t)return{priceRange:null,margins:t}}return null}lr(t){this.Ps=gr({...this.Ps,...t}),this.eM&&this.eM()}QM(){const t=l(this.Of).timeScale().options().barSpacing;if(this.qM||t!==this.XM){if(this.XM=t,this.EM.length>0){const i=hr(t),s=1.5*rr(t)+i+lr(t),n=this.ty();this.YM={above:or(s,n.aboveBar,n.inBar),below:or(s,n.belowBar,n.inBar)}}else this.YM=null;this.qM=!1}return this.YM}ty(){return null===this.jM&&(this.jM=this.EM.reduce((t,i)=>(t[i.position]||(t[i.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1,atPriceTop:!1,atPriceBottom:!1,atPriceMiddle:!1})),this.jM}KM(){if(!this.GM||!this.Of||!this.be)return;const t=this.Of.timeScale(),i=this.be?.data();if(null==t.getVisibleLogicalRange()||!this.be||0===i.length)return void(this.NM=[]);const s=t.timeToIndex(l(i[0].time),!0);this.NM=this.EM.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,HM:n,text:i.text,size:i.size,price:i.price,textColor:i.textColor,borderColor:i.borderColor,borderWidth:i.borderWidth,borderRadius:i.borderRadius,Vw: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.GM=!1}JM(t){this.eh&&(this.KM(),this.eh.zM(this.NM),this.eh.$M(this.Ps),this.eh.Tt(t))}Bg(t){this.GM=!0,this.eM()}}class Mr extends ir{constructor(t,i,s){super(t,i),s&&this.setMarkers(s)}setMarkers(t){this._h.zM(t)}markers(){return this._h.ZM()}}function yr(t,i,s){const n=new Mr(t,new br(s??{}));return i&&n.setMarkers(i),n}class Sr{constructor(t){this.EM=new Map,this.iy=t}sy(t,i,s){if(this.ny(i),void 0!==s){const n=window.setTimeout(()=>{this.EM.delete(i),this.ey()},s),e={...t,hy:n,ly:Date.now()+s};this.EM.set(i,e)}else this.EM.set(i,{...t,hy:void 0,ly:void 0});this.ey()}ny(t){const i=this.EM.get(t);i&&void 0!==i.hy&&window.clearTimeout(i.hy),this.EM.delete(t),this.ey()}oy(){for(const[t]of this.EM)this.ny(t)}_y(){const t=Date.now(),i=[];for(const[s,n]of this.EM)!n.ly||n.ly>t?i.push({time:n.time,sign:n.sign,value:n.value}):this.ny(s);return i}uy(t){this.iy=t}ey(){this.iy&&this.iy()}}const xr={positiveColor:"#22AB94",negativeColor:"#F7525F",updateVisibilityDuration:5e3};class Cr{constructor(t,i,s,n){this.jt=t,this.py=i,this.vy=s,this.my=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.jt.forEach(e=>{const r=Math.round(e.ut*t.horizontalPixelRatio)+s;i.beginPath();const h=this.wy(e.gy);i.fillStyle=h,i.arc(r,e.ct*t.verticalPixelRatio,n,0,2*Math.PI,!1),i.fill(),e.gy&&(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.gy)*t.verticalPixelRatio),i.lineTo(e.ut*t.horizontalPixelRatio+s,(e.ct-7*e.gy-7*e.gy*.5)*t.verticalPixelRatio),i.lineTo((e.ut+4.7)*t.horizontalPixelRatio+s,(e.ct-7*e.gy)*t.verticalPixelRatio),i.stroke())})})}wy(t){return 0===t?this.py:t>0?this.my:this.vy}}class Pr{constructor(t,i,s){this.jt=[],this.be=t,this.ph=i,this.Ps=s}Tt(t){this.jt=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,gy:t.sign}}).filter(v)}renderer(){const t=function(t,i){return function(t,i){return"Area"===i}(0,i)?t.lineColor:t.color}(this.be.options(),this.be.seriesType());return new Cr(this.jt,t,this.Ps.negativeColor,this.Ps.positiveColor)}}function Tr(t,i){return"Line"===i||"Area"===i}class kr{constructor(t){this.Of=void 0,this.be=void 0,this.nM=[],this.u_=null,this.by=new Map,this.My=new Sr(()=>this.eM()),this.Ps={...xr,...t}}lr(t){this.Ps={...this.Ps,...t},this.eM()}zM(t){this.My.oy();const i=this.u_;i&&t.forEach(t=>{this.My.sy(t,i.key(t.time))})}ZM(){return this.My._y()}eM(){this.gM?.()}attached(t){const{chart:i,series:s,requestUpdate:n,horzScaleBehavior:e}=t;this.Of=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.nM=[new Pr(this.be,this.Of.timeScale(),this.Ps)],this.gM=n,this.eM()}detached(){this.Of=void 0,this.be=void 0,this.gM=void 0}Jf(){return h(this.Of)}za(){return h(this.be)}updateAllViews(){this.nM.forEach(t=>t.Tt(this.ZM()))}paneViews(){return this.nM}lt(t){if(!this.be)throw new Error("Primitive not attached to series");const i=this.be.seriesType();this.by.clear();const s=this.u_;s&&t.forEach(t=>{tn(t)&&Tr(0,i)&&this.by.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(Qs(t)&&this.by.delete(n),tn(t)&&Tr(0,s)){const i=this.by.get(n);i&&this.My.sy({time:t.time,value:t.value,sign:Dr(t.value,i)},n,this.Ps.updateVisibilityDuration)}h(this.be).update(t,i)}yy(){this.My.oy()}}function Dr(t,i){return t===i?0:t-i>0?1:-1}class Rr extends ir{setData(t){return this._h.lt(t)}update(t,i){return this._h.Tt(t,i)}markers(){return this._h.ZM()}setMarkers(t){return this._h.zM(t)}clearMarkers(){return this._h.yy()}}const Fr={position:"bottom",offset:4,fontSize:11,fontFamily:"",color:"#787B86"};class Ir{constructor(t){this.jt=t}draw(t){const{_t:i,Mf:s,Sy:n}=this.jt;0!==i.length&&t.useMediaCoordinateSpace(({context:t,mediaSize:e})=>{const r="top"===s?n:e.height-n;t.save(),t.textAlign="center",t.textBaseline="top"===s?"top":"bottom";for(const s of i)s.ut<-100||s.ut>e.width+100||(t.font=s.T,t.fillStyle=s.R,t.fillText(s.hi,s.ut,r));t.restore()})}}class Vr{constructor(){this.jt={_t:[],Mf:"bottom",Sy:0}}Tt(t){this.jt=t}zOrder(){return"top"}renderer(){return new Ir(this.jt)}}class Ar{constructor(t){this.Of=null,this.gM=null,this.Y_=[],this.eh=new Vr,this.Ps={...Fr,...t}}attached(t){this.Of=t.chart,this.gM=t.requestUpdate,this.gM()}detached(){this.Of=null,this.gM=null}xy(t){this.Y_=t.slice(),this.gM?.()}Cy(){return this.Y_}lr(t){this.Ps={...this.Ps,...t},this.gM?.()}updateAllViews(){const t=this.Of,i=this.Ps;if(null===t)return void this.eh.Tt({_t:[],Mf:i.position,Sy:i.offset});const s=t.timeScale(),n=i.fontFamily||t.options().layout.fontFamily,e=[];for(const t of this.Y_){const r=s.timeToCoordinate(t.time);null!==r&&e.push({ut:r,hi:t.text,R:t.color??i.color,T:g(t.size??i.fontSize,n)})}this.eh.Tt({_t:e,Mf:i.position,Sy:i.offset})}paneViews(){return[this.eh]}}class Lr extends ir{setLabels(t){this._h.xy(t)}labels(){return this._h.Cy()}}class Br{constructor(t,i){this.Py=null,this.Ty=[],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.Py=yr(t)}addPosition(t){this.Ty.push(t),this.ky()}addPositions(t){this.Ty.push(...t),this.ky()}setPositions(t){this.Ty=[...t],this.ky()}closePosition(t,i,s){const n=this.Ty.find(i=>i.id===t);n&&(n.exit=i,s&&n.text?n.text.exit=s:s&&(n.text={exit:s}),this.ky())}removePosition(t){this.Ty=this.Ty.filter(i=>i.id!==t),this.ky()}clearPositions(){this.Ty=[],this.ky()}getPositions(){return this.Ty}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.ky()}Dy(){const t=[];for(const i of this.Ty){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}ky(){if(this.Py){const t=this.Dy();this.Py.setMarkers(t)}}detach(){this.Py&&(this.Py.detach(),this.Py=null),this.Ty=[]}}const Er=new WeakMap;function Or(t){return"string"==typeof t?t:String(t)}function Wr(t,i){return Er.get(t)?.get(Or(i))}function zr(t){const i=Er.get(t);return void 0!==i&&i.size>0}const $r="rgba(0, 0, 0, 0)";function Hr(t){switch(t.seriesType()){case"Candlestick":return Nr(t,{upColor:$r,downColor:$r,borderVisible:!1,wickVisible:!1});case"Bar":return Nr(t,{upColor:$r,downColor:$r});case"Line":return Nr(t,{color:$r,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Area":return Nr(t,{lineColor:$r,topColor:$r,bottomColor:$r,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Baseline":return Nr(t,{topLineColor:$r,topFillColor1:$r,topFillColor2:$r,bottomLineColor:$r,bottomFillColor1:$r,bottomFillColor2:$r,crosshairMarkerVisible:!1,pointMarkersVisible:!1});case"Histogram":return Nr(t,{color:$r});default:return Nr(t,{visible:!1})}}function Nr(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 Ur(t,i){return()=>{const s={};s.minValue=t,s.maxValue=i;const n={};return n.priceRange=s,n}}function qr(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 Yr(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 jr(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 Xr(t){return null==t?void 0:t.time}function Gr(t){const{r_:i,Jf:s,Ry:n,Fy:e,Iy:r,Jl:h}=t,l=t.Vy??[];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=Xr(s[s.length-1])===Xr(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&&Xr(a[a.length-1])===Xr(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 Kr(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.Ay,i.Ly-1,i.By))}}if(Number.isNaN(s.getTime()))return null;const n=s.getUTCFullYear();if("monthly"===i)return`${n}-${s.getUTCMonth()}`;if("weekly"===i){const t=new Date(s.getTime()),i=(t.getUTCDay()+6)%7;return t.setUTCDate(t.getUTCDate()-i),`${t.getUTCFullYear()}-${t.getUTCMonth()}-${t.getUTCDate()}`}return`${n}-${s.getUTCMonth()}-${s.getUTCDate()}`}class Zr{constructor(t,i,s,n){this.Of=t,this.be=i,this.V_=s,this.Ey=n}draw(t){const i=this.Ey();if(!i.It||i.Oy<=0)return;const s=this.V_();s.length<2||t.useBitmapCoordinateSpace(t=>{const n=t.context,e=this.Of.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.Wy),u=this.be.priceToCoordinate(h.zy),c=this.be.priceToCoordinate(l.Wy),d=this.be.priceToCoordinate(l.zy);if(null===_||null===u||null===c||null===d)continue;const p=h.Wy>=h.zy;n.fillStyle=this.$y(p?i.Hy:i.Ny,i.Oy),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()}})}$y(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class Jr{constructor(t,i,s,n){this.Jt=new Zr(t,i,s,n)}renderer(){return this.Jt}zOrder(){return"bottom"}}function Qr(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 th(t){return null!=t&&"number"==typeof t.close}function ih(t){const i=[];let s=null,n=null;for(const e of t){if(!th(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 sh{constructor(t){this.Uy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Uy.getSessionBoxes();if(s&&0!==s.length)for(const n of s)this.qy(i,n,t.horizontalPixelRatio,t.verticalPixelRatio)})}qy(t,i,s,n){const e=i.Yy||i.startTime,r=i.jy||i.endTime,h=i.R||i.color,l=i.Oy||i.opacity;if(!i||!e||!r)return;const o=this.Uy.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.Xy(h,l),t.fillRect(u,d,c-u,p-d)}Xy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class nh{constructor(t){this.Jt=new sh(t)}renderer(){return this.Jt}zOrder(){return"bottom"}}const eh=[{name:"Tokyo",startHour:9,endHour:18,timeZone:"Asia/Tokyo",color:"#FF6B00",opacity:.1},{name:"London",startHour:8,endHour:17,timeZone:"Europe/London",color:"#2962FF",opacity:.1},{name:"New York",startHour:8,endHour:17,timeZone:"America/New_York",color:"#089981",opacity:.1}];class rh{constructor(t,i,s={}){this.Gy=[],this.Zb=null,this.eh=null,this.Of=t,this.be=i,this.Ps={sessions:s.sessions||eh,showOverlaps:s.showOverlaps??!0,overlapColor:s.overlapColor||"#9C27B0",overlapOpacity:s.overlapOpacity||.15,enabled:s.enabled??!0},this.Ky(),this.Ps.enabled&&this.Zy()}Ky(){this.eh=new nh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.Zb=t,this.be.attachPrimitive(t)}Zy(){this.Of.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.Jy()}),this.Jy()}Jy(){this.Qy();const t=this.Of.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.tS(s),this.gM()}tS(t){if(0!==t.length){for(const i of this.Ps.sessions)this.iS(i,t);this.Ps.showOverlaps&&this.sS(t)}}iS(t,i){this.nS(i,i=>this.eS(i,t),(i,s)=>this.rS(i,s,t))}sS(t){const i=this.Ps.sessions;for(let s=0;s<i.length;s++)for(let n=s+1;n<i.length;n++)this.nS(t,t=>this.eS(t,i[s])&&this.eS(t,i[n]),(t,i)=>this.hS(t,i))}nS(t,i,s){let n=null,e=null;for(const r of t)i(r.time)?(n=n??r.time,e=r.time):null!==n&&null!==e&&(s(n,e),n=null,e=null);null!==n&&null!==e&&s(n,e)}eS(t,i){const s=this.lS(t,i.timeZone);return i.startHour<i.endHour?s>=i.startHour&&s<i.endHour:s>=i.startHour||s<i.endHour}lS(t,i){const s="number"==typeof t?t:"string"==typeof t?Date.parse(t)/1e3:NaN;return Number.isFinite(s)?new Date(1e3*(s+Gi(i,s))).getUTCHours():0}rS(t,i,s){if(!t||!i)return void console.warn("Invalid session box times:",{startTime:t,endTime:i,session:s.name});const n={an:"session",Yy:t,jy:i,R:s.color,Oy:s.opacity,oS:s.name};this.Gy.push(n)}hS(t,i){const s={an:"overlap",Yy:t,jy:i,R:this.Ps.overlapColor,Oy:this.Ps.overlapOpacity,oS:"Overlap"};this.Gy.push(s)}Qy(){this.Gy=[]}applyOptions(t){this.Ps={...this.Ps,...t},this.Ps.enabled?this.Jy():this.Qy(),this.gM()}options(){return{...this.Ps}}enable(){this.Ps.enabled=!0,this.Jy(),this.gM()}disable(){this.Ps.enabled=!1,this.Qy(),this.gM()}remove(){this.Zb&&this.be&&this.be.detachPrimitive(this.Zb),this.Qy(),this.gM()}getSessionBoxes(){return this.Gy}getChart(){return this.Of}getSeries(){return this.be}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.Of.timeScale().applyOptions({})}}class hh{constructor(t){this.Uy=t}draw(t){t.useBitmapCoordinateSpace(t=>{const i=t.context,s=this.Uy.getProfileData();if(!s||0===s.bins.length)return;const n=this.Uy.options(),e=this.Uy.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.aS(i,r,l,h,o,s,n,e,t.horizontalPixelRatio,t.verticalPixelRatio);n.showPOC&&this._S(i,s.poc,n.pocColor||"#FF6B00",e,r,t.horizontalPixelRatio,t.verticalPixelRatio),n.showValueArea&&this.uS(i,s.valueAreaHigh,s.valueAreaLow,n.valueAreaColor||"#089981",e,r,t.horizontalPixelRatio,t.verticalPixelRatio)}})}aS(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.Xy(M,y),t.fillRect(f,v,m,w)}_S(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([])}uS(t,i,s,n,e,r,h,l){const o=e.priceToCoordinate(i);if(null!==o){const i=o*l;t.strokeStyle=this.Xy(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.Xy(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([])}Xy(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}}class lh{constructor(t){this.Jt=new hh(t)}renderer(){return this.Jt}zOrder(){return"normal"}}class oh{constructor(t,i,s={}){this.cS=null,this.dS=new Map,this.Zb=null,this.eh=null,this.Of=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.Ky(),this.Zy()}Ky(){this.eh=new lh(this);const t={attached:t=>{},detached:()=>{},paneViews:()=>this.eh?[this.eh]:[],updateAllViews:()=>{this.eh}};this.Zb=t,this.be.attachPrimitive(t)}Zy(){this.Of.timeScale().subscribeVisibleLogicalRangeChange(()=>{this.pS()}),this.pS()}setVolumeData(t){this.dS=t,this.pS()}addVolumeData(t,i){this.dS.set(t,i),this.pS()}pS(){const t=this.Of.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.dS.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.cS={bins:h,binSize:r,poc:o.priceLevel,valueAreaHigh:d,valueAreaLow:p,totalVolume:l},this.gM()}getProfileData(){return this.cS}applyOptions(t){this.Ps={...this.Ps,...t},this.pS(),this.gM()}remove(){this.Zb&&this.be&&this.be.detachPrimitive(this.Zb),this.cS=null,this.dS.clear(),this.gM()}getChart(){return this.Of}getSeries(){return this.be}options(){return this.Ps}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.Of.timeScale().applyOptions({})}}class ah{constructor(t,i){this.fS=new Map,this.vS=null,this.mS=null,this.wS=null,this.gS=null,this.bS=null,this.MS=null,this.yS=!1,this.SS=0,this.xS=null,this.Tg=void 0,this.Of=t,this.Af=i,this.CS=t=>this.PS(t),this.TS=t=>this.kS(t),this.DS=t=>this.RS(t),this.FS=t=>this.IS(t),this.VS=()=>this.AS(),this.LS=t=>{"Escape"===t.key&&this.AS()},this.Of.subscribeCrosshairMove(this.CS),this.Af.addEventListener("pointerdown",this.TS),this.Af.addEventListener("pointermove",this.DS),this.Af.addEventListener("pointerup",this.FS),this.Af.addEventListener("pointercancel",this.VS),document.addEventListener("keydown",this.LS)}BS(t){this.fS.set(t.id(),t)}ES(t){const i=t.id();this.vS===i&&this.OS(null),this.wS===t&&this.AS(),this.fS.delete(i)}Gi(){return 0===this.fS.size}m(){this.Of.unsubscribeCrosshairMove(this.CS),this.Af.removeEventListener("pointerdown",this.TS),this.Af.removeEventListener("pointermove",this.DS),this.Af.removeEventListener("pointerup",this.FS),this.Af.removeEventListener("pointercancel",this.VS),document.removeEventListener("keydown",this.LS),this.fS.clear()}PS(t){if(this.xS=t.point?{ut:t.point.x,ct:t.point.y}:null,this.Tg=t.paneIndex,null!==this.wS)return;const i=this.WS(t.hoveredObjectId),s=null===i?null:this.fS.get(i.gl)??null;this.OS(s?s.id():null),this.zS(s,null===s?null:i?.$S??null),this.HS()}kS(t){this.yS="mouse"!==t.pointerType;let i=this.yS||null===this.vS?null:this.fS.get(this.vS)??null;null===i&&(i=this.NS(t)),i?(this.bS={ut:t.clientX,ct:t.clientY},this.MS=i,i.isDraggable()&&(this.wS=i,this.gS=t.pointerId,this.Af.setPointerCapture(t.pointerId),i.beginDrag(),this.SS=this.US(i,t),this.HS(),t.preventDefault(),t.stopPropagation())):this.qS()}RS(t){if(null===this.wS)return;if(!this.YS(t))return void this.AS();const i=this.jS(t);null!==i&&this.wS.dragTo(i),t.preventDefault(),t.stopPropagation()}IS(t){const i=this.wS,s=this.yS,n=this.MS,e=this.bS;this.XS(),this.MS=null,this.bS=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.wS=null,this.SS=0,h?i.commitDrag():(i.cancelDrag(),i.isClickable()&&i.click()),this.qS(s),void this.HS();null!==n&&!h&&n.isClickable()&&n.click(),this.qS(s)}qS(t=this.yS){if(!t||null===this.vS)return;const i=this.fS.get(this.vS)??null;this.OS(null),this.zS(i,null),this.HS()}AS(){if(null===this.wS)return;const t=this.wS;this.wS=null,this.SS=0,this.XS(),t.cancelDrag(),this.HS()}YS(t){const i=this.Af.getBoundingClientRect();return t.clientX>=i.left&&t.clientX<=i.right&&t.clientY>=i.top&&t.clientY<=i.bottom}XS(){null!==this.gS&&(this.Af.hasPointerCapture(this.gS)&&this.Af.releasePointerCapture(this.gS),this.gS=null)}jS(t){const i=this.wS;if(null===i)return null;const s=this.GS(i,t);return null===s?null:i.priceAt(s-this.SS)}NS(t){for(const i of this.fS.values()){if(!i.hitTestAt)continue;const s=this.KS(i);if(null===s)continue;const n=s.getBoundingClientRect(),e="mouse"===t.pointerType?0:12,r=this.WS(i.hitTestAt(t.clientX-n.left,t.clientY-n.top,e));if(null!==r)return this.OS(i.id()),this.zS(i,r.$S),i}return null}KS(t){const i=this.Of.panes()[t.paneIndex()];return i?i.getHTMLElement():null}GS(t,i){const s=this.KS(t);return s?i.clientY-s.getBoundingClientRect().top:null!==this.xS&&this.Tg===t.paneIndex()?this.xS.ct:null}US(t,i){if(!t.dragAnchorY)return 0;const s=t.dragAnchorY(),n=this.GS(t,i);if(null===s||null===n)return 0;const e=n-s;return Math.abs(e)>40?0:e}WS(t){if("string"!=typeof t||0===t.length)return null;const i=t.indexOf("#");return-1===i?{gl:t,$S:null}:{gl:t.slice(0,i),$S:t.slice(i+1)}}zS(t,i){this.mS!==i&&(this.mS=i,t&&t.setHoveredPart&&t.setHoveredPart(i))}OS(t){this.vS!==t&&(null!==this.vS&&this.fS.get(this.vS)?.setHovered(!1),this.vS=t,this.mS=null,null!==t&&this.fS.get(t)?.setHovered(!0))}HS(){if(null!==this.wS)return void this.Of.chartElement().style.setProperty("cursor","ns-resize");const t=null===this.vS?null:this.fS.get(this.vS);t?this.Of.chartElement().style.setProperty("cursor",t.isDraggable()?"ns-resize":"pointer"):this.Of.chartElement().style.removeProperty("cursor")}}const _h=new WeakMap;function uh(t){const i=t.chartElement();if(!i)return null;let s=_h.get(t);return s||(s=new ah(t,i),_h.set(t,s)),s}function ch(t,i){const s=_h.get(t);s&&(s.ES(i),s.Gi()&&(s.m(),_h.delete(t)))}let dh=0;class ph{constructor(t,i,s){this.sr=null,this.ZS=!1,this.JS="",this.QS=null,this.Of=t,this.be=i,this.So="pipsend-trading-line-"+dh++,this.Ps={lineWidth:2,lineStyle:0,axisLabelVisible:!0,draggable:!0,hoverColor:"#000000",...s},this.tx(),(this.Ps.draggable||this.Ps.onClick)&&uh(this.Of)?.BS(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.JS}))}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.QS=this.Ps.price,this.Ps.onDragStart&&this.Ps.onDragStart(this.Ps.price)}dragTo(t){this.ix(t),this.Ps.onDragMove&&this.Ps.onDragMove(t)}commitDrag(){this.QS=null,this.Ps.onDragEnd&&this.Ps.onDragEnd(this.Ps.price)}cancelDrag(){const t=this.QS;this.QS=null,null!==t&&t!==this.Ps.price&&(this.ix(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.JS=t.color),!this.sr)return;const i={title:this.sx()};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.ix(t)}remove(){ch(this.Of,this),this.sr&&(this.be.removePriceLine(this.sr),this.sr=null)}getPriceLine(){return this.sr}sx(){if(this.Ps.formatTitle)try{return this.Ps.formatTitle(this.Ps.price)}catch(t){console.error("Error in formatTitle:",t)}return this.Ps.title||""}tx(){this.JS=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.sx()})}ix(t){this.Ps.price=t,this.sr&&this.sr.applyOptions({price:t,title:this.sx()})}}class fh{constructor(t,i){this.Ef=null,this.nx=null,this.hx=null,this.lx={},this.Of=t,this.be=i,this.ox()}ox(){this.Ef=this.Of.chartElement()}_x(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.Ef?(this.nx=t,this.lx=i||{},new Promise(t=>{this.Ef.style.cursor="crosshair",this.hx=i=>{const s=this._x(i),n=this.ux(s);this.disableClickToCreate(),t(n)},this.Ef.addEventListener("click",this.hx)})):Promise.resolve(null)}disableClickToCreate(){this.Ef&&this.hx&&(this.Ef.removeEventListener("click",this.hx),this.Ef.style.cursor="default"),this.nx=null,this.hx=null,this.lx={}}ux(t){if(!this.nx)return null;let i;switch(this.nx){case"stop-loss":i={price:t,color:"#ef5350",lineWidth:2,title:"Stop Loss",draggable:!0,...this.lx};break;case"take-profit":i={price:t,color:"#26a69a",lineWidth:2,title:"Take Profit",draggable:!0,...this.lx};break;case"entry":i={price:t,color:"#2196F3",lineWidth:2,title:"Entry",draggable:!0,...this.lx};break;case"target":i={price:t,color:"#FF9800",lineWidth:2,title:"Target",draggable:!0,...this.lx};break;case"resistance":i={price:t,color:"#f44336",lineWidth:2,title:"Resistance",draggable:!0,...this.lx};break;case"support":i={price:t,color:"#4CAF50",lineWidth:2,title:"Support",draggable:!0,...this.lx};break;case"custom":i={price:t,color:"#9E9E9E",lineWidth:2,title:"Custom",draggable:!0,...this.lx};break;default:return null}return new ph(this.Of,this.be,i)}getCreationMode(){return this.nx}isCreating(){return null!==this.nx}}class vh{constructor(){this.vx=[],this.mx=new Map,this.wx=new Map,this.xt=!0}BS(t){this.mx.has(t)||(this.vx.push(t),this.mx.set(t,[]),this.xt=!0)}ES(t){const i=this.vx.indexOf(t);-1!==i&&this.vx.splice(i,1),this.mx.delete(t),this.xt=!0}Gi(){return 0===this.vx.length}gx(t,i){const s=this.mx.get(t);this.mx.set(t,i),void 0!==s&&function(t,i){if(t.length!==i.length)return!1;for(let s=0;s<t.length;s++)if(t[s].sn!==i[s].sn||t[s].ct!==i[s].ct||t[s].qt!==i[s].qt)return!1;return!0}(s,i)||(this.xt=!0)}bx(t,i){return this.xt&&this.Mx(),this.wx.get(mh(t,i))??0}Mx(){const t=new Map,i=[];for(const s of this.vx)for(const n of this.mx.get(s)??[]){const e=wh(n.qt),r=n.qt;let h=n.ct;for(const t of i){if(t.ct>=h+e)break;Math.abs(h-t.ct)<e&&(h=t.ct+e)}let l=h-n.ct;l>r&&(l=0),gh(i,{ct:n.ct+l,qt:n.qt}),t.set(mh(s,n.sn),l)}this.wx=t,this.xt=!1}}function mh(t,i){return`${t}:${i}`}function wh(t){return Math.max(9,Math.round(.4*t))}function gh(t,i){let s=0,n=t.length;for(;s<n;){const e=s+n>>1;t[e].ct<=i.ct?s=e+1:n=e}t.splice(s,0,i)}const bh=new WeakMap;const Mh={entry:"#2962FF",takeProfit:"#26A17B",stopLoss:"#D9A23B"},yh={badgeTextColor:"#FFFFFF",borderRadius:4,borderWidth:1,paddingX:8,paddingY:6,backgroundOpacity:1},Sh=["takeProfit","entry","stopLoss"];class xh{constructor(){this.jt=null,this.yx=[],this.Sx=0,this.Xf="",this.Po=new S([]),this.Wn=new it(50)}lt(t){this.jt=t}Xn(t,i,s=0){for(const n of this.yx)if(n.xx&&t>=n.Cx-s&&t<=n.Px+s&&Math.abs(i-n.Tx)<=n.qt/2+s)return{sn:n.sn,$S:"close"};for(const n of this.yx)if(t>=n.kx-s&&t<=n.Dx+s&&Math.abs(i-n.Tx)<=n.qt/2+s)return{sn:n.sn,$S:"body"};for(const t of this.yx)if(Math.abs(i-t.ct)<=8+s)return{sn:t.sn,$S:"line"};return null}draw(t){t.useBitmapCoordinateSpace(t=>this.uw(t))}uw(t){const i=this.jt;if(this.yx=[],null===i||0===i.Rx.length)return;const{context:s,mediaSize:n}=t;s.save(),this.Xf!==i.T&&(this.Xf=i.T,this.Wn.Vn()),s.font=i.T,s.textBaseline="middle",this.Sx=Math.max(0,n.width-i.yu);const e=i.Fx?this.Sx:n.width;for(const s of i.Rx)this.yx.push(this.Ix(t,i,s,e));i.Fx&&i.Rx.length>1&&this.Vx(t,i),s.restore()}Ix(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.P+2*i.Ax,o=0===s.Lx.length?0:Math.max(this.Wn.Ii(e,s.Lx)+2*i.TM,.85*l),a=this.Wn.Ii(e,s.hi)+2*i.TM,_=s.xx?l:0,u=o+a+_,c=Math.max(u,n-8),d=c-u,p=s.ct+s.Bx,f=p-l/2;this.Ex(t,s,d,c,n),this.Ox(t,i,s,{qh:d,Wx:f,ts:u,qt:l});let v=d;return o>0&&(this.zx(t,i,s,{qh:v,Wx:f,ts:o,qt:l}),v+=o,this.$x(e,s.R,v,f,l,r,h)),e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=i.AM??s.R,e.fillText(s.hi,v+a/2,p),e.restore(),v+=a,s.xx&&(this.$x(e,s.R,v,f,l,r,h),this.Hx(t,i,s,{qh:v,Wx:f,ts:_,qt:l})),{sn:s.sn,ct:s.ct,Tx:p,qt:l,kx:d,Dx:c,Cx:v,Px:v+_,xx:s.xx}}Ex(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.Bx?(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()}Ox(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t,l=i.Nx===s.sn,o=Math.max(1,Math.round((l?i.Wt+1:i.Wt)*r));e.save(),e.setLineDash([]),Ch(e,n,i.Ux,r,h),e.fillStyle=this.Po.X(i.Z,i.qx),e.fill(),e.lineWidth=o,e.strokeStyle=s.R,e.stroke(),e.restore()}zx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(s.Yx){const t=i.Wt;e.save(),Ch(e,{qh:n.qh+t,Wx:n.Wx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Ux-t),r,h,"left"),e.fillStyle=s.R,e.fill(),e.restore()}e.save(),e.scale(r,h),e.textAlign="center",e.fillStyle=s.Yx?i.jx:s.R,e.fillText(s.Lx,n.qh+n.ts/2,n.Wx+n.qt/2),e.restore()}$x(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()}Hx(t,i,s,n){const{context:e,horizontalPixelRatio:r,verticalPixelRatio:h}=t;if(i.Nx===s.sn&&"close"===i.Xx){e.save();const t=i.Wt;Ch(e,{qh:n.qh,Wx:n.Wx+t,ts:n.ts-t,qt:n.qt-2*t},Math.max(0,i.Ux-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.Wx+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()}Vx(t,i){const{context:s,horizontalPixelRatio:n,verticalPixelRatio:e}=t,r=i.Rx.find(t=>"entry"===t.sn)??i.Rx[0],h=i.Rx.map(t=>t.ct),l=Math.round(this.Sx*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.Rx)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.qx),s.fill(),s.lineWidth=Math.max(1,Math.round(1.5*n)),s.strokeStyle=t.R,s.stroke();s.restore()}}function Ch(t,i,s,n,e,r="all"){const h=Math.round(i.qh*n),l=Math.round(i.Wx*e),o=Math.round(i.ts*n),a=Math.round(i.qt*e),_=Math.min(s*n,o/2,a/2);A(t,h,l,o,a,"left"===r?[_,0,0,_]:"right"===r?[0,_,_,0]:[_,_,_,_])}class Ph{constructor(){this.Jt=new xh,this.jt=null}Tt(t){this.jt=t}renderer(){return null===this.jt?null:(this.Jt.lt(this.jt),this.Jt)}zOrder(){return"top"}Xn(t,i,s=0){return null===this.jt?null:this.Jt.Xn(t,i,s)}}class Th{constructor(t){this.Qt=t}coordinate(){return this.Gx()?.Ai??-1e3}text(){return this.Gx()?.hi??""}textColor(){return this.Gx()?.AM??"#FFFFFF"}backColor(){return this.Gx()?.R??"#000000"}visible(){return null!==this.Gx()}Gx(){return this.Qt()}}let kh=0;class Dh{constructor(t,i,s){this.eh=new Ph,this.Po=new S([]),this.Kx=new Map,this.Zx=!1,this.Jx=null,this.mS=null,this.Qx=null,this.QS=null,this.Of=t,this.be=i,this.So="pipsend-position-line-"+kh++,this.Ps=s,this.Bf={...yh,...s.theme},this.nM=[this.eh],this.tC=Sh.map(t=>new Th(()=>this.iC(t))),this.sC=function(t,i){let s=bh.get(t);return s||(s=new vh,bh.set(t,s)),s.BS(i),s}(this.Of,this.So),this.be.attachPrimitive(this),uh(this.Of)?.BS(this)}attached(t){this.gM=t.requestUpdate,this.Zx=!0,this.requestUpdate()}detached(){this.Zx=!1,this.gM=void 0}paneViews(){return this.nM}priceAxisViews(){return this.tC}updateAllViews(){this.eh.Tt(this.nC())}hitTest(t,i){const s=this.eh.Xn(t,i);if(null===s)return null;const n=this.eC(s.sn);return null===n?null:{externalId:`${this.So}#${s.sn}:${s.$S}`,zOrder:"top",cursorStyle:"close"===s.$S?"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.Jx===n&&this.mS===e||(this.Jx=n,this.mS=e,this.requestUpdate())}setHovered(t){t||this.setHoveredPart(null)}isDraggable(){return null!==this.Jx&&"close"!==this.mS&&(this.eC(this.Jx)?.draggable??!0)}isClickable(){return"close"===this.mS||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.eC(n.sn)?null:`${this.So}#${n.sn}:${n.$S}`}dragAnchorY(){if(null===this.Qx)return null;const t=this.eC(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.Jx,null===this.Qx)return;const t=this.eC(this.Qx)?.price??null;this.QS=t,null!==t&&this.Ps.onDragStart&&this.Ps.onDragStart(this.Qx,t)}dragTo(t){null!==this.Qx&&(this.rC(this.Qx,t),this.Ps.onDragMove&&this.Ps.onDragMove(this.Qx,t))}commitDrag(){const t=this.Qx;if(this.Qx=null,this.QS=null,null===t)return;const i=this.eC(t)?.price;void 0!==i&&this.Ps.onDragEnd&&this.Ps.onDragEnd(t,i)}cancelDrag(){const t=this.Qx,i=this.QS;if(this.Qx=null,this.QS=null,null===t)return;null!==i&&i!==this.eC(t)?.price&&(this.rC(t,i),this.Ps.onDragMove&&this.Ps.onDragMove(t,i)),this.Ps.onDragCancel&&this.Ps.onDragCancel(t,this.eC(t)?.price??0)}click(){const t=this.Jx;if(null===t)return;if("close"===this.mS)return void(this.Ps.onClose&&this.Ps.onClose(t));const i=this.eC(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.eC(i)?.price,n={...this.Ps,...t};if(n.entry={...this.Ps.entry,...t.entry},n.takeProfit=Rh(this.Ps.takeProfit,t,"takeProfit"),n.stopLoss=Rh(this.Ps.stopLoss,t,"stopLoss"),this.Ps=n,null!==i&&void 0!==s){const t=this.eC(i);null!==t&&(t.price=s)}t.theme&&(this.Bf={...this.Bf,...t.theme}),this.requestUpdate()}setPrice(t,i){this.Qx!==t&&this.rC(t,i)}setText(t,i){const s=this.eC(t);null!==s&&(s.text=i,this.requestUpdate())}prices(){const t={};for(const i of Sh){const s=this.eC(i);null!==s&&(t[i]=s.price)}return t}options(){return this.Ps}remove(){ch(this.Of,this),function(t,i){const s=bh.get(t);s&&(s.ES(i),s.Gi()&&bh.delete(t))}(this.Of,this.So),this.be.detachPrimitive(this)}requestUpdate(){this.gM&&this.gM()}iC(t){const i=this.eC(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??Mh[t],e=this.be.priceFormatter(),r=this.Kx.get(t);if(void 0!==r&&r.bt===i.price&&r.R===n&&r.hl===e)return r.Jl.Ai!==s&&(r.Jl={...r.Jl,Ai:s}),r.Jl;const h={Ai:s,hi:e.format(i.price),R:n,AM:this.Po.K(n).J};return this.Kx.set(t,{bt:i.price,R:n,hl:e,Jl:h}),h}eC(t){return("entry"===t?this.Ps.entry:this.Ps[t])??null}rC(t,i){const s=this.eC(t);null!==s&&(s.price=i,s.formatText&&(s.text=s.formatText(i)),this.requestUpdate())}nC(){if(!this.Zx||!1===this.Ps.visible)return null;const t=this.Of.options().layout,i=this.Bf.fontSize??t.fontSize,s=i+2*this.Bf.paddingY,n=[],e=[];for(const t of Sh){const i=this.eC(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,Bx:0,R:i.color??Mh[t],hi:i.formatText?i.formatText(i.price):i.text??"",Lx:i.badge??"",Yx:i.badgeFilled??h,dt:i.lineWidth??1,Kt:i.lineStyle??(h?0:2),xx:i.closable??!0,hC:i.draggable??!0})}if(0===n.length)return this.sC.gx(this.So,[]),null;this.sC.gx(this.So,e);for(const t of n)t.Bx=this.sC.bx(this.So,t.sn);return{Rx:n,Z:this.Bf.background??(r=t.background,"solid"===r.type?r.color:r.topColor),AM:this.Bf.textColor,jx:this.Bf.badgeTextColor,Ux:this.Bf.borderRadius,Wt:this.Bf.borderWidth,TM:this.Bf.paddingX,Ax:this.Bf.paddingY,qx:this.Bf.backgroundOpacity,T:g(i,this.Bf.fontFamily??t.fontFamily),P:i,Fx:!1!==this.Ps.connectorVisible&&n.length>1,yu:this.Ps.rightOffset??56,Nx:this.Jx,Xx:this.mS};var r}}function Rh(t,i,s){if(!(s in i))return t;const n=i[s];return void 0===n?void 0:{...t,...n}}const Fh=new Set(["line","body","stroke","center","move"]);function Ih(t,i,s){if(null===i)return null;const n=String(i);return{externalId:`${t}#${n}`,zOrder:"normal",cursorStyle:s?Fh.has(n)?"move":"grab":void 0}}function Vh(t,i,s){return t?{bt:s-t.price,gt:null===t.time?0:i-t.time}:{bt:0,gt:0}}var Ah;function Lh(t){if(null==t)return null;if("number"==typeof t||"string"==typeof t)return t;const i=t,s=i.year??i.Ay;if(void 0!==s){const t={};return t.year=s,t.month=i.month??i.Ly,t.day=i.day??i.By,t}return t}function Bh(t,i){const s={};return s.price=t,s.time=i,s}function Eh(t){if(!t)return Bh(0,null);return Bh(t.price??t.bt??0,Lh(t.time??t.gt??null))}function Oh(t,i="time"){return t?t[i]??null:null}function Wh(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"}(Ah||(Ah={}));class zh{constructor(t,i,s={}){this._state=Ah.Idle,this._visible=!0,this._locked=!1,this._ownOptions=null,this._chart=t.chart,this._series=t.series,this._type=i,this._id=this.lC(),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}lC(){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}selectionBox(){return null}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 $h=new WeakMap;function Hh(t,i){$h.set(t,i)}function Nh(t){const i=!0===$h.get(t);return i&&$h.set(t,!1),i}function Uh(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.AM??"#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(l,(a+5)*s,e.ct*n),t.restore()}var qh;!function(t){t.oC="idle",t.aC="waiting_first_point",t._C="waiting_second_point",t.uC="completed"}(qh||(qh={}));class Yh{constructor(t,i,s={}){this.Ov=qh.oC,this.cC=null,this.hx=null,this.op=null,this.Of=t,this.be=i,this.dC=s}pC(){this.Ov===qh.oC&&(this.Ov=qh.aC,this.cC=null,this.fC(),this.vC())}mC(){this.Ov=qh.oC,this.cC=null,this.wC(),this.gC(),this.dC.bC&&this.dC.bC()}MC(){return this.Ov}yC(){return this.Ov===qh.aC||this.Ov===qh._C}fC(){this.hx=t=>{this.SC(t)},this.Of.subscribeClick(this.hx)}vC(){this.op=t=>{this.xC(t)},this.Of.subscribeCrosshairMove(this.op)}wC(){this.hx&&(this.Of.unsubscribeClick(this.hx),this.hx=null)}gC(){this.op&&(this.Of.unsubscribeCrosshairMove(this.op),this.op=null)}SC(t){if(!t.point)return;if(Nh(this.Of))return;const i=this.be.coordinateToPrice(t.point.y),s=Jn(this.Of,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.Ov===qh.aC?(this.cC=n,this.Ov=qh._C,this.dC.CC&&this.dC.CC(n)):this.Ov===qh._C&&this.cC&&(this.Ov=qh.uC,this.dC.PC&&this.dC.PC(n),this.dC.TC&&this.dC.TC(this.cC,n),this.wC(),this.gC(),this.Ov=qh.oC,this.cC=null)}xC(t){if(!t.point)return;if(this.Ov!==qh._C)return;const i=this.be.coordinateToPrice(t.point.y),s=Jn(this.Of,this.be,t.point.x);if(null===i||null===s)return;const n={gt:s,bt:i};this.dC.kC&&this.dC.kC(n)}m(){this.mC()}}class jh{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Xh{constructor(t){this.DC=t,this.Jt=new jh(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Gh extends zh{constructor(t,i){super(t,"trend-line",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.BC=null,this.EC=null,this.OC=!1,this.WC=null,this.zC=null,this.$C={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",extendLeft:!1,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.$C),this.Ky(),this.$C.interactive?this.HC():this.OC=!0}HC(){const t=new Yh(this._chart,this._series,{CC:t=>{this.$C.point1Time=t.gt,this.$C.point1Price=t.bt,this.gM()},PC:t=>{this.$C.point2Time=t.gt,this.$C.point2Price=t.bt,this.OC=!0,this.gM(),this.$C.onUpdate&&this.$C.onUpdate()},kC:t=>{this.$C.point1Time&&!this.OC&&(this.zC=t,this.gM())},TC:()=>{this.OC=!0}});this.WC=t,t.pC()}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Xh(this)}qC(){if(!this.$C.point1Time||!this.$C.point2Time)return null;const t=Qn(this._chart,this._series,this.$C.point1Time)??0,i=this._series.priceToCoordinate(this.$C.point1Price)??0,s=Qn(this._chart,this._series,this.$C.point2Time)??0,n=this._series.priceToCoordinate(this.$C.point2Price)??0;if(!this.$C.extendLeft&&!this.$C.extendRight)return{YC:t,jC:i,XC:s,GC:n};if(s===t)return{YC:t,jC:i,XC:s,GC:n};const e=this._chart.chartElement().clientWidth,r=(n-i)/(s-t);return{YC:this.$C.extendLeft?0:t,jC:this.$C.extendLeft?i-r*t:i,XC:this.$C.extendRight?e:s,GC:this.$C.extendRight?i+r*(e-t):n}}KC(){const t=this.qC();if(null===t)return null;const i=t.XC>=t.YC?t.GC:t.jC,s=this._chart.chartElement().clientHeight;return i>=0&&i<=s?this._series.coordinateToPrice(i):this.$C.point2Price??this.$C.point1Price??null}drawToCanvas(t,i,s){if(!this.OC&&this.$C.point1Time&&this.zC)return void this.ZC(t,i,s);if(!this.$C.point1Time||!this.$C.point2Time)return;const n=(Qn(this._chart,this._series,this.$C.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.$C.point1Price)??0)*s,r=(Qn(this._chart,this._series,this.$C.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.$C.point2Price)??0)*s,l=this.$C.lineColor,o=this.FC?this.$C.lineWidth+1:this.$C.lineWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.$C.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.$C.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath();const a=this.qC();if(null===a)return;t.moveTo(a.YC*i,a.jC*s),t.lineTo(a.XC*i,a.GC*s),t.stroke(),t.setLineDash([]),!this.FC&&!this.IC||this.isLocked()||(this.JC(t,n,e,i,l),this.JC(t,r,h,i,l));const _=this.KC();if(!1!==this.$C.showPriceLabel&&null!==_){const n=this._series.priceToCoordinate(_);null!==n&&Uh(t,this._series,i,s,{bt:_,ct:n,Ot:l})}}ZC(t,i,s){if(!this.$C.point1Time||!this.zC)return;const n=(Qn(this._chart,this._series,this.$C.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.$C.point1Price)??0)*s,r=(Qn(this._chart,this._series,this.zC.gt)??0)*i,h=(this._series.priceToCoordinate(this.zC.bt)??0)*s;t.strokeStyle=this.$C.lineColor,t.lineWidth=this.$C.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.JC(t,n,e,i,this.$C.lineColor),t.globalAlpha=.5,this.JC(t,r,h,i,this.$C.lineColor),t.globalAlpha=1}JC(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.$C.lineColor=t,this.gM()}color(){return this.$C.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}isHovered(){return this.IC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){const s=this.qC();if(null===s)return!1;return this.QC(t,i,s.YC,s.jC,s.XC,s.GC)<=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.$C.point1Time||!this.$C.point2Time)return null;const s=Qn(this._chart,this._series,this.$C.point1Time)??0,n=this._series.priceToCoordinate(this.$C.point1Price)??0,e=Qn(this._chart,this._series,this.$C.point2Time)??0,r=this._series.priceToCoordinate(this.$C.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.VC=!0,this.AC=t,this.LC=i,"line"===t&&(this.BC={gt:this.$C.point1Time,bt:this.$C.point1Price},this.EC={gt:this.$C.point2Time,bt:this.$C.point2Price})}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.BC=null,this.EC=null}updateDrag(t,i){if(this.VC&&this.AC){if("point1"===this.AC)this.$C.point1Time=t,this.$C.point1Price=i;else if("point2"===this.AC)this.$C.point2Time=t,this.$C.point2Price=i;else if("line"===this.AC&&this.BC&&this.EC){const s=Vh(this.LC,t,i);this.$C.point1Time=this.BC.gt+s.gt,this.$C.point1Price=this.BC.bt+s.bt,this.$C.point2Time=this.EC.gt+s.gt,this.$C.point2Price=this.EC.bt+s.bt}this.gM(),this.$C.onUpdate&&this.$C.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"trendLine",points:[Bh(this.$C.point1Price??0,Lh(this.$C.point1Time)),Bh(this.$C.point2Price??0,Lh(this.$C.point2Time))],style:{lineColor:this.$C.lineColor,lineWidth:this.$C.lineWidth,lineStyle:this.$C.lineStyle,extendLeft:this.$C.extendLeft,extendRight:this.$C.extendRight}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return this.OC}remove(){this.WC&&(this.WC.m(),this.WC=null),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.$C.onRemove&&this.$C.onRemove()}}function Kh(t,i){return new Gh(t,i)}function Zh(t,i,s,n){let e=0,r=null;const h=()=>{null!==r&&(t.unsubscribeClick(r),r=null)};return r=r=>{if(!r.point||Nh(t))return;const l=i.coordinateToPrice(r.point.y),o=Jn(t,i,r.point.x);null!==l&&null!==o&&(e++,e>=s&&h(),n({gt:o,bt:l,ut:r.point.x,ct:r.point.y},e-1))},t.subscribeClick(r),{tP:()=>null!==r,iP:h}}function Jh(t){const i=t.timeScale();return Math.max(i.width()/5,i.options().barSpacing)}function Qh(t,i){const s=t.timeScale(),n=Math.min(i+Jh(t),s.width()-10);return Math.max(n,i+s.options().barSpacing)}class tl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class il{constructor(t){this.DC=t,this.Jt=new tl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class sl extends zh{constructor(t,i){super(t,"horizontal-line",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.LC=null,this.sP=0,this.nP=null,this.eP={lineColor:"#2962ff",lineWidth:2,lineStyle:"solid",showLabel:!0,showPriceLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.eP),this.Ky(),this.eP.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>this.rP(t)))}rP(t){this.eP.price=t.bt,void 0!==this.eP.startTime&&(this.eP.startTime=t.gt),this.gM()}isComplete(){return!this.nP?.tP()}selectionBox(){const t=void 0===this.eP.price?null:this._series.priceToCoordinate(this.eP.price);return null===t?null:{left:this.hP(),right:this._chart.timeScale().width(),top:t,bottom:t}}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new il(this)}hP(){return void 0===this.eP.startTime?0:Qn(this._chart,this._series,this.eP.startTime)??0}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.eP.price)return;const n=(this._series.priceToCoordinate(this.eP.price)??0)*s,e=this._chart.chartElement().clientWidth*i,r=this.hP()*i,h=this.eP.lineColor,l=this.FC?this.eP.lineWidth+1:this.eP.lineWidth;t.strokeStyle=h,t.lineWidth=l*i,"dashed"===this.eP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.eP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(r,n),t.lineTo(e,n),t.stroke(),t.setLineDash([]),!1!==this.eP.showPriceLabel&&Uh(t,this._series,i,s,{bt:this.eP.price,ct:n/s,Ot:h}),this.eP.showLabel&&(this.FC||this.IC)&&this.lP(t,n,i,s,h)}lP(t,i,s,n,e){const r=this.eP.labelText||this.eP.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.eP.lineColor=t,this.gM()}color(){return this.eP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.eP.price)return!1;const s=this._series.priceToCoordinate(this.eP.price)??0;return!(t<this.hP()-8)&&Math.abs(i-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.VC=!0,this.LC=i,this.sP=this.eP.price??0}stopDrag(){this.VC=!1,this.LC=null}updateDrag(t,i){this.VC&&(this.eP.price=this.sP+Vh(this.LC,t,i).bt,this.gM(),this.eP.onUpdate&&this.eP.onUpdate())}getPrice(){return this.eP.price}setPrice(t){this.eP.price=t,this.gM()}setLabel(t){this.eP.labelText=t,this.gM()}isVisible(){return this._visible}_serializeShape(){return{type:"horizontalLine",points:[Bh(this.eP.price??0,Lh(this.eP.startTime))],style:{lineColor:this.eP.lineColor,lineWidth:this.eP.lineWidth,lineStyle:this.eP.lineStyle,showLabel:this.eP.showLabel,labelText:this.eP.labelText}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.nP?.iP(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.eP.onRemove&&this.eP.onRemove()}}function nl(t,i){return new sl(t,i)}class el{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class rl{constructor(t){this.DC=t,this.Jt=new el(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class hl extends zh{constructor(t,i){super(t,"cross-line",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.LC=null,this.oP=0,this.sP=0,this.nP=null,this.aP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showPriceLabel:!0,...i},this._registerOptions(this.aP),this.Ky(),this.aP.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>{this.aP.time=t.gt,this.aP.price=t.bt,this.gM()}))}isComplete(){return!this.nP?.tP()}Ky(){this.eh=new rl(this);const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}gM(){this.RC&&this.RC()}_update(){this.gM()}_P(){if(!this.isComplete()||void 0===this.aP.time||void 0===this.aP.price)return null;const t=Qn(this._chart,this._series,this.aP.time),i=this._series.priceToCoordinate(this.aP.price);return null===t||null===i?null:{ut:t,ct:i}}drawToCanvas(t,i,s){const n=this._P();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.aP.lineColor,_=this.FC||this.IC&&!this.isLocked(),u=_?this.aP.lineWidth+1:this.aP.lineWidth;t.strokeStyle=a,t.lineWidth=u*i,"dashed"===this.aP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.aP.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.aP.showPriceLabel&&void 0!==this.aP.price&&Uh(t,this._series,i,s,{bt:this.aP.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())}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){const s=this._P();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.VC=!0,this.LC=i,this.oP=this.aP.time,this.sP=this.aP.price??0}updateDrag(t,i){if(!this.VC)return;const s=Vh(this.LC,t,i);this.aP.time=this.oP+s.gt,this.aP.price=this.sP+s.bt,this.gM(),this.aP.onUpdate&&this.aP.onUpdate()}stopDrag(){this.VC=!1,this.LC=null}setColor(t){this.aP.lineColor=t,this.gM()}color(){return this.aP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}remove(){if(this.nP?.iP(),this.Zb){try{this._series.detachPrimitive(this.Zb)}catch(t){}this.Zb=null}this.RC=null,this.aP.onRemove&&this.aP.onRemove()}_serializeShape(){return{type:"crossLine",points:[Bh(this.aP.price??0,Lh(this.aP.time))],style:{lineColor:this.aP.lineColor,lineWidth:this.aP.lineWidth,lineStyle:this.aP.lineStyle}}}}function ll(t,i){return new hl(t,i)}class ol{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class al{constructor(t){this.DC=t,this.Jt=new ol(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class _l extends zh{constructor(t,i){super(t,"polygon",i),this.V_=[],this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.uP=null,this.OC=!1,this.zC=null,this.hx=null,this.cP=null,this.dP=null,this.pP={fillColor:"#2962FF",fillOpacity:.15,borderColor:"#2962FF",borderWidth:2,borderStyle:"solid",interactive:!1,...i},this._registerOptions(this.pP),this.V_=[...i.points??[]],this.Ky(),this.pP.interactive?this.fP():this.OC=this.V_.length>=3}Ky(){this.eh=new al(this);const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}gM(){this.RC&&this.RC()}_update(){this.gM()}fP(){this.hx=t=>{if(!t.point||Nh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.V_.length>=3&&this.vP(t.point.x,t.point.y)?this.mP():(this.V_.push({time:s,price:i}),this.gM()))},this.cP=t=>{if(!t.point||this.OC)return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.zC={time:s,price:i},this.gM())},this.dP=t=>{"Enter"===t.key&&this.V_.length>=3?this.mP():"Escape"===t.key&&(this.V_=[],this.mP())},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.cP),document.addEventListener("keydown",this.dP)}vP(t,i){const s=this.V_[0],n=Qn(this._chart,this._series,s.time),e=this._series.priceToCoordinate(s.price);return null!==n&&null!==e&&(Math.abs(t-n)<=_l.wP&&Math.abs(i-e)<=_l.wP)}mP(){this.OC=!0,this.zC=null,this.gP(),this.gM(),this.pP.onComplete&&this.pP.onComplete(),this.pP.onUpdate&&this.pP.onUpdate()}gP(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.cP&&(this._chart.unsubscribeCrosshairMove(this.cP),this.cP=null),this.dP&&(document.removeEventListener("keydown",this.dP),this.dP=null)}bP(){const t=[...this.V_];return this.OC||null===this.zC||t.push(this.zC),this.MP(t)}MP(t){const i=[];for(const s of t){const t=Qn(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.bP();if(n.length<2)return;const e=this.pP.borderColor,r=this.FC?this.pP.borderWidth+1:this.pP.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.OC&&(t.closePath(),this.pP.fillOpacity>0&&(t.fillStyle=this.$y(this.pP.fillColor,this.pP.fillOpacity),t.fill())),t.strokeStyle=e,t.lineWidth=r*i,this.OC?"dashed"===this.pP.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.pP.borderStyle&&t.setLineDash([2*i,3*i]):t.setLineDash([6*i,4*i]),t.stroke(),t.setLineDash([]);if((this.FC||this.IC||!this.OC)&&!this.isLocked())for(const n of this.yP())this.SP(t,n.ut*i,n.ct*s,i,e)}yP(){return this.MP(this.V_)}SP(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()}$y(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}UC(t,i){if(!this.isVisible()||!this.OC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,`corner-${s}`,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){const s=this.yP();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.yP();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.VC=!0,this.AC=t,this.LC=i,this.uP=this.V_.map(t=>({gt:t.time,bt:t.price}))}updateDrag(t,i){if(this.VC&&null!==this.AC&&null!==this.uP){if("shape"===this.AC){const s=Vh(this.LC,t,i);this.V_=this.uP.map(t=>({gt:t.time+s.gt,bt:t.price+s.bt}))}else{const s=this.AC;this.V_[s]&&(this.V_[s]={time:t,price:i})}this.gM(),this.pP.onUpdate&&this.pP.onUpdate()}}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.uP=null}setColor(t){this.pP.borderColor=t,this.pP.fillColor=t,this.gM()}color(){return this.pP.borderColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}points(){return this.V_}isComplete(){return this.OC}remove(){if(this.gP(),this.Zb){try{this._series.detachPrimitive(this.Zb)}catch(t){}this.Zb=null}this.RC=null,this.pP.onRemove&&this.pP.onRemove()}_serializeShape(){return{type:"polygon",points:this.V_.map(t=>Bh(t.price,Lh(t.time))),style:{fillColor:this.pP.fillColor,fillOpacity:this.pP.fillOpacity,borderColor:this.pP.borderColor,borderWidth:this.pP.borderWidth,borderStyle:this.pP.borderStyle}}}}function ul(t,i){return new _l(t,i)}_l.wP=12;class cl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class dl{constructor(t){this.DC=t,this.Jt=new cl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class pl extends zh{constructor(t,i){super(t,"parallel-channel",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.xP=null,this.OC=!1,this.md=0,this.zC=null,this.hx=null,this.cP=null,this.CP={lineColor:"#2962FF",lineWidth:2,lineStyle:"solid",fillColor:"#2962FF",fillOpacity:.1,channelWidth:0,extendRight:!1,showPriceLabel:!0,interactive:!1,...i},this._registerOptions(this.CP),this.Ky(),this.CP.interactive?this.fP():this.OC=!0}Ky(){this.eh=new dl(this);const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}gM(){this.RC&&this.RC()}_update(){this.gM()}fP(){this.hx=t=>{if(!t.point||Nh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.md)this.CP.point1Time=s,this.CP.point1Price=i;else{if(1!==this.md)return this.CP.channelWidth=i-this.PP(s),void this.mP();this.CP.point2Time=s,this.CP.point2Price=i}this.md++,this.gM()}},this.cP=t=>{if(!t.point||this.OC)return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.zC={gt:s,bt:i},2===this.md&&(this.CP.channelWidth=i-this.PP(s)),this.gM())},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.cP)}mP(){this.OC=!0,this.zC=null,this.gP(),this.gM(),this.CP.onComplete&&this.CP.onComplete(),this.CP.onUpdate&&this.CP.onUpdate()}gP(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.cP&&(this._chart.unsubscribeCrosshairMove(this.cP),this.cP=null)}PP(t){const i=this.CP.point1Time,s=this.CP.point2Time,n=this.CP.point1Price,e=this.CP.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)}fS(){const t=this.CP,i=this.OC?t.point2Time:t.point2Time??this.zC?.gt,s=this.OC?t.point2Price:t.point2Price??this.zC?.bt;if(void 0===t.point1Time||void 0===t.point1Price||void 0===i||void 0===s)return null;const n=Qn(this._chart,this._series,t.point1Time),e=Qn(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:{YC:n,XC:l,TP:r,kP:o,DP:_,RP:u}}drawToCanvas(t,i,s){const n=this.fS();if(null===n)return;const e=this.CP,r=e.lineColor,h=this.FC?e.lineWidth+1:e.lineWidth,l=i,o=s;e.fillOpacity>0&&0!==(e.channelWidth??0)&&(t.fillStyle=this.$y(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.YC*l,n.TP*o),t.lineTo(n.XC*l,n.kP*o),t.lineTo(n.XC*l,n.RP*o),t.lineTo(n.YC*l,n.DP*o),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=h*l,this.OC?"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.YC*l,n.TP*o),t.lineTo(n.XC*l,n.kP*o),0!==(e.channelWidth??0)&&(t.moveTo(n.YC*l,n.DP*o),t.lineTo(n.XC*l,n.RP*o)),t.stroke(),t.setLineDash([]);if((this.FC||this.IC||!this.OC)&&!this.isLocked()&&(this.SP(t,n.YC*l,n.TP*o,l,r),this.SP(t,n.XC*l,n.kP*o,l,r),0!==(e.channelWidth??0))){const i=(n.YC+n.XC)/2,s=(n.DP+n.RP)/2;this.SP(t,i*l,s*o,l,r)}if(!1!==e.showPriceLabel&&this.OC){const i=this._series.coordinateToPrice(n.kP);null!==i&&Uh(t,this._series,l,o,{bt:i,ct:n.kP,Ot:r})}}SP(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()}$y(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}UC(t,i){if(!this.isVisible()||!this.OC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(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.fS();if(null===s)return!1;return this.FP(t,i,s.YC,s.TP,s.XC,s.kP)<=8||this.FP(t,i,s.YC,s.DP,s.XC,s.RP)<=8}hitTestEndpoint(t,i){const s=this.fS();if(null===s)return null;const n=(s,n)=>Math.abs(t-s)<=10&&Math.abs(i-n)<=10;if(n(s.YC,s.TP))return"point1";if(n(s.XC,s.kP))return"point2";if(0!==(this.CP.channelWidth??0)){if(n((s.YC+s.XC)/2,(s.DP+s.RP)/2))return"width"}return null}startDrag(t,i){this.VC=!0,this.AC=t,this.LC=i,this.xP={IP:{gt:this.CP.point1Time,bt:this.CP.point1Price},VP:{gt:this.CP.point2Time,bt:this.CP.point2Price},ts:this.CP.channelWidth??0}}updateDrag(t,i){if(!this.VC||null===this.AC||null===this.xP)return;const s=this.CP;if("point1"===this.AC)s.point1Time=t,s.point1Price=i;else if("point2"===this.AC)s.point2Time=t,s.point2Price=i;else if("width"===this.AC)s.channelWidth=i-this.PP(t);else{const n=Vh(this.LC,t,i);s.point1Time=this.xP.IP.gt+n.gt,s.point1Price=this.xP.IP.bt+n.bt,s.point2Time=this.xP.VP.gt+n.gt,s.point2Price=this.xP.VP.bt+n.bt,s.channelWidth=this.xP.ts}this.gM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.xP=null}setColor(t){this.CP.lineColor=t,this.CP.fillColor=t,this.gM()}color(){return this.CP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}isComplete(){return this.OC}remove(){if(this.gP(),this.Zb){try{this._series.detachPrimitive(this.Zb)}catch(t){}this.Zb=null}this.RC=null,this.CP.onRemove&&this.CP.onRemove()}_serializeShape(){return{type:"parallelChannel",points:[Bh(this.CP.point1Price??0,Lh(this.CP.point1Time)),Bh(this.CP.point2Price??0,Lh(this.CP.point2Time))],style:{lineColor:this.CP.lineColor,lineWidth:this.CP.lineWidth,lineStyle:this.CP.lineStyle,fillColor:this.CP.fillColor,fillOpacity:this.CP.fillOpacity,extendRight:this.CP.extendRight},extra:{channelWidth:this.CP.channelWidth}}}}function fl(t,i){return new pl(t,i)}class vl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ml{constructor(t){this.DC=t,this.Jt=new vl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class wl extends zh{constructor(t,i){super(t,"pitchfork",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.xP=null,this.OC=!1,this.md=0,this.zC=null,this.hx=null,this.cP=null,this.AP={lineColor:"#9C27B0",lineWidth:2,lineStyle:"solid",fillColor:"#9C27B0",fillOpacity:.08,interactive:!1,...i},this._registerOptions(this.AP),this.Ky(),this.AP.interactive?this.fP():this.OC=!0}Ky(){this.eh=new ml(this);const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}gM(){this.RC&&this.RC()}_update(){this.gM()}fP(){this.hx=t=>{if(!t.point||Nh(this._chart))return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);if(null!==i&&null!==s){if(0===this.md)this.AP.pivotTime=s,this.AP.pivotPrice=i;else{if(1!==this.md)return this.AP.lowerTime=s,this.AP.lowerPrice=i,this.md++,void this.mP();this.AP.upperTime=s,this.AP.upperPrice=i}this.md++,this.gM()}},this.cP=t=>{if(!t.point||this.OC)return;const i=this._series.coordinateToPrice(t.point.y),s=Jn(this._chart,this._series,t.point.x);null!==i&&null!==s&&(this.zC={gt:s,bt:i},this.gM())},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.cP)}mP(){this.OC=!0,this.zC=null,this.gP(),this.gM(),this.AP.onComplete&&this.AP.onComplete(),this.AP.onUpdate&&this.AP.onUpdate()}gP(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.cP&&(this._chart.unsubscribeCrosshairMove(this.cP),this.cP=null)}LP(t,i){if(void 0===t||void 0===i)return null;const s=Qn(this._chart,this._series,t),n=this._series.priceToCoordinate(i);return null===s||null===n?null:{ut:s,ct:n}}BP(){const t=this.AP,i=this.LP(t.pivotTime,t.pivotPrice),s=this.LP(t.upperTime,t.upperPrice),n=this.OC?this.LP(t.lowerTime,t.lowerPrice):this.LP(t.lowerTime,t.lowerPrice)??(null!==this.zC&&this.md>=2?this.LP(this.zC.gt,this.zC.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{EP:i,OP:e,WP:s,zP:n,$P:l(i),HP:l(s),NP:l(n)}}drawToCanvas(t,i,s){const n=this.BP();if(null===n)return void this.UP(t,i,s);const e=this.AP,r=e.lineColor,h=i,l=s;e.fillOpacity>0&&(t.fillStyle=this.$y(e.fillColor,e.fillOpacity),t.beginPath(),t.moveTo(n.WP.ut*h,n.WP.ct*l),t.lineTo(n.HP.ut*h,n.HP.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.lineTo(n.zP.ut*h,n.zP.ct*l),t.closePath(),t.fill()),t.strokeStyle=r,t.lineWidth=(this.FC?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.WP.ut*h,n.WP.ct*l),t.lineTo(n.zP.ut*h,n.zP.ct*l),t.moveTo(n.EP.ut*h,n.EP.ct*l),t.lineTo(n.$P.ut*h,n.$P.ct*l),t.moveTo(n.WP.ut*h,n.WP.ct*l),t.lineTo(n.HP.ut*h,n.HP.ct*l),t.moveTo(n.zP.ut*h,n.zP.ct*l),t.lineTo(n.NP.ut*h,n.NP.ct*l),t.stroke(),t.setLineDash([]);if((this.FC||this.IC||!this.OC)&&!this.isLocked())for(const i of[n.EP,n.WP,n.zP])this.SP(t,i.ut*h,i.ct*l,h,r)}UP(t,i,s){const n=this.AP,e=this.LP(n.pivotTime,n.pivotPrice);if(null===e)return;const r=this.LP(n.upperTime,n.upperPrice)??(null!==this.zC?this.LP(this.zC.gt,this.zC.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.SP(t,e.ut*i,e.ct*s,i,h)}SP(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()}$y(t,i){return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}UC(t,i){if(!this.isVisible()||!this.OC)return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(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.EP,s.$P],[s.WP,s.HP],[s.zP,s.NP],[s.WP,s.zP]].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.EP)?"pivot":n(s.WP)?"upper":n(s.zP)?"lower":null}startDrag(t,i){this.VC=!0,this.AC=t,this.LC=i,this.xP=[{gt:this.AP.pivotTime,bt:this.AP.pivotPrice},{gt:this.AP.upperTime,bt:this.AP.upperPrice},{gt:this.AP.lowerTime,bt:this.AP.lowerPrice}]}updateDrag(t,i){if(!this.VC||null===this.AC||null===this.xP)return;const s=this.AP;if("pivot"===this.AC)s.pivotTime=t,s.pivotPrice=i;else if("upper"===this.AC)s.upperTime=t,s.upperPrice=i;else if("lower"===this.AC)s.lowerTime=t,s.lowerPrice=i;else{const n=Vh(this.LC,t,i),[e,r,h]=this.xP;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.gM(),s.onUpdate&&s.onUpdate()}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.xP=null}setColor(t){this.AP.lineColor=t,this.AP.fillColor=t,this.gM()}color(){return this.AP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}isComplete(){return this.OC}remove(){if(this.gP(),this.Zb){try{this._series.detachPrimitive(this.Zb)}catch(t){}this.Zb=null}this.RC=null,this.AP.onRemove&&this.AP.onRemove()}_serializeShape(){return{type:"pitchfork",points:[Bh(this.AP.pivotPrice??0,Lh(this.AP.pivotTime)),Bh(this.AP.upperPrice??0,Lh(this.AP.upperTime)),Bh(this.AP.lowerPrice??0,Lh(this.AP.lowerTime))],style:{lineColor:this.AP.lineColor,lineWidth:this.AP.lineWidth,lineStyle:this.AP.lineStyle,fillColor:this.AP.fillColor,fillOpacity:this.AP.fillOpacity}}}}function gl(t,i){return new wl(t,i)}class bl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Ml{constructor(t){this.DC=t,this.Jt=new bl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class yl extends zh{constructor(t,i){super(t,"vertical-line",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.LC=null,this.oP=0,this.nP=null,this.qP={lineColor:"#787b86",lineWidth:1,lineStyle:"dashed",showLabel:!0,labelText:"",interactive:!1,...i},this._registerOptions(this.qP),this.Ky(),this.qP.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>{this.qP.time=t.gt,this.gM()}))}isComplete(){return!this.nP?.tP()}selectionBox(){const t=Qn(this._chart,this._series,this.qP.time);if(null===t)return null;let i;try{i=this._series.getPane().getHeight()/2}catch(t){return null}return{left:t,right:t,top:i,bottom:i}}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Ml(this)}drawToCanvas(t,i,s){if(!this.isComplete()||void 0===this.qP.time)return;const n=(Qn(this._chart,this._series,this.qP.time)??0)*i,e=this._chart.chartElement().clientHeight*s,r=this.qP.lineColor,h=this.FC||this.IC&&!this.isLocked()?this.qP.lineWidth+1:this.qP.lineWidth;t.strokeStyle=r,t.lineWidth=h*i,"dashed"===this.qP.lineStyle?t.setLineDash([10*i,5*i]):"dotted"===this.qP.lineStyle&&t.setLineDash([2*i,3*i]),t.beginPath(),t.moveTo(n,0),t.lineTo(n,e),t.stroke(),t.setLineDash([]),this.qP.showLabel&&(this.FC||this.IC)&&this.qP.labelText&&this.lP(t,n,i,s,r)}lP(t,i,s,n,e){const r=this.qP.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.qP.lineColor=t,this.gM()}color(){return this.qP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||void 0===this.qP.time)return!1;const s=Qn(this._chart,this._series,this.qP.time)??0;return Math.abs(t-s)<=8}hitTestEndpoint(t,i){return this.hitTest(t,i)?"line":null}startDrag(t,i){this.VC=!0,this.LC=i,this.oP=this.qP.time}stopDrag(){this.VC=!1,this.LC=null}updateDrag(t,i){this.VC&&(this.qP.time=this.oP+Vh(this.LC,t,i).gt,this.gM(),this.qP.onUpdate&&this.qP.onUpdate())}getTime(){return this.qP.time}setTime(t){this.qP.time=t,this.gM()}setLabel(t){this.qP.labelText=t,this.gM()}isVisible(){return this._visible}_serializeShape(){return{type:"verticalLine",points:[Bh(0,Lh(this.qP.time))],style:{lineColor:this.qP.lineColor,lineWidth:this.qP.lineWidth,lineStyle:this.qP.lineStyle,showLabel:this.qP.showLabel,labelText:this.qP.labelText}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.nP?.iP(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.qP.onRemove&&this.qP.onRemove()}}function Sl(t,i){return new yl(t,i)}const xl=[{YP:0,Jl:"0.0%"},{YP:.236,Jl:"23.6%"},{YP:.382,Jl:"38.2%"},{YP:.5,Jl:"50.0%"},{YP:.618,Jl:"61.8%"},{YP:.786,Jl:"78.6%"},{YP:1,Jl:"100.0%"}],Cl=[...xl,{YP:1.272,Jl:"127.2%"},{YP:1.414,Jl:"141.4%"},{YP:1.618,Jl:"161.8%"},{YP:2,Jl:"200.0%"},{YP:2.618,Jl:"261.8%"}];class Pl{constructor(t=!1){this.jP=t?Cl:xl}calculateLevels(t,i,s,n){const e=Math.abs(n-i),r=e/i*100,h=n>i,l=this.jP.map(({YP:t,Jl:i})=>{let s;return s=h?n-e*t:n+e*t,{YP:t,bt:s,Jl:i}});return{point1:{time:t,price:i},point2:{time:s,price:n},priceRange:e,priceRangePercent:r,levels:l,isUptrend:h}}getPriceAtRatio(t,i,s){const n=Math.abs(i-t);return i>t?i-n*s:i+n*s}formatPrice(t,i=5){return t.toFixed(i)}formatLevel(t,i=5){return`${t.label} (${this.formatPrice(t.price,i)})`}updateRatios(t){this.jP=t}getRatios(){return[...this.jP]}getRatioValues(){return this.jP.map(t=>t.YP)}useStandardRatios(){this.jP=xl}useExtendedRatios(){this.jP=Cl}}class Tl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class kl{constructor(t){this.DC=t,this.Jt=new Tl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}}function Dl(t){return{YP:t,Jl:`${(100*t).toFixed(1)}%`}}class Rl extends zh{constructor(t,i){super(t,"fibonacci-tool",i),this.Zb=null,this.RC=null,this.tM=null,this.eh=null,this.XP=null,this.OC=!1,this.FC=!1,this.IC=!1,this.zC=null,this.VC=!1,this.GP=null,this.op=null,this.KP={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.KP),this.ZP=new Pl(this.KP.useExtended),void 0!==this.KP.levels&&this.KP.levels.length>0&&this.ZP.updateRatios(this.KP.levels.map(Dl)),this.Ky(),this.KP.interactive?this.HC():(this.OC=!0,this.JP())}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new kl(this)}drawToCanvas(t,i,s){if(!this.OC&&this.KP.point1Time&&this.zC)return void this.ZC(t,i,s);if(!this.tM||!this.KP.point1Time||!this.KP.point2Time)return;const n=(Qn(this._chart,this._series,this.KP.point1Time)??0)*i,e=(Qn(this._chart,this._series,this.KP.point2Time)??0)*i,r=Math.min(n,e),h=Math.max(n,e),l=this.FC?2:this.KP.lineWidth;this.tM.levels.forEach(n=>{this.Ix(t,n,r,h,i,s,l)}),!this.FC&&!this.IC||this.isLocked()||(this.JC(t,n,(this._series.priceToCoordinate(this.KP.point1Price)??0)*s,i),this.JC(t,e,(this._series.priceToCoordinate(this.KP.point2Price)??0)*s,i))}Ix(t,i,s,n,e,r,h=1){const l=i.ratio??i.YP,o=i.price??i.bt;if(void 0===l||void 0===o)return;const a=(this._series.priceToCoordinate(o)??0)*r;let _=this.KP.levelColors?.[l.toString()]||this.KP.lineColor;t.strokeStyle=_,t.lineWidth=h*e,t.beginPath(),t.moveTo(s,a),t.lineTo(n,a),t.stroke(),this.KP.showLabels&&this.lP(t,i,s,n,a,e,_)}lP(t,i,s,n,e,r,h){const l=i.label??i.Jl,o=i.price??i.bt,a=`${l} ${this.ZP.formatPrice(o)}`;t.font=11*r+"px sans-serif";const _=t.measureText(a),u=4*r,c="right"===this.KP.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.KP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(a,c,d)}JP(){this.KP.point1Time&&this.KP.point1Price&&this.KP.point2Time&&this.KP.point2Price&&(this.tM=this.ZP.calculateLevels(this.KP.point1Time,this.KP.point1Price,this.KP.point2Time,this.KP.point2Price),this.KP.onUpdate&&this.tM&&this.KP.onUpdate(this.tM))}updatePoints(t,i,s,n){this.KP.point1Time=t,this.KP.point1Price=i,this.KP.point2Time=s,this.KP.point2Price=n,this.JP(),this.gM()}getMetrics(){return this.tM}getLevels(){return this.tM?.levels||[]}isVisible(){return this._visible}_serializeShape(){const t=this.ZP.getRatioValues();return{type:"fibRetracement",points:[Bh(this.KP.point1Price??0,Lh(this.KP.point1Time)),Bh(this.KP.point2Price??0,Lh(this.KP.point2Time))],style:{lineColor:this.KP.lineColor,lineWidth:this.KP.lineWidth,showLabels:this.KP.showLabels,labelPosition:this.KP.labelPosition,levelColors:this.KP.levelColors},extra:{levels:t,useExtended:this.KP.useExtended}}}useExtendedLevels(t){this.KP.useExtended=t,t?this.ZP.useExtendedRatios():this.ZP.useStandardRatios(),this.JP(),this.gM()}HC(){this.XP=new Yh(this._chart,this._series,{CC:t=>{this.KP.point1Time=t.gt,this.KP.point1Price=t.bt,this.gM()},PC:t=>{this.KP.point2Time=t.gt,this.KP.point2Price=t.bt},TC:(t,i)=>{this.KP.point1Time=t.gt,this.KP.point1Price=t.bt,this.KP.point2Time=i.gt,this.KP.point2Price=i.bt,this.OC=!0,this.zC=null,this.JP(),this.QP(),this.gM()},kC:t=>{this.zC=t,this.gM()}}),this.XP.pC()}ZC(t,i,s){if(!this.KP.point1Time||!this.zC)return;const n=(Qn(this._chart,this._series,this.KP.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.KP.point1Price)??0)*s,r=(Qn(this._chart,this._series,this.zC.gt)??0)*i,h=(this._series.priceToCoordinate(this.zC.bt)??0)*s,l=this.ZP.calculateLevels(this.KP.point1Time,this.KP.point1Price,this.zC.gt,this.zC.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.YP,r=n.price??n.bt;if(void 0===e||void 0===r)return;const h=(this._series.priceToCoordinate(r)??0)*s,l=this.KP.levelColors?.[e.toString()]||this.KP.lineColor;if(t.strokeStyle=l,t.lineWidth=this.KP.lineWidth*i,t.beginPath(),t.moveTo(o,h),t.lineTo(a,h),t.stroke(),this.KP.showLabels){const s=`${n.label??n.Jl} ${this.ZP.formatPrice(r)}`;t.font=11*i+"px sans-serif";const e=t.measureText(s),_=4*i,u="right"===this.KP.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.KP.labelPosition?"left":"right",t.textBaseline="middle",t.fillText(s,u,c)}}),t.setLineDash([]),t.globalAlpha=1,this.JC(t,n,e,i),t.globalAlpha=.6,this.JC(t,r,h,i),t.globalAlpha=1}JC(t,i,s,n){const e=this.KP.lineColor,r=this.FC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.FC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}QP(){this.op=t=>{this.tT(t)},this._chart.subscribeCrosshairMove(this.op)}iT(){this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null)}tT(t){if(!t.point)return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.FC||!this.VC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.GP?(this.KP.point1Time=i,this.KP.point1Price=s):"point2"===this.GP&&(this.KP.point2Time=i,this.KP.point2Price=s),this.JP(),this.gM())}startDrag(t){this.VC=!0,this.GP=t}stopDrag(){this.VC=!1,this.GP=null}updateDrag(t,i){this.VC&&this.GP&&("point1"===this.GP?(this.KP.point1Time=t,this.KP.point1Price=i):(this.KP.point2Time=t,this.KP.point2Price=i),this.JP(),this.gM())}hitTestEndpoint(t,i){if(!this.OC||!this.KP.point1Time||!this.KP.point2Time)return null;const s=Qn(this._chart,this._series,this.KP.point1Time)??0,n=this._series.priceToCoordinate(this.KP.point1Price)??0,e=Qn(this._chart,this._series,this.KP.point2Time)??0,r=this._series.priceToCoordinate(this.KP.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.KP={...this.KP,...t},void 0!==t.levels&&t.levels.length>0?this.ZP.updateRatios(t.levels.map(Dl)):void 0!==t.useExtended&&(t.useExtended?this.ZP.useExtendedRatios():this.ZP.useStandardRatios()),super.applyOptions(t),this.JP(),this.gM()}options(){return{...this.KP,levels:this.ZP.getRatioValues()}}setColor(t){this.KP.lineColor=t,this.gM()}color(){return this.KP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}isSelected(){return this.FC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.OC||!this.KP.point1Time||!this.KP.point2Time)return!1;const s=Qn(this._chart,this._series,this.KP.point1Time)??0,n=Qn(this._chart,this._series,this.KP.point2Time)??0;if(t<Math.min(s,n)||t>Math.max(s,n))return!1;if(!this.tM)return!1;for(const t of this.tM.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.OC}remove(){this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.XP&&(this.XP.m(),this.XP=null),this.iT(),this.KP.onRemove&&this.KP.onRemove()}destroy(){this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.KP.onRemove&&this.KP.onRemove()}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.JP(),this.gM()}}function Fl(t,i){return new Rl(t,i)}class Il{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Vl{constructor(t){this.DC=t,this.Jt=new Il(t)}renderer(){return this.DC.isVisible()?this.Jt:null}}class Al extends zh{constructor(t,i){super(t,"fibonacci-extension",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.nP=null,this.KP={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.Ky(),this.KP.interactive&&(this.nP=Zh(this._chart,this._series,3,(t,i)=>{const s={time:t.gt,price:t.bt};0===i?this.setPoint1(s):1===i?this.setPoint2(s):this.setPoint3(s)}))}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Vl(this)}getPoint1(){return this.KP.point1}getPoint2(){return this.KP.point2}getPoint3(){return this.KP.point3}getLevels(){return this.KP.levels||[]}getOptions(){return this.KP}setPoint1(t){this.KP.point1=t,this.gM()}setPoint2(t){this.KP.point2=t,this.gM()}setPoint3(t){this.KP.point3=t,this.gM()}isComplete(){return!this.nP?.tP()&&!!(this.KP.point1&&this.KP.point2&&this.KP.point3)}setColor(t){this.KP.lineColor=t,this.gM()}color(){return this.KP.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=[this.KP.point1,this.KP.point2,this.KP.point3];for(const n of s){const s=Qn(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.sT();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.KP.point1,n=this.KP.point2,e=this.KP.point3;if(!s||!n||!e)return null;if(s&&s.time&&void 0!==s.price){const n=Qn(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=Qn(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=Qn(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.VC=!0,this.AC=t}stopDrag(){this.VC=!1,this.AC=null}updateDrag(t,i){if(!this.VC||!this.AC)return;const s={time:t,price:i};switch(this.AC){case"point1":this.setPoint1(s);break;case"point2":this.setPoint2(s);break;case"point3":this.setPoint3(s)}this.KP.onUpdate&&this.KP.onUpdate()}sT(){if(!this.isComplete())return[];const t=this.KP.point1,i=this.KP.point2,s=this.KP.point3,n=i.price-t.price;return(this.KP.levels||[]).map(t=>({sn:t.level,bt:s.price+n*t.level,Jl:t.label,R:t.color}))}getExtensionLevels(){return this.sT()}drawToCanvas(t,i,s){if(!this.isComplete())return;const n=this.KP.point1,e=this.KP.point2,r=this.KP.point3,h=this.FC||this.IC&&!this.isLocked(),l=(Qn(this._chart,this._series,n.time)??0)*i,o=(this._series.priceToCoordinate(n.price)??0)*s,a=(Qn(this._chart,this._series,e.time)??0)*i,_=(this._series.priceToCoordinate(e.price)??0)*s,u=(Qn(this._chart,this._series,r.time)??0)*i,c=(this._series.priceToCoordinate(r.price)??0)*s;t.strokeStyle=this.KP.lineColor||"#787B86",t.lineWidth=(this.KP.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.KP.lineWidth||1)*i*(h?1.5:1),t.beginPath(),this.KP.extendLines?(t.moveTo(0,o),t.lineTo(p,o)):(t.moveTo(u,o),t.lineTo(p,o)),t.stroke(),this.KP.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:[Eh(this.KP.point1),Eh(this.KP.point2),Eh(this.KP.point3)],style:{lineColor:this.KP.lineColor,lineWidth:this.KP.lineWidth,showLabels:this.KP.showLabels,extendLines:this.KP.extendLines},extra:{levels:(this.KP.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.nP?.iP(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null)}}function Ll(t,i){return new Al(t,i)}class Bl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class El{constructor(t){this.DC=t,this.Jt=new Bl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}const Ol=[{level:.382,color:"#787B86",label:"38.2%"},{level:.5,color:"#9598A1",label:"50%"},{level:.618,color:"#787B86",label:"61.8%"}];class Wl extends zh{constructor(t,i){super(t,"fibonacci-fan",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.nT=!1,this.hx=null,this.op=null,this.zC=null,this.eT={levels:Ol,lineWidth:1,showLabels:!0,extendLines:!0,interactive:!1,...i},this.Ky(),this.eT.interactive&&!this.eT.point1Time&&this.HC()}HC(){this.nT=!0,this.hx=t=>{if(!t.point)return;if(Nh(this._chart))return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.eT.point1Time?(this.eT.point2Time=i,this.eT.point2Price=s,this.nT=!1,this.zC=null,this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.gM(),this.eT.onUpdate&&this.eT.onUpdate()):(this.eT.point1Time=i,this.eT.point1Price=s,this.gM()))},this.op=t=>{if(this.nT&&this.eT.point1Time)if(t.point){const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.zC={gt:i,bt:s},this.gM())}else this.zC=null,this.gM()},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.op)}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new El(this)}drawToCanvas(t,i,s){const n=this.eT.point1Time,e=this.eT.point1Price,r=this.nT&&this.zC?this.zC.gt:this.eT.point2Time,h=this.nT&&this.zC?this.zC.bt:this.eT.point2Price;if(!n||void 0===e||!r||void 0===h)return;const l=(Qn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Qn(this._chart,this._series,r)??0)*i,_=(this._series.priceToCoordinate(h)??0)*s,u=this.FC?this.eT.lineWidth+1:this.eT.lineWidth;if(this.rT(t,l,o,a,_,"#2962FF",u*i),this.eT.levels)for(const n of this.eT.levels)this.hT(t,l,o,a,_,n,i,s,undefined,u);!this.FC&&!this.IC||this.nT||this.isLocked()||(this.JC(t,l,o,i,"#2962ff"),this.JC(t,a,_,i,"#2962ff"))}hT(t,i,s,n,e,r,h,l,o,a){const _=n,u=s+(e-s)*r.level;let c=_,d=u;if(this.eT.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.rT(t,i,s,c,d,p,a*h),this.eT.showLabels&&!this.nT&&this.lP(t,_,u,r.label,h,p)}rT(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()}JC(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()}lP(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.eT.levels??[];for(const s of i)s.color=t;this.gM()}color(){const t=this.eT.levels??[];return t.length>0?t[0].color:""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.eT.point1Time||!this.eT.point2Time)return!1;const s=Qn(this._chart,this._series,this.eT.point1Time)??0,n=this._series.priceToCoordinate(this.eT.point1Price)??0,e=Qn(this._chart,this._series,this.eT.point2Time)??0,r=this._series.priceToCoordinate(this.eT.point2Price)??0;if(this.QC(t,i,s,n,e,r)<=8)return!0;if(this.eT.levels)for(const h of this.eT.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.eT.point1Time||!this.eT.point2Time)return null;const s=Qn(this._chart,this._series,this.eT.point1Time)??0,n=this._series.priceToCoordinate(this.eT.point1Price)??0,e=Qn(this._chart,this._series,this.eT.point2Time)??0,r=this._series.priceToCoordinate(this.eT.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.VC=!0,this.AC=t}stopDrag(){this.VC=!1,this.AC=null}updateDrag(t,i){this.VC&&this.AC&&("point1"===this.AC?(this.eT.point1Time=t,this.eT.point1Price=i):"point2"===this.AC&&(this.eT.point2Time=t,this.eT.point2Price=i),this.gM(),this.eT.onUpdate&&this.eT.onUpdate())}isVisible(){return this._visible}_serializeShape(){return{type:"fibFan",points:[Bh(this.eT.point1Price??0,Lh(this.eT.point1Time)),Bh(this.eT.point2Price??0,Lh(this.eT.point2Time))],style:{lineWidth:this.eT.lineWidth,showLabels:this.eT.showLabels,extendLines:this.eT.extendLines},extra:{levels:(this.eT.levels||[]).map(t=>({sn:t.level,R:t.color,Jl:t.label}))}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return!this.nT}remove(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.eT.onRemove&&this.eT.onRemove()}}function zl(t,i){return new Wl(t,i)}class $l{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Hl{constructor(t){this.DC=t,this.Jt=new $l(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Nl extends zh{constructor(t,i){super(t,"rectangle",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.BC=null,this.EC=null,this.nT=!1,this.hx=null,this.op=null,this.zC=null,this.lT={fillColor:"#2962ff",fillOpacity:.2,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!0,labelText:"",labelPosition:"top-left",interactive:!1,...i},this._registerOptions(this.lT),this.Ky(),!this.lT.interactive||this.lT.time1&&this.lT.time2||this.HC()}HC(){this.nT=!0,this.hx=t=>{if(!t.point)return;if(Nh(this._chart))return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.lT.time1?(this.lT.time2=i,this.lT.price2=s,this.nT=!1,this.zC=null,this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.gM(),this.lT.onUpdate&&this.lT.onUpdate()):(this.lT.time1=i,this.lT.price1=s,this.gM()))},this.op=t=>{if(this.nT&&this.lT.time1)if(t.point){const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.zC={gt:i,bt:s},this.gM())}else this.zC=null,this.gM()},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.op)}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Hl(this)}drawToCanvas(t,i,s){const n=this.lT.time1,e=this.lT.price1,r=this.nT&&this.zC?this.zC.gt:this.lT.time2,h=this.nT&&this.zC?this.zC.bt:this.lT.price2;if(!n||void 0===e||!r||void 0===h)return;const l=(Qn(this._chart,this._series,n)??0)*i,o=(this._series.priceToCoordinate(e)??0)*s,a=(Qn(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.lT.fillOpacity>0){const i=this.Xy(this.lT.fillColor,this.nT?.1:this.lT.fillOpacity);t.fillStyle=i,t.fillRect(u,d,f,v)}const m=this.lT.borderColor,w=this.FC?this.lT.borderWidth+1:this.lT.borderWidth;w>0&&(t.strokeStyle=m,t.lineWidth=w*i,"dashed"===this.lT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.lT.borderStyle&&t.setLineDash([2*i,3*i]),t.strokeRect(u,d,f,v),t.setLineDash([])),!this.FC&&!this.IC||this.nT||this.isLocked()||this.oT(t,u,d,c,p,i,m),this.lT.showLabel&&this.lT.labelText&&!this.nT&&this.lP(t,u,d,c,p,i,s,m)}oT(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)}lP(t,i,s,n,e,r,h,l){const o=6*r,a=(this.lT.labelFontSize??12)*r;t.font=`${a}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`;const _=t.measureText(this.lT.labelText).width,u=a,c=(s+e)/2-u/2-o,d=Math.min(n,t.canvas.width);let p=i+o,f=s+o;switch(this.lT.labelPosition){case"top-right":p=d-_-2*o,f=s+o;break;case"bottom-left":p=i+o,f=e-u-2*o;break;case"bottom-right":p=d-_-2*o,f=e-u-2*o;break;case"center":p=(Math.max(i,0)+d)/2-_/2-o,f=c;break;case"left":p=i+o,f=c;break;case"right":p=d-_-2*o,f=c}t.fillStyle=this.lT.labelBackgroundColor??l,t.fillRect(p,f,_+2*o,u+2*o),t.fillStyle=this.lT.labelColor??"#ffffff",t.textBaseline="top",t.fillText(this.lT.labelText,p+o,f+o)}Xy(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.lT.borderColor=t,this.lT.fillColor=t,this.gM()}color(){return this.lT.borderColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.lT.time1||!this.lT.time2)return!1;const s=Qn(this._chart,this._series,this.lT.time1)??0,n=this._series.priceToCoordinate(this.lT.price1)??0,e=Qn(this._chart,this._series,this.lT.time2)??0,r=this._series.priceToCoordinate(this.lT.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.lT.time1||!this.lT.time2)return null;const s=Qn(this._chart,this._series,this.lT.time1)??0,n=this._series.priceToCoordinate(this.lT.price1)??0,e=Qn(this._chart,this._series,this.lT.time2)??0,r=this._series.priceToCoordinate(this.lT.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.VC=!0,this.AC=t,this.LC=i,"body"===t&&(this.BC={gt:this.lT.time1,bt:this.lT.price1},this.EC={gt:this.lT.time2,bt:this.lT.price2})}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.BC=null,this.EC=null}updateDrag(t,i){if(!this.VC||!this.AC)return;const s=Qn(this._chart,this._series,this.lT.time1)??0,n=this._series.priceToCoordinate(this.lT.price1)??0,e=s<(Qn(this._chart,this._series,this.lT.time2)??0),r=n<(this._series.priceToCoordinate(this.lT.price2)??0);if("body"===this.AC&&this.BC&&this.EC){const s=Vh(this.LC,t,i);this.lT.time1=this.BC.gt+s.gt,this.lT.price1=this.BC.bt+s.bt,this.lT.time2=this.EC.gt+s.gt,this.lT.price2=this.EC.bt+s.bt}else switch(this.AC){case"corner1":e&&r?(this.lT.time1=t,this.lT.price1=i):!e&&r?(this.lT.time2=t,this.lT.price1=i):e&&!r?(this.lT.time1=t,this.lT.price2=i):(this.lT.time2=t,this.lT.price2=i);break;case"corner2":e&&r?(this.lT.time2=t,this.lT.price1=i):!e&&r?(this.lT.time1=t,this.lT.price1=i):e&&!r?(this.lT.time2=t,this.lT.price2=i):(this.lT.time1=t,this.lT.price2=i);break;case"corner3":e&&r?(this.lT.time1=t,this.lT.price2=i):!e&&r?(this.lT.time2=t,this.lT.price2=i):e&&!r?(this.lT.time1=t,this.lT.price1=i):(this.lT.time2=t,this.lT.price1=i);break;case"corner4":e&&r?(this.lT.time2=t,this.lT.price2=i):!e&&r?(this.lT.time1=t,this.lT.price2=i):e&&!r?(this.lT.time2=t,this.lT.price1=i):(this.lT.time1=t,this.lT.price1=i)}this.gM(),this.lT.onUpdate&&this.lT.onUpdate()}isVisible(){return this._visible}_serializeShape(){return{type:"rectangle",points:[Bh(this.lT.price1??0,Lh(this.lT.time1)),Bh(this.lT.price2??0,Lh(this.lT.time2))],style:{fillColor:this.lT.fillColor,fillOpacity:this.lT.fillOpacity,borderColor:this.lT.borderColor,borderWidth:this.lT.borderWidth,borderStyle:this.lT.borderStyle,showLabel:this.lT.showLabel,labelText:this.lT.labelText,labelPosition:this.lT.labelPosition,labelColor:this.lT.labelColor,labelBackgroundColor:this.lT.labelBackgroundColor,labelFontSize:this.lT.labelFontSize}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return!this.nT}remove(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.lT.onRemove&&this.lT.onRemove()}}function Ul(t,i){return new Nl(t,i)}class ql{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Yl{constructor(t){this.DC=t,this.Jt=new ql(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class jl extends zh{constructor(t,i){super(t,"circle",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.xP=null,this.nT=!1,this.hx=null,this.op=null,this.zC=null,this.aT={fillColor:"#2962ff",fillOpacity:.1,borderColor:"#2962ff",borderWidth:2,borderStyle:"solid",showLabel:!1,labelText:"",interactive:!1,...i},this._registerOptions(this.aT),this.Ky(),this.aT.interactive&&!this.aT.centerTime&&this.HC()}HC(){this.nT=!0,this.hx=t=>{if(!t.point)return;if(Nh(this._chart))return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);if(null!==s)if(this.aT.centerTime){const t=this._chart.timeScale().timeToCoordinate(this.aT.centerTime)??0,n=this._series.priceToCoordinate(this.aT.centerPrice)??0,e=Qn(this._chart,this._series,i)??0,r=this._series.priceToCoordinate(s)??0;this.aT.radiusTime=Math.abs(e-t),this.aT.radiusPrice=Math.abs(r-n),this.nT=!1,this.zC=null,this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.gM(),this.aT.onUpdate&&this.aT.onUpdate()}else this.aT.centerTime=i,this.aT.centerPrice=s,this.gM()},this.op=t=>{if(this.nT&&this.aT.centerTime)if(t.point){const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.zC={gt:i,bt:s},this.gM())}else this.zC=null,this.gM()},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.op)}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Yl(this)}drawToCanvas(t,i,s){if(!this.aT.centerTime||void 0===this.aT.centerPrice)return;const n=(Qn(this._chart,this._series,this.aT.centerTime)??0)*i,e=(this._series.priceToCoordinate(this.aT.centerPrice)??0)*s;let r,h;if(this.nT&&this.zC){const t=(Qn(this._chart,this._series,this.zC.gt)??0)*i,l=(this._series.priceToCoordinate(this.zC.bt)??0)*s;r=Math.abs(t-n),h=Math.abs(l-e)}else{if(void 0===this.aT.radiusTime||void 0===this.aT.radiusPrice)return;r=this.aT.radiusTime*i,h=this.aT.radiusPrice*s}if(this.aT.fillOpacity>0){const i=this.Xy(this.aT.fillColor,this.nT?.05:this.aT.fillOpacity);t.fillStyle=i,t.beginPath(),t.ellipse(n,e,r,h,0,0,2*Math.PI),t.fill()}const l=this.aT.borderColor,o=this.FC?this.aT.borderWidth+1:this.aT.borderWidth;t.strokeStyle=l,t.lineWidth=o*i,"dashed"===this.aT.borderStyle?t.setLineDash([10*i,5*i]):"dotted"===this.aT.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.FC&&!this.IC||this.nT||this.isLocked()||this._T(t,n,e,i,l),!this.FC&&!this.IC||this.nT||this.isLocked()||this.uT(t,n,e,r,h,i,l),this.aT.showLabel&&this.aT.labelText&&!this.nT&&this.lP(t,n,e,i,l)}_T(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()}uT(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)}lP(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.aT.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.aT.labelText,a+r,_+r)}Xy(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}setColor(t){this.aT.borderColor=t,this.aT.fillColor=t,this.gM()}color(){return this.aT.borderColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.aT.centerTime||void 0===this.aT.radiusTime)return!1;const s=Qn(this._chart,this._series,this.aT.centerTime)??0,n=this._series.priceToCoordinate(this.aT.centerPrice)??0,e=(t-s)/this.aT.radiusTime,r=(i-n)/this.aT.radiusPrice;return e*e+r*r<=1}hitTestEndpoint(t,i){if(!this.aT.centerTime||void 0===this.aT.radiusTime)return null;const s=Qn(this._chart,this._series,this.aT.centerTime)??0,n=this._series.priceToCoordinate(this.aT.centerPrice)??0,e=this.aT.radiusTime,r=this.aT.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.VC=!0,this.AC=t,this.LC=i,this.xP="center"===t?{gt:this.aT.centerTime,bt:this.aT.centerPrice}:null}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.xP=null}updateDrag(t,i){if(this.VC&&this.AC){if("center"===this.AC&&this.xP){const s=Vh(this.LC,t,i);this.aT.centerTime=this.xP.gt+s.gt,this.aT.centerPrice=this.xP.bt+s.bt}else if("edge"===this.AC){const s=Qn(this._chart,this._series,this.aT.centerTime)??0,n=this._series.priceToCoordinate(this.aT.centerPrice)??0,e=Qn(this._chart,this._series,t)??0,r=this._series.priceToCoordinate(i)??0;this.aT.radiusTime=Math.abs(e-s),this.aT.radiusPrice=Math.abs(r-n)}this.gM(),this.aT.onUpdate&&this.aT.onUpdate()}}isVisible(){return this._visible}_serializeShape(){return{type:"circle",points:[Bh(this.aT.centerPrice??0,Lh(this.aT.centerTime))],style:{fillColor:this.aT.fillColor,fillOpacity:this.aT.fillOpacity,borderColor:this.aT.borderColor,borderWidth:this.aT.borderWidth,borderStyle:this.aT.borderStyle,showLabel:this.aT.showLabel,labelText:this.aT.labelText},extra:{radiusTime:this.aT.radiusTime,radiusPrice:this.aT.radiusPrice}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return!this.nT}remove(){this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.aT.onRemove&&this.aT.onRemove()}}function Xl(t,i){return new jl(t,i)}class Gl{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class Kl{constructor(t){this.DC=t,this.Jt=new Gl(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class Zl extends zh{constructor(t,i){super(t,"arrow",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.cT=-1,this.nT=!1,this.hx=null,this.dT=null,this.op=null,this.zC=null,this.pT={points:[],lineColor:"#2962ff",lineWidth:2,showArrowHead:!0,showCircles:!0,circleRadius:4,interactive:!1,...i},this._registerOptions(this.pT),this.Ky(),!this.pT.interactive||this.pT.points&&0!==this.pT.points.length||this.HC()}HC(){this.nT=!0,this.hx=t=>{if(!t.point)return;if(Nh(this._chart))return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.pT.points||(this.pT.points=[]),this.pT.points.push({time:i,price:s}),this.gM(),this.pT.onUpdate&&this.pT.onUpdate())},this.op=t=>{if(this.nT)if(t.point){const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&(this.zC={gt:i,bt:s},this.gM())}else this.zC=null,this.gM()},this.dT=t=>{this.nT&&(t.preventDefault(),t.stopPropagation(),this.finishDrawing())},this._chart.subscribeClick(this.hx),this._chart.subscribeCrosshairMove(this.op);const t=this._chart.chartElement?.();t&&t.addEventListener("contextmenu",this.dT)}finishDrawing(){if(this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.dT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.dT),this.dT=null}this.nT=!1,this.zC=null,this.gM(),this.pT.onComplete&&this.pT.onComplete()}isDrawing(){return this.nT}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new Kl(this)}drawToCanvas(t,i,s){if(!this.pT.points||0===this.pT.points.length)return;const n=this.pT.lineColor,e=this.FC||this.IC&&!this.isLocked()?this.pT.lineWidth+1:this.pT.lineWidth,r=[];for(const t of this.pT.points)try{let n=Qn(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.nT)return;let h=null;if(this.nT&&this.zC&&this.pT.points.length>0){h={ut:(Qn(this._chart,this._series,this.zC.gt)??0)*i,ct:(this._series.priceToCoordinate(this.zC.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.pT.showArrowHead&&r.length>1&&this.fT(t,r[r.length-2],r[r.length-1],i,n),this.pT.showCircles)for(let s=0;s<r.length;s++)this.vT(t,r[s].ut,r[s].ct,i,n,0===s)}fT(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()}vT(t,i,s,n,e,r){const h=this.pT.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.pT.lineColor=t,this.gM()}color(){return this.pT.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.pT.points||0===this.pT.points.length)return!1;for(let s=0;s<this.pT.points.length-1;s++)try{const n=this.pT.points[s],e=this.pT.points[s+1];let r=Qn(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=Qn(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.pT.points)try{let n=Qn(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.pT.points||0===this.pT.points.length)return null;for(let s=0;s<this.pT.points.length;s++)try{const n=this.pT.points[s];let e=Qn(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.VC=!0,this.cT=t}stopDrag(){this.VC=!1,this.cT=-1}updateDrag(t,i){this.VC&&-1!==this.cT&&this.pT.points&&this.cT>=0&&this.cT<this.pT.points.length&&(this.pT.points[this.cT]={time:t,price:i},this.gM(),this.pT.onUpdate&&this.pT.onUpdate())}getPoints(){return this.pT.points||[]}addPoint(t){this.pT.points||(this.pT.points=[]),this.pT.points.push(t),this.gM()}isVisible(){return this._visible}_serializeShape(){return{type:"arrow",points:(this.pT.points||[]).map(t=>Eh(t)),style:{lineColor:this.pT.lineColor,lineWidth:this.pT.lineWidth,showArrowHead:this.pT.showArrowHead,showCircles:this.pT.showCircles,circleRadius:this.pT.circleRadius}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return!this.nT}remove(){if(this.hx&&(this._chart.unsubscribeClick(this.hx),this.hx=null),this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null),this.dT){const t=this._chart.chartElement?.();t&&t.removeEventListener("contextmenu",this.dT),this.dT=null}this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.pT.onRemove&&this.pT.onRemove()}}function Jl(t,i){return new Zl(t,i)}class Ql{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class to{constructor(t){this.DC=t,this.Jt=new Ql(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class io extends zh{constructor(t,i){super(t,"brush",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.mT=!1,this.nT=!1,this.wT=[],this.gT=!1,this.Af=null,this.gS=null,this.TS=null,this.DS=null,this.FS=null,this.bT=void 0,this.CS=null,this.VC=!1,this.LC=null,this.uP=null,this.MT={points:[],color:"#2962ff",lineWidth:2,smoothing:!0,sampleDistance:4,...i},this._registerOptions(this.MT),this.Ky(),0===(this.MT.points??[]).length&&this.startDrawingMode()}startDrawingMode(){if(this.mT)return;const t=this._chart.chartElement();t&&(this.Af=t,this.mT=!0,this.TS=t=>this.kS(t),this.DS=t=>this.RS(t),this.FS=()=>this.IS(),this.CS=t=>{this.bT=t.hoveredObjectId},this._chart.subscribeCrosshairMove(this.CS),t.addEventListener("pointerdown",this.TS,!0),t.addEventListener("pointermove",this.DS,!0),t.addEventListener("pointerup",this.FS,!0),t.addEventListener("pointercancel",this.FS,!0))}stopDrawingMode(){if(!this.mT)return;this.yT(),this.mT=!1;const t=this.Af;t&&(this.TS&&t.removeEventListener("pointerdown",this.TS,!0),this.DS&&t.removeEventListener("pointermove",this.DS,!0),this.FS&&(t.removeEventListener("pointerup",this.FS,!0),t.removeEventListener("pointercancel",this.FS,!0))),this.CS&&(this._chart.unsubscribeCrosshairMove(this.CS),this.CS=null),this.TS=null,this.DS=null,this.FS=null,this.Af=null}isDrawingModeActive(){return this.mT}isComplete(){return(this.MT.points??[]).length>0}kS(t){if(this.ST())return;const i=this.xT(t,!1);null!==i&&(this.nT=!0,this.wT=[i],this.gS=t.pointerId,Hh(this._chart,!0),this.Af?.setPointerCapture(t.pointerId),t.preventDefault(),t.stopPropagation(),this.CT())}RS(t){if(!this.nT)return;const i=this.xT(t,!0);if(null===i)return;const s=this.wT[this.wT.length-1];Math.hypot(i.ut-s.ut,i.ct-s.ct)<(this.MT.sampleDistance??4)||(this.wT.push(i),t.preventDefault(),t.stopPropagation(),this.CT())}IS(){this.nT&&this.yT()}yT(){if(!this.nT)return;this.nT=!1,this.XS();const t=[];for(const i of this.wT){const s=Jn(this._chart,this._series,i.ut),n=this._series.coordinateToPrice(i.ct);null!==s&&null!==n&&t.push({time:s,price:n})}this.wT=[],t.length<2?this.gM():(this.MT.points=t,this.stopDrawingMode(),this.gM(),this.MT.onUpdate&&this.MT.onUpdate(),this.MT.onComplete&&this.MT.onComplete())}ST(){const t=this.bT;return"string"==typeof t&&t.split("#")[0]!==this.id}XS(){null!==this.gS&&(this.Af&&this.Af.hasPointerCapture(this.gS)&&this.Af.releasePointerCapture(this.gS),this.gS=null)}xT(t,i){const s=this.PT();if(null===s)return null;const n=t.clientX-s.qh,e=t.clientY-s.Wx;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.TT();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,Wx:i.top,ts:n,qt:i.height}}TT(){try{return this._series.getPane().getHTMLElement()}catch(t){return null}}CT(){this.gT||(this.gT=!0,requestAnimationFrame(()=>{this.gT=!1,this.gM()}))}drawToCanvas(t,i,s){const n=this.nT?this.wT.map(t=>({ut:t.ut*i,ct:t.ct*s})):this.kT(i,s);if(0===n.length)return;const e=this.FC;if(t.strokeStyle=this.MT.color,t.lineWidth=(this.MT.lineWidth+(e?1:0))*i,t.lineCap="round",t.lineJoin="round",t.beginPath(),t.moveTo(n[0].ut,n[0].ct),this.MT.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.IC||this.isLocked()||(this.JC(t,n[0],i),this.JC(t,n[n.length-1],i))}JC(t,i,s){t.fillStyle=this.MT.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()}kT(t,i){const s=this.MT.points??[],n=[];for(const e of s){const s=Qn(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.kT(1,1);for(let n=1;n<s.length;n++)if(so(t,i,s[n-1],s[n])<=8)return!0;return!1}hitTestEndpoint(t,i){return this.hitTest(t,i)?"stroke":null}startDrag(t,i){this.VC=!0,this.LC=i,this.uP=(this.MT.points??[]).map(t=>({time:t.time,price:t.price}))}updateDrag(t,i){const s=this.uP;if(!this.VC||null===s||!this.MT.points)return;const n=Vh(this.LC,t,i);this.MT.points.forEach((t,i)=>{const e=s[i];e&&(t.time=e.time+n.gt,t.price=e.price+n.bt)}),this.gM(),this.MT.onUpdate&&this.MT.onUpdate()}stopDrag(){this.VC=!1,this.LC=null,this.uP=null}setColor(t){this.MT.color=t,this.gM()}color(){return this.MT.color??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}Ky(){this.eh=new to(this);const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):null}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.stopDrawingMode(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null),this.eh=null,this.MT.onRemove&&this.MT.onRemove()}_serializeShape(){return{type:"brush",points:(this.MT.points??[]).map(Eh),style:{color:this.MT.color,lineWidth:this.MT.lineWidth,smoothing:this.MT.smoothing}}}getPoints(){return this.MT.points??[]}}function so(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 no(t,i={}){return new io(t,i)}class eo{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class ro{constructor(t){this.DC=t,this.Jt=new eo(t)}renderer(){return this.DC.isComplete()?this.Jt:null}}class ho extends zh{constructor(t,i){super(t,"text-tool",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.AC=null,this.LC=null,this.xP=null,this.DT=!1,this.RT=null,this.nP=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,anchor:"top-left",pointer:!1,borderRadius:0,...i},this._registerOptions(this.FT),this.Ky(),this.IT(),this.FT.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>{this.setPosition(t.gt,t.bt),this.FT.onComplete&&this.FT.onComplete()}))}IT(){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.RT=t,this._chart.subscribeClick(t)}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new ro(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)}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}isComplete(){return!this.nP?.tP()&&!(!this.FT.time||void 0===this.FT.price)}setColor(t){this.FT.textColor=t,this.FT.borderColor=t,this.gM()}color(){return this.FT.textColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this._update())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this._update())}isHovered(){return this.IC}setEditing(t){this.DT!==t&&(this.DT=t,this._update())}isEditing(){return this.DT}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete())return!1;const s=this.FT.time,n=this.FT.price,e=Qn(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)+2*l,u=h+2*l,c=this.VT(u),d=this.AT(e,r,_,u,c),p=d.qh-("left"===this.FT.anchor?c:0),f=d.qh+_+("right"===this.FT.anchor?c:0);return t>=p&&t<=f&&i>=d.Wx&&i<=d.Wx+u}VT(t){const i=this.FT.anchor;return!this.FT.pointer||"left"!==i&&"right"!==i?0:Math.round(.35*t)}AT(t,i,s,n,e){switch(this.FT.anchor){case"left":return{qh:t+e,Wx:i-n/2};case"right":return{qh:t-e-s,Wx:i-n/2};case"center":return{qh:t-s/2,Wx:i-n/2};default:return{qh:t,Wx:i}}}LT(t,i,s,n,e,r,h,l,o){const a=Math.max(0,Math.min(o,n/2,e/2));t.beginPath(),t.moveTo(i+a,s),t.lineTo(i+n-a,s),t.arcTo(i+n,s,i+n,s+a,a),r>0&&"right"===this.FT.anchor&&(t.lineTo(i+n,l-r),t.lineTo(h,l),t.lineTo(i+n,l+r)),t.lineTo(i+n,s+e-a),t.arcTo(i+n,s+e,i+n-a,s+e,a),t.lineTo(i+a,s+e),t.arcTo(i,s+e,i,s+e-a,a),r>0&&"left"===this.FT.anchor&&(t.lineTo(i,l+r),t.lineTo(h,l),t.lineTo(i,l-r)),t.lineTo(i,s+a),t.arcTo(i,s,i+a,s,a),t.closePath()}hitTestEndpoint(t,i){if(!this.isComplete())return null;const s=this.FT.time,n=this.FT.price,e=Qn(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.VC=!0,this.AC=t,this.LC=i,this.xP={gt:this.FT.time,bt:this.FT.price}}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.xP=null}updateDrag(t,i){if(this.VC){if("body"===this.AC&&this.xP){const s=Vh(this.LC,t,i);this.setPosition(this.xP.gt+s.gt,this.xP.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=(Qn(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.VT(m),{qh:g,Wx:b}=this.AT(h,l,f,m,w),M=(this.FT.borderRadius??0)*i,y=this.FT.backgroundOpacity??.8,S=this.FT.backgroundColor||"#2962FF";y>0&&(t.fillStyle=this.Xy(S,y),this.LT(t,g,b,f,m,w,h,l,M),t.fill()),(this.FC||this.IC)&&(t.strokeStyle=this.FT.borderColor??"#FFFFFF",t.lineWidth=(this.FT.borderWidth||1)*i*(this.FC?2:1),this.LT(t,g,b,f,m,w,h,l,M),t.stroke()),t.fillStyle=this.FT.textColor||"#FFFFFF";for(let i=0;i<c.length;i++){const s=c[i];let n=g+a;if("center"===this.FT.textAlign){n=g+(f-t.measureText(s).width)/2}else if("right"===this.FT.textAlign){n=g+f-t.measureText(s).width-a}const e=b+a+i*v;t.fillText(s,n,e)}if((this.FC||this.IC)&&!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()}}Xy(t,i){if(!/^#[0-9a-f]{6}$/i.test(t))return t;return`rgba(${parseInt(t.slice(1,3),16)}, ${parseInt(t.slice(3,5),16)}, ${parseInt(t.slice(5,7),16)}, ${i})`}_serializeShape(){return{type:"text",points:[Bh(this.FT.price??0,Lh(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,anchor:this.FT.anchor,pointer:this.FT.pointer,borderRadius:this.FT.borderRadius},extra:{text:this.FT.text}}}remove(){this.nP?.iP(),this.RT&&(this._chart.unsubscribeClick(this.RT),this.RT=null),this.Zb&&this._series&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.FT.onRemove&&this.FT.onRemove()}}function lo(t,i){return new ho(t,i)}class oo{constructor(t){this.BT=t}calculatePips(t,i){return Math.abs(i-t)/this.BT.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.BT={...this.BT,...t}}getPipConfig(){return{...this.BT}}}function ao(t){const i=t.toString().split("."),s=i.length>1?i[1].length:0;let n;return n=s>=5?1e-5:4===s?1e-4:3===s?.001:2===s?.01:1===s?.1:1,{pipValue:n,decimals:s}}function _o(t,i){return"number"==typeof t?ao(t):void 0!==i?ao(i):{pipValue:.1,decimals:1}}class uo{constructor(t){this.BT=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.BT.pipValue,timeDifference:this.ET(t,s),barCount:e}}ET(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.BT={...this.BT,...t}}getPipConfig(){return{...this.BT}}}class co{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class po{constructor(t){this.DC=t,this.Jt=new co(t)}renderer(){return this.DC.isVisible()?this.Jt:null}}class fo extends zh{constructor(t,i){super(t,"ruler-tool",i),this.Zb=null,this.RC=null,this.tM=null,this.eh=null,this.XP=null,this.OC=!1,this.FC=!1,this.IC=!1,this.zC=null,this.VC=!1,this.GP=null,this.op=null,this.OT={lineColor:"#2962ff",lineWidth:2,showLabel:!0,labelBackgroundColor:"#2962ff",labelTextColor:"#ffffff",selectionColor:"#2962ff",selectionLineWidth:3,symbol:"DEFAULT",...i},this._registerOptions(this.OT);const s=this.OT.pipConfig||_o(this.OT.symbol||"DEFAULT");this.ZP=new uo(s),this.Ky(),this.OT.interactive?this.HC():this.OT.point1Time&&this.OT.point2Time&&(this.OC=!0,this.JP())}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new po(this)}HC(){this.XP=new Yh(this._chart,this._series,{CC:t=>{this.OT.point1Time=t.gt,this.OT.point1Price=t.bt,this.gM()},PC:t=>{this.OT.point2Time=t.gt,this.OT.point2Price=t.bt},TC:(t,i)=>{this.OT.point1Time=t.gt,this.OT.point1Price=t.bt,this.OT.point2Time=i.gt,this.OT.point2Price=i.bt,this.OC=!0,this.zC=null,this.JP(),this.QP(),this.gM()},kC:t=>{this.zC=t,this.gM()}}),this.XP.pC()}drawToCanvas(t,i,s){if(!this.OC&&this.OT.point1Time&&this.zC)return void this.ZC(t,i,s);if(!this.OC||!this.OT.point1Time||!this.OT.point2Time)return;const n=(Qn(this._chart,this._series,this.OT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.OT.point1Price)??0)*s,r=(Qn(this._chart,this._series,this.OT.point2Time)??0)*i,h=(this._series.priceToCoordinate(this.OT.point2Price)??0)*s;(this.FC||this.IC&&!this.isLocked())&&(t.strokeStyle=this.OT.selectionColor,t.lineWidth=this.OT.selectionLineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke()),t.strokeStyle=this.OT.lineColor,t.lineWidth=this.OT.lineWidth*i,t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),this.WT(t,n,e,r,h,i),this.JC(t,n,e,i),this.JC(t,r,h,i),this.OT.showLabel&&this.tM&&this.lP(t,n,e,r,h,i,s)}WT(t,i,s,n,e,r){const h=this.OT.measure??"both";if("both"===h)return;const l=14*r;if(t.strokeStyle=this.OT.lineColor,t.lineWidth=this.OT.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()}JC(t,i,s,n){const e=this.FC?this.OT.selectionColor:this.OT.lineColor,r=this.FC?5*n:4*n;t.fillStyle=e,t.beginPath(),t.arc(i,s,r,0,2*Math.PI),t.fill(),this.FC&&(t.strokeStyle="#ffffff",t.lineWidth=2*n,t.stroke())}ZC(t,i,s){if(!this.OT.point1Time||!this.zC)return;const n=(Qn(this._chart,this._series,this.OT.point1Time)??0)*i,e=(this._series.priceToCoordinate(this.OT.point1Price)??0)*s,r=(Qn(this._chart,this._series,this.zC.gt)??0)*i,h=(this._series.priceToCoordinate(this.zC.bt)??0)*s;t.strokeStyle=this.OT.lineColor,t.lineWidth=this.OT.lineWidth*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(n,e),t.lineTo(r,h),t.stroke(),t.setLineDash([]),this.JC(t,n,e,i),t.globalAlpha=.5,this.JC(t,r,h,i),t.globalAlpha=1}lP(t,i,s,n,e,r,h){if(!this.tM)return;const l=(i+n)/2,o=(s+e)/2,a=this.OT.measure??"both",_=[];"time"!==a&&(_.push(this.ZP.formatPips(this.tM.pips)),_.push(this.ZP.formatPercent(this.tM.pricePercent))),"price"!==a&&_.push(this.ZP.formatBarCount(this.tM.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.OT.labelBackgroundColor,t.fillRect(l-d/2,o-p/2,d,p),t.fillStyle=this.OT.labelTextColor,t.textAlign="center",t.textBaseline="middle",t.fillText(u,l,o)}JP(){if(!this.OT.point1Time||!this.OT.point2Time||void 0===this.OT.point1Price||void 0===this.OT.point2Price)return;const t=this.zT();this.tM=this.ZP.calculateMetrics(this.OT.point1Time,this.OT.point1Price,this.OT.point2Time,this.OT.point2Price,t),this.OT.onUpdate&&this.tM&&this.OT.onUpdate(this.tM)}zT(){if(!this.OT.point1Time||!this.OT.point2Time)return 0;const t=Qn(this._chart,this._series,this.OT.point1Time),i=Qn(this._chart,this._series,this.OT.point2Time);if(null===t||null===i)return 0;return Math.abs(Math.round((i-t)/6))}updatePoints(t,i,s,n){this.OT.point1Time=t,this.OT.point1Price=i,this.OT.point2Time=s,this.OT.point2Price=n,this.JP(),this.gM()}getMetrics(){return this.tM}remove(){this.destroy()}destroy(){this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.XP&&(this.XP.m(),this.XP=null),this.iT(),this.OT.onRemove&&this.OT.onRemove()}QP(){this.op=t=>{this.tT(t)},this._chart.subscribeCrosshairMove(this.op)}iT(){this.op&&(this._chart.unsubscribeCrosshairMove(this.op),this.op=null)}tT(t){if(!t.point)return;const i=Jn(this._chart,this._series,t.point.x);if(null===i)return;if(!this.FC||!this.VC)return;const s=this._series.coordinateToPrice(t.point.y);null!==s&&("point1"===this.GP?(this.OT.point1Time=i,this.OT.point1Price=s):"point2"===this.GP&&(this.OT.point2Time=i,this.OT.point2Price=s),this.JP(),this.gM())}startDrag(t){this.VC=!0,this.GP=t}stopDrag(){this.VC=!1,this.GP=null}updateDrag(t,i){this.VC&&this.GP&&("point1"===this.GP?(this.OT.point1Time=t,this.OT.point1Price=i):(this.OT.point2Time=t,this.OT.point2Price=i),this.JP(),this.gM())}hitTestEndpoint(t,i){if(!this.OC||!this.OT.point1Time||!this.OT.point2Time)return null;const s=Qn(this._chart,this._series,this.OT.point1Time)??0,n=this._series.priceToCoordinate(this.OT.point1Price)??0,e=Qn(this._chart,this._series,this.OT.point2Time)??0,r=this._series.priceToCoordinate(this.OT.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}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.JP(),this.gM()}_serializeShape(){return{type:"ruler",points:[Bh(this.OT.point1Price??0,Lh(this.OT.point1Time)),Bh(this.OT.point2Price??0,Lh(this.OT.point2Time))],style:{lineColor:this.OT.lineColor,lineWidth:this.OT.lineWidth,showLabel:this.OT.showLabel,labelBackgroundColor:this.OT.labelBackgroundColor,labelTextColor:this.OT.labelTextColor,selectionColor:this.OT.selectionColor,selectionLineWidth:this.OT.selectionLineWidth},extra:{symbol:this.OT.symbol,pipConfig:this.OT.pipConfig,measure:this.OT.measure}}}setColor(t){this.OT.lineColor=t,this.gM()}color(){return this.OT.lineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}isSelected(){return this.FC}isComplete(){return this.OC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.OC||!this.OT.point1Time||!this.OT.point2Time)return!1;const s=Qn(this._chart,this._series,this.OT.point1Time)??0,n=this._series.priceToCoordinate(this.OT.point1Price)??0,e=Qn(this._chart,this._series,this.OT.point2Time)??0,r=this._series.priceToCoordinate(this.OT.point2Price)??0;return this.$T(t,i,s,n,e,r)<=(this.FC?12:8)}$T(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 vo(t,i){return new fo(t,i)}class mo{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class wo{constructor(t){this.DC=t,this.Jt=new mo(t)}renderer(){return this.DC.isVisible()?this.Jt:null}}class go extends zh{constructor(t,i){super(t,"position-tool",i),this.Zb=null,this.RC=null,this.tM=null,this.eh=null,this.FC=!1,this.IC=!1,this.nP=null,this.VC=!1,this.AC=null,this.LC=null,this.xP=null,this.HT=null,this.NT=null,this.UT={profitColor:"#26a69a",lossColor:"#ef5350",entryLineColor:"#ffffff",opacity:.3,showTooltips:!0,...i},this._registerOptions(this.UT);const s=this.UT.pipConfig||_o(this.UT.entryPrice);this.ZP=new oo(s),this.Ky(),this.JP(),this.UT.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>this.rP(t)))}rP(t){const i=this.UT,s=t.bt-i.entryPrice;i.entryPrice=t.bt,i.entryTime=t.gt,void 0!==i.stopLoss&&(i.stopLoss+=s),void 0!==i.takeProfit&&(i.takeProfit+=s),i.endTime=Jn(this._chart,this._series,Qh(this._chart,t.ut))??void 0,this.JP(),this.gM()}isComplete(){return!this.nP?.tP()}qT(){const t=Qn(this._chart,this._series,this.UT.entryTime)??0;return{YT:t,jT:Qn(this._chart,this._series,this.UT.endTime)??t+Jh(this._chart)}}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new wo(this)}drawToCanvas(t,i,s){if(!this.isComplete())return;if(this.HT&&this.UT.takeProfit){const n=this._chart.timeScale();this.XT(t,this.HT,i,s,n),(this.IC||this.FC)&&this.lP(t,this.HT,"profit",i,s,n)}if(this.NT&&this.UT.stopLoss){const n=this._chart.timeScale();if(this.XT(t,this.NT,i,s,n),this.IC||this.FC){const n=this._chart.timeScale();this.lP(t,this.NT,"loss",i,s,n)}}const n=this._chart.timeScale();if(this.GT(t,i,s,n),this.UT.takeProfit){const n=this._chart.timeScale();this.JC(t,this.UT.takeProfit,this.UT.profitColor,i,s,n)}if(this.UT.stopLoss){const n=this._chart.timeScale();this.JC(t,this.UT.stopLoss,this.UT.lossColor,i,s,n)}}XT(t,i,s,n,e){const r=this.qT(),h=r.YT*s,l=r.jT*s,o=(this._series.priceToCoordinate(i.KT)??0)*n,a=(this._series.priceToCoordinate(i.ZT)??0)*n;t.fillStyle=this.Xy(i.R,.15),t.fillRect(h,Math.min(o,a),l-h,Math.abs(a-o)),t.strokeStyle=i.R,t.lineWidth=2*s,t.beginPath(),t.moveTo(h,a),t.lineTo(l,a),t.stroke()}GT(t,i,s,n){const e=this.qT(),r=e.YT*i,h=e.jT*i,l=(this._series.priceToCoordinate(this.UT.entryPrice)??0)*s,o=this.UT.entryLineColor;t.strokeStyle=o,t.lineWidth=2*i,t.setLineDash([5*i,5*i]),t.beginPath(),t.moveTo(r,l),t.lineTo(h,l),t.stroke(),t.setLineDash([]),t.strokeStyle=this.UT.entryLineColor,t.lineWidth=1*i,t.setLineDash([5*i,5*i]);const a=this._chart.chartElement().clientHeight*s;if(t.beginPath(),t.moveTo(r,0),t.lineTo(r,a),t.stroke(),t.setLineDash([]),!this.FC&&!this.IC||this.isLocked())t.fillStyle=this.UT.entryLineColor,t.beginPath(),t.arc(r,l,4*i,0,2*Math.PI),t.fill();else{t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.beginPath(),t.arc(r,l,5*i,0,2*Math.PI),t.fill(),t.stroke();const s=8*i;t.fillStyle=o,t.strokeStyle="#ffffff",t.lineWidth=2*i,t.fillRect(h-s/2,l-s/2,s,s),t.strokeRect(h-s/2,l-s/2,s,s)}}JP(){this.UT.stopLoss&&this.UT.takeProfit&&(this.tM=this.ZP.calculateMetrics(this.UT.entryPrice,this.UT.stopLoss,this.UT.takeProfit,this.UT.quantity),this.JT(),this.UT.onUpdate&&this.tM&&this.UT.onUpdate(this.tM))}JT(){const t=this.QT();this.UT.takeProfit&&(this.HT={tk:this.UT.entryTime,ik:t,KT:this.UT.entryPrice,ZT:this.UT.takeProfit,R:this.UT.profitColor,Oy:this.UT.opacity}),this.UT.stopLoss&&(this.NT={tk:this.UT.entryTime,ik:t,KT:this.UT.entryPrice,ZT:this.UT.stopLoss,R:this.UT.lossColor,Oy:this.UT.opacity})}QT(){this._chart.timeScale().getVisibleLogicalRange();return this.UT.entryTime}lP(t,i,s,n,e,r){if(!this.tM)return;const h=(Qn(this._chart,this._series,this.UT.entryTime)??0)*n,l=(this._series.priceToCoordinate(i.ZT)??0)*e,o="profit"===s,a=o?this.tM.takeProfitPips:this.tM.stopLossPips,_=o?this.UT.takeProfit:this.UT.stopLoss,u=this.tM.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=3*e,m=h+8*n,w=l<=(this._series.priceToCoordinate(this.UT.entryPrice)??0)*e?l-f-v:l+v;t.fillStyle=i.R,t.fillRect(m,w,p,f),t.fillStyle="#ffffff",t.textAlign="left",t.textBaseline="middle",t.fillText(c,m+d,w+f/2)}JC(t,i,s,n,e,r){const h=this.qT(),l=h.YT*n,o=h.jT*n,a=(this._series.priceToCoordinate(i)??0)*e,_=s;t.fillStyle=_,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.beginPath(),t.arc(l,a,5*n,0,2*Math.PI),t.fill(),t.stroke();const u=8*n,c=s;t.fillStyle=c,t.strokeStyle="#ffffff",t.lineWidth=2*n,t.fillRect(o-u/2,a-u/2,u,u),t.strokeRect(o-u/2,a-u/2,u,u)}Xy(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.UT={...this.UT,...t},this.JP(),this._update()}getMetrics(){return this.tM}setStopLoss(t){this.UT.stopLoss=t,this.JP(),this._update()}setTakeProfit(t){this.UT.takeProfit=t,this.JP(),this._update()}setEntryPrice(t){this.UT.entryPrice=t,this.JP(),this._update()}_serializeShape(){return{type:"position",points:[Bh(this.UT.entryPrice,Lh(this.UT.entryTime))],style:{profitColor:this.UT.profitColor,lossColor:this.UT.lossColor,entryLineColor:this.UT.entryLineColor,opacity:this.UT.opacity,showTooltips:this.UT.showTooltips},extra:{endTime:Lh(this.UT.endTime),stopLoss:this.UT.stopLoss,takeProfit:this.UT.takeProfit,quantity:this.UT.quantity,pipConfig:this.UT.pipConfig}}}setColor(t){this.UT.entryLineColor=t,this.gM()}color(){return this.UT.entryLineColor??""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):this.hitTest(t,i)?Ih(this.id,"body",!1):null}hitTest(t,i){if(!this.isComplete()||!this.UT.stopLoss&&!this.UT.takeProfit)return!1;const{YT:s,jT:n}=this.qT(),e=Math.min(s,n),r=Math.max(s,n);if(this.UT.takeProfit&&this.UT.stopLoss){const n=this._series.priceToCoordinate(this.UT.takeProfit)??0,h=this._series.priceToCoordinate(this.UT.stopLoss)??0,l=Math.min(n,h),o=Math.max(n,h);if(t>=e&&t<=r&&i>=l&&i<=o)return!0;const a=8;if(Math.abs(t-s)<=a&&i>=l&&i<=o)return!0}return!1}hitTestEndpoint(t,i){if(!this.isComplete())return null;const{YT:s,jT:n}=this.qT(),e=Math.min(s,n),r=Math.max(s,n);if(this.UT.takeProfit){const n=this._series.priceToCoordinate(this.UT.takeProfit)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"tp"}if(this.UT.stopLoss){const n=this._series.priceToCoordinate(this.UT.stopLoss)??0;if(Math.sqrt(Math.pow(t-s,2)+Math.pow(i-n,2))<=10)return"sl"}if(this.UT.takeProfit){const s=this._series.priceToCoordinate(this.UT.takeProfit)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"tp-right"}if(this.UT.stopLoss){const s=this._series.priceToCoordinate(this.UT.stopLoss)??0;if(Math.sqrt(Math.pow(t-n,2)+Math.pow(i-s,2))<=10)return"sl-right"}const h=this._series.priceToCoordinate(this.UT.entryPrice)??0;if(t>=e&&t<=r&&Math.abs(i-h)<=8)return"entry";if(this.UT.takeProfit&&this.UT.stopLoss){const s=this._series.priceToCoordinate(this.UT.takeProfit)??0,n=this._series.priceToCoordinate(this.UT.stopLoss)??0,h=Math.min(s,n),l=Math.max(s,n);if(t>=e&&t<=r&&i>=h&&i<=l)return"move"}return null}startDrag(t,i){this.VC=!0,this.AC=t,this.LC=i,"move"===t&&(this.xP={sk:this.UT.entryPrice,nk:this.UT.entryTime??null,jy:this.UT.endTime??null,ek:this.UT.takeProfit??null,rk:this.UT.stopLoss??null})}stopDrag(){this.VC=!1,this.AC=null,this.LC=null,this.xP=null}updateDrag(t,i){if(this.VC&&this.AC){if("entry"===this.AC)this.UT.entryPrice=i;else if("move"===this.AC){if(this.xP){const s=Vh(this.LC,t,i),n=this.xP;this.UT.entryPrice=n.sk+s.bt,null!==n.ek&&(this.UT.takeProfit=n.ek+s.bt),null!==n.rk&&(this.UT.stopLoss=n.rk+s.bt),null!==n.nk&&(this.UT.entryTime=this.hk(n.nk,s.gt)),null!==n.jy&&(this.UT.endTime=this.hk(n.jy,s.gt))}}else"tp"===this.AC||"tp-right"===this.AC?(this.UT.takeProfit=i,"tp-right"===this.AC?this.UT.endTime=t:this.UT.entryTime=t):"sl"!==this.AC&&"sl-right"!==this.AC||(this.UT.stopLoss=i,"sl-right"===this.AC?this.UT.endTime=t:this.UT.entryTime=t);this.JP(),this.gM()}}hk(t,i){return t+i}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.nP?.iP(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this.UT.onRemove&&this.UT.onRemove()}}function bo(t,i){return new go(t,i)}class Mo{constructor(t){this.DC=t}draw(t){t.useBitmapCoordinateSpace(t=>{this.DC.drawToCanvas(t.context,t.horizontalPixelRatio,t.verticalPixelRatio)})}}class yo{constructor(t){this.DC=t,this.Jt=new Mo(t)}renderer(){return this.DC.isVisible()?this.Jt:null}Tt(){}zOrder(){return"normal"}}class So extends zh{constructor(t,i){super(t,"gantt",i),this.Zb=null,this.RC=null,this.eh=null,this.FC=!1,this.IC=!1,this.VC=!1,this.lk=-1,this.LC=null,this.xP=null,this.ak=-1,this.nP=null,this._k={segments:[],rowHeight:40,rowSpacing:5,fillOpacity:.7,borderWidth:2,showLabels:!0,showGrid:!0,...i},this._registerOptions(this._k),this.Ky(),this._k.interactive&&(this.nP=Zh(this._chart,this._series,1,t=>this.rP(t)))}rP(t){const i=this._k.segments??[],s=Jn(this._chart,this._series,Qh(this._chart,t.ut))??t.gt,n=this._k.rowHeight+this._k.rowSpacing,e=Math.max(0,Math.floor((t.ct-50)/n)),r=i.length>0?e-i[0].level:0;for(const n of i)n.startTime=t.gt,n.endTime=s,n.level=Math.max(0,n.level+r);this.gM()}isComplete(){return!this.nP?.tP()}selectionBox(){const t=this._k.segments??[];if(0===t.length)return null;const i=this._k.rowHeight,s=i+this._k.rowSpacing,n={left:1/0,top:1/0,right:-1/0,bottom:-1/0};for(const e of t){const t=50+e.level*s;n.left=Math.min(n.left,Qn(this._chart,this._series,e.startTime)??0),n.right=Math.max(n.right,Qn(this._chart,this._series,e.endTime)??0),n.top=Math.min(n.top,t),n.bottom=Math.max(n.bottom,t+i)}return n}Ky(){this.eh=this.NC();const t={attached:t=>{this.RC=t.requestUpdate},detached:()=>{this.RC=null},updateAllViews:()=>{},paneViews:()=>this.eh?[this.eh]:[],hitTest:(t,i)=>this.UC(t,i)};this.Zb=t,this._series.attachPrimitive(t),this.gM()}NC(){return new yo(this)}drawToCanvas(t,i,s){if(!this.isComplete()||!this._k.segments||0===this._k.segments.length)return;const n=50*s,e=this._k.rowHeight*s,r=this._k.rowSpacing*s;this._k.showGrid&&this.am(t,n,e,r,i,s),this._k.segments.forEach((s,h)=>{const l=(Qn(this._chart,this._series,s.startTime)??0)*i,o=(Qn(this._chart,this._series,s.endTime)??0)*i,a=n+s.level*(e+r),_=h===this.ak||this.IC&&!this.isLocked();this.uk(t,l,o,a,e,s,_,i)})}am(t,i,s,n,e,r){if(!this._k.segments)return;const h=Math.max(...this._k.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()}}uk(t,i,s,n,e,r,h,l){const o=s-i,a=this.Xy(r.color,h?this._k.fillOpacity+.2:this._k.fillOpacity);t.fillStyle=a,t.fillRect(i,n,o,e),t.strokeStyle=r.color;const _=this._k.borderWidth+(this.FC?2:0);t.lineWidth=_*l,t.strokeRect(i,n,o,e),this._k.showLabels&&r.label&&this.lP(t,i,n,o,e,r.label,l)}lP(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)}Xy(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._k.segments||(this._k.segments=[]),this._k.segments.push(t),this.gM(),this._k.onUpdate&&this._k.onUpdate()}removeSegment(t){this._k.segments&&t>=0&&t<this._k.segments.length&&(this._k.segments.splice(t,1),this.gM(),this._k.onUpdate&&this._k.onUpdate())}getSegments(){return this._k.segments||[]}setColor(t){const i=this._k.segments??[];for(const s of i)s.color=t;this.gM()}color(){const t=this._k.segments??[];return t.length>0?t[0].color:""}setSelected(t){this.FC!==t&&(this.FC=t,this.gM())}isSelected(){return this.FC}setHovered(t){this.IC!==t&&(this.IC=t,this.gM())}isHovered(){return this.IC}UC(t,i){if(!this.isVisible())return null;const s=this.hitTestEndpoint(t,i);return null!==s?Ih(this.id,s,!this.isLocked()):null}hitTestEndpoint(t,i){return this.hitTest(t,i)?"move":null}startDrag(t,i){const s=this._k.segments?.[this.ak];s&&(this.VC=!0,this.lk=this.ak,this.LC=i,this.xP={Yy:s.startTime,jy:s.endTime})}updateDrag(t,i){const s=this._k.segments?.[this.lk];if(!this.VC||!this.xP||!s)return;const n=Vh(this.LC,t,i);s.startTime=this.xP.Yy+n.gt,s.endTime=this.xP.jy+n.gt,this.gM(),this._k.onUpdate&&this._k.onUpdate()}stopDrag(){this.VC=!1,this.lk=-1,this.LC=null,this.xP=null}hitTest(t,i){if(!this.isComplete()||!this._k.segments||0===this._k.segments.length)return!1;const s=this._k.rowHeight,n=this._k.rowSpacing;for(let e=0;e<this._k.segments.length;e++){const r=this._k.segments[e],h=Qn(this._chart,this._series,r.startTime)??0,l=Qn(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.ak=e,!0}return this.ak=-1,!1}isVisible(){return this._visible}_serializeShape(){return{type:"gantt",points:[],style:{rowHeight:this._k.rowHeight,rowSpacing:this._k.rowSpacing,fillOpacity:this._k.fillOpacity,borderWidth:this._k.borderWidth,showLabels:this._k.showLabels,showGrid:this._k.showGrid},extra:{segments:(this._k.segments||[]).map(t=>({Yy:Lh(t.startTime),jy:Lh(t.endTime),sn:t.level,Jl:t.label,R:t.color,ck:t.category}))}}}gM(){this.Zb&&this.Zb.updateAllViews?.(),this.RC?.()}_update(){this.gM()}remove(){this.nP?.iP(),this.Zb&&(this._series.detachPrimitive(this.Zb),this.Zb=null,this.eh=null),this._k.onRemove&&this._k.onRemove()}}function xo(t,i){return new So(t,i)}function Co(t){return t.map(t=>Bh(Wh(t,"price")??0,Oh(t)))}class Po{constructor(t,i,s={}){this.dk=[],this.pk=[],this.fk=[],this.vk=!1,this.mk=new Map,this.wk=null,this.gk=null,this.bk=null,this.hx=null,this.Mk=null,this.op=null,this.yk=null,this.Sk=null,this.xk=null,this.Ck=null,this.Pk=null,this.Tk=null,this.gS=null,this.kk=!1,this.Dk=null,this.Rk=null,this.Fk=new a,this.VC=!1,this.Ik=null,this.Vk=new Set,this.Ak=null,this.Lk=new a,this.Of=t,this.be=i,this.Ps={enableKeyboardShortcuts:!0,selectionColor:"#2962ff",selectionLineWidth:3,...s},this.Bk()}startDrawing(t){this.bk=t,this.Ek()}activeDrawingType(){return this.bk}stopDrawing(){this.bk=null}addTool(t,i){const s=i??t.id;return this.mk.set(s,t),t.isComplete()||this.Vk.add(s),this.recordChange(),s}hasPendingDrawing(){return this.Vk.size>0}cancelPendingDrawings(){if(0===this.Vk.size)return 0;let t=0;for(const i of Array.from(this.Vk)){const s=this.mk.get(i);s&&(this.wk===i&&this.Ok(null),s.remove(),this.mk.delete(i),t++)}return this.Vk.clear(),t>0&&this.recordChange(),t}subscribeDrawingCompleted(t){this.Lk.i(t)}unsubscribeDrawingCompleted(t){this.Lk._(t)}Wk(){0!==this.Vk.size&&null===this.Ak&&(this.Ak=setTimeout(()=>{this.Ak=null;const t=[];for(const i of Array.from(this.Vk)){const s=this.mk.get(i);s?s.isComplete()&&(this.Vk.delete(i),t.push(i)):this.Vk.delete(i)}t.length>0&&this.recordChange();for(const i of t)this.Lk.p(i)},0))}removeTool(t){const i=this.mk.get(t);return!!i&&(this.wk===t&&this.Ok(null),i.remove(),this.mk.delete(t),this.Vk.delete(t),this.recordChange(),!0)}selectTool(t){return!!this.mk.has(t)&&(this.Ok(t),!0)}Ok(t){if(this.wk===t)return;const i=null===this.wk?void 0:this.mk.get(this.wk);i&&i.setSelected(!1),this.wk=t;const s=null===t?void 0:this.mk.get(t);s&&s.setSelected(!0),this.zk()}recordChange(){if(this.vk)return;const t=this.serializeAll();JSON.stringify(t)!==JSON.stringify(this.fk)&&(this.dk.push(this.fk),this.dk.length>100&&this.dk.shift(),this.pk=[],this.fk=t)}canUndo(){return this.dk.length>0}canRedo(){return this.pk.length>0}undo(){const t=this.dk.pop();return void 0!==t&&(this.pk.push(this.fk),this.$k(t),!0)}redo(){const t=this.pk.pop();return void 0!==t&&(this.dk.push(this.fk),this.$k(t),!0)}$k(t){this.vk=!0;try{this.Ok(null);for(const[t,i]of Array.from(this.mk))i.isComplete()&&(i.remove(),this.mk.delete(t),this.Vk.delete(t));const i={chart:this.Of,series:this.be};for(const s of t)this.restoreTool(i,s);this.fk=t}finally{this.vk=!1}}subscribeSelectionChanged(t){this.Fk.i(t)}unsubscribeSelectionChanged(t){this.Fk._(t)}selectionBounds(){if(null===this.wk)return null;const t=this.mk.get(this.wk);return t?this.Hk(t):null}Hk(t){const i=t.selectionBox()??this.Nk(t);if(null===i)return null;const s=this.Uk(t);return{left:i.left+s.ut,right:i.right+s.ut,top:i.top+s.ct,bottom:i.bottom+s.ct}}Nk(t){const i=t.series(),s=t.serialize().points;let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,l=!1;for(const t of s){const s=Qn(this.Of,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))}return l?{left:n,top:e,right:r,bottom:h}:null}Uk(t){const i=this.Of.chartElement(),s=this.KS(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}}zk(){this.Fk.p({id:this.wk,bounds:this.selectionBounds()})}deselectAll(){this.Ek()}deleteSelected(){if(this.wk){const t=this.mk.get(this.wk);return(!t||!t.isLocked())&&this.removeTool(this.wk)}return!1}getSelectedToolId(){return this.wk}getAllTools(){return new Map(this.mk)}getTool(t){return this.mk.get(t)}clearAll(){this.Ok(null),this.mk.forEach(t=>t.remove()),this.mk.clear(),this.Vk.clear(),this.recordChange()}getToolCount(){return this.mk.size}isToolSelected(t){return this.wk===t}serializeAll(){const t=[];for(const i of this.mk.values())i.isComplete()&&t.push(i.serialize());return t}restoreTool(t,i){const s=Po.qk(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 qk(t,i){const{type:s,points:n,style:e,extra:r}=i,h=t=>({Yk:Oh(n[t]),jk:Wh(n[t],"price")??0});switch(s){case"trendLine":return Kh(t,{point1Time:h(0).Yk,point1Price:h(0).jk,point2Time:h(1).Yk,point2Price:h(1).jk,...e});case"horizontalLine":return nl(t,{price:h(0).jk,startTime:h(0).Yk??void 0,...e});case"parallelChannel":return fl(t,{point1Time:h(0).Yk,point1Price:h(0).jk,point2Time:h(1).Yk,point2Price:h(1).jk,channelWidth:r?.channelWidth,...e});case"pitchfork":return gl(t,{pivotTime:h(0).Yk,pivotPrice:h(0).jk,upperTime:h(1).Yk,upperPrice:h(1).jk,lowerTime:h(2).Yk,lowerPrice:h(2).jk,...e});case"polygon":return ul(t,{points:Co(n),...e});case"crossLine":return ll(t,{time:h(0).Yk,price:h(0).jk,...e});case"verticalLine":return Sl(t,{time:h(0).Yk,...e});case"fibRetracement":return Fl(t,{point1Time:h(0).Yk,point1Price:h(0).jk,point2Time:h(1).Yk,point2Price:h(1).jk,useExtended:r?.useExtended,levels:r?.levels,levelColors:e?.levelColors,...e});case"fibExtension":{const i=h(0),s=h(1),n=h(2);return Ll(t,{point1:i.Yk?{time:i.Yk,price:i.jk}:void 0,point2:s.Yk?{time:s.Yk,price:s.jk}:void 0,point3:n.Yk?{time:n.Yk,price:n.jk}:void 0,levels:r?.levels,...e})}case"fibFan":return zl(t,{point1Time:h(0).Yk,point1Price:h(0).jk,point2Time:h(1).Yk,point2Price:h(1).jk,levels:r?.levels,...e});case"rectangle":return Ul(t,{time1:h(0).Yk,price1:h(0).jk,time2:h(1).Yk,price2:h(1).jk,...e});case"circle":return Xl(t,{centerTime:h(0).Yk,centerPrice:h(0).jk,radiusTime:r?.radiusTime,radiusPrice:r?.radiusPrice,...e});case"arrow":return Jl(t,{points:Co(n),...e});case"brush":return no(t,{points:Co(n),...e});case"text":return lo(t,{time:h(0).Yk,price:h(0).jk,text:r?.text,...e});case"ruler":return vo(t,{point1Time:h(0).Yk,point1Price:h(0).jk,point2Time:h(1).Yk,point2Price:h(1).jk,symbol:r?.symbol,pipConfig:r?.pipConfig,measure:r?.measure,...e});case"position":return bo(t,{entryPrice:h(0).jk,entryTime:h(0).Yk,endTime:r?.endTime,stopLoss:r?.stopLoss,takeProfit:r?.takeProfit,quantity:r?.quantity,pipConfig:r?.pipConfig,...e});case"gantt":return xo(t,{segments:r?.segments,...e});default:throw new Error(`Unknown drawing tool type: ${s}`)}}destroy(){null!==this.Ak&&(clearTimeout(this.Ak),this.Ak=null),this.Lk.m(),this.Fk.m(),this.clearAll(),this.Xk(),this.dk=[],this.pk=[],this.fk=[]}Bk(){this.hx=t=>{this.SC(t)},this.Of.subscribeClick(this.hx),this.op=t=>{this.xC(t)},this.Of.subscribeCrosshairMove(this.op);const t=this.Of.chartElement();t&&(this.yk=t=>this.Gk(t),this.Sk=t=>this.Kk(t),this.xk=t=>this.Zk(t),this.Ck=t=>this.Kk(t),this.Pk=t=>this.Jk(t),t.addEventListener("pointerdown",this.yk),t.addEventListener("pointerup",this.Sk),t.addEventListener("pointermove",this.xk),t.addEventListener("pointercancel",this.Ck),t.addEventListener("lostpointercapture",this.Pk)),fs&&(this.Tk=t=>this.Kk(t),window.addEventListener("pointerup",this.Tk)),this.Ps.enableKeyboardShortcuts&&(this.Mk=t=>{this.Qk(t)},document.addEventListener("keydown",this.Mk))}Xk(){this.hx&&(this.Of.unsubscribeClick(this.hx),this.hx=null),this.op&&(this.Of.unsubscribeCrosshairMove(this.op),this.op=null);const t=this.Of.chartElement();t&&(this.yk&&(t.removeEventListener("pointerdown",this.yk),this.yk=null),this.Sk&&(t.removeEventListener("pointerup",this.Sk),this.Sk=null),this.xk&&(t.removeEventListener("pointermove",this.xk),this.xk=null),this.Ck&&(t.removeEventListener("pointercancel",this.Ck),this.Ck=null),this.Pk&&(t.removeEventListener("lostpointercapture",this.Pk),this.Pk=null)),this.Tk&&(window.removeEventListener("pointerup",this.Tk),this.Tk=null),this.Mk&&(document.removeEventListener("keydown",this.Mk),this.Mk=null)}SC(t){if(this.Wk(),!t.point)return;if(this.kk)return void(this.kk=!1);if(this.VC)return;const i=this.tD(t.hoveredObjectId);i?this.selectTool(i):this.Ek()}xC(t){if(this.Dk=t.point?{ut:t.point.x,ct:t.point.y}:null,!t.point)return;if(this.VC&&this.Ik){const i=this.mk.get(this.Ik);if(i){const s=i.series(),n=s.coordinateToPrice(t.point.y),e=s?Jn(this.Of,s,t.point.x):null;null!==n&&null!==e&&i.updateDrag(e,n)}return}const i=this.tD(t.hoveredObjectId);if(this.gk&&this.gk!==i){const t=this.mk.get(this.gk);t&&t.setHovered(!1)}if(i){const t=this.mk.get(i);t&&t.setHovered(!0)}this.gk=i}tD(t){if("string"!=typeof t)return null;const i=t.split("#")[0];for(const[t,s]of this.mk)if(s.id===i)return t;return null}Gk(t){if(this.VC)return;Hh(this.Of,!1);const i=this.Of.chartElement();if(!i)return;const s=null!==this.gk&&null!==this.Dk?{iD:this.gk,Aw:this.Dk}:this.sD(t);if(null===s)return;const{iD:n,Aw:e}=s,r=this.mk.get(n);if(!r||r.isLocked())return;const h=r.hitTestEndpoint(e.ut,e.ct),l=this.nD(r,e.ut,e.ct);if(null!==h&&null!==l){Hh(this.Of,!0),this.selectTool(n),this.VC=!0,this.kk=!0,this.Ik=n,this.gS=t.pointerId;try{i.setPointerCapture(t.pointerId)}catch(t){this.gS=null}r.startDrag(h,l),this.eD()}}Zk(t){if(!this.VC||null===this.Ik||"mouse"===t.pointerType)return;if(null!==this.gS&&t.pointerId!==this.gS)return;const i=this.mk.get(this.Ik);if(!i)return;const s=this.KS(i);if(null===s)return;const n=s.getBoundingClientRect(),e=i.series(),r=e.coordinateToPrice(t.clientY-n.top),h=Jn(this.Of,e,t.clientX-n.left);null!==r&&null!==h&&(i.updateDrag(h,r),t.preventDefault())}Kk(t){if(this.Wk(),!this.VC||null===this.Ik)return;if(t&&null!==this.gS&&t.pointerId!==this.gS)return;const i=this.Ik;this.VC=!1,this.Ik=null;try{const t=this.mk.get(i);t&&t.stopDrag()}finally{this.XS(),this.rD()}this.recordChange()}Jk(t){null!==this.gS&&t.pointerId!==this.gS||(this.gS=null,this.Kk())}KS(t){try{return t.series().getPane().getHTMLElement()}catch(t){return null}}sD(t){for(const[i,s]of this.mk){if(!s.isVisible()||s.isLocked())continue;const n=this.KS(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{iD:i,Aw:r}}return null}XS(){if(null===this.gS)return;const t=this.Of.chartElement();t&&t.hasPointerCapture(this.gS)&&t.releasePointerCapture(this.gS),this.gS=null}eD(){if(null!==this.Rk)return;const t=this.Of.options();this.Rk={hD:f(t.handleScroll),lD:f(t.handleScale)},this.Of.applyOptions({handleScroll:!1,handleScale:!1})}rD(){const t=this.Rk;this.Rk=null,null!==t&&this.Of.applyOptions({handleScroll:t.hD,handleScale:t.lD})}Qk(t){const i=t.target;if(!!i&&("INPUT"===i.tagName||"TEXTAREA"===i.tagName||i.isContentEditable))return;"Enter"===t.key&&this.Wk(),"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.Kk(),this.Ek(),this.stopDrawing(),t.preventDefault())}nD(t,i,s){const n=t.series().coordinateToPrice(s);return null==n?null:{price:n,time:Jn(this.Of,t.series(),i)}}Ek(){this.Ok(null)}}const To={...t,color:"#2196f3"};var ko=Object.freeze({__proto__:null,AreaSeries:ke,ArrowTool:Zl,BarSeries:Ie,BaselineSeries:Ce,BrushTool:io,CandlestickSeries:Le,CircleTool:jl,get ColorType(){return Ai},CrossLineTool:hl,get CrosshairMode(){return U},DEFAULT_SESSIONS:eh,DraggablePriceLine:ph,DrawingToolsManager:Po,EXTENDED_FIBONACCI_RATIOS:Cl,FibonacciCalculator:Pl,FibonacciExtensionTool:Al,FibonacciFanTool:Wl,FibonacciTool:Rl,GanttTool:So,HistogramSeries:Oe,HorizontalLineTool:sl,InteractiveLineManager:fh,get LastPriceAnimationMode(){return Ii},LineSeries:_e,get LineStyle(){return s},get LineType(){return i},get MismatchDirection(){return xt},ParallelChannelTool:pl,PitchforkTool:wl,PolygonTool:_l,PositionCalculator:oo,PositionLine:Dh,PositionMarkersManager:Br,PositionTool:go,get PriceLineSource(){return Vi},get PriceScaleMode(){return di},RectangleTool:Nl,RulerCalculator:uo,RulerTool:fo,STANDARD_FIBONACCI_RATIOS:xl,TextTool:ho,get TickMarkType(){return Li},get TrackingModeExitMode(){return Fi},TradingSessionsIndicator:rh,TrendLineTool:Gh,VerticalLineTool:yl,VolumeProfileIndicator:oh,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=Ur(0,100),h=i.addSeries(_e,{color:n.colorADX,autoscaleInfoProvider:r},e),l=qr(i,h,e),o=i.addSeries(_e,{color:n.colorPlusDI,autoscaleInfoProvider:r},l),a=i.addSeries(_e,{color:n.colorMinusDI,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const _=jr(h,n.levelColor),u=Gr({r_:t,Jf:i,Ry:[h,o,a],Jl:"ADX",W:n,Vy:["period"],Fy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<2*i)return{oD:[],aD:[],_D:[]};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{oD:o,aD:a,_D:_}})(t,i.period??14),n=i.showDI??!0;return[[h,s.oD],[o,n?s.aD:[]],[a,n?s._D:[]]]},Iy: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(_e,{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=Gr({r_:t,Jf:i,Ry:[e],Jl:"ATR",W:n,Vy:["period"],Fy:(t,i)=>[[e,r(t,i.period??14)]],Iy: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(_e,{color:n.colorUpper},e),h=i.addSeries(_e,{color:n.colorMiddle},e),l=i.addSeries(_e,{color:n.colorLower},e),o=Gr({r_:t,Jf:i,Ry:[r,h,l],Jl:"Bollinger Bands",W:n,Vy:["period","stdDev"],Fy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{WP:[],uD:[],zP:[]};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{WP:e,uD:r,zP:h}})(t,i.period??20,i.stdDev??2);return[[r,s.WP],[h,s.uD],[l,s.zP]]},Iy: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(_e,{color:n.color,lineWidth:n.lineWidth},e),h=qr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=jr(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=Gr({r_:t,Jf:i,Ry:[r],Jl:"CCI",W:n,Vy:["period"],Fy:(t,i)=>[[r,o(t,i.period??20)]],Iy: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(_e,{color:n.colorUpper},e),h=i.addSeries(_e,{color:n.colorMiddle},e),l=i.addSeries(_e,{color:n.colorLower},e),o=Gr({r_:t,Jf:i,Ry:[r,h,l],Jl:"Donchian Channels",W:n,Vy:["period"],Fy:(t,i)=>{const s=((t,i)=>{if(!t||t.length<i)return{WP:[],uD:[],zP:[]};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{WP:s,uD:n,zP:e}})(t,i.period??20);return[[r,s.WP],[h,s.uD],[l,s.zP]]},Iy: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(_e,{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=Yr(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=Gr({r_:t,Jf:i,Ry:[e],Jl:"EMA",W:n,Vy:["period","source"],Fy:(t,i)=>[[e,r(t,i.period??12,i.source??"close")]],Iy: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(Le,{upColor:n.upColor,downColor:n.downColor,borderVisible:n.borderVisible,borderUpColor:n.borderUpColor,borderDownColor:n.borderDownColor,wickVisible:n.wickVisible,wickUpColor:n.wickUpColor,wickDownColor:n.wickDownColor,priceScaleId:e.priceScaleId,priceFormat:e.priceFormat,lastValueVisible:e.lastValueVisible,priceLineVisible:e.priceLineVisible},n.paneIndex);let h=null;const l=i=>{i&&null===h?(h=Hr(t),r.setSeriesOrder(t.seriesOrder())):i||null===h||(h(),h=null,r.setSeriesOrder(t.seriesOrder()+1))},o=Gr({r_:t,Jf:i,Ry:[r],Jl:"Heikin Ashi",W:n,Vy:[],Fy:t=>[[r,ih(t)]],Iy: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{series: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(_e,{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 Jr(i,t,()=>u,()=>({Hy:c.cloudBullishColor??"#089981",Ny:c.cloudBearishColor??"#F23645",Oy: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{cD:h,rh:l,Wy:o,zy:a,dD:_,pD: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=Qr(t,i,s),u=Qr(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=Qr(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,Wy:s,zy:n};u.push(t)}}return{cD:h,rh:l,Wy:o,zy:a,dD:_,pD:u}},v=Gr({r_:t,Jf:i,Ry:[h,l,o,a,_],Jl:"Ichimoku",W:n,Vy:["conversionPeriod","basePeriod","spanBPeriod","displacement"],Fy:(t,i)=>{c=i;const s=f(t,i);return u=s.pD,[[h,s.cD],[l,s.rh],[o,s.Wy],[a,s.zy],[_,i.showLagging??1?s.dD:[]]]},Iy: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(_e,{color:n.colorUpper},e),h=i.addSeries(_e,{color:n.colorMiddle},e),l=i.addSeries(_e,{color:n.colorLower},e),o=Gr({r_:t,Jf:i,Ry:[r,h,l],Jl:"Keltner Channels",W:n,Vy:["period","atrPeriod","multiplier","source"],Fy:(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{WP:[],uD:[],zP:[]};const r=Yr(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{WP:c,uD:d,zP:p}})(t,i);return[[r,s.WP],[h,s.uD],[l,s.zP]]},Iy: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(_e,{color:n.colorMACD},e),h=qr(i,r,e),l=i.addSeries(_e,{color:n.colorSignal},h),o=i.addSeries(Oe,{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},_=Gr({r_:t,Jf:i,Ry:[r,l,o],Jl:"MACD",W:n,Vy:["fastPeriod","slowPeriod","signalPeriod","colorHistogramUp","colorHistogramDown"],Fy:(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{fD:[],vD:[],mD:[]};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{fD:c,vD:d,mD:p}})(t,i);return[[r,s.fD],[l,s.vD],[o,s.mD]]},Iy: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(_e,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Ur(0,100)},e),h=qr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=jr(r,n.levelColor),o=(i,s)=>{if(!i||i.length<s+1||!zr(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*(Wr(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=Gr({r_:t,Jf:i,Ry:[r],Jl:"MFI",W:n,Vy:["period"],Fy:(t,i)=>[[r,o(t,i.period??14)]],Iy: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(_e,{color:n.color,lineWidth:n.lineWidth},n.paneIndex),r=()=>{const i=t.data();if(!i||i.length<2||!zr(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=Wr(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=Gr({r_:t,Jf:i,Ry:[e],Jl:"OBV",W:n,Fy:()=>[[e,r()]],Iy: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(_e,{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=Gr({r_:t,Jf:i,Ry:[e],Jl:"Parabolic SAR",W:n,Vy:["step","maxStep","colorUp","colorDown"],Fy:(t,i)=>[[e,r(t,i.step??.02,i.maxStep??.2,i.colorUp??"#089981",i.colorDown??"#F23645")]],Iy: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(_e,{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=Gr({r_:t,Jf:i,Ry:[h,...l,...o],Jl:"Pivot Points",W:n,Vy:["pivotPeriod"],Fy:(t,i)=>{const s=((t,i)=>{const s=[],n=[[],[],[]],e=[[],[],[]];if(!t||0===t.length)return{EP:s,wD:n,gD:e};let r=null,h=-1/0,l=1/0,o=0,a=null;for(const _ of t){const t=Kr(_.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={bD:i,MD:[2*i-l,i+s,h+2*(i-l)],yD:[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.bD});for(let t=0;t<3;t++)n[t].push({time:_.time,value:a.MD[t]}),e[t].push({time:_.time,value:a.yD[t]})}}return{EP:s,wD:n,gD:e}})(t,i.pivotPeriod??"daily"),n=Math.max(1,Math.min(i.levels??3,3)),e=[[h,s.EP]];for(let t=0;t<3;t++)e.push([l[t],t<n?s.wD[t]:[]]),e.push([o[t],t<n?s.gD[t]:[]]);return e},Iy: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(_e,{color:n.color,lineWidth:n.lineWidth,priceFormat:{type:"price",precision:2,minMove:.01},autoscaleInfoProvider:Ur(0,100)},e),h=qr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1},borderVisible:!1});const l=jr(r,n.levelColor),o=(t,i,s)=>{if(!t||t.length<i+1)return[];const n=Yr(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=Gr({r_:t,Jf:i,Ry:[r],Jl:"RSI",W:n,Vy:["period","source"],Fy:(t,i)=>[[r,o(t,i.period??14,i.source??"close")]],Iy: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(_e,{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=Yr(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=Gr({r_:t,Jf:i,Ry:[e],Jl:"SMA",W:n,Vy:["period","source"],Fy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Iy: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=Ur(0,100),h=i.addSeries(_e,{color:n.colorK,autoscaleInfoProvider:r},e),l=qr(i,h,e),o=i.addSeries(_e,{color:n.colorD,autoscaleInfoProvider:r},l);i.priceScale(h.options().priceScaleId??"right",l).applyOptions({scaleMargins:{top:.1,bottom:.1}});const a=jr(h,n.levelColor),_=Gr({r_:t,Jf:i,Ry:[h,o],Jl:"Stochastic",W:n,Vy:["kPeriod","dPeriod"],Fy:(t,i)=>{const s=((t,i,s)=>{if(!t||t.length<i)return{SD:[],xD:[]};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{SD:e,xD:r}})(t,i.kPeriod??14,i.dPeriod??3);return[[h,s.SD],[o,s.xD]]},Iy: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(_e,{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=Gr({r_:t,Jf:i,Ry:[e],Jl:"SuperTrend",Vy:["period","multiplier","colorUp","colorDown"],W:n,Fy:(t,i)=>[[e,r(t,i.period??10,i.multiplier??3,i.colorUp??"#089981",i.colorDown??"#F23645")]],Iy: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(_e,{color:n.color},e),h=i.addSeries(_e,{color:n.bandColor},e),l=i.addSeries(_e,{color:n.bandColor},e),o=Gr({r_:t,Jf:i,Ry:[r,h,l],Jl:"VWAP",W:n,Vy:["anchorPeriod","bandMultiplier"],Fy:(i,s)=>{const n=((i,s,n)=>{const e=[],r=[],h=[];if(!i||0===i.length||!zr(t))return{CD:e,WP:r,zP:h};let l=null,o=0,a=0,_=0;for(const u of i){const i=Kr(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=Wr(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{CD:e,WP:r,zP:h}})(i,s.anchorPeriod??"daily",s.bandMultiplier??0);return[[r,n.CD],[h,n.WP],[l,n.zP]]},Iy: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(Oe,{color:n.colorUp,priceFormat:{type:"volume"},priceScaleId:""},e),h=qr(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||!zr(t))return[];const e=[];for(const r of n){const n=Wr(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=Gr({r_:t,Jf:i,Ry:[r],Jl:"Volume",W:n,Vy:["colorUp","colorDown"],Fy:(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(_e,{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=Yr(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=Gr({r_:t,Jf:i,Ry:[e],Jl:"WMA",W:n,Vy:["period","source"],Fy:(t,i)=>[[e,r(t,i.period??20,i.source??"close")]],Iy: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(_e,{color:n.color,lineWidth:n.lineWidth,autoscaleInfoProvider:Ur(-100,0)},e),h=qr(i,r,e);i.priceScale(r.options().priceScaleId??"right",h).applyOptions({scaleMargins:{top:.1,bottom:.1}});const l=jr(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=Gr({r_:t,Jf:i,Ry:[r],Jl:"Williams %R",W:n,Vy:["period"],Fy:(t,i)=>[[r,o(t,i.period??14)]],Iy: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:ih,calculatePipConfig:ao,coordinateFromTime:Qn,createArrowTool:Jl,createBrushTool:no,createChart:function(t,i){return Kn(t,new ls,ls.vd(i))},createChartEx:Kn,createCircleTool:Xl,createCrossLineTool:ll,createFibonacciExtensionTool:Ll,createFibonacciFanTool:zl,createFibonacciTool:Fl,createGanttTool:xo,createHorizontalLineTool:nl,createImageWatermark:function(t,i,s){return new We(t,new tr(i,s))},createInteractiveLineManager:function(t,i){return new fh(t,i)},createOptionsChart:function(t,i){return Kn(t,new we,i)},createParallelChannelTool:fl,createPitchforkTool:gl,createPolygonTool:ul,createPositionLine:function(t,i,s){return new Dh(i,t,s)},createPositionMarkers:function(t,i,s){const n=new Br(t,s);return i&&i.length>0&&n.setPositions(i),n},createPositionTool:bo,createRectangleTool:Ul,createRulerTool:vo,createSeriesMarkers:yr,createTextTool:lo,createTextWatermark:function(t,i){return new We(t,new Xe(i))},createTimeLabels:function(t,i,s){const n=new Lr(t,new Ar(s));return i&&n.setLabels(i),n},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 ph(i,t,r)},createTradingSessionsIndicator:function(t,i,s){return new rh(t,i,s)},createTrendLineTool:Kh,createUpDownMarkers:function(t,i={}){return new Rr(t,new kr(i))},createVerticalLineTool:Sl,createVolumeProfileIndicator:function(t,i,s){return new oh(t,i,s)},createYieldCurveChart:function(t,i){const s=Gn(t);return new ve(s,i)},customSeriesDefaultOptions:To,defaultHorzScaleBehavior:function(){return ls},getPipConfig:_o,hideSeriesPaint:Hr,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(Or(t.time),t.volume);Er.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:Jn,timeZoneOffset:Gi,version:function(){return"2.3.20-dev+202610211649"}});window.PipsendCharts=ko,window.LightweightCharts=ko}();
|