@devexperts/dxcharts-lite 2.5.0 → 2.5.2

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,21 +3,21 @@
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 Ro={168:(k,it,j)=>{const $=j(874),W={};for(const v of Object.keys($))W[$[v]]=v;const I={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=I;for(const v of Object.keys(I)){if(!("channels"in I[v]))throw new Error("missing channels property: "+v);if(!("labels"in I[v]))throw new Error("missing channel labels property: "+v);if(I[v].labels.length!==I[v].channels)throw new Error("channel and label counts mismatch: "+v);const{channels:y,labels:b}=I[v];delete I[v].channels,delete I[v].labels,Object.defineProperty(I[v],"channels",{value:y}),Object.defineProperty(I[v],"labels",{value:b})}I.rgb.hsl=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.min(y,b,w),S=Math.max(y,b,w),P=S-f;let A,p;S===f?A=0:y===S?A=(b-w)/P:b===S?A=2+(w-y)/P:w===S&&(A=4+(y-b)/P),A=Math.min(A*60,360),A<0&&(A+=360);const T=(f+S)/2;return S===f?p=0:T<=.5?p=P/(S+f):p=P/(2-S-f),[A,p*100,T*100]},I.rgb.hsv=function(v){let y,b,w,f,S;const P=v[0]/255,A=v[1]/255,p=v[2]/255,T=Math.max(P,A,p),E=T-Math.min(P,A,p),D=function(B){return(T-B)/6/E+1/2};return E===0?(f=0,S=0):(S=E/T,y=D(P),b=D(A),w=D(p),P===T?f=w-b:A===T?f=.3333333333333333+y-w:p===T&&(f=.6666666666666666+b-y),f<0?f+=1:f>1&&(f-=1)),[f*360,S*100,T*100]},I.rgb.hwb=function(v){const y=v[0],b=v[1];let w=v[2];const f=I.rgb.hsl(v)[0],S=1/255*Math.min(y,Math.min(b,w));return w=1-.00392156862745098*Math.max(y,Math.max(b,w)),[f,S*100,w*100]},I.rgb.cmyk=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.min(1-y,1-b,1-w),S=(1-y-f)/(1-f)||0,P=(1-b-f)/(1-f)||0,A=(1-w-f)/(1-f)||0;return[S*100,P*100,A*100,f*100]};function ct(v,y){return rt(v[0]-y[0],2)+rt(v[1]-y[1],2)+rt(v[2]-y[2],2)}I.rgb.keyword=function(v){const y=W[v];if(y)return y;let b=1/0,w;for(const f of Object.keys($)){const S=$[f],P=ct(v,S);P<b&&(b=P,w=f)}return w},I.keyword.rgb=function(v){return $[v]},I.rgb.xyz=function(v){let y=v[0]/255,b=v[1]/255,w=v[2]/255;y=y>.04045?rt((y+.055)/1.055,2.4):y/12.92,b=b>.04045?rt((b+.055)/1.055,2.4):b/12.92,w=w>.04045?rt((w+.055)/1.055,2.4):w/12.92;const f=y*.4124+b*.3576+w*.1805,S=y*.2126+b*.7152+w*.0722,P=y*.0193+b*.1192+w*.9505;return[f*100,S*100,P*100]},I.rgb.lab=function(v){const y=I.rgb.xyz(v);let b=y[0],w=y[1],f=y[2];b/=95.047,w/=100,f/=108.883,b=b>.008856?rt(b,.3333333333333333):7.787*b+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862,f=f>.008856?rt(f,.3333333333333333):7.787*f+.13793103448275862;const S=116*w-16,P=500*(b-w),A=200*(w-f);return[S,P,A]},I.hsl.rgb=function(v){const y=v[0]/360,b=v[1]/100,w=v[2]/100;let f,S,P;if(b===0)return P=w*255,[P,P,P];w<.5?f=w*(1+b):f=w+b-w*b;const A=2*w-f,p=[0,0,0];for(let T=0;T<3;T++)S=y+.3333333333333333*-(T-1),S<0&&S++,S>1&&S--,6*S<1?P=A+(f-A)*6*S:2*S<1?P=f:3*S<2?P=A+(f-A)*(.6666666666666666-S)*6:P=A,p[T]=P*255;return p},I.hsl.hsv=function(v){const y=v[0];let b=v[1]/100,w=v[2]/100,f=b;const S=Math.max(w,.01);w*=2,b*=w<=1?w:2-w,f*=S<=1?S:2-S;const P=(w+b)/2,A=w===0?2*f/(S+f):2*b/(w+b);return[y,A*100,P*100]},I.hsv.rgb=function(v){const y=v[0]/60,b=v[1]/100;let w=v[2]/100;const f=Math.floor(y)%6,S=y-Math.floor(y),P=255*w*(1-b),A=255*w*(1-b*S),p=255*w*(1-b*(1-S));switch(w*=255,f){case 0:return[w,p,P];case 1:return[A,w,P];case 2:return[P,w,p];case 3:return[P,A,w];case 4:return[p,P,w];case 5:return[w,P,A]}},I.hsv.hsl=function(v){const y=v[0],b=v[1]/100,w=v[2]/100,f=Math.max(w,.01);let S,P;P=(2-b)*w;const A=(2-b)*f;return S=b*f,S/=A<=1?A:2-A,S=S||0,P/=2,[y,S*100,P*100]},I.hwb.rgb=function(v){const y=v[0]/360;let b=v[1]/100,w=v[2]/100;const f=b+w;let S;f>1&&(b/=f,w/=f);const P=Math.floor(6*y),A=1-w;S=6*y-P,P&1&&(S=1-S);const p=b+S*(A-b);let T,E,D;switch(P){default:case 6:case 0:T=A,E=p,D=b;break;case 1:T=p,E=A,D=b;break;case 2:T=b,E=A,D=p;break;case 3:T=b,E=p,D=A;break;case 4:T=p,E=b,D=A;break;case 5:T=A,E=b,D=p;break}return[T*255,E*255,D*255]},I.cmyk.rgb=function(v){const y=v[0]/100,b=v[1]/100,w=v[2]/100,f=v[3]/100,S=1-Math.min(1,y*(1-f)+f),P=1-Math.min(1,b*(1-f)+f),A=1-Math.min(1,w*(1-f)+f);return[S*255,P*255,A*255]},I.xyz.rgb=function(v){const y=v[0]/100,b=v[1]/100,w=v[2]/100;let f,S,P;return f=y*3.2406+b*-1.5372+w*-.4986,S=y*-.9689+b*1.8758+w*.0415,P=y*.0557+b*-.204+w*1.057,f=f>.0031308?1.055*rt(f,.4166666666666667)-.055:f*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,f=Math.min(Math.max(0,f),1),S=Math.min(Math.max(0,S),1),P=Math.min(Math.max(0,P),1),[f*255,S*255,P*255]},I.xyz.lab=function(v){let y=v[0],b=v[1],w=v[2];y/=95.047,b/=100,w/=108.883,y=y>.008856?rt(y,.3333333333333333):7.787*y+.13793103448275862,b=b>.008856?rt(b,.3333333333333333):7.787*b+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862;const f=116*b-16,S=500*(y-b),P=200*(b-w);return[f,S,P]},I.lab.xyz=function(v){const y=v[0],b=v[1],w=v[2];let f,S,P;S=(y+16)/116,f=b/500+S,P=S-w/200;const A=rt(S,3),p=rt(f,3),T=rt(P,3);return S=A>.008856?A:(S-.13793103448275862)/7.787,f=p>.008856?p:(f-.13793103448275862)/7.787,P=T>.008856?T:(P-.13793103448275862)/7.787,f*=95.047,S*=100,P*=108.883,[f,S,P]},I.lab.lch=function(v){const y=v[0],b=v[1],w=v[2];let f;f=Math.atan2(w,b)*360/2/Math.PI,f<0&&(f+=360);const P=Math.sqrt(b*b+w*w);return[y,P,f]},I.lch.lab=function(v){const y=v[0],b=v[1],f=v[2]/360*2*Math.PI,S=b*Math.cos(f),P=b*Math.sin(f);return[y,S,P]},I.rgb.ansi16=function(v,y=null){const[b,w,f]=v;let S=y===null?I.rgb.hsv(v)[2]:y;if(S=Math.round(S/50),S===0)return 30;let P=30+(Math.round(f/255)<<2|Math.round(w/255)<<1|Math.round(b/255));return S===2&&(P+=60),P},I.hsv.ansi16=function(v){return I.rgb.ansi16(I.hsv.rgb(v),v[2])},I.rgb.ansi256=function(v){const y=v[0],b=v[1],w=v[2];return y===b&&b===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(b/255*5)+Math.round(w/255*5)},I.ansi16.rgb=function(v){let y=v%10;if(y===0||y===7)return v>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const b=(~~(v>50)+1)*.5,w=(y&1)*b*255,f=(y>>1&1)*b*255,S=(y>>2&1)*b*255;return[w,f,S]},I.ansi256.rgb=function(v){if(v>=232){const S=(v-232)*10+8;return[S,S,S]}v-=16;let y;const b=Math.floor(v/36)/5*255,w=Math.floor((y=v%36)/6)/5*255,f=y%6/5*255;return[b,w,f]},I.rgb.hex=function(v){const b=(((Math.round(v[0])&255)<<16)+((Math.round(v[1])&255)<<8)+(Math.round(v[2])&255)).toString(16).toUpperCase();return"000000".substring(b.length)+b},I.hex.rgb=function(v){const y=v.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let b=y[0];y[0].length===3&&(b=b.split("").map(A=>A+A).join(""));const w=parseInt(b,16),f=w>>16&255,S=w>>8&255,P=w&255;return[f,S,P]},I.rgb.hcg=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.max(Math.max(y,b),w),S=Math.min(Math.min(y,b),w),P=f-S;let A,p;return P<1?A=S/(1-P):A=0,P<=0?p=0:f===y?p=(b-w)/P%6:f===b?p=2+(w-y)/P:p=4+(y-b)/P,p/=6,p%=1,[p*360,P*100,A*100]},I.hsl.hcg=function(v){const y=v[1]/100,b=v[2]/100,w=b<.5?2*y*b:2*y*(1-b);let f=0;return w<1&&(f=(b-.5*w)/(1-w)),[v[0],w*100,f*100]},I.hsv.hcg=function(v){const y=v[1]/100,b=v[2]/100,w=y*b;let f=0;return w<1&&(f=(b-w)/(1-w)),[v[0],w*100,f*100]},I.hcg.rgb=function(v){const y=v[0]/360,b=v[1]/100,w=v[2]/100;if(b===0)return[w*255,w*255,w*255];const f=[0,0,0],S=y%1*6,P=S%1,A=1-P;let p=0;switch(Math.floor(S)){case 0:f[0]=1,f[1]=P,f[2]=0;break;case 1:f[0]=A,f[1]=1,f[2]=0;break;case 2:f[0]=0,f[1]=1,f[2]=P;break;case 3:f[0]=0,f[1]=A,f[2]=1;break;case 4:f[0]=P,f[1]=0,f[2]=1;break;default:f[0]=1,f[1]=0,f[2]=A}return p=(1-b)*w,[(b*f[0]+p)*255,(b*f[1]+p)*255,(b*f[2]+p)*255]},I.hcg.hsv=function(v){const y=v[1]/100,b=v[2]/100,w=y+b*(1-y);let f=0;return w>0&&(f=y/w),[v[0],f*100,w*100]},I.hcg.hsl=function(v){const y=v[1]/100,w=v[2]/100*(1-y)+.5*y;let f=0;return w>0&&w<.5?f=y/(2*w):w>=.5&&w<1&&(f=y/(2*(1-w))),[v[0],f*100,w*100]},I.hcg.hwb=function(v){const y=v[1]/100,b=v[2]/100,w=y+b*(1-y);return[v[0],(w-y)*100,(1-w)*100]},I.hwb.hcg=function(v){const y=v[1]/100,w=1-v[2]/100,f=w-y;let S=0;return f<1&&(S=(w-f)/(1-f)),[v[0],f*100,S*100]},I.apple.rgb=function(v){return[v[0]/65535*255,v[1]/65535*255,v[2]/65535*255]},I.rgb.apple=function(v){return[v[0]/255*65535,v[1]/255*65535,v[2]/255*65535]},I.gray.rgb=function(v){return[v[0]/100*255,v[0]/100*255,v[0]/100*255]},I.gray.hsl=function(v){return[0,0,v[0]]},I.gray.hsv=I.gray.hsl,I.gray.hwb=function(v){return[0,100,v[0]]},I.gray.cmyk=function(v){return[0,0,0,v[0]]},I.gray.lab=function(v){return[v[0],0,0]},I.gray.hex=function(v){const y=Math.round(v[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},I.rgb.gray=function(v){return[(v[0]+v[1]+v[2])/3/255*100]}},85:(k,it,j)=>{const $=j(168),W=j(111),I={},ct=Object.keys($);function v(b){const w=function(...f){const S=f[0];return S==null?S:(S.length>1&&(f=S),b(f))};return"conversion"in b&&(w.conversion=b.conversion),w}function y(b){const w=function(...f){const S=f[0];if(S==null)return S;S.length>1&&(f=S);const P=b(f);if(typeof P=="object")for(let A=P.length,p=0;p<A;p++)P[p]=Math.round(P[p]);return P};return"conversion"in b&&(w.conversion=b.conversion),w}ct.forEach(b=>{I[b]={},Object.defineProperty(I[b],"channels",{value:$[b].channels}),Object.defineProperty(I[b],"labels",{value:$[b].labels});const w=W(b);Object.keys(w).forEach(S=>{const P=w[S];I[b][S]=y(P),I[b][S].raw=v(P)})}),k.exports=I},111:(k,it,j)=>{const $=j(168);function W(){const y={},b=Object.keys($);for(let w=b.length,f=0;f<w;f++)y[b[f]]={distance:-1,parent:null};return y}function I(y){const b=W(),w=[y];for(b[y].distance=0;w.length;){const f=w.pop(),S=Object.keys($[f]);for(let P=S.length,A=0;A<P;A++){const p=S[A],T=b[p];T.distance===-1&&(T.distance=b[f].distance+1,T.parent=f,w.unshift(p))}}return b}function ct(y,b){return function(w){return b(y(w))}}function v(y,b){const w=[b[y].parent,y];let f=$[b[y].parent][y],S=b[y].parent;for(;b[S].parent;)w.unshift(b[S].parent),f=ct($[b[S].parent][S],f),S=b[S].parent;return f.conversion=w,f}k.exports=function(y){const b=I(y),w={},f=Object.keys(b);for(let S=f.length,P=0;P<S;P++){const A=f[P];b[A].parent!==null&&(w[A]=v(A,b))}return w}},874: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]}},818:(k,it,j)=>{var $=j(874),W=j(851),I=Object.hasOwnProperty,ct=Object.create(null);for(var v in $)I.call($,v)&&(ct[$[v]]=v);var y=k.exports={to:{},get:{}};y.get=function(f){var S=f.substring(0,3).toLowerCase(),P,A;switch(S){case"hsl":P=y.get.hsl(f),A="hsl";break;case"hwb":P=y.get.hwb(f),A="hwb";break;default:P=y.get.rgb(f),A="rgb";break}return P?{model:A,value:P}:null},y.get.rgb=function(f){if(!f)return null;var S=/^#([a-f0-9]{3,4})$/i,P=/^#([a-f0-9]{6})([a-f0-9]{2})?$/i,A=/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,p=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,T=/^(\w+)$/,E=[0,0,0,1],D,B,lt;if(D=f.match(P)){for(lt=D[2],D=D[1],B=0;B<3;B++){var Dt=B*2;E[B]=parseInt(D.slice(Dt,Dt+2),16)}lt&&(E[3]=parseInt(lt,16)/255)}else if(D=f.match(S)){for(D=D[1],lt=D[3],B=0;B<3;B++)E[B]=parseInt(D[B]+D[B],16);lt&&(E[3]=parseInt(lt+lt,16)/255)}else if(D=f.match(A)){for(B=0;B<3;B++)E[B]=parseInt(D[B+1],0);D[4]&&(D[5]?E[3]=parseFloat(D[4])*.01:E[3]=parseFloat(D[4]))}else if(D=f.match(p)){for(B=0;B<3;B++)E[B]=Math.round(parseFloat(D[B+1])*2.55);D[4]&&(D[5]?E[3]=parseFloat(D[4])*.01:E[3]=parseFloat(D[4]))}else return(D=f.match(T))?D[1]==="transparent"?[0,0,0,0]:I.call($,D[1])?(E=$[D[1]],E[3]=1,E):null:null;for(B=0;B<3;B++)E[B]=b(E[B],0,255);return E[3]=b(E[3],0,1),E},y.get.hsl=function(f){if(!f)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=f.match(S);if(P){var A=parseFloat(P[4]),p=(parseFloat(P[1])%360+360)%360,T=b(parseFloat(P[2]),0,100),E=b(parseFloat(P[3]),0,100),D=b(isNaN(A)?1:A,0,1);return[p,T,E,D]}return null},y.get.hwb=function(f){if(!f)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=f.match(S);if(P){var A=parseFloat(P[4]),p=(parseFloat(P[1])%360+360)%360,T=b(parseFloat(P[2]),0,100),E=b(parseFloat(P[3]),0,100),D=b(isNaN(A)?1:A,0,1);return[p,T,E,D]}return null},y.to.hex=function(){var f=W(arguments);return"#"+w(f[0])+w(f[1])+w(f[2])+(f[3]<1?w(Math.round(f[3]*255)):"")},y.to.rgb=function(){var f=W(arguments);return f.length<4||f[3]===1?"rgb("+Math.round(f[0])+", "+Math.round(f[1])+", "+Math.round(f[2])+")":"rgba("+Math.round(f[0])+", "+Math.round(f[1])+", "+Math.round(f[2])+", "+f[3]+")"},y.to.rgb.percent=function(){var f=W(arguments),S=Math.round(f[0]/255*100),P=Math.round(f[1]/255*100),A=Math.round(f[2]/255*100);return f.length<4||f[3]===1?"rgb("+S+"%, "+P+"%, "+A+"%)":"rgba("+S+"%, "+P+"%, "+A+"%, "+f[3]+")"},y.to.hsl=function(){var f=W(arguments);return f.length<4||f[3]===1?"hsl("+f[0]+", "+f[1]+"%, "+f[2]+"%)":"hsla("+f[0]+", "+f[1]+"%, "+f[2]+"%, "+f[3]+")"},y.to.hwb=function(){var f=W(arguments),S="";return f.length>=4&&f[3]!==1&&(S=", "+f[3]),"hwb("+f[0]+", "+f[1]+"%, "+f[2]+"%"+S+")"},y.to.keyword=function(f){return ct[f.slice(0,3)]};function b(f,S,P){return Math.min(Math.max(S,f),P)}function w(f){var S=Math.round(f).toString(16).toUpperCase();return S.length<2?"0"+S:S}},767:(k,it,j)=>{const $=j(818),W=j(85),I=["keyword","gray","hex"],ct={};for(const p of Object.keys(W))ct[[...W[p].labels].sort().join("")]=p;const v={};function y(p,T){if(!(this instanceof y))return new y(p,T);if(T&&T in I&&(T=null),T&&!(T in W))throw new Error("Unknown model: "+T);let E,D;if(p==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(p instanceof y)this.model=p.model,this.color=[...p.color],this.valpha=p.valpha;else if(typeof p=="string"){const B=$.get(p);if(B===null)throw new Error("Unable to parse color from string: "+p);this.model=B.model,D=W[this.model].channels,this.color=B.value.slice(0,D),this.valpha=typeof B.value[D]=="number"?B.value[D]:1}else if(p.length>0){this.model=T||"rgb",D=W[this.model].channels;const B=Array.prototype.slice.call(p,0,D);this.color=A(B,D),this.valpha=typeof p[D]=="number"?p[D]:1}else if(typeof p=="number")this.model="rgb",this.color=[p>>16&255,p>>8&255,p&255],this.valpha=1;else{this.valpha=1;const B=Object.keys(p);"alpha"in p&&(B.splice(B.indexOf("alpha"),1),this.valpha=typeof p.alpha=="number"?p.alpha:0);const lt=B.sort().join("");if(!(lt in ct))throw new Error("Unable to parse color from object: "+JSON.stringify(p));this.model=ct[lt];const{labels:Dt}=W[this.model],Rt=[];for(E=0;E<Dt.length;E++)Rt.push(p[Dt[E]]);this.color=A(Rt)}if(v[this.model])for(D=W[this.model].channels,E=0;E<D;E++){const B=v[this.model][E];B&&(this.color[E]=B(this.color[E]))}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(p){let T=this.model in $.to?this:this.rgb();T=T.round(typeof p=="number"?p:1);const E=T.valpha===1?T.color:[...T.color,this.valpha];return $.to[T.model](E)},percentString(p){const T=this.rgb().round(typeof p=="number"?p:1),E=T.valpha===1?T.color:[...T.color,this.valpha];return $.to.rgb.percent(E)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const p={},{channels:T}=W[this.model],{labels:E}=W[this.model];for(let D=0;D<T;D++)p[E[D]]=this.color[D];return this.valpha!==1&&(p.alpha=this.valpha),p},unitArray(){const p=this.rgb().color;return p[0]/=255,p[1]/=255,p[2]/=255,this.valpha!==1&&p.push(this.valpha),p},unitObject(){const p=this.rgb().object();return p.r/=255,p.g/=255,p.b/=255,this.valpha!==1&&(p.alpha=this.valpha),p},round(p){return p=Math.max(p||0,0),new y([...this.color.map(w(p)),this.valpha],this.model)},alpha(p){return p!==void 0?new y([...this.color,Math.max(0,Math.min(1,p))],this.model):this.valpha},red:f("rgb",0,S(255)),green:f("rgb",1,S(255)),blue:f("rgb",2,S(255)),hue:f(["hsl","hsv","hsl","hwb","hcg"],0,p=>(p%360+360)%360),saturationl:f("hsl",1,S(100)),lightness:f("hsl",2,S(100)),saturationv:f("hsv",1,S(100)),value:f("hsv",2,S(100)),chroma:f("hcg",1,S(100)),gray:f("hcg",2,S(100)),white:f("hwb",1,S(100)),wblack:f("hwb",2,S(100)),cyan:f("cmyk",0,S(100)),magenta:f("cmyk",1,S(100)),yellow:f("cmyk",2,S(100)),black:f("cmyk",3,S(100)),x:f("xyz",0,S(95.047)),y:f("xyz",1,S(100)),z:f("xyz",2,S(108.833)),l:f("lab",0,S(100)),a:f("lab",1),b:f("lab",2),keyword(p){return p!==void 0?new y(p):W[this.model].keyword(this.color)},hex(p){return p!==void 0?new y(p):$.to.hex(this.rgb().round().color)},hexa(p){if(p!==void 0)return new y(p);const T=this.rgb().round().color;let E=Math.round(this.valpha*255).toString(16).toUpperCase();return E.length===1&&(E="0"+E),$.to.hex(T)+E},rgbNumber(){const p=this.rgb().color;return(p[0]&255)<<16|(p[1]&255)<<8|p[2]&255},luminosity(){const p=this.rgb().color,T=[];for(const[E,D]of p.entries()){const B=D/255;T[E]=B<=.04045?B/12.92:rt((B+.055)/1.055,2.4)}return .2126*T[0]+.7152*T[1]+.0722*T[2]},contrast(p){const T=this.luminosity(),E=p.luminosity();return T>E?(T+.05)/(E+.05):(E+.05)/(T+.05)},level(p){const T=this.contrast(p);return T>=7?"AAA":T>=4.5?"AA":""},isDark(){const p=this.rgb().color;return(p[0]*2126+p[1]*7152+p[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const p=this.rgb();for(let T=0;T<3;T++)p.color[T]=255-p.color[T];return p},lighten(p){const T=this.hsl();return T.color[2]+=T.color[2]*p,T},darken(p){const T=this.hsl();return T.color[2]-=T.color[2]*p,T},saturate(p){const T=this.hsl();return T.color[1]+=T.color[1]*p,T},desaturate(p){const T=this.hsl();return T.color[1]-=T.color[1]*p,T},whiten(p){const T=this.hwb();return T.color[1]+=T.color[1]*p,T},blacken(p){const T=this.hwb();return T.color[2]+=T.color[2]*p,T},grayscale(){const p=this.rgb().color,T=p[0]*.3+p[1]*.59+p[2]*.11;return y.rgb(T,T,T)},fade(p){return this.alpha(this.valpha-this.valpha*p)},opaquer(p){return this.alpha(this.valpha+this.valpha*p)},rotate(p){const T=this.hsl();let E=T.color[0];return E=(E+p)%360,E=E<0?360+E:E,T.color[0]=E,T},mix(p,T){if(!p||!p.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof p);const E=p.rgb(),D=this.rgb(),B=T===void 0?.5:T,lt=2*B-1,Dt=E.alpha()-D.alpha(),Rt=((lt*Dt===-1?lt:(lt+Dt)/(1+lt*Dt))+1)/2,Te=1-Rt;return y.rgb(Rt*E.red()+Te*D.red(),Rt*E.green()+Te*D.green(),Rt*E.blue()+Te*D.blue(),E.alpha()*B+D.alpha()*(1-B))}};for(const p of Object.keys(W)){if(I.includes(p))continue;const{channels:T}=W[p];y.prototype[p]=function(...E){return this.model===p?new y(this):E.length>0?new y(E,p):new y([...P(W[this.model][p].raw(this.color)),this.valpha],p)},y[p]=function(...E){let D=E[0];return typeof D=="number"&&(D=A(E,T)),new y(D,p)}}function b(p,T){return Number(p.toFixed(T))}function w(p){return function(T){return b(T,p)}}function f(p,T,E){p=Array.isArray(p)?p:[p];for(const D of p)(v[D]||(v[D]=[]))[T]=E;return p=p[0],function(D){let B;return D!==void 0?(E&&(D=E(D)),B=this[p](),B.color[T]=D,B):(B=this[p]().color[T],E&&(B=E(B)),B)}}function S(p){return function(T){return Math.max(0,Math.min(p,T))}}function P(p){return Array.isArray(p)?p:[p]}function A(p,T){for(let E=0;E<T;E++)typeof p[E]!="number"&&(p[E]=0);return p}k.exports=y},171:k=>{k.exports=function(j){return!j||typeof j=="string"?!1:j instanceof Array||Array.isArray(j)||j.length>=0&&(j.splice instanceof Function||Object.getOwnPropertyDescriptor(j,j.length-1)&&j.constructor.name!=="String")}},851:(k,it,j)=>{"use strict";var $=j(171),W=Array.prototype.concat,I=Array.prototype.slice,ct=k.exports=function(y){for(var b=[],w=0,f=y.length;w<f;w++){var S=y[w];$(S)?b=W.call(b,I.call(S)):b.push(S)}return b};ct.wrap=function(v){return function(){return v(ct(arguments))}}}},dn={};function St(k){var it=dn[k];if(it!==void 0)return it.exports;var j=dn[k]={exports:{}};return Ro[k](j,j.exports,St),j.exports}St.n=k=>{var it=k&&k.__esModule?()=>k.default:()=>k;return St.d(it,{a:it}),it},St.d=(k,it)=>{for(var j in it)St.o(it,j)&&!St.o(k,j)&&Object.defineProperty(k,j,{enumerable:!0,get:it[j]})},St.o=(k,it)=>Object.prototype.hasOwnProperty.call(k,it),St.r=k=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(k,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(k,"__esModule",{value:!0})};var hs={};(()=>{"use strict";St.r(hs),St.d(hs,{Chart:()=>Io,createChart:()=>Sf,generateCandlesData:()=>wf});function k(s){return typeof s=="function"}function it(s){return k(s==null?void 0:s.lift)}function j(s){return function(t){if(it(t))return t.lift(function(e){try{return s(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}var $=function(s,t){return $=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])},$(s,t)};function W(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");$(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var I=function(){return I=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},I.apply(this,arguments)};function ct(s,t){var e={};for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&t.indexOf(n)<0&&(e[n]=s[n]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(s);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(s,n[i])&&(e[n[i]]=s[n[i]]);return e}function v(s,t,e,n){var i=arguments.length,r=i<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,n);else for(var a=s.length-1;a>=0;a--)(o=s[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(s,t){return function(e,n){t(e,n,s)}}function b(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}function w(s,t,e,n){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(n.next(h))}catch(d){o(d)}}function l(h){try{c(n.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):i(h.value).then(a,l)}c((n=n.apply(s,t||[])).next())})}function f(s,t){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,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(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(n=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(s,e)}catch(h){c=[6,h],i=0}finally{n=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var S=Object.create?function(s,t,e,n){n===void 0&&(n=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(s,n,i)}:function(s,t,e,n){n===void 0&&(n=e),s[n]=t[e]};function P(s,t){for(var e in s)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&S(t,s,e)}function A(s){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&s[t],n=0;if(e)return e.call(s);if(s&&typeof s.length=="number")return{next:function(){return s&&n>=s.length&&(s=void 0),{value:s&&s[n++],done:!s}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function p(s,t){var e=typeof Symbol=="function"&&s[Symbol.iterator];if(!e)return s;var n=e.call(s),i,r=[],o;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)r.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(o)throw o.error}}return r}function T(){for(var s=[],t=0;t<arguments.length;t++)s=s.concat(p(arguments[t]));return s}function E(){for(var s=0,t=0,e=arguments.length;t<e;t++)s+=arguments[t].length;for(var n=Array(s),i=0,t=0;t<e;t++)for(var r=arguments[t],o=0,a=r.length;o<a;o++,i++)n[i]=r[o];return n}function D(s,t,e){if(e||arguments.length===2)for(var n=0,i=t.length,r;n<i;n++)(r||!(n in t))&&(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return s.concat(r||Array.prototype.slice.call(t))}function B(s){return this instanceof B?(this.v=s,this):new B(s)}function lt(s,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(s,t||[]),i,r=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(u){n[u]&&(i[u]=function(g){return new Promise(function(m,C){r.push([u,g,m,C])>1||a(u,g)})})}function a(u,g){try{l(n[u](g))}catch(m){d(r[0][3],m)}}function l(u){u.value instanceof B?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,g){u(g),r.shift(),r.length&&a(r[0][0],r[0][1])}}function Dt(s){var t,e;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,r){t[i]=s[i]?function(o){return(e=!e)?{value:B(s[i](o)),done:i==="return"}:r?r(o):o}:r}}function Rt(s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=s[Symbol.asyncIterator],e;return t?t.call(s):(s=typeof A=="function"?A(s):s[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=s[r]&&function(o){return new Promise(function(a,l){o=s[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 Te(s,t){return Object.defineProperty?Object.defineProperty(s,"raw",{value:t}):s.raw=t,s}var Fo=Object.create?function(s,t){Object.defineProperty(s,"default",{enumerable:!0,value:t})}:function(s,t){s.default=t};function xf(s){if(s&&s.__esModule)return s;var t={};if(s!=null)for(var e in s)e!=="default"&&Object.prototype.hasOwnProperty.call(s,e)&&S(t,s,e);return Fo(t,s),t}function _f(s){return s&&s.__esModule?s:{default:s}}function Pf(s,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?s!==t||!n:!t.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(s):n?n.value:t.get(s)}function Tf(s,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?s!==t||!i:!t.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(s,e):i?i.value=e:t.set(s,e),e}function Mf(s,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof s=="function"?t===s:s.has(t)}function un(s){var t=function(n){Error.call(n),n.stack=new Error().stack},e=s(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var ds=un(function(s){return function(e){s(this),this.message=e?e.length+` errors occurred during unsubscription:
6
+ (()=>{var rt=Math.pow;(()=>{var Oo={168:(k,it,j)=>{const $=j(874),W={};for(const v of Object.keys($))W[$[v]]=v;const I={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=I;for(const v of Object.keys(I)){if(!("channels"in I[v]))throw new Error("missing channels property: "+v);if(!("labels"in I[v]))throw new Error("missing channel labels property: "+v);if(I[v].labels.length!==I[v].channels)throw new Error("channel and label counts mismatch: "+v);const{channels:y,labels:b}=I[v];delete I[v].channels,delete I[v].labels,Object.defineProperty(I[v],"channels",{value:y}),Object.defineProperty(I[v],"labels",{value:b})}I.rgb.hsl=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.min(y,b,w),S=Math.max(y,b,w),P=S-f;let A,p;S===f?A=0:y===S?A=(b-w)/P:b===S?A=2+(w-y)/P:w===S&&(A=4+(y-b)/P),A=Math.min(A*60,360),A<0&&(A+=360);const T=(f+S)/2;return S===f?p=0:T<=.5?p=P/(S+f):p=P/(2-S-f),[A,p*100,T*100]},I.rgb.hsv=function(v){let y,b,w,f,S;const P=v[0]/255,A=v[1]/255,p=v[2]/255,T=Math.max(P,A,p),E=T-Math.min(P,A,p),D=function(B){return(T-B)/6/E+1/2};return E===0?(f=0,S=0):(S=E/T,y=D(P),b=D(A),w=D(p),P===T?f=w-b:A===T?f=.3333333333333333+y-w:p===T&&(f=.6666666666666666+b-y),f<0?f+=1:f>1&&(f-=1)),[f*360,S*100,T*100]},I.rgb.hwb=function(v){const y=v[0],b=v[1];let w=v[2];const f=I.rgb.hsl(v)[0],S=1/255*Math.min(y,Math.min(b,w));return w=1-.00392156862745098*Math.max(y,Math.max(b,w)),[f,S*100,w*100]},I.rgb.cmyk=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.min(1-y,1-b,1-w),S=(1-y-f)/(1-f)||0,P=(1-b-f)/(1-f)||0,A=(1-w-f)/(1-f)||0;return[S*100,P*100,A*100,f*100]};function ct(v,y){return rt(v[0]-y[0],2)+rt(v[1]-y[1],2)+rt(v[2]-y[2],2)}I.rgb.keyword=function(v){const y=W[v];if(y)return y;let b=1/0,w;for(const f of Object.keys($)){const S=$[f],P=ct(v,S);P<b&&(b=P,w=f)}return w},I.keyword.rgb=function(v){return $[v]},I.rgb.xyz=function(v){let y=v[0]/255,b=v[1]/255,w=v[2]/255;y=y>.04045?rt((y+.055)/1.055,2.4):y/12.92,b=b>.04045?rt((b+.055)/1.055,2.4):b/12.92,w=w>.04045?rt((w+.055)/1.055,2.4):w/12.92;const f=y*.4124+b*.3576+w*.1805,S=y*.2126+b*.7152+w*.0722,P=y*.0193+b*.1192+w*.9505;return[f*100,S*100,P*100]},I.rgb.lab=function(v){const y=I.rgb.xyz(v);let b=y[0],w=y[1],f=y[2];b/=95.047,w/=100,f/=108.883,b=b>.008856?rt(b,.3333333333333333):7.787*b+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862,f=f>.008856?rt(f,.3333333333333333):7.787*f+.13793103448275862;const S=116*w-16,P=500*(b-w),A=200*(w-f);return[S,P,A]},I.hsl.rgb=function(v){const y=v[0]/360,b=v[1]/100,w=v[2]/100;let f,S,P;if(b===0)return P=w*255,[P,P,P];w<.5?f=w*(1+b):f=w+b-w*b;const A=2*w-f,p=[0,0,0];for(let T=0;T<3;T++)S=y+.3333333333333333*-(T-1),S<0&&S++,S>1&&S--,6*S<1?P=A+(f-A)*6*S:2*S<1?P=f:3*S<2?P=A+(f-A)*(.6666666666666666-S)*6:P=A,p[T]=P*255;return p},I.hsl.hsv=function(v){const y=v[0];let b=v[1]/100,w=v[2]/100,f=b;const S=Math.max(w,.01);w*=2,b*=w<=1?w:2-w,f*=S<=1?S:2-S;const P=(w+b)/2,A=w===0?2*f/(S+f):2*b/(w+b);return[y,A*100,P*100]},I.hsv.rgb=function(v){const y=v[0]/60,b=v[1]/100;let w=v[2]/100;const f=Math.floor(y)%6,S=y-Math.floor(y),P=255*w*(1-b),A=255*w*(1-b*S),p=255*w*(1-b*(1-S));switch(w*=255,f){case 0:return[w,p,P];case 1:return[A,w,P];case 2:return[P,w,p];case 3:return[P,A,w];case 4:return[p,P,w];case 5:return[w,P,A]}},I.hsv.hsl=function(v){const y=v[0],b=v[1]/100,w=v[2]/100,f=Math.max(w,.01);let S,P;P=(2-b)*w;const A=(2-b)*f;return S=b*f,S/=A<=1?A:2-A,S=S||0,P/=2,[y,S*100,P*100]},I.hwb.rgb=function(v){const y=v[0]/360;let b=v[1]/100,w=v[2]/100;const f=b+w;let S;f>1&&(b/=f,w/=f);const P=Math.floor(6*y),A=1-w;S=6*y-P,P&1&&(S=1-S);const p=b+S*(A-b);let T,E,D;switch(P){default:case 6:case 0:T=A,E=p,D=b;break;case 1:T=p,E=A,D=b;break;case 2:T=b,E=A,D=p;break;case 3:T=b,E=p,D=A;break;case 4:T=p,E=b,D=A;break;case 5:T=A,E=b,D=p;break}return[T*255,E*255,D*255]},I.cmyk.rgb=function(v){const y=v[0]/100,b=v[1]/100,w=v[2]/100,f=v[3]/100,S=1-Math.min(1,y*(1-f)+f),P=1-Math.min(1,b*(1-f)+f),A=1-Math.min(1,w*(1-f)+f);return[S*255,P*255,A*255]},I.xyz.rgb=function(v){const y=v[0]/100,b=v[1]/100,w=v[2]/100;let f,S,P;return f=y*3.2406+b*-1.5372+w*-.4986,S=y*-.9689+b*1.8758+w*.0415,P=y*.0557+b*-.204+w*1.057,f=f>.0031308?1.055*rt(f,.4166666666666667)-.055:f*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,f=Math.min(Math.max(0,f),1),S=Math.min(Math.max(0,S),1),P=Math.min(Math.max(0,P),1),[f*255,S*255,P*255]},I.xyz.lab=function(v){let y=v[0],b=v[1],w=v[2];y/=95.047,b/=100,w/=108.883,y=y>.008856?rt(y,.3333333333333333):7.787*y+.13793103448275862,b=b>.008856?rt(b,.3333333333333333):7.787*b+.13793103448275862,w=w>.008856?rt(w,.3333333333333333):7.787*w+.13793103448275862;const f=116*b-16,S=500*(y-b),P=200*(b-w);return[f,S,P]},I.lab.xyz=function(v){const y=v[0],b=v[1],w=v[2];let f,S,P;S=(y+16)/116,f=b/500+S,P=S-w/200;const A=rt(S,3),p=rt(f,3),T=rt(P,3);return S=A>.008856?A:(S-.13793103448275862)/7.787,f=p>.008856?p:(f-.13793103448275862)/7.787,P=T>.008856?T:(P-.13793103448275862)/7.787,f*=95.047,S*=100,P*=108.883,[f,S,P]},I.lab.lch=function(v){const y=v[0],b=v[1],w=v[2];let f;f=Math.atan2(w,b)*360/2/Math.PI,f<0&&(f+=360);const P=Math.sqrt(b*b+w*w);return[y,P,f]},I.lch.lab=function(v){const y=v[0],b=v[1],f=v[2]/360*2*Math.PI,S=b*Math.cos(f),P=b*Math.sin(f);return[y,S,P]},I.rgb.ansi16=function(v,y=null){const[b,w,f]=v;let S=y===null?I.rgb.hsv(v)[2]:y;if(S=Math.round(S/50),S===0)return 30;let P=30+(Math.round(f/255)<<2|Math.round(w/255)<<1|Math.round(b/255));return S===2&&(P+=60),P},I.hsv.ansi16=function(v){return I.rgb.ansi16(I.hsv.rgb(v),v[2])},I.rgb.ansi256=function(v){const y=v[0],b=v[1],w=v[2];return y===b&&b===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(b/255*5)+Math.round(w/255*5)},I.ansi16.rgb=function(v){let y=v%10;if(y===0||y===7)return v>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const b=(~~(v>50)+1)*.5,w=(y&1)*b*255,f=(y>>1&1)*b*255,S=(y>>2&1)*b*255;return[w,f,S]},I.ansi256.rgb=function(v){if(v>=232){const S=(v-232)*10+8;return[S,S,S]}v-=16;let y;const b=Math.floor(v/36)/5*255,w=Math.floor((y=v%36)/6)/5*255,f=y%6/5*255;return[b,w,f]},I.rgb.hex=function(v){const b=(((Math.round(v[0])&255)<<16)+((Math.round(v[1])&255)<<8)+(Math.round(v[2])&255)).toString(16).toUpperCase();return"000000".substring(b.length)+b},I.hex.rgb=function(v){const y=v.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let b=y[0];y[0].length===3&&(b=b.split("").map(A=>A+A).join(""));const w=parseInt(b,16),f=w>>16&255,S=w>>8&255,P=w&255;return[f,S,P]},I.rgb.hcg=function(v){const y=v[0]/255,b=v[1]/255,w=v[2]/255,f=Math.max(Math.max(y,b),w),S=Math.min(Math.min(y,b),w),P=f-S;let A,p;return P<1?A=S/(1-P):A=0,P<=0?p=0:f===y?p=(b-w)/P%6:f===b?p=2+(w-y)/P:p=4+(y-b)/P,p/=6,p%=1,[p*360,P*100,A*100]},I.hsl.hcg=function(v){const y=v[1]/100,b=v[2]/100,w=b<.5?2*y*b:2*y*(1-b);let f=0;return w<1&&(f=(b-.5*w)/(1-w)),[v[0],w*100,f*100]},I.hsv.hcg=function(v){const y=v[1]/100,b=v[2]/100,w=y*b;let f=0;return w<1&&(f=(b-w)/(1-w)),[v[0],w*100,f*100]},I.hcg.rgb=function(v){const y=v[0]/360,b=v[1]/100,w=v[2]/100;if(b===0)return[w*255,w*255,w*255];const f=[0,0,0],S=y%1*6,P=S%1,A=1-P;let p=0;switch(Math.floor(S)){case 0:f[0]=1,f[1]=P,f[2]=0;break;case 1:f[0]=A,f[1]=1,f[2]=0;break;case 2:f[0]=0,f[1]=1,f[2]=P;break;case 3:f[0]=0,f[1]=A,f[2]=1;break;case 4:f[0]=P,f[1]=0,f[2]=1;break;default:f[0]=1,f[1]=0,f[2]=A}return p=(1-b)*w,[(b*f[0]+p)*255,(b*f[1]+p)*255,(b*f[2]+p)*255]},I.hcg.hsv=function(v){const y=v[1]/100,b=v[2]/100,w=y+b*(1-y);let f=0;return w>0&&(f=y/w),[v[0],f*100,w*100]},I.hcg.hsl=function(v){const y=v[1]/100,w=v[2]/100*(1-y)+.5*y;let f=0;return w>0&&w<.5?f=y/(2*w):w>=.5&&w<1&&(f=y/(2*(1-w))),[v[0],f*100,w*100]},I.hcg.hwb=function(v){const y=v[1]/100,b=v[2]/100,w=y+b*(1-y);return[v[0],(w-y)*100,(1-w)*100]},I.hwb.hcg=function(v){const y=v[1]/100,w=1-v[2]/100,f=w-y;let S=0;return f<1&&(S=(w-f)/(1-f)),[v[0],f*100,S*100]},I.apple.rgb=function(v){return[v[0]/65535*255,v[1]/65535*255,v[2]/65535*255]},I.rgb.apple=function(v){return[v[0]/255*65535,v[1]/255*65535,v[2]/255*65535]},I.gray.rgb=function(v){return[v[0]/100*255,v[0]/100*255,v[0]/100*255]},I.gray.hsl=function(v){return[0,0,v[0]]},I.gray.hsv=I.gray.hsl,I.gray.hwb=function(v){return[0,100,v[0]]},I.gray.cmyk=function(v){return[0,0,0,v[0]]},I.gray.lab=function(v){return[v[0],0,0]},I.gray.hex=function(v){const y=Math.round(v[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},I.rgb.gray=function(v){return[(v[0]+v[1]+v[2])/3/255*100]}},85:(k,it,j)=>{const $=j(168),W=j(111),I={},ct=Object.keys($);function v(b){const w=function(...f){const S=f[0];return S==null?S:(S.length>1&&(f=S),b(f))};return"conversion"in b&&(w.conversion=b.conversion),w}function y(b){const w=function(...f){const S=f[0];if(S==null)return S;S.length>1&&(f=S);const P=b(f);if(typeof P=="object")for(let A=P.length,p=0;p<A;p++)P[p]=Math.round(P[p]);return P};return"conversion"in b&&(w.conversion=b.conversion),w}ct.forEach(b=>{I[b]={},Object.defineProperty(I[b],"channels",{value:$[b].channels}),Object.defineProperty(I[b],"labels",{value:$[b].labels});const w=W(b);Object.keys(w).forEach(S=>{const P=w[S];I[b][S]=y(P),I[b][S].raw=v(P)})}),k.exports=I},111:(k,it,j)=>{const $=j(168);function W(){const y={},b=Object.keys($);for(let w=b.length,f=0;f<w;f++)y[b[f]]={distance:-1,parent:null};return y}function I(y){const b=W(),w=[y];for(b[y].distance=0;w.length;){const f=w.pop(),S=Object.keys($[f]);for(let P=S.length,A=0;A<P;A++){const p=S[A],T=b[p];T.distance===-1&&(T.distance=b[f].distance+1,T.parent=f,w.unshift(p))}}return b}function ct(y,b){return function(w){return b(y(w))}}function v(y,b){const w=[b[y].parent,y];let f=$[b[y].parent][y],S=b[y].parent;for(;b[S].parent;)w.unshift(b[S].parent),f=ct($[b[S].parent][S],f),S=b[S].parent;return f.conversion=w,f}k.exports=function(y){const b=I(y),w={},f=Object.keys(b);for(let S=f.length,P=0;P<S;P++){const A=f[P];b[A].parent!==null&&(w[A]=v(A,b))}return w}},874: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]}},818:(k,it,j)=>{var $=j(874),W=j(851),I=Object.hasOwnProperty,ct=Object.create(null);for(var v in $)I.call($,v)&&(ct[$[v]]=v);var y=k.exports={to:{},get:{}};y.get=function(f){var S=f.substring(0,3).toLowerCase(),P,A;switch(S){case"hsl":P=y.get.hsl(f),A="hsl";break;case"hwb":P=y.get.hwb(f),A="hwb";break;default:P=y.get.rgb(f),A="rgb";break}return P?{model:A,value:P}:null},y.get.rgb=function(f){if(!f)return null;var S=/^#([a-f0-9]{3,4})$/i,P=/^#([a-f0-9]{6})([a-f0-9]{2})?$/i,A=/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,p=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,T=/^(\w+)$/,E=[0,0,0,1],D,B,lt;if(D=f.match(P)){for(lt=D[2],D=D[1],B=0;B<3;B++){var Dt=B*2;E[B]=parseInt(D.slice(Dt,Dt+2),16)}lt&&(E[3]=parseInt(lt,16)/255)}else if(D=f.match(S)){for(D=D[1],lt=D[3],B=0;B<3;B++)E[B]=parseInt(D[B]+D[B],16);lt&&(E[3]=parseInt(lt+lt,16)/255)}else if(D=f.match(A)){for(B=0;B<3;B++)E[B]=parseInt(D[B+1],0);D[4]&&(D[5]?E[3]=parseFloat(D[4])*.01:E[3]=parseFloat(D[4]))}else if(D=f.match(p)){for(B=0;B<3;B++)E[B]=Math.round(parseFloat(D[B+1])*2.55);D[4]&&(D[5]?E[3]=parseFloat(D[4])*.01:E[3]=parseFloat(D[4]))}else return(D=f.match(T))?D[1]==="transparent"?[0,0,0,0]:I.call($,D[1])?(E=$[D[1]],E[3]=1,E):null:null;for(B=0;B<3;B++)E[B]=b(E[B],0,255);return E[3]=b(E[3],0,1),E},y.get.hsl=function(f){if(!f)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=f.match(S);if(P){var A=parseFloat(P[4]),p=(parseFloat(P[1])%360+360)%360,T=b(parseFloat(P[2]),0,100),E=b(parseFloat(P[3]),0,100),D=b(isNaN(A)?1:A,0,1);return[p,T,E,D]}return null},y.get.hwb=function(f){if(!f)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=f.match(S);if(P){var A=parseFloat(P[4]),p=(parseFloat(P[1])%360+360)%360,T=b(parseFloat(P[2]),0,100),E=b(parseFloat(P[3]),0,100),D=b(isNaN(A)?1:A,0,1);return[p,T,E,D]}return null},y.to.hex=function(){var f=W(arguments);return"#"+w(f[0])+w(f[1])+w(f[2])+(f[3]<1?w(Math.round(f[3]*255)):"")},y.to.rgb=function(){var f=W(arguments);return f.length<4||f[3]===1?"rgb("+Math.round(f[0])+", "+Math.round(f[1])+", "+Math.round(f[2])+")":"rgba("+Math.round(f[0])+", "+Math.round(f[1])+", "+Math.round(f[2])+", "+f[3]+")"},y.to.rgb.percent=function(){var f=W(arguments),S=Math.round(f[0]/255*100),P=Math.round(f[1]/255*100),A=Math.round(f[2]/255*100);return f.length<4||f[3]===1?"rgb("+S+"%, "+P+"%, "+A+"%)":"rgba("+S+"%, "+P+"%, "+A+"%, "+f[3]+")"},y.to.hsl=function(){var f=W(arguments);return f.length<4||f[3]===1?"hsl("+f[0]+", "+f[1]+"%, "+f[2]+"%)":"hsla("+f[0]+", "+f[1]+"%, "+f[2]+"%, "+f[3]+")"},y.to.hwb=function(){var f=W(arguments),S="";return f.length>=4&&f[3]!==1&&(S=", "+f[3]),"hwb("+f[0]+", "+f[1]+"%, "+f[2]+"%"+S+")"},y.to.keyword=function(f){return ct[f.slice(0,3)]};function b(f,S,P){return Math.min(Math.max(S,f),P)}function w(f){var S=Math.round(f).toString(16).toUpperCase();return S.length<2?"0"+S:S}},767:(k,it,j)=>{const $=j(818),W=j(85),I=["keyword","gray","hex"],ct={};for(const p of Object.keys(W))ct[[...W[p].labels].sort().join("")]=p;const v={};function y(p,T){if(!(this instanceof y))return new y(p,T);if(T&&T in I&&(T=null),T&&!(T in W))throw new Error("Unknown model: "+T);let E,D;if(p==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(p instanceof y)this.model=p.model,this.color=[...p.color],this.valpha=p.valpha;else if(typeof p=="string"){const B=$.get(p);if(B===null)throw new Error("Unable to parse color from string: "+p);this.model=B.model,D=W[this.model].channels,this.color=B.value.slice(0,D),this.valpha=typeof B.value[D]=="number"?B.value[D]:1}else if(p.length>0){this.model=T||"rgb",D=W[this.model].channels;const B=Array.prototype.slice.call(p,0,D);this.color=A(B,D),this.valpha=typeof p[D]=="number"?p[D]:1}else if(typeof p=="number")this.model="rgb",this.color=[p>>16&255,p>>8&255,p&255],this.valpha=1;else{this.valpha=1;const B=Object.keys(p);"alpha"in p&&(B.splice(B.indexOf("alpha"),1),this.valpha=typeof p.alpha=="number"?p.alpha:0);const lt=B.sort().join("");if(!(lt in ct))throw new Error("Unable to parse color from object: "+JSON.stringify(p));this.model=ct[lt];const{labels:Dt}=W[this.model],Rt=[];for(E=0;E<Dt.length;E++)Rt.push(p[Dt[E]]);this.color=A(Rt)}if(v[this.model])for(D=W[this.model].channels,E=0;E<D;E++){const B=v[this.model][E];B&&(this.color[E]=B(this.color[E]))}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(p){let T=this.model in $.to?this:this.rgb();T=T.round(typeof p=="number"?p:1);const E=T.valpha===1?T.color:[...T.color,this.valpha];return $.to[T.model](E)},percentString(p){const T=this.rgb().round(typeof p=="number"?p:1),E=T.valpha===1?T.color:[...T.color,this.valpha];return $.to.rgb.percent(E)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const p={},{channels:T}=W[this.model],{labels:E}=W[this.model];for(let D=0;D<T;D++)p[E[D]]=this.color[D];return this.valpha!==1&&(p.alpha=this.valpha),p},unitArray(){const p=this.rgb().color;return p[0]/=255,p[1]/=255,p[2]/=255,this.valpha!==1&&p.push(this.valpha),p},unitObject(){const p=this.rgb().object();return p.r/=255,p.g/=255,p.b/=255,this.valpha!==1&&(p.alpha=this.valpha),p},round(p){return p=Math.max(p||0,0),new y([...this.color.map(w(p)),this.valpha],this.model)},alpha(p){return p!==void 0?new y([...this.color,Math.max(0,Math.min(1,p))],this.model):this.valpha},red:f("rgb",0,S(255)),green:f("rgb",1,S(255)),blue:f("rgb",2,S(255)),hue:f(["hsl","hsv","hsl","hwb","hcg"],0,p=>(p%360+360)%360),saturationl:f("hsl",1,S(100)),lightness:f("hsl",2,S(100)),saturationv:f("hsv",1,S(100)),value:f("hsv",2,S(100)),chroma:f("hcg",1,S(100)),gray:f("hcg",2,S(100)),white:f("hwb",1,S(100)),wblack:f("hwb",2,S(100)),cyan:f("cmyk",0,S(100)),magenta:f("cmyk",1,S(100)),yellow:f("cmyk",2,S(100)),black:f("cmyk",3,S(100)),x:f("xyz",0,S(95.047)),y:f("xyz",1,S(100)),z:f("xyz",2,S(108.833)),l:f("lab",0,S(100)),a:f("lab",1),b:f("lab",2),keyword(p){return p!==void 0?new y(p):W[this.model].keyword(this.color)},hex(p){return p!==void 0?new y(p):$.to.hex(this.rgb().round().color)},hexa(p){if(p!==void 0)return new y(p);const T=this.rgb().round().color;let E=Math.round(this.valpha*255).toString(16).toUpperCase();return E.length===1&&(E="0"+E),$.to.hex(T)+E},rgbNumber(){const p=this.rgb().color;return(p[0]&255)<<16|(p[1]&255)<<8|p[2]&255},luminosity(){const p=this.rgb().color,T=[];for(const[E,D]of p.entries()){const B=D/255;T[E]=B<=.04045?B/12.92:rt((B+.055)/1.055,2.4)}return .2126*T[0]+.7152*T[1]+.0722*T[2]},contrast(p){const T=this.luminosity(),E=p.luminosity();return T>E?(T+.05)/(E+.05):(E+.05)/(T+.05)},level(p){const T=this.contrast(p);return T>=7?"AAA":T>=4.5?"AA":""},isDark(){const p=this.rgb().color;return(p[0]*2126+p[1]*7152+p[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const p=this.rgb();for(let T=0;T<3;T++)p.color[T]=255-p.color[T];return p},lighten(p){const T=this.hsl();return T.color[2]+=T.color[2]*p,T},darken(p){const T=this.hsl();return T.color[2]-=T.color[2]*p,T},saturate(p){const T=this.hsl();return T.color[1]+=T.color[1]*p,T},desaturate(p){const T=this.hsl();return T.color[1]-=T.color[1]*p,T},whiten(p){const T=this.hwb();return T.color[1]+=T.color[1]*p,T},blacken(p){const T=this.hwb();return T.color[2]+=T.color[2]*p,T},grayscale(){const p=this.rgb().color,T=p[0]*.3+p[1]*.59+p[2]*.11;return y.rgb(T,T,T)},fade(p){return this.alpha(this.valpha-this.valpha*p)},opaquer(p){return this.alpha(this.valpha+this.valpha*p)},rotate(p){const T=this.hsl();let E=T.color[0];return E=(E+p)%360,E=E<0?360+E:E,T.color[0]=E,T},mix(p,T){if(!p||!p.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof p);const E=p.rgb(),D=this.rgb(),B=T===void 0?.5:T,lt=2*B-1,Dt=E.alpha()-D.alpha(),Rt=((lt*Dt===-1?lt:(lt+Dt)/(1+lt*Dt))+1)/2,Me=1-Rt;return y.rgb(Rt*E.red()+Me*D.red(),Rt*E.green()+Me*D.green(),Rt*E.blue()+Me*D.blue(),E.alpha()*B+D.alpha()*(1-B))}};for(const p of Object.keys(W)){if(I.includes(p))continue;const{channels:T}=W[p];y.prototype[p]=function(...E){return this.model===p?new y(this):E.length>0?new y(E,p):new y([...P(W[this.model][p].raw(this.color)),this.valpha],p)},y[p]=function(...E){let D=E[0];return typeof D=="number"&&(D=A(E,T)),new y(D,p)}}function b(p,T){return Number(p.toFixed(T))}function w(p){return function(T){return b(T,p)}}function f(p,T,E){p=Array.isArray(p)?p:[p];for(const D of p)(v[D]||(v[D]=[]))[T]=E;return p=p[0],function(D){let B;return D!==void 0?(E&&(D=E(D)),B=this[p](),B.color[T]=D,B):(B=this[p]().color[T],E&&(B=E(B)),B)}}function S(p){return function(T){return Math.max(0,Math.min(p,T))}}function P(p){return Array.isArray(p)?p:[p]}function A(p,T){for(let E=0;E<T;E++)typeof p[E]!="number"&&(p[E]=0);return p}k.exports=y},171:k=>{k.exports=function(j){return!j||typeof j=="string"?!1:j instanceof Array||Array.isArray(j)||j.length>=0&&(j.splice instanceof Function||Object.getOwnPropertyDescriptor(j,j.length-1)&&j.constructor.name!=="String")}},851:(k,it,j)=>{"use strict";var $=j(171),W=Array.prototype.concat,I=Array.prototype.slice,ct=k.exports=function(y){for(var b=[],w=0,f=y.length;w<f;w++){var S=y[w];$(S)?b=W.call(b,I.call(S)):b.push(S)}return b};ct.wrap=function(v){return function(){return v(ct(arguments))}}}},dn={};function St(k){var it=dn[k];if(it!==void 0)return it.exports;var j=dn[k]={exports:{}};return Oo[k](j,j.exports,St),j.exports}St.n=k=>{var it=k&&k.__esModule?()=>k.default:()=>k;return St.d(it,{a:it}),it},St.d=(k,it)=>{for(var j in it)St.o(it,j)&&!St.o(k,j)&&Object.defineProperty(k,j,{enumerable:!0,get:it[j]})},St.o=(k,it)=>Object.prototype.hasOwnProperty.call(k,it),St.r=k=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(k,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(k,"__esModule",{value:!0})};var hs={};(()=>{"use strict";St.r(hs),St.d(hs,{Chart:()=>Do,createChart:()=>yf,generateCandlesData:()=>Cf});function k(s){return typeof s=="function"}function it(s){return k(s==null?void 0:s.lift)}function j(s){return function(t){if(it(t))return t.lift(function(e){try{return s(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}var $=function(s,t){return $=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])},$(s,t)};function W(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");$(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var I=function(){return I=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},I.apply(this,arguments)};function ct(s,t){var e={};for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&t.indexOf(n)<0&&(e[n]=s[n]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(s);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(s,n[i])&&(e[n[i]]=s[n[i]]);return e}function v(s,t,e,n){var i=arguments.length,r=i<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,e):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(s,t,e,n);else for(var a=s.length-1;a>=0;a--)(o=s[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(s,t){return function(e,n){t(e,n,s)}}function b(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)}function w(s,t,e,n){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(n.next(h))}catch(d){o(d)}}function l(h){try{c(n.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):i(h.value).then(a,l)}c((n=n.apply(s,t||[])).next())})}function f(s,t){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,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(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(e=0)),e;)try{if(n=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(s,e)}catch(h){c=[6,h],i=0}finally{n=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}var S=Object.create?function(s,t,e,n){n===void 0&&(n=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(s,n,i)}:function(s,t,e,n){n===void 0&&(n=e),s[n]=t[e]};function P(s,t){for(var e in s)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&S(t,s,e)}function A(s){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&s[t],n=0;if(e)return e.call(s);if(s&&typeof s.length=="number")return{next:function(){return s&&n>=s.length&&(s=void 0),{value:s&&s[n++],done:!s}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function p(s,t){var e=typeof Symbol=="function"&&s[Symbol.iterator];if(!e)return s;var n=e.call(s),i,r=[],o;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)r.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(o)throw o.error}}return r}function T(){for(var s=[],t=0;t<arguments.length;t++)s=s.concat(p(arguments[t]));return s}function E(){for(var s=0,t=0,e=arguments.length;t<e;t++)s+=arguments[t].length;for(var n=Array(s),i=0,t=0;t<e;t++)for(var r=arguments[t],o=0,a=r.length;o<a;o++,i++)n[i]=r[o];return n}function D(s,t,e){if(e||arguments.length===2)for(var n=0,i=t.length,r;n<i;n++)(r||!(n in t))&&(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return s.concat(r||Array.prototype.slice.call(t))}function B(s){return this instanceof B?(this.v=s,this):new B(s)}function lt(s,t,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(s,t||[]),i,r=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(u){n[u]&&(i[u]=function(g){return new Promise(function(m,C){r.push([u,g,m,C])>1||a(u,g)})})}function a(u,g){try{l(n[u](g))}catch(m){d(r[0][3],m)}}function l(u){u.value instanceof B?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,g){u(g),r.shift(),r.length&&a(r[0][0],r[0][1])}}function Dt(s){var t,e;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,r){t[i]=s[i]?function(o){return(e=!e)?{value:B(s[i](o)),done:i==="return"}:r?r(o):o}:r}}function Rt(s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=s[Symbol.asyncIterator],e;return t?t.call(s):(s=typeof A=="function"?A(s):s[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=s[r]&&function(o){return new Promise(function(a,l){o=s[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 Me(s,t){return Object.defineProperty?Object.defineProperty(s,"raw",{value:t}):s.raw=t,s}var Ro=Object.create?function(s,t){Object.defineProperty(s,"default",{enumerable:!0,value:t})}:function(s,t){s.default=t};function wf(s){if(s&&s.__esModule)return s;var t={};if(s!=null)for(var e in s)e!=="default"&&Object.prototype.hasOwnProperty.call(s,e)&&S(t,s,e);return Ro(t,s),t}function Sf(s){return s&&s.__esModule?s:{default:s}}function xf(s,t,e,n){if(e==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?s!==t||!n:!t.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e==="m"?n:e==="a"?n.call(s):n?n.value:t.get(s)}function _f(s,t,e,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?s!==t||!i:!t.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(s,e):i?i.value=e:t.set(s,e),e}function Pf(s,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof s=="function"?t===s:s.has(t)}function un(s){var t=function(n){Error.call(n),n.stack=new Error().stack},e=s(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var ds=un(function(s){return function(e){s(this),this.message=e?e.length+` errors occurred during unsubscription:
7
7
  `+e.map(function(n,i){return i+1+") "+n.toString()}).join(`
8
- `):"",this.name="UnsubscriptionError",this.errors=e}});function Me(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var ne=function(){function s(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return s.prototype.unsubscribe=function(){var t,e,n,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=A(o),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(C){t={error:C}}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(C){r=C instanceof ds?C.errors:[C]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=A(d),g=u.next();!g.done;g=u.next()){var m=g.value;try{pn(m)}catch(C){r=r!=null?r:[],C instanceof ds?r=D(D([],p(r)),p(C.errors)):r.push(C)}}}catch(C){n={error:C}}finally{try{g&&!g.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}if(r)throw new ds(r)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)pn(t);else{if(t instanceof s){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},s.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},s.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},s.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Me(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&Me(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}(),gn=ne.EMPTY;function fn(s){return s instanceof ne||s&&"closed"in s&&k(s.remove)&&k(s.add)&&k(s.unsubscribe)}function pn(s){k(s)?s():s.unsubscribe()}var Zt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Ae={setTimeout:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=Ae.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,D([s,t],p(e))):setTimeout.apply(void 0,D([s,t],p(e)))},clearTimeout:function(s){var t=Ae.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(s)},delegate:void 0};function mn(s){Ae.setTimeout(function(){var t=Zt.onUnhandledError;if(t)t(s);else throw s})}function vn(){}var Ho=function(){return us("C",void 0,void 0)}();function ko(s){return us("E",void 0,s)}function Yo(s){return us("N",s,void 0)}function us(s,t,e){return{kind:s,value:t,error:e}}var $t=null;function Ee(s){if(Zt.useDeprecatedSynchronousErrorHandling){var t=!$t;if(t&&($t={errorThrown:!1,error:null}),s(),t){var e=$t,n=e.errorThrown,i=e.error;if($t=null,n)throw i}}else s()}function jo(s){Zt.useDeprecatedSynchronousErrorHandling&&$t&&($t.errorThrown=!0,$t.error=s)}var gs=function(s){W(t,s);function t(e){var n=s.call(this)||this;return n.isStopped=!1,e?(n.destination=e,fn(e)&&e.add(n)):n.destination=Wo,n}return t.create=function(e,n,i){return new ge(e,n,i)},t.prototype.next=function(e){this.isStopped?ps(Yo(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ps(ko(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ps(Ho,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,s.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}(ne),No=Function.prototype.bind;function fs(s,t){return No.call(s,t)}var Xo=function(){function s(t){this.partialObserver=t}return s.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){De(n)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){De(n)}else De(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){De(e)}},s}(),ge=function(s){W(t,s);function t(e,n,i){var r=s.call(this)||this,o;if(k(e)||!e)o={next:e!=null?e:void 0,error:n!=null?n:void 0,complete:i!=null?i:void 0};else{var a;r&&Zt.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&fs(e.next,a),error:e.error&&fs(e.error,a),complete:e.complete&&fs(e.complete,a)}):o=e}return r.destination=new Xo(o),r}return t}(gs);function De(s){Zt.useDeprecatedSynchronousErrorHandling?jo(s):mn(s)}function zo(s){throw s}function ps(s,t){var e=Zt.onStoppedNotification;e&&Ae.setTimeout(function(){return e(s,t)})}var Wo={closed:!0,next:vn,error:zo,complete:vn};function Tt(s,t,e,n,i){return new Uo(s,t,e,n,i)}var Uo=function(s){W(t,s);function t(e,n,i,r,o,a){var l=s.call(this,e)||this;return l.onFinalize=o,l.shouldUnsubscribe=a,l._next=n?function(c){try{n(c)}catch(h){e.error(h)}}:s.prototype._next,l._error=r?function(c){try{r(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:s.prototype._error,l._complete=i?function(){try{i()}catch(c){e.error(c)}finally{this.unsubscribe()}}:s.prototype._complete,l}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;s.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(gs);function ht(s,t){return j(function(e,n){var i=0;e.subscribe(Tt(n,function(r){n.next(s.call(t,r,i++))}))})}var bn=function(s){return s&&typeof s.length=="number"&&typeof s!="function"};function Cn(s){return k(s==null?void 0:s.then)}var ms=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function ie(s){return s}function Af(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return yn(s)}function yn(s){return s.length===0?ie:s.length===1?s[0]:function(e){return s.reduce(function(n,i){return i(n)},e)}}var pt=function(){function s(t){t&&(this._subscribe=t)}return s.prototype.lift=function(t){var e=new s;return e.source=this,e.operator=t,e},s.prototype.subscribe=function(t,e,n){var i=this,r=Go(t)?t:new ge(t,e,n);return Ee(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},s.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},s.prototype.forEach=function(t,e){var n=this;return e=wn(e),new e(function(i,r){var o=new ge({next:function(a){try{t(a)}catch(l){r(l),o.unsubscribe()}},error:r,complete:i});n.subscribe(o)})},s.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},s.prototype[ms]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return yn(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=wn(t),new t(function(n,i){var r;e.subscribe(function(o){return r=o},function(o){return i(o)},function(){return n(r)})})},s.create=function(t){return new s(t)},s}();function wn(s){var t;return(t=s!=null?s:Zt.Promise)!==null&&t!==void 0?t:Promise}function Vo(s){return s&&k(s.next)&&k(s.error)&&k(s.complete)}function Go(s){return s&&s instanceof gs||Vo(s)&&fn(s)}function Sn(s){return k(s[ms])}function xn(s){return Symbol.asyncIterator&&k(s==null?void 0:s[Symbol.asyncIterator])}function _n(s){return new TypeError("You provided "+(s!==null&&typeof s=="object"?"an invalid object":"'"+s+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Zo(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Pn=Zo();function Tn(s){return k(s==null?void 0:s[Pn])}function Mn(s){return lt(this,arguments,function(){var e,n,i,r;return f(this,function(o){switch(o.label){case 0:e=s.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,B(e.read())];case 3:return n=o.sent(),i=n.value,r=n.done,r?[4,B(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,B(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 An(s){return k(s==null?void 0:s.getReader)}function Ft(s){if(s instanceof pt)return s;if(s!=null){if(Sn(s))return $o(s);if(bn(s))return Ko(s);if(Cn(s))return qo(s);if(xn(s))return En(s);if(Tn(s))return Jo(s);if(An(s))return Qo(s)}throw _n(s)}function $o(s){return new pt(function(t){var e=s[ms]();if(k(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Ko(s){return new pt(function(t){for(var e=0;e<s.length&&!t.closed;e++)t.next(s[e]);t.complete()})}function qo(s){return new pt(function(t){s.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,mn)})}function Jo(s){return new pt(function(t){var e,n;try{for(var i=A(s),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&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function En(s){return new pt(function(t){ta(s,t).catch(function(e){return t.error(e)})})}function Qo(s){return En(Mn(s))}function ta(s,t){var e,n,i,r;return w(this,void 0,void 0,function(){var o,a;return f(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Rt(s),l.label=1;case 1:return[4,e.next()];case 2:if(n=l.sent(),!!n.done)return[3,4];if(o=n.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]),n&&!n.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 Ht(s,t,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var r=t.schedule(function(){e(),i?s.add(this.schedule(null,n)):this.unsubscribe()},n);if(s.add(r),!i)return r}function ea(s,t,e,n,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},g=function(C){return c<n?m(C):l.push(C)},m=function(C){r&&t.next(C),c++;var _=!1;Ft(e(C,h++)).subscribe(Tt(t,function(M){i==null||i(M),r?g(M):t.next(M)},function(){_=!0},void 0,function(){if(_)try{c--;for(var M=function(){var L=l.shift();o?Ht(t,o,function(){return m(L)}):m(L)};l.length&&c<n;)M();u()}catch(L){t.error(L)}}))};return s.subscribe(Tt(t,g,function(){d=!0,u()})),function(){a==null||a()}}function Dn(s,t,e){return e===void 0&&(e=1/0),k(t)?Dn(function(n,i){return ht(function(r,o){return t(n,r,i,o)})(Ft(s(n,i)))},e):(typeof t=="number"&&(e=t),j(function(n,i){return ea(n,i,s,e)}))}function In(s){return s===void 0&&(s=1/0),Dn(ie,s)}var Ln=new pt(function(s){return s.complete()});function Ef(s){return s?sa(s):Ln}function sa(s){return new Observable(function(t){return s.schedule(function(){return t.complete()})})}function Bn(s){return s&&k(s.schedule)}function vs(s){return s[s.length-1]}function na(s){return k(vs(s))?s.pop():void 0}function Ie(s){return Bn(vs(s))?s.pop():void 0}function ia(s,t){return typeof vs(s)=="number"?s.pop():t}function On(s,t){return t===void 0&&(t=0),j(function(e,n){e.subscribe(Tt(n,function(i){return Ht(n,s,function(){return n.next(i)},t)},function(){return Ht(n,s,function(){return n.complete()},t)},function(i){return Ht(n,s,function(){return n.error(i)},t)}))})}function Rn(s,t){return t===void 0&&(t=0),j(function(e,n){n.add(s.schedule(function(){return e.subscribe(n)},t))})}function ra(s,t){return Ft(s).pipe(Rn(t),On(t))}function oa(s,t){return Ft(s).pipe(Rn(t),On(t))}function aa(s,t){return new pt(function(e){var n=0;return t.schedule(function(){n===s.length?e.complete():(e.next(s[n++]),e.closed||this.schedule())})})}function la(s,t){return new pt(function(e){var n;return Ht(e,t,function(){n=s[Pn](),Ht(e,t,function(){var i,r,o;try{i=n.next(),r=i.value,o=i.done}catch(a){e.error(a);return}o?e.complete():e.next(r)},0,!0)}),function(){return k(n==null?void 0:n.return)&&n.return()}})}function Fn(s,t){if(!s)throw new Error("Iterable cannot be null");return new pt(function(e){Ht(e,t,function(){var n=s[Symbol.asyncIterator]();Ht(e,t,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function ca(s,t){return Fn(Mn(s),t)}function ha(s,t){if(s!=null){if(Sn(s))return ra(s,t);if(bn(s))return aa(s,t);if(Cn(s))return oa(s,t);if(xn(s))return Fn(s,t);if(Tn(s))return la(s,t);if(An(s))return ca(s,t)}throw _n(s)}function Le(s,t){return t?ha(s,t):Ft(s)}function xt(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Ie(s),n=ia(s,1/0),i=s;return i.length?i.length===1?Ft(i[0]):In(n)(Le(i,e)):Ln}class bs{constructor(t,e){this.onTickFunction=e,this.animationTimeLeft=0,this.animationInProgress=!1,this.animationTime=t.duration,this.animationTimeLeft=t.timeLeft===void 0?t.duration:t.timeLeft,this.animationInProgress=!0}tick(){this.animationTimeLeft<=0?this.animationInProgress=!1:this.animationTimeLeft--,this.onTickFunction&&this.onTickFunction()}getProgress(){return 1-this.animationTimeLeft/this.animationTime}finishAnimation(){this.animationInProgress=!1,this.animationTimeLeft=0}}var da=St(767),It=St.n(da);class ua extends bs{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=It().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{t.initialAlpha===void 0||t.rgbColor===void 0||(t.type==="fading"?t.currentAnimationColor=t.rgbColor.alpha(t.initialAlpha*this.animationTimeLeft/this.animationTime):t.type==="appearing"&&(t.currentAnimationColor=t.rgbColor.alpha(t.initialAlpha*(1-this.animationTimeLeft/this.animationTime))))})}getColor(t){var e,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#FFFFFF"}revert(){this.animationTimeLeft=Math.max(this.animationTime-this.animationTimeLeft,1),this.colorConfigs.forEach(t=>{t.type==="fading"?t.type="appearing":t.type="fading"})}}class ga extends bs{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=It().rgb(i.startColor),i.rgbEndColor=It().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,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#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,n){const i=t.red()-(t.red()-e.red())*n,r=t.green()-(t.green()-e.green())*n,o=t.blue()-(t.blue()-e.blue())*n;return It().rgb(i,r,o)}}var fa=Math.pow;const Be=14,Oe=[];for(let s=0;s<Be+1;s++)Oe.push(fa(10,s));const Cs=5e-13;class dt{static roundToNearest(t,e){return isFinite(t)?dt.isZero(t)?0:(t>0?t+=Cs:t<0&&(t-=Cs),dt.roundDecimal(Math.round(dt.roundDecimal(t/e))*e)):t}static roundUpToNearest(t,e){return dt.roundDecimal(Math.ceil(t/e))*e}static roundDecimal(t){if(isNaN(t)||t===Math.floor(t))return t;const e=Math.sign(t),n=Math.abs(t),i=Math.min(Be,Be-1-Math.floor(Math.log10(n)));for(let r=i;r>=0;r--){const o=Math.floor(Oe[r]*n+.5);if(o<Oe[Be])return e*o/Oe[r]}return Math.round(t)}static makeDecimal(t,e,n){if(isFinite(t)){const i=t.toFixed(e);return n?i.replace(".",n):i}else return""}static compare(t,e,n){return t>e+n?1:t<e-n?-1:(isNaN(t)?1:0)-(isNaN(e)?1:0)}static isZero(t){return dt.compare(t,0,Cs)===0}static cutNumber(t,e,n=0){return{K:r=>r/1e3,M:r=>r/1e6}[e](t).toFixed(n)+e}static isExponential(t){return/\de(\-|\+)\d/.test(t.toString())}}function pa(s,t,e){const n=s/t;return n>=e||n<=1/e}function Hn(s,t,e){return Math.max(t,Math.min(s,e))}function ma(s){return 1-(Math.pow(2,-5*s)-.0009765625)*1.0009775171065494}function fe(...s){for(const t of s)if(t!==void 0&&isFinite(t))return t;return NaN}const et=s=>~~s,va=s=>~~(s+1),Kt=s=>~~(s+.5),ba=(s,t)=>s>>t;function _t(){const s=()=>Math.random().toString(16).slice(-4);return`${s()+s()}-${s()}-${s()}-${s()}-${s()+s()+s()}`}class Ca extends bs{constructor(t,e,n){var i;super(e,n),this.viewportModel=t,this.animationConfig=e,this.id=_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.easingFn=(i=e.easingFn)!=null?i:ma}tick(){if(super.tick(),this.animationInProgress){const t=this.easingFn(this.getProgress()),e=this.xStart+(this.animationConfig.targetXStart-this.xStart)*t,n=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:n,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})}}var ya=un(function(s){return function(){s(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),O=function(s){W(t,s);function t(){var e=s.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 n=new kn(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new ya},t.prototype.next=function(e){var n=this;Ee(function(){var i,r;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var o=A(n.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 n=this;Ee(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var i=n.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;Ee(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.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(),s.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 n=this,i=this,r=i.hasError,o=i.isStopped,a=i.observers;return r||o?gn:(this.currentObservers=null,a.push(e),new ne(function(){n.currentObservers=null,Me(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,r=n.thrownError,o=n.isStopped;i?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new pt;return e.source=this,e},t.create=function(e,n){return new kn(e,n)},t}(pt),kn=function(s){W(t,s);function t(e,n){var i=s.call(this)||this;return i.destination=e,i.source=n,i}return t.prototype.next=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,e)},t.prototype.error=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,e)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:gn},t}(O),mt=function(s){W(t,s);function t(e){var n=s.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=s.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,r=e._value;if(n)throw i;return this._throwIfClosed(),r},t.prototype.next=function(e){s.prototype.next.call(this,this._value=e)},t}(O),wa=Object.defineProperty,Sa=Object.defineProperties,xa=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertySymbols,_a=Object.prototype.hasOwnProperty,Pa=Object.prototype.propertyIsEnumerable,jn=(s,t,e)=>t in s?wa(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ta=(s,t)=>{for(var e in t||(t={}))_a.call(t,e)&&jn(s,e,t[e]);if(Yn)for(var e of Yn(t))Pa.call(t,e)&&jn(s,e,t[e]);return s},Ma=(s,t)=>Sa(s,xa(t));const Nn=10,Re="VIEWPORT_ANIMATION";class Aa{constructor(t){this.eventBus=t,this.animations={},this.animationInProgressSubject=new mt(!1)}startViewportMovementAnimation(t,e,n=Re,i){const r=new Ca(t,e,i);return this.animations[n]=r,this.ensureIntervalStarted(),r}startColorAlphaAnimation(t,e,n,i){const r=new ua(Ma(Ta({},i),{duration:i&&i.duration||Nn}),e,n);return this.animations[t]=r,this.ensureIntervalStarted(),r}startColorTransitionAnimation(t,e,n=Nn,i){const r=new ga({duration:n},e,i);return this.animations[t]=r,this.ensureIntervalStarted(),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.animationTimeLeft=-1,e.animationInProgress=!1)}ensureIntervalStarted(){this.animationIntervalId||(this.animationIntervalId=window.setInterval(()=>this.tick(),20))}tick(){let t=!0;for(const e of Object.keys(this.animations)){const n=this.animations[e];n.tick(),n.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.eventBus.fireDraw()}stopInterval(){clearInterval(this.animationIntervalId),this.animationIntervalId=void 0}}function Mt(s,t){return t===void 0&&(t=ie),s=s!=null?s:Ea,j(function(e,n){var i,r=!0;e.subscribe(Tt(n,function(o){var a=t(o);(r||!s(i,a))&&(r=!1,i=a,n.next(o))}))})}function Ea(s,t){return s===t}function Da(s){return function(){s.forEach(e=>typeof e=="function"&&e()),s.length=0}}function ys(s){return s}function Xn(s){return s!=null}const Df=()=>{};function If(s){return s!=null}function Ia(s,t,e=La,n=!0){const i=s.filter(r=>t.some(o=>e(r,o)));return n?i.filter((r,o,a)=>a.indexOf(r)===o):i}const zn=(s,t)=>{const e=t.slice().filter(n=>s.find(i=>i===n));return s.map(n=>{var i;return t.indexOf(n)>=0&&(i=e.shift())!=null?i:n})},La=(s,t)=>s===t,Lf=(s,t,e)=>s.filter(n=>t.filter(i=>e(n,i)).length===0),Ba=(s,t)=>s===t,Wn=(s,t,e=Ba)=>s.length===t.length&&s.every((n,i)=>e(n,t[i]));function Bf(s,t,e){const n=s.slice(),i=n[t];return n.splice(t,1),n.splice(e,0,i),n}function ws(s,t,e){const n=s.length,i=Hn(t,0,n-1),r=Hn(e,0,n-1),o=s[i];return s.splice(i,1),s.splice(r,0,o),s}function Of(s,t,e){const n=s.slice(),i=n.findIndex(t);return i!==-1&&(n.splice(i,1),n.splice(i,0,e)),n}const Rf=s=>{const t={};return s.filter(e=>t[e]?!1:t[e]=!0)},Ff=(s,t)=>s.reduce((e,n)=>((e[n[t]]=e[n[t]]||[]).push(n),e),{}),Hf=(s,t)=>[].concat(...s.map(e=>[e,t])).slice(0,-1),kf=s=>Array.isArray(s[0]),Un=s=>Array.isArray(s[0])?s:[s],Oa=(s,t,e)=>{const n=[];let i=0;for(const r of s){const o=Math.max(t-i,0),a=Math.max(e-i,-1),l=r.slice(o,a+1);l.length>0&&n.push(l),i+=r.length}return n},Ra=(s,t)=>s>=0?t[s]:t[t.length+s],vt=s=>Array.prototype.flat?s.flat():pe(s,ys),pe=(s,t)=>{if(Array.prototype.flatMap)return s.flatMap(t);const e=[];for(let n=0;n<s.length;n++){const i=s[n];e.push(...t(i,n,s))}return e};function Lt(s,t,e){const n=e!=null?e:ys;return!s.length||t!==t?{index:-1,exact:!0}:Ss(s,t,0,s.length,n)}function Ss(s,t,e,n,i){const r=ba(e+n,1),o=i(s[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Ss(s,t,e,r,i):Ss(s,t,r,n,i)}function bt(s){if(s&&s.length)return s[s.length-1]}function Fa(s){const t=this.indexOf(s);return t!==-1&&this.splice(t,1),this}function Ha(s,t){if(!s)return;const e=s.indexOf(t);e!==-1&&s.splice(e,1)}function re(s){if(s)return s[0]}function ka(s){function t(e,n){const i=s(n);return i==null||!isFinite(i)?e:[Math.max(e[0],i),Math.min(e[1],i)]}return function(e){const n=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY];return e?e.reduce(t,n):n}}function Ya(s,t,e,n=()=>0){const i=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);n(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);n(o[h])>=a?c=h-1:l=h+1}return l};return s.slice(r(s,t),i(s,e)+1)}let xs;const _s=()=>(xs||(xs=!!navigator.userAgent.match(/Android|iPhone|Opera Mini/)||!1),xs),ja=1.33;function Vn(s,t){let e="";t.textStyle&&(t.textStyle.italic&&(e+="italic "),t.textStyle.bold&&(e+="bold ")),s.font=e+(t.textSize||12)+" "+(t.textFontFamily||"monospace"),s.fillStyle=t.textFill||"#FFFFFF",t.rtl?s.textAlign="right":s.textAlign="start"}function Fe(s,t=!0){const e=s.font.match(/(\d+.)?\d+(px|pt)/gi);let n="10px";return e&&e.length&&(e[0].includes("pt")?n=+e[0].slice(0,e[0].indexOf("pt"))*96/72+"px":n=e[0]),t?parseInt(n,10)*ja:parseInt(n,10)}function Gn(s,t,e){s.save(),Vn(s,e);const n=Math.ceil(Math.max.apply(Math,t.map(o=>s.measureText(o).width))),i=Fe(s),r=i*t.length;return s.restore(),[n,r,i]}function Zn(s){return(s||"").split(/\r\n|\r|\n/)}function Na(s,t,e,n,i){s.save();const[r,,o]=Gn(s,t,i);t.forEach((a,l)=>{var c,h,d;const u=s.measureText(a).width,g=Xa(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&za(s,a,g,n+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),s.fillText(a,g,n+o*l)}),s.restore()}function Xa(s,t,e,n){switch(n){case"left":return s;case"right":return s+t-e;default:return s}}function za(s,t,e,n,i,r){s.save();const o=s.measureText(t).width,a=e,l=e+o,c=n+2,h=c;let d=parseInt(r,10)/15;d<1&&(d=1),s.beginPath(),s.strokeStyle=i,s.lineWidth=d,s.moveTo(a,c),s.lineTo(l,h),s.stroke(),s.restore()}function Yf(s){return`${s}px`}function qt(s,t,e){const n=It().rgb(s).array(),i=n[0],r=n[1],o=n[2];return(i*299+r*587+o*114)/1e3<128?t:e}function Wa(s,t,e,n){const i=n.components.navigationMap.timeLabels,r=i.padding,o=$n(t,i.dateFormat,e),a=Zn(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=Gn(s,a,l);return[c+r.x*2,h+r.y*2]}function $n(s,t,e){return e(t)(s).split(" ").join(`
9
- `)}const Kn={};function kt(s,t){let e=Kn[s];return e!==void 0||(t.save(),t.font=s,e=t.measureText("M").width,Kn[s]=e,t.restore()),e}const qn=new Map;function Pt(s,t,e){const n=e+s;let i=qn.get(n);return i||(t.save(),t.font=e,i=t.measureText(s).width,qn.set(n,i),t.restore()),i}function At(s,t,e=Jn){function n(i,r){for(const o in r)o in i?typeof i[o]=="object"&&i[o]!==null&&!Array.isArray(i[o])?n(i[o],r[o]):e!=null&&e.overrideExisting&&(i[o]=r[o]):e!=null&&e.addIfMissing&&(i[o]=r[o]);return i}return n(s,t)}function jf(s,t,e,n=!1){!s||!t||t.length===0||t.forEach(i=>{const r=e(i),o=s.findIndex(a=>e(a)===r);o===-1?s.push(i):n?At(s[o],i,{overrideExisting:!0,addIfMissing:!0}):s.splice(o,1,i)})}const Jn={overrideExisting:!1,addIfMissing:!0};var Ua=Object.defineProperty,Qn=Object.getOwnPropertySymbols,Va=Object.prototype.hasOwnProperty,Ga=Object.prototype.propertyIsEnumerable,ti=(s,t,e)=>t in s?Ua(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Za=(s,t)=>{for(var e in t||(t={}))Va.call(t,e)&&ti(s,e,t[e]);if(Qn)for(var e of Qn(t))Ga.call(t,e)&&ti(s,e,t[e]);return s};const ei="Open Sans Semibold, sans-serif",$a=null,Ka=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Nf=s=>$a.find(t=>t===s)!==void 0,He=()=>({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,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}},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:ei,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"}}}},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:ei,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"},highlights:{visible:!1,fontFamily:"Open Sans",fontSize:13,border:{width:1,dash:[8,4]}},crossTool:{type:"cross-and-labels",discrete:!1,magnetTarget:"none",lineDash:[4,6],xAxisLabelFormat:[{format:"dd.MM.YYYY",showWhen:{periodMoreThen:24*60*60*1e3}},{format:"dd.MM.YYYY HH:mm",showWhen:{periodLessThen:24*60*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(55,55,54,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)"},"conference-calls":{color:"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","UNDERLAY_VOLUMES_AREA","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function qa(s,t=He()){return At(s,t,Jn),s}function Xf(s,t=He()){const e=Za({},s);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function zf(s,t){Object.keys(s).forEach(e=>delete s[e]),Object.keys(t).forEach(e=>s[e]=t[e])}function si(s){return typeof s=="object"&&s!==null}function ni(s,t){return[...s].map(n=>Ps(n,t))}const Ja=s=>Array.isArray(s);function Ps(s,t){if(!si(s))return s;if(Ja(s))return ni(s,t);{const e=ii({},s,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(s)),e}}function ii(s,t,e){if(!si(s))return e.overrideExisting?t:s;if(Array.isArray(s)&&Array.isArray(t)){const i=e.overrideExisting?t:s;return ni(i,e)}const n=Object.create(Object.getPrototypeOf(s));return Object.keys(s).forEach(i=>n[i]=Ps(s[i],e)),Object.keys(t).forEach(i=>{i in s?n[i]=ii(s[i],t[i],e):e.addIfMissing&&(n[i]=Ps(t[i],e))}),n}const Jt=s=>`${s.fontSize}px ${s.fontFamily}`;class Qa{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=Jt(this.config.components.yAxis);return Pt(t,this.mainCanvasModel.ctx,e)}getYAxisWidths(){this.extentsOrder.clear();const t=[],e=[];return this.yAxisWidthContributors.forEach(n=>{var i,r,o;const a=n.getYAxisState();if(!a.visible)return;const l=a.labelBoxMargin.start+a.labelBoxMargin.end,c=this.getTextWidth(n.getLargestLabel())+l,h=n.getYAxisIndex(),d=n.getPaneUUID(),u=(i=this.extentsOrder.get(d))!=null?i:{left:[],right:[]};if(a.align==="left"){const g=u.left.length;t[g]=Math.max((r=t[g])!=null?r:0,c),u.left.push(h)}else{const g=u.right.length;e[g]=Math.max((o=e[g])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var tl=Object.defineProperty,el=Object.defineProperties,sl=Object.getOwnPropertyDescriptors,ri=Object.getOwnPropertySymbols,nl=Object.prototype.hasOwnProperty,il=Object.prototype.propertyIsEnumerable,oi=(s,t,e)=>t in s?tl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Yt=(s,t)=>{for(var e in t||(t={}))nl.call(t,e)&&oi(s,e,t[e]);if(ri)for(var e of ri(t))il.call(t,e)&&oi(s,e,t[e]);return s},ai=(s,t)=>el(s,sl(t));const tt="CHART",Ts=class{};let x=Ts;x.CANVAS="CANVAS",x.N_MAP="N_MAP",x.X_AXIS="X_AXIS",x.N_MAP_KNOT_L="N_MAP_KNOT_L",x.N_MAP_KNOT_R="N_MAP_KNOT_R",x.N_MAP_BTN_L="N_MAP_BTN_L",x.N_MAP_BTN_R="N_MAP_BTN_R",x.N_MAP_SLIDER_WINDOW="N_MAP_SLIDER_WINDOW",x.N_MAP_CHART="N_MAP_CHART",x.N_MAP_LABEL_R="N_MAP_LABEL_R",x.N_MAP_LABEL_L="N_MAP_LABEL_L",x.PANE_UUID=s=>"PANE_"+s,x.PANE_UUID_Y_AXIS=(s,t=0)=>"PANE_"+s+"_Y_AXIS_"+t,x.PANE_UUID_RESIZER=s=>"PANE_"+s+"_RESIZER",x.ALL_PANES="ALL_PANES",x.CHART_WITH_Y_AXIS="CHART_WITH_Y_AXIS",x.EVENTS="EVENTS",x.CHART=Ts.PANE_UUID(tt),x.Y_AXIS=Ts.PANE_UUID_Y_AXIS(tt);const li={x:0,y:0,pageX:0,pageY:0,width:0,height:0},ci=20,hi=35,Ms=15,di=1.5,ui=_s()?8*di:8,rl=1e-6;class As{constructor(t,e,n,i,r){this.config=t,this.eventBus=e,this.canvasModel=n,this.formatterFactory=i,this.bounds={},this.canvasOnPageLocation={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.panesOrder=[],this.panesOrderChangedSubject=new O,this.paneVisibilityChangedSubject=new O,this.xAxisHeight=void 0,this.yAxisWidths={right:[0],left:[0]},this.leftRatio=0,this.rightRatio=0,this.boundsChangedSubject=new O,this.barResizerChangedSubject=new O,this._graphsHeightRatio={chart:1},this.graphsHeightRatioChangedSubject=new O,this.boundsChangedSubscriptions={},r.canvasResized.subscribe(o=>{let a=o;a||(a=this.canvasModel.canvas.getBoundingClientRect()),this.updateCanvasOnPageLocation(a),this.recalculateBounds()}),this.yAxisBoundsContainer=new Qa(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 n=this.panesOrder.indexOf(t);ws(this.panesOrder,n,e)}this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}}overrideChartHeightRatios(t){const e=Yt(Yt({},this.graphsHeightRatio),t),n=Object.values(e).reduce((i,r)=>i+r,0);Math.abs(n-1)<rl?(this._graphsHeightRatio=e,this.recalculateBounds()):console.error(`Result ratio should be equal 1, but equal ${n}`)}movePaneUp(t){const e=this.panesOrder.indexOf(t);e!==-1&&(ws(this.panesOrder,e,e-1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder))}movePaneDown(t){const e=this.panesOrder.indexOf(t);e!==-1&&(ws(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder))}reorderPanes(t){this.panesOrder=zn(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===tt){const[e]=gi(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Ha(this.panesOrder,t),delete this.graphsHeightRatio[t],delete this.bounds[x.PANE_UUID(t)],this.yAxisWidths.left.concat(this.yAxisWidths.right).forEach((e,n)=>delete this.bounds[x.PANE_UUID_Y_AXIS(t,n)]),delete this.bounds[x.PANE_UUID_RESIZER(t)],this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}recalculateBounds(){const t=this.canvasOnPageLocation.width,e=this.canvasOnPageLocation.height,n=this.config.components.paneResizer.height,i=this.getBounds(x.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((R,F)=>R+F,0),h=r.right.reduce((R,F)=>R+F,0),d=0,u=i.width-h,g=d+c,m=0,C=i.width-c-h;let _=m;const M=this.panesOrder.findIndex(R=>this.graphsHeightRatio[R]>0);this.panesOrder.forEach((R,F)=>{var Y;const q=this.graphsHeightRatio[this.panesOrder[F]],V=x.PANE_UUID_RESIZER(R),N=x.PANE_UUID(R),U=this.config.components.paneResizer.visible&&F>M&&q>0;U?oe(this.bounds,V,0,_,i.width,n,this.canvasOnPageLocation):oe(this.bounds,V,0,0,0,0,this.canvasOnPageLocation);const Q=_+(U?n:0),J=oe(this.bounds,N,g,Q,C,l*q-(U?n:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const st=this.yAxisBoundsContainer.extentsOrder.get(R);if(st===void 0)return;const G=l*q-(U?n:0);let nt=g-((Y=r.left[0])!=null?Y:0),ot=u;st.left.forEach((ft,at)=>{var wt;oe(this.bounds,x.PANE_UUID_Y_AXIS(R,ft),nt,Q,r.left[at],G,this.canvasOnPageLocation),nt-=(wt=r.left[at+1])!=null?wt:0}),st.right.forEach((ft,at)=>{oe(this.bounds,x.PANE_UUID_Y_AXIS(R,ft),ot,Q,r.right[at],G,this.canvasOnPageLocation),ot+=r.right[at]})}else oe(this.bounds,x.PANE_UUID_Y_AXIS(R),0,0,0,0,this.canvasOnPageLocation);_=J.y+J.height});const L=this.getBounds(x.ALL_PANES);L.x=g,L.y=m,L.width=C,L.height=_;const H=this.getBounds(x.CHART_WITH_Y_AXIS),z=this.getBounds(x.CHART);this.getEventsBounds(z),this.copyBounds(z,H),H.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=ai(Yt({},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(x.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(x.N_MAP);return this.config.components.navigationMap.visible?(e.x=0,e.y=t.height-hi,e.width=t.width,e.height=hi):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const n=this.getBounds(x.X_AXIS);if(this.config.components.xAxis.visible){const i=this.getXAxisHeight();n.x=0,n.y=e.height-i-t.height,n.width=e.width,n.height=i}else this.applyDefaultBounds(n);return n}getXAxisHeight(){var t,e;if(!this.xAxisHeight){const n=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily,i=kt(n,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)}return this.xAxisHeight}setYAxisWidths(t){(!Wn(this.yAxisWidths.left,t.left)||!Wn(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[tt];const e=[];e.push(...this.panesOrder.filter(g=>g!==tt));const n=e.map(g=>this.graphsHeightRatio[g]===void 0?void 0:this.graphsHeightRatio[g]),i=n.filter(g=>g!==0),r=i.length,o=i.filter(g=>g!==void 0).length,a=n.filter(g=>g===void 0).length;let l=0,c=0,h=1,d=0;a>0&&([h,d]=gi(r),t*=h),o===0&&(t=1-d*a),c=1-t-d*a,i.forEach(g=>{g&&(c-=g*h)}),l=c/(r||1);const u=n.map(g=>g===0?g:g?g*h+l:d+l);this._graphsHeightRatio={},this.graphsHeightRatio[tt]=t,u.forEach((g,m)=>{const C=e[m];this.graphsHeightRatio[C]=g})}recalculateNavigationMapElementBounds(){var t,e,n,i;if(!this.config.components.navigationMap.visible)return;const r=this.getBounds(x.N_MAP),{height:o,width:a}=this.config.components.navigationMap.knots,l=o!=null?o:0,c=_s()?a*di: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=G=>Wa(this.canvasModel.ctx,G,this.formatterFactory,this.config)[0],g=vt((i=(n=this.mainCandleSeries)==null?void 0:n.getSeriesInViewport())!=null?i:[]),m=d&&g.length?u(g[0].candle.timestamp):0,C=d&&g.length?u(g[g.length-1].candle.timestamp):0,_=Math.max(m,C);if(d){const G=this.getBounds(x.N_MAP_LABEL_L);G.x=r.x,G.y=r.y,G.width=_,G.height=r.height;const nt=this.getBounds(x.N_MAP_LABEL_R);nt.x=r.x+r.width-_,nt.y=r.y,nt.width=_,nt.height=r.height}const M=this.getBounds(x.N_MAP_BTN_L);M.x=r.x+_,M.y=r.y,M.width=Ms,M.height=r.height;const L=this.getBounds(x.N_MAP_BTN_R);L.x=r.x+r.width-Ms-_,L.y=r.y,L.width=Ms,L.height=r.height;const H=M.x+M.width,z=L.x-H,R=H+z,F=this.config.components.navigationMap.minSliderWindowWidth,Y=c!=null?c:ui,q=l!=null?l:r.height,V=Y+F,N=this.getBounds(x.N_MAP_KNOT_L);N.x=H+z*this.leftRatio,N.x=Math.min(N.x,R-V),N.y=h,N.width=Y,N.height=q;const U=this.getBounds(x.N_MAP_KNOT_R);U.x=H+z*this.rightRatio-ui,U.x=Math.max(U.x,H+V),U.y=h,U.width=Y,U.height=q;const Q=V-(U.x-N.x);Q>0&&(N.x-=Q);const J=this.getBounds(x.N_MAP_SLIDER_WINDOW);J.x=N.x+N.width,J.y=r.y,J.width=U.x-J.x,J.height=r.height;const st=this.getBounds(x.N_MAP_CHART);st.x=H,st.y=r.y,st.width=z,st.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(li),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>ai(Yt({},t),{[e]:this.bounds[x.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=ke){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},ke),e);return r?(o,a)=>{const l=this.getBounds(t);return o>l.pageX-n&&o<l.pageX+l.width+n&&a>l.pageY-i&&a<l.pageY+l.height+i}:(o,a)=>{const l=this.getBounds(t);return o>l.x-n&&o<l.x+l.width+n&&a>l.y-i&&a<l.y+l.height+i}}static hitTestOf(t,e=ke){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},ke),e);return r?(o,a)=>o>t.pageX-n&&o<t.pageX+t.width+n&&a>t.pageY-i&&a<t.pageY+t.height+i:(o,a)=>o>t.x-n&&o<t.x+t.width+n&&a>t.y-i&&a<t.y+t.height+i}isChartBoundsAvailable(){const t=this.getBounds(x.CANVAS);return t.width>0&&t.height>0}resizePaneVertically(t,e){const n=this.panesOrder.indexOf(t),i=this.getBounds(x.PANE_UUID_RESIZER(t));this.doResizePaneVertically(n,i.y-e),this.barResizerChangedSubject.next()}doResizePaneVertically(t,e){let n=t-1;const i=this.panesOrder[n];if(this._graphsHeightRatio[i]<=0)for(let d=0;d<t;d++)this._graphsHeightRatio[this.panesOrder[d]]>0&&(n=d);const r=this.getBounds(x.ALL_PANES).height,o=ci,a=r*this.graphsHeightRatio[this.panesOrder[t]],l=r*this.graphsHeightRatio[this.panesOrder[n]],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[n]]-=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 mt(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ht(n=>this.copyOf(n)),Mt((n,i)=>this.sameBounds(n,i)))}observeAnyBoundsChanged(){return this.boundsChangedSubject.asObservable()}copyOf(t){return Yt({},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(li,t)}setMainCandleSeries(t){this.mainCandleSeries=t}}const ol={0:1,1:.8,2:.6,3:.5,4:.4,5:.2},gi=s=>{var t;const e=(t=ol[s])!=null?t:.4,n=(1-e)/s;return[e,n]},Wf=(s,t)=>s.x>t.x&&s.x<t.x+t.width&&s.y>t.y&&s.y<t.y+t.height,al=(s,t)=>s>t.y&&s<t.y+t.height,oe=(s,t,e,n,i,r,o)=>{const a=s[t];if(a)return a.x=e,a.y=n,a.pageX=e+o.x,a.pageY=n+o.y,a.width=i,a.height=r,a;const l={x:e,y:n,pageX:e+o.x,pageY:n+o.y,width:i,height:r};return s[t]=l,l},fi=(s,t)=>Math.min(Math.max(s,t.y),t.y+t.height),ke={extensionX:0,extensionY:0,wholePage:!1},pi=(s,t)=>s.width===t.width&&s.height===t.height;var ll=function(s){W(t,s);function t(e,n){return s.call(this)||this}return t.prototype.schedule=function(e,n){return n===void 0&&(n=0),this},t}(ne),Ye={setInterval:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=Ye.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,D([s,t],p(e))):setInterval.apply(void 0,D([s,t],p(e)))},clearInterval:function(s){var t=Ye.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(s)},delegate:void 0},mi=function(s){W(t,s);function t(e,n){var i=s.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return t.prototype.schedule=function(e,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return r!=null&&(this.id=this.recycleAsyncId(o,r,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,n),this},t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),Ye.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&Ye.clearInterval(n)},t.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,n){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,n=e.id,i=e.scheduler,r=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Me(r,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,s.prototype.unsubscribe.call(this)}},t}(ll),me={schedule:function(s){var t=requestAnimationFrame,e=cancelAnimationFrame,n=me.delegate;n&&(t=n.requestAnimationFrame,e=n.cancelAnimationFrame);var i=t(function(r){e=void 0,s(r)});return new ne(function(){return e==null?void 0:e(i)})},requestAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=me.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,D([],p(s)))},cancelAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=me.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,D([],p(s)))},delegate:void 0},cl=function(s){W(t,s);function t(e,n){var i=s.call(this,e,n)||this;return i.scheduler=e,i.work=n,i}return t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),i!==null&&i>0?s.prototype.requestAsyncId.call(this,e,n,i):(e.actions.push(this),e._scheduled||(e._scheduled=me.requestAnimationFrame(function(){return e.flush(void 0)})))},t.prototype.recycleAsyncId=function(e,n,i){var r;if(i===void 0&&(i=0),i!=null?i>0:this.delay>0)return s.prototype.recycleAsyncId.call(this,e,n,i);var o=e.actions;n!=null&&((r=o[o.length-1])===null||r===void 0?void 0:r.id)!==n&&(me.cancelAnimationFrame(n),e._scheduled=void 0)},t}(mi),Es={now:function(){return(Es.delegate||Date).now()},delegate:void 0},vi=function(){function s(t,e){e===void 0&&(e=s.now),this.schedulerActionCtor=t,this.now=e}return s.prototype.schedule=function(t,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},s.now=Es.now,s}(),bi=function(s){W(t,s);function t(e,n){n===void 0&&(n=vi.now);var i=s.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var n=this.actions;if(this._active){n.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=n.shift());if(this._active=!1,i){for(;e=n.shift();)e.unsubscribe();throw i}},t}(vi),hl=function(s){W(t,s);function t(){return s!==null&&s.apply(this,arguments)||this}return t.prototype.flush=function(e){this._active=!0;var n=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===n&&i.shift());if(this._active=!1,r){for(;(e=i[0])&&e.id===n&&i.shift();)e.unsubscribe();throw r}},t}(bi),je=new hl(cl),Uf=null,Ci=new bi(mi),dl=Ci;function ul(s,t){return j(function(e,n){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,g=function(){d==null||d.unsubscribe(),d=null,l&&(_(),u&&n.complete())},m=function(){d=null,u&&n.complete()},C=function(M){return d=Ft(s(M)).subscribe(Tt(n,g,m))},_=function(){if(c){c=!1;var M=h;h=null,n.next(M),!u&&C(M)}};e.subscribe(Tt(n,function(M){c=!0,h=M,!(d&&!d.closed)&&(o?_():C(M))},function(){u=!0,!(l&&c&&d&&!d.closed)&&n.complete()}))})}function gl(s){return s instanceof Date&&!isNaN(s)}function fl(s,t,e){s===void 0&&(s=0),e===void 0&&(e=dl);var n=-1;return t!=null&&(Bn(t)?e=t:n=t),new pt(function(i){var r=gl(s)?+s-e.now():s;r<0&&(r=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=n?this.schedule(void 0,n):i.complete())},r)})}function Ne(s,t,e){t===void 0&&(t=Ci);var n=fl(s,t);return ul(function(){return n},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 pl extends X{constructor(t,e,n,i){super(),this.element=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.hitTestCanvasModel=i,this.normalLayer=new Map,this.extensionLayer=new Map,this.cursorChangedSubject=new O}doActivate(){super.doActivate(),this.canvasInputListener.observeMouseMoveNoDrag().pipe(Ne(100,je,{trailing:!0})).subscribe(t=>{const e=this.hitTestCanvasModel.resolveCursor(t);if(e!==void 0){this.updateCursor(e);return}t&&(this.normalLayer.forEach(n=>{n.hitTest(t.x,t.y)&&this.updateCursor(n.cursor)}),this.extensionLayer.forEach(n=>{n.hitTest(t.x,t.y)&&this.updateCursor(n.cursor)}))})}setCursorForBounds(t,e,n,i=0){const r=As.hitTestOf(e,{extensionY:i});i?this.extensionLayer.set(t,{cursor:n,hitTest:r}):this.normalLayer.set(t,{cursor:n,hitTest:r})}setCursorForCanvasEl(t,e,n){this.observeCursorType(t,e,n)}removeCursorForCanvasEl(t){this.normalLayer.delete(t),this.extensionLayer.delete(t)}observeCursorChanged(){return this.cursorChangedSubject.pipe(Mt())}observeCursorType(t,e,n){const i=n?this.canvasBoundsContainer.getBoundsHitTest(t,{extensionY:n}):this.canvasBoundsContainer.getBoundsHitTest(t);n?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 ml=s=>{const t=s.canvasArea!==null,e=s.snapshotCanvas!==null,n=s.backgroundCanvas!==null,i=s.mainCanvas!==null,r=s.yAxisLabelsCanvas!==null,o=s.crossToolCanvas!==null,a=s.hitTestCanvas!==null,l=s.chartResizer!==null,c=s.chartContainer!==null,h=s.dynamicObjectsCanvas!==null;return t&&e&&n&&i&&r&&o&&a&&l&&c&&h},vl=s=>`<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 Ae(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var ne=function(){function s(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return s.prototype.unsubscribe=function(){var t,e,n,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=A(o),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(C){t={error:C}}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(C){r=C instanceof ds?C.errors:[C]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=A(d),g=u.next();!g.done;g=u.next()){var m=g.value;try{pn(m)}catch(C){r=r!=null?r:[],C instanceof ds?r=D(D([],p(r)),p(C.errors)):r.push(C)}}}catch(C){n={error:C}}finally{try{g&&!g.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}if(r)throw new ds(r)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)pn(t);else{if(t instanceof s){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},s.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},s.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},s.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&Ae(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&Ae(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}(),gn=ne.EMPTY;function fn(s){return s instanceof ne||s&&"closed"in s&&k(s.remove)&&k(s.add)&&k(s.unsubscribe)}function pn(s){k(s)?s():s.unsubscribe()}var Zt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Ee={setTimeout:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=Ee.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,D([s,t],p(e))):setTimeout.apply(void 0,D([s,t],p(e)))},clearTimeout:function(s){var t=Ee.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(s)},delegate:void 0};function mn(s){Ee.setTimeout(function(){var t=Zt.onUnhandledError;if(t)t(s);else throw s})}function vn(){}var Fo=function(){return us("C",void 0,void 0)}();function Ho(s){return us("E",void 0,s)}function ko(s){return us("N",s,void 0)}function us(s,t,e){return{kind:s,value:t,error:e}}var $t=null;function De(s){if(Zt.useDeprecatedSynchronousErrorHandling){var t=!$t;if(t&&($t={errorThrown:!1,error:null}),s(),t){var e=$t,n=e.errorThrown,i=e.error;if($t=null,n)throw i}}else s()}function Yo(s){Zt.useDeprecatedSynchronousErrorHandling&&$t&&($t.errorThrown=!0,$t.error=s)}var gs=function(s){W(t,s);function t(e){var n=s.call(this)||this;return n.isStopped=!1,e?(n.destination=e,fn(e)&&e.add(n)):n.destination=zo,n}return t.create=function(e,n,i){return new ge(e,n,i)},t.prototype.next=function(e){this.isStopped?ps(ko(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ps(Ho(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ps(Fo,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,s.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}(ne),jo=Function.prototype.bind;function fs(s,t){return jo.call(s,t)}var No=function(){function s(t){this.partialObserver=t}return s.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){Ie(n)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){Ie(n)}else Ie(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){Ie(e)}},s}(),ge=function(s){W(t,s);function t(e,n,i){var r=s.call(this)||this,o;if(k(e)||!e)o={next:e!=null?e:void 0,error:n!=null?n:void 0,complete:i!=null?i:void 0};else{var a;r&&Zt.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&fs(e.next,a),error:e.error&&fs(e.error,a),complete:e.complete&&fs(e.complete,a)}):o=e}return r.destination=new No(o),r}return t}(gs);function Ie(s){Zt.useDeprecatedSynchronousErrorHandling?Yo(s):mn(s)}function Xo(s){throw s}function ps(s,t){var e=Zt.onStoppedNotification;e&&Ee.setTimeout(function(){return e(s,t)})}var zo={closed:!0,next:vn,error:Xo,complete:vn};function Tt(s,t,e,n,i){return new Wo(s,t,e,n,i)}var Wo=function(s){W(t,s);function t(e,n,i,r,o,a){var l=s.call(this,e)||this;return l.onFinalize=o,l.shouldUnsubscribe=a,l._next=n?function(c){try{n(c)}catch(h){e.error(h)}}:s.prototype._next,l._error=r?function(c){try{r(c)}catch(h){e.error(h)}finally{this.unsubscribe()}}:s.prototype._error,l._complete=i?function(){try{i()}catch(c){e.error(c)}finally{this.unsubscribe()}}:s.prototype._complete,l}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;s.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(gs);function ht(s,t){return j(function(e,n){var i=0;e.subscribe(Tt(n,function(r){n.next(s.call(t,r,i++))}))})}var bn=function(s){return s&&typeof s.length=="number"&&typeof s!="function"};function Cn(s){return k(s==null?void 0:s.then)}var ms=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function ie(s){return s}function Tf(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return yn(s)}function yn(s){return s.length===0?ie:s.length===1?s[0]:function(e){return s.reduce(function(n,i){return i(n)},e)}}var pt=function(){function s(t){t&&(this._subscribe=t)}return s.prototype.lift=function(t){var e=new s;return e.source=this,e.operator=t,e},s.prototype.subscribe=function(t,e,n){var i=this,r=Vo(t)?t:new ge(t,e,n);return De(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},s.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},s.prototype.forEach=function(t,e){var n=this;return e=wn(e),new e(function(i,r){var o=new ge({next:function(a){try{t(a)}catch(l){r(l),o.unsubscribe()}},error:r,complete:i});n.subscribe(o)})},s.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},s.prototype[ms]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return yn(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=wn(t),new t(function(n,i){var r;e.subscribe(function(o){return r=o},function(o){return i(o)},function(){return n(r)})})},s.create=function(t){return new s(t)},s}();function wn(s){var t;return(t=s!=null?s:Zt.Promise)!==null&&t!==void 0?t:Promise}function Uo(s){return s&&k(s.next)&&k(s.error)&&k(s.complete)}function Vo(s){return s&&s instanceof gs||Uo(s)&&fn(s)}function Sn(s){return k(s[ms])}function xn(s){return Symbol.asyncIterator&&k(s==null?void 0:s[Symbol.asyncIterator])}function _n(s){return new TypeError("You provided "+(s!==null&&typeof s=="object"?"an invalid object":"'"+s+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Go(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Pn=Go();function Tn(s){return k(s==null?void 0:s[Pn])}function Mn(s){return lt(this,arguments,function(){var e,n,i,r;return f(this,function(o){switch(o.label){case 0:e=s.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,B(e.read())];case 3:return n=o.sent(),i=n.value,r=n.done,r?[4,B(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,B(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 An(s){return k(s==null?void 0:s.getReader)}function Ft(s){if(s instanceof pt)return s;if(s!=null){if(Sn(s))return Zo(s);if(bn(s))return $o(s);if(Cn(s))return Ko(s);if(xn(s))return En(s);if(Tn(s))return qo(s);if(An(s))return Jo(s)}throw _n(s)}function Zo(s){return new pt(function(t){var e=s[ms]();if(k(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function $o(s){return new pt(function(t){for(var e=0;e<s.length&&!t.closed;e++)t.next(s[e]);t.complete()})}function Ko(s){return new pt(function(t){s.then(function(e){t.closed||(t.next(e),t.complete())},function(e){return t.error(e)}).then(null,mn)})}function qo(s){return new pt(function(t){var e,n;try{for(var i=A(s),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&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}t.complete()})}function En(s){return new pt(function(t){Qo(s,t).catch(function(e){return t.error(e)})})}function Jo(s){return En(Mn(s))}function Qo(s,t){var e,n,i,r;return w(this,void 0,void 0,function(){var o,a;return f(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Rt(s),l.label=1;case 1:return[4,e.next()];case 2:if(n=l.sent(),!!n.done)return[3,4];if(o=n.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]),n&&!n.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 Ht(s,t,e,n,i){n===void 0&&(n=0),i===void 0&&(i=!1);var r=t.schedule(function(){e(),i?s.add(this.schedule(null,n)):this.unsubscribe()},n);if(s.add(r),!i)return r}function ta(s,t,e,n,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},g=function(C){return c<n?m(C):l.push(C)},m=function(C){r&&t.next(C),c++;var _=!1;Ft(e(C,h++)).subscribe(Tt(t,function(M){i==null||i(M),r?g(M):t.next(M)},function(){_=!0},void 0,function(){if(_)try{c--;for(var M=function(){var L=l.shift();o?Ht(t,o,function(){return m(L)}):m(L)};l.length&&c<n;)M();u()}catch(L){t.error(L)}}))};return s.subscribe(Tt(t,g,function(){d=!0,u()})),function(){a==null||a()}}function Dn(s,t,e){return e===void 0&&(e=1/0),k(t)?Dn(function(n,i){return ht(function(r,o){return t(n,r,i,o)})(Ft(s(n,i)))},e):(typeof t=="number"&&(e=t),j(function(n,i){return ta(n,i,s,e)}))}function In(s){return s===void 0&&(s=1/0),Dn(ie,s)}var Ln=new pt(function(s){return s.complete()});function Mf(s){return s?ea(s):Ln}function ea(s){return new Observable(function(t){return s.schedule(function(){return t.complete()})})}function Bn(s){return s&&k(s.schedule)}function vs(s){return s[s.length-1]}function sa(s){return k(vs(s))?s.pop():void 0}function Le(s){return Bn(vs(s))?s.pop():void 0}function na(s,t){return typeof vs(s)=="number"?s.pop():t}function On(s,t){return t===void 0&&(t=0),j(function(e,n){e.subscribe(Tt(n,function(i){return Ht(n,s,function(){return n.next(i)},t)},function(){return Ht(n,s,function(){return n.complete()},t)},function(i){return Ht(n,s,function(){return n.error(i)},t)}))})}function Rn(s,t){return t===void 0&&(t=0),j(function(e,n){n.add(s.schedule(function(){return e.subscribe(n)},t))})}function ia(s,t){return Ft(s).pipe(Rn(t),On(t))}function ra(s,t){return Ft(s).pipe(Rn(t),On(t))}function oa(s,t){return new pt(function(e){var n=0;return t.schedule(function(){n===s.length?e.complete():(e.next(s[n++]),e.closed||this.schedule())})})}function aa(s,t){return new pt(function(e){var n;return Ht(e,t,function(){n=s[Pn](),Ht(e,t,function(){var i,r,o;try{i=n.next(),r=i.value,o=i.done}catch(a){e.error(a);return}o?e.complete():e.next(r)},0,!0)}),function(){return k(n==null?void 0:n.return)&&n.return()}})}function Fn(s,t){if(!s)throw new Error("Iterable cannot be null");return new pt(function(e){Ht(e,t,function(){var n=s[Symbol.asyncIterator]();Ht(e,t,function(){n.next().then(function(i){i.done?e.complete():e.next(i.value)})},0,!0)})})}function la(s,t){return Fn(Mn(s),t)}function ca(s,t){if(s!=null){if(Sn(s))return ia(s,t);if(bn(s))return oa(s,t);if(Cn(s))return ra(s,t);if(xn(s))return Fn(s,t);if(Tn(s))return aa(s,t);if(An(s))return la(s,t)}throw _n(s)}function Be(s,t){return t?ca(s,t):Ft(s)}function xt(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Le(s),n=na(s,1/0),i=s;return i.length?i.length===1?Ft(i[0]):In(n)(Be(i,e)):Ln}class bs{constructor(t,e){this.onTickFunction=e,this.animationTimeLeft=0,this.animationInProgress=!1,this.animationTime=t.duration,this.animationTimeLeft=t.timeLeft===void 0?t.duration:t.timeLeft,this.animationInProgress=!0}tick(){this.animationTimeLeft<=0?this.animationInProgress=!1:this.animationTimeLeft--,this.onTickFunction&&this.onTickFunction()}getProgress(){return 1-this.animationTimeLeft/this.animationTime}finishAnimation(){this.animationInProgress=!1,this.animationTimeLeft=0}}var ha=St(767),It=St.n(ha);class da extends bs{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=It().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{t.initialAlpha===void 0||t.rgbColor===void 0||(t.type==="fading"?t.currentAnimationColor=t.rgbColor.alpha(t.initialAlpha*this.animationTimeLeft/this.animationTime):t.type==="appearing"&&(t.currentAnimationColor=t.rgbColor.alpha(t.initialAlpha*(1-this.animationTimeLeft/this.animationTime))))})}getColor(t){var e,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#FFFFFF"}revert(){this.animationTimeLeft=Math.max(this.animationTime-this.animationTimeLeft,1),this.colorConfigs.forEach(t=>{t.type==="fading"?t.type="appearing":t.type="fading"})}}class ua extends bs{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=It().rgb(i.startColor),i.rgbEndColor=It().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,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#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,n){const i=t.red()-(t.red()-e.red())*n,r=t.green()-(t.green()-e.green())*n,o=t.blue()-(t.blue()-e.blue())*n;return It().rgb(i,r,o)}}var ga=Math.pow;const Oe=14,Re=[];for(let s=0;s<Oe+1;s++)Re.push(ga(10,s));const Cs=5e-13;class dt{static roundToNearest(t,e){return isFinite(t)?dt.isZero(t)?0:(t>0?t+=Cs:t<0&&(t-=Cs),dt.roundDecimal(Math.round(dt.roundDecimal(t/e))*e)):t}static roundUpToNearest(t,e){return dt.roundDecimal(Math.ceil(t/e))*e}static roundDecimal(t){if(isNaN(t)||t===Math.floor(t))return t;const e=Math.sign(t),n=Math.abs(t),i=Math.min(Oe,Oe-1-Math.floor(Math.log10(n)));for(let r=i;r>=0;r--){const o=Math.floor(Re[r]*n+.5);if(o<Re[Oe])return e*o/Re[r]}return Math.round(t)}static makeDecimal(t,e,n){if(isFinite(t)){const i=t.toFixed(e);return n?i.replace(".",n):i}else return""}static compare(t,e,n){return t>e+n?1:t<e-n?-1:(isNaN(t)?1:0)-(isNaN(e)?1:0)}static isZero(t){return dt.compare(t,0,Cs)===0}static cutNumber(t,e,n=0){return{K:r=>r/1e3,M:r=>r/1e6}[e](t).toFixed(n)+e}static isExponential(t){return/\de(\-|\+)\d/.test(t.toString())}}function fa(s,t,e){const n=s/t;return n>=e||n<=1/e}function Hn(s,t,e){return Math.max(t,Math.min(s,e))}function pa(s){return 1-(Math.pow(2,-5*s)-.0009765625)*1.0009775171065494}function fe(...s){for(const t of s)if(t!==void 0&&isFinite(t))return t;return NaN}const et=s=>~~s,ma=s=>~~(s+1),Kt=s=>~~(s+.5),va=(s,t)=>s>>t;function _t(){const s=()=>Math.random().toString(16).slice(-4);return`${s()+s()}-${s()}-${s()}-${s()}-${s()+s()+s()}`}class ba extends bs{constructor(t,e,n){var i;super(e,n),this.viewportModel=t,this.animationConfig=e,this.id=_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.easingFn=(i=e.easingFn)!=null?i:pa}tick(){if(super.tick(),this.animationInProgress){const t=this.easingFn(this.getProgress()),e=this.xStart+(this.animationConfig.targetXStart-this.xStart)*t,n=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:n,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})}}var Ca=un(function(s){return function(){s(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),O=function(s){W(t,s);function t(){var e=s.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 n=new kn(this,this);return n.operator=e,n},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ca},t.prototype.next=function(e){var n=this;De(function(){var i,r;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var o=A(n.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 n=this;De(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;for(var i=n.observers;i.length;)i.shift().error(e)}})},t.prototype.complete=function(){var e=this;De(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var n=e.observers;n.length;)n.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(),s.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 n=this,i=this,r=i.hasError,o=i.isStopped,a=i.observers;return r||o?gn:(this.currentObservers=null,a.push(e),new ne(function(){n.currentObservers=null,Ae(a,e)}))},t.prototype._checkFinalizedStatuses=function(e){var n=this,i=n.hasError,r=n.thrownError,o=n.isStopped;i?e.error(r):o&&e.complete()},t.prototype.asObservable=function(){var e=new pt;return e.source=this,e},t.create=function(e,n){return new kn(e,n)},t}(pt),kn=function(s){W(t,s);function t(e,n){var i=s.call(this)||this;return i.destination=e,i.source=n,i}return t.prototype.next=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.next)===null||i===void 0||i.call(n,e)},t.prototype.error=function(e){var n,i;(i=(n=this.destination)===null||n===void 0?void 0:n.error)===null||i===void 0||i.call(n,e)},t.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},t.prototype._subscribe=function(e){var n,i;return(i=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&i!==void 0?i:gn},t}(O),mt=function(s){W(t,s);function t(e){var n=s.call(this)||this;return n._value=e,n}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(e){var n=s.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},t.prototype.getValue=function(){var e=this,n=e.hasError,i=e.thrownError,r=e._value;if(n)throw i;return this._throwIfClosed(),r},t.prototype.next=function(e){s.prototype.next.call(this,this._value=e)},t}(O),ya=Object.defineProperty,wa=Object.defineProperties,Sa=Object.getOwnPropertyDescriptors,Yn=Object.getOwnPropertySymbols,xa=Object.prototype.hasOwnProperty,_a=Object.prototype.propertyIsEnumerable,jn=(s,t,e)=>t in s?ya(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Pa=(s,t)=>{for(var e in t||(t={}))xa.call(t,e)&&jn(s,e,t[e]);if(Yn)for(var e of Yn(t))_a.call(t,e)&&jn(s,e,t[e]);return s},Ta=(s,t)=>wa(s,Sa(t));const Nn=10,Fe="VIEWPORT_ANIMATION";class Ma{constructor(t){this.eventBus=t,this.animations={},this.animationInProgressSubject=new mt(!1)}startViewportMovementAnimation(t,e,n=Fe,i){const r=new ba(t,e,i);return this.animations[n]=r,this.ensureIntervalStarted(),r}startColorAlphaAnimation(t,e,n,i){const r=new da(Ta(Pa({},i),{duration:i&&i.duration||Nn}),e,n);return this.animations[t]=r,this.ensureIntervalStarted(),r}startColorTransitionAnimation(t,e,n=Nn,i){const r=new ua({duration:n},e,i);return this.animations[t]=r,this.ensureIntervalStarted(),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.animationTimeLeft=-1,e.animationInProgress=!1)}ensureIntervalStarted(){this.animationIntervalId||(this.animationIntervalId=window.setInterval(()=>this.tick(),20))}tick(){let t=!0;for(const e of Object.keys(this.animations)){const n=this.animations[e];n.tick(),n.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.eventBus.fireDraw()}stopInterval(){clearInterval(this.animationIntervalId),this.animationIntervalId=void 0}}function Mt(s,t){return t===void 0&&(t=ie),s=s!=null?s:Aa,j(function(e,n){var i,r=!0;e.subscribe(Tt(n,function(o){var a=t(o);(r||!s(i,a))&&(r=!1,i=a,n.next(o))}))})}function Aa(s,t){return s===t}function Ea(s){return function(){s.forEach(e=>typeof e=="function"&&e()),s.length=0}}function ys(s){return s}function Xn(s){return s!=null}const Af=()=>{};function Ef(s){return s!=null}function Da(s,t,e=Ia,n=!0){const i=s.filter(r=>t.some(o=>e(r,o)));return n?i.filter((r,o,a)=>a.indexOf(r)===o):i}const zn=(s,t)=>{const e=t.slice().filter(n=>s.find(i=>i===n));return s.map(n=>{var i;return t.indexOf(n)>=0&&(i=e.shift())!=null?i:n})},Ia=(s,t)=>s===t,Df=(s,t,e)=>s.filter(n=>t.filter(i=>e(n,i)).length===0),La=(s,t)=>s===t,Wn=(s,t,e=La)=>s.length===t.length&&s.every((n,i)=>e(n,t[i]));function If(s,t,e){const n=s.slice(),i=n[t];return n.splice(t,1),n.splice(e,0,i),n}function ws(s,t,e){const n=s.length,i=Hn(t,0,n-1),r=Hn(e,0,n-1),o=s[i];return s.splice(i,1),s.splice(r,0,o),s}function Lf(s,t,e){const n=s.slice(),i=n.findIndex(t);return i!==-1&&(n.splice(i,1),n.splice(i,0,e)),n}const Bf=s=>{const t={};return s.filter(e=>t[e]?!1:t[e]=!0)},Of=(s,t)=>s.reduce((e,n)=>((e[n[t]]=e[n[t]]||[]).push(n),e),{}),Rf=(s,t)=>[].concat(...s.map(e=>[e,t])).slice(0,-1),Ff=s=>Array.isArray(s[0]),Un=s=>Array.isArray(s[0])?s:[s],Ba=(s,t,e)=>{const n=[];let i=0;for(const r of s){const o=Math.max(t-i,0),a=Math.max(e-i,-1),l=r.slice(o,a+1);l.length>0&&n.push(l),i+=r.length}return n},Oa=(s,t)=>s>=0?t[s]:t[t.length+s],vt=s=>Array.prototype.flat?s.flat():pe(s,ys),pe=(s,t)=>{if(Array.prototype.flatMap)return s.flatMap(t);const e=[];for(let n=0;n<s.length;n++){const i=s[n];e.push(...t(i,n,s))}return e};function Lt(s,t,e){const n=e!=null?e:ys;return!s.length||t!==t?{index:-1,exact:!0}:Ss(s,t,0,s.length,n)}function Ss(s,t,e,n,i){const r=va(e+n,1),o=i(s[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Ss(s,t,e,r,i):Ss(s,t,r,n,i)}function bt(s){if(s&&s.length)return s[s.length-1]}function Ra(s){const t=this.indexOf(s);return t!==-1&&this.splice(t,1),this}function Fa(s,t){if(!s)return;const e=s.indexOf(t);e!==-1&&s.splice(e,1)}function re(s){if(s)return s[0]}function Ha(s){function t(e,n){const i=s(n);return i==null||!isFinite(i)?e:[Math.max(e[0],i),Math.min(e[1],i)]}return function(e){const n=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY];return e?e.reduce(t,n):n}}function ka(s,t,e,n=()=>0){const i=(o,a)=>{let l=0,c=o.length-1;for(;c>=l;){const h=Math.ceil((l+c)/2);n(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);n(o[h])>=a?c=h-1:l=h+1}return l};return s.slice(r(s,t),i(s,e)+1)}let xs;const _s=()=>(xs||(xs=!!navigator.userAgent.match(/Android|iPhone|Opera Mini/)||!1),xs),Ya=1.33;function Vn(s,t){let e="";t.textStyle&&(t.textStyle.italic&&(e+="italic "),t.textStyle.bold&&(e+="bold ")),s.font=e+(t.textSize||12)+" "+(t.textFontFamily||"monospace"),s.fillStyle=t.textFill||"#FFFFFF",t.rtl?s.textAlign="right":s.textAlign="start"}function He(s,t=!0){const e=s.font.match(/(\d+.)?\d+(px|pt)/gi);let n="10px";return e&&e.length&&(e[0].includes("pt")?n=+e[0].slice(0,e[0].indexOf("pt"))*96/72+"px":n=e[0]),t?parseInt(n,10)*Ya:parseInt(n,10)}function Gn(s,t,e){s.save(),Vn(s,e);const n=Math.ceil(Math.max.apply(Math,t.map(o=>s.measureText(o).width))),i=He(s),r=i*t.length;return s.restore(),[n,r,i]}function Zn(s){return(s||"").split(/\r\n|\r|\n/)}function ja(s,t,e,n,i){s.save();const[r,,o]=Gn(s,t,i);t.forEach((a,l)=>{var c,h,d;const u=s.measureText(a).width,g=Na(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&Xa(s,a,g,n+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),s.fillText(a,g,n+o*l)}),s.restore()}function Na(s,t,e,n){switch(n){case"left":return s;case"right":return s+t-e;default:return s}}function Xa(s,t,e,n,i,r){s.save();const o=s.measureText(t).width,a=e,l=e+o,c=n+2,h=c;let d=parseInt(r,10)/15;d<1&&(d=1),s.beginPath(),s.strokeStyle=i,s.lineWidth=d,s.moveTo(a,c),s.lineTo(l,h),s.stroke(),s.restore()}function Hf(s){return`${s}px`}function qt(s,t,e){const n=It().rgb(s).array(),i=n[0],r=n[1],o=n[2];return(i*299+r*587+o*114)/1e3<128?t:e}function za(s,t,e,n){const i=n.components.navigationMap.timeLabels,r=i.padding,o=$n(t,i.dateFormat,e),a=Zn(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=Gn(s,a,l);return[c+r.x*2,h+r.y*2]}function $n(s,t,e){return e(t)(s).split(" ").join(`
9
+ `)}const Kn={};function kt(s,t){let e=Kn[s];return e!==void 0||(t.save(),t.font=s,e=t.measureText("M").width,Kn[s]=e,t.restore()),e}const qn=new Map;function Pt(s,t,e){const n=e+s;let i=qn.get(n);return i||(t.save(),t.font=e,i=t.measureText(s).width,qn.set(n,i),t.restore()),i}function At(s,t,e=Jn){function n(i,r){for(const o in r)o in i?typeof i[o]=="object"&&i[o]!==null&&!Array.isArray(i[o])?n(i[o],r[o]):e!=null&&e.overrideExisting&&(i[o]=r[o]):e!=null&&e.addIfMissing&&(i[o]=r[o]);return i}return n(s,t)}function kf(s,t,e,n=!1){!s||!t||t.length===0||t.forEach(i=>{const r=e(i),o=s.findIndex(a=>e(a)===r);o===-1?s.push(i):n?At(s[o],i,{overrideExisting:!0,addIfMissing:!0}):s.splice(o,1,i)})}const Jn={overrideExisting:!1,addIfMissing:!0};var Wa=Object.defineProperty,Qn=Object.getOwnPropertySymbols,Ua=Object.prototype.hasOwnProperty,Va=Object.prototype.propertyIsEnumerable,ti=(s,t,e)=>t in s?Wa(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ga=(s,t)=>{for(var e in t||(t={}))Ua.call(t,e)&&ti(s,e,t[e]);if(Qn)for(var e of Qn(t))Va.call(t,e)&&ti(s,e,t[e]);return s};const ei="Open Sans Semibold, sans-serif",Za=null,$a=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Yf=s=>Za.find(t=>t===s)!==void 0,ke=()=>({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,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}},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:ei,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"}}}},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:ei,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"},highlights:{visible:!1,fontFamily:"Open Sans",fontSize:13,border:{width:1,dash:[8,4]}},crossTool:{type:"cross-and-labels",discrete:!1,magnetTarget:"none",lineDash:[4,6],xAxisLabelFormat:[{format:"dd.MM.YYYY",showWhen:{periodMoreThen:24*60*60*1e3}},{format:"dd.MM.YYYY HH:mm",showWhen:{periodLessThen:24*60*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(55,55,54,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)"},"conference-calls":{color:"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","UNDERLAY_VOLUMES_AREA","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function Ka(s,t=ke()){return At(s,t,Jn),s}function jf(s,t=ke()){const e=Ga({},s);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function Nf(s,t){Object.keys(s).forEach(e=>delete s[e]),Object.keys(t).forEach(e=>s[e]=t[e])}function si(s){return typeof s=="object"&&s!==null}function ni(s,t){return[...s].map(n=>Ps(n,t))}const qa=s=>Array.isArray(s);function Ps(s,t){if(!si(s))return s;if(qa(s))return ni(s,t);{const e=ii({},s,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(s)),e}}function ii(s,t,e){if(!si(s))return e.overrideExisting?t:s;if(Array.isArray(s)&&Array.isArray(t)){const i=e.overrideExisting?t:s;return ni(i,e)}const n=Object.create(Object.getPrototypeOf(s));return Object.keys(s).forEach(i=>n[i]=Ps(s[i],e)),Object.keys(t).forEach(i=>{i in s?n[i]=ii(s[i],t[i],e):e.addIfMissing&&(n[i]=Ps(t[i],e))}),n}const Jt=s=>`${s.fontSize}px ${s.fontFamily}`;class Ja{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=Jt(this.config.components.yAxis);return Pt(t,this.mainCanvasModel.ctx,e)}getYAxisWidths(){this.extentsOrder.clear();const t=[],e=[];return this.yAxisWidthContributors.forEach(n=>{var i,r,o;const a=n.getYAxisState();if(!a.visible)return;const l=a.labelBoxMargin.start+a.labelBoxMargin.end,c=this.getTextWidth(n.getLargestLabel())+l,h=n.getYAxisIndex(),d=n.getPaneUUID(),u=(i=this.extentsOrder.get(d))!=null?i:{left:[],right:[]};if(a.align==="left"){const g=u.left.length;t[g]=Math.max((r=t[g])!=null?r:0,c),u.left.push(h)}else{const g=u.right.length;e[g]=Math.max((o=e[g])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var Qa=Object.defineProperty,tl=Object.defineProperties,el=Object.getOwnPropertyDescriptors,ri=Object.getOwnPropertySymbols,sl=Object.prototype.hasOwnProperty,nl=Object.prototype.propertyIsEnumerable,oi=(s,t,e)=>t in s?Qa(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Yt=(s,t)=>{for(var e in t||(t={}))sl.call(t,e)&&oi(s,e,t[e]);if(ri)for(var e of ri(t))nl.call(t,e)&&oi(s,e,t[e]);return s},ai=(s,t)=>tl(s,el(t));const tt="CHART",Ts=class{};let x=Ts;x.CANVAS="CANVAS",x.N_MAP="N_MAP",x.X_AXIS="X_AXIS",x.N_MAP_KNOT_L="N_MAP_KNOT_L",x.N_MAP_KNOT_R="N_MAP_KNOT_R",x.N_MAP_BTN_L="N_MAP_BTN_L",x.N_MAP_BTN_R="N_MAP_BTN_R",x.N_MAP_SLIDER_WINDOW="N_MAP_SLIDER_WINDOW",x.N_MAP_CHART="N_MAP_CHART",x.N_MAP_LABEL_R="N_MAP_LABEL_R",x.N_MAP_LABEL_L="N_MAP_LABEL_L",x.PANE_UUID=s=>"PANE_"+s,x.PANE_UUID_Y_AXIS=(s,t=0)=>"PANE_"+s+"_Y_AXIS_"+t,x.PANE_UUID_RESIZER=s=>"PANE_"+s+"_RESIZER",x.ALL_PANES="ALL_PANES",x.CHART_WITH_Y_AXIS="CHART_WITH_Y_AXIS",x.EVENTS="EVENTS",x.CHART=Ts.PANE_UUID(tt),x.Y_AXIS=Ts.PANE_UUID_Y_AXIS(tt);const li={x:0,y:0,pageX:0,pageY:0,width:0,height:0},ci=20,hi=35,Ms=15,di=1.5,ui=_s()?8*di:8,il=1e-6;class As{constructor(t,e,n,i,r){this.config=t,this.eventBus=e,this.canvasModel=n,this.formatterFactory=i,this.bounds={},this.canvasOnPageLocation={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.panesOrder=[],this.panesOrderChangedSubject=new O,this.paneVisibilityChangedSubject=new O,this.xAxisHeight=void 0,this.yAxisWidths={right:[0],left:[0]},this.leftRatio=0,this.rightRatio=0,this.boundsChangedSubject=new O,this.barResizerChangedSubject=new O,this._graphsHeightRatio={chart:1},this.graphsHeightRatioChangedSubject=new O,this.boundsChangedSubscriptions={},r.canvasResized.subscribe(o=>{let a=o;a||(a=this.canvasModel.canvas.getBoundingClientRect()),this.updateCanvasOnPageLocation(a),this.recalculateBounds()}),this.yAxisBoundsContainer=new Ja(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 n=this.panesOrder.indexOf(t);ws(this.panesOrder,n,e)}this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}}overrideChartHeightRatios(t){const e=Yt(Yt({},this.graphsHeightRatio),t),n=Object.values(e).reduce((i,r)=>i+r,0);Math.abs(n-1)<il?(this._graphsHeightRatio=e,this.recalculateBounds()):console.error(`Result ratio should be equal 1, but equal ${n}`)}movePaneUp(t){const e=this.panesOrder.indexOf(t);e!==-1&&(ws(this.panesOrder,e,e-1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder))}movePaneDown(t){const e=this.panesOrder.indexOf(t);e!==-1&&(ws(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder))}reorderPanes(t){this.panesOrder=zn(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===tt){const[e]=gi(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Fa(this.panesOrder,t),delete this.graphsHeightRatio[t],delete this.bounds[x.PANE_UUID(t)],this.yAxisWidths.left.concat(this.yAxisWidths.right).forEach((e,n)=>delete this.bounds[x.PANE_UUID_Y_AXIS(t,n)]),delete this.bounds[x.PANE_UUID_RESIZER(t)],this.recalculatePanesHeightRatios(),this.panesOrderChangedSubject.next(this.panesOrder)}recalculateBounds(){const t=this.canvasOnPageLocation.width,e=this.canvasOnPageLocation.height,n=this.config.components.paneResizer.height,i=this.getBounds(x.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((R,F)=>R+F,0),h=r.right.reduce((R,F)=>R+F,0),d=0,u=i.width-h,g=d+c,m=0,C=i.width-c-h;let _=m;const M=this.panesOrder.findIndex(R=>this.graphsHeightRatio[R]>0);this.panesOrder.forEach((R,F)=>{var Y;const q=this.graphsHeightRatio[this.panesOrder[F]],V=x.PANE_UUID_RESIZER(R),N=x.PANE_UUID(R),U=this.config.components.paneResizer.visible&&F>M&&q>0;U?oe(this.bounds,V,0,_,i.width,n,this.canvasOnPageLocation):oe(this.bounds,V,0,0,0,0,this.canvasOnPageLocation);const Q=_+(U?n:0),J=oe(this.bounds,N,g,Q,C,l*q-(U?n:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const st=this.yAxisBoundsContainer.extentsOrder.get(R);if(st===void 0)return;const G=l*q-(U?n:0);let nt=g-((Y=r.left[0])!=null?Y:0),ot=u;st.left.forEach((ft,at)=>{var wt;oe(this.bounds,x.PANE_UUID_Y_AXIS(R,ft),nt,Q,r.left[at],G,this.canvasOnPageLocation),nt-=(wt=r.left[at+1])!=null?wt:0}),st.right.forEach((ft,at)=>{oe(this.bounds,x.PANE_UUID_Y_AXIS(R,ft),ot,Q,r.right[at],G,this.canvasOnPageLocation),ot+=r.right[at]})}else oe(this.bounds,x.PANE_UUID_Y_AXIS(R),0,0,0,0,this.canvasOnPageLocation);_=J.y+J.height});const L=this.getBounds(x.ALL_PANES);L.x=g,L.y=m,L.width=C,L.height=_;const H=this.getBounds(x.CHART_WITH_Y_AXIS),z=this.getBounds(x.CHART);this.getEventsBounds(z),this.copyBounds(z,H),H.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=ai(Yt({},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(x.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(x.N_MAP);return this.config.components.navigationMap.visible?(e.x=0,e.y=t.height-hi,e.width=t.width,e.height=hi):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const n=this.getBounds(x.X_AXIS);if(this.config.components.xAxis.visible){const i=this.getXAxisHeight();n.x=0,n.y=e.height-i-t.height,n.width=e.width,n.height=i}else this.applyDefaultBounds(n);return n}getXAxisHeight(){var t,e;if(!this.xAxisHeight){const n=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily,i=kt(n,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)}return this.xAxisHeight}setYAxisWidths(t){(!Wn(this.yAxisWidths.left,t.left)||!Wn(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[tt];const e=[];e.push(...this.panesOrder.filter(g=>g!==tt));const n=e.map(g=>this.graphsHeightRatio[g]===void 0?void 0:this.graphsHeightRatio[g]),i=n.filter(g=>g!==0),r=i.length,o=i.filter(g=>g!==void 0).length,a=n.filter(g=>g===void 0).length;let l=0,c=0,h=1,d=0;a>0&&([h,d]=gi(r),t*=h),o===0&&(t=1-d*a),c=1-t-d*a,i.forEach(g=>{g&&(c-=g*h)}),l=c/(r||1);const u=n.map(g=>g===0?g:g?g*h+l:d+l);this._graphsHeightRatio={},this.graphsHeightRatio[tt]=t,u.forEach((g,m)=>{const C=e[m];this.graphsHeightRatio[C]=g})}recalculateNavigationMapElementBounds(){var t,e,n,i;if(!this.config.components.navigationMap.visible)return;const r=this.getBounds(x.N_MAP),{height:o,width:a}=this.config.components.navigationMap.knots,l=o!=null?o:0,c=_s()?a*di: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=G=>za(this.canvasModel.ctx,G,this.formatterFactory,this.config)[0],g=vt((i=(n=this.mainCandleSeries)==null?void 0:n.getSeriesInViewport())!=null?i:[]),m=d&&g.length?u(g[0].candle.timestamp):0,C=d&&g.length?u(g[g.length-1].candle.timestamp):0,_=Math.max(m,C);if(d){const G=this.getBounds(x.N_MAP_LABEL_L);G.x=r.x,G.y=r.y,G.width=_,G.height=r.height;const nt=this.getBounds(x.N_MAP_LABEL_R);nt.x=r.x+r.width-_,nt.y=r.y,nt.width=_,nt.height=r.height}const M=this.getBounds(x.N_MAP_BTN_L);M.x=r.x+_,M.y=r.y,M.width=Ms,M.height=r.height;const L=this.getBounds(x.N_MAP_BTN_R);L.x=r.x+r.width-Ms-_,L.y=r.y,L.width=Ms,L.height=r.height;const H=M.x+M.width,z=L.x-H,R=H+z,F=this.config.components.navigationMap.minSliderWindowWidth,Y=c!=null?c:ui,q=l!=null?l:r.height,V=Y+F,N=this.getBounds(x.N_MAP_KNOT_L);N.x=H+z*this.leftRatio,N.x=Math.min(N.x,R-V),N.y=h,N.width=Y,N.height=q;const U=this.getBounds(x.N_MAP_KNOT_R);U.x=H+z*this.rightRatio-ui,U.x=Math.max(U.x,H+V),U.y=h,U.width=Y,U.height=q;const Q=V-(U.x-N.x);Q>0&&(N.x-=Q);const J=this.getBounds(x.N_MAP_SLIDER_WINDOW);J.x=N.x+N.width,J.y=r.y,J.width=U.x-J.x,J.height=r.height;const st=this.getBounds(x.N_MAP_CHART);st.x=H,st.y=r.y,st.width=z,st.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(li),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>ai(Yt({},t),{[e]:this.bounds[x.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=Ye){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ye),e);return r?(o,a)=>{const l=this.getBounds(t);return o>l.pageX-n&&o<l.pageX+l.width+n&&a>l.pageY-i&&a<l.pageY+l.height+i}:(o,a)=>{const l=this.getBounds(t);return o>l.x-n&&o<l.x+l.width+n&&a>l.y-i&&a<l.y+l.height+i}}static hitTestOf(t,e=Ye){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ye),e);return r?(o,a)=>o>t.pageX-n&&o<t.pageX+t.width+n&&a>t.pageY-i&&a<t.pageY+t.height+i:(o,a)=>o>t.x-n&&o<t.x+t.width+n&&a>t.y-i&&a<t.y+t.height+i}isChartBoundsAvailable(){const t=this.getBounds(x.CANVAS);return t.width>0&&t.height>0}resizePaneVertically(t,e){const n=this.panesOrder.indexOf(t),i=this.getBounds(x.PANE_UUID_RESIZER(t));this.doResizePaneVertically(n,i.y-e),this.barResizerChangedSubject.next()}doResizePaneVertically(t,e){let n=t-1;const i=this.panesOrder[n];if(this._graphsHeightRatio[i]<=0)for(let d=0;d<t;d++)this._graphsHeightRatio[this.panesOrder[d]]>0&&(n=d);const r=this.getBounds(x.ALL_PANES).height,o=ci,a=r*this.graphsHeightRatio[this.panesOrder[t]],l=r*this.graphsHeightRatio[this.panesOrder[n]],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[n]]-=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 mt(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ht(n=>this.copyOf(n)),Mt((n,i)=>this.sameBounds(n,i)))}observeAnyBoundsChanged(){return this.boundsChangedSubject.asObservable()}copyOf(t){return Yt({},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(li,t)}setMainCandleSeries(t){this.mainCandleSeries=t}}const rl={0:1,1:.8,2:.6,3:.5,4:.4,5:.2},gi=s=>{var t;const e=(t=rl[s])!=null?t:.4,n=(1-e)/s;return[e,n]},Xf=(s,t)=>s.x>t.x&&s.x<t.x+t.width&&s.y>t.y&&s.y<t.y+t.height,ol=(s,t)=>s>t.y&&s<t.y+t.height,oe=(s,t,e,n,i,r,o)=>{const a=s[t];if(a)return a.x=e,a.y=n,a.pageX=e+o.x,a.pageY=n+o.y,a.width=i,a.height=r,a;const l={x:e,y:n,pageX:e+o.x,pageY:n+o.y,width:i,height:r};return s[t]=l,l},fi=(s,t)=>Math.min(Math.max(s,t.y),t.y+t.height),Ye={extensionX:0,extensionY:0,wholePage:!1},pi=(s,t)=>s.width===t.width&&s.height===t.height;var al=function(s){W(t,s);function t(e,n){return s.call(this)||this}return t.prototype.schedule=function(e,n){return n===void 0&&(n=0),this},t}(ne),je={setInterval:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=je.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,D([s,t],p(e))):setInterval.apply(void 0,D([s,t],p(e)))},clearInterval:function(s){var t=je.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(s)},delegate:void 0},mi=function(s){W(t,s);function t(e,n){var i=s.call(this,e,n)||this;return i.scheduler=e,i.work=n,i.pending=!1,i}return t.prototype.schedule=function(e,n){var i;if(n===void 0&&(n=0),this.closed)return this;this.state=e;var r=this.id,o=this.scheduler;return r!=null&&(this.id=this.recycleAsyncId(o,r,n)),this.pending=!0,this.delay=n,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,n),this},t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),je.setInterval(e.flush.bind(e,this),i)},t.prototype.recycleAsyncId=function(e,n,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return n;n!=null&&je.clearInterval(n)},t.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(e,n);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(e,n){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,n=e.id,i=e.scheduler,r=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,Ae(r,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,s.prototype.unsubscribe.call(this)}},t}(al),me={schedule:function(s){var t=requestAnimationFrame,e=cancelAnimationFrame,n=me.delegate;n&&(t=n.requestAnimationFrame,e=n.cancelAnimationFrame);var i=t(function(r){e=void 0,s(r)});return new ne(function(){return e==null?void 0:e(i)})},requestAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=me.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,D([],p(s)))},cancelAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=me.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,D([],p(s)))},delegate:void 0},ll=function(s){W(t,s);function t(e,n){var i=s.call(this,e,n)||this;return i.scheduler=e,i.work=n,i}return t.prototype.requestAsyncId=function(e,n,i){return i===void 0&&(i=0),i!==null&&i>0?s.prototype.requestAsyncId.call(this,e,n,i):(e.actions.push(this),e._scheduled||(e._scheduled=me.requestAnimationFrame(function(){return e.flush(void 0)})))},t.prototype.recycleAsyncId=function(e,n,i){var r;if(i===void 0&&(i=0),i!=null?i>0:this.delay>0)return s.prototype.recycleAsyncId.call(this,e,n,i);var o=e.actions;n!=null&&((r=o[o.length-1])===null||r===void 0?void 0:r.id)!==n&&(me.cancelAnimationFrame(n),e._scheduled=void 0)},t}(mi),Es={now:function(){return(Es.delegate||Date).now()},delegate:void 0},vi=function(){function s(t,e){e===void 0&&(e=s.now),this.schedulerActionCtor=t,this.now=e}return s.prototype.schedule=function(t,e,n){return e===void 0&&(e=0),new this.schedulerActionCtor(this,t).schedule(n,e)},s.now=Es.now,s}(),bi=function(s){W(t,s);function t(e,n){n===void 0&&(n=vi.now);var i=s.call(this,e,n)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(e){var n=this.actions;if(this._active){n.push(e);return}var i;this._active=!0;do if(i=e.execute(e.state,e.delay))break;while(e=n.shift());if(this._active=!1,i){for(;e=n.shift();)e.unsubscribe();throw i}},t}(vi),cl=function(s){W(t,s);function t(){return s!==null&&s.apply(this,arguments)||this}return t.prototype.flush=function(e){this._active=!0;var n=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===n&&i.shift());if(this._active=!1,r){for(;(e=i[0])&&e.id===n&&i.shift();)e.unsubscribe();throw r}},t}(bi),Ne=new cl(ll),zf=null,Ci=new bi(mi),hl=Ci;function dl(s,t){return j(function(e,n){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,g=function(){d==null||d.unsubscribe(),d=null,l&&(_(),u&&n.complete())},m=function(){d=null,u&&n.complete()},C=function(M){return d=Ft(s(M)).subscribe(Tt(n,g,m))},_=function(){if(c){c=!1;var M=h;h=null,n.next(M),!u&&C(M)}};e.subscribe(Tt(n,function(M){c=!0,h=M,!(d&&!d.closed)&&(o?_():C(M))},function(){u=!0,!(l&&c&&d&&!d.closed)&&n.complete()}))})}function ul(s){return s instanceof Date&&!isNaN(s)}function gl(s,t,e){s===void 0&&(s=0),e===void 0&&(e=hl);var n=-1;return t!=null&&(Bn(t)?e=t:n=t),new pt(function(i){var r=ul(s)?+s-e.now():s;r<0&&(r=0);var o=0;return e.schedule(function(){i.closed||(i.next(o++),0<=n?this.schedule(void 0,n):i.complete())},r)})}function Xe(s,t,e){t===void 0&&(t=Ci);var n=gl(s,t);return dl(function(){return n},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 fl extends X{constructor(t,e,n,i){super(),this.element=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.hitTestCanvasModel=i,this.normalLayer=new Map,this.extensionLayer=new Map,this.cursorChangedSubject=new O}doActivate(){super.doActivate(),this.canvasInputListener.observeMouseMoveNoDrag().pipe(Xe(100,Ne,{trailing:!0})).subscribe(t=>{const e=this.hitTestCanvasModel.resolveCursor(t);if(e!==void 0){this.updateCursor(e);return}t&&(this.normalLayer.forEach(n=>{n.hitTest(t.x,t.y)&&this.updateCursor(n.cursor)}),this.extensionLayer.forEach(n=>{n.hitTest(t.x,t.y)&&this.updateCursor(n.cursor)}))})}setCursorForBounds(t,e,n,i=0){const r=As.hitTestOf(e,{extensionY:i});i?this.extensionLayer.set(t,{cursor:n,hitTest:r}):this.normalLayer.set(t,{cursor:n,hitTest:r})}setCursorForCanvasEl(t,e,n){this.observeCursorType(t,e,n)}removeCursorForCanvasEl(t){this.normalLayer.delete(t),this.extensionLayer.delete(t)}observeCursorChanged(){return this.cursorChangedSubject.pipe(Mt())}observeCursorType(t,e,n){const i=n?this.canvasBoundsContainer.getBoundsHitTest(t,{extensionY:n}):this.canvasBoundsContainer.getBoundsHitTest(t);n?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 pl=s=>{const t=s.canvasArea!==null,e=s.snapshotCanvas!==null,n=s.backgroundCanvas!==null,i=s.mainCanvas!==null,r=s.yAxisLabelsCanvas!==null,o=s.crossToolCanvas!==null,a=s.hitTestCanvas!==null,l=s.chartResizer!==null,c=s.chartContainer!==null,h=s.dynamicObjectsCanvas!==null;return t&&e&&n&&i&&r&&o&&a&&l&&c&&h},ml=s=>`<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
- <canvas data-element="snapshotCanvas" style="z-index: 0"></canvas>
13
- <canvas data-element="backgroundCanvas" style="z-index: 1"></canvas>
14
- <canvas data-element="mainCanvas" style="z-index: 2"></canvas>
15
- <canvas data-element="dynamicObjectsCanvas" style="z-index: 3"></canvas>
16
- <canvas data-element="yAxisLabelsCanvas" style="z-index: 4"></canvas>
17
- <canvas data-element="crossToolCanvas" style="z-index: 5"></canvas>
18
- <canvas data-element="hitTestCanvas" style="z-index: 6"></canvas>
12
+ <canvas data-element="snapshotCanvas"></canvas>
13
+ <canvas data-element="backgroundCanvas"></canvas>
14
+ <canvas data-element="mainCanvas"></canvas>
15
+ <canvas data-element="yAxisLabelsCanvas"></canvas>
16
+ <canvas data-element="dynamicObjectsCanvas"></canvas>
17
+ <canvas data-element="crossToolCanvas"></canvas>
18
+ <canvas data-element="hitTestCanvas"></canvas>
19
19
  ${s?` <p style="position: absolute; visibility: hidden;">If you have any suggestions or are experiencing any issues, please feel free to contact us at <a href="https://devexperts.com/dxcharts/">devexperts.com</a></p>
20
20
  `:""} </div>
21
21
  </div>
22
22
  </div>
23
- `;function bl(s){const t=document.createElement("template");return t.innerHTML=vl(s.devexpertsPromoLink),t}function Cl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),ml(t))return t;throw new Error("Some chart elements are missing")}function yl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const ve=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=re(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=bt(e))==null?void 0:o.timestamp)!=null?a:0;return s>c?t?{index:e.length-1+Math.ceil((s-c)/n),exact:!0}:{index:e.length-1,exact:!0}:s<l?t?{index:et((s-l)/n),exact:!0}:{index:-1,exact:!0}:Lt(e,s,h=>h.timestamp)},Ds=1;function Xe(s,t){return t===s?"none":t>s?"up":"down"}function wl(s,t){return t>s?"up":"down"}function Sl(s,t,e=!1){const{expansion:n,impVolatility:i,vwap:r,volume:o,timestamp:a}=s;let l=s.hi,c=s.lo,h=s.open;const d=s.close;e&&(l=d,c=d,h=d);let u=s.idx;return t!==void 0&&(u=t),{hi:l,lo:c,open:h,close:d,timestamp:a,volume:o,expansion:n,idx:u,impVolatility:i,vwap:r}}const yi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2},wi={paintConfig:[yi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var xl=Object.defineProperty,Si=Object.getOwnPropertySymbols,_l=Object.prototype.hasOwnProperty,Pl=Object.prototype.propertyIsEnumerable,xi=(s,t,e)=>t in s?xl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Tl=(s,t)=>{for(var e in t||(t={}))_l.call(t,e)&&xi(s,e,t[e]);if(Si)for(var e of Si(t))Pl.call(t,e)&&xi(s,e,t[e]);return s};class Ml{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=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:[Tl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:yi).color;return{textColor:qt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}let Bt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Is=()=>{ze.removeEventListener("change",Is),Bt=window.devicePixelRatio,ze=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),ze.addEventListener("change",Is)};ze.addEventListener("change",Is);const Al=()=>Bt,El=s=>Kt(Bt*s)/Bt,Z=s=>et(Bt*s)/Bt,_i=s=>va(Bt*s)/Bt,We=s=>JSON.parse(JSON.stringify(s));function Ls(s){return Object.entries(s)}const Pi=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Ti(s){return Object.keys(s)}function Mi(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Mi(s[e[i]],t[e[i]]))return!1;return!0}function Ai(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new O}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,g=0,m=!1,C=!1,_=function(){d==null||d.unsubscribe(),d=void 0},M=function(){_(),h=u=void 0,m=C=!1},L=function(){var H=h;M(),H==null||H.unsubscribe()};return j(function(H,z){g++,!C&&!m&&_();var R=u=u!=null?u:e();z.add(function(){g--,g===0&&!C&&!m&&(d=Bs(L,l))}),R.subscribe(z),!h&&g>0&&(h=new ge({next:function(F){return R.next(F)},error:function(F){C=!0,_(),d=Bs(M,i,F),R.error(F)},complete:function(){m=!0,_(),d=Bs(M,o),R.complete()}}),Ft(H).subscribe(h))})(c)}}function Bs(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new ge({next:function(){i.unsubscribe(),s()}});return Ft(t.apply(void 0,D([],p(e)))).subscribe(i)}}const Ue=(s,t)=>s/t,ut=(s,t)=>s/t,jt=(s,t)=>s*t,Ei=(s,t)=>(s-t)*100/t,Di=(s,t)=>s*t/100+t,Ii=s=>Math.log2(s),Os=s=>Math.pow(2,s);class Dl 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 O,this.xChanged=this.changed.pipe(ht(()=>({start:this.xStart,end:this.xEnd})),Mt((t,e)=>t.start===e.start&&t.end===e.end),Ai()),this.yChanged=this.changed.pipe(ht(()=>({start:this.yStart,end:this.yEnd})),Mt((t,e)=>t.start===e.start&&t.end===e.end),Ai())}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ut(t-this.xStart,this.zoomX)}xPixels(t){return ut(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ut(t-this.yStart,this.zoomY):e.y+e.height-ut(t-this.yStart,this.zoomY)}yPixels(t){return ut(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return jt(e+ut(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?jt(n+ut(this.yStart,this.zoomY),this.zoomY):jt(e.height-n+ut(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 Ue(e-t,this.getBounds().width)}calculateZoomY(t,e){return Ue(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&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(){return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&this.zoomX>0&&this.zoomY>0}}const Il=(s,t)=>!Ti(s).some(e=>s[e]!==t[e]);class Ll{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;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(Lt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Lt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class Li{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,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 Ll(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ei(t,n);case"logarithmic":return Ii(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 Di(t,this.getBaseline());case"logarithmic":return Os(t);case"regular":return t}}}var Bl=Object.defineProperty,Ol=Object.defineProperties,Rl=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,Fl=Object.prototype.hasOwnProperty,Hl=Object.prototype.propertyIsEnumerable,Oi=(s,t,e)=>t in s?Bl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,kl=(s,t)=>{for(var e in t||(t={}))Fl.call(t,e)&&Oi(s,e,t[e]);if(Bi)for(var e of Bi(t))Hl.call(t,e)&&Oi(s,e,t[e]);return s},Yl=(s,t)=>Ol(s,Rl(t));class be{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Z(t.toY(this.close))}x(t){return Z(t.toX(this.centerUnit))}clone(){return new be(this.centerUnit,this.close)}}class Ri extends X{constructor(t,e,n,i=We(wi)){var r;super(),this.extentComponent=t,this.id=e,this.htId=n,this.name="",this.hovered=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=o=>{var a;return(a=this.config.paintConfig[o])!=null?a:this.config.paintConfig[0]},this.getBaseline=(o=this.dataIdxStart)=>{var a,l;return(l=(a=this.visualPoints[o])==null?void 0:a.close)!=null?l:1},this.getTextForPoint=o=>`${o.close}`,this.getLastVisualSeriesPoint=()=>{const o=this.visualPoints,a=Lt(o,this.scale.xEnd,l=>l.centerUnit).index;return o[a]},this.getLastDataSeriesPoint=()=>{const o=this.visualPoints;return bt(o)},this.config=At(i,wi),this.scale=t.scale,this.view=new Li(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Ml(this,this.config,t.getYAxisBounds,(r=t.yAxis)==null?void 0:r.state),this.highLowProvider=Nl(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Un(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=Un(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new Li(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,this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,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:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=Lt(this.visualPoints,t,r=>r.centerUnit).index,i=Lt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return Fi(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Oa(this.visualPoints2D,n,i)}}const jl=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},Nl=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=jl(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return Yl(kl({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),Fi=s=>{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))))(s);return dt.makeDecimal(s,i)};class Ve extends be{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Z(Math.abs(t.toY(this.open)-t.toY(this.close)))}candleHeight(t){return Z(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=Z(t.toY(this.high)),n=Z(t.toY(this.low)),i=Z(t.toY(this.open)),r=Z(t.toY(this.close)),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Z(Math.max(t.toY(this.high),t.toY(this.low)))}yLineStart(t){return Z(Math.min(t.toY(this.high),t.toY(this.low)))}yBodyStart(t){return Z(Math.min(t.toY(this.open),t.toY(this.close)))}yBodyEnd(t){return Z(Math.max(t.toY(this.open),t.toY(this.close)))}xCenter(t){return this.x(t)}xStart(t){return El(t.toX(this.startUnit))}}const ae=60,Ce=(s,t,e=ae)=>({hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:Hi(s,t,e),volume:NaN,expansion:!0,idx:t}),Xl=(s,t,e=ae)=>({close:NaN,timestamp:Hi(s,t,e)});function Hi(s,t,e=ae){var n,i;const r=Kt(t);if(s.length===0)return 0;const o=bt(s);if(r>=s.length&&o)return ki(o,s.length-1,r,e);const a=re(s);return r<0&&a?ki(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const ki=(s,t,e,n=ae)=>s.timestamp+(e-(t!=null?t:0))*n,Yi=(s,t,e,n,i=ae)=>{const r=Ce(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Ve(o,e,r.open,r.close,r.lo,r.hi,Xe(r.open,r.close),r)},zl=(s,t,e,n,i=ae)=>{const r=Xl(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new be(o,r.close)};class Wl{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new O,this.dataSetSubject=new O,this.dataRemovedSubject=new O,this.dataPrependSubject=new O,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e=!0,n=this.mainDataPoints){const i=ve(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=yl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Yi(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):zl(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Ul=Object.defineProperty,ji=Object.getOwnPropertySymbols,Vl=Object.prototype.hasOwnProperty,Gl=Object.prototype.propertyIsEnumerable,Ni=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zl=(s,t)=>{for(var e in t||(t={}))Vl.call(t,e)&&Ni(s,e,t[e]);if(ji)for(var e of ji(t))Gl.call(t,e)&&Ni(s,e,t[e]);return s};class $l{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={}}draw(){if(this.drawPredicate()||!Mi(this.config.colors.chartAreaTheme,this.prevState)){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=Zl({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const Kl=(s,t,e,n,i,r,o)=>{const a=Al(),l=[e*a,n*a,i*a,r*a];let c=s.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]=et(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?et(u*o):et(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Xi=(s,{x:t,width:e,activeCandle:n})=>new Ve(t,e,s.open,s.close,s.hi,s.lo,Xe(s.open,s.close),s,!0,Rs(s,n)),ql=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ve(t,e,s.open,s.close,s.hi,s.lo,wl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},zi=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ve(t,e,s.open,s.close,s.hi,s.lo,Xe((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},Jl=zi,Rs=(s,t)=>{const e=t&&t.idx===s.idx;return e!=null?e:!1},Wi=()=>Ds,Qt=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>et(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=Qt.getPriceIncrement(e||s,t);return dt.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=Qt.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*Qt.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<Qt.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*Qt.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return Qt.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Ot=Qt;Ot.DEFAULT_INCREMENT=.01,Ot.DEFAULT_PRECISION=2,Ot.RELATIVE_EPS=1e-8,Ot.MAXIMUM_PRECISION=10;const Ql=(s,t)=>{var e;const n=(e=bt(t))!=null?e:1;return Math.pow(10,-n)};var tc=Object.defineProperty,ec=Object.defineProperties,sc=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,nc=Object.prototype.hasOwnProperty,ic=Object.prototype.propertyIsEnumerable,Vi=(s,t,e)=>t in s?tc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,rc=(s,t)=>{for(var e in t||(t={}))nc.call(t,e)&&Vi(s,e,t[e]);if(Ui)for(var e of Ui(t))ic.call(t,e)&&Vi(s,e,t[e]);return s},oc=(s,t)=>ec(s,sc(t));const ac=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Gi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return oc(rc({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Gi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},lc=20,Zi=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:lc,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},Re,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class cc{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){hc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const hc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=$i(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function $i(s){if(s.length===0)return dc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const dc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER});var uc=Object.defineProperty,Ki=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,fc=Object.prototype.propertyIsEnumerable,qi=(s,t,e)=>t in s?uc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ji=(s,t)=>{for(var e in t||(t={}))gc.call(t,e)&&qi(s,e,t[e]);if(Ki)for(var e of Ki(t))fc.call(t,e)&&qi(s,e,t[e]);return s};const pc=(s,t,e,n)=>{var i,r,o,a;const l=Ji({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ra(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-jt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},mc=(s,t,e,n)=>{const i=Ji({},t),r=n(),o=i.xEnd-i.xStart,a=o<e.minCandles,l=r.width/e.minWidth,c=o>l;if(r.width>0){if(c)return i.xStart=i.xEnd-l,i.zoomX=Ue(i.xEnd-i.xStart,r.width),{newState:i,maxZoomReached:{zoomOut:!0,zoomIn:!1}};if(a)return i.xStart=i.xEnd-e.minCandles,i.zoomX=Ue(i.xEnd-i.xStart,r.width),{newState:i,maxZoomReached:{zoomOut:!1,zoomIn:!0}}}return{newState:i,maxZoomReached:{zoomOut:!1,zoomIn:!1}}},vc=(s,t)=>s/t,bc=(s,t)=>s/t,Cc=(s,t)=>s*t,Qi=(s,t)=>{const e=s.zoomY;s.zoomY=bc(s.zoomX,t);const n=s.zoomY/e,i=s.yEnd-s.yStart,o=i*n-i;s.yEnd=s.yEnd+o/2,s.yStart=s.yStart-o/2},yc=(s,t)=>{const e=s.zoomX;s.zoomX=Cc(s.zoomY,t);const n=s.zoomX/e,i=s.xEnd-s.xStart,o=i*n-i;s.xStart=s.xStart-o},wc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},Sc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},tr=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,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=s.calculateZoomX(t.xStart,t.xEnd),t},xc=(s,t,e,n)=>tr(s,t,1,e,n);var _c=Object.defineProperty,Pc=Object.defineProperties,Tc=Object.getOwnPropertyDescriptors,er=Object.getOwnPropertySymbols,Mc=Object.prototype.hasOwnProperty,Ac=Object.prototype.propertyIsEnumerable,sr=(s,t,e)=>t in s?_c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ye=(s,t)=>{for(var e in t||(t={}))Mc.call(t,e)&&sr(s,e,t[e]);if(er)for(var e of er(t))Ac.call(t,e)&&sr(s,e,t[e]);return s},Ec=(s,t)=>Pc(s,Tc(t));const Dc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class nr extends Dl{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new O,this.beforeStartAnimationSubject=new O,this.history=[],this.zoomXYRatio=0,this.xConstraints=[],this.maxZoomReached={zoomIn:!1,zoomOut:!1},this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=We(t.scale),this.autoScaleModel=new cc(this),this.offsets=this.config.components.offsets,this.addXConstraint((i,r)=>{const{maxZoomReached:o,newState:a}=mc(i,r,this.config.components.chart,this.getBounds);return this.maxZoomReached=o,a})}doActivate(){super.doActivate(),this.scaleInversedSubject=new O,this.beforeStartAnimationSubject=new O,this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=ye(ye({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();tr(this,o,t,i,e),this.zoomXTo(o,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();xc(this,n,e,t),this.zoomXTo(n,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e){const n=ye({},t),i=this.scalePostProcessor(n,t);this.state.lockPriceToBarRatio&&Qi(i,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(i),e?this.apply(i):Zi(this.canvasAnimation,this,i)}isMaxZoomXReached(t){return this.maxZoomReached.zoomIn&&t||this.maxZoomReached.zoomOut&&!t}setXScale(t,e,n=!0){const i=this.export(),r=this.calculateZoomX(t,e),o=Ec(ye({},i),{zoomX:r,xStart:t,xEnd:e}),a=this.scalePostProcessor(i,o);this.state.lockPriceToBarRatio&&Qi(a,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(a),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(a)):Zi(this.canvasAnimation,this,a)}setYScale(t,e,n=!1){const i=this.export();super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);if(this.state.lockPriceToBarRatio){yc(o,this.zoomXYRatio),this.setXScale(o.xStart,o.xEnd);return}else this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}moveXStart(t){const e=this.export(),n=ye({},e);this.haltAnimation(),wc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Sc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Il(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}t&&this.recalculateZoomXYRatio(),this.state.lockPriceToBarRatio=t}recalculateZoomXYRatio(){this.zoomXYRatio=vc(this.zoomX,this.zoomY)}}class Ic extends nr{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}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 Lc=He().colors;class Wt extends Ri{constructor(t,e,n,i,r,o,a,l,c=Lc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Dc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new O,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=ac(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=Ot.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const n=Lt(this.visualPoints,t,r=>r.startUnit).index,i=Lt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=bt(this.dataPoints);t&&(this.lastPriceMovement=Xe(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Gi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd))}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=At(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Wi;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),g=a+u/2,m=(i=this.candlesTransformersByChartType[r])!=null?i:Xi;o.push(m(h,{x:g,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ds}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 Vf(s){switch(s){case"line":case"area":return!0;default:return!1}}class Bc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);if(r.length===0)return;i.singleColor?t.strokeStyle=i.singleColor:t.strokeStyle=n.colors.areaTheme.lineColor,n.hovered?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const o=n.extentComponent.getBounds(),a=r[0],l=n.view.toX(a.centerUnit);for(let c=0;c<r.length;c++){const h=r[c-1],d=r[c+1],u=r[c],g=n.view.toX(u.centerUnit),m=n.view.toY(u.close),C=o.y+o.height;if(h===void 0)t.beginPath(),t.lineTo(et(g),C),t.moveTo(et(g),m);else if(d===void 0){t.lineTo(et(g),m),t.stroke(),t.lineTo(et(g),C),t.lineTo(et(l),C),t.closePath();let _;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(_=t.createLinearGradient(0,0,0,o.height),_.addColorStop(0,n.colors.areaTheme.startColor),_.addColorStop(1,n.colors.areaTheme.stopColor),_):"",t.fill()}else t.lineTo(et(g),m)}}}}function ir(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Oc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const g=c==="right"?a:-a,m=c==="right"?h:-h,C=h;s.save(),s.beginPath(),l?s.moveTo(r+m,o):s.moveTo(r,o),l?(s.lineTo(r+g-m,o),s.quadraticCurveTo(r+g,o,r+g,o-C),s.lineTo(r+g,e+C),s.quadraticCurveTo(r+g,e,r+g-m,e),s.lineTo(t+m,e)):(s.lineTo(r+g,o),s.lineTo(r+g,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-m/3,e+C/3),s.lineTo(n+m/3,i-C/3),s.quadraticCurveTo(n,i,n+m/3,i+C/3),s.lineTo(r-m/3,o-C/3),s.quadraticCurveTo(r,o,r+m/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Rc(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function te(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function rr(s,t,e){const n=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);s.fillRect(n,i,r,o)}const Ut=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Gf=s=>Array.isArray(s[0])?s:[s];class Fc{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Ut(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);r&&r.length>=1&&i.draw(t,r,e,{})}else console.error(`Data series drawer with type ${n} isn't registered!`)}}}const le=(s,t,e,n,i=t)=>{n.forceBold?s.lineWidth=n.forceBold:e.hovered?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Hc{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.singleColor)t.strokeStyle=e.singleColor;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.barLineWidth,n,i),te(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=Z(n.view.toX(o.centerUnit)),l=Z(n.view.toX(o.startUnit)),[c,h,d,u]=o.yBodyKeyPoints(n.view),g=Z(n.view.xPixels(o.width)/2),m=Z(n.view.toY(o.close)),C=Z(n.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,m),t.lineTo(a+g,m),t.moveTo(l,C),t.lineTo(a,C),t.stroke()}})}}}class kc{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Wt){const r=vt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.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],g=r[h+1],m=n.view.toX(c.centerUnit),C=n.view.toX(d.centerUnit),_=n.view.toY(d.close),M=u?n.view.toY(u.close)<l:!1,L=_<l;if(u!==void 0&&M!==L){or(t,n,i,M);const H=n.view.toX(u.centerUnit),z=n.view.toY(u.close),R=C-H,F=_-z,Y=R/F,q=_-l,V=Y*q,N=H+(R-V);t.lineTo(N,l),t.stroke(),t.lineTo(m,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(N,l)}u===void 0?(t.beginPath(),t.moveTo(C,_)):g===void 0?(or(t,n,i,L),t.lineTo(C,_),t.stroke(),t.lineTo(C,l),t.lineTo(m,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(m,l),t.lineTo(C,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(C,_)}}}}const or=(s,t,e,n)=>{e.singleColor?(s.fillStyle=e.singleColor,s.strokeStyle=e.singleColor):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Yc{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),te(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.singleColor?t.fillStyle=e.singleColor:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=Z(n.view.toX(i.startUnit)),d=Z(n.view.xPixels(i.width)),u=i.bodyHeight(n.view),[g,m,C,_]=i.yBodyKeyPoints(n.view),M=m===C?m+1:C,L=g===_?g+1:_,H=l[`${a}Color`],z=a==="none"?H:l[`${a}WickColor`];t.fillStyle=H,e.singleColor?t.strokeStyle=e.singleColor:t.strokeStyle=z;const R=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),F=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,F?g:m),t.lineTo(h,F?L:M),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,F?g:m),t.lineTo(h,F?L:M),t.moveTo(h+1,m),t.lineTo(h+1,M),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,g,L,m,M),c||(t.beginPath(),t.moveTo(h+Y,m),t.lineTo(h+Y,M),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,m+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,g,L,m,M-1);const q=this.config.candlePaddingPercent,V=Math.max(Z(d*q/2),this.pixelLength),N=h+V,U=d-V*2;c||(e.singleColor&&(t.fillStyle=e.singleColor),t.fillRect(N,m,U,u)),R&&this.drawCandleBorder(t,e,l,i,N+this.halfLineWidthCU,m+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.singleColor)t.strokeStyle=e.singleColor;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class jc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),g=Z(n.view.toY(l.close)),m=Z(n.view.xPixels(l.width));t.fillRect(u,g,m,h);const C=t.createLinearGradient(0,g+h,0,a);i.singleColor?t.fillStyle=i.singleColor:(C.addColorStop(0,d[`${c}Cap`]),C.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=C),m===0?(t.beginPath(),t.strokeStyle=C,t.moveTo(u,g+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,g+h,m,a-g-h)}}}}class Nc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.singleColor&&(t.strokeStyle=i.singleColor);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.singleColor||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),g=n.view.toX(c.centerUnit),m=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(g,m),t.stroke()}}}}const Xc=1.5;class zc{constructor(t){this.config=t}draw(t,e,n,i){var r;t.fillStyle=(r=i.singleColor)!=null?r:this.config.mainColor;for(const o of vt(e)){t.beginPath();const a=Z(n.view.toX(o.centerUnit)),l=Z(n.view.toY(o.close));t.arc(a,l,Xc,0,Math.PI*2,!0),t.fill()}}}const Wc=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Uc{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Ut(t,this.chartBounds())}isChartTypeAllowed(){return Wc.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Ut(t,e.scale.getBounds())}}class Vc{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(Kt(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,g=Z(ut(h.width,u)),m=Z(h.bodyHeight(this.chartModel.scale)),C=h.xCenter(this.chartModel.scale)-g/2,_=h.yBodyStart(this.chartModel.scale),M=this.chartModel.config.components.chart.candlePaddingPercent,L=Z(g*M/2),H=C+L,z=g-L*2;t.fillRect(H,_,z,m)}})})}}const ar=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{const{centerUnit:r,close:o}=n,a=e.toX(r),l=e.toY(o);i===0?t.moveTo(a,l):t.lineTo(a,l)})},Gc=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Zc=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i;function $c(s){const t=Gc.exec(s)||Zc.exec(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const lr={};function Kc(s,t){let e=lr[s+t];if(!e){const n=$c(s);e=n&&"rgba("+n.join(",")+","+t+")",lr[s+t]=e}return e}class qc{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);le(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.singleColor)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(hr(r.config.type)&&hr(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{const g=Math.min(d.length,h[u].length);for(let _=0;_<g;_++){const M=[d[_].clone(),h[u][_].clone()];a.push({diffPoints:M})}const m=l.getPaintConfig(u).color,C=r.getPaintConfig(o).color;this.drawDifference(t,m,C,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),ar(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[g,m]=u.diffPoints;l.push(g),c.push(m)});const h=cr(l,r.view),d=cr(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=re(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=bt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,g)=>{g===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.singleColor?r.singleColor:Kc(e||"#383838",.3),t.fill(),t.restore()}}const cr=(s,t)=>s.map(e=>{const{centerUnit:n,close:i}=e,r=t.toX(n),o=t.toY(i);return{x:r,y:o}}),hr=s=>s==="DIFFERENCE";class Jc{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);le(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.singleColor)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,et(r)),t.lineTo(d,et(u))}),t.stroke()})}}class Qc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);le(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.singleColor)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),ar(e,t,n),t.stroke()}}class th{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=l.lineWidth;t.fillStyle=(a=i.singleColor)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class eh{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=Pt(d,t,c),g=kt(c,t),m=n.view.toX(h.centerUnit)-u/2,C=n.view.toY(h.close)+g;t.fillText(d,m,C)})}),t.restore()}}class sh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const Fs="resized_local",Ge="draw",Zf="draw_last_candle",ce={width:20,height:20};class dr{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Hs;var a;i.push(this),this.parent=rh(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:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,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 n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ce.width&&this.height>ce.height}}const Hs={name:"candle"},nh={candle:Hs,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function ih(s,t,e,n,i,r,o){var a;const l=he(s,t,i,r,o,e);return l.type=(a=nh[n])!=null?a:Hs,l}function he(s,t,e,n,i,r,o){const a=new dr(s,t,n,i,r,o);return ur(a,e),a}function ur(s,t){const e=s.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",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function rh(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}let ks=!1,Ys=0;const Ze=new Map,js=new Map,gr=()=>{ks||(ks=!0,Ys=requestAnimationFrame(()=>{js.forEach((s,t)=>{s(),js.delete(t)}),Ze.forEach((s,t)=>{s(),Ze.delete(t)}),ks=!1}))},fr=(s,t)=>{Ze.set(s,t),gr()},Jf=s=>{Ze.delete(s)},Ns=(s,t)=>{js.set(s,t),gr()},$e="HIT_TEST_",Qf=null;class oh{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${_t()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf($e)!==-1&&this.drawersMap[n].draw()})},t.on(Ge,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),fr(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf($e)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf($e)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Ia(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ce.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ce.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=_t()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);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 n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=zn(this.drawingOrder,t)}}class pr{static paneResizer(t){return`PANE_RESIZER_${t}`}}class ah{constructor(t,e,n,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Ut(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={singleColor:this.canvasModel.idToColor(e.htId),forceBold:7};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const mr={dragPredicate:()=>!0};class vr extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,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 Ke extends vr{constructor(t,e,n,i,r=mr){super(t,e,n,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 lh="BASELINE_RESIZER";class ch extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=n,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.baselineYPercents=50,this.ht=As.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>this.chartPanComponent.deactivatePanHandlers(),this.dragEndCb=()=>this.chartPanComponent.activateChartPanHandlers(),this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&al(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new Ke(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.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(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[lh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const qe=s=>{var t;const e=fe(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=fe(s.hi,Math.max(s.open,s.close),e),i=fe(s.lo,Math.min(s.open,s.close),e),r=fe(s.open,s.lo,e),o=fe(s.close,s.hi,e);return{hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility}},Xs=s=>{for(let t=0;t<s.length;++t)s[t].idx=t},br=s=>{s.forEach(t=>{t.idx=void 0})};class hh{constructor(){}draw(t,e,n){const i=n.view.toY(0),r=vt(e),o=n.getPaintConfig(0);r.forEach((a,l)=>{var c,h;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(a.close<this.previousValue(r,l)?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF",t.lineWidth=o.lineWidth,t.beginPath();const g=n.view.toX(a.centerUnit),m=n.view.toY(a.close);t.moveTo(g,et(i)),t.lineTo(g,et(m)),t.stroke();return}if(((h=o.multiplyColors)==null?void 0:h.length)===4){const g=this.previousValue(r,l);a.close<g&&a.close<0&&(t.strokeStyle=o.multiplyColors[0]||o.color||"#FF00FF"),a.close>g&&a.close<0&&(t.strokeStyle=o.multiplyColors[1]||o.color||"#FF00FF"),a.close<g&&a.close>0&&(t.strokeStyle=o.multiplyColors[2]||o.color||"#FF00FF"),a.close>g&&a.close>0&&(t.strokeStyle=o.multiplyColors[3]||o.color||"#FF00FF"),t.lineWidth=o.lineWidth,t.beginPath();const m=n.view.toX(a.centerUnit),C=n.view.toY(a.close);t.moveTo(m,et(i)),t.lineTo(m,et(C)),t.stroke();return}t.strokeStyle=o.color||"#FF00FF",t.lineWidth=o.lineWidth,t.beginPath();const d=n.view.toX(a.centerUnit),u=n.view.toY(a.close);t.moveTo(d,et(i)),t.lineTo(d,et(u)),t.stroke()})}previousValue(t,e){do e--;while(e>=0&&!isFinite(t[e]&&t[e].close));return t[e]?t[e].close:Number.NaN}}var dh=Object.defineProperty,Cr=Object.getOwnPropertySymbols,uh=Object.prototype.hasOwnProperty,gh=Object.prototype.propertyIsEnumerable,yr=(s,t,e)=>t in s?dh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fh=(s,t)=>{for(var e in t||(t={}))uh.call(t,e)&&yr(s,e,t[e]);if(Cr)for(var e of Cr(t))gh.call(t,e)&&yr(s,e,t[e]);return s};class ph{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class mh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=g,this.chartResizeHandler=m,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new mt(!0),this.strToBarType=_=>{var M;return(M=this.barTypeValues.find(L=>L===_))!=null?M:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new ch(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const C=new ah(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(C,$e+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new $l(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(tt),n.components.chart.cursor),this.dataSeriesDrawer=new Fc(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,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!1)})),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Xi),this.registerCandlesTransformer("trend",zi),this.registerCandlesTransformer("hollow",ql),this.registerCandlesTransformer("line",Jl)}get barTypeValues(){return Ti(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 Yc(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Hc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Nc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new zc(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Bc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new kc(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new jc(this.config.components.chart.histogram));const e=x.PANE_UUID(tt),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new Qc),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Jc),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new hh),this.registerDataSeriesTypeDrawer("POINTS",new th),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Uc(new Vc(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new eh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new sh),this.registerDataSeriesTypeDrawer("DIFFERENCE",new qc)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(fh({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return br(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n: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)}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||!Ot.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Ot.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}}class wr extends Wt{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,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}}const vh=s=>t=>{if(t.length!==0){const e=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),n=e[0],i=e[e.length-1];s.setXScale(n.startUnit,i.startUnit+i.width+s.offsets.right),s.doAutoScale(!0),s.recalculateZoomXYRatio(),s.fireChanged()}},bh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var Ch=Object.defineProperty,yh=Object.defineProperties,wh=Object.getOwnPropertyDescriptors,Sr=Object.getOwnPropertySymbols,Sh=Object.prototype.hasOwnProperty,xh=Object.prototype.propertyIsEnumerable,xr=(s,t,e)=>t in s?Ch(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,we=(s,t)=>{for(var e in t||(t={}))Sh.call(t,e)&&xr(s,e,t[e]);if(Sr)for(var e of Sr(t))xh.call(t,e)&&xr(s,e,t[e]);return s},zs=(s,t)=>yh(s,wh(t));class _h{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,n)=>zs(we({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=zs(we({},We(this.config.colors)),{lineTheme:we({},n.lineTheme),areaTheme:we({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=zs(we({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Ph=Object.defineProperty,_r=Object.getOwnPropertySymbols,Th=Object.prototype.hasOwnProperty,Mh=Object.prototype.propertyIsEnumerable,Pr=(s,t,e)=>t in s?Ph(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Je=(s,t)=>{for(var e in t||(t={}))Th.call(t,e)&&Pr(s,e,t[e]);if(_r)for(var e of _r(t))Mh.call(t,e)&&Pr(s,e,t[e]);return s};class Ah extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,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 O,this.mainInstrumentChangedSubject=new O,this.offsetsChanged=new O,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new _h(this.config);const d=new wr(this.chartBaseModel,this.paneManager.panes[tt].mainExtent,_t(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new ph,this.candlesTransformersByChartType,this.candleWidthByChartType,Je({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),o.addXConstraint((u,g)=>pc(g,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=vh(o),this.timeFrameViewportTransformer=bh(o,this),this.pane=this.paneManager.panes[tt]}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(x.PANE_UUID(tt)).pipe(Mt(pi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ce.width&&t.height>ce.height){const e=this.getEffectiveChartWidth(),n=this.getEffectiveYAxisWidth();if(this.prevChartWidth===0){this.scale.isViewportValid()?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=jt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=jt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return br(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=Qe(t.map(qe)),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,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=Qe(t.candles.map(qe));this.mainCandleSeries.clearData(),Xs(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.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()}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=Je({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.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=Qe(t.candles.map(qe)),r=Mr(this.mainCandleSeries.dataPoints,i),o=r.candles;Xs(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const g=Qe(l.candles.map(qe)),m=Mr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],g).candles;return this.setSecondaryCandleSeries(m,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});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.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(n=>{const i=Lt(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}createSecondaryCandleSeriesModel(t){const e=Je(Je({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Wt(this.paneManager.panes[tt].mainExtent,_t(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[tt].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{var r;const o=(r=i.idx)!=null?r:0,a=e[o];if(a)n.push(a);else{let l=Tr(e,o,-1);if(l||(l=Tr(e,o,1)),l){const c=Sl(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=At(t,He().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}getEffectiveYAxisWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(tt)).width}getEffectiveChartWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)).width}getEffectiveChartHeight(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)).height}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.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,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=Lt(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Kt((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?Ce(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Ce(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e=!0,n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}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,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.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,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return bt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return bt(t)}getMaxCandlesFitLength(){return et(this.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((n,i)=>{const r=i.timestamp,o=ve(r,!1,t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=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=ve(h.timestamp,!0,o,this.getPeriod()),g=Math.min(u.index,o.length);a=a||g===o.length,o[g]=h,h.idx=g,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(g);const m=g>=o.length-1,C=c&&h.timestamp<c.timestamp;if(m&&!C&&(c=h),a&&c&&n&&l){const _=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Wi;this.scale.moveXStart(this.scale.xStart+_(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.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return xt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Ce(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(Ce(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...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 n=t.slice(),i=[];return e.forEach(r=>{const a=ve(r.timestamp,!1,t).index;a<0?i.push(r):t[a].timestamp===r.timestamp?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}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){const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Xs(i.dataPoints),i.recalculateVisualPoints()}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Qe=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),Tr=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Mr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=ve(r.timestamp,!0,s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class Se{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ws{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Pi(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=Pi(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=vt(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class Eh{constructor(t,e,n){this.model=t,this.crossToolCanvasModel=e,this.crossToolTypeDrawers=n}draw(){const t=this.crossToolTypeDrawers[this.model.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.model.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}class Dh extends X{constructor(t,e,n,i){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.currentHoverSubject=new mt(null),this.type="cross-and-labels",this.type=t.type}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?this.updateHover(t):this.currentHover=null,this.fireDraw()}))}fireDraw(){this.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateHover(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===tt)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)}}const Et=4;function Ih(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m;const C=r.align,_=(l=i.textFont)!=null?l:Jt(r),M=i.bgColor,L=(c=i.textColor)!=null?c:qt(M,o.labelTextColor,o.labelInvertedTextColor),H=(h=i.paddingTop)!=null?h:Et,z=(d=i.paddingBottom)!=null?d:Et,R=(u=i.paddingEnd)!=null?u:Et,F=Kt(kt(_,s)/2),Y=n-F-H,V=n+F+z-Y;if(a&&!ts(n,t,V))return;s.save(),s.fillStyle=M,s.strokeStyle=M;const N=Kt(t.width/6),U=C==="right"?t.x:t.x+t.width,Q=C==="right"?U+N:U-N,J=r.labelBoxMargin.end,st=J-R,G=t.width-N-st;Oc(s,Q,Y,U,Y+Kt(V/2),Q,Y+V,G,(m=(g=r.typeConfig.badge)==null?void 0:g.rounded)!=null?m:!1,C),s.fillStyle=L,s.font=_;const nt=C==="right"?t.x+t.width-Pt(e,s,_)-J:t.x+J;s.fillText(e,nt,n+F-1),s.restore()}function Lh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m,C,_,M,L;const H=r.align,z=(l=i.textFont)!=null?l:Jt(r),R=i.bgColor,F=(c=i.textColor)!=null?c:qt(R,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,q=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Et,V=(m=(g=i.paddingBottom)!=null?g:Y==null?void 0:Y.bottom)!=null?m:Et,N=(_=(C=i.paddingEnd)!=null?C:Y==null?void 0:Y.end)!=null?_:Et,U=i.paddingStart,Q=kt(z,s),J=n-Q/2-q,G=n+Q/2+V-J,nt=(L=i.rounded)!=null?L:(M=r.typeConfig.rectangle)==null?void 0:M.rounded;if(a&&!ts(n,t,G))return;s.save(),s.fillStyle=R,s.strokeStyle=R;const ot=r.labelBoxMargin.end;s.font=z;const ft=Pt(e,s,z),at=ot-N,wt=U!==void 0?ft+U+N:t.width-at,se=H==="right"?t.x+t.width-at-wt:t.x+at,cs=H==="right"?t.x+t.width-ft-ot:ot;nt?ir(s,se,J,wt,G,4,!0):s.fillRect(se,J,wt,G),s.fillStyle=F,s.fillText(e,cs,n+Q/2-1),s.restore()}function Bh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m,C,_;const M=r.align,L=(l=i.textFont)!=null?l:Jt(r),H=o.backgroundColor,z=(c=i.textColor)!=null?c:qt(H,o.labelTextColor,o.labelInvertedTextColor),R=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,F=(u=(d=i.paddingTop)!=null?d:R==null?void 0:R.top)!=null?u:Et,Y=(m=(g=i.paddingBottom)!=null?g:R==null?void 0:R.bottom)!=null?m:Et,q=(_=(C=i.paddingEnd)!=null?C:R==null?void 0:R.end)!=null?_:Et,V=i.paddingStart,N=kt(L,s),U=n-N/2-F,J=n+N/2+Y-U;if(a&&!ts(n,t,J))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const st=r.labelBoxMargin.end;s.font=L;const G=Pt(e,s,L),nt=st-q,ot=V!==void 0?G+V+q:t.width-nt,ft=M==="right"?t.x+t.width-nt-ot:t.x+nt,at=M==="right"?t.x+t.width-G-st:st;s.fillStyle=H,s.strokeStyle=H,s.fillRect(ft,U,ot,J),s.fillStyle=z,s.fillText(e,at,n+N/2-1),s.restore()}function Oh(s,t,e=Et){return kt(s,t)/2+e}function ts(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const Rh="badge",Ar=4,Er={badge:Ih,rectangle:Lh,plain:Bh};function Dr(s,t,e,n,i,r,o,a){var l,c,h,d,u;const g=i.y,m=i.labelText,C=(l=i.mode)!=null?l:"label",_=(c=i.labelType)!=null?c:Rh,M=i.description,L=(h=i.textFont)!=null?h:Jt(o),H=i.bgColor,z=(d=i.lineColor)!=null?d:H,R=Pt(M!=null?M:"",s,L)+8,F=et(i.y),Y=kt(L,s),q=g-Y/2,N=g+Y/2-q;s.save(),s.fillStyle=H,s.strokeStyle=z;const U=r.getBounds(x.PANE_UUID(tt)),Q=Er[_],J=o.labels.descriptions,st=Fh(e,F,N),G=()=>J&&Hh(t,s,e,n,i,o);let nt,ot;const ft=2;o.align==="right"?(nt=U.x,ot=J?U.x+U.width-R:U.x+U.width+ft):(nt=J?U.x+R:U.x-ft,ot=U.x+U.width);const at=(u=i.lineY)!=null?u:i.y,wt=()=>st&&te(s,()=>Rc(s,nt,at,ot,at,1)),se=()=>Q(s,e,m,g,i,o,a.yAxis,!1),hn={line:()=>{wt(),G()},"line-label":()=>{wt(),se(),G()},label:()=>{G(),se()}};C!=="none"&&ts(g,e,N)&&hn[C](),s.restore()}const Fh=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Hh(s,t,e,n,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=Jt(r),g=Pt(h,t,u),m=kt(u,t),C=(o=i.paddingTop)!=null?o:Ar,_=(a=i.paddingBottom)!=null?a:Ar,M=d-m/2-C,H=d+m/2+_-M;t.save();const z=g+5,R=4,F=g+R*2,Y=n.x+n.width,q=c==="right"?Y-F:n.x+R;Kl(s,t,q,M,z,H,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const V=c==="right"?Y-g-R*2:n.x+R*2;t.fillText(h,V,d+m/2-1),t.restore()}class Ir{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&te(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n: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,g=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const m={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},C={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},_=g==null?void 0:g(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),_&&(t.moveTo(...m.start),t.lineTo(...m.end)),t.moveTo(...C.start),t.lineTo(...C.end),t.stroke()),_&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,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,g=t.measureText(u).width,m=this.config.components.xAxis.fontSize,C=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const _=(n=l==null?void 0:l.left)!=null?n:0,M=(i=l==null?void 0:l.right)!=null?i:0,L=(r=l==null?void 0:l.top)!=null?r:0,H=(o=l==null?void 0:l.bottom)!=null?o:0,z=(a=c==null?void 0:c.top)!=null?a:0,R=g+_+M,F=m+L+H,Y=Math.max(d-R/2,0),q=C.y+z;ir(t,Y,q,R,F),t.fillStyle=h.labelTextColor;const V=Math.max(d-g/2,_),N=C.y+z+m+L-1;t.fillText(u,V,N),t.restore()}}drawYLabel(t,e){const n=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(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=Er[a],g=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:g,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class kh{draw(){}}class Yh extends X{constructor(t,e,n,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossToolTypeDrawers={},this.model=new Dh(t.components.crossTool,this.crossToolCanvasModel,o,a),this.addChildEntity(this.model);const l=new Se(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const c=new Eh(this.model,this.crossToolCanvasModel,this.crossToolTypeDrawers),h=new Ws;h.addDrawer(l,"CLEAR_CANVAS"),h.addDrawer(c,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(h,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Ir(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Ir(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new kh)}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 jh{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Nt{constructor(t){this.data=t,this.next=null}}class Nh{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 Nt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new Nt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.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 Xh extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._objects=new mt({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new Nt(n);return i.getNodePosition(r)}addObject(t){var e;const n=t.paneId,i=this.objects,r=(e=i[n])!=null?e:new Nh;Object.keys(i).find(o=>o===n)||(i[n]=r),r.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.setDynamicObjects(i)}removeObject(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);i.removeAt(o),this.modelIdToObjectMap.delete(t),i.size()===0&&delete this.objects[n.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[n]=e;this.removeObject(n.id),this.addObject(t)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Nt(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[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class zh extends X{constructor(t,e){super();const n=new Xh(t);this.model=n,this.addChildEntity(n);const i=new jh(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Wh=()=>s=>s.toString(),Uh=(s,t)=>{var e;const n="date.get"+(t((e=s.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 n+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:Vh(s),shortMonths:Gh(s),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=s.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Zh(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Vh(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Gh(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const Lr=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.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(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Wh()},Zh=(s,t,e,n)=>{t||(t="M/d/yyyy");const i=s.getDate(),r=s.getMonth(),o=s.getFullYear(),a=s.getHours(),l=s.getMinutes(),c=s.getSeconds(),h=s.getMilliseconds(),d=a%12,u=de(d),g=de(a),m=de(l),C=de(c),_=a<12?"AM":"PM",M=e[s.getDay()],L=M.substring(0,3),H=de(i),z=r+1,R=de(z),F=n[r],Y=F.substring(0,3),q=o+"",V=q.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",g+"").replace("H",a+"").replace("mm",m+"").replace("m",l+"").replace("ss",C+"").replace("s",c+"").replace("S",h+"").replace("dd",H+"").replace("d",i+"").replace("EEEE",M).replace("EEE",L).replace("YYYY",q).replace("yyyy",q).replace("YY",V).replace("yy",V).replace("aaa",_),t.indexOf("MMM")>-1?t=t.replace("MMMM",F).replace("MMM",Y):t=t.replace("MM",R+"").replace("M",z+""),t},de=s=>typeof s=="number"&&s<10?"0"+s:s,$h={"rhombus-small":4,rhombus:6,"rhombus-large":8},xe=(s,t)=>`${s}_${t}`;class Kh{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&(this.createCustomIcon("earnings",a.earnings),this.createCustomIcon("dividends",a.dividends),this.createCustomIcon("splits",a.splits),this.createCustomIcon("conference-calls",a.conferenceCalls))}createCustomIcon(t,e){if(e){const n=this.createIconImage(e.normal),i=this.createIconImage(e.hover);this.customIcons[xe(t,"normal")]=n,this.customIcons[xe(t,"hover")]=i}}createIconImage(t){var e;const i=new DOMParser().parseFromString(t,"text/html").querySelector("svg");let r=0;i&&(r=parseInt((e=i.getAttribute("height"))!=null?e:"",10));const l="data:image/svg+xml;base64,"+btoa(t),c=new Image;return c.src=l,{img:c,svgHeight:r}}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{const r=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(r>e.x&&r<e.x+e.width){const o=this.config.colors.events[i.type].color;n.strokeStyle=o,this.customIcons[xe(i.type,"hover")]!==void 0?this.drawCustomSvgEvent(n,r,t,i):this.drawDefaultEvent(n,r,t,i,o),this.model.hoveredEvent.getValue()===i&&(n.beginPath(),n.moveTo(r,e.y),n.lineTo(r,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(r,i))}}),n.restore()}drawCustomSvgEvent(t,e,n,i){const r=n.y+n.height/2,o=this.customIcons[xe(i.type,"normal")],a=this.customIcons[xe(i.type,"hover")];this.model.hoveredEvent.getValue()===i?t.drawImage(a.img,e-a.svgHeight/2,r-a.svgHeight/2):t.drawImage(o.img,e-o.svgHeight/2,r-o.svgHeight/2)}drawDefaultEvent(t,e,n,i,r){const o=n.y+n.height/2;t.fillStyle=r,t.lineWidth=1.5;const a=Us(i);t.beginPath(),t.moveTo(e-a,o),t.lineTo(e,o-a),t.lineTo(e+a,o),t.lineTo(e,o+a),t.closePath(),this.model.hoveredEvent.getValue()===i?t.fill():t.stroke()}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n: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 Us(s){return $h[s.style]}const es=5;class qh{constructor(t,e,n,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{const r=this.model.events[i-1],o=r&&this.chartModel.candleFromTimestamp(r.timestamp).xCenter(this.chartModel.scale),a=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(a>e.x&&a<e.x+e.width){const l=this.config.colors.events[n.type].color;t.strokeStyle=l,t.fillStyle=l;const c=Us(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const h=(c+es)*2;if(o!==void 0){const d=Us(r);if(o+d>a-h/2){const g=c*2+es;t.fillRect(o+d,e.y,g,e.height)}else t.fillRect(a-c-es,e.y,h,e.height)}else t.fillRect(a-c-es,e.y,h,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Jh=Object.defineProperty,Br=Object.getOwnPropertySymbols,Qh=Object.prototype.hasOwnProperty,td=Object.prototype.propertyIsEnumerable,Or=(s,t,e)=>t in s?Jh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ed=(s,t)=>{for(var e in t||(t={}))Qh.call(t,e)&&Or(s,e,t[e]);if(Br)for(var e of Br(t))td.call(t,e)&&Or(s,e,t[e]);return s};const Rr=317,Vs={DRAWINGS:[1,199],NEWS:[200,299],DATA_SERIES:[300,2999],EVENTS:[3e3,4e3],EXECUTED_ORDERS:[4001,5e3]};class sd extends dr{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new O,this.touchStartSubject=new O,this.dblClickSubject=new O,this.rightClickSubject=new O,this.hitTestDrawersPredicateSubject=new mt(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,ur(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Ne(100,je,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=xt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=xt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ht(()=>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(ht(()=>ed({},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,n,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*Rr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Rr}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ys&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ys),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=Gs(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=Gs(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 n,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),[g,m]=Gs(this.hitTestSubscribers,u),C=g==null?void 0:g.lookup(d),_={point:t,model:C};switch(e){case"mousedown":C&&((n=g==null?void 0:g.onMouseDown)==null||n.call(g,C,t)),m.forEach(M=>M.onMouseDown&&M.onMouseDown(null,t));break;case"mouseup":C&&((i=g==null?void 0:g.onMouseUp)==null||i.call(g,C,t)),m.forEach(M=>M.onMouseUp&&M.onMouseUp(null,t));break;case"hover":C&&((r=g==null?void 0:g.onHover)==null||r.call(g,C,t)),m.forEach(M=>M.onHover&&M.onHover(null,t)),this.hoverSubject.next(_);break;case"touchstart":C&&((o=g==null?void 0:g.onTouchStart)==null||o.call(g,C,t)),m.forEach(M=>M.onTouchStart&&M.onTouchStart(null,t)),this.touchStartSubject.next(_);break;case"dblclick":C&&((a=g==null?void 0:g.onDblClick)==null||a.call(g,C,t)),this.dblClickSubject.next(_);break;case"contextmenu":C&&((l=g==null?void 0:g.onRightClick)==null||l.call(g,C,t)),this.rightClickSubject.next(_);break;case"zoom":C&&((c=g==null?void 0:g.onZoom)==null||c.call(g,C,t)),m.forEach(M=>M.onZoom&&M.onZoom(null,t));break;default:break}}}const Gs=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var nd=Object.defineProperty,id=Object.defineProperties,rd=Object.getOwnPropertyDescriptors,Fr=Object.getOwnPropertySymbols,od=Object.prototype.hasOwnProperty,ad=Object.prototype.propertyIsEnumerable,Hr=(s,t,e)=>t in s?nd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ld=(s,t)=>{for(var e in t||(t={}))od.call(t,e)&&Hr(s,e,t[e]);if(Fr)for(var e of Fr(t))ad.call(t,e)&&Hr(s,e,t[e]);return s},cd=(s,t)=>id(s,rd(t));class hd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new mt(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>cd(ld({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Vs.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 dd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>Lr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new hd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new Kh(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new qh(n,i,t,r,c,()=>n.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.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){At(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class ud{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;te(t,()=>this.drawVertical(t)),te(t,()=>this.drawHorizontal(t)),te(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=et(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.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 n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=Z(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=et(this.viewportModel.toY(i.value)),o=Oh(i.text,t,Et);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class kr extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new ud(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class gd{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,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,n,i){const r=this.getMarkerY(t,n,i==="low"),o=Fe(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,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");Ut(t,h)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?"H:":"L:"} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=Fe(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class fd extends X{constructor(t,e,n,i,r){super();const o=new gd(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const pd=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],md=24*60*60*1e3;class vd extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new O}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()+md;Ya(this.highlights,t,e,bd).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,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const bd=s=>s.to,Vt=[20,10];class Cd{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,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(x.ALL_PANES);o.save(),Ut(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=(n=this.config.components.highlights.fontSize)!=null?n:11,g=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",m=`${u}px ${g}, monospace`;o.font=m,o.lineWidth=h,o.setLineDash(d),pd.forEach(C=>{var _,M;const L=a[C];if(L){const H=this.config.colors.highlights[C],z=(_=H==null?void 0:H.border)!=null?_:"#ffffff",R=(M=H==null?void 0:H.background)!=null?M:"#ffffff";o.save(),o.beginPath(),o.fillStyle=R,o.strokeStyle=z,L.forEach(F=>{var Y,q,V;const N=this.chartModel.candleFromTimestamp(F.from),U=ut(N.width,this.chartModel.scale.zoomX),Q=N.xStart(this.chartModel.scale),J=this.chartModel.candleFromTimestamp(F.to),st=ut(J.width,this.chartModel.scale.zoomX),G=J.xStart(this.chartModel.scale)+st;if(F.border&&this.drawBorders(F.border,o,Q+U,G-st,c),o.fillRect(Q,c.y,G-Q,c.y+c.height),F.label){const nt=(Y=F.label.text)!=null?Y:"",ot=this.config.colors.highlights[F.type];o.save(),o.fillStyle=(q=ot==null?void 0:ot.label)!=null?q:"#ffffff";const ft=Pt(nt,o,m),[at,wt]=this.resolveHighlightLabelPosition((V=F.label.placement)!=null?V:"left-left",c,[Q,G],ft);o.fillText(nt,at,wt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Vt[1]-i,e.y+Vt[0]];case"left-left":return[r-Vt[1]-i,e.y+Vt[0]];case"right-right":return[o+Vt[1],e.y+Vt[0]];case"left-right":default:return[r+Vt[1],e.y+Vt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,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 yd="HIGHLIGHTS_PLUGIN";class wd extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new vd(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new Cd(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,yd)}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 Sd(){return j(function(s,t){var e,n=!1;s.subscribe(Tt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function K(s,t){return j(function(e,n){var i=0;e.subscribe(Tt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var xd=Object.defineProperty,_d=Object.defineProperties,Pd=Object.getOwnPropertyDescriptors,Yr=Object.getOwnPropertySymbols,Td=Object.prototype.hasOwnProperty,Md=Object.prototype.propertyIsEnumerable,jr=(s,t,e)=>t in s?xd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Nr=(s,t)=>{for(var e in t||(t={}))Td.call(t,e)&&jr(s,e,t[e]);if(Yr)for(var e of Yr(t))Md.call(t,e)&&jr(s,e,t[e]);return s},Xr=(s,t)=>_d(s,Pd(t));const Xt=4;class Ad{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,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(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.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(),n.width!==0&&this.drawLeftArrowButton(c,n,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,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Xt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Xt,r+Xt),t.lineTo(i+Xt,r-Xt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Xt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Xt),t.lineTo(i,r+Xt),t.lineTo(i+Xt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.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=n.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=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=vt(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:Xr(Nr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:Xr(Nr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=$n(n,i.dateFormat,this.formatterFactory);Vn(t,i.textProperties);const a=Fe(t),l=Zn(o);Na(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class _e extends vr{constructor(t,e,n,i,r=mr){super(t,e,n,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 zr=4;class Ed extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=g=>{const m=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=g.x-m.x-zr},this.leftKnotDragTick=g=>{const{delta:m}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.leftKnotDragStartXRelative+m)/_;this.canvasBoundsContainer.leftRatio=M,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=g=>{const m=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=g.x-m.x+zr},this.rightKnotDragTick=g=>{const{delta:m}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.rightKnotDragStartXRelative+m)/_;this.canvasBoundsContainer.rightRatio=M,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=g=>{const{delta:m}=g,C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),_=this.chartModel.mainCandleSeries.meanCandleWidth/(C.width/this.chartModel.mainCandleSeries.dataPoints.length),M=(this.lastMousePosition-m)*_;this.scale.moveXStart(this.scale.xStart-M),this.lastMousePosition=m};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new _e(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new _e(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new _e(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.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(x.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 n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class Dd extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new Ad(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new Ed(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(Sd(),K(([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 n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,g,m;for(g=0;g<h;g++)m=et(g*o/h)-r,m in e?(d[g]=e[m].close,u=(t=d[g])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[g]=0;return a-=l,d.map((C,_)=>[_+c.x,(a+l-C)*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(Fs),this.canvasModel.fireDraw())}}const Wr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},tp=(s,t)=>s==="apple"||s==="mobile"?3:t,Id=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Ld=!!window.chrome,Ur=typeof InstallTrigger!="undefined",Bd=navigator.platform.indexOf("Win")>-1,ep=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Id)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(Ld){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,Bd){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else Ur?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return Ur&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Od=(s,t)=>s==="percent"?t/4:t;var Zs=Math.pow;class Rd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,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 g=d.deltaY<0;if(this.config.scale.zoomToCursor){const C=this.canvasBoundsContainer.getBounds(x.CANVAS).width,M=d.offsetX/C;this.scale.zoomXToPercent(M,g,!1,u)}else this.scale.zoomXToEnd(g,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(Re),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 g=jt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-g),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new _e(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(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(K(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Ne(this.wheelThrottleTime,je,{trailing:!0,leading:!0})).subscribe(e=>{const n=Wr(),i=n==="apple"||n==="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=jt(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 Od(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(Re),this.currentPoint={x:0,y:0},n=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)Fd(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=jt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new Ke(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Fd=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Zs(Zs(Math.abs(s.x),2)+Zs(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle},Hd=30;class kd extends X{constructor(t,e,n,i){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.touchedCandleIndexes=[0,0],this.pinchDistance=0,this.isDraggable=!0}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){t.touches.length===2&&(this.isDraggable=!0,this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(e=>this.scale.fromX(e)))}handleTouchMoveEvent(t){t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[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];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=Math.abs(e[0])-Math.abs(e[1]),i=Math.abs(n),r=i>this.pinchDistance;if(this.scale.isMaxZoomXReached(r)&&(this.isDraggable=!1),!this.isDraggable||i<Hd)return;this.pinchDistance=i;const o=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),a=o+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;o>=a||this.scale.setXScale(o,a)}}class Yd extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c,this.chartAreaPanHandler=new Rd(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new kd(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const Vr=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},Gr=(s,t)=>{const e=Vr(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function jd(){return In(1)}function Zr(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return jd()(Le(s,Ie(s)))}function Nd(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Ie(s);return j(function(n,i){(e?Zr(s,n,e):Zr(s,n)).subscribe(i)})}function Xd(s){return K(function(t,e){return s<=e})}class zd{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}class $s extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,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=g,this.initialY=0,this.resizeEvent$=new O,this.onYDragStart=()=>{this.config.components.crossTool.type="none",this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEnd=()=>{this.config.components.crossTool.type="cross-and-labels",this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=m=>{const{delta:C,draggedPixels:_}=m;Math.abs(this.initialY-this.boundsProvider().y+_)>=0&&(this.dragTickCb(C),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new Ke(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Nd(!1),K(this.dragPredicate),Mt(),Xd(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new zd(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,pr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(pr.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 Wd=s=>t=>{let e;if(typeof t=="number")e=t;else if(typeof t=="string")e=Number(t);else return"\u2014";const[n]=s.dataSeries;if(n!==void 0){const i=Ot.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},Ud=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ei(t,r.getBaseline()));const o=i.toFixed(Ot.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Vd=s=>({percent:Ud(s),regular:Wd(s)});class Gd extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:Fi}){super(),this.paneUUID=t,this.idx=e,this.paneComponent=n,this.chartBaseModel=i,this.canvasBoundsContainer=r,this.hitTestController=o,this.dynamicObjectsCanvasModel=a,this.scale=l,this.dragNDrop=h,this.dataSeries=d,this.formatters=u,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(m=>new be(this.chartBaseModel.dataFromTimestamp(m.timestamp).centerUnit,m.close)),this.toY=g=>{var m,C;return(C=(m=this.mainDataSeries)==null?void 0:m.view.toY(g))!=null?C:1},this.valueFormatter=(g,m)=>{var C;return((C=this.formatters[this.yAxis.getAxisType()])!=null?C:this.formatters.regular)(g,m)},this.addChildEntity(l),this.setValueFormatters(Vd(this)),this.yAxis=c(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 Ri(this,_t(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),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,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const $r=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return $i(e)}});class Zd{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Vs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Vs.DATA_SERIES}get allDataSeries(){return pe(pe(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.hovered=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(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const zt="#FF00FF";function sp(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const $d=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Kd=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:zt},qd=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:zt},Jd=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:zt},Qd=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:zt},tu=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:zt},eu=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:zt},su=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:zt},Kr=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:zt},nu=()=>(console.warn("Fallback for label default color"),zt);function iu(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>ru(a,l,e)).filter(Xn).sort(ou),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[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<n.length;a++){const l=n[a],c=n[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 ru=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,ou=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var au=Object.defineProperty,lu=Object.defineProperties,cu=Object.getOwnPropertyDescriptors,qr=Object.getOwnPropertySymbols,hu=Object.prototype.hasOwnProperty,du=Object.prototype.propertyIsEnumerable,Jr=(s,t,e)=>t in s?au(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Qr=(s,t)=>{for(var e in t||(t={}))hu.call(t,e)&&Jr(s,e,t[e]);if(qr)for(var e of qr(t))du.call(t,e)&&Jr(s,e,t[e]);return s},to=(s,t)=>lu(s,cu(t));const Ks={MAIN:"MAIN"};class uu extends X{constructor(t,e,n,i,r,o,a){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.orderedLabels=[],this.customLabels={},this.labelsProviders={},this.labelsPositionRecalculatedSubject=new O,this.animFrameId=`anim_cache_${_t()}`,this.initModel()}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed).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,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Ns(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=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=vt(Object.values(i).map(l=>l.getUnorderedLabels())),o=vt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=iu(o,n);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,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return to(Qr({},t),{labels:t.labels.map((n,i)=>to(Qr({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}const eo=10;class gu extends X{constructor(t,e,n,i,r,o,a,l,c){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.autoScaleCallback=l,this.hitTestCanvasModel=c,this.yAxisDragEndSubject=new O,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(x.Y_AXIS).height,ci),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=h=>{const{delta:d}=h;let u;d<0?u=1/(1+-d/this.lastYPxHeight*(eo-1)):u=1+d/this.lastYPxHeight*(eo-1);const m=(this.lastYHeight*u-this.lastYHeight)/2,C=this.lastYStart-m,_=this.lastYEnd+m;(this.lastYStart!==C||this.lastYEnd!==_)&&(this.scale.setYScale(C,_),this.autoScaleCallback(!1),this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},e.customScale){const h=new Ke(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(h)}}doActivate(){this.config.customScaleDblClick&&this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.autoScaleCallback(!0),this.bus.fireDraw()}))}}class fu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${_t()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),fr(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 pu=0,mu=.01;class qs{constructor(t,e,n,i,r=!1,o,a,l=ys,c=23){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new O,this.newGeneratedLabelsSubject=new O,this.lastStart=0,this.lastEnd=0,this.labelsCache=new fu(()=>this.labelFilter(this.doGenerateLabels()))}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=dt.roundToNearest(t,n);for(;r<e;){const o=dt.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=dt.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=dt.roundToNearest(t,n);for(;o<e;){const a=dt.roundToNearest(o,n),l=Di(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=dt.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=dt.roundToNearest(t,n);for(;r<e;){const o=Os(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=dt.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,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(),n=this.lengthProvider(),i=qs.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/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){if(this.increment)return this.increment;if(!isNaN(t)){const e=Ot.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(mu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Os(e)+t;return Ii(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,n){const i=Math.abs((e-t)*(pu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class vu extends qs{constructor(t,e,n,i,r=()=>"regular",o=23){super(t,()=>[n.yStart,n.yEnd],()=>n.getBounds().height,i,!1,r,()=>{var a,l;return(l=(a=e())==null?void 0:a.getBaseline())!=null?l:1},void 0,o),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,n)=>n.text.length>e.length?n.text:e,"")}calculateIncrement(t){var e;const n=this.dataSeriesProvider();if(n){const i=bt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=Ql(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function so(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?j(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(Tt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):ie}class bu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${_t()}`}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ht(t=>t.height),K(t=>pa(t,this.prevYAxisHeight,1.5)),so(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),Ns(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class Cu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new vu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new bu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new uu(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths()),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class yu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasBoundsContainer=o,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new O,this.state=At(m!=null?m:{},e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new gu(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),C=>i.autoScale(C),g),this.addChildEntity(this.yAxisScaleHandler),this.model=new Cu(this.paneUUID,t,this.state,o,n,i,c,h,u),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Jd),this.registerLabelColorResolver("bar",Kd),this.registerLabelColorResolver("line",qd),this.registerLabelColorResolver("area",Qd),this.registerLabelColorResolver("scatterPlot",tu),this.registerLabelColorResolver("histogram",eu),this.registerLabelColorResolver("baseline",su),this.registerLabelColorResolver("trend",Kr),this.registerLabelColorResolver("hollow",Kr)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.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:nu}registerYAxisLabelsProvider(t,e=Ks.MAIN,n=_t()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(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=Ks.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.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())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),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){this.scale.state.inverse=t,this.scale.inverseY=t,this.scale.scaleInversedSubject.next(t)}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class wu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m,C,_,M,L,H){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,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=g,this.canvasBoundsContainer=m,this.uuid=C,this.seriesAddedSubject=_,this.seriesRemovedSubject=M,this.hitTestCanvasModel=L,this.yExtentComponents=[],this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(R,F)=>this.mainExtent.valueFormatter(R,F);const z=this.createExtentComponent(H);this.mainExtent=z,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(C),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return pe(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(Mt(pi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i){const r=x.PANE_UUID(t);return new kr(this.mainCanvasModel,e,this.config,i,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(r),()=>this.canvasBoundsContainer.getBounds(r),()=>[],()=>n.generateNumericLabels())}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Ic(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(C,_)=>new yu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,C,_,this.uuid,i,this.hitTestCanvasModel,l),u=new Gd(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),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",Gr(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),$r(u)));const m=this.createGridComponent(this.uuid,a,u.yAxis.model.labelsGenerator,u.yAxis.state);return u.addChildEntity(m),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),u}removeExtentComponent(t){t.disable(),this.yExtentComponents.splice(t.idx,1),this.yExtentComponents.forEach((e,n)=>e.idx=n),this.canvasBoundsContainer.updateYAxisWidths()}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(n=>n.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=re(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=bt(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)}}class Su extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m,C,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,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=g,this.mainCanvasModel=m,this.yAxisLabelsCanvasModel=C,this.hitTestCanvasModel=_,this.panes={},this.paneRemovedSubject=new O,this.paneAddedSubject=new O,this.dataSeriesAddedSubject=new O,this.dataSeriesRemovedSubject=new O,this.hitTestController=new Zd(this.panes,this.dynamicObjectsCanvasModel);const M=this.createPane(tt,{useDefaultHighLow:!1,scale:this.mainScale});M.mainExtent.scale.autoScaleModel.setHighLowProvider("series",$r(M.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",Vr(()=>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(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone}),n=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=x.PANE_UUID_RESIZER(t),o=new $s(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,n,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 pe(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=_t(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new wu(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,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,n;const i=re(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&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}canMovePaneDown(t){var e,n;const i=bt(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&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const n=x.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof $s&&r.id===n);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],n=x.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof $s&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone),()=>{this.cursorHandler.removeCursorForCanvasEl(n),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 xu extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),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 _u=(s,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 n(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 n(s)},ss=class extends X{constructor(s,t,e,n,i){super(),this.chartComponent=s,this.drawingManager=t,this.config=e,this.volumesModel=n,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[ss.UUID]===void 0){const t=this.paneManager.createPane(ss.UUID,{paneFormatters:{regular:i=>_u(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=Gr(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(ss.UUID),delete this.pane,this.drawingManager.removeDrawerByName("UNDERLAY_VOLUMES_AREA")}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let no=ss;no.UUID="volumes";const ns=.3,Pu=(s,t)=>{const e=t.barTheme[`${s}Color`];return It()(e).alpha(ns).toString()},Tu=(s,t)=>{const e=t.volume[`${s}BarColor`];return It()(e).alpha(ns).toString()},Mu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return It()(e).alpha(ns).toString()},Js=(s,t)=>{const e=t.candleTheme[`${s}Color`];return It()(e).alpha(ns).toString()},Au=3;class Eu{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:Tu;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("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 n=this.getViewportModel().getBounds();Ut(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=vt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?Z(i.toX(n[o+1].startUnit)):void 0,h=Z(i.toX(r.startUnit)),d=c!==void 0?c-h:Z(ut(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Z(i.toY(r.candle.volume)),g=Z(i.toY(0))-u;this.drawVolume(t,r,h,u,d,g)}else{const u=e/(l/Au),g=Math.max(ut(r.candle.volume,u),2),m=Z(a.y+l-g);this.drawVolume(t,r,h,m,d,g)}}})}drawVolume(t,e,n,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(n,l),a.lineTo(n,_i(c)),a.stroke()):a.fillRect(n,i,r,_i(o))}}const Du=ka(s=>s.candle.volume),io="volumes";class Iu extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=io,this.volumeMax=new mt(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(xt(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=re(Du(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Lu extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new mt(!1),this.volumeIsSeparateModeChangedSubject=new mt(!1);const c=new Iu(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new no(e,r,o,c,a),this.volumesDrawer=new Eu(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:n},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.addVolumesToDynamicObjects(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",Js),this.registerVolumeColorResolver("trend",Js),this.registerVolumeColorResolver("hollow",Js),this.registerVolumeColorResolver("line",Mu),this.registerVolumeColorResolver("bar",Pu)}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))}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),t?this.addVolumesToDynamicObjects():this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.canvasModel.fireDraw()}addVolumesToDynamicObjects(){this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1&&this.dynamicObjectsComponent.model.addObject({id:this.volumesModel.id,paneId:this.config.components.volumes.showSeparately?io:tt,drawer:this.volumesDrawer,model:this.volumesModel})}}class Bu{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,g=this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)),{position:m,offsetY:C,offsetX:_}=this.config.components.waterMark;let M;switch(d?M=d:(u.font=is(this.config,l),M=u.measureText(a).width,g.width-10<M&&(u.font=Ou(this.config,this.canvasBoundsContainer,l,M),M=u.measureText(a).width)),m){case"left-top":return{x:_+g.x,y:C+o+g.y,font:u.font,text:a,color:c};case"left-bottom":return{x:_+g.x,y:g.height-h-C+o+g.y,font:u.font,text:a,color:c};case"center":return{x:g.width/2-M/2+g.x,y:(g.height-h)/2+o+g.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,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,g=this.canvasModel.ctx;let m=0,C=0,_=0,M=0,L=0;if(g.save(),d.firstRowFontSize&&l){g.font=is(this.config,d.firstRowFontSize);const F=g.measureText(l);m=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){g.font=is(this.config,d.secondRowFontSize);const F=g.measureText(c);C=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent,_=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){g.font=is(this.config,d.thirdRowFontSize);const F=g.measureText(h);M=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent,L=(n=d.secondRowBottomPadding)!=null?n:0}const H=(i=d.thirdRowBottomPadding)!=null?i:0,z=(r=d.logoHeight)!=null?r:0,R=m+C+_+M+L+H+z;if(l&&this.drawWaterMark(this.getConfig(m,l,d.firstRowFontSize,u.firstRowColor,R)),c&&this.drawWaterMark(this.getConfig(m+_+C,c,d.secondRowFontSize,u.secondRowColor,R)),h&&this.drawWaterMark(this.getConfig(m+_+C+L+M,h,d.thirdRowFontSize,u.thirdRowColor,R)),this.logoImage){const F=this.getConfig(m+_+C+L+M+H,"",d.thirdRowFontSize,u.thirdRowColor,R,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,F.x,F.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}g.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const Ou=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},is=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Ru=Object.defineProperty,ro=Object.getOwnPropertySymbols,Fu=Object.prototype.hasOwnProperty,Hu=Object.prototype.propertyIsEnumerable,oo=(s,t,e)=>t in s?Ru(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ao=(s,t)=>{for(var e in t||(t={}))Fu.call(t,e)&&oo(s,e,t[e]);if(ro)for(var e of ro(t))Hu.call(t,e)&&oo(s,e,t[e]);return s};class ku extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new Bu(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(At(r.observeBoundsChanged(x.PANE_UUID(tt)),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={};At(e,t),At(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 ao(ao({},this.config.components.waterMark),h)}}const lo={x:4,y:4};function Yu(s,t,e,n){var i,r;const o=(i=n.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(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const m=s.measureText(n.text).width+lo.x*2;let C=0;const _=n.x;switch(o){case"start":C=_-m;break;case"end":C=_;break;case"middle":default:C=_-m/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(C,u.y,m,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(_,u.y),s.lineTo(_,u.y+u.height),s.stroke()),s.fillStyle=n.color;const M=C+lo.x,L=u.y+d+a;s.fillText(n.text,M,L),s.restore()}class ju{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Yu(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=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(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=It().rgb(r[0].color).alpha(.1).toString(),rr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const np="week-weekday",Nu=["second","minute","hour","day","month","year"],Xu=["lessThanSecond"],zu=s=>Nu.some(t=>t===s),Wu=s=>s==="week-weekday",Uu=s=>Xu.some(t=>t===s),co=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},Qs=s=>parseInt(s,10),ho=s=>{const[t,...e]=s.split("_");if(zu(t)){const[n]=e,i=co(n),r=Qs(n);return{key:t,value:r,exact:i["!"]}}else if(Wu(t)){const[n,i]=e,r=co(n),o=Qs(n),a=Qs(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Uu(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats https://webdev.prosp.devexperts.com:8095/docs/chart/x-axis`),null)};class rs{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=rs.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=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);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),e.restore()}}drawLabels(t,e,n,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,d=n.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 tn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},uo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return tn[s.key]+s.value;case"lessThanSecond":return tn[s.key];case"week-weekday":return tn[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},go=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Vu=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const g=r[u],m=g.idx;for(;c<a;){const C=o[c],_=C.idx;if(m>_)c++,n.push(C),d=_,h=1/0;else{h=_;break}}h-m>=t&&m-d>=t&&(n.push(g),d=m)}for(;c<a;)n.push(o[c]),c++}return n},Gu=(s,t,e,n,i,r)=>{const o=rs.getFontFromConfig(t),a=Pt(e.text,s,o),l=Pt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function en(s){"@babel/helpers - typeof";return en=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},en(s)}function Ct(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function yt(s){Ct(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||en(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Zu(s){return Ct(1,arguments),yt(s).getDay()===1}function $u(s){return Ct(1,arguments),yt(s).getDay()===2}function Ku(s){return Ct(1,arguments),yt(s).getDay()===3}function qu(s){return Ct(1,arguments),yt(s).getDay()===4}function Ju(s){return Ct(1,arguments),yt(s).getDay()===5}function Qu(s){return Ct(1,arguments),yt(s).getDay()===6}function tg(s){return Ct(1,arguments),yt(s).getDay()===0}function eg(s,t){var e;Ct(1,arguments);var n=s||{},i=yt(n.start),r=yt(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(yt(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function sg(s){Ct(1,arguments);var t=yt(s);return t.setDate(1),t.setHours(0,0,0,0),t}function ng(s){Ct(1,arguments);var t=yt(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function fo(s){Ct(1,arguments);var t=yt(s);return t.setHours(0,0,0,0),t}function po(s,t){Ct(2,arguments);var e=fo(s),n=fo(t);return e.getTime()===n.getTime()}const ig=s=>{switch(s.key){case"lessThanSecond":return lg(s);case"month":return cg(s);case"second":case"minute":case"hour":case"day":case"year":return hg(s);case"week-weekday":return dg(s);default:return()=>!1}},Gt=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},sn=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n!==i},rg=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n>=i},og={1:Zu,2:$u,3:Ku,4:qu,5:Ju,6:Qu,7:tg},ag=(s,t,e)=>{var n;const i=eg({start:sg(s),end:ng(s)}),r=(n=og[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return po(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return po(s,a);o++}}return!1},mo=(s,t)=>t===1?s===1:s/t===1,vo=(s,t)=>t===1?!0:s%t===0,lg=s=>(t,e)=>rg(s.key)(t,e),cg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?mo(Gt(t,s.key)+1,s.value):vo(Gt(t,s.key)+1,s.value);return n&&i},hg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?mo(Gt(t,s.key),s.value):vo(Gt(t,s.key),s.value);return n&&i},dg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=ag(t,s.week,s.weekday);return n&&i},ug=s=>{switch(s.key){case"second":case"minute":return gg(s.value);case"hour":return fg(s.value);case"day":return pg(s.value);case"month":return bg(s.value);case"year":return Cg(s.value);case"week-weekday":const t=vg(s.week),e=mg(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},gg=s=>s>0&&s<=60,fg=s=>s>0&&s<=24,pg=s=>s>0&&s<=31,mg=s=>bo(s)?s>=1&&s<=7:!1,vg=s=>s==="$"?!0:bo(s)?s>=1&&s<=6:!1,bg=s=>s>0&&s<=12,Cg=s=>s>0,bo=s=>!isNaN(s)&&isFinite(s),yg=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function nn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:yg(a,i,t)};n[r]=l,i=a}return n}const Co=s=>{const t={},e={};return Ls(s).forEach(([n,i])=>{const r=ho(n),o=r===null?!1:ug(r);if(r&&o){const a=uo(r);t[a]=i,e[a]=ig(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class yo{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},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?ut(d,h.animationConfig.targetZoomX):ut(d,this.scale.zoomX);if(!isFinite(u))return-1;const g=this.config.components.xAxis.fontSize,m=Object.values(this.formatsByWeightMap).reduce((_,M)=>Math.max(M.length,_),1),C=g*m;return Math.round(C/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Co(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(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(){const t=this.chartModel.mainCandleSeries.visualPoints;if(t.length===0)return[];const n=Array.from({length:750}).map((i,r)=>Yi(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,t.length+r,this.chartModel.getPeriod()));return[...t,...n]}mapWeightedPointsToLabels(t,e){var n;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:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=Co(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(){const t=this.getAllCandlesWithFake(),e=nn(t,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),n=this.mapWeightedPointsToLabels(e,t);this.labelsGroupedByWeight=go(n),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}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=nn([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(g=>g.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]),n=nn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=go(i),o=We(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),g=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&g.shift(),g){const m=g.map(C=>(C.idx=C.idx+t.length,C.value=a.startUnit+a.width+C.value,C));r[u]?c[h]=d.concat(m):c[h]=m}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(){this.generateWeightedLabels()}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 n=Vu(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Gu(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=Ls(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=ho(o);if(l){const c=uo(l);i[c]=a}}return i},{});return Ls(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class wg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(Ge,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}class Sg extends X{constructor(t,e,n,i,r,o){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTestCanvasModel=o,this.lastXStart=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=l.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=l=>{const{delta:c}=l,h=this.lastXPxWidth-c;if(h<0)return;const d=this.lastXPxWidth/h,u=this.lastXWidth*d,g=this.lastXStart+(this.lastXWidth-u);this.scale.setXScale(g,this.scale.xEnd)},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const a=new _e(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS),{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(a)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS)).subscribe(()=>this.chartModel.doBasicScale())),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class xg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h;const m=new yo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=m,this.xAxisLabelsModel=new wg(t,[]);const C=new Ws;c.addDrawer(C,"X_AXIS"),this.xAxisDrawer=new rs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),C.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new ju(e,n,o,this.xAxisLabelsModel),C.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new Sg(r,a,o,d,this.chartComponent.chartModel,g),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(K(({prependedCandles:t})=>t.length!==0),ht(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;Ka.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(xt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Ne(50,je,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ht(()=>bt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Mt((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.timestamp)===((i=e==null?void 0:e.candle)==null?void 0:i.timestamp)}),K(Xn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.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 yo?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 _g=Object.defineProperty,wo=Object.getOwnPropertySymbols,Pg=Object.prototype.hasOwnProperty,Tg=Object.prototype.propertyIsEnumerable,So=(s,t,e)=>t in s?_g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,os=(s,t)=>{for(var e in t||(t={}))Pg.call(t,e)&&So(s,e,t[e]);if(wo)for(var e of wo(t))Tg.call(t,e)&&So(s,e,t[e]);return s};class Mg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&os(os({},n),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&&os(os({},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=bt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=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:qt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const c=$d(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,c,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,r,o),rounded:!0}}}class Ag{constructor(t,e,n,i,r){this.yAxisLabelsCanvasModel=t,this.backgroundCanvasModel=e,this.canvasBoundsContainer=n,this.fullConfig=i,this.paneManager=r}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx;this.paneManager.yExtents.forEach(n=>{if(n.yAxis.state.visible){const i=n.getYAxisBounds(),r=this.canvasBoundsContainer.getBounds(x.ALL_PANES),o=n.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(o),o.forEach(a=>{var l;const c=(l=a.bounds)!=null?l:i;a.labels.forEach(h=>Dr(t,e,c,r,h,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}),Object.values(n.yAxis.model.fancyLabelsModel.customLabels).forEach(a=>Dr(t,e,i,r,a,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(tt));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];rr(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 Eg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height);const o=Jt(e.state),a=kt(o,r),l=this.getLabelTextColor();r.save(),Ut(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const g=a.scale.toY(u.value);g>h&&g<d&&Dg(t,n,u.text,g,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 Dg=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class Ig{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Fa.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new O,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];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(Ge,t)}}class Lg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ht(r=>i.components.chart.highlightActiveCandle?r:void 0),Mt()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class Bg{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${_t()}`,this.canvasResized=new O,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Ns(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.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(Fs,e),this.bus.fire(Ge))}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.previousBCR!==void 0}}var Og=Array.isArray,Rg=Object.getPrototypeOf,Fg=Object.prototype,Hg=Object.keys;function kg(s){if(s.length===1){var t=s[0];if(Og(t))return{args:t,keys:null};if(Yg(t)){var e=Hg(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Yg(s){return s&&typeof s=="object"&&Rg(s)===Fg}var jg=Array.isArray;function Ng(s,t){return jg(t)?s.apply(void 0,D([],p(t))):s(t)}function Xg(s){return ht(function(t){return Ng(s,t)})}function zg(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Wg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Ie(s),n=na(s),i=kg(s),r=i.args,o=i.keys;if(r.length===0)return Le([],e);var a=new pt(Ug(r,e,o?function(l){return zg(o,l)}:ie));return n?a.pipe(Xg(n)):a}function Ug(s,t,e){return e===void 0&&(e=ie),function(n){xo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){xo(t,function(){var d=Le(s[h],t),u=!1;d.subscribe(Tt(n,function(g){r[h]=g,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function xo(s,t,e){s?Ht(e,s,t):t()}class Vg extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new mt(null)}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Wg([n,i]).pipe(K(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}else this.crossSubject.next(null),r=!0});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}class Gg{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,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 Zg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Gg(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class $g{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof wr)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 Kg=Object.defineProperty,qg=Object.defineProperties,Jg=Object.getOwnPropertyDescriptors,_o=Object.getOwnPropertySymbols,Qg=Object.prototype.hasOwnProperty,tf=Object.prototype.propertyIsEnumerable,Po=(s,t,e)=>t in s?Kg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Pe=(s,t)=>{for(var e in t||(t={}))Qg.call(t,e)&&Po(s,e,t[e]);if(_o)for(var e of _o(t))tf.call(t,e)&&Po(s,e,t[e]);return s},rn=(s,t)=>qg(s,Jg(t));class ef extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.formatterFactory=c,this.hoverSubject=new mt(null),this.longTouchActivatedSubject=new mt(!1),this.xFormatter=()=>"";const h=new Zg(this.chartModel),d=new $g(this.chartModel);this.hoverProducerParts={candleHover:h,compareSeriesHover:d}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.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(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;const i=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,r=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y,o=this.chartModel.candleFromX(i,!0),a=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";o&&this.createAndFireHover([i,r,a])}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;this.paneManager.chartPanComponent.deactivatePanHandlers(),this.longTouchActivatedSubject.next(!0);const i=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,r=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y,o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o]),this.crossEventProducer.crossSubject.next([i,r,o])})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(()=>{this.paneManager.chartPanComponent.activateChartPanHandlers(),this.longTouchActivatedSubject.getValue()&&(this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose())})),this.addRxSubscription(xt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter()))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=Lr(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,tt)}createHover(t,e,n){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:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>rn(Pe({},l),{[c[0]]:c[1].getData(o)}),{});return Pe(Pe({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=rn(Pe({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e;if(t){if(_s()&&this.config.components.crossTool.type!=="none"){const n=(e=t.candleHover)==null?void 0:e.visualCandle.candle;n&&this.chartModel.mainCandleSeries.setActiveCandle(n)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=rn(Pe({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const To={left:0,middle:1,right:2};function gt(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function ue(s){return t=>{t.button===To.left&&s(t)}}var sf=Object.defineProperty,Mo=Object.getOwnPropertySymbols,nf=Object.prototype.hasOwnProperty,rf=Object.prototype.propertyIsEnumerable,Ao=(s,t,e)=>t in s?sf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,of=(s,t)=>{for(var e in t||(t={}))nf.call(t,e)&&Ao(s,e,t[e]);if(Mo)for(var e of Mo(t))rf.call(t,e)&&Ao(s,e,t[e]);return s};const ee=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new O,this.xDragSubject=new O,this.xDragTickSubject=new O,this.xDragEndSubject=new O,this.yDragStartSubject=new O,this.yDragSubject=new O,this.yDragTickSubject=new O,this.yDragEndSubject=new O,this.mouseMoveSubject=new O,this.mouseMoveDocumentSubject=new O,this.clickSubject=new O,this.clickDocumentSubject=new O,this.dbClickSubject=new O,this.dbTapSubject=new O,this.mouseDownSubject=new O,this.mouseUpSubject=new O,this.mouseUpDocumentSubject=new O,this.wheelSubject=new O,this.touchStartSubject=new O,this.touchStartTimestamp=0,this.touchMoveSubject=new O,this.touchEndSubject=new O,this.touchCancelSubject=new O,this.longTouchStartSubject=new O,this.longTouchEndSubject=new O,this.contextMenuSubject=new O,this.fastTouchScroll=new O,this.mouseLeavesCanvasSubject=new O,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.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=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=ee.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=of({},this.dragStartPoint),ee.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===To.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ee.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),ee.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),ee.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,ue(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,ue(e=>this.clickDocumentSubject.next(e)),"click"));const s=Wr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(gt(this.element,n,"touchend"));const i=(o,a=700,l=3)=>{o.preventDefault();const c={x:o.touches[0].clientX,y:o.touches[0].clientY};let h={x:0,y:0},d=!1,u=null;u=setTimeout(()=>{d=!0,this.longTouchStartSubject.next(o)},a);const g=C=>{C.preventDefault(),h={x:C.touches[0].clientX,y:C.touches[0].clientY},(Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2))>l||C.touches.length>1)&&u&&clearTimeout(u)},m=C=>{C.preventDefault(),u&&clearTimeout(u),d&&(d=!1,this.longTouchEndSubject.next(C)),this.element.removeEventListener("touchend",m),this.element.removeEventListener("touchmove",g)};this.element.addEventListener("touchmove",g),this.element.addEventListener("touchend",m)};this.addSubscription(gt(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,m=d<=250;g&&m&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,ue(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(gt(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(gt(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(gt(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(gt(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(gt(this.element,e=>{this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(gt(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(gt(this.element,ue(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,ue(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,ue(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(Fs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ee.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(K(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(K(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ht(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(K(()=>!(t&&this.dragging)),ht(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ht(()=>!1));return xt(e,n).pipe(Mt())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)),so(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let as=ee;as.DRAG_START_EVENTS=["mousedown","touchstart"],as.DRAG_EVENTS=["mousemove","touchmove"],as.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var af=function(s){W(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Es);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=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),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<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}(O);const on={};function lf(s){return on[s]||(on[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),on[s]}const Eo=(s,t=Date.now())=>{const n=lf(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);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},Do=60*1e3;class cf{constructor(t){this.config=t,this.timeZoneChangedSubject=new af,this.currentTzOffset=e=>Eo(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Do,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 n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Uh(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+Eo(t,e)+new Date(e).getTimezoneOffset()*Do):e=>new Date(e)}}class hf extends X{constructor(t,e,n){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=n}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(Mt((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class an{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;qa(r),this.config=r;const o=bl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new cf(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Cl(t);this.elements=c;const h=new Ig;this.bus=h;const d=new Bg(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 oh(h,d);this.drawingManager=u;const g=ih(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=g,this.dynamicObjectsCanvasModel=he(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const m=new Se(this.dynamicObjectsCanvasModel);u.addDrawer(m,"SERIES_CLEAR");const C=he(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),_=new As(r,h,g,l,d);this.canvasBoundsContainer=_;const M=c.mainCanvas.parentElement;if(M===null)throw new Error("Couldn't get main canvas parent");const L=new as(h,M);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const H=new sd(h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=H;const z=new Se(H);u.addDrawer(z,"HIT_TEST_CLEAR");const R=new Aa(h);this.canvasAnimation=R;const F=x.PANE_UUID(tt),Y=new nr(r,()=>_.getBounds(F),R);this.scaleModel=Y;const q=he(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=q,this.cursorHandler=new pl(c.canvasArea,L,_,H),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Vg(L,_),this.chartComponents.push(this.crossEventProducer);const V=new Wl("candle");this.chartBaseModel=V;const N=new Yd(h,Y,_,r,R,L,M,V,H);this.chartPanComponent=N,this.chartComponents.push(N),this.userInputListenerComponents.push(N.chartAreaPanHandler);const U=new hf(H,R,h);this.hitTestComponent=U,this.chartComponents.push(U);const Q=new Su(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,Y,_,r,R,L,u,this.cursorHandler,this.crossEventProducer,N,g,C,this.hitTestCanvasModel);this.paneManager=Q;const J=this.paneManager.panes[tt];this.mainPane=J,this.chartComponents.push(Q),this.dynamicObjects=new zh(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Ah(V,Q,h,this.dynamicObjectsCanvasModel,r,Y,l,M,_,d);const st=new mh(this.chartModel,this.dynamicObjectsCanvasModel,r,Y,_,u,H,L,q,N,Q,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(st),this.chartComponent=st;const G=this.chartComponent.chartModel;this.chartModel=G,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),H.addSubscriber(Q.hitTestController),this.xAxisComponent=new xg(h,r,g,st,Y,_,L,d,this.drawingManager,a,N,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const nt=new Se(g);u.addDrawer(nt,"MAIN_CLEAR");const ot=new Lg(M,G,L,r);this.chartComponents.push(ot),this.watermarkComponent=new ku(Q,G,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ft=he(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new wd(h,r,G,g,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(G)),this.navigationMapComponent=new Dd(h,G,g,r,L,_,u,l,N,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const at=new fd(r,this.dynamicObjectsCanvasModel,G,_,u);this.chartComponents.push(at),this.initYAxisDrawer(C),this.yAxisComponent=J.mainExtent.yAxis;const wt=new Mg(this.chartModel,this.config,J.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(wt,Ks.MAIN),this.volumesComponent=new Lu(this.dynamicObjectsCanvasModel,st,Y,_,u,r,Q,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const se=new kr(g,Y,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(F),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>this.yAxisComponent.model.baseLabelsModel.labels,()=>J.mainExtent.toY(J.mainExtent.getBaseline()),()=>r.components.grid.visible);this.chartComponents.push(se),this.hoverProducer=new ef(this.crossEventProducer,Y,r,G,L,this.canvasBoundsContainer,this.paneManager,a,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new Yh(r,ft,_,u,Q,this.crossEventProducer,this.hoverProducer),this.chartComponents.push(this.crossToolComponent);const cs=he(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),ln=new xu(this.elements,cs);this.snapshotComponent=ln,this.chartComponents.push(ln);const cn=new dd(r,this.dynamicObjectsCanvasModel,H,G,_,u,l,this.cursorHandler);this.eventsComponent=cn,this.chartComponents.push(cn),this.chartComponents.forEach(hn=>hn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Da(this.components)}initYAxisDrawer(t){const e=new Ws,n=new Se(t);e.addDrawer(n,"YAXIS_CLEAR"),this.drawingManager.addDrawer(e,"Y_AXIS");const i=new Eg(this.config,t,this.paneManager);e.addDrawer(i);const r=new Ag(t,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);e.addDrawer(r)}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&an.mergeConfig(t[n],e[n]):t[n]=e[n];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,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[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){At(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=xt(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class Io extends an{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 n;(n=this.paneManager.panes[t])==null||n.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,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.chartComponent.setChartType(t)}createPane(){return this.paneManager.createPane()}}var df=Object.defineProperty,uf=Object.defineProperties,gf=Object.getOwnPropertyDescriptors,Lo=Object.getOwnPropertySymbols,ff=Object.prototype.hasOwnProperty,pf=Object.prototype.propertyIsEnumerable,Bo=(s,t,e)=>t in s?df(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,mf=(s,t)=>{for(var e in t||(t={}))ff.call(t,e)&&Bo(s,e,t[e]);if(Lo)for(var e of Lo(t))pf.call(t,e)&&Bo(s,e,t[e]);return s},vf=(s,t)=>uf(s,gf(t));function Oo(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=ls(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(yf(t[t.length-1],a,n)):d>3?t=t.concat(bf(t[t.length-1],a,r)):t=t.concat(Cf(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let g=0;g<t.length;g++){const m=t[g];Object.assign(m,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(m.volume=Math.ceil(Math.random()*1e3+200))}return t}function ls(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function bf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=ls(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),n.push(c)}return n}function Cf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=ls(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),n.push(c)}return n}function yf(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var g,m;return Math.random()>.5?(g=u.lo-t*.2,m=u.hi+t*1.2):(g=u.lo-t*1.2,m=u.hi+t*.2),{from:g,to:m}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=ls(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),n.push(d)}return n}window.DXChart=vf(mf({},window.DXChart),{generateCandlesData:Oo});function wf(s){return Oo(s)}const Sf=(s,t={})=>new Io(s,t)})(),window.DXChart=hs})();})();
23
+ `;function vl(s){const t=document.createElement("template");return t.innerHTML=ml(s.devexpertsPromoLink),t}function bl(s){const t={},e=Array.from(s.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(n=>{var i;t[(i=n.getAttribute("data-element"))!=null?i:""]=n}),pl(t))return t;throw new Error("Some chart elements are missing")}function Cl(s){if(s.length>1){const t=s.reduce((i,r,o)=>{if(o!==s.length-1){const a=s[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,n;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,n=r)}if(n)return n}}const ve=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=re(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=bt(e))==null?void 0:o.timestamp)!=null?a:0;return s>c?t?{index:e.length-1+Math.ceil((s-c)/n),exact:!0}:{index:e.length-1,exact:!0}:s<l?t?{index:et((s-l)/n),exact:!0}:{index:-1,exact:!0}:Lt(e,s,h=>h.timestamp)},Ds=1;function ze(s,t){return t===s?"none":t>s?"up":"down"}function yl(s,t){return t>s?"up":"down"}function wl(s,t,e=!1){const{expansion:n,impVolatility:i,vwap:r,volume:o,timestamp:a}=s;let l=s.hi,c=s.lo,h=s.open;const d=s.close;e&&(l=d,c=d,h=d);let u=s.idx;return t!==void 0&&(u=t),{hi:l,lo:c,open:h,close:d,timestamp:a,volume:o,expansion:n,idx:u,impVolatility:i,vwap:r}}const yi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2},wi={paintConfig:[yi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var Sl=Object.defineProperty,Si=Object.getOwnPropertySymbols,xl=Object.prototype.hasOwnProperty,_l=Object.prototype.propertyIsEnumerable,xi=(s,t,e)=>t in s?Sl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Pl=(s,t)=>{for(var e in t||(t={}))xl.call(t,e)&&xi(s,e,t[e]);if(Si)for(var e of Si(t))_l.call(t,e)&&xi(s,e,t[e]);return s};class Tl{constructor(t,e,n,i){this.series=t,this.config=e,this.yAxisBoundsProvider=n,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,n=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:[Pl({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:n}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:yi).color;return{textColor:qt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}let Bt=window.devicePixelRatio,We=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Is=()=>{We.removeEventListener("change",Is),Bt=window.devicePixelRatio,We=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),We.addEventListener("change",Is)};We.addEventListener("change",Is);const Ml=()=>Bt,Al=s=>Kt(Bt*s)/Bt,Z=s=>et(Bt*s)/Bt,_i=s=>ma(Bt*s)/Bt,be=s=>JSON.parse(JSON.stringify(s));function Ls(s){return Object.entries(s)}const Pi=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Ti(s){return Object.keys(s)}function Mi(s,t){if(Object.is(s,t))return!0;if(typeof s!="object"||s===null||typeof t!="object"||t===null)return!1;const e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!Mi(s[e[i]],t[e[i]]))return!1;return!0}function Ai(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new O}:t,n=s.resetOnError,i=n===void 0?!0:n,r=s.resetOnComplete,o=r===void 0?!0:r,a=s.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,g=0,m=!1,C=!1,_=function(){d==null||d.unsubscribe(),d=void 0},M=function(){_(),h=u=void 0,m=C=!1},L=function(){var H=h;M(),H==null||H.unsubscribe()};return j(function(H,z){g++,!C&&!m&&_();var R=u=u!=null?u:e();z.add(function(){g--,g===0&&!C&&!m&&(d=Bs(L,l))}),R.subscribe(z),!h&&g>0&&(h=new ge({next:function(F){return R.next(F)},error:function(F){C=!0,_(),d=Bs(M,i,F),R.error(F)},complete:function(){m=!0,_(),d=Bs(M,o),R.complete()}}),Ft(H).subscribe(h))})(c)}}function Bs(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];if(t===!0){s();return}if(t!==!1){var i=new ge({next:function(){i.unsubscribe(),s()}});return Ft(t.apply(void 0,D([],p(e)))).subscribe(i)}}const Ue=(s,t)=>s/t,ut=(s,t)=>s/t,jt=(s,t)=>s*t,Ei=(s,t)=>(s-t)*100/t,Di=(s,t)=>s*t/100+t,Ii=s=>Math.log2(s),Os=s=>Math.pow(2,s);class El 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 O,this.xChanged=this.changed.pipe(ht(()=>({start:this.xStart,end:this.xEnd})),Mt((t,e)=>t.start===e.start&&t.end===e.end),Ai()),this.yChanged=this.changed.pipe(ht(()=>({start:this.yStart,end:this.yEnd})),Mt((t,e)=>t.start===e.start&&t.end===e.end),Ai())}doActivate(){super.doActivate()}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ut(t-this.xStart,this.zoomX)}xPixels(t){return ut(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ut(t-this.yStart,this.zoomY):e.y+e.height-ut(t-this.yStart,this.zoomY)}yPixels(t){return ut(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return jt(e+ut(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?jt(n+ut(this.yStart,this.zoomY),this.zoomY):jt(e.height-n+ut(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 Ue(e-t,this.getBounds().width)}calculateZoomY(t,e){return Ue(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,n=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),n&&this.fireChanged()}setYScale(t,e,n=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),n&&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(){return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&this.zoomX>0&&this.zoomY>0}}const Dl=(s,t)=>!Ti(s).some(e=>s[e]!==t[e]);class Il{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let n;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(Lt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Lt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class Li{constructor(t,e,n,i){this.dataSeries=t,this.scale=e,this.getAxisType=n,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 Il(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ei(t,n);case"logarithmic":return Ii(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 Di(t,this.getBaseline());case"logarithmic":return Os(t);case"regular":return t}}}var Ll=Object.defineProperty,Bl=Object.defineProperties,Ol=Object.getOwnPropertyDescriptors,Bi=Object.getOwnPropertySymbols,Rl=Object.prototype.hasOwnProperty,Fl=Object.prototype.propertyIsEnumerable,Oi=(s,t,e)=>t in s?Ll(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Hl=(s,t)=>{for(var e in t||(t={}))Rl.call(t,e)&&Oi(s,e,t[e]);if(Bi)for(var e of Bi(t))Fl.call(t,e)&&Oi(s,e,t[e]);return s},kl=(s,t)=>Bl(s,Ol(t));class Ce{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Z(t.toY(this.close))}x(t){return Z(t.toX(this.centerUnit))}clone(){return new Ce(this.centerUnit,this.close)}}class Ri extends X{constructor(t,e,n,i=be(wi)){var r;super(),this.extentComponent=t,this.id=e,this.htId=n,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=o=>{var a;return(a=this.config.paintConfig[o])!=null?a:this.config.paintConfig[0]},this.getBaseline=(o=this.dataIdxStart)=>{var a,l;return(l=(a=this.visualPoints[o])==null?void 0:a.close)!=null?l:1},this.getTextForPoint=o=>`${o.close}`,this.getLastVisualSeriesPoint=()=>{const o=this.visualPoints,a=Lt(o,this.scale.xEnd,l=>l.centerUnit).index;return o[a]},this.getLastDataSeriesPoint=()=>{const o=this.visualPoints;return bt(o)},this.config=At(i,wi),this.scale=t.scale,this.view=new Li(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Tl(this,this.config,t.getYAxisBounds,(r=t.yAxis)==null?void 0:r.state),this.highLowProvider=jl(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Un(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=Un(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new Li(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,this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,n)=>({centerUnit:n,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:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const n=Lt(this.visualPoints,t,r=>r.centerUnit).index,i=Lt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return Fi(t)}getSeriesInViewport(t,e){let n=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);n=r.dataIdxStart,i=r.dataIdxEnd}return Ba(this.visualPoints2D,n,i)}}const Yl=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.close>t.high&&(t.high=n.close,t.highIdx=e),n.close<t.low&&(t.low=n.close,t.lowIdx=e)}return t},jl=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=Yl(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return kl(Hl({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),Fi=s=>{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))))(s);return dt.makeDecimal(s,i)};class Ve extends Ce{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.width=e,this.open=n,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Z(Math.abs(t.toY(this.open)-t.toY(this.close)))}candleHeight(t){return Z(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=Z(t.toY(this.high)),n=Z(t.toY(this.low)),i=Z(t.toY(this.open)),r=Z(t.toY(this.close)),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Z(Math.max(t.toY(this.high),t.toY(this.low)))}yLineStart(t){return Z(Math.min(t.toY(this.high),t.toY(this.low)))}yBodyStart(t){return Z(Math.min(t.toY(this.open),t.toY(this.close)))}yBodyEnd(t){return Z(Math.max(t.toY(this.open),t.toY(this.close)))}xCenter(t){return this.x(t)}xStart(t){return Al(t.toX(this.startUnit))}}const ae=60,ye=(s,t,e=ae)=>({hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:Hi(s,t,e),volume:NaN,expansion:!0,idx:t}),Nl=(s,t,e=ae)=>({close:NaN,timestamp:Hi(s,t,e)});function Hi(s,t,e=ae){var n,i;const r=Kt(t);if(s.length===0)return 0;const o=bt(s);if(r>=s.length&&o)return ki(o,s.length-1,r,e);const a=re(s);return r<0&&a?ki(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const ki=(s,t,e,n=ae)=>s.timestamp+(e-(t!=null?t:0))*n,Yi=(s,t,e,n,i=ae)=>{const r=ye(s,n,i);r.volume=e;let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Ve(o,e,r.open,r.close,r.lo,r.hi,ze(r.open,r.close),r)},Xl=(s,t,e,n,i=ae)=>{const r=Nl(s,n,i);let o;if(t.length===0)o=0;else if(n>=t.length){const a=t[t.length-1],c=(n-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-n*e;o=a.centerUnit-c}return new Ce(o,r.close)};class zl{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new O,this.dataSetSubject=new O,this.dataRemovedSubject=new O,this.dataPrependSubject=new O,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e=!0,n=this.mainDataPoints){const i=ve(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=Cl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Yi(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):Xl(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var Wl=Object.defineProperty,ji=Object.getOwnPropertySymbols,Ul=Object.prototype.hasOwnProperty,Vl=Object.prototype.propertyIsEnumerable,Ni=(s,t,e)=>t in s?Wl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Gl=(s,t)=>{for(var e in t||(t={}))Ul.call(t,e)&&Ni(s,e,t[e]);if(ji)for(var e of ji(t))Vl.call(t,e)&&Ni(s,e,t[e]);return s};class Zl{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={}}draw(){if(this.drawPredicate()||!Mi(this.config.colors.chartAreaTheme,this.prevState)){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=Gl({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const $l=(s,t,e,n,i,r,o)=>{const a=Ml(),l=[e*a,n*a,i*a,r*a];let c=s.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]=et(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?et(u*o):et(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Xi=(s,{x:t,width:e,activeCandle:n})=>new Ve(t,e,s.open,s.close,s.hi,s.lo,ze(s.open,s.close),s,!0,Rs(s,n)),Kl=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ve(t,e,s.open,s.close,s.hi,s.lo,yl((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},zi=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Ve(t,e,s.open,s.close,s.hi,s.lo,ze((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Rs(s,n),s.close>s.open)},ql=zi,Rs=(s,t)=>{const e=t&&t.idx===s.idx;return e!=null?e:!1},Wi=()=>Ds,Qt=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>et(Math.log10((n^n>>31)-(n>>31)))+1;let e=t(s);return e===1&&s<1&&(e=t(s*1e9)-9),e}static getPriceIncrement(s,t=[]){if(!this.validatePriceIncrementsOrPrecisions(t))return this.DEFAULT_INCREMENT;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;const n=1e-6;for(;e<t.length&&s>t[e]+Math.min(t[e-1],t[e+1])*n;)e+=2;return e>=t.length||s<t[e]-Math.min(t[e-1],t[e+1])*n?t[e-1]:Math.min(t[e-1],t[e+1])}static getPricePrecision(s,t){if(!this.validatePriceIncrementsOrPrecisions(t))return 0;if(isNaN(s))return Math.round(t[0]);s=Math.abs(s);let e=1;for(;e<t.length&&s>t[e];)e+=2;return Math.round(t[e-1])}static roundPriceToIncrement(s,t,e){const n=Qt.getPriceIncrement(e||s,t);return dt.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=Qt.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*Qt.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<Qt.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*Qt.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return Qt.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Ot=Qt;Ot.DEFAULT_INCREMENT=.01,Ot.DEFAULT_PRECISION=2,Ot.RELATIVE_EPS=1e-8,Ot.MAXIMUM_PRECISION=10;const Jl=(s,t)=>{var e;const n=(e=bt(t))!=null?e:1;return Math.pow(10,-n)};var Ql=Object.defineProperty,tc=Object.defineProperties,ec=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,sc=Object.prototype.hasOwnProperty,nc=Object.prototype.propertyIsEnumerable,Vi=(s,t,e)=>t in s?Ql(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ic=(s,t)=>{for(var e in t||(t={}))sc.call(t,e)&&Vi(s,e,t[e]);if(Ui)for(var e of Ui(t))nc.call(t,e)&&Vi(s,e,t[e]);return s},rc=(s,t)=>tc(s,ec(t));const oc=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:s.scale.xStart,n=t?t.xEnd:s.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=s.calculateDataViewportIndexes(e,n),o=s.visualPoints.slice(i,r+1),a=Gi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return rc(ic({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Gi=s=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<s.length;e++){const n=s[e];n.high>t.high&&(t.high=n.high,t.highIdx=e),n.low<t.low&&(t.low=n.low,t.lowIdx=e)}return t},ac=20,Zi=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:ac,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},Fe,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class lc{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){cc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const cc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=$i(i),o=n.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=s.calculateZoomY(t.yStart,t.yEnd)};function $i(s){if(s.length===0)return hc();let t=s[0].high,e=s[0].low;return s.forEach(n=>{isFinite(n.high)&&n.high>=t&&(t=n.high),isFinite(n.low)&&n.low<=e&&(e=n.low)}),{low:e,high:t}}const hc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),dc=(s,t)=>s/t,uc=(s,t)=>s/t,gc=(s,t)=>s*t,Ki=(s,t)=>{const e=s.zoomY;s.zoomY=uc(s.zoomX,t);const n=s.zoomY/e,i=s.yEnd-s.yStart,o=i*n-i;s.yEnd=s.yEnd+o/2,s.yStart=s.yStart-o/2},fc=(s,t)=>{const e=s.zoomX;s.zoomX=gc(s.zoomY,t);const n=s.zoomX/e,i=s.xEnd-s.xStart,o=i*n-i;s.xStart=s.xStart-o},pc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},mc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},qi=(s,t,e,n,i)=>{const r=(t.xEnd-t.xStart)*n,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=s.calculateZoomX(t.xStart,t.xEnd),t},vc=(s,t,e,n)=>qi(s,t,1,e,n);var bc=Object.defineProperty,Cc=Object.defineProperties,yc=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,wc=Object.prototype.hasOwnProperty,Sc=Object.prototype.propertyIsEnumerable,Qi=(s,t,e)=>t in s?bc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,we=(s,t)=>{for(var e in t||(t={}))wc.call(t,e)&&Qi(s,e,t[e]);if(Ji)for(var e of Ji(t))Sc.call(t,e)&&Qi(s,e,t[e]);return s},xc=(s,t)=>Cc(s,yc(t));const _c=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class tr extends El{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new O,this.beforeStartAnimationSubject=new O,this.zoomXYRatio=0,this.zoomReached={min:!1,max:!1},this.history=[],this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=be(t.scale),this.autoScaleModel=new lc(this),this.offsets=this.config.components.offsets}doActivate(){super.doActivate(),this.scaleInversedSubject=new O,this.beforeStartAnimationSubject=new O,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=we(we({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,n=!1,i){const r=this.config.scale.disableAnimations||n;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();qi(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){this.config.scale.disableAnimations&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const n=this.export();vc(this,n,e,t),this.zoomXTo(n,t,this.config.scale.disableAnimations)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.doAutoScale())}zoomXTo(t,e,n){const i=we({},t),r=this.scalePostProcessor(i,t);this.zoomReached=this.calculateZoomReached(r.zoomX,e),!(this.zoomReached.max||this.zoomReached.min)&&(this.state.lockPriceToBarRatio&&Ki(r,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(r),n?this.apply(r):Zi(this.canvasAnimation,this,r))}calculateZoomReached(t,e=!0){const n=this.getBounds().width,i=.001;if(n>0){const o=t-Ue(this.config.components.chart.minCandles,n)<=i&&e,l=t-Ue(n/this.config.components.chart.minWidth,n)>=i&&!e;return{max:o,min:l}}return{max:!1,min:!1}}setXScale(t,e,n=!0){const i=this.export(),r=this.calculateZoomX(t,e);if(i.xStart===t&&i.xEnd===e&&i.zoomX>0)return;const o=xc(we({},i),{zoomX:r,xStart:t,xEnd:e}),a=this.scalePostProcessor(i,o),l=a.xEnd-a.xStart<i.xEnd-i.xStart;this.zoomReached=this.calculateZoomReached(r,l),!(this.zoomReached.max||this.zoomReached.min)&&(this.state.lockPriceToBarRatio&&Ki(a,this.zoomXYRatio),this.state.auto&&this.autoScaleModel.doAutoYScale(a),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(a)):Zi(this.canvasAnimation,this,a))}setYScale(t,e,n=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);if(this.state.lockPriceToBarRatio){fc(o,this.zoomXYRatio),this.setXScale(o.xStart,o.xEnd);return}else this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}moveXStart(t){const e=this.export(),n=we({},e);this.haltAnimation(),pc(e,t);const i=this.scalePostProcessor(n,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();mc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Dl(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}t&&this.recalculateZoomXYRatio(),this.state.lockPriceToBarRatio=t}recalculateZoomXYRatio(){this.zoomXYRatio=dc(this.zoomX,this.zoomY)}}class Pc extends tr{constructor(t,e,n,i){super(e,n,i),this.delegate=t,this.config=e,this.getBounds=n}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 Tc=ke().colors;class Wt extends Ri{constructor(t,e,n,i,r,o,a,l,c=Tc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=_c(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new O,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=oc(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=Ot.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:n,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=n,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const n=Lt(this.visualPoints,t,r=>r.startUnit).index,i=Lt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=bt(this.dataPoints);t&&(this.lastPriceMovement=ze(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Gi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd))}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=At(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Wi;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),g=a+u/2,m=(i=this.candlesTransformersByChartType[r])!=null?i:Xi;o.push(m(h,{x:g,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,n)=>e+n.width,0)/t.length:this.meanCandleWidth=Ds}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 Wf(s){switch(s){case"line":case"area":return!0;default:return!1}}class Mc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);if(r.length===0)return;i.singleColor?t.strokeStyle=i.singleColor:t.strokeStyle=n.colors.areaTheme.lineColor,n.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const o=n.extentComponent.getBounds(),a=r[0],l=n.view.toX(a.centerUnit);for(let c=0;c<r.length;c++){const h=r[c-1],d=r[c+1],u=r[c],g=n.view.toX(u.centerUnit),m=n.view.toY(u.close),C=o.y+o.height;if(h===void 0)t.beginPath(),t.lineTo(et(g),C),t.moveTo(et(g),m);else if(d===void 0){t.lineTo(et(g),m),t.stroke(),t.lineTo(et(g),C),t.lineTo(et(l),C),t.closePath();let _;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(_=t.createLinearGradient(0,0,0,o.height),_.addColorStop(0,n.colors.areaTheme.startColor),_.addColorStop(1,n.colors.areaTheme.stopColor),_):"",t.fill()}else t.lineTo(et(g),m)}}}}function er(s,t,e,n,i,r=4,o=!0,a=!1){s.save(),s.beginPath(),s.moveTo(t+r,e),s.lineTo(t+n-r,e),s.quadraticCurveTo(t+n,e,t+n,e+r),s.lineTo(t+n,e+i-r),s.quadraticCurveTo(t+n,e+i,t+n-r,e+i),s.lineTo(t+r,e+i),s.quadraticCurveTo(t,e+i,t,e+i-r),s.lineTo(t,e+r),s.quadraticCurveTo(t,e,t+r,e),s.closePath(),o&&s.fill(),a&&s.stroke(),s.restore()}function Ac(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const g=c==="right"?a:-a,m=c==="right"?h:-h,C=h;s.save(),s.beginPath(),l?s.moveTo(r+m,o):s.moveTo(r,o),l?(s.lineTo(r+g-m,o),s.quadraticCurveTo(r+g,o,r+g,o-C),s.lineTo(r+g,e+C),s.quadraticCurveTo(r+g,e,r+g-m,e),s.lineTo(t+m,e)):(s.lineTo(r+g,o),s.lineTo(r+g,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-m/3,e+C/3),s.lineTo(n+m/3,i-C/3),s.quadraticCurveTo(n,i,n+m/3,i+C/3),s.lineTo(r-m/3,o-C/3),s.quadraticCurveTo(r,o,r+m/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function Ec(s,t,e,n,i,r=1){s.save(),s.lineWidth=r,s.beginPath(),s.moveTo(t,e),s.lineTo(n,i),s.stroke(),s.closePath(),s.restore()}function te(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function sr(s,t,e){const n=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);s.fillRect(n,i,r,o)}const Ut=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Uf=s=>Array.isArray(s[0])?s:[s];class Dc{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,n){const i=t.ctx,r=n&&this.paneManager.panes[n];e&&(i.save(),r&&Ut(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);r&&r.length>=1&&i.draw(t,r,e,{})}else console.error(`Data series drawer with type ${n} isn't registered!`)}}}const le=(s,t,e,n,i=t)=>{n.forceBold?s.lineWidth=n.forceBold:e.highlighted?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Ic{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.singleColor)t.strokeStyle=e.singleColor;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.barLineWidth,n,i),te(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=Z(n.view.toX(o.centerUnit)),l=Z(n.view.toX(o.startUnit)),[c,h,d,u]=o.yBodyKeyPoints(n.view),g=Z(n.view.xPixels(o.width)/2),m=Z(n.view.toY(o.close)),C=Z(n.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,m),t.lineTo(a+g,m),t.moveTo(l,C),t.lineTo(a,C),t.stroke()}})}}}class Lc{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Wt){const r=vt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(x.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],g=r[h+1],m=n.view.toX(c.centerUnit),C=n.view.toX(d.centerUnit),_=n.view.toY(d.close),M=u?n.view.toY(u.close)<l:!1,L=_<l;if(u!==void 0&&M!==L){nr(t,n,i,M);const H=n.view.toX(u.centerUnit),z=n.view.toY(u.close),R=C-H,F=_-z,Y=R/F,q=_-l,V=Y*q,N=H+(R-V);t.lineTo(N,l),t.stroke(),t.lineTo(m,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(N,l)}u===void 0?(t.beginPath(),t.moveTo(C,_)):g===void 0?(nr(t,n,i,L),t.lineTo(C,_),t.stroke(),t.lineTo(C,l),t.lineTo(m,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(m,l),t.lineTo(C,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(C,_)}}}}const nr=(s,t,e,n)=>{e.singleColor?(s.fillStyle=e.singleColor,s.strokeStyle=e.singleColor):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Bc{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),te(t,()=>{this.pixelLength=1/Bt,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=n.colors;a&&l&&this.drawCandle(t,i,n,o)}})}}drawCandle(t,e,n,i){const{candleTheme:r,activeCandleTheme:o}=n.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.singleColor?t.fillStyle=e.singleColor:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=Z(n.view.toX(i.startUnit)),d=Z(n.view.xPixels(i.width)),u=i.bodyHeight(n.view),[g,m,C,_]=i.yBodyKeyPoints(n.view),M=m===C?m+1:C,L=g===_?g+1:_,H=l[`${a}Color`],z=a==="none"?H:l[`${a}WickColor`];t.fillStyle=H,e.singleColor?t.strokeStyle=e.singleColor:t.strokeStyle=z;const R=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),F=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,F?g:m),t.lineTo(h,F?L:M),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,F?g:m),t.lineTo(h,F?L:M),t.moveTo(h+1,m),t.lineTo(h+1,M),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,g,L,m,M),c||(t.beginPath(),t.moveTo(h+Y,m),t.lineTo(h+Y,M),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,m+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,g,L,m,M-1);const q=this.config.candlePaddingPercent,V=Math.max(Z(d*q/2),this.pixelLength),N=h+V,U=d-V*2;c||(e.singleColor&&(t.fillStyle=e.singleColor),t.fillRect(N,m,U,u)),R&&this.drawCandleBorder(t,e,l,i,N+this.halfLineWidthCU,m+this.halfLineWidthCU,U-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,n,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,n),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,n,i,r,o,a,l){if(e.singleColor)t.strokeStyle=e.singleColor;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class Oc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=e.flat(),o=n.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=n.colors.histogram;if(d===void 0)return;i.singleColor?t.fillStyle=i.singleColor:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),g=Z(n.view.toY(l.close)),m=Z(n.view.xPixels(l.width));t.fillRect(u,g,m,h);const C=t.createLinearGradient(0,g+h,0,a);i.singleColor?t.fillStyle=i.singleColor:(C.addColorStop(0,d[`${c}Cap`]),C.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=C),m===0?(t.beginPath(),t.strokeStyle=C,t.moveTo(u,g+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,g+h,m,a-g-h)}}}}class Rc{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Wt){const r=vt(e);le(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.singleColor&&(t.strokeStyle=i.singleColor);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.singleColor||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),g=n.view.toX(c.centerUnit),m=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(g,m),t.stroke()}}}}const Fc=1.5;class Hc{constructor(t){this.config=t}draw(t,e,n,i){var r;t.fillStyle=(r=i.singleColor)!=null?r:this.config.mainColor;for(const o of vt(e)){t.beginPath();const a=Z(n.view.toX(o.centerUnit)),l=Z(n.view.toY(o.close));t.arc(a,l,Fc,0,Math.PI*2,!0),t.fill()}}}const kc=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Yc{constructor(t,e,n){this.drawer=t,this.config=e,this.chartBounds=n}draw(t,e,n,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,n,i),this.afterDraw(t,n))}beforeDraw(t){t.restore(),t.save(),Ut(t,this.chartBounds())}isChartTypeAllowed(){return kc.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Ut(t,e.scale.getBounds())}}class jc{constructor(t){this.chartModel=t}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(Kt(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,g=Z(ut(h.width,u)),m=Z(h.bodyHeight(this.chartModel.scale)),C=h.xCenter(this.chartModel.scale)-g/2,_=h.yBodyStart(this.chartModel.scale),M=this.chartModel.config.components.chart.candlePaddingPercent,L=Z(g*M/2),H=C+L,z=g-L*2;t.fillRect(H,_,z,m)}})})}}const ir=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{const{centerUnit:r,close:o}=n,a=e.toX(r),l=e.toY(o);i===0?t.moveTo(a,l):t.lineTo(a,l)})},Nc=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,Xc=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i;function zc(s){const t=Nc.exec(s)||Xc.exec(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const rr={};function Wc(s,t){let e=rr[s+t];if(!e){const n=zc(s);e=n&&"rgba("+n.join(",")+","+t+")",rr[s+t]=e}return e}class Uc{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);le(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.singleColor)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(ar(r.config.type)&&ar(n.config.type)&&r.config.visible){const a=[],l=n,c=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1),h=r.getSeriesInViewport(r.scale.xStart-1,r.scale.xEnd+1);c.forEach((d,u)=>{const g=Math.min(d.length,h[u].length);for(let _=0;_<g;_++){const M=[d[_].clone(),h[u][_].clone()];a.push({diffPoints:M})}const m=l.getPaintConfig(u).color,C=r.getPaintConfig(o).color;this.drawDifference(t,m,C,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),ir(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[g,m]=u.diffPoints;l.push(g),c.push(m)});const h=or(l,r.view),d=or(c,o.view);this.fillCloud(t,n,h,d,a),this.fillCloud(t,e,d,h,a)}fillCloud(t,e,n,i,r){var o,a,l,c;t.save(),t.beginPath();const h=(a=(o=re(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=bt(n))==null?void 0:l.x)!=null?c:0;t.lineTo(h,0),n.forEach(u=>{t.lineTo(u.x,u.y)}),t.lineTo(d,0),t.closePath(),t.clip(),t.beginPath(),n.forEach((u,g)=>{g===0?t.moveTo(u.x,u.y):t.lineTo(u.x,u.y)}),i.slice().reverse().forEach(u=>{t.lineTo(u.x,u.y)}),t.closePath(),t.fillStyle=r.singleColor?r.singleColor:Wc(e||"#383838",.3),t.fill(),t.restore()}}const or=(s,t)=>s.map(e=>{const{centerUnit:n,close:i}=e,r=t.toX(n),o=t.toY(i);return{x:r,y:o}}),ar=s=>s==="DIFFERENCE";class Vc{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);le(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.singleColor)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.moveTo(d,et(r)),t.lineTo(d,et(u))}),t.stroke()})}}class Gc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);le(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.singleColor)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),ir(e,t,n),t.stroke()}}class Zc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=l.lineWidth;t.fillStyle=(a=i.singleColor)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class $c{constructor(t){this.config=t}draw(t,e,n,i){t.save(),e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=n.getTextForPoint(h),u=Pt(d,t,c),g=kt(c,t),m=n.view.toX(h.centerUnit)-u/2,C=n.view.toY(h.close)+g;t.fillText(d,m,C)})}),t.restore()}}class Kc{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.singleColor)!=null?a:l.color,r.forEach(c=>{const h=n.view.toX(c.centerUnit),d=n.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,n,i){t.beginPath(),t.moveTo(e-i/2,n),t.lineTo(e,n-i),t.lineTo(e+i/2,n),t.fill()}}const Fs="resized_local",Ge="draw",Vf="draw_last_candle",ce={width:20,height:20};class lr{constructor(t,e,n,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=n,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.type=Hs;var a;i.push(this),this.parent=Qc(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:n}=t,i=window.devicePixelRatio;this.canvas.style.height=n+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=n*i,this.width=e,this.height=n,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 n=e.height;n!==this.height&&(t.style.height=n+"px",this.height=n,t.height=n,this.prevHeight=n)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>ce.width&&this.height>ce.height}}const Hs={name:"candle"},qc={candle:Hs,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function Jc(s,t,e,n,i,r,o){var a;const l=he(s,t,i,r,o,e);return l.type=(a=qc[n])!=null?a:Hs,l}function he(s,t,e,n,i,r,o){const a=new lr(s,t,n,i,r,o);return cr(a,e),a}function cr(s,t){const e=s.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",s.width=t.fixedSize.width,s.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function Qc(s){let t=s;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}let ks=!1,Ys=0;const Ze=new Map,js=new Map,hr=()=>{ks||(ks=!0,Ys=requestAnimationFrame(()=>{js.forEach((s,t)=>{s(),js.delete(t)}),Ze.forEach((s,t)=>{s(),Ze.delete(t)}),ks=!1}))},dr=(s,t)=>{Ze.set(s,t),hr()},Kf=s=>{Ze.delete(s)},Ns=(s,t)=>{js.set(s,t),hr()},$e="HIT_TEST_",qf=null;class th{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${_t()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf($e)!==-1&&this.drawersMap[n].draw()})},t.on(Ge,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),dr(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf($e)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf($e)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Da(t,n.getCanvasIds()).length&&n.draw()}})}isDrawable(){var t,e,n,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>ce.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ce.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=_t()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(n);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,n){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(n);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 n=this.drawingOrder.indexOf(e);n!==-1&&this.drawingOrder.splice(n,1)}})}reorderDrawers(t){this.drawingOrder=zn(this.drawingOrder,t)}}class ur{static paneResizer(t){return`PANE_RESIZER_${t}`}}class eh{constructor(t,e,n,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=n,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Ut(t,e.getBounds()),e.dataSeries.forEach(n=>this.drawSeries(t,n)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const n=e.config.type,i=this.seriesDrawers[n];if(i){const r={singleColor:this.canvasModel.idToColor(e.htId),forceBold:7};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const gr={dragPredicate:()=>!0};class fr extends X{constructor(t,e,n,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=n,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 Ke extends fr{constructor(t,e,n,i,r=gr){super(t,e,n,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 sh="BASELINE_RESIZER";class nh extends X{constructor(t,e,n,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=n,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.baselineYPercents=50,this.ht=As.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>this.chartPanComponent.deactivatePanHandlers(),this.dragEndCb=()=>this.chartPanComponent.activateChartPanHandlers(),this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&ol(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new Ke(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(x.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(x.CHART),e=this.canvasBoundContainer.getBounds(x.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const n=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=n,this.canvasBoundContainer.bounds[sh]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(x.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const qe=s=>{var t;const e=fe(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=fe(s.hi,Math.max(s.open,s.close),e),i=fe(s.lo,Math.min(s.open,s.close),e),r=fe(s.open,s.lo,e),o=fe(s.close,s.hi,e);return{hi:n,lo:i,open:r,close:o,timestamp:s.timestamp,volume:(t=s.volume)!=null?t:0,expansion:s.expansion,idx:s.idx,impVolatility:s.impVolatility}},Xs=s=>{for(let t=0;t<s.length;++t)s[t].idx=t},pr=s=>{s.forEach(t=>{t.idx=void 0})};class ih{constructor(){}draw(t,e,n){const i=n.view.toY(0),r=vt(e),o=n.getPaintConfig(0);r.forEach((a,l)=>{var c,h;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(a.close<this.previousValue(r,l)?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF",t.lineWidth=o.lineWidth,t.beginPath();const g=n.view.toX(a.centerUnit),m=n.view.toY(a.close);t.moveTo(g,et(i)),t.lineTo(g,et(m)),t.stroke();return}if(((h=o.multiplyColors)==null?void 0:h.length)===4){const g=this.previousValue(r,l);a.close<g&&a.close<0&&(t.strokeStyle=o.multiplyColors[0]||o.color||"#FF00FF"),a.close>g&&a.close<0&&(t.strokeStyle=o.multiplyColors[1]||o.color||"#FF00FF"),a.close<g&&a.close>0&&(t.strokeStyle=o.multiplyColors[2]||o.color||"#FF00FF"),a.close>g&&a.close>0&&(t.strokeStyle=o.multiplyColors[3]||o.color||"#FF00FF"),t.lineWidth=o.lineWidth,t.beginPath();const m=n.view.toX(a.centerUnit),C=n.view.toY(a.close);t.moveTo(m,et(i)),t.lineTo(m,et(C)),t.stroke();return}t.strokeStyle=o.color||"#FF00FF",t.lineWidth=o.lineWidth,t.beginPath();const d=n.view.toX(a.centerUnit),u=n.view.toY(a.close);t.moveTo(d,et(i)),t.lineTo(d,et(u)),t.stroke()})}previousValue(t,e){do e--;while(e>=0&&!isFinite(t[e]&&t[e].close));return t[e]?t[e].close:Number.NaN}}var rh=Object.defineProperty,mr=Object.getOwnPropertySymbols,oh=Object.prototype.hasOwnProperty,ah=Object.prototype.propertyIsEnumerable,vr=(s,t,e)=>t in s?rh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,lh=(s,t)=>{for(var e in t||(t={}))oh.call(t,e)&&vr(s,e,t[e]);if(mr)for(var e of mr(t))ah.call(t,e)&&vr(s,e,t[e]);return s};class ch{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class hh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m){super(),this.chartModel=t,this.canvasModel=e,this.config=n,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=g,this.chartResizeHandler=m,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new mt(!0),this.strToBarType=_=>{var M;return(M=this.barTypeValues.find(L=>L===_))!=null?M:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new nh(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const C=new eh(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(C,$e+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new Zl(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(tt),n.components.chart.cursor),this.dataSeriesDrawer=new Dc(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,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!1)})),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Xi),this.registerCandlesTransformer("trend",zi),this.registerCandlesTransformer("hollow",Kl),this.registerCandlesTransformer("line",ql)}get barTypeValues(){return Ti(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 Bc(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Ic(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new Rc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new Hc(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Mc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new Lc(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new Oc(this.config.components.chart.histogram));const e=x.PANE_UUID(tt),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new Gc),this.registerDataSeriesTypeDrawer("HISTOGRAM",new Vc),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new ih),this.registerDataSeriesTypeDrawer("POINTS",new Zc),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Yc(new jc(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new $c(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new Kc),this.registerDataSeriesTypeDrawer("DIFFERENCE",new Uc)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(lh({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,n=!0){return this.chartModel.setTimestampRange(t,e,n)}setXScale(t,e,n=!0){return this.scale.setXScale(t,e,n)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setMainSeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=n,this.chartModel.setAllSeries({candles:t.candles,instrument:n},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return pr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(n)}setSecondarySeries(t){var e;const n=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,n);if(this.updatePriceIncrementsIfNeeded(n),i)return i}setAllSeries(t,e=[]){var n;const i=(n=t.instrument)!=null?n: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)}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||!Ot.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Ot.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}}class br extends Wt{constructor(t,e,n,i,r,o,a,l,c,h){super(e,n,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 dh=Object.defineProperty,Cr=Object.getOwnPropertySymbols,uh=Object.prototype.hasOwnProperty,gh=Object.prototype.propertyIsEnumerable,yr=(s,t,e)=>t in s?dh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,fh=(s,t)=>{for(var e in t||(t={}))uh.call(t,e)&&yr(s,e,t[e]);if(Cr)for(var e of Cr(t))gh.call(t,e)&&yr(s,e,t[e]);return s};const ph=(s,t,e,n)=>{var i,r,o,a;const l=fh({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Oa(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=s.xStart,u=s.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-jt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},mh=s=>t=>{if(t.length!==0){const e=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),n=e[0],i=e[e.length-1];s.setXScale(n.startUnit,i.startUnit+i.width+s.offsets.right),s.doAutoScale(!0),s.recalculateZoomXYRatio(),s.fireChanged()}},vh=(s,t)=>(e,n=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=n===null?0:t.mainCandleSeries.meanCandleWidth*2,c=n?o-l:o+l,h=n?a+l:a-l;s.setXScale(c,h)};var bh=Object.defineProperty,Ch=Object.defineProperties,yh=Object.getOwnPropertyDescriptors,wr=Object.getOwnPropertySymbols,wh=Object.prototype.hasOwnProperty,Sh=Object.prototype.propertyIsEnumerable,Sr=(s,t,e)=>t in s?bh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Se=(s,t)=>{for(var e in t||(t={}))wh.call(t,e)&&Sr(s,e,t[e]);if(wr)for(var e of wr(t))Sh.call(t,e)&&Sr(s,e,t[e]);return s},zs=(s,t)=>Ch(s,yh(t));class xh{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,n)=>zs(Se({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=zs(Se({},be(this.config.colors)),{lineTheme:Se({},n.lineTheme),areaTheme:Se({},n.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,n="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,n=i);return this.usedChartColors[n]=this.usedChartColors[n]+1,this.symbolsToColorKeys[t]=n,this.secondaryChartColorsPool[n]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var n,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=zs(Se({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var _h=Object.defineProperty,xr=Object.getOwnPropertySymbols,Ph=Object.prototype.hasOwnProperty,Th=Object.prototype.propertyIsEnumerable,_r=(s,t,e)=>t in s?_h(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Je=(s,t)=>{for(var e in t||(t={}))Ph.call(t,e)&&_r(s,e,t[e]);if(xr)for(var e of xr(t))Th.call(t,e)&&_r(s,e,t[e]);return s};class Mh extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=n,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 O,this.mainInstrumentChangedSubject=new O,this.offsetsChanged=new O,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new xh(this.config);const d=new br(this.chartBaseModel,this.paneManager.panes[tt].mainExtent,_t(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new ch,this.candlesTransformersByChartType,this.candleWidthByChartType,Je({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),o.addXConstraint((u,g)=>ph(g,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=mh(o),this.timeFrameViewportTransformer=vh(o,this),this.pane=this.paneManager.panes[tt]}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(x.PANE_UUID(tt)).pipe(Mt(pi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ce.width&&t.height>ce.height){const e=this.getEffectiveChartWidth(),n=this.getEffectiveYAxisWidth();if(this.prevChartWidth===0){this.scale.isViewportValid()?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=jt(n-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=n,this.prevChartWidth=e;return}const i=jt(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=n,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(n=>{const i=n.dataPoints;return pr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=Qe(t.map(qe)),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,n&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var n;this.mainCandleSeries.instrument=(n=t.instrument)!=null?n:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=Qe(t.candles.map(qe));this.mainCandleSeries.clearData(),Xs(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.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()}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=Je({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const n=[t,...e];if(!this.candleSeries.every(l=>n.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=Qe(t.candles.map(qe)),r=Tr(this.mainCandleSeries.dataPoints,i),o=r.candles;Xs(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const g=Qe(l.candles.map(qe)),m=Tr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],g).candles;return this.setSecondaryCandleSeries(m,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),l.recalculateDataViewportIndexes()});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.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(n=>{const i=Lt(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}createSecondaryCandleSeriesModel(t){const e=Je(Je({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Wt(this.paneManager.panes[tt].mainExtent,_t(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return n.config.type="line",this.candleSeries.push(n),n}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[tt].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{var r;const o=(r=i.idx)!=null?r:0,a=e[o];if(a)n.push(a);else{let l=Pr(e,o,-1);if(l||(l=Pr(e,o,1)),l){const c=wl(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=At(t,ke().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=n,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}getEffectiveYAxisWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(tt)).width}getEffectiveChartWidth(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)).width}getEffectiveChartHeight(){return this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)).height}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),n=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=n.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,n=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,n)}candleFromUnit(t,e=!1,n=this.mainCandleSeries){var i,r;const o=Lt(n.visualPoints,t,d=>d.startUnit),a=n.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Kt((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?ye(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:ye(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e=!0,n=this.mainCandleSeries){const i=n.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}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,n,i;const r=t-((i=(n=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:n.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,n=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,n)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return bt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return bt(t)}getMaxCandlesFitLength(){return et(this.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((n,i)=>{const r=i.timestamp,o=ve(r,!1,t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,n[o.index]=i),n},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const n=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=ve(h.timestamp,!0,o,this.getPeriod()),g=Math.min(u.index,o.length);a=a||g===o.length,o[g]=h,h.idx=g,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(g);const m=g>=o.length-1,C=c&&h.timestamp<c.timestamp;if(m&&!C&&(c=h),a&&c&&n&&l){const _=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Wi;this.scale.moveXStart(this.scale.xStart+_(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.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return xt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=0,e){let n=this.getCandles().slice();const i=this.getCandlesCount(),r=e!=null?e:i+this.FAKE_CANDLES_DEFAULT;n=n.slice(Math.max(0,t),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(ye(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...n,...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 n=t.slice(),i=[];return e.forEach(r=>{const a=ve(r.timestamp,!1,t).index;a<0?i.push(r):t[a].timestamp===r.timestamp?n[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...n]}}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){const n=this.findSeriesBySymbol(e);if(n.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}n.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),Xs(i.dataPoints),i.recalculateVisualPoints()}),this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Qe=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),Pr=(s,t,e)=>{if(t>=s.length)return s[s.length-1];for(let n=t;n<s.length&&n>=0;n+=e){const i=s[n];if(i)return i}},Tr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=ve(r.timestamp,!0,s).index;a<0?n.push(r):a>=s.length?i.push(r):s[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:n,appended:i,candles:[...n,...e,...i]}};class xe{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ws{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const n=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(n,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Pi(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=Pi(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=vt(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class Ah{constructor(t,e,n){this.model=t,this.crossToolCanvasModel=e,this.crossToolTypeDrawers=n}draw(){const t=this.crossToolTypeDrawers[this.model.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.model.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}class Eh extends X{constructor(t,e,n,i){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.currentHoverSubject=new mt(null),this.type="cross-and-labels",this.type=t.type}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?this.updateHover(t):this.currentHover=null,this.fireDraw()}))}fireDraw(){this.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateHover(t,e=this.config.magnetTarget){if(this.currentHover===null?this.currentHover={x:t.x,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=t.x,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===tt)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)}}const Et=4;function Dh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m;const C=r.align,_=(l=i.textFont)!=null?l:Jt(r),M=i.bgColor,L=(c=i.textColor)!=null?c:qt(M,o.labelTextColor,o.labelInvertedTextColor),H=(h=i.paddingTop)!=null?h:Et,z=(d=i.paddingBottom)!=null?d:Et,R=(u=i.paddingEnd)!=null?u:Et,F=Kt(kt(_,s)/2),Y=n-F-H,V=n+F+z-Y;if(a&&!ts(n,t,V))return;s.save(),s.fillStyle=M,s.strokeStyle=M;const N=Kt(t.width/6),U=C==="right"?t.x:t.x+t.width,Q=C==="right"?U+N:U-N,J=r.labelBoxMargin.end,st=J-R,G=t.width-N-st;Ac(s,Q,Y,U,Y+Kt(V/2),Q,Y+V,G,(m=(g=r.typeConfig.badge)==null?void 0:g.rounded)!=null?m:!1,C),s.fillStyle=L,s.font=_;const nt=C==="right"?t.x+t.width-Pt(e,s,_)-J:t.x+J;s.fillText(e,nt,n+F-1),s.restore()}function Ih(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m,C,_,M,L;const H=r.align,z=(l=i.textFont)!=null?l:Jt(r),R=i.bgColor,F=(c=i.textColor)!=null?c:qt(R,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,q=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Et,V=(m=(g=i.paddingBottom)!=null?g:Y==null?void 0:Y.bottom)!=null?m:Et,N=(_=(C=i.paddingEnd)!=null?C:Y==null?void 0:Y.end)!=null?_:Et,U=i.paddingStart,Q=kt(z,s),J=n-Q/2-q,G=n+Q/2+V-J,nt=(L=i.rounded)!=null?L:(M=r.typeConfig.rectangle)==null?void 0:M.rounded;if(a&&!ts(n,t,G))return;s.save(),s.fillStyle=R,s.strokeStyle=R;const ot=r.labelBoxMargin.end;s.font=z;const ft=Pt(e,s,z),at=ot-N,wt=U!==void 0?ft+U+N:t.width-at,se=H==="right"?t.x+t.width-at-wt:t.x+at,cs=H==="right"?t.x+t.width-ft-ot:ot;nt?er(s,se,J,wt,G,4,!0):s.fillRect(se,J,wt,G),s.fillStyle=F,s.fillText(e,cs,n+Q/2-1),s.restore()}function Lh(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,g,m,C,_;const M=r.align,L=(l=i.textFont)!=null?l:Jt(r),H=o.backgroundColor,z=(c=i.textColor)!=null?c:qt(H,o.labelTextColor,o.labelInvertedTextColor),R=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,F=(u=(d=i.paddingTop)!=null?d:R==null?void 0:R.top)!=null?u:Et,Y=(m=(g=i.paddingBottom)!=null?g:R==null?void 0:R.bottom)!=null?m:Et,q=(_=(C=i.paddingEnd)!=null?C:R==null?void 0:R.end)!=null?_:Et,V=i.paddingStart,N=kt(L,s),U=n-N/2-F,J=n+N/2+Y-U;if(a&&!ts(n,t,J))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const st=r.labelBoxMargin.end;s.font=L;const G=Pt(e,s,L),nt=st-q,ot=V!==void 0?G+V+q:t.width-nt,ft=M==="right"?t.x+t.width-nt-ot:t.x+nt,at=M==="right"?t.x+t.width-G-st:st;s.fillStyle=H,s.strokeStyle=H,s.fillRect(ft,U,ot,J),s.fillStyle=z,s.fillText(e,at,n+N/2-1),s.restore()}function Bh(s,t,e=Et){return kt(s,t)/2+e}function ts(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const Oh="badge",Mr=4,Ar={badge:Dh,rectangle:Ih,plain:Lh};function Er(s,t,e,n,i,r,o,a){var l,c,h,d,u;const g=i.y,m=i.labelText,C=(l=i.mode)!=null?l:"label",_=(c=i.labelType)!=null?c:Oh,M=i.description,L=(h=i.textFont)!=null?h:Jt(o),H=i.bgColor,z=(d=i.lineColor)!=null?d:H,R=Pt(M!=null?M:"",s,L)+8,F=et(i.y),Y=kt(L,s),q=g-Y/2,N=g+Y/2-q;s.save(),s.fillStyle=H,s.strokeStyle=z;const U=r.getBounds(x.PANE_UUID(tt)),Q=Ar[_],J=o.labels.descriptions,st=Rh(e,F,N),G=()=>J&&Fh(t,s,e,n,i,o);let nt,ot;const ft=2;o.align==="right"?(nt=U.x,ot=J?U.x+U.width-R:U.x+U.width+ft):(nt=J?U.x+R:U.x-ft,ot=U.x+U.width);const at=(u=i.lineY)!=null?u:i.y,wt=()=>st&&te(s,()=>Ec(s,nt,at,ot,at,1)),se=()=>Q(s,e,m,g,i,o,a.yAxis,!1),hn={line:()=>{wt(),G()},"line-label":()=>{wt(),se(),G()},label:()=>{G(),se()}};C!=="none"&&ts(g,e,N)&&hn[C](),s.restore()}const Rh=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function Fh(s,t,e,n,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=Jt(r),g=Pt(h,t,u),m=kt(u,t),C=(o=i.paddingTop)!=null?o:Mr,_=(a=i.paddingBottom)!=null?a:Mr,M=d-m/2-C,H=d+m/2+_-M;t.save();const z=g+5,R=4,F=g+R*2,Y=n.x+n.width,q=c==="right"?Y-F:n.x+R;$l(s,t,q,M,z,H,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const V=c==="right"?Y-g-R*2:n.x+R*2;t.fillText(h,V,d+m/2-1),t.restore()}class Dr{constructor(t,e,n,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=n,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&te(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var n,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(x.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES,{extensionY:1e-4}),h=(n=this.config.components.xAxis.padding.top)!=null?n: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,g=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const m={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},C={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},_=g==null?void 0:g(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),_&&(t.moveTo(...m.start),t.lineTo(...m.end)),t.moveTo(...C.start),t.lineTo(...C.end),t.stroke()),_&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var n,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,g=t.measureText(u).width,m=this.config.components.xAxis.fontSize,C=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const _=(n=l==null?void 0:l.left)!=null?n:0,M=(i=l==null?void 0:l.right)!=null?i:0,L=(r=l==null?void 0:l.top)!=null?r:0,H=(o=l==null?void 0:l.bottom)!=null?o:0,z=(a=c==null?void 0:c.top)!=null?a:0,R=g+_+M,F=m+L+H,Y=Math.max(d-R/2,0),q=C.y+z;er(t,Y,q,R,F),t.fillStyle=h.labelTextColor;const V=Math.max(d-g/2,_),N=C.y+z+m+L-1;t.fillText(u,V,N),t.restore()}}drawYLabel(t,e){const n=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(x.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=Ar[a],g=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:g,bgColor:i.labelBoxColor,paddingBottom:n==null?void 0:n.bottom,paddingEnd:n==null?void 0:n.end,paddingTop:n==null?void 0:n.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class Hh{draw(){}}class kh extends X{constructor(t,e,n,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossToolTypeDrawers={},this.model=new Eh(t.components.crossTool,this.crossToolCanvasModel,o,a),this.addChildEntity(this.model);const l=new xe(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const c=new Ah(this.model,this.crossToolCanvasModel,this.crossToolTypeDrawers),h=new Ws;h.addDrawer(l,"CLEAR_CANVAS"),h.addDrawer(c,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(h,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Dr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Dr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new Hh)}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 Yh{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,n])=>{for(const i of n){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class Nt{constructor(t){this.data=t,this.next=null}}class jh{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 Nt(t);if(this.head===null)this._head=e;else{let n=this.head;for(;n.next;)n=n.next;n.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const n=new Nt(e);if(t===0)n.next=this.head,this._head=n;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;n.next=i,r.next=n,t===this.length-1&&(this._tail=n)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,n=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,n=e,e=e.next;n.next=e.next,t===this.length-1&&(this._tail=n)}this.length--}getNodePosition(t){let e=0,n=this.head;for(;n;){if(n.data===t.data)return e;n=n.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 Nh extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._objects=new mt({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const n=e.paneId,r=this.objects[n];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[n,i]=e,r=new Nt(n);return i.getNodePosition(r)}addObject(t){var e;const n=t.paneId,i=this.objects,r=(e=i[n])!=null?e:new jh;Object.keys(i).find(o=>o===n)||(i[n]=r),r.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.setDynamicObjects(i)}removeObject(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);i.removeAt(o),this.modelIdToObjectMap.delete(t),i.size()===0&&delete this.objects[n.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[n]=e;this.removeObject(n.id),this.addObject(t)}moveToPosition(t,e){const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Nt(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[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(n),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,n),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,n),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[n,i]=e,r=new Nt(n),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,n),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class Xh extends X{constructor(t,e){super();const n=new Nh(t);this.model=n,this.addChildEntity(n);const i=new Yh(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const zh=()=>s=>s.toString(),Wh=(s,t)=>{var e;const n="date.get"+(t((e=s.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 n+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:Uh(s),shortMonths:Vh(s),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=s.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Gh(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Uh(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Vh(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const Ir=(s,t,e)=>{if(s){if(typeof s=="string")return e(s);if(Array.isArray(s)){const n=s.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(n.length>0){const i=n[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return zh()},Gh=(s,t,e,n)=>{t||(t="M/d/yyyy");const i=s.getDate(),r=s.getMonth(),o=s.getFullYear(),a=s.getHours(),l=s.getMinutes(),c=s.getSeconds(),h=s.getMilliseconds(),d=a%12,u=de(d),g=de(a),m=de(l),C=de(c),_=a<12?"AM":"PM",M=e[s.getDay()],L=M.substring(0,3),H=de(i),z=r+1,R=de(z),F=n[r],Y=F.substring(0,3),q=o+"",V=q.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",g+"").replace("H",a+"").replace("mm",m+"").replace("m",l+"").replace("ss",C+"").replace("s",c+"").replace("S",h+"").replace("dd",H+"").replace("d",i+"").replace("EEEE",M).replace("EEE",L).replace("YYYY",q).replace("yyyy",q).replace("YY",V).replace("yy",V).replace("aaa",_),t.indexOf("MMM")>-1?t=t.replace("MMMM",F).replace("MMM",Y):t=t.replace("MM",R+"").replace("M",z+""),t},de=s=>typeof s=="number"&&s<10?"0"+s:s,Zh={"rhombus-small":4,rhombus:6,"rhombus-large":8},_e=(s,t)=>`${s}_${t}`;class $h{constructor(t,e,n,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&(this.createCustomIcon("earnings",a.earnings),this.createCustomIcon("dividends",a.dividends),this.createCustomIcon("splits",a.splits),this.createCustomIcon("conference-calls",a.conferenceCalls))}createCustomIcon(t,e){if(e){const n=this.createIconImage(e.normal),i=this.createIconImage(e.hover);this.customIcons[_e(t,"normal")]=n,this.customIcons[_e(t,"hover")]=i}}createIconImage(t){var e;const i=new DOMParser().parseFromString(t,"text/html").querySelector("svg");let r=0;i&&(r=parseInt((e=i.getAttribute("height"))!=null?e:"",10));const l="data:image/svg+xml;base64,"+btoa(t),c=new Image;return c.src=l,{img:c,svgHeight:r}}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(x.EVENTS),e=this.canvasBoundsContainer.getBounds(x.ALL_PANES),n=this.canvasModel.ctx;n.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{const r=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(r>e.x&&r<e.x+e.width){const o=this.config.colors.events[i.type].color;n.strokeStyle=o,this.customIcons[_e(i.type,"hover")]!==void 0?this.drawCustomSvgEvent(n,r,t,i):this.drawDefaultEvent(n,r,t,i,o),this.model.hoveredEvent.getValue()===i&&(n.beginPath(),n.moveTo(r,e.y),n.lineTo(r,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(r,i))}}),n.restore()}drawCustomSvgEvent(t,e,n,i){const r=n.y+n.height/2,o=this.customIcons[_e(i.type,"normal")],a=this.customIcons[_e(i.type,"hover")];this.model.hoveredEvent.getValue()===i?t.drawImage(a.img,e-a.svgHeight/2,r-a.svgHeight/2):t.drawImage(o.img,e-o.svgHeight/2,r-o.svgHeight/2)}drawDefaultEvent(t,e,n,i,r){const o=n.y+n.height/2;t.fillStyle=r,t.lineWidth=1.5;const a=Us(i);t.beginPath(),t.moveTo(e-a,o),t.lineTo(e,o-a),t.lineTo(e+a,o),t.lineTo(e,o+a),t.closePath(),this.model.hoveredEvent.getValue()===i?t.fill():t.stroke()}drawLabel(t,e){var n;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(x.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(n=this.config.components.xAxis.padding.top)!=null?n: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 Us(s){return Zh[s.style]}const es=5;class Kh{constructor(t,e,n,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(x.EVENTS);t.save(),this.model.events.forEach((n,i)=>{const r=this.model.events[i-1],o=r&&this.chartModel.candleFromTimestamp(r.timestamp).xCenter(this.chartModel.scale),a=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(a>e.x&&a<e.x+e.width){const l=this.config.colors.events[n.type].color;t.strokeStyle=l,t.fillStyle=l;const c=Us(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const h=(c+es)*2;if(o!==void 0){const d=Us(r);if(o+d>a-h/2){const g=c*2+es;t.fillRect(o+d,e.y,g,e.height)}else t.fillRect(a-c-es,e.y,h,e.height)}else t.fillRect(a-c-es,e.y,h,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var qh=Object.defineProperty,Lr=Object.getOwnPropertySymbols,Jh=Object.prototype.hasOwnProperty,Qh=Object.prototype.propertyIsEnumerable,Br=(s,t,e)=>t in s?qh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,td=(s,t)=>{for(var e in t||(t={}))Jh.call(t,e)&&Br(s,e,t[e]);if(Lr)for(var e of Lr(t))Qh.call(t,e)&&Br(s,e,t[e]);return s};const Or=317,Vs={DRAWINGS:[1,199],NEWS:[200,299],DATA_SERIES:[300,2999],EVENTS:[3e3,4e3],EXECUTED_ORDERS:[4001,5e3]};class ed extends lr{constructor(t,e,n,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=n,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new O,this.touchStartSubject=new O,this.dblClickSubject=new O,this.rightClickSubject=new O,this.hitTestDrawersPredicateSubject=new mt(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,cr(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Xe(100,Ne,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=xt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=xt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ht(()=>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(ht(()=>td({},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,n,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*Or).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Or}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const n=window.devicePixelRatio;return this.prevAnimationFrameId!==Ys&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ys),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),n=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(n),[r]=Gs(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(n)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const n=this.getPixel(t.x,t.y),i=this.colorToId(n[0]*65536+n[1]*256+n[2]),r=Number(i),[o]=Gs(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 n,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),[g,m]=Gs(this.hitTestSubscribers,u),C=g==null?void 0:g.lookup(d),_={point:t,model:C};switch(e){case"mousedown":C&&((n=g==null?void 0:g.onMouseDown)==null||n.call(g,C,t)),m.forEach(M=>M.onMouseDown&&M.onMouseDown(null,t));break;case"mouseup":C&&((i=g==null?void 0:g.onMouseUp)==null||i.call(g,C,t)),m.forEach(M=>M.onMouseUp&&M.onMouseUp(null,t));break;case"hover":C&&((r=g==null?void 0:g.onHover)==null||r.call(g,C,t)),m.forEach(M=>M.onHover&&M.onHover(null,t)),this.hoverSubject.next(_);break;case"touchstart":C&&((o=g==null?void 0:g.onTouchStart)==null||o.call(g,C,t)),m.forEach(M=>M.onTouchStart&&M.onTouchStart(null,t)),this.touchStartSubject.next(_);break;case"dblclick":C&&((a=g==null?void 0:g.onDblClick)==null||a.call(g,C,t)),this.dblClickSubject.next(_);break;case"contextmenu":C&&((l=g==null?void 0:g.onRightClick)==null||l.call(g,C,t)),this.rightClickSubject.next(_);break;case"zoom":C&&((c=g==null?void 0:g.onZoom)==null||c.call(g,C,t)),m.forEach(M=>M.onZoom&&M.onZoom(null,t));break;default:break}}}const Gs=(s,t)=>{let e;const n=[];return s.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:n.push(i)}),[e,n]};var sd=Object.defineProperty,nd=Object.defineProperties,id=Object.getOwnPropertyDescriptors,Rr=Object.getOwnPropertySymbols,rd=Object.prototype.hasOwnProperty,od=Object.prototype.propertyIsEnumerable,Fr=(s,t,e)=>t in s?sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ad=(s,t)=>{for(var e in t||(t={}))rd.call(t,e)&&Fr(s,e,t[e]);if(Rr)for(var e of Rr(t))od.call(t,e)&&Fr(s,e,t[e]);return s},ld=(s,t)=>nd(s,id(t));class cd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new mt(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>ld(ad({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Vs.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 hd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>Ir(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new cd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new $h(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Kh(n,i,t,r,c,()=>n.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(x.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){At(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class dd{constructor(t,e,n,i,r,o,a,l,c=()=>!0,h){this.canvasModel=t,this.viewportModel=e,this.config=n,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.getBaseline=h}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;te(t,()=>this.drawVertical(t)),te(t,()=>this.drawHorizontal(t)),te(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const n=this.xBoundsProvider(),i=et(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(n.x,i),t.lineTo(n.x+n.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 n=this.xBoundsProvider(),i=n.x+n.width;for(const r of e){const o=Z(this.viewportModel.toX(r.value));o>n.x&&o<i&&(t.beginPath(),t.moveTo(o,n.y),t.lineTo(o,n.y+n.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length&&this.config.components.grid.horizontal){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const n=this.yBoundsProvider();for(const i of e){const r=et(this.viewportModel.toY(i.value)),o=Bh(i.text,t,Et);r>n.y+o&&r<n.y+n.height-o&&(t.beginPath(),t.moveTo(n.x,r),t.lineTo(n.x+n.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class Hr extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new dd(t,e,n,i,a,l,c,h,u,d)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class ud{constructor(t,e,n,i){this.canvasModel=t,this.chartModel=e,this.config=n,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:n,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+n,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,n,i){const r=this.getMarkerY(t,n,i==="low"),o=He(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(n,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");Ut(t,h)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?"H:":"L:"} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=He(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(x.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,n){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(x.CHART),o=4,a=t.measureText(n).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class gd extends X{constructor(t,e,n,i,r){super();const o=new ud(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const fd=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],pd=24*60*60*1e3;class md extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new O}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()+pd;ka(this.highlights,t,e,vd).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,n)=>e.to-n.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const vd=s=>s.to,Vt=[20,10];class bd{constructor(t,e,n,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=n,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,n,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(x.ALL_PANES);o.save(),Ut(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=(n=this.config.components.highlights.fontSize)!=null?n:11,g=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",m=`${u}px ${g}, monospace`;o.font=m,o.lineWidth=h,o.setLineDash(d),fd.forEach(C=>{var _,M;const L=a[C];if(L){const H=this.config.colors.highlights[C],z=(_=H==null?void 0:H.border)!=null?_:"#ffffff",R=(M=H==null?void 0:H.background)!=null?M:"#ffffff";o.save(),o.beginPath(),o.fillStyle=R,o.strokeStyle=z,L.forEach(F=>{var Y,q,V;const N=this.chartModel.candleFromTimestamp(F.from),U=ut(N.width,this.chartModel.scale.zoomX),Q=N.xStart(this.chartModel.scale),J=this.chartModel.candleFromTimestamp(F.to),st=ut(J.width,this.chartModel.scale.zoomX),G=J.xStart(this.chartModel.scale)+st;if(F.border&&this.drawBorders(F.border,o,Q+U,G-st,c),o.fillRect(Q,c.y,G-Q,c.y+c.height),F.label){const nt=(Y=F.label.text)!=null?Y:"",ot=this.config.colors.highlights[F.type];o.save(),o.fillStyle=(q=ot==null?void 0:ot.label)!=null?q:"#ffffff";const ft=Pt(nt,o,m),[at,wt]=this.resolveHighlightLabelPosition((V=F.label.placement)!=null?V:"left-left",c,[Q,G],ft);o.fillText(nt,at,wt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Vt[1]-i,e.y+Vt[0]];case"left-left":return[r-Vt[1]-i,e.y+Vt[0]];case"right-right":return[o+Vt[1],e.y+Vt[0]];case"left-right":default:return[r+Vt[1],e.y+Vt[0]]}}drawBorders(t,e,n,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(n,r.y),e.lineTo(n,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 Cd="HIGHLIGHTS_PLUGIN";class yd extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new md(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new bd(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,Cd)}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 wd(){return j(function(s,t){var e,n=!1;s.subscribe(Tt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function K(s,t){return j(function(e,n){var i=0;e.subscribe(Tt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var Sd=Object.defineProperty,xd=Object.defineProperties,_d=Object.getOwnPropertyDescriptors,kr=Object.getOwnPropertySymbols,Pd=Object.prototype.hasOwnProperty,Td=Object.prototype.propertyIsEnumerable,Yr=(s,t,e)=>t in s?Sd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,jr=(s,t)=>{for(var e in t||(t={}))Pd.call(t,e)&&Yr(s,e,t[e]);if(kr)for(var e of kr(t))Td.call(t,e)&&Yr(s,e,t[e]);return s},Nr=(s,t)=>xd(s,_d(t));const Xt=4;class Md{constructor(t,e,n,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=n,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(x.N_MAP),n=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(x.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(x.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(x.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(x.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(),n.width!==0&&this.drawLeftArrowButton(c,n,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,n,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,n,i){t.x<=n.x+n.width&&(t.x=n.x+n.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,n,i,r){this.blockDrawSliderOnLeftArrow(e,n,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,n,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Xt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Xt,r+Xt),t.lineTo(i+Xt,r-Xt),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,n){t.fillStyle=n.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Xt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Xt),t.lineTo(i,r+Xt),t.lineTo(i+Xt,r),t.fillStyle=n.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,n,i){const r=n.components.navigationMap.knots.border;t.fillStyle=n.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=n.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=n.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=n.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=vt(this.chartModel.mainCandleSeries.getSeriesInViewport()),n=this.config.components.navigationMap.timeLabels,i=n.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(x.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:n.fontFamily,textSize:`${n.fontSize}px`},d={dateFormat:n.dateFormat,padding:n.padding,textProperties:Nr(jr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:Nr(jr({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,n,i){const r=i.padding,o=$n(n,i.dateFormat,this.formatterFactory);Vn(t,i.textProperties);const a=He(t),l=Zn(o);ja(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Pe extends fr{constructor(t,e,n,i,r=gr){super(t,e,n,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 Xr=4;class Ad extends X{constructor(t,e,n,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=n,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=g=>{const m=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=g.x-m.x-Xr},this.leftKnotDragTick=g=>{const{delta:m}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.leftKnotDragStartXRelative+m)/_;this.canvasBoundsContainer.leftRatio=M,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=g=>{const m=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=g.x-m.x+Xr},this.rightKnotDragTick=g=>{const{delta:m}=g,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,M=(this.rightKnotDragStartXRelative+m)/_;this.canvasBoundsContainer.rightRatio=M,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=g=>{const{delta:m}=g,C=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),_=this.chartModel.mainCandleSeries.meanCandleWidth/(C.width/this.chartModel.mainCandleSeries.dataPoints.length),M=(this.lastMousePosition-m)*_;this.scale.moveXStart(this.scale.xStart-M),this.lastMousePosition=m};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Pe(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Pe(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_SLIDER_WINDOW),u=new Pe(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(x.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(x.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 n=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=n.dataIdxStart/(n.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=n.dataIdxEnd/(n.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class Ed extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=n,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new Md(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new Ad(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(x.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(x.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(x.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(x.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(x.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(x.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(wd(),K(([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 n=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-n,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),h=c.width,d=[];let u=0,g,m;for(g=0;g<h;g++)m=et(g*o/h)-r,m in e?(d[g]=e[m].close,u=(t=d[g])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[g]=0;return a-=l,d.map((C,_)=>[_+c.x,(a+l-C)*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(Fs),this.canvasModel.fireDraw())}}const zr=()=>{const s=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(n=>navigator.userAgent.match(n));return s?"apple":e?"mobile":"other"},Jf=(s,t)=>s==="apple"||s==="mobile"?3:t,Dd=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Id=!!window.chrome,Wr=typeof InstallTrigger!="undefined",Ld=navigator.platform.indexOf("Win")>-1,Qf=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(Dd)i=e===s.deltaY*-3||Math.abs(e+Math.sign(e))===Math.abs(Math.round(s.deltaY)*3)||Math.abs(e-Math.sign(e))===Math.abs(Math.round(s.deltaY)*3);else if(Id){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,Ld){const r=Math.round(s.deltaY)===e||Math.abs(Math.round(s.deltaY)+Math.sign(s.deltaY))===Math.abs(e)||Math.abs(Math.round(s.deltaY)-Math.sign(s.deltaY))===Math.abs(e);i=Math.abs(e)===Math.abs(s.deltaY)||r}}else Wr?Math.abs(s.deltaY)>Math.abs(s.deltaX)?i=!1:i=n===s.deltaX*-3:i=e===s.deltaY*-3;i&&(t=!0)}else s.deltaMode===0&&(t=!0);return Wr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},Bd=(s,t)=>s==="percent"?t/4:t;var Zs=Math.pow;class Od extends X{constructor(t,e,n,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=n,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 g=d.deltaY<0;if(this.config.scale.zoomToCursor){const C=this.canvasBoundsContainer.getBounds(x.CANVAS).width,M=d.offsetX/C;this.scale.zoomXToPercent(M,g,!1,u)}else this.scale.zoomXToEnd(g,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(Fe),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 g=jt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-g),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Pe(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(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(K(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Xe(this.wheelThrottleTime,Ne,{trailing:!0,leading:!0})).subscribe(e=>{const n=zr(),i=n==="apple"||n==="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=jt(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 Bd(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(Fe),this.currentPoint={x:0,y:0},n=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)Rd(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=jt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new Ke(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Rd=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Zs(Zs(Math.abs(s.x),2)+Zs(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle};class Fd extends X{constructor(t,e,n,i){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.touchedCandleIndexes=[0,0]}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(e=>this.scale.fromX(e)))}handleTouchMoveEvent(t){t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),n=[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];n[r]=a.pageX-e.left-i}return n}pinchHandler(t,e){const n=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=n+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;n>=i||this.scale.setXScale(n,i)}}class Hd extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=n,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c,this.chartAreaPanHandler=new Od(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new Fd(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const Ur=s=>t=>{const{top:e,bottom:n}=s(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*n/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},Vr=(s,t)=>{const e=Ur(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function kd(){return In(1)}function Gr(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return kd()(Be(s,Le(s)))}function Yd(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Le(s);return j(function(n,i){(e?Gr(s,n,e):Gr(s,n)).subscribe(i)})}function jd(s){return K(function(t,e){return s<=e})}class Nd{constructor(t,e,n,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=n,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),n=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(n.fillStyle=i.getColor(0),n.fillRect(e.x,e.y-r,e.width,e.height+2*r)),n.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?n.fillRect(e.x,e.y,e.width,e.height):n.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}class $s extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g){super(),this.id=t,this.boundsProvider=e,this.hitTest=n,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=g,this.initialY=0,this.resizeEvent$=new O,this.onYDragStart=()=>{this.config.components.crossTool.type="none",this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEnd=()=>{this.config.components.crossTool.type="cross-and-labels",this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=m=>{const{delta:C,draggedPixels:_}=m;Math.abs(this.initialY-this.boundsProvider().y+_)>=0&&(this.dragTickCb(C),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new Ke(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(n),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Yd(!1),K(this.dragPredicate),Mt(),jd(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Nd(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,ur.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(ur.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 Xd=s=>t=>{let e;if(typeof t=="number")e=t;else if(typeof t=="string")e=Number(t);else return"\u2014";const[n]=s.dataSeries;if(n!==void 0){const i=Ot.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},zd=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ei(t,r.getBaseline()));const o=i.toFixed(Ot.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Wd=s=>({percent:zd(s),regular:Xd(s)});class Ud extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:Fi}){super(),this.paneUUID=t,this.idx=e,this.paneComponent=n,this.chartBaseModel=i,this.canvasBoundsContainer=r,this.hitTestController=o,this.dynamicObjectsCanvasModel=a,this.scale=l,this.dragNDrop=h,this.dataSeries=d,this.formatters=u,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(m=>new Ce(this.chartBaseModel.dataFromTimestamp(m.timestamp).centerUnit,m.close)),this.toY=g=>{var m,C;return(C=(m=this.mainDataSeries)==null?void 0:m.view.toY(g))!=null?C:1},this.valueFormatter=(g,m)=>{var C;return((C=this.formatters[this.yAxis.getAxisType()])!=null?C:this.formatters.regular)(g,m)},this.addChildEntity(l),this.setValueFormatters(Wd(this)),this.yAxis=c(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 Ri(this,_t(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){this.dataSeries.add(t),this.dataSeries.size===1&&(this.mainDataSeries=t),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,n;return(n=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?n:this.scale.fromY(t)}}const Zr=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return $i(e)}});class Vd{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Vs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Vs.DATA_SERIES}get allDataSeries(){return pe(pe(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(n=>n.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(n=>n.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const zt="#FF00FF";function tp(s,t,e,n){const i=s.yAxis.backgroundColor,r=s.chartAreaTheme.backgroundColor,o=s.chartAreaTheme.backgroundGradientTopColor,a=s.chartAreaTheme.backgroundGradientBottomColor,l=n.align==="left"?o:a,c=s.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const Gd=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Zd=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:zt},$d=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:zt},Kd=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:zt},qd=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:zt},Jd=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:zt},Qd=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:zt},tu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:zt},$r=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:zt},eu=()=>(console.warn("Fallback for label default color"),zt);function su(s,t){if(s.filter(a=>a!==null).length<=1)return s.map(a=>a.y);const e=t-2,n=s.map((a,l)=>nu(a,l,e)).filter(Xn).sort(iu),i=new Array(n.length),r=n.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=n.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=n[a],c=n[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<n.length;a++){const l=n[a],c=n[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 nu=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,iu=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var ru=Object.defineProperty,ou=Object.defineProperties,au=Object.getOwnPropertyDescriptors,Kr=Object.getOwnPropertySymbols,lu=Object.prototype.hasOwnProperty,cu=Object.prototype.propertyIsEnumerable,qr=(s,t,e)=>t in s?ru(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Jr=(s,t)=>{for(var e in t||(t={}))lu.call(t,e)&&qr(s,e,t[e]);if(Kr)for(var e of Kr(t))cu.call(t,e)&&qr(s,e,t[e]);return s},Qr=(s,t)=>ou(s,au(t));const Ks={MAIN:"MAIN"};class hu extends X{constructor(t,e,n,i,r,o,a){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.orderedLabels=[],this.customLabels={},this.labelsProviders={},this.labelsPositionRecalculatedSubject=new O,this.animFrameId=`anim_cache_${_t()}`,this.initModel()}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed).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,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Ns(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const n=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=vt(Object.values(i).map(l=>l.getUnorderedLabels())),o=vt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=su(o,n);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,n){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][n]=t))}updateLabelsCoordinates(t,e){return Qr(Jr({},t),{labels:t.labels.map((n,i)=>Qr(Jr({},n),{lineY:n.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,n){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[n]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var n;const i=(n=this.labelsProviders[t])!=null?n:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}const to=10;class du extends X{constructor(t,e,n,i,r,o,a,l,c){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.autoScaleCallback=l,this.hitTestCanvasModel=c,this.yAxisDragEndSubject=new O,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(x.Y_AXIS).height,ci),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=h=>{const{delta:d}=h;let u;d<0?u=1/(1+-d/this.lastYPxHeight*(to-1)):u=1+d/this.lastYPxHeight*(to-1);const m=(this.lastYHeight*u-this.lastYHeight)/2,C=this.lastYStart-m,_=this.lastYEnd+m;(this.lastYStart!==C||this.lastYEnd!==_)&&(this.scale.setYScale(C,_),this.autoScaleCallback(!1),this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},e.customScale){const h=new Ke(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(h)}}doActivate(){this.config.customScaleDblClick&&this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.autoScaleCallback(!0),this.bus.fireDraw()}))}}class uu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${_t()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),dr(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 gu=0,fu=.01;class qs{constructor(t,e,n,i,r=!1,o,a,l=ys,c=23){this.increment=t,this.startEndProvider=e,this.lengthProvider=n,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new O,this.newGeneratedLabelsSubject=new O,this.lastStart=0,this.lastEnd=0,this.labelsCache=new uu(()=>this.labelFilter(this.doGenerateLabels()))}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=dt.roundToNearest(t,n);for(;r<e;){const o=dt.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=dt.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=dt.roundToNearest(t,n);for(;o<e;){const a=dt.roundToNearest(o,n),l=Di(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=dt.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=dt.roundToNearest(t,n);for(;r<e;){const o=Os(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=dt.roundDecimal(r+n)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[n,i]=this.calculateMinMax(),r=this.getAxisStep(n,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(n,i,r):a==="percent"?o=this.generatePercentLabels(n,i,r):o=this.generateRegularLabels(n,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(),n=this.lengthProvider(),i=qs.getLabelBounds(t,e,n);return[i[0],i[1]]}getAxisStep(t,e,n){const i=e-t,r=n/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){if(this.increment)return this.increment;if(!isNaN(t)){const e=Ot.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(fu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Os(e)+t;return Ii(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,n){const i=Math.abs((e-t)*(gu/n));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let n=e,i=e,r=0;for(;n<t&&n>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),n=i*this.gridDistanceMultipliers[r++];return n}}class pu extends qs{constructor(t,e,n,i,r=()=>"regular",o=23){super(t,()=>[n.yStart,n.yEnd],()=>n.getBounds().height,i,!1,r,()=>{var a,l;return(l=(a=e())==null?void 0:a.getBaseline())!=null?l:1},void 0,o),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,n)=>n.text.length>e.length?n.text:e,"")}calculateIncrement(t){var e;const n=this.dataSeriesProvider();if(n){const i=bt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=Jl(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function eo(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?j(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(Tt(r,function(l){var c;(c=n.next)===null||c===void 0||c.call(n,l),r.next(l)},function(){var l;a=!1,(l=n.complete)===null||l===void 0||l.call(n),r.complete()},function(l){var c;a=!1,(c=n.error)===null||c===void 0||c.call(n,l),r.error(l)},function(){var l,c;a&&((l=n.unsubscribe)===null||l===void 0||l.call(n)),(c=n.finalize)===null||c===void 0||c.call(n)}))}):ie}class mu extends X{constructor(t,e,n,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=n,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${_t()}`}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ht(t=>t.height),K(t=>fa(t,this.prevYAxisHeight,1.5)),eo(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),Ns(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class vu extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new pu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new mu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new hu(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths()),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(n=>n.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(n=>n.labels).map(n=>n.labelText)).reduce((n,i)=>i.length>n.length?i:n,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class bu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasBoundsContainer=o,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new O;const C=m?be(m):{};this.state=At(C,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new du(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),_=>i.autoScale(_),g),this.addChildEntity(this.yAxisScaleHandler),this.model=new vu(this.paneUUID,t,this.state,o,n,i,c,h,u),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Kd),this.registerLabelColorResolver("bar",Zd),this.registerLabelColorResolver("line",$d),this.registerLabelColorResolver("area",qd),this.registerLabelColorResolver("scatterPlot",Jd),this.registerLabelColorResolver("histogram",Qd),this.registerLabelColorResolver("baseline",tu),this.registerLabelColorResolver("trend",$r),this.registerLabelColorResolver("hollow",$r)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(x.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:eu}registerYAxisLabelsProvider(t,e=Ks.MAIN,n=_t()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,n),n}addSimpleYAxisLabel(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=Ks.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(x.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())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),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){this.scale.state.inverse=t,this.scale.inverseY=t,this.scale.scaleInversedSubject.next(t)}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Cu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m,C,_,M,L,H){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=n,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=g,this.canvasBoundsContainer=m,this.uuid=C,this.seriesAddedSubject=_,this.seriesRemovedSubject=M,this.hitTestCanvasModel=L,this.yExtentComponents=[],this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(R,F)=>this.mainExtent.valueFormatter(R,F);const z=this.createExtentComponent(H);this.mainExtent=z,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(C),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return pe(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.uuid)).pipe(Mt(pi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,n;return(n=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?n:this.scale.toY(t)}createGridComponent(t,e,n,i){const r=x.PANE_UUID(t);return new Hr(this.mainCanvasModel,e,this.config,i,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(r),()=>this.canvasBoundsContainer.getBounds(r),()=>[],()=>n.generateNumericLabels())}createYPanHandler(t,e){const n=x.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(n));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const n=x.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(n,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(n)}createExtentComponent(t){var e,n;const i=this.yExtentComponents.length,r=x.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new Pc(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(C,_)=>new bu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,C,_,this.uuid,i,this.hitTestCanvasModel,l),u=new Ud(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),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",Vr(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),Zr(u)));const m=this.createGridComponent(this.uuid,a,u.yAxis.model.labelsGenerator,u.yAxis.state);return u.addChildEntity(m),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),u}removeExtentComponent(t){t.disable(),this.yExtentComponents.splice(t.idx,1),this.yExtentComponents.forEach((e,n)=>e.idx=n),this.canvasBoundsContainer.updateYAxisWidths()}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(n=>n.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=re(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=bt(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)}}class yu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g,m,C,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=n,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=g,this.mainCanvasModel=m,this.yAxisLabelsCanvasModel=C,this.hitTestCanvasModel=_,this.panes={},this.paneRemovedSubject=new O,this.paneAddedSubject=new O,this.dataSeriesAddedSubject=new O,this.dataSeriesRemovedSubject=new O,this.hitTestController=new Vd(this.panes,this.dynamicObjectsCanvasModel);const M=this.createPane(tt,{useDefaultHighLow:!1,scale:this.mainScale});M.mainExtent.scale.autoScaleModel.setHighLowProvider("series",Zr(M.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",Ur(()=>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(x.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone}),n=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=x.PANE_UUID_RESIZER(t),o=new $s(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,n,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 pe(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(n=>this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(n.uuid))(t.x,t.y))}createPane(t=_t(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new Cu(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,e);return this.config.components.paneResizer.visible&&n.addChildEntity(this.addResizer(t)),n.addSubscription(this.addBounds(t,e==null?void 0:e.order)),n.addSubscription(this.addCursors(t)),n.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,n.ht)),this.panes[t]=n,n.activate(),this.recalculateState(),n.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),n}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,n;const i=re(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&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}canMovePaneDown(t){var e,n;const i=bt(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&&((n=(e=this.panes[t])==null?void 0:e.visible)!=null?n:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(n=>n.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const n=x.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof $s&&r.id===n);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],n=x.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof $s&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}addCursors(t,e=this.config.components.chart.cursor){const n=x.PANE_UUID(t),i=x.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(n,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone),()=>{this.cursorHandler.removeCursorForCanvasEl(n),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 wu extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,n=this.canvasModel.ctx;if(n){n.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return n.drawImage(this.elements.backgroundCanvas,0,0,i,r),n.drawImage(this.elements.mainCanvas,0,0,i,r),n.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),n.drawImage(this.elements.crossToolCanvas,0,0,i,r),n.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(n),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 Su=(s,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 n(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 n(s)},ss=class extends X{constructor(s,t,e,n,i){super(),this.chartComponent=s,this.drawingManager=t,this.config=e,this.volumesModel=n,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var s,t;return!((s=this.pane)!=null&&s.scale.isViewportValid())&&((t=this.pane)==null?void 0:t.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var s;return(s=this.pane)==null?void 0:s.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[ss.UUID]===void 0){const t=this.paneManager.createPane(ss.UUID,{paneFormatters:{regular:i=>Su(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=Vr(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);e.autoScaleModel.setHighLowProvider("volumes",n),e.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(ss.UUID),delete this.pane,this.drawingManager.removeDrawerByName("UNDERLAY_VOLUMES_AREA")}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let so=ss;so.UUID="volumes";const ns=.3,xu=(s,t)=>{const e=t.barTheme[`${s}Color`];return It()(e).alpha(ns).toString()},_u=(s,t)=>{const e=t.volume[`${s}BarColor`];return It()(e).alpha(ns).toString()},Pu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return It()(e).alpha(ns).toString()},Js=(s,t)=>{const e=t.candleTheme[`${s}Color`];return It()(e).alpha(ns).toString()},Tu=3;class Mu{constructor(t,e,n,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=n,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const n=(e=this.volumesColorByChartTypeMap[t])!=null?e:_u;this.volumeBarColors.down=n("down",this.config.colors),this.volumeBarColors.up=n("up",this.config.colors),this.volumeBarColors.none=n("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 n=this.getViewportModel().getBounds();Ut(e,n),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const n=vt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1)),i=this.getViewportModel();n.forEach((r,o)=>{if(r.candle.volume){const a=i.getBounds(),l=a.height,c=n[o+1]!==void 0?Z(i.toX(n[o+1].startUnit)):void 0,h=Z(i.toX(r.startUnit)),d=c!==void 0?c-h:Z(ut(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Z(i.toY(r.candle.volume)),g=Z(i.toY(0))-u;this.drawVolume(t,r,h,u,d,g)}else{const u=e/(l/Tu),g=Math.max(ut(r.candle.volume,u),2),m=Z(a.y+l-g);this.drawVolume(t,r,h,m,d,g)}}})}drawVolume(t,e,n,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(n,l),a.lineTo(n,_i(c)),a.stroke()):a.fillRect(n,i,r,_i(o))}}const Au=Ha(s=>s.candle.volume),no="volumes";class Eu extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=no,this.volumeMax=new mt(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(xt(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=re(Au(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class Du extends X{constructor(t,e,n,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new mt(!1),this.volumeIsSeparateModeChangedSubject=new mt(!1);const c=new Eu(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new so(e,r,o,c,a),this.volumesDrawer=new Mu(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:n},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",Js),this.registerVolumeColorResolver("trend",Js),this.registerVolumeColorResolver("hollow",Js),this.registerVolumeColorResolver("line",Pu),this.registerVolumeColorResolver("bar",xu)}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?no:tt,n={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(n);return}this.dynamicObjectsComponent.model.updateObject(n)}}class Iu{constructor(t,e,n,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=n,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,g=this.canvasBoundsContainer.getBounds(x.PANE_UUID(tt)),{position:m,offsetY:C,offsetX:_}=this.config.components.waterMark;let M;switch(d?M=d:(u.font=is(this.config,l),M=u.measureText(a).width,g.width-10<M&&(u.font=Lu(this.config,this.canvasBoundsContainer,l,M),M=u.measureText(a).width)),m){case"left-top":return{x:_+g.x,y:C+o+g.y,font:u.font,text:a,color:c};case"left-bottom":return{x:_+g.x,y:g.height-h-C+o+g.y,font:u.font,text:a,color:c};case"center":return{x:g.width/2-M/2+g.x,y:(g.height-h)/2+o+g.y,font:u.font,text:a,color:c}}}}draw(){var t,e,n,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,g=this.canvasModel.ctx;let m=0,C=0,_=0,M=0,L=0;if(g.save(),d.firstRowFontSize&&l){g.font=is(this.config,d.firstRowFontSize);const F=g.measureText(l);m=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){g.font=is(this.config,d.secondRowFontSize);const F=g.measureText(c);C=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent,_=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){g.font=is(this.config,d.thirdRowFontSize);const F=g.measureText(h);M=F.actualBoundingBoxAscent+F.actualBoundingBoxDescent,L=(n=d.secondRowBottomPadding)!=null?n:0}const H=(i=d.thirdRowBottomPadding)!=null?i:0,z=(r=d.logoHeight)!=null?r:0,R=m+C+_+M+L+H+z;if(l&&this.drawWaterMark(this.getConfig(m,l,d.firstRowFontSize,u.firstRowColor,R)),c&&this.drawWaterMark(this.getConfig(m+_+C,c,d.secondRowFontSize,u.secondRowColor,R)),h&&this.drawWaterMark(this.getConfig(m+_+C+L+M,h,d.thirdRowFontSize,u.thirdRowColor,R)),this.logoImage){const F=this.getConfig(m+_+C+L+M+H,"",d.thirdRowFontSize,u.thirdRowColor,R,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,F.x,F.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}g.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const n=this.canvasModel.ctx;n.font=t.font,n.fillStyle=t.color;const i=t.x,r=t.y;n.fillText(e,i,r)}reset(){}}const Lu=(s,t,e,n)=>{const r=((a,l)=>t.getBounds(x.CHART).width/l*a)(e,n);let o;return s.components&&s.components.waterMark&&(o=s.components.waterMark.fontFamily),r+"px "+o},is=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Bu=Object.defineProperty,io=Object.getOwnPropertySymbols,Ou=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,ro=(s,t,e)=>t in s?Bu(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,oo=(s,t)=>{for(var e in t||(t={}))Ou.call(t,e)&&ro(s,e,t[e]);if(io)for(var e of io(t))Ru.call(t,e)&&ro(s,e,t[e]);return s};class Fu extends X{constructor(t,e,n,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=n,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new Iu(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(At(r.observeBoundsChanged(x.PANE_UUID(tt)),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={};At(e,t),At(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 oo(oo({},this.config.components.waterMark),h)}}const ao={x:4,y:4};function Hu(s,t,e,n){var i,r;const o=(i=n.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(x.X_AXIS);s.save(),s.font=`bold ${a}px ${l}`;const m=s.measureText(n.text).width+ao.x*2;let C=0;const _=n.x;switch(o){case"start":C=_-m;break;case"end":C=_;break;case"middle":default:C=_-m/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(C,u.y,m,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(_,u.y),s.lineTo(_,u.y+u.height),s.stroke()),s.fillStyle=n.color;const M=C+ao.x,L=u.y+d+a;s.fillText(n.text,M,L),s.restore()}class ku{constructor(t,e,n,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=n,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Hu(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},n=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(n).forEach(i=>{const r=n[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.fillStyle=It().rgb(r[0].color).alpha(.1).toString(),sr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const ep="week-weekday",Yu=["second","minute","hour","day","month","year"],ju=["lessThanSecond"],Nu=s=>Yu.some(t=>t===s),Xu=s=>s==="week-weekday",zu=s=>ju.some(t=>t===s),lo=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},Qs=s=>parseInt(s,10),co=s=>{const[t,...e]=s.split("_");if(Nu(t)){const[n]=e,i=lo(n),r=Qs(n);return{key:t,value:r,exact:i["!"]}}else if(Xu(t)){const[n,i]=e,r=lo(n),o=Qs(n),a=Qs(i);return{key:t,week:r.$?"$":o,weekday:a}}else return zu(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats https://webdev.prosp.devexperts.com:8095/docs/chart/x-axis`),null)};class rs{constructor(t,e,n,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=n,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,n=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=rs.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=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);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),e.restore()}}drawLabels(t,e,n,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,d=n.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 tn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},ho=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return tn[s.key]+s.value;case"lessThanSecond":return tn[s.key];case"week-weekday":return tn[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},uo=s=>{const t={};for(const e of s){const n=t[e.weight];n===void 0?t[e.weight]=[e]:n.push(e)}return t},Wu=(s,t)=>{const e=Object.keys(s).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let n=[];for(const i of e){const r=s[i];if(!r)continue;const o=[...n];n=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const g=r[u],m=g.idx;for(;c<a;){const C=o[c],_=C.idx;if(m>_)c++,n.push(C),d=_,h=1/0;else{h=_;break}}h-m>=t&&m-d>=t&&(n.push(g),d=m)}for(;c<a;)n.push(o[c]),c++}return n},Uu=(s,t,e,n,i,r)=>{const o=rs.getFontFromConfig(t),a=Pt(e.text,s,o),l=Pt(n.text,s,o),c=i.toX(e.value)+a/2;return i.toX(n.value)-l/2-c<r};function en(s){"@babel/helpers - typeof";return en=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},en(s)}function Ct(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function yt(s){Ct(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||en(s)==="object"&&t==="[object Date]"?new Date(s.getTime()):typeof s=="number"||t==="[object Number]"?new Date(s):((typeof s=="string"||t==="[object String]")&&typeof console!="undefined"&&(console.warn("Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings. See: https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#string-arguments"),console.warn(new Error().stack)),new Date(NaN))}function Vu(s){return Ct(1,arguments),yt(s).getDay()===1}function Gu(s){return Ct(1,arguments),yt(s).getDay()===2}function Zu(s){return Ct(1,arguments),yt(s).getDay()===3}function $u(s){return Ct(1,arguments),yt(s).getDay()===4}function Ku(s){return Ct(1,arguments),yt(s).getDay()===5}function qu(s){return Ct(1,arguments),yt(s).getDay()===6}function Ju(s){return Ct(1,arguments),yt(s).getDay()===0}function Qu(s,t){var e;Ct(1,arguments);var n=s||{},i=yt(n.start),r=yt(n.end),o=r.getTime();if(!(i.getTime()<=o))throw new RangeError("Invalid interval");var a=[],l=i;l.setHours(0,0,0,0);var c=Number((e=t==null?void 0:t.step)!==null&&e!==void 0?e:1);if(c<1||isNaN(c))throw new RangeError("`options.step` must be a number greater than 1");for(;l.getTime()<=o;)a.push(yt(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function tg(s){Ct(1,arguments);var t=yt(s);return t.setDate(1),t.setHours(0,0,0,0),t}function eg(s){Ct(1,arguments);var t=yt(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function go(s){Ct(1,arguments);var t=yt(s);return t.setHours(0,0,0,0),t}function fo(s,t){Ct(2,arguments);var e=go(s),n=go(t);return e.getTime()===n.getTime()}const sg=s=>{switch(s.key){case"lessThanSecond":return og(s);case"month":return ag(s);case"second":case"minute":case"hour":case"day":case"year":return lg(s);case"week-weekday":return cg(s);default:return()=>!1}},Gt=(s,t)=>{switch(t){case"lessThanSecond":return s.getMilliseconds();case"month":return s.getMonth();case"second":return s.getSeconds();case"minute":return s.getMinutes();case"hour":return s.getHours();case"day":return s.getDate();case"year":return s.getFullYear();case"week-weekday":return s.getDate()}},sn=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n!==i},ng=s=>(t,e)=>{const n=Gt(t,s),i=Gt(e,s);return n>=i},ig={1:Vu,2:Gu,3:Zu,4:$u,5:Ku,6:qu,7:Ju},rg=(s,t,e)=>{var n;const i=Qu({start:tg(s),end:eg(s)}),r=(n=ig[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return fo(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return fo(s,a);o++}}return!1},po=(s,t)=>t===1?s===1:s/t===1,mo=(s,t)=>t===1?!0:s%t===0,og=s=>(t,e)=>ng(s.key)(t,e),ag=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?po(Gt(t,s.key)+1,s.value):mo(Gt(t,s.key)+1,s.value);return n&&i},lg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=s.exact?po(Gt(t,s.key),s.value):mo(Gt(t,s.key),s.value);return n&&i},cg=s=>(t,e)=>{const n=sn(s.key)(t,e),i=rg(t,s.week,s.weekday);return n&&i},hg=s=>{switch(s.key){case"second":case"minute":return dg(s.value);case"hour":return ug(s.value);case"day":return gg(s.value);case"month":return mg(s.value);case"year":return vg(s.value);case"week-weekday":const t=pg(s.week),e=fg(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},dg=s=>s>0&&s<=60,ug=s=>s>0&&s<=24,gg=s=>s>0&&s<=31,fg=s=>vo(s)?s>=1&&s<=7:!1,pg=s=>s==="$"?!0:vo(s)?s>=1&&s<=6:!1,mg=s=>s>0&&s<=12,vg=s=>s>0,vo=s=>!isNaN(s)&&isFinite(s),bg=(s,t,e)=>{var n,i;for(const[r,o]of e)if(o(s,t))return r;return(i=(n=e[e.length-1])==null?void 0:n[0])!=null?i:0};function nn(s,t,e){const n=new Array(s.length);let i=e(0);for(let r=0;r<s.length;r++){const o=s[r],a=e(o.candle.timestamp),l={weight:bg(a,i,t)};n[r]=l,i=a}return n}const bo=s=>{const t={},e={};return Ls(s).forEach(([n,i])=>{const r=co(n),o=r===null?!1:hg(r);if(r&&o){const a=ho(r);t[a]=i,e[a]=sg(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Co{constructor(t,e,n,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=n,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},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?ut(d,h.animationConfig.targetZoomX):ut(d,this.scale.zoomX);if(!isFinite(u))return-1;const g=this.config.components.xAxis.fontSize,m=Object.values(this.formatsByWeightMap).reduce((_,M)=>Math.max(M.length,_),1),C=g*m;return Math.round(C/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=bo(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(x.X_AXIS),n=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||n.push(i)}return n}getLabelsFromChartType(){var t,e;const n=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(n):n}getAllCandlesWithFake(){const t=this.chartModel.mainCandleSeries.visualPoints;if(t.length===0)return[];const n=Array.from({length:750}).map((i,r)=>Yi(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,t.length+r,this.chartModel.getPeriod()));return[...t,...n]}mapWeightedPointsToLabels(t,e){var n;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:(n=a.candle.idx)!=null?n:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:n}=bo(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(n).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateWeightedLabels()}generateWeightedLabels(){const t=this.getAllCandlesWithFake(),e=nn(t,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),n=this.mapWeightedPointsToLabels(e,t);this.labelsGroupedByWeight=uo(n),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}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=nn([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(g=>g.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]),n=nn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=uo(i),o=be(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),g=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&g.shift(),g){const m=g.map(C=>(C.idx=C.idx+t.length,C.value=a.startUnit+a.width+C.value,C));r[u]?c[h]=d.concat(m):c[h]=m}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(){this.generateWeightedLabels()}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 n=Wu(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=n,this.weightedCache={labels:n,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,n;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Uu(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((n=a.weight)!=null?n:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const n=Ls(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=co(o);if(l){const c=ho(l);i[c]=a}}return i},{});return Ls(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class Cg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(Ge,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}class yg extends X{constructor(t,e,n,i,r,o){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTestCanvasModel=o,this.lastXStart=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=l.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=l=>{const{delta:c}=l,h=this.lastXPxWidth-c;if(h<0)return;const d=this.lastXPxWidth/h,u=this.lastXWidth*d,g=this.lastXStart+(this.lastXWidth-u);this.scale.setXScale(g,this.scale.xEnd)},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const a=new Pe(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS),{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(a)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.canvasBoundsContainer.getBoundsHitTest(x.X_AXIS)).subscribe(()=>this.chartModel.doBasicScale())),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class wg extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,g){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h;const m=new Co(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=m,this.xAxisLabelsModel=new Cg(t,[]);const C=new Ws;c.addDrawer(C,"X_AXIS"),this.xAxisDrawer=new rs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),C.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new ku(e,n,o,this.xAxisLabelsModel),C.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new yg(r,a,o,d,this.chartComponent.chartModel,g),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(xt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(K(({prependedCandles:t})=>t.length!==0),ht(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;$a.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(xt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Xe(50,Ne,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ht(()=>bt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Mt((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.timestamp)===((i=e==null?void 0:e.candle)==null?void 0:i.timestamp)}),K(Xn)).subscribe(t=>{var e,n;return(n=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:n.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 Co?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 Sg=Object.defineProperty,yo=Object.getOwnPropertySymbols,xg=Object.prototype.hasOwnProperty,_g=Object.prototype.propertyIsEnumerable,wo=(s,t,e)=>t in s?Sg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,os=(s,t)=>{for(var e in t||(t={}))xg.call(t,e)&&wo(s,e,t[e]);if(yo)for(var e of yo(t))_g.call(t,e)&&wo(s,e,t[e]);return s};class Pg{constructor(t,e,n,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=n,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const n=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=n&&os(os({},n),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&&os(os({},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=bt(t.dataPoints);if(e){const n=t.view.toY(e.close);if(isFinite(n)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:n,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const n=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:qt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const c=Gd(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,c,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,r,o),rounded:!0}}}class Tg{constructor(t,e,n,i,r){this.yAxisLabelsCanvasModel=t,this.backgroundCanvasModel=e,this.canvasBoundsContainer=n,this.fullConfig=i,this.paneManager=r}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx;this.paneManager.yExtents.forEach(n=>{if(n.yAxis.state.visible){const i=n.getYAxisBounds(),r=this.canvasBoundsContainer.getBounds(x.ALL_PANES),o=n.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(o),o.forEach(a=>{var l;const c=(l=a.bounds)!=null?l:i;a.labels.forEach(h=>Er(t,e,c,r,h,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}),Object.values(n.yAxis.model.fancyLabelsModel.customLabels).forEach(a=>Er(t,e,i,r,a,this.canvasBoundsContainer,n.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,n={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=n[r.subGroupId])!=null?o:[];if(n[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(tt));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];sr(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 Mg{constructor(t,e,n){this.fullConfig=t,this.canvasModel=e,this.paneManager=n}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const n=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height);const o=Jt(e.state),a=kt(o,r),l=this.getLabelTextColor();r.save(),Ut(r,i),this.drawLabels(r,n,i,a,o,l,e),r.restore()}})}drawLabels(t,e,n,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=n.y+c,d=n.y+n.height-c;e.forEach(u=>{const g=a.scale.toY(u.value);g>h&&g<d&&Ag(t,n,u.text,g,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 Ag=(s,t,e,n,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Pt(e,s,r)-o:t.x+o;s.fillText(e,l,n+i/2-1)};class Eg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Ra.call(n,e)},this.add=(t,e,n)=>(e in this.handlers?t.call(this.handlers[e],n):this.handlers[e]=[n],this.unsub.bind(this,e,n)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new O,n=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,n),e.unsubscribe=()=>{this.unsub(t,n),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var n;if(!this.muted){const i=(n=this.handlers[t])!=null?n:[];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(Ge,t)}}class Dg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ht(r=>i.components.chart.highlightActiveCandle?r:void 0),Mt()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,n){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=n.candleFromX(r);o&&n.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const n=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-n.left-i}}class Ig{constructor(t,e,n,i,r){this.frameElement=t,this.resizerElement=e,this.bus=n,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${_t()}`,this.canvasResized=new O,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Ns(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.canvasModels.forEach(n=>this.previousBCR&&n.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(Fs,e),this.bus.fire(Ge))}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.previousBCR!==void 0}}var Lg=Array.isArray,Bg=Object.getPrototypeOf,Og=Object.prototype,Rg=Object.keys;function Fg(s){if(s.length===1){var t=s[0];if(Lg(t))return{args:t,keys:null};if(Hg(t)){var e=Rg(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function Hg(s){return s&&typeof s=="object"&&Bg(s)===Og}var kg=Array.isArray;function Yg(s,t){return kg(t)?s.apply(void 0,D([],p(t))):s(t)}function jg(s){return ht(function(t){return Yg(s,t)})}function Ng(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Xg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=Le(s),n=sa(s),i=Fg(s),r=i.args,o=i.keys;if(r.length===0)return Be([],e);var a=new pt(zg(r,e,o?function(l){return Ng(o,l)}:ie));return n?a.pipe(jg(n)):a}function zg(s,t,e){return e===void 0&&(e=ie),function(n){So(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){So(t,function(){var d=Be(s[h],t),u=!1;d.subscribe(Tt(n,function(g){r[h]=g,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function So(s,t,e){s?Ht(e,s,t):t()}class Wg extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new mt(null)}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,n){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,n)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const n=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Xg([n,i]).pipe(K(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}else this.crossSubject.next(null),r=!0});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}class Ug{constructor(t,e,n,i){this.visualCandle=t,this.price=e,this.priceFormatter=n,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 Vg{constructor(t){this.chartModel=t}getData(t){const{x:e,y:n}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(n);return o&&new Ug(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Gg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof br)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 Zg=Object.defineProperty,$g=Object.defineProperties,Kg=Object.getOwnPropertyDescriptors,xo=Object.getOwnPropertySymbols,qg=Object.prototype.hasOwnProperty,Jg=Object.prototype.propertyIsEnumerable,_o=(s,t,e)=>t in s?Zg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Te=(s,t)=>{for(var e in t||(t={}))qg.call(t,e)&&_o(s,e,t[e]);if(xo)for(var e of xo(t))Jg.call(t,e)&&_o(s,e,t[e]);return s},rn=(s,t)=>$g(s,Kg(t));class Qg extends X{constructor(t,e,n,i,r,o,a,l,c){super(),this.crossEventProducer=t,this.scale=e,this.config=n,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.formatterFactory=c,this.hoverSubject=new mt(null),this.longTouchActivatedSubject=new mt(!1),this.xFormatter=()=>"";const h=new Vg(this.chartModel),d=new Gg(this.chartModel);this.hoverProducerParts={candleHover:h,compareSeriesHover:d}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.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(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;const i=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,r=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y,o=this.chartModel.candleFromX(i,!0),a=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";o&&this.createAndFireHover([i,r,a])}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;this.paneManager.chartPanComponent.deactivatePanHandlers(),this.longTouchActivatedSubject.next(!0);const i=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,r=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y,o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o]),this.crossEventProducer.crossSubject.next([i,r,o])})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(()=>{this.paneManager.chartPanComponent.activateChartPanHandlers(),this.longTouchActivatedSubject.getValue()&&(this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose())})),this.addRxSubscription(xt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter()))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=Ir(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),n=this.scale.toY(t.close);return this.createHover(e,n,tt)}createHover(t,e,n){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:n},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>rn(Te({},l),{[c[0]]:c[1].getData(o)}),{});return Te(Te({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const n=rn(Te({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(n)}}createAndFireHover([t,e,n]){const i=this.createHover(t,e,n);this.fireHover(i)}fireHover(t){var e;if(t){if(_s()&&this.config.components.crossTool.type!=="none"){const n=(e=t.candleHover)==null?void 0:e.visualCandle.candle;n&&this.chartModel.mainCandleSeries.setActiveCandle(n)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=rn(Te({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const Po={left:0,middle:1,right:2};function gt(s,t,e,n){return s.addEventListener(e,t,n),function(){s.removeEventListener(e,t,n)}}function ue(s){return t=>{t.button===Po.left&&s(t)}}var tf=Object.defineProperty,To=Object.getOwnPropertySymbols,ef=Object.prototype.hasOwnProperty,sf=Object.prototype.propertyIsEnumerable,Mo=(s,t,e)=>t in s?tf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,nf=(s,t)=>{for(var e in t||(t={}))ef.call(t,e)&&Mo(s,e,t[e]);if(To)for(var e of To(t))sf.call(t,e)&&Mo(s,e,t[e]);return s};const ee=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new O,this.xDragSubject=new O,this.xDragTickSubject=new O,this.xDragEndSubject=new O,this.yDragStartSubject=new O,this.yDragSubject=new O,this.yDragTickSubject=new O,this.yDragEndSubject=new O,this.mouseMoveSubject=new O,this.mouseMoveDocumentSubject=new O,this.clickSubject=new O,this.clickDocumentSubject=new O,this.dbClickSubject=new O,this.dbTapSubject=new O,this.mouseDownSubject=new O,this.mouseUpSubject=new O,this.mouseUpDocumentSubject=new O,this.wheelSubject=new O,this.touchStartSubject=new O,this.touchStartTimestamp=0,this.touchMoveSubject=new O,this.touchEndSubject=new O,this.touchCancelSubject=new O,this.longTouchStartSubject=new O,this.longTouchEndSubject=new O,this.contextMenuSubject=new O,this.fastTouchScroll=new O,this.mouseLeavesCanvasSubject=new O,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.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=e=>{this.isDraggable(e)&&(this.updateCurrentPoints(e),this.dragging=!0,this.dragStartEvent=e,this.documentDragListeners.forEach(n=>n()),this.dragStartPoint=ee.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=nf({},this.dragStartPoint),ee.DRAG_EVENTS.forEach(n=>{document.addEventListener(n,this.dragProcessListener,!0);const i=document.removeEventListener.bind(document,n,this.dragProcessListener,!0);this.documentDragListeners.push(i),this.addSubscription(i)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.documentDragListeners.forEach(e=>e()),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=e=>{this.updateCurrentDocumentPoint(e),this.updateCurrentMousePoint(e)}}isDraggable(s){return s instanceof MouseEvent?s.button===Po.left:s instanceof TouchEvent}startDragging(s){this.updateCurrentPoints(s),this.dragStartListener(s)}movePointer(s){this.updateCurrentPoints(s),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const s=t=>(t.preventDefault(),!1);this.element.addEventListener("selectstart",s,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",s,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],ee.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),ee.DRAG_EVENTS.forEach(e=>{document.addEventListener(e,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragListener)),this.element.addEventListener(e,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,e,this.updateElementOffsetListener))}),ee.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,ue(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,ue(e=>this.clickDocumentSubject.next(e)),"click"));const s=zr();if(s==="apple"||s==="mobile"){let e=null;const n=o=>{o.preventDefault(),e?(this.dbTapSubject.next(this.currentPoint),clearTimeout(e),e=null):e=window.setTimeout(()=>{e=null},250)};this.addSubscription(gt(this.element,n,"touchend"));const i=(o,a=700,l=3)=>{o.preventDefault();const c={x:o.touches[0].clientX,y:o.touches[0].clientY};let h={x:0,y:0},d=!1,u=null;u=setTimeout(()=>{d=!0,this.longTouchStartSubject.next(o)},a);const g=C=>{C.preventDefault(),h={x:C.touches[0].clientX,y:C.touches[0].clientY},(Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2))>l||C.touches.length>1)&&u&&clearTimeout(u)},m=C=>{C.preventDefault(),u&&clearTimeout(u),d&&(d=!1,this.longTouchEndSubject.next(C)),this.element.removeEventListener("touchend",m),this.element.removeEventListener("touchmove",g)};this.element.addEventListener("touchmove",g),this.element.addEventListener("touchend",m)};this.addSubscription(gt(this.element,o=>i(o),"touchstart"));const r=o=>{if(o.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const c=this.touchStartTimestamp,d=Date.now()-c,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,m=d<=250;g&&m&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,ue(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(gt(this.element,e=>{this.touchStartSubject.next(e),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(gt(this.element,e=>this.touchMoveSubject.next(e),"touchmove",!0)),this.addSubscription(gt(this.element,e=>this.touchEndSubject.next(e),"touchend")),this.addSubscription(gt(this.element,e=>this.touchCancelSubject.next(e),"touchcancel")),this.addSubscription(gt(this.element,e=>{this.wheelSubject.next(e),e.preventDefault()},"wheel")),this.addSubscription(gt(this.element,e=>this.contextMenuSubject.next(e),"contextmenu")),this.addSubscription(gt(this.element,ue(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,ue(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,ue(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(Fs).subscribe(()=>{const e=this.element.getBoundingClientRect();this.canvasBounds.x=e.left,this.canvasBounds.y=e.top,this.canvasBounds.width=e.width,this.canvasBounds.height=e.height}));const t=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",t,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){ee.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(s,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(s){"pageX"in s?this.currentPointDocument.x=s.pageX:s.touches!==void 0&&(this.currentPointDocument.x=s.touches[0].pageX),"pageY"in s?this.currentPointDocument.y=s.pageY:s.touches!==void 0&&(this.currentPointDocument.y=s.touches[0].pageY)}updateCurrentMousePoint(s){const t=this.element.getBoundingClientRect();"clientX"in s?this.currentPoint.x=s.clientX-t.left:s.touches!==void 0&&(this.currentPoint.x=s.touches[0].clientX-t.left),"clientY"in s?this.currentPoint.y=s.clientY-t.top:s.touches!==void 0&&(this.currentPoint.y=s.touches[0].clientY-t.top)}static copyPoint(s){return{x:s.x,y:s.y}}observeMouseMove(s=()=>!0){return this.mouseMoveSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(K(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(K(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ht(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(K(()=>!(t&&this.dragging)),ht(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ht(()=>!1));return xt(e,n).pipe(Mt())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(s=()=>!0){return this.mouseDownSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)),eo(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(K(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let as=ee;as.DRAG_START_EVENTS=["mousedown","touchstart"],as.DRAG_EVENTS=["mousemove","touchmove"],as.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var rf=function(s){W(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Es);var r=s.call(this)||this;return r._bufferSize=e,r._windowTime=n,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=n===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,n),r}return t.prototype.next=function(e){var n=this,i=n.isStopped,r=n._buffer,o=n._infiniteTimeWindow,a=n._timestampProvider,l=n._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),s.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var n=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),n},t.prototype._trimBuffer=function(){var e=this,n=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*n;if(n<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}(O);const on={};function of(s){return on[s]||(on[s]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:s,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),on[s]}const Ao=(s,t=Date.now())=>{const n=of(s).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);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},Eo=60*1e3;class af{constructor(t){this.config=t,this.timeZoneChangedSubject=new rf,this.currentTzOffset=e=>Ao(this.config.timezone,e)+new Date(e).getTimezoneOffset()*Eo,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 n=t.createFormatterFunction;e=i=>n(i).bind(t)}else e=Wh(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+Ao(t,e)+new Date(e).getTimezoneOffset()*Eo):e=>new Date(e)}}class lf extends X{constructor(t,e,n){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=n}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(Mt((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class an{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;Ka(r),this.config=r;const o=vl(r);t.innerHTML="",t.appendChild(o.content),this.id=(n=t.getAttribute("data-id"))!=null?n:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new af(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=bl(t);this.elements=c;const h=new Eg;this.bus=h;const d=new Ig(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 th(h,d);this.drawingManager=u;const g=Jc(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=g,this.dynamicObjectsCanvasModel=he(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const m=new xe(this.dynamicObjectsCanvasModel);u.addDrawer(m,"SERIES_CLEAR");const C=he(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),_=new As(r,h,g,l,d);this.canvasBoundsContainer=_;const M=c.mainCanvas.parentElement;if(M===null)throw new Error("Couldn't get main canvas parent");const L=new as(h,M);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const H=new ed(h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=H;const z=new xe(H);u.addDrawer(z,"HIT_TEST_CLEAR");const R=new Ma(h);this.canvasAnimation=R;const F=x.PANE_UUID(tt),Y=new tr(r,()=>_.getBounds(F),R);this.scaleModel=Y;const q=he(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=q,this.cursorHandler=new fl(c.canvasArea,L,_,H),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Wg(L,_),this.chartComponents.push(this.crossEventProducer);const V=new zl("candle");this.chartBaseModel=V;const N=new Hd(h,Y,_,r,R,L,M,V,H);this.chartPanComponent=N,this.chartComponents.push(N),this.userInputListenerComponents.push(N.chartAreaPanHandler);const U=new lf(H,R,h);this.hitTestComponent=U,this.chartComponents.push(U);const Q=new yu(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,Y,_,r,R,L,u,this.cursorHandler,this.crossEventProducer,N,g,C,this.hitTestCanvasModel);this.paneManager=Q;const J=this.paneManager.panes[tt];this.mainPane=J,this.chartComponents.push(Q),this.dynamicObjects=new Xh(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Mh(V,Q,h,this.dynamicObjectsCanvasModel,r,Y,l,M,_,d);const st=new hh(this.chartModel,this.dynamicObjectsCanvasModel,r,Y,_,u,H,L,q,N,Q,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(st),this.chartComponent=st;const G=this.chartComponent.chartModel;this.chartModel=G,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),H.addSubscriber(Q.hitTestController),this.xAxisComponent=new wg(h,r,g,st,Y,_,L,d,this.drawingManager,a,N,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const nt=new xe(g);u.addDrawer(nt,"MAIN_CLEAR");const ot=new Dg(M,G,L,r);this.chartComponents.push(ot),this.watermarkComponent=new Fu(Q,G,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ft=he(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new yd(h,r,G,g,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(G)),this.navigationMapComponent=new Ed(h,G,g,r,L,_,u,l,N,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const at=new gd(r,this.dynamicObjectsCanvasModel,G,_,u);this.chartComponents.push(at),this.initYAxisDrawer(C),this.yAxisComponent=J.mainExtent.yAxis;const wt=new Pg(this.chartModel,this.config,J.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(wt,Ks.MAIN),this.volumesComponent=new Du(this.dynamicObjectsCanvasModel,st,Y,_,u,r,Q,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const se=new Hr(g,Y,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(F),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>this.yAxisComponent.model.baseLabelsModel.labels,()=>J.mainExtent.toY(J.mainExtent.getBaseline()),()=>r.components.grid.visible);this.chartComponents.push(se),this.hoverProducer=new Qg(this.crossEventProducer,Y,r,G,L,this.canvasBoundsContainer,this.paneManager,a,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new kh(r,ft,_,u,Q,this.crossEventProducer,this.hoverProducer),this.chartComponents.push(this.crossToolComponent);const cs=he(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),ln=new wu(this.elements,cs);this.snapshotComponent=ln,this.chartComponents.push(ln);const cn=new hd(r,this.dynamicObjectsCanvasModel,H,G,_,u,l,this.cursorHandler);this.eventsComponent=cn,this.chartComponents.push(cn),this.chartComponents.forEach(hn=>hn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Ea(this.components)}initYAxisDrawer(t){const e=new Ws,n=new xe(t);e.addDrawer(n,"YAXIS_CLEAR"),this.drawingManager.addDrawer(e,"Y_AXIS");const i=new Mg(this.config,t,this.paneManager);e.addDrawer(i);const r=new Tg(t,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);e.addDrawer(r)}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&an.mergeConfig(t[n],e[n]):t[n]=e[n];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,n,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(n=t.dash)!=null?n:[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){At(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(n).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,n=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,n).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(n).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const n=this.canvasBoundsContainer.getBoundsHitTest(t),i=xt(this.canvasInputListener.observeYDrag(n),this.canvasInputListener.observeXDrag(n)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const n=t(this);this.components.push(n),e&&e(n),n.activate()}}class Do extends an{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 n;(n=this.paneManager.panes[t])==null||n.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,...n]=t;this.chartComponent.setAllSeries(e,n)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...n]=t;this.chartComponent.updateAllSeries(e,n)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.chartComponent.setChartType(t)}createPane(){return this.paneManager.createPane()}}var cf=Object.defineProperty,hf=Object.defineProperties,df=Object.getOwnPropertyDescriptors,Io=Object.getOwnPropertySymbols,uf=Object.prototype.hasOwnProperty,gf=Object.prototype.propertyIsEnumerable,Lo=(s,t,e)=>t in s?cf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ff=(s,t)=>{for(var e in t||(t={}))uf.call(t,e)&&Lo(s,e,t[e]);if(Io)for(var e of Io(t))gf.call(t,e)&&Lo(s,e,t[e]);return s},pf=(s,t)=>hf(s,df(t));function Bo(s){s=s||{},s.quantity=s.quantity||200,s.startY=s.startY||50,s.avgCandleSize=s.avgCandleSize||2,s.avgTrendLength=s.avgTrendLength||{},s.avgTrendLength.sw=s.avgTrendLength.sw||10,s.avgTrendLength.down=s.avgTrendLength.down||10,s.avgTrendLength.up=s.avgTrendLength.up||10,s.withVolume=s.withVolume===!0||!1,s.period=s.period||3600;var t=[],e=s.quantity||200,n=10,i=10,r=10;s.avgTrendLength&&(n=s.avgTrendLength.sw||10,i=s.avgTrendLength.down||10,r=s.avgTrendLength.up||10);var o=s.startY||50,a=s.avgCandleSize||2,l=o-a,c=o+a,h=ls(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(bf(t[t.length-1],a,n)):d>3?t=t.concat(mf(t[t.length-1],a,r)):t=t.concat(vf(t[t.length-1],a,i))}t=t.slice(0,s.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*s.period;for(let g=0;g<t.length;g++){const m=t[g];Object.assign(m,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(m.volume=Math.ceil(Math.random()*1e3+200))}return t}function ls(s,t,e,n){var i=Math.random()*(t-s)+s,r;if(n&&n==="bull"||!n&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>s?a:s}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function mf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.lo,o=s.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=ls(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),n.push(c)}return n}function vf(s,t,e){for(var n=[],i=Math.random()*e+e/2,r=s.hi-t*1.2,o=s.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=ls(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),n.push(c)}return n}function bf(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var g,m;return Math.random()>.5?(g=u.lo-t*.2,m=u.hi+t*1.2):(g=u.lo-t*1.2,m=u.hi+t*.2),{from:g,to:m}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=ls(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),n.push(d)}return n}window.DXChart=pf(ff({},window.DXChart),{generateCandlesData:Bo});function Cf(s){return Bo(s)}const yf=(s,t={})=>new Do(s,t)})(),window.DXChart=hs})();})();