@devexperts/dxcharts-lite 2.7.23 → 2.7.24

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.
@@ -3,10 +3,10 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- (()=>{var rt=Math.pow;(()=>{var ba={156:(k=>{"use strict";k.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}}),195:(k=>{k.exports=function(N){return!N||typeof N=="string"?!1:N instanceof Array||Array.isArray(N)||N.length>=0&&(N.splice instanceof Function||Object.getOwnPropertyDescriptor(N,N.length-1)&&N.constructor.name!=="String")}}),507:((k,it,N)=>{const q=N(659);function z(){const y={},C=Object.keys(q);for(let w=C.length,g=0;g<w;g++)y[C[g]]={distance:-1,parent:null};return y}function O(y){const C=z(),w=[y];for(C[y].distance=0;w.length;){const g=w.pop(),S=Object.keys(q[g]);for(let P=S.length,E=0;E<P;E++){const m=S[E],M=C[m];M.distance===-1&&(M.distance=C[g].distance+1,M.parent=g,w.unshift(m))}}return C}function dt(y,C){return function(w){return C(y(w))}}function b(y,C){const w=[C[y].parent,y];let g=q[C[y].parent][y],S=C[y].parent;for(;C[S].parent;)w.unshift(C[S].parent),g=dt(q[C[S].parent][S],g),S=C[S].parent;return g.conversion=w,g}k.exports=function(y){const C=O(y),w={},g=Object.keys(C);for(let S=g.length,P=0;P<S;P++){const E=g[P];C[E].parent!==null&&(w[E]=b(E,C))}return w}}),520:((k,it,N)=>{const q=N(854),z=N(734),O=["keyword","gray","hex"],dt={};for(const m of Object.keys(z))dt[[...z[m].labels].sort().join("")]=m;const b={};function y(m,M){if(!(this instanceof y))return new y(m,M);if(M&&M in O&&(M=null),M&&!(M in z))throw new Error("Unknown model: "+M);let I,D;if(m==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(m instanceof y)this.model=m.model,this.color=[...m.color],this.valpha=m.valpha;else if(typeof m=="string"){const H=q.get(m);if(H===null)throw new Error("Unable to parse color from string: "+m);this.model=H.model,D=z[this.model].channels,this.color=H.value.slice(0,D),this.valpha=typeof H.value[D]=="number"?H.value[D]:1}else if(m.length>0){this.model=M||"rgb",D=z[this.model].channels;const H=Array.prototype.slice.call(m,0,D);this.color=E(H,D),this.valpha=typeof m[D]=="number"?m[D]:1}else if(typeof m=="number")this.model="rgb",this.color=[m>>16&255,m>>8&255,m&255],this.valpha=1;else{this.valpha=1;const H=Object.keys(m);"alpha"in m&&(H.splice(H.indexOf("alpha"),1),this.valpha=typeof m.alpha=="number"?m.alpha:0);const lt=H.sort().join("");if(!(lt in dt))throw new Error("Unable to parse color from object: "+JSON.stringify(m));this.model=dt[lt];const{labels:Dt}=z[this.model],Ht=[];for(I=0;I<Dt.length;I++)Ht.push(m[Dt[I]]);this.color=E(Ht)}if(b[this.model])for(D=z[this.model].channels,I=0;I<D;I++){const H=b[this.model][I];H&&(this.color[I]=H(this.color[I]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}y.prototype={toString(){return this.string()},toJSON(){return this[this.model]()},string(m){let M=this.model in q.to?this:this.rgb();M=M.round(typeof m=="number"?m:1);const I=M.valpha===1?M.color:[...M.color,this.valpha];return q.to[M.model](I)},percentString(m){const M=this.rgb().round(typeof m=="number"?m:1),I=M.valpha===1?M.color:[...M.color,this.valpha];return q.to.rgb.percent(I)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const m={},{channels:M}=z[this.model],{labels:I}=z[this.model];for(let D=0;D<M;D++)m[I[D]]=this.color[D];return this.valpha!==1&&(m.alpha=this.valpha),m},unitArray(){const m=this.rgb().color;return m[0]/=255,m[1]/=255,m[2]/=255,this.valpha!==1&&m.push(this.valpha),m},unitObject(){const m=this.rgb().object();return m.r/=255,m.g/=255,m.b/=255,this.valpha!==1&&(m.alpha=this.valpha),m},round(m){return m=Math.max(m||0,0),new y([...this.color.map(w(m)),this.valpha],this.model)},alpha(m){return m!==void 0?new y([...this.color,Math.max(0,Math.min(1,m))],this.model):this.valpha},red:g("rgb",0,S(255)),green:g("rgb",1,S(255)),blue:g("rgb",2,S(255)),hue:g(["hsl","hsv","hsl","hwb","hcg"],0,m=>(m%360+360)%360),saturationl:g("hsl",1,S(100)),lightness:g("hsl",2,S(100)),saturationv:g("hsv",1,S(100)),value:g("hsv",2,S(100)),chroma:g("hcg",1,S(100)),gray:g("hcg",2,S(100)),white:g("hwb",1,S(100)),wblack:g("hwb",2,S(100)),cyan:g("cmyk",0,S(100)),magenta:g("cmyk",1,S(100)),yellow:g("cmyk",2,S(100)),black:g("cmyk",3,S(100)),x:g("xyz",0,S(95.047)),y:g("xyz",1,S(100)),z:g("xyz",2,S(108.833)),l:g("lab",0,S(100)),a:g("lab",1),b:g("lab",2),keyword(m){return m!==void 0?new y(m):z[this.model].keyword(this.color)},hex(m){return m!==void 0?new y(m):q.to.hex(this.rgb().round().color)},hexa(m){if(m!==void 0)return new y(m);const M=this.rgb().round().color;let I=Math.round(this.valpha*255).toString(16).toUpperCase();return I.length===1&&(I="0"+I),q.to.hex(M)+I},rgbNumber(){const m=this.rgb().color;return(m[0]&255)<<16|(m[1]&255)<<8|m[2]&255},luminosity(){const m=this.rgb().color,M=[];for(const[I,D]of m.entries()){const H=D/255;M[I]=H<=.04045?H/12.92:rt((H+.055)/1.055,2.4)}return .2126*M[0]+.7152*M[1]+.0722*M[2]},contrast(m){const M=this.luminosity(),I=m.luminosity();return M>I?(M+.05)/(I+.05):(I+.05)/(M+.05)},level(m){const M=this.contrast(m);return M>=7?"AAA":M>=4.5?"AA":""},isDark(){const m=this.rgb().color;return(m[0]*2126+m[1]*7152+m[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const m=this.rgb();for(let M=0;M<3;M++)m.color[M]=255-m.color[M];return m},lighten(m){const M=this.hsl();return M.color[2]+=M.color[2]*m,M},darken(m){const M=this.hsl();return M.color[2]-=M.color[2]*m,M},saturate(m){const M=this.hsl();return M.color[1]+=M.color[1]*m,M},desaturate(m){const M=this.hsl();return M.color[1]-=M.color[1]*m,M},whiten(m){const M=this.hwb();return M.color[1]+=M.color[1]*m,M},blacken(m){const M=this.hwb();return M.color[2]+=M.color[2]*m,M},grayscale(){const m=this.rgb().color,M=m[0]*.3+m[1]*.59+m[2]*.11;return y.rgb(M,M,M)},fade(m){return this.alpha(this.valpha-this.valpha*m)},opaquer(m){return this.alpha(this.valpha+this.valpha*m)},rotate(m){const M=this.hsl();let I=M.color[0];return I=(I+m)%360,I=I<0?360+I:I,M.color[0]=I,M},mix(m,M){if(!m||!m.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof m);const I=m.rgb(),D=this.rgb(),H=M===void 0?.5:M,lt=2*H-1,Dt=I.alpha()-D.alpha(),Ht=((lt*Dt===-1?lt:(lt+Dt)/(1+lt*Dt))+1)/2,Ne=1-Ht;return y.rgb(Ht*I.red()+Ne*D.red(),Ht*I.green()+Ne*D.green(),Ht*I.blue()+Ne*D.blue(),I.alpha()*H+D.alpha()*(1-H))}};for(const m of Object.keys(z)){if(O.includes(m))continue;const{channels:M}=z[m];y.prototype[m]=function(...I){return this.model===m?new y(this):I.length>0?new y(I,m):new y([...P(z[this.model][m].raw(this.color)),this.valpha],m)},y[m]=function(...I){let D=I[0];return typeof D=="number"&&(D=E(I,M)),new y(D,m)}}function C(m,M){return Number(m.toFixed(M))}function w(m){return function(M){return C(M,m)}}function g(m,M,I){m=Array.isArray(m)?m:[m];for(const D of m)(b[D]||(b[D]=[]))[M]=I;return m=m[0],function(D){let H;return D!==void 0?(I&&(D=I(D)),H=this[m](),H.color[M]=D,H):(H=this[m]().color[M],I&&(H=I(H)),H)}}function S(m){return function(M){return Math.max(0,Math.min(m,M))}}function P(m){return Array.isArray(m)?m:[m]}function E(m,M){for(let I=0;I<M;I++)typeof m[I]!="number"&&(m[I]=0);return m}k.exports=y}),659:((k,it,N)=>{const q=N(156),z={};for(const b of Object.keys(q))z[q[b]]=b;const O={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};k.exports=O;for(const b of Object.keys(O)){if(!("channels"in O[b]))throw new Error("missing channels property: "+b);if(!("labels"in O[b]))throw new Error("missing channel labels property: "+b);if(O[b].labels.length!==O[b].channels)throw new Error("channel and label counts mismatch: "+b);const{channels:y,labels:C}=O[b];delete O[b].channels,delete O[b].labels,Object.defineProperty(O[b],"channels",{value:y}),Object.defineProperty(O[b],"labels",{value:C})}O.rgb.hsl=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(y,C,w),S=Math.max(y,C,w),P=S-g;let E,m;S===g?E=0:y===S?E=(C-w)/P:C===S?E=2+(w-y)/P:w===S&&(E=4+(y-C)/P),E=Math.min(E*60,360),E<0&&(E+=360);const M=(g+S)/2;return S===g?m=0:M<=.5?m=P/(S+g):m=P/(2-S-g),[E,m*100,M*100]},O.rgb.hsv=function(b){let y,C,w,g,S;const P=b[0]/255,E=b[1]/255,m=b[2]/255,M=Math.max(P,E,m),I=M-Math.min(P,E,m),D=function(H){return(M-H)/6/I+1/2};return I===0?(g=0,S=0):(S=I/M,y=D(P),C=D(E),w=D(m),P===M?g=w-C:E===M?g=.3333333333333333+y-w:m===M&&(g=.6666666666666666+C-y),g<0?g+=1:g>1&&(g-=1)),[g*360,S*100,M*100]},O.rgb.hwb=function(b){const y=b[0],C=b[1];let w=b[2];const g=O.rgb.hsl(b)[0],S=1/255*Math.min(y,Math.min(C,w));return w=1-.00392156862745098*Math.max(y,Math.max(C,w)),[g,S*100,w*100]},O.rgb.cmyk=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(1-y,1-C,1-w),S=(1-y-g)/(1-g)||0,P=(1-C-g)/(1-g)||0,E=(1-w-g)/(1-g)||0;return[S*100,P*100,E*100,g*100]};function dt(b,y){return rt(b[0]-y[0],2)+rt(b[1]-y[1],2)+rt(b[2]-y[2],2)}O.rgb.keyword=function(b){const y=z[b];if(y)return y;let C=1/0,w;for(const g of Object.keys(q)){const S=q[g],P=dt(b,S);P<C&&(C=P,w=g)}return w},O.keyword.rgb=function(b){return q[b]},O.rgb.xyz=function(b){let y=b[0]/255,C=b[1]/255,w=b[2]/255;y=y>.04045?rt((y+.055)/1.055,2.4):y/12.92,C=C>.04045?rt((C+.055)/1.055,2.4):C/12.92,w=w>.04045?rt((w+.055)/1.055,2.4):w/12.92;const g=y*.4124+C*.3576+w*.1805,S=y*.2126+C*.7152+w*.0722,P=y*.0193+C*.1192+w*.9505;return[g*100,S*100,P*100]},O.rgb.lab=function(b){const y=O.rgb.xyz(b);let C=y[0],w=y[1],g=y[2];C/=95.047,w/=100,g/=108.883,C=C>.008856?rt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862,g=g>.008856?rt(g,.3333333333333333):7.787*g+.13793103448275862;const S=116*w-16,P=500*(C-w),E=200*(w-g);return[S,P,E]},O.hsl.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;let g,S,P;if(C===0)return P=w*255,[P,P,P];w<.5?g=w*(1+C):g=w+C-w*C;const E=2*w-g,m=[0,0,0];for(let M=0;M<3;M++)S=y+.3333333333333333*-(M-1),S<0&&S++,S>1&&S--,6*S<1?P=E+(g-E)*6*S:2*S<1?P=g:3*S<2?P=E+(g-E)*(.6666666666666666-S)*6:P=E,m[M]=P*255;return m},O.hsl.hsv=function(b){const y=b[0];let C=b[1]/100,w=b[2]/100,g=C;const S=Math.max(w,.01);w*=2,C*=w<=1?w:2-w,g*=S<=1?S:2-S;const P=(w+C)/2,E=w===0?2*g/(S+g):2*C/(w+C);return[y,E*100,P*100]},O.hsv.rgb=function(b){const y=b[0]/60,C=b[1]/100;let w=b[2]/100;const g=Math.floor(y)%6,S=y-Math.floor(y),P=255*w*(1-C),E=255*w*(1-C*S),m=255*w*(1-C*(1-S));switch(w*=255,g){case 0:return[w,m,P];case 1:return[E,w,P];case 2:return[P,w,m];case 3:return[P,E,w];case 4:return[m,P,w];case 5:return[w,P,E]}},O.hsv.hsl=function(b){const y=b[0],C=b[1]/100,w=b[2]/100,g=Math.max(w,.01);let S,P;P=(2-C)*w;const E=(2-C)*g;return S=C*g,S/=E<=1?E:2-E,S=S||0,P/=2,[y,S*100,P*100]},O.hwb.rgb=function(b){const y=b[0]/360;let C=b[1]/100,w=b[2]/100;const g=C+w;let S;g>1&&(C/=g,w/=g);const P=Math.floor(6*y),E=1-w;S=6*y-P,(P&1)!==0&&(S=1-S);const m=C+S*(E-C);let M,I,D;switch(P){default:case 6:case 0:M=E,I=m,D=C;break;case 1:M=m,I=E,D=C;break;case 2:M=C,I=E,D=m;break;case 3:M=C,I=m,D=E;break;case 4:M=m,I=C,D=E;break;case 5:M=E,I=C,D=m;break}return[M*255,I*255,D*255]},O.cmyk.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100,g=b[3]/100,S=1-Math.min(1,y*(1-g)+g),P=1-Math.min(1,C*(1-g)+g),E=1-Math.min(1,w*(1-g)+g);return[S*255,P*255,E*255]},O.xyz.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100;let g,S,P;return g=y*3.2406+C*-1.5372+w*-.4986,S=y*-.9689+C*1.8758+w*.0415,P=y*.0557+C*-.204+w*1.057,g=g>.0031308?1.055*rt(g,.4166666666666667)-.055:g*12.92,S=S>.0031308?1.055*rt(S,.4166666666666667)-.055:S*12.92,P=P>.0031308?1.055*rt(P,.4166666666666667)-.055:P*12.92,g=Math.min(Math.max(0,g),1),S=Math.min(Math.max(0,S),1),P=Math.min(Math.max(0,P),1),[g*255,S*255,P*255]},O.xyz.lab=function(b){let y=b[0],C=b[1],w=b[2];y/=95.047,C/=100,w/=108.883,y=y>.008856?rt(y,.3333333333333333):7.787*y+.13793103448275862,C=C>.008856?rt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862;const g=116*C-16,S=500*(y-C),P=200*(C-w);return[g,S,P]},O.lab.xyz=function(b){const y=b[0],C=b[1],w=b[2];let g,S,P;S=(y+16)/116,g=C/500+S,P=S-w/200;const E=rt(S,3),m=rt(g,3),M=rt(P,3);return S=E>.008856?E:(S-.13793103448275862)/7.787,g=m>.008856?m:(g-.13793103448275862)/7.787,P=M>.008856?M:(P-.13793103448275862)/7.787,g*=95.047,S*=100,P*=108.883,[g,S,P]},O.lab.lch=function(b){const y=b[0],C=b[1],w=b[2];let g;g=Math.atan2(w,C)*360/2/Math.PI,g<0&&(g+=360);const P=Math.sqrt(C*C+w*w);return[y,P,g]},O.lch.lab=function(b){const y=b[0],C=b[1],g=b[2]/360*2*Math.PI,S=C*Math.cos(g),P=C*Math.sin(g);return[y,S,P]},O.rgb.ansi16=function(b,y=null){const[C,w,g]=b;let S=y===null?O.rgb.hsv(b)[2]:y;if(S=Math.round(S/50),S===0)return 30;let P=30+(Math.round(g/255)<<2|Math.round(w/255)<<1|Math.round(C/255));return S===2&&(P+=60),P},O.hsv.ansi16=function(b){return O.rgb.ansi16(O.hsv.rgb(b),b[2])},O.rgb.ansi256=function(b){const y=b[0],C=b[1],w=b[2];return y===C&&C===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(C/255*5)+Math.round(w/255*5)},O.ansi16.rgb=function(b){let y=b%10;if(y===0||y===7)return b>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const C=(~~(b>50)+1)*.5,w=(y&1)*C*255,g=(y>>1&1)*C*255,S=(y>>2&1)*C*255;return[w,g,S]},O.ansi256.rgb=function(b){if(b>=232){const S=(b-232)*10+8;return[S,S,S]}b-=16;let y;const C=Math.floor(b/36)/5*255,w=Math.floor((y=b%36)/6)/5*255,g=y%6/5*255;return[C,w,g]},O.rgb.hex=function(b){const C=(((Math.round(b[0])&255)<<16)+((Math.round(b[1])&255)<<8)+(Math.round(b[2])&255)).toString(16).toUpperCase();return"000000".substring(C.length)+C},O.hex.rgb=function(b){const y=b.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let C=y[0];y[0].length===3&&(C=C.split("").map(E=>E+E).join(""));const w=parseInt(C,16),g=w>>16&255,S=w>>8&255,P=w&255;return[g,S,P]},O.rgb.hcg=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.max(Math.max(y,C),w),S=Math.min(Math.min(y,C),w),P=g-S;let E,m;return P<1?E=S/(1-P):E=0,P<=0?m=0:g===y?m=(C-w)/P%6:g===C?m=2+(w-y)/P:m=4+(y-C)/P,m/=6,m%=1,[m*360,P*100,E*100]},O.hsl.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=C<.5?2*y*C:2*y*(1-C);let g=0;return w<1&&(g=(C-.5*w)/(1-w)),[b[0],w*100,g*100]},O.hsv.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=y*C;let g=0;return w<1&&(g=(C-w)/(1-w)),[b[0],w*100,g*100]},O.hcg.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;if(C===0)return[w*255,w*255,w*255];const g=[0,0,0],S=y%1*6,P=S%1,E=1-P;let m=0;switch(Math.floor(S)){case 0:g[0]=1,g[1]=P,g[2]=0;break;case 1:g[0]=E,g[1]=1,g[2]=0;break;case 2:g[0]=0,g[1]=1,g[2]=P;break;case 3:g[0]=0,g[1]=E,g[2]=1;break;case 4:g[0]=P,g[1]=0,g[2]=1;break;default:g[0]=1,g[1]=0,g[2]=E}return m=(1-C)*w,[(C*g[0]+m)*255,(C*g[1]+m)*255,(C*g[2]+m)*255]},O.hcg.hsv=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);let g=0;return w>0&&(g=y/w),[b[0],g*100,w*100]},O.hcg.hsl=function(b){const y=b[1]/100,w=b[2]/100*(1-y)+.5*y;let g=0;return w>0&&w<.5?g=y/(2*w):w>=.5&&w<1&&(g=y/(2*(1-w))),[b[0],g*100,w*100]},O.hcg.hwb=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);return[b[0],(w-y)*100,(1-w)*100]},O.hwb.hcg=function(b){const y=b[1]/100,w=1-b[2]/100,g=w-y;let S=0;return g<1&&(S=(w-g)/(1-g)),[b[0],g*100,S*100]},O.apple.rgb=function(b){return[b[0]/65535*255,b[1]/65535*255,b[2]/65535*255]},O.rgb.apple=function(b){return[b[0]/255*65535,b[1]/255*65535,b[2]/255*65535]},O.gray.rgb=function(b){return[b[0]/100*255,b[0]/100*255,b[0]/100*255]},O.gray.hsl=function(b){return[0,0,b[0]]},O.gray.hsv=O.gray.hsl,O.gray.hwb=function(b){return[0,100,b[0]]},O.gray.cmyk=function(b){return[0,0,0,b[0]]},O.gray.lab=function(b){return[b[0],0,0]},O.gray.hex=function(b){const y=Math.round(b[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},O.rgb.gray=function(b){return[(b[0]+b[1]+b[2])/3/255*100]}}),734:((k,it,N)=>{const q=N(659),z=N(507),O={},dt=Object.keys(q);function b(C){const w=function(...g){const S=g[0];return S==null?S:(S.length>1&&(g=S),C(g))};return"conversion"in C&&(w.conversion=C.conversion),w}function y(C){const w=function(...g){const S=g[0];if(S==null)return S;S.length>1&&(g=S);const P=C(g);if(typeof P=="object")for(let E=P.length,m=0;m<E;m++)P[m]=Math.round(P[m]);return P};return"conversion"in C&&(w.conversion=C.conversion),w}dt.forEach(C=>{O[C]={},Object.defineProperty(O[C],"channels",{value:q[C].channels}),Object.defineProperty(O[C],"labels",{value:q[C].labels});const w=z(C);Object.keys(w).forEach(S=>{const P=w[S];O[C][S]=y(P),O[C][S].raw=b(P)})}),k.exports=O}),854:((k,it,N)=>{var q=N(156),z=N(872),O=Object.hasOwnProperty,dt=Object.create(null);for(var b in q)O.call(q,b)&&(dt[q[b]]=b);var y=k.exports={to:{},get:{}};y.get=function(g){var S=g.substring(0,3).toLowerCase(),P,E;switch(S){case"hsl":P=y.get.hsl(g),E="hsl";break;case"hwb":P=y.get.hwb(g),E="hwb";break;default:P=y.get.rgb(g),E="rgb";break}return P?{model:E,value:P}:null},y.get.rgb=function(g){if(!g)return null;var S=/^#([a-f0-9]{3,4})$/i,P=/^#([a-f0-9]{6})([a-f0-9]{2})?$/i,E=/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,m=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,M=/^(\w+)$/,I=[0,0,0,1],D,H,lt;if(D=g.match(P)){for(lt=D[2],D=D[1],H=0;H<3;H++){var Dt=H*2;I[H]=parseInt(D.slice(Dt,Dt+2),16)}lt&&(I[3]=parseInt(lt,16)/255)}else if(D=g.match(S)){for(D=D[1],lt=D[3],H=0;H<3;H++)I[H]=parseInt(D[H]+D[H],16);lt&&(I[3]=parseInt(lt+lt,16)/255)}else if(D=g.match(E)){for(H=0;H<3;H++)I[H]=parseInt(D[H+1],0);D[4]&&(D[5]?I[3]=parseFloat(D[4])*.01:I[3]=parseFloat(D[4]))}else if(D=g.match(m)){for(H=0;H<3;H++)I[H]=Math.round(parseFloat(D[H+1])*2.55);D[4]&&(D[5]?I[3]=parseFloat(D[4])*.01:I[3]=parseFloat(D[4]))}else return(D=g.match(M))?D[1]==="transparent"?[0,0,0,0]:O.call(q,D[1])?(I=q[D[1]],I[3]=1,I):null:null;for(H=0;H<3;H++)I[H]=C(I[H],0,255);return I[3]=C(I[3],0,1),I},y.get.hsl=function(g){if(!g)return null;var S=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,P=g.match(S);if(P){var E=parseFloat(P[4]),m=(parseFloat(P[1])%360+360)%360,M=C(parseFloat(P[2]),0,100),I=C(parseFloat(P[3]),0,100),D=C(isNaN(E)?1:E,0,1);return[m,M,I,D]}return null},y.get.hwb=function(g){if(!g)return null;var S=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,P=g.match(S);if(P){var E=parseFloat(P[4]),m=(parseFloat(P[1])%360+360)%360,M=C(parseFloat(P[2]),0,100),I=C(parseFloat(P[3]),0,100),D=C(isNaN(E)?1:E,0,1);return[m,M,I,D]}return null},y.to.hex=function(){var g=z(arguments);return"#"+w(g[0])+w(g[1])+w(g[2])+(g[3]<1?w(Math.round(g[3]*255)):"")},y.to.rgb=function(){var g=z(arguments);return g.length<4||g[3]===1?"rgb("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+")":"rgba("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+", "+g[3]+")"},y.to.rgb.percent=function(){var g=z(arguments),S=Math.round(g[0]/255*100),P=Math.round(g[1]/255*100),E=Math.round(g[2]/255*100);return g.length<4||g[3]===1?"rgb("+S+"%, "+P+"%, "+E+"%)":"rgba("+S+"%, "+P+"%, "+E+"%, "+g[3]+")"},y.to.hsl=function(){var g=z(arguments);return g.length<4||g[3]===1?"hsl("+g[0]+", "+g[1]+"%, "+g[2]+"%)":"hsla("+g[0]+", "+g[1]+"%, "+g[2]+"%, "+g[3]+")"},y.to.hwb=function(){var g=z(arguments),S="";return g.length>=4&&g[3]!==1&&(S=", "+g[3]),"hwb("+g[0]+", "+g[1]+"%, "+g[2]+"%"+S+")"},y.to.keyword=function(g){return dt[g.slice(0,3)]};function C(g,S,P){return Math.min(Math.max(S,g),P)}function w(g){var S=Math.round(g).toString(16).toUpperCase();return S.length<2?"0"+S:S}}),872:((k,it,N)=>{"use strict";var q=N(195),z=Array.prototype.concat,O=Array.prototype.slice,dt=k.exports=function(y){for(var C=[],w=0,g=y.length;w<g;w++){var S=y[w];q(S)?C=z.call(C,O.call(S)):C.push(S)}return C};dt.wrap=function(b){return function(){return b(dt(arguments))}}})},_n={};function xt(k){var it=_n[k];if(it!==void 0)return it.exports;var N=_n[k]={exports:{}};return ba[k](N,N.exports,xt),N.exports}xt.n=k=>{var it=k&&k.__esModule?()=>k.default:()=>k;return xt.d(it,{a:it}),it},xt.d=(k,it)=>{for(var N in it)xt.o(it,N)&&!xt.o(k,N)&&Object.defineProperty(k,N,{enumerable:!0,get:it[N]})},xt.o=(k,it)=>Object.prototype.hasOwnProperty.call(k,it),xt.r=k=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(k,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(k,"__esModule",{value:!0})};var Ps={};(()=>{"use strict";xt.r(Ps),xt.d(Ps,{Chart:()=>ua,createChart:()=>lm,generateCandlesData:()=>am});function k(n){return typeof n=="function"}function it(n){return k(n==null?void 0:n.lift)}function N(n){return function(t){if(it(t))return t.lift(function(e){try{return n(e,this)}catch(s){this.error(s)}});throw new TypeError("Unable to lift unknown Observable type")}}var q=function(n,t){return q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,s){e.__proto__=s}||function(e,s){for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(e[i]=s[i])},q(n,t)};function z(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");q(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var O=function(){return O=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++){e=arguments[s];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},O.apply(this,arguments)};function dt(n,t){var e={};for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&t.indexOf(s)<0&&(e[s]=n[s]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,s=Object.getOwnPropertySymbols(n);i<s.length;i++)t.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(n,s[i])&&(e[s[i]]=n[s[i]]);return e}function b(n,t,e,s){var i=arguments.length,r=i<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,t,e,s);else for(var a=n.length-1;a>=0;a--)(o=n[a])&&(r=(i<3?o(r):i>3?o(t,e,r):o(t,e))||r);return i>3&&r&&Object.defineProperty(t,e,r),r}function y(n,t){return function(e,s){t(e,s,n)}}function C(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)}function w(n,t,e,s){function i(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function a(h){try{c(s.next(h))}catch(d){o(d)}}function l(h){try{c(s.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):i(h.value).then(a,l)}c((s=s.apply(n,t||[])).next())})}function g(n,t){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},s,i,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(s=1,i&&(r=c[0]&2?i.return:c[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,c[1])).done)return r;switch(i=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,i=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){e.label=c[1];break}if(c[0]===6&&e.label<r[1]){e.label=r[1],r=c;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(c);break}r[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(h){c=[6,h],i=0}finally{s=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var S=Object.create?(function(n,t,e,s){s===void 0&&(s=e);var i=Object.getOwnPropertyDescriptor(t,e);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,s,i)}):(function(n,t,e,s){s===void 0&&(s=e),n[s]=t[e]});function P(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&S(t,n,e)}function E(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],s=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&s>=n.length&&(n=void 0),{value:n&&n[s++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var s=e.call(n),i,r=[],o;try{for(;(t===void 0||t-- >0)&&!(i=s.next()).done;)r.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(e=s.return)&&e.call(s)}finally{if(o)throw o.error}}return r}function M(){for(var n=[],t=0;t<arguments.length;t++)n=n.concat(m(arguments[t]));return n}function I(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var s=Array(n),i=0,t=0;t<e;t++)for(var r=arguments[t],o=0,a=r.length;o<a;o++,i++)s[i]=r[o];return s}function D(n,t,e){if(e||arguments.length===2)for(var s=0,i=t.length,r;s<i;s++)(r||!(s in t))&&(r||(r=Array.prototype.slice.call(t,0,s)),r[s]=t[s]);return n.concat(r||Array.prototype.slice.call(t))}function H(n){return this instanceof H?(this.v=n,this):new H(n)}function lt(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=e.apply(n,t||[]),i,r=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(u){s[u]&&(i[u]=function(f){return new Promise(function(p,v){r.push([u,f,p,v])>1||a(u,f)})})}function a(u,f){try{l(s[u](f))}catch(p){d(r[0][3],p)}}function l(u){u.value instanceof H?Promise.resolve(u.value.v).then(c,h):d(r[0][2],u)}function c(u){a("next",u)}function h(u){a("throw",u)}function d(u,f){u(f),r.shift(),r.length&&a(r[0][0],r[0][1])}}function Dt(n){var t,e;return t={},s("next"),s("throw",function(i){throw i}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(i,r){t[i]=n[i]?function(o){return(e=!e)?{value:H(n[i](o)),done:i==="return"}:r?r(o):o}:r}}function Ht(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof E=="function"?E(n):n[Symbol.iterator](),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(r){e[r]=n[r]&&function(o){return new Promise(function(a,l){o=n[r](o),i(a,l,o.done,o.value)})}}function i(r,o,a,l){Promise.resolve(l).then(function(c){r({value:c,done:a})},o)}}function Ne(n,t){return Object.defineProperty?Object.defineProperty(n,"raw",{value:t}):n.raw=t,n}var Ca=Object.create?(function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}):function(n,t){n.default=t};function hm(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var e in n)e!=="default"&&Object.prototype.hasOwnProperty.call(n,e)&&S(t,n,e);return Ca(t,n),t}function dm(n){return n&&n.__esModule?n:{default:n}}function um(n,t,e,s){if(e==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?n!==t||!s:!t.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?s:e==="a"?s.call(n):s?s.value:t.get(n)}function fm(n,t,e,s,i){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?n!==t||!i:!t.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?i.call(n,e):i?i.value=e:t.set(n,e),e}function gm(n,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof n=="function"?t===n:n.has(t)}function Pn(n){var t=function(s){Error.call(s),s.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Ts=Pn(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
6
+ (()=>{var rt=Math.pow;(()=>{var ba={156:(k=>{"use strict";k.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}}),195:(k=>{k.exports=function(N){return!N||typeof N=="string"?!1:N instanceof Array||Array.isArray(N)||N.length>=0&&(N.splice instanceof Function||Object.getOwnPropertyDescriptor(N,N.length-1)&&N.constructor.name!=="String")}}),507:((k,it,N)=>{const q=N(659);function z(){const y={},C=Object.keys(q);for(let w=C.length,p=0;p<w;p++)y[C[p]]={distance:-1,parent:null};return y}function O(y){const C=z(),w=[y];for(C[y].distance=0;w.length;){const p=w.pop(),S=Object.keys(q[p]);for(let P=S.length,E=0;E<P;E++){const v=S[E],M=C[v];M.distance===-1&&(M.distance=C[p].distance+1,M.parent=p,w.unshift(v))}}return C}function dt(y,C){return function(w){return C(y(w))}}function b(y,C){const w=[C[y].parent,y];let p=q[C[y].parent][y],S=C[y].parent;for(;C[S].parent;)w.unshift(C[S].parent),p=dt(q[C[S].parent][S],p),S=C[S].parent;return p.conversion=w,p}k.exports=function(y){const C=O(y),w={},p=Object.keys(C);for(let S=p.length,P=0;P<S;P++){const E=p[P];C[E].parent!==null&&(w[E]=b(E,C))}return w}}),520:((k,it,N)=>{const q=N(854),z=N(734),O=["keyword","gray","hex"],dt={};for(const v of Object.keys(z))dt[[...z[v].labels].sort().join("")]=v;const b={};function y(v,M){if(!(this instanceof y))return new y(v,M);if(M&&M in O&&(M=null),M&&!(M in z))throw new Error("Unknown model: "+M);let I,D;if(v==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(v instanceof y)this.model=v.model,this.color=[...v.color],this.valpha=v.valpha;else if(typeof v=="string"){const H=q.get(v);if(H===null)throw new Error("Unable to parse color from string: "+v);this.model=H.model,D=z[this.model].channels,this.color=H.value.slice(0,D),this.valpha=typeof H.value[D]=="number"?H.value[D]:1}else if(v.length>0){this.model=M||"rgb",D=z[this.model].channels;const H=Array.prototype.slice.call(v,0,D);this.color=E(H,D),this.valpha=typeof v[D]=="number"?v[D]:1}else if(typeof v=="number")this.model="rgb",this.color=[v>>16&255,v>>8&255,v&255],this.valpha=1;else{this.valpha=1;const H=Object.keys(v);"alpha"in v&&(H.splice(H.indexOf("alpha"),1),this.valpha=typeof v.alpha=="number"?v.alpha:0);const lt=H.sort().join("");if(!(lt in dt))throw new Error("Unable to parse color from object: "+JSON.stringify(v));this.model=dt[lt];const{labels:Dt}=z[this.model],Ht=[];for(I=0;I<Dt.length;I++)Ht.push(v[Dt[I]]);this.color=E(Ht)}if(b[this.model])for(D=z[this.model].channels,I=0;I<D;I++){const H=b[this.model][I];H&&(this.color[I]=H(this.color[I]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}y.prototype={toString(){return this.string()},toJSON(){return this[this.model]()},string(v){let M=this.model in q.to?this:this.rgb();M=M.round(typeof v=="number"?v:1);const I=M.valpha===1?M.color:[...M.color,this.valpha];return q.to[M.model](I)},percentString(v){const M=this.rgb().round(typeof v=="number"?v:1),I=M.valpha===1?M.color:[...M.color,this.valpha];return q.to.rgb.percent(I)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const v={},{channels:M}=z[this.model],{labels:I}=z[this.model];for(let D=0;D<M;D++)v[I[D]]=this.color[D];return this.valpha!==1&&(v.alpha=this.valpha),v},unitArray(){const v=this.rgb().color;return v[0]/=255,v[1]/=255,v[2]/=255,this.valpha!==1&&v.push(this.valpha),v},unitObject(){const v=this.rgb().object();return v.r/=255,v.g/=255,v.b/=255,this.valpha!==1&&(v.alpha=this.valpha),v},round(v){return v=Math.max(v||0,0),new y([...this.color.map(w(v)),this.valpha],this.model)},alpha(v){return v!==void 0?new y([...this.color,Math.max(0,Math.min(1,v))],this.model):this.valpha},red:p("rgb",0,S(255)),green:p("rgb",1,S(255)),blue:p("rgb",2,S(255)),hue:p(["hsl","hsv","hsl","hwb","hcg"],0,v=>(v%360+360)%360),saturationl:p("hsl",1,S(100)),lightness:p("hsl",2,S(100)),saturationv:p("hsv",1,S(100)),value:p("hsv",2,S(100)),chroma:p("hcg",1,S(100)),gray:p("hcg",2,S(100)),white:p("hwb",1,S(100)),wblack:p("hwb",2,S(100)),cyan:p("cmyk",0,S(100)),magenta:p("cmyk",1,S(100)),yellow:p("cmyk",2,S(100)),black:p("cmyk",3,S(100)),x:p("xyz",0,S(95.047)),y:p("xyz",1,S(100)),z:p("xyz",2,S(108.833)),l:p("lab",0,S(100)),a:p("lab",1),b:p("lab",2),keyword(v){return v!==void 0?new y(v):z[this.model].keyword(this.color)},hex(v){return v!==void 0?new y(v):q.to.hex(this.rgb().round().color)},hexa(v){if(v!==void 0)return new y(v);const M=this.rgb().round().color;let I=Math.round(this.valpha*255).toString(16).toUpperCase();return I.length===1&&(I="0"+I),q.to.hex(M)+I},rgbNumber(){const v=this.rgb().color;return(v[0]&255)<<16|(v[1]&255)<<8|v[2]&255},luminosity(){const v=this.rgb().color,M=[];for(const[I,D]of v.entries()){const H=D/255;M[I]=H<=.04045?H/12.92:rt((H+.055)/1.055,2.4)}return .2126*M[0]+.7152*M[1]+.0722*M[2]},contrast(v){const M=this.luminosity(),I=v.luminosity();return M>I?(M+.05)/(I+.05):(I+.05)/(M+.05)},level(v){const M=this.contrast(v);return M>=7?"AAA":M>=4.5?"AA":""},isDark(){const v=this.rgb().color;return(v[0]*2126+v[1]*7152+v[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const v=this.rgb();for(let M=0;M<3;M++)v.color[M]=255-v.color[M];return v},lighten(v){const M=this.hsl();return M.color[2]+=M.color[2]*v,M},darken(v){const M=this.hsl();return M.color[2]-=M.color[2]*v,M},saturate(v){const M=this.hsl();return M.color[1]+=M.color[1]*v,M},desaturate(v){const M=this.hsl();return M.color[1]-=M.color[1]*v,M},whiten(v){const M=this.hwb();return M.color[1]+=M.color[1]*v,M},blacken(v){const M=this.hwb();return M.color[2]+=M.color[2]*v,M},grayscale(){const v=this.rgb().color,M=v[0]*.3+v[1]*.59+v[2]*.11;return y.rgb(M,M,M)},fade(v){return this.alpha(this.valpha-this.valpha*v)},opaquer(v){return this.alpha(this.valpha+this.valpha*v)},rotate(v){const M=this.hsl();let I=M.color[0];return I=(I+v)%360,I=I<0?360+I:I,M.color[0]=I,M},mix(v,M){if(!v||!v.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof v);const I=v.rgb(),D=this.rgb(),H=M===void 0?.5:M,lt=2*H-1,Dt=I.alpha()-D.alpha(),Ht=((lt*Dt===-1?lt:(lt+Dt)/(1+lt*Dt))+1)/2,Ne=1-Ht;return y.rgb(Ht*I.red()+Ne*D.red(),Ht*I.green()+Ne*D.green(),Ht*I.blue()+Ne*D.blue(),I.alpha()*H+D.alpha()*(1-H))}};for(const v of Object.keys(z)){if(O.includes(v))continue;const{channels:M}=z[v];y.prototype[v]=function(...I){return this.model===v?new y(this):I.length>0?new y(I,v):new y([...P(z[this.model][v].raw(this.color)),this.valpha],v)},y[v]=function(...I){let D=I[0];return typeof D=="number"&&(D=E(I,M)),new y(D,v)}}function C(v,M){return Number(v.toFixed(M))}function w(v){return function(M){return C(M,v)}}function p(v,M,I){v=Array.isArray(v)?v:[v];for(const D of v)(b[D]||(b[D]=[]))[M]=I;return v=v[0],function(D){let H;return D!==void 0?(I&&(D=I(D)),H=this[v](),H.color[M]=D,H):(H=this[v]().color[M],I&&(H=I(H)),H)}}function S(v){return function(M){return Math.max(0,Math.min(v,M))}}function P(v){return Array.isArray(v)?v:[v]}function E(v,M){for(let I=0;I<M;I++)typeof v[I]!="number"&&(v[I]=0);return v}k.exports=y}),659:((k,it,N)=>{const q=N(156),z={};for(const b of Object.keys(q))z[q[b]]=b;const O={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};k.exports=O;for(const b of Object.keys(O)){if(!("channels"in O[b]))throw new Error("missing channels property: "+b);if(!("labels"in O[b]))throw new Error("missing channel labels property: "+b);if(O[b].labels.length!==O[b].channels)throw new Error("channel and label counts mismatch: "+b);const{channels:y,labels:C}=O[b];delete O[b].channels,delete O[b].labels,Object.defineProperty(O[b],"channels",{value:y}),Object.defineProperty(O[b],"labels",{value:C})}O.rgb.hsl=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,p=Math.min(y,C,w),S=Math.max(y,C,w),P=S-p;let E,v;S===p?E=0:y===S?E=(C-w)/P:C===S?E=2+(w-y)/P:w===S&&(E=4+(y-C)/P),E=Math.min(E*60,360),E<0&&(E+=360);const M=(p+S)/2;return S===p?v=0:M<=.5?v=P/(S+p):v=P/(2-S-p),[E,v*100,M*100]},O.rgb.hsv=function(b){let y,C,w,p,S;const P=b[0]/255,E=b[1]/255,v=b[2]/255,M=Math.max(P,E,v),I=M-Math.min(P,E,v),D=function(H){return(M-H)/6/I+1/2};return I===0?(p=0,S=0):(S=I/M,y=D(P),C=D(E),w=D(v),P===M?p=w-C:E===M?p=.3333333333333333+y-w:v===M&&(p=.6666666666666666+C-y),p<0?p+=1:p>1&&(p-=1)),[p*360,S*100,M*100]},O.rgb.hwb=function(b){const y=b[0],C=b[1];let w=b[2];const p=O.rgb.hsl(b)[0],S=1/255*Math.min(y,Math.min(C,w));return w=1-.00392156862745098*Math.max(y,Math.max(C,w)),[p,S*100,w*100]},O.rgb.cmyk=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,p=Math.min(1-y,1-C,1-w),S=(1-y-p)/(1-p)||0,P=(1-C-p)/(1-p)||0,E=(1-w-p)/(1-p)||0;return[S*100,P*100,E*100,p*100]};function dt(b,y){return rt(b[0]-y[0],2)+rt(b[1]-y[1],2)+rt(b[2]-y[2],2)}O.rgb.keyword=function(b){const y=z[b];if(y)return y;let C=1/0,w;for(const p of Object.keys(q)){const S=q[p],P=dt(b,S);P<C&&(C=P,w=p)}return w},O.keyword.rgb=function(b){return q[b]},O.rgb.xyz=function(b){let y=b[0]/255,C=b[1]/255,w=b[2]/255;y=y>.04045?rt((y+.055)/1.055,2.4):y/12.92,C=C>.04045?rt((C+.055)/1.055,2.4):C/12.92,w=w>.04045?rt((w+.055)/1.055,2.4):w/12.92;const p=y*.4124+C*.3576+w*.1805,S=y*.2126+C*.7152+w*.0722,P=y*.0193+C*.1192+w*.9505;return[p*100,S*100,P*100]},O.rgb.lab=function(b){const y=O.rgb.xyz(b);let C=y[0],w=y[1],p=y[2];C/=95.047,w/=100,p/=108.883,C=C>.008856?rt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862,p=p>.008856?rt(p,.3333333333333333):7.787*p+.13793103448275862;const S=116*w-16,P=500*(C-w),E=200*(w-p);return[S,P,E]},O.hsl.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;let p,S,P;if(C===0)return P=w*255,[P,P,P];w<.5?p=w*(1+C):p=w+C-w*C;const E=2*w-p,v=[0,0,0];for(let M=0;M<3;M++)S=y+.3333333333333333*-(M-1),S<0&&S++,S>1&&S--,6*S<1?P=E+(p-E)*6*S:2*S<1?P=p:3*S<2?P=E+(p-E)*(.6666666666666666-S)*6:P=E,v[M]=P*255;return v},O.hsl.hsv=function(b){const y=b[0];let C=b[1]/100,w=b[2]/100,p=C;const S=Math.max(w,.01);w*=2,C*=w<=1?w:2-w,p*=S<=1?S:2-S;const P=(w+C)/2,E=w===0?2*p/(S+p):2*C/(w+C);return[y,E*100,P*100]},O.hsv.rgb=function(b){const y=b[0]/60,C=b[1]/100;let w=b[2]/100;const p=Math.floor(y)%6,S=y-Math.floor(y),P=255*w*(1-C),E=255*w*(1-C*S),v=255*w*(1-C*(1-S));switch(w*=255,p){case 0:return[w,v,P];case 1:return[E,w,P];case 2:return[P,w,v];case 3:return[P,E,w];case 4:return[v,P,w];case 5:return[w,P,E]}},O.hsv.hsl=function(b){const y=b[0],C=b[1]/100,w=b[2]/100,p=Math.max(w,.01);let S,P;P=(2-C)*w;const E=(2-C)*p;return S=C*p,S/=E<=1?E:2-E,S=S||0,P/=2,[y,S*100,P*100]},O.hwb.rgb=function(b){const y=b[0]/360;let C=b[1]/100,w=b[2]/100;const p=C+w;let S;p>1&&(C/=p,w/=p);const P=Math.floor(6*y),E=1-w;S=6*y-P,(P&1)!==0&&(S=1-S);const v=C+S*(E-C);let M,I,D;switch(P){default:case 6:case 0:M=E,I=v,D=C;break;case 1:M=v,I=E,D=C;break;case 2:M=C,I=E,D=v;break;case 3:M=C,I=v,D=E;break;case 4:M=v,I=C,D=E;break;case 5:M=E,I=C,D=v;break}return[M*255,I*255,D*255]},O.cmyk.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100,p=b[3]/100,S=1-Math.min(1,y*(1-p)+p),P=1-Math.min(1,C*(1-p)+p),E=1-Math.min(1,w*(1-p)+p);return[S*255,P*255,E*255]},O.xyz.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100;let p,S,P;return p=y*3.2406+C*-1.5372+w*-.4986,S=y*-.9689+C*1.8758+w*.0415,P=y*.0557+C*-.204+w*1.057,p=p>.0031308?1.055*rt(p,.4166666666666667)-.055:p*12.92,S=S>.0031308?1.055*rt(S,.4166666666666667)-.055:S*12.92,P=P>.0031308?1.055*rt(P,.4166666666666667)-.055:P*12.92,p=Math.min(Math.max(0,p),1),S=Math.min(Math.max(0,S),1),P=Math.min(Math.max(0,P),1),[p*255,S*255,P*255]},O.xyz.lab=function(b){let y=b[0],C=b[1],w=b[2];y/=95.047,C/=100,w/=108.883,y=y>.008856?rt(y,.3333333333333333):7.787*y+.13793103448275862,C=C>.008856?rt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862;const p=116*C-16,S=500*(y-C),P=200*(C-w);return[p,S,P]},O.lab.xyz=function(b){const y=b[0],C=b[1],w=b[2];let p,S,P;S=(y+16)/116,p=C/500+S,P=S-w/200;const E=rt(S,3),v=rt(p,3),M=rt(P,3);return S=E>.008856?E:(S-.13793103448275862)/7.787,p=v>.008856?v:(p-.13793103448275862)/7.787,P=M>.008856?M:(P-.13793103448275862)/7.787,p*=95.047,S*=100,P*=108.883,[p,S,P]},O.lab.lch=function(b){const y=b[0],C=b[1],w=b[2];let p;p=Math.atan2(w,C)*360/2/Math.PI,p<0&&(p+=360);const P=Math.sqrt(C*C+w*w);return[y,P,p]},O.lch.lab=function(b){const y=b[0],C=b[1],p=b[2]/360*2*Math.PI,S=C*Math.cos(p),P=C*Math.sin(p);return[y,S,P]},O.rgb.ansi16=function(b,y=null){const[C,w,p]=b;let S=y===null?O.rgb.hsv(b)[2]:y;if(S=Math.round(S/50),S===0)return 30;let P=30+(Math.round(p/255)<<2|Math.round(w/255)<<1|Math.round(C/255));return S===2&&(P+=60),P},O.hsv.ansi16=function(b){return O.rgb.ansi16(O.hsv.rgb(b),b[2])},O.rgb.ansi256=function(b){const y=b[0],C=b[1],w=b[2];return y===C&&C===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(C/255*5)+Math.round(w/255*5)},O.ansi16.rgb=function(b){let y=b%10;if(y===0||y===7)return b>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const C=(~~(b>50)+1)*.5,w=(y&1)*C*255,p=(y>>1&1)*C*255,S=(y>>2&1)*C*255;return[w,p,S]},O.ansi256.rgb=function(b){if(b>=232){const S=(b-232)*10+8;return[S,S,S]}b-=16;let y;const C=Math.floor(b/36)/5*255,w=Math.floor((y=b%36)/6)/5*255,p=y%6/5*255;return[C,w,p]},O.rgb.hex=function(b){const C=(((Math.round(b[0])&255)<<16)+((Math.round(b[1])&255)<<8)+(Math.round(b[2])&255)).toString(16).toUpperCase();return"000000".substring(C.length)+C},O.hex.rgb=function(b){const y=b.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let C=y[0];y[0].length===3&&(C=C.split("").map(E=>E+E).join(""));const w=parseInt(C,16),p=w>>16&255,S=w>>8&255,P=w&255;return[p,S,P]},O.rgb.hcg=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,p=Math.max(Math.max(y,C),w),S=Math.min(Math.min(y,C),w),P=p-S;let E,v;return P<1?E=S/(1-P):E=0,P<=0?v=0:p===y?v=(C-w)/P%6:p===C?v=2+(w-y)/P:v=4+(y-C)/P,v/=6,v%=1,[v*360,P*100,E*100]},O.hsl.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=C<.5?2*y*C:2*y*(1-C);let p=0;return w<1&&(p=(C-.5*w)/(1-w)),[b[0],w*100,p*100]},O.hsv.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=y*C;let p=0;return w<1&&(p=(C-w)/(1-w)),[b[0],w*100,p*100]},O.hcg.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;if(C===0)return[w*255,w*255,w*255];const p=[0,0,0],S=y%1*6,P=S%1,E=1-P;let v=0;switch(Math.floor(S)){case 0:p[0]=1,p[1]=P,p[2]=0;break;case 1:p[0]=E,p[1]=1,p[2]=0;break;case 2:p[0]=0,p[1]=1,p[2]=P;break;case 3:p[0]=0,p[1]=E,p[2]=1;break;case 4:p[0]=P,p[1]=0,p[2]=1;break;default:p[0]=1,p[1]=0,p[2]=E}return v=(1-C)*w,[(C*p[0]+v)*255,(C*p[1]+v)*255,(C*p[2]+v)*255]},O.hcg.hsv=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);let p=0;return w>0&&(p=y/w),[b[0],p*100,w*100]},O.hcg.hsl=function(b){const y=b[1]/100,w=b[2]/100*(1-y)+.5*y;let p=0;return w>0&&w<.5?p=y/(2*w):w>=.5&&w<1&&(p=y/(2*(1-w))),[b[0],p*100,w*100]},O.hcg.hwb=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);return[b[0],(w-y)*100,(1-w)*100]},O.hwb.hcg=function(b){const y=b[1]/100,w=1-b[2]/100,p=w-y;let S=0;return p<1&&(S=(w-p)/(1-p)),[b[0],p*100,S*100]},O.apple.rgb=function(b){return[b[0]/65535*255,b[1]/65535*255,b[2]/65535*255]},O.rgb.apple=function(b){return[b[0]/255*65535,b[1]/255*65535,b[2]/255*65535]},O.gray.rgb=function(b){return[b[0]/100*255,b[0]/100*255,b[0]/100*255]},O.gray.hsl=function(b){return[0,0,b[0]]},O.gray.hsv=O.gray.hsl,O.gray.hwb=function(b){return[0,100,b[0]]},O.gray.cmyk=function(b){return[0,0,0,b[0]]},O.gray.lab=function(b){return[b[0],0,0]},O.gray.hex=function(b){const y=Math.round(b[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},O.rgb.gray=function(b){return[(b[0]+b[1]+b[2])/3/255*100]}}),734:((k,it,N)=>{const q=N(659),z=N(507),O={},dt=Object.keys(q);function b(C){const w=function(...p){const S=p[0];return S==null?S:(S.length>1&&(p=S),C(p))};return"conversion"in C&&(w.conversion=C.conversion),w}function y(C){const w=function(...p){const S=p[0];if(S==null)return S;S.length>1&&(p=S);const P=C(p);if(typeof P=="object")for(let E=P.length,v=0;v<E;v++)P[v]=Math.round(P[v]);return P};return"conversion"in C&&(w.conversion=C.conversion),w}dt.forEach(C=>{O[C]={},Object.defineProperty(O[C],"channels",{value:q[C].channels}),Object.defineProperty(O[C],"labels",{value:q[C].labels});const w=z(C);Object.keys(w).forEach(S=>{const P=w[S];O[C][S]=y(P),O[C][S].raw=b(P)})}),k.exports=O}),854:((k,it,N)=>{var q=N(156),z=N(872),O=Object.hasOwnProperty,dt=Object.create(null);for(var b in q)O.call(q,b)&&(dt[q[b]]=b);var y=k.exports={to:{},get:{}};y.get=function(p){var S=p.substring(0,3).toLowerCase(),P,E;switch(S){case"hsl":P=y.get.hsl(p),E="hsl";break;case"hwb":P=y.get.hwb(p),E="hwb";break;default:P=y.get.rgb(p),E="rgb";break}return P?{model:E,value:P}:null},y.get.rgb=function(p){if(!p)return null;var S=/^#([a-f0-9]{3,4})$/i,P=/^#([a-f0-9]{6})([a-f0-9]{2})?$/i,E=/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,v=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,M=/^(\w+)$/,I=[0,0,0,1],D,H,lt;if(D=p.match(P)){for(lt=D[2],D=D[1],H=0;H<3;H++){var Dt=H*2;I[H]=parseInt(D.slice(Dt,Dt+2),16)}lt&&(I[3]=parseInt(lt,16)/255)}else if(D=p.match(S)){for(D=D[1],lt=D[3],H=0;H<3;H++)I[H]=parseInt(D[H]+D[H],16);lt&&(I[3]=parseInt(lt+lt,16)/255)}else if(D=p.match(E)){for(H=0;H<3;H++)I[H]=parseInt(D[H+1],0);D[4]&&(D[5]?I[3]=parseFloat(D[4])*.01:I[3]=parseFloat(D[4]))}else if(D=p.match(v)){for(H=0;H<3;H++)I[H]=Math.round(parseFloat(D[H+1])*2.55);D[4]&&(D[5]?I[3]=parseFloat(D[4])*.01:I[3]=parseFloat(D[4]))}else return(D=p.match(M))?D[1]==="transparent"?[0,0,0,0]:O.call(q,D[1])?(I=q[D[1]],I[3]=1,I):null:null;for(H=0;H<3;H++)I[H]=C(I[H],0,255);return I[3]=C(I[3],0,1),I},y.get.hsl=function(p){if(!p)return null;var S=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,P=p.match(S);if(P){var E=parseFloat(P[4]),v=(parseFloat(P[1])%360+360)%360,M=C(parseFloat(P[2]),0,100),I=C(parseFloat(P[3]),0,100),D=C(isNaN(E)?1:E,0,1);return[v,M,I,D]}return null},y.get.hwb=function(p){if(!p)return null;var S=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,P=p.match(S);if(P){var E=parseFloat(P[4]),v=(parseFloat(P[1])%360+360)%360,M=C(parseFloat(P[2]),0,100),I=C(parseFloat(P[3]),0,100),D=C(isNaN(E)?1:E,0,1);return[v,M,I,D]}return null},y.to.hex=function(){var p=z(arguments);return"#"+w(p[0])+w(p[1])+w(p[2])+(p[3]<1?w(Math.round(p[3]*255)):"")},y.to.rgb=function(){var p=z(arguments);return p.length<4||p[3]===1?"rgb("+Math.round(p[0])+", "+Math.round(p[1])+", "+Math.round(p[2])+")":"rgba("+Math.round(p[0])+", "+Math.round(p[1])+", "+Math.round(p[2])+", "+p[3]+")"},y.to.rgb.percent=function(){var p=z(arguments),S=Math.round(p[0]/255*100),P=Math.round(p[1]/255*100),E=Math.round(p[2]/255*100);return p.length<4||p[3]===1?"rgb("+S+"%, "+P+"%, "+E+"%)":"rgba("+S+"%, "+P+"%, "+E+"%, "+p[3]+")"},y.to.hsl=function(){var p=z(arguments);return p.length<4||p[3]===1?"hsl("+p[0]+", "+p[1]+"%, "+p[2]+"%)":"hsla("+p[0]+", "+p[1]+"%, "+p[2]+"%, "+p[3]+")"},y.to.hwb=function(){var p=z(arguments),S="";return p.length>=4&&p[3]!==1&&(S=", "+p[3]),"hwb("+p[0]+", "+p[1]+"%, "+p[2]+"%"+S+")"},y.to.keyword=function(p){return dt[p.slice(0,3)]};function C(p,S,P){return Math.min(Math.max(S,p),P)}function w(p){var S=Math.round(p).toString(16).toUpperCase();return S.length<2?"0"+S:S}}),872:((k,it,N)=>{"use strict";var q=N(195),z=Array.prototype.concat,O=Array.prototype.slice,dt=k.exports=function(y){for(var C=[],w=0,p=y.length;w<p;w++){var S=y[w];q(S)?C=z.call(C,O.call(S)):C.push(S)}return C};dt.wrap=function(b){return function(){return b(dt(arguments))}}})},_n={};function xt(k){var it=_n[k];if(it!==void 0)return it.exports;var N=_n[k]={exports:{}};return ba[k](N,N.exports,xt),N.exports}xt.n=k=>{var it=k&&k.__esModule?()=>k.default:()=>k;return xt.d(it,{a:it}),it},xt.d=(k,it)=>{for(var N in it)xt.o(it,N)&&!xt.o(k,N)&&Object.defineProperty(k,N,{enumerable:!0,get:it[N]})},xt.o=(k,it)=>Object.prototype.hasOwnProperty.call(k,it),xt.r=k=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(k,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(k,"__esModule",{value:!0})};var Ps={};(()=>{"use strict";xt.r(Ps),xt.d(Ps,{Chart:()=>ua,createChart:()=>lm,generateCandlesData:()=>am});function k(n){return typeof n=="function"}function it(n){return k(n==null?void 0:n.lift)}function N(n){return function(t){if(it(t))return t.lift(function(e){try{return n(e,this)}catch(s){this.error(s)}});throw new TypeError("Unable to lift unknown Observable type")}}var q=function(n,t){return q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,s){e.__proto__=s}||function(e,s){for(var i in s)Object.prototype.hasOwnProperty.call(s,i)&&(e[i]=s[i])},q(n,t)};function z(n,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");q(n,t);function e(){this.constructor=n}n.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var O=function(){return O=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++){e=arguments[s];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},O.apply(this,arguments)};function dt(n,t){var e={};for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&t.indexOf(s)<0&&(e[s]=n[s]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,s=Object.getOwnPropertySymbols(n);i<s.length;i++)t.indexOf(s[i])<0&&Object.prototype.propertyIsEnumerable.call(n,s[i])&&(e[s[i]]=n[s[i]]);return e}function b(n,t,e,s){var i=arguments.length,r=i<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(n,t,e,s);else for(var a=n.length-1;a>=0;a--)(o=n[a])&&(r=(i<3?o(r):i>3?o(t,e,r):o(t,e))||r);return i>3&&r&&Object.defineProperty(t,e,r),r}function y(n,t){return function(e,s){t(e,s,n)}}function C(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)}function w(n,t,e,s){function i(r){return r instanceof e?r:new e(function(o){o(r)})}return new(e||(e=Promise))(function(r,o){function a(h){try{c(s.next(h))}catch(d){o(d)}}function l(h){try{c(s.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):i(h.value).then(a,l)}c((s=s.apply(n,t||[])).next())})}function p(n,t){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},s,i,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(s=1,i&&(r=c[0]&2?i.return:c[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,c[1])).done)return r;switch(i=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return e.label++,{value:c[1],done:!1};case 5:e.label++,i=c[1],c=[0];continue;case 7:c=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){e=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){e.label=c[1];break}if(c[0]===6&&e.label<r[1]){e.label=r[1],r=c;break}if(r&&e.label<r[2]){e.label=r[2],e.ops.push(c);break}r[2]&&e.ops.pop(),e.trys.pop();continue}c=t.call(n,e)}catch(h){c=[6,h],i=0}finally{s=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var S=Object.create?(function(n,t,e,s){s===void 0&&(s=e);var i=Object.getOwnPropertyDescriptor(t,e);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,s,i)}):(function(n,t,e,s){s===void 0&&(s=e),n[s]=t[e]});function P(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&S(t,n,e)}function E(n){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&n[t],s=0;if(e)return e.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&s>=n.length&&(n=void 0),{value:n&&n[s++],done:!n}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(n,t){var e=typeof Symbol=="function"&&n[Symbol.iterator];if(!e)return n;var s=e.call(n),i,r=[],o;try{for(;(t===void 0||t-- >0)&&!(i=s.next()).done;)r.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(e=s.return)&&e.call(s)}finally{if(o)throw o.error}}return r}function M(){for(var n=[],t=0;t<arguments.length;t++)n=n.concat(v(arguments[t]));return n}function I(){for(var n=0,t=0,e=arguments.length;t<e;t++)n+=arguments[t].length;for(var s=Array(n),i=0,t=0;t<e;t++)for(var r=arguments[t],o=0,a=r.length;o<a;o++,i++)s[i]=r[o];return s}function D(n,t,e){if(e||arguments.length===2)for(var s=0,i=t.length,r;s<i;s++)(r||!(s in t))&&(r||(r=Array.prototype.slice.call(t,0,s)),r[s]=t[s]);return n.concat(r||Array.prototype.slice.call(t))}function H(n){return this instanceof H?(this.v=n,this):new H(n)}function lt(n,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=e.apply(n,t||[]),i,r=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(u){s[u]&&(i[u]=function(f){return new Promise(function(g,m){r.push([u,f,g,m])>1||a(u,f)})})}function a(u,f){try{l(s[u](f))}catch(g){d(r[0][3],g)}}function l(u){u.value instanceof H?Promise.resolve(u.value.v).then(c,h):d(r[0][2],u)}function c(u){a("next",u)}function h(u){a("throw",u)}function d(u,f){u(f),r.shift(),r.length&&a(r[0][0],r[0][1])}}function Dt(n){var t,e;return t={},s("next"),s("throw",function(i){throw i}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(i,r){t[i]=n[i]?function(o){return(e=!e)?{value:H(n[i](o)),done:i==="return"}:r?r(o):o}:r}}function Ht(n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=n[Symbol.asyncIterator],e;return t?t.call(n):(n=typeof E=="function"?E(n):n[Symbol.iterator](),e={},s("next"),s("throw"),s("return"),e[Symbol.asyncIterator]=function(){return this},e);function s(r){e[r]=n[r]&&function(o){return new Promise(function(a,l){o=n[r](o),i(a,l,o.done,o.value)})}}function i(r,o,a,l){Promise.resolve(l).then(function(c){r({value:c,done:a})},o)}}function Ne(n,t){return Object.defineProperty?Object.defineProperty(n,"raw",{value:t}):n.raw=t,n}var Ca=Object.create?(function(n,t){Object.defineProperty(n,"default",{enumerable:!0,value:t})}):function(n,t){n.default=t};function hm(n){if(n&&n.__esModule)return n;var t={};if(n!=null)for(var e in n)e!=="default"&&Object.prototype.hasOwnProperty.call(n,e)&&S(t,n,e);return Ca(t,n),t}function dm(n){return n&&n.__esModule?n:{default:n}}function um(n,t,e,s){if(e==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?n!==t||!s:!t.has(n))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?s:e==="a"?s.call(n):s?s.value:t.get(n)}function fm(n,t,e,s,i){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?n!==t||!i:!t.has(n))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?i.call(n,e):i?i.value=e:t.set(n,e),e}function gm(n,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof n=="function"?t===n:n.has(t)}function Pn(n){var t=function(s){Error.call(s),s.stack=new Error().stack},e=n(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var Ts=Pn(function(n){return function(e){n(this),this.message=e?e.length+` errors occurred during unsubscription:
7
7
  `+e.map(function(s,i){return i+1+") "+s.toString()}).join(`
8
- `):"",this.name="UnsubscriptionError",this.errors=e}});function Xe(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var he=(function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,s,i,r;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=E(o),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(v){t={error:v}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(k(h))try{h()}catch(v){r=v instanceof Ts?v.errors:[v]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=E(d),f=u.next();!f.done;f=u.next()){var p=f.value;try{An(p)}catch(v){r=r!=null?r:[],v instanceof Ts?r=D(D([],m(r)),m(v.errors)):r.push(v)}}}catch(v){s={error:v}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(s)throw s.error}}}if(r)throw new Ts(r)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)An(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Xe(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&Xe(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=(function(){var t=new n;return t.closed=!0,t})(),n})(),Tn=he.EMPTY;function Mn(n){return n instanceof he||n&&"closed"in n&&k(n.remove)&&k(n.add)&&k(n.unsubscribe)}function An(n){k(n)?n():n.unsubscribe()}var Jt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},We={setTimeout:function(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];var i=We.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,D([n,t],m(e))):setTimeout.apply(void 0,D([n,t],m(e)))},clearTimeout:function(n){var t=We.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function En(n){We.setTimeout(function(){var t=Jt.onUnhandledError;if(t)t(n);else throw n})}function In(){}var ya=(function(){return Ms("C",void 0,void 0)})();function wa(n){return Ms("E",void 0,n)}function Sa(n){return Ms("N",n,void 0)}function Ms(n,t,e){return{kind:n,value:t,error:e}}var Qt=null;function ze(n){if(Jt.useDeprecatedSynchronousErrorHandling){var t=!Qt;if(t&&(Qt={errorThrown:!1,error:null}),n(),t){var e=Qt,s=e.errorThrown,i=e.error;if(Qt=null,s)throw i}}else n()}function xa(n){Jt.useDeprecatedSynchronousErrorHandling&&Qt&&(Qt.errorThrown=!0,Qt.error=n)}var As=(function(n){z(t,n);function t(e){var s=n.call(this)||this;return s.isStopped=!1,e?(s.destination=e,Mn(e)&&e.add(s)):s.destination=Ma,s}return t.create=function(e,s,i){return new xe(e,s,i)},t.prototype.next=function(e){this.isStopped?Is(Sa(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?Is(wa(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?Is(ya,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(he),_a=Function.prototype.bind;function Es(n,t){return _a.call(n,t)}var Pa=(function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(s){Ve(s)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(s){Ve(s)}else Ve(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){Ve(e)}},n})(),xe=(function(n){z(t,n);function t(e,s,i){var r=n.call(this)||this,o;if(k(e)||!e)o={next:e!=null?e:void 0,error:s!=null?s:void 0,complete:i!=null?i:void 0};else{var a;r&&Jt.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&Es(e.next,a),error:e.error&&Es(e.error,a),complete:e.complete&&Es(e.complete,a)}):o=e}return r.destination=new Pa(o),r}return t})(As);function Ve(n){Jt.useDeprecatedSynchronousErrorHandling?xa(n):En(n)}function Ta(n){throw n}function Is(n,t){var e=Jt.onStoppedNotification;e&&We.setTimeout(function(){return e(n,t)})}var Ma={closed:!0,next:In,error:Ta,complete:In};function bt(n,t,e,s,i){return new Aa(n,t,e,s,i)}var Aa=(function(n){z(t,n);function t(e,s,i,r,o,a){var l=n.call(this,e)||this;return l.onFinalize=o,l.shouldUnsubscribe=a,l._next=s?function(c){try{s(c)}catch(h){e.error(h)}}:n.prototype._next,l._error=r?function(c){try{r(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,l._complete=i?function(){try{i()}catch(c){e.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,l}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;n.prototype.unsubscribe.call(this),!s&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(As);function ct(n,t){return N(function(e,s){var i=0;e.subscribe(bt(s,function(r){s.next(n.call(t,r,i++))}))})}var Ds=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function Dn(n){return k(n==null?void 0:n.then)}var Ls=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function de(n){return n}function pm(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return Ln(n)}function Ln(n){return n.length===0?de:n.length===1?n[0]:function(e){return n.reduce(function(s,i){return i(s)},e)}}var gt=(function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,s){var i=this,r=Ia(t)?t:new xe(t,e,s);return ze(function(){var o=i,a=o.operator,l=o.source;r.add(a?a.call(r,l):l?i._subscribe(r):i._trySubscribe(r))}),r},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var s=this;return e=On(e),new e(function(i,r){var o=new xe({next:function(a){try{t(a)}catch(l){r(l),o.unsubscribe()}},error:r,complete:i});s.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[Ls]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ln(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=On(t),new t(function(s,i){var r;e.subscribe(function(o){return r=o},function(o){return i(o)},function(){return s(r)})})},n.create=function(t){return new n(t)},n})();function On(n){var t;return(t=n!=null?n:Jt.Promise)!==null&&t!==void 0?t:Promise}function Ea(n){return n&&k(n.next)&&k(n.error)&&k(n.complete)}function Ia(n){return n&&n instanceof As||Ea(n)&&Mn(n)}function Bn(n){return k(n[Ls])}function Rn(n){return Symbol.asyncIterator&&k(n==null?void 0:n[Symbol.asyncIterator])}function Fn(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Da(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Hn=Da();function kn(n){return k(n==null?void 0:n[Hn])}function Yn(n){return lt(this,arguments,function(){var e,s,i,r;return g(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,H(e.read())];case 3:return s=o.sent(),i=s.value,r=s.done,r?[4,H(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,H(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function jn(n){return k(n==null?void 0:n.getReader)}function At(n){if(n instanceof gt)return n;if(n!=null){if(Bn(n))return La(n);if(Ds(n))return Oa(n);if(Dn(n))return Ba(n);if(Rn(n))return Nn(n);if(kn(n))return Ra(n);if(jn(n))return Fa(n)}throw Fn(n)}function La(n){return new gt(function(t){var e=n[Ls]();if(k(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Oa(n){return new gt(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function Ba(n){return new gt(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,En)})}function Ra(n){return new gt(function(t){var e,s;try{for(var i=E(n),r=i.next();!r.done;r=i.next()){var o=r.value;if(t.next(o),t.closed)return}}catch(a){e={error:a}}finally{try{r&&!r.done&&(s=i.return)&&s.call(i)}finally{if(e)throw e.error}}t.complete()})}function Nn(n){return new gt(function(t){Ha(n,t).catch(function(e){return t.error(e)})})}function Fa(n){return Nn(Yn(n))}function Ha(n,t){var e,s,i,r;return w(this,void 0,void 0,function(){var o,a;return g(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Ht(n),l.label=1;case 1:return[4,e.next()];case 2:if(s=l.sent(),!!s.done)return[3,4];if(o=s.value,t.next(o),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),i={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),s&&!s.done&&(r=e.return)?[4,r.call(e)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function kt(n,t,e,s,i){s===void 0&&(s=0),i===void 0&&(i=!1);var r=t.schedule(function(){e(),i?n.add(this.schedule(null,s)):this.unsubscribe()},s);if(n.add(r),!i)return r}function ka(n,t,e,s,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},f=function(v){return c<s?p(v):l.push(v)},p=function(v){r&&t.next(v),c++;var x=!1;At(e(v,h++)).subscribe(bt(t,function(_){i==null||i(_),r?f(_):t.next(_)},function(){x=!0},void 0,function(){if(x)try{c--;for(var _=function(){var A=l.shift();o?kt(t,o,function(){return p(A)}):p(A)};l.length&&c<s;)_();u()}catch(A){t.error(A)}}))};return n.subscribe(bt(t,f,function(){d=!0,u()})),function(){a==null||a()}}function Os(n,t,e){return e===void 0&&(e=1/0),k(t)?Os(function(s,i){return ct(function(r,o){return t(s,r,i,o)})(At(n(s,i)))},e):(typeof t=="number"&&(e=t),N(function(s,i){return ka(s,i,n,e)}))}function Xn(n){return n===void 0&&(n=1/0),Os(de,n)}var Wn=new gt(function(n){return n.complete()});function mm(n){return n?Ya(n):Wn}function Ya(n){return new Observable(function(t){return n.schedule(function(){return t.complete()})})}function zn(n){return n&&k(n.schedule)}function Bs(n){return n[n.length-1]}function ja(n){return k(Bs(n))?n.pop():void 0}function Ue(n){return zn(Bs(n))?n.pop():void 0}function Na(n,t){return typeof Bs(n)=="number"?n.pop():t}function Vn(n,t){return t===void 0&&(t=0),N(function(e,s){e.subscribe(bt(s,function(i){return kt(s,n,function(){return s.next(i)},t)},function(){return kt(s,n,function(){return s.complete()},t)},function(i){return kt(s,n,function(){return s.error(i)},t)}))})}function Un(n,t){return t===void 0&&(t=0),N(function(e,s){s.add(n.schedule(function(){return e.subscribe(s)},t))})}function Xa(n,t){return At(n).pipe(Un(t),Vn(t))}function Wa(n,t){return At(n).pipe(Un(t),Vn(t))}function za(n,t){return new gt(function(e){var s=0;return t.schedule(function(){s===n.length?e.complete():(e.next(n[s++]),e.closed||this.schedule())})})}function Va(n,t){return new gt(function(e){var s;return kt(e,t,function(){s=n[Hn](),kt(e,t,function(){var i,r,o;try{i=s.next(),r=i.value,o=i.done}catch(a){e.error(a);return}o?e.complete():e.next(r)},0,!0)}),function(){return k(s==null?void 0:s.return)&&s.return()}})}function Gn(n,t){if(!n)throw new Error("Iterable cannot be null");return new gt(function(e){kt(e,t,function(){var s=n[Symbol.asyncIterator]();kt(e,t,function(){s.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function Ua(n,t){return Gn(Yn(n),t)}function Ga(n,t){if(n!=null){if(Bn(n))return Xa(n,t);if(Ds(n))return za(n,t);if(Dn(n))return Wa(n,t);if(Rn(n))return Gn(n,t);if(kn(n))return Va(n,t);if(jn(n))return Ua(n,t)}throw Fn(n)}function Ge(n,t){return t?Ga(n,t):At(n)}function Ct(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=Na(n,1/0),i=n;return i.length?i.length===1?At(i[0]):Xn(s)(Ge(i,e)):Wn}var Za=Pn(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),R=(function(n){z(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var s=new Zn(this,this);return s.operator=e,s},t.prototype._throwIfClosed=function(){if(this.closed)throw new Za},t.prototype.next=function(e){var s=this;ze(function(){var i,r;if(s._throwIfClosed(),!s.isStopped){s.currentObservers||(s.currentObservers=Array.from(s.observers));try{for(var o=E(s.currentObservers),a=o.next();!a.done;a=o.next()){var l=a.value;l.next(e)}}catch(c){i={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var s=this;ze(function(){if(s._throwIfClosed(),!s.isStopped){s.hasError=s.isStopped=!0,s.thrownError=e;for(var i=s.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;ze(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var s=e.observers;s.length;)s.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var s=this,i=this,r=i.hasError,o=i.isStopped,a=i.observers;return r||o?Tn:(this.currentObservers=null,a.push(e),new he(function(){s.currentObservers=null,Xe(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var s=this,i=s.hasError,r=s.thrownError,o=s.isStopped;i?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new gt;return e.source=this,e},t.create=function(e,s){return new Zn(e,s)},t})(gt),Zn=(function(n){z(t,n);function t(e,s){var i=n.call(this)||this;return i.destination=e,i.source=s,i}return t.prototype.next=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.next)===null||i===void 0||i.call(s,e)},t.prototype.error=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.error)===null||i===void 0||i.call(s,e)},t.prototype.complete=function(){var e,s;(s=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||s===void 0||s.call(e)},t.prototype._subscribe=function(e){var s,i;return(i=(s=this.source)===null||s===void 0?void 0:s.subscribe(e))!==null&&i!==void 0?i:Tn},t})(R),ut=(function(n){z(t,n);function t(e){var s=n.call(this)||this;return s._value=e,s}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var s=n.prototype._subscribe.call(this,e);return!s.closed&&e.next(this._value),s},t.prototype.getValue=function(){var e=this,s=e.hasError,i=e.thrownError,r=e._value;if(s)throw i;return this._throwIfClosed(),r},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t})(R);let Rs=!1,Fs=0;const Ze=new Map,$e=new Map,$n=()=>{Rs||(Rs=!0,Fs=requestAnimationFrame(()=>{$e.forEach((n,t)=>{n(),$e.delete(t)}),Ze.forEach((n,t)=>{n(),Ze.delete(t)}),Rs=!1}))},Kn=(n,t)=>{Ze.set(n,t),$n()},$a=n=>{Ze.delete(n)},Ka=n=>{$e.delete(n)},_e=(n,t)=>{$e.set(n,t),$n()};function yt(){const n=()=>Math.random().toString(16).slice(-4);return`${n()+n()}-${n()}-${n()}-${n()}-${n()+n()+n()}`}const qn="\u2212",qa="-";var Ja=Math.pow;const Ke=14,qe=[];for(let n=0;n<Ke+1;n++)qe.push(Ja(10,n));const Hs=5e-13;class ft{static roundToNearest(t,e){return isFinite(t)?ft.isZero(t)?0:(t>0?t+=Hs:t<0&&(t-=Hs),ft.roundDecimal(Math.round(ft.roundDecimal(t/e))*e)):t}static roundUpToNearest(t,e){return ft.roundDecimal(Math.ceil(t/e))*e}static roundDecimal(t){if(isNaN(t)||t===Math.floor(t))return t;const e=Math.sign(t),s=Math.abs(t),i=Math.min(Ke,Ke-1-Math.floor(Math.log10(s)));for(let r=i;r>=0;r--){const o=Math.floor(qe[r]*s+.5);if(o<qe[Ke])return e*o/qe[r]}return Math.round(t)}static makeDecimal(t,e,s,i){if(!isFinite(t))return"";if(isFinite(t)){let r=t.toFixed(e);if(!i)return s?r.replace(".",s):r;if(s===i)throw new Error("Grouping symbol cannot be the same as decimal separator.");const o=r.split(".");let a=o[0];const l=o[1];return Math.abs(t)>=1e3&&(a=a.replace(RegExp("\\d(?=(\\d{3})+$)","g"),`$&${i}`)),l?(r=[a,l].join(s),r):a}return""}static compare(t,e,s){return t>e+s?1:t<e-s?-1:(isNaN(t)?1:0)-(isNaN(e)?1:0)}static isZero(t){return ft.compare(t,0,Hs)===0}static cutNumber(t,e,s=0){return{K:r=>r/1e3,M:r=>r/1e6}[e](t).toFixed(s)+e}static isExponential(t){return/\de(\-|\+)\d/.test(t.toString())}}function Qa(n,t,e){const s=n/t;return s>=e||s<=1/e}function ks(n,t,e){return Math.max(t,Math.min(n,e))}function tl(n){return 1-(Math.pow(2,-10*n)-.0009765625)*1.0009775171065494}function Pe(...n){for(const t of n)if(t!==void 0&&isFinite(t))return t;return NaN}const ot=n=>~~n,el=n=>~~(n+1),Te=n=>~~(n+.5),sl=(n,t)=>n>>t;function vm(n){if(!Number.isFinite(n))throw new Error("Input must be a finite number.");const t=n.toString();return t.includes(".")?t.split(".")[1].length:0}const Je=n=>n.replace(qa,qn);class Ys{constructor(t,e){this.animationTimeLeft=0,this.onTickFunction=e,this.animationTime=t.duration,this.animationStartTime=Date.now(),this.animationInProgress=!0}tick(){var t;Date.now()>this.animationStartTime+this.animationTime&&(this.animationInProgress=!1),(t=this.onTickFunction)==null||t.call(this)}getProgress(){return Math.min((Date.now()-this.animationStartTime)/this.animationTime,1)}finishAnimation(){this.animationInProgress=!1,this.animationStartTime=0}}var nl=xt(520),Lt=xt.n(nl);class Jn extends Ys{constructor(t,e,s=()=>{}){super(t,s),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=Lt().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.colorConfigs.forEach(t=>{if(t.initialAlpha===void 0||t.rgbColor===void 0)return;const e=t.initialAlpha*(t.type==="fading"?1-this.getProgress():this.getProgress());t.currentAnimationColor=t.rgbColor.alpha(e)})}getColor(t){var e,s;return(s=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?s:"#FFFFFF"}revert(){const t=ks(Date.now()-this.animationStartTime,0,this.animationTime);this.animationStartTime=Date.now()-this.animationTime+t,this.colorConfigs.forEach(e=>{e.type=e.type==="fading"?"appearing":"fading"})}}class Qn extends Ys{constructor(t,e,s=()=>{}){super(t,s),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=Lt().rgb(i.startColor),i.rgbEndColor=Lt().rgb(i.endColor),i.currentAnimationColor=i.type==="appearing"?i.rgbStartColor:i.rgbEndColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{const e=1-this.animationTimeLeft/this.animationTime;!t.rgbStartColor||!t.rgbEndColor||(t.type==="fading"?t.currentAnimationColor=this.calculateTransitionColor(t.rgbEndColor,t.rgbStartColor,e):t.type==="appearing"&&(t.currentAnimationColor=this.calculateTransitionColor(t.rgbStartColor,t.rgbEndColor,e)))})}getColor(t){var e,s;return(s=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?s:"#FFFFFF"}revert(){this.animationTimeLeft=Math.max(this.animationTime-this.animationTimeLeft,1),this.colorConfigs.forEach(t=>{t.type==="fading"?t.type="appearing":t.type="fading"})}moveToLastTick(){this.animationTimeLeft=1}calculateTransitionColor(t,e,s){const i=t.red()-(t.red()-e.red())*s,r=t.green()-(t.green()-e.green())*s,o=t.blue()-(t.blue()-e.blue())*s;return Lt().rgb(i,r,o)}}class ti extends Ys{constructor(t,e,s){var i;super(e,s),this.viewportModel=t,this.animationConfig=e,this.id=yt(),this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.easingFn=(i=e.easingFn)!=null?i:tl}tick(){if(super.tick(),this.animationInProgress){const t=this.easingFn(this.getProgress()),e=this.xStart+(this.animationConfig.targetXStart-this.xStart)*t,s=this.xEnd+(this.animationConfig.targetXEnd-this.xEnd)*t,i=this.yStart+(this.animationConfig.targetYStart-this.yStart)*t,r=this.yEnd+(this.animationConfig.targetYEnd-this.yEnd)*t,o=this.zoomX+(this.animationConfig.targetZoomX-this.zoomX)*t,a=this.zoomY+(this.animationConfig.targetZoomY-this.zoomY)*t;this.viewportModel.apply({xStart:e,xEnd:s,yStart:i,yEnd:r,zoomX:o,zoomY:a,inverseY:this.viewportModel.inverseY})}}finishAnimation(){super.finishAnimation(),this.viewportModel.apply({xStart:this.animationConfig.targetXStart,xEnd:this.animationConfig.targetXEnd,yStart:this.animationConfig.targetYStart,yEnd:this.animationConfig.targetYEnd,zoomX:this.animationConfig.targetZoomX,zoomY:this.animationConfig.targetZoomY,inverseY:this.viewportModel.inverseY})}}const Me=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),il=!!window.chrome,ei=typeof InstallTrigger!="undefined",rl=navigator.platform.indexOf("Win")>-1,bm=n=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:s}=n;if(e||s){let i;if(Me)i=e===n.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(n.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(n.deltaY)*3);else if(il){if(i=e+Math.sign(e)===n.deltaY*-3?e+Math.sign(e)===n.deltaY*-3:e===n.deltaY*-3,rl){const r=Math.round(n.deltaY)===e||Math.abs(Math.round(n.deltaY)+Math.sign(n.deltaY))===Math.abs(e)||Math.abs(Math.round(n.deltaY)-Math.sign(n.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(n.deltaY)||r}}else ei?Math.abs(n.deltaY)>Math.abs(n.deltaX)?i=!1:i=s===n.deltaX*-3:i=e===n.deltaY*-3;i&&(t=!0)}else n.deltaMode===0&&(t=!0);return ei&&n.deltaY>=16&&Math.abs(n.deltaY)%16===0&&(t=!1),n.ctrlKey&&(t=!0),t},ol=(n,t)=>n==="percent"?t/4:t;var al=Object.defineProperty,ll=Object.defineProperties,cl=Object.getOwnPropertyDescriptors,si=Object.getOwnPropertySymbols,hl=Object.prototype.hasOwnProperty,dl=Object.prototype.propertyIsEnumerable,ni=(n,t,e)=>t in n?al(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ul=(n,t)=>{for(var e in t||(t={}))hl.call(t,e)&&ni(n,e,t[e]);if(si)for(var e of si(t))dl.call(t,e)&&ni(n,e,t[e]);return n},fl=(n,t)=>ll(n,cl(t));const Ae=Me?150:400,ue="VIEWPORT_ANIMATION";class ii{constructor(t){this.animations={},this.animationInProgressSubject=new ut(!1),this.animFrameId=`canvas_animation_${yt()}`,this.eventBus=t}startViewportMovementAnimation(t,e,s=ue,i){const r=new ti(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new Jn(fl(ul({},i),{duration:i&&i.duration||Ae}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ae,i){const r=new Qn({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0)}processAnimation(){_e(this.animFrameId,()=>this.tick())}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():queueMicrotask(()=>{this.processAnimation(),this.eventBus.fireDraw()})}stopInterval(){$a(this.animFrameId)}}function _t(n,t){return t===void 0&&(t=de),n=n!=null?n:gl,N(function(e,s){var i,r=!0;e.subscribe(bt(s,function(o){var a=t(o);(r||!n(i,a))&&(r=!1,i=a,s.next(o))}))})}function gl(n,t){return n===t}function pl(n){return function(){n.forEach(e=>typeof e=="function"&&e()),n.length=0}}function js(n){return n}function ri(n){return n!=null}const Cm=()=>{};function ym(n){return n!=null}function ml(n,t,e=vl,s=!0){const i=n.filter(r=>t.some(o=>e(r,o)));return s?i.filter((r,o,a)=>a.indexOf(r)===o):i}const oi=(n,t)=>{const e=t.slice().filter(s=>n.find(i=>i===s));return n.map(s=>{var i;return t.indexOf(s)>=0&&(i=e.shift())!=null?i:s})},vl=(n,t)=>n===t,wm=(n,t,e)=>n.filter(s=>t.filter(i=>e(s,i)).length===0),bl=(n,t)=>n===t,ai=(n,t,e=bl)=>n.length===t.length&&n.every((s,i)=>e(s,t[i]));function Sm(n,t,e){const s=n.slice(),i=s[t];return s.splice(t,1),s.splice(e,0,i),s}function Ns(n,t,e){const s=n.length,i=ks(t,0,s-1),r=ks(e,0,s-1),o=n[i];return n.splice(i,1),n.splice(r,0,o),n}function xm(n,t,e){const s=n.slice(),i=s.findIndex(t);return i!==-1&&(s.splice(i,1),s.splice(i,0,e)),s}const _m=n=>{const t={};return n.filter(e=>t[e]?!1:t[e]=!0)},Pm=(n,t)=>n.reduce((e,s)=>((e[s[t]]=e[s[t]]||[]).push(s),e),{}),Tm=(n,t)=>[].concat(...n.map(e=>[e,t])).slice(0,-1),Mm=n=>Array.isArray(n[0]),li=n=>Array.isArray(n[0])?n:[n],Cl=(n,t,e)=>{const s=[];let i=0;for(const r of n){const o=Math.max(t-i,0),a=Math.max(e-i,-1),l=r.slice(o,a+1);l.length>0&&s.push(l),i+=r.length}return s},yl=(n,t)=>n>=0?t[n]:t[t.length+n],pt=n=>Array.prototype.flat?n.flat():Ee(n,js),Ee=(n,t)=>{if(Array.prototype.flatMap)return n.flatMap(t);const e=[];for(let s=0;s<n.length;s++){const i=n[s];e.push(...t(i,s,n))}return e};function Yt(n,t,e){const s=e!=null?e:js;return!n.length||t!==t?{index:-1,exact:!0}:Xs(n,t,0,n.length,s)}function Xs(n,t,e,s,i){const r=sl(e+s,1),o=i(n[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Xs(n,t,e,r,i):Xs(n,t,r,s,i)}function wt(n){if(n&&n.length)return n[n.length-1]}function wl(n){const t=this.indexOf(n);return t!==-1&&this.splice(t,1),this}function Sl(n,t){if(!n)return;const e=n.indexOf(t);e!==-1&&n.splice(e,1)}function fe(n){if(n)return n[0]}function xl(n){function t(e,s){const i=n(s);return i==null||!isFinite(i)?e:[Math.max(e[0],i),Math.min(e[1],i)]}return function(e){const s=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY];return e?e.reduce(t,s):s}}function _l(n,t,e,s=()=>0){const i=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);s(o[h])<=a?l=h+1:c=h-1}return c},r=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);s(o[h])>=a?c=h-1:l=h+1}return l};return n.slice(r(n,t),i(n,e)+1)}let Ws,ci;const jt=()=>{if(typeof navigator=="undefined")return!1;const n=navigator.userAgent;return(ci!==n||Ws===void 0)&&(ci=n,Ws=!!n.match(/Android|iPhone|Opera Mini/)),Ws},Pl=1.33,hi=4.5;function di(n,t){let e="";t.textStyle&&(t.textStyle.italic&&(e+="italic "),t.textStyle.bold&&(e+="bold ")),n.font=e+(t.textSize||12)+" "+(t.textFontFamily||"monospace"),n.fillStyle=t.textFill||"#FFFFFF",t.rtl?n.textAlign="right":n.textAlign="start"}function Qe(n,t=!0){const e=n.font.match(/(\d+.)?\d+(px|pt)/gi);let s="10px";return e&&e.length&&(e[0].includes("pt")?s=+e[0].slice(0,e[0].indexOf("pt"))*96/72+"px":s=e[0]),t?parseInt(s,10)*Pl:parseInt(s,10)}function ui(n,t,e){n.save(),di(n,e);const s=Math.ceil(Math.max.apply(Math,t.map(o=>n.measureText(o).width))),i=Qe(n),r=i*t.length;return n.restore(),[s,r,i]}function fi(n){return(n||"").split(/\r\n|\r|\n/)}function Tl(n,t,e,s,i){n.save();const[r,,o]=ui(n,t,i);t.forEach((a,l)=>{var c,h,d;const u=n.measureText(a).width,f=Ml(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&Al(n,a,f,s+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),n.fillText(a,f,s+o*l)}),n.restore()}function Ml(n,t,e,s){switch(s){case"left":return n;case"right":return n+t-e;default:return n}}function Al(n,t,e,s,i,r){n.save();const o=n.measureText(t).width,a=e,l=e+o,c=s+2,h=c;let d=parseInt(r,10)/15;d<1&&(d=1),n.beginPath(),n.strokeStyle=i,n.lineWidth=d,n.moveTo(a,c),n.lineTo(l,h),n.stroke(),n.restore()}function Am(n){return`${n}px`}function gi(n){const t=Lt().rgb(n).array(),[e,s,i]=t.map(r=>{const o=r/255;return o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4)});return .2126*e+.7152*s+.0722*i}function pi(n,t){const e=gi(n),s=gi(t),i=Math.max(e,s),r=Math.min(e,s);return(i+.05)/(r+.05)}function te(n,t,e){const s=pi(n,t),i=pi(n,e),r=s>=hi,o=i>=hi;return r&&!o?t:o&&!r?e:s>=i?t:e}function El(n,t,e,s){const i=s.components.navigationMap.timeLabels,r=i.padding,o=mi(t,i.dateFormat,e),a=fi(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=ui(n,a,l);return[c+r.x*2,h+r.y*2]}function mi(n,t,e){return e(t)(n).split(" ").join(`
9
- `)}const vi={};function Nt(n,t){let e=vi[n];return e!==void 0||(t.save(),t.font=n,e=t.measureText("M").width,vi[n]=e,t.restore()),e}const bi=new Map;function Pt(n,t,e){const s=e+n;let i=bi.get(s);return i||(t.save(),t.font=e,i=t.measureText(n).width,bi.set(s,i),t.restore()),i}function Tt(n,t,e=Ci){function s(i,r){for(const o in r)o in i?typeof i[o]=="object"&&i[o]!==null&&!Array.isArray(i[o])?s(i[o],r[o]):e!=null&&e.overrideExisting&&(i[o]=r[o]):e!=null&&e.addIfMissing&&(i[o]=r[o]);return i}return s(n,t)}function Em(n,t,e,s=!1){!n||!t||t.length===0||t.forEach(i=>{const r=e(i),o=n.findIndex(a=>e(a)===r);o===-1?n.push(i):s?Tt(n[o],i,{overrideExisting:!0,addIfMissing:!0}):n.splice(o,1,i)})}const Ci={overrideExisting:!1,addIfMissing:!0};function Il(n){let t=0;if(n.length===0)return t;for(let e=0;e<n.length;e++){const s=n.charCodeAt(e);t=(t<<5)-t+s,t|=0}return t}const zs=1,Dl=n=>n.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),yi=(n,t)=>`${n}_${Il(t.toString())}`;function ts(n,t){return t===n?"none":t>n?"up":"down"}function Ll(n,t){return t>n?"up":"down"}function Ol(n,t,e=!1){const{id:s,expansion:i,impVolatility:r,vwap:o,typicalPrice:a,volume:l,timestamp:c}=n;let h=n.hi,d=n.lo,u=n.open;const f=n.close;e&&(h=f,d=f,u=f);let p=n.idx;return t!==void 0&&(p=t),{id:s,hi:h,lo:d,open:u,close:f,timestamp:c,volume:l,expansion:i,idx:p,impVolatility:r,vwap:o,typicalPrice:a}}var Bl=Object.defineProperty,wi=Object.getOwnPropertySymbols,Rl=Object.prototype.hasOwnProperty,Fl=Object.prototype.propertyIsEnumerable,Si=(n,t,e)=>t in n?Bl(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Hl=(n,t)=>{for(var e in t||(t={}))Rl.call(t,e)&&Si(n,e,t[e]);if(wi)for(var e of wi(t))Fl.call(t,e)&&Si(n,e,t[e]);return n};const xi="Open Sans Semibold, sans-serif",kl=null,Yl=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Im=n=>kl.find(t=>t===n)!==void 0,es=()=>({devexpertsPromoLink:!0,useUTCTimeOverride:!1,shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],rtl:!1,intlFormatter:{decimalSeparator:".",thousandsSeparator:""},scale:{keepZoomXOnYAxisChange:!0,auto:!0,zoomToCursor:!1,lockPriceToBarRatio:!1,autoScaleOnCandles:!0,autoScaleDisableOnDrag:{enabled:!0,edgeAngle:Math.PI/15,yDiff:80},inverse:!1,zoomSensitivity:{wheel:.25},defaultViewportItems:100,disableAnimations:!1},timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,components:{chart:{type:"candle",showCandlesBorder:!0,showActiveCandlesBorder:!0,showWicks:!0,candleLineWidth:1,lineWidth:1,areaLineWidth:1,barLineWidth:1,minWidth:.5,minCandles:10,candlePaddingPercent:.25,highlightActiveCandle:!0,cursor:"default",selectedWidth:3,minCandlesOffset:2,defaultZoomCandleWidth:7,zoomStep:0,histogram:{barCapSize:1},maxYAxisScalesAmount:10,applyBackgroundToAxes:{x:!0,y:!0},sortCandles:Dl},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:xi,cursor:"ns-resize",resizeDisabledCursor:"default",labelBoxMargin:{top:4,bottom:4,end:8,start:10},typeConfig:{badge:{rounded:!0,paddings:{top:4,bottom:4,end:4,start:4}},plain:{},rectangle:{rounded:!1,paddings:{top:4,bottom:4,end:4,start:4}}},labels:{descriptions:!1,settings:{lastPrice:{mode:"label",type:"badge"},countdownToBarClose:{mode:"none",type:"rectangle"}}},treasuryFormat:{enabled:!1}},xAxis:{visible:!0,formatsForLabelsConfig:{lessThanSecond:"HH:mm:ss",second_1:"HH:mm:ss",minute_1:"HH:mm",minute_5:"HH:mm",minute_30:"HH:mm",hour_1:"HH:mm",day_1:"dd.MM",month_1:"MMM",year_1:"YYYY"},fontSize:12,fontFamily:xi,cursor:"ew-resize",padding:{top:8,bottom:16},fontStyle:""},events:{visible:!1,eventsVisibility:{"conference-calls":!0,dividends:!0,splits:!0,earnings:!0},height:20,cursor:"default",xAxisLabelFormat:[{format:"d MMM"}],icons:{earnings:{normal:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" stroke="#D92C40" stroke-width="1.5"/></svg>',hover:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" fill="#D92C40" stroke="#D92C40" stroke-width="1.5"/></svg>'}}},offsets:{visible:!0,right:10,top:10,bottom:20,left:0},waterMark:{visible:!1,fontFamily:"Open Sans, sans-serif",firstRowFontSize:80,firstRowBottomPadding:10,secondRowFontSize:40,secondRowBottomPadding:25,thirdRowFontSize:40,thirdRowBottomPadding:15,position:"center",offsetX:20,offsetY:20,logoWidth:20,logoHeight:20},highLow:{visible:!1,font:"12px sans-serif",prefix:{high:"H: ",low:"L: "},lineDash:[2,4]},highlights:{visible:!1,fontFamily:"Open Sans",fontSize:13,border:{width:1,dash:[8,4]}},crossTool:{type:"cross-and-labels",discrete:!0,magnetTarget:"none",lineDash:[4,6],xAxisLabelFormat:[{format:"dd.MM.YYYY",showWhen:{periodMoreThen:1440*60*1e3}},{format:"dd.MM.YYYY HH:mm",showWhen:{periodLessThen:1440*60*1e3,periodMoreThen:6*1e3}},{format:"dd.MM.YYYY HH:mm:ss",showWhen:{periodLessThen:6*1e3}}],xLabel:{padding:{top:4,bottom:4,right:8,left:8},margin:{top:4}},yLabel:{padding:{top:4,bottom:4,end:4,start:4},type:"badge"}},grid:{visible:!0,horizontal:!1,vertical:!0,width:1,dash:[0,0],color:"#FFFFFF"},volumes:{visible:!0,showSeparately:!1,valueLines:15,barCapSize:1,volumeBarSpace:0,volumeFillColor:"#FFFFFF"},navigationMap:{visible:!1,allCandlesHistory:!0,timeLabels:{visible:!1,dateFormat:"dd.MM.YYYY HH:mm",fontFamily:"Open Sans",fontSize:13,padding:{x:10,y:1}},minSliderWindowWidth:10,cursors:{chart:"default",buttonLeft:"pointer",buttonRight:"pointer",leftResizer:"ew-resize",rightResizer:"ew-resize",slider:"grab"},knots:{height:35,width:7,border:0,lineWidth:1}},baseline:{cursor:"ns-resize",dragZone:3,height:1},paneResizer:{cursor:"ns-resize",height:1,visible:!0,fixedMode:!1,dragZone:3}},colors:{candleTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)",upWickColor:"rgba(77,153,83,1)",downWickColor:"rgba(217,44,64,1)",noneWickColor:"rgba(255,255,255,1)",borderOpacity:1},barTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)"},lineTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)"},chartAreaTheme:{backgroundMode:"regular",backgroundColor:"rgba(20,20,19,1)",backgroundGradientTopColor:"red",backgroundGradientBottomColor:"blue",gridColor:"rgba(37,37,36,1)"},scatterPlot:{mainColor:"rgba(255,255,255,1)"},areaTheme:{lineColor:"rgba(127,120,214,1)",startColor:"rgba(169,38,251,1)",stopColor:"rgba(169,38,251,0.8)"},baseLineTheme:{lowerSectionStrokeColor:"rgba(217,44,64,1)",upperSectionStrokeColor:"rgba(77,153,83,1)",lowerSectionFillColor:"rgba(217, 44, 64, 0.07)",upperSectionFillColor:"rgba(77, 153, 83, 0.07)",baselineColor:"rgba(55,55,54,1)"},histogram:{upCap:"rgba(77,153,83,1)",upBottom:"rgba(77,153,83,0.1)",upBright:"rgba(77,153,83,0.4)",downCap:"rgba(217,44,64,1)",downBottom:"rgba(217,44,64,0.1)",downBright:"rgba(217,44,64,0.4)",noneCap:"rgba(255,255,255,1)",noneBottom:"rgba(255,255,255,0.1)",noneBright:"rgba(255,255,255,0.4)"},crossTool:{lineColor:"rgba(107,96,86,1)",labelBoxColor:"rgba(107,96,86,1)",labelTextColor:"rgba(255,255,255,1)"},waterMarkTheme:{firstRowColor:"rgba(255,255,255,0.2)",secondRowColor:"rgba(255,255,255,0.2)",thirdRowColor:"rgba(255,255,255,0.2)"},highlights:{NO_TRADING:{border:"rgba(107,96,86,1)",background:"transparent",label:"transparent"},AFTER_MARKET:{border:"rgba(107,96,86,1)",background:"rgba(38, 251, 149, 0.05)",label:"transparent"},PRE_MARKET:{border:"rgba(107,96,86,1)",background:"rgba(255, 170, 0, 0.05)",label:"transparent"},REGULAR:{border:"rgba(107,96,86,1)",background:"transparent",label:"transparent"}},activeCandleTheme:{upColor:"rgba(98,201,93,1)",downColor:"rgba(255,47,47,1)",noneColor:"rgba(255,255,255,1)",upWickColor:"rgba(98,201,93,1)",downWickColor:"rgba(255,47,47,1)",noneWickColor:"rgba(255,255,255,1)",borderOpacity:.5},volume:{downBarColor:"rgba(99,30,37,1)",upBarColor:"rgba(42,72,44,1)",noneBarColor:"rgba(255,255,255,0.4)",upCapColor:"rgba(42,72,44,1)",downCapColor:"rgba(99,30,37,1)",noneCapColor:"rgba(255,255,255,0.4)"},highLowTheme:{highColor:"rgba(223,222,223,1)",lowColor:"rgba(223,222,223,1)"},instrumentInfo:{textColor:"#aeb1b3"},paneResizer:{lineColor:"rgba(61,61,61,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)",normal:"rgba(217,44,64,1)",hover:"rgba(217,44,64,1)",line:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)",normal:"rgba(169,38,251,1)",hover:"rgba(169,38,251,1)",line:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)",normal:"rgba(244,187,63,1)",hover:"rgba(244,187,63,1)",line:"rgba(244,187,63,1)"},"conference-calls":{color:"rgba(48,194,97,1)",normal:"rgba(48,194,97,1)",hover:"rgba(48,194,97,1)",line:"rgba(48,194,97,1)"}},secondaryChartTheme:[{lineTheme:{upColor:"rgba(226,61,25,1)",downColor:"rgba(226,61,25,1)",noneColor:"rgba(226,61,25,1)"},areaTheme:{lineColor:"rgba(226,61,25,1)",startColor:"rgba(226,61,25,0.8)",stopColor:"rgba(226,61,25,0)"}},{lineTheme:{upColor:"rgba(250,191,64,1)",downColor:"rgba(250,191,64,1)",noneColor:"rgba(250,191,64,1)"},areaTheme:{lineColor:"rgba(250,191,64,1)",startColor:"rgba(250,191,64,0.8)",stopColor:"rgba(250,191,64,0)"}},{lineTheme:{upColor:"rgba(169,38,251,1)",downColor:"rgba(169,38,251,1)",noneColor:"rgba(169,38,251,1)"},areaTheme:{lineColor:"rgba(169,38,251,1)",startColor:"rgba(169,38,251,0.8)",stopColor:"rgba(169,38,251,0)"}},{lineTheme:{upColor:"rgba(77,211,240,1)",downColor:"rgba(77,211,240,1)",noneColor:"rgba(77,211,240,1)"},areaTheme:{lineColor:"rgba(77,211,240,1)",startColor:"rgba(77,211,240,0.8)",stopColor:"rgba(77,211,240,0)"}},{lineTheme:{upColor:"rgba(59,203,91,1)",downColor:"rgba(59,203,91,1)",noneColor:"rgba(59,203,91,1)"},areaTheme:{lineColor:"rgba(59,203,91,1)",startColor:"rgba(59,203,91,0.8)",stopColor:"rgba(59,203,91,0)"}}],yAxis:{backgroundColor:"rgba(20,20,19,1)",labelBoxColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)",labelInvertedTextColor:"rgba(20,20,19,1)",rectLabelTextColor:"rgba(255,255,255,1)",rectLabelInvertedTextColor:"rgba(20,20,19,1)",zeroPercentLine:"rgba(55,55,54,1)"},labels:{lastPrice:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(0,0,0,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},countdownToBarClose:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(255,255,255,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},highLow:{high:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"High"},low:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Low"}},bidAsk:{bid:{boxColor:"rgba(77,153,83,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Bid"},ask:{boxColor:"rgba(217,44,64,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Ask"}},prePostMarket:{post:{boxColor:"rgba(38,251,149,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Post"},pre:{boxColor:"rgba(255,170,0,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Pre"}},prevDayClose:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)"}},xAxis:{backgroundColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)"},navigationMap:{backgroundColor:"transparent",buttonColor:"rgba(255,255,255,0.1)",buttonArrowColor:"rgba(212,212,211,1)",knotColor:"rgba(255,255,255,0.1)",knotLineColor:"rgba(212,212,211,1)",sliderColor:"rgba(255,255,255,0.08)",knotBorderColor:"#0b0d1a",timeLabelsTextColor:"rgba(128,128,128,1)",mapColor:"rgba(255,255,255,0.1)",mapFillColor:"rgba(255,255,255,0.1)",mapGradientTopColor:"rgba(255,255,255,0.1)",mapGradientBottomColor:"rgba(255,255,255,0.1)"}},animation:{moveDuration:1e3,candleDuration:200,paneResizer:{bgMode:!0,enabled:!0,duration:40},yAxis:{background:{enabled:!1,duration:40}}},drawingOrder:["OVER_SERIES_CLEAR","MAIN_CLEAR","SERIES_CLEAR","GRID","X_AXIS","Y_AXIS","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function jl(n,t=es()){return Tt(n,t,Ci),n}function Dm(n,t=es()){const e=Hl({},n);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function Lm(n,t){Object.keys(n).forEach(e=>delete n[e]),Object.keys(t).forEach(e=>n[e]=t[e])}function _i(n){return typeof n=="object"&&n!==null}function Pi(n,t){return[...n].map(s=>Vs(s,t))}const Nl=n=>Array.isArray(n);function Vs(n,t){if(!_i(n))return n;if(Nl(n))return Pi(n,t);{const e=Ti({},n,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e}}function Ti(n,t,e){if(!_i(n))return e.overrideExisting?t:n;if(Array.isArray(n)&&Array.isArray(t)){const i=e.overrideExisting?t:n;return Pi(i,e)}const s=Object.create(Object.getPrototypeOf(n));return Object.keys(n).forEach(i=>s[i]=Vs(n[i],e)),Object.keys(t).forEach(i=>{i in n?s[i]=Ti(n[i],t[i],e):e.addIfMissing&&(s[i]=Vs(t[i],e))}),s}const ee=n=>`${n.fontSize}px ${n.fontFamily}`;class Xl{constructor(t,e){this.config=t,this.mainCanvasModel=e,this.extentsOrder=new Map,this.yAxisWidthContributors=[]}registerYAxisWidthContributor(t){this.yAxisWidthContributors.push(t)}removeYAxisWidthContributor(t){this.yAxisWidthContributors=this.yAxisWidthContributors.filter(e=>e!==t)}getTextWidth(t){const e=ee(this.config.components.yAxis);return Pt(t,this.mainCanvasModel.ctx,e)}getYAxisWidths(){this.extentsOrder.clear();const t=[],e=[];return this.yAxisWidthContributors.forEach(s=>{var i,r,o;const a=s.getYAxisState();if(!a.visible)return;const l=a.labelBoxMargin.start+a.labelBoxMargin.end,c=this.getTextWidth(s.getLargestLabel())+l,h=s.getYAxisIndex(),d=s.getPaneUUID(),u=(i=this.extentsOrder.get(d))!=null?i:{left:[],right:[]};if(a.align==="left"){const f=u.left.length;t[f]=Math.max((r=t[f])!=null?r:0,c),u.left.push(h)}else{const f=u.right.length;e[f]=Math.max((o=e[f])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var Wl=Object.defineProperty,zl=Object.defineProperties,Vl=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,Ul=Object.prototype.hasOwnProperty,Gl=Object.prototype.propertyIsEnumerable,Ai=(n,t,e)=>t in n?Wl(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Xt=(n,t)=>{for(var e in t||(t={}))Ul.call(t,e)&&Ai(n,e,t[e]);if(Mi)for(var e of Mi(t))Gl.call(t,e)&&Ai(n,e,t[e]);return n},Ei=(n,t)=>zl(n,Vl(t));const K="CHART",nt=class{};nt.CANVAS="CANVAS",nt.N_MAP="N_MAP",nt.X_AXIS="X_AXIS",nt.N_MAP_KNOT_L="N_MAP_KNOT_L",nt.N_MAP_KNOT_R="N_MAP_KNOT_R",nt.N_MAP_BTN_L="N_MAP_BTN_L",nt.N_MAP_BTN_R="N_MAP_BTN_R",nt.N_MAP_SLIDER_WINDOW="N_MAP_SLIDER_WINDOW",nt.N_MAP_CHART="N_MAP_CHART",nt.N_MAP_LABEL_R="N_MAP_LABEL_R",nt.N_MAP_LABEL_L="N_MAP_LABEL_L",nt.PANE_UUID=n=>"PANE_"+n,nt.PANE_UUID_Y_AXIS=(n,t=0)=>"PANE_"+n+"_Y_AXIS_"+t,nt.PANE_UUID_RESIZER=n=>"PANE_"+n+"_RESIZER",nt.ALL_PANES="ALL_PANES",nt.CHART_WITH_Y_AXIS="CHART_WITH_Y_AXIS",nt.EVENTS="EVENTS",nt.CHART=nt.PANE_UUID(K),nt.Y_AXIS=nt.PANE_UUID_Y_AXIS(K);let T=nt;const Ii={x:0,y:0,pageX:0,pageY:0,width:0,height:0},Di=20,Li=35,Us=15,Oi=1.5,Bi=jt()?8*Oi:8,Ie=jt()?5:0,Zl=1e-6;class Gs{constructor(t,e,s,i,r){this.config=t,this.eventBus=e,this.canvasModel=s,this.formatterFactory=i,this.bounds={},this.canvasOnPageLocation={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.panesOrder=[],this.panesOrderChangedSubject=new R,this.paneMovedSubject=new R,this.paneVisibilityChangedSubject=new R,this.xAxisHeight=void 0,this.yAxisWidths={right:[0],left:[0]},this.leftRatio=0,this.rightRatio=0,this.boundsChangedSubject=new R,this.barResizerChangedSubject=new R,this._graphsHeightRatio={[K]:1},this.graphsHeightRatioChangedSubject=new R,this.boundsChangedSubscriptions={},r.canvasResized.subscribe(o=>{let a=o;a||(a=this.canvasModel.canvas.getBoundingClientRect()),this.updateCanvasOnPageLocation(a),this.recalculateBounds()}),this.yAxisBoundsContainer=new Xl(this.config,this.canvasModel)}get graphsHeightRatio(){return this._graphsHeightRatio}updateYAxisWidths(){const t=this.yAxisBoundsContainer.getYAxisWidths();this.setYAxisWidths(t)}addPaneBounds(t,e){if(this.panesOrder.indexOf(t)===-1){if(this.panesOrder.push(t),e!==void 0){const s=this.panesOrder.indexOf(t);Ns(this.panesOrder,s,e)}this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}}overrideChartHeightRatios(t){const e=Xt(Xt({},this.graphsHeightRatio),t),s=Object.values(e).reduce((i,r)=>i+r,0);Math.abs(s-1)<Zl?(this._graphsHeightRatio=e,this.recalculateBounds()):console.error(`Result ratio should be equal 1, but equal ${s}`)}movePaneUp(t){const e=this.panesOrder.indexOf(t);e!==-1&&(Ns(this.panesOrder,e,e-1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}movePaneDown(t){const e=this.panesOrder.indexOf(t);e!==-1&&(Ns(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}reorderPanes(t){this.panesOrder=oi(this.panesOrder,t),this.recalculateBounds(),this.panesOrderChangedSubject.next(this.panesOrder)}hidePaneBounds(t){this.graphsHeightRatio[t]=0,this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}showPaneBounds(t){if(t===K){const[e]=Ri(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Sl(this.panesOrder,t),delete this.graphsHeightRatio[t],delete this.bounds[T.PANE_UUID(t)],this.yAxisWidths.left.concat(this.yAxisWidths.right).forEach((e,s)=>delete this.bounds[T.PANE_UUID_Y_AXIS(t,s)]),delete this.bounds[T.PANE_UUID_RESIZER(t)],this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}recalculateBounds(){const t=this.canvasOnPageLocation.width,e=this.canvasOnPageLocation.height,s=this.config.components.paneResizer.height,i=this.getBounds(T.CANVAS);i.x=0,i.y=0,i.width=t,i.height=e;const r=this.yAxisWidths,o=this.getNavMapBounds(i),a=this.getXAxisBounds(o,i),l=e-a.height-o.height,c=r.left.reduce((F,B)=>F+B,0),h=r.right.reduce((F,B)=>F+B,0),d=0,u=i.width-h,f=d+c,p=0,v=i.width-c-h;let x=p;const _=this.panesOrder.findIndex(F=>this.graphsHeightRatio[F]>0);this.panesOrder.forEach((F,B)=>{var Y;const $=this.graphsHeightRatio[this.panesOrder[B]],W=T.PANE_UUID_RESIZER(F),U=T.PANE_UUID(F),G=this.config.components.paneResizer.visible&&B>_&&$>0;G?ge(this.bounds,W,0,x,i.width,s,this.canvasOnPageLocation):ge(this.bounds,W,0,0,0,0,this.canvasOnPageLocation);const V=x+(G?s:0),Q=ge(this.bounds,U,f,V,v,l*$-(G?s:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const J=this.yAxisBoundsContainer.extentsOrder.get(F);if(J===void 0)return;const et=l*$-(G?s:0);let tt=f-((Y=r.left[0])!=null?Y:0),st=u;J.left.forEach((ht,at)=>{var St;ge(this.bounds,T.PANE_UUID_Y_AXIS(F,ht),tt,V,r.left[at],et,this.canvasOnPageLocation),tt-=(St=r.left[at+1])!=null?St:0}),J.right.forEach((ht,at)=>{ge(this.bounds,T.PANE_UUID_Y_AXIS(F,ht),st,V,r.right[at],et,this.canvasOnPageLocation),st+=r.right[at]})}else ge(this.bounds,T.PANE_UUID_Y_AXIS(F),0,0,0,0,this.canvasOnPageLocation);x=Q.y+Q.height});const A=this.getBounds(T.ALL_PANES);A.x=f,A.y=p,A.width=v,A.height=x;const L=this.getBounds(T.CHART_WITH_Y_AXIS),j=this.getBounds(T.CHART);this.getEventsBounds(j),this.copyBounds(j,L),L.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=Ei(Xt({},this.canvasOnPageLocation),{x:t.x,y:t.y,width:t.width,height:t.height})}updateAllBoundsPageCoordinates(){for(const t of Object.keys(this.bounds)){const e=this.bounds[t];e.pageX=e.x+this.canvasOnPageLocation.x,e.pageY=e.y+this.canvasOnPageLocation.y}}getEventsBounds(t){const e=this.getBounds(T.EVENTS);return this.config.components.events.visible?(e.x=0,e.y=t.y+t.height-this.config.components.events.height,e.width=t.width,e.height=this.config.components.events.height):this.applyDefaultBounds(e),e}getNavMapBounds(t){const e=this.getBounds(T.N_MAP);return this.config.components.navigationMap.visible?(e.x=0,e.y=t.height-Li,e.width=t.width,e.height=Li):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const s=this.getBounds(T.X_AXIS),i=this.yAxisWidths.left.length+this.yAxisWidths.right.length===1,r=i?0:this.yAxisWidths.left.reduce((a,l)=>a+=l,0),o=i?0:this.yAxisWidths.right.reduce((a,l)=>a+=l,0);if(this.config.components.xAxis.visible){const a=this.getXAxisHeight();s.x=r,s.y=e.height-a-t.height,s.width=e.width-o,s.height=a}else this.applyDefaultBounds(s);return s}getXAxisHeight(){var t,e;if(!this.xAxisHeight){const s=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily,i=Nt(s,this.canvasModel.ctx);this.xAxisHeight=i+((t=this.config.components.xAxis.padding.top)!=null?t:0)+((e=this.config.components.xAxis.padding.bottom)!=null?e:0)+Ie}return this.xAxisHeight}setYAxisWidths(t){(!ai(this.yAxisWidths.left,t.left)||!ai(this.yAxisWidths.right,t.right))&&(this.yAxisWidths=t,this.recalculateBounds())}setXAxisHeight(t){t!==this.xAxisHeight&&(this.xAxisHeight=t,this.recalculateBounds())}setPanesOrder(t){this.panesOrder=t,this.recalculateBounds()}recalculatePanesHeightRatios(){this.calculateGraphsHeightRatios(),this.recalculateBounds()}calculateGraphsHeightRatios(){let t=this.graphsHeightRatio[K];const e=[];e.push(...this.panesOrder.filter(p=>p!==K));const s=e.map(p=>this.graphsHeightRatio[p]===void 0?void 0:this.graphsHeightRatio[p]),i=s.filter(p=>p!==0),r=i.length,o=i.filter(p=>p!==void 0).length,a=s.filter(p=>p===void 0).length,l=a>0;let c=0,h=0,d=1,u=0;if(l&&([d,u]=Ri(r)),(!this.graphsHeightRatio[K]||this.graphsHeightRatio[K]===0)&&(t=0),this.graphsHeightRatio[K]&&this.graphsHeightRatio[K]!==0)if(l)t=1*d;else{const p=Object.values(this.graphsHeightRatio).reduce((v,x)=>x+=v);p<1&&this.graphsHeightRatio[K]!==0&&(t+=1-p)}o===0&&(t=1-u*a),h=1-t-u*a,i.forEach(p=>{p&&(h-=p*d)}),c=h/(r||1);const f=s.map(p=>p===0?p:p?p*d+c:u+c);this._graphsHeightRatio={},this.graphsHeightRatio[K]=t,f.forEach((p,v)=>{const x=e[v];this.graphsHeightRatio[x]=p})}recalculateNavigationMapElementBounds(){var t,e,s,i;if(!this.config.components.navigationMap.visible)return;const r=this.getBounds(T.N_MAP),{height:o,width:a}=this.config.components.navigationMap.knots,l=o!=null?o:0,c=jt()?a*Oi:a!=null?a:0,h=l?r.y+(r.height-l)/2:r.y,d=(e=(t=this.config.components.navigationMap)==null?void 0:t.timeLabels)==null?void 0:e.visible,u=et=>El(this.canvasModel.ctx,et,this.formatterFactory,this.config)[0],f=pt((i=(s=this.mainCandleSeries)==null?void 0:s.getSeriesInViewport())!=null?i:[]),p=d&&f.length?u(f[0].candle.timestamp):0,v=d&&f.length?u(f[f.length-1].candle.timestamp):0,x=Math.max(p,v);if(d){const et=this.getBounds(T.N_MAP_LABEL_L);et.x=r.x,et.y=r.y,et.width=x,et.height=r.height;const tt=this.getBounds(T.N_MAP_LABEL_R);tt.x=r.x+r.width-x,tt.y=r.y,tt.width=x,tt.height=r.height}const _=this.getBounds(T.N_MAP_BTN_L);_.x=r.x+x,_.y=r.y,_.width=Us,_.height=r.height;const A=this.getBounds(T.N_MAP_BTN_R);A.x=r.x+r.width-Us-x,A.y=r.y,A.width=Us,A.height=r.height;const L=_.x+_.width,j=A.x-L,F=L+j,B=this.config.components.navigationMap.minSliderWindowWidth,Y=c!=null?c:Bi,$=l!=null?l:r.height,W=Y+B,U=this.getBounds(T.N_MAP_KNOT_L);U.x=L+j*this.leftRatio,U.x=Math.min(U.x,F-W),U.y=h,U.width=Y,U.height=$;const G=this.getBounds(T.N_MAP_KNOT_R);G.x=L+j*this.rightRatio-Bi,G.x=Math.max(G.x,L+W),G.y=h,G.width=Y,G.height=$;const V=W-(G.x-U.x);V>0&&(U.x-=V);const Q=this.getBounds(T.N_MAP_SLIDER_WINDOW);Q.x=U.x+U.width,Q.y=r.y,Q.width=G.x-Q.x,Q.height=r.height;const J=this.getBounds(T.N_MAP_CHART);J.x=L,J.y=r.y,J.width=j,J.height=r.height}isVolumesInSeparatePane(){return this.config.components.volumes.visible&&this.config.components.volumes.showSeparately}getBounds(t){let e=this.bounds[t];return e===void 0&&(e=this.copyOf(Ii),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>Ei(Xt({},t),{[e]:this.bounds[T.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=ss){const{extensionX:s,extensionY:i,wholePage:r}=Xt(Xt({},ss),e);return r?(o,a)=>{const l=this.getBounds(t);return o>l.pageX-s&&o<l.pageX+l.width+s&&a>l.pageY-i&&a<l.pageY+l.height+i}:(o,a)=>{const l=this.getBounds(t);return o>l.x-s&&o<l.x+l.width+s&&a>l.y-i&&a<l.y+l.height+i}}static hitTestOf(t,e=ss){const{extensionX:s,extensionY:i,wholePage:r}=Xt(Xt({},ss),e);return r?(o,a)=>o>t.pageX-s&&o<t.pageX+t.width+s&&a>t.pageY-i&&a<t.pageY+t.height+i:(o,a)=>o>t.x-s&&o<t.x+t.width+s&&a>t.y-i&&a<t.y+t.height+i}isChartBoundsAvailable(){const t=this.getBounds(T.CANVAS);return t.width>0&&t.height>0}isAllBoundsAvailable(){return Object.values(this.bounds).every(t=>t.width>=0&&t.height>=0)}resizePaneVertically(t,e){const s=this.panesOrder.indexOf(t),i=this.getBounds(T.PANE_UUID_RESIZER(t));this.doResizePaneVertically(s,i.y-e),this.barResizerChangedSubject.next()}doResizePaneVertically(t,e){let s=t-1;const i=this.panesOrder[s];if(this._graphsHeightRatio[i]<=0)for(let d=0;d<t;d++)this._graphsHeightRatio[this.panesOrder[d]]>0&&(s=d);const r=this.getBounds(T.ALL_PANES).height,o=Di,a=r*this.graphsHeightRatio[this.panesOrder[t]],l=r*this.graphsHeightRatio[this.panesOrder[s]],c=a+e>o,h=l-e>o;if(c&&h){const d=e/r;this.graphsHeightRatio[this.panesOrder[t]]+=d,this.graphsHeightRatio[this.panesOrder[s]]-=d,this.recalculateBounds()}}notifyBoundsSubscribers(){Object.keys(this.boundsChangedSubscriptions).forEach(t=>{this.boundsChangedSubscriptions[t].next(this.getBounds(t))}),this.boundsChangedSubject.next()}observeBoundsChanged(t){let e=this.boundsChangedSubscriptions[t];return e||(e=new ut(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ct(s=>this.copyOf(s)),_t((s,i)=>this.sameBounds(s,i)))}observeAnyBoundsChanged(){return this.boundsChangedSubject.asObservable()}copyOf(t){return Xt({},t)}copyBounds(t,e){e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height}sameBounds(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}applyDefaultBounds(t){this.copyBounds(Ii,t)}setMainCandleSeries(t){this.mainCandleSeries=t}getEffectiveYAxisWidth(){return this.getBounds(T.PANE_UUID_Y_AXIS(K)).width}getEffectiveChartWidth(){return this.getBounds(T.PANE_UUID(K)).width}getEffectiveChartHeight(){return this.getBounds(T.PANE_UUID(K)).height}}const $l={0:1,1:.8,2:.6,3:.5,4:.4,5:.4,6:.4},Ri=n=>{var t;const e=(t=$l[n])!=null?t:.4,s=(1-e)/n;return[e,s]},Om=(n,t)=>n.x>t.x&&n.x<t.x+t.width&&n.y>t.y&&n.y<t.y+t.height,Kl=(n,t)=>n>t.y&&n<t.y+t.height,ge=(n,t,e,s,i,r,o)=>{const a=n[t];if(a)return a.x=e,a.y=s,a.pageX=e+o.x,a.pageY=s+o.y,a.width=i,a.height=r,a;const l={x:e,y:s,pageX:e+o.x,pageY:s+o.y,width:i,height:r};return n[t]=l,l},Fi=(n,t)=>Math.min(Math.max(n,t.y),t.y+t.height),ss={extensionX:0,extensionY:0,wholePage:!1},Hi=(n,t)=>n.width===t.width&&n.height===t.height;var ql=(function(n){z(t,n);function t(e,s){return n.call(this)||this}return t.prototype.schedule=function(e,s){return s===void 0&&(s=0),this},t})(he),ns={setInterval:function(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];var i=ns.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,D([n,t],m(e))):setInterval.apply(void 0,D([n,t],m(e)))},clearInterval:function(n){var t=ns.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(n)},delegate:void 0},ki=(function(n){z(t,n);function t(e,s){var i=n.call(this,e,s)||this;return i.scheduler=e,i.work=s,i.pending=!1,i}return t.prototype.schedule=function(e,s){var i;if(s===void 0&&(s=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return r!=null&&(this.id=this.recycleAsyncId(o,r,s)),this.pending=!0,this.delay=s,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,s),this},t.prototype.requestAsyncId=function(e,s,i){return i===void 0&&(i=0),ns.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,s,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return s;s!=null&&ns.clearInterval(s)},t.prototype.execute=function(e,s){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,s);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,s){var i=!1,r;try{this.work(e)}catch(o){i=!0,r=o||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),r},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,s=e.id,i=e.scheduler,r=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Xe(r,this),s!=null&&(this.id=this.recycleAsyncId(i,s,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t})(ql),De={schedule:function(n){var t=requestAnimationFrame,e=cancelAnimationFrame,s=De.delegate;s&&(t=s.requestAnimationFrame,e=s.cancelAnimationFrame);var i=t(function(r){e=void 0,n(r)});return new he(function(){return e==null?void 0:e(i)})},requestAnimationFrame:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=De.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,D([],m(n)))},cancelAnimationFrame:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=De.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,D([],m(n)))},delegate:void 0},Jl=(function(n){z(t,n);function t(e,s){var i=n.call(this,e,s)||this;return i.scheduler=e,i.work=s,i}return t.prototype.requestAsyncId=function(e,s,i){return i===void 0&&(i=0),i!==null&&i>0?n.prototype.requestAsyncId.call(this,e,s,i):(e.actions.push(this),e._scheduled||(e._scheduled=De.requestAnimationFrame(function(){return e.flush(void 0)})))},t.prototype.recycleAsyncId=function(e,s,i){var r;if(i===void 0&&(i=0),i!=null?i>0:this.delay>0)return n.prototype.recycleAsyncId.call(this,e,s,i);var o=e.actions;s!=null&&s===e._scheduled&&((r=o[o.length-1])===null||r===void 0?void 0:r.id)!==s&&(De.cancelAnimationFrame(s),e._scheduled=void 0)},t})(ki),Zs={now:function(){return(Zs.delegate||Date).now()},delegate:void 0},Yi=(function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,s){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(s,e)},n.now=Zs.now,n})(),ji=(function(n){z(t,n);function t(e,s){s===void 0&&(s=Yi.now);var i=n.call(this,e,s)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var s=this.actions;if(this._active){s.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=s.shift());if(this._active=!1,i){for(;e=s.shift();)e.unsubscribe();throw i}},t})(Yi),Ql=(function(n){z(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.flush=function(e){this._active=!0;var s;e?s=e.id:(s=this._scheduled,this._scheduled=void 0);var i=this.actions,r;e=e||i.shift();do if(r=e.execute(e.state,e.delay))break;while((e=i[0])&&e.id===s&&i.shift());if(this._active=!1,r){for(;(e=i[0])&&e.id===s&&i.shift();)e.unsubscribe();throw r}},t})(ji),Ot=new Ql(Jl),Bm=null,is=new ji(ki),tc=is;function ec(n,t){return N(function(e,s){var i=t!=null?t:{},r=i.leading,o=r===void 0?!0:r,a=i.trailing,l=a===void 0?!1:a,c=!1,h=null,d=null,u=!1,f=function(){d==null||d.unsubscribe(),d=null,l&&(x(),u&&s.complete())},p=function(){d=null,u&&s.complete()},v=function(_){return d=At(n(_)).subscribe(bt(s,f,p))},x=function(){if(c){c=!1;var _=h;h=null,s.next(_),!u&&v(_)}};e.subscribe(bt(s,function(_){c=!0,h=_,!(d&&!d.closed)&&(o?x():v(_))},function(){u=!0,!(l&&c&&d&&!d.closed)&&s.complete()}))})}function sc(n){return n instanceof Date&&!isNaN(n)}function nc(n,t,e){n===void 0&&(n=0),e===void 0&&(e=tc);var s=-1;return t!=null&&(zn(t)?e=t:s=t),new gt(function(i){var r=sc(n)?+n-e.now():n;r<0&&(r=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=s?this.schedule(void 0,s):i.complete())},r)})}function Et(n,t,e){t===void 0&&(t=is);var s=nc(n,t);return ec(function(){return s},e)}class X{constructor(){this.subscriptions=[],this._state="initial",this.entities=[]}doActivate(){}doDeactivate(){this.subscriptions.forEach(t=>t()),this.subscriptions=[]}enable(){this._state!=="active"&&(this._state="deactivated",this.activate())}disable(){this._state!=="disabled"&&(this.deactivate(),this._state="disabled")}activate(){this._state!=="disabled"&&(this._state!=="active"&&(this.doActivate(),this._state="active"),this.entities.forEach(t=>t.activate()))}deactivate(){this._state!=="disabled"&&(this._state!=="deactivated"&&(this.doDeactivate(),this._state="deactivated"),this.entities.forEach(t=>t.deactivate()))}getState(){return this._state}addSubscription(t){this.subscriptions.push(t)}addRxSubscription(t){t&&this.subscriptions.push(t.unsubscribe.bind(t))}addChildEntity(t){this.entities.push(t),this._state==="active"&&t.activate()}removeChildEntity(t){this.entities=this.entities.filter(e=>e!==t)}}class ic extends X{constructor(t,e,s,i){super(),this.element=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.hitTestCanvasModel=i,this.normalLayer=new Map,this.extensionLayer=new Map,this.cursorChangedSubject=new R}doActivate(){super.doActivate(),this.canvasInputListener.observeMouseMoveNoDrag().pipe(Et(100,Ot,{trailing:!0})).subscribe(t=>{const e=this.hitTestCanvasModel.resolveCursor(t);if(e!==void 0){this.updateCursor(e);return}t&&(this.normalLayer.forEach(s=>{s.hitTest(t.x,t.y)&&this.updateCursor(s.cursor)}),this.extensionLayer.forEach(s=>{s.hitTest(t.x,t.y)&&this.updateCursor(s.cursor)}))})}setCursorForBounds(t,e,s,i=0){const r=Gs.hitTestOf(e,{extensionY:i});i?this.extensionLayer.set(t,{cursor:s,hitTest:r}):this.normalLayer.set(t,{cursor:s,hitTest:r})}setCursorForCanvasEl(t,e,s){this.observeCursorType(t,e,s)}removeCursorForCanvasEl(t){this.normalLayer.delete(t),this.extensionLayer.delete(t)}observeCursorChanged(){return this.cursorChangedSubject.pipe(_t())}observeCursorType(t,e,s){const i=s?this.canvasBoundsContainer.getBoundsHitTest(t,{extensionY:s}):this.canvasBoundsContainer.getBoundsHitTest(t);s?this.extensionLayer.set(t,{cursor:e,hitTest:i}):this.normalLayer.set(t,{cursor:e,hitTest:i})}updateCursor(t){this.element.style.cursor!==t&&(this.element.style.cursor=t,this.cursorChangedSubject.next(t))}}const rc=n=>{const t=n.canvasArea!==null,e=n.snapshotCanvas!==null,s=n.backgroundCanvas!==null,i=n.mainCanvas!==null,r=n.yAxisLabelsCanvas!==null,o=n.crossToolCanvas!==null,a=n.hitTestCanvas!==null,l=n.chartResizer!==null,c=n.chartContainer!==null,h=n.dynamicObjectsCanvas!==null;return t&&e&&s&&i&&r&&o&&a&&l&&c&&h},oc=(n=>`<div data-element="chartResizer" style="position: relative; min-height: 20px; height: 100%; width: 100%; touch-action: manipulation; z-index: 0;">
8
+ `):"",this.name="UnsubscriptionError",this.errors=e}});function Xe(n,t){if(n){var e=n.indexOf(t);0<=e&&n.splice(e,1)}}var he=(function(){function n(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return n.prototype.unsubscribe=function(){var t,e,s,i,r;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=E(o),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(m){t={error:m}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(k(h))try{h()}catch(m){r=m instanceof Ts?m.errors:[m]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=E(d),f=u.next();!f.done;f=u.next()){var g=f.value;try{An(g)}catch(m){r=r!=null?r:[],m instanceof Ts?r=D(D([],v(r)),v(m.errors)):r.push(m)}}}catch(m){s={error:m}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(s)throw s.error}}}if(r)throw new Ts(r)}},n.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)An(t);else{if(t instanceof n){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},n.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},n.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},n.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Xe(e,t)},n.prototype.remove=function(t){var e=this._finalizers;e&&Xe(e,t),t instanceof n&&t._removeParent(this)},n.EMPTY=(function(){var t=new n;return t.closed=!0,t})(),n})(),Tn=he.EMPTY;function Mn(n){return n instanceof he||n&&"closed"in n&&k(n.remove)&&k(n.add)&&k(n.unsubscribe)}function An(n){k(n)?n():n.unsubscribe()}var Jt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},We={setTimeout:function(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];var i=We.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,D([n,t],v(e))):setTimeout.apply(void 0,D([n,t],v(e)))},clearTimeout:function(n){var t=We.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(n)},delegate:void 0};function En(n){We.setTimeout(function(){var t=Jt.onUnhandledError;if(t)t(n);else throw n})}function In(){}var ya=(function(){return Ms("C",void 0,void 0)})();function wa(n){return Ms("E",void 0,n)}function Sa(n){return Ms("N",n,void 0)}function Ms(n,t,e){return{kind:n,value:t,error:e}}var Qt=null;function ze(n){if(Jt.useDeprecatedSynchronousErrorHandling){var t=!Qt;if(t&&(Qt={errorThrown:!1,error:null}),n(),t){var e=Qt,s=e.errorThrown,i=e.error;if(Qt=null,s)throw i}}else n()}function xa(n){Jt.useDeprecatedSynchronousErrorHandling&&Qt&&(Qt.errorThrown=!0,Qt.error=n)}var As=(function(n){z(t,n);function t(e){var s=n.call(this)||this;return s.isStopped=!1,e?(s.destination=e,Mn(e)&&e.add(s)):s.destination=Ma,s}return t.create=function(e,s,i){return new xe(e,s,i)},t.prototype.next=function(e){this.isStopped?Is(Sa(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?Is(wa(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?Is(ya,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,n.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(he),_a=Function.prototype.bind;function Es(n,t){return _a.call(n,t)}var Pa=(function(){function n(t){this.partialObserver=t}return n.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(s){Ve(s)}},n.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(s){Ve(s)}else Ve(t)},n.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){Ve(e)}},n})(),xe=(function(n){z(t,n);function t(e,s,i){var r=n.call(this)||this,o;if(k(e)||!e)o={next:e!=null?e:void 0,error:s!=null?s:void 0,complete:i!=null?i:void 0};else{var a;r&&Jt.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&Es(e.next,a),error:e.error&&Es(e.error,a),complete:e.complete&&Es(e.complete,a)}):o=e}return r.destination=new Pa(o),r}return t})(As);function Ve(n){Jt.useDeprecatedSynchronousErrorHandling?xa(n):En(n)}function Ta(n){throw n}function Is(n,t){var e=Jt.onStoppedNotification;e&&We.setTimeout(function(){return e(n,t)})}var Ma={closed:!0,next:In,error:Ta,complete:In};function bt(n,t,e,s,i){return new Aa(n,t,e,s,i)}var Aa=(function(n){z(t,n);function t(e,s,i,r,o,a){var l=n.call(this,e)||this;return l.onFinalize=o,l.shouldUnsubscribe=a,l._next=s?function(c){try{s(c)}catch(h){e.error(h)}}:n.prototype._next,l._error=r?function(c){try{r(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:n.prototype._error,l._complete=i?function(){try{i()}catch(c){e.error(c)}finally{this.unsubscribe()}}:n.prototype._complete,l}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var s=this.closed;n.prototype.unsubscribe.call(this),!s&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t})(As);function ct(n,t){return N(function(e,s){var i=0;e.subscribe(bt(s,function(r){s.next(n.call(t,r,i++))}))})}var Ds=(function(n){return n&&typeof n.length=="number"&&typeof n!="function"});function Dn(n){return k(n==null?void 0:n.then)}var Ls=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function de(n){return n}function pm(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return Ln(n)}function Ln(n){return n.length===0?de:n.length===1?n[0]:function(e){return n.reduce(function(s,i){return i(s)},e)}}var gt=(function(){function n(t){t&&(this._subscribe=t)}return n.prototype.lift=function(t){var e=new n;return e.source=this,e.operator=t,e},n.prototype.subscribe=function(t,e,s){var i=this,r=Ia(t)?t:new xe(t,e,s);return ze(function(){var o=i,a=o.operator,l=o.source;r.add(a?a.call(r,l):l?i._subscribe(r):i._trySubscribe(r))}),r},n.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},n.prototype.forEach=function(t,e){var s=this;return e=On(e),new e(function(i,r){var o=new xe({next:function(a){try{t(a)}catch(l){r(l),o.unsubscribe()}},error:r,complete:i});s.subscribe(o)})},n.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},n.prototype[Ls]=function(){return this},n.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return Ln(t)(this)},n.prototype.toPromise=function(t){var e=this;return t=On(t),new t(function(s,i){var r;e.subscribe(function(o){return r=o},function(o){return i(o)},function(){return s(r)})})},n.create=function(t){return new n(t)},n})();function On(n){var t;return(t=n!=null?n:Jt.Promise)!==null&&t!==void 0?t:Promise}function Ea(n){return n&&k(n.next)&&k(n.error)&&k(n.complete)}function Ia(n){return n&&n instanceof As||Ea(n)&&Mn(n)}function Bn(n){return k(n[Ls])}function Rn(n){return Symbol.asyncIterator&&k(n==null?void 0:n[Symbol.asyncIterator])}function Fn(n){return new TypeError("You provided "+(n!==null&&typeof n=="object"?"an invalid object":"'"+n+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Da(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Hn=Da();function kn(n){return k(n==null?void 0:n[Hn])}function Yn(n){return lt(this,arguments,function(){var e,s,i,r;return p(this,function(o){switch(o.label){case 0:e=n.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,H(e.read())];case 3:return s=o.sent(),i=s.value,r=s.done,r?[4,H(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,H(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}})})}function jn(n){return k(n==null?void 0:n.getReader)}function At(n){if(n instanceof gt)return n;if(n!=null){if(Bn(n))return La(n);if(Ds(n))return Oa(n);if(Dn(n))return Ba(n);if(Rn(n))return Nn(n);if(kn(n))return Ra(n);if(jn(n))return Fa(n)}throw Fn(n)}function La(n){return new gt(function(t){var e=n[Ls]();if(k(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Oa(n){return new gt(function(t){for(var e=0;e<n.length&&!t.closed;e++)t.next(n[e]);t.complete()})}function Ba(n){return new gt(function(t){n.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,En)})}function Ra(n){return new gt(function(t){var e,s;try{for(var i=E(n),r=i.next();!r.done;r=i.next()){var o=r.value;if(t.next(o),t.closed)return}}catch(a){e={error:a}}finally{try{r&&!r.done&&(s=i.return)&&s.call(i)}finally{if(e)throw e.error}}t.complete()})}function Nn(n){return new gt(function(t){Ha(n,t).catch(function(e){return t.error(e)})})}function Fa(n){return Nn(Yn(n))}function Ha(n,t){var e,s,i,r;return w(this,void 0,void 0,function(){var o,a;return p(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Ht(n),l.label=1;case 1:return[4,e.next()];case 2:if(s=l.sent(),!!s.done)return[3,4];if(o=s.value,t.next(o),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),i={error:a},[3,11];case 6:return l.trys.push([6,,9,10]),s&&!s.done&&(r=e.return)?[4,r.call(e)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function kt(n,t,e,s,i){s===void 0&&(s=0),i===void 0&&(i=!1);var r=t.schedule(function(){e(),i?n.add(this.schedule(null,s)):this.unsubscribe()},s);if(n.add(r),!i)return r}function ka(n,t,e,s,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},f=function(m){return c<s?g(m):l.push(m)},g=function(m){r&&t.next(m),c++;var x=!1;At(e(m,h++)).subscribe(bt(t,function(_){i==null||i(_),r?f(_):t.next(_)},function(){x=!0},void 0,function(){if(x)try{c--;for(var _=function(){var A=l.shift();o?kt(t,o,function(){return g(A)}):g(A)};l.length&&c<s;)_();u()}catch(A){t.error(A)}}))};return n.subscribe(bt(t,f,function(){d=!0,u()})),function(){a==null||a()}}function Os(n,t,e){return e===void 0&&(e=1/0),k(t)?Os(function(s,i){return ct(function(r,o){return t(s,r,i,o)})(At(n(s,i)))},e):(typeof t=="number"&&(e=t),N(function(s,i){return ka(s,i,n,e)}))}function Xn(n){return n===void 0&&(n=1/0),Os(de,n)}var Wn=new gt(function(n){return n.complete()});function mm(n){return n?Ya(n):Wn}function Ya(n){return new Observable(function(t){return n.schedule(function(){return t.complete()})})}function zn(n){return n&&k(n.schedule)}function Bs(n){return n[n.length-1]}function ja(n){return k(Bs(n))?n.pop():void 0}function Ue(n){return zn(Bs(n))?n.pop():void 0}function Na(n,t){return typeof Bs(n)=="number"?n.pop():t}function Vn(n,t){return t===void 0&&(t=0),N(function(e,s){e.subscribe(bt(s,function(i){return kt(s,n,function(){return s.next(i)},t)},function(){return kt(s,n,function(){return s.complete()},t)},function(i){return kt(s,n,function(){return s.error(i)},t)}))})}function Un(n,t){return t===void 0&&(t=0),N(function(e,s){s.add(n.schedule(function(){return e.subscribe(s)},t))})}function Xa(n,t){return At(n).pipe(Un(t),Vn(t))}function Wa(n,t){return At(n).pipe(Un(t),Vn(t))}function za(n,t){return new gt(function(e){var s=0;return t.schedule(function(){s===n.length?e.complete():(e.next(n[s++]),e.closed||this.schedule())})})}function Va(n,t){return new gt(function(e){var s;return kt(e,t,function(){s=n[Hn](),kt(e,t,function(){var i,r,o;try{i=s.next(),r=i.value,o=i.done}catch(a){e.error(a);return}o?e.complete():e.next(r)},0,!0)}),function(){return k(s==null?void 0:s.return)&&s.return()}})}function Gn(n,t){if(!n)throw new Error("Iterable cannot be null");return new gt(function(e){kt(e,t,function(){var s=n[Symbol.asyncIterator]();kt(e,t,function(){s.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function Ua(n,t){return Gn(Yn(n),t)}function Ga(n,t){if(n!=null){if(Bn(n))return Xa(n,t);if(Ds(n))return za(n,t);if(Dn(n))return Wa(n,t);if(Rn(n))return Gn(n,t);if(kn(n))return Va(n,t);if(jn(n))return Ua(n,t)}throw Fn(n)}function Ge(n,t){return t?Ga(n,t):At(n)}function Ct(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=Na(n,1/0),i=n;return i.length?i.length===1?At(i[0]):Xn(s)(Ge(i,e)):Wn}var Za=Pn(function(n){return function(){n(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),R=(function(n){z(t,n);function t(){var e=n.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return t.prototype.lift=function(e){var s=new Zn(this,this);return s.operator=e,s},t.prototype._throwIfClosed=function(){if(this.closed)throw new Za},t.prototype.next=function(e){var s=this;ze(function(){var i,r;if(s._throwIfClosed(),!s.isStopped){s.currentObservers||(s.currentObservers=Array.from(s.observers));try{for(var o=E(s.currentObservers),a=o.next();!a.done;a=o.next()){var l=a.value;l.next(e)}}catch(c){i={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(e){var s=this;ze(function(){if(s._throwIfClosed(),!s.isStopped){s.hasError=s.isStopped=!0,s.thrownError=e;for(var i=s.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;ze(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var s=e.observers;s.length;)s.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(e){return this._throwIfClosed(),n.prototype._trySubscribe.call(this,e)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var s=this,i=this,r=i.hasError,o=i.isStopped,a=i.observers;return r||o?Tn:(this.currentObservers=null,a.push(e),new he(function(){s.currentObservers=null,Xe(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var s=this,i=s.hasError,r=s.thrownError,o=s.isStopped;i?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new gt;return e.source=this,e},t.create=function(e,s){return new Zn(e,s)},t})(gt),Zn=(function(n){z(t,n);function t(e,s){var i=n.call(this)||this;return i.destination=e,i.source=s,i}return t.prototype.next=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.next)===null||i===void 0||i.call(s,e)},t.prototype.error=function(e){var s,i;(i=(s=this.destination)===null||s===void 0?void 0:s.error)===null||i===void 0||i.call(s,e)},t.prototype.complete=function(){var e,s;(s=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||s===void 0||s.call(e)},t.prototype._subscribe=function(e){var s,i;return(i=(s=this.source)===null||s===void 0?void 0:s.subscribe(e))!==null&&i!==void 0?i:Tn},t})(R),ut=(function(n){z(t,n);function t(e){var s=n.call(this)||this;return s._value=e,s}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var s=n.prototype._subscribe.call(this,e);return!s.closed&&e.next(this._value),s},t.prototype.getValue=function(){var e=this,s=e.hasError,i=e.thrownError,r=e._value;if(s)throw i;return this._throwIfClosed(),r},t.prototype.next=function(e){n.prototype.next.call(this,this._value=e)},t})(R);let Rs=!1,Fs=0;const Ze=new Map,$e=new Map,$n=()=>{Rs||(Rs=!0,Fs=requestAnimationFrame(()=>{$e.forEach((n,t)=>{n(),$e.delete(t)}),Ze.forEach((n,t)=>{n(),Ze.delete(t)}),Rs=!1}))},Kn=(n,t)=>{Ze.set(n,t),$n()},$a=n=>{Ze.delete(n)},Ka=n=>{$e.delete(n)},_e=(n,t)=>{$e.set(n,t),$n()};function yt(){const n=()=>Math.random().toString(16).slice(-4);return`${n()+n()}-${n()}-${n()}-${n()}-${n()+n()+n()}`}const qn="\u2212",qa="-";var Ja=Math.pow;const Ke=14,qe=[];for(let n=0;n<Ke+1;n++)qe.push(Ja(10,n));const Hs=5e-13;class ft{static roundToNearest(t,e){return isFinite(t)?ft.isZero(t)?0:(t>0?t+=Hs:t<0&&(t-=Hs),ft.roundDecimal(Math.round(ft.roundDecimal(t/e))*e)):t}static roundUpToNearest(t,e){return ft.roundDecimal(Math.ceil(t/e))*e}static roundDecimal(t){if(isNaN(t)||t===Math.floor(t))return t;const e=Math.sign(t),s=Math.abs(t),i=Math.min(Ke,Ke-1-Math.floor(Math.log10(s)));for(let r=i;r>=0;r--){const o=Math.floor(qe[r]*s+.5);if(o<qe[Ke])return e*o/qe[r]}return Math.round(t)}static makeDecimal(t,e,s,i){if(!isFinite(t))return"";if(isFinite(t)){let r=t.toFixed(e);if(!i)return s?r.replace(".",s):r;if(s===i)throw new Error("Grouping symbol cannot be the same as decimal separator.");const o=r.split(".");let a=o[0];const l=o[1];return Math.abs(t)>=1e3&&(a=a.replace(RegExp("\\d(?=(\\d{3})+$)","g"),`$&${i}`)),l?(r=[a,l].join(s),r):a}return""}static compare(t,e,s){return t>e+s?1:t<e-s?-1:(isNaN(t)?1:0)-(isNaN(e)?1:0)}static isZero(t){return ft.compare(t,0,Hs)===0}static cutNumber(t,e,s=0){return{K:r=>r/1e3,M:r=>r/1e6}[e](t).toFixed(s)+e}static isExponential(t){return/\de(\-|\+)\d/.test(t.toString())}}function Qa(n,t,e){const s=n/t;return s>=e||s<=1/e}function ks(n,t,e){return Math.max(t,Math.min(n,e))}function tl(n){return 1-(Math.pow(2,-10*n)-.0009765625)*1.0009775171065494}function Pe(...n){for(const t of n)if(t!==void 0&&isFinite(t))return t;return NaN}const ot=n=>~~n,el=n=>~~(n+1),Te=n=>~~(n+.5),sl=(n,t)=>n>>t;function vm(n){if(!Number.isFinite(n))throw new Error("Input must be a finite number.");const t=n.toString();return t.includes(".")?t.split(".")[1].length:0}const Je=n=>n.replace(qa,qn);class Ys{constructor(t,e){this.animationTimeLeft=0,this.onTickFunction=e,this.animationTime=t.duration,this.animationStartTime=Date.now(),this.animationInProgress=!0}tick(){var t;Date.now()>this.animationStartTime+this.animationTime&&(this.animationInProgress=!1),(t=this.onTickFunction)==null||t.call(this)}getProgress(){return Math.min((Date.now()-this.animationStartTime)/this.animationTime,1)}finishAnimation(){this.animationInProgress=!1,this.animationStartTime=0}}var nl=xt(520),Lt=xt.n(nl);class Jn extends Ys{constructor(t,e,s=()=>{}){super(t,s),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=Lt().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.colorConfigs.forEach(t=>{if(t.initialAlpha===void 0||t.rgbColor===void 0)return;const e=t.initialAlpha*(t.type==="fading"?1-this.getProgress():this.getProgress());t.currentAnimationColor=t.rgbColor.alpha(e)})}getColor(t){var e,s;return(s=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?s:"#FFFFFF"}revert(){const t=ks(Date.now()-this.animationStartTime,0,this.animationTime);this.animationStartTime=Date.now()-this.animationTime+t,this.colorConfigs.forEach(e=>{e.type=e.type==="fading"?"appearing":"fading"})}}class Qn extends Ys{constructor(t,e,s=()=>{}){super(t,s),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=Lt().rgb(i.startColor),i.rgbEndColor=Lt().rgb(i.endColor),i.currentAnimationColor=i.type==="appearing"?i.rgbStartColor:i.rgbEndColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{const e=1-this.animationTimeLeft/this.animationTime;!t.rgbStartColor||!t.rgbEndColor||(t.type==="fading"?t.currentAnimationColor=this.calculateTransitionColor(t.rgbEndColor,t.rgbStartColor,e):t.type==="appearing"&&(t.currentAnimationColor=this.calculateTransitionColor(t.rgbStartColor,t.rgbEndColor,e)))})}getColor(t){var e,s;return(s=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?s:"#FFFFFF"}revert(){this.animationTimeLeft=Math.max(this.animationTime-this.animationTimeLeft,1),this.colorConfigs.forEach(t=>{t.type==="fading"?t.type="appearing":t.type="fading"})}moveToLastTick(){this.animationTimeLeft=1}calculateTransitionColor(t,e,s){const i=t.red()-(t.red()-e.red())*s,r=t.green()-(t.green()-e.green())*s,o=t.blue()-(t.blue()-e.blue())*s;return Lt().rgb(i,r,o)}}class ti extends Ys{constructor(t,e,s){var i;super(e,s),this.viewportModel=t,this.animationConfig=e,this.id=yt(),this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.easingFn=(i=e.easingFn)!=null?i:tl}tick(){if(super.tick(),this.animationInProgress){const t=this.easingFn(this.getProgress()),e=this.xStart+(this.animationConfig.targetXStart-this.xStart)*t,s=this.xEnd+(this.animationConfig.targetXEnd-this.xEnd)*t,i=this.yStart+(this.animationConfig.targetYStart-this.yStart)*t,r=this.yEnd+(this.animationConfig.targetYEnd-this.yEnd)*t,o=this.zoomX+(this.animationConfig.targetZoomX-this.zoomX)*t,a=this.zoomY+(this.animationConfig.targetZoomY-this.zoomY)*t;this.viewportModel.apply({xStart:e,xEnd:s,yStart:i,yEnd:r,zoomX:o,zoomY:a,inverseY:this.viewportModel.inverseY})}}finishAnimation(){super.finishAnimation(),this.viewportModel.apply({xStart:this.animationConfig.targetXStart,xEnd:this.animationConfig.targetXEnd,yStart:this.animationConfig.targetYStart,yEnd:this.animationConfig.targetYEnd,zoomX:this.animationConfig.targetZoomX,zoomY:this.animationConfig.targetZoomY,inverseY:this.viewportModel.inverseY})}}const Me=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),il=!!window.chrome,ei=typeof InstallTrigger!="undefined",rl=navigator.platform.indexOf("Win")>-1,bm=n=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:s}=n;if(e||s){let i;if(Me)i=e===n.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(n.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(n.deltaY)*3);else if(il){if(i=e+Math.sign(e)===n.deltaY*-3?e+Math.sign(e)===n.deltaY*-3:e===n.deltaY*-3,rl){const r=Math.round(n.deltaY)===e||Math.abs(Math.round(n.deltaY)+Math.sign(n.deltaY))===Math.abs(e)||Math.abs(Math.round(n.deltaY)-Math.sign(n.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(n.deltaY)||r}}else ei?Math.abs(n.deltaY)>Math.abs(n.deltaX)?i=!1:i=s===n.deltaX*-3:i=e===n.deltaY*-3;i&&(t=!0)}else n.deltaMode===0&&(t=!0);return ei&&n.deltaY>=16&&Math.abs(n.deltaY)%16===0&&(t=!1),n.ctrlKey&&(t=!0),t},ol=(n,t)=>n==="percent"?t/4:t;var al=Object.defineProperty,ll=Object.defineProperties,cl=Object.getOwnPropertyDescriptors,si=Object.getOwnPropertySymbols,hl=Object.prototype.hasOwnProperty,dl=Object.prototype.propertyIsEnumerable,ni=(n,t,e)=>t in n?al(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ul=(n,t)=>{for(var e in t||(t={}))hl.call(t,e)&&ni(n,e,t[e]);if(si)for(var e of si(t))dl.call(t,e)&&ni(n,e,t[e]);return n},fl=(n,t)=>ll(n,cl(t));const Ae=Me?150:400,ue="VIEWPORT_ANIMATION";class ii{constructor(t){this.animations={},this.animationInProgressSubject=new ut(!1),this.animFrameId=`canvas_animation_${yt()}`,this.eventBus=t}startViewportMovementAnimation(t,e,s=ue,i){const r=new ti(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new Jn(fl(ul({},i),{duration:i&&i.duration||Ae}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ae,i){const r=new Qn({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0)}processAnimation(){_e(this.animFrameId,()=>this.tick())}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():queueMicrotask(()=>{this.processAnimation(),this.eventBus.fireDraw()})}stopInterval(){$a(this.animFrameId)}}function _t(n,t){return t===void 0&&(t=de),n=n!=null?n:gl,N(function(e,s){var i,r=!0;e.subscribe(bt(s,function(o){var a=t(o);(r||!n(i,a))&&(r=!1,i=a,s.next(o))}))})}function gl(n,t){return n===t}function pl(n){return function(){n.forEach(e=>typeof e=="function"&&e()),n.length=0}}function js(n){return n}function ri(n){return n!=null}const Cm=()=>{};function ym(n){return n!=null}function ml(n,t,e=vl,s=!0){const i=n.filter(r=>t.some(o=>e(r,o)));return s?i.filter((r,o,a)=>a.indexOf(r)===o):i}const oi=(n,t)=>{const e=t.slice().filter(s=>n.find(i=>i===s));return n.map(s=>{var i;return t.indexOf(s)>=0&&(i=e.shift())!=null?i:s})},vl=(n,t)=>n===t,wm=(n,t,e)=>n.filter(s=>t.filter(i=>e(s,i)).length===0),bl=(n,t)=>n===t,ai=(n,t,e=bl)=>n.length===t.length&&n.every((s,i)=>e(s,t[i]));function Sm(n,t,e){const s=n.slice(),i=s[t];return s.splice(t,1),s.splice(e,0,i),s}function Ns(n,t,e){const s=n.length,i=ks(t,0,s-1),r=ks(e,0,s-1),o=n[i];return n.splice(i,1),n.splice(r,0,o),n}function xm(n,t,e){const s=n.slice(),i=s.findIndex(t);return i!==-1&&(s.splice(i,1),s.splice(i,0,e)),s}const _m=n=>{const t={};return n.filter(e=>t[e]?!1:t[e]=!0)},Pm=(n,t)=>n.reduce((e,s)=>((e[s[t]]=e[s[t]]||[]).push(s),e),{}),Tm=(n,t)=>[].concat(...n.map(e=>[e,t])).slice(0,-1),Mm=n=>Array.isArray(n[0]),li=n=>Array.isArray(n[0])?n:[n],Cl=(n,t,e)=>{const s=[];let i=0;for(const r of n){const o=Math.max(t-i,0),a=Math.max(e-i,-1),l=r.slice(o,a+1);l.length>0&&s.push(l),i+=r.length}return s},yl=(n,t)=>n>=0?t[n]:t[t.length+n],pt=n=>Array.prototype.flat?n.flat():Ee(n,js),Ee=(n,t)=>{if(Array.prototype.flatMap)return n.flatMap(t);const e=[];for(let s=0;s<n.length;s++){const i=n[s];e.push(...t(i,s,n))}return e};function Yt(n,t,e){const s=e!=null?e:js;return!n.length||t!==t?{index:-1,exact:!0}:Xs(n,t,0,n.length,s)}function Xs(n,t,e,s,i){const r=sl(e+s,1),o=i(n[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Xs(n,t,e,r,i):Xs(n,t,r,s,i)}function wt(n){if(n&&n.length)return n[n.length-1]}function wl(n){const t=this.indexOf(n);return t!==-1&&this.splice(t,1),this}function Sl(n,t){if(!n)return;const e=n.indexOf(t);e!==-1&&n.splice(e,1)}function fe(n){if(n)return n[0]}function xl(n){function t(e,s){const i=n(s);return i==null||!isFinite(i)?e:[Math.max(e[0],i),Math.min(e[1],i)]}return function(e){const s=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY];return e?e.reduce(t,s):s}}function _l(n,t,e,s=()=>0){const i=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);s(o[h])<=a?l=h+1:c=h-1}return c},r=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);s(o[h])>=a?c=h-1:l=h+1}return l};return n.slice(r(n,t),i(n,e)+1)}let Ws,ci;const jt=()=>{if(typeof navigator=="undefined")return!1;const n=navigator.userAgent;return(ci!==n||Ws===void 0)&&(ci=n,Ws=!!n.match(/Android|iPhone|Opera Mini/)),Ws},Pl=1.33,hi=4.5;function di(n,t){let e="";t.textStyle&&(t.textStyle.italic&&(e+="italic "),t.textStyle.bold&&(e+="bold ")),n.font=e+(t.textSize||12)+" "+(t.textFontFamily||"monospace"),n.fillStyle=t.textFill||"#FFFFFF",t.rtl?n.textAlign="right":n.textAlign="start"}function Qe(n,t=!0){const e=n.font.match(/(\d+.)?\d+(px|pt)/gi);let s="10px";return e&&e.length&&(e[0].includes("pt")?s=+e[0].slice(0,e[0].indexOf("pt"))*96/72+"px":s=e[0]),t?parseInt(s,10)*Pl:parseInt(s,10)}function ui(n,t,e){n.save(),di(n,e);const s=Math.ceil(Math.max.apply(Math,t.map(o=>n.measureText(o).width))),i=Qe(n),r=i*t.length;return n.restore(),[s,r,i]}function fi(n){return(n||"").split(/\r\n|\r|\n/)}function Tl(n,t,e,s,i){n.save();const[r,,o]=ui(n,t,i);t.forEach((a,l)=>{var c,h,d;const u=n.measureText(a).width,f=Ml(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&Al(n,a,f,s+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),n.fillText(a,f,s+o*l)}),n.restore()}function Ml(n,t,e,s){switch(s){case"left":return n;case"right":return n+t-e;default:return n}}function Al(n,t,e,s,i,r){n.save();const o=n.measureText(t).width,a=e,l=e+o,c=s+2,h=c;let d=parseInt(r,10)/15;d<1&&(d=1),n.beginPath(),n.strokeStyle=i,n.lineWidth=d,n.moveTo(a,c),n.lineTo(l,h),n.stroke(),n.restore()}function Am(n){return`${n}px`}function gi(n){const t=Lt().rgb(n).array(),[e,s,i]=t.map(r=>{const o=r/255;return o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4)});return .2126*e+.7152*s+.0722*i}function pi(n,t){const e=gi(n),s=gi(t),i=Math.max(e,s),r=Math.min(e,s);return(i+.05)/(r+.05)}function te(n,t,e){const s=pi(n,t),i=pi(n,e),r=s>=hi,o=i>=hi;return r&&!o?t:o&&!r?e:s>=i?t:e}function El(n,t,e,s){const i=s.components.navigationMap.timeLabels,r=i.padding,o=mi(t,i.dateFormat,e),a=fi(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=ui(n,a,l);return[c+r.x*2,h+r.y*2]}function mi(n,t,e){return e(t)(n).split(" ").join(`
9
+ `)}const vi={};function Nt(n,t){let e=vi[n];return e!==void 0||(t.save(),t.font=n,e=t.measureText("M").width,vi[n]=e,t.restore()),e}const bi=new Map;function Pt(n,t,e){const s=e+n;let i=bi.get(s);return i||(t.save(),t.font=e,i=t.measureText(n).width,bi.set(s,i),t.restore()),i}function Tt(n,t,e=Ci){function s(i,r){for(const o in r)o in i?typeof i[o]=="object"&&i[o]!==null&&!Array.isArray(i[o])?s(i[o],r[o]):e!=null&&e.overrideExisting&&(i[o]=r[o]):e!=null&&e.addIfMissing&&(i[o]=r[o]);return i}return s(n,t)}function Em(n,t,e,s=!1){!n||!t||t.length===0||t.forEach(i=>{const r=e(i),o=n.findIndex(a=>e(a)===r);o===-1?n.push(i):s?Tt(n[o],i,{overrideExisting:!0,addIfMissing:!0}):n.splice(o,1,i)})}const Ci={overrideExisting:!1,addIfMissing:!0};function Il(n){let t=0;if(n.length===0)return t;for(let e=0;e<n.length;e++){const s=n.charCodeAt(e);t=(t<<5)-t+s,t|=0}return t}const zs=1,Dl=n=>n.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),yi=(n,t)=>`${n}_${Il(t.toString())}`;function ts(n,t){return t===n?"none":t>n?"up":"down"}function Ll(n,t){return t>n?"up":"down"}function Ol(n,t,e=!1){const{id:s,expansion:i,impVolatility:r,openInterest:o,vwap:a,typicalPrice:l,volume:c,timestamp:h}=n;let d=n.hi,u=n.lo,f=n.open;const g=n.close;e&&(d=g,u=g,f=g);let m=n.idx;return t!==void 0&&(m=t),{id:s,hi:d,lo:u,open:f,close:g,timestamp:h,volume:c,expansion:i,idx:m,impVolatility:r,openInterest:o,vwap:a,typicalPrice:l}}var Bl=Object.defineProperty,wi=Object.getOwnPropertySymbols,Rl=Object.prototype.hasOwnProperty,Fl=Object.prototype.propertyIsEnumerable,Si=(n,t,e)=>t in n?Bl(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Hl=(n,t)=>{for(var e in t||(t={}))Rl.call(t,e)&&Si(n,e,t[e]);if(wi)for(var e of wi(t))Fl.call(t,e)&&Si(n,e,t[e]);return n};const xi="Open Sans Semibold, sans-serif",kl=null,Yl=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Im=n=>kl.find(t=>t===n)!==void 0,es=()=>({devexpertsPromoLink:!0,useUTCTimeOverride:!1,shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],rtl:!1,intlFormatter:{decimalSeparator:".",thousandsSeparator:""},scale:{keepZoomXOnYAxisChange:!0,auto:!0,zoomToCursor:!1,lockPriceToBarRatio:!1,autoScaleOnCandles:!0,autoScaleDisableOnDrag:{enabled:!0,edgeAngle:Math.PI/15,yDiff:80},inverse:!1,zoomSensitivity:{wheel:.25},defaultViewportItems:100,disableAnimations:!1},timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,components:{chart:{type:"candle",showCandlesBorder:!0,showActiveCandlesBorder:!0,showWicks:!0,candleLineWidth:1,lineWidth:1,areaLineWidth:1,barLineWidth:1,minWidth:.5,minCandles:10,candlePaddingPercent:.25,highlightActiveCandle:!0,cursor:"default",selectedWidth:3,minCandlesOffset:2,defaultZoomCandleWidth:7,zoomStep:0,histogram:{barCapSize:1},maxYAxisScalesAmount:10,applyBackgroundToAxes:{x:!0,y:!0},sortCandles:Dl},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:xi,cursor:"ns-resize",resizeDisabledCursor:"default",labelBoxMargin:{top:4,bottom:4,end:8,start:10},typeConfig:{badge:{rounded:!0,paddings:{top:4,bottom:4,end:4,start:4}},plain:{},rectangle:{rounded:!1,paddings:{top:4,bottom:4,end:4,start:4}}},labels:{descriptions:!1,settings:{lastPrice:{mode:"label",type:"badge"},countdownToBarClose:{mode:"none",type:"rectangle"}}},treasuryFormat:{enabled:!1}},xAxis:{visible:!0,formatsForLabelsConfig:{lessThanSecond:"HH:mm:ss",second_1:"HH:mm:ss",minute_1:"HH:mm",minute_5:"HH:mm",minute_30:"HH:mm",hour_1:"HH:mm",day_1:"dd.MM",month_1:"MMM",year_1:"YYYY"},fontSize:12,fontFamily:xi,cursor:"ew-resize",padding:{top:8,bottom:16},fontStyle:""},events:{visible:!1,eventsVisibility:{"conference-calls":!0,dividends:!0,splits:!0,earnings:!0},height:20,cursor:"default",xAxisLabelFormat:[{format:"d MMM"}],icons:{earnings:{normal:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" stroke="#D92C40" stroke-width="1.5"/></svg>',hover:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" fill="#D92C40" stroke="#D92C40" stroke-width="1.5"/></svg>'}}},offsets:{visible:!0,right:10,top:10,bottom:20,left:0},waterMark:{visible:!1,fontFamily:"Open Sans, sans-serif",firstRowFontSize:80,firstRowBottomPadding:10,secondRowFontSize:40,secondRowBottomPadding:25,thirdRowFontSize:40,thirdRowBottomPadding:15,position:"center",offsetX:20,offsetY:20,logoWidth:20,logoHeight:20},highLow:{visible:!1,font:"12px sans-serif",prefix:{high:"H: ",low:"L: "},lineDash:[2,4]},highlights:{visible:!1,fontFamily:"Open Sans",fontSize:13,border:{width:1,dash:[8,4]}},crossTool:{type:"cross-and-labels",discrete:!0,magnetTarget:"none",lineDash:[4,6],xAxisLabelFormat:[{format:"dd.MM.YYYY",showWhen:{periodMoreThen:1440*60*1e3}},{format:"dd.MM.YYYY HH:mm",showWhen:{periodLessThen:1440*60*1e3,periodMoreThen:6*1e3}},{format:"dd.MM.YYYY HH:mm:ss",showWhen:{periodLessThen:6*1e3}}],xLabel:{padding:{top:4,bottom:4,right:8,left:8},margin:{top:4}},yLabel:{padding:{top:4,bottom:4,end:4,start:4},type:"badge"}},grid:{visible:!0,horizontal:!1,vertical:!0,width:1,dash:[0,0],color:"#FFFFFF"},volumes:{visible:!0,showSeparately:!1,valueLines:15,barCapSize:1,volumeBarSpace:0,volumeFillColor:"#FFFFFF"},navigationMap:{visible:!1,allCandlesHistory:!0,timeLabels:{visible:!1,dateFormat:"dd.MM.YYYY HH:mm",fontFamily:"Open Sans",fontSize:13,padding:{x:10,y:1}},minSliderWindowWidth:10,cursors:{chart:"default",buttonLeft:"pointer",buttonRight:"pointer",leftResizer:"ew-resize",rightResizer:"ew-resize",slider:"grab"},knots:{height:35,width:7,border:0,lineWidth:1}},baseline:{cursor:"ns-resize",dragZone:3,height:1},paneResizer:{cursor:"ns-resize",height:1,visible:!0,fixedMode:!1,dragZone:3}},colors:{candleTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)",upWickColor:"rgba(77,153,83,1)",downWickColor:"rgba(217,44,64,1)",noneWickColor:"rgba(255,255,255,1)",borderOpacity:1},barTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)"},lineTheme:{upColor:"rgba(77,153,83,1)",downColor:"rgba(217,44,64,1)",noneColor:"rgba(255,255,255,1)"},chartAreaTheme:{backgroundMode:"regular",backgroundColor:"rgba(20,20,19,1)",backgroundGradientTopColor:"red",backgroundGradientBottomColor:"blue",gridColor:"rgba(37,37,36,1)"},scatterPlot:{mainColor:"rgba(255,255,255,1)"},areaTheme:{lineColor:"rgba(127,120,214,1)",startColor:"rgba(169,38,251,1)",stopColor:"rgba(169,38,251,0.8)"},baseLineTheme:{lowerSectionStrokeColor:"rgba(217,44,64,1)",upperSectionStrokeColor:"rgba(77,153,83,1)",lowerSectionFillColor:"rgba(217, 44, 64, 0.07)",upperSectionFillColor:"rgba(77, 153, 83, 0.07)",baselineColor:"rgba(55,55,54,1)"},histogram:{upCap:"rgba(77,153,83,1)",upBottom:"rgba(77,153,83,0.1)",upBright:"rgba(77,153,83,0.4)",downCap:"rgba(217,44,64,1)",downBottom:"rgba(217,44,64,0.1)",downBright:"rgba(217,44,64,0.4)",noneCap:"rgba(255,255,255,1)",noneBottom:"rgba(255,255,255,0.1)",noneBright:"rgba(255,255,255,0.4)"},crossTool:{lineColor:"rgba(107,96,86,1)",labelBoxColor:"rgba(107,96,86,1)",labelTextColor:"rgba(255,255,255,1)"},waterMarkTheme:{firstRowColor:"rgba(255,255,255,0.2)",secondRowColor:"rgba(255,255,255,0.2)",thirdRowColor:"rgba(255,255,255,0.2)"},highlights:{NO_TRADING:{border:"rgba(107,96,86,1)",background:"transparent",label:"transparent"},AFTER_MARKET:{border:"rgba(107,96,86,1)",background:"rgba(38, 251, 149, 0.05)",label:"transparent"},PRE_MARKET:{border:"rgba(107,96,86,1)",background:"rgba(255, 170, 0, 0.05)",label:"transparent"},REGULAR:{border:"rgba(107,96,86,1)",background:"transparent",label:"transparent"}},activeCandleTheme:{upColor:"rgba(98,201,93,1)",downColor:"rgba(255,47,47,1)",noneColor:"rgba(255,255,255,1)",upWickColor:"rgba(98,201,93,1)",downWickColor:"rgba(255,47,47,1)",noneWickColor:"rgba(255,255,255,1)",borderOpacity:.5},volume:{downBarColor:"rgba(99,30,37,1)",upBarColor:"rgba(42,72,44,1)",noneBarColor:"rgba(255,255,255,0.4)",upCapColor:"rgba(42,72,44,1)",downCapColor:"rgba(99,30,37,1)",noneCapColor:"rgba(255,255,255,0.4)"},highLowTheme:{highColor:"rgba(223,222,223,1)",lowColor:"rgba(223,222,223,1)"},instrumentInfo:{textColor:"#aeb1b3"},paneResizer:{lineColor:"rgba(61,61,61,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)",normal:"rgba(217,44,64,1)",hover:"rgba(217,44,64,1)",line:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)",normal:"rgba(169,38,251,1)",hover:"rgba(169,38,251,1)",line:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)",normal:"rgba(244,187,63,1)",hover:"rgba(244,187,63,1)",line:"rgba(244,187,63,1)"},"conference-calls":{color:"rgba(48,194,97,1)",normal:"rgba(48,194,97,1)",hover:"rgba(48,194,97,1)",line:"rgba(48,194,97,1)"}},secondaryChartTheme:[{lineTheme:{upColor:"rgba(226,61,25,1)",downColor:"rgba(226,61,25,1)",noneColor:"rgba(226,61,25,1)"},areaTheme:{lineColor:"rgba(226,61,25,1)",startColor:"rgba(226,61,25,0.8)",stopColor:"rgba(226,61,25,0)"}},{lineTheme:{upColor:"rgba(250,191,64,1)",downColor:"rgba(250,191,64,1)",noneColor:"rgba(250,191,64,1)"},areaTheme:{lineColor:"rgba(250,191,64,1)",startColor:"rgba(250,191,64,0.8)",stopColor:"rgba(250,191,64,0)"}},{lineTheme:{upColor:"rgba(169,38,251,1)",downColor:"rgba(169,38,251,1)",noneColor:"rgba(169,38,251,1)"},areaTheme:{lineColor:"rgba(169,38,251,1)",startColor:"rgba(169,38,251,0.8)",stopColor:"rgba(169,38,251,0)"}},{lineTheme:{upColor:"rgba(77,211,240,1)",downColor:"rgba(77,211,240,1)",noneColor:"rgba(77,211,240,1)"},areaTheme:{lineColor:"rgba(77,211,240,1)",startColor:"rgba(77,211,240,0.8)",stopColor:"rgba(77,211,240,0)"}},{lineTheme:{upColor:"rgba(59,203,91,1)",downColor:"rgba(59,203,91,1)",noneColor:"rgba(59,203,91,1)"},areaTheme:{lineColor:"rgba(59,203,91,1)",startColor:"rgba(59,203,91,0.8)",stopColor:"rgba(59,203,91,0)"}}],yAxis:{backgroundColor:"rgba(20,20,19,1)",labelBoxColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)",labelInvertedTextColor:"rgba(20,20,19,1)",rectLabelTextColor:"rgba(255,255,255,1)",rectLabelInvertedTextColor:"rgba(20,20,19,1)",zeroPercentLine:"rgba(55,55,54,1)"},labels:{lastPrice:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(0,0,0,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},countdownToBarClose:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(255,255,255,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},highLow:{high:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"High"},low:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Low"}},bidAsk:{bid:{boxColor:"rgba(77,153,83,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Bid"},ask:{boxColor:"rgba(217,44,64,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Ask"}},prePostMarket:{post:{boxColor:"rgba(38,251,149,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Post"},pre:{boxColor:"rgba(255,170,0,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Pre"}},prevDayClose:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)"}},xAxis:{backgroundColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)"},navigationMap:{backgroundColor:"transparent",buttonColor:"rgba(255,255,255,0.1)",buttonArrowColor:"rgba(212,212,211,1)",knotColor:"rgba(255,255,255,0.1)",knotLineColor:"rgba(212,212,211,1)",sliderColor:"rgba(255,255,255,0.08)",knotBorderColor:"#0b0d1a",timeLabelsTextColor:"rgba(128,128,128,1)",mapColor:"rgba(255,255,255,0.1)",mapFillColor:"rgba(255,255,255,0.1)",mapGradientTopColor:"rgba(255,255,255,0.1)",mapGradientBottomColor:"rgba(255,255,255,0.1)"}},animation:{moveDuration:1e3,candleDuration:200,paneResizer:{bgMode:!0,enabled:!0,duration:40},yAxis:{background:{enabled:!1,duration:40}}},drawingOrder:["OVER_SERIES_CLEAR","MAIN_CLEAR","SERIES_CLEAR","GRID","X_AXIS","Y_AXIS","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function jl(n,t=es()){return Tt(n,t,Ci),n}function Dm(n,t=es()){const e=Hl({},n);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function Lm(n,t){Object.keys(n).forEach(e=>delete n[e]),Object.keys(t).forEach(e=>n[e]=t[e])}function _i(n){return typeof n=="object"&&n!==null}function Pi(n,t){return[...n].map(s=>Vs(s,t))}const Nl=n=>Array.isArray(n);function Vs(n,t){if(!_i(n))return n;if(Nl(n))return Pi(n,t);{const e=Ti({},n,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(n)),e}}function Ti(n,t,e){if(!_i(n))return e.overrideExisting?t:n;if(Array.isArray(n)&&Array.isArray(t)){const i=e.overrideExisting?t:n;return Pi(i,e)}const s=Object.create(Object.getPrototypeOf(n));return Object.keys(n).forEach(i=>s[i]=Vs(n[i],e)),Object.keys(t).forEach(i=>{i in n?s[i]=Ti(n[i],t[i],e):e.addIfMissing&&(s[i]=Vs(t[i],e))}),s}const ee=n=>`${n.fontSize}px ${n.fontFamily}`;class Xl{constructor(t,e){this.config=t,this.mainCanvasModel=e,this.extentsOrder=new Map,this.yAxisWidthContributors=[]}registerYAxisWidthContributor(t){this.yAxisWidthContributors.push(t)}removeYAxisWidthContributor(t){this.yAxisWidthContributors=this.yAxisWidthContributors.filter(e=>e!==t)}getTextWidth(t){const e=ee(this.config.components.yAxis);return Pt(t,this.mainCanvasModel.ctx,e)}getYAxisWidths(){this.extentsOrder.clear();const t=[],e=[];return this.yAxisWidthContributors.forEach(s=>{var i,r,o;const a=s.getYAxisState();if(!a.visible)return;const l=a.labelBoxMargin.start+a.labelBoxMargin.end,c=this.getTextWidth(s.getLargestLabel())+l,h=s.getYAxisIndex(),d=s.getPaneUUID(),u=(i=this.extentsOrder.get(d))!=null?i:{left:[],right:[]};if(a.align==="left"){const f=u.left.length;t[f]=Math.max((r=t[f])!=null?r:0,c),u.left.push(h)}else{const f=u.right.length;e[f]=Math.max((o=e[f])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var Wl=Object.defineProperty,zl=Object.defineProperties,Vl=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,Ul=Object.prototype.hasOwnProperty,Gl=Object.prototype.propertyIsEnumerable,Ai=(n,t,e)=>t in n?Wl(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Xt=(n,t)=>{for(var e in t||(t={}))Ul.call(t,e)&&Ai(n,e,t[e]);if(Mi)for(var e of Mi(t))Gl.call(t,e)&&Ai(n,e,t[e]);return n},Ei=(n,t)=>zl(n,Vl(t));const K="CHART",nt=class{};nt.CANVAS="CANVAS",nt.N_MAP="N_MAP",nt.X_AXIS="X_AXIS",nt.N_MAP_KNOT_L="N_MAP_KNOT_L",nt.N_MAP_KNOT_R="N_MAP_KNOT_R",nt.N_MAP_BTN_L="N_MAP_BTN_L",nt.N_MAP_BTN_R="N_MAP_BTN_R",nt.N_MAP_SLIDER_WINDOW="N_MAP_SLIDER_WINDOW",nt.N_MAP_CHART="N_MAP_CHART",nt.N_MAP_LABEL_R="N_MAP_LABEL_R",nt.N_MAP_LABEL_L="N_MAP_LABEL_L",nt.PANE_UUID=n=>"PANE_"+n,nt.PANE_UUID_Y_AXIS=(n,t=0)=>"PANE_"+n+"_Y_AXIS_"+t,nt.PANE_UUID_RESIZER=n=>"PANE_"+n+"_RESIZER",nt.ALL_PANES="ALL_PANES",nt.CHART_WITH_Y_AXIS="CHART_WITH_Y_AXIS",nt.EVENTS="EVENTS",nt.CHART=nt.PANE_UUID(K),nt.Y_AXIS=nt.PANE_UUID_Y_AXIS(K);let T=nt;const Ii={x:0,y:0,pageX:0,pageY:0,width:0,height:0},Di=20,Li=35,Us=15,Oi=1.5,Bi=jt()?8*Oi:8,Ie=jt()?5:0,Zl=1e-6;class Gs{constructor(t,e,s,i,r){this.config=t,this.eventBus=e,this.canvasModel=s,this.formatterFactory=i,this.bounds={},this.canvasOnPageLocation={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.panesOrder=[],this.panesOrderChangedSubject=new R,this.paneMovedSubject=new R,this.paneVisibilityChangedSubject=new R,this.xAxisHeight=void 0,this.yAxisWidths={right:[0],left:[0]},this.leftRatio=0,this.rightRatio=0,this.boundsChangedSubject=new R,this.barResizerChangedSubject=new R,this._graphsHeightRatio={[K]:1},this.graphsHeightRatioChangedSubject=new R,this.boundsChangedSubscriptions={},r.canvasResized.subscribe(o=>{let a=o;a||(a=this.canvasModel.canvas.getBoundingClientRect()),this.updateCanvasOnPageLocation(a),this.recalculateBounds()}),this.yAxisBoundsContainer=new Xl(this.config,this.canvasModel)}get graphsHeightRatio(){return this._graphsHeightRatio}updateYAxisWidths(){const t=this.yAxisBoundsContainer.getYAxisWidths();this.setYAxisWidths(t)}addPaneBounds(t,e){if(this.panesOrder.indexOf(t)===-1){if(this.panesOrder.push(t),e!==void 0){const s=this.panesOrder.indexOf(t);Ns(this.panesOrder,s,e)}this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}}overrideChartHeightRatios(t){const e=Xt(Xt({},this.graphsHeightRatio),t),s=Object.values(e).reduce((i,r)=>i+r,0);Math.abs(s-1)<Zl?(this._graphsHeightRatio=e,this.recalculateBounds()):console.error(`Result ratio should be equal 1, but equal ${s}`)}movePaneUp(t){const e=this.panesOrder.indexOf(t);e!==-1&&(Ns(this.panesOrder,e,e-1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}movePaneDown(t){const e=this.panesOrder.indexOf(t);e!==-1&&(Ns(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}reorderPanes(t){this.panesOrder=oi(this.panesOrder,t),this.recalculateBounds(),this.panesOrderChangedSubject.next(this.panesOrder)}hidePaneBounds(t){this.graphsHeightRatio[t]=0,this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}showPaneBounds(t){if(t===K){const[e]=Ri(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Sl(this.panesOrder,t),delete this.graphsHeightRatio[t],delete this.bounds[T.PANE_UUID(t)],this.yAxisWidths.left.concat(this.yAxisWidths.right).forEach((e,s)=>delete this.bounds[T.PANE_UUID_Y_AXIS(t,s)]),delete this.bounds[T.PANE_UUID_RESIZER(t)],this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}recalculateBounds(){const t=this.canvasOnPageLocation.width,e=this.canvasOnPageLocation.height,s=this.config.components.paneResizer.height,i=this.getBounds(T.CANVAS);i.x=0,i.y=0,i.width=t,i.height=e;const r=this.yAxisWidths,o=this.getNavMapBounds(i),a=this.getXAxisBounds(o,i),l=e-a.height-o.height,c=r.left.reduce((F,B)=>F+B,0),h=r.right.reduce((F,B)=>F+B,0),d=0,u=i.width-h,f=d+c,g=0,m=i.width-c-h;let x=g;const _=this.panesOrder.findIndex(F=>this.graphsHeightRatio[F]>0);this.panesOrder.forEach((F,B)=>{var Y;const $=this.graphsHeightRatio[this.panesOrder[B]],W=T.PANE_UUID_RESIZER(F),U=T.PANE_UUID(F),G=this.config.components.paneResizer.visible&&B>_&&$>0;G?ge(this.bounds,W,0,x,i.width,s,this.canvasOnPageLocation):ge(this.bounds,W,0,0,0,0,this.canvasOnPageLocation);const V=x+(G?s:0),Q=ge(this.bounds,U,f,V,m,l*$-(G?s:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const J=this.yAxisBoundsContainer.extentsOrder.get(F);if(J===void 0)return;const et=l*$-(G?s:0);let tt=f-((Y=r.left[0])!=null?Y:0),st=u;J.left.forEach((ht,at)=>{var St;ge(this.bounds,T.PANE_UUID_Y_AXIS(F,ht),tt,V,r.left[at],et,this.canvasOnPageLocation),tt-=(St=r.left[at+1])!=null?St:0}),J.right.forEach((ht,at)=>{ge(this.bounds,T.PANE_UUID_Y_AXIS(F,ht),st,V,r.right[at],et,this.canvasOnPageLocation),st+=r.right[at]})}else ge(this.bounds,T.PANE_UUID_Y_AXIS(F),0,0,0,0,this.canvasOnPageLocation);x=Q.y+Q.height});const A=this.getBounds(T.ALL_PANES);A.x=f,A.y=g,A.width=m,A.height=x;const L=this.getBounds(T.CHART_WITH_Y_AXIS),j=this.getBounds(T.CHART);this.getEventsBounds(j),this.copyBounds(j,L),L.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=Ei(Xt({},this.canvasOnPageLocation),{x:t.x,y:t.y,width:t.width,height:t.height})}updateAllBoundsPageCoordinates(){for(const t of Object.keys(this.bounds)){const e=this.bounds[t];e.pageX=e.x+this.canvasOnPageLocation.x,e.pageY=e.y+this.canvasOnPageLocation.y}}getEventsBounds(t){const e=this.getBounds(T.EVENTS);return this.config.components.events.visible?(e.x=0,e.y=t.y+t.height-this.config.components.events.height,e.width=t.width,e.height=this.config.components.events.height):this.applyDefaultBounds(e),e}getNavMapBounds(t){const e=this.getBounds(T.N_MAP);return this.config.components.navigationMap.visible?(e.x=0,e.y=t.height-Li,e.width=t.width,e.height=Li):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const s=this.getBounds(T.X_AXIS),i=this.yAxisWidths.left.length+this.yAxisWidths.right.length===1,r=i?0:this.yAxisWidths.left.reduce((a,l)=>a+=l,0),o=i?0:this.yAxisWidths.right.reduce((a,l)=>a+=l,0);if(this.config.components.xAxis.visible){const a=this.getXAxisHeight();s.x=r,s.y=e.height-a-t.height,s.width=e.width-o,s.height=a}else this.applyDefaultBounds(s);return s}getXAxisHeight(){var t,e;if(!this.xAxisHeight){const s=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily,i=Nt(s,this.canvasModel.ctx);this.xAxisHeight=i+((t=this.config.components.xAxis.padding.top)!=null?t:0)+((e=this.config.components.xAxis.padding.bottom)!=null?e:0)+Ie}return this.xAxisHeight}setYAxisWidths(t){(!ai(this.yAxisWidths.left,t.left)||!ai(this.yAxisWidths.right,t.right))&&(this.yAxisWidths=t,this.recalculateBounds())}setXAxisHeight(t){t!==this.xAxisHeight&&(this.xAxisHeight=t,this.recalculateBounds())}setPanesOrder(t){this.panesOrder=t,this.recalculateBounds()}recalculatePanesHeightRatios(){this.calculateGraphsHeightRatios(),this.recalculateBounds()}calculateGraphsHeightRatios(){let t=this.graphsHeightRatio[K];const e=[];e.push(...this.panesOrder.filter(g=>g!==K));const s=e.map(g=>this.graphsHeightRatio[g]===void 0?void 0:this.graphsHeightRatio[g]),i=s.filter(g=>g!==0),r=i.length,o=i.filter(g=>g!==void 0).length,a=s.filter(g=>g===void 0).length,l=a>0;let c=0,h=0,d=1,u=0;if(l&&([d,u]=Ri(r)),(!this.graphsHeightRatio[K]||this.graphsHeightRatio[K]===0)&&(t=0),this.graphsHeightRatio[K]&&this.graphsHeightRatio[K]!==0)if(l)t=1*d;else{const g=Object.values(this.graphsHeightRatio).reduce((m,x)=>x+=m);g<1&&this.graphsHeightRatio[K]!==0&&(t+=1-g)}o===0&&(t=1-u*a),h=1-t-u*a,i.forEach(g=>{g&&(h-=g*d)}),c=h/(r||1);const f=s.map(g=>g===0?g:g?g*d+c:u+c);this._graphsHeightRatio={},this.graphsHeightRatio[K]=t,f.forEach((g,m)=>{const x=e[m];this.graphsHeightRatio[x]=g})}recalculateNavigationMapElementBounds(){var t,e,s,i;if(!this.config.components.navigationMap.visible)return;const r=this.getBounds(T.N_MAP),{height:o,width:a}=this.config.components.navigationMap.knots,l=o!=null?o:0,c=jt()?a*Oi:a!=null?a:0,h=l?r.y+(r.height-l)/2:r.y,d=(e=(t=this.config.components.navigationMap)==null?void 0:t.timeLabels)==null?void 0:e.visible,u=et=>El(this.canvasModel.ctx,et,this.formatterFactory,this.config)[0],f=pt((i=(s=this.mainCandleSeries)==null?void 0:s.getSeriesInViewport())!=null?i:[]),g=d&&f.length?u(f[0].candle.timestamp):0,m=d&&f.length?u(f[f.length-1].candle.timestamp):0,x=Math.max(g,m);if(d){const et=this.getBounds(T.N_MAP_LABEL_L);et.x=r.x,et.y=r.y,et.width=x,et.height=r.height;const tt=this.getBounds(T.N_MAP_LABEL_R);tt.x=r.x+r.width-x,tt.y=r.y,tt.width=x,tt.height=r.height}const _=this.getBounds(T.N_MAP_BTN_L);_.x=r.x+x,_.y=r.y,_.width=Us,_.height=r.height;const A=this.getBounds(T.N_MAP_BTN_R);A.x=r.x+r.width-Us-x,A.y=r.y,A.width=Us,A.height=r.height;const L=_.x+_.width,j=A.x-L,F=L+j,B=this.config.components.navigationMap.minSliderWindowWidth,Y=c!=null?c:Bi,$=l!=null?l:r.height,W=Y+B,U=this.getBounds(T.N_MAP_KNOT_L);U.x=L+j*this.leftRatio,U.x=Math.min(U.x,F-W),U.y=h,U.width=Y,U.height=$;const G=this.getBounds(T.N_MAP_KNOT_R);G.x=L+j*this.rightRatio-Bi,G.x=Math.max(G.x,L+W),G.y=h,G.width=Y,G.height=$;const V=W-(G.x-U.x);V>0&&(U.x-=V);const Q=this.getBounds(T.N_MAP_SLIDER_WINDOW);Q.x=U.x+U.width,Q.y=r.y,Q.width=G.x-Q.x,Q.height=r.height;const J=this.getBounds(T.N_MAP_CHART);J.x=L,J.y=r.y,J.width=j,J.height=r.height}isVolumesInSeparatePane(){return this.config.components.volumes.visible&&this.config.components.volumes.showSeparately}getBounds(t){let e=this.bounds[t];return e===void 0&&(e=this.copyOf(Ii),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>Ei(Xt({},t),{[e]:this.bounds[T.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=ss){const{extensionX:s,extensionY:i,wholePage:r}=Xt(Xt({},ss),e);return r?(o,a)=>{const l=this.getBounds(t);return o>l.pageX-s&&o<l.pageX+l.width+s&&a>l.pageY-i&&a<l.pageY+l.height+i}:(o,a)=>{const l=this.getBounds(t);return o>l.x-s&&o<l.x+l.width+s&&a>l.y-i&&a<l.y+l.height+i}}static hitTestOf(t,e=ss){const{extensionX:s,extensionY:i,wholePage:r}=Xt(Xt({},ss),e);return r?(o,a)=>o>t.pageX-s&&o<t.pageX+t.width+s&&a>t.pageY-i&&a<t.pageY+t.height+i:(o,a)=>o>t.x-s&&o<t.x+t.width+s&&a>t.y-i&&a<t.y+t.height+i}isChartBoundsAvailable(){const t=this.getBounds(T.CANVAS);return t.width>0&&t.height>0}isAllBoundsAvailable(){return Object.values(this.bounds).every(t=>t.width>=0&&t.height>=0)}resizePaneVertically(t,e){const s=this.panesOrder.indexOf(t),i=this.getBounds(T.PANE_UUID_RESIZER(t));this.doResizePaneVertically(s,i.y-e),this.barResizerChangedSubject.next()}doResizePaneVertically(t,e){let s=t-1;const i=this.panesOrder[s];if(this._graphsHeightRatio[i]<=0)for(let d=0;d<t;d++)this._graphsHeightRatio[this.panesOrder[d]]>0&&(s=d);const r=this.getBounds(T.ALL_PANES).height,o=Di,a=r*this.graphsHeightRatio[this.panesOrder[t]],l=r*this.graphsHeightRatio[this.panesOrder[s]],c=a+e>o,h=l-e>o;if(c&&h){const d=e/r;this.graphsHeightRatio[this.panesOrder[t]]+=d,this.graphsHeightRatio[this.panesOrder[s]]-=d,this.recalculateBounds()}}notifyBoundsSubscribers(){Object.keys(this.boundsChangedSubscriptions).forEach(t=>{this.boundsChangedSubscriptions[t].next(this.getBounds(t))}),this.boundsChangedSubject.next()}observeBoundsChanged(t){let e=this.boundsChangedSubscriptions[t];return e||(e=new ut(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ct(s=>this.copyOf(s)),_t((s,i)=>this.sameBounds(s,i)))}observeAnyBoundsChanged(){return this.boundsChangedSubject.asObservable()}copyOf(t){return Xt({},t)}copyBounds(t,e){e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height}sameBounds(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}applyDefaultBounds(t){this.copyBounds(Ii,t)}setMainCandleSeries(t){this.mainCandleSeries=t}getEffectiveYAxisWidth(){return this.getBounds(T.PANE_UUID_Y_AXIS(K)).width}getEffectiveChartWidth(){return this.getBounds(T.PANE_UUID(K)).width}getEffectiveChartHeight(){return this.getBounds(T.PANE_UUID(K)).height}}const $l={0:1,1:.8,2:.6,3:.5,4:.4,5:.4,6:.4},Ri=n=>{var t;const e=(t=$l[n])!=null?t:.4,s=(1-e)/n;return[e,s]},Om=(n,t)=>n.x>t.x&&n.x<t.x+t.width&&n.y>t.y&&n.y<t.y+t.height,Kl=(n,t)=>n>t.y&&n<t.y+t.height,ge=(n,t,e,s,i,r,o)=>{const a=n[t];if(a)return a.x=e,a.y=s,a.pageX=e+o.x,a.pageY=s+o.y,a.width=i,a.height=r,a;const l={x:e,y:s,pageX:e+o.x,pageY:s+o.y,width:i,height:r};return n[t]=l,l},Fi=(n,t)=>Math.min(Math.max(n,t.y),t.y+t.height),ss={extensionX:0,extensionY:0,wholePage:!1},Hi=(n,t)=>n.width===t.width&&n.height===t.height;var ql=(function(n){z(t,n);function t(e,s){return n.call(this)||this}return t.prototype.schedule=function(e,s){return s===void 0&&(s=0),this},t})(he),ns={setInterval:function(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];var i=ns.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,D([n,t],v(e))):setInterval.apply(void 0,D([n,t],v(e)))},clearInterval:function(n){var t=ns.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(n)},delegate:void 0},ki=(function(n){z(t,n);function t(e,s){var i=n.call(this,e,s)||this;return i.scheduler=e,i.work=s,i.pending=!1,i}return t.prototype.schedule=function(e,s){var i;if(s===void 0&&(s=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return r!=null&&(this.id=this.recycleAsyncId(o,r,s)),this.pending=!0,this.delay=s,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,s),this},t.prototype.requestAsyncId=function(e,s,i){return i===void 0&&(i=0),ns.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,s,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return s;s!=null&&ns.clearInterval(s)},t.prototype.execute=function(e,s){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,s);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,s){var i=!1,r;try{this.work(e)}catch(o){i=!0,r=o||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),r},t.prototype.unsubscribe=function(){if(!this.closed){var e=this,s=e.id,i=e.scheduler,r=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Xe(r,this),s!=null&&(this.id=this.recycleAsyncId(i,s,null)),this.delay=null,n.prototype.unsubscribe.call(this)}},t})(ql),De={schedule:function(n){var t=requestAnimationFrame,e=cancelAnimationFrame,s=De.delegate;s&&(t=s.requestAnimationFrame,e=s.cancelAnimationFrame);var i=t(function(r){e=void 0,n(r)});return new he(function(){return e==null?void 0:e(i)})},requestAnimationFrame:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=De.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,D([],v(n)))},cancelAnimationFrame:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=De.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,D([],v(n)))},delegate:void 0},Jl=(function(n){z(t,n);function t(e,s){var i=n.call(this,e,s)||this;return i.scheduler=e,i.work=s,i}return t.prototype.requestAsyncId=function(e,s,i){return i===void 0&&(i=0),i!==null&&i>0?n.prototype.requestAsyncId.call(this,e,s,i):(e.actions.push(this),e._scheduled||(e._scheduled=De.requestAnimationFrame(function(){return e.flush(void 0)})))},t.prototype.recycleAsyncId=function(e,s,i){var r;if(i===void 0&&(i=0),i!=null?i>0:this.delay>0)return n.prototype.recycleAsyncId.call(this,e,s,i);var o=e.actions;s!=null&&s===e._scheduled&&((r=o[o.length-1])===null||r===void 0?void 0:r.id)!==s&&(De.cancelAnimationFrame(s),e._scheduled=void 0)},t})(ki),Zs={now:function(){return(Zs.delegate||Date).now()},delegate:void 0},Yi=(function(){function n(t,e){e===void 0&&(e=n.now),this.schedulerActionCtor=t,this.now=e}return n.prototype.schedule=function(t,e,s){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(s,e)},n.now=Zs.now,n})(),ji=(function(n){z(t,n);function t(e,s){s===void 0&&(s=Yi.now);var i=n.call(this,e,s)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var s=this.actions;if(this._active){s.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=s.shift());if(this._active=!1,i){for(;e=s.shift();)e.unsubscribe();throw i}},t})(Yi),Ql=(function(n){z(t,n);function t(){return n!==null&&n.apply(this,arguments)||this}return t.prototype.flush=function(e){this._active=!0;var s;e?s=e.id:(s=this._scheduled,this._scheduled=void 0);var i=this.actions,r;e=e||i.shift();do if(r=e.execute(e.state,e.delay))break;while((e=i[0])&&e.id===s&&i.shift());if(this._active=!1,r){for(;(e=i[0])&&e.id===s&&i.shift();)e.unsubscribe();throw r}},t})(ji),Ot=new Ql(Jl),Bm=null,is=new ji(ki),tc=is;function ec(n,t){return N(function(e,s){var i=t!=null?t:{},r=i.leading,o=r===void 0?!0:r,a=i.trailing,l=a===void 0?!1:a,c=!1,h=null,d=null,u=!1,f=function(){d==null||d.unsubscribe(),d=null,l&&(x(),u&&s.complete())},g=function(){d=null,u&&s.complete()},m=function(_){return d=At(n(_)).subscribe(bt(s,f,g))},x=function(){if(c){c=!1;var _=h;h=null,s.next(_),!u&&m(_)}};e.subscribe(bt(s,function(_){c=!0,h=_,!(d&&!d.closed)&&(o?x():m(_))},function(){u=!0,!(l&&c&&d&&!d.closed)&&s.complete()}))})}function sc(n){return n instanceof Date&&!isNaN(n)}function nc(n,t,e){n===void 0&&(n=0),e===void 0&&(e=tc);var s=-1;return t!=null&&(zn(t)?e=t:s=t),new gt(function(i){var r=sc(n)?+n-e.now():n;r<0&&(r=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=s?this.schedule(void 0,s):i.complete())},r)})}function Et(n,t,e){t===void 0&&(t=is);var s=nc(n,t);return ec(function(){return s},e)}class X{constructor(){this.subscriptions=[],this._state="initial",this.entities=[]}doActivate(){}doDeactivate(){this.subscriptions.forEach(t=>t()),this.subscriptions=[]}enable(){this._state!=="active"&&(this._state="deactivated",this.activate())}disable(){this._state!=="disabled"&&(this.deactivate(),this._state="disabled")}activate(){this._state!=="disabled"&&(this._state!=="active"&&(this.doActivate(),this._state="active"),this.entities.forEach(t=>t.activate()))}deactivate(){this._state!=="disabled"&&(this._state!=="deactivated"&&(this.doDeactivate(),this._state="deactivated"),this.entities.forEach(t=>t.deactivate()))}getState(){return this._state}addSubscription(t){this.subscriptions.push(t)}addRxSubscription(t){t&&this.subscriptions.push(t.unsubscribe.bind(t))}addChildEntity(t){this.entities.push(t),this._state==="active"&&t.activate()}removeChildEntity(t){this.entities=this.entities.filter(e=>e!==t)}}class ic extends X{constructor(t,e,s,i){super(),this.element=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.hitTestCanvasModel=i,this.normalLayer=new Map,this.extensionLayer=new Map,this.cursorChangedSubject=new R}doActivate(){super.doActivate(),this.canvasInputListener.observeMouseMoveNoDrag().pipe(Et(100,Ot,{trailing:!0})).subscribe(t=>{const e=this.hitTestCanvasModel.resolveCursor(t);if(e!==void 0){this.updateCursor(e);return}t&&(this.normalLayer.forEach(s=>{s.hitTest(t.x,t.y)&&this.updateCursor(s.cursor)}),this.extensionLayer.forEach(s=>{s.hitTest(t.x,t.y)&&this.updateCursor(s.cursor)}))})}setCursorForBounds(t,e,s,i=0){const r=Gs.hitTestOf(e,{extensionY:i});i?this.extensionLayer.set(t,{cursor:s,hitTest:r}):this.normalLayer.set(t,{cursor:s,hitTest:r})}setCursorForCanvasEl(t,e,s){this.observeCursorType(t,e,s)}removeCursorForCanvasEl(t){this.normalLayer.delete(t),this.extensionLayer.delete(t)}observeCursorChanged(){return this.cursorChangedSubject.pipe(_t())}observeCursorType(t,e,s){const i=s?this.canvasBoundsContainer.getBoundsHitTest(t,{extensionY:s}):this.canvasBoundsContainer.getBoundsHitTest(t);s?this.extensionLayer.set(t,{cursor:e,hitTest:i}):this.normalLayer.set(t,{cursor:e,hitTest:i})}updateCursor(t){this.element.style.cursor!==t&&(this.element.style.cursor=t,this.cursorChangedSubject.next(t))}}const rc=n=>{const t=n.canvasArea!==null,e=n.snapshotCanvas!==null,s=n.backgroundCanvas!==null,i=n.mainCanvas!==null,r=n.yAxisLabelsCanvas!==null,o=n.crossToolCanvas!==null,a=n.hitTestCanvas!==null,l=n.chartResizer!==null,c=n.chartContainer!==null,h=n.dynamicObjectsCanvas!==null;return t&&e&&s&&i&&r&&o&&a&&l&&c&&h},oc=(n=>`<div data-element="chartResizer" style="position: relative; min-height: 20px; height: 100%; width: 100%; touch-action: manipulation; z-index: 0;">
10
10
  <div data-element="chartContainer" style="position: absolute; height: 100%; width: 100%;" class="chart chartArea--graph">
11
11
  <div data-element="canvasArea" style="position: relative; height: 100%; width: 100%; touch-action: manipulation;">
12
12
  <canvas data-element="snapshotCanvas"></canvas>
@@ -21,4 +21,4 @@ ${n?` <p style="position: absolute; visibility: hidden;">If you have any sugge
21
21
  `:""} </div>
22
22
  </div>
23
23
  </div>
24
- `);function ac(n){const t=document.createElement("template");return t.innerHTML=oc(n.devexpertsPromoLink),t}function lc(n){const t={},e=Array.from(n.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(s=>{var i;t[(i=s.getAttribute("data-element"))!=null?i:""]=s}),rc(t))return t;throw new Error("Some chart elements are missing")}function cc(n){if(n.length>1){const t=n.reduce((i,r,o)=>{if(o!==n.length-1){const a=n[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,s;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,s=r)}if(s)return s}}const hc=n=>t=>n?new Date(t).setHours(0,0,0,0):t,Le=(n,t={},e,s=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=hc(!!c),u=d(n),f=d((r=(i=fe(e))==null?void 0:i.timestamp)!=null?r:0),p=d((a=(o=wt(e))==null?void 0:o.timestamp)!=null?a:0);return u>p?h?{index:e.length-1+Math.ceil((u-p)/s),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:ot((u-f)/s),exact:!0}:{index:-1,exact:!0}:Yt(e,u,v=>d(v.timestamp))},Rm=n=>{const t=n[0],e=n[n.length-1];return n.length>0&&[t,e].some(s=>s!==void 0&&s.impVolatility!==null&&s.impVolatility!==void 0&&!isNaN(s.impVolatility))},Ni={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},Xi={paintConfig:[Ni],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var dc=Object.defineProperty,Wi=Object.getOwnPropertySymbols,uc=Object.prototype.hasOwnProperty,fc=Object.prototype.propertyIsEnumerable,zi=(n,t,e)=>t in n?dc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,gc=(n,t)=>{for(var e in t||(t={}))uc.call(t,e)&&zi(n,e,t[e]);if(Wi)for(var e of Wi(t))fc.call(t,e)&&zi(n,e,t[e]);return n};class pc{constructor(t,e,s,i){this.series=t,this.config=e,this.yAxisBoundsProvider=s,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,s=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[gc({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:s}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:Ni).color;return{textColor:te(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function mc(n,t){if(n.filter(a=>a!==null).length<=1)return n.map(a=>a.y);const e=t-2,s=n.map((a,l)=>vc(a,l,e)).filter(ri).sort(bc),i=new Array(s.length),r=s.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=s.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=s[a],c=s[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<s.length;a++){const l=s[a],c=s[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const vc=(n,t,e)=>n?{top:n.y-e/2,bottom:n.y+e/2,labelWeight:n.weight,actualIndex:t}:null,bc=(n,t)=>{const e=n.top,s=t.top;return e>s?1:e<s||e===s&&n.labelWeight<t.labelWeight?-1:0};var Cc=Object.defineProperty,yc=Object.defineProperties,wc=Object.getOwnPropertyDescriptors,Vi=Object.getOwnPropertySymbols,Sc=Object.prototype.hasOwnProperty,xc=Object.prototype.propertyIsEnumerable,Ui=(n,t,e)=>t in n?Cc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Gi=(n,t)=>{for(var e in t||(t={}))Sc.call(t,e)&&Ui(n,e,t[e]);if(Vi)for(var e of Vi(t))xc.call(t,e)&&Ui(n,e,t[e]);return n},Zi=(n,t)=>yc(n,wc(t));const se={MAIN:"MAIN"};class _c extends X{constructor(t,e,s,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=s,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new R,this.animFrameId=`anim_cache_${yt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,Ct(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Et(50,Ot,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,s])=>{this.addToGroup(s,t,e)})}updateLabels(t=!1){this.recalculateLabels(),_e(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const s=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=pt(Object.values(i).map(l=>l.getUnorderedLabels())),o=pt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=mc(o,s);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,s){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][s]=t))}updateLabelsCoordinates(t,e){return Zi(Gi({},t),{labels:t.labels.map((s,i)=>Zi(Gi({},s),{lineY:s.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,s){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[s]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var s;const i=(s=this.labelsProviders[t])!=null?s:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Bt=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const $s=()=>{rs.removeEventListener("change",$s),Bt=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),rs.addEventListener("change",$s)};rs.addEventListener("change",$s);const Pc=()=>Bt,Fm=n=>round(Bt*n)/Bt,Mt=n=>ot(Bt*n)/Bt,Ks=n=>el(Bt*n)/Bt,ne=n=>JSON.parse(JSON.stringify(n));function qs(n){return Object.entries(n)}const $i=(n,t)=>{for(const[e,s]of Array.from(n.entries()))if(s===t)return e};function Ki(n){return Object.keys(n)}function qi(n,t){if(Object.is(n,t))return!0;if(typeof n!="object"||n===null||typeof t!="object"||t===null)return!1;const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!qi(n[e[i]],t[e[i]]))return!1;return!0}const Tc=n=>Object.keys(n).length===0&&n.constructor===Object;function Ji(n){n===void 0&&(n={});var t=n.connector,e=t===void 0?function(){return new R}:t,s=n.resetOnError,i=s===void 0?!0:s,r=n.resetOnComplete,o=r===void 0?!0:r,a=n.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,p=!1,v=!1,x=function(){d==null||d.unsubscribe(),d=void 0},_=function(){x(),h=u=void 0,p=v=!1},A=function(){var L=h;_(),L==null||L.unsubscribe()};return N(function(L,j){f++,!v&&!p&&x();var F=u=u!=null?u:e();j.add(function(){f--,f===0&&!v&&!p&&(d=Js(A,l))}),F.subscribe(j),!h&&f>0&&(h=new xe({next:function(B){return F.next(B)},error:function(B){v=!0,x(),d=Js(_,i,B),F.error(B)},complete:function(){p=!0,x(),d=Js(_,o),F.complete()}}),At(L).subscribe(h))})(c)}}function Js(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];if(t===!0){n();return}if(t!==!1){var i=new xe({next:function(){i.unsubscribe(),n()}});return At(t.apply(void 0,D([],m(e)))).subscribe(i)}}const os=(n,t)=>n/t,mt=(n,t)=>n/t,Rt=(n,t)=>n*t,Qi=(n,t)=>(n-t)*100/t,tr=(n,t)=>n*t/100+t,er=n=>Math.log2(n),Qs=n=>Math.pow(2,n);class Mc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new R,this.xChanged=this.changed.pipe(ct(()=>({start:this.xStart,end:this.xEnd})),_t((t,e)=>t.start===e.start&&t.end===e.end),Ji()),this.yChanged=this.changed.pipe(ct(()=>({start:this.yStart,end:this.yEnd})),_t((t,e)=>t.start===e.start&&t.end===e.end),Ji()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+mt(t-this.xStart,this.zoomX)}xPixels(t){return mt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+mt(t-this.yStart,this.zoomY):e.y+e.height-mt(t-this.yStart,this.zoomY)}yPixels(t){return mt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Rt(e+mt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),s=t-e.y;return this.inverseY?Rt(s+mt(this.yStart,this.zoomY),this.zoomY):Rt(e.height-s+mt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return os(e-t,this.getBounds().width)}calculateZoomY(t,e){return os(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,s=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),s&&this.fireChanged()}setYScale(t,e,s=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),s&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const Ac=(n,t)=>!Ki(n).some(e=>n[e]!==t[e]);class Ec{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let s;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Yt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Yt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),s=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else s=t();return s}}class sr{constructor(t,e,s,i){this.dataSeries=t,this.scale=e,this.getAxisType=s,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Ec(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const s=this.percentAnimationHandler.getBaselineForPercent(e);return Qi(t,s);case"logarithmic":return t<=0?t:er(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return tr(t,this.getBaseline());case"logarithmic":return Qs(t);case"regular":return t}}}const ie=16;var Ic=Object.defineProperty,Dc=Object.defineProperties,Lc=Object.getOwnPropertyDescriptors,nr=Object.getOwnPropertySymbols,Oc=Object.prototype.hasOwnProperty,Bc=Object.prototype.propertyIsEnumerable,ir=(n,t,e)=>t in n?Ic(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,rr=(n,t)=>{for(var e in t||(t={}))Oc.call(t,e)&&ir(n,e,t[e]);if(nr)for(var e of nr(t))Bc.call(t,e)&&ir(n,e,t[e]);return n},Rc=(n,t)=>Dc(n,Lc(t));class Oe{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Oe(this.centerUnit,this.close)}}class or extends X{constructor(t,e,s,i,r){var o;super(),this.extentComponent=t,this.id=e,this.htId=s,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=l=>{var c;return(c=this.config.paintConfig[l])!=null?c:this.config.paintConfig[0]},this.getBaseline=(l=this.dataIdxStart)=>{var c,h,d;return(c=this.visualPoints[l])!=null&&c.close&&((h=this.visualPoints[l])==null?void 0:h.close)>=0?(d=this.visualPoints[l])==null?void 0:d.close:1},this.getTextForPoint=l=>`${l.close}`,this.getLastVisualSeriesPoint=()=>{const l=this.visualPoints;if(l.length!==0)return l[this.dataIdxEnd]},this.getLastDataSeriesPoint=()=>{const l=this.visualPoints;return wt(l)};const a=r!=null?r:ne(Xi);this.config=Tt(a,Xi),this.scale=t.scale,this.view=new sr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new pc(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=Hc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=li(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=li(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.pipe(Et(ie,Ot,{trailing:!0,leading:!0}),ct(()=>this.calculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)),_t((t,e)=>t.dataIdxStart===e.dataIdxStart&&t.dataIdxEnd===e.dataIdxEnd)).subscribe(()=>{this.recalculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)})),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const s=rr({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new sr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=s.yAxis.model.fancyLabelsModel.labelsProviders[se.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[se.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(se.MAIN,a,r),s.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(se.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,s)=>({centerUnit:s,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.centerUnit).index,i=Yt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let s=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);s=r.dataIdxStart,i=r.dataIdxEnd}return Cl(this.visualPoints2D,s,i)}}const Fc=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.close>t.high&&(t.high=s.close,t.highIdx=e),s.close<t.low&&(t.low=s.close,t.lowIdx=e)}return t},Hc=n=>({isHighLowActive:()=>n.config.highLowActive,calculateHighLow:t=>{const e=Fc(n.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return Rc(rr({},e),{high:n.view.toAxisUnits(e.high),low:n.view.toAxisUnits(e.low)})}}),kc=n=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(n);return ft.makeDecimal(n,i)};class as extends Oe{constructor(t,e,s,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=s,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),s=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>s?[s,e]:[e,s];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const pe=60,Be=(n,t,e=pe)=>{const s=ar(n,t,e);return{id:yi(s,s),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:s,volume:NaN,expansion:!0,idx:t}},Yc=(n,t,e=pe)=>({close:NaN,timestamp:ar(n,t,e)});function ar(n,t,e=pe){var s,i;const r=Te(t);if(n.length===0)return 0;const o=wt(n);if(r>=n.length&&o)return lr(o,n.length-1,r,e);const a=fe(n);return r<0&&a?lr(a,0,r,e):(i=(s=n[r])==null?void 0:s.timestamp)!=null?i:0}const lr=(n,t,e,s=pe)=>n.timestamp+(e-(t!=null?t:0))*s,tn=(n,t,e,s,i=pe)=>{const r=Be(n,s,i);r.volume=e;let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new as(o,e,r.open,r.close,r.lo,r.hi,ts(r.open,r.close),r)},jc=(n,t,e,s,i=pe)=>{const r=Yc(n,s,i);let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new Oe(o,r.close)};class Nc{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new R,this.dataSetSubject=new R,this.dataRemovedSubject=new R,this.dataPrependSubject=new R,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},s=this.mainDataPoints){const i=Le(t,e,s,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=cc(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?tn(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):jc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Xc=Object.defineProperty,cr=Object.getOwnPropertySymbols,Wc=Object.prototype.hasOwnProperty,zc=Object.prototype.propertyIsEnumerable,hr=(n,t,e)=>t in n?Xc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Vc=(n,t)=>{for(var e in t||(t={}))Wc.call(t,e)&&hr(n,e,t[e]);if(cr)for(var e of cr(t))zc.call(t,e)&&hr(n,e,t[e]);return n};class Uc{constructor(t,e,s=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=s,this.prevState={},this.isColorsChanged=()=>!qi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=Vc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const Gc=(n,t,e,s,i,r,o)=>{const a=Pc(),l=[e*a,s*a,i*a,r*a];let c=n.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=ot(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?ot(u*o):ot(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},dr=(n,{x:t,width:e,activeCandle:s})=>new as(t,e,n.open,n.close,n.hi,n.lo,ts(n.open,n.close),n,!0,en(n,s)),Zc=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,Ll((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,en(n,s),n.close>n.open)},ur=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,ts((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,en(n,s),n.close>n.open)},$c=ur,en=(n,t)=>{const e=t&&t.id===n.id;return e!=null?e:!1},fr=()=>zs,Re=class le{static autoDetectIncrementOfValueRange(t){const e=this.getDigitsInNumber(t);return t===0?.01:Math.pow(10,e-3)}static getDigitsInNumber(t){const e=i=>ot(Math.log10((i^i>>31)-(i>>31)))+1;let s=e(t);return s===1&&t<1&&(s=e(t*1e9)-9),s}static getPriceIncrement(t,e=[]){if(!this.validatePriceIncrementsOrPrecisions(e))return this.DEFAULT_INCREMENT;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;const i=1e-6;for(;s<e.length&&t>e[s]+Math.min(e[s-1],e[s+1])*i;)s+=2;return s>=e.length||t<e[s]-Math.min(e[s-1],e[s+1])*i?e[s-1]:Math.min(e[s-1],e[s+1])}static getPricePrecision(t,e){if(!this.validatePriceIncrementsOrPrecisions(e))return 0;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;for(;s<e.length&&t>e[s];)s+=2;return Math.round(e[s-1])}static roundPriceToIncrement(t,e,s){const i=le.getPriceIncrement(s||t,e);return ft.roundToNearest(t,i)}static computePrecisions(t){const e=[...t];for(let s=0;s<t.length;s+=2)e[s]=le.calculatePrecision(t[s]);for(let s=1;s<t.length;s+=2)e[s]=t[s]+Math.min(t[s-1],t[s+1])*le.RELATIVE_EPS;return e}static calculatePrecision(t){let e=t>1?Math.abs(Math.floor(t)-t):t;for(let s=0;s<le.MAXIMUM_PRECISION;s++){const i=Math.floor(e+.5),r=Math.abs(e*le.RELATIVE_EPS);if(i>=e-r&&i<=e+r)return s;e*=10}return le.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(t){return!(t.length===0||!Array.isArray(t)||t.findIndex(e=>e!==0)===-1)}};Re.DEFAULT_INCREMENT=.01,Re.DEFAULT_PRECISION=2,Re.RELATIVE_EPS=1e-8,Re.MAXIMUM_PRECISION=10;let me=Re;const Kc=(n,t)=>{var e;const s=(e=wt(t))!=null?e:1;return Math.pow(10,-s)};var qc=Object.defineProperty,Jc=Object.defineProperties,Qc=Object.getOwnPropertyDescriptors,gr=Object.getOwnPropertySymbols,th=Object.prototype.hasOwnProperty,eh=Object.prototype.propertyIsEnumerable,pr=(n,t,e)=>t in n?qc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sh=(n,t)=>{for(var e in t||(t={}))th.call(t,e)&&pr(n,e,t[e]);if(gr)for(var e of gr(t))eh.call(t,e)&&pr(n,e,t[e]);return n},nh=(n,t)=>Jc(n,Qc(t));const ih=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:n.scale.xStart,s=t?t.xEnd:n.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=n.calculateDataViewportIndexes(e,s),o=n.visualPoints.slice(i,r+1),a=mr(o),l=()=>{var c,h;return(h=(c=n.visualPoints[i])==null?void 0:c.close)!=null?h:1};return nh(sh({},a),{low:n.view.toAxisUnits(a.low,l),high:n.view.toAxisUnits(a.high,l)})}}),mr=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.high>t.high&&(t.high=s.high,t.highIdx=e),s.low<t.low&&(t.low=s.low,t.lowIdx=e)}return t};class rh{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){oh(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const oh=(n,t,e,s)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=vr(i),o=s.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=n.calculateZoomY(t.yStart,t.yEnd)};function vr(n){if(n.length===0)return ah();let t=n[0].high,e=n[0].low;return n.forEach(s=>{isFinite(s.high)&&s.high>=t&&(t=s.high),isFinite(s.low)&&s.low<=e&&(e=s.low)}),{low:e,high:t}}const ah=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),br=(n,t)=>n/t,lh=(n,t)=>n/t,ch=(n,t)=>n*t,Cr=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=br(e,s),r=n.yEnd-n.yStart;t.zoomY=lh(t.zoomX,i);const o=t.zoomY/s,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},hh=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=br(e,s),r=n.xEnd-n.xStart;t.zoomX=ch(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},dh=(n,t)=>{const e=n.xStart;n.xStart=t,n.xEnd=n.xEnd+(t-e)},uh=(n,t)=>{const e=n.yStart;n.yStart=t,n.yEnd=n.yEnd+(t-e)},yr=(n,t,e,s,i)=>{const r=(t.xEnd-t.xStart)*s,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=n.calculateZoomX(t.xStart,t.xEnd),t},fh=(n,t,e,s)=>yr(n,t,1,e,s),gh=Ae,ph=.9,mh=(n,t,e,s)=>{t.currentAnimation&&t.currentAnimation.animationInProgress&&t.currentAnimation.getProgress()>ph&&(t.currentAnimation.finishAnimation(),t.currentAnimation=void 0),s&&s.doAutoYScale(e),ls(n,t,e)},ls=(n,t,e)=>{const s=n.startViewportMovementAnimation(t,{duration:gh,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},ue,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=s};var vh=Object.defineProperty,bh=Object.defineProperties,Ch=Object.getOwnPropertyDescriptors,wr=Object.getOwnPropertySymbols,yh=Object.prototype.hasOwnProperty,wh=Object.prototype.propertyIsEnumerable,Sr=(n,t,e)=>t in n?vh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,re=(n,t)=>{for(var e in t||(t={}))yh.call(t,e)&&Sr(n,e,t[e]);if(wr)for(var e of wr(t))wh.call(t,e)&&Sr(n,e,t[e]);return n},xr=(n,t)=>bh(n,Ch(t));const Sh=new R,xh=new R,_h=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class _r extends Mc{constructor(t,e,s){super(),this.config=t,this.getBounds=e,this.canvasAnimation=s,this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.autoScaleZoomSubscription=null,this.autoScalePanSubscription=null,this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=ne(t.scale),this.autoScaleModel=new rh(this),this.offsets=this.config.components.offsets,this.initAutoScaleThrottling()}doActivate(){super.doActivate(),this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){this.autoScaleZoomSubscription&&(this.autoScaleZoomSubscription.unsubscribe(),this.autoScaleZoomSubscription=null),this.autoScalePanSubscription&&(this.autoScalePanSubscription.unsubscribe(),this.autoScalePanSubscription=null),super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=re(re({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,s=!1,i){const r=this.config.scale.disableAnimations||s;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();yr(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const s=this.export();fh(this,s,e,t),this.zoomXTo(s,t,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.currentAnimation=void 0,this.canvasAnimation.forceStopAnimation(ue),this.doAutoScale())}zoomXTo(t,e,s){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Cr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),s?this.apply(o):((i=this.currentAnimation)==null||i.tick(),ls(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const s=this.getBounds().width,i=.001;if(s>0){const r=os(this.config.components.chart.minCandles,s),a=t!==r&&t-r<=i&&e,l=os(s/this.config.components.chart.minWidth,s),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,s=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=xr(re({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Cr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),s||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),Me?mh(this.canvasAnimation,this,l,this.state.auto?this.autoScaleModel:void 0):ls(this.canvasAnimation,this,l)))}setXScaleWithoutYScale(t){var e;const s=this.export(),i=t.slice(Math.max(t.length-this.state.defaultViewportItems,0)),r=i[i.length-1],o=r.startUnit+r.width+this.offsets.right,a=o-this.getBounds().width*this.zoomX,l=xr(re({},s),{xStart:a,xEnd:o}),c=this.scalePostProcessor(s,l);this.state.auto&&this.autoScaleModel.doAutoYScale(c),(e=this.currentAnimation)==null||e.tick(),ls(this.canvasAnimation,this,c)}setYScale(t,e,s=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio&&this.initialViewportValidSubject.getValue()){this.setLockedYScale(t,e,s,i);return}super.setYScale(t,e,s);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,s=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,s);const o=this.export(),a=this.scalePostProcessor(i,o);hh(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),s=re({},e);this.haltAnimation(),dh(e,t);const i=this.scalePostProcessor(s,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();uh(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Ac(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}initAutoScaleThrottling(){this.autoScaleZoomSubscription=Sh.pipe(Et(ie,Ot,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=re({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)}),this.autoScalePanSubscription=xh.pipe(Et(ie,Ot,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=re({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)})}}class Ph extends _r{constructor(t,e,s,i){super(e,s,i),this.delegate=t,this.config=e,this.getBounds=s}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Th=es().colors;class Gt extends or{constructor(t,e,s,i,r,o,a,l,c=Th){super(t,e,s),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=_h(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new R,this.meanCandleWidth=zs,this._instrument=o,this.instrument=o,this.highLowProvider=ih(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=me.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.startUnit).index,i=Yt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}applyPriceMovement(){const t=wt(this.dataPoints);t&&(this.lastPriceMovement=ts(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=mr(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var s,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(s=this.candleWidthByChartType[r])!=null?s:fr;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,p=(i=this.candlesTransformersByChartType[r])!=null?i:dr;o.push(p(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,s)=>e+s.width,0)/t.length:this.meanCandleWidth=zs}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Hm(n){switch(n){case"line":case"area":return!0;default:return!1}}class Mh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=!!i.color;if(s instanceof Gt){const a=pt(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=s.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:s.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=s.extentComponent.getBounds(),c=a[0],h=s.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],p=a[d],v=s.view.toX(p.centerUnit),x=s.view.toY(p.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(ot(v),_),t.moveTo(ot(v),x);else if(f===void 0){t.lineTo(ot(v),x),t.stroke(),t.lineTo(ot(v),_),t.lineTo(ot(h),_),t.closePath();let A;i.color?t.fillStyle=i.color:t.fillStyle=s.colors.areaTheme.startColor&&s.colors.areaTheme.stopColor?(A=t.createLinearGradient(0,0,0,l.height),A.addColorStop(0,s.colors.areaTheme.startColor),A.addColorStop(1,s.colors.areaTheme.stopColor),A):"",o||t.fill()}else t.lineTo(v,x)}}}}function Pr(n,t,e,s,i,r=4,o=!0,a=!1){n.save(),n.beginPath(),n.moveTo(t+r,e),n.lineTo(t+s-r,e),n.quadraticCurveTo(t+s,e,t+s,e+r),n.lineTo(t+s,e+i-r),n.quadraticCurveTo(t+s,e+i,t+s-r,e+i),n.lineTo(t+r,e+i),n.quadraticCurveTo(t,e+i,t,e+i-r),n.lineTo(t,e+r),n.quadraticCurveTo(t,e,t+r,e),n.closePath(),o&&n.fill(),a&&n.stroke(),n.restore()}function Ah(n,t,e,s,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,p=c==="right"?h:-h,v=h;n.save(),n.beginPath(),l?n.moveTo(r+p,o):n.moveTo(r,o),l?(n.lineTo(r+f-p,o),n.quadraticCurveTo(r+f,o,r+f,o-v),n.lineTo(r+f,e+v),n.quadraticCurveTo(r+f,e,r+f-p,e),n.lineTo(t+p,e)):(n.lineTo(r+f,o),n.lineTo(r+f,e),n.lineTo(t,e)),l?(n.quadraticCurveTo(t,e,t-p/3,e+v/3),n.lineTo(s+p/3,i-v/3),n.quadraticCurveTo(s,i,s+p/3,i+v/3),n.lineTo(r-p/3,o-v/3),n.quadraticCurveTo(r,o,r+p/3,o)):(n.lineTo(s,i),n.lineTo(r,o)),n.closePath(),d&&n.fill(),u&&n.stroke(),n.restore()}function Eh(n,t,e,s,i,r=1,o=[]){n.save(),n.setLineDash(o),n.lineWidth=r,n.beginPath(),n.moveTo(t,e),n.lineTo(s,i),n.stroke(),n.closePath(),n.restore()}function oe(n,t){n.save(),n.lineWidth%2&&n.translate(.5,.5),t(),n.restore()}function Tr(n,t,e){const s=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);n.fillRect(s,i,r,o)}const Zt=(n,t)=>{n.beginPath(),n.rect(t.x,t.y,t.width,t.height),n.clip(),n.closePath()},km=n=>Array.isArray(n[0])?n:[n];class Ih{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,s){const i=t.ctx,r=s&&this.paneManager.panes[s];e&&(i.save(),r&&Zt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const s=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||s&&!Tc(s)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const $t=(n,t,e,s,i=t)=>{s.hoverWidth?n.lineWidth=s.hoverWidth:e.highlighted?n.lineWidth=t!==i?t+1:i:n.lineWidth=t};class Dh{constructor(t){this.config=t}setFillStyle(t,e,s,i){if(e.color)t.strokeStyle=e.color;else{const r=s.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.barLineWidth,s,i),oe(t,()=>{for(const o of r){this.setFillStyle(t,i,s,o),t.beginPath();const a=s.view.toX(o.centerUnit),l=s.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(s.view),f=Mt(s.view.xPixels(o.width)/2),p=s.view.toY(o.close),v=s.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,p),t.lineTo(a+f,p),t.moveTo(l,v),t.lineTo(a,v),t.stroke()}})}}}class Lh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,s,i){if(i!==void 0&&s instanceof Gt){const r=pt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(T.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],p=s.view.toX(c.centerUnit),v=s.view.toX(d.centerUnit),x=s.view.toY(d.close),_=u?s.view.toY(u.close)<l:!1,A=x<l;if(u!==void 0&&_!==A){Mr(t,s,i,_);const L=s.view.toX(u.centerUnit),j=s.view.toY(u.close),F=v-L,B=x-j,Y=F/B,$=x-l,W=Y*$,U=L+(F-W);t.lineTo(U,l),t.stroke(),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(U,l)}u===void 0?(t.beginPath(),t.moveTo(v,x)):f===void 0?(Mr(t,s,i,A),t.lineTo(v,x),t.stroke(),t.lineTo(v,l),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(p,l),t.lineTo(v,l),t.strokeStyle=s.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(v,x)}}}}const Mr=(n,t,e,s)=>{e.color?(n.fillStyle=e.color,n.strokeStyle=e.color):(n.fillStyle=s?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,n.strokeStyle=s?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Oh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.candleLineWidth,s,i,this.config.candleLineWidth),oe(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=s.colors;a&&l&&this.drawCandle(t,i,s,o)}})}}drawCandle(t,e,s,i){const{candleTheme:r,activeCandleTheme:o}=s.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=s.view.toX(i.startUnit),d=s.view.xPixels(i.width),u=i.bodyHeight(s.view),[f,p,v,x]=i.yBodyKeyPoints(s.view),_=p===v?p+1:v,A=f===x?f+1:x,L=l[`${a}Color`],j=a==="none"?L:l[`${a}WickColor`];t.fillStyle=L,e.color?t.strokeStyle=e.color:t.strokeStyle=j;const F=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?A:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?A:_),t.moveTo(h+1,p),t.lineTo(h+1,_),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,f,A,p,_),c||(t.beginPath(),t.moveTo(h+Y,p),t.lineTo(h+Y,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,p+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(s.view);this.drawCandlesWicks(t,Y,f,A,p,_);const $=this.config.candlePaddingPercent,W=Math.max(d*$/2,this.pixelLength),U=h+W,G=d-W*2;if(!c){e.color&&(t.fillStyle=e.color);const V=e.hoverWidth?d+W:G,Q=e.hoverWidth?u+e.hoverWidth+W:u;t.fillRect(U,p,V,Q)}F&&this.drawCandleBorder(t,e,l,i,U+this.halfLineWidthCU,p+this.halfLineWidthCU,G-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,s,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,s),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,s,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?s[`${c}Color`]:s[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class Bh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof Gt){const r=e.flat(),o=s.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=s.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(s.view),f=s.view.toY(l.close),p=Mt(s.view.xPixels(l.width));t.fillRect(u,f,p,h);const v=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(v.addColorStop(0,d[`${c}Cap`]),v.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=v),p===0?(t.beginPath(),t.strokeStyle=v,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,p,a-f-h)}}}}class Rh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.lineWidth,s,i,this.config.selectedWidth);const o=s.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=s.view.toX(l.centerUnit),u=s.view.toY(l.close),f=s.view.toX(c.centerUnit),p=s.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,p),t.stroke()}}}}const Fh=1.5;class Hh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=i.hoverWidth?i.hoverWidth/2:Fh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of pt(e)){t.beginPath();const l=s.view.toX(a.centerUnit),c=s.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const kh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Yh{constructor(t,e,s){this.drawer=t,this.config=e,this.chartBounds=s}draw(t,e,s,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,s,i),this.afterDraw(t,s))}beforeDraw(t){t.restore(),t.save(),Zt(t,this.chartBounds())}isChartTypeAllowed(){return kh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Zt(t,e.scale.getBounds())}}class jh{constructor(t){this.chartModel=t}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(ot(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(mt(h.width,u)),p=Mt(h.bodyHeight(this.chartModel.scale)),v=h.xCenter(this.chartModel.scale)-f/2,x=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,A=Mt(f*_/2),L=v+A,j=f-A*2;t.fillRect(L,x,j,p)}})})}}const Nh=(n,t,e,s)=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);s===0?t.moveTo(o,a):t.lineTo(o,a)},Ar=(n,t,e)=>{n.length!==0&&n.forEach((s,i)=>{Nh(s,t,e,i)})},Xh=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Wh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,zh=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,Vh=n=>Xh.exec(n),Uh=n=>Wh.exec(n),Ym=n=>zh.exec(n);function Gh(n){const t=Vh(n)||Uh(n);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(s){return parseInt(s,16)}):e}const Er={};function Zh(n,t){let e=Er[n+t];if(!e){const s=Gh(n);e=s&&"rgba("+s.join(",")+","+t+")",Er[n+t]=e}return e}const Ir="#383838";class $h{constructor(){}draw(t,e,s,i){const r=s.config.additionalVisibilityPredicatesMap,o=(r==null?void 0:r.showLine)!==void 0?r.showLine:s.config.visible,a=(r==null?void 0:r.showCloud)!==void 0?r.showCloud:s.config.visible;o&&e.forEach((l,c)=>{var h;const d=s.getPaintConfig(c);$t(t,d.lineWidth,s,i,d.hoveredLineWidth);const u=(h=i.color)!=null?h:d.color;t.strokeStyle=u,this.drawLine(t,l,s.view)}),a&&s.linkedDataSeriesModels.forEach((l,c)=>{const h=l.config.additionalVisibilityPredicatesMap,d=(h==null?void 0:h.showCloud)!==void 0?h.showCloud:l.config.visible;if(Dr(l.config.type)&&Dr(s.config.type)&&d){const u=[],f=s,p=f.getSeriesInViewport(f.scale.xStart-1,f.scale.xEnd+1),v=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1);p.forEach((x,_)=>{var A,L;const j=Math.min(x.length,(L=(A=v[_])==null?void 0:A.length)!=null?L:0);for(let Y=0;Y<j;Y++){const $=[x[Y].clone(),v[_][Y].clone()];u.push({diffPoints:$})}const F=f.getPaintConfig(_).color,B=l.getPaintConfig(c).color;this.drawDifference(t,F,B,u,f,l,i,r)})}})}drawLine(t,e,s){t.beginPath(),Ar(e,t,s),t.stroke()}drawDifference(t,e,s,i,r,o,a,l){const[c,h]=[[],[]];i.forEach(x=>{const[_,A]=x.diffPoints;c.push(_),h.push(A)});const d=this.mapDataSeriesDiffPointsIntoPoints(c,r.view),u=this.mapDataSeriesDiffPointsIntoPoints(h,o.view),f=l==null?void 0:l.backgroundColor,p=f!==void 0?f:s,v=f!==void 0?f:e;this.fillCloud(t,p,d,u,a,l),this.fillCloud(t,v,u,d,a,l)}fillCloud(t,e,s,i,r,o){var a,l,c,h;t.save(),t.beginPath();const d=(l=(a=fe(s))==null?void 0:a.x)!=null?l:0,u=(h=(c=wt(s))==null?void 0:c.x)!=null?h:0;t.lineTo(d,0),s.forEach(p=>{t.lineTo(p.x,p.y)}),t.lineTo(u,0),t.closePath(),t.clip(),t.beginPath(),s.forEach((p,v)=>{v===0?t.moveTo(p.x,p.y):t.lineTo(p.x,p.y)}),i.slice().reverse().forEach(p=>{t.lineTo(p.x,p.y)}),t.closePath();const f=(o==null?void 0:o.backgroundColor)!==void 0;r.color?t.fillStyle=r.color:f?t.fillStyle=e!=null?e:Ir:t.fillStyle=Zh(e!=null?e:Ir,.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(s=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const Dr=n=>n==="DIFFERENCE";class Kh{constructor(){}draw(t,e,s,i){const r=s.view.toY(0);e.forEach((o,a)=>{var l;const c=s.getPaintConfig(a);$t(t,c.lineWidth,s,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.moveTo(d,ot(r)),t.lineTo(d,ot(u))}),t.stroke()})}}class qh{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);$t(t,l.lineWidth,s,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,s.view)})}drawLinePath(t,e,s){t.beginPath(),Ar(e,t,s),t.stroke()}}class Jh{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class Qh{constructor(t){this.config=t}draw(t,e,s,i){t.save(),e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=s.getTextForPoint(h),u=Pt(d,t,c),f=Nt(c,t),p=s.view.toX(h.centerUnit)-u/2,v=s.view.toY(h.close)+f;t.fillText(d,p,v)})}),t.restore()}}class td{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=s.view.toX(c.centerUnit),d=s.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,s,i){t.beginPath(),t.moveTo(e-i/2,s),t.lineTo(e,s-i),t.lineTo(e+i/2,s),t.fill()}}const cs="resized_local",hs="draw",jm="draw_last_candle",ve={width:20,height:20};class Lr{constructor(t,e,s,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=s,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=sn;var a;i.push(this),this.parent=nd(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:s}=t,i=window.devicePixelRatio;this.canvas.style.height=s+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=s*i,this.width=e,this.height=s,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const s=e.height;s!==this.height&&(t.style.height=s+"px",this.height=s,t.height=s,this.prevHeight=s)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ve.width&&this.height>ve.height}}const sn={name:"candle"},ed={candle:sn,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function sd(n,t,e,s,i,r,o){var a;const l=ae(n,t,i,r,o,e);return l.type=(a=ed[s])!=null?a:sn,l}function ae(n,t,e,s,i,r,o){const a=new Lr(n,t,s,i,r,o);return Or(a,e),a}function Or(n,t){const e=n.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",n.width=t.fixedSize.width,n.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function nd(n){let t=n;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const ds="HIT_TEST_",zm=null;class id{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${yt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(s=>{s.indexOf(ds)!==-1&&this.drawersMap[s].draw()})},t.on(hs,s=>{e.wasResized()&&(this.canvasIdsList&&(s&&s.length!==0?this.canvasIdsList=this.canvasIdsList.concat(s):this.canvasIdsList=void 0),Kn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(ds)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(ds)===-1){const s=this.drawersMap[e];if(!t||t.length===0){s.draw();return}ml(t,s.getCanvasIds()).length&&s.draw()}})}isDrawable(){var t,e,s,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ve.width&&((i=(s=this.chartResizeHandler.previousBCR)==null?void 0:s.width)!=null?i:0)>ve.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=yt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(s);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(s);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const s=this.drawingOrder.indexOf(e);s!==-1&&this.drawingOrder.splice(s,1)}})}reorderDrawers(t){this.drawingOrder=oi(this.drawingOrder,t)}}class Br{static paneResizer(t){return`PANE_RESIZER_${t}`}}const rd=7;class od{constructor(t,e,s,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=s,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Zt(t,e.getBounds()),e.dataSeries.forEach(s=>this.drawSeries(t,s)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const s=e.config.type,i=this.seriesDrawers[s];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:rd};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const Rr={dragPredicate:()=>!0};class Fr extends X{constructor(t,e,s,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=s,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class us extends Fr{constructor(t,e,s,i,r=Rr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const ad="BASELINE_RESIZER";class ld extends X{constructor(t,e,s,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=s,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Gs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(T.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&Kl(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new us(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(T.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(T.CHART),e=this.canvasBoundContainer.getBounds(T.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const s=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=s,this.canvasBoundContainer.bounds[ad]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(T.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const cd=n=>{var t;try{const e=Pe(n.close,n.open,n.hi,n.lo);if(!isFinite(e))throw new Error("Received candle without any price");const s=Pe(n.hi,Math.max(n.open,n.close),e),i=Pe(n.lo,Math.min(n.open,n.close),e),r=Pe(n.open,n.lo,e),o=Pe(n.close,n.hi,e),a=Number.isNaN(n.vwap)?void 0:n.vwap;return{id:n.id,hi:s,lo:i,open:r,close:o,timestamp:n.timestamp,volume:(t=n.volume)!=null?t:0,expansion:n.expansion,idx:n.idx,impVolatility:n.impVolatility,vwap:a,typicalPrice:n.typicalPrice}}catch(e){console.warn(e);return}},Fe=(n,t=0)=>{for(let e=t;e<n.length;++e)n[e].idx=e},Hr=n=>{n.forEach(t=>{t.idx=void 0})},hd=n=>n!==void 0;class dd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0),o=pt(e),a=s.getPaintConfig(0);$t(t,a.lineWidth,s,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,p,v,x,_;const A=ud(o,c),L=A&&l.close<A;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(L?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!L&&l.close<0&&(t.strokeStyle=(p=i.color)!=null?p:a.multiplyColors[1]||a.color||"#FF00FF"),L&&l.close>0&&(t.strokeStyle=(v=i.color)!=null?v:a.multiplyColors[2]||a.color||"#FF00FF"),!L&&l.close>0&&(t.strokeStyle=(x=i.color)!=null?x:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const j=s.view.toX(l.centerUnit),F=s.view.toY(l.close);t.moveTo(j,r),t.lineTo(j,F),t.stroke()})}}const ud=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0},fd=(n,t)=>{let e=0;return(...s)=>{clearTimeout(e),e=+setTimeout(()=>n(...s),t)}};class gd{constructor(){}draw(t,e,s,i){const r=pt(e),o=s.getPaintConfig(0);$t(t,o.lineWidth,s,i,o.hoveredLineWidth),t.lineCap="round",r.forEach((a,l)=>{var c,h;const d=pd(r,l)||r[0],u=d&&a.close<d.close;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(h=i.color)!=null?h:(u?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF";const f=s.view.toX(a.centerUnit),p=s.view.toY(a.close),v=s.view.toX(d.centerUnit),x=s.view.toY(d.close);t.beginPath(),t.moveTo(v,x),t.lineTo(f,p),t.stroke();return}})}}const pd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t]:void 0},be="#FF00FF";class md{constructor(){}draw(t,e,s,i){const r=pt(e),o=s.getPaintConfig(0),a=i.hoverWidth?i.hoverWidth/2:o.lineWidth;r.forEach((l,c)=>{var h,d,u,f,p,v,x,_;const A=vd(r,c),L=A&&l.close<A;if(((h=o.multiplyColors)==null?void 0:h.length)===2){t.fillStyle=(d=i.color)!=null?d:(L?o.multiplyColors[1]:o.multiplyColors[0])||o.color||be;const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.arc(B,Y,a,0,Math.PI*2),t.fill();return}if(((u=o.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.fillStyle=(f=i.color)!=null?f:o.multiplyColors[0]||o.color||be),!L&&l.close<0&&(t.fillStyle=(p=i.color)!=null?p:o.multiplyColors[1]||o.color||be),L&&l.close>0&&(t.fillStyle=(v=i.color)!=null?v:o.multiplyColors[2]||o.color||be),!L&&l.close>0&&(t.fillStyle=(x=i.color)!=null?x:o.multiplyColors[3]||o.color||be),t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.arc(B,Y,a,0,Math.PI*2),t.fill();return}t.fillStyle=(_=i.color)!=null?_:o.color||be,t.beginPath();const j=s.view.toX(l.centerUnit),F=s.view.toY(l.close);t.arc(j,F,a,0,Math.PI*2),t.fill()})}}const vd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0};var bd=Object.defineProperty,kr=Object.getOwnPropertySymbols,Cd=Object.prototype.hasOwnProperty,yd=Object.prototype.propertyIsEnumerable,Yr=(n,t,e)=>t in n?bd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,jr=(n,t)=>{for(var e in t||(t={}))Cd.call(t,e)&&Yr(n,e,t[e]);if(kr)for(var e of kr(t))yd.call(t,e)&&Yr(n,e,t[e]);return n};class wd{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class Sd extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,p){super(),this.chartModel=t,this.canvasModel=e,this.config=s,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=p,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=x=>{var _;return(_=this.barTypeValues.find(A=>A===x))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new ld(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const v=new od(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(v,ds+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new Uc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(T.PANE_UUID(K),s.components.chart.cursor),this.dataSeriesDrawer=new Ih(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(fd(()=>{this.backgroundDrawerPredicateSubject.next(!1)},ie))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",dr),this.registerCandlesTransformer("trend",ur),this.registerCandlesTransformer("hollow",Zc),this.registerCandlesTransformer("line",$c)}get barTypeValues(){return Ki(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Oh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Dh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Rh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new Hh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Mh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new Lh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new Bh(this.config.components.chart.histogram));const e=T.PANE_UUID(K),s=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new qh),this.registerDataSeriesTypeDrawer("LINEAR_TREND",new gd),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Kh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new dd),this.registerDataSeriesTypeDrawer("POINTS",new Jh),this.registerDataSeriesTypeDrawer("TREND_POINTS",new md),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Yh(new jh(this.chartModel),this.config,s)),this.registerDataSeriesTypeDrawer("TEXT",new Qh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new td),this.registerDataSeriesTypeDrawer("DIFFERENCE",new $h)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(jr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,s=!0){return this.chartModel.setTimestampRange(t,e,s)}setXScale(t,e,s=!0){return this.scale.setXScale(t,e,s)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=jr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=s,this.chartModel.setAllSeries({candles:t.candles,instrument:s},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Hr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(s)}setSecondarySeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,s);if(this.updatePriceIncrementsIfNeeded(s),i)return i}setAllSeries(t,e=[]){var s;const i=(s=t.instrument)!=null?s:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,s=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,s)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!me.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[me.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}function Nr(n,t){return t===void 0&&(t=is),N(function(e,s){var i=null,r=null,o=null,a=function(){if(i){i.unsubscribe(),i=null;var c=r;r=null,s.next(c)}};function l(){var c=o+n,h=t.now();if(h<c){i=this.schedule(void 0,c-h),s.add(i);return}a()}e.subscribe(bt(s,function(c){r=c,o=t.now(),i||(i=t.schedule(l,n),s.add(i))},function(){a(),s.complete()},void 0,function(){r=i=null}))})}class Xr extends Gt{constructor(t,e,s,i,r,o,a,l,c,h){super(e,s,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var xd=Object.defineProperty,Wr=Object.getOwnPropertySymbols,_d=Object.prototype.hasOwnProperty,Pd=Object.prototype.propertyIsEnumerable,zr=(n,t,e)=>t in n?xd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Td=(n,t)=>{for(var e in t||(t={}))_d.call(t,e)&&zr(n,e,t[e]);if(Wr)for(var e of Wr(t))Pd.call(t,e)&&zr(n,e,t[e]);return n};const Md=(n,t,e,s)=>{var i,r,o,a;const l=Td({},n),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=yl(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=n.xStart,u=n.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Rt(s.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Ad=n=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const s=t.slice(Math.max(t.length-n.state.defaultViewportItems,0)),i=s[0],r=s[s.length-1];n.setXScale(i.startUnit,r.startUnit+r.width+n.offsets.right)}e.yScale&&n.doAutoScale(!0),n.fireChanged()}},Ed=(n,t)=>(e,s=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=s===null?0:t.mainCandleSeries.meanCandleWidth*2,c=s?o-l:o+l,h=s?a+l:a-l;n.setXScale(c,h)};var Id=Object.defineProperty,Dd=Object.defineProperties,Ld=Object.getOwnPropertyDescriptors,Vr=Object.getOwnPropertySymbols,Od=Object.prototype.hasOwnProperty,Bd=Object.prototype.propertyIsEnumerable,Ur=(n,t,e)=>t in n?Id(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,He=(n,t)=>{for(var e in t||(t={}))Od.call(t,e)&&Ur(n,e,t[e]);if(Vr)for(var e of Vr(t))Bd.call(t,e)&&Ur(n,e,t[e]);return n},nn=(n,t)=>Dd(n,Ld(t));class Rd{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,s)=>nn(He({},e),{[s]:0}),{})}createColorPool(t){return t.reduce((e,s,i)=>(e[`color${i}`]=nn(He({},ne(this.config.colors)),{lineTheme:He({},s.lineTheme),areaTheme:He({},s.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,s="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,s=i);return this.usedChartColors[s]=this.usedChartColors[s]+1,this.symbolsToColorKeys[t]=s,this.secondaryChartColorsPool[s]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var s,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=nn(He({},e),{lineTheme:Object.assign(r.lineTheme,(s=o.lineTheme)!=null?s:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Fd=Object.defineProperty,Gr=Object.getOwnPropertySymbols,Hd=Object.prototype.hasOwnProperty,kd=Object.prototype.propertyIsEnumerable,Zr=(n,t,e)=>t in n?Fd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,fs=(n,t)=>{for(var e in t||(t={}))Hd.call(t,e)&&Zr(n,e,t[e]);if(Gr)for(var e of Gr(t))kd.call(t,e)&&Zr(n,e,t[e]);return n};class Yd extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=s,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new R,this.mainInstrumentChangedSubject=new R,this.offsetsChanged=new R,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(cd).filter(hd),{sortCandles:p}=this.config.components.chart;return p?p(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new Rd(this.config);const d=new Xr(this.chartBaseModel,this.paneManager.panes[K].mainExtent,yt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new wd,this.candlesTransformersByChartType,this.candleWidthByChartType,fs({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Md(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Ad(o),this.timeFrameViewportTransformer=Ed(o,this),this.pane=this.paneManager.panes[K]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(K)).pipe(_t(Hi)).subscribe(t=>{this.handleChartResize(t)})),this.addRxSubscription(this.scale.changed.pipe(Nr(ie)).subscribe(()=>this.paneManager.yExtents.forEach(t=>t.yAxis.updateOrderedLabels(!0))))}handleChartResize(t){if(t.width>ve.width&&t.height>ve.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),s=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=s;return}if(s!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Rt(s-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=s,this.prevChartWidth=e;return}const i=Rt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=s,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(s=>{const i=s.dataPoints;return Hr(i),{candles:i,instrument:s.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,s=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,s&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var s;this.mainCandleSeries.instrument=(s=t.instrument)!=null?s:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Fe(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doBasicXScale(){this.scale.setXScaleWithoutYScale(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=fs({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const s=[t,...e];if(!this.candleSeries.every(l=>s.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Kr(this.mainCandleSeries.dataPoints,i),o=r.candles;Fe(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),p=Kr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(p,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candleSeries.forEach(l=>{l.recalculateDataViewportIndexes()}),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(s=>{const i=Yt(s.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;s.dataPoints=s.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=fs(fs({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const s=new Gt(this.paneManager.panes[K].mainExtent,yt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return s.config.type="line",this.candleSeries.push(s),s}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[K].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const s=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)s.push(a);else{let l=$r(e,o,-1);if(l||(l=$r(e,o,1)),l){const c=Ol(l,o,!0);s.push(c)}}}),s}updateSecondaryCandleSeriesConfig(t,e,s){const i=Tt(t,es().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=s,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),s=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=s.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,s=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,s)}candleFromUnit(t,e=!1,s=this.mainCandleSeries){var i,r;const o=Yt(s.visualPoints,t,d=>d.startUnit),a=s.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Te((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Be(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Be(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},s=this.mainCandleSeries){const i=s.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(s=>s.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(s=>s.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,s,i;const r=t-((i=(s=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:s.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,s=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,s)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return wt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return wt(t)}getMaxCandlesFitLength(){return ot(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((s,i)=>{const r=i.timestamp,o=Le(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,s[o.index]=i),s},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}isLastCandleInViewport(){const t=this.getLastCandle();return t&&t.idx?this.isCandleInViewport(t.idx):!1}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const s=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Le(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const p=f>=o.length-1,v=c&&h.timestamp<c.timestamp;if(p&&!v&&(c=h),a&&c&&s&&l){const x=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:fr;this.scale.moveXStart(this.scale.xStart+x(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return Ct(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=this.getCandles(),e=0,s){const i=this.getCandlesCount(),r=s!=null?s:i+this.FAKE_CANDLES_DEFAULT;t=t.slice(Math.max(0,e),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Be(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=e;c<l;c++)a.push(Be(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...t,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const s=t.slice(),i=[];return e.forEach(r=>{const a=Le(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?s[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...s]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const s=this.findSeriesBySymbol(e);if(s.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}s.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Fe(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const s=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(s<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,s).concat(e.dataPoints.slice(i+1)),Fe(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(s=>this.removeCandleByIdx(this.candleIdxFromId(s,e)))}addCandlesById(t,e,s){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=s.dataPoints.slice(0,i),o=s.dataPoints.slice(i);s.dataPoints=r.concat(t).concat(o),Fe(s.dataPoints),s.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const $r=(n,t,e)=>{if(t>=n.length)return n[n.length-1];for(let s=t;s<n.length&&s>=0;s+=e){const i=n[s];if(i)return i}},Kr=(n,t)=>{const e=n.slice(),s=[],i=[];return t.forEach(r=>{const a=Le(r.timestamp,{extrapolate:!0},n).index;a<0?s.push(r):a>=n.length?i.push(r):n[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:s,appended:i,candles:[...s,...e,...i]}};class Ce{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class rn{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const s=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(s,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=$i(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=$i(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=pt(Array.from(this.drawers).map(([,s])=>s.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class jd{constructor(t,e,s,i){this.model=t,this.config=e,this.crossToolCanvasModel=s,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var Nd=Object.defineProperty,Xd=Object.defineProperties,Wd=Object.getOwnPropertyDescriptors,qr=Object.getOwnPropertySymbols,zd=Object.prototype.hasOwnProperty,Vd=Object.prototype.propertyIsEnumerable,Jr=(n,t,e)=>t in n?Nd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ud=(n,t)=>{for(var e in t||(t={}))zd.call(t,e)&&Jr(n,e,t[e]);if(qr)for(var e of qr(t))Vd.call(t,e)&&Jr(n,e,t[e]);return n},Gd=(n,t)=>Xd(n,Wd(t));class Zd extends X{constructor(t,e,s,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=s,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.chartModel=a,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?jt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(jt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,K]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget,s=this.config.discrete){var i;const r=s?this.chartModel.toX((i=this.chartModel.candleFromX(t.x,!0).idx)!=null?i:0):t.x;if(this.currentHover===null?this.currentHover={x:r,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=r,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===K)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:s,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(T.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=s.x+l,d=s.y+c,u=o.y+a,f=o.y+o.height-a,p=h<a?a:h>o.width-a?o.width-a:h,v=d<u?u:d>f?f:d,x=(e=this.hoverProducer.createHover(p,v,t.paneId))!=null?e:t,_=Gd(Ud({},x),{x:p,y:v});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const It=4;function $d(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,p;const v=r.align,x=(l=i.textFont)!=null?l:ee(r),_=i.bgColor,A=(c=i.textColor)!=null?c:te(_,o.labelTextColor,o.labelInvertedTextColor),L=(h=i.paddingTop)!=null?h:It,j=(d=i.paddingBottom)!=null?d:It,F=(u=i.paddingEnd)!=null?u:It,B=Te(Nt(x,n)/2),Y=s-B-L,W=s+B+j-Y;if(a&&!gs(s,t,W))return;n.save(),n.fillStyle=_,n.strokeStyle=_;const U=Te(t.width/6),G=v==="right"?t.x:t.x+t.width,V=v==="right"?G+U:G-U,Q=r.labelBoxMargin.end,J=Q-F,et=t.width-U-J;Ah(n,V,Y,G,Y+Te(W/2),V,Y+W,et,(p=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?p:!1,v),n.fillStyle=A,n.font=x;const tt=v==="right"?t.x+t.width-Pt(e,n,x)-Q:t.x+Q;n.fillText(e,tt,s+B-1),n.restore()}function Kd(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,p,v,x,_,A;const L=r.align,j=(l=i.textFont)!=null?l:ee(r),F=i.bgColor,B=(c=i.textColor)!=null?c:te(F,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,$=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:It,W=(p=(f=i.paddingBottom)!=null?f:Y==null?void 0:Y.bottom)!=null?p:It,U=(x=(v=i.paddingEnd)!=null?v:Y==null?void 0:Y.end)!=null?x:It,G=i.paddingStart,V=Nt(j,n),Q=s-V/2-$,et=s+V/2+W-Q,tt=(A=i.rounded)!=null?A:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!gs(s,t,et))return;n.save(),n.fillStyle=F,n.strokeStyle=F;const st=r.labelBoxMargin.end;n.font=j;const ht=Pt(e,n,j),at=st-U,St=G!==void 0?ht+G+U:t.width-at,Ut=L==="right"?t.x+t.width-at-St:t.x+at,Se=L==="right"?t.x+t.width-ht-st:st;tt?Pr(n,Ut,Q,St,et,4,!0):n.fillRect(Ut,Q,St,et),n.fillStyle=B,n.fillText(e,Se,s+V/2-1),n.restore()}function qd(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,p,v,x;const _=r.align,A=(l=i.textFont)!=null?l:ee(r),L=o.backgroundColor,j=(c=i.textColor)!=null?c:te(L,o.labelTextColor,o.labelInvertedTextColor),F=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:F==null?void 0:F.top)!=null?u:It,Y=(p=(f=i.paddingBottom)!=null?f:F==null?void 0:F.bottom)!=null?p:It,$=(x=(v=i.paddingEnd)!=null?v:F==null?void 0:F.end)!=null?x:It,W=i.paddingStart,U=Nt(A,n),G=s-U/2-B,Q=s+U/2+Y-G;if(a&&!gs(s,t,Q))return;n.save(),n.fillStyle=L,n.strokeStyle=L;const J=r.labelBoxMargin.end;n.font=A;const et=Pt(e,n,A),tt=J-$,st=W!==void 0?et+W+$:t.width-tt,ht=_==="right"?t.x+t.width-tt-st:t.x+tt,at=_==="right"?t.x+t.width-et-J:J;n.fillStyle=L,n.strokeStyle=L,n.fillRect(ht,G,st,Q),n.fillStyle=j,n.fillText(e,at,s+U/2-1),n.restore()}function Jd(n,t,e=It){return Nt(n,t)/2+e}function gs(n,t,e){return!(n<t.y+e/2||n>t.y+t.height-e/2)}const Qd="badge",Qr=4,to={badge:$d,rectangle:Kd,plain:qd};function eo(n,t,e,s,i,r,o,a,l){var c,h,d,u,f;const p=r.y,v=r.labelText,x=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:Qd,A=r.description,L=(d=r.textFont)!=null?d:ee(a),j=r.bgColor,F=(u=r.lineColor)!=null?u:j,B=Pt(A!=null?A:"",n,L)+8,Y=ot(r.y),$=Nt(L,n),W=p-$/2,G=p+$/2-W;n.save(),n.fillStyle=j,n.strokeStyle=F;const V=o.getBounds(T.PANE_UUID(K)),Q=to[_],J=a.labels.descriptions,et=tu(s,Y,G),tt=()=>J&&eu(e,t,s,i,r,a);let st,ht;const at=2;a.align==="right"?(st=V.x,ht=J?V.x+V.width-B:V.x+V.width+at):(st=J?V.x+B:V.x-at,ht=V.x+V.width);const St=(f=r.lineY)!=null?f:r.y,Ut=()=>et&&oe(n,()=>Eh(n,st,St,ht,St,1,r.lineDash)),Se=()=>Q(n,s,Je(v),p,r,a,l.yAxis,!1),xs={line:()=>{Ut(),tt()},"line-label":()=>{Ut(),Se(),tt()},label:()=>{tt(),Se()}};x!=="none"&&gs(p,s,G)&&xs[x](),n.restore()}const tu=(n,t,e)=>t>n.y+e/2&&t<n.y+n.height-e/2;function eu(n,t,e,s,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=ee(r),f=Pt(h,t,u),p=Nt(u,t),v=(o=i.paddingTop)!=null?o:Qr,x=(a=i.paddingBottom)!=null?a:Qr,_=d-p/2-v,L=d+p/2+x-_;t.save();const j=f+5,F=4,B=f+F*2,Y=s.x+s.width,$=c==="right"?Y-B:s.x+F;Gc(n,t,$,_,j,L,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const W=c==="right"?Y-f-F*2:s.x+F*2;t.fillText(h,W,d+p/2-1),t.restore()}class so{constructor(t,e,s,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=s,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&oe(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var s,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(T.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES,{extensionY:1e-4}),h=(s=this.config.components.xAxis.padding.top)!=null?s:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const p={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},v={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},x=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),x&&(t.moveTo(...p.start),t.lineTo(...p.end)),t.moveTo(...v.start),t.lineTo(...v.end),t.stroke()),x&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var s,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,p=this.config.components.xAxis.fontSize,v=this.canvasBoundsContainer.getBounds(T.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const x=(s=l==null?void 0:l.left)!=null?s:0,_=(i=l==null?void 0:l.right)!=null?i:0,A=(r=l==null?void 0:l.top)!=null?r:0,L=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,F=f+x+_,B=p+A+L,Y=Math.max(d-F/2,0),$=v.y+j+Ie/2;Pr(t,Y,$,F,B),t.fillStyle=h.labelTextColor;const W=Math.max(d-f/2,x),U=v.y+j+p+Ie/2+A-1;t.fillText(u,W,U),t.restore()}}drawYLabel(t,e){const s=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=to[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:s==null?void 0:s.bottom,paddingEnd:s==null?void 0:s.end,paddingTop:s==null?void 0:s.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class su{draw(){}}class nu extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=s,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.chartModel=c,this.crossToolTypeDrawers={},this.model=new Zd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel,this.chartModel),this.addChildEntity(this.model);const h=new Ce(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const d=new jd(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),u=new rn;u.addDrawer(h,"CLEAR_CANVAS"),u.addDrawer(d,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(u,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new so(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new so(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new su)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class iu{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,s])=>{for(const i of s){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Wt{constructor(t){this.data=t,this.next=null}}class ru{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new Wt(t);if(this.head===null)this._head=e;else{let s=this.head;for(;s.next;)s=s.next;s.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const s=new Wt(e);if(t===0)s.next=this.head,this._head=s;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;s.next=i,r.next=s,t===this.length-1&&(this._tail=s)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,s=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,s=e,e=e.next;s.next=e.next,t===this.length-1&&(this._tail=s)}this.length--}getNodePosition(t){let e=0,s=this.head;for(;s;){if(s.data===t.data)return e;s=s.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class ou extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const s=e.paneId,r=this.objects[s];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[s,i]=e,r=new Wt(s);return i.getNodePosition(r)}addObject(t){var e,s;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new ru;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((s=t.parentId)!=null?s:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new Wt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[s]=e;this.removeObject(s.id),this.addObject(t)}moveToPosition(t,e){const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new Wt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(s),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,s),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,s),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,s),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class au extends X{constructor(t,e){super();const s=new ou(t);this.model=s,this.addChildEntity(s);const i=new iu(s,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const lu=()=>n=>n.toString(),cu=(n,t)=>{var e;const s="date.get"+(t((e=n.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return s+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:hu(n),shortMonths:du(n),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=n.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>uu(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function hu(n){var t;return(t=n.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function du(n){var t;return(t=n.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const no=(n,t,e)=>{if(n){if(typeof n=="string")return e(n);if(Array.isArray(n)){const s=n.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(s.length>0){const i=s[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return lu()},uu=(n,t,e,s)=>{t||(t="M/d/yyyy");const i=n.getDate(),r=n.getMonth(),o=n.getFullYear(),a=n.getHours(),l=n.getMinutes(),c=n.getSeconds(),h=n.getMilliseconds(),d=a%12,u=ye(d),f=ye(a),p=ye(l),v=ye(c),x=a<12?"AM":"PM",_=e[n.getDay()],A=_.substring(0,3),L=ye(i),j=r+1,F=ye(j),B=s[r],Y=B.substring(0,3),$=o+"",W=$.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",p+"").replace("m",l+"").replace("ss",v+"").replace("s",c+"").replace("S",h+"").replace("dd",L+"").replace("d",i+"").replace("EEEE",_).replace("EEE",A).replace("YYYY",$).replace("yyyy",$).replace("YY",W).replace("yy",W).replace("aaa",x),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",Y):t=t.replace("MM",F+"").replace("M",j+""),t},ye=n=>typeof n=="number"&&n<10?"0"+n:n,ke=(n,t)=>`${n}_${t}`,fu=(n,t)=>{if(t){const e=io(t.normal),s=io(t.hover);return{type:n,normal:e,hover:s}}},io=n=>{var t;const s=new DOMParser().parseFromString(n,"text/html").querySelector("svg");let i=0;s&&(i=parseInt((t=s.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(n),l=new Image;return l.src=a,{img:l,svgHeight:i}},gu=(n,t,e,s,i)=>{if(i){const r=t[ke(s,"hover")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[ke(s,"normal")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},pu={"rhombus-small":4,rhombus:6,"rhombus-large":8},mu=["earnings","dividends","splits","conference-calls"];class vu{constructor(t,e,s,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&mu.forEach(l=>{const c=fu(l,a[l]);c&&(this.customIcons[ke(c.type,"normal")]=c.normal,this.customIcons[ke(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(T.EVENTS),e=this.canvasBoundsContainer.getBounds(T.ALL_PANES),s=this.canvasModel.ctx;s.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(s.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[ke(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;gu(s,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(s,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);s.lineWidth=u!=null?u:1,s.beginPath(),s.setLineDash(f!=null?f:[]),s.moveTo(c,e.y),s.lineTo(c,t.y+t.height/2),s.stroke(),s.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),s.restore()}drawDefaultEvent(t,e,s,i,r){var o,a,l;const c=s.y+s.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=on(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var s;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(T.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(s=this.config.components.xAxis.padding.top)!=null?s:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function on(n){return pu[n.style]}const ps=5;class bu{constructor(t,e,s,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(T.EVENTS);t.save(),this.model.events.forEach((s,i)=>{if(!this.config.components.events.eventsVisibility[s.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(s.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[s.type].color;t.strokeStyle=c,t.fillStyle=c;const h=on(s);t.fillStyle=this.hitTestCanvasModel.idToColor(s.id);const d=(h+ps)*2;if(a!==void 0){const u=on(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const v=h*2+ps;t.fillRect(a+u,e.y,v,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Cu=Object.defineProperty,ro=Object.getOwnPropertySymbols,yu=Object.prototype.hasOwnProperty,wu=Object.prototype.propertyIsEnumerable,oo=(n,t,e)=>t in n?Cu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Su=(n,t)=>{for(var e in t||(t={}))yu.call(t,e)&&oo(n,e,t[e]);if(ro)for(var e of ro(t))wu.call(t,e)&&oo(n,e,t[e]);return n};const ao=317,an={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class xu extends Lr{constructor(t,e,s,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=s,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new R,this.touchStartSubject=new R,this.dblClickSubject=new R,this.rightClickSubject=new R,this.hitTestDrawersPredicateSubject=new ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,Or(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Et(100,Ot,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),s=this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=Ct(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=Ct(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ct(()=>Su({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,s,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*ao).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/ao}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const s=window.devicePixelRatio;return this.prevAnimationFrameId!==Fs&&(this.curImgData=this.ctx.getImageData(t*s,e*s,1,1).data,this.prevAnimationFrameId=Fs),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),s=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(s),[r]=ln(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(s)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const s=this.getPixel(t.x,t.y),i=this.colorToId(s[0]*65536+s[1]*256+s[2]),r=Number(i),[o]=ln(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var s,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,p]=ln(this.hitTestSubscribers,u),v=f==null?void 0:f.lookup(d),x={point:t,model:v};switch(e){case"mousedown":v&&((s=f==null?void 0:f.onMouseDown)==null||s.call(f,v,t)),p.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":v&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,v,t)),p.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":v&&((r=f==null?void 0:f.onHover)==null||r.call(f,v,t)),p.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(x);break;case"touchstart":v&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,v,t)),p.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(x);break;case"dblclick":v&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,v,t)),this.dblClickSubject.next(x);break;case"contextmenu":v&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,v,t)),this.rightClickSubject.next(x);break;case"zoom":v&&((c=f==null?void 0:f.onZoom)==null||c.call(f,v,t)),p.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const ln=(n,t)=>{let e;const s=[];return n.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:s.push(i)}),[e,s]};var _u=Object.defineProperty,Pu=Object.defineProperties,Tu=Object.getOwnPropertyDescriptors,lo=Object.getOwnPropertySymbols,Mu=Object.prototype.hasOwnProperty,Au=Object.prototype.propertyIsEnumerable,co=(n,t,e)=>t in n?_u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Eu=(n,t)=>{for(var e in t||(t={}))Mu.call(t,e)&&co(n,e,t[e]);if(lo)for(var e of lo(t))Au.call(t,e)&&co(n,e,t[e]);return n},Iu=(n,t)=>Pu(n,Tu(t));class Du extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((s,i)=>Iu(Eu({},s),{id:i+e})).sort((s,i)=>s.timestamp-i.timestamp)}getIdRange(){return an.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Lu extends X{constructor(t,e,s,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>no(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Du(e);this.eventsModel=c,this.addChildEntity(c),s.addSubscriber(c);const h=new vu(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new bu(s,i,t,r,c,()=>s.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(T.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class Ou{constructor(t,e,s,i,r,o,a,l,c=()=>!0,h,d,u){this.canvasModel=t,this.viewportModel=e,this.config=s,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.extentIdx=h,this.getBaseline=d,this.mainExtentIdx=u}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;oe(t,()=>this.drawVertical(t)),oe(t,()=>this.drawHorizontal(t)),oe(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.extentIdx===0&&this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const s=this.xBoundsProvider(),i=ot(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(s.x,i),t.lineTo(s.x+s.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.xBoundsProvider(),i=s.x+s.width;for(const r of e){const o=Mt(this.viewportModel.toX(r.value));o>s.x&&o<i&&(t.beginPath(),t.moveTo(o,s.y),t.lineTo(o,s.y+s.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length>0&&this.config.components.grid.horizontal&&this.extentIdx===this.mainExtentIdx){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.yBoundsProvider();for(const i of e){const r=ot(this.viewportModel.toY(i.value)),o=Jd(i.text,t,It);r>s.y+o&&r<s.y+s.height-o&&(t.beginPath(),t.moveTo(s.x,r),t.lineTo(s.x+s.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class ho extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,p){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new Ou(t,e,s,i,a,l,c,h,f,d,u,p)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class Bu{constructor(t,e,s,i){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:s,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+s,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,s,i){const r=this.getMarkerY(t,s,i==="low"),o=Qe(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(s,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Zt(t,h)}getMarkerText(t,e){const s=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${s}`}getMarkerY(t,e,s=!1){const i=this.chartModel.toY(e);if(s){const r=Qe(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(T.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,s){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(T.CHART),o=4,a=t.measureText(s).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ru extends X{constructor(t,e,s,i,r){super();const o=new Bu(e,s,t,i);r.addDrawer(o,"HIGH_LOW")}}const Fu=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],Hu=1440*60*1e3;class ku extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new R}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+Hu;_l(this.highlights,t,e,Yu).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,s)=>e.to-s.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const Yu=n=>n.to,Kt=[20,10];class ju{constructor(t,e,s,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,s,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(T.ALL_PANES);o.save(),Zt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(s=this.config.components.highlights.fontSize)!=null?s:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",p=`${u}px ${f}, monospace`;o.font=p,o.lineWidth=h,o.setLineDash(d),Fu.forEach(v=>{var x,_;const A=a[v];if(A){const L=this.config.colors.highlights[v],j=(x=L==null?void 0:L.border)!=null?x:"#ffffff",F=(_=L==null?void 0:L.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=F,o.strokeStyle=j,A.forEach(B=>{var Y,$,W;const U=this.chartModel.candleFromTimestamp(B.from),G=mt(U.width,this.chartModel.scale.zoomX),V=U.xStart(this.chartModel.scale),Q=B.to-this.chartModel.chartBaseModel.period,J=this.chartModel.candleFromTimestamp(Q),et=mt(J.width,this.chartModel.scale.zoomX),tt=J.xStart(this.chartModel.scale)+et;if(B.border&&this.drawBorders(B.border,o,V+G,tt-et,c),o.fillRect(V,c.y,tt-V,c.y+c.height),B.label){const st=(Y=B.label.text)!=null?Y:"",ht=this.config.colors.highlights[B.type];o.save(),o.fillStyle=($=ht==null?void 0:ht.label)!=null?$:"#ffffff";const at=Pt(st,o,p),[St,Ut]=this.resolveHighlightLabelPosition((W=B.label.placement)!=null?W:"left-left",c,[V,tt],at);o.fillText(st,St,Ut),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,s,i){const[r,o]=s;switch(t){case"right-left":return[o-Kt[1]-i,e.y+Kt[0]];case"left-left":return[r-Kt[1]-i,e.y+Kt[0]];case"right-right":return[o+Kt[1],e.y+Kt[0]];case"left-right":default:return[r+Kt[1],e.y+Kt[0]]}}drawBorders(t,e,s,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(s,r.y),e.lineTo(s,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const Nu="HIGHLIGHTS_PLUGIN";class Xu extends X{constructor(t,e,s,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new ku(s),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new ju(this.highlightsModel,s,i,r,e),o.addDrawer(this.highLightsDrawer,Nu)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function Wu(){return N(function(n,t){var e,s=!1;n.subscribe(bt(t,function(i){var r=e;e=i,s&&t.next([r,i]),s=!0}))})}function Z(n,t){return N(function(e,s){var i=0;e.subscribe(bt(s,function(r){return n.call(t,r,i++)&&s.next(r)}))})}var zu=Object.defineProperty,Vu=Object.defineProperties,Uu=Object.getOwnPropertyDescriptors,uo=Object.getOwnPropertySymbols,Gu=Object.prototype.hasOwnProperty,Zu=Object.prototype.propertyIsEnumerable,fo=(n,t,e)=>t in n?zu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,go=(n,t)=>{for(var e in t||(t={}))Gu.call(t,e)&&fo(n,e,t[e]);if(uo)for(var e of uo(t))Zu.call(t,e)&&fo(n,e,t[e]);return n},po=(n,t)=>Vu(n,Uu(t));const zt=4;class $u{constructor(t,e,s,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(T.N_MAP),s=this.canvasBoundsContainer.getBounds(T.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(T.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(T.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(T.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(T.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),s.width!==0&&this.drawLeftArrowButton(c,s,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,s,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,s,i){t.x<=s.x+s.width&&(t.x=s.x+s.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,s,i,r){this.blockDrawSliderOnLeftArrow(e,s,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,s,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,s,i){const r=s.components.navigationMap.knots.border;t.fillStyle=s.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=s.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=s.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=s.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=pt(this.chartModel.mainCandleSeries.getSeriesInViewport()),s=this.config.components.navigationMap.timeLabels,i=s.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(T.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(T.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:s.fontFamily,textSize:`${s.fontSize}px`},d={dateFormat:s.dateFormat,padding:s.padding,textProperties:po(go({},h),{textAlign:"left"})},u={dateFormat:s.dateFormat,padding:s.padding,textProperties:po(go({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,s,i){const r=i.padding,o=mi(s,i.dateFormat,this.formatterFactory);di(t,i.textProperties);const a=Qe(t),l=fi(o);Tl(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ye extends Fr{constructor(t,e,s,i,r=Rr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const mo=4;class Ku extends X{constructor(t,e,s,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=s,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-p.x-mo},this.leftKnotDragTick=f=>{const{delta:p}=f,x=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+p)/x;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-p.x+mo},this.rightKnotDragTick=f=>{const{delta:p}=f,x=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+p)/x;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:p}=f,v=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),x=this.chartModel.mainCandleSeries.meanCandleWidth/(v.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-p)*x;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=p};const a=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_KNOT_R),c=new Ye(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Ye(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_SLIDER_WINDOW),u=new Ye(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const s=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=s.dataIdxStart/(s.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=s.dataIdxEnd/(s.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class qu extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=s,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new $u(i,e,s,o,l,()=>this.visualCandles);a.addDrawer(d,T.N_MAP_CHART),this.navigationMapMoveHandler=new Ku(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(T.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(T.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(T.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(T.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(T.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(T.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(T.N_MAP),this.chartModel.scale.xChanged.pipe(Wu(),Z(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const s=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-s,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),h=c.width,d=[];let u=0,f,p;for(f=0;f<h;f++)p=ot(f*o/h)-r,p in e?(d[f]=e[p].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((v,x)=>[x+c.x,(a+l-v)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(cs),this.canvasModel.fireDraw())}}const ms=()=>{const n=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(s=>navigator.userAgent.match(s));return n?"apple":e?"mobile":"other"},Vm=(n,t)=>n==="apple"||n==="mobile"?3:t;var cn=Math.pow;class vo extends X{constructor(t,e,s,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=15,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const v=this.canvasBoundsContainer.getBounds(T.CANVAS).width,_=d.offsetX/v;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(ue),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Rt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),h=new Ye(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Et(this.wheelThrottleTime,Ot,{trailing:!0,leading:!0})).subscribe(e=>{const s=ms(),i=s==="apple"||s==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Rt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return ol(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let s=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(ue),this.currentPoint={x:0,y:0},s=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)Ju(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Rt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(s+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new us(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Ju=(n,t)=>{if(!t.enabled)return!1;const e=Math.abs(n.y),s=cn(cn(Math.abs(n.x),2)+cn(e,2),.5),i=Math.abs(Math.acos(e/s));return e>t.yDiff&&i<t.edgeAngle},Qu=2;class tf extends X{constructor(t,e,s,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=s,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:s}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:s}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:s}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=bo(e,i.x,s,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),s=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];s[r]=a.pageX-e.left-i}return s}pinchHandler(t,e){const s=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=s+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;s>=i||e[0]===e[1]||this.scale.setXScale(s,i)}}const bo=(n,t,e,s,i=Qu)=>Math.sqrt(Math.pow(n-t,2)+Math.pow(e-s,2))>i,Um={MAX_DIMENSION:2048,MAX_TOTAL_PIXELS:18e5,ZOOM_OPTIMIZED_PIXELS:12e5},ef=2e6,sf=24,nf=20,rf=16,of=10,af=1e3,Gm=5e4,Zm={MIN:60,LOW:80,MEDIUM:100,HIGH:120,MAX:150};class lf extends vo{constructor(t,e,s,i,r,o,a,l){super(t,e,s,i,r,o,a,l),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=ie,this.wheelSubscription=null,this.initFrameId=null,this.isActivated=!1,this.lastWheelTime=0,this.wheelCount=0,this.consecutiveLowWheelEvents=0,this.chartPanningOptions={horizontal:!0,vertical:!0}}doActivate(){this.isActivated||(this.isActivated=!0,super.doActivate(),this.canvasInputListener.initializeRectCache(),this.createWheelSubscription(),this.initFrameId=requestAnimationFrame(()=>{this.bus.fireDraw()}),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:t})=>{this.lastXStart+=t})),this.addRxSubscription(this.bus.observe(cs).pipe(Nr(100)).subscribe(()=>{this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation()})))}createWheelSubscription(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null);const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),e=this.canvasBoundsContainer.getBounds(T.CANVAS),s=e.width*e.height;s>0?s>ef?this.wheelThrottleTime=sf:this.wheelThrottleTime=nf:this.wheelThrottleTime=rf,this.wheelSubscription=this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Z(i=>ms()==="apple"?Math.abs(i.deltaY)>1||Math.abs(i.deltaX)>1:!0),Et(this.wheelThrottleTime,Ot,{trailing:!0,leading:!0})).subscribe(i=>{const r=performance.now();this.lastWheelTime||(this.lastWheelTime=r,this.wheelCount=0),this.wheelCount++,r-this.lastWheelTime>af&&(Math.round(this.wheelCount*1e3/(r-this.lastWheelTime))<of?(this.consecutiveLowWheelEvents++,this.consecutiveLowWheelEvents>=1&&(this.triggerPerformanceCleanup(),this.consecutiveLowWheelEvents=0)):this.consecutiveLowWheelEvents=0,this.lastWheelTime=r,this.wheelCount=0);const o=ms(),a=o==="apple"||o==="mobile"?-1:1,l=0+i.deltaX*a,c=0+i.deltaY*a;if(i.ctrlKey){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw();return}if(c!==0&&Math.abs(c)>Math.abs(l)){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw()}if(l!==0&&Math.abs(l)>Math.abs(c)){const h=Rt(l,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-h),this.bus.fireDraw();return}}),this.addRxSubscription(this.wheelSubscription)}triggerPerformanceCleanup(){window.dispatchEvent(new Event("resize")),window.gc&&window.gc(),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation(),this.consecutiveLowWheelEvents=0,this.wheelCount=0,this.lastWheelTime=0}doDeactivate(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.isActivated=!1,super.doDeactivate()}}class cf extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=s,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c;const h=[this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel],d=Me?new lf(...h):new vo(...h);this.chartAreaPanHandler=d,this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new tf(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const Co=n=>t=>{const{top:e,bottom:s}=n(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*s/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},yo=(n,t)=>{const e=Co(n);return{isHighLowActive:()=>!0,calculateHighLow:s=>{const i=t.calculateHighLow(s);return e(i)}}};function hf(){return Xn(1)}function wo(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return hf()(Ge(n,Ue(n)))}function df(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n);return N(function(s,i){(e?wo(n,s,e):wo(n,s)).subscribe(i)})}function uf(n){return Z(function(t,e){return n<=e})}class ff{constructor(t,e,s,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=s,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),s=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(s.fillStyle=i.getColor(0),s.fillRect(e.x,e.y-r,e.width,e.height+2*r)),s.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?s.fillRect(e.x,e.y,e.width,e.height):s.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const So=8;class hn extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=s,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new R,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=p=>{const{delta:v,draggedPixels:x}=p;Math.abs(this.initialY-this.boundsProvider().y+x)>=0&&(this.dragTickCb(v),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const s=new us(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:jt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:jt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(s),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(df(!1),Z(this.dragPredicate),_t(),uf(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new ff(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,Br.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(Br.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const dn=1/32,gf=n=>{const t=Math.floor(n),e=n-t,s=Math.round(e*64),r=Math.floor(s/2).toString().padStart(2,"0");return`${t}'${r}`},xo=n=>n.match(/^\-?0*(\d+)'(\d{2})$/),$m=n=>!!xo(n),Km=n=>{const t=xo(n);if(t){const e=parseInt(t[1],10),i=parseInt(t[2],10)*dn;return e+i}return Number(n)},pf=(n,t)=>e=>{let s;if(typeof e=="number")s=e;else if(typeof e=="string")s=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return gf(s);const[r]=n.dataSeries;if(r!==void 0){const o=me.getPricePrecision(s,r.pricePrecisions);return s.toFixed(o)}return`${s}`},mf=n=>(t,e)=>{const[s]=n.dataSeries;let i=t;const r=e!=null?e:s;r!==void 0&&(i=Qi(t,r.getBaseline()));const o=Je(i.toFixed(me.DEFAULT_PRECISION))+" %";return o===`${qn}0.00 %`?"0.00 %":o},vf=(n,t)=>({percent:mf(n),regular:pf(n,t)});class bf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u=new Set,f={regular:kc}){super(),this.config=t,this.paneUUID=e,this.idx=s,this.paneComponent=i,this.chartBaseModel=r,this.canvasBoundsContainer=o,this.hitTestController=a,this.dynamicObjectsCanvasModel=l,this.scale=c,this.dragNDrop=d,this.dataSeries=u,this.formatters=f,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=p=>p.map(v=>new Oe(this.chartBaseModel.dataFromTimestamp(v.timestamp).centerUnit,v.close)),this.toY=p=>{var v,x;return(x=(v=this.mainDataSeries)==null?void 0:v.view.toY(p))!=null?x:1},this.valueFormatter=(p,v)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(p);const{regular:x,percent:_,logarithmic:A}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(p);case"percent":return _?_(p,v):x(p);case"logarithmic":return A?A(p):x(p);default:return this.regularFormatter(p)}},this.addChildEntity(c),this.setValueFormatters(vf(this,t)),this.yAxis=h(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new or(this,yt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){if(this.dataSeries.add(t),this.dataSeries.size===1)this.mainDataSeries=t;else if(this.paneComponent.yExtentComponents.length>1&&this.paneUUID!==K){this.mainDataSeries=t;const e=Array.from(this.paneComponent.mainExtent.dataSeries);this.paneComponent.mainExtent.mainDataSeries=e[e.length-1]}this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,s;return(s=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?s:this.scale.fromY(t)}}const _o=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(n.dataSeries).filter(s=>s.highLowProvider.isHighLowActive()).map(s=>s.highLowProvider.calculateHighLow(t));return vr(e)}});class Cf{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=an.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return an.DATA_SERIES}get allDataSeries(){return Ee(Ee(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(s=>s.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(s=>s.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Vt="#FF00FF";function qm(n,t,e,s){const i=n.yAxis.backgroundColor,r=n.chartAreaTheme.backgroundColor,o=n.chartAreaTheme.backgroundGradientTopColor,a=n.chartAreaTheme.backgroundGradientBottomColor,l=s.align==="left"?o:a,c=n.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const yf=(n,t)=>n==="down"?t.lastPrice.textNegative:n==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,wf=(n,t)=>{const e=t.barTheme[`${n}Color`];return e!=null?e:Vt},Sf=(n,t)=>{const e=t.lineTheme[`${n}Color`];return e!=null?e:Vt},xf=(n,t)=>{const e=t.candleTheme[`${n}Color`];return e!=null?e:Vt},_f=(n,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Vt},Pf=(n,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Vt},Tf=(n,t)=>{const e=t.histogram[`${n}Bright`];return e!=null?e:Vt},Mf=(n,t)=>{const e=n==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Vt},Po=(n,t)=>{const e=t.candleTheme[`${n}WickColor`];return e!=null?e:Vt},Af=()=>(console.warn("Fallback for label default color"),Vt),To=10;class Mo extends X{constructor(t,e,s,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new R,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(T.Y_AXIS).height,Di),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(To-1)):d=1+h/this.lastYPxHeight*(To-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,p=this.lastYStart-f,v=this.lastYEnd+f;(this.lastYStart!==p||this.lastYEnd!==v)&&(this.scale.setYScale(p,v),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new us(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,s,{dragPredicate:()=>s.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Ef{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${yt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Kn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const If=0,Df=.01;class un{constructor(t,e,s,i,r=!1,o,a,l=js,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=s,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new R,this.newGeneratedLabelsSubject=new R,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Ef(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,s){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=ft.roundToNearest(t,s);for(;r<e;){const o=ft.roundToNearest(r,s),a=Je(this.valueFormatter(o));i.push({value:o,text:a}),r=ft.roundDecimal(r+s)}return i}generatePercentLabels(t,e,s){const i=[],r=this.baseLineProvider();let o=ft.roundToNearest(t,s);for(;o<e;){const a=ft.roundToNearest(o,s),l=tr(a,r),c=Je(this.valueFormatter(l));i.push({value:a,text:c}),o=ft.roundDecimal(o+s)}return i}generateLogarithmLabels(t,e,s){const i=[];let r=ft.roundToNearest(t,s);for(;r<e;){const o=Qs(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=ft.roundDecimal(r+s)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[s,i]=this.calculateMinMax(),r=this.getAxisStep(s,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(s,i,r):a==="percent"?o=this.generatePercentLabels(s,i,r):o=this.generateRegularLabels(s,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),s=this.lengthProvider(),i=un.getLabelBounds(t,e,s);return[i[0],i[1]]}getAxisStep(t,e,s){const i=e-t,r=s/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const s=(e=this.treasuryFormat)!=null&&e.enabled?dn:me.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(s)}return this.adjustIncrementOnAxisType(Df)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Qs(e)+t;return er(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,s){const i=Math.abs((e-t)*(If/s));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let s=e,i=e,r=0;for(;s<t&&s>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),s=i*this.gridDistanceMultipliers[r++];return s}}class Lf extends un{constructor(t,e,s,i,r=()=>"regular",o=23,a){super(t,()=>[s.yStart,s.yEnd],()=>s.getBounds().height,i,!1,r,()=>{var l,c;return(c=(l=e())==null?void 0:l.getBaseline())!=null?c:1},void 0,o,a),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,s)=>s.text.length>e.length?s.text:e,"")}updateTreasuryFormat(t){this.treasuryFormat=t}calculateIncrement(t){var e,s;const i=this.dataSeriesProvider();if(i){const r=wt(i.dataPoints),o=(e=r==null?void 0:r.close)!=null?e:0,a=Kc(o,i.pricePrecisions),l=(s=this.treasuryFormat)!=null&&s.enabled?dn:a;return this.adjustIncrementOnAxisType(l)}return super.calculateIncrement(t)}}function Ao(n,t,e){var s=k(n)||t||e?{next:n,error:t,complete:e}:n;return s?N(function(i,r){var o;(o=s.subscribe)===null||o===void 0||o.call(s);var a=!0;i.subscribe(bt(r,function(l){var c;(c=s.next)===null||c===void 0||c.call(s,l),r.next(l)},function(){var l;a=!1,(l=s.complete)===null||l===void 0||l.call(s),r.complete()},function(l){var c;a=!1,(c=s.error)===null||c===void 0||c.call(s,l),r.error(l)},function(){var l,c;a&&((l=s.unsubscribe)===null||l===void 0||l.call(s)),(c=s.finalize)===null||c===void 0||c.call(s)}))}):de}class Of extends X{constructor(t,e,s,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=s,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${yt()}`}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ct(t=>t.height),Z(t=>Qa(t,this.prevYAxisHeight,1.5)),Ao(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,_e(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){_e(this.animFrameId,()=>{this.labels=this.labelsGenerator.generateNumericLabels(),this.canvasBoundsContainer.updateYAxisWidths()})}}class Bf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=s,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Lf(null,l,o,a,()=>this.state.type,s.labelHeight,s),this.baseLabelsModel=new Of(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new _c(e,o,i,s,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(s=>s.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(s=>s.labels).map(s=>s.labelText)).reduce((s,i)=>i.length>s.length?i:s,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class Rf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,p,v,x){super(),this.eventBus=t,this.config=e,this.mainCanvasModel=s,this.canvasModel=i,this.scale=r,this.canvasInputListeners=o,this.canvasBoundsContainer=a,this.chartPanComponent=l,this.cursors=c,this.paneUUID=u,this.extentIdx=f,this.hitTestCanvasModel=p,this.chartResizeHandler=v,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new R,this.axisAlignSetSubject=new R,this.axisAlignMovedSubject=new R,this.setDblClickCallback=A=>this.yAxisScaleHandler.setDblClickCallback(A),this.setDblTapCallback=A=>this.yAxisScaleHandler.setDblTapCallback(A);const _=x?ne(x):{};this.state=Tt(_,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new Mo(t,this.state,l,r,o,a,a.getBoundsHitTest(T.PANE_UUID_Y_AXIS(u,f)),p),this.addChildEntity(this.yAxisScaleHandler),this.model=new Bf(this.paneUUID,t,this.state,a,i,r,h,d,f,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new Mo(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",xf),this.registerLabelColorResolver("bar",wf),this.registerLabelColorResolver("line",Sf),this.registerLabelColorResolver("area",_f),this.registerLabelColorResolver("scatterPlot",Pf),this.registerLabelColorResolver("histogram",Tf),this.registerLabelColorResolver("baseline",Mf),this.registerLabelColorResolver("trend",Po),this.registerLabelColorResolver("hollow",Po)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Af}registerYAxisLabelsProvider(t,e=se.MAIN,s=yt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,s),s}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}updateCustomYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=se.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor(),this.mainCanvasModel.fireDraw())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Ff extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,p,v,x,_,A,L,j){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=s,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=p,this.uuid=v,this.seriesAddedSubject=x,this.seriesRemovedSubject=_,this.hitTestCanvasModel=A,this.chartResizeHandler=L,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new R,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,Y)=>this.mainExtent.valueFormatter(B,Y);const F=this.createExtentComponent(j);this.mainExtent=F,this.ht=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID(v),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return Ee(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(this.uuid)).pipe(_t(Hi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,s;return(s=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?s:this.scale.toY(t)}createGridComponent(t,e,s,i,r,o){var a,l;const c=T.PANE_UUID(t),h=(l=(a=this.mainExtent)==null?void 0:a.idx)!=null?l:0;return new ho(this.mainCanvasModel,s,this.config,i,`PANE_${t}_${e}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(c),()=>this.canvasBoundsContainer.getBounds(c),()=>[],r,e,o,()=>this.config.components.grid.visible,h)}createYPanHandler(t,e){const s=T.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(s));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const s=T.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(s,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(s)}createExtentComponent(t){var e,s;const i=this.yExtentComponents.length,r=T.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Ph(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(v,x)=>new Rf(this.eventBus,this.config,this.mainCanvasModel,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,v,x,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new bf(this.config.components.yAxis,this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((s=t==null?void 0:t.useDefaultHighLow)!=null?s:!0)&&a.autoScaleModel.setHighLowProvider("default",yo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),_o(u)));const p=this.createGridComponent(this.uuid,u.idx,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(p),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(s=>s.idx).includes(e.idx)),this.yExtentComponents.forEach((e,s)=>{e.yAxis.setExtentIdx(s),e.idx=s,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,s,i="right"){const r=ne(s.yAxis.state),o=ne(s.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),s.dataSeries.size===0&&e.removeExtentComponents([s])}moveDataSeriesToExistingExtentComponent(t,e,s,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&s.dataSeries.size===0&&e.removeExtentComponents([s]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(s=>s.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=fe(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=wt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var Hf=Object.defineProperty,kf=Object.defineProperties,Yf=Object.getOwnPropertyDescriptors,Eo=Object.getOwnPropertySymbols,jf=Object.prototype.hasOwnProperty,Nf=Object.prototype.propertyIsEnumerable,Io=(n,t,e)=>t in n?Hf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Xf=(n,t)=>{for(var e in t||(t={}))jf.call(t,e)&&Io(n,e,t[e]);if(Eo)for(var e of Eo(t))Nf.call(t,e)&&Io(n,e,t[e]);return n},Wf=(n,t)=>kf(n,Yf(t));class zf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,p,v,x,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=s,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=p,this.yAxisLabelsCanvasModel=v,this.hitTestCanvasModel=x,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new R,this.paneAddedSubject=new R,this.dataSeriesAddedSubject=new R,this.dataSeriesRemovedSubject=new R,this.hitTestController=new Cf(this.panes,this.dynamicObjectsCanvasModel);const A=this.createPane(K,{useDefaultHighLow:!1,scale:this.mainScale});A.mainExtent.scale.autoScaleModel.setHighLowProvider("series",_o(A.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",Co(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+So}),s=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=T.PANE_UUID_RESIZER(t),o=new hn(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,s,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return Ee(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(s=>this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID(s.uuid))(t.x,t.y))}createPane(t=yt(),e){if(this.panes[t]!==void 0)return this.panes[t];const s=new Ff(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&s.addChildEntity(this.addResizer(t)),s.addSubscription(this.addBounds(t,e==null?void 0:e.order)),s.addSubscription(this.addCursors(t)),s.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,s.ht)),this.panes[t]=s,s.activate(),this.recalculateState(),s.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),s}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,s;const i=fe(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}canMovePaneDown(t){var e,s;const i=wt(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(s=>s.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const s=T.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof hn&&r.id===s);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],s=T.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof hn&&r.id===s);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,s,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?Wf(Xf({},s.yAxis.state),{align:l}):void 0,p=c&&c>0;if(!u){const v=a&&a==="above"?d:d+1,x=this.createPane(r,{order:v,initialYAxisState:f,inverse:s.scale.state.inverse,lockToPriceRatio:s.scale.state.lockPriceToBarRatio});x.moveDataSeriesToExistingExtentComponent(t,e,s,x.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!p?u.moveDataSeriesToExistingExtentComponent(t,e,s,o):u.moveDataSeriesToNewExtentComponent(t,e,s,l!=null?l:s.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const s=T.PANE_UUID(t),i=T.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(s,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+So),()=>{this.cursorHandler.removeCursorForCanvasEl(s),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class Vf extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,s=this.canvasModel.ctx;if(s){s.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return s.drawImage(this.elements.backgroundCanvas,0,0,i,r),s.drawImage(this.elements.mainCanvas,0,0,i,r),s.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),s.drawImage(this.elements.crossToolCanvas,0,0,i,r),s.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(s),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const Uf=(n,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function s(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return s(n)},Do=class _s extends X{constructor(t,e,s,i){super(),this.chartComponent=t,this.config=e,this.volumesModel=s,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var t,e;return!((t=this.pane)!=null&&t.scale.isViewportValid())&&((e=this.pane)==null?void 0:e.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var t;return(t=this.pane)==null?void 0:t.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[_s.UUID]===void 0){const e=this.paneManager.createPane(_s.UUID,{paneFormatters:{regular:r=>Uf(r,1)},useDefaultHighLow:!1,increment:1});this.pane=e,e.mainExtent.yAxis.setAxisType("regular");const{scale:s}=e,i=yo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);s.autoScaleModel.setHighLowProvider("volumes",i),s.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(_s.UUID),delete this.pane}fromY(t){var e,s;return(s=(e=this.pane)==null?void 0:e.scale.fromY(t))!=null?s:0}};Do.UUID="volumes";let Gf=Do;const vs=.3,Zf=(n,t)=>{const e=t.barTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},$f=(n,t)=>{const e=t.volume[`${n}BarColor`];return Lt()(e).alpha(vs).toString()},Kf=(n,t)=>{const e=t.lineTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},fn=(n,t)=>{const e=t.candleTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},qf=3;class Jf{constructor(t,e,s,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=s,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const s=(e=this.volumesColorByChartTypeMap[t])!=null?e:$f;this.volumeBarColors.down=s("down",this.config.colors),this.volumeBarColors.up=s("up",this.config.colors),this.volumeBarColors.none=s("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const s=this.getViewportModel().getBounds();Zt(e,s),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const s=pt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();s.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=s[o+1]!==void 0?Mt(i.toX(s[o+1].startUnit)):void 0,h=Mt(i.toX(r.startUnit)),d=c!==void 0?c-h:Mt(mt(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(i.toY(r.candle.volume)),f=Ks(i.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=e/(l/qf),f=Math.max(Ks(mt(r.candle.volume,u)),2),p=Mt(a.y+l-f);this.drawVolume(t,r,h,p,d,f)}}})}drawVolume(t,e,s,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(s,l),a.lineTo(s,Ks(c)),a.stroke()):a.fillRect(s,i,r,o)}}const Qf=xl(n=>n.candle.volume),Lo="volumes";class tg extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=Lo,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;this.volumeMax.next((t=fe(Qf(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class eg extends X{constructor(t,e,s,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new tg(e,s);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new Gf(e,o,c,a),this.volumesDrawer=new Jf(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:s},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",fn),this.registerVolumeColorResolver("trend",fn),this.registerVolumeColorResolver("hollow",fn),this.registerVolumeColorResolver("line",Kf),this.registerVolumeColorResolver("bar",Zf)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t),this.syncVolumesDynamicObject())}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.syncVolumesDynamicObject(),this.canvasModel.fireDraw()}syncVolumesDynamicObject(){if(!this.config.components.volumes.visible){this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id);return}const e=this.config.components.volumes.showSeparately?Lo:K,s={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(s);return}this.dynamicObjectsComponent.model.updateObject(s)}}class sg{constructor(t,e,s,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=s,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(T.PANE_UUID(K)),{position:p,offsetY:v,offsetX:x}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=bs(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=ng(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),p){case"left-top":return{x:x+f.x,y:v+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:x+f.x,y:f.height-h-v+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,s,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let p=0,v=0,x=0,_=0,A=0;if(f.save(),d.firstRowFontSize&&l){f.font=bs(this.config,d.firstRowFontSize);const B=f.measureText(l);p=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=bs(this.config,d.secondRowFontSize);const B=f.measureText(c);v=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,x=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=bs(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,A=(s=d.secondRowBottomPadding)!=null?s:0}const L=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,F=p+v+x+_+A+L+j;if(l&&this.drawWaterMark(this.getConfig(p,l,d.firstRowFontSize,u.firstRowColor,F)),c&&this.drawWaterMark(this.getConfig(p+x+v,c,d.secondRowFontSize,u.secondRowColor,F)),h&&this.drawWaterMark(this.getConfig(p+x+v+A+_,h,d.thirdRowFontSize,u.thirdRowColor,F)),this.logoImage){const B=this.getConfig(p+x+v+A+_+L,"",d.thirdRowFontSize,u.thirdRowColor,F,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const s=this.canvasModel.ctx;s.font=t.font,s.fillStyle=t.color;const i=t.x,r=t.y;s.fillText(e,i,r)}reset(){}}const ng=(n,t,e,s)=>{const r=((a,l)=>t.getBounds(T.CHART).width/l*a)(e,s);let o;return n.components&&n.components.waterMark&&(o=n.components.waterMark.fontFamily),r+"px "+o},bs=(n,t)=>{let e;return n.components&&n.components.waterMark&&(e=n.components.waterMark.fontFamily),t+"px "+e};var ig=Object.defineProperty,Oo=Object.getOwnPropertySymbols,rg=Object.prototype.hasOwnProperty,og=Object.prototype.propertyIsEnumerable,Bo=(n,t,e)=>t in n?ig(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ro=(n,t)=>{for(var e in t||(t={}))rg.call(t,e)&&Bo(n,e,t[e]);if(Oo)for(var e of Oo(t))og.call(t,e)&&Bo(n,e,t[e]);return n};class ag extends X{constructor(t,e,s,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=s,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new sg(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(T.PANE_UUID(K)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return Ro(Ro({},this.config.components.waterMark),h)}}const Fo={x:4,y:4};function lg(n,t,e,s){var i,r;const o=(i=s.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(T.X_AXIS);n.save(),n.font=`bold ${a}px ${l}`;const p=n.measureText(s.text).width+Fo.x*2;let v=0;const x=s.x;switch(o){case"start":v=x-p;break;case"end":v=x;break;case"middle":default:v=x-p/2;break}n.fillStyle=h.backgroundColor,n.strokeStyle=h.backgroundColor,n.fillRect(v,u.y,p,u.height),o!=="middle"&&(n.strokeStyle=s.color,n.beginPath(),n.moveTo(x,u.y),n.lineTo(x,u.y+u.height),n.stroke()),n.fillStyle=s.color;const _=v+Fo.x,A=u.y+d+a+Ie/2;n.fillText(s.text,_,A),n.restore()}class cg{constructor(t,e,s,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=s,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{lg(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},s=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(s).forEach(i=>{const r=s[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(T.X_AXIS);t.fillStyle=Lt().rgb(r[0].color).alpha(.1).toString(),Tr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const Jm="week-weekday",hg=["second","minute","hour","day","month","year"],dg=["lessThanSecond"],ug=n=>hg.some(t=>t===n),fg=n=>n==="week-weekday",gg=n=>dg.some(t=>t===n),Ho=n=>{const t={"!":!1,$:!1};return n.includes("!")&&(t["!"]=!0),n.includes("$")&&(t.$=!0),t},gn=n=>parseInt(n,10),ko=n=>{const[t,...e]=n.split("_");if(ug(t)){const[s]=e,i=Ho(s),r=gn(s);return{key:t,value:r,exact:i["!"]}}else if(fg(t)){const[s,i]=e,r=Ho(s),o=gn(s),a=gn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return gg(t)?{key:t}:(console.warn(`${n} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class Cs{constructor(t,e,s,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=s,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,s=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=Cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=s.backgroundColor;const l=this.canvasBoundsContainer.getBounds(T.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Ie/2),e.restore()}}drawLabels(t,e,s,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Pt(c.text,t,l)/2;if(h<s.x||h>s.width)continue;const d=s.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const pn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},Yo=n=>{switch(n.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return pn[n.key]+n.value;case"lessThanSecond":return pn[n.key];case"week-weekday":return pn[n.key]+(n.week==="$"?9:n.week)+n.weekday*10}},jo=n=>{const t={};for(const e of n){const s=t[e.weight];s===void 0?t[e.weight]=[e]:s.push(e)}return t},pg=(n,t)=>{const e=Object.keys(n).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let s=[];for(const i of e){const r=n[i];if(!r)continue;const o=[...s];s=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],p=f.idx;for(;c<a;){const v=o[c],x=v.idx;if(p>x)c++,s.push(v),d=x,h=1/0;else{h=x;break}}h-p>=t&&p-d>=t&&(s.push(f),d=p)}for(;c<a;)s.push(o[c]),c++}return s},mg=(n,t,e,s,i,r)=>{const o=Cs.getFontFromConfig(t),a=Pt(e.text,n,o),l=Pt(s.text,n,o),c=i.toX(e.value)+a/2;return i.toX(s.value)-l/2-c<r},Qm=7,vg=365.2425,ev=-(Math.pow(10,8)*24*60*60*1e3),sv=6048e5,nv=864e5,iv=6e4,rv=36e5,ov=1e3,av=525600,lv=43200,cv=1440,hv=60,dv=3,uv=12,fv=4,bg=3600,gv=60,No=bg*24,pv=No*7,bv=No*vg/12*3,Xo=Symbol.for("constructDateFrom");function mn(n,t){return typeof n=="function"?n(t):n&&typeof n=="object"&&Xo in n?n[Xo](t):n instanceof Date?new n.constructor(t):new Date(t)}const Cv=null;function Ft(n,t){return mn(t||n,n)}const yv=null;function Cg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===1}const wv=null;function yg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===2}const Sv=null;function wg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===3}const xv=null;function Sg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===4}const _v=null;function xg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===5}const Pv=null;function _g(n,t){return Ft(n,t==null?void 0:t.in).getDay()===6}const Tv=null;function Pg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===0}const Mv=null;function Wo(n,...t){const e=mn.bind(null,n||t.find(s=>typeof s=="object"));return t.map(e)}function Tg(n,t){const[e,s]=Wo(n,t.start,t.end);return{start:e,end:s}}function Mg(n,t){var c;const{start:e,end:s}=Tg(t==null?void 0:t.in,n);let i=+e>+s;const r=i?+e:+s,o=i?s:e;o.setHours(0,0,0,0);let a=(c=t==null?void 0:t.step)!=null?c:1;if(!a)return[];a<0&&(a=-a,i=!i);const l=[];for(;+o<=r;)l.push(mn(e,o)),o.setDate(o.getDate()+a),o.setHours(0,0,0,0);return i?l.reverse():l}const Av=null;function Ag(n,t){const e=Ft(n,t==null?void 0:t.in);return e.setDate(1),e.setHours(0,0,0,0),e}const Ev=null;function Eg(n,t){const e=Ft(n,t==null?void 0:t.in),s=e.getMonth();return e.setFullYear(e.getFullYear(),s+1,0),e.setHours(23,59,59,999),e}const Iv=null;function zo(n,t){const e=Ft(n,t==null?void 0:t.in);return e.setHours(0,0,0,0),e}const Dv=null;function Vo(n,t,e){const[s,i]=Wo(e==null?void 0:e.in,n,t);return+zo(s)==+zo(i)}const Lv=null,Ig=n=>{switch(n.key){case"lessThanSecond":return Bg(n);case"month":return Rg(n);case"second":case"minute":case"hour":case"day":case"year":return Fg(n);case"week-weekday":return Hg(n);default:return()=>!1}},qt=(n,t)=>{switch(t){case"lessThanSecond":return n.getMilliseconds();case"month":return n.getMonth();case"second":return n.getSeconds();case"minute":return n.getMinutes();case"hour":return n.getHours();case"day":return n.getDate();case"year":return n.getFullYear();case"week-weekday":return n.getDate()}},vn=n=>(t,e)=>{const s=qt(t,n),i=qt(e,n);return s!==i},Dg=n=>(t,e)=>{const s=qt(t,n),i=qt(e,n);return s>=i},Lg={1:Cg,2:yg,3:wg,4:Sg,5:xg,6:_g,7:Pg},Og=(n,t,e)=>{var s;const i=Mg({start:Ag(n),end:Eg(n)}),r=(s=Lg[e])!=null?s:(()=>!1);if(t==="$"){for(const o of i.reverse())if(r(o))return Vo(n,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return Vo(n,a);o++}}return!1},Uo=(n,t)=>t===1?n===1:n/t===1,Go=(n,t)=>t===1?!0:n%t===0,Bg=n=>(t,e)=>Dg(n.key)(t,e),Rg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=n.exact?Uo(qt(t,n.key)+1,n.value):Go(qt(t,n.key)+1,n.value);return s&&i},Fg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=n.exact?Uo(qt(t,n.key),n.value):Go(qt(t,n.key),n.value);return s&&i},Hg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=Og(t,n.week,n.weekday);return s&&i},kg=n=>{switch(n.key){case"second":case"minute":return Yg(n.value);case"hour":return jg(n.value);case"day":return Ng(n.value);case"month":return zg(n.value);case"year":return Vg(n.value);case"week-weekday":const t=Wg(n.week),e=Xg(n.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},Yg=n=>n>0&&n<=60,jg=n=>n>0&&n<=24,Ng=n=>n>0&&n<=31,Xg=n=>Zo(n)?n>=1&&n<=7:!1,Wg=n=>n==="$"?!0:Zo(n)?n>=1&&n<=6:!1,zg=n=>n>0&&n<=12,Vg=n=>n>0,Zo=n=>!isNaN(n)&&isFinite(n),Ug=(n,t,e)=>{var s,i;for(const[r,o]of e)if(o(n,t))return r;return(i=(s=e[e.length-1])==null?void 0:s[0])!=null?i:0};function bn(n,t,e){const s=new Array(n.length);let i=e(0);for(let r=0;r<n.length;r++){const o=n[r],a=e(o.candle.timestamp),l={weight:Ug(a,i,t)};s[r]=l,i=a}return s}const $o=n=>{const t={},e={};return qs(n).forEach(([s,i])=>{const r=ko(s),o=r===null?!1:kg(r);if(r&&o){const a=Yo(r);t[a]=i,e[a]=Ig(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Ko{constructor(t,e,s,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=s,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.labelCache=new Map,this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?mt(d,h.animationConfig.targetZoomX):mt(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,p=Object.values(this.formatsByWeightMap).reduce((x,_)=>Math.max(_.length,x),1),v=f*p;return Math.round(v/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=$o(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(T.X_AXIS),s=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||s.push(i)}return s}getLabelsFromChartType(){var t,e;const s=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(s):s}getVisualCandleAtIndex(t,e,s,i,r){return t>=0&&t<s.length?s[t]:tn(e,s,i,t,r)}getVisualCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>tn(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}getViewportCandlesWithFake(){var t;const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0||this.scale.xEnd-this.scale.xStart<=1)return[];const s=this.chartModel.mainCandleSeries.meanCandleWidth,i=this.chartModel.getPeriod(),r=this.chartModel.mainCandleSeries.dataPoints,o=this.canvasBoundsContainer.getBounds(T.CHART),a=0,l=o.width,c=this.scale.fromX(a),h=this.scale.fromX(l);let d=0;if(e.length>0){const L=e[0];d=L.centerUnit-((t=L.candle.idx)!=null?t:0)*s}const u=500,f=500,p=Math.floor((c-d)/s)-u,v=Math.ceil((h-d)/s)+u,x=Math.floor(p/f)*f,_=Math.ceil(v/f)*f,A=[];for(let L=x;L<=_;L++)A.push(this.getVisualCandleAtIndex(L,r,e,s,i));return[...A]}getAllCandlesWithFake(t=[]){return this.config.components.chart.minCandlesOffset?this.getVisualCandlesWithFake(t):this.getViewportCandlesWithFake()}mapWeightedPointsToLabels(t,e){var s;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(s=a.candle.idx)!=null?s:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){this.clearLabelCache();const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:s}=$o(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(s).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=bn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),s=bn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(s,e),r=jo(i),o=ne(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const p=f.map(v=>(v.idx=v.idx+t.length,v.value=a.startUnit+a.width+v.value,v));r[u]?c[h]=d.concat(p):c[h]=p}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t,e=!1){var s;const i=this.getAllCandlesWithFake(t),r=bn(i,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone));let o=[];if(e)for(let a=0;a<i.length;a++){const l=(s=i[a].candle.idx)!=null?s:a,c=i[a].candle.timestamp,h=`${l}_${c}`;let d=this.labelCache.get(h);d||(d=this.mapWeightedPointsToLabels([r[a]],[i[a]])[0],this.labelCache.set(h,d)),o.push(d)}else o=this.mapWeightedPointsToLabels(r,i);this.labelsGroupedByWeight=jo(o),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const s=pg(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=s,this.weightedCache={labels:s,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,s;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];mg(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((s=a.weight)!=null?s:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const s=qs(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=ko(o);if(l){const c=Yo(l);i[c]=a}}return i},{});return qs(t).reduce((i,[r,o])=>(s[r]&&s[r](e)||(i[r]=o),i),{})}clearLabelCache(){this.labelCache.clear()}}class Gg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(hs,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const qo=3;class Zg extends X{constructor(t,e,s,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(T.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,p=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(p,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(qo-1)):u=1+h/this.lastXPxWidth*(qo-1);const p=(this.lastXWidth*u-this.lastXWidth)/2,v=this.lastXStart-p,x=this.lastXEnd+p;(this.lastXStart!==v||this.lastXEnd!==x)&&this.scale.setXScale(v,x)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Ye(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class $g extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=s,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=x=>this.xAxisScaleHandler.setDblClickCallback(x),this.setDblTapCallback=x=>this.xAxisScaleHandler.setDblTapCallback(x);const p=new Ko(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=p,this.xAxisLabelsModel=new Gg(t,[]);const v=new rn;c.addDrawer(v,"X_AXIS"),this.xAxisDrawer=new Cs(e,s,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),v.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new cg(e,s,o,this.xAxisLabelsModel),v.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new Zg(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(T.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(T.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(Z(({prependedCandles:t})=>t.length!==0),ct(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,s;Yl.includes(this.config.components.chart.type)&&((s=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||s.call(e,t))})),this.config.components.chart.minCandlesOffset?this.addRxSubscription(Ct(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Et(50,Ot,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.recalculateLabels())):this.addRxSubscription(Ct(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Et(150,Ot,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.generateLabels(void 0,!0))),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ct(()=>wt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),_t((t,e)=>{var s,i;return((s=t==null?void 0:t.candle)==null?void 0:s.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),Z(ri)).subscribe(t=>{var e,s;return(s=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:s.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Ko?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var Kg=Object.defineProperty,Jo=Object.getOwnPropertySymbols,qg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,Qo=(n,t,e)=>t in n?Kg(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ys=(n,t)=>{for(var e in t||(t={}))qg.call(t,e)&&Qo(n,e,t[e]);if(Jo)for(var e of Jo(t))Jg.call(t,e)&&Qo(n,e,t[e]);return n};class Qg{constructor(t,e,s,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=s,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const s=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=s&&ys(ys({},s),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&ys(ys({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=wt(t.dataPoints);if(e){const s=t.view.toY(e.close);if(isFinite(s)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:s,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const s=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:te("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:yf(t.lastPriceMovement,i);return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):te(l,h,o),rounded:!0}}return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):te(l,r,o),rounded:!0}}}class tp{constructor(t,e,s,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=s,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,s=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(T.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>eo(t,s,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>eo(t,s,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,s={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=s[r.subGroupId])!=null?o:[];if(s[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(K));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];Tr(e,{x:h.x,y:Fi(d,h)},{x:h.x+h.width-6,y:Fi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class ep{constructor(t,e,s){this.fullConfig=t,this.canvasModel=e,this.paneManager=s}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const s=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=ee(e.state),a=Nt(o,r),l=this.getLabelTextColor();r.save(),Zt(r,i),this.drawLabels(r,s,i,a,o,l,e),r.restore()}})}drawLabels(t,e,s,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=s.y+c,d=s.y+s.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&sp(t,s,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const sp=(n,t,e,s,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,n,r)-o:t.x+o;n.fillText(e,l,s+i/2-1)};class np{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const s=this.handlers[t];s!==void 0&&wl.call(s,e)},this.add=(t,e,s)=>(e in this.handlers?t.call(this.handlers[e],s):this.handlers[e]=[s],this.unsub.bind(this,e,s)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new R,s=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,s),e.unsubscribe=()=>{this.unsub(t,s),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var s;if(!this.muted){const i=(s=this.handlers[t])!=null?s:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(hs,t)}}class ip extends X{constructor(t,e,s,i){super(),s.observeTouchStart().pipe(ct(r=>i.components.chart.highlightActiveCandle?r:void 0),_t()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,s){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=s.candleFromX(r);o&&s.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const s=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-s.left-i}}class rp{constructor(t,e,s,i,r){this.frameElement=t,this.resizerElement=e,this.bus=s,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${yt()}`,this.canvasResized=new R,this.recentlyResized=!1,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){_e(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.recentlyResized=!0,this.canvasModels.forEach(s=>this.previousBCR&&s.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(cs,e),this.bus.fire(hs))}clearResizedFlag(){this.recentlyResized=!1}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.recentlyResized}}var op=Array.isArray,ap=Object.getPrototypeOf,lp=Object.prototype,cp=Object.keys;function hp(n){if(n.length===1){var t=n[0];if(op(t))return{args:t,keys:null};if(dp(t)){var e=cp(t);return{args:e.map(function(s){return t[s]}),keys:e}}}return{args:n,keys:null}}function dp(n){return n&&typeof n=="object"&&ap(n)===lp}var up=Array.isArray;function fp(n,t){return up(t)?n.apply(void 0,D([],m(t))):n(t)}function ta(n){return ct(function(t){return fp(n,t)})}function gp(n,t){return n.reduce(function(e,s,i){return e[s]=t[i],e},{})}function pp(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=ja(n),i=hp(n),r=i.args,o=i.keys;if(r.length===0)return Ge([],e);var a=new gt(mp(r,e,o?function(l){return gp(o,l)}:de));return s?a.pipe(ta(s)):a}function mp(n,t,e){return e===void 0&&(e=de),function(s){ea(t,function(){for(var i=n.length,r=new Array(i),o=i,a=i,l=function(h){ea(t,function(){var d=Ge(n[h],t),u=!1;d.subscribe(bt(s,function(f){r[h]=f,u||(u=!0,a--),a||s.next(e(r.slice()))},function(){--o||s.complete()}))},s)},c=0;c<i;c++)l(c)},s)}}function ea(n,t,e){n?kt(e,n,t):t()}class vp extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,s){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,s)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const s=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=pp([s,i]).pipe(Z(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!jt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function bp(n,t){return N(function(e,s){var i=null,r=0,o=!1,a=function(){return o&&!i&&s.complete()};e.subscribe(bt(s,function(l){i==null||i.unsubscribe();var c=0,h=r++;At(n(l,h)).subscribe(i=bt(s,function(d){return s.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Cp{constructor(t,e,s,i){this.visualCandle=t,this.price=e,this.priceFormatter=s,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class yp{constructor(t){this.chartModel=t}getData(t){const{x:e,y:s}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(s);return o&&new Cp(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class wp{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof Xr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Sp=Object.defineProperty,xp=Object.defineProperties,_p=Object.getOwnPropertyDescriptors,sa=Object.getOwnPropertySymbols,Pp=Object.prototype.hasOwnProperty,Tp=Object.prototype.propertyIsEnumerable,na=(n,t,e)=>t in n?Sp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,je=(n,t)=>{for(var e in t||(t={}))Pp.call(t,e)&&na(n,e,t[e]);if(sa)for(var e of sa(t))Tp.call(t,e)&&na(n,e,t[e]);return n},Cn=(n,t)=>xp(n,_p(t));class Mp extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=s,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new yp(this.chartModel),u=new wp(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(bp(()=>this.scale.initialViewportValidSubject.pipe(Z(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(Ct(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var s;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((s=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:s.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var s;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((s=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:s.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var s,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!bo(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(s=this.crossEventProducer.crossToolHover)==null?void 0:s.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(T.PANE_UUID(d)),f=u.y+5,p=u.y+u.height-5,v=c-l.x,x=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=v,A=a.y<f?f:a.y>p?p:a.y+=x;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:A}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=no(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),s=this.scale.toY(t.close);return this.createHover(e,s,K)}createHover(t,e,s){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:s},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>Cn(je({},l),{[c[0]]:c[1].getData(o)}),{});return je(je({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const s=Cn(je({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(s)}}createAndFireHover([t,e,s]){const i=this.createHover(t,e,s);this.fireHover(i)}fireHover(t){var e,s;if(t){if(jt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(s=t.candleHover)==null?void 0:s.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=Cn(je({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const ia={left:0,middle:1,right:2};function vt(n,t,e,s){return n.addEventListener(e,t,s),function(){n.removeEventListener(e,t,s)}}function we(n){return t=>{t.button===ia.left&&n(t)}}var Ap=["addListener","removeListener"],Ep=["addEventListener","removeEventListener"],Ip=["on","off"];function yn(n,t,e,s){if(k(e)&&(s=e,e=void 0),s)return yn(n,t,e).pipe(ta(s));var i=m(Op(n)?Ep.map(function(a){return function(l){return n[a](t,l,e)}}):Dp(n)?Ap.map(ra(n,t)):Lp(n)?Ip.map(ra(n,t)):[],2),r=i[0],o=i[1];if(!r&&Ds(n))return Os(function(a){return yn(a,t,e)})(At(n));if(!r)throw new TypeError("Invalid event target");return new gt(function(a){var l=function(){for(var c=[],h=0;h<arguments.length;h++)c[h]=arguments[h];return a.next(1<c.length?c:c[0])};return r(l),function(){return o(l)}})}function ra(n,t){return function(e){return function(s){return n[e](t,s)}}}function Dp(n){return k(n.addListener)&&k(n.removeListener)}function Lp(n){return k(n.on)&&k(n.off)}function Op(n){return k(n.addEventListener)&&k(n.removeEventListener)}var Bp=Object.defineProperty,oa=Object.getOwnPropertySymbols,Rp=Object.prototype.hasOwnProperty,Fp=Object.prototype.propertyIsEnumerable,aa=(n,t,e)=>t in n?Bp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Hp=(n,t)=>{for(var e in t||(t={}))Rp.call(t,e)&&aa(n,e,t[e]);if(oa)for(var e of oa(t))Fp.call(t,e)&&aa(n,e,t[e]);return n};const ws=class ce extends X{constructor(t,e){super(),this.eventBus=t,this.element=e,this.xDragStartSubject=new R,this.xDragSubject=new R,this.xDragTickSubject=new R,this.xDragEndSubject=new R,this.yDragStartSubject=new R,this.yDragSubject=new R,this.yDragTickSubject=new R,this.yDragEndSubject=new R,this.mouseMoveSubject=new R,this.mouseMoveDocumentSubject=new R,this.clickSubject=new R,this.clickDocumentSubject=new R,this.dbClickSubject=new R,this.dbTapSubject=new R,this.mouseDownSubject=new R,this.mouseUpSubject=new R,this.mouseUpDocumentSubject=new R,this.wheelSubject=new R,this.touchStartSubject=new R,this.touchStartTimestamp=0,this.touchMoveSubject=new R,this.touchEndSubject=new R,this.touchCancelSubject=new R,this.longTouchStartSubject=new R,this.longTouchEndSubject=new R,this.contextMenuSubject=new R,this.fastTouchScroll=new R,this.mouseLeavesCanvasSubject=new R,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.cachedElementRect=null,this.rectCacheValid=!1,this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=s=>{this.isDraggable(s)&&(this.updateCurrentPoints(s),this.dragging=!0,this.dragStartEvent=s,this.cleanupDocumentDragListeners(),this.dragStartPoint=ce.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Hp({},this.dragStartPoint),ce.DRAG_EVENTS.forEach(i=>{document.addEventListener(i,this.dragProcessListener,!0);const r=document.removeEventListener.bind(document,i,this.dragProcessListener,!0);this.documentDragListeners.push(r),this.addSubscription(r)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.cleanupDocumentDragListeners(),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=s=>{this.updateCurrentDocumentPoint(s),this.updateCurrentMousePoint(s)}}getElementRect(){if(this.rectCacheValid&&this.cachedElementRect)return this.cachedElementRect;try{if(!this.element||!this.element.isConnected)return this.createFallbackRect();const t=this.element.getBoundingClientRect();return this.cachedElementRect=t,this.rectCacheValid=!0,t}catch(t){return this.createFallbackRect()}}createFallbackRect(){return typeof DOMRect!="undefined"?new DOMRect(0,0,0,0):{x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON:()=>({})}}invalidateRectCache(){this.rectCacheValid=!1}initializeRectCache(){this.invalidateRectCache();const t=this.getElementRect();this.canvasBounds.x=t.left,this.canvasBounds.y=t.top,this.canvasBounds.width=t.width,this.canvasBounds.height=t.height}cleanupDocumentDragListeners(){if(!this.documentDragListeners||!Array.isArray(this.documentDragListeners)){this.documentDragListeners=[];return}this.documentDragListeners.forEach(t=>{try{t()}catch(e){console.warn("Error cleaning up drag listener:",e)}}),this.documentDragListeners=[]}doDeactivate(){this.invalidateRectCache(),this.cachedElementRect=null,this.cleanupDocumentDragListeners(),super.doDeactivate()}isDraggable(t){return t instanceof MouseEvent?t.button===ia.left:t instanceof TouchEvent}startDragging(t){this.updateCurrentPoints(t),this.dragStartListener(t)}movePointer(t){this.updateCurrentPoints(t),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const t=e=>(e.preventDefault(),!1);this.element.addEventListener("selectstart",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",t,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ce.DRAG_START_EVENTS.forEach(s=>{this.element.addEventListener(s,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(s,this.dragStartListener))}),this.trackMousePosition(),ce.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragListener)),this.element.addEventListener(s,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,s,this.updateElementOffsetListener))}),ce.DRAG_END_EVENTS.forEach(s=>{document.addEventListener(s,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragEndListener))}),this.addSubscription(vt(this.element,we(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(vt(document,we(s=>this.clickDocumentSubject.next(s)),"click"));const t=ms();if(t==="apple"||t==="mobile"){let s=null;const i=a=>{a.preventDefault(),s?(this.dbTapSubject.next(this.currentPoint),clearTimeout(s),s=null):s=window.setTimeout(()=>{s=null},250)};this.addSubscription(vt(this.element,i,"touchend"));const r=(a,l=200)=>{a.preventDefault();let c=!1,h=null;h=setTimeout(()=>{c=!0,this.longTouchStartSubject.next(a)},l);const d=f=>{f.preventDefault(),f.touches.length>1&&h&&clearTimeout(h)},u=f=>{f.preventDefault(),h&&clearTimeout(h),c&&(c=!1,this.longTouchEndSubject.next(f)),this.element.removeEventListener("touchend",u),this.element.removeEventListener("touchmove",d)};this.element.addEventListener("touchmove",d),this.element.addEventListener("touchend",u)};this.addSubscription(vt(this.element,a=>r(a),"touchstart"));const o=a=>{if(a.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const h=this.touchStartTimestamp,u=Date.now()-h,p=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,v=u<=250;p&&v&&this.fastTouchScroll.next(a)}};this.addSubscription(vt(this.element,o,"touchend"))}this.addSubscription(vt(this.element,we(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(vt(this.element,s=>{this.touchStartSubject.next(s),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(vt(this.element,s=>this.touchMoveSubject.next(s),"touchmove",!0)),this.addSubscription(vt(this.element,s=>this.touchEndSubject.next(s),"touchend")),this.addSubscription(vt(this.element,s=>this.touchCancelSubject.next(s),"touchcancel")),this.addSubscription(vt(this.element,s=>{this.updateCurrentPoints(s),this.wheelSubject.next(s),s.preventDefault()},"wheel")),this.addSubscription(vt(this.element,s=>this.contextMenuSubject.next(s),"contextmenu")),this.addSubscription(vt(this.element,we(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(vt(this.element,we(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(vt(document,we(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(cs).subscribe(()=>{this.invalidateRectCache();const s=this.getElementRect();this.canvasBounds.x=s.left,this.canvasBounds.y=s.top,this.canvasBounds.width=s.width,this.canvasBounds.height=s.height})),this.addRxSubscription(yn(document,"scroll",{capture:!0,passive:!0}).pipe(Et(ie,is,{trailing:!0})).subscribe(()=>this.invalidateRectCache()));const e=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",e,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",e,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ce.DRAG_EVENTS.forEach(t=>{document.addEventListener(t,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(t,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(t){"pageX"in t?this.currentPointDocument.x=t.pageX:t.touches!==void 0&&(this.currentPointDocument.x=t.touches[0].pageX),"pageY"in t?this.currentPointDocument.y=t.pageY:t.touches!==void 0&&(this.currentPointDocument.y=t.touches[0].pageY)}updateCurrentMousePoint(t){const e=this.getElementRect();"clientX"in t?this.currentPoint.x=t.clientX-e.left:t.touches!==void 0&&(this.currentPoint.x=t.touches[0].clientX-e.left),"clientY"in t?this.currentPoint.y=t.clientY-e.top:t.touches!==void 0&&(this.currentPoint.y=t.touches[0].clientY-e.top)}static copyPoint(t){return{x:t.x,y:t.y}}observeMouseMove(t=()=>!0){return this.mouseMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(Z(()=>!this.dragging))}observeMouseMoveDocument(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPointDocument.x,this.currentPointDocument.y)),ct(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(t=()=>!0){return this.xDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(t=()=>!0){return this.xDragSubject.pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(t=()=>!0){return this.xDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(t=()=>!0){return this.yDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(t=()=>!0){return this.yDragSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(t=()=>!0){return this.yDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(t=()=>!0,e=!1){const s=this.mouseMoveSubject.asObservable().pipe(Z(()=>!(e&&this.dragging)),ct(()=>t(this.currentPoint.x,this.currentPoint.y))),i=this.observeMouseLeavesCanvas().pipe(ct(()=>!1));return Ct(s,i).pipe(_t())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(t=()=>!0){return this.clickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(t=()=>!0){return this.dbClickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(t=()=>!0){return this.dbTapSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeWheel(t=()=>!0){return this.wheelSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(t=()=>!0){return this.touchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(t=()=>!0){return this.touchMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(t=()=>!0){return this.mouseDownSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(t=()=>!0){return this.mouseUpSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(t=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(t=()=>!0){return this.contextMenuSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)),Ao(e=>e.preventDefault()))}observeLongTouchStart(t=()=>!0){return this.longTouchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(t=()=>!0){return this.longTouchEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(t=()=>!0){return this.fastTouchScroll.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};ws.DRAG_START_EVENTS=["mousedown","touchstart"],ws.DRAG_EVENTS=["mousemove","touchmove"],ws.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];let kp=ws;var Yp=(function(n){z(t,n);function t(e,s,i){e===void 0&&(e=1/0),s===void 0&&(s=1/0),i===void 0&&(i=Zs);var r=n.call(this)||this;return r._bufferSize=e,r._windowTime=s,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=s===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,s),r}return t.prototype.next=function(e){var s=this,i=s.isStopped,r=s._buffer,o=s._infiniteTimeWindow,a=s._timestampProvider,l=s._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),n.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var s=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),s},t.prototype._trimBuffer=function(){var e=this,s=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*s;if(s<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t})(R);const wn={};function jp(n){return wn[n]||(wn[n]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:n,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),wn[n]}const la=(n,t=Date.now())=>{const s=jp(n).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(s);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},ca=60*1e3;class Np{constructor(t){this.config=t,this.timeZoneChangedSubject=new Yp,this.currentTzOffset=e=>la(this.config.timezone,e)+new Date(e).getTimezoneOffset()*ca,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const s=t.createFormatterFunction;e=i=>s(i).bind(t)}else e=cu(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+la(t,e)+new Date(e).getTimezoneOffset()*ca):e=>new Date(e)}}class Xp extends X{constructor(t,e,s){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=s}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(_t((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}var Wp=Object.defineProperty,zp=Object.defineProperties,Vp=Object.getOwnPropertyDescriptors,ha=Object.getOwnPropertySymbols,Up=Object.prototype.hasOwnProperty,Gp=Object.prototype.propertyIsEnumerable,da=(n,t,e)=>t in n?Wp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Zp=(n,t)=>{for(var e in t||(t={}))Up.call(t,e)&&da(n,e,t[e]);if(ha)for(var e of ha(t))Gp.call(t,e)&&da(n,e,t[e]);return n},$p=(n,t)=>zp(n,Vp(t));class Kp extends ii{constructor(t){super(t),this.animations={},this.animFrameId="animation",this.animationInProgressSubject=new ut(!1),this.microtaskQueued=!1}startViewportMovementAnimation(t,e,s=ue,i){const r=new ti(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new Jn($p(Zp({},i),{duration:i&&i.duration||Ae}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ae,i){const r=new Qn({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0,delete this.animations[t]),Object.keys(this.animations).length===0&&this.stopInterval()}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.microtaskQueued||(this.microtaskQueued=!0,queueMicrotask(()=>{this.microtaskQueued=!1,this.processAnimation(),this.eventBus.fireDraw()}))}stopInterval(){Ka(this.animFrameId),this.microtaskQueued=!1}}class Sn{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var s,i;this.parentElement=t;const r=e;jl(r),this.config=r;const o=ac(r);t.innerHTML="",t.appendChild(o.content),this.id=(s=t.getAttribute("data-id"))!=null?s:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new Np(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=lc(t);this.elements=c;const h=new np;this.bus=h;const d=new rp(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new id(h,d);this.drawingManager=u;const f=sd(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=ae(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const p=new Ce(this.dynamicObjectsCanvasModel);u.addDrawer(p,"SERIES_CLEAR");const v=ae(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),x=ae(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Gs(r,h,f,l,d);this.canvasBoundsContainer=_;const A=c.mainCanvas.parentElement;if(A===null)throw new Error("Couldn't get main canvas parent");const L=new kp(h,A);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const j=[h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer],F=new xu(...j);this.hitTestCanvasModel=F;const B=new Ce(F);u.addDrawer(B,"HIT_TEST_CLEAR");const Y=Me?new Kp(h):new ii(h);this.canvasAnimation=Y;const $=T.PANE_UUID(K),W=new _r(r,()=>_.getBounds($),Y);this.scaleModel=W;const U=ae(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=U,this.cursorHandler=new ic(c.canvasArea,L,_,F),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new vp(L,_),this.chartComponents.push(this.crossEventProducer);const G=new Nc("candle");this.chartBaseModel=G;const V=new cf(h,W,_,r,Y,L,A,G,F);this.chartPanComponent=V,this.chartComponents.push(V),this.userInputListenerComponents.push(V.chartAreaPanHandler);const Q=new Xp(F,Y,h);this.hitTestComponent=Q,this.chartComponents.push(Q);const J=new zf(G,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,Y,L,u,this.cursorHandler,this.crossEventProducer,V,f,v,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=J;const et=this.paneManager.panes[K];this.mainPane=et,this.chartComponents.push(J),this.dynamicObjects=new au(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Yd(G,J,h,this.dynamicObjectsCanvasModel,r,W,l,A,_,d);const tt=new Sd(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,F,L,U,V,J,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const st=this.chartComponent.chartModel;this.chartModel=st,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),F.addSubscriber(J.hitTestController),this.xAxisComponent=new $g(h,r,f,tt,W,_,L,d,this.drawingManager,a,V,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const ht=new Ce(f);u.addDrawer(ht,"MAIN_CLEAR");const at=new ip(A,st,L,r);this.chartComponents.push(at),this.watermarkComponent=new ag(J,st,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const St=ae(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new Xu(h,r,st,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(st)),this.navigationMapComponent=new qu(h,st,f,r,L,_,u,l,V,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Ut=new Ru(r,this.dynamicObjectsCanvasModel,st,_,u);this.chartComponents.push(Ut),this.initYAxisDrawer(v,x),this.yAxisComponent=et.mainExtent.yAxis;const Se=new Qg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(Se,se.MAIN),this.volumesComponent=new eg(this.dynamicObjectsCanvasModel,tt,W,_,u,r,J,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const ma=new ho(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(T.ALL_PANES),()=>this.canvasBoundsContainer.getBounds($),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,void 0,()=>r.components.grid.visible,this.mainPane.mainExtent.idx);this.chartComponents.push(ma),this.hoverProducer=new Mp(this.crossEventProducer,W,r,st,L,this.canvasBoundsContainer,this.paneManager,a,V.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new nu(r,St,_,u,J,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel,this.chartModel),this.chartComponents.push(this.crossToolComponent);const va=ae(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),xn=new Vf(this.elements,va);this.snapshotComponent=xn,this.chartComponents.push(xn);const xs=new Lu(r,this.dynamicObjectsCanvasModel,F,st,_,u,l,this.cursorHandler);this.eventsComponent=xs,this.chartComponents.push(xs),this.chartComponents.forEach(cm=>cm.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=pl(this.components)}initYAxisDrawer(t,e){const s=new rn,i=new Ce(t),r=new Ce(e);s.addDrawer(i,"YAXIS_CLEAR"),s.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(s,"Y_AXIS");const o=new ep(this.config,t,this.paneManager);s.addDrawer(o);const a=new tp(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:s=>e.test(s)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const s in e)s in t?typeof t[s]=="object"&&Sn.mergeConfig(t[s],e[s]):t[s]=e[s];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,s,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(s=t.dash)!=null?s:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Tt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(s).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,s=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,s).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(s).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=Ct(this.canvasInputListener.observeYDrag(s),this.canvasInputListener.observeXDrag(s)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const s=t(this);this.components.push(s),e&&e(s),s.activate()}}class ua extends Sn{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var s;(s=this.paneManager.panes[t])==null||s.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.setAllSeries(e,s)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.updateAllSeries(e,s)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}setTreasuryFormat(t){this.config.components.yAxis.treasuryFormat=t,this.paneManager.yExtents.forEach(e=>{e.yAxis.model.labelsGenerator.updateTreasuryFormat(t),e.yAxis.model.labelsGenerator.doGenerateLabels(),e.yAxis.model.fancyLabelsModel.updateLabels(!0),e.yAxis.model.baseLabelsModel.updateLabels()})}createPane(){return this.paneManager.createPane()}}var qp=Object.defineProperty,Jp=Object.defineProperties,Qp=Object.getOwnPropertyDescriptors,fa=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,em=Object.prototype.propertyIsEnumerable,ga=(n,t,e)=>t in n?qp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sm=(n,t)=>{for(var e in t||(t={}))tm.call(t,e)&&ga(n,e,t[e]);if(fa)for(var e of fa(t))em.call(t,e)&&ga(n,e,t[e]);return n},nm=(n,t)=>Jp(n,Qp(t));function pa(n){n=n||{},n.quantity=n.quantity||200,n.startY=n.startY||50,n.avgCandleSize=n.avgCandleSize||2,n.avgTrendLength=n.avgTrendLength||{},n.avgTrendLength.sw=n.avgTrendLength.sw||10,n.avgTrendLength.down=n.avgTrendLength.down||10,n.avgTrendLength.up=n.avgTrendLength.up||10,n.withVolume=n.withVolume===!0||!1,n.period=n.period||3600;var t=[],e=n.quantity||200,s=10,i=10,r=10;n.avgTrendLength&&(s=n.avgTrendLength.sw||10,i=n.avgTrendLength.down||10,r=n.avgTrendLength.up||10);var o=n.startY||50,a=n.avgCandleSize||2,l=o-a,c=o+a,h=Ss(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(om(t[t.length-1],a,s)):d>3?t=t.concat(im(t[t.length-1],a,r)):t=t.concat(rm(t[t.length-1],a,i))}t=t.slice(0,n.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*n.period;for(let f=0;f<t.length;f++){const p=t[f];Object.assign(p,{timestamp:u,isVisible:!0}),u+=1e3*n.period,n.withVolume&&(p.volume=Math.ceil(Math.random()*1e3+200))}return t}function Ss(n,t,e,s){var i=Math.random()*(t-n)+n,r;if(s&&s==="bull"||!s&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>n?a:n}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:yi(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function im(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.lo,o=n.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),s.push(c)}return s}function rm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.hi-t*1.2,o=n.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),s.push(c)}return s}function om(n,t,e){var s=[],i=Math.random()*e+e/2;function r(u){var f,p;return Math.random()>.5?(f=u.lo-t*.2,p=u.hi+t*1.2):(f=u.lo-t*1.2,p=u.hi+t*.2),{from:f,to:p}}for(var o=r(n),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=Ss(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),s.push(d)}return s}window.DXChart=nm(sm({},window.DXChart),{generateCandlesData:pa});function am(n){return pa(n)}const lm=((n,t={})=>new ua(n,t))})(),window.DXChart=Ps})();})();
24
+ `);function ac(n){const t=document.createElement("template");return t.innerHTML=oc(n.devexpertsPromoLink),t}function lc(n){const t={},e=Array.from(n.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(s=>{var i;t[(i=s.getAttribute("data-element"))!=null?i:""]=s}),rc(t))return t;throw new Error("Some chart elements are missing")}function cc(n){if(n.length>1){const t=n.reduce((i,r,o)=>{if(o!==n.length-1){const a=n[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,s;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,s=r)}if(s)return s}}const hc=n=>t=>n?new Date(t).setHours(0,0,0,0):t,Le=(n,t={},e,s=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=hc(!!c),u=d(n),f=d((r=(i=fe(e))==null?void 0:i.timestamp)!=null?r:0),g=d((a=(o=wt(e))==null?void 0:o.timestamp)!=null?a:0);return u>g?h?{index:e.length-1+Math.ceil((u-g)/s),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:ot((u-f)/s),exact:!0}:{index:-1,exact:!0}:Yt(e,u,m=>d(m.timestamp))},Rm=n=>{const t=n[0],e=n[n.length-1];return n.length>0&&[t,e].some(s=>s!==void 0&&s.impVolatility!==null&&s.impVolatility!==void 0&&!isNaN(s.impVolatility))},Ni={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},Xi={paintConfig:[Ni],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var dc=Object.defineProperty,Wi=Object.getOwnPropertySymbols,uc=Object.prototype.hasOwnProperty,fc=Object.prototype.propertyIsEnumerable,zi=(n,t,e)=>t in n?dc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,gc=(n,t)=>{for(var e in t||(t={}))uc.call(t,e)&&zi(n,e,t[e]);if(Wi)for(var e of Wi(t))fc.call(t,e)&&zi(n,e,t[e]);return n};class pc{constructor(t,e,s,i){this.series=t,this.config=e,this.yAxisBoundsProvider=s,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,s=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[gc({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:s}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:Ni).color;return{textColor:te(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function mc(n,t){if(n.filter(a=>a!==null).length<=1)return n.map(a=>a.y);const e=t-2,s=n.map((a,l)=>vc(a,l,e)).filter(ri).sort(bc),i=new Array(s.length),r=s.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=s.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=s[a],c=s[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<s.length;a++){const l=s[a],c=s[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const vc=(n,t,e)=>n?{top:n.y-e/2,bottom:n.y+e/2,labelWeight:n.weight,actualIndex:t}:null,bc=(n,t)=>{const e=n.top,s=t.top;return e>s?1:e<s||e===s&&n.labelWeight<t.labelWeight?-1:0};var Cc=Object.defineProperty,yc=Object.defineProperties,wc=Object.getOwnPropertyDescriptors,Vi=Object.getOwnPropertySymbols,Sc=Object.prototype.hasOwnProperty,xc=Object.prototype.propertyIsEnumerable,Ui=(n,t,e)=>t in n?Cc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Gi=(n,t)=>{for(var e in t||(t={}))Sc.call(t,e)&&Ui(n,e,t[e]);if(Vi)for(var e of Vi(t))xc.call(t,e)&&Ui(n,e,t[e]);return n},Zi=(n,t)=>yc(n,wc(t));const se={MAIN:"MAIN"};class _c extends X{constructor(t,e,s,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=s,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new R,this.animFrameId=`anim_cache_${yt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,Ct(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Et(50,Ot,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,s])=>{this.addToGroup(s,t,e)})}updateLabels(t=!1){this.recalculateLabels(),_e(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const s=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=pt(Object.values(i).map(l=>l.getUnorderedLabels())),o=pt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=mc(o,s);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,s){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][s]=t))}updateLabelsCoordinates(t,e){return Zi(Gi({},t),{labels:t.labels.map((s,i)=>Zi(Gi({},s),{lineY:s.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,s){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[s]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var s;const i=(s=this.labelsProviders[t])!=null?s:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Bt=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const $s=()=>{rs.removeEventListener("change",$s),Bt=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),rs.addEventListener("change",$s)};rs.addEventListener("change",$s);const Pc=()=>Bt,Fm=n=>round(Bt*n)/Bt,Mt=n=>ot(Bt*n)/Bt,Ks=n=>el(Bt*n)/Bt,ne=n=>JSON.parse(JSON.stringify(n));function qs(n){return Object.entries(n)}const $i=(n,t)=>{for(const[e,s]of Array.from(n.entries()))if(s===t)return e};function Ki(n){return Object.keys(n)}function qi(n,t){if(Object.is(n,t))return!0;if(typeof n!="object"||n===null||typeof t!="object"||t===null)return!1;const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!qi(n[e[i]],t[e[i]]))return!1;return!0}const Tc=n=>Object.keys(n).length===0&&n.constructor===Object;function Ji(n){n===void 0&&(n={});var t=n.connector,e=t===void 0?function(){return new R}:t,s=n.resetOnError,i=s===void 0?!0:s,r=n.resetOnComplete,o=r===void 0?!0:r,a=n.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,g=!1,m=!1,x=function(){d==null||d.unsubscribe(),d=void 0},_=function(){x(),h=u=void 0,g=m=!1},A=function(){var L=h;_(),L==null||L.unsubscribe()};return N(function(L,j){f++,!m&&!g&&x();var F=u=u!=null?u:e();j.add(function(){f--,f===0&&!m&&!g&&(d=Js(A,l))}),F.subscribe(j),!h&&f>0&&(h=new xe({next:function(B){return F.next(B)},error:function(B){m=!0,x(),d=Js(_,i,B),F.error(B)},complete:function(){g=!0,x(),d=Js(_,o),F.complete()}}),At(L).subscribe(h))})(c)}}function Js(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];if(t===!0){n();return}if(t!==!1){var i=new xe({next:function(){i.unsubscribe(),n()}});return At(t.apply(void 0,D([],v(e)))).subscribe(i)}}const os=(n,t)=>n/t,mt=(n,t)=>n/t,Rt=(n,t)=>n*t,Qi=(n,t)=>(n-t)*100/t,tr=(n,t)=>n*t/100+t,er=n=>Math.log2(n),Qs=n=>Math.pow(2,n);class Mc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new R,this.xChanged=this.changed.pipe(ct(()=>({start:this.xStart,end:this.xEnd})),_t((t,e)=>t.start===e.start&&t.end===e.end),Ji()),this.yChanged=this.changed.pipe(ct(()=>({start:this.yStart,end:this.yEnd})),_t((t,e)=>t.start===e.start&&t.end===e.end),Ji()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+mt(t-this.xStart,this.zoomX)}xPixels(t){return mt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+mt(t-this.yStart,this.zoomY):e.y+e.height-mt(t-this.yStart,this.zoomY)}yPixels(t){return mt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Rt(e+mt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),s=t-e.y;return this.inverseY?Rt(s+mt(this.yStart,this.zoomY),this.zoomY):Rt(e.height-s+mt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return os(e-t,this.getBounds().width)}calculateZoomY(t,e){return os(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,s=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),s&&this.fireChanged()}setYScale(t,e,s=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),s&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const Ac=(n,t)=>!Ki(n).some(e=>n[e]!==t[e]);class Ec{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let s;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Yt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Yt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),s=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else s=t();return s}}class sr{constructor(t,e,s,i){this.dataSeries=t,this.scale=e,this.getAxisType=s,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Ec(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const s=this.percentAnimationHandler.getBaselineForPercent(e);return Qi(t,s);case"logarithmic":return t<=0?t:er(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return tr(t,this.getBaseline());case"logarithmic":return Qs(t);case"regular":return t}}}const ie=16;var Ic=Object.defineProperty,Dc=Object.defineProperties,Lc=Object.getOwnPropertyDescriptors,nr=Object.getOwnPropertySymbols,Oc=Object.prototype.hasOwnProperty,Bc=Object.prototype.propertyIsEnumerable,ir=(n,t,e)=>t in n?Ic(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,rr=(n,t)=>{for(var e in t||(t={}))Oc.call(t,e)&&ir(n,e,t[e]);if(nr)for(var e of nr(t))Bc.call(t,e)&&ir(n,e,t[e]);return n},Rc=(n,t)=>Dc(n,Lc(t));class Oe{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Oe(this.centerUnit,this.close)}}class or extends X{constructor(t,e,s,i,r){var o;super(),this.extentComponent=t,this.id=e,this.htId=s,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=l=>{var c;return(c=this.config.paintConfig[l])!=null?c:this.config.paintConfig[0]},this.getBaseline=(l=this.dataIdxStart)=>{var c,h,d;return(c=this.visualPoints[l])!=null&&c.close&&((h=this.visualPoints[l])==null?void 0:h.close)>=0?(d=this.visualPoints[l])==null?void 0:d.close:1},this.getTextForPoint=l=>`${l.close}`,this.getLastVisualSeriesPoint=()=>{const l=this.visualPoints;if(l.length!==0)return l[this.dataIdxEnd]},this.getLastDataSeriesPoint=()=>{const l=this.visualPoints;return wt(l)};const a=r!=null?r:ne(Xi);this.config=Tt(a,Xi),this.scale=t.scale,this.view=new sr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new pc(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=Hc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=li(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=li(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.pipe(Et(ie,Ot,{trailing:!0,leading:!0}),ct(()=>this.calculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)),_t((t,e)=>t.dataIdxStart===e.dataIdxStart&&t.dataIdxEnd===e.dataIdxEnd)).subscribe(()=>{this.recalculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)})),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const s=rr({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new sr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=s.yAxis.model.fancyLabelsModel.labelsProviders[se.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[se.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(se.MAIN,a,r),s.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(se.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,s)=>({centerUnit:s,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.centerUnit).index,i=Yt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let s=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);s=r.dataIdxStart,i=r.dataIdxEnd}return Cl(this.visualPoints2D,s,i)}}const Fc=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.close>t.high&&(t.high=s.close,t.highIdx=e),s.close<t.low&&(t.low=s.close,t.lowIdx=e)}return t},Hc=n=>({isHighLowActive:()=>n.config.highLowActive,calculateHighLow:t=>{const e=Fc(n.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return Rc(rr({},e),{high:n.view.toAxisUnits(e.high),low:n.view.toAxisUnits(e.low)})}}),kc=n=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(n);return ft.makeDecimal(n,i)};class as extends Oe{constructor(t,e,s,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=s,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),s=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>s?[s,e]:[e,s];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const pe=60,Be=(n,t,e=pe)=>{const s=ar(n,t,e);return{id:yi(s,s),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:s,volume:NaN,expansion:!0,idx:t}},Yc=(n,t,e=pe)=>({close:NaN,timestamp:ar(n,t,e)});function ar(n,t,e=pe){var s,i;const r=Te(t);if(n.length===0)return 0;const o=wt(n);if(r>=n.length&&o)return lr(o,n.length-1,r,e);const a=fe(n);return r<0&&a?lr(a,0,r,e):(i=(s=n[r])==null?void 0:s.timestamp)!=null?i:0}const lr=(n,t,e,s=pe)=>n.timestamp+(e-(t!=null?t:0))*s,tn=(n,t,e,s,i=pe)=>{const r=Be(n,s,i);r.volume=e;let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new as(o,e,r.open,r.close,r.lo,r.hi,ts(r.open,r.close),r)},jc=(n,t,e,s,i=pe)=>{const r=Yc(n,s,i);let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new Oe(o,r.close)};class Nc{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new R,this.dataSetSubject=new R,this.dataRemovedSubject=new R,this.dataPrependSubject=new R,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},s=this.mainDataPoints){const i=Le(t,e,s,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=cc(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?tn(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):jc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Xc=Object.defineProperty,cr=Object.getOwnPropertySymbols,Wc=Object.prototype.hasOwnProperty,zc=Object.prototype.propertyIsEnumerable,hr=(n,t,e)=>t in n?Xc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Vc=(n,t)=>{for(var e in t||(t={}))Wc.call(t,e)&&hr(n,e,t[e]);if(cr)for(var e of cr(t))zc.call(t,e)&&hr(n,e,t[e]);return n};class Uc{constructor(t,e,s=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=s,this.prevState={},this.isColorsChanged=()=>!qi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=Vc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const Gc=(n,t,e,s,i,r,o)=>{const a=Pc(),l=[e*a,s*a,i*a,r*a];let c=n.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=ot(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?ot(u*o):ot(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},dr=(n,{x:t,width:e,activeCandle:s})=>new as(t,e,n.open,n.close,n.hi,n.lo,ts(n.open,n.close),n,!0,en(n,s)),Zc=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,Ll((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,en(n,s),n.close>n.open)},ur=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,ts((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,en(n,s),n.close>n.open)},$c=ur,en=(n,t)=>{const e=t&&t.id===n.id;return e!=null?e:!1},fr=()=>zs,Re=class le{static autoDetectIncrementOfValueRange(t){const e=this.getDigitsInNumber(t);return t===0?.01:Math.pow(10,e-3)}static getDigitsInNumber(t){const e=i=>ot(Math.log10((i^i>>31)-(i>>31)))+1;let s=e(t);return s===1&&t<1&&(s=e(t*1e9)-9),s}static getPriceIncrement(t,e=[]){if(!this.validatePriceIncrementsOrPrecisions(e))return this.DEFAULT_INCREMENT;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;const i=1e-6;for(;s<e.length&&t>e[s]+Math.min(e[s-1],e[s+1])*i;)s+=2;return s>=e.length||t<e[s]-Math.min(e[s-1],e[s+1])*i?e[s-1]:Math.min(e[s-1],e[s+1])}static getPricePrecision(t,e){if(!this.validatePriceIncrementsOrPrecisions(e))return 0;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;for(;s<e.length&&t>e[s];)s+=2;return Math.round(e[s-1])}static roundPriceToIncrement(t,e,s){const i=le.getPriceIncrement(s||t,e);return ft.roundToNearest(t,i)}static computePrecisions(t){const e=[...t];for(let s=0;s<t.length;s+=2)e[s]=le.calculatePrecision(t[s]);for(let s=1;s<t.length;s+=2)e[s]=t[s]+Math.min(t[s-1],t[s+1])*le.RELATIVE_EPS;return e}static calculatePrecision(t){let e=t>1?Math.abs(Math.floor(t)-t):t;for(let s=0;s<le.MAXIMUM_PRECISION;s++){const i=Math.floor(e+.5),r=Math.abs(e*le.RELATIVE_EPS);if(i>=e-r&&i<=e+r)return s;e*=10}return le.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(t){return!(t.length===0||!Array.isArray(t)||t.findIndex(e=>e!==0)===-1)}};Re.DEFAULT_INCREMENT=.01,Re.DEFAULT_PRECISION=2,Re.RELATIVE_EPS=1e-8,Re.MAXIMUM_PRECISION=10;let me=Re;const Kc=(n,t)=>{var e;const s=(e=wt(t))!=null?e:1;return Math.pow(10,-s)};var qc=Object.defineProperty,Jc=Object.defineProperties,Qc=Object.getOwnPropertyDescriptors,gr=Object.getOwnPropertySymbols,th=Object.prototype.hasOwnProperty,eh=Object.prototype.propertyIsEnumerable,pr=(n,t,e)=>t in n?qc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sh=(n,t)=>{for(var e in t||(t={}))th.call(t,e)&&pr(n,e,t[e]);if(gr)for(var e of gr(t))eh.call(t,e)&&pr(n,e,t[e]);return n},nh=(n,t)=>Jc(n,Qc(t));const ih=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:n.scale.xStart,s=t?t.xEnd:n.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=n.calculateDataViewportIndexes(e,s),o=n.visualPoints.slice(i,r+1),a=mr(o),l=()=>{var c,h;return(h=(c=n.visualPoints[i])==null?void 0:c.close)!=null?h:1};return nh(sh({},a),{low:n.view.toAxisUnits(a.low,l),high:n.view.toAxisUnits(a.high,l)})}}),mr=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.high>t.high&&(t.high=s.high,t.highIdx=e),s.low<t.low&&(t.low=s.low,t.lowIdx=e)}return t};class rh{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){oh(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const oh=(n,t,e,s)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=vr(i),o=s.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=n.calculateZoomY(t.yStart,t.yEnd)};function vr(n){if(n.length===0)return ah();let t=n[0].high,e=n[0].low;return n.forEach(s=>{isFinite(s.high)&&s.high>=t&&(t=s.high),isFinite(s.low)&&s.low<=e&&(e=s.low)}),{low:e,high:t}}const ah=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),br=(n,t)=>n/t,lh=(n,t)=>n/t,ch=(n,t)=>n*t,Cr=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=br(e,s),r=n.yEnd-n.yStart;t.zoomY=lh(t.zoomX,i);const o=t.zoomY/s,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},hh=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=br(e,s),r=n.xEnd-n.xStart;t.zoomX=ch(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},dh=(n,t)=>{const e=n.xStart;n.xStart=t,n.xEnd=n.xEnd+(t-e)},uh=(n,t)=>{const e=n.yStart;n.yStart=t,n.yEnd=n.yEnd+(t-e)},yr=(n,t,e,s,i)=>{const r=(t.xEnd-t.xStart)*s,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=n.calculateZoomX(t.xStart,t.xEnd),t},fh=(n,t,e,s)=>yr(n,t,1,e,s),gh=Ae,ph=.9,mh=(n,t,e,s)=>{t.currentAnimation&&t.currentAnimation.animationInProgress&&t.currentAnimation.getProgress()>ph&&(t.currentAnimation.finishAnimation(),t.currentAnimation=void 0),s&&s.doAutoYScale(e),ls(n,t,e)},ls=(n,t,e)=>{const s=n.startViewportMovementAnimation(t,{duration:gh,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},ue,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=s};var vh=Object.defineProperty,bh=Object.defineProperties,Ch=Object.getOwnPropertyDescriptors,wr=Object.getOwnPropertySymbols,yh=Object.prototype.hasOwnProperty,wh=Object.prototype.propertyIsEnumerable,Sr=(n,t,e)=>t in n?vh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,re=(n,t)=>{for(var e in t||(t={}))yh.call(t,e)&&Sr(n,e,t[e]);if(wr)for(var e of wr(t))wh.call(t,e)&&Sr(n,e,t[e]);return n},xr=(n,t)=>bh(n,Ch(t));const Sh=new R,xh=new R,_h=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class _r extends Mc{constructor(t,e,s){super(),this.config=t,this.getBounds=e,this.canvasAnimation=s,this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.autoScaleZoomSubscription=null,this.autoScalePanSubscription=null,this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=ne(t.scale),this.autoScaleModel=new rh(this),this.offsets=this.config.components.offsets,this.initAutoScaleThrottling()}doActivate(){super.doActivate(),this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){this.autoScaleZoomSubscription&&(this.autoScaleZoomSubscription.unsubscribe(),this.autoScaleZoomSubscription=null),this.autoScalePanSubscription&&(this.autoScalePanSubscription.unsubscribe(),this.autoScalePanSubscription=null),super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=re(re({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,s=!1,i){const r=this.config.scale.disableAnimations||s;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();yr(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const s=this.export();fh(this,s,e,t),this.zoomXTo(s,t,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.currentAnimation=void 0,this.canvasAnimation.forceStopAnimation(ue),this.doAutoScale())}zoomXTo(t,e,s){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Cr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),s?this.apply(o):((i=this.currentAnimation)==null||i.tick(),ls(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const s=this.getBounds().width,i=.001;if(s>0){const r=os(this.config.components.chart.minCandles,s),a=t!==r&&t-r<=i&&e,l=os(s/this.config.components.chart.minWidth,s),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,s=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=xr(re({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Cr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),s||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),Me?mh(this.canvasAnimation,this,l,this.state.auto?this.autoScaleModel:void 0):ls(this.canvasAnimation,this,l)))}setXScaleWithoutYScale(t){var e;const s=this.export(),i=t.slice(Math.max(t.length-this.state.defaultViewportItems,0)),r=i[i.length-1],o=r.startUnit+r.width+this.offsets.right,a=o-this.getBounds().width*this.zoomX,l=xr(re({},s),{xStart:a,xEnd:o}),c=this.scalePostProcessor(s,l);this.state.auto&&this.autoScaleModel.doAutoYScale(c),(e=this.currentAnimation)==null||e.tick(),ls(this.canvasAnimation,this,c)}setYScale(t,e,s=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio&&this.initialViewportValidSubject.getValue()){this.setLockedYScale(t,e,s,i);return}super.setYScale(t,e,s);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,s=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,s);const o=this.export(),a=this.scalePostProcessor(i,o);hh(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),s=re({},e);this.haltAnimation(),dh(e,t);const i=this.scalePostProcessor(s,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();uh(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Ac(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}initAutoScaleThrottling(){this.autoScaleZoomSubscription=Sh.pipe(Et(ie,Ot,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=re({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)}),this.autoScalePanSubscription=xh.pipe(Et(ie,Ot,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=re({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)})}}class Ph extends _r{constructor(t,e,s,i){super(e,s,i),this.delegate=t,this.config=e,this.getBounds=s}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Th=es().colors;class Gt extends or{constructor(t,e,s,i,r,o,a,l,c=Th){super(t,e,s),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=_h(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new R,this.meanCandleWidth=zs,this._instrument=o,this.instrument=o,this.highLowProvider=ih(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=me.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.startUnit).index,i=Yt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}applyPriceMovement(){const t=wt(this.dataPoints);t&&(this.lastPriceMovement=ts(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=mr(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var s,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(s=this.candleWidthByChartType[r])!=null?s:fr;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,g=(i=this.candlesTransformersByChartType[r])!=null?i:dr;o.push(g(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,s)=>e+s.width,0)/t.length:this.meanCandleWidth=zs}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Hm(n){switch(n){case"line":case"area":return!0;default:return!1}}class Mh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=!!i.color;if(s instanceof Gt){const a=pt(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=s.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:s.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=s.extentComponent.getBounds(),c=a[0],h=s.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],g=a[d],m=s.view.toX(g.centerUnit),x=s.view.toY(g.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(ot(m),_),t.moveTo(ot(m),x);else if(f===void 0){t.lineTo(ot(m),x),t.stroke(),t.lineTo(ot(m),_),t.lineTo(ot(h),_),t.closePath();let A;i.color?t.fillStyle=i.color:t.fillStyle=s.colors.areaTheme.startColor&&s.colors.areaTheme.stopColor?(A=t.createLinearGradient(0,0,0,l.height),A.addColorStop(0,s.colors.areaTheme.startColor),A.addColorStop(1,s.colors.areaTheme.stopColor),A):"",o||t.fill()}else t.lineTo(m,x)}}}}function Pr(n,t,e,s,i,r=4,o=!0,a=!1){n.save(),n.beginPath(),n.moveTo(t+r,e),n.lineTo(t+s-r,e),n.quadraticCurveTo(t+s,e,t+s,e+r),n.lineTo(t+s,e+i-r),n.quadraticCurveTo(t+s,e+i,t+s-r,e+i),n.lineTo(t+r,e+i),n.quadraticCurveTo(t,e+i,t,e+i-r),n.lineTo(t,e+r),n.quadraticCurveTo(t,e,t+r,e),n.closePath(),o&&n.fill(),a&&n.stroke(),n.restore()}function Ah(n,t,e,s,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,g=c==="right"?h:-h,m=h;n.save(),n.beginPath(),l?n.moveTo(r+g,o):n.moveTo(r,o),l?(n.lineTo(r+f-g,o),n.quadraticCurveTo(r+f,o,r+f,o-m),n.lineTo(r+f,e+m),n.quadraticCurveTo(r+f,e,r+f-g,e),n.lineTo(t+g,e)):(n.lineTo(r+f,o),n.lineTo(r+f,e),n.lineTo(t,e)),l?(n.quadraticCurveTo(t,e,t-g/3,e+m/3),n.lineTo(s+g/3,i-m/3),n.quadraticCurveTo(s,i,s+g/3,i+m/3),n.lineTo(r-g/3,o-m/3),n.quadraticCurveTo(r,o,r+g/3,o)):(n.lineTo(s,i),n.lineTo(r,o)),n.closePath(),d&&n.fill(),u&&n.stroke(),n.restore()}function Eh(n,t,e,s,i,r=1,o=[]){n.save(),n.setLineDash(o),n.lineWidth=r,n.beginPath(),n.moveTo(t,e),n.lineTo(s,i),n.stroke(),n.closePath(),n.restore()}function oe(n,t){n.save(),n.lineWidth%2&&n.translate(.5,.5),t(),n.restore()}function Tr(n,t,e){const s=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);n.fillRect(s,i,r,o)}const Zt=(n,t)=>{n.beginPath(),n.rect(t.x,t.y,t.width,t.height),n.clip(),n.closePath()},km=n=>Array.isArray(n[0])?n:[n];class Ih{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,s){const i=t.ctx,r=s&&this.paneManager.panes[s];e&&(i.save(),r&&Zt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const s=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||s&&!Tc(s)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const $t=(n,t,e,s,i=t)=>{s.hoverWidth?n.lineWidth=s.hoverWidth:e.highlighted?n.lineWidth=t!==i?t+1:i:n.lineWidth=t};class Dh{constructor(t){this.config=t}setFillStyle(t,e,s,i){if(e.color)t.strokeStyle=e.color;else{const r=s.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.barLineWidth,s,i),oe(t,()=>{for(const o of r){this.setFillStyle(t,i,s,o),t.beginPath();const a=s.view.toX(o.centerUnit),l=s.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(s.view),f=Mt(s.view.xPixels(o.width)/2),g=s.view.toY(o.close),m=s.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,g),t.lineTo(a+f,g),t.moveTo(l,m),t.lineTo(a,m),t.stroke()}})}}}class Lh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,s,i){if(i!==void 0&&s instanceof Gt){const r=pt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(T.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],g=s.view.toX(c.centerUnit),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close),_=u?s.view.toY(u.close)<l:!1,A=x<l;if(u!==void 0&&_!==A){Mr(t,s,i,_);const L=s.view.toX(u.centerUnit),j=s.view.toY(u.close),F=m-L,B=x-j,Y=F/B,$=x-l,W=Y*$,U=L+(F-W);t.lineTo(U,l),t.stroke(),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(U,l)}u===void 0?(t.beginPath(),t.moveTo(m,x)):f===void 0?(Mr(t,s,i,A),t.lineTo(m,x),t.stroke(),t.lineTo(m,l),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(g,l),t.lineTo(m,l),t.strokeStyle=s.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(m,x)}}}}const Mr=(n,t,e,s)=>{e.color?(n.fillStyle=e.color,n.strokeStyle=e.color):(n.fillStyle=s?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,n.strokeStyle=s?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Oh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.candleLineWidth,s,i,this.config.candleLineWidth),oe(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=s.colors;a&&l&&this.drawCandle(t,i,s,o)}})}}drawCandle(t,e,s,i){const{candleTheme:r,activeCandleTheme:o}=s.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=s.view.toX(i.startUnit),d=s.view.xPixels(i.width),u=i.bodyHeight(s.view),[f,g,m,x]=i.yBodyKeyPoints(s.view),_=g===m?g+1:m,A=f===x?f+1:x,L=l[`${a}Color`],j=a==="none"?L:l[`${a}WickColor`];t.fillStyle=L,e.color?t.strokeStyle=e.color:t.strokeStyle=j;const F=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.moveTo(h+1,g),t.lineTo(h+1,_),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,f,A,g,_),c||(t.beginPath(),t.moveTo(h+Y,g),t.lineTo(h+Y,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,g+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(s.view);this.drawCandlesWicks(t,Y,f,A,g,_);const $=this.config.candlePaddingPercent,W=Math.max(d*$/2,this.pixelLength),U=h+W,G=d-W*2;if(!c){e.color&&(t.fillStyle=e.color);const V=e.hoverWidth?d+W:G,Q=e.hoverWidth?u+e.hoverWidth+W:u;t.fillRect(U,g,V,Q)}F&&this.drawCandleBorder(t,e,l,i,U+this.halfLineWidthCU,g+this.halfLineWidthCU,G-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,s,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,s),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,s,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?s[`${c}Color`]:s[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class Bh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof Gt){const r=e.flat(),o=s.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=s.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(s.view),f=s.view.toY(l.close),g=Mt(s.view.xPixels(l.width));t.fillRect(u,f,g,h);const m=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(m.addColorStop(0,d[`${c}Cap`]),m.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=m),g===0?(t.beginPath(),t.strokeStyle=m,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,g,a-f-h)}}}}class Rh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof Gt){const r=pt(e);$t(t,this.config.lineWidth,s,i,this.config.selectedWidth);const o=s.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=s.view.toX(l.centerUnit),u=s.view.toY(l.close),f=s.view.toX(c.centerUnit),g=s.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,g),t.stroke()}}}}const Fh=1.5;class Hh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=i.hoverWidth?i.hoverWidth/2:Fh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of pt(e)){t.beginPath();const l=s.view.toX(a.centerUnit),c=s.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const kh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Yh{constructor(t,e,s){this.drawer=t,this.config=e,this.chartBounds=s}draw(t,e,s,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,s,i),this.afterDraw(t,s))}beforeDraw(t){t.restore(),t.save(),Zt(t,this.chartBounds())}isChartTypeAllowed(){return kh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Zt(t,e.scale.getBounds())}}class jh{constructor(t){this.chartModel=t}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(ot(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(mt(h.width,u)),g=Mt(h.bodyHeight(this.chartModel.scale)),m=h.xCenter(this.chartModel.scale)-f/2,x=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,A=Mt(f*_/2),L=m+A,j=f-A*2;t.fillRect(L,x,j,g)}})})}}const Nh=(n,t,e,s)=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);s===0?t.moveTo(o,a):t.lineTo(o,a)},Ar=(n,t,e)=>{n.length!==0&&n.forEach((s,i)=>{Nh(s,t,e,i)})},Xh=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Wh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,zh=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,Vh=n=>Xh.exec(n),Uh=n=>Wh.exec(n),Ym=n=>zh.exec(n);function Gh(n){const t=Vh(n)||Uh(n);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(s){return parseInt(s,16)}):e}const Er={};function Zh(n,t){let e=Er[n+t];if(!e){const s=Gh(n);e=s&&"rgba("+s.join(",")+","+t+")",Er[n+t]=e}return e}const Ir="#383838";class $h{constructor(){}draw(t,e,s,i){const r=s.config.additionalVisibilityPredicatesMap,o=(r==null?void 0:r.showLine)!==void 0?r.showLine:s.config.visible,a=(r==null?void 0:r.showCloud)!==void 0?r.showCloud:s.config.visible;o&&e.forEach((l,c)=>{var h;const d=s.getPaintConfig(c);$t(t,d.lineWidth,s,i,d.hoveredLineWidth);const u=(h=i.color)!=null?h:d.color;t.strokeStyle=u,this.drawLine(t,l,s.view)}),a&&s.linkedDataSeriesModels.forEach((l,c)=>{const h=l.config.additionalVisibilityPredicatesMap,d=(h==null?void 0:h.showCloud)!==void 0?h.showCloud:l.config.visible;if(Dr(l.config.type)&&Dr(s.config.type)&&d){const u=[],f=s,g=f.getSeriesInViewport(f.scale.xStart-1,f.scale.xEnd+1),m=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1);g.forEach((x,_)=>{var A,L;const j=Math.min(x.length,(L=(A=m[_])==null?void 0:A.length)!=null?L:0);for(let Y=0;Y<j;Y++){const $=[x[Y].clone(),m[_][Y].clone()];u.push({diffPoints:$})}const F=f.getPaintConfig(_).color,B=l.getPaintConfig(c).color;this.drawDifference(t,F,B,u,f,l,i,r)})}})}drawLine(t,e,s){t.beginPath(),Ar(e,t,s),t.stroke()}drawDifference(t,e,s,i,r,o,a,l){const[c,h]=[[],[]];i.forEach(x=>{const[_,A]=x.diffPoints;c.push(_),h.push(A)});const d=this.mapDataSeriesDiffPointsIntoPoints(c,r.view),u=this.mapDataSeriesDiffPointsIntoPoints(h,o.view),f=l==null?void 0:l.backgroundColor,g=f!==void 0?f:s,m=f!==void 0?f:e;this.fillCloud(t,g,d,u,a,l),this.fillCloud(t,m,u,d,a,l)}fillCloud(t,e,s,i,r,o){var a,l,c,h;t.save(),t.beginPath();const d=(l=(a=fe(s))==null?void 0:a.x)!=null?l:0,u=(h=(c=wt(s))==null?void 0:c.x)!=null?h:0;t.lineTo(d,0),s.forEach(g=>{t.lineTo(g.x,g.y)}),t.lineTo(u,0),t.closePath(),t.clip(),t.beginPath(),s.forEach((g,m)=>{m===0?t.moveTo(g.x,g.y):t.lineTo(g.x,g.y)}),i.slice().reverse().forEach(g=>{t.lineTo(g.x,g.y)}),t.closePath();const f=(o==null?void 0:o.backgroundColor)!==void 0;r.color?t.fillStyle=r.color:f?t.fillStyle=e!=null?e:Ir:t.fillStyle=Zh(e!=null?e:Ir,.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(s=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const Dr=n=>n==="DIFFERENCE";class Kh{constructor(){}draw(t,e,s,i){const r=s.view.toY(0);e.forEach((o,a)=>{var l;const c=s.getPaintConfig(a);$t(t,c.lineWidth,s,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.moveTo(d,ot(r)),t.lineTo(d,ot(u))}),t.stroke()})}}class qh{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);$t(t,l.lineWidth,s,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,s.view)})}drawLinePath(t,e,s){t.beginPath(),Ar(e,t,s),t.stroke()}}class Jh{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class Qh{constructor(t){this.config=t}draw(t,e,s,i){t.save(),e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=s.getTextForPoint(h),u=Pt(d,t,c),f=Nt(c,t),g=s.view.toX(h.centerUnit)-u/2,m=s.view.toY(h.close)+f;t.fillText(d,g,m)})}),t.restore()}}class td{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=s.view.toX(c.centerUnit),d=s.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,s,i){t.beginPath(),t.moveTo(e-i/2,s),t.lineTo(e,s-i),t.lineTo(e+i/2,s),t.fill()}}const cs="resized_local",hs="draw",jm="draw_last_candle",ve={width:20,height:20};class Lr{constructor(t,e,s,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=s,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=sn;var a;i.push(this),this.parent=nd(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:s}=t,i=window.devicePixelRatio;this.canvas.style.height=s+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=s*i,this.width=e,this.height=s,this.ctx.scale(i,i)}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const s=e.height;s!==this.height&&(t.style.height=s+"px",this.height=s,t.height=s,this.prevHeight=s)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ve.width&&this.height>ve.height}}const sn={name:"candle"},ed={candle:sn,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function sd(n,t,e,s,i,r,o){var a;const l=ae(n,t,i,r,o,e);return l.type=(a=ed[s])!=null?a:sn,l}function ae(n,t,e,s,i,r,o){const a=new Lr(n,t,s,i,r,o);return Or(a,e),a}function Or(n,t){const e=n.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",n.width=t.fixedSize.width,n.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function nd(n){let t=n;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const ds="HIT_TEST_",zm=null;class id{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${yt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(s=>{s.indexOf(ds)!==-1&&this.drawersMap[s].draw()})},t.on(hs,s=>{e.wasResized()&&(this.canvasIdsList&&(s&&s.length!==0?this.canvasIdsList=this.canvasIdsList.concat(s):this.canvasIdsList=void 0),Kn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(ds)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(ds)===-1){const s=this.drawersMap[e];if(!t||t.length===0){s.draw();return}ml(t,s.getCanvasIds()).length&&s.draw()}})}isDrawable(){var t,e,s,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ve.width&&((i=(s=this.chartResizeHandler.previousBCR)==null?void 0:s.width)!=null?i:0)>ve.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=yt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(s);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(s);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const s=this.drawingOrder.indexOf(e);s!==-1&&this.drawingOrder.splice(s,1)}})}reorderDrawers(t){this.drawingOrder=oi(this.drawingOrder,t)}}class Br{static paneResizer(t){return`PANE_RESIZER_${t}`}}const rd=7;class od{constructor(t,e,s,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=s,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Zt(t,e.getBounds()),e.dataSeries.forEach(s=>this.drawSeries(t,s)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const s=e.config.type,i=this.seriesDrawers[s];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:rd};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const Rr={dragPredicate:()=>!0};class Fr extends X{constructor(t,e,s,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=s,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class us extends Fr{constructor(t,e,s,i,r=Rr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const ad="BASELINE_RESIZER";class ld extends X{constructor(t,e,s,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=s,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Gs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(T.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&Kl(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new us(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(T.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(T.CHART),e=this.canvasBoundContainer.getBounds(T.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const s=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=s,this.canvasBoundContainer.bounds[ad]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(T.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const cd=n=>{var t;try{const e=Pe(n.close,n.open,n.hi,n.lo);if(!isFinite(e))throw new Error("Received candle without any price");const s=Pe(n.hi,Math.max(n.open,n.close),e),i=Pe(n.lo,Math.min(n.open,n.close),e),r=Pe(n.open,n.lo,e),o=Pe(n.close,n.hi,e),a=Number.isNaN(n.vwap)?void 0:n.vwap;return{id:n.id,hi:s,lo:i,open:r,close:o,timestamp:n.timestamp,volume:(t=n.volume)!=null?t:0,expansion:n.expansion,idx:n.idx,impVolatility:n.impVolatility,openInterest:n.openInterest,vwap:a,typicalPrice:n.typicalPrice}}catch(e){console.warn(e);return}},Fe=(n,t=0)=>{for(let e=t;e<n.length;++e)n[e].idx=e},Hr=n=>{n.forEach(t=>{t.idx=void 0})},hd=n=>n!==void 0;class dd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0),o=pt(e),a=s.getPaintConfig(0);$t(t,a.lineWidth,s,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=ud(o,c),L=A&&l.close<A;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(L?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!L&&l.close<0&&(t.strokeStyle=(g=i.color)!=null?g:a.multiplyColors[1]||a.color||"#FF00FF"),L&&l.close>0&&(t.strokeStyle=(m=i.color)!=null?m:a.multiplyColors[2]||a.color||"#FF00FF"),!L&&l.close>0&&(t.strokeStyle=(x=i.color)!=null?x:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const j=s.view.toX(l.centerUnit),F=s.view.toY(l.close);t.moveTo(j,r),t.lineTo(j,F),t.stroke()})}}const ud=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0},fd=(n,t)=>{let e=0;return(...s)=>{clearTimeout(e),e=+setTimeout(()=>n(...s),t)}};class gd{constructor(){}draw(t,e,s,i){const r=pt(e),o=s.getPaintConfig(0);$t(t,o.lineWidth,s,i,o.hoveredLineWidth),t.lineCap="round",r.forEach((a,l)=>{var c,h;const d=pd(r,l)||r[0],u=d&&a.close<d.close;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(h=i.color)!=null?h:(u?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF";const f=s.view.toX(a.centerUnit),g=s.view.toY(a.close),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close);t.beginPath(),t.moveTo(m,x),t.lineTo(f,g),t.stroke();return}})}}const pd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t]:void 0},be="#FF00FF";class md{constructor(){}draw(t,e,s,i){const r=pt(e),o=s.getPaintConfig(0),a=i.hoverWidth?i.hoverWidth/2:o.lineWidth;r.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=vd(r,c),L=A&&l.close<A;if(((h=o.multiplyColors)==null?void 0:h.length)===2){t.fillStyle=(d=i.color)!=null?d:(L?o.multiplyColors[1]:o.multiplyColors[0])||o.color||be;const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.arc(B,Y,a,0,Math.PI*2),t.fill();return}if(((u=o.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.fillStyle=(f=i.color)!=null?f:o.multiplyColors[0]||o.color||be),!L&&l.close<0&&(t.fillStyle=(g=i.color)!=null?g:o.multiplyColors[1]||o.color||be),L&&l.close>0&&(t.fillStyle=(m=i.color)!=null?m:o.multiplyColors[2]||o.color||be),!L&&l.close>0&&(t.fillStyle=(x=i.color)!=null?x:o.multiplyColors[3]||o.color||be),t.beginPath();const B=s.view.toX(l.centerUnit),Y=s.view.toY(l.close);t.arc(B,Y,a,0,Math.PI*2),t.fill();return}t.fillStyle=(_=i.color)!=null?_:o.color||be,t.beginPath();const j=s.view.toX(l.centerUnit),F=s.view.toY(l.close);t.arc(j,F,a,0,Math.PI*2),t.fill()})}}const vd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0};var bd=Object.defineProperty,kr=Object.getOwnPropertySymbols,Cd=Object.prototype.hasOwnProperty,yd=Object.prototype.propertyIsEnumerable,Yr=(n,t,e)=>t in n?bd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,jr=(n,t)=>{for(var e in t||(t={}))Cd.call(t,e)&&Yr(n,e,t[e]);if(kr)for(var e of kr(t))yd.call(t,e)&&Yr(n,e,t[e]);return n};class wd{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class Sd extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.chartModel=t,this.canvasModel=e,this.config=s,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=g,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=x=>{var _;return(_=this.barTypeValues.find(A=>A===x))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new ld(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const m=new od(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(m,ds+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new Uc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(T.PANE_UUID(K),s.components.chart.cursor),this.dataSeriesDrawer=new Ih(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(fd(()=>{this.backgroundDrawerPredicateSubject.next(!1)},ie))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",dr),this.registerCandlesTransformer("trend",ur),this.registerCandlesTransformer("hollow",Zc),this.registerCandlesTransformer("line",$c)}get barTypeValues(){return Ki(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Oh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Dh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Rh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new Hh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Mh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new Lh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new Bh(this.config.components.chart.histogram));const e=T.PANE_UUID(K),s=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new qh),this.registerDataSeriesTypeDrawer("LINEAR_TREND",new gd),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Kh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new dd),this.registerDataSeriesTypeDrawer("POINTS",new Jh),this.registerDataSeriesTypeDrawer("TREND_POINTS",new md),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Yh(new jh(this.chartModel),this.config,s)),this.registerDataSeriesTypeDrawer("TEXT",new Qh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new td),this.registerDataSeriesTypeDrawer("DIFFERENCE",new $h)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(jr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,s=!0){return this.chartModel.setTimestampRange(t,e,s)}setXScale(t,e,s=!0){return this.scale.setXScale(t,e,s)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=jr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=s,this.chartModel.setAllSeries({candles:t.candles,instrument:s},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Hr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(s)}setSecondarySeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,s);if(this.updatePriceIncrementsIfNeeded(s),i)return i}setAllSeries(t,e=[]){var s;const i=(s=t.instrument)!=null?s:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,s=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,s)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!me.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[me.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}function Nr(n,t){return t===void 0&&(t=is),N(function(e,s){var i=null,r=null,o=null,a=function(){if(i){i.unsubscribe(),i=null;var c=r;r=null,s.next(c)}};function l(){var c=o+n,h=t.now();if(h<c){i=this.schedule(void 0,c-h),s.add(i);return}a()}e.subscribe(bt(s,function(c){r=c,o=t.now(),i||(i=t.schedule(l,n),s.add(i))},function(){a(),s.complete()},void 0,function(){r=i=null}))})}class Xr extends Gt{constructor(t,e,s,i,r,o,a,l,c,h){super(e,s,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var xd=Object.defineProperty,Wr=Object.getOwnPropertySymbols,_d=Object.prototype.hasOwnProperty,Pd=Object.prototype.propertyIsEnumerable,zr=(n,t,e)=>t in n?xd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Td=(n,t)=>{for(var e in t||(t={}))_d.call(t,e)&&zr(n,e,t[e]);if(Wr)for(var e of Wr(t))Pd.call(t,e)&&zr(n,e,t[e]);return n};const Md=(n,t,e,s)=>{var i,r,o,a;const l=Td({},n),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=yl(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=n.xStart,u=n.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Rt(s.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Ad=n=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const s=t.slice(Math.max(t.length-n.state.defaultViewportItems,0)),i=s[0],r=s[s.length-1];n.setXScale(i.startUnit,r.startUnit+r.width+n.offsets.right)}e.yScale&&n.doAutoScale(!0),n.fireChanged()}},Ed=(n,t)=>(e,s=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=s===null?0:t.mainCandleSeries.meanCandleWidth*2,c=s?o-l:o+l,h=s?a+l:a-l;n.setXScale(c,h)};var Id=Object.defineProperty,Dd=Object.defineProperties,Ld=Object.getOwnPropertyDescriptors,Vr=Object.getOwnPropertySymbols,Od=Object.prototype.hasOwnProperty,Bd=Object.prototype.propertyIsEnumerable,Ur=(n,t,e)=>t in n?Id(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,He=(n,t)=>{for(var e in t||(t={}))Od.call(t,e)&&Ur(n,e,t[e]);if(Vr)for(var e of Vr(t))Bd.call(t,e)&&Ur(n,e,t[e]);return n},nn=(n,t)=>Dd(n,Ld(t));class Rd{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,s)=>nn(He({},e),{[s]:0}),{})}createColorPool(t){return t.reduce((e,s,i)=>(e[`color${i}`]=nn(He({},ne(this.config.colors)),{lineTheme:He({},s.lineTheme),areaTheme:He({},s.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,s="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,s=i);return this.usedChartColors[s]=this.usedChartColors[s]+1,this.symbolsToColorKeys[t]=s,this.secondaryChartColorsPool[s]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var s,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=nn(He({},e),{lineTheme:Object.assign(r.lineTheme,(s=o.lineTheme)!=null?s:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Fd=Object.defineProperty,Gr=Object.getOwnPropertySymbols,Hd=Object.prototype.hasOwnProperty,kd=Object.prototype.propertyIsEnumerable,Zr=(n,t,e)=>t in n?Fd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,fs=(n,t)=>{for(var e in t||(t={}))Hd.call(t,e)&&Zr(n,e,t[e]);if(Gr)for(var e of Gr(t))kd.call(t,e)&&Zr(n,e,t[e]);return n};class Yd extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=s,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new R,this.mainInstrumentChangedSubject=new R,this.offsetsChanged=new R,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(cd).filter(hd),{sortCandles:g}=this.config.components.chart;return g?g(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new Rd(this.config);const d=new Xr(this.chartBaseModel,this.paneManager.panes[K].mainExtent,yt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new wd,this.candlesTransformersByChartType,this.candleWidthByChartType,fs({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Md(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Ad(o),this.timeFrameViewportTransformer=Ed(o,this),this.pane=this.paneManager.panes[K]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(K)).pipe(_t(Hi)).subscribe(t=>{this.handleChartResize(t)})),this.addRxSubscription(this.scale.changed.pipe(Nr(ie)).subscribe(()=>this.paneManager.yExtents.forEach(t=>t.yAxis.updateOrderedLabels(!0))))}handleChartResize(t){if(t.width>ve.width&&t.height>ve.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),s=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=s;return}if(s!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Rt(s-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=s,this.prevChartWidth=e;return}const i=Rt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=s,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(s=>{const i=s.dataPoints;return Hr(i),{candles:i,instrument:s.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,s=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,s&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var s;this.mainCandleSeries.instrument=(s=t.instrument)!=null?s:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Fe(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doBasicXScale(){this.scale.setXScaleWithoutYScale(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=fs({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const s=[t,...e];if(!this.candleSeries.every(l=>s.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Kr(this.mainCandleSeries.dataPoints,i),o=r.candles;Fe(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),g=Kr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(g,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candleSeries.forEach(l=>{l.recalculateDataViewportIndexes()}),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(s=>{const i=Yt(s.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;s.dataPoints=s.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=fs(fs({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const s=new Gt(this.paneManager.panes[K].mainExtent,yt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return s.config.type="line",this.candleSeries.push(s),s}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[K].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const s=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)s.push(a);else{let l=$r(e,o,-1);if(l||(l=$r(e,o,1)),l){const c=Ol(l,o,!0);s.push(c)}}}),s}updateSecondaryCandleSeriesConfig(t,e,s){const i=Tt(t,es().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=s,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),s=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=s.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,s=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,s)}candleFromUnit(t,e=!1,s=this.mainCandleSeries){var i,r;const o=Yt(s.visualPoints,t,d=>d.startUnit),a=s.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Te((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Be(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Be(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},s=this.mainCandleSeries){const i=s.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(s=>s.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(s=>s.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,s,i;const r=t-((i=(s=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:s.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,s=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,s)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return wt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return wt(t)}getMaxCandlesFitLength(){return ot(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((s,i)=>{const r=i.timestamp,o=Le(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,s[o.index]=i),s},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}isLastCandleInViewport(){const t=this.getLastCandle();return t&&t.idx?this.isCandleInViewport(t.idx):!1}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const s=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Le(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const g=f>=o.length-1,m=c&&h.timestamp<c.timestamp;if(g&&!m&&(c=h),a&&c&&s&&l){const x=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:fr;this.scale.moveXStart(this.scale.xStart+x(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return Ct(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=this.getCandles(),e=0,s){const i=this.getCandlesCount(),r=s!=null?s:i+this.FAKE_CANDLES_DEFAULT;t=t.slice(Math.max(0,e),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Be(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=e;c<l;c++)a.push(Be(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...t,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const s=t.slice(),i=[];return e.forEach(r=>{const a=Le(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?s[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...s]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const s=this.findSeriesBySymbol(e);if(s.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}s.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Fe(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const s=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(s<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,s).concat(e.dataPoints.slice(i+1)),Fe(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(s=>this.removeCandleByIdx(this.candleIdxFromId(s,e)))}addCandlesById(t,e,s){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=s.dataPoints.slice(0,i),o=s.dataPoints.slice(i);s.dataPoints=r.concat(t).concat(o),Fe(s.dataPoints),s.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const $r=(n,t,e)=>{if(t>=n.length)return n[n.length-1];for(let s=t;s<n.length&&s>=0;s+=e){const i=n[s];if(i)return i}},Kr=(n,t)=>{const e=n.slice(),s=[],i=[];return t.forEach(r=>{const a=Le(r.timestamp,{extrapolate:!0},n).index;a<0?s.push(r):a>=n.length?i.push(r):n[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:s,appended:i,candles:[...s,...e,...i]}};class Ce{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class rn{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const s=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(s,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=$i(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=$i(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=pt(Array.from(this.drawers).map(([,s])=>s.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class jd{constructor(t,e,s,i){this.model=t,this.config=e,this.crossToolCanvasModel=s,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var Nd=Object.defineProperty,Xd=Object.defineProperties,Wd=Object.getOwnPropertyDescriptors,qr=Object.getOwnPropertySymbols,zd=Object.prototype.hasOwnProperty,Vd=Object.prototype.propertyIsEnumerable,Jr=(n,t,e)=>t in n?Nd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ud=(n,t)=>{for(var e in t||(t={}))zd.call(t,e)&&Jr(n,e,t[e]);if(qr)for(var e of qr(t))Vd.call(t,e)&&Jr(n,e,t[e]);return n},Gd=(n,t)=>Xd(n,Wd(t));class Zd extends X{constructor(t,e,s,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=s,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.chartModel=a,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?jt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(jt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,K]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget,s=this.config.discrete){var i;const r=s?this.chartModel.toX((i=this.chartModel.candleFromX(t.x,!0).idx)!=null?i:0):t.x;if(this.currentHover===null?this.currentHover={x:r,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=r,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===K)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:s,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(T.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=s.x+l,d=s.y+c,u=o.y+a,f=o.y+o.height-a,g=h<a?a:h>o.width-a?o.width-a:h,m=d<u?u:d>f?f:d,x=(e=this.hoverProducer.createHover(g,m,t.paneId))!=null?e:t,_=Gd(Ud({},x),{x:g,y:m});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const It=4;function $d(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g;const m=r.align,x=(l=i.textFont)!=null?l:ee(r),_=i.bgColor,A=(c=i.textColor)!=null?c:te(_,o.labelTextColor,o.labelInvertedTextColor),L=(h=i.paddingTop)!=null?h:It,j=(d=i.paddingBottom)!=null?d:It,F=(u=i.paddingEnd)!=null?u:It,B=Te(Nt(x,n)/2),Y=s-B-L,W=s+B+j-Y;if(a&&!gs(s,t,W))return;n.save(),n.fillStyle=_,n.strokeStyle=_;const U=Te(t.width/6),G=m==="right"?t.x:t.x+t.width,V=m==="right"?G+U:G-U,Q=r.labelBoxMargin.end,J=Q-F,et=t.width-U-J;Ah(n,V,Y,G,Y+Te(W/2),V,Y+W,et,(g=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?g:!1,m),n.fillStyle=A,n.font=x;const tt=m==="right"?t.x+t.width-Pt(e,n,x)-Q:t.x+Q;n.fillText(e,tt,s+B-1),n.restore()}function Kd(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x,_,A;const L=r.align,j=(l=i.textFont)!=null?l:ee(r),F=i.bgColor,B=(c=i.textColor)!=null?c:te(F,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,$=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:It,W=(g=(f=i.paddingBottom)!=null?f:Y==null?void 0:Y.bottom)!=null?g:It,U=(x=(m=i.paddingEnd)!=null?m:Y==null?void 0:Y.end)!=null?x:It,G=i.paddingStart,V=Nt(j,n),Q=s-V/2-$,et=s+V/2+W-Q,tt=(A=i.rounded)!=null?A:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!gs(s,t,et))return;n.save(),n.fillStyle=F,n.strokeStyle=F;const st=r.labelBoxMargin.end;n.font=j;const ht=Pt(e,n,j),at=st-U,St=G!==void 0?ht+G+U:t.width-at,Ut=L==="right"?t.x+t.width-at-St:t.x+at,Se=L==="right"?t.x+t.width-ht-st:st;tt?Pr(n,Ut,Q,St,et,4,!0):n.fillRect(Ut,Q,St,et),n.fillStyle=B,n.fillText(e,Se,s+V/2-1),n.restore()}function qd(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x;const _=r.align,A=(l=i.textFont)!=null?l:ee(r),L=o.backgroundColor,j=(c=i.textColor)!=null?c:te(L,o.labelTextColor,o.labelInvertedTextColor),F=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:F==null?void 0:F.top)!=null?u:It,Y=(g=(f=i.paddingBottom)!=null?f:F==null?void 0:F.bottom)!=null?g:It,$=(x=(m=i.paddingEnd)!=null?m:F==null?void 0:F.end)!=null?x:It,W=i.paddingStart,U=Nt(A,n),G=s-U/2-B,Q=s+U/2+Y-G;if(a&&!gs(s,t,Q))return;n.save(),n.fillStyle=L,n.strokeStyle=L;const J=r.labelBoxMargin.end;n.font=A;const et=Pt(e,n,A),tt=J-$,st=W!==void 0?et+W+$:t.width-tt,ht=_==="right"?t.x+t.width-tt-st:t.x+tt,at=_==="right"?t.x+t.width-et-J:J;n.fillStyle=L,n.strokeStyle=L,n.fillRect(ht,G,st,Q),n.fillStyle=j,n.fillText(e,at,s+U/2-1),n.restore()}function Jd(n,t,e=It){return Nt(n,t)/2+e}function gs(n,t,e){return!(n<t.y+e/2||n>t.y+t.height-e/2)}const Qd="badge",Qr=4,to={badge:$d,rectangle:Kd,plain:qd};function eo(n,t,e,s,i,r,o,a,l){var c,h,d,u,f;const g=r.y,m=r.labelText,x=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:Qd,A=r.description,L=(d=r.textFont)!=null?d:ee(a),j=r.bgColor,F=(u=r.lineColor)!=null?u:j,B=Pt(A!=null?A:"",n,L)+8,Y=ot(r.y),$=Nt(L,n),W=g-$/2,G=g+$/2-W;n.save(),n.fillStyle=j,n.strokeStyle=F;const V=o.getBounds(T.PANE_UUID(K)),Q=to[_],J=a.labels.descriptions,et=tu(s,Y,G),tt=()=>J&&eu(e,t,s,i,r,a);let st,ht;const at=2;a.align==="right"?(st=V.x,ht=J?V.x+V.width-B:V.x+V.width+at):(st=J?V.x+B:V.x-at,ht=V.x+V.width);const St=(f=r.lineY)!=null?f:r.y,Ut=()=>et&&oe(n,()=>Eh(n,st,St,ht,St,1,r.lineDash)),Se=()=>Q(n,s,Je(m),g,r,a,l.yAxis,!1),xs={line:()=>{Ut(),tt()},"line-label":()=>{Ut(),Se(),tt()},label:()=>{tt(),Se()}};x!=="none"&&gs(g,s,G)&&xs[x](),n.restore()}const tu=(n,t,e)=>t>n.y+e/2&&t<n.y+n.height-e/2;function eu(n,t,e,s,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=ee(r),f=Pt(h,t,u),g=Nt(u,t),m=(o=i.paddingTop)!=null?o:Qr,x=(a=i.paddingBottom)!=null?a:Qr,_=d-g/2-m,L=d+g/2+x-_;t.save();const j=f+5,F=4,B=f+F*2,Y=s.x+s.width,$=c==="right"?Y-B:s.x+F;Gc(n,t,$,_,j,L,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const W=c==="right"?Y-f-F*2:s.x+F*2;t.fillText(h,W,d+g/2-1),t.restore()}class so{constructor(t,e,s,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=s,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&oe(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var s,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(T.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES,{extensionY:1e-4}),h=(s=this.config.components.xAxis.padding.top)!=null?s:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const g={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},m={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},x=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),x&&(t.moveTo(...g.start),t.lineTo(...g.end)),t.moveTo(...m.start),t.lineTo(...m.end),t.stroke()),x&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var s,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,g=this.config.components.xAxis.fontSize,m=this.canvasBoundsContainer.getBounds(T.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const x=(s=l==null?void 0:l.left)!=null?s:0,_=(i=l==null?void 0:l.right)!=null?i:0,A=(r=l==null?void 0:l.top)!=null?r:0,L=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,F=f+x+_,B=g+A+L,Y=Math.max(d-F/2,0),$=m.y+j+Ie/2;Pr(t,Y,$,F,B),t.fillStyle=h.labelTextColor;const W=Math.max(d-f/2,x),U=m.y+j+g+Ie/2+A-1;t.fillText(u,W,U),t.restore()}}drawYLabel(t,e){const s=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=to[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:s==null?void 0:s.bottom,paddingEnd:s==null?void 0:s.end,paddingTop:s==null?void 0:s.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class su{draw(){}}class nu extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=s,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.chartModel=c,this.crossToolTypeDrawers={},this.model=new Zd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel,this.chartModel),this.addChildEntity(this.model);const h=new Ce(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const d=new jd(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),u=new rn;u.addDrawer(h,"CLEAR_CANVAS"),u.addDrawer(d,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(u,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new so(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new so(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new su)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class iu{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,s])=>{for(const i of s){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Wt{constructor(t){this.data=t,this.next=null}}class ru{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new Wt(t);if(this.head===null)this._head=e;else{let s=this.head;for(;s.next;)s=s.next;s.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const s=new Wt(e);if(t===0)s.next=this.head,this._head=s;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;s.next=i,r.next=s,t===this.length-1&&(this._tail=s)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,s=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,s=e,e=e.next;s.next=e.next,t===this.length-1&&(this._tail=s)}this.length--}getNodePosition(t){let e=0,s=this.head;for(;s;){if(s.data===t.data)return e;s=s.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class ou extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const s=e.paneId,r=this.objects[s];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[s,i]=e,r=new Wt(s);return i.getNodePosition(r)}addObject(t){var e,s;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new ru;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((s=t.parentId)!=null?s:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new Wt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[s]=e;this.removeObject(s.id),this.addObject(t)}moveToPosition(t,e){const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new Wt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(s),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,s),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,s),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new Wt(s),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,s),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class au extends X{constructor(t,e){super();const s=new ou(t);this.model=s,this.addChildEntity(s);const i=new iu(s,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const lu=()=>n=>n.toString(),cu=(n,t)=>{var e;const s="date.get"+(t((e=n.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return s+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:hu(n),shortMonths:du(n),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=n.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>uu(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function hu(n){var t;return(t=n.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function du(n){var t;return(t=n.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const no=(n,t,e)=>{if(n){if(typeof n=="string")return e(n);if(Array.isArray(n)){const s=n.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(s.length>0){const i=s[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return lu()},uu=(n,t,e,s)=>{t||(t="M/d/yyyy");const i=n.getDate(),r=n.getMonth(),o=n.getFullYear(),a=n.getHours(),l=n.getMinutes(),c=n.getSeconds(),h=n.getMilliseconds(),d=a%12,u=ye(d),f=ye(a),g=ye(l),m=ye(c),x=a<12?"AM":"PM",_=e[n.getDay()],A=_.substring(0,3),L=ye(i),j=r+1,F=ye(j),B=s[r],Y=B.substring(0,3),$=o+"",W=$.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",g+"").replace("m",l+"").replace("ss",m+"").replace("s",c+"").replace("S",h+"").replace("dd",L+"").replace("d",i+"").replace("EEEE",_).replace("EEE",A).replace("YYYY",$).replace("yyyy",$).replace("YY",W).replace("yy",W).replace("aaa",x),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",Y):t=t.replace("MM",F+"").replace("M",j+""),t},ye=n=>typeof n=="number"&&n<10?"0"+n:n,ke=(n,t)=>`${n}_${t}`,fu=(n,t)=>{if(t){const e=io(t.normal),s=io(t.hover);return{type:n,normal:e,hover:s}}},io=n=>{var t;const s=new DOMParser().parseFromString(n,"text/html").querySelector("svg");let i=0;s&&(i=parseInt((t=s.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(n),l=new Image;return l.src=a,{img:l,svgHeight:i}},gu=(n,t,e,s,i)=>{if(i){const r=t[ke(s,"hover")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[ke(s,"normal")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},pu={"rhombus-small":4,rhombus:6,"rhombus-large":8},mu=["earnings","dividends","splits","conference-calls"];class vu{constructor(t,e,s,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&mu.forEach(l=>{const c=fu(l,a[l]);c&&(this.customIcons[ke(c.type,"normal")]=c.normal,this.customIcons[ke(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(T.EVENTS),e=this.canvasBoundsContainer.getBounds(T.ALL_PANES),s=this.canvasModel.ctx;s.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(s.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[ke(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;gu(s,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(s,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);s.lineWidth=u!=null?u:1,s.beginPath(),s.setLineDash(f!=null?f:[]),s.moveTo(c,e.y),s.lineTo(c,t.y+t.height/2),s.stroke(),s.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),s.restore()}drawDefaultEvent(t,e,s,i,r){var o,a,l;const c=s.y+s.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=on(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var s;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(T.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(s=this.config.components.xAxis.padding.top)!=null?s:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function on(n){return pu[n.style]}const ps=5;class bu{constructor(t,e,s,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(T.EVENTS);t.save(),this.model.events.forEach((s,i)=>{if(!this.config.components.events.eventsVisibility[s.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(s.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[s.type].color;t.strokeStyle=c,t.fillStyle=c;const h=on(s);t.fillStyle=this.hitTestCanvasModel.idToColor(s.id);const d=(h+ps)*2;if(a!==void 0){const u=on(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const m=h*2+ps;t.fillRect(a+u,e.y,m,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Cu=Object.defineProperty,ro=Object.getOwnPropertySymbols,yu=Object.prototype.hasOwnProperty,wu=Object.prototype.propertyIsEnumerable,oo=(n,t,e)=>t in n?Cu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Su=(n,t)=>{for(var e in t||(t={}))yu.call(t,e)&&oo(n,e,t[e]);if(ro)for(var e of ro(t))wu.call(t,e)&&oo(n,e,t[e]);return n};const ao=317,an={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class xu extends Lr{constructor(t,e,s,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=s,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new R,this.touchStartSubject=new R,this.dblClickSubject=new R,this.rightClickSubject=new R,this.hitTestDrawersPredicateSubject=new ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,Or(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Et(100,Ot,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),s=this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=Ct(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=Ct(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ct(()=>Su({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,s,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*ao).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/ao}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const s=window.devicePixelRatio;return this.prevAnimationFrameId!==Fs&&(this.curImgData=this.ctx.getImageData(t*s,e*s,1,1).data,this.prevAnimationFrameId=Fs),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),s=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(s),[r]=ln(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(s)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const s=this.getPixel(t.x,t.y),i=this.colorToId(s[0]*65536+s[1]*256+s[2]),r=Number(i),[o]=ln(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var s,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,g]=ln(this.hitTestSubscribers,u),m=f==null?void 0:f.lookup(d),x={point:t,model:m};switch(e){case"mousedown":m&&((s=f==null?void 0:f.onMouseDown)==null||s.call(f,m,t)),g.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":m&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,m,t)),g.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":m&&((r=f==null?void 0:f.onHover)==null||r.call(f,m,t)),g.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(x);break;case"touchstart":m&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,m,t)),g.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(x);break;case"dblclick":m&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,m,t)),this.dblClickSubject.next(x);break;case"contextmenu":m&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,m,t)),this.rightClickSubject.next(x);break;case"zoom":m&&((c=f==null?void 0:f.onZoom)==null||c.call(f,m,t)),g.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const ln=(n,t)=>{let e;const s=[];return n.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:s.push(i)}),[e,s]};var _u=Object.defineProperty,Pu=Object.defineProperties,Tu=Object.getOwnPropertyDescriptors,lo=Object.getOwnPropertySymbols,Mu=Object.prototype.hasOwnProperty,Au=Object.prototype.propertyIsEnumerable,co=(n,t,e)=>t in n?_u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Eu=(n,t)=>{for(var e in t||(t={}))Mu.call(t,e)&&co(n,e,t[e]);if(lo)for(var e of lo(t))Au.call(t,e)&&co(n,e,t[e]);return n},Iu=(n,t)=>Pu(n,Tu(t));class Du extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((s,i)=>Iu(Eu({},s),{id:i+e})).sort((s,i)=>s.timestamp-i.timestamp)}getIdRange(){return an.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Lu extends X{constructor(t,e,s,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>no(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Du(e);this.eventsModel=c,this.addChildEntity(c),s.addSubscriber(c);const h=new vu(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new bu(s,i,t,r,c,()=>s.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(T.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class Ou{constructor(t,e,s,i,r,o,a,l,c=()=>!0,h,d,u){this.canvasModel=t,this.viewportModel=e,this.config=s,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.extentIdx=h,this.getBaseline=d,this.mainExtentIdx=u}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;oe(t,()=>this.drawVertical(t)),oe(t,()=>this.drawHorizontal(t)),oe(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.extentIdx===0&&this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const s=this.xBoundsProvider(),i=ot(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(s.x,i),t.lineTo(s.x+s.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.xBoundsProvider(),i=s.x+s.width;for(const r of e){const o=Mt(this.viewportModel.toX(r.value));o>s.x&&o<i&&(t.beginPath(),t.moveTo(o,s.y),t.lineTo(o,s.y+s.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length>0&&this.config.components.grid.horizontal&&this.extentIdx===this.mainExtentIdx){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.yBoundsProvider();for(const i of e){const r=ot(this.viewportModel.toY(i.value)),o=Jd(i.text,t,It);r>s.y+o&&r<s.y+s.height-o&&(t.beginPath(),t.moveTo(s.x,r),t.lineTo(s.x+s.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class ho extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new Ou(t,e,s,i,a,l,c,h,f,d,u,g)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class Bu{constructor(t,e,s,i){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:s,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+s,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,s,i){const r=this.getMarkerY(t,s,i==="low"),o=Qe(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(s,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Zt(t,h)}getMarkerText(t,e){const s=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${s}`}getMarkerY(t,e,s=!1){const i=this.chartModel.toY(e);if(s){const r=Qe(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(T.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,s){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(T.CHART),o=4,a=t.measureText(s).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ru extends X{constructor(t,e,s,i,r){super();const o=new Bu(e,s,t,i);r.addDrawer(o,"HIGH_LOW")}}const Fu=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],Hu=1440*60*1e3;class ku extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new R}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+Hu;_l(this.highlights,t,e,Yu).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,s)=>e.to-s.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const Yu=n=>n.to,Kt=[20,10];class ju{constructor(t,e,s,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,s,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(T.ALL_PANES);o.save(),Zt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(s=this.config.components.highlights.fontSize)!=null?s:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",g=`${u}px ${f}, monospace`;o.font=g,o.lineWidth=h,o.setLineDash(d),Fu.forEach(m=>{var x,_;const A=a[m];if(A){const L=this.config.colors.highlights[m],j=(x=L==null?void 0:L.border)!=null?x:"#ffffff",F=(_=L==null?void 0:L.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=F,o.strokeStyle=j,A.forEach(B=>{var Y,$,W;const U=this.chartModel.candleFromTimestamp(B.from),G=mt(U.width,this.chartModel.scale.zoomX),V=U.xStart(this.chartModel.scale),Q=B.to-this.chartModel.chartBaseModel.period,J=this.chartModel.candleFromTimestamp(Q),et=mt(J.width,this.chartModel.scale.zoomX),tt=J.xStart(this.chartModel.scale)+et;if(B.border&&this.drawBorders(B.border,o,V+G,tt-et,c),o.fillRect(V,c.y,tt-V,c.y+c.height),B.label){const st=(Y=B.label.text)!=null?Y:"",ht=this.config.colors.highlights[B.type];o.save(),o.fillStyle=($=ht==null?void 0:ht.label)!=null?$:"#ffffff";const at=Pt(st,o,g),[St,Ut]=this.resolveHighlightLabelPosition((W=B.label.placement)!=null?W:"left-left",c,[V,tt],at);o.fillText(st,St,Ut),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,s,i){const[r,o]=s;switch(t){case"right-left":return[o-Kt[1]-i,e.y+Kt[0]];case"left-left":return[r-Kt[1]-i,e.y+Kt[0]];case"right-right":return[o+Kt[1],e.y+Kt[0]];case"left-right":default:return[r+Kt[1],e.y+Kt[0]]}}drawBorders(t,e,s,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(s,r.y),e.lineTo(s,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const Nu="HIGHLIGHTS_PLUGIN";class Xu extends X{constructor(t,e,s,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new ku(s),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new ju(this.highlightsModel,s,i,r,e),o.addDrawer(this.highLightsDrawer,Nu)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function Wu(){return N(function(n,t){var e,s=!1;n.subscribe(bt(t,function(i){var r=e;e=i,s&&t.next([r,i]),s=!0}))})}function Z(n,t){return N(function(e,s){var i=0;e.subscribe(bt(s,function(r){return n.call(t,r,i++)&&s.next(r)}))})}var zu=Object.defineProperty,Vu=Object.defineProperties,Uu=Object.getOwnPropertyDescriptors,uo=Object.getOwnPropertySymbols,Gu=Object.prototype.hasOwnProperty,Zu=Object.prototype.propertyIsEnumerable,fo=(n,t,e)=>t in n?zu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,go=(n,t)=>{for(var e in t||(t={}))Gu.call(t,e)&&fo(n,e,t[e]);if(uo)for(var e of uo(t))Zu.call(t,e)&&fo(n,e,t[e]);return n},po=(n,t)=>Vu(n,Uu(t));const zt=4;class $u{constructor(t,e,s,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(T.N_MAP),s=this.canvasBoundsContainer.getBounds(T.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(T.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(T.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(T.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(T.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),s.width!==0&&this.drawLeftArrowButton(c,s,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,s,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,s,i){t.x<=s.x+s.width&&(t.x=s.x+s.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,s,i,r){this.blockDrawSliderOnLeftArrow(e,s,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,s,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,s,i){const r=s.components.navigationMap.knots.border;t.fillStyle=s.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=s.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=s.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=s.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=pt(this.chartModel.mainCandleSeries.getSeriesInViewport()),s=this.config.components.navigationMap.timeLabels,i=s.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(T.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(T.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:s.fontFamily,textSize:`${s.fontSize}px`},d={dateFormat:s.dateFormat,padding:s.padding,textProperties:po(go({},h),{textAlign:"left"})},u={dateFormat:s.dateFormat,padding:s.padding,textProperties:po(go({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,s,i){const r=i.padding,o=mi(s,i.dateFormat,this.formatterFactory);di(t,i.textProperties);const a=Qe(t),l=fi(o);Tl(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ye extends Fr{constructor(t,e,s,i,r=Rr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const mo=4;class Ku extends X{constructor(t,e,s,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=s,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-g.x-mo},this.leftKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-g.x+mo},this.rightKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:g}=f,m=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),x=this.chartModel.mainCandleSeries.meanCandleWidth/(m.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-g)*x;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=g};const a=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_KNOT_R),c=new Ye(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Ye(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_SLIDER_WINDOW),u=new Ye(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(T.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const s=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=s.dataIdxStart/(s.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=s.dataIdxEnd/(s.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class qu extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=s,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new $u(i,e,s,o,l,()=>this.visualCandles);a.addDrawer(d,T.N_MAP_CHART),this.navigationMapMoveHandler=new Ku(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(T.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(T.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(T.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(T.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(T.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(T.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(T.N_MAP),this.chartModel.scale.xChanged.pipe(Wu(),Z(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const s=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-s,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(T.N_MAP_CHART),h=c.width,d=[];let u=0,f,g;for(f=0;f<h;f++)g=ot(f*o/h)-r,g in e?(d[f]=e[g].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((m,x)=>[x+c.x,(a+l-m)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(cs),this.canvasModel.fireDraw())}}const ms=()=>{const n=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(s=>navigator.userAgent.match(s));return n?"apple":e?"mobile":"other"},Vm=(n,t)=>n==="apple"||n==="mobile"?3:t;var cn=Math.pow;class vo extends X{constructor(t,e,s,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=15,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const m=this.canvasBoundsContainer.getBounds(T.CANVAS).width,_=d.offsetX/m;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(ue),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Rt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),h=new Ye(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Et(this.wheelThrottleTime,Ot,{trailing:!0,leading:!0})).subscribe(e=>{const s=ms(),i=s==="apple"||s==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Rt(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return ol(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let s=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(ue),this.currentPoint={x:0,y:0},s=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)Ju(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Rt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(s+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new us(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Ju=(n,t)=>{if(!t.enabled)return!1;const e=Math.abs(n.y),s=cn(cn(Math.abs(n.x),2)+cn(e,2),.5),i=Math.abs(Math.acos(e/s));return e>t.yDiff&&i<t.edgeAngle},Qu=2;class tf extends X{constructor(t,e,s,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=s,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:s}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:s}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:s}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=bo(e,i.x,s,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),s=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];s[r]=a.pageX-e.left-i}return s}pinchHandler(t,e){const s=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=s+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;s>=i||e[0]===e[1]||this.scale.setXScale(s,i)}}const bo=(n,t,e,s,i=Qu)=>Math.sqrt(Math.pow(n-t,2)+Math.pow(e-s,2))>i,Um={MAX_DIMENSION:2048,MAX_TOTAL_PIXELS:18e5,ZOOM_OPTIMIZED_PIXELS:12e5},ef=2e6,sf=24,nf=20,rf=16,of=10,af=1e3,Gm=5e4,Zm={MIN:60,LOW:80,MEDIUM:100,HIGH:120,MAX:150};class lf extends vo{constructor(t,e,s,i,r,o,a,l){super(t,e,s,i,r,o,a,l),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=ie,this.wheelSubscription=null,this.initFrameId=null,this.isActivated=!1,this.lastWheelTime=0,this.wheelCount=0,this.consecutiveLowWheelEvents=0,this.chartPanningOptions={horizontal:!0,vertical:!0}}doActivate(){this.isActivated||(this.isActivated=!0,super.doActivate(),this.canvasInputListener.initializeRectCache(),this.createWheelSubscription(),this.initFrameId=requestAnimationFrame(()=>{this.bus.fireDraw()}),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:t})=>{this.lastXStart+=t})),this.addRxSubscription(this.bus.observe(cs).pipe(Nr(100)).subscribe(()=>{this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation()})))}createWheelSubscription(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null);const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES),e=this.canvasBoundsContainer.getBounds(T.CANVAS),s=e.width*e.height;s>0?s>ef?this.wheelThrottleTime=sf:this.wheelThrottleTime=nf:this.wheelThrottleTime=rf,this.wheelSubscription=this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Z(i=>ms()==="apple"?Math.abs(i.deltaY)>1||Math.abs(i.deltaX)>1:!0),Et(this.wheelThrottleTime,Ot,{trailing:!0,leading:!0})).subscribe(i=>{const r=performance.now();this.lastWheelTime||(this.lastWheelTime=r,this.wheelCount=0),this.wheelCount++,r-this.lastWheelTime>af&&(Math.round(this.wheelCount*1e3/(r-this.lastWheelTime))<of?(this.consecutiveLowWheelEvents++,this.consecutiveLowWheelEvents>=1&&(this.triggerPerformanceCleanup(),this.consecutiveLowWheelEvents=0)):this.consecutiveLowWheelEvents=0,this.lastWheelTime=r,this.wheelCount=0);const o=ms(),a=o==="apple"||o==="mobile"?-1:1,l=0+i.deltaX*a,c=0+i.deltaY*a;if(i.ctrlKey){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw();return}if(c!==0&&Math.abs(c)>Math.abs(l)){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw()}if(l!==0&&Math.abs(l)>Math.abs(c)){const h=Rt(l,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-h),this.bus.fireDraw();return}}),this.addRxSubscription(this.wheelSubscription)}triggerPerformanceCleanup(){window.dispatchEvent(new Event("resize")),window.gc&&window.gc(),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation(),this.consecutiveLowWheelEvents=0,this.wheelCount=0,this.lastWheelTime=0}doDeactivate(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.isActivated=!1,super.doDeactivate()}}class cf extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=s,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c;const h=[this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel],d=Me?new lf(...h):new vo(...h);this.chartAreaPanHandler=d,this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new tf(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const Co=n=>t=>{const{top:e,bottom:s}=n(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*s/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},yo=(n,t)=>{const e=Co(n);return{isHighLowActive:()=>!0,calculateHighLow:s=>{const i=t.calculateHighLow(s);return e(i)}}};function hf(){return Xn(1)}function wo(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return hf()(Ge(n,Ue(n)))}function df(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n);return N(function(s,i){(e?wo(n,s,e):wo(n,s)).subscribe(i)})}function uf(n){return Z(function(t,e){return n<=e})}class ff{constructor(t,e,s,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=s,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),s=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(s.fillStyle=i.getColor(0),s.fillRect(e.x,e.y-r,e.width,e.height+2*r)),s.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?s.fillRect(e.x,e.y,e.width,e.height):s.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const So=8;class hn extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=s,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new R,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=g=>{const{delta:m,draggedPixels:x}=g;Math.abs(this.initialY-this.boundsProvider().y+x)>=0&&(this.dragTickCb(m),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const s=new us(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:jt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:jt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(s),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(df(!1),Z(this.dragPredicate),_t(),uf(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new ff(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,Br.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(Br.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const dn=1/32,gf=n=>{const t=Math.floor(n),e=n-t,s=Math.round(e*64),r=Math.floor(s/2).toString().padStart(2,"0");return`${t}'${r}`},xo=n=>n.match(/^\-?0*(\d+)'(\d{2})$/),$m=n=>!!xo(n),Km=n=>{const t=xo(n);if(t){const e=parseInt(t[1],10),i=parseInt(t[2],10)*dn;return e+i}return Number(n)},pf=(n,t)=>e=>{let s;if(typeof e=="number")s=e;else if(typeof e=="string")s=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return gf(s);const[r]=n.dataSeries;if(r!==void 0){const o=me.getPricePrecision(s,r.pricePrecisions);return s.toFixed(o)}return`${s}`},mf=n=>(t,e)=>{const[s]=n.dataSeries;let i=t;const r=e!=null?e:s;r!==void 0&&(i=Qi(t,r.getBaseline()));const o=Je(i.toFixed(me.DEFAULT_PRECISION))+" %";return o===`${qn}0.00 %`?"0.00 %":o},vf=(n,t)=>({percent:mf(n),regular:pf(n,t)});class bf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u=new Set,f={regular:kc}){super(),this.config=t,this.paneUUID=e,this.idx=s,this.paneComponent=i,this.chartBaseModel=r,this.canvasBoundsContainer=o,this.hitTestController=a,this.dynamicObjectsCanvasModel=l,this.scale=c,this.dragNDrop=d,this.dataSeries=u,this.formatters=f,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(m=>new Oe(this.chartBaseModel.dataFromTimestamp(m.timestamp).centerUnit,m.close)),this.toY=g=>{var m,x;return(x=(m=this.mainDataSeries)==null?void 0:m.view.toY(g))!=null?x:1},this.valueFormatter=(g,m)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(g);const{regular:x,percent:_,logarithmic:A}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(g);case"percent":return _?_(g,m):x(g);case"logarithmic":return A?A(g):x(g);default:return this.regularFormatter(g)}},this.addChildEntity(c),this.setValueFormatters(vf(this,t)),this.yAxis=h(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new or(this,yt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){if(this.dataSeries.add(t),this.dataSeries.size===1)this.mainDataSeries=t;else if(this.paneComponent.yExtentComponents.length>1&&this.paneUUID!==K){this.mainDataSeries=t;const e=Array.from(this.paneComponent.mainExtent.dataSeries);this.paneComponent.mainExtent.mainDataSeries=e[e.length-1]}this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,s;return(s=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?s:this.scale.fromY(t)}}const _o=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(n.dataSeries).filter(s=>s.highLowProvider.isHighLowActive()).map(s=>s.highLowProvider.calculateHighLow(t));return vr(e)}});class Cf{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=an.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return an.DATA_SERIES}get allDataSeries(){return Ee(Ee(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(s=>s.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(s=>s.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Vt="#FF00FF";function qm(n,t,e,s){const i=n.yAxis.backgroundColor,r=n.chartAreaTheme.backgroundColor,o=n.chartAreaTheme.backgroundGradientTopColor,a=n.chartAreaTheme.backgroundGradientBottomColor,l=s.align==="left"?o:a,c=n.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const yf=(n,t)=>n==="down"?t.lastPrice.textNegative:n==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,wf=(n,t)=>{const e=t.barTheme[`${n}Color`];return e!=null?e:Vt},Sf=(n,t)=>{const e=t.lineTheme[`${n}Color`];return e!=null?e:Vt},xf=(n,t)=>{const e=t.candleTheme[`${n}Color`];return e!=null?e:Vt},_f=(n,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Vt},Pf=(n,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Vt},Tf=(n,t)=>{const e=t.histogram[`${n}Bright`];return e!=null?e:Vt},Mf=(n,t)=>{const e=n==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Vt},Po=(n,t)=>{const e=t.candleTheme[`${n}WickColor`];return e!=null?e:Vt},Af=()=>(console.warn("Fallback for label default color"),Vt),To=10;class Mo extends X{constructor(t,e,s,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new R,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(T.Y_AXIS).height,Di),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(To-1)):d=1+h/this.lastYPxHeight*(To-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,g=this.lastYStart-f,m=this.lastYEnd+f;(this.lastYStart!==g||this.lastYEnd!==m)&&(this.scale.setYScale(g,m),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new us(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,s,{dragPredicate:()=>s.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Ef{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${yt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Kn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const If=0,Df=.01;class un{constructor(t,e,s,i,r=!1,o,a,l=js,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=s,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new R,this.newGeneratedLabelsSubject=new R,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Ef(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,s){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=ft.roundToNearest(t,s);for(;r<e;){const o=ft.roundToNearest(r,s),a=Je(this.valueFormatter(o));i.push({value:o,text:a}),r=ft.roundDecimal(r+s)}return i}generatePercentLabels(t,e,s){const i=[],r=this.baseLineProvider();let o=ft.roundToNearest(t,s);for(;o<e;){const a=ft.roundToNearest(o,s),l=tr(a,r),c=Je(this.valueFormatter(l));i.push({value:a,text:c}),o=ft.roundDecimal(o+s)}return i}generateLogarithmLabels(t,e,s){const i=[];let r=ft.roundToNearest(t,s);for(;r<e;){const o=Qs(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=ft.roundDecimal(r+s)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[s,i]=this.calculateMinMax(),r=this.getAxisStep(s,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(s,i,r):a==="percent"?o=this.generatePercentLabels(s,i,r):o=this.generateRegularLabels(s,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),s=this.lengthProvider(),i=un.getLabelBounds(t,e,s);return[i[0],i[1]]}getAxisStep(t,e,s){const i=e-t,r=s/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const s=(e=this.treasuryFormat)!=null&&e.enabled?dn:me.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(s)}return this.adjustIncrementOnAxisType(Df)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Qs(e)+t;return er(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,s){const i=Math.abs((e-t)*(If/s));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let s=e,i=e,r=0;for(;s<t&&s>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),s=i*this.gridDistanceMultipliers[r++];return s}}class Lf extends un{constructor(t,e,s,i,r=()=>"regular",o=23,a){super(t,()=>[s.yStart,s.yEnd],()=>s.getBounds().height,i,!1,r,()=>{var l,c;return(c=(l=e())==null?void 0:l.getBaseline())!=null?c:1},void 0,o,a),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,s)=>s.text.length>e.length?s.text:e,"")}updateTreasuryFormat(t){this.treasuryFormat=t}calculateIncrement(t){var e,s;const i=this.dataSeriesProvider();if(i){const r=wt(i.dataPoints),o=(e=r==null?void 0:r.close)!=null?e:0,a=Kc(o,i.pricePrecisions),l=(s=this.treasuryFormat)!=null&&s.enabled?dn:a;return this.adjustIncrementOnAxisType(l)}return super.calculateIncrement(t)}}function Ao(n,t,e){var s=k(n)||t||e?{next:n,error:t,complete:e}:n;return s?N(function(i,r){var o;(o=s.subscribe)===null||o===void 0||o.call(s);var a=!0;i.subscribe(bt(r,function(l){var c;(c=s.next)===null||c===void 0||c.call(s,l),r.next(l)},function(){var l;a=!1,(l=s.complete)===null||l===void 0||l.call(s),r.complete()},function(l){var c;a=!1,(c=s.error)===null||c===void 0||c.call(s,l),r.error(l)},function(){var l,c;a&&((l=s.unsubscribe)===null||l===void 0||l.call(s)),(c=s.finalize)===null||c===void 0||c.call(s)}))}):de}class Of extends X{constructor(t,e,s,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=s,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${yt()}`}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ct(t=>t.height),Z(t=>Qa(t,this.prevYAxisHeight,1.5)),Ao(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,_e(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){_e(this.animFrameId,()=>{this.labels=this.labelsGenerator.generateNumericLabels(),this.canvasBoundsContainer.updateYAxisWidths()})}}class Bf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=s,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Lf(null,l,o,a,()=>this.state.type,s.labelHeight,s),this.baseLabelsModel=new Of(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new _c(e,o,i,s,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(s=>s.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(s=>s.labels).map(s=>s.labelText)).reduce((s,i)=>i.length>s.length?i:s,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class Rf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x){super(),this.eventBus=t,this.config=e,this.mainCanvasModel=s,this.canvasModel=i,this.scale=r,this.canvasInputListeners=o,this.canvasBoundsContainer=a,this.chartPanComponent=l,this.cursors=c,this.paneUUID=u,this.extentIdx=f,this.hitTestCanvasModel=g,this.chartResizeHandler=m,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new R,this.axisAlignSetSubject=new R,this.axisAlignMovedSubject=new R,this.setDblClickCallback=A=>this.yAxisScaleHandler.setDblClickCallback(A),this.setDblTapCallback=A=>this.yAxisScaleHandler.setDblTapCallback(A);const _=x?ne(x):{};this.state=Tt(_,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new Mo(t,this.state,l,r,o,a,a.getBoundsHitTest(T.PANE_UUID_Y_AXIS(u,f)),g),this.addChildEntity(this.yAxisScaleHandler),this.model=new Bf(this.paneUUID,t,this.state,a,i,r,h,d,f,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new Mo(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",xf),this.registerLabelColorResolver("bar",wf),this.registerLabelColorResolver("line",Sf),this.registerLabelColorResolver("area",_f),this.registerLabelColorResolver("scatterPlot",Pf),this.registerLabelColorResolver("histogram",Tf),this.registerLabelColorResolver("baseline",Mf),this.registerLabelColorResolver("trend",Po),this.registerLabelColorResolver("hollow",Po)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Af}registerYAxisLabelsProvider(t,e=se.MAIN,s=yt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,s),s}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}updateCustomYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=se.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor(),this.mainCanvasModel.fireDraw())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Ff extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_,A,L,j){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=s,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=g,this.uuid=m,this.seriesAddedSubject=x,this.seriesRemovedSubject=_,this.hitTestCanvasModel=A,this.chartResizeHandler=L,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new R,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,Y)=>this.mainExtent.valueFormatter(B,Y);const F=this.createExtentComponent(j);this.mainExtent=F,this.ht=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID(m),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return Ee(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(T.PANE_UUID(this.uuid)).pipe(_t(Hi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,s;return(s=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?s:this.scale.toY(t)}createGridComponent(t,e,s,i,r,o){var a,l;const c=T.PANE_UUID(t),h=(l=(a=this.mainExtent)==null?void 0:a.idx)!=null?l:0;return new ho(this.mainCanvasModel,s,this.config,i,`PANE_${t}_${e}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(c),()=>this.canvasBoundsContainer.getBounds(c),()=>[],r,e,o,()=>this.config.components.grid.visible,h)}createYPanHandler(t,e){const s=T.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(s));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const s=T.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(s,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(s)}createExtentComponent(t){var e,s;const i=this.yExtentComponents.length,r=T.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Ph(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(m,x)=>new Rf(this.eventBus,this.config,this.mainCanvasModel,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,m,x,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new bf(this.config.components.yAxis,this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((s=t==null?void 0:t.useDefaultHighLow)!=null?s:!0)&&a.autoScaleModel.setHighLowProvider("default",yo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),_o(u)));const g=this.createGridComponent(this.uuid,u.idx,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(g),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(s=>s.idx).includes(e.idx)),this.yExtentComponents.forEach((e,s)=>{e.yAxis.setExtentIdx(s),e.idx=s,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,s,i="right"){const r=ne(s.yAxis.state),o=ne(s.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),s.dataSeries.size===0&&e.removeExtentComponents([s])}moveDataSeriesToExistingExtentComponent(t,e,s,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&s.dataSeries.size===0&&e.removeExtentComponents([s]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(s=>s.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=fe(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=wt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var Hf=Object.defineProperty,kf=Object.defineProperties,Yf=Object.getOwnPropertyDescriptors,Eo=Object.getOwnPropertySymbols,jf=Object.prototype.hasOwnProperty,Nf=Object.prototype.propertyIsEnumerable,Io=(n,t,e)=>t in n?Hf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Xf=(n,t)=>{for(var e in t||(t={}))jf.call(t,e)&&Io(n,e,t[e]);if(Eo)for(var e of Eo(t))Nf.call(t,e)&&Io(n,e,t[e]);return n},Wf=(n,t)=>kf(n,Yf(t));class zf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=s,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=g,this.yAxisLabelsCanvasModel=m,this.hitTestCanvasModel=x,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new R,this.paneAddedSubject=new R,this.dataSeriesAddedSubject=new R,this.dataSeriesRemovedSubject=new R,this.hitTestController=new Cf(this.panes,this.dynamicObjectsCanvasModel);const A=this.createPane(K,{useDefaultHighLow:!1,scale:this.mainScale});A.mainExtent.scale.autoScaleModel.setHighLowProvider("series",_o(A.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",Co(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+So}),s=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=T.PANE_UUID_RESIZER(t),o=new hn(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,s,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return Ee(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(s=>this.canvasBoundsContainer.getBoundsHitTest(T.PANE_UUID(s.uuid))(t.x,t.y))}createPane(t=yt(),e){if(this.panes[t]!==void 0)return this.panes[t];const s=new Ff(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&s.addChildEntity(this.addResizer(t)),s.addSubscription(this.addBounds(t,e==null?void 0:e.order)),s.addSubscription(this.addCursors(t)),s.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,s.ht)),this.panes[t]=s,s.activate(),this.recalculateState(),s.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),s}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,s;const i=fe(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}canMovePaneDown(t){var e,s;const i=wt(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(s=>s.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const s=T.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof hn&&r.id===s);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],s=T.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof hn&&r.id===s);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,s,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?Wf(Xf({},s.yAxis.state),{align:l}):void 0,g=c&&c>0;if(!u){const m=a&&a==="above"?d:d+1,x=this.createPane(r,{order:m,initialYAxisState:f,inverse:s.scale.state.inverse,lockToPriceRatio:s.scale.state.lockPriceToBarRatio});x.moveDataSeriesToExistingExtentComponent(t,e,s,x.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!g?u.moveDataSeriesToExistingExtentComponent(t,e,s,o):u.moveDataSeriesToNewExtentComponent(t,e,s,l!=null?l:s.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const s=T.PANE_UUID(t),i=T.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(s,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+So),()=>{this.cursorHandler.removeCursorForCanvasEl(s),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class Vf extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,s=this.canvasModel.ctx;if(s){s.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return s.drawImage(this.elements.backgroundCanvas,0,0,i,r),s.drawImage(this.elements.mainCanvas,0,0,i,r),s.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),s.drawImage(this.elements.crossToolCanvas,0,0,i,r),s.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(s),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const Uf=(n,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function s(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return s(n)},Do=class _s extends X{constructor(t,e,s,i){super(),this.chartComponent=t,this.config=e,this.volumesModel=s,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var t,e;return!((t=this.pane)!=null&&t.scale.isViewportValid())&&((e=this.pane)==null?void 0:e.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var t;return(t=this.pane)==null?void 0:t.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[_s.UUID]===void 0){const e=this.paneManager.createPane(_s.UUID,{paneFormatters:{regular:r=>Uf(r,1)},useDefaultHighLow:!1,increment:1});this.pane=e,e.mainExtent.yAxis.setAxisType("regular");const{scale:s}=e,i=yo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);s.autoScaleModel.setHighLowProvider("volumes",i),s.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(_s.UUID),delete this.pane}fromY(t){var e,s;return(s=(e=this.pane)==null?void 0:e.scale.fromY(t))!=null?s:0}};Do.UUID="volumes";let Gf=Do;const vs=.3,Zf=(n,t)=>{const e=t.barTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},$f=(n,t)=>{const e=t.volume[`${n}BarColor`];return Lt()(e).alpha(vs).toString()},Kf=(n,t)=>{const e=t.lineTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},fn=(n,t)=>{const e=t.candleTheme[`${n}Color`];return Lt()(e).alpha(vs).toString()},qf=3;class Jf{constructor(t,e,s,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=s,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const s=(e=this.volumesColorByChartTypeMap[t])!=null?e:$f;this.volumeBarColors.down=s("down",this.config.colors),this.volumeBarColors.up=s("up",this.config.colors),this.volumeBarColors.none=s("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const s=this.getViewportModel().getBounds();Zt(e,s),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const s=this.getViewportModel();if(!s.isViewportValid())return;const i=pt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1));i.forEach((r,o)=>{if(r.candle.volume){const a=s.getBounds(),l=a.height;if(l<=0)return;const c=i[o+1]!==void 0?Mt(s.toX(i[o+1].startUnit)):void 0,h=Mt(s.toX(r.startUnit)),d=c!==void 0?c-h:Mt(mt(r.width,s.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(s.toY(r.candle.volume)),f=Ks(s.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=l/qf;if(u<=0)return;const f=e/u;if(!isFinite(f)||f<=0)return;const g=Math.max(Ks(mt(r.candle.volume,f)),2),m=Math.min(g,l),x=Mt(a.y+l-m);this.drawVolume(t,r,h,x,d,m)}}})}drawVolume(t,e,s,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(s,l),a.lineTo(s,Ks(c)),a.stroke()):a.fillRect(s,i,r,o)}}const Qf=xl(n=>n.candle.volume),Lo="volumes";class tg extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=Lo,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;const e=this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport(this.scale.xStart-1,this.scale.xEnd+1);this.volumeMax.next((t=fe(Qf(e.flat())))!=null?t:0)}}class eg extends X{constructor(t,e,s,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new tg(e,s);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new Gf(e,o,c,a),this.volumesDrawer=new Jf(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:s},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",fn),this.registerVolumeColorResolver("trend",fn),this.registerVolumeColorResolver("hollow",fn),this.registerVolumeColorResolver("line",Kf),this.registerVolumeColorResolver("bar",Zf)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t),this.syncVolumesDynamicObject())}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.syncVolumesDynamicObject(),this.canvasModel.fireDraw()}syncVolumesDynamicObject(){if(!this.config.components.volumes.visible){this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id);return}const e=this.config.components.volumes.showSeparately?Lo:K,s={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(s);return}this.dynamicObjectsComponent.model.updateObject(s)}}class sg{constructor(t,e,s,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=s,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(T.PANE_UUID(K)),{position:g,offsetY:m,offsetX:x}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=bs(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=ng(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),g){case"left-top":return{x:x+f.x,y:m+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:x+f.x,y:f.height-h-m+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,s,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let g=0,m=0,x=0,_=0,A=0;if(f.save(),d.firstRowFontSize&&l){f.font=bs(this.config,d.firstRowFontSize);const B=f.measureText(l);g=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=bs(this.config,d.secondRowFontSize);const B=f.measureText(c);m=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,x=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=bs(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,A=(s=d.secondRowBottomPadding)!=null?s:0}const L=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,F=g+m+x+_+A+L+j;if(l&&this.drawWaterMark(this.getConfig(g,l,d.firstRowFontSize,u.firstRowColor,F)),c&&this.drawWaterMark(this.getConfig(g+x+m,c,d.secondRowFontSize,u.secondRowColor,F)),h&&this.drawWaterMark(this.getConfig(g+x+m+A+_,h,d.thirdRowFontSize,u.thirdRowColor,F)),this.logoImage){const B=this.getConfig(g+x+m+A+_+L,"",d.thirdRowFontSize,u.thirdRowColor,F,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const s=this.canvasModel.ctx;s.font=t.font,s.fillStyle=t.color;const i=t.x,r=t.y;s.fillText(e,i,r)}reset(){}}const ng=(n,t,e,s)=>{const r=((a,l)=>t.getBounds(T.CHART).width/l*a)(e,s);let o;return n.components&&n.components.waterMark&&(o=n.components.waterMark.fontFamily),r+"px "+o},bs=(n,t)=>{let e;return n.components&&n.components.waterMark&&(e=n.components.waterMark.fontFamily),t+"px "+e};var ig=Object.defineProperty,Oo=Object.getOwnPropertySymbols,rg=Object.prototype.hasOwnProperty,og=Object.prototype.propertyIsEnumerable,Bo=(n,t,e)=>t in n?ig(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ro=(n,t)=>{for(var e in t||(t={}))rg.call(t,e)&&Bo(n,e,t[e]);if(Oo)for(var e of Oo(t))og.call(t,e)&&Bo(n,e,t[e]);return n};class ag extends X{constructor(t,e,s,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=s,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new sg(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(T.PANE_UUID(K)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return Ro(Ro({},this.config.components.waterMark),h)}}const Fo={x:4,y:4};function lg(n,t,e,s){var i,r;const o=(i=s.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(T.X_AXIS);n.save(),n.font=`bold ${a}px ${l}`;const g=n.measureText(s.text).width+Fo.x*2;let m=0;const x=s.x;switch(o){case"start":m=x-g;break;case"end":m=x;break;case"middle":default:m=x-g/2;break}n.fillStyle=h.backgroundColor,n.strokeStyle=h.backgroundColor,n.fillRect(m,u.y,g,u.height),o!=="middle"&&(n.strokeStyle=s.color,n.beginPath(),n.moveTo(x,u.y),n.lineTo(x,u.y+u.height),n.stroke()),n.fillStyle=s.color;const _=m+Fo.x,A=u.y+d+a+Ie/2;n.fillText(s.text,_,A),n.restore()}class cg{constructor(t,e,s,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=s,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{lg(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},s=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(s).forEach(i=>{const r=s[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(T.X_AXIS);t.fillStyle=Lt().rgb(r[0].color).alpha(.1).toString(),Tr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const Jm="week-weekday",hg=["second","minute","hour","day","month","year"],dg=["lessThanSecond"],ug=n=>hg.some(t=>t===n),fg=n=>n==="week-weekday",gg=n=>dg.some(t=>t===n),Ho=n=>{const t={"!":!1,$:!1};return n.includes("!")&&(t["!"]=!0),n.includes("$")&&(t.$=!0),t},gn=n=>parseInt(n,10),ko=n=>{const[t,...e]=n.split("_");if(ug(t)){const[s]=e,i=Ho(s),r=gn(s);return{key:t,value:r,exact:i["!"]}}else if(fg(t)){const[s,i]=e,r=Ho(s),o=gn(s),a=gn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return gg(t)?{key:t}:(console.warn(`${n} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class Cs{constructor(t,e,s,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=s,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,s=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=Cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=s.backgroundColor;const l=this.canvasBoundsContainer.getBounds(T.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Ie/2),e.restore()}}drawLabels(t,e,s,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Pt(c.text,t,l)/2;if(h<s.x||h>s.width)continue;const d=s.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const pn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},Yo=n=>{switch(n.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return pn[n.key]+n.value;case"lessThanSecond":return pn[n.key];case"week-weekday":return pn[n.key]+(n.week==="$"?9:n.week)+n.weekday*10}},jo=n=>{const t={};for(const e of n){const s=t[e.weight];s===void 0?t[e.weight]=[e]:s.push(e)}return t},pg=(n,t)=>{const e=Object.keys(n).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let s=[];for(const i of e){const r=n[i];if(!r)continue;const o=[...s];s=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],g=f.idx;for(;c<a;){const m=o[c],x=m.idx;if(g>x)c++,s.push(m),d=x,h=1/0;else{h=x;break}}h-g>=t&&g-d>=t&&(s.push(f),d=g)}for(;c<a;)s.push(o[c]),c++}return s},mg=(n,t,e,s,i,r)=>{const o=Cs.getFontFromConfig(t),a=Pt(e.text,n,o),l=Pt(s.text,n,o),c=i.toX(e.value)+a/2;return i.toX(s.value)-l/2-c<r},Qm=7,vg=365.2425,ev=-(Math.pow(10,8)*24*60*60*1e3),sv=6048e5,nv=864e5,iv=6e4,rv=36e5,ov=1e3,av=525600,lv=43200,cv=1440,hv=60,dv=3,uv=12,fv=4,bg=3600,gv=60,No=bg*24,pv=No*7,bv=No*vg/12*3,Xo=Symbol.for("constructDateFrom");function mn(n,t){return typeof n=="function"?n(t):n&&typeof n=="object"&&Xo in n?n[Xo](t):n instanceof Date?new n.constructor(t):new Date(t)}const Cv=null;function Ft(n,t){return mn(t||n,n)}const yv=null;function Cg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===1}const wv=null;function yg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===2}const Sv=null;function wg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===3}const xv=null;function Sg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===4}const _v=null;function xg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===5}const Pv=null;function _g(n,t){return Ft(n,t==null?void 0:t.in).getDay()===6}const Tv=null;function Pg(n,t){return Ft(n,t==null?void 0:t.in).getDay()===0}const Mv=null;function Wo(n,...t){const e=mn.bind(null,n||t.find(s=>typeof s=="object"));return t.map(e)}function Tg(n,t){const[e,s]=Wo(n,t.start,t.end);return{start:e,end:s}}function Mg(n,t){var c;const{start:e,end:s}=Tg(t==null?void 0:t.in,n);let i=+e>+s;const r=i?+e:+s,o=i?s:e;o.setHours(0,0,0,0);let a=(c=t==null?void 0:t.step)!=null?c:1;if(!a)return[];a<0&&(a=-a,i=!i);const l=[];for(;+o<=r;)l.push(mn(e,o)),o.setDate(o.getDate()+a),o.setHours(0,0,0,0);return i?l.reverse():l}const Av=null;function Ag(n,t){const e=Ft(n,t==null?void 0:t.in);return e.setDate(1),e.setHours(0,0,0,0),e}const Ev=null;function Eg(n,t){const e=Ft(n,t==null?void 0:t.in),s=e.getMonth();return e.setFullYear(e.getFullYear(),s+1,0),e.setHours(23,59,59,999),e}const Iv=null;function zo(n,t){const e=Ft(n,t==null?void 0:t.in);return e.setHours(0,0,0,0),e}const Dv=null;function Vo(n,t,e){const[s,i]=Wo(e==null?void 0:e.in,n,t);return+zo(s)==+zo(i)}const Lv=null,Ig=n=>{switch(n.key){case"lessThanSecond":return Bg(n);case"month":return Rg(n);case"second":case"minute":case"hour":case"day":case"year":return Fg(n);case"week-weekday":return Hg(n);default:return()=>!1}},qt=(n,t)=>{switch(t){case"lessThanSecond":return n.getMilliseconds();case"month":return n.getMonth();case"second":return n.getSeconds();case"minute":return n.getMinutes();case"hour":return n.getHours();case"day":return n.getDate();case"year":return n.getFullYear();case"week-weekday":return n.getDate()}},vn=n=>(t,e)=>{const s=qt(t,n),i=qt(e,n);return s!==i},Dg=n=>(t,e)=>{const s=qt(t,n),i=qt(e,n);return s>=i},Lg={1:Cg,2:yg,3:wg,4:Sg,5:xg,6:_g,7:Pg},Og=(n,t,e)=>{var s;const i=Mg({start:Ag(n),end:Eg(n)}),r=(s=Lg[e])!=null?s:(()=>!1);if(t==="$"){for(const o of i.reverse())if(r(o))return Vo(n,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return Vo(n,a);o++}}return!1},Uo=(n,t)=>t===1?n===1:n/t===1,Go=(n,t)=>t===1?!0:n%t===0,Bg=n=>(t,e)=>Dg(n.key)(t,e),Rg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=n.exact?Uo(qt(t,n.key)+1,n.value):Go(qt(t,n.key)+1,n.value);return s&&i},Fg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=n.exact?Uo(qt(t,n.key),n.value):Go(qt(t,n.key),n.value);return s&&i},Hg=n=>(t,e)=>{const s=vn(n.key)(t,e),i=Og(t,n.week,n.weekday);return s&&i},kg=n=>{switch(n.key){case"second":case"minute":return Yg(n.value);case"hour":return jg(n.value);case"day":return Ng(n.value);case"month":return zg(n.value);case"year":return Vg(n.value);case"week-weekday":const t=Wg(n.week),e=Xg(n.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},Yg=n=>n>0&&n<=60,jg=n=>n>0&&n<=24,Ng=n=>n>0&&n<=31,Xg=n=>Zo(n)?n>=1&&n<=7:!1,Wg=n=>n==="$"?!0:Zo(n)?n>=1&&n<=6:!1,zg=n=>n>0&&n<=12,Vg=n=>n>0,Zo=n=>!isNaN(n)&&isFinite(n),Ug=(n,t,e)=>{var s,i;for(const[r,o]of e)if(o(n,t))return r;return(i=(s=e[e.length-1])==null?void 0:s[0])!=null?i:0};function bn(n,t,e){const s=new Array(n.length);let i=e(0);for(let r=0;r<n.length;r++){const o=n[r],a=e(o.candle.timestamp),l={weight:Ug(a,i,t)};s[r]=l,i=a}return s}const $o=n=>{const t={},e={};return qs(n).forEach(([s,i])=>{const r=ko(s),o=r===null?!1:kg(r);if(r&&o){const a=Yo(r);t[a]=i,e[a]=Ig(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Ko{constructor(t,e,s,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=s,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.labelCache=new Map,this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?mt(d,h.animationConfig.targetZoomX):mt(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,g=Object.values(this.formatsByWeightMap).reduce((x,_)=>Math.max(_.length,x),1),m=f*g;return Math.round(m/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=$o(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(T.X_AXIS),s=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||s.push(i)}return s}getLabelsFromChartType(){var t,e;const s=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(s):s}getVisualCandleAtIndex(t,e,s,i,r){return t>=0&&t<s.length?s[t]:tn(e,s,i,t,r)}getVisualCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>tn(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}getViewportCandlesWithFake(){var t;const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0||this.scale.xEnd-this.scale.xStart<=1)return[];const s=this.chartModel.mainCandleSeries.meanCandleWidth,i=this.chartModel.getPeriod(),r=this.chartModel.mainCandleSeries.dataPoints,o=this.canvasBoundsContainer.getBounds(T.CHART),a=0,l=o.width,c=this.scale.fromX(a),h=this.scale.fromX(l);let d=0;if(e.length>0){const L=e[0];d=L.centerUnit-((t=L.candle.idx)!=null?t:0)*s}const u=500,f=500,g=Math.floor((c-d)/s)-u,m=Math.ceil((h-d)/s)+u,x=Math.floor(g/f)*f,_=Math.ceil(m/f)*f,A=[];for(let L=x;L<=_;L++)A.push(this.getVisualCandleAtIndex(L,r,e,s,i));return[...A]}getAllCandlesWithFake(t=[]){return this.config.components.chart.minCandlesOffset?this.getVisualCandlesWithFake(t):this.getViewportCandlesWithFake()}mapWeightedPointsToLabels(t,e){var s;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(s=a.candle.idx)!=null?s:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){this.clearLabelCache();const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:s}=$o(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(s).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=bn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),s=bn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(s,e),r=jo(i),o=ne(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const g=f.map(m=>(m.idx=m.idx+t.length,m.value=a.startUnit+a.width+m.value,m));r[u]?c[h]=d.concat(g):c[h]=g}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t,e=!1){var s;const i=this.getAllCandlesWithFake(t),r=bn(i,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone));let o=[];if(e)for(let a=0;a<i.length;a++){const l=(s=i[a].candle.idx)!=null?s:a,c=i[a].candle.timestamp,h=`${l}_${c}`;let d=this.labelCache.get(h);d||(d=this.mapWeightedPointsToLabels([r[a]],[i[a]])[0],this.labelCache.set(h,d)),o.push(d)}else o=this.mapWeightedPointsToLabels(r,i);this.labelsGroupedByWeight=jo(o),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const s=pg(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=s,this.weightedCache={labels:s,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,s;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];mg(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((s=a.weight)!=null?s:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const s=qs(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=ko(o);if(l){const c=Yo(l);i[c]=a}}return i},{});return qs(t).reduce((i,[r,o])=>(s[r]&&s[r](e)||(i[r]=o),i),{})}clearLabelCache(){this.labelCache.clear()}}class Gg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(hs,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const qo=3;class Zg extends X{constructor(t,e,s,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(T.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,g=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(g,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(qo-1)):u=1+h/this.lastXPxWidth*(qo-1);const g=(this.lastXWidth*u-this.lastXWidth)/2,m=this.lastXStart-g,x=this.lastXEnd+g;(this.lastXStart!==m||this.lastXEnd!==x)&&this.scale.setXScale(m,x)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Ye(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class $g extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=s,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=x=>this.xAxisScaleHandler.setDblClickCallback(x),this.setDblTapCallback=x=>this.xAxisScaleHandler.setDblTapCallback(x);const g=new Ko(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=g,this.xAxisLabelsModel=new Gg(t,[]);const m=new rn;c.addDrawer(m,"X_AXIS"),this.xAxisDrawer=new Cs(e,s,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),m.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new cg(e,s,o,this.xAxisLabelsModel),m.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new Zg(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(T.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(T.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(Ct(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(Z(({prependedCandles:t})=>t.length!==0),ct(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,s;Yl.includes(this.config.components.chart.type)&&((s=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||s.call(e,t))})),this.config.components.chart.minCandlesOffset?this.addRxSubscription(Ct(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Et(50,Ot,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.recalculateLabels())):this.addRxSubscription(Ct(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Et(150,Ot,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.generateLabels(void 0,!0))),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ct(()=>wt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),_t((t,e)=>{var s,i;return((s=t==null?void 0:t.candle)==null?void 0:s.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),Z(ri)).subscribe(t=>{var e,s;return(s=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:s.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Ko?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var Kg=Object.defineProperty,Jo=Object.getOwnPropertySymbols,qg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,Qo=(n,t,e)=>t in n?Kg(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ys=(n,t)=>{for(var e in t||(t={}))qg.call(t,e)&&Qo(n,e,t[e]);if(Jo)for(var e of Jo(t))Jg.call(t,e)&&Qo(n,e,t[e]);return n};class Qg{constructor(t,e,s,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=s,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const s=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=s&&ys(ys({},s),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&ys(ys({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=wt(t.dataPoints);if(e){const s=t.view.toY(e.close);if(isFinite(s)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:s,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const s=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:te("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:yf(t.lastPriceMovement,i);return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):te(l,h,o),rounded:!0}}return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):te(l,r,o),rounded:!0}}}class tp{constructor(t,e,s,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=s,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,s=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(T.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>eo(t,s,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>eo(t,s,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,s={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=s[r.subGroupId])!=null?o:[];if(s[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(T.PANE_UUID_Y_AXIS(K));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];Tr(e,{x:h.x,y:Fi(d,h)},{x:h.x+h.width-6,y:Fi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class ep{constructor(t,e,s){this.fullConfig=t,this.canvasModel=e,this.paneManager=s}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const s=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=ee(e.state),a=Nt(o,r),l=this.getLabelTextColor();r.save(),Zt(r,i),this.drawLabels(r,s,i,a,o,l,e),r.restore()}})}drawLabels(t,e,s,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=s.y+c,d=s.y+s.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&sp(t,s,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const sp=(n,t,e,s,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,n,r)-o:t.x+o;n.fillText(e,l,s+i/2-1)};class np{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const s=this.handlers[t];s!==void 0&&wl.call(s,e)},this.add=(t,e,s)=>(e in this.handlers?t.call(this.handlers[e],s):this.handlers[e]=[s],this.unsub.bind(this,e,s)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new R,s=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,s),e.unsubscribe=()=>{this.unsub(t,s),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var s;if(!this.muted){const i=(s=this.handlers[t])!=null?s:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(hs,t)}}class ip extends X{constructor(t,e,s,i){super(),s.observeTouchStart().pipe(ct(r=>i.components.chart.highlightActiveCandle?r:void 0),_t()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,s){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=s.candleFromX(r);o&&s.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const s=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-s.left-i}}class rp{constructor(t,e,s,i,r){this.frameElement=t,this.resizerElement=e,this.bus=s,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${yt()}`,this.canvasResized=new R,this.recentlyResized=!1,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){_e(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.recentlyResized=!0,this.canvasModels.forEach(s=>this.previousBCR&&s.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(cs,e),this.bus.fire(hs))}clearResizedFlag(){this.recentlyResized=!1}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.recentlyResized}}var op=Array.isArray,ap=Object.getPrototypeOf,lp=Object.prototype,cp=Object.keys;function hp(n){if(n.length===1){var t=n[0];if(op(t))return{args:t,keys:null};if(dp(t)){var e=cp(t);return{args:e.map(function(s){return t[s]}),keys:e}}}return{args:n,keys:null}}function dp(n){return n&&typeof n=="object"&&ap(n)===lp}var up=Array.isArray;function fp(n,t){return up(t)?n.apply(void 0,D([],v(t))):n(t)}function ta(n){return ct(function(t){return fp(n,t)})}function gp(n,t){return n.reduce(function(e,s,i){return e[s]=t[i],e},{})}function pp(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=ja(n),i=hp(n),r=i.args,o=i.keys;if(r.length===0)return Ge([],e);var a=new gt(mp(r,e,o?function(l){return gp(o,l)}:de));return s?a.pipe(ta(s)):a}function mp(n,t,e){return e===void 0&&(e=de),function(s){ea(t,function(){for(var i=n.length,r=new Array(i),o=i,a=i,l=function(h){ea(t,function(){var d=Ge(n[h],t),u=!1;d.subscribe(bt(s,function(f){r[h]=f,u||(u=!0,a--),a||s.next(e(r.slice()))},function(){--o||s.complete()}))},s)},c=0;c<i;c++)l(c)},s)}}function ea(n,t,e){n?kt(e,n,t):t()}class vp extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,s){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,s)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const s=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=pp([s,i]).pipe(Z(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!jt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function bp(n,t){return N(function(e,s){var i=null,r=0,o=!1,a=function(){return o&&!i&&s.complete()};e.subscribe(bt(s,function(l){i==null||i.unsubscribe();var c=0,h=r++;At(n(l,h)).subscribe(i=bt(s,function(d){return s.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Cp{constructor(t,e,s,i){this.visualCandle=t,this.price=e,this.priceFormatter=s,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class yp{constructor(t){this.chartModel=t}getData(t){const{x:e,y:s}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(s);return o&&new Cp(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class wp{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof Xr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Sp=Object.defineProperty,xp=Object.defineProperties,_p=Object.getOwnPropertyDescriptors,sa=Object.getOwnPropertySymbols,Pp=Object.prototype.hasOwnProperty,Tp=Object.prototype.propertyIsEnumerable,na=(n,t,e)=>t in n?Sp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,je=(n,t)=>{for(var e in t||(t={}))Pp.call(t,e)&&na(n,e,t[e]);if(sa)for(var e of sa(t))Tp.call(t,e)&&na(n,e,t[e]);return n},Cn=(n,t)=>xp(n,_p(t));class Mp extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=s,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new yp(this.chartModel),u=new wp(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(bp(()=>this.scale.initialViewportValidSubject.pipe(Z(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(Ct(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var s;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((s=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:s.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(T.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var s;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((s=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:s.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var s,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!bo(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(s=this.crossEventProducer.crossToolHover)==null?void 0:s.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(T.PANE_UUID(d)),f=u.y+5,g=u.y+u.height-5,m=c-l.x,x=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=m,A=a.y<f?f:a.y>g?g:a.y+=x;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:A}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=no(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),s=this.scale.toY(t.close);return this.createHover(e,s,K)}createHover(t,e,s){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:s},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>Cn(je({},l),{[c[0]]:c[1].getData(o)}),{});return je(je({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const s=Cn(je({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(s)}}createAndFireHover([t,e,s]){const i=this.createHover(t,e,s);this.fireHover(i)}fireHover(t){var e,s;if(t){if(jt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(s=t.candleHover)==null?void 0:s.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=Cn(je({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const ia={left:0,middle:1,right:2};function vt(n,t,e,s){return n.addEventListener(e,t,s),function(){n.removeEventListener(e,t,s)}}function we(n){return t=>{t.button===ia.left&&n(t)}}var Ap=["addListener","removeListener"],Ep=["addEventListener","removeEventListener"],Ip=["on","off"];function yn(n,t,e,s){if(k(e)&&(s=e,e=void 0),s)return yn(n,t,e).pipe(ta(s));var i=v(Op(n)?Ep.map(function(a){return function(l){return n[a](t,l,e)}}):Dp(n)?Ap.map(ra(n,t)):Lp(n)?Ip.map(ra(n,t)):[],2),r=i[0],o=i[1];if(!r&&Ds(n))return Os(function(a){return yn(a,t,e)})(At(n));if(!r)throw new TypeError("Invalid event target");return new gt(function(a){var l=function(){for(var c=[],h=0;h<arguments.length;h++)c[h]=arguments[h];return a.next(1<c.length?c:c[0])};return r(l),function(){return o(l)}})}function ra(n,t){return function(e){return function(s){return n[e](t,s)}}}function Dp(n){return k(n.addListener)&&k(n.removeListener)}function Lp(n){return k(n.on)&&k(n.off)}function Op(n){return k(n.addEventListener)&&k(n.removeEventListener)}var Bp=Object.defineProperty,oa=Object.getOwnPropertySymbols,Rp=Object.prototype.hasOwnProperty,Fp=Object.prototype.propertyIsEnumerable,aa=(n,t,e)=>t in n?Bp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Hp=(n,t)=>{for(var e in t||(t={}))Rp.call(t,e)&&aa(n,e,t[e]);if(oa)for(var e of oa(t))Fp.call(t,e)&&aa(n,e,t[e]);return n};const ws=class ce extends X{constructor(t,e){super(),this.eventBus=t,this.element=e,this.xDragStartSubject=new R,this.xDragSubject=new R,this.xDragTickSubject=new R,this.xDragEndSubject=new R,this.yDragStartSubject=new R,this.yDragSubject=new R,this.yDragTickSubject=new R,this.yDragEndSubject=new R,this.mouseMoveSubject=new R,this.mouseMoveDocumentSubject=new R,this.clickSubject=new R,this.clickDocumentSubject=new R,this.dbClickSubject=new R,this.dbTapSubject=new R,this.mouseDownSubject=new R,this.mouseUpSubject=new R,this.mouseUpDocumentSubject=new R,this.wheelSubject=new R,this.touchStartSubject=new R,this.touchStartTimestamp=0,this.touchMoveSubject=new R,this.touchEndSubject=new R,this.touchCancelSubject=new R,this.longTouchStartSubject=new R,this.longTouchEndSubject=new R,this.contextMenuSubject=new R,this.fastTouchScroll=new R,this.mouseLeavesCanvasSubject=new R,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.cachedElementRect=null,this.rectCacheValid=!1,this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=s=>{this.isDraggable(s)&&(this.updateCurrentPoints(s),this.dragging=!0,this.dragStartEvent=s,this.cleanupDocumentDragListeners(),this.dragStartPoint=ce.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Hp({},this.dragStartPoint),ce.DRAG_EVENTS.forEach(i=>{document.addEventListener(i,this.dragProcessListener,!0);const r=document.removeEventListener.bind(document,i,this.dragProcessListener,!0);this.documentDragListeners.push(r),this.addSubscription(r)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.cleanupDocumentDragListeners(),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=s=>{this.updateCurrentDocumentPoint(s),this.updateCurrentMousePoint(s)}}getElementRect(){if(this.rectCacheValid&&this.cachedElementRect)return this.cachedElementRect;try{if(!this.element||!this.element.isConnected)return this.createFallbackRect();const t=this.element.getBoundingClientRect();return this.cachedElementRect=t,this.rectCacheValid=!0,t}catch(t){return this.createFallbackRect()}}createFallbackRect(){return typeof DOMRect!="undefined"?new DOMRect(0,0,0,0):{x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON:()=>({})}}invalidateRectCache(){this.rectCacheValid=!1}initializeRectCache(){this.invalidateRectCache();const t=this.getElementRect();this.canvasBounds.x=t.left,this.canvasBounds.y=t.top,this.canvasBounds.width=t.width,this.canvasBounds.height=t.height}cleanupDocumentDragListeners(){if(!this.documentDragListeners||!Array.isArray(this.documentDragListeners)){this.documentDragListeners=[];return}this.documentDragListeners.forEach(t=>{try{t()}catch(e){console.warn("Error cleaning up drag listener:",e)}}),this.documentDragListeners=[]}doDeactivate(){this.invalidateRectCache(),this.cachedElementRect=null,this.cleanupDocumentDragListeners(),super.doDeactivate()}isDraggable(t){return t instanceof MouseEvent?t.button===ia.left:t instanceof TouchEvent}startDragging(t){this.updateCurrentPoints(t),this.dragStartListener(t)}movePointer(t){this.updateCurrentPoints(t),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const t=e=>(e.preventDefault(),!1);this.element.addEventListener("selectstart",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",t,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ce.DRAG_START_EVENTS.forEach(s=>{this.element.addEventListener(s,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(s,this.dragStartListener))}),this.trackMousePosition(),ce.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragListener)),this.element.addEventListener(s,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,s,this.updateElementOffsetListener))}),ce.DRAG_END_EVENTS.forEach(s=>{document.addEventListener(s,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragEndListener))}),this.addSubscription(vt(this.element,we(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(vt(document,we(s=>this.clickDocumentSubject.next(s)),"click"));const t=ms();if(t==="apple"||t==="mobile"){let s=null;const i=a=>{a.preventDefault(),s?(this.dbTapSubject.next(this.currentPoint),clearTimeout(s),s=null):s=window.setTimeout(()=>{s=null},250)};this.addSubscription(vt(this.element,i,"touchend"));const r=(a,l=200)=>{a.preventDefault();let c=!1,h=null;h=setTimeout(()=>{c=!0,this.longTouchStartSubject.next(a)},l);const d=f=>{f.preventDefault(),f.touches.length>1&&h&&clearTimeout(h)},u=f=>{f.preventDefault(),h&&clearTimeout(h),c&&(c=!1,this.longTouchEndSubject.next(f)),this.element.removeEventListener("touchend",u),this.element.removeEventListener("touchmove",d)};this.element.addEventListener("touchmove",d),this.element.addEventListener("touchend",u)};this.addSubscription(vt(this.element,a=>r(a),"touchstart"));const o=a=>{if(a.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const h=this.touchStartTimestamp,u=Date.now()-h,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,m=u<=250;g&&m&&this.fastTouchScroll.next(a)}};this.addSubscription(vt(this.element,o,"touchend"))}this.addSubscription(vt(this.element,we(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(vt(this.element,s=>{this.touchStartSubject.next(s),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(vt(this.element,s=>this.touchMoveSubject.next(s),"touchmove",!0)),this.addSubscription(vt(this.element,s=>this.touchEndSubject.next(s),"touchend")),this.addSubscription(vt(this.element,s=>this.touchCancelSubject.next(s),"touchcancel")),this.addSubscription(vt(this.element,s=>{this.updateCurrentPoints(s),this.wheelSubject.next(s),s.preventDefault()},"wheel")),this.addSubscription(vt(this.element,s=>this.contextMenuSubject.next(s),"contextmenu")),this.addSubscription(vt(this.element,we(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(vt(this.element,we(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(vt(document,we(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(cs).subscribe(()=>{this.invalidateRectCache();const s=this.getElementRect();this.canvasBounds.x=s.left,this.canvasBounds.y=s.top,this.canvasBounds.width=s.width,this.canvasBounds.height=s.height})),this.addRxSubscription(yn(document,"scroll",{capture:!0,passive:!0}).pipe(Et(ie,is,{trailing:!0})).subscribe(()=>this.invalidateRectCache()));const e=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",e,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",e,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ce.DRAG_EVENTS.forEach(t=>{document.addEventListener(t,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(t,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(t){"pageX"in t?this.currentPointDocument.x=t.pageX:t.touches!==void 0&&(this.currentPointDocument.x=t.touches[0].pageX),"pageY"in t?this.currentPointDocument.y=t.pageY:t.touches!==void 0&&(this.currentPointDocument.y=t.touches[0].pageY)}updateCurrentMousePoint(t){const e=this.getElementRect();"clientX"in t?this.currentPoint.x=t.clientX-e.left:t.touches!==void 0&&(this.currentPoint.x=t.touches[0].clientX-e.left),"clientY"in t?this.currentPoint.y=t.clientY-e.top:t.touches!==void 0&&(this.currentPoint.y=t.touches[0].clientY-e.top)}static copyPoint(t){return{x:t.x,y:t.y}}observeMouseMove(t=()=>!0){return this.mouseMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(Z(()=>!this.dragging))}observeMouseMoveDocument(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPointDocument.x,this.currentPointDocument.y)),ct(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(t=()=>!0){return this.xDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(t=()=>!0){return this.xDragSubject.pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(t=()=>!0){return this.xDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(t=()=>!0){return this.yDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(t=()=>!0){return this.yDragSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(t=()=>!0){return this.yDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(t=()=>!0,e=!1){const s=this.mouseMoveSubject.asObservable().pipe(Z(()=>!(e&&this.dragging)),ct(()=>t(this.currentPoint.x,this.currentPoint.y))),i=this.observeMouseLeavesCanvas().pipe(ct(()=>!1));return Ct(s,i).pipe(_t())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(t=()=>!0){return this.clickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(t=()=>!0){return this.dbClickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(t=()=>!0){return this.dbTapSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeWheel(t=()=>!0){return this.wheelSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(t=()=>!0){return this.touchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(t=()=>!0){return this.touchMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(t=()=>!0){return this.mouseDownSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(t=()=>!0){return this.mouseUpSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(t=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(t=()=>!0){return this.contextMenuSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)),Ao(e=>e.preventDefault()))}observeLongTouchStart(t=()=>!0){return this.longTouchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(t=()=>!0){return this.longTouchEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(t=()=>!0){return this.fastTouchScroll.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};ws.DRAG_START_EVENTS=["mousedown","touchstart"],ws.DRAG_EVENTS=["mousemove","touchmove"],ws.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];let kp=ws;var Yp=(function(n){z(t,n);function t(e,s,i){e===void 0&&(e=1/0),s===void 0&&(s=1/0),i===void 0&&(i=Zs);var r=n.call(this)||this;return r._bufferSize=e,r._windowTime=s,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=s===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,s),r}return t.prototype.next=function(e){var s=this,i=s.isStopped,r=s._buffer,o=s._infiniteTimeWindow,a=s._timestampProvider,l=s._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),n.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var s=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),s},t.prototype._trimBuffer=function(){var e=this,s=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*s;if(s<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t})(R);const wn={};function jp(n){return wn[n]||(wn[n]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:n,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),wn[n]}const la=(n,t=Date.now())=>{const s=jp(n).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(s);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},ca=60*1e3;class Np{constructor(t){this.config=t,this.timeZoneChangedSubject=new Yp,this.currentTzOffset=e=>la(this.config.timezone,e)+new Date(e).getTimezoneOffset()*ca,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const s=t.createFormatterFunction;e=i=>s(i).bind(t)}else e=cu(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+la(t,e)+new Date(e).getTimezoneOffset()*ca):e=>new Date(e)}}class Xp extends X{constructor(t,e,s){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=s}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(_t((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}var Wp=Object.defineProperty,zp=Object.defineProperties,Vp=Object.getOwnPropertyDescriptors,ha=Object.getOwnPropertySymbols,Up=Object.prototype.hasOwnProperty,Gp=Object.prototype.propertyIsEnumerable,da=(n,t,e)=>t in n?Wp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Zp=(n,t)=>{for(var e in t||(t={}))Up.call(t,e)&&da(n,e,t[e]);if(ha)for(var e of ha(t))Gp.call(t,e)&&da(n,e,t[e]);return n},$p=(n,t)=>zp(n,Vp(t));class Kp extends ii{constructor(t){super(t),this.animations={},this.animFrameId="animation",this.animationInProgressSubject=new ut(!1),this.microtaskQueued=!1}startViewportMovementAnimation(t,e,s=ue,i){const r=new ti(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new Jn($p(Zp({},i),{duration:i&&i.duration||Ae}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ae,i){const r=new Qn({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0,delete this.animations[t]),Object.keys(this.animations).length===0&&this.stopInterval()}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.microtaskQueued||(this.microtaskQueued=!0,queueMicrotask(()=>{this.microtaskQueued=!1,this.processAnimation(),this.eventBus.fireDraw()}))}stopInterval(){Ka(this.animFrameId),this.microtaskQueued=!1}}class Sn{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var s,i;this.parentElement=t;const r=e;jl(r),this.config=r;const o=ac(r);t.innerHTML="",t.appendChild(o.content),this.id=(s=t.getAttribute("data-id"))!=null?s:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new Np(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=lc(t);this.elements=c;const h=new np;this.bus=h;const d=new rp(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new id(h,d);this.drawingManager=u;const f=sd(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=ae(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const g=new Ce(this.dynamicObjectsCanvasModel);u.addDrawer(g,"SERIES_CLEAR");const m=ae(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),x=ae(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Gs(r,h,f,l,d);this.canvasBoundsContainer=_;const A=c.mainCanvas.parentElement;if(A===null)throw new Error("Couldn't get main canvas parent");const L=new kp(h,A);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const j=[h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer],F=new xu(...j);this.hitTestCanvasModel=F;const B=new Ce(F);u.addDrawer(B,"HIT_TEST_CLEAR");const Y=Me?new Kp(h):new ii(h);this.canvasAnimation=Y;const $=T.PANE_UUID(K),W=new _r(r,()=>_.getBounds($),Y);this.scaleModel=W;const U=ae(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=U,this.cursorHandler=new ic(c.canvasArea,L,_,F),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new vp(L,_),this.chartComponents.push(this.crossEventProducer);const G=new Nc("candle");this.chartBaseModel=G;const V=new cf(h,W,_,r,Y,L,A,G,F);this.chartPanComponent=V,this.chartComponents.push(V),this.userInputListenerComponents.push(V.chartAreaPanHandler);const Q=new Xp(F,Y,h);this.hitTestComponent=Q,this.chartComponents.push(Q);const J=new zf(G,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,Y,L,u,this.cursorHandler,this.crossEventProducer,V,f,m,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=J;const et=this.paneManager.panes[K];this.mainPane=et,this.chartComponents.push(J),this.dynamicObjects=new au(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Yd(G,J,h,this.dynamicObjectsCanvasModel,r,W,l,A,_,d);const tt=new Sd(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,F,L,U,V,J,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const st=this.chartComponent.chartModel;this.chartModel=st,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),F.addSubscriber(J.hitTestController),this.xAxisComponent=new $g(h,r,f,tt,W,_,L,d,this.drawingManager,a,V,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const ht=new Ce(f);u.addDrawer(ht,"MAIN_CLEAR");const at=new ip(A,st,L,r);this.chartComponents.push(at),this.watermarkComponent=new ag(J,st,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const St=ae(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new Xu(h,r,st,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(st)),this.navigationMapComponent=new qu(h,st,f,r,L,_,u,l,V,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Ut=new Ru(r,this.dynamicObjectsCanvasModel,st,_,u);this.chartComponents.push(Ut),this.initYAxisDrawer(m,x),this.yAxisComponent=et.mainExtent.yAxis;const Se=new Qg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(Se,se.MAIN),this.volumesComponent=new eg(this.dynamicObjectsCanvasModel,tt,W,_,u,r,J,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const ma=new ho(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(T.ALL_PANES),()=>this.canvasBoundsContainer.getBounds($),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,void 0,()=>r.components.grid.visible,this.mainPane.mainExtent.idx);this.chartComponents.push(ma),this.hoverProducer=new Mp(this.crossEventProducer,W,r,st,L,this.canvasBoundsContainer,this.paneManager,a,V.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new nu(r,St,_,u,J,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel,this.chartModel),this.chartComponents.push(this.crossToolComponent);const va=ae(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),xn=new Vf(this.elements,va);this.snapshotComponent=xn,this.chartComponents.push(xn);const xs=new Lu(r,this.dynamicObjectsCanvasModel,F,st,_,u,l,this.cursorHandler);this.eventsComponent=xs,this.chartComponents.push(xs),this.chartComponents.forEach(cm=>cm.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=pl(this.components)}initYAxisDrawer(t,e){const s=new rn,i=new Ce(t),r=new Ce(e);s.addDrawer(i,"YAXIS_CLEAR"),s.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(s,"Y_AXIS");const o=new ep(this.config,t,this.paneManager);s.addDrawer(o);const a=new tp(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:s=>e.test(s)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const s in e)s in t?typeof t[s]=="object"&&Sn.mergeConfig(t[s],e[s]):t[s]=e[s];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,s,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(s=t.dash)!=null?s:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){Tt(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(s).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,s=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,s).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(s).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=Ct(this.canvasInputListener.observeYDrag(s),this.canvasInputListener.observeXDrag(s)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const s=t(this);this.components.push(s),e&&e(s),s.activate()}}class ua extends Sn{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var s;(s=this.paneManager.panes[t])==null||s.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.setAllSeries(e,s)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.updateAllSeries(e,s)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}setTreasuryFormat(t){this.config.components.yAxis.treasuryFormat=t,this.paneManager.yExtents.forEach(e=>{e.yAxis.model.labelsGenerator.updateTreasuryFormat(t),e.yAxis.model.labelsGenerator.doGenerateLabels(),e.yAxis.model.fancyLabelsModel.updateLabels(!0),e.yAxis.model.baseLabelsModel.updateLabels()})}createPane(){return this.paneManager.createPane()}}var qp=Object.defineProperty,Jp=Object.defineProperties,Qp=Object.getOwnPropertyDescriptors,fa=Object.getOwnPropertySymbols,tm=Object.prototype.hasOwnProperty,em=Object.prototype.propertyIsEnumerable,ga=(n,t,e)=>t in n?qp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sm=(n,t)=>{for(var e in t||(t={}))tm.call(t,e)&&ga(n,e,t[e]);if(fa)for(var e of fa(t))em.call(t,e)&&ga(n,e,t[e]);return n},nm=(n,t)=>Jp(n,Qp(t));function pa(n){n=n||{},n.quantity=n.quantity||200,n.startY=n.startY||50,n.avgCandleSize=n.avgCandleSize||2,n.avgTrendLength=n.avgTrendLength||{},n.avgTrendLength.sw=n.avgTrendLength.sw||10,n.avgTrendLength.down=n.avgTrendLength.down||10,n.avgTrendLength.up=n.avgTrendLength.up||10,n.withVolume=n.withVolume===!0||!1,n.period=n.period||3600;var t=[],e=n.quantity||200,s=10,i=10,r=10;n.avgTrendLength&&(s=n.avgTrendLength.sw||10,i=n.avgTrendLength.down||10,r=n.avgTrendLength.up||10);var o=n.startY||50,a=n.avgCandleSize||2,l=o-a,c=o+a,h=Ss(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(om(t[t.length-1],a,s)):d>3?t=t.concat(im(t[t.length-1],a,r)):t=t.concat(rm(t[t.length-1],a,i))}t=t.slice(0,n.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*n.period;for(let f=0;f<t.length;f++){const g=t[f];Object.assign(g,{timestamp:u,isVisible:!0}),u+=1e3*n.period,n.withVolume&&(g.volume=Math.ceil(Math.random()*1e3+200))}return t}function Ss(n,t,e,s){var i=Math.random()*(t-n)+n,r;if(s&&s==="bull"||!s&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>n?a:n}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:yi(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function im(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.lo,o=n.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),s.push(c)}return s}function rm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.hi-t*1.2,o=n.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),s.push(c)}return s}function om(n,t,e){var s=[],i=Math.random()*e+e/2;function r(u){var f,g;return Math.random()>.5?(f=u.lo-t*.2,g=u.hi+t*1.2):(f=u.lo-t*1.2,g=u.hi+t*.2),{from:f,to:g}}for(var o=r(n),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=Ss(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),s.push(d)}return s}window.DXChart=nm(sm({},window.DXChart),{generateCandlesData:pa});function am(n){return pa(n)}const lm=((n,t={})=>new ua(n,t))})(),window.DXChart=Ps})();})();