@devexperts/dxcharts-lite 2.7.6 → 2.7.9

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.
Files changed (29) hide show
  1. package/README.md +41 -43
  2. package/dist/chart/canvas/canvas-bounds-container.d.ts +1 -0
  3. package/dist/chart/canvas/canvas-bounds-container.js +8 -0
  4. package/dist/chart/chart.config.d.ts +5 -0
  5. package/dist/chart/chart.config.js +4 -0
  6. package/dist/chart/components/chart/candle.functions.js +1 -0
  7. package/dist/chart/components/highlights/highlights.drawer.js +4 -1
  8. package/dist/chart/components/pane/extent/y-extent-component.d.ts +1 -1
  9. package/dist/chart/components/pane/extent/y-extent-component.js +19 -3
  10. package/dist/chart/components/pane/pane.component.d.ts +2 -2
  11. package/dist/chart/components/pane/pane.component.js +5 -0
  12. package/dist/chart/drawers/chart-type-drawers/area.drawer.js +9 -2
  13. package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.d.ts +1 -0
  14. package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.js +12 -9
  15. package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.d.ts +5 -2
  16. package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +12 -11
  17. package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.d.ts +1 -1
  18. package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +14 -15
  19. package/dist/chart/drawers/data-series.drawer.js +3 -1
  20. package/dist/chart/drawers/ht-data-series.drawer.d.ts +1 -0
  21. package/dist/chart/drawers/ht-data-series.drawer.js +2 -1
  22. package/dist/chart/model/candle.model.d.ts +4 -0
  23. package/dist/chart/model/candle.model.js +2 -1
  24. package/dist/chart/model/data-series.config.d.ts +2 -1
  25. package/dist/chart/model/data-series.model.js +1 -1
  26. package/dist/chart/utils/math.utils.d.ts +2 -1
  27. package/dist/chart/utils/math.utils.js +37 -6
  28. package/dist/dxchart.min.js +4 -4
  29. package/package.json +1 -1
@@ -3,10 +3,10 @@
3
3
  * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
4
  * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
5
  */
6
- (()=>{var nt=Math.pow;(()=>{var Go={168:(j,st,Y)=>{const K=Y(874),z={};for(const b of Object.keys(K))z[K[b]]=b;const D={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"]}};j.exports=D;for(const b of Object.keys(D)){if(!("channels"in D[b]))throw new Error("missing channels property: "+b);if(!("labels"in D[b]))throw new Error("missing channel labels property: "+b);if(D[b].labels.length!==D[b].channels)throw new Error("channel and label counts mismatch: "+b);const{channels:y,labels:C}=D[b];delete D[b].channels,delete D[b].labels,Object.defineProperty(D[b],"channels",{value:y}),Object.defineProperty(D[b],"labels",{value:C})}D.rgb.hsl=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(y,C,w),S=Math.max(y,C,w),T=S-g;let A,m;S===g?A=0:y===S?A=(C-w)/T:C===S?A=2+(w-y)/T:w===S&&(A=4+(y-C)/T),A=Math.min(A*60,360),A<0&&(A+=360);const M=(g+S)/2;return S===g?m=0:M<=.5?m=T/(S+g):m=T/(2-S-g),[A,m*100,M*100]},D.rgb.hsv=function(b){let y,C,w,g,S;const T=b[0]/255,A=b[1]/255,m=b[2]/255,M=Math.max(T,A,m),E=M-Math.min(T,A,m),I=function(R){return(M-R)/6/E+1/2};return E===0?(g=0,S=0):(S=E/M,y=I(T),C=I(A),w=I(m),T===M?g=w-C:A===M?g=.3333333333333333+y-w:m===M&&(g=.6666666666666666+C-y),g<0?g+=1:g>1&&(g-=1)),[g*360,S*100,M*100]},D.rgb.hwb=function(b){const y=b[0],C=b[1];let w=b[2];const g=D.rgb.hsl(b)[0],S=1/255*Math.min(y,Math.min(C,w));return w=1-.00392156862745098*Math.max(y,Math.max(C,w)),[g,S*100,w*100]},D.rgb.cmyk=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(1-y,1-C,1-w),S=(1-y-g)/(1-g)||0,T=(1-C-g)/(1-g)||0,A=(1-w-g)/(1-g)||0;return[S*100,T*100,A*100,g*100]};function lt(b,y){return nt(b[0]-y[0],2)+nt(b[1]-y[1],2)+nt(b[2]-y[2],2)}D.rgb.keyword=function(b){const y=z[b];if(y)return y;let C=1/0,w;for(const g of Object.keys(K)){const S=K[g],T=lt(b,S);T<C&&(C=T,w=g)}return w},D.keyword.rgb=function(b){return K[b]},D.rgb.xyz=function(b){let y=b[0]/255,C=b[1]/255,w=b[2]/255;y=y>.04045?nt((y+.055)/1.055,2.4):y/12.92,C=C>.04045?nt((C+.055)/1.055,2.4):C/12.92,w=w>.04045?nt((w+.055)/1.055,2.4):w/12.92;const g=y*.4124+C*.3576+w*.1805,S=y*.2126+C*.7152+w*.0722,T=y*.0193+C*.1192+w*.9505;return[g*100,S*100,T*100]},D.rgb.lab=function(b){const y=D.rgb.xyz(b);let C=y[0],w=y[1],g=y[2];C/=95.047,w/=100,g/=108.883,C=C>.008856?nt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?nt(w,.3333333333333333):7.787*w+.13793103448275862,g=g>.008856?nt(g,.3333333333333333):7.787*g+.13793103448275862;const S=116*w-16,T=500*(C-w),A=200*(w-g);return[S,T,A]},D.hsl.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;let g,S,T;if(C===0)return T=w*255,[T,T,T];w<.5?g=w*(1+C):g=w+C-w*C;const A=2*w-g,m=[0,0,0];for(let M=0;M<3;M++)S=y+.3333333333333333*-(M-1),S<0&&S++,S>1&&S--,6*S<1?T=A+(g-A)*6*S:2*S<1?T=g:3*S<2?T=A+(g-A)*(.6666666666666666-S)*6:T=A,m[M]=T*255;return m},D.hsl.hsv=function(b){const y=b[0];let C=b[1]/100,w=b[2]/100,g=C;const S=Math.max(w,.01);w*=2,C*=w<=1?w:2-w,g*=S<=1?S:2-S;const T=(w+C)/2,A=w===0?2*g/(S+g):2*C/(w+C);return[y,A*100,T*100]},D.hsv.rgb=function(b){const y=b[0]/60,C=b[1]/100;let w=b[2]/100;const g=Math.floor(y)%6,S=y-Math.floor(y),T=255*w*(1-C),A=255*w*(1-C*S),m=255*w*(1-C*(1-S));switch(w*=255,g){case 0:return[w,m,T];case 1:return[A,w,T];case 2:return[T,w,m];case 3:return[T,A,w];case 4:return[m,T,w];case 5:return[w,T,A]}},D.hsv.hsl=function(b){const y=b[0],C=b[1]/100,w=b[2]/100,g=Math.max(w,.01);let S,T;T=(2-C)*w;const A=(2-C)*g;return S=C*g,S/=A<=1?A:2-A,S=S||0,T/=2,[y,S*100,T*100]},D.hwb.rgb=function(b){const y=b[0]/360;let C=b[1]/100,w=b[2]/100;const g=C+w;let S;g>1&&(C/=g,w/=g);const T=Math.floor(6*y),A=1-w;S=6*y-T,T&1&&(S=1-S);const m=C+S*(A-C);let M,E,I;switch(T){default:case 6:case 0:M=A,E=m,I=C;break;case 1:M=m,E=A,I=C;break;case 2:M=C,E=A,I=m;break;case 3:M=C,E=m,I=A;break;case 4:M=m,E=C,I=A;break;case 5:M=A,E=C,I=m;break}return[M*255,E*255,I*255]},D.cmyk.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100,g=b[3]/100,S=1-Math.min(1,y*(1-g)+g),T=1-Math.min(1,C*(1-g)+g),A=1-Math.min(1,w*(1-g)+g);return[S*255,T*255,A*255]},D.xyz.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100;let g,S,T;return g=y*3.2406+C*-1.5372+w*-.4986,S=y*-.9689+C*1.8758+w*.0415,T=y*.0557+C*-.204+w*1.057,g=g>.0031308?1.055*nt(g,.4166666666666667)-.055:g*12.92,S=S>.0031308?1.055*nt(S,.4166666666666667)-.055:S*12.92,T=T>.0031308?1.055*nt(T,.4166666666666667)-.055:T*12.92,g=Math.min(Math.max(0,g),1),S=Math.min(Math.max(0,S),1),T=Math.min(Math.max(0,T),1),[g*255,S*255,T*255]},D.xyz.lab=function(b){let y=b[0],C=b[1],w=b[2];y/=95.047,C/=100,w/=108.883,y=y>.008856?nt(y,.3333333333333333):7.787*y+.13793103448275862,C=C>.008856?nt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?nt(w,.3333333333333333):7.787*w+.13793103448275862;const g=116*C-16,S=500*(y-C),T=200*(C-w);return[g,S,T]},D.lab.xyz=function(b){const y=b[0],C=b[1],w=b[2];let g,S,T;S=(y+16)/116,g=C/500+S,T=S-w/200;const A=nt(S,3),m=nt(g,3),M=nt(T,3);return S=A>.008856?A:(S-.13793103448275862)/7.787,g=m>.008856?m:(g-.13793103448275862)/7.787,T=M>.008856?M:(T-.13793103448275862)/7.787,g*=95.047,S*=100,T*=108.883,[g,S,T]},D.lab.lch=function(b){const y=b[0],C=b[1],w=b[2];let g;g=Math.atan2(w,C)*360/2/Math.PI,g<0&&(g+=360);const T=Math.sqrt(C*C+w*w);return[y,T,g]},D.lch.lab=function(b){const y=b[0],C=b[1],g=b[2]/360*2*Math.PI,S=C*Math.cos(g),T=C*Math.sin(g);return[y,S,T]},D.rgb.ansi16=function(b,y=null){const[C,w,g]=b;let S=y===null?D.rgb.hsv(b)[2]:y;if(S=Math.round(S/50),S===0)return 30;let T=30+(Math.round(g/255)<<2|Math.round(w/255)<<1|Math.round(C/255));return S===2&&(T+=60),T},D.hsv.ansi16=function(b){return D.rgb.ansi16(D.hsv.rgb(b),b[2])},D.rgb.ansi256=function(b){const y=b[0],C=b[1],w=b[2];return y===C&&C===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(C/255*5)+Math.round(w/255*5)},D.ansi16.rgb=function(b){let y=b%10;if(y===0||y===7)return b>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const C=(~~(b>50)+1)*.5,w=(y&1)*C*255,g=(y>>1&1)*C*255,S=(y>>2&1)*C*255;return[w,g,S]},D.ansi256.rgb=function(b){if(b>=232){const S=(b-232)*10+8;return[S,S,S]}b-=16;let y;const C=Math.floor(b/36)/5*255,w=Math.floor((y=b%36)/6)/5*255,g=y%6/5*255;return[C,w,g]},D.rgb.hex=function(b){const C=(((Math.round(b[0])&255)<<16)+((Math.round(b[1])&255)<<8)+(Math.round(b[2])&255)).toString(16).toUpperCase();return"000000".substring(C.length)+C},D.hex.rgb=function(b){const y=b.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let C=y[0];y[0].length===3&&(C=C.split("").map(A=>A+A).join(""));const w=parseInt(C,16),g=w>>16&255,S=w>>8&255,T=w&255;return[g,S,T]},D.rgb.hcg=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.max(Math.max(y,C),w),S=Math.min(Math.min(y,C),w),T=g-S;let A,m;return T<1?A=S/(1-T):A=0,T<=0?m=0:g===y?m=(C-w)/T%6:g===C?m=2+(w-y)/T:m=4+(y-C)/T,m/=6,m%=1,[m*360,T*100,A*100]},D.hsl.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=C<.5?2*y*C:2*y*(1-C);let g=0;return w<1&&(g=(C-.5*w)/(1-w)),[b[0],w*100,g*100]},D.hsv.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=y*C;let g=0;return w<1&&(g=(C-w)/(1-w)),[b[0],w*100,g*100]},D.hcg.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;if(C===0)return[w*255,w*255,w*255];const g=[0,0,0],S=y%1*6,T=S%1,A=1-T;let m=0;switch(Math.floor(S)){case 0:g[0]=1,g[1]=T,g[2]=0;break;case 1:g[0]=A,g[1]=1,g[2]=0;break;case 2:g[0]=0,g[1]=1,g[2]=T;break;case 3:g[0]=0,g[1]=A,g[2]=1;break;case 4:g[0]=T,g[1]=0,g[2]=1;break;default:g[0]=1,g[1]=0,g[2]=A}return m=(1-C)*w,[(C*g[0]+m)*255,(C*g[1]+m)*255,(C*g[2]+m)*255]},D.hcg.hsv=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);let g=0;return w>0&&(g=y/w),[b[0],g*100,w*100]},D.hcg.hsl=function(b){const y=b[1]/100,w=b[2]/100*(1-y)+.5*y;let g=0;return w>0&&w<.5?g=y/(2*w):w>=.5&&w<1&&(g=y/(2*(1-w))),[b[0],g*100,w*100]},D.hcg.hwb=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);return[b[0],(w-y)*100,(1-w)*100]},D.hwb.hcg=function(b){const y=b[1]/100,w=1-b[2]/100,g=w-y;let S=0;return g<1&&(S=(w-g)/(1-g)),[b[0],g*100,S*100]},D.apple.rgb=function(b){return[b[0]/65535*255,b[1]/65535*255,b[2]/65535*255]},D.rgb.apple=function(b){return[b[0]/255*65535,b[1]/255*65535,b[2]/255*65535]},D.gray.rgb=function(b){return[b[0]/100*255,b[0]/100*255,b[0]/100*255]},D.gray.hsl=function(b){return[0,0,b[0]]},D.gray.hsv=D.gray.hsl,D.gray.hwb=function(b){return[0,100,b[0]]},D.gray.cmyk=function(b){return[0,0,0,b[0]]},D.gray.lab=function(b){return[b[0],0,0]},D.gray.hex=function(b){const y=Math.round(b[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},D.rgb.gray=function(b){return[(b[0]+b[1]+b[2])/3/255*100]}},85:(j,st,Y)=>{const K=Y(168),z=Y(111),D={},lt=Object.keys(K);function b(C){const w=function(...g){const S=g[0];return S==null?S:(S.length>1&&(g=S),C(g))};return"conversion"in C&&(w.conversion=C.conversion),w}function y(C){const w=function(...g){const S=g[0];if(S==null)return S;S.length>1&&(g=S);const T=C(g);if(typeof T=="object")for(let A=T.length,m=0;m<A;m++)T[m]=Math.round(T[m]);return T};return"conversion"in C&&(w.conversion=C.conversion),w}lt.forEach(C=>{D[C]={},Object.defineProperty(D[C],"channels",{value:K[C].channels}),Object.defineProperty(D[C],"labels",{value:K[C].labels});const w=z(C);Object.keys(w).forEach(S=>{const T=w[S];D[C][S]=y(T),D[C][S].raw=b(T)})}),j.exports=D},111:(j,st,Y)=>{const K=Y(168);function z(){const y={},C=Object.keys(K);for(let w=C.length,g=0;g<w;g++)y[C[g]]={distance:-1,parent:null};return y}function D(y){const C=z(),w=[y];for(C[y].distance=0;w.length;){const g=w.pop(),S=Object.keys(K[g]);for(let T=S.length,A=0;A<T;A++){const m=S[A],M=C[m];M.distance===-1&&(M.distance=C[g].distance+1,M.parent=g,w.unshift(m))}}return C}function lt(y,C){return function(w){return C(y(w))}}function b(y,C){const w=[C[y].parent,y];let g=K[C[y].parent][y],S=C[y].parent;for(;C[S].parent;)w.unshift(C[S].parent),g=lt(K[C[S].parent][S],g),S=C[S].parent;return g.conversion=w,g}j.exports=function(y){const C=D(y),w={},g=Object.keys(C);for(let S=g.length,T=0;T<S;T++){const A=g[T];C[A].parent!==null&&(w[A]=b(A,C))}return w}},874:j=>{"use strict";j.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:(j,st,Y)=>{var K=Y(874),z=Y(851),D=Object.hasOwnProperty,lt=Object.create(null);for(var b in K)D.call(K,b)&&(lt[K[b]]=b);var y=j.exports={to:{},get:{}};y.get=function(g){var S=g.substring(0,3).toLowerCase(),T,A;switch(S){case"hsl":T=y.get.hsl(g),A="hsl";break;case"hwb":T=y.get.hwb(g),A="hwb";break;default:T=y.get.rgb(g),A="rgb";break}return T?{model:A,value:T}:null},y.get.rgb=function(g){if(!g)return null;var S=/^#([a-f0-9]{3,4})$/i,T=/^#([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*)?\)$/,m=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,M=/^(\w+)$/,E=[0,0,0,1],I,R,at;if(I=g.match(T)){for(at=I[2],I=I[1],R=0;R<3;R++){var It=R*2;E[R]=parseInt(I.slice(It,It+2),16)}at&&(E[3]=parseInt(at,16)/255)}else if(I=g.match(S)){for(I=I[1],at=I[3],R=0;R<3;R++)E[R]=parseInt(I[R]+I[R],16);at&&(E[3]=parseInt(at+at,16)/255)}else if(I=g.match(A)){for(R=0;R<3;R++)E[R]=parseInt(I[R+1],0);I[4]&&(I[5]?E[3]=parseFloat(I[4])*.01:E[3]=parseFloat(I[4]))}else if(I=g.match(m)){for(R=0;R<3;R++)E[R]=Math.round(parseFloat(I[R+1])*2.55);I[4]&&(I[5]?E[3]=parseFloat(I[4])*.01:E[3]=parseFloat(I[4]))}else return(I=g.match(M))?I[1]==="transparent"?[0,0,0,0]:D.call(K,I[1])?(E=K[I[1]],E[3]=1,E):null:null;for(R=0;R<3;R++)E[R]=C(E[R],0,255);return E[3]=C(E[3],0,1),E},y.get.hsl=function(g){if(!g)return null;var S=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,T=g.match(S);if(T){var A=parseFloat(T[4]),m=(parseFloat(T[1])%360+360)%360,M=C(parseFloat(T[2]),0,100),E=C(parseFloat(T[3]),0,100),I=C(isNaN(A)?1:A,0,1);return[m,M,E,I]}return null},y.get.hwb=function(g){if(!g)return null;var S=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,T=g.match(S);if(T){var A=parseFloat(T[4]),m=(parseFloat(T[1])%360+360)%360,M=C(parseFloat(T[2]),0,100),E=C(parseFloat(T[3]),0,100),I=C(isNaN(A)?1:A,0,1);return[m,M,E,I]}return null},y.to.hex=function(){var g=z(arguments);return"#"+w(g[0])+w(g[1])+w(g[2])+(g[3]<1?w(Math.round(g[3]*255)):"")},y.to.rgb=function(){var g=z(arguments);return g.length<4||g[3]===1?"rgb("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+")":"rgba("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+", "+g[3]+")"},y.to.rgb.percent=function(){var g=z(arguments),S=Math.round(g[0]/255*100),T=Math.round(g[1]/255*100),A=Math.round(g[2]/255*100);return g.length<4||g[3]===1?"rgb("+S+"%, "+T+"%, "+A+"%)":"rgba("+S+"%, "+T+"%, "+A+"%, "+g[3]+")"},y.to.hsl=function(){var g=z(arguments);return g.length<4||g[3]===1?"hsl("+g[0]+", "+g[1]+"%, "+g[2]+"%)":"hsla("+g[0]+", "+g[1]+"%, "+g[2]+"%, "+g[3]+")"},y.to.hwb=function(){var g=z(arguments),S="";return g.length>=4&&g[3]!==1&&(S=", "+g[3]),"hwb("+g[0]+", "+g[1]+"%, "+g[2]+"%"+S+")"},y.to.keyword=function(g){return lt[g.slice(0,3)]};function C(g,S,T){return Math.min(Math.max(S,g),T)}function w(g){var S=Math.round(g).toString(16).toUpperCase();return S.length<2?"0"+S:S}},767:(j,st,Y)=>{const K=Y(818),z=Y(85),D=["keyword","gray","hex"],lt={};for(const m of Object.keys(z))lt[[...z[m].labels].sort().join("")]=m;const b={};function y(m,M){if(!(this instanceof y))return new y(m,M);if(M&&M in D&&(M=null),M&&!(M in z))throw new Error("Unknown model: "+M);let E,I;if(m==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(m instanceof y)this.model=m.model,this.color=[...m.color],this.valpha=m.valpha;else if(typeof m=="string"){const R=K.get(m);if(R===null)throw new Error("Unable to parse color from string: "+m);this.model=R.model,I=z[this.model].channels,this.color=R.value.slice(0,I),this.valpha=typeof R.value[I]=="number"?R.value[I]:1}else if(m.length>0){this.model=M||"rgb",I=z[this.model].channels;const R=Array.prototype.slice.call(m,0,I);this.color=A(R,I),this.valpha=typeof m[I]=="number"?m[I]:1}else if(typeof m=="number")this.model="rgb",this.color=[m>>16&255,m>>8&255,m&255],this.valpha=1;else{this.valpha=1;const R=Object.keys(m);"alpha"in m&&(R.splice(R.indexOf("alpha"),1),this.valpha=typeof m.alpha=="number"?m.alpha:0);const at=R.sort().join("");if(!(at in lt))throw new Error("Unable to parse color from object: "+JSON.stringify(m));this.model=lt[at];const{labels:It}=z[this.model],Ft=[];for(E=0;E<It.length;E++)Ft.push(m[It[E]]);this.color=A(Ft)}if(b[this.model])for(I=z[this.model].channels,E=0;E<I;E++){const R=b[this.model][E];R&&(this.color[E]=R(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(m){let M=this.model in K.to?this:this.rgb();M=M.round(typeof m=="number"?m:1);const E=M.valpha===1?M.color:[...M.color,this.valpha];return K.to[M.model](E)},percentString(m){const M=this.rgb().round(typeof m=="number"?m:1),E=M.valpha===1?M.color:[...M.color,this.valpha];return K.to.rgb.percent(E)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const m={},{channels:M}=z[this.model],{labels:E}=z[this.model];for(let I=0;I<M;I++)m[E[I]]=this.color[I];return this.valpha!==1&&(m.alpha=this.valpha),m},unitArray(){const m=this.rgb().color;return m[0]/=255,m[1]/=255,m[2]/=255,this.valpha!==1&&m.push(this.valpha),m},unitObject(){const m=this.rgb().object();return m.r/=255,m.g/=255,m.b/=255,this.valpha!==1&&(m.alpha=this.valpha),m},round(m){return m=Math.max(m||0,0),new y([...this.color.map(w(m)),this.valpha],this.model)},alpha(m){return m!==void 0?new y([...this.color,Math.max(0,Math.min(1,m))],this.model):this.valpha},red:g("rgb",0,S(255)),green:g("rgb",1,S(255)),blue:g("rgb",2,S(255)),hue:g(["hsl","hsv","hsl","hwb","hcg"],0,m=>(m%360+360)%360),saturationl:g("hsl",1,S(100)),lightness:g("hsl",2,S(100)),saturationv:g("hsv",1,S(100)),value:g("hsv",2,S(100)),chroma:g("hcg",1,S(100)),gray:g("hcg",2,S(100)),white:g("hwb",1,S(100)),wblack:g("hwb",2,S(100)),cyan:g("cmyk",0,S(100)),magenta:g("cmyk",1,S(100)),yellow:g("cmyk",2,S(100)),black:g("cmyk",3,S(100)),x:g("xyz",0,S(95.047)),y:g("xyz",1,S(100)),z:g("xyz",2,S(108.833)),l:g("lab",0,S(100)),a:g("lab",1),b:g("lab",2),keyword(m){return m!==void 0?new y(m):z[this.model].keyword(this.color)},hex(m){return m!==void 0?new y(m):K.to.hex(this.rgb().round().color)},hexa(m){if(m!==void 0)return new y(m);const M=this.rgb().round().color;let E=Math.round(this.valpha*255).toString(16).toUpperCase();return E.length===1&&(E="0"+E),K.to.hex(M)+E},rgbNumber(){const m=this.rgb().color;return(m[0]&255)<<16|(m[1]&255)<<8|m[2]&255},luminosity(){const m=this.rgb().color,M=[];for(const[E,I]of m.entries()){const R=I/255;M[E]=R<=.04045?R/12.92:nt((R+.055)/1.055,2.4)}return .2126*M[0]+.7152*M[1]+.0722*M[2]},contrast(m){const M=this.luminosity(),E=m.luminosity();return M>E?(M+.05)/(E+.05):(E+.05)/(M+.05)},level(m){const M=this.contrast(m);return M>=7?"AAA":M>=4.5?"AA":""},isDark(){const m=this.rgb().color;return(m[0]*2126+m[1]*7152+m[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const m=this.rgb();for(let M=0;M<3;M++)m.color[M]=255-m.color[M];return m},lighten(m){const M=this.hsl();return M.color[2]+=M.color[2]*m,M},darken(m){const M=this.hsl();return M.color[2]-=M.color[2]*m,M},saturate(m){const M=this.hsl();return M.color[1]+=M.color[1]*m,M},desaturate(m){const M=this.hsl();return M.color[1]-=M.color[1]*m,M},whiten(m){const M=this.hwb();return M.color[1]+=M.color[1]*m,M},blacken(m){const M=this.hwb();return M.color[2]+=M.color[2]*m,M},grayscale(){const m=this.rgb().color,M=m[0]*.3+m[1]*.59+m[2]*.11;return y.rgb(M,M,M)},fade(m){return this.alpha(this.valpha-this.valpha*m)},opaquer(m){return this.alpha(this.valpha+this.valpha*m)},rotate(m){const M=this.hsl();let E=M.color[0];return E=(E+m)%360,E=E<0?360+E:E,M.color[0]=E,M},mix(m,M){if(!m||!m.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof m);const E=m.rgb(),I=this.rgb(),R=M===void 0?.5:M,at=2*R-1,It=E.alpha()-I.alpha(),Ft=((at*It===-1?at:(at+It)/(1+at*It))+1)/2,Be=1-Ft;return y.rgb(Ft*E.red()+Be*I.red(),Ft*E.green()+Be*I.green(),Ft*E.blue()+Be*I.blue(),E.alpha()*R+I.alpha()*(1-R))}};for(const m of Object.keys(z)){if(D.includes(m))continue;const{channels:M}=z[m];y.prototype[m]=function(...E){return this.model===m?new y(this):E.length>0?new y(E,m):new y([...T(z[this.model][m].raw(this.color)),this.valpha],m)},y[m]=function(...E){let I=E[0];return typeof I=="number"&&(I=A(E,M)),new y(I,m)}}function C(m,M){return Number(m.toFixed(M))}function w(m){return function(M){return C(M,m)}}function g(m,M,E){m=Array.isArray(m)?m:[m];for(const I of m)(b[I]||(b[I]=[]))[M]=E;return m=m[0],function(I){let R;return I!==void 0?(E&&(I=E(I)),R=this[m](),R.color[M]=I,R):(R=this[m]().color[M],E&&(R=E(R)),R)}}function S(m){return function(M){return Math.max(0,Math.min(m,M))}}function T(m){return Array.isArray(m)?m:[m]}function A(m,M){for(let E=0;E<M;E++)typeof m[E]!="number"&&(m[E]=0);return m}j.exports=y},171:j=>{j.exports=function(Y){return!Y||typeof Y=="string"?!1:Y instanceof Array||Array.isArray(Y)||Y.length>=0&&(Y.splice instanceof Function||Object.getOwnPropertyDescriptor(Y,Y.length-1)&&Y.constructor.name!=="String")}},851:(j,st,Y)=>{"use strict";var K=Y(171),z=Array.prototype.concat,D=Array.prototype.slice,lt=j.exports=function(y){for(var C=[],w=0,g=y.length;w<g;w++){var S=y[w];K(S)?C=z.call(C,D.call(S)):C.push(S)}return C};lt.wrap=function(b){return function(){return b(lt(arguments))}}}},un={};function _t(j){var st=un[j];if(st!==void 0)return st.exports;var Y=un[j]={exports:{}};return Go[j](Y,Y.exports,_t),Y.exports}_t.n=j=>{var st=j&&j.__esModule?()=>j.default:()=>j;return _t.d(st,{a:st}),st},_t.d=(j,st)=>{for(var Y in st)_t.o(st,Y)&&!_t.o(j,Y)&&Object.defineProperty(j,Y,{enumerable:!0,get:st[Y]})},_t.o=(j,st)=>Object.prototype.hasOwnProperty.call(j,st),_t.r=j=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(j,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(j,"__esModule",{value:!0})};var fs={};(()=>{"use strict";_t.r(fs),_t.d(fs,{Chart:()=>Xo,createChart:()=>np,generateCandlesData:()=>sp});function j(s){return typeof s=="function"}function st(s){return j(s==null?void 0:s.lift)}function Y(s){return function(t){if(st(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 K=function(s,t){return K=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])},K(s,t)};function z(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");K(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var D=function(){return D=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},D.apply(this,arguments)};function lt(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 b(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 C(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 g(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 T(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 m(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 M(){for(var s=[],t=0;t<arguments.length;t++)s=s.concat(m(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 I(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 R(s){return this instanceof R?(this.v=s,this):new R(s)}function at(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(f){return new Promise(function(p,v){r.push([u,f,p,v])>1||a(u,f)})})}function a(u,f){try{l(n[u](f))}catch(p){d(r[0][3],p)}}function l(u){u.value instanceof R?Promise.resolve(u.value.v).then(c,h):d(r[0][2],u)}function c(u){a("next",u)}function h(u){a("throw",u)}function d(u,f){u(f),r.shift(),r.length&&a(r[0][0],r[0][1])}}function It(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:R(s[i](o)),done:i==="return"}:r?r(o):o}:r}}function Ft(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 Be(s,t){return Object.defineProperty?Object.defineProperty(s,"raw",{value:t}):s.raw=t,s}var Zo=Object.create?function(s,t){Object.defineProperty(s,"default",{enumerable:!0,value:t})}:function(s,t){s.default=t};function ip(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 Zo(t,s),t}function rp(s){return s&&s.__esModule?s:{default:s}}function op(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 ap(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 lp(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 fn(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 gs=fn(function(s){return function(e){s(this),this.message=e?e.length+` errors occurred during unsubscription:
6
+ (()=>{var nt=Math.pow;(()=>{var Vo={168:(k,st,N)=>{const K=N(874),z={};for(const b of Object.keys(K))z[K[b]]=b;const L={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=L;for(const b of Object.keys(L)){if(!("channels"in L[b]))throw new Error("missing channels property: "+b);if(!("labels"in L[b]))throw new Error("missing channel labels property: "+b);if(L[b].labels.length!==L[b].channels)throw new Error("channel and label counts mismatch: "+b);const{channels:y,labels:C}=L[b];delete L[b].channels,delete L[b].labels,Object.defineProperty(L[b],"channels",{value:y}),Object.defineProperty(L[b],"labels",{value:C})}L.rgb.hsl=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(y,C,w),S=Math.max(y,C,w),T=S-g;let A,m;S===g?A=0:y===S?A=(C-w)/T:C===S?A=2+(w-y)/T:w===S&&(A=4+(y-C)/T),A=Math.min(A*60,360),A<0&&(A+=360);const M=(g+S)/2;return S===g?m=0:M<=.5?m=T/(S+g):m=T/(2-S-g),[A,m*100,M*100]},L.rgb.hsv=function(b){let y,C,w,g,S;const T=b[0]/255,A=b[1]/255,m=b[2]/255,M=Math.max(T,A,m),E=M-Math.min(T,A,m),I=function(F){return(M-F)/6/E+1/2};return E===0?(g=0,S=0):(S=E/M,y=I(T),C=I(A),w=I(m),T===M?g=w-C:A===M?g=.3333333333333333+y-w:m===M&&(g=.6666666666666666+C-y),g<0?g+=1:g>1&&(g-=1)),[g*360,S*100,M*100]},L.rgb.hwb=function(b){const y=b[0],C=b[1];let w=b[2];const g=L.rgb.hsl(b)[0],S=1/255*Math.min(y,Math.min(C,w));return w=1-.00392156862745098*Math.max(y,Math.max(C,w)),[g,S*100,w*100]},L.rgb.cmyk=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.min(1-y,1-C,1-w),S=(1-y-g)/(1-g)||0,T=(1-C-g)/(1-g)||0,A=(1-w-g)/(1-g)||0;return[S*100,T*100,A*100,g*100]};function ct(b,y){return nt(b[0]-y[0],2)+nt(b[1]-y[1],2)+nt(b[2]-y[2],2)}L.rgb.keyword=function(b){const y=z[b];if(y)return y;let C=1/0,w;for(const g of Object.keys(K)){const S=K[g],T=ct(b,S);T<C&&(C=T,w=g)}return w},L.keyword.rgb=function(b){return K[b]},L.rgb.xyz=function(b){let y=b[0]/255,C=b[1]/255,w=b[2]/255;y=y>.04045?nt((y+.055)/1.055,2.4):y/12.92,C=C>.04045?nt((C+.055)/1.055,2.4):C/12.92,w=w>.04045?nt((w+.055)/1.055,2.4):w/12.92;const g=y*.4124+C*.3576+w*.1805,S=y*.2126+C*.7152+w*.0722,T=y*.0193+C*.1192+w*.9505;return[g*100,S*100,T*100]},L.rgb.lab=function(b){const y=L.rgb.xyz(b);let C=y[0],w=y[1],g=y[2];C/=95.047,w/=100,g/=108.883,C=C>.008856?nt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?nt(w,.3333333333333333):7.787*w+.13793103448275862,g=g>.008856?nt(g,.3333333333333333):7.787*g+.13793103448275862;const S=116*w-16,T=500*(C-w),A=200*(w-g);return[S,T,A]},L.hsl.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;let g,S,T;if(C===0)return T=w*255,[T,T,T];w<.5?g=w*(1+C):g=w+C-w*C;const A=2*w-g,m=[0,0,0];for(let M=0;M<3;M++)S=y+.3333333333333333*-(M-1),S<0&&S++,S>1&&S--,6*S<1?T=A+(g-A)*6*S:2*S<1?T=g:3*S<2?T=A+(g-A)*(.6666666666666666-S)*6:T=A,m[M]=T*255;return m},L.hsl.hsv=function(b){const y=b[0];let C=b[1]/100,w=b[2]/100,g=C;const S=Math.max(w,.01);w*=2,C*=w<=1?w:2-w,g*=S<=1?S:2-S;const T=(w+C)/2,A=w===0?2*g/(S+g):2*C/(w+C);return[y,A*100,T*100]},L.hsv.rgb=function(b){const y=b[0]/60,C=b[1]/100;let w=b[2]/100;const g=Math.floor(y)%6,S=y-Math.floor(y),T=255*w*(1-C),A=255*w*(1-C*S),m=255*w*(1-C*(1-S));switch(w*=255,g){case 0:return[w,m,T];case 1:return[A,w,T];case 2:return[T,w,m];case 3:return[T,A,w];case 4:return[m,T,w];case 5:return[w,T,A]}},L.hsv.hsl=function(b){const y=b[0],C=b[1]/100,w=b[2]/100,g=Math.max(w,.01);let S,T;T=(2-C)*w;const A=(2-C)*g;return S=C*g,S/=A<=1?A:2-A,S=S||0,T/=2,[y,S*100,T*100]},L.hwb.rgb=function(b){const y=b[0]/360;let C=b[1]/100,w=b[2]/100;const g=C+w;let S;g>1&&(C/=g,w/=g);const T=Math.floor(6*y),A=1-w;S=6*y-T,T&1&&(S=1-S);const m=C+S*(A-C);let M,E,I;switch(T){default:case 6:case 0:M=A,E=m,I=C;break;case 1:M=m,E=A,I=C;break;case 2:M=C,E=A,I=m;break;case 3:M=C,E=m,I=A;break;case 4:M=m,E=C,I=A;break;case 5:M=A,E=C,I=m;break}return[M*255,E*255,I*255]},L.cmyk.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100,g=b[3]/100,S=1-Math.min(1,y*(1-g)+g),T=1-Math.min(1,C*(1-g)+g),A=1-Math.min(1,w*(1-g)+g);return[S*255,T*255,A*255]},L.xyz.rgb=function(b){const y=b[0]/100,C=b[1]/100,w=b[2]/100;let g,S,T;return g=y*3.2406+C*-1.5372+w*-.4986,S=y*-.9689+C*1.8758+w*.0415,T=y*.0557+C*-.204+w*1.057,g=g>.0031308?1.055*nt(g,.4166666666666667)-.055:g*12.92,S=S>.0031308?1.055*nt(S,.4166666666666667)-.055:S*12.92,T=T>.0031308?1.055*nt(T,.4166666666666667)-.055:T*12.92,g=Math.min(Math.max(0,g),1),S=Math.min(Math.max(0,S),1),T=Math.min(Math.max(0,T),1),[g*255,S*255,T*255]},L.xyz.lab=function(b){let y=b[0],C=b[1],w=b[2];y/=95.047,C/=100,w/=108.883,y=y>.008856?nt(y,.3333333333333333):7.787*y+.13793103448275862,C=C>.008856?nt(C,.3333333333333333):7.787*C+.13793103448275862,w=w>.008856?nt(w,.3333333333333333):7.787*w+.13793103448275862;const g=116*C-16,S=500*(y-C),T=200*(C-w);return[g,S,T]},L.lab.xyz=function(b){const y=b[0],C=b[1],w=b[2];let g,S,T;S=(y+16)/116,g=C/500+S,T=S-w/200;const A=nt(S,3),m=nt(g,3),M=nt(T,3);return S=A>.008856?A:(S-.13793103448275862)/7.787,g=m>.008856?m:(g-.13793103448275862)/7.787,T=M>.008856?M:(T-.13793103448275862)/7.787,g*=95.047,S*=100,T*=108.883,[g,S,T]},L.lab.lch=function(b){const y=b[0],C=b[1],w=b[2];let g;g=Math.atan2(w,C)*360/2/Math.PI,g<0&&(g+=360);const T=Math.sqrt(C*C+w*w);return[y,T,g]},L.lch.lab=function(b){const y=b[0],C=b[1],g=b[2]/360*2*Math.PI,S=C*Math.cos(g),T=C*Math.sin(g);return[y,S,T]},L.rgb.ansi16=function(b,y=null){const[C,w,g]=b;let S=y===null?L.rgb.hsv(b)[2]:y;if(S=Math.round(S/50),S===0)return 30;let T=30+(Math.round(g/255)<<2|Math.round(w/255)<<1|Math.round(C/255));return S===2&&(T+=60),T},L.hsv.ansi16=function(b){return L.rgb.ansi16(L.hsv.rgb(b),b[2])},L.rgb.ansi256=function(b){const y=b[0],C=b[1],w=b[2];return y===C&&C===w?y<8?16:y>248?231:Math.round((y-8)/247*24)+232:16+36*Math.round(y/255*5)+6*Math.round(C/255*5)+Math.round(w/255*5)},L.ansi16.rgb=function(b){let y=b%10;if(y===0||y===7)return b>50&&(y+=3.5),y=y/10.5*255,[y,y,y];const C=(~~(b>50)+1)*.5,w=(y&1)*C*255,g=(y>>1&1)*C*255,S=(y>>2&1)*C*255;return[w,g,S]},L.ansi256.rgb=function(b){if(b>=232){const S=(b-232)*10+8;return[S,S,S]}b-=16;let y;const C=Math.floor(b/36)/5*255,w=Math.floor((y=b%36)/6)/5*255,g=y%6/5*255;return[C,w,g]},L.rgb.hex=function(b){const C=(((Math.round(b[0])&255)<<16)+((Math.round(b[1])&255)<<8)+(Math.round(b[2])&255)).toString(16).toUpperCase();return"000000".substring(C.length)+C},L.hex.rgb=function(b){const y=b.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!y)return[0,0,0];let C=y[0];y[0].length===3&&(C=C.split("").map(A=>A+A).join(""));const w=parseInt(C,16),g=w>>16&255,S=w>>8&255,T=w&255;return[g,S,T]},L.rgb.hcg=function(b){const y=b[0]/255,C=b[1]/255,w=b[2]/255,g=Math.max(Math.max(y,C),w),S=Math.min(Math.min(y,C),w),T=g-S;let A,m;return T<1?A=S/(1-T):A=0,T<=0?m=0:g===y?m=(C-w)/T%6:g===C?m=2+(w-y)/T:m=4+(y-C)/T,m/=6,m%=1,[m*360,T*100,A*100]},L.hsl.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=C<.5?2*y*C:2*y*(1-C);let g=0;return w<1&&(g=(C-.5*w)/(1-w)),[b[0],w*100,g*100]},L.hsv.hcg=function(b){const y=b[1]/100,C=b[2]/100,w=y*C;let g=0;return w<1&&(g=(C-w)/(1-w)),[b[0],w*100,g*100]},L.hcg.rgb=function(b){const y=b[0]/360,C=b[1]/100,w=b[2]/100;if(C===0)return[w*255,w*255,w*255];const g=[0,0,0],S=y%1*6,T=S%1,A=1-T;let m=0;switch(Math.floor(S)){case 0:g[0]=1,g[1]=T,g[2]=0;break;case 1:g[0]=A,g[1]=1,g[2]=0;break;case 2:g[0]=0,g[1]=1,g[2]=T;break;case 3:g[0]=0,g[1]=A,g[2]=1;break;case 4:g[0]=T,g[1]=0,g[2]=1;break;default:g[0]=1,g[1]=0,g[2]=A}return m=(1-C)*w,[(C*g[0]+m)*255,(C*g[1]+m)*255,(C*g[2]+m)*255]},L.hcg.hsv=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);let g=0;return w>0&&(g=y/w),[b[0],g*100,w*100]},L.hcg.hsl=function(b){const y=b[1]/100,w=b[2]/100*(1-y)+.5*y;let g=0;return w>0&&w<.5?g=y/(2*w):w>=.5&&w<1&&(g=y/(2*(1-w))),[b[0],g*100,w*100]},L.hcg.hwb=function(b){const y=b[1]/100,C=b[2]/100,w=y+C*(1-y);return[b[0],(w-y)*100,(1-w)*100]},L.hwb.hcg=function(b){const y=b[1]/100,w=1-b[2]/100,g=w-y;let S=0;return g<1&&(S=(w-g)/(1-g)),[b[0],g*100,S*100]},L.apple.rgb=function(b){return[b[0]/65535*255,b[1]/65535*255,b[2]/65535*255]},L.rgb.apple=function(b){return[b[0]/255*65535,b[1]/255*65535,b[2]/255*65535]},L.gray.rgb=function(b){return[b[0]/100*255,b[0]/100*255,b[0]/100*255]},L.gray.hsl=function(b){return[0,0,b[0]]},L.gray.hsv=L.gray.hsl,L.gray.hwb=function(b){return[0,100,b[0]]},L.gray.cmyk=function(b){return[0,0,0,b[0]]},L.gray.lab=function(b){return[b[0],0,0]},L.gray.hex=function(b){const y=Math.round(b[0]/100*255)&255,w=((y<<16)+(y<<8)+y).toString(16).toUpperCase();return"000000".substring(w.length)+w},L.rgb.gray=function(b){return[(b[0]+b[1]+b[2])/3/255*100]}},85:(k,st,N)=>{const K=N(168),z=N(111),L={},ct=Object.keys(K);function b(C){const w=function(...g){const S=g[0];return S==null?S:(S.length>1&&(g=S),C(g))};return"conversion"in C&&(w.conversion=C.conversion),w}function y(C){const w=function(...g){const S=g[0];if(S==null)return S;S.length>1&&(g=S);const T=C(g);if(typeof T=="object")for(let A=T.length,m=0;m<A;m++)T[m]=Math.round(T[m]);return T};return"conversion"in C&&(w.conversion=C.conversion),w}ct.forEach(C=>{L[C]={},Object.defineProperty(L[C],"channels",{value:K[C].channels}),Object.defineProperty(L[C],"labels",{value:K[C].labels});const w=z(C);Object.keys(w).forEach(S=>{const T=w[S];L[C][S]=y(T),L[C][S].raw=b(T)})}),k.exports=L},111:(k,st,N)=>{const K=N(168);function z(){const y={},C=Object.keys(K);for(let w=C.length,g=0;g<w;g++)y[C[g]]={distance:-1,parent:null};return y}function L(y){const C=z(),w=[y];for(C[y].distance=0;w.length;){const g=w.pop(),S=Object.keys(K[g]);for(let T=S.length,A=0;A<T;A++){const m=S[A],M=C[m];M.distance===-1&&(M.distance=C[g].distance+1,M.parent=g,w.unshift(m))}}return C}function ct(y,C){return function(w){return C(y(w))}}function b(y,C){const w=[C[y].parent,y];let g=K[C[y].parent][y],S=C[y].parent;for(;C[S].parent;)w.unshift(C[S].parent),g=ct(K[C[S].parent][S],g),S=C[S].parent;return g.conversion=w,g}k.exports=function(y){const C=L(y),w={},g=Object.keys(C);for(let S=g.length,T=0;T<S;T++){const A=g[T];C[A].parent!==null&&(w[A]=b(A,C))}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,st,N)=>{var K=N(874),z=N(851),L=Object.hasOwnProperty,ct=Object.create(null);for(var b in K)L.call(K,b)&&(ct[K[b]]=b);var y=k.exports={to:{},get:{}};y.get=function(g){var S=g.substring(0,3).toLowerCase(),T,A;switch(S){case"hsl":T=y.get.hsl(g),A="hsl";break;case"hwb":T=y.get.hwb(g),A="hwb";break;default:T=y.get.rgb(g),A="rgb";break}return T?{model:A,value:T}:null},y.get.rgb=function(g){if(!g)return null;var S=/^#([a-f0-9]{3,4})$/i,T=/^#([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*)?\)$/,m=/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/,M=/^(\w+)$/,E=[0,0,0,1],I,F,at;if(I=g.match(T)){for(at=I[2],I=I[1],F=0;F<3;F++){var It=F*2;E[F]=parseInt(I.slice(It,It+2),16)}at&&(E[3]=parseInt(at,16)/255)}else if(I=g.match(S)){for(I=I[1],at=I[3],F=0;F<3;F++)E[F]=parseInt(I[F]+I[F],16);at&&(E[3]=parseInt(at+at,16)/255)}else if(I=g.match(A)){for(F=0;F<3;F++)E[F]=parseInt(I[F+1],0);I[4]&&(I[5]?E[3]=parseFloat(I[4])*.01:E[3]=parseFloat(I[4]))}else if(I=g.match(m)){for(F=0;F<3;F++)E[F]=Math.round(parseFloat(I[F+1])*2.55);I[4]&&(I[5]?E[3]=parseFloat(I[4])*.01:E[3]=parseFloat(I[4]))}else return(I=g.match(M))?I[1]==="transparent"?[0,0,0,0]:L.call(K,I[1])?(E=K[I[1]],E[3]=1,E):null:null;for(F=0;F<3;F++)E[F]=C(E[F],0,255);return E[3]=C(E[3],0,1),E},y.get.hsl=function(g){if(!g)return null;var S=/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,T=g.match(S);if(T){var A=parseFloat(T[4]),m=(parseFloat(T[1])%360+360)%360,M=C(parseFloat(T[2]),0,100),E=C(parseFloat(T[3]),0,100),I=C(isNaN(A)?1:A,0,1);return[m,M,E,I]}return null},y.get.hwb=function(g){if(!g)return null;var S=/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/,T=g.match(S);if(T){var A=parseFloat(T[4]),m=(parseFloat(T[1])%360+360)%360,M=C(parseFloat(T[2]),0,100),E=C(parseFloat(T[3]),0,100),I=C(isNaN(A)?1:A,0,1);return[m,M,E,I]}return null},y.to.hex=function(){var g=z(arguments);return"#"+w(g[0])+w(g[1])+w(g[2])+(g[3]<1?w(Math.round(g[3]*255)):"")},y.to.rgb=function(){var g=z(arguments);return g.length<4||g[3]===1?"rgb("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+")":"rgba("+Math.round(g[0])+", "+Math.round(g[1])+", "+Math.round(g[2])+", "+g[3]+")"},y.to.rgb.percent=function(){var g=z(arguments),S=Math.round(g[0]/255*100),T=Math.round(g[1]/255*100),A=Math.round(g[2]/255*100);return g.length<4||g[3]===1?"rgb("+S+"%, "+T+"%, "+A+"%)":"rgba("+S+"%, "+T+"%, "+A+"%, "+g[3]+")"},y.to.hsl=function(){var g=z(arguments);return g.length<4||g[3]===1?"hsl("+g[0]+", "+g[1]+"%, "+g[2]+"%)":"hsla("+g[0]+", "+g[1]+"%, "+g[2]+"%, "+g[3]+")"},y.to.hwb=function(){var g=z(arguments),S="";return g.length>=4&&g[3]!==1&&(S=", "+g[3]),"hwb("+g[0]+", "+g[1]+"%, "+g[2]+"%"+S+")"},y.to.keyword=function(g){return ct[g.slice(0,3)]};function C(g,S,T){return Math.min(Math.max(S,g),T)}function w(g){var S=Math.round(g).toString(16).toUpperCase();return S.length<2?"0"+S:S}},767:(k,st,N)=>{const K=N(818),z=N(85),L=["keyword","gray","hex"],ct={};for(const m of Object.keys(z))ct[[...z[m].labels].sort().join("")]=m;const b={};function y(m,M){if(!(this instanceof y))return new y(m,M);if(M&&M in L&&(M=null),M&&!(M in z))throw new Error("Unknown model: "+M);let E,I;if(m==null)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(m instanceof y)this.model=m.model,this.color=[...m.color],this.valpha=m.valpha;else if(typeof m=="string"){const F=K.get(m);if(F===null)throw new Error("Unable to parse color from string: "+m);this.model=F.model,I=z[this.model].channels,this.color=F.value.slice(0,I),this.valpha=typeof F.value[I]=="number"?F.value[I]:1}else if(m.length>0){this.model=M||"rgb",I=z[this.model].channels;const F=Array.prototype.slice.call(m,0,I);this.color=A(F,I),this.valpha=typeof m[I]=="number"?m[I]:1}else if(typeof m=="number")this.model="rgb",this.color=[m>>16&255,m>>8&255,m&255],this.valpha=1;else{this.valpha=1;const F=Object.keys(m);"alpha"in m&&(F.splice(F.indexOf("alpha"),1),this.valpha=typeof m.alpha=="number"?m.alpha:0);const at=F.sort().join("");if(!(at in ct))throw new Error("Unable to parse color from object: "+JSON.stringify(m));this.model=ct[at];const{labels:It}=z[this.model],Ft=[];for(E=0;E<It.length;E++)Ft.push(m[It[E]]);this.color=A(Ft)}if(b[this.model])for(I=z[this.model].channels,E=0;E<I;E++){const F=b[this.model][E];F&&(this.color[E]=F(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(m){let M=this.model in K.to?this:this.rgb();M=M.round(typeof m=="number"?m:1);const E=M.valpha===1?M.color:[...M.color,this.valpha];return K.to[M.model](E)},percentString(m){const M=this.rgb().round(typeof m=="number"?m:1),E=M.valpha===1?M.color:[...M.color,this.valpha];return K.to.rgb.percent(E)},array(){return this.valpha===1?[...this.color]:[...this.color,this.valpha]},object(){const m={},{channels:M}=z[this.model],{labels:E}=z[this.model];for(let I=0;I<M;I++)m[E[I]]=this.color[I];return this.valpha!==1&&(m.alpha=this.valpha),m},unitArray(){const m=this.rgb().color;return m[0]/=255,m[1]/=255,m[2]/=255,this.valpha!==1&&m.push(this.valpha),m},unitObject(){const m=this.rgb().object();return m.r/=255,m.g/=255,m.b/=255,this.valpha!==1&&(m.alpha=this.valpha),m},round(m){return m=Math.max(m||0,0),new y([...this.color.map(w(m)),this.valpha],this.model)},alpha(m){return m!==void 0?new y([...this.color,Math.max(0,Math.min(1,m))],this.model):this.valpha},red:g("rgb",0,S(255)),green:g("rgb",1,S(255)),blue:g("rgb",2,S(255)),hue:g(["hsl","hsv","hsl","hwb","hcg"],0,m=>(m%360+360)%360),saturationl:g("hsl",1,S(100)),lightness:g("hsl",2,S(100)),saturationv:g("hsv",1,S(100)),value:g("hsv",2,S(100)),chroma:g("hcg",1,S(100)),gray:g("hcg",2,S(100)),white:g("hwb",1,S(100)),wblack:g("hwb",2,S(100)),cyan:g("cmyk",0,S(100)),magenta:g("cmyk",1,S(100)),yellow:g("cmyk",2,S(100)),black:g("cmyk",3,S(100)),x:g("xyz",0,S(95.047)),y:g("xyz",1,S(100)),z:g("xyz",2,S(108.833)),l:g("lab",0,S(100)),a:g("lab",1),b:g("lab",2),keyword(m){return m!==void 0?new y(m):z[this.model].keyword(this.color)},hex(m){return m!==void 0?new y(m):K.to.hex(this.rgb().round().color)},hexa(m){if(m!==void 0)return new y(m);const M=this.rgb().round().color;let E=Math.round(this.valpha*255).toString(16).toUpperCase();return E.length===1&&(E="0"+E),K.to.hex(M)+E},rgbNumber(){const m=this.rgb().color;return(m[0]&255)<<16|(m[1]&255)<<8|m[2]&255},luminosity(){const m=this.rgb().color,M=[];for(const[E,I]of m.entries()){const F=I/255;M[E]=F<=.04045?F/12.92:nt((F+.055)/1.055,2.4)}return .2126*M[0]+.7152*M[1]+.0722*M[2]},contrast(m){const M=this.luminosity(),E=m.luminosity();return M>E?(M+.05)/(E+.05):(E+.05)/(M+.05)},level(m){const M=this.contrast(m);return M>=7?"AAA":M>=4.5?"AA":""},isDark(){const m=this.rgb().color;return(m[0]*2126+m[1]*7152+m[2]*722)/1e4<128},isLight(){return!this.isDark()},negate(){const m=this.rgb();for(let M=0;M<3;M++)m.color[M]=255-m.color[M];return m},lighten(m){const M=this.hsl();return M.color[2]+=M.color[2]*m,M},darken(m){const M=this.hsl();return M.color[2]-=M.color[2]*m,M},saturate(m){const M=this.hsl();return M.color[1]+=M.color[1]*m,M},desaturate(m){const M=this.hsl();return M.color[1]-=M.color[1]*m,M},whiten(m){const M=this.hwb();return M.color[1]+=M.color[1]*m,M},blacken(m){const M=this.hwb();return M.color[2]+=M.color[2]*m,M},grayscale(){const m=this.rgb().color,M=m[0]*.3+m[1]*.59+m[2]*.11;return y.rgb(M,M,M)},fade(m){return this.alpha(this.valpha-this.valpha*m)},opaquer(m){return this.alpha(this.valpha+this.valpha*m)},rotate(m){const M=this.hsl();let E=M.color[0];return E=(E+m)%360,E=E<0?360+E:E,M.color[0]=E,M},mix(m,M){if(!m||!m.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof m);const E=m.rgb(),I=this.rgb(),F=M===void 0?.5:M,at=2*F-1,It=E.alpha()-I.alpha(),Ft=((at*It===-1?at:(at+It)/(1+at*It))+1)/2,Be=1-Ft;return y.rgb(Ft*E.red()+Be*I.red(),Ft*E.green()+Be*I.green(),Ft*E.blue()+Be*I.blue(),E.alpha()*F+I.alpha()*(1-F))}};for(const m of Object.keys(z)){if(L.includes(m))continue;const{channels:M}=z[m];y.prototype[m]=function(...E){return this.model===m?new y(this):E.length>0?new y(E,m):new y([...T(z[this.model][m].raw(this.color)),this.valpha],m)},y[m]=function(...E){let I=E[0];return typeof I=="number"&&(I=A(E,M)),new y(I,m)}}function C(m,M){return Number(m.toFixed(M))}function w(m){return function(M){return C(M,m)}}function g(m,M,E){m=Array.isArray(m)?m:[m];for(const I of m)(b[I]||(b[I]=[]))[M]=E;return m=m[0],function(I){let F;return I!==void 0?(E&&(I=E(I)),F=this[m](),F.color[M]=I,F):(F=this[m]().color[M],E&&(F=E(F)),F)}}function S(m){return function(M){return Math.max(0,Math.min(m,M))}}function T(m){return Array.isArray(m)?m:[m]}function A(m,M){for(let E=0;E<M;E++)typeof m[E]!="number"&&(m[E]=0);return m}k.exports=y},171:k=>{k.exports=function(N){return!N||typeof N=="string"?!1:N instanceof Array||Array.isArray(N)||N.length>=0&&(N.splice instanceof Function||Object.getOwnPropertyDescriptor(N,N.length-1)&&N.constructor.name!=="String")}},851:(k,st,N)=>{"use strict";var K=N(171),z=Array.prototype.concat,L=Array.prototype.slice,ct=k.exports=function(y){for(var C=[],w=0,g=y.length;w<g;w++){var S=y[w];K(S)?C=z.call(C,L.call(S)):C.push(S)}return C};ct.wrap=function(b){return function(){return b(ct(arguments))}}}},un={};function _t(k){var st=un[k];if(st!==void 0)return st.exports;var N=un[k]={exports:{}};return Vo[k](N,N.exports,_t),N.exports}_t.n=k=>{var st=k&&k.__esModule?()=>k.default:()=>k;return _t.d(st,{a:st}),st},_t.d=(k,st)=>{for(var N in st)_t.o(st,N)&&!_t.o(k,N)&&Object.defineProperty(k,N,{enumerable:!0,get:st[N]})},_t.o=(k,st)=>Object.prototype.hasOwnProperty.call(k,st),_t.r=k=>{typeof Symbol!="undefined"&&Symbol.toStringTag&&Object.defineProperty(k,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(k,"__esModule",{value:!0})};var fs={};(()=>{"use strict";_t.r(fs),_t.d(fs,{Chart:()=>Yo,createChart:()=>op,generateCandlesData:()=>rp});function k(s){return typeof s=="function"}function st(s){return k(s==null?void 0:s.lift)}function N(s){return function(t){if(st(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 K=function(s,t){return K=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])},K(s,t)};function z(s,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");K(s,t);function e(){this.constructor=s}s.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}var L=function(){return L=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},L.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 b(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 C(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 g(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 T(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 m(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 M(){for(var s=[],t=0;t<arguments.length;t++)s=s.concat(m(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 I(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 F(s){return this instanceof F?(this.v=s,this):new F(s)}function at(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(f){return new Promise(function(p,v){r.push([u,f,p,v])>1||a(u,f)})})}function a(u,f){try{l(n[u](f))}catch(p){d(r[0][3],p)}}function l(u){u.value instanceof F?Promise.resolve(u.value.v).then(c,h):d(r[0][2],u)}function c(u){a("next",u)}function h(u){a("throw",u)}function d(u,f){u(f),r.shift(),r.length&&a(r[0][0],r[0][1])}}function It(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:F(s[i](o)),done:i==="return"}:r?r(o):o}:r}}function Ft(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 Be(s,t){return Object.defineProperty?Object.defineProperty(s,"raw",{value:t}):s.raw=t,s}var Uo=Object.create?function(s,t){Object.defineProperty(s,"default",{enumerable:!0,value:t})}:function(s,t){s.default=t};function ap(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 Uo(t,s),t}function lp(s){return s&&s.__esModule?s:{default:s}}function cp(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 hp(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 dp(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 fn(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 gs=fn(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 Re(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var ae=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(v){t={error:v}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(j(h))try{h()}catch(v){r=v instanceof gs?v.errors:[v]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=A(d),f=u.next();!f.done;f=u.next()){var p=f.value;try{mn(p)}catch(v){r=r!=null?r:[],v instanceof gs?r=I(I([],m(r)),m(v.errors)):r.push(v)}}}catch(v){n={error:v}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}if(r)throw new gs(r)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)mn(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)&&Re(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&Re(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}(),gn=ae.EMPTY;function pn(s){return s instanceof ae||s&&"closed"in s&&j(s.remove)&&j(s.add)&&j(s.unsubscribe)}function mn(s){j(s)?s():s.unsubscribe()}var $t={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Fe={setTimeout:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=Fe.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,I([s,t],m(e))):setTimeout.apply(void 0,I([s,t],m(e)))},clearTimeout:function(s){var t=Fe.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(s)},delegate:void 0};function vn(s){Fe.setTimeout(function(){var t=$t.onUnhandledError;if(t)t(s);else throw s})}function bn(){}var $o=function(){return ps("C",void 0,void 0)}();function Ko(s){return ps("E",void 0,s)}function qo(s){return ps("N",s,void 0)}function ps(s,t,e){return{kind:s,value:t,error:e}}var Kt=null;function He(s){if($t.useDeprecatedSynchronousErrorHandling){var t=!Kt;if(t&&(Kt={errorThrown:!1,error:null}),s(),t){var e=Kt,n=e.errorThrown,i=e.error;if(Kt=null,n)throw i}}else s()}function Jo(s){$t.useDeprecatedSynchronousErrorHandling&&Kt&&(Kt.errorThrown=!0,Kt.error=s)}var ms=function(s){z(t,s);function t(e){var n=s.call(this)||this;return n.isStopped=!1,e?(n.destination=e,pn(e)&&e.add(n)):n.destination=sa,n}return t.create=function(e,n,i){return new ve(e,n,i)},t.prototype.next=function(e){this.isStopped?bs(qo(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?bs(Ko(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?bs($o,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}(ae),Qo=Function.prototype.bind;function vs(s,t){return Qo.call(s,t)}var ta=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){ke(n)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){ke(n)}else ke(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){ke(e)}},s}(),ve=function(s){z(t,s);function t(e,n,i){var r=s.call(this)||this,o;if(j(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&&$t.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&vs(e.next,a),error:e.error&&vs(e.error,a),complete:e.complete&&vs(e.complete,a)}):o=e}return r.destination=new ta(o),r}return t}(ms);function ke(s){$t.useDeprecatedSynchronousErrorHandling?Jo(s):vn(s)}function ea(s){throw s}function bs(s,t){var e=$t.onStoppedNotification;e&&Fe.setTimeout(function(){return e(s,t)})}var sa={closed:!0,next:bn,error:ea,complete:bn};function mt(s,t,e,n,i){return new na(s,t,e,n,i)}var na=function(s){z(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}(ms);function ct(s,t){return Y(function(e,n){var i=0;e.subscribe(mt(n,function(r){n.next(s.call(t,r,i++))}))})}var Cn=function(s){return s&&typeof s.length=="number"&&typeof s!="function"};function yn(s){return j(s==null?void 0:s.then)}var Cs=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function le(s){return s}function cp(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return wn(s)}function wn(s){return s.length===0?le: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=ra(t)?t:new ve(t,e,n);return He(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=Sn(e),new e(function(i,r){var o=new ve({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[Cs]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return wn(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=Sn(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 Sn(s){var t;return(t=s!=null?s:$t.Promise)!==null&&t!==void 0?t:Promise}function ia(s){return s&&j(s.next)&&j(s.error)&&j(s.complete)}function ra(s){return s&&s instanceof ms||ia(s)&&pn(s)}function xn(s){return j(s[Cs])}function _n(s){return Symbol.asyncIterator&&j(s==null?void 0:s[Symbol.asyncIterator])}function Pn(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 oa(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Tn=oa();function Mn(s){return j(s==null?void 0:s[Tn])}function An(s){return at(this,arguments,function(){var e,n,i,r;return g(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,R(e.read())];case 3:return n=o.sent(),i=n.value,r=n.done,r?[4,R(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,R(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 En(s){return j(s==null?void 0:s.getReader)}function Dt(s){if(s instanceof pt)return s;if(s!=null){if(xn(s))return aa(s);if(Cn(s))return la(s);if(yn(s))return ca(s);if(_n(s))return In(s);if(Mn(s))return ha(s);if(En(s))return da(s)}throw Pn(s)}function aa(s){return new pt(function(t){var e=s[Cs]();if(j(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function la(s){return new pt(function(t){for(var e=0;e<s.length&&!t.closed;e++)t.next(s[e]);t.complete()})}function ca(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,vn)})}function ha(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 In(s){return new pt(function(t){ua(s,t).catch(function(e){return t.error(e)})})}function da(s){return In(An(s))}function ua(s,t){var e,n,i,r;return w(this,void 0,void 0,function(){var o,a;return g(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Ft(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 fa(s,t,e,n,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},f=function(v){return c<n?p(v):l.push(v)},p=function(v){r&&t.next(v),c++;var _=!1;Dt(e(v,h++)).subscribe(mt(t,function(P){i==null||i(P),r?f(P):t.next(P)},function(){_=!0},void 0,function(){if(_)try{c--;for(var P=function(){var L=l.shift();o?Ht(t,o,function(){return p(L)}):p(L)};l.length&&c<n;)P();u()}catch(L){t.error(L)}}))};return s.subscribe(mt(t,f,function(){d=!0,u()})),function(){a==null||a()}}function Dn(s,t,e){return e===void 0&&(e=1/0),j(t)?Dn(function(n,i){return ct(function(r,o){return t(n,r,i,o)})(Dt(s(n,i)))},e):(typeof t=="number"&&(e=t),Y(function(n,i){return fa(n,i,s,e)}))}function Ln(s){return s===void 0&&(s=1/0),Dn(le,s)}var On=new pt(function(s){return s.complete()});function hp(s){return s?ga(s):On}function ga(s){return new Observable(function(t){return s.schedule(function(){return t.complete()})})}function Bn(s){return s&&j(s.schedule)}function ys(s){return s[s.length-1]}function pa(s){return j(ys(s))?s.pop():void 0}function je(s){return Bn(ys(s))?s.pop():void 0}function ma(s,t){return typeof ys(s)=="number"?s.pop():t}function Rn(s,t){return t===void 0&&(t=0),Y(function(e,n){e.subscribe(mt(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 Fn(s,t){return t===void 0&&(t=0),Y(function(e,n){n.add(s.schedule(function(){return e.subscribe(n)},t))})}function va(s,t){return Dt(s).pipe(Fn(t),Rn(t))}function ba(s,t){return Dt(s).pipe(Fn(t),Rn(t))}function Ca(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 ya(s,t){return new pt(function(e){var n;return Ht(e,t,function(){n=s[Tn](),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 j(n==null?void 0:n.return)&&n.return()}})}function Hn(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 wa(s,t){return Hn(An(s),t)}function Sa(s,t){if(s!=null){if(xn(s))return va(s,t);if(Cn(s))return Ca(s,t);if(yn(s))return ba(s,t);if(_n(s))return Hn(s,t);if(Mn(s))return ya(s,t);if(En(s))return wa(s,t)}throw Pn(s)}function Ye(s,t){return t?Sa(s,t):Dt(s)}function vt(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=ma(s,1/0),i=s;return i.length?i.length===1?Dt(i[0]):Ln(n)(Ye(i,e)):On}var xa=fn(function(s){return function(){s(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),O=function(s){z(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 xa},t.prototype.next=function(e){var n=this;He(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;He(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;He(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 ae(function(){n.currentObservers=null,Re(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){z(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),ut=function(s){z(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);let ws=!1,Ss=0;const Ne=new Map,xs=new Map,jn=()=>{ws||(ws=!0,Ss=requestAnimationFrame(()=>{xs.forEach((s,t)=>{s(),xs.delete(t)}),Ne.forEach((s,t)=>{s(),Ne.delete(t)}),ws=!1}))},Yn=(s,t)=>{Ne.set(s,t),jn()},_a=s=>{Ne.delete(s)},be=(s,t)=>{xs.set(s,t),jn()};function bt(){const s=()=>Math.random().toString(16).slice(-4);return`${s()+s()}-${s()}-${s()}-${s()}-${s()+s()+s()}`}var Pa=Math.pow;const Xe=14,ze=[];for(let s=0;s<Xe+1;s++)ze.push(Pa(10,s));const _s=5e-13;class ht{static roundToNearest(t,e){return isFinite(t)?ht.isZero(t)?0:(t>0?t+=_s:t<0&&(t-=_s),ht.roundDecimal(Math.round(ht.roundDecimal(t/e))*e)):t}static roundUpToNearest(t,e){return ht.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(Xe,Xe-1-Math.floor(Math.log10(n)));for(let r=i;r>=0;r--){const o=Math.floor(ze[r]*n+.5);if(o<ze[Xe])return e*o/ze[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 ht.compare(t,0,_s)===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 Ta(s,t,e){const n=s/t;return n>=e||n<=1/e}function Ps(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 Ce(...s){for(const t of s)if(t!==void 0&&isFinite(t))return t;return NaN}const it=s=>~~s,Aa=s=>~~(s+1),ye=s=>~~(s+.5),Ea=(s,t)=>s>>t;class Ts{constructor(t,e){this.animationTimeLeft=0,this.onTickFunction=e,this.animationTime=t.duration,this.animationStartTime=Date.now(),this.animationInProgress=!0}tick(){var t;Date.now()>this.animationStartTime+this.animationTime&&(this.animationInProgress=!1),(t=this.onTickFunction)==null||t.call(this)}getProgress(){return Math.min((Date.now()-this.animationStartTime)/this.animationTime,1)}finishAnimation(){this.animationInProgress=!1,this.animationStartTime=0}}var Ia=_t(767),Lt=_t.n(Ia);class Da extends Ts{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=Lt().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.colorConfigs.forEach(t=>{if(t.initialAlpha===void 0||t.rgbColor===void 0)return;const e=t.initialAlpha*(t.type==="fading"?1-this.getProgress():this.getProgress());t.currentAnimationColor=t.rgbColor.alpha(e)})}getColor(t){var e,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#FFFFFF"}revert(){const t=Ps(Date.now()-this.animationStartTime,0,this.animationTime);this.animationStartTime=Date.now()-this.animationTime+t,this.colorConfigs.forEach(e=>{e.type=e.type==="fading"?"appearing":"fading"})}}class La extends Ts{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=Lt().rgb(i.startColor),i.rgbEndColor=Lt().rgb(i.endColor),i.currentAnimationColor=i.type==="appearing"?i.rgbStartColor:i.rgbEndColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{const e=1-this.animationTimeLeft/this.animationTime;!t.rgbStartColor||!t.rgbEndColor||(t.type==="fading"?t.currentAnimationColor=this.calculateTransitionColor(t.rgbEndColor,t.rgbStartColor,e):t.type==="appearing"&&(t.currentAnimationColor=this.calculateTransitionColor(t.rgbStartColor,t.rgbEndColor,e)))})}getColor(t){var e,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 Lt().rgb(i,r,o)}}class Oa extends Ts{constructor(t,e,n){var i;super(e,n),this.viewportModel=t,this.animationConfig=e,this.id=bt(),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 Ba=Object.defineProperty,Ra=Object.defineProperties,Fa=Object.getOwnPropertyDescriptors,Nn=Object.getOwnPropertySymbols,Ha=Object.prototype.hasOwnProperty,ka=Object.prototype.propertyIsEnumerable,Xn=(s,t,e)=>t in s?Ba(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ja=(s,t)=>{for(var e in t||(t={}))Ha.call(t,e)&&Xn(s,e,t[e]);if(Nn)for(var e of Nn(t))ka.call(t,e)&&Xn(s,e,t[e]);return s},Ya=(s,t)=>Ra(s,Fa(t));const zn=400,We="VIEWPORT_ANIMATION";class Na{constructor(t){this.animations={},this.animationInProgressSubject=new ut(!1),this.animFrameId=`canvas_animation_${bt()}`,this.eventBus=t}startViewportMovementAnimation(t,e,n=We,i){const r=new Oa(t,e,i);return this.animations[n]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,n,i){const r=new Da(Ya(ja({},i),{duration:i&&i.duration||zn}),e,n);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,n=zn,i){const r=new La({duration:n},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0)}processAnimation(){be(this.animFrameId,()=>this.tick())}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():queueMicrotask(()=>{this.processAnimation(),this.eventBus.fireDraw()})}stopInterval(){_a(this.animFrameId)}}function At(s,t){return t===void 0&&(t=le),s=s!=null?s:Xa,Y(function(e,n){var i,r=!0;e.subscribe(mt(n,function(o){var a=t(o);(r||!s(i,a))&&(r=!1,i=a,n.next(o))}))})}function Xa(s,t){return s===t}function za(s){return function(){s.forEach(e=>typeof e=="function"&&e()),s.length=0}}function Ms(s){return s}function Wn(s){return s!=null}const dp=()=>{};function up(s){return s!=null}function Wa(s,t,e=Va,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 Vn=(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})},Va=(s,t)=>s===t,fp=(s,t,e)=>s.filter(n=>t.filter(i=>e(n,i)).length===0),Ua=(s,t)=>s===t,Un=(s,t,e=Ua)=>s.length===t.length&&s.every((n,i)=>e(n,t[i]));function gp(s,t,e){const n=s.slice(),i=n[t];return n.splice(t,1),n.splice(e,0,i),n}function As(s,t,e){const n=s.length,i=Ps(t,0,n-1),r=Ps(e,0,n-1),o=s[i];return s.splice(i,1),s.splice(r,0,o),s}function pp(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 mp=s=>{const t={};return s.filter(e=>t[e]?!1:t[e]=!0)},vp=(s,t)=>s.reduce((e,n)=>((e[n[t]]=e[n[t]]||[]).push(n),e),{}),bp=(s,t)=>[].concat(...s.map(e=>[e,t])).slice(0,-1),Cp=s=>Array.isArray(s[0]),Gn=s=>Array.isArray(s[0])?s:[s],Ga=(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},Za=(s,t)=>s>=0?t[s]:t[t.length+s],Ct=s=>Array.prototype.flat?s.flat():we(s,Ms),we=(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 Ot(s,t,e){const n=e!=null?e:Ms;return!s.length||t!==t?{index:-1,exact:!0}:Es(s,t,0,s.length,n)}function Es(s,t,e,n,i){const r=Ea(e+n,1),o=i(s[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Es(s,t,e,r,i):Es(s,t,r,n,i)}function yt(s){if(s&&s.length)return s[s.length-1]}function $a(s){const t=this.indexOf(s);return t!==-1&&this.splice(t,1),this}function Ka(s,t){if(!s)return;const e=s.indexOf(t);e!==-1&&s.splice(e,1)}function ce(s){if(s)return s[0]}function qa(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 Ja(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 Is;const kt=()=>(Is||(Is=!!navigator.userAgent.match(/Android|iPhone|Opera Mini/)||!1),Is),Qa=1.33;function Zn(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 Ve(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)*Qa:parseInt(n,10)}function $n(s,t,e){s.save(),Zn(s,e);const n=Math.ceil(Math.max.apply(Math,t.map(o=>s.measureText(o).width))),i=Ve(s),r=i*t.length;return s.restore(),[n,r,i]}function Kn(s){return(s||"").split(/\r\n|\r|\n/)}function tl(s,t,e,n,i){s.save();const[r,,o]=$n(s,t,i);t.forEach((a,l)=>{var c,h,d;const u=s.measureText(a).width,f=el(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&sl(s,a,f,n+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),s.fillText(a,f,n+o*l)}),s.restore()}function el(s,t,e,n){switch(n){case"left":return s;case"right":return s+t-e;default:return s}}function sl(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 yp(s){return`${s}px`}function qt(s,t,e){const n=Lt().rgb(s).array(),i=n[0],r=n[1],o=n[2];return(i*299+r*587+o*114)/1e3<128?t:e}function nl(s,t,e,n){const i=n.components.navigationMap.timeLabels,r=i.padding,o=qn(t,i.dateFormat,e),a=Kn(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=$n(s,a,l);return[c+r.x*2,h+r.y*2]}function qn(s,t,e){return e(t)(s).split(" ").join(`
9
- `)}const Jn={};function jt(s,t){let e=Jn[s];return e!==void 0||(t.save(),t.font=s,e=t.measureText("M").width,Jn[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 Tt(s,t,e=ti){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 wp(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?Tt(s[o],i,{overrideExisting:!0,addIfMissing:!0}):s.splice(o,1,i)})}const ti={overrideExisting:!1,addIfMissing:!0};function il(s){let t=0;if(s.length===0)return t;for(let e=0;e<s.length;e++){const n=s.charCodeAt(e);t=(t<<5)-t+n,t|=0}return t}const Ds=1,rl=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),ei=(s,t)=>`${s}_${il(t.toString())}`;function Ue(s,t){return t===s?"none":t>s?"up":"down"}function ol(s,t){return t>s?"up":"down"}function al(s,t,e=!1){const{id:n,expansion:i,impVolatility:r,vwap:o,volume:a,timestamp:l}=s;let c=s.hi,h=s.lo,d=s.open;const u=s.close;e&&(c=u,h=u,d=u);let f=s.idx;return t!==void 0&&(f=t),{id:n,hi:c,lo:h,open:d,close:u,timestamp:l,volume:a,expansion:i,idx:f,impVolatility:r,vwap:o}}var ll=Object.defineProperty,si=Object.getOwnPropertySymbols,cl=Object.prototype.hasOwnProperty,hl=Object.prototype.propertyIsEnumerable,ni=(s,t,e)=>t in s?ll(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,dl=(s,t)=>{for(var e in t||(t={}))cl.call(t,e)&&ni(s,e,t[e]);if(si)for(var e of si(t))hl.call(t,e)&&ni(s,e,t[e]);return s};const ii="Open Sans Semibold, sans-serif",ul=null,fl=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Sp=s=>ul.find(t=>t===s)!==void 0,Ge=()=>({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},maxYAxisScalesAmount:10,applyBackgroundToAxes:{x:!0,y:!0},sortCandles:rl},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:ii,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:ii,cursor:"ew-resize",padding:{top:8,bottom:16},fontStyle:""},events:{visible:!1,eventsVisibility:{"conference-calls":!0,dividends:!0,splits:!0,earnings:!0},height:20,cursor:"default",xAxisLabelFormat:[{format:"d MMM"}],icons:{earnings:{normal:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" stroke="#D92C40" stroke-width="1.5"/></svg>',hover:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" fill="#D92C40" stroke="#D92C40" stroke-width="1.5"/></svg>'}}},offsets:{visible:!0,right:10,top:10,bottom:20,left:0},waterMark:{visible:!1,fontFamily:"Open Sans, sans-serif",firstRowFontSize:80,firstRowBottomPadding:10,secondRowFontSize:40,secondRowBottomPadding:25,thirdRowFontSize:40,thirdRowBottomPadding:15,position:"center",offsetX:20,offsetY:20,logoWidth:20,logoHeight:20},highLow:{visible:!1,font:"12px sans-serif",prefix:{high:"H: ",low:"L: "}},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(61,61,61,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)",normal:"rgba(217,44,64,1)",hover:"rgba(217,44,64,1)",line:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)",normal:"rgba(169,38,251,1)",hover:"rgba(169,38,251,1)",line:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)",normal:"rgba(244,187,63,1)",hover:"rgba(244,187,63,1)",line:"rgba(244,187,63,1)"},"conference-calls":{color:"rgba(48,194,97,1)",normal:"rgba(48,194,97,1)",hover:"rgba(48,194,97,1)",line:"rgba(48,194,97,1)"}},secondaryChartTheme:[{lineTheme:{upColor:"rgba(226,61,25,1)",downColor:"rgba(226,61,25,1)",noneColor:"rgba(226,61,25,1)"},areaTheme:{lineColor:"rgba(226,61,25,1)",startColor:"rgba(226,61,25,0.8)",stopColor:"rgba(226,61,25,0)"}},{lineTheme:{upColor:"rgba(250,191,64,1)",downColor:"rgba(250,191,64,1)",noneColor:"rgba(250,191,64,1)"},areaTheme:{lineColor:"rgba(250,191,64,1)",startColor:"rgba(250,191,64,0.8)",stopColor:"rgba(250,191,64,0)"}},{lineTheme:{upColor:"rgba(169,38,251,1)",downColor:"rgba(169,38,251,1)",noneColor:"rgba(169,38,251,1)"},areaTheme:{lineColor:"rgba(169,38,251,1)",startColor:"rgba(169,38,251,0.8)",stopColor:"rgba(169,38,251,0)"}},{lineTheme:{upColor:"rgba(77,211,240,1)",downColor:"rgba(77,211,240,1)",noneColor:"rgba(77,211,240,1)"},areaTheme:{lineColor:"rgba(77,211,240,1)",startColor:"rgba(77,211,240,0.8)",stopColor:"rgba(77,211,240,0)"}},{lineTheme:{upColor:"rgba(59,203,91,1)",downColor:"rgba(59,203,91,1)",noneColor:"rgba(59,203,91,1)"},areaTheme:{lineColor:"rgba(59,203,91,1)",startColor:"rgba(59,203,91,0.8)",stopColor:"rgba(59,203,91,0)"}}],yAxis:{backgroundColor:"rgba(20,20,19,1)",labelBoxColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)",labelInvertedTextColor:"rgba(20,20,19,1)",rectLabelTextColor:"rgba(255,255,255,1)",rectLabelInvertedTextColor:"rgba(20,20,19,1)",zeroPercentLine:"rgba(55,55,54,1)"},labels:{lastPrice:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(0,0,0,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},countdownToBarClose:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(255,255,255,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},highLow:{high:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"High"},low:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Low"}},bidAsk:{bid:{boxColor:"rgba(77,153,83,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Bid"},ask:{boxColor:"rgba(217,44,64,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Ask"}},prePostMarket:{post:{boxColor:"rgba(38,251,149,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Post"},pre:{boxColor:"rgba(255,170,0,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Pre"}},prevDayClose:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)"}},xAxis:{backgroundColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)"},navigationMap:{backgroundColor:"transparent",buttonColor:"rgba(255,255,255,0.1)",buttonArrowColor:"rgba(212,212,211,1)",knotColor:"rgba(255,255,255,0.1)",knotLineColor:"rgba(212,212,211,1)",sliderColor:"rgba(255,255,255,0.08)",knotBorderColor:"#0b0d1a",timeLabelsTextColor:"rgba(128,128,128,1)",mapColor:"rgba(255,255,255,0.1)",mapFillColor:"rgba(255,255,255,0.1)",mapGradientTopColor:"rgba(255,255,255,0.1)",mapGradientBottomColor:"rgba(255,255,255,0.1)"}},animation:{moveDuration:1e3,candleDuration:200,paneResizer:{bgMode:!0,enabled:!0,duration:40},yAxis:{background:{enabled:!1,duration:40}}},drawingOrder:["OVER_SERIES_CLEAR","MAIN_CLEAR","SERIES_CLEAR","GRID","X_AXIS","Y_AXIS","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function gl(s,t=Ge()){return Tt(s,t,ti),s}function xp(s,t=Ge()){const e=dl({},s);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function _p(s,t){Object.keys(s).forEach(e=>delete s[e]),Object.keys(t).forEach(e=>s[e]=t[e])}function ri(s){return typeof s=="object"&&s!==null}function oi(s,t){return[...s].map(n=>Ls(n,t))}const pl=s=>Array.isArray(s);function Ls(s,t){if(!ri(s))return s;if(pl(s))return oi(s,t);{const e=ai({},s,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(s)),e}}function ai(s,t,e){if(!ri(s))return e.overrideExisting?t:s;if(Array.isArray(s)&&Array.isArray(t)){const i=e.overrideExisting?t:s;return oi(i,e)}const n=Object.create(Object.getPrototypeOf(s));return Object.keys(s).forEach(i=>n[i]=Ls(s[i],e)),Object.keys(t).forEach(i=>{i in s?n[i]=ai(s[i],t[i],e):e.addIfMissing&&(n[i]=Ls(t[i],e))}),n}const Jt=s=>`${s.fontSize}px ${s.fontFamily}`;class ml{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 f=u.left.length;t[f]=Math.max((r=t[f])!=null?r:0,c),u.left.push(h)}else{const f=u.right.length;e[f]=Math.max((o=e[f])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var vl=Object.defineProperty,bl=Object.defineProperties,Cl=Object.getOwnPropertyDescriptors,li=Object.getOwnPropertySymbols,yl=Object.prototype.hasOwnProperty,wl=Object.prototype.propertyIsEnumerable,ci=(s,t,e)=>t in s?vl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Yt=(s,t)=>{for(var e in t||(t={}))yl.call(t,e)&&ci(s,e,t[e]);if(li)for(var e of li(t))wl.call(t,e)&&ci(s,e,t[e]);return s},hi=(s,t)=>bl(s,Cl(t));const q="CHART",Os=class{};let x=Os;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=Os.PANE_UUID(q),x.Y_AXIS=Os.PANE_UUID_Y_AXIS(q);const di={x:0,y:0,pageX:0,pageY:0,width:0,height:0},ui=20,fi=35,Bs=15,gi=1.5,pi=kt()?8*gi:8,Se=kt()?5:0,Sl=1e-6;class Rs{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={[q]: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 ml(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);As(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)<Sl?(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&&(As(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&&(As(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder))}reorderPanes(t){this.panesOrder=Vn(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===q){const[e]=mi(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Ka(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((H,B)=>H+B,0),h=r.right.reduce((H,B)=>H+B,0),d=0,u=i.width-h,f=d+c,p=0,v=i.width-c-h;let _=p;const P=this.panesOrder.findIndex(H=>this.graphsHeightRatio[H]>0);this.panesOrder.forEach((H,B)=>{var N;const W=this.graphsHeightRatio[this.panesOrder[B]],G=x.PANE_UUID_RESIZER(H),V=x.PANE_UUID(H),U=this.config.components.paneResizer.visible&&B>P&&W>0;U?he(this.bounds,G,0,_,i.width,n,this.canvasOnPageLocation):he(this.bounds,G,0,0,0,0,this.canvasOnPageLocation);const $=_+(U?n:0),Z=he(this.bounds,V,f,$,v,l*W-(U?n:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const et=this.yAxisBoundsContainer.extentsOrder.get(H);if(et===void 0)return;const tt=l*W-(U?n:0);let Q=f-((N=r.left[0])!=null?N:0),rt=u;et.left.forEach((dt,ot)=>{var xt;he(this.bounds,x.PANE_UUID_Y_AXIS(H,dt),Q,$,r.left[ot],tt,this.canvasOnPageLocation),Q-=(xt=r.left[ot+1])!=null?xt:0}),et.right.forEach((dt,ot)=>{he(this.bounds,x.PANE_UUID_Y_AXIS(H,dt),rt,$,r.right[ot],tt,this.canvasOnPageLocation),rt+=r.right[ot]})}else he(this.bounds,x.PANE_UUID_Y_AXIS(H),0,0,0,0,this.canvasOnPageLocation);_=Z.y+Z.height});const L=this.getBounds(x.ALL_PANES);L.x=f,L.y=p,L.width=v,L.height=_;const F=this.getBounds(x.CHART_WITH_Y_AXIS),k=this.getBounds(x.CHART);this.getEventsBounds(k),this.copyBounds(k,F),F.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=hi(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-fi,e.width=t.width,e.height=fi):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const n=this.getBounds(x.X_AXIS),i=this.yAxisWidths.left.length+this.yAxisWidths.right.length===1,r=i?0:this.yAxisWidths.left.reduce((a,l)=>a+=l,0),o=i?0:this.yAxisWidths.right.reduce((a,l)=>a+=l,0);if(this.config.components.xAxis.visible){const a=this.getXAxisHeight();n.x=r,n.y=e.height-a-t.height,n.width=e.width-o,n.height=a}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=jt(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)+Se}return this.xAxisHeight}setYAxisWidths(t){(!Un(this.yAxisWidths.left,t.left)||!Un(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[q];const e=[];e.push(...this.panesOrder.filter(p=>p!==q));const n=e.map(p=>this.graphsHeightRatio[p]===void 0?void 0:this.graphsHeightRatio[p]),i=n.filter(p=>p!==0),r=i.length,o=i.filter(p=>p!==void 0).length,a=n.filter(p=>p===void 0).length,l=a>0;let c=0,h=0,d=1,u=0;if(l&&([d,u]=mi(r)),(!this.graphsHeightRatio[q]||this.graphsHeightRatio[q]===0)&&(t=0),this.graphsHeightRatio[q]&&this.graphsHeightRatio[q]!==0)if(l)t=1*d;else{const p=Object.values(this.graphsHeightRatio).reduce((v,_)=>_+=v);p<1&&this.graphsHeightRatio[q]!==0&&(t+=1-p)}o===0&&(t=1-u*a),h=1-t-u*a,i.forEach(p=>{p&&(h-=p*d)}),c=h/(r||1);const f=n.map(p=>p===0?p:p?p*d+c:u+c);this._graphsHeightRatio={},this.graphsHeightRatio[q]=t,f.forEach((p,v)=>{const _=e[v];this.graphsHeightRatio[_]=p})}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=kt()?a*gi: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=tt=>nl(this.canvasModel.ctx,tt,this.formatterFactory,this.config)[0],f=Ct((i=(n=this.mainCandleSeries)==null?void 0:n.getSeriesInViewport())!=null?i:[]),p=d&&f.length?u(f[0].candle.timestamp):0,v=d&&f.length?u(f[f.length-1].candle.timestamp):0,_=Math.max(p,v);if(d){const tt=this.getBounds(x.N_MAP_LABEL_L);tt.x=r.x,tt.y=r.y,tt.width=_,tt.height=r.height;const Q=this.getBounds(x.N_MAP_LABEL_R);Q.x=r.x+r.width-_,Q.y=r.y,Q.width=_,Q.height=r.height}const P=this.getBounds(x.N_MAP_BTN_L);P.x=r.x+_,P.y=r.y,P.width=Bs,P.height=r.height;const L=this.getBounds(x.N_MAP_BTN_R);L.x=r.x+r.width-Bs-_,L.y=r.y,L.width=Bs,L.height=r.height;const F=P.x+P.width,k=L.x-F,H=F+k,B=this.config.components.navigationMap.minSliderWindowWidth,N=c!=null?c:pi,W=l!=null?l:r.height,G=N+B,V=this.getBounds(x.N_MAP_KNOT_L);V.x=F+k*this.leftRatio,V.x=Math.min(V.x,H-G),V.y=h,V.width=N,V.height=W;const U=this.getBounds(x.N_MAP_KNOT_R);U.x=F+k*this.rightRatio-pi,U.x=Math.max(U.x,F+G),U.y=h,U.width=N,U.height=W;const $=G-(U.x-V.x);$>0&&(V.x-=$);const Z=this.getBounds(x.N_MAP_SLIDER_WINDOW);Z.x=V.x+V.width,Z.y=r.y,Z.width=U.x-Z.x,Z.height=r.height;const et=this.getBounds(x.N_MAP_CHART);et.x=F,et.y=r.y,et.width=k,et.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(di),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>hi(Yt({},t),{[e]:this.bounds[x.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=Ze){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ze),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=Ze){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ze),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}isAllBoundsAvailable(){return Object.values(this.bounds).every(t=>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=ui,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 ut(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ct(n=>this.copyOf(n)),At((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(di,t)}setMainCandleSeries(t){this.mainCandleSeries=t}getEffectiveYAxisWidth(){return this.getBounds(x.PANE_UUID_Y_AXIS(q)).width}getEffectiveChartWidth(){return this.getBounds(x.PANE_UUID(q)).width}getEffectiveChartHeight(){return this.getBounds(x.PANE_UUID(q)).height}}const xl={0:1,1:.8,2:.6,3:.5,4:.4,5:.4,6:.4},mi=s=>{var t;const e=(t=xl[s])!=null?t:.4,n=(1-e)/s;return[e,n]},Pp=(s,t)=>s.x>t.x&&s.x<t.x+t.width&&s.y>t.y&&s.y<t.y+t.height,_l=(s,t)=>s>t.y&&s<t.y+t.height,he=(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},vi=(s,t)=>Math.min(Math.max(s,t.y),t.y+t.height),Ze={extensionX:0,extensionY:0,wholePage:!1},bi=(s,t)=>s.width===t.width&&s.height===t.height;var Pl=function(s){z(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}(ae),$e={setInterval:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=$e.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,I([s,t],m(e))):setInterval.apply(void 0,I([s,t],m(e)))},clearInterval:function(s){var t=$e.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(s)},delegate:void 0},Ci=function(s){z(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),$e.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&&$e.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,Re(r,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,s.prototype.unsubscribe.call(this)}},t}(Pl),xe={schedule:function(s){var t=requestAnimationFrame,e=cancelAnimationFrame,n=xe.delegate;n&&(t=n.requestAnimationFrame,e=n.cancelAnimationFrame);var i=t(function(r){e=void 0,s(r)});return new ae(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=xe.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,I([],m(s)))},cancelAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=xe.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,I([],m(s)))},delegate:void 0},Tl=function(s){z(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=xe.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&&(xe.cancelAnimationFrame(n),e._scheduled=void 0)},t}(Ci),Fs={now:function(){return(Fs.delegate||Date).now()},delegate:void 0},yi=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=Fs.now,s}(),wi=function(s){z(t,s);function t(e,n){n===void 0&&(n=yi.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}(yi),Ml=function(s){z(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}(wi),_e=new Ml(Tl),Tp=null,Si=new wi(Ci),Al=Si;function El(s,t){return Y(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,f=function(){d==null||d.unsubscribe(),d=null,l&&(_(),u&&n.complete())},p=function(){d=null,u&&n.complete()},v=function(P){return d=Dt(s(P)).subscribe(mt(n,f,p))},_=function(){if(c){c=!1;var P=h;h=null,n.next(P),!u&&v(P)}};e.subscribe(mt(n,function(P){c=!0,h=P,!(d&&!d.closed)&&(o?_():v(P))},function(){u=!0,!(l&&c&&d&&!d.closed)&&n.complete()}))})}function Il(s){return s instanceof Date&&!isNaN(s)}function Dl(s,t,e){s===void 0&&(s=0),e===void 0&&(e=Al);var n=-1;return t!=null&&(Bn(t)?e=t:n=t),new pt(function(i){var r=Il(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 Pe(s,t,e){t===void 0&&(t=Si);var n=Dl(s,t);return El(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 Ll 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(Pe(100,_e,{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=Rs.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(At())}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 Ol=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},Bl=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 Re(s,t){if(s){var e=s.indexOf(t);0<=e&&s.splice(e,1)}}var ae=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(v){t={error:v}}finally{try{l&&!l.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}else o.remove(this);var h=this.initialTeardown;if(k(h))try{h()}catch(v){r=v instanceof gs?v.errors:[v]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var u=A(d),f=u.next();!f.done;f=u.next()){var p=f.value;try{mn(p)}catch(v){r=r!=null?r:[],v instanceof gs?r=I(I([],m(r)),m(v.errors)):r.push(v)}}}catch(v){n={error:v}}finally{try{f&&!f.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}if(r)throw new gs(r)}},s.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)mn(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)&&Re(e,t)},s.prototype.remove=function(t){var e=this._finalizers;e&&Re(e,t),t instanceof s&&t._removeParent(this)},s.EMPTY=function(){var t=new s;return t.closed=!0,t}(),s}(),gn=ae.EMPTY;function pn(s){return s instanceof ae||s&&"closed"in s&&k(s.remove)&&k(s.add)&&k(s.unsubscribe)}function mn(s){k(s)?s():s.unsubscribe()}var Kt={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Fe={setTimeout:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=Fe.delegate;return i!=null&&i.setTimeout?i.setTimeout.apply(i,I([s,t],m(e))):setTimeout.apply(void 0,I([s,t],m(e)))},clearTimeout:function(s){var t=Fe.delegate;return((t==null?void 0:t.clearTimeout)||clearTimeout)(s)},delegate:void 0};function vn(s){Fe.setTimeout(function(){var t=Kt.onUnhandledError;if(t)t(s);else throw s})}function bn(){}var Go=function(){return ps("C",void 0,void 0)}();function Zo(s){return ps("E",void 0,s)}function $o(s){return ps("N",s,void 0)}function ps(s,t,e){return{kind:s,value:t,error:e}}var qt=null;function He(s){if(Kt.useDeprecatedSynchronousErrorHandling){var t=!qt;if(t&&(qt={errorThrown:!1,error:null}),s(),t){var e=qt,n=e.errorThrown,i=e.error;if(qt=null,n)throw i}}else s()}function Ko(s){Kt.useDeprecatedSynchronousErrorHandling&&qt&&(qt.errorThrown=!0,qt.error=s)}var ms=function(s){z(t,s);function t(e){var n=s.call(this)||this;return n.isStopped=!1,e?(n.destination=e,pn(e)&&e.add(n)):n.destination=ta,n}return t.create=function(e,n,i){return new ve(e,n,i)},t.prototype.next=function(e){this.isStopped?bs($o(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?bs(Zo(e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?bs(Go,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}(ae),qo=Function.prototype.bind;function vs(s,t){return qo.call(s,t)}var Jo=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){ke(n)}},s.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){ke(n)}else ke(t)},s.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){ke(e)}},s}(),ve=function(s){z(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&&Kt.useDeprecatedNextContext?(a=Object.create(e),a.unsubscribe=function(){return r.unsubscribe()},o={next:e.next&&vs(e.next,a),error:e.error&&vs(e.error,a),complete:e.complete&&vs(e.complete,a)}):o=e}return r.destination=new Jo(o),r}return t}(ms);function ke(s){Kt.useDeprecatedSynchronousErrorHandling?Ko(s):vn(s)}function Qo(s){throw s}function bs(s,t){var e=Kt.onStoppedNotification;e&&Fe.setTimeout(function(){return e(s,t)})}var ta={closed:!0,next:bn,error:Qo,complete:bn};function mt(s,t,e,n,i){return new ea(s,t,e,n,i)}var ea=function(s){z(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}(ms);function ht(s,t){return N(function(e,n){var i=0;e.subscribe(mt(n,function(r){n.next(s.call(t,r,i++))}))})}var Cn=function(s){return s&&typeof s.length=="number"&&typeof s!="function"};function yn(s){return k(s==null?void 0:s.then)}var Cs=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function le(s){return s}function up(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return wn(s)}function wn(s){return s.length===0?le: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=na(t)?t:new ve(t,e,n);return He(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=Sn(e),new e(function(i,r){var o=new ve({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[Cs]=function(){return this},s.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return wn(t)(this)},s.prototype.toPromise=function(t){var e=this;return t=Sn(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 Sn(s){var t;return(t=s!=null?s:Kt.Promise)!==null&&t!==void 0?t:Promise}function sa(s){return s&&k(s.next)&&k(s.error)&&k(s.complete)}function na(s){return s&&s instanceof ms||sa(s)&&pn(s)}function xn(s){return k(s[Cs])}function _n(s){return Symbol.asyncIterator&&k(s==null?void 0:s[Symbol.asyncIterator])}function Pn(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 ia(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Tn=ia();function Mn(s){return k(s==null?void 0:s[Tn])}function An(s){return at(this,arguments,function(){var e,n,i,r;return g(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,F(e.read())];case 3:return n=o.sent(),i=n.value,r=n.done,r?[4,F(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,F(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 En(s){return k(s==null?void 0:s.getReader)}function Dt(s){if(s instanceof pt)return s;if(s!=null){if(xn(s))return ra(s);if(Cn(s))return oa(s);if(yn(s))return aa(s);if(_n(s))return In(s);if(Mn(s))return la(s);if(En(s))return ca(s)}throw Pn(s)}function ra(s){return new pt(function(t){var e=s[Cs]();if(k(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function oa(s){return new pt(function(t){for(var e=0;e<s.length&&!t.closed;e++)t.next(s[e]);t.complete()})}function aa(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,vn)})}function la(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 In(s){return new pt(function(t){ha(s,t).catch(function(e){return t.error(e)})})}function ca(s){return In(An(s))}function ha(s,t){var e,n,i,r;return w(this,void 0,void 0,function(){var o,a;return g(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),e=Ft(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 da(s,t,e,n,i,r,o,a){var l=[],c=0,h=0,d=!1,u=function(){d&&!l.length&&!c&&t.complete()},f=function(v){return c<n?p(v):l.push(v)},p=function(v){r&&t.next(v),c++;var P=!1;Dt(e(v,h++)).subscribe(mt(t,function(_){i==null||i(_),r?f(_):t.next(_)},function(){P=!0},void 0,function(){if(P)try{c--;for(var _=function(){var D=l.shift();o?Ht(t,o,function(){return p(D)}):p(D)};l.length&&c<n;)_();u()}catch(D){t.error(D)}}))};return s.subscribe(mt(t,f,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)})(Dt(s(n,i)))},e):(typeof t=="number"&&(e=t),N(function(n,i){return da(n,i,s,e)}))}function Ln(s){return s===void 0&&(s=1/0),Dn(le,s)}var On=new pt(function(s){return s.complete()});function fp(s){return s?ua(s):On}function ua(s){return new Observable(function(t){return s.schedule(function(){return t.complete()})})}function Bn(s){return s&&k(s.schedule)}function ys(s){return s[s.length-1]}function fa(s){return k(ys(s))?s.pop():void 0}function je(s){return Bn(ys(s))?s.pop():void 0}function ga(s,t){return typeof ys(s)=="number"?s.pop():t}function Rn(s,t){return t===void 0&&(t=0),N(function(e,n){e.subscribe(mt(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 Fn(s,t){return t===void 0&&(t=0),N(function(e,n){n.add(s.schedule(function(){return e.subscribe(n)},t))})}function pa(s,t){return Dt(s).pipe(Fn(t),Rn(t))}function ma(s,t){return Dt(s).pipe(Fn(t),Rn(t))}function va(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 ba(s,t){return new pt(function(e){var n;return Ht(e,t,function(){n=s[Tn](),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 Hn(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 Hn(An(s),t)}function ya(s,t){if(s!=null){if(xn(s))return pa(s,t);if(Cn(s))return va(s,t);if(yn(s))return ma(s,t);if(_n(s))return Hn(s,t);if(Mn(s))return ba(s,t);if(En(s))return Ca(s,t)}throw Pn(s)}function Ye(s,t){return t?ya(s,t):Dt(s)}function vt(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=ga(s,1/0),i=s;return i.length?i.length===1?Dt(i[0]):Ln(n)(Ye(i,e)):On}var wa=fn(function(s){return function(){s(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),R=function(s){z(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 wa},t.prototype.next=function(e){var n=this;He(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;He(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;He(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 ae(function(){n.currentObservers=null,Re(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){z(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}(R),ut=function(s){z(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}(R);let ws=!1,Ss=0;const Ne=new Map,xs=new Map,jn=()=>{ws||(ws=!0,Ss=requestAnimationFrame(()=>{xs.forEach((s,t)=>{s(),xs.delete(t)}),Ne.forEach((s,t)=>{s(),Ne.delete(t)}),ws=!1}))},Yn=(s,t)=>{Ne.set(s,t),jn()},Sa=s=>{Ne.delete(s)},be=(s,t)=>{xs.set(s,t),jn()};function bt(){const s=()=>Math.random().toString(16).slice(-4);return`${s()+s()}-${s()}-${s()}-${s()}-${s()+s()+s()}`}var xa=Math.pow;const Xe=14,ze=[];for(let s=0;s<Xe+1;s++)ze.push(xa(10,s));const _s=5e-13;class dt{static roundToNearest(t,e){return isFinite(t)?dt.isZero(t)?0:(t>0?t+=_s:t<0&&(t-=_s),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(Xe,Xe-1-Math.floor(Math.log10(n)));for(let r=i;r>=0;r--){const o=Math.floor(ze[r]*n+.5);if(o<ze[Xe])return e*o/ze[r]}return Math.round(t)}static makeDecimal(t,e,n,i){if(!isFinite(t))return"";if(isFinite(t)){let r=t.toFixed(e);if(!i)return n?r.replace(".",n):r;if(n===i)throw new Error("Grouping symbol cannot be the same as decimal separator.");const o=r.split(".");let a=o[0];const l=o[1];return Math.abs(t)>=1e3&&(a=a.replace(RegExp("\\d(?=(\\d{3})+$)","g"),`$&${i}`)),l?(r=[a,l].join(n),r):a}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,_s)===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 _a(s,t,e){const n=s/t;return n>=e||n<=1/e}function Ps(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 Ce(...s){for(const t of s)if(t!==void 0&&isFinite(t))return t;return NaN}const it=s=>~~s,Ta=s=>~~(s+1),ye=s=>~~(s+.5),Ma=(s,t)=>s>>t;function gp(s){if(!Number.isFinite(s))throw new Error("Input must be a finite number.");const t=s.toString();return t.includes(".")?t.split(".")[1].length:0}class Ts{constructor(t,e){this.animationTimeLeft=0,this.onTickFunction=e,this.animationTime=t.duration,this.animationStartTime=Date.now(),this.animationInProgress=!0}tick(){var t;Date.now()>this.animationStartTime+this.animationTime&&(this.animationInProgress=!1),(t=this.onTickFunction)==null||t.call(this)}getProgress(){return Math.min((Date.now()-this.animationStartTime)/this.animationTime,1)}finishAnimation(){this.animationInProgress=!1,this.animationStartTime=0}}var Aa=_t(767),Lt=_t.n(Aa);class Ea extends Ts{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbColor=Lt().rgb(i.color),i.initialAlpha=i.rgbColor.valpha,i.currentAnimationColor=i.rgbColor})}tick(){super.tick(),this.colorConfigs.forEach(t=>{if(t.initialAlpha===void 0||t.rgbColor===void 0)return;const e=t.initialAlpha*(t.type==="fading"?1-this.getProgress():this.getProgress());t.currentAnimationColor=t.rgbColor.alpha(e)})}getColor(t){var e,n;return(n=(e=this.colorConfigs[t].currentAnimationColor)==null?void 0:e.toString())!=null?n:"#FFFFFF"}revert(){const t=Ps(Date.now()-this.animationStartTime,0,this.animationTime);this.animationStartTime=Date.now()-this.animationTime+t,this.colorConfigs.forEach(e=>{e.type=e.type==="fading"?"appearing":"fading"})}}class Ia extends Ts{constructor(t,e,n=()=>{}){super(t,n),this.colorConfigs=e,e.forEach(i=>{i.rgbStartColor=Lt().rgb(i.startColor),i.rgbEndColor=Lt().rgb(i.endColor),i.currentAnimationColor=i.type==="appearing"?i.rgbStartColor:i.rgbEndColor})}tick(){super.tick(),this.animationInProgress&&this.colorConfigs.forEach(t=>{const e=1-this.animationTimeLeft/this.animationTime;!t.rgbStartColor||!t.rgbEndColor||(t.type==="fading"?t.currentAnimationColor=this.calculateTransitionColor(t.rgbEndColor,t.rgbStartColor,e):t.type==="appearing"&&(t.currentAnimationColor=this.calculateTransitionColor(t.rgbStartColor,t.rgbEndColor,e)))})}getColor(t){var e,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 Lt().rgb(i,r,o)}}class Da extends Ts{constructor(t,e,n){var i;super(e,n),this.viewportModel=t,this.animationConfig=e,this.id=bt(),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 La=Object.defineProperty,Oa=Object.defineProperties,Ba=Object.getOwnPropertyDescriptors,Nn=Object.getOwnPropertySymbols,Ra=Object.prototype.hasOwnProperty,Fa=Object.prototype.propertyIsEnumerable,Xn=(s,t,e)=>t in s?La(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ha=(s,t)=>{for(var e in t||(t={}))Ra.call(t,e)&&Xn(s,e,t[e]);if(Nn)for(var e of Nn(t))Fa.call(t,e)&&Xn(s,e,t[e]);return s},ka=(s,t)=>Oa(s,Ba(t));const zn=400,We="VIEWPORT_ANIMATION";class ja{constructor(t){this.animations={},this.animationInProgressSubject=new ut(!1),this.animFrameId=`canvas_animation_${bt()}`,this.eventBus=t}startViewportMovementAnimation(t,e,n=We,i){const r=new Da(t,e,i);return this.animations[n]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,n,i){const r=new Ea(ka(Ha({},i),{duration:i&&i.duration||zn}),e,n);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,n=zn,i){const r=new Ia({duration:n},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0)}processAnimation(){be(this.animFrameId,()=>this.tick())}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():queueMicrotask(()=>{this.processAnimation(),this.eventBus.fireDraw()})}stopInterval(){Sa(this.animFrameId)}}function At(s,t){return t===void 0&&(t=le),s=s!=null?s:Ya,N(function(e,n){var i,r=!0;e.subscribe(mt(n,function(o){var a=t(o);(r||!s(i,a))&&(r=!1,i=a,n.next(o))}))})}function Ya(s,t){return s===t}function Na(s){return function(){s.forEach(e=>typeof e=="function"&&e()),s.length=0}}function Ms(s){return s}function Wn(s){return s!=null}const pp=()=>{};function mp(s){return s!=null}function Xa(s,t,e=za,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 Vn=(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})},za=(s,t)=>s===t,vp=(s,t,e)=>s.filter(n=>t.filter(i=>e(n,i)).length===0),Wa=(s,t)=>s===t,Un=(s,t,e=Wa)=>s.length===t.length&&s.every((n,i)=>e(n,t[i]));function bp(s,t,e){const n=s.slice(),i=n[t];return n.splice(t,1),n.splice(e,0,i),n}function As(s,t,e){const n=s.length,i=Ps(t,0,n-1),r=Ps(e,0,n-1),o=s[i];return s.splice(i,1),s.splice(r,0,o),s}function Cp(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 yp=s=>{const t={};return s.filter(e=>t[e]?!1:t[e]=!0)},wp=(s,t)=>s.reduce((e,n)=>((e[n[t]]=e[n[t]]||[]).push(n),e),{}),Sp=(s,t)=>[].concat(...s.map(e=>[e,t])).slice(0,-1),xp=s=>Array.isArray(s[0]),Gn=s=>Array.isArray(s[0])?s:[s],Va=(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},Ua=(s,t)=>s>=0?t[s]:t[t.length+s],Ct=s=>Array.prototype.flat?s.flat():we(s,Ms),we=(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 Ot(s,t,e){const n=e!=null?e:Ms;return!s.length||t!==t?{index:-1,exact:!0}:Es(s,t,0,s.length,n)}function Es(s,t,e,n,i){const r=Ma(e+n,1),o=i(s[r]);return t===o?{index:r,exact:!0}:e===r?{index:e,exact:!1}:t<o?Es(s,t,e,r,i):Es(s,t,r,n,i)}function yt(s){if(s&&s.length)return s[s.length-1]}function Ga(s){const t=this.indexOf(s);return t!==-1&&this.splice(t,1),this}function Za(s,t){if(!s)return;const e=s.indexOf(t);e!==-1&&s.splice(e,1)}function ce(s){if(s)return s[0]}function $a(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 Is;const kt=()=>(Is||(Is=!!navigator.userAgent.match(/Android|iPhone|Opera Mini/)||!1),Is),qa=1.33;function Zn(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 Ve(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)*qa:parseInt(n,10)}function $n(s,t,e){s.save(),Zn(s,e);const n=Math.ceil(Math.max.apply(Math,t.map(o=>s.measureText(o).width))),i=Ve(s),r=i*t.length;return s.restore(),[n,r,i]}function Kn(s){return(s||"").split(/\r\n|\r|\n/)}function Ja(s,t,e,n,i){s.save();const[r,,o]=$n(s,t,i);t.forEach((a,l)=>{var c,h,d;const u=s.measureText(a).width,f=Qa(e,r,u,(c=i.textAlign)!=null?c:"left");i.textStyle&&i.textStyle.underline&&tl(s,a,f,n+o*l,(h=i.textFill)!=null?h:"",(d=i.textSize)!=null?d:""),s.fillText(a,f,n+o*l)}),s.restore()}function Qa(s,t,e,n){switch(n){case"left":return s;case"right":return s+t-e;default:return s}}function tl(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 _p(s){return`${s}px`}function Jt(s,t,e){const n=Lt().rgb(s).array(),i=n[0],r=n[1],o=n[2];return(i*299+r*587+o*114)/1e3<128?t:e}function el(s,t,e,n){const i=n.components.navigationMap.timeLabels,r=i.padding,o=qn(t,i.dateFormat,e),a=Kn(o),l={textFontFamily:i.fontFamily,textSize:`${i.fontSize}px`},[c,h]=$n(s,a,l);return[c+r.x*2,h+r.y*2]}function qn(s,t,e){return e(t)(s).split(" ").join(`
9
+ `)}const Jn={};function jt(s,t){let e=Jn[s];return e!==void 0||(t.save(),t.font=s,e=t.measureText("M").width,Jn[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 Tt(s,t,e=ti){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 Pp(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?Tt(s[o],i,{overrideExisting:!0,addIfMissing:!0}):s.splice(o,1,i)})}const ti={overrideExisting:!1,addIfMissing:!0};function sl(s){let t=0;if(s.length===0)return t;for(let e=0;e<s.length;e++){const n=s.charCodeAt(e);t=(t<<5)-t+n,t|=0}return t}const Ds=1,nl=s=>s.slice().sort((t,e)=>t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1),ei=(s,t)=>`${s}_${sl(t.toString())}`;function Ue(s,t){return t===s?"none":t>s?"up":"down"}function il(s,t){return t>s?"up":"down"}function rl(s,t,e=!1){const{id:n,expansion:i,impVolatility:r,vwap:o,typicalPrice:a,volume:l,timestamp:c}=s;let h=s.hi,d=s.lo,u=s.open;const f=s.close;e&&(h=f,d=f,u=f);let p=s.idx;return t!==void 0&&(p=t),{id:n,hi:h,lo:d,open:u,close:f,timestamp:c,volume:l,expansion:i,idx:p,impVolatility:r,vwap:o,typicalPrice:a}}var ol=Object.defineProperty,si=Object.getOwnPropertySymbols,al=Object.prototype.hasOwnProperty,ll=Object.prototype.propertyIsEnumerable,ni=(s,t,e)=>t in s?ol(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,cl=(s,t)=>{for(var e in t||(t={}))al.call(t,e)&&ni(s,e,t[e]);if(si)for(var e of si(t))ll.call(t,e)&&ni(s,e,t[e]);return s};const ii="Open Sans Semibold, sans-serif",hl=null,dl=["candle","line","area","bar","scatterPlot","trend","hollow","histogram","baseline"],Tp=s=>hl.find(t=>t===s)!==void 0,Ge=()=>({devexpertsPromoLink:!0,useUTCTimeOverride:!1,shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],rtl:!1,intlFormatter:{decimalSeparator:".",thousandsSeparator:""},scale:{keepZoomXOnYAxisChange:!0,auto:!0,zoomToCursor:!1,lockPriceToBarRatio:!1,autoScaleOnCandles:!0,autoScaleDisableOnDrag:{enabled:!0,edgeAngle:Math.PI/15,yDiff:80},inverse:!1,zoomSensitivity:{wheel:.25},defaultViewportItems:100,disableAnimations:!1},timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,components:{chart:{type:"candle",showCandlesBorder:!0,showActiveCandlesBorder:!0,showWicks:!0,candleLineWidth:1,lineWidth:1,areaLineWidth:1,barLineWidth:1,minWidth:.5,minCandles:10,candlePaddingPercent:.25,highlightActiveCandle:!0,cursor:"default",selectedWidth:3,minCandlesOffset:2,defaultZoomCandleWidth:7,zoomStep:0,histogram:{barCapSize:1},maxYAxisScalesAmount:10,applyBackgroundToAxes:{x:!0,y:!0},sortCandles:nl},yAxis:{type:"regular",visible:!0,labelHeight:23,zeroPercentLine:!0,customScale:!0,customScaleDblClick:!0,align:"right",fontSize:12,fontFamily:ii,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:ii,cursor:"ew-resize",padding:{top:8,bottom:16},fontStyle:""},events:{visible:!1,eventsVisibility:{"conference-calls":!0,dividends:!0,splits:!0,earnings:!0},height:20,cursor:"default",xAxisLabelFormat:[{format:"d MMM"}],icons:{earnings:{normal:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" stroke="#D92C40" stroke-width="1.5"/></svg>',hover:'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.06066 6.5L6.5 1.06066L11.9393 6.5L6.5 11.9393L1.06066 6.5Z" fill="#D92C40" stroke="#D92C40" stroke-width="1.5"/></svg>'}}},offsets:{visible:!0,right:10,top:10,bottom:20,left:0},waterMark:{visible:!1,fontFamily:"Open Sans, sans-serif",firstRowFontSize:80,firstRowBottomPadding:10,secondRowFontSize:40,secondRowBottomPadding:25,thirdRowFontSize:40,thirdRowBottomPadding:15,position:"center",offsetX:20,offsetY:20,logoWidth:20,logoHeight:20},highLow:{visible:!1,font:"12px sans-serif",prefix:{high:"H: ",low:"L: "}},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(61,61,61,1)",bgColor:"rgba(20,20,19,1)",bgHoverColor:"rgba(55,55,54,0.6)"},events:{earnings:{color:"rgba(217,44,64,1)",normal:"rgba(217,44,64,1)",hover:"rgba(217,44,64,1)",line:"rgba(217,44,64,1)"},dividends:{color:"rgba(169,38,251,1)",normal:"rgba(169,38,251,1)",hover:"rgba(169,38,251,1)",line:"rgba(169,38,251,1)"},splits:{color:"rgba(244,187,63,1)",normal:"rgba(244,187,63,1)",hover:"rgba(244,187,63,1)",line:"rgba(244,187,63,1)"},"conference-calls":{color:"rgba(48,194,97,1)",normal:"rgba(48,194,97,1)",hover:"rgba(48,194,97,1)",line:"rgba(48,194,97,1)"}},secondaryChartTheme:[{lineTheme:{upColor:"rgba(226,61,25,1)",downColor:"rgba(226,61,25,1)",noneColor:"rgba(226,61,25,1)"},areaTheme:{lineColor:"rgba(226,61,25,1)",startColor:"rgba(226,61,25,0.8)",stopColor:"rgba(226,61,25,0)"}},{lineTheme:{upColor:"rgba(250,191,64,1)",downColor:"rgba(250,191,64,1)",noneColor:"rgba(250,191,64,1)"},areaTheme:{lineColor:"rgba(250,191,64,1)",startColor:"rgba(250,191,64,0.8)",stopColor:"rgba(250,191,64,0)"}},{lineTheme:{upColor:"rgba(169,38,251,1)",downColor:"rgba(169,38,251,1)",noneColor:"rgba(169,38,251,1)"},areaTheme:{lineColor:"rgba(169,38,251,1)",startColor:"rgba(169,38,251,0.8)",stopColor:"rgba(169,38,251,0)"}},{lineTheme:{upColor:"rgba(77,211,240,1)",downColor:"rgba(77,211,240,1)",noneColor:"rgba(77,211,240,1)"},areaTheme:{lineColor:"rgba(77,211,240,1)",startColor:"rgba(77,211,240,0.8)",stopColor:"rgba(77,211,240,0)"}},{lineTheme:{upColor:"rgba(59,203,91,1)",downColor:"rgba(59,203,91,1)",noneColor:"rgba(59,203,91,1)"},areaTheme:{lineColor:"rgba(59,203,91,1)",startColor:"rgba(59,203,91,0.8)",stopColor:"rgba(59,203,91,0)"}}],yAxis:{backgroundColor:"rgba(20,20,19,1)",labelBoxColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)",labelInvertedTextColor:"rgba(20,20,19,1)",rectLabelTextColor:"rgba(255,255,255,1)",rectLabelInvertedTextColor:"rgba(20,20,19,1)",zeroPercentLine:"rgba(55,55,54,1)"},labels:{lastPrice:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(0,0,0,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},countdownToBarClose:{textNegative:"rgba(255,255,255,1)",textPositive:"rgba(255,255,255,1)",textSelected:"rgba(255,255,255,1)",boxNegative:"rgba(217,44,64,1)",boxPositive:"rgba(77,153,83,1)",boxSelected:"rgba(255,255,255,1)"},highLow:{high:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"High"},low:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Low"}},bidAsk:{bid:{boxColor:"rgba(77,153,83,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Bid"},ask:{boxColor:"rgba(217,44,64,1)",textColor:"rgba(255,255,255,1)",descriptionText:"Ask"}},prePostMarket:{post:{boxColor:"rgba(38,251,149,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Post"},pre:{boxColor:"rgba(255,170,0,1)",textColor:"rgba(20,20,19,1)",descriptionText:"Pre"}},prevDayClose:{boxColor:"rgba(107,96,86,1)",textColor:"rgba(255,255,255,1)"}},xAxis:{backgroundColor:"rgba(20,20,19,1)",labelTextColor:"rgba(128,128,128,1)"},navigationMap:{backgroundColor:"transparent",buttonColor:"rgba(255,255,255,0.1)",buttonArrowColor:"rgba(212,212,211,1)",knotColor:"rgba(255,255,255,0.1)",knotLineColor:"rgba(212,212,211,1)",sliderColor:"rgba(255,255,255,0.08)",knotBorderColor:"#0b0d1a",timeLabelsTextColor:"rgba(128,128,128,1)",mapColor:"rgba(255,255,255,0.1)",mapFillColor:"rgba(255,255,255,0.1)",mapGradientTopColor:"rgba(255,255,255,0.1)",mapGradientBottomColor:"rgba(255,255,255,0.1)"}},animation:{moveDuration:1e3,candleDuration:200,paneResizer:{bgMode:!0,enabled:!0,duration:40},yAxis:{background:{enabled:!1,duration:40}}},drawingOrder:["OVER_SERIES_CLEAR","MAIN_CLEAR","SERIES_CLEAR","GRID","X_AXIS","Y_AXIS","DYNAMIC_OBJECTS","WATERMARK","N_MAP_CHART","EVENTS"]});function ul(s,t=Ge()){return Tt(s,t,ti),s}function Mp(s,t=Ge()){const e=cl({},s);return merge(e,t,DEFAULT_MERGE_OPTIONS),e}function Ap(s,t){Object.keys(s).forEach(e=>delete s[e]),Object.keys(t).forEach(e=>s[e]=t[e])}function ri(s){return typeof s=="object"&&s!==null}function oi(s,t){return[...s].map(n=>Ls(n,t))}const fl=s=>Array.isArray(s);function Ls(s,t){if(!ri(s))return s;if(fl(s))return oi(s,t);{const e=ai({},s,t);return Object.setPrototypeOf(e,Object.getPrototypeOf(s)),e}}function ai(s,t,e){if(!ri(s))return e.overrideExisting?t:s;if(Array.isArray(s)&&Array.isArray(t)){const i=e.overrideExisting?t:s;return oi(i,e)}const n=Object.create(Object.getPrototypeOf(s));return Object.keys(s).forEach(i=>n[i]=Ls(s[i],e)),Object.keys(t).forEach(i=>{i in s?n[i]=ai(s[i],t[i],e):e.addIfMissing&&(n[i]=Ls(t[i],e))}),n}const Qt=s=>`${s.fontSize}px ${s.fontFamily}`;class gl{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=Qt(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 f=u.left.length;t[f]=Math.max((r=t[f])!=null?r:0,c),u.left.push(h)}else{const f=u.right.length;e[f]=Math.max((o=e[f])!=null?o:0,c),u.right.push(h)}this.extentsOrder.set(d,u)}),{left:t,right:e}}}var pl=Object.defineProperty,ml=Object.defineProperties,vl=Object.getOwnPropertyDescriptors,li=Object.getOwnPropertySymbols,bl=Object.prototype.hasOwnProperty,Cl=Object.prototype.propertyIsEnumerable,ci=(s,t,e)=>t in s?pl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Yt=(s,t)=>{for(var e in t||(t={}))bl.call(t,e)&&ci(s,e,t[e]);if(li)for(var e of li(t))Cl.call(t,e)&&ci(s,e,t[e]);return s},hi=(s,t)=>ml(s,vl(t));const q="CHART",Os=class{};let x=Os;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=Os.PANE_UUID(q),x.Y_AXIS=Os.PANE_UUID_Y_AXIS(q);const di={x:0,y:0,pageX:0,pageY:0,width:0,height:0},ui=20,fi=35,Bs=15,gi=1.5,pi=kt()?8*gi:8,Se=kt()?5:0,yl=1e-6;class Rs{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 R,this.paneMovedSubject=new R,this.paneVisibilityChangedSubject=new R,this.xAxisHeight=void 0,this.yAxisWidths={right:[0],left:[0]},this.leftRatio=0,this.rightRatio=0,this.boundsChangedSubject=new R,this.barResizerChangedSubject=new R,this._graphsHeightRatio={[q]:1},this.graphsHeightRatioChangedSubject=new R,this.boundsChangedSubscriptions={},r.canvasResized.subscribe(o=>{let a=o;a||(a=this.canvasModel.canvas.getBoundingClientRect()),this.updateCanvasOnPageLocation(a),this.recalculateBounds()}),this.yAxisBoundsContainer=new gl(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);As(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)<yl?(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&&(As(this.panesOrder,e,e-1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}movePaneDown(t){const e=this.panesOrder.indexOf(t);e!==-1&&(As(this.panesOrder,e,e+1),this.recalculateBounds(),this.eventBus.fireDraw(),this.panesOrderChangedSubject.next(this.panesOrder),this.paneMovedSubject.next())}reorderPanes(t){this.panesOrder=Vn(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===q){const[e]=mi(this.panesOrder.length-1);this.graphsHeightRatio[t]=e}else delete this.graphsHeightRatio[t];this.recalculatePanesHeightRatios(),this.paneVisibilityChangedSubject.next()}removePaneBounds(t){Za(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((H,B)=>H+B,0),h=r.right.reduce((H,B)=>H+B,0),d=0,u=i.width-h,f=d+c,p=0,v=i.width-c-h;let P=p;const _=this.panesOrder.findIndex(H=>this.graphsHeightRatio[H]>0);this.panesOrder.forEach((H,B)=>{var Y;const W=this.graphsHeightRatio[this.panesOrder[B]],G=x.PANE_UUID_RESIZER(H),V=x.PANE_UUID(H),U=this.config.components.paneResizer.visible&&B>_&&W>0;U?he(this.bounds,G,0,P,i.width,n,this.canvasOnPageLocation):he(this.bounds,G,0,0,0,0,this.canvasOnPageLocation);const Z=P+(U?n:0),$=he(this.bounds,V,f,Z,v,l*W-(U?n:0),this.canvasOnPageLocation);if(this.config.components.yAxis.visible){const et=this.yAxisBoundsContainer.extentsOrder.get(H);if(et===void 0)return;const tt=l*W-(U?n:0);let Q=f-((Y=r.left[0])!=null?Y:0),rt=u;et.left.forEach((lt,ot)=>{var xt;he(this.bounds,x.PANE_UUID_Y_AXIS(H,lt),Q,Z,r.left[ot],tt,this.canvasOnPageLocation),Q-=(xt=r.left[ot+1])!=null?xt:0}),et.right.forEach((lt,ot)=>{he(this.bounds,x.PANE_UUID_Y_AXIS(H,lt),rt,Z,r.right[ot],tt,this.canvasOnPageLocation),rt+=r.right[ot]})}else he(this.bounds,x.PANE_UUID_Y_AXIS(H),0,0,0,0,this.canvasOnPageLocation);P=$.y+$.height});const D=this.getBounds(x.ALL_PANES);D.x=f,D.y=p,D.width=v,D.height=P;const O=this.getBounds(x.CHART_WITH_Y_AXIS),j=this.getBounds(x.CHART);this.getEventsBounds(j),this.copyBounds(j,O),O.width=i.width,this.recalculateNavigationMapElementBounds(),this.updateAllBoundsPageCoordinates(),this.notifyBoundsSubscribers()}updateCanvasOnPageLocation(t){this.canvasOnPageLocation=hi(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-fi,e.width=t.width,e.height=fi):this.applyDefaultBounds(e),e}getXAxisBounds(t,e){const n=this.getBounds(x.X_AXIS),i=this.yAxisWidths.left.length+this.yAxisWidths.right.length===1,r=i?0:this.yAxisWidths.left.reduce((a,l)=>a+=l,0),o=i?0:this.yAxisWidths.right.reduce((a,l)=>a+=l,0);if(this.config.components.xAxis.visible){const a=this.getXAxisHeight();n.x=r,n.y=e.height-a-t.height,n.width=e.width-o,n.height=a}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=jt(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)+Se}return this.xAxisHeight}setYAxisWidths(t){(!Un(this.yAxisWidths.left,t.left)||!Un(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[q];const e=[];e.push(...this.panesOrder.filter(p=>p!==q));const n=e.map(p=>this.graphsHeightRatio[p]===void 0?void 0:this.graphsHeightRatio[p]),i=n.filter(p=>p!==0),r=i.length,o=i.filter(p=>p!==void 0).length,a=n.filter(p=>p===void 0).length,l=a>0;let c=0,h=0,d=1,u=0;if(l&&([d,u]=mi(r)),(!this.graphsHeightRatio[q]||this.graphsHeightRatio[q]===0)&&(t=0),this.graphsHeightRatio[q]&&this.graphsHeightRatio[q]!==0)if(l)t=1*d;else{const p=Object.values(this.graphsHeightRatio).reduce((v,P)=>P+=v);p<1&&this.graphsHeightRatio[q]!==0&&(t+=1-p)}o===0&&(t=1-u*a),h=1-t-u*a,i.forEach(p=>{p&&(h-=p*d)}),c=h/(r||1);const f=n.map(p=>p===0?p:p?p*d+c:u+c);this._graphsHeightRatio={},this.graphsHeightRatio[q]=t,f.forEach((p,v)=>{const P=e[v];this.graphsHeightRatio[P]=p})}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=kt()?a*gi: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=tt=>el(this.canvasModel.ctx,tt,this.formatterFactory,this.config)[0],f=Ct((i=(n=this.mainCandleSeries)==null?void 0:n.getSeriesInViewport())!=null?i:[]),p=d&&f.length?u(f[0].candle.timestamp):0,v=d&&f.length?u(f[f.length-1].candle.timestamp):0,P=Math.max(p,v);if(d){const tt=this.getBounds(x.N_MAP_LABEL_L);tt.x=r.x,tt.y=r.y,tt.width=P,tt.height=r.height;const Q=this.getBounds(x.N_MAP_LABEL_R);Q.x=r.x+r.width-P,Q.y=r.y,Q.width=P,Q.height=r.height}const _=this.getBounds(x.N_MAP_BTN_L);_.x=r.x+P,_.y=r.y,_.width=Bs,_.height=r.height;const D=this.getBounds(x.N_MAP_BTN_R);D.x=r.x+r.width-Bs-P,D.y=r.y,D.width=Bs,D.height=r.height;const O=_.x+_.width,j=D.x-O,H=O+j,B=this.config.components.navigationMap.minSliderWindowWidth,Y=c!=null?c:pi,W=l!=null?l:r.height,G=Y+B,V=this.getBounds(x.N_MAP_KNOT_L);V.x=O+j*this.leftRatio,V.x=Math.min(V.x,H-G),V.y=h,V.width=Y,V.height=W;const U=this.getBounds(x.N_MAP_KNOT_R);U.x=O+j*this.rightRatio-pi,U.x=Math.max(U.x,O+G),U.y=h,U.width=Y,U.height=W;const Z=G-(U.x-V.x);Z>0&&(V.x-=Z);const $=this.getBounds(x.N_MAP_SLIDER_WINDOW);$.x=V.x+V.width,$.y=r.y,$.width=U.x-$.x,$.height=r.height;const et=this.getBounds(x.N_MAP_CHART);et.x=O,et.y=r.y,et.width=j,et.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(di),this.bounds[t]=e),e}getCanvasOnPageLocation(){return this.canvasOnPageLocation}getBoundsPanes(){return this.panesOrder.reduce((t,e)=>hi(Yt({},t),{[e]:this.bounds[x.PANE_UUID(e)]}),{})}getBoundsHitTest(t,e=Ze){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ze),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=Ze){const{extensionX:n,extensionY:i,wholePage:r}=Yt(Yt({},Ze),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}isAllBoundsAvailable(){return Object.values(this.bounds).every(t=>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=ui,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 ut(this.getBounds(t)),this.boundsChangedSubscriptions[t]=e),e.pipe(ht(n=>this.copyOf(n)),At((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(di,t)}setMainCandleSeries(t){this.mainCandleSeries=t}getEffectiveYAxisWidth(){return this.getBounds(x.PANE_UUID_Y_AXIS(q)).width}getEffectiveChartWidth(){return this.getBounds(x.PANE_UUID(q)).width}getEffectiveChartHeight(){return this.getBounds(x.PANE_UUID(q)).height}}const wl={0:1,1:.8,2:.6,3:.5,4:.4,5:.4,6:.4},mi=s=>{var t;const e=(t=wl[s])!=null?t:.4,n=(1-e)/s;return[e,n]},Ep=(s,t)=>s.x>t.x&&s.x<t.x+t.width&&s.y>t.y&&s.y<t.y+t.height,Sl=(s,t)=>s>t.y&&s<t.y+t.height,he=(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},vi=(s,t)=>Math.min(Math.max(s,t.y),t.y+t.height),Ze={extensionX:0,extensionY:0,wholePage:!1},bi=(s,t)=>s.width===t.width&&s.height===t.height;var xl=function(s){z(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}(ae),$e={setInterval:function(s,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];var i=$e.delegate;return i!=null&&i.setInterval?i.setInterval.apply(i,I([s,t],m(e))):setInterval.apply(void 0,I([s,t],m(e)))},clearInterval:function(s){var t=$e.delegate;return((t==null?void 0:t.clearInterval)||clearInterval)(s)},delegate:void 0},Ci=function(s){z(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),$e.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&&$e.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,Re(r,this),n!=null&&(this.id=this.recycleAsyncId(i,n,null)),this.delay=null,s.prototype.unsubscribe.call(this)}},t}(xl),xe={schedule:function(s){var t=requestAnimationFrame,e=cancelAnimationFrame,n=xe.delegate;n&&(t=n.requestAnimationFrame,e=n.cancelAnimationFrame);var i=t(function(r){e=void 0,s(r)});return new ae(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=xe.delegate;return((e==null?void 0:e.requestAnimationFrame)||requestAnimationFrame).apply(void 0,I([],m(s)))},cancelAnimationFrame:function(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=xe.delegate;return((e==null?void 0:e.cancelAnimationFrame)||cancelAnimationFrame).apply(void 0,I([],m(s)))},delegate:void 0},_l=function(s){z(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=xe.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&&(xe.cancelAnimationFrame(n),e._scheduled=void 0)},t}(Ci),Fs={now:function(){return(Fs.delegate||Date).now()},delegate:void 0},yi=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=Fs.now,s}(),wi=function(s){z(t,s);function t(e,n){n===void 0&&(n=yi.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}(yi),Pl=function(s){z(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}(wi),_e=new Pl(_l),Ip=null,Si=new wi(Ci),Tl=Si;function Ml(s,t){return N(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,f=function(){d==null||d.unsubscribe(),d=null,l&&(P(),u&&n.complete())},p=function(){d=null,u&&n.complete()},v=function(_){return d=Dt(s(_)).subscribe(mt(n,f,p))},P=function(){if(c){c=!1;var _=h;h=null,n.next(_),!u&&v(_)}};e.subscribe(mt(n,function(_){c=!0,h=_,!(d&&!d.closed)&&(o?P():v(_))},function(){u=!0,!(l&&c&&d&&!d.closed)&&n.complete()}))})}function Al(s){return s instanceof Date&&!isNaN(s)}function El(s,t,e){s===void 0&&(s=0),e===void 0&&(e=Tl);var n=-1;return t!=null&&(Bn(t)?e=t:n=t),new pt(function(i){var r=Al(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 Pe(s,t,e){t===void 0&&(t=Si);var n=El(s,t);return Ml(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 Il 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 R}doActivate(){super.doActivate(),this.canvasInputListener.observeMouseMoveNoDrag().pipe(Pe(100,_e,{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=Rs.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(At())}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 Dl=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},Ll=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
12
  <canvas data-element="snapshotCanvas"></canvas>
@@ -21,4 +21,4 @@ ${s?` <p style="position: absolute; visibility: hidden;">If you have any sugge
21
21
  `:""} </div>
22
22
  </div>
23
23
  </div>
24
- `;function Rl(s){const t=document.createElement("template");return t.innerHTML=Bl(s.devexpertsPromoLink),t}function Fl(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}),Ol(t))return t;throw new Error("Some chart elements are missing")}function Hl(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 Te=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=ce(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=yt(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:it((s-l)/n),exact:!0}:{index:-1,exact:!0}:Ot(e,s,h=>h.timestamp)},xi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},_i={paintConfig:[xi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var kl=Object.defineProperty,Pi=Object.getOwnPropertySymbols,jl=Object.prototype.hasOwnProperty,Yl=Object.prototype.propertyIsEnumerable,Ti=(s,t,e)=>t in s?kl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Nl=(s,t)=>{for(var e in t||(t={}))jl.call(t,e)&&Ti(s,e,t[e]);if(Pi)for(var e of Pi(t))Yl.call(t,e)&&Ti(s,e,t[e]);return s};class Xl{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:[Nl({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:xi).color;return{textColor:qt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function zl(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)=>Wl(a,l,e)).filter(Wn).sort(Vl),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 Wl=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,Vl=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var Ul=Object.defineProperty,Gl=Object.defineProperties,Zl=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,$l=Object.prototype.hasOwnProperty,Kl=Object.prototype.propertyIsEnumerable,Ai=(s,t,e)=>t in s?Ul(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ei=(s,t)=>{for(var e in t||(t={}))$l.call(t,e)&&Ai(s,e,t[e]);if(Mi)for(var e of Mi(t))Kl.call(t,e)&&Ai(s,e,t[e]);return s},Ii=(s,t)=>Gl(s,Zl(t));const Qt={MAIN:"MAIN"};class ql extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new O,this.animFrameId=`anim_cache_${bt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,vt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),be(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=Ct(Object.values(i).map(l=>l.getUnorderedLabels())),o=Ct(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=zl(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 Ii(Ei({},t),{labels:t.labels.map((n,i)=>Ii(Ei({},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()}}let Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Hs=()=>{Ke.removeEventListener("change",Hs),Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),Ke.addEventListener("change",Hs)};Ke.addEventListener("change",Hs);const Jl=()=>Bt,Mp=s=>round(Bt*s)/Bt,Mt=s=>it(Bt*s)/Bt,ks=s=>Aa(Bt*s)/Bt,te=s=>JSON.parse(JSON.stringify(s));function js(s){return Object.entries(s)}const Di=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Li(s){return Object.keys(s)}function Oi(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])||!Oi(s[e[i]],t[e[i]]))return!1;return!0}const Ap=s=>Object.keys(s).length===0&&s.constructor===Object;function Bi(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,f=0,p=!1,v=!1,_=function(){d==null||d.unsubscribe(),d=void 0},P=function(){_(),h=u=void 0,p=v=!1},L=function(){var F=h;P(),F==null||F.unsubscribe()};return Y(function(F,k){f++,!v&&!p&&_();var H=u=u!=null?u:e();k.add(function(){f--,f===0&&!v&&!p&&(d=Ys(L,l))}),H.subscribe(k),!h&&f>0&&(h=new ve({next:function(B){return H.next(B)},error:function(B){v=!0,_(),d=Ys(P,i,B),H.error(B)},complete:function(){p=!0,_(),d=Ys(P,o),H.complete()}}),Dt(F).subscribe(h))})(c)}}function Ys(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 ve({next:function(){i.unsubscribe(),s()}});return Dt(t.apply(void 0,I([],m(e)))).subscribe(i)}}const qe=(s,t)=>s/t,ft=(s,t)=>s/t,Nt=(s,t)=>s*t,Ri=(s,t)=>(s-t)*100/t,Fi=(s,t)=>s*t/100+t,Hi=s=>Math.log2(s),Ns=s=>Math.pow(2,s);class Ql 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(ct(()=>({start:this.xStart,end:this.xEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.yChanged=this.changed.pipe(ct(()=>({start:this.yStart,end:this.yEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ft(t-this.xStart,this.zoomX)}xPixels(t){return ft(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ft(t-this.yStart,this.zoomY):e.y+e.height-ft(t-this.yStart,this.zoomY)}yPixels(t){return ft(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Nt(e+ft(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Nt(n+ft(this.yStart,this.zoomY),this.zoomY):Nt(e.height-n+ft(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 qe(e-t,this.getBounds().width)}calculateZoomY(t,e){return qe(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(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const tc=(s,t)=>!Li(s).some(e=>s[e]!==t[e]);class ec{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(Ot(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Ot(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class ki{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 ec(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ri(t,n);case"logarithmic":return t<=0?t:Hi(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 Fi(t,this.getBaseline());case"logarithmic":return Ns(t);case"regular":return t}}}var sc=Object.defineProperty,nc=Object.defineProperties,ic=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,rc=Object.prototype.hasOwnProperty,oc=Object.prototype.propertyIsEnumerable,Yi=(s,t,e)=>t in s?sc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ni=(s,t)=>{for(var e in t||(t={}))rc.call(t,e)&&Yi(s,e,t[e]);if(ji)for(var e of ji(t))oc.call(t,e)&&Yi(s,e,t[e]);return s},ac=(s,t)=>nc(s,ic(t));class Me{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Me(this.centerUnit,this.close)}}class Xi extends X{constructor(t,e,n,i,r=te(_i)){var o;super(),this.extentComponent=t,this.id=e,this.htId=n,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=a=>{var l;return(l=this.config.paintConfig[a])!=null?l:this.config.paintConfig[0]},this.getBaseline=(a=this.dataIdxStart)=>{var l,c,h;return(l=this.visualPoints[a])!=null&&l.close&&((c=this.visualPoints[a])==null?void 0:c.close)>=0?(h=this.visualPoints[a])==null?void 0:h.close:1},this.getTextForPoint=a=>`${a.close}`,this.getLastVisualSeriesPoint=()=>{const a=this.visualPoints,l=Ot(a,this.scale.xEnd,c=>c.centerUnit).index;return a[l]},this.getLastDataSeriesPoint=()=>{const a=this.visualPoints;return yt(a)},this.config=Tt(r,_i),this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Xl(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=cc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Gn(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=Gn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const n=Ni({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=n.yAxis.model.fancyLabelsModel.labelsProviders[Qt.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[Qt.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(Qt.MAIN,a,r),n.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(Qt.MAIN,r))}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=Ot(this.visualPoints,t,r=>r.centerUnit).index,i=Ot(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return zi(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 Ga(this.visualPoints2D,n,i)}}const lc=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},cc=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=lc(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return ac(Ni({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),zi=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 ht.makeDecimal(s,i)};class Je extends Me{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=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 Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),n=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const de=60,Ae=(s,t,e=de)=>{const n=Wi(s,t,e);return{id:ei(n,n),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:n,volume:NaN,expansion:!0,idx:t}},hc=(s,t,e=de)=>({close:NaN,timestamp:Wi(s,t,e)});function Wi(s,t,e=de){var n,i;const r=ye(t);if(s.length===0)return 0;const o=yt(s);if(r>=s.length&&o)return Vi(o,s.length-1,r,e);const a=ce(s);return r<0&&a?Vi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Vi=(s,t,e,n=de)=>s.timestamp+(e-(t!=null?t:0))*n,Ui=(s,t,e,n,i=de)=>{const r=Ae(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 Je(o,e,r.open,r.close,r.lo,r.hi,Ue(r.open,r.close),r)},dc=(s,t,e,n,i=de)=>{const r=hc(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 Me(o,r.close)};class uc{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=Te(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=Hl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Ui(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):dc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var fc=Object.defineProperty,Gi=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,pc=Object.prototype.propertyIsEnumerable,Zi=(s,t,e)=>t in s?fc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,mc=(s,t)=>{for(var e in t||(t={}))gc.call(t,e)&&Zi(s,e,t[e]);if(Gi)for(var e of Gi(t))pc.call(t,e)&&Zi(s,e,t[e]);return s};class vc{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={},this.isColorsChanged=()=>!Oi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=mc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const bc=(s,t,e,n,i,r,o)=>{const a=Jl(),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]=it(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?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},$i=(s,{x:t,width:e,activeCandle:n})=>new Je(t,e,s.open,s.close,s.hi,s.lo,Ue(s.open,s.close),s,!0,Xs(s,n)),Cc=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,ol((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},Ki=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,Ue((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},yc=Ki,Xs=(s,t)=>{const e=t&&t.id===s.id;return e!=null?e:!1},qi=()=>Ds,ee=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(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=ee.getPriceIncrement(e||s,t);return ht.roundToNearest(s,n)}static computePrecisions(s){const t=[...s];for(let e=0;e<s.length;e+=2)t[e]=ee.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*ee.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<ee.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*ee.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return ee.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Rt=ee;Rt.DEFAULT_INCREMENT=.01,Rt.DEFAULT_PRECISION=2,Rt.RELATIVE_EPS=1e-8,Rt.MAXIMUM_PRECISION=10;const wc=(s,t)=>{var e;const n=(e=yt(t))!=null?e:1;return Math.pow(10,-n)};var Sc=Object.defineProperty,xc=Object.defineProperties,_c=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,Pc=Object.prototype.hasOwnProperty,Tc=Object.prototype.propertyIsEnumerable,Qi=(s,t,e)=>t in s?Sc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Mc=(s,t)=>{for(var e in t||(t={}))Pc.call(t,e)&&Qi(s,e,t[e]);if(Ji)for(var e of Ji(t))Tc.call(t,e)&&Qi(s,e,t[e]);return s},Ac=(s,t)=>xc(s,_c(t));const Ec=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=tr(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return Ac(Mc({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),tr=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},Ic=400,er=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:Ic,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},We,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class Dc{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){Lc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const Lc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=sr(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 sr(s){if(s.length===0)return Oc();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 Oc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),nr=(s,t)=>s/t,Bc=(s,t)=>s/t,Rc=(s,t)=>s*t,ir=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=nr(e,n),r=s.yEnd-s.yStart;t.zoomY=Bc(t.zoomX,i);const o=t.zoomY/n,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},Fc=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=nr(e,n),r=s.xEnd-s.xStart;t.zoomX=Rc(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},Hc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},kc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},rr=(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},jc=(s,t,e,n)=>rr(s,t,1,e,n);var Yc=Object.defineProperty,Nc=Object.defineProperties,Xc=Object.getOwnPropertyDescriptors,or=Object.getOwnPropertySymbols,zc=Object.prototype.hasOwnProperty,Wc=Object.prototype.propertyIsEnumerable,ar=(s,t,e)=>t in s?Yc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Qe=(s,t)=>{for(var e in t||(t={}))zc.call(t,e)&&ar(s,e,t[e]);if(or)for(var e of or(t))Wc.call(t,e)&&ar(s,e,t[e]);return s},Vc=(s,t)=>Nc(s,Xc(t));const Uc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class lr extends Ql{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new O,this.beforeStartAnimationSubject=new O,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=te(t.scale),this.autoScaleModel=new Dc(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=Qe(Qe({},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();rr(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();jc(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){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&ir(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),n?this.apply(o):((i=this.currentAnimation)==null||i.tick(),er(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const n=this.getBounds().width,i=.001;if(n>0){const r=qe(this.config.components.chart.minCandles,n),a=t!==r&&t-r<=i&&e,l=qe(n/this.config.components.chart.minWidth,n),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,n=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Vc(Qe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&ir(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),er(this.canvasAnimation,this,l)))}setYScale(t,e,n=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio){this.setLockedYScale(t,e,n,i);return}super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,n=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,n);const o=this.export(),a=this.scalePostProcessor(i,o);Fc(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),n=Qe({},e);this.haltAnimation(),Hc(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();kc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),tc(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}}class Gc extends lr{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 Zc=Ge().colors;class Vt extends Xi{constructor(t,e,n,i,r,o,a,l,c=Zc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Uc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new O,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=Ec(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=Rt.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=Ot(this.visualPoints,t,r=>r.startUnit).index,i=Ot(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=yt(this.dataPoints);t&&(this.lastPriceMovement=Ue(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=tr(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:qi;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,p=(i=this.candlesTransformersByChartType[r])!=null?i:$i;o.push(p(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,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 Ep(s){switch(s){case"line":case"area":return!0;default:return!1}}class $c{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Vt){const r=Ct(e);if(r.length===0)return;i.color?t.strokeStyle=i.color: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],f=n.view.toX(u.centerUnit),p=n.view.toY(u.close),v=o.y+o.height;if(h===void 0)t.beginPath(),t.lineTo(it(f),v),t.moveTo(it(f),p);else if(d===void 0){t.lineTo(it(f),p),t.stroke(),t.lineTo(it(f),v),t.lineTo(it(l),v),t.closePath();let _;i.color?t.fillStyle=i.color: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(f,p)}}}}function cr(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 Kc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,p=c==="right"?h:-h,v=h;s.save(),s.beginPath(),l?s.moveTo(r+p,o):s.moveTo(r,o),l?(s.lineTo(r+f-p,o),s.quadraticCurveTo(r+f,o,r+f,o-v),s.lineTo(r+f,e+v),s.quadraticCurveTo(r+f,e,r+f-p,e),s.lineTo(t+p,e)):(s.lineTo(r+f,o),s.lineTo(r+f,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-p/3,e+v/3),s.lineTo(n+p/3,i-v/3),s.quadraticCurveTo(n,i,n+p/3,i+v/3),s.lineTo(r-p/3,o-v/3),s.quadraticCurveTo(r,o,r+p/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function qc(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 se(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function hr(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()},Ip=s=>Array.isArray(s[0])?s:[s];class Jc{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 ne=(s,t,e,n,i=t)=>{n.hoverWidth?s.lineWidth=n.hoverWidth:e.highlighted?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Qc{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.color)t.strokeStyle=e.color;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Vt){const r=Ct(e);ne(t,this.config.barLineWidth,n,i),se(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=n.view.toX(o.centerUnit),l=n.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(n.view),f=Mt(n.view.xPixels(o.width)/2),p=n.view.toY(o.close),v=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,p),t.lineTo(a+f,p),t.moveTo(l,v),t.lineTo(a,v),t.stroke()}})}}}class th{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Vt){const r=Ct(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],f=r[h+1],p=n.view.toX(c.centerUnit),v=n.view.toX(d.centerUnit),_=n.view.toY(d.close),P=u?n.view.toY(u.close)<l:!1,L=_<l;if(u!==void 0&&P!==L){dr(t,n,i,P);const F=n.view.toX(u.centerUnit),k=n.view.toY(u.close),H=v-F,B=_-k,N=H/B,W=_-l,G=N*W,V=F+(H-G);t.lineTo(V,l),t.stroke(),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(V,l)}u===void 0?(t.beginPath(),t.moveTo(v,_)):f===void 0?(dr(t,n,i,L),t.lineTo(v,_),t.stroke(),t.lineTo(v,l),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(p,l),t.lineTo(v,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(v,_)}}}}const dr=(s,t,e,n)=>{e.color?(s.fillStyle=e.color,s.strokeStyle=e.color):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class eh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Vt){const r=Ct(e);ne(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),se(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.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=n.view.toX(i.startUnit),d=n.view.xPixels(i.width),u=i.bodyHeight(n.view),[f,p,v,_]=i.yBodyKeyPoints(n.view),P=p===v?p+1:v,L=f===_?f+1:_,F=l[`${a}Color`],k=a==="none"?F:l[`${a}WickColor`];t.fillStyle=F,e.color?t.strokeStyle=e.color:t.strokeStyle=k;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?L:P),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?L:P),t.moveTo(h+1,p),t.lineTo(h+1,P),t.stroke();else if(d===3){const N=d/Bt;this.drawCandlesWicks(t,h+N,f,L,p,P),c||(t.beginPath(),t.moveTo(h+N,p),t.lineTo(h+N,P),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,p+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const N=i.x(n.view);this.drawCandlesWicks(t,N,f,L,p,P);const W=this.config.candlePaddingPercent,G=Math.max(d*W/2,this.pixelLength),V=h+G,U=d-G*2;if(!c){e.color&&(t.fillStyle=e.color);const $=e.hoverWidth?d+G:U,Z=e.hoverWidth?u+e.hoverWidth+G:u;t.fillRect(V,p,$,Z)}H&&this.drawCandleBorder(t,e,l,i,V+this.halfLineWidthCU,p+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.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class sh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Vt){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.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),f=n.view.toY(l.close),p=Mt(n.view.xPixels(l.width));t.fillRect(u,f,p,h);const v=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(v.addColorStop(0,d[`${c}Cap`]),v.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=v),p===0?(t.beginPath(),t.strokeStyle=v,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,p,a-f-h)}}}}class nh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Vt){const r=Ct(e);ne(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),f=n.view.toX(c.centerUnit),p=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,p),t.stroke()}}}}const ih=1.5;class rh{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=i.hoverWidth?i.hoverWidth/2:ih;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of Ct(e)){t.beginPath();const l=n.view.toX(a.centerUnit),c=n.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const oh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class ah{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 oh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Ut(t,e.scale.getBounds())}}class lh{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.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(it(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(ft(h.width,u)),p=Mt(h.bodyHeight(this.chartModel.scale)),v=h.xCenter(this.chartModel.scale)-f/2,_=h.yBodyStart(this.chartModel.scale),P=this.chartModel.config.components.chart.candlePaddingPercent,L=Mt(f*P/2),F=v+L,k=f-L*2;t.fillRect(F,_,k,p)}})})}}const ur=(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)})},ch=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,hh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,dh=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,uh=s=>ch.exec(s),fh=s=>hh.exec(s),Dp=s=>dh.exec(s);function gh(s){const t=uh(s)||fh(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const fr={};function ph(s,t){let e=fr[s+t];if(!e){const n=gh(s);e=n&&"rgba("+n.join(",")+","+t+")",fr[s+t]=e}return e}class mh{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ne(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.color)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(pr(r.config.type)&&pr(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 f=Math.min(d.length,h[u].length);for(let _=0;_<f;_++){const P=[d[_].clone(),h[u][_].clone()];a.push({diffPoints:P})}const p=l.getPaintConfig(u).color,v=r.getPaintConfig(o).color;this.drawDifference(t,p,v,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),ur(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[f,p]=u.diffPoints;l.push(f),c.push(p)});const h=gr(l,r.view),d=gr(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=ce(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=yt(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,f)=>{f===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.color?r.color:ph(e||"#383838",.3),t.fill(),t.restore()}}const gr=(s,t)=>s.map(e=>{const{centerUnit:n,close:i}=e,r=t.toX(n),o=t.toY(i);return{x:r,y:o}}),pr=s=>s==="DIFFERENCE";class vh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ne(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=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,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class bh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ne(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),ur(e,t,n),t.stroke()}}class Ch{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class yh{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.color)!=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),f=jt(c,t),p=n.view.toX(h.centerUnit)-u/2,v=n.view.toY(h.close)+f;t.fillText(d,p,v)})}),t.restore()}}class wh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);t.fillStyle=(a=i.color)!=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 zs="resized_local",ts="draw",Lp="draw_last_candle",ue={width:20,height:20};class mr{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=Ws;var a;i.push(this),this.parent=_h(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>ue.width&&this.height>ue.height}}const Ws={name:"candle"},Sh={candle:Ws,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function xh(s,t,e,n,i,r,o){var a;const l=ie(s,t,i,r,o,e);return l.type=(a=Sh[n])!=null?a:Ws,l}function ie(s,t,e,n,i,r,o){const a=new mr(s,t,n,i,r,o);return vr(a,e),a}function vr(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 _h(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}const es="HIT_TEST_",Fp=null;class Ph{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${bt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(es)!==-1&&this.drawersMap[n].draw()})},t.on(ts,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),Yn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(es)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(es)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Wa(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)>ue.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ue.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=bt()){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=Vn(this.drawingOrder,t)}}class br{static paneResizer(t){return`PANE_RESIZER_${t}`}}class Th{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={color:this.canvasModel.idToColor(e.htId),hoverWidth:7};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const Cr={dragPredicate:()=>!0};class yr 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 ss extends yr{constructor(t,e,n,i,r=Cr){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 Mh="BASELINE_RESIZER";class Ah 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.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Rs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&_l(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new ss(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[Mh]=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 Eh=16,Ih=s=>{var t;try{const e=Ce(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=Ce(s.hi,Math.max(s.open,s.close),e),i=Ce(s.lo,Math.min(s.open,s.close),e),r=Ce(s.open,s.lo,e),o=Ce(s.close,s.hi,e),a=Number.isNaN(s.vwap)?void 0:s.vwap;return{id:s.id,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,vwap:a}}catch(e){console.warn(e);return}},Ee=(s,t=0)=>{for(let e=t;e<s.length;++e)s[e].idx=e},wr=s=>{s.forEach(t=>{t.idx=void 0})},Dh=s=>s!==void 0;class Lh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0),o=Ct(e),a=n.getPaintConfig(0);ne(t,a.lineWidth,n,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,p,v,_,P;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(l.close<this.previousValue(o,c)?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const k=n.view.toX(l.centerUnit),H=n.view.toY(l.close);t.moveTo(k,r),t.lineTo(k,H),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){const k=this.previousValue(o,c);l.close<k&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),l.close>k&&l.close<0&&(t.strokeStyle=(p=i.color)!=null?p:a.multiplyColors[1]||a.color||"#FF00FF"),l.close<k&&l.close>0&&(t.strokeStyle=(v=i.color)!=null?v:a.multiplyColors[2]||a.color||"#FF00FF"),l.close>k&&l.close>0&&(t.strokeStyle=(_=i.color)!=null?_:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const H=n.view.toX(l.centerUnit),B=n.view.toY(l.close);t.moveTo(H,r),t.lineTo(H,B),t.stroke();return}t.strokeStyle=(P=i.color)!=null?P:a.color||"#FF00FF",t.beginPath();const L=n.view.toX(l.centerUnit),F=n.view.toY(l.close);t.moveTo(L,r),t.lineTo(L,F),t.stroke()})}previousValue(t,e){do e--;while(e>=0&&!isFinite(t[e]&&t[e].close));return t[e]?t[e].close:Number.NaN}}const Oh=(s,t)=>{let e=0;return(...n)=>{clearTimeout(e),e=+setTimeout(()=>s(...n),t)}};var Bh=Object.defineProperty,Sr=Object.getOwnPropertySymbols,Rh=Object.prototype.hasOwnProperty,Fh=Object.prototype.propertyIsEnumerable,xr=(s,t,e)=>t in s?Bh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,_r=(s,t)=>{for(var e in t||(t={}))Rh.call(t,e)&&xr(s,e,t[e]);if(Sr)for(var e of Sr(t))Fh.call(t,e)&&xr(s,e,t[e]);return s};class Hh{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class kh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p){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=f,this.chartResizeHandler=p,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=_=>{var P;return(P=this.barTypeValues.find(L=>L===_))!=null?P:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Ah(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const v=new Th(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(v,es+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new vc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new Jc(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(Oh(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Eh))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",$i),this.registerCandlesTransformer("trend",Ki),this.registerCandlesTransformer("hollow",Cc),this.registerCandlesTransformer("line",yc)}get barTypeValues(){return Li(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 eh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Qc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new nh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new rh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new $c(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new th(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new sh(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new bh),this.registerDataSeriesTypeDrawer("HISTOGRAM",new vh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Lh),this.registerDataSeriesTypeDrawer("POINTS",new Ch),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new ah(new lh(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new yh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new wh),this.registerDataSeriesTypeDrawer("DIFFERENCE",new mh)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(_r({},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()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=_r({},t),this.chartModel.bus.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 wr(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)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,n=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,n)}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||!Rt.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Rt.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 Pr extends Vt{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 jh=Object.defineProperty,Tr=Object.getOwnPropertySymbols,Yh=Object.prototype.hasOwnProperty,Nh=Object.prototype.propertyIsEnumerable,Mr=(s,t,e)=>t in s?jh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Xh=(s,t)=>{for(var e in t||(t={}))Yh.call(t,e)&&Mr(s,e,t[e]);if(Tr)for(var e of Tr(t))Nh.call(t,e)&&Mr(s,e,t[e]);return s};const zh=(s,t,e,n)=>{var i,r,o,a;const l=Xh({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Za(-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-Nt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Wh=s=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const n=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),i=n[0],r=n[n.length-1];s.setXScale(i.startUnit,r.startUnit+r.width+s.offsets.right)}e.yScale&&s.doAutoScale(!0),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 Uh=Object.defineProperty,Gh=Object.defineProperties,Zh=Object.getOwnPropertyDescriptors,Ar=Object.getOwnPropertySymbols,$h=Object.prototype.hasOwnProperty,Kh=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?Uh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ie=(s,t)=>{for(var e in t||(t={}))$h.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))Kh.call(t,e)&&Er(s,e,t[e]);return s},Vs=(s,t)=>Gh(s,Zh(t));class qh{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)=>Vs(Ie({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=Vs(Ie({},te(this.config.colors)),{lineTheme:Ie({},n.lineTheme),areaTheme:Ie({},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]]=Vs(Ie({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Jh=Object.defineProperty,Ir=Object.getOwnPropertySymbols,Qh=Object.prototype.hasOwnProperty,td=Object.prototype.propertyIsEnumerable,Dr=(s,t,e)=>t in s?Jh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ns=(s,t)=>{for(var e in t||(t={}))Qh.call(t,e)&&Dr(s,e,t[e]);if(Ir)for(var e of Ir(t))td.call(t,e)&&Dr(s,e,t[e]);return s};class ed 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.prepareCandles=u=>{const f=u.map(Ih).filter(Dh),{sortCandles:p}=this.config.components.chart;return p?p(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new qh(this.config);const d=new Pr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Hh,this.candlesTransformersByChartType,this.candleWidthByChartType,ns({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>zh(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Wh(o),this.timeFrameViewportTransformer=Vh(o,this),this.pane=this.paneManager.panes[q]}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(q)).pipe(At(bi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ue.width&&t.height>ue.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),n=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Nt(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=Nt(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 wr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,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=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Ee(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}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=ns({},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=this.prepareCandles(t.candles),r=Or(this.mainCandleSeries.dataPoints,i),o=r.candles;Ee(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),p=Or((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(p,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),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=Ot(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=ns(ns({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Vt(this.paneManager.panes[q].mainExtent,bt(),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[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)n.push(a);else{let l=Lr(e,o,-1);if(l||(l=Lr(e,o,1)),l){const c=al(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Tt(t,Ge().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)}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=Ot(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+=ye((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?Ae(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Ae(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)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(n=>n.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(n=>n.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,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 yt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return yt(t)}getMaxCandlesFitLength(){return it(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=Te(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=Te(h.timestamp,!0,o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const p=f>=o.length-1,v=c&&h.timestamp<c.timestamp;if(p&&!v&&(c=h),a&&c&&n&&l){const _=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:qi;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.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return vt(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(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(Ae(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=Te(r.timestamp,!1,t).index;a<0?i.push(r):t[a].id===r.id?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){if(t<0)return;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)),Ee(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const n=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(n<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,n).concat(e.dataPoints.slice(i+1)),Ee(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(n=>this.removeCandleByIdx(this.candleIdxFromId(n,e)))}addCandlesById(t,e,n){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=n.dataPoints.slice(0,i),o=n.dataPoints.slice(i);n.dataPoints=r.concat(t).concat(o),Ee(n.dataPoints),n.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Lr=(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}},Or=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=Te(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 fe{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Us{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=Di(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=Di(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=Ct(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class sd{constructor(t,e,n,i){this.model=t,this.config=e,this.crossToolCanvasModel=n,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var nd=Object.defineProperty,id=Object.defineProperties,rd=Object.getOwnPropertyDescriptors,Br=Object.getOwnPropertySymbols,od=Object.prototype.hasOwnProperty,ad=Object.prototype.propertyIsEnumerable,Rr=(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)&&Rr(s,e,t[e]);if(Br)for(var e of Br(t))ad.call(t,e)&&Rr(s,e,t[e]);return s},cd=(s,t)=>id(s,rd(t));class hd extends X{constructor(t,e,n,i,r,o){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?kt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(kt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,q]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(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===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:n,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(x.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=n.x+l,d=n.y+c,u=o.y+a,f=o.y+o.height-a,p=h<a?a:h>o.width-a?o.width-a:h,v=d<u?u:d>f?f:d,_=(e=this.hoverProducer.createHover(p,v,t.paneId))!=null?e:t,P=cd(ld({},_),{x:p,y:v});this.crossEventProducer.crossToolHover=P,this.updateCrossTool(P)}}const Et=4;function dd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p;const v=r.align,_=(l=i.textFont)!=null?l:Jt(r),P=i.bgColor,L=(c=i.textColor)!=null?c:qt(P,o.labelTextColor,o.labelInvertedTextColor),F=(h=i.paddingTop)!=null?h:Et,k=(d=i.paddingBottom)!=null?d:Et,H=(u=i.paddingEnd)!=null?u:Et,B=ye(jt(_,s)/2),N=n-B-F,G=n+B+k-N;if(a&&!is(n,t,G))return;s.save(),s.fillStyle=P,s.strokeStyle=P;const V=ye(t.width/6),U=v==="right"?t.x:t.x+t.width,$=v==="right"?U+V:U-V,Z=r.labelBoxMargin.end,et=Z-H,tt=t.width-V-et;Kc(s,$,N,U,N+ye(G/2),$,N+G,tt,(p=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?p:!1,v),s.fillStyle=L,s.font=_;const Q=v==="right"?t.x+t.width-Pt(e,s,_)-Z:t.x+Z;s.fillText(e,Q,n+B-1),s.restore()}function ud(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,_,P,L;const F=r.align,k=(l=i.textFont)!=null?l:Jt(r),H=i.bgColor,B=(c=i.textColor)!=null?c:qt(H,o.labelTextColor,o.labelInvertedTextColor),N=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,W=(u=(d=i.paddingTop)!=null?d:N==null?void 0:N.top)!=null?u:Et,G=(p=(f=i.paddingBottom)!=null?f:N==null?void 0:N.bottom)!=null?p:Et,V=(_=(v=i.paddingEnd)!=null?v:N==null?void 0:N.end)!=null?_:Et,U=i.paddingStart,$=jt(k,s),Z=n-$/2-W,tt=n+$/2+G-Z,Q=(L=i.rounded)!=null?L:(P=r.typeConfig.rectangle)==null?void 0:P.rounded;if(a&&!is(n,t,tt))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const rt=r.labelBoxMargin.end;s.font=k;const dt=Pt(e,s,k),ot=rt-V,xt=U!==void 0?dt+U+V:t.width-ot,oe=F==="right"?t.x+t.width-ot-xt:t.x+ot,me=F==="right"?t.x+t.width-dt-rt:rt;Q?cr(s,oe,Z,xt,tt,4,!0):s.fillRect(oe,Z,xt,tt),s.fillStyle=B,s.fillText(e,me,n+$/2-1),s.restore()}function fd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,_;const P=r.align,L=(l=i.textFont)!=null?l:Jt(r),F=o.backgroundColor,k=(c=i.textColor)!=null?c:qt(F,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Et,N=(p=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?p:Et,W=(_=(v=i.paddingEnd)!=null?v:H==null?void 0:H.end)!=null?_:Et,G=i.paddingStart,V=jt(L,s),U=n-V/2-B,Z=n+V/2+N-U;if(a&&!is(n,t,Z))return;s.save(),s.fillStyle=F,s.strokeStyle=F;const et=r.labelBoxMargin.end;s.font=L;const tt=Pt(e,s,L),Q=et-W,rt=G!==void 0?tt+G+W:t.width-Q,dt=P==="right"?t.x+t.width-Q-rt:t.x+Q,ot=P==="right"?t.x+t.width-tt-et:et;s.fillStyle=F,s.strokeStyle=F,s.fillRect(dt,U,rt,Z),s.fillStyle=k,s.fillText(e,ot,n+V/2-1),s.restore()}function gd(s,t,e=Et){return jt(s,t)/2+e}function is(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const pd="badge",Fr=4,Hr={badge:dd,rectangle:ud,plain:fd};function kr(s,t,e,n,i,r,o,a,l){var c,h,d,u,f;const p=r.y,v=r.labelText,_=(c=r.mode)!=null?c:"label",P=(h=r.labelType)!=null?h:pd,L=r.description,F=(d=r.textFont)!=null?d:Jt(a),k=r.bgColor,H=(u=r.lineColor)!=null?u:k,B=Pt(L!=null?L:"",s,F)+8,N=it(r.y),W=jt(F,s),G=p-W/2,U=p+W/2-G;s.save(),s.fillStyle=k,s.strokeStyle=H;const $=o.getBounds(x.PANE_UUID(q)),Z=Hr[P],et=a.labels.descriptions,tt=md(n,N,U),Q=()=>et&&vd(e,t,n,i,r,a);let rt,dt;const ot=2;a.align==="right"?(rt=$.x,dt=et?$.x+$.width-B:$.x+$.width+ot):(rt=et?$.x+B:$.x-ot,dt=$.x+$.width);const xt=(f=r.lineY)!=null?f:r.y,oe=()=>tt&&se(s,()=>qc(s,rt,xt,dt,xt,1)),me=()=>Z(s,n,v,p,r,a,l.yAxis,!1),dn={line:()=>{oe(),Q()},"line-label":()=>{oe(),me(),Q()},label:()=>{Q(),me()}};_!=="none"&&is(p,n,U)&&dn[_](),s.restore()}const md=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function vd(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),f=Pt(h,t,u),p=jt(u,t),v=(o=i.paddingTop)!=null?o:Fr,_=(a=i.paddingBottom)!=null?a:Fr,P=d-p/2-v,F=d+p/2+_-P;t.save();const k=f+5,H=4,B=f+H*2,N=n.x+n.width,W=c==="right"?N-B:n.x+H;bc(s,t,W,P,k,F,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const G=c==="right"?N-f-H*2:n.x+H*2;t.fillText(h,G,d+p/2-1),t.restore()}class jr{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()&&se(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,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const p={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},v={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},_=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),_&&(t.moveTo(...p.start),t.lineTo(...p.end)),t.moveTo(...v.start),t.lineTo(...v.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,f=t.measureText(u).width,p=this.config.components.xAxis.fontSize,v=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const _=(n=l==null?void 0:l.left)!=null?n:0,P=(i=l==null?void 0:l.right)!=null?i:0,L=(r=l==null?void 0:l.top)!=null?r:0,F=(o=l==null?void 0:l.bottom)!=null?o:0,k=(a=c==null?void 0:c.top)!=null?a:0,H=f+_+P,B=p+L+F,N=Math.max(d-H/2,0),W=v.y+k+Se/2;cr(t,N,W,H,B),t.fillStyle=h.labelTextColor;const G=Math.max(d-f/2,_),V=v.y+k+p+Se/2+L-1;t.fillText(u,G,V),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=Hr[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,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 bd{draw(){}}class Cd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.crossToolTypeDrawers={},this.model=new hd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel),this.addChildEntity(this.model);const c=new fe(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const h=new sd(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),d=new Us;d.addDrawer(c,"CLEAR_CANVAS"),d.addDrawer(h,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(d,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new jr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new jr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new bd)}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 yd{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 Xt{constructor(t){this.data=t,this.next=null}}class wd{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 Xt(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 Xt(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 Sd extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const 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 Xt(n);return i.getNodePosition(r)}addObject(t){var e,n;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new wd;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((n=t.parentId)!=null?n:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[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 Xt(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 Xt(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 Xt(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 Xt(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 Xt(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()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class xd extends X{constructor(t,e){super();const n=new Sd(t);this.model=n,this.addChildEntity(n);const i=new yd(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const _d=()=>s=>s.toString(),Pd=(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:Td(s),shortMonths:Md(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=>Ad(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Td(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Md(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const Yr=(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 _d()},Ad=(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=ge(d),f=ge(a),p=ge(l),v=ge(c),_=a<12?"AM":"PM",P=e[s.getDay()],L=P.substring(0,3),F=ge(i),k=r+1,H=ge(k),B=n[r],N=B.substring(0,3),W=o+"",G=W.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",p+"").replace("m",l+"").replace("ss",v+"").replace("s",c+"").replace("S",h+"").replace("dd",F+"").replace("d",i+"").replace("EEEE",P).replace("EEE",L).replace("YYYY",W).replace("yyyy",W).replace("YY",G).replace("yy",G).replace("aaa",_),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",N):t=t.replace("MM",H+"").replace("M",k+""),t},ge=s=>typeof s=="number"&&s<10?"0"+s:s,De=(s,t)=>`${s}_${t}`,Ed=(s,t)=>{if(t){const e=Nr(t.normal),n=Nr(t.hover);return{type:s,normal:e,hover:n}}},Nr=s=>{var t;const n=new DOMParser().parseFromString(s,"text/html").querySelector("svg");let i=0;n&&(i=parseInt((t=n.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(s),l=new Image;return l.src=a,{img:l,svgHeight:i}},Id=(s,t,e,n,i)=>{if(i){const r=t[De(n,"hover")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[De(n,"normal")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Dd={"rhombus-small":4,rhombus:6,"rhombus-large":8},Ld=["earnings","dividends","splits","conference-calls"];class Od{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&&Ld.forEach(l=>{const c=Ed(l,a[l]);c&&(this.customIcons[De(c.type,"normal")]=c.normal,this.customIcons[De(c.type,"hover")]=c.hover)})}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=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(n.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[De(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Id(n,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(n,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);n.lineWidth=u!=null?u:1,n.beginPath(),n.setLineDash(f!=null?f:[]),n.moveTo(c,e.y),n.lineTo(c,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),n.restore()}drawDefaultEvent(t,e,n,i,r){var o,a,l;const c=n.y+n.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=Gs(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var 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 Gs(s){return Dd[s.style]}const rs=5;class Bd{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)=>{if(!this.config.components.events.eventsVisibility[n.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[n.type].color;t.strokeStyle=c,t.fillStyle=c;const h=Gs(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const d=(h+rs)*2;if(a!==void 0){const u=Gs(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const v=h*2+rs;t.fillRect(a+u,e.y,v,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Rd=Object.defineProperty,Xr=Object.getOwnPropertySymbols,Fd=Object.prototype.hasOwnProperty,Hd=Object.prototype.propertyIsEnumerable,zr=(s,t,e)=>t in s?Rd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,kd=(s,t)=>{for(var e in t||(t={}))Fd.call(t,e)&&zr(s,e,t[e]);if(Xr)for(var e of Xr(t))Hd.call(t,e)&&zr(s,e,t[e]);return s};const Wr=317,Zs={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class jd extends mr{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 ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,vr(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(Pe(100,_e,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=vt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=vt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(ct(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(ct(()=>kd({},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*Wr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Wr}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!==Ss&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ss),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]=$s(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]=$s(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),[f,p]=$s(this.hitTestSubscribers,u),v=f==null?void 0:f.lookup(d),_={point:t,model:v};switch(e){case"mousedown":v&&((n=f==null?void 0:f.onMouseDown)==null||n.call(f,v,t)),p.forEach(P=>P.onMouseDown&&P.onMouseDown(null,t));break;case"mouseup":v&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,v,t)),p.forEach(P=>P.onMouseUp&&P.onMouseUp(null,t));break;case"hover":v&&((r=f==null?void 0:f.onHover)==null||r.call(f,v,t)),p.forEach(P=>P.onHover&&P.onHover(null,t)),this.hoverSubject.next(_);break;case"touchstart":v&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,v,t)),p.forEach(P=>P.onTouchStart&&P.onTouchStart(null,t)),this.touchStartSubject.next(_);break;case"dblclick":v&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,v,t)),this.dblClickSubject.next(_);break;case"contextmenu":v&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,v,t)),this.rightClickSubject.next(_);break;case"zoom":v&&((c=f==null?void 0:f.onZoom)==null||c.call(f,v,t)),p.forEach(P=>P.onZoom&&P.onZoom(null,t));break;default:break}}}const $s=(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 Yd=Object.defineProperty,Nd=Object.defineProperties,Xd=Object.getOwnPropertyDescriptors,Vr=Object.getOwnPropertySymbols,zd=Object.prototype.hasOwnProperty,Wd=Object.prototype.propertyIsEnumerable,Ur=(s,t,e)=>t in s?Yd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Vd=(s,t)=>{for(var e in t||(t={}))zd.call(t,e)&&Ur(s,e,t[e]);if(Vr)for(var e of Vr(t))Wd.call(t,e)&&Ur(s,e,t[e]);return s},Ud=(s,t)=>Nd(s,Xd(t));class Gd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>Ud(Vd({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Zs.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 Zd 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=()=>Yr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Gd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new Od(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Bd(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){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class $d{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;se(t,()=>this.drawVertical(t)),se(t,()=>this.drawHorizontal(t)),se(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=it(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=Mt(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=it(this.viewportModel.toY(i.value)),o=gd(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 Gr 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 $d(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 Kd{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=Ve(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"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=Ve(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 qd extends X{constructor(t,e,n,i,r){super();const o=new Kd(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const Jd=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],Qd=24*60*60*1e3;class tu 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()+Qd;Ja(this.highlights,t,e,eu).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 eu=s=>s.to,Gt=[20,10];class su{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,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",p=`${u}px ${f}, monospace`;o.font=p,o.lineWidth=h,o.setLineDash(d),Jd.forEach(v=>{var _,P;const L=a[v];if(L){const F=this.config.colors.highlights[v],k=(_=F==null?void 0:F.border)!=null?_:"#ffffff",H=(P=F==null?void 0:F.background)!=null?P:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=k,L.forEach(B=>{var N,W,G;const V=this.chartModel.candleFromTimestamp(B.from),U=ft(V.width,this.chartModel.scale.zoomX),$=V.xStart(this.chartModel.scale),Z=this.chartModel.candleFromTimestamp(B.to),et=ft(Z.width,this.chartModel.scale.zoomX),tt=Z.xStart(this.chartModel.scale)+et;if(B.border&&this.drawBorders(B.border,o,$+U,tt-et,c),o.fillRect($,c.y,tt-$,c.y+c.height),B.label){const Q=(N=B.label.text)!=null?N:"",rt=this.config.colors.highlights[B.type];o.save(),o.fillStyle=(W=rt==null?void 0:rt.label)!=null?W:"#ffffff";const dt=Pt(Q,o,p),[ot,xt]=this.resolveHighlightLabelPosition((G=B.label.placement)!=null?G:"left-left",c,[$,tt],dt);o.fillText(Q,ot,xt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Gt[1]-i,e.y+Gt[0]];case"left-left":return[r-Gt[1]-i,e.y+Gt[0]];case"right-right":return[o+Gt[1],e.y+Gt[0]];case"left-right":default:return[r+Gt[1],e.y+Gt[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 nu="HIGHLIGHTS_PLUGIN";class iu extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new tu(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new su(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,nu)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function ru(){return Y(function(s,t){var e,n=!1;s.subscribe(mt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function J(s,t){return Y(function(e,n){var i=0;e.subscribe(mt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var ou=Object.defineProperty,au=Object.defineProperties,lu=Object.getOwnPropertyDescriptors,Zr=Object.getOwnPropertySymbols,cu=Object.prototype.hasOwnProperty,hu=Object.prototype.propertyIsEnumerable,$r=(s,t,e)=>t in s?ou(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Kr=(s,t)=>{for(var e in t||(t={}))cu.call(t,e)&&$r(s,e,t[e]);if(Zr)for(var e of Zr(t))hu.call(t,e)&&$r(s,e,t[e]);return s},qr=(s,t)=>au(s,lu(t));const zt=4;class du{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-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=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-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=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=Ct(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:qr(Kr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:qr(Kr({},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=qn(n,i.dateFormat,this.formatterFactory);Zn(t,i.textProperties);const a=Ve(t),l=Kn(o);tl(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Le extends yr{constructor(t,e,n,i,r=Cr){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 Jr=4;class uu 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=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-p.x-Jr},this.leftKnotDragTick=f=>{const{delta:p}=f,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,P=(this.leftKnotDragStartXRelative+p)/_;this.canvasBoundsContainer.leftRatio=P,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-p.x+Jr},this.rightKnotDragTick=f=>{const{delta:p}=f,_=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,P=(this.rightKnotDragStartXRelative+p)/_;this.canvasBoundsContainer.rightRatio=P,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:p}=f,v=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),_=this.chartModel.mainCandleSeries.meanCandleWidth/(v.width/this.chartModel.mainCandleSeries.dataPoints.length),P=(this.lastMousePosition-p)*_;this.scale.moveXStart(this.scale.xStart-P),this.lastMousePosition=p};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Le(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Le(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 Le(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 fu 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 du(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new uu(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(vt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(ru(),J(([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,f,p;for(f=0;f<h;f++)p=it(f*o/h)-r,p in e?(d[f]=e[p].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((v,_)=>[_+c.x,(a+l-v)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(zs),this.canvasModel.fireDraw())}}const Qr=()=>{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"},Hp=(s,t)=>s==="apple"||s==="mobile"?3:t,gu=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),pu=!!window.chrome,to=typeof InstallTrigger!="undefined",mu=navigator.platform.indexOf("Win")>-1,kp=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(gu)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(pu){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,mu){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 to?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 to&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},vu=(s,t)=>s==="percent"?t/4:t;var Ks=Math.pow;class bu 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 f=d.deltaY<0;if(this.config.scale.zoomToCursor){const v=this.canvasBoundsContainer.getBounds(x.CANVAS).width,P=d.offsetX/v;this.scale.zoomXToPercent(P,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(We),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Nt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Le(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(J(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Pe(this.wheelThrottleTime,_e,{trailing:!0,leading:!0})).subscribe(e=>{const n=Qr(),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=Nt(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 vu(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(We),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)Cu(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Nt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new ss(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Cu=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Ks(Ks(Math.abs(s.x),2)+Ks(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle},yu=2;class wu extends X{constructor(t,e,n,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:n}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:n}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:n}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=eo(e,i.x,n,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),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||e[0]===e[1]||this.scale.setXScale(n,i)}}const eo=(s,t,e,n,i=yu)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-n,2))>i;class Su 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 bu(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new wu(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const so=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}},no=(s,t)=>{const e=so(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function xu(){return Ln(1)}function io(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return xu()(Ye(s,je(s)))}function _u(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s);return Y(function(n,i){(e?io(s,n,e):io(s,n)).subscribe(i)})}function Pu(s){return J(function(t,e){return s<=e})}class Tu{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]}}const ro=8;class qs extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){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=f,this.initialY=0,this.resizeEvent$=new O,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=p=>{const{delta:v,draggedPixels:_}=p;Math.abs(this.initialY-this.boundsProvider().y+_)>=0&&(this.dragTickCb(v),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new ss(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:kt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:kt()?this.onYDragEndMobile: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(_u(!1),J(this.dragPredicate),At(),Pu(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Tu(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,br.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(br.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const Mu=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=Rt.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},Au=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ri(t,r.getBaseline()));const o=i.toFixed(Rt.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Eu=s=>({percent:Au(s),regular:Mu(s)});class Iu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:zi}){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=f=>f.map(p=>new Me(this.chartBaseModel.dataFromTimestamp(p.timestamp).centerUnit,p.close)),this.toY=f=>{var p,v;return(v=(p=this.mainDataSeries)==null?void 0:p.view.toY(f))!=null?v:1},this.valueFormatter=(f,p)=>{var v;return((v=this.formatters[this.yAxis.getAxisType()])!=null?v:this.formatters.regular)(f,p)},this.addChildEntity(l),this.setValueFormatters(Eu(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 Xi(this,bt(),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 oo=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return sr(e)}});class Du{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Zs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Zs.DATA_SERIES}get allDataSeries(){return we(we(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 Wt="#FF00FF";function jp(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 Lu=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Ou=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Wt},Bu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Wt},Ru=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Wt},Fu=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Wt},Hu=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Wt},ku=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:Wt},ju=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Wt},ao=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Wt},Yu=()=>(console.warn("Fallback for label default color"),Wt),lo=10;class co extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new 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,ui),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(lo-1)):d=1+h/this.lastYPxHeight*(lo-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,p=this.lastYStart-f,v=this.lastYEnd+f;(this.lastYStart!==p||this.lastYEnd!==v)&&(this.scale.setYScale(p,v),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new ss(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Nu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${bt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Yn(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 Xu=0,zu=.01;class Js{constructor(t,e,n,i,r=!1,o,a,l=Ms,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 Nu(()=>this.labelFilter(this.doGenerateLabels()))}generateRegularLabels(t,e,n){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=ht.roundToNearest(t,n);for(;r<e;){const o=ht.roundToNearest(r,n),a=this.valueFormatter(o);i.push({value:o,text:a}),r=ht.roundDecimal(r+n)}return i}generatePercentLabels(t,e,n){const i=[],r=this.baseLineProvider();let o=ht.roundToNearest(t,n);for(;o<e;){const a=ht.roundToNearest(o,n),l=Fi(a,r),c=this.valueFormatter(l);i.push({value:a,text:c}),o=ht.roundDecimal(o+n)}return i}generateLogarithmLabels(t,e,n){const i=[];let r=ht.roundToNearest(t,n);for(;r<e;){const o=Ns(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=ht.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=Js.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=Rt.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(zu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Ns(e)+t;return Hi(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)*(Xu/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 Wu extends Js{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=yt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=wc(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function ho(s,t,e){var n=j(s)||t||e?{next:s,error:t,complete:e}:s;return n?Y(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(mt(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)}))}):le}class Vu 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_${bt()}`}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ct(t=>t.height),J(t=>Ta(t,this.prevYAxisHeight,1.5)),ho(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class Uu extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Wu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new Vu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new ql(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(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 Gu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=a,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.hitTestCanvasModel=f,this.chartResizeHandler=p,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new O,this.axisAlignSetSubject=new O,this.axisAlignMovedSubject=new O,this.setDblClickCallback=P=>this.yAxisScaleHandler.setDblClickCallback(P),this.setDblTapCallback=P=>this.yAxisScaleHandler.setDblTapCallback(P);const _=v?te(v):{};this.state=Tt(_,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new co(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),f),this.addChildEntity(this.yAxisScaleHandler),this.model=new Uu(this.paneUUID,t,this.state,o,n,i,c,h,u,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new co(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Ru),this.registerLabelColorResolver("bar",Ou),this.registerLabelColorResolver("line",Bu),this.registerLabelColorResolver("area",Fu),this.registerLabelColorResolver("scatterPlot",Hu),this.registerLabelColorResolver("histogram",ku),this.registerLabelColorResolver("baseline",ju),this.registerLabelColorResolver("trend",ao),this.registerLabelColorResolver("hollow",ao)}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:Yu}registerYAxisLabelsProvider(t,e=Qt.MAIN,n=bt()){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=Qt.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.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Zu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,_,P,L,F,k){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=f,this.canvasBoundsContainer=p,this.uuid=v,this.seriesAddedSubject=_,this.seriesRemovedSubject=P,this.hitTestCanvasModel=L,this.chartResizeHandler=F,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new O,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,N)=>this.mainExtent.valueFormatter(B,N);const H=this.createExtentComponent(k);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(v),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return we(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(At(bi)).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,r){const o=x.PANE_UUID(t);return new Gr(this.mainCanvasModel,e,this.config,n,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(o),()=>this.canvasBoundsContainer.getBounds(o),()=>[],i,r,()=>this.config.components.grid.visible)}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 Gc(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(v,_)=>new Gu(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,v,_,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Iu(this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",no(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),oo(u)));const p=this.createGridComponent(this.uuid,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(p),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(n=>n.idx).includes(e.idx)),this.yExtentComponents.forEach((e,n)=>{e.yAxis.setExtentIdx(n),e.idx=n,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,n,i="right"){const r=te(n.yAxis.state),o=te(n.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),n.dataSeries.size===0&&e.removeExtentComponents([n])}moveDataSeriesToExistingExtentComponent(t,e,n,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&n.dataSeries.size===0&&e.removeExtentComponents([n]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(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=ce(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=yt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var $u=Object.defineProperty,Ku=Object.defineProperties,qu=Object.getOwnPropertyDescriptors,uo=Object.getOwnPropertySymbols,Ju=Object.prototype.hasOwnProperty,Qu=Object.prototype.propertyIsEnumerable,fo=(s,t,e)=>t in s?$u(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,tf=(s,t)=>{for(var e in t||(t={}))Ju.call(t,e)&&fo(s,e,t[e]);if(uo)for(var e of uo(t))Qu.call(t,e)&&fo(s,e,t[e]);return s},ef=(s,t)=>Ku(s,qu(t));class sf extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,_,P){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=f,this.mainCanvasModel=p,this.yAxisLabelsCanvasModel=v,this.hitTestCanvasModel=_,this.chartResizeHandler=P,this.panes={},this.paneRemovedSubject=new O,this.paneAddedSubject=new O,this.dataSeriesAddedSubject=new O,this.dataSeriesRemovedSubject=new O,this.hitTestController=new Du(this.panes,this.dynamicObjectsCanvasModel);const L=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});L.mainExtent.scale.autoScaleModel.setHighLowProvider("series",oo(L.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",so(()=>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+ro}),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 qs(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 we(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=bt(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new Zu(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&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=ce(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=yt(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 qs&&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 qs&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,n,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?ef(tf({},n.yAxis.state),{align:l}):void 0,p=c&&c>0;if(!u){const v=a&&a==="above"?d:d+1,_=this.createPane(r,{order:v,initialYAxisState:f,inverse:n.scale.state.inverse,lockToPriceRatio:n.scale.state.lockPriceToBarRatio});_.moveDataSeriesToExistingExtentComponent(t,e,n,_.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!p?u.moveDataSeriesToExistingExtentComponent(t,e,n,o):u.moveDataSeriesToNewExtentComponent(t,e,n,l!=null?l:n.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}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+ro),()=>{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 nf 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 rf=(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)},os=class extends X{constructor(s,t,e,n){super(),this.chartComponent=s,this.config=t,this.volumesModel=e,this.paneManager=n,t.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[os.UUID]===void 0){const t=this.paneManager.createPane(os.UUID,{paneFormatters:{regular:i=>rf(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=no(()=>({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(os.UUID),delete this.pane}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let go=os;go.UUID="volumes";const as=.3,of=(s,t)=>{const e=t.barTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},af=(s,t)=>{const e=t.volume[`${s}BarColor`];return Lt()(e).alpha(as).toString()},lf=(s,t)=>{const e=t.lineTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},Qs=(s,t)=>{const e=t.candleTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},cf=3;class hf{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:af;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=Ct(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?Mt(i.toX(n[o+1].startUnit)):void 0,h=Mt(i.toX(r.startUnit)),d=c!==void 0?c-h:Mt(ft(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(i.toY(r.candle.volume)),f=ks(i.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=e/(l/cf),f=Math.max(ks(ft(r.candle.volume,u)),2),p=Mt(a.y+l-f);this.drawVolume(t,r,h,p,d,f)}}})}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,ks(c)),a.stroke()):a.fillRect(n,i,r,o)}}const df=qa(s=>s.candle.volume),po="volumes";class uf extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=po,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(vt(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=ce(df(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class ff 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 ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new uf(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new go(e,o,c,a),this.volumesDrawer=new hf(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",Qs),this.registerVolumeColorResolver("trend",Qs),this.registerVolumeColorResolver("hollow",Qs),this.registerVolumeColorResolver("line",lf),this.registerVolumeColorResolver("bar",of)}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?po:q,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 gf{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,f=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:p,offsetY:v,offsetX:_}=this.config.components.waterMark;let P;switch(d?P=d:(u.font=ls(this.config,l),P=u.measureText(a).width,f.width-10<P&&(u.font=pf(this.config,this.canvasBoundsContainer,l,P),P=u.measureText(a).width)),p){case"left-top":return{x:_+f.x,y:v+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:_+f.x,y:f.height-h-v+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-P/2+f.x,y:(f.height-h)/2+o+f.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,f=this.canvasModel.ctx;let p=0,v=0,_=0,P=0,L=0;if(f.save(),d.firstRowFontSize&&l){f.font=ls(this.config,d.firstRowFontSize);const B=f.measureText(l);p=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=ls(this.config,d.secondRowFontSize);const B=f.measureText(c);v=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,_=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=ls(this.config,d.thirdRowFontSize);const B=f.measureText(h);P=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,L=(n=d.secondRowBottomPadding)!=null?n:0}const F=(i=d.thirdRowBottomPadding)!=null?i:0,k=(r=d.logoHeight)!=null?r:0,H=p+v+_+P+L+F+k;if(l&&this.drawWaterMark(this.getConfig(p,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(p+_+v,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(p+_+v+L+P,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(p+_+v+L+P+F,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const 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 pf=(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},ls=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var mf=Object.defineProperty,mo=Object.getOwnPropertySymbols,vf=Object.prototype.hasOwnProperty,bf=Object.prototype.propertyIsEnumerable,vo=(s,t,e)=>t in s?mf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,bo=(s,t)=>{for(var e in t||(t={}))vf.call(t,e)&&vo(s,e,t[e]);if(mo)for(var e of mo(t))bf.call(t,e)&&vo(s,e,t[e]);return s};class Cf 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 gf(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return bo(bo({},this.config.components.waterMark),h)}}const Co={x:4,y:4};function yf(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 p=s.measureText(n.text).width+Co.x*2;let v=0;const _=n.x;switch(o){case"start":v=_-p;break;case"end":v=_;break;case"middle":default:v=_-p/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(v,u.y,p,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 P=v+Co.x,L=u.y+d+a+Se/2;s.fillText(n.text,P,L),s.restore()}class wf{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=>{yf(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=Lt().rgb(r[0].color).alpha(.1).toString(),hr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const Yp="week-weekday",Sf=["second","minute","hour","day","month","year"],xf=["lessThanSecond"],_f=s=>Sf.some(t=>t===s),Pf=s=>s==="week-weekday",Tf=s=>xf.some(t=>t===s),yo=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},tn=s=>parseInt(s,10),wo=s=>{const[t,...e]=s.split("_");if(_f(t)){const[n]=e,i=yo(n),r=tn(n);return{key:t,value:r,exact:i["!"]}}else if(Pf(t)){const[n,i]=e,r=yo(n),o=tn(n),a=tn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Tf(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class cs{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=cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Se/2),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;if(h<n.x||h>n.width)continue;const 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 en={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},So=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return en[s.key]+s.value;case"lessThanSecond":return en[s.key];case"week-weekday":return en[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},xo=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},Mf=(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 f=r[u],p=f.idx;for(;c<a;){const v=o[c],_=v.idx;if(p>_)c++,n.push(v),d=_,h=1/0;else{h=_;break}}h-p>=t&&p-d>=t&&(n.push(f),d=p)}for(;c<a;)n.push(o[c]),c++}return n},Af=(s,t,e,n,i,r)=>{const o=cs.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 sn(s){"@babel/helpers - typeof";return sn=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},sn(s)}function wt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function St(s){wt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||sn(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 Ef(s){return wt(1,arguments),St(s).getDay()===1}function If(s){return wt(1,arguments),St(s).getDay()===2}function Df(s){return wt(1,arguments),St(s).getDay()===3}function Lf(s){return wt(1,arguments),St(s).getDay()===4}function Of(s){return wt(1,arguments),St(s).getDay()===5}function Bf(s){return wt(1,arguments),St(s).getDay()===6}function Rf(s){return wt(1,arguments),St(s).getDay()===0}function Ff(s,t){var e;wt(1,arguments);var n=s||{},i=St(n.start),r=St(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(St(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function Hf(s){wt(1,arguments);var t=St(s);return t.setDate(1),t.setHours(0,0,0,0),t}function kf(s){wt(1,arguments);var t=St(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function _o(s){wt(1,arguments);var t=St(s);return t.setHours(0,0,0,0),t}function Po(s,t){wt(2,arguments);var e=_o(s),n=_o(t);return e.getTime()===n.getTime()}const jf=s=>{switch(s.key){case"lessThanSecond":return zf(s);case"month":return Wf(s);case"second":case"minute":case"hour":case"day":case"year":return Vf(s);case"week-weekday":return Uf(s);default:return()=>!1}},Zt=(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()}},nn=s=>(t,e)=>{const n=Zt(t,s),i=Zt(e,s);return n!==i},Yf=s=>(t,e)=>{const n=Zt(t,s),i=Zt(e,s);return n>=i},Nf={1:Ef,2:If,3:Df,4:Lf,5:Of,6:Bf,7:Rf},Xf=(s,t,e)=>{var n;const i=Ff({start:Hf(s),end:kf(s)}),r=(n=Nf[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},To=(s,t)=>t===1?s===1:s/t===1,Mo=(s,t)=>t===1?!0:s%t===0,zf=s=>(t,e)=>Yf(s.key)(t,e),Wf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?To(Zt(t,s.key)+1,s.value):Mo(Zt(t,s.key)+1,s.value);return n&&i},Vf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?To(Zt(t,s.key),s.value):Mo(Zt(t,s.key),s.value);return n&&i},Uf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=Xf(t,s.week,s.weekday);return n&&i},Gf=s=>{switch(s.key){case"second":case"minute":return Zf(s.value);case"hour":return $f(s.value);case"day":return Kf(s.value);case"month":return Qf(s.value);case"year":return tg(s.value);case"week-weekday":const t=Jf(s.week),e=qf(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},Zf=s=>s>0&&s<=60,$f=s=>s>0&&s<=24,Kf=s=>s>0&&s<=31,qf=s=>Ao(s)?s>=1&&s<=7:!1,Jf=s=>s==="$"?!0:Ao(s)?s>=1&&s<=6:!1,Qf=s=>s>0&&s<=12,tg=s=>s>0,Ao=s=>!isNaN(s)&&isFinite(s),eg=(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 rn(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:eg(a,i,t)};n[r]=l,i=a}return n}const Eo=s=>{const t={},e={};return js(s).forEach(([n,i])=>{const r=wo(n),o=r===null?!1:Gf(r);if(r&&o){const a=So(r);t[a]=i,e[a]=jf(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Io{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?ft(d,h.animationConfig.targetZoomX):ft(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,p=Object.values(this.formatsByWeightMap).reduce((_,P)=>Math.max(P.length,_),1),v=f*p;return Math.round(v/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Eo(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(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>Ui(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}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}=Eo(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(t=[]){const e=this.getAllCandlesWithFake(t),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e);this.labelsGroupedByWeight=xo(i),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=rn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=xo(i),o=te(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const p=f.map(v=>(v.idx=v.idx+t.length,v.value=a.startUnit+a.width+v.value,v));r[u]?c[h]=d.concat(p):c[h]=p}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t){this.generateWeightedLabels(t)}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=Mf(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];Af(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=js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=wo(o);if(l){const c=So(l);i[c]=a}}return i},{});return js(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class sg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(ts,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const Do=3;class ng extends X{constructor(t,e,n,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,p=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(p,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(Do-1)):u=1+h/this.lastXPxWidth*(Do-1);const p=(this.lastXWidth*u-this.lastXWidth)/2,v=this.lastXStart-p,_=this.lastXEnd+p;(this.lastXStart!==v||this.lastXEnd!==_)&&this.scale.setXScale(v,_)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Le(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class ig extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=_=>this.xAxisScaleHandler.setDblClickCallback(_),this.setDblTapCallback=_=>this.xAxisScaleHandler.setDblTapCallback(_);const p=new Io(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=p,this.xAxisLabelsModel=new sg(t,[]);const v=new Us;c.addDrawer(v,"X_AXIS"),this.xAxisDrawer=new cs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),v.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new wf(e,n,o,this.xAxisLabelsModel),v.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new ng(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(x.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(J(({prependedCandles:t})=>t.length!==0),ct(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;fl.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(vt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ct(()=>yt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),At((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),J(Wn)).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 Io?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 rg=Object.defineProperty,Lo=Object.getOwnPropertySymbols,og=Object.prototype.hasOwnProperty,ag=Object.prototype.propertyIsEnumerable,Oo=(s,t,e)=>t in s?rg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,hs=(s,t)=>{for(var e in t||(t={}))og.call(t,e)&&Oo(s,e,t[e]);if(Lo)for(var e of Lo(t))ag.call(t,e)&&Oo(s,e,t[e]);return s};class lg{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&&hs(hs({},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&&hs(hs({},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=yt(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 h=t.config.type==="scatterPlot"?r:Lu(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,h,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):qt(l,r,o),rounded:!0}}}class cg{constructor(t,e,n,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=n,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,n=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(x.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>kr(t,n,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>kr(t,n,e,r,o,l,this.canvasBoundsContainer,i.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(q));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];hr(e,{x:h.x,y:vi(d,h)},{x:h.x+h.width-6,y:vi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class hg{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;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=Jt(e.state),a=jt(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 f=a.scale.toY(u.value);f>h&&f<d&&dg(t,n,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const 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 ug{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&$a.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(ts,t)}}class fg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ct(r=>i.components.chart.highlightActiveCandle?r:void 0),At()).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 gg{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_${bt()}`,this.canvasResized=new O,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){be(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(zs,e),this.bus.fire(ts))}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 pg=Array.isArray,mg=Object.getPrototypeOf,vg=Object.prototype,bg=Object.keys;function Cg(s){if(s.length===1){var t=s[0];if(pg(t))return{args:t,keys:null};if(yg(t)){var e=bg(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"&&mg(s)===vg}var wg=Array.isArray;function Sg(s,t){return wg(t)?s.apply(void 0,I([],m(t))):s(t)}function xg(s){return ct(function(t){return Sg(s,t)})}function _g(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Pg(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=pa(s),i=Cg(s),r=i.args,o=i.keys;if(r.length===0)return Ye([],e);var a=new pt(Tg(r,e,o?function(l){return _g(o,l)}:le));return n?a.pipe(xg(n)):a}function Tg(s,t,e){return e===void 0&&(e=le),function(n){Bo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){Bo(t,function(){var d=Ye(s[h],t),u=!1;d.subscribe(mt(n,function(f){r[h]=f,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function Bo(s,t,e){s?Ht(e,s,t):t()}class Mg extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,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=Pg([n,i]).pipe(J(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!kt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Ag(s,t){return Y(function(e,n){var i=null,r=0,o=!1,a=function(){return o&&!i&&n.complete()};e.subscribe(mt(n,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(s(l,h)).subscribe(i=mt(n,function(d){return n.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Eg{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 Ig{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 Eg(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Dg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof Pr)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 Lg=Object.defineProperty,Og=Object.defineProperties,Bg=Object.getOwnPropertyDescriptors,Ro=Object.getOwnPropertySymbols,Rg=Object.prototype.hasOwnProperty,Fg=Object.prototype.propertyIsEnumerable,Fo=(s,t,e)=>t in s?Lg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Oe=(s,t)=>{for(var e in t||(t={}))Rg.call(t,e)&&Fo(s,e,t[e]);if(Ro)for(var e of Ro(t))Fg.call(t,e)&&Fo(s,e,t[e]);return s},on=(s,t)=>Og(s,Bg(t));class Hg extends X{constructor(t,e,n,i,r,o,a,l,c,h){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.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new Ig(this.chartModel),u=new Dg(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Ag(()=>this.scale.initialViewportValidSubject.pipe(J(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(vt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((n=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:n.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var n,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!eo(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(n=this.crossEventProducer.crossToolHover)==null?void 0:n.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(x.PANE_UUID(d)),f=u.y+5,p=u.y+u.height-5,v=c-l.x,_=h-l.y,P=a.x<0?0:a.x>u.width?u.width:a.x+=v,L=a.y<f?f:a.y>p?p:a.y+=_;this.crossEventProducer.crossToolTouchInfo.fixed={x:P,y:L}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=Yr(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,q)}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)=>on(Oe({},l),{[c[0]]:c[1].getData(o)}),{});return Oe(Oe({},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=on(Oe({},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,n;if(t){if(kt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(n=t.candleHover)==null?void 0:n.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=on(Oe({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const Ho={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 pe(s){return t=>{t.button===Ho.left&&s(t)}}var kg=Object.defineProperty,ko=Object.getOwnPropertySymbols,jg=Object.prototype.hasOwnProperty,Yg=Object.prototype.propertyIsEnumerable,jo=(s,t,e)=>t in s?kg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ng=(s,t)=>{for(var e in t||(t={}))jg.call(t,e)&&jo(s,e,t[e]);if(ko)for(var e of ko(t))Yg.call(t,e)&&jo(s,e,t[e]);return s};const re=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=re.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Ng({},this.dragStartPoint),re.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===Ho.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=[],re.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),re.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))}),re.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,pe(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,pe(e=>this.clickDocumentSubject.next(e)),"click"));const s=Qr();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=200)=>{o.preventDefault();let l=!1,c=null;c=setTimeout(()=>{l=!0,this.longTouchStartSubject.next(o)},a);const h=u=>{u.preventDefault(),u.touches.length>1&&c&&clearTimeout(c)},d=u=>{u.preventDefault(),c&&clearTimeout(c),l&&(l=!1,this.longTouchEndSubject.next(u)),this.element.removeEventListener("touchend",d),this.element.removeEventListener("touchmove",h)};this.element.addEventListener("touchmove",h),this.element.addEventListener("touchend",d)};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,f=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,p=d<=250;f&&p&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,pe(()=>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,pe(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,pe(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,pe(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(zs).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(){re.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(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(J(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ct(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(J(()=>!(t&&this.dragging)),ct(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ct(()=>!1));return vt(e,n).pipe(At())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(J(()=>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(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)),ho(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let ds=re;ds.DRAG_START_EVENTS=["mousedown","touchstart"],ds.DRAG_EVENTS=["mousemove","touchmove"],ds.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var Xg=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Fs);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 an={};function zg(s){return an[s]||(an[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"})),an[s]}const Yo=(s,t=Date.now())=>{const n=zg(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},No=60*1e3;class Wg{constructor(t){this.config=t,this.timeZoneChangedSubject=new Xg,this.currentTzOffset=e=>Yo(this.config.timezone,e)+new Date(e).getTimezoneOffset()*No,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=Pd(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+Yo(t,e)+new Date(e).getTimezoneOffset()*No):e=>new Date(e)}}class Vg 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(At((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class ln{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;gl(r),this.config=r;const o=Rl(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 Wg(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Fl(t);this.elements=c;const h=new ug;this.bus=h;const d=new gg(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 Ph(h,d);this.drawingManager=u;const f=xh(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=ie(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const p=new fe(this.dynamicObjectsCanvasModel);u.addDrawer(p,"SERIES_CLEAR");const v=ie(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),_=ie(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),P=new Rs(r,h,f,l,d);this.canvasBoundsContainer=P;const L=c.mainCanvas.parentElement;if(L===null)throw new Error("Couldn't get main canvas parent");const F=new ds(h,L);this.canvasInputListener=F,this.chartComponents.push(this.canvasInputListener);const k=new jd(h,c.hitTestCanvas,F,P,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=k;const H=new fe(k);u.addDrawer(H,"HIT_TEST_CLEAR");const B=new Na(h);this.canvasAnimation=B;const N=x.PANE_UUID(q),W=new lr(r,()=>P.getBounds(N),B);this.scaleModel=W;const G=ie(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=G,this.cursorHandler=new Ll(c.canvasArea,F,P,k),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Mg(F,P),this.chartComponents.push(this.crossEventProducer);const V=new uc("candle");this.chartBaseModel=V;const U=new Su(h,W,P,r,B,F,L,V,k);this.chartPanComponent=U,this.chartComponents.push(U),this.userInputListenerComponents.push(U.chartAreaPanHandler);const $=new Vg(k,B,h);this.hitTestComponent=$,this.chartComponents.push($);const Z=new sf(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,P,r,B,F,u,this.cursorHandler,this.crossEventProducer,U,f,v,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=Z;const et=this.paneManager.panes[q];this.mainPane=et,this.chartComponents.push(Z),this.dynamicObjects=new xd(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new ed(V,Z,h,this.dynamicObjectsCanvasModel,r,W,l,L,P,d);const tt=new kh(this.chartModel,this.dynamicObjectsCanvasModel,r,W,P,u,k,F,G,U,Z,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),k.addSubscriber(Z.hitTestController),this.xAxisComponent=new ig(h,r,f,tt,W,P,F,d,this.drawingManager,a,U,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const rt=new fe(f);u.addDrawer(rt,"MAIN_CLEAR");const dt=new fg(L,Q,F,r);this.chartComponents.push(dt),this.watermarkComponent=new Cf(Z,Q,h,r,P,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=ie(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new iu(h,r,Q,f,P,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new fu(h,Q,f,r,F,P,u,l,U,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const xt=new qd(r,this.dynamicObjectsCanvasModel,Q,P,u);this.chartComponents.push(xt),this.initYAxisDrawer(v,_),this.yAxisComponent=et.mainExtent.yAxis;const oe=new lg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(oe,Qt.MAIN),this.volumesComponent=new ff(this.dynamicObjectsCanvasModel,tt,W,P,u,r,Z,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const me=new Gr(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(N),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,()=>r.components.grid.visible);this.chartComponents.push(me),this.hoverProducer=new Hg(this.crossEventProducer,W,r,Q,F,this.canvasBoundsContainer,this.paneManager,a,U.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new Cd(r,ot,P,u,Z,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel),this.chartComponents.push(this.crossToolComponent);const Uo=ie(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),cn=new nf(this.elements,Uo);this.snapshotComponent=cn,this.chartComponents.push(cn);const hn=new Zd(r,this.dynamicObjectsCanvasModel,k,Q,P,u,l,this.cursorHandler);this.eventsComponent=hn,this.chartComponents.push(hn),this.chartComponents.forEach(dn=>dn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=za(this.components)}initYAxisDrawer(t,e){const n=new Us,i=new fe(t),r=new fe(e);n.addDrawer(i,"YAXIS_CLEAR"),n.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(n,"Y_AXIS");const o=new hg(this.config,t,this.paneManager);n.addDrawer(o);const a=new cg(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&ln.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){Tt(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=vt(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 Xo extends ln{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.data.setChartType(t),this.yAxis.updateOrderedLabels()}createPane(){return this.paneManager.createPane()}}var Ug=Object.defineProperty,Gg=Object.defineProperties,Zg=Object.getOwnPropertyDescriptors,zo=Object.getOwnPropertySymbols,$g=Object.prototype.hasOwnProperty,Kg=Object.prototype.propertyIsEnumerable,Wo=(s,t,e)=>t in s?Ug(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,qg=(s,t)=>{for(var e in t||(t={}))$g.call(t,e)&&Wo(s,e,t[e]);if(zo)for(var e of zo(t))Kg.call(t,e)&&Wo(s,e,t[e]);return s},Jg=(s,t)=>Gg(s,Zg(t));function Vo(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=us(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ep(t[t.length-1],a,n)):d>3?t=t.concat(Qg(t[t.length-1],a,r)):t=t.concat(tp(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 f=0;f<t.length;f++){const p=t[f];Object.assign(p,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(p.volume=Math.ceil(Math.random()*1e3+200))}return t}function us(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{id:ei(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function Qg(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=us(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 tp(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=us(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 ep(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var f,p;return Math.random()>.5?(f=u.lo-t*.2,p=u.hi+t*1.2):(f=u.lo-t*1.2,p=u.hi+t*.2),{from:f,to:p}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=us(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=Jg(qg({},window.DXChart),{generateCandlesData:Vo});function sp(s){return Vo(s)}const np=(s,t={})=>new Xo(s,t)})(),window.DXChart=fs})();})();
24
+ `;function Ol(s){const t=document.createElement("template");return t.innerHTML=Ll(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}),Dl(t))return t;throw new Error("Some chart elements are missing")}function Rl(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 Te=(s,t,e,n=1e3)=>{var i,r,o,a;const l=(r=(i=ce(e))==null?void 0:i.timestamp)!=null?r:0,c=(a=(o=yt(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:it((s-l)/n),exact:!0}:{index:-1,exact:!0}:Ot(e,s,h=>h.timestamp)},xi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},_i={paintConfig:[xi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var Fl=Object.defineProperty,Pi=Object.getOwnPropertySymbols,Hl=Object.prototype.hasOwnProperty,kl=Object.prototype.propertyIsEnumerable,Ti=(s,t,e)=>t in s?Fl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,jl=(s,t)=>{for(var e in t||(t={}))Hl.call(t,e)&&Ti(s,e,t[e]);if(Pi)for(var e of Pi(t))kl.call(t,e)&&Ti(s,e,t[e]);return s};class Yl{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:[jl({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:xi).color;return{textColor:Jt(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function Nl(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)=>Xl(a,l,e)).filter(Wn).sort(zl),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 Xl=(s,t,e)=>s?{top:s.y-e/2,bottom:s.y+e/2,labelWeight:s.weight,actualIndex:t}:null,zl=(s,t)=>{const e=s.top,n=t.top;return e>n?1:e<n||e===n&&s.labelWeight<t.labelWeight?-1:0};var Wl=Object.defineProperty,Vl=Object.defineProperties,Ul=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,Gl=Object.prototype.hasOwnProperty,Zl=Object.prototype.propertyIsEnumerable,Ai=(s,t,e)=>t in s?Wl(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ei=(s,t)=>{for(var e in t||(t={}))Gl.call(t,e)&&Ai(s,e,t[e]);if(Mi)for(var e of Mi(t))Zl.call(t,e)&&Ai(s,e,t[e]);return s},Ii=(s,t)=>Vl(s,Ul(t));const te={MAIN:"MAIN"};class $l extends X{constructor(t,e,n,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=n,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new R,this.animFrameId=`anim_cache_${bt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,vt(this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,n])=>{this.addToGroup(n,t,e)})}updateLabels(t=!1){this.recalculateLabels(),be(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=Ct(Object.values(i).map(l=>l.getUnorderedLabels())),o=Ct(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=Nl(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 Ii(Ei({},t),{labels:t.labels.map((n,i)=>Ii(Ei({},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()}}let Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Hs=()=>{Ke.removeEventListener("change",Hs),Bt=window.devicePixelRatio,Ke=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),Ke.addEventListener("change",Hs)};Ke.addEventListener("change",Hs);const Kl=()=>Bt,Dp=s=>round(Bt*s)/Bt,Mt=s=>it(Bt*s)/Bt,ks=s=>Ta(Bt*s)/Bt,ee=s=>JSON.parse(JSON.stringify(s));function js(s){return Object.entries(s)}const Di=(s,t)=>{for(const[e,n]of Array.from(s.entries()))if(n===t)return e};function Li(s){return Object.keys(s)}function Oi(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])||!Oi(s[e[i]],t[e[i]]))return!1;return!0}const ql=s=>Object.keys(s).length===0&&s.constructor===Object;function Bi(s){s===void 0&&(s={});var t=s.connector,e=t===void 0?function(){return new R}: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,f=0,p=!1,v=!1,P=function(){d==null||d.unsubscribe(),d=void 0},_=function(){P(),h=u=void 0,p=v=!1},D=function(){var O=h;_(),O==null||O.unsubscribe()};return N(function(O,j){f++,!v&&!p&&P();var H=u=u!=null?u:e();j.add(function(){f--,f===0&&!v&&!p&&(d=Ys(D,l))}),H.subscribe(j),!h&&f>0&&(h=new ve({next:function(B){return H.next(B)},error:function(B){v=!0,P(),d=Ys(_,i,B),H.error(B)},complete:function(){p=!0,P(),d=Ys(_,o),H.complete()}}),Dt(O).subscribe(h))})(c)}}function Ys(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 ve({next:function(){i.unsubscribe(),s()}});return Dt(t.apply(void 0,I([],m(e)))).subscribe(i)}}const qe=(s,t)=>s/t,ft=(s,t)=>s/t,Nt=(s,t)=>s*t,Ri=(s,t)=>(s-t)*100/t,Fi=(s,t)=>s*t/100+t,Hi=s=>Math.log2(s),Ns=s=>Math.pow(2,s);class Jl extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new R,this.xChanged=this.changed.pipe(ht(()=>({start:this.xStart,end:this.xEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.yChanged=this.changed.pipe(ht(()=>({start:this.yStart,end:this.yEnd})),At((t,e)=>t.start===e.start&&t.end===e.end),Bi()),this.initialViewportValidSubject=new ut(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+ft(t-this.xStart,this.zoomX)}xPixels(t){return ft(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+ft(t-this.yStart,this.zoomY):e.y+e.height-ft(t-this.yStart,this.zoomY)}yPixels(t){return ft(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Nt(e+ft(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),n=t-e.y;return this.inverseY?Nt(n+ft(this.yStart,this.zoomY),this.zoomY):Nt(e.height-n+ft(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 qe(e-t,this.getBounds().width)}calculateZoomY(t,e){return qe(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(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const Ql=(s,t)=>!Li(s).some(e=>s[e]!==t[e]);class tc{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(Ot(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Ot(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),n=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else n=t();return n}}class ki{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 tc(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const n=this.percentAnimationHandler.getBaselineForPercent(e);return Ri(t,n);case"logarithmic":return t<=0?t:Hi(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 Fi(t,this.getBaseline());case"logarithmic":return Ns(t);case"regular":return t}}}var ec=Object.defineProperty,sc=Object.defineProperties,nc=Object.getOwnPropertyDescriptors,ji=Object.getOwnPropertySymbols,ic=Object.prototype.hasOwnProperty,rc=Object.prototype.propertyIsEnumerable,Yi=(s,t,e)=>t in s?ec(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ni=(s,t)=>{for(var e in t||(t={}))ic.call(t,e)&&Yi(s,e,t[e]);if(ji)for(var e of ji(t))rc.call(t,e)&&Yi(s,e,t[e]);return s},oc=(s,t)=>sc(s,nc(t));class Me{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Mt(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Me(this.centerUnit,this.close)}}class Xi extends X{constructor(t,e,n,i,r=ee(_i)){var o;super(),this.extentComponent=t,this.id=e,this.htId=n,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=a=>{var l;return(l=this.config.paintConfig[a])!=null?l:this.config.paintConfig[0]},this.getBaseline=(a=this.dataIdxStart)=>{var l,c,h;return(l=this.visualPoints[a])!=null&&l.close&&((c=this.visualPoints[a])==null?void 0:c.close)>=0?(h=this.visualPoints[a])==null?void 0:h.close:1},this.getTextForPoint=a=>`${a.close}`,this.getLastVisualSeriesPoint=()=>{const a=this.visualPoints,l=Ot(a,this.scale.xEnd,c=>c.centerUnit).index;return a[l]},this.getLastDataSeriesPoint=()=>{const a=this.visualPoints;return yt(a)},this.config=Tt(r,_i),this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Yl(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=lc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=Gn(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=Gn(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.recalculateDataViewportIndexes())),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const n=Ni({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new ki(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=n.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[te.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(te.MAIN,a,r),n.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(te.MAIN,r))}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=Ot(this.visualPoints,t,r=>r.centerUnit).index,i=Ot(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(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 Va(this.visualPoints2D,n,i)}}const ac=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},lc=s=>({isHighLowActive:()=>s.config.highLowActive,calculateHighLow:t=>{const e=ac(s.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return oc(Ni({},e),{high:s.view.toAxisUnits(e.high),low:s.view.toAxisUnits(e.low)})}}),cc=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 Je extends Me{constructor(t,e,n,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=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 Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),n=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>n?[n,e]:[e,n];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const de=60,Ae=(s,t,e=de)=>{const n=zi(s,t,e);return{id:ei(n,n),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:n,volume:NaN,expansion:!0,idx:t}},hc=(s,t,e=de)=>({close:NaN,timestamp:zi(s,t,e)});function zi(s,t,e=de){var n,i;const r=ye(t);if(s.length===0)return 0;const o=yt(s);if(r>=s.length&&o)return Wi(o,s.length-1,r,e);const a=ce(s);return r<0&&a?Wi(a,0,r,e):(i=(n=s[r])==null?void 0:n.timestamp)!=null?i:0}const Wi=(s,t,e,n=de)=>s.timestamp+(e-(t!=null?t:0))*n,Vi=(s,t,e,n,i=de)=>{const r=Ae(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 Je(o,e,r.open,r.close,r.lo,r.hi,Ue(r.open,r.close),r)},dc=(s,t,e,n,i=de)=>{const r=hc(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 Me(o,r.close)};class uc{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new R,this.dataSetSubject=new R,this.dataRemovedSubject=new R,this.dataPrependSubject=new R,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e=!0,n=this.mainDataPoints){const i=Te(t,e,n,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=Rl(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?Vi(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):dc(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var fc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,gc=Object.prototype.hasOwnProperty,pc=Object.prototype.propertyIsEnumerable,Gi=(s,t,e)=>t in s?fc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,mc=(s,t)=>{for(var e in t||(t={}))gc.call(t,e)&&Gi(s,e,t[e]);if(Ui)for(var e of Ui(t))pc.call(t,e)&&Gi(s,e,t[e]);return s};class vc{constructor(t,e,n=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=n,this.prevState={},this.isColorsChanged=()=>!Oi(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=mc({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const bc=(s,t,e,n,i,r,o)=>{const a=Kl(),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]=it(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?it(u*o):it(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},Zi=(s,{x:t,width:e,activeCandle:n})=>new Je(t,e,s.open,s.close,s.hi,s.lo,Ue(s.open,s.close),s,!0,Xs(s,n)),Cc=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,il((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},$i=(s,{x:t,width:e,activeCandle:n,prevCandle:i})=>{var r;return new Je(t,e,s.open,s.close,s.hi,s.lo,Ue((r=i==null?void 0:i.close)!=null?r:s.close,s.close),s,!0,Xs(s,n),s.close>s.open)},yc=$i,Xs=(s,t)=>{const e=t&&t.id===s.id;return e!=null?e:!1},Ki=()=>Ds,se=class{static autoDetectIncrementOfValueRange(s){const t=this.getDigitsInNumber(s);return s===0?.01:Math.pow(10,t-3)}static getDigitsInNumber(s){const t=n=>it(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=se.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]=se.calculatePrecision(s[e]);for(let e=1;e<s.length;e+=2)t[e]=s[e]+Math.min(s[e-1],s[e+1])*se.RELATIVE_EPS;return t}static calculatePrecision(s){let t=s>1?Math.abs(Math.floor(s)-s):s;for(let e=0;e<se.MAXIMUM_PRECISION;e++){const n=Math.floor(t+.5),i=Math.abs(t*se.RELATIVE_EPS);if(n>=t-i&&n<=t+i)return e;t*=10}return se.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(s){return!(s.length===0||!Array.isArray(s)||s.findIndex(t=>t!==0)===-1)}};let Rt=se;Rt.DEFAULT_INCREMENT=.01,Rt.DEFAULT_PRECISION=2,Rt.RELATIVE_EPS=1e-8,Rt.MAXIMUM_PRECISION=10;const wc=(s,t)=>{var e;const n=(e=yt(t))!=null?e:1;return Math.pow(10,-n)};var Sc=Object.defineProperty,xc=Object.defineProperties,_c=Object.getOwnPropertyDescriptors,qi=Object.getOwnPropertySymbols,Pc=Object.prototype.hasOwnProperty,Tc=Object.prototype.propertyIsEnumerable,Ji=(s,t,e)=>t in s?Sc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Mc=(s,t)=>{for(var e in t||(t={}))Pc.call(t,e)&&Ji(s,e,t[e]);if(qi)for(var e of qi(t))Tc.call(t,e)&&Ji(s,e,t[e]);return s},Ac=(s,t)=>xc(s,_c(t));const Ec=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=Qi(o),l=()=>{var c,h;return(h=(c=s.visualPoints[i])==null?void 0:c.close)!=null?h:1};return Ac(Mc({},a),{low:s.view.toAxisUnits(a.low,l),high:s.view.toAxisUnits(a.high,l)})}}),Qi=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},Ic=400,tr=(s,t,e)=>{const n=s.startViewportMovementAnimation(t,{duration:Ic,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},We,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=n};class Dc{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){Lc(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const Lc=(s,t,e,n)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=er(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 er(s){if(s.length===0)return Oc();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 Oc=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),sr=(s,t)=>s/t,Bc=(s,t)=>s/t,Rc=(s,t)=>s*t,nr=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.yEnd-s.yStart;t.zoomY=Bc(t.zoomX,i);const o=t.zoomY/n,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},Fc=(s,t)=>{const e=s.zoomX,n=s.zoomY,i=sr(e,n),r=s.xEnd-s.xStart;t.zoomX=Rc(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},Hc=(s,t)=>{const e=s.xStart;s.xStart=t,s.xEnd=s.xEnd+(t-e)},kc=(s,t)=>{const e=s.yStart;s.yStart=t,s.yEnd=s.yEnd+(t-e)},ir=(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},jc=(s,t,e,n)=>ir(s,t,1,e,n);var Yc=Object.defineProperty,Nc=Object.defineProperties,Xc=Object.getOwnPropertyDescriptors,rr=Object.getOwnPropertySymbols,zc=Object.prototype.hasOwnProperty,Wc=Object.prototype.propertyIsEnumerable,or=(s,t,e)=>t in s?Yc(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Qe=(s,t)=>{for(var e in t||(t={}))zc.call(t,e)&&or(s,e,t[e]);if(rr)for(var e of rr(t))Wc.call(t,e)&&or(s,e,t[e]);return s},Vc=(s,t)=>Nc(s,Xc(t));const Uc=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class ar extends Jl{constructor(t,e,n){super(),this.config=t,this.getBounds=e,this.canvasAnimation=n,this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=ee(t.scale),this.autoScaleModel=new Dc(this),this.offsets=this.config.components.offsets}doActivate(){super.doActivate(),this.scaleInversedSubject=new R,this.beforeStartAnimationSubject=new R,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=Qe(Qe({},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();ir(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();jc(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){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),n?this.apply(o):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const n=this.getBounds().width,i=.001;if(n>0){const r=qe(this.config.components.chart.minCandles,n),a=t!==r&&t-r<=i&&e,l=qe(n/this.config.components.chart.minWidth,n),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,n=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Vc(Qe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&nr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),n||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),tr(this.canvasAnimation,this,l)))}setYScale(t,e,n=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio){this.setLockedYScale(t,e,n,i);return}super.setYScale(t,e,n);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,n=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,n);const o=this.export(),a=this.scalePostProcessor(i,o);Fc(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),n=Qe({},e);this.haltAnimation(),Hc(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();kc(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Ql(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}}class Gc extends ar{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 Zc=Ge().colors;class Ut extends Xi{constructor(t,e,n,i,r,o,a,l,c=Zc){super(t,e,n),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=Uc(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new R,this.meanCandleWidth=Ds,this._instrument=o,this.instrument=o,this.highLowProvider=Ec(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=Rt.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=Ot(this.visualPoints,t,r=>r.startUnit).index,i=Ot(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:n,dataIdxEnd:i}}applyPriceMovement(){const t=yt(this.dataPoints);t&&(this.lastPriceMovement=Ue(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Qi(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=Tt(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var n,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(n=this.candleWidthByChartType[r])!=null?n:Ki;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,p=(i=this.candlesTransformersByChartType[r])!=null?i:Zi;o.push(p(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,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 Lp(s){switch(s){case"line":case"area":return!0;default:return!1}}class $c{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=!!i.color;if(n instanceof Ut){const a=Ct(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=n.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:n.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=n.extentComponent.getBounds(),c=a[0],h=n.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],p=a[d],v=n.view.toX(p.centerUnit),P=n.view.toY(p.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(it(v),_),t.moveTo(it(v),P);else if(f===void 0){t.lineTo(it(v),P),t.stroke(),t.lineTo(it(v),_),t.lineTo(it(h),_),t.closePath();let D;i.color?t.fillStyle=i.color:t.fillStyle=n.colors.areaTheme.startColor&&n.colors.areaTheme.stopColor?(D=t.createLinearGradient(0,0,0,l.height),D.addColorStop(0,n.colors.areaTheme.startColor),D.addColorStop(1,n.colors.areaTheme.stopColor),D):"",o||t.fill()}else t.lineTo(v,P)}}}}function lr(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 Kc(s,t,e,n,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,p=c==="right"?h:-h,v=h;s.save(),s.beginPath(),l?s.moveTo(r+p,o):s.moveTo(r,o),l?(s.lineTo(r+f-p,o),s.quadraticCurveTo(r+f,o,r+f,o-v),s.lineTo(r+f,e+v),s.quadraticCurveTo(r+f,e,r+f-p,e),s.lineTo(t+p,e)):(s.lineTo(r+f,o),s.lineTo(r+f,e),s.lineTo(t,e)),l?(s.quadraticCurveTo(t,e,t-p/3,e+v/3),s.lineTo(n+p/3,i-v/3),s.quadraticCurveTo(n,i,n+p/3,i+v/3),s.lineTo(r-p/3,o-v/3),s.quadraticCurveTo(r,o,r+p/3,o)):(s.lineTo(n,i),s.lineTo(r,o)),s.closePath(),d&&s.fill(),u&&s.stroke(),s.restore()}function qc(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 ne(s,t){s.save(),s.lineWidth%2&&s.translate(.5,.5),t(),s.restore()}function cr(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 Gt=(s,t)=>{s.beginPath(),s.rect(t.x,t.y,t.width,t.height),s.clip(),s.closePath()},Op=s=>Array.isArray(s[0])?s:[s];class Jc{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&&Gt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const n=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||n&&!ql(n)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const ie=(s,t,e,n,i=t)=>{n.hoverWidth?s.lineWidth=n.hoverWidth:e.highlighted?s.lineWidth=t!==i?t+1:i:s.lineWidth=t};class Qc{constructor(t){this.config=t}setFillStyle(t,e,n,i){if(e.color)t.strokeStyle=e.color;else{const r=n.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.barLineWidth,n,i),ne(t,()=>{for(const o of r){this.setFillStyle(t,i,n,o),t.beginPath();const a=n.view.toX(o.centerUnit),l=n.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(n.view),f=Mt(n.view.xPixels(o.width)/2),p=n.view.toY(o.close),v=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,p),t.lineTo(a+f,p),t.moveTo(l,v),t.lineTo(a,v),t.stroke()}})}}}class th{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,n,i){if(i!==void 0&&n instanceof Ut){const r=Ct(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],f=r[h+1],p=n.view.toX(c.centerUnit),v=n.view.toX(d.centerUnit),P=n.view.toY(d.close),_=u?n.view.toY(u.close)<l:!1,D=P<l;if(u!==void 0&&_!==D){hr(t,n,i,_);const O=n.view.toX(u.centerUnit),j=n.view.toY(u.close),H=v-O,B=P-j,Y=H/B,W=P-l,G=Y*W,V=O+(H-G);t.lineTo(V,l),t.stroke(),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(V,l)}u===void 0?(t.beginPath(),t.moveTo(v,P)):f===void 0?(hr(t,n,i,D),t.lineTo(v,P),t.stroke(),t.lineTo(v,l),t.lineTo(p,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(p,l),t.lineTo(v,l),t.strokeStyle=n.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(v,P)}}}}const hr=(s,t,e,n)=>{e.color?(s.fillStyle=e.color,s.strokeStyle=e.color):(s.fillStyle=n?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,s.strokeStyle=n?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class eh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.candleLineWidth,n,i,this.config.candleLineWidth),ne(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.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=n.view.toX(i.startUnit),d=n.view.xPixels(i.width),u=i.bodyHeight(n.view),[f,p,v,P]=i.yBodyKeyPoints(n.view),_=p===v?p+1:v,D=f===P?f+1:P,O=l[`${a}Color`],j=a==="none"?O:l[`${a}WickColor`];t.fillStyle=O,e.color?t.strokeStyle=e.color:t.strokeStyle=j;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:p),t.lineTo(h,B?D:_),t.moveTo(h+1,p),t.lineTo(h+1,_),t.stroke();else if(d===3){const Y=d/Bt;this.drawCandlesWicks(t,h+Y,f,D,p,_),c||(t.beginPath(),t.moveTo(h+Y,p),t.lineTo(h+Y,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,p+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const Y=i.x(n.view);this.drawCandlesWicks(t,Y,f,D,p,_);const W=this.config.candlePaddingPercent,G=Math.max(d*W/2,this.pixelLength),V=h+G,U=d-G*2;if(!c){e.color&&(t.fillStyle=e.color);const Z=e.hoverWidth?d+G:U,$=e.hoverWidth?u+e.hoverWidth+G:u;t.fillRect(V,p,Z,$)}H&&this.drawCandleBorder(t,e,l,i,V+this.halfLineWidthCU,p+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.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?n[`${c}Color`]:n[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class sh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){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.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(n.view),f=n.view.toY(l.close),p=Mt(n.view.xPixels(l.width));t.fillRect(u,f,p,h);const v=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(v.addColorStop(0,d[`${c}Cap`]),v.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=v),p===0?(t.beginPath(),t.strokeStyle=v,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,p,a-f-h)}}}}class nh{constructor(t){this.config=t}draw(t,e,n,i){if(n instanceof Ut){const r=Ct(e);ie(t,this.config.lineWidth,n,i,this.config.selectedWidth);const o=n.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=n.view.toX(l.centerUnit),u=n.view.toY(l.close),f=n.view.toX(c.centerUnit),p=n.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,p),t.stroke()}}}}const ih=1.5;class rh{constructor(t){this.config=t}draw(t,e,n,i){var r;const o=i.hoverWidth?i.hoverWidth/2:ih;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of Ct(e)){t.beginPath();const l=n.view.toX(a.centerUnit),c=n.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const oh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class ah{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(),Gt(t,this.chartBounds())}isChartTypeAllowed(){return oh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Gt(t,e.scale.getBounds())}}class lh{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.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(it(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Mt(ft(h.width,u)),p=Mt(h.bodyHeight(this.chartModel.scale)),v=h.xCenter(this.chartModel.scale)-f/2,P=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,D=Mt(f*_/2),O=v+D,j=f-D*2;t.fillRect(O,P,j,p)}})})}}const ch=(s,t,e,n)=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);n===0?t.moveTo(o,a):t.lineTo(o,a)},dr=(s,t,e)=>{s.length!==0&&s.forEach((n,i)=>{ch(n,t,e,i)})},hh=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,dh=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,uh=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,fh=s=>hh.exec(s),gh=s=>dh.exec(s),Bp=s=>uh.exec(s);function ph(s){const t=fh(s)||gh(s);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(n){return parseInt(n,16)}):e}const ur={};function mh(s,t){let e=ur[s+t];if(!e){const n=ph(s);e=n&&"rgba("+n.join(",")+","+t+")",ur[s+t]=e}return e}class vh{constructor(){}draw(t,e,n,i){n.config.visible&&(e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth);const c=(a=i.color)!=null?a:l.color;t.strokeStyle=c,this.drawLine(t,r,n.view)}),n.linkedDataSeriesModels.forEach((r,o)=>{if(fr(r.config.type)&&fr(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)=>{var f,p;const v=Math.min(d.length,(p=(f=h[u])==null?void 0:f.length)!=null?p:0);for(let D=0;D<v;D++){const O=[d[D].clone(),h[u][D].clone()];a.push({diffPoints:O})}const P=l.getPaintConfig(u).color,_=r.getPaintConfig(o).color;this.drawDifference(t,P,_,a,l,r,i)})}}))}drawLine(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}drawDifference(t,e,n,i,r,o,a){const[l,c]=[[],[]];i.forEach(u=>{const[f,p]=u.diffPoints;l.push(f),c.push(p)});const h=this.mapDataSeriesDiffPointsIntoPoints(l,r.view),d=this.mapDataSeriesDiffPointsIntoPoints(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=ce(n))==null?void 0:o.x)!=null?a:0,d=(c=(l=yt(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,f)=>{f===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.color?r.color:mh(e||"#383838",.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(n=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const fr=s=>s==="DIFFERENCE";class bh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0);e.forEach((o,a)=>{var l;const c=n.getPaintConfig(a);ie(t,c.lineWidth,n,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=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,it(r)),t.lineTo(d,it(u))}),t.stroke()})}}class Ch{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o);ie(t,l.lineWidth,n,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,n.view)})}drawLinePath(t,e,n){t.beginPath(),dr(e,t,n),t.stroke()}}class yh{constructor(){}draw(t,e,n,i){e.forEach((r,o)=>{var a;const l=n.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=n.view.toX(h.centerUnit),u=n.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class wh{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.color)!=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),f=jt(c,t),p=n.view.toX(h.centerUnit)-u/2,v=n.view.toY(h.close)+f;t.fillText(d,p,v)})}),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.color)!=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 zs="resized_local",ts="draw",Rp="draw_last_candle",ue={width:20,height:20};class gr{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=Ws;var a;i.push(this),this.parent=Ph(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>ue.width&&this.height>ue.height}}const Ws={name:"candle"},xh={candle:Ws,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function _h(s,t,e,n,i,r,o){var a;const l=re(s,t,i,r,o,e);return l.type=(a=xh[n])!=null?a:Ws,l}function re(s,t,e,n,i,r,o){const a=new gr(s,t,n,i,r,o);return pr(a,e),a}function pr(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 Ph(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}const es="HIT_TEST_",jp=null;class Th{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${bt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(n=>{n.indexOf(es)!==-1&&this.drawersMap[n].draw()})},t.on(ts,n=>{e.wasResized()&&(this.canvasIdsList&&(n&&n.length!==0?this.canvasIdsList=this.canvasIdsList.concat(n):this.canvasIdsList=void 0),Yn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(es)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(es)===-1){const n=this.drawersMap[e];if(!t||t.length===0){n.draw();return}Xa(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)>ue.width&&((i=(n=this.chartResizeHandler.previousBCR)==null?void 0:n.width)!=null?i:0)>ue.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=bt()){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=Vn(this.drawingOrder,t)}}class mr{static paneResizer(t){return`PANE_RESIZER_${t}`}}const Mh=7;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(),Gt(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={color:this.canvasModel.idToColor(e.htId),hoverWidth:Mh};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const vr={dragPredicate:()=>!0};class br 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 ss extends br{constructor(t,e,n,i,r=vr){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 Eh="BASELINE_RESIZER";class Ih 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.dragPredicate=new ut(!1),this.baselineYPercents=50,this.ht=Rs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(x.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&Sl(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new ss(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[Eh]=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 Dh=16,Lh=s=>{var t;try{const e=Ce(s.close,s.open,s.hi,s.lo);if(!isFinite(e))throw new Error("Received candle without any price");const n=Ce(s.hi,Math.max(s.open,s.close),e),i=Ce(s.lo,Math.min(s.open,s.close),e),r=Ce(s.open,s.lo,e),o=Ce(s.close,s.hi,e),a=Number.isNaN(s.vwap)?void 0:s.vwap;return{id:s.id,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,vwap:a,typicalPrice:s.typicalPrice}}catch(e){console.warn(e);return}},Ee=(s,t=0)=>{for(let e=t;e<s.length;++e)s[e].idx=e},Cr=s=>{s.forEach(t=>{t.idx=void 0})},Oh=s=>s!==void 0;class Bh{constructor(){}draw(t,e,n,i){const r=n.view.toY(0),o=Ct(e),a=n.getPaintConfig(0);ie(t,a.lineWidth,n,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,p,v,P,_;const D=Rh(o,c),O=D&&l.close<D;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(O?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){O&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!O&&l.close<0&&(t.strokeStyle=(p=i.color)!=null?p:a.multiplyColors[1]||a.color||"#FF00FF"),O&&l.close>0&&(t.strokeStyle=(v=i.color)!=null?v:a.multiplyColors[2]||a.color||"#FF00FF"),!O&&l.close>0&&(t.strokeStyle=(P=i.color)!=null?P:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=n.view.toX(l.centerUnit),Y=n.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,Y),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const j=n.view.toX(l.centerUnit),H=n.view.toY(l.close);t.moveTo(j,r),t.lineTo(j,H),t.stroke()})}}const Rh=(s,t)=>{do t--;while(t>=0&&!isFinite(s[t]&&s[t].close));return s[t]?s[t].close:void 0},Fh=(s,t)=>{let e=0;return(...n)=>{clearTimeout(e),e=+setTimeout(()=>s(...n),t)}};var Hh=Object.defineProperty,yr=Object.getOwnPropertySymbols,kh=Object.prototype.hasOwnProperty,jh=Object.prototype.propertyIsEnumerable,wr=(s,t,e)=>t in s?Hh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Sr=(s,t)=>{for(var e in t||(t={}))kh.call(t,e)&&wr(s,e,t[e]);if(yr)for(var e of yr(t))jh.call(t,e)&&wr(s,e,t[e]);return s};class Yh{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class Nh extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p){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=f,this.chartResizeHandler=p,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ut(!0),this.strToBarType=P=>{var _;return(_=this.barTypeValues.find(D=>D===P))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Ih(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const v=new Ah(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(v,es+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new vc(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(x.PANE_UUID(q),n.components.chart.cursor),this.dataSeriesDrawer=new Jc(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(Fh(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Dh))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",Zi),this.registerCandlesTransformer("trend",$i),this.registerCandlesTransformer("hollow",Cc),this.registerCandlesTransformer("line",yc)}get barTypeValues(){return Li(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 eh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Qc(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new nh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new rh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new $c(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new th(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new sh(this.config.components.chart.histogram));const e=x.PANE_UUID(q),n=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new Ch),this.registerDataSeriesTypeDrawer("HISTOGRAM",new bh),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Bh),this.registerDataSeriesTypeDrawer("POINTS",new yh),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new ah(new lh(this.chartModel),this.config,n)),this.registerDataSeriesTypeDrawer("TEXT",new wh(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new Sh),this.registerDataSeriesTypeDrawer("DIFFERENCE",new vh)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(Sr({},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()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=Sr({},t),this.chartModel.bus.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 Cr(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)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,n=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,n)}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||!Rt.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[Rt.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 xr extends Ut{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 Xh=Object.defineProperty,_r=Object.getOwnPropertySymbols,zh=Object.prototype.hasOwnProperty,Wh=Object.prototype.propertyIsEnumerable,Pr=(s,t,e)=>t in s?Xh(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Vh=(s,t)=>{for(var e in t||(t={}))zh.call(t,e)&&Pr(s,e,t[e]);if(_r)for(var e of _r(t))Wh.call(t,e)&&Pr(s,e,t[e]);return s};const Uh=(s,t,e,n)=>{var i,r,o,a;const l=Vh({},s),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Ua(-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-Nt(n.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Gh=s=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const n=t.slice(Math.max(t.length-s.state.defaultViewportItems,0)),i=n[0],r=n[n.length-1];s.setXScale(i.startUnit,r.startUnit+r.width+s.offsets.right)}e.yScale&&s.doAutoScale(!0),s.fireChanged()}},Zh=(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 $h=Object.defineProperty,Kh=Object.defineProperties,qh=Object.getOwnPropertyDescriptors,Tr=Object.getOwnPropertySymbols,Jh=Object.prototype.hasOwnProperty,Qh=Object.prototype.propertyIsEnumerable,Mr=(s,t,e)=>t in s?$h(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ie=(s,t)=>{for(var e in t||(t={}))Jh.call(t,e)&&Mr(s,e,t[e]);if(Tr)for(var e of Tr(t))Qh.call(t,e)&&Mr(s,e,t[e]);return s},Vs=(s,t)=>Kh(s,qh(t));class td{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)=>Vs(Ie({},e),{[n]:0}),{})}createColorPool(t){return t.reduce((e,n,i)=>(e[`color${i}`]=Vs(Ie({},ee(this.config.colors)),{lineTheme:Ie({},n.lineTheme),areaTheme:Ie({},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]]=Vs(Ie({},e),{lineTheme:Object.assign(r.lineTheme,(n=o.lineTheme)!=null?n:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var ed=Object.defineProperty,Ar=Object.getOwnPropertySymbols,sd=Object.prototype.hasOwnProperty,nd=Object.prototype.propertyIsEnumerable,Er=(s,t,e)=>t in s?ed(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ns=(s,t)=>{for(var e in t||(t={}))sd.call(t,e)&&Er(s,e,t[e]);if(Ar)for(var e of Ar(t))nd.call(t,e)&&Er(s,e,t[e]);return s};class id 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 R,this.mainInstrumentChangedSubject=new R,this.offsetsChanged=new R,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(Lh).filter(Oh),{sortCandles:p}=this.config.components.chart;return p?p(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new td(this.config);const d=new xr(this.chartBaseModel,this.paneManager.panes[q].mainExtent,bt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Yh,this.candlesTransformersByChartType,this.candleWidthByChartType,ns({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Uh(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Gh(o),this.timeFrameViewportTransformer=Zh(o,this),this.pane=this.paneManager.panes[q]}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(q)).pipe(At(bi)).subscribe(t=>{this.handleChartResize(t)}))}handleChartResize(t){if(t.width>ue.width&&t.height>ue.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),n=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=n;return}if(n!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Nt(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=Nt(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 Cr(i),{candles:i,instrument:n.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,n=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,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=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),Ee(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}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=ns({},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=this.prepareCandles(t.candles),r=Dr(this.mainCandleSeries.dataPoints,i),o=r.candles;Ee(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),p=Dr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(p,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints(),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=Ot(n.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;n.dataPoints=n.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=ns(ns({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const n=new Ut(this.paneManager.panes[q].mainExtent,bt(),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[q].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const n=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)n.push(a);else{let l=Ir(e,o,-1);if(l||(l=Ir(e,o,1)),l){const c=rl(l,o,!0);n.push(c)}}}),n}updateSecondaryCandleSeriesConfig(t,e,n){const i=Tt(t,Ge().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)}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=Ot(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+=ye((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?Ae(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Ae(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)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(n=>n.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(n=>n.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,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 yt(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return yt(t)}getMaxCandlesFitLength(){return it(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((n,i)=>{const r=i.timestamp,o=Te(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=Te(h.timestamp,!0,o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const p=f>=o.length-1,v=c&&h.timestamp<c.timestamp;if(p&&!v&&(c=h),a&&c&&n&&l){const P=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:Ki;this.scale.moveXStart(this.scale.xStart+P(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return vt(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(Ae(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=t;c<l;c++)a.push(Ae(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=Te(r.timestamp,!1,t).index;a<0?i.push(r):t[a].id===r.id?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){if(t<0)return;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)),Ee(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const n=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(n<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,n).concat(e.dataPoints.slice(i+1)),Ee(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(n=>this.removeCandleByIdx(this.candleIdxFromId(n,e)))}addCandlesById(t,e,n){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=n.dataPoints.slice(0,i),o=n.dataPoints.slice(i);n.dataPoints=r.concat(t).concat(o),Ee(n.dataPoints),n.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Ir=(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}},Dr=(s,t)=>{const e=s.slice(),n=[],i=[];return t.forEach(r=>{const a=Te(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 fe{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class Us{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=Di(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=Di(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=Ct(Array.from(this.drawers).map(([,n])=>n.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class rd{constructor(t,e,n,i){this.model=t,this.config=e,this.crossToolCanvasModel=n,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var od=Object.defineProperty,ad=Object.defineProperties,ld=Object.getOwnPropertyDescriptors,Lr=Object.getOwnPropertySymbols,cd=Object.prototype.hasOwnProperty,hd=Object.prototype.propertyIsEnumerable,Or=(s,t,e)=>t in s?od(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,dd=(s,t)=>{for(var e in t||(t={}))cd.call(t,e)&&Or(s,e,t[e]);if(Lr)for(var e of Lr(t))hd.call(t,e)&&Or(s,e,t[e]);return s},ud=(s,t)=>ad(s,ld(t));class fd extends X{constructor(t,e,n,i,r,o){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=n,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.currentHoverSubject=new ut(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?kt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(kt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,q]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(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===q)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:n,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(x.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=n.x+l,d=n.y+c,u=o.y+a,f=o.y+o.height-a,p=h<a?a:h>o.width-a?o.width-a:h,v=d<u?u:d>f?f:d,P=(e=this.hoverProducer.createHover(p,v,t.paneId))!=null?e:t,_=ud(dd({},P),{x:p,y:v});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const Et=4;function gd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p;const v=r.align,P=(l=i.textFont)!=null?l:Qt(r),_=i.bgColor,D=(c=i.textColor)!=null?c:Jt(_,o.labelTextColor,o.labelInvertedTextColor),O=(h=i.paddingTop)!=null?h:Et,j=(d=i.paddingBottom)!=null?d:Et,H=(u=i.paddingEnd)!=null?u:Et,B=ye(jt(P,s)/2),Y=n-B-O,G=n+B+j-Y;if(a&&!is(n,t,G))return;s.save(),s.fillStyle=_,s.strokeStyle=_;const V=ye(t.width/6),U=v==="right"?t.x:t.x+t.width,Z=v==="right"?U+V:U-V,$=r.labelBoxMargin.end,et=$-H,tt=t.width-V-et;Kc(s,Z,Y,U,Y+ye(G/2),Z,Y+G,tt,(p=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?p:!1,v),s.fillStyle=D,s.font=P;const Q=v==="right"?t.x+t.width-Pt(e,s,P)-$:t.x+$;s.fillText(e,Q,n+B-1),s.restore()}function pd(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P,_,D;const O=r.align,j=(l=i.textFont)!=null?l:Qt(r),H=i.bgColor,B=(c=i.textColor)!=null?c:Jt(H,o.labelTextColor,o.labelInvertedTextColor),Y=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,W=(u=(d=i.paddingTop)!=null?d:Y==null?void 0:Y.top)!=null?u:Et,G=(p=(f=i.paddingBottom)!=null?f:Y==null?void 0:Y.bottom)!=null?p:Et,V=(P=(v=i.paddingEnd)!=null?v:Y==null?void 0:Y.end)!=null?P:Et,U=i.paddingStart,Z=jt(j,s),$=n-Z/2-W,tt=n+Z/2+G-$,Q=(D=i.rounded)!=null?D:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!is(n,t,tt))return;s.save(),s.fillStyle=H,s.strokeStyle=H;const rt=r.labelBoxMargin.end;s.font=j;const lt=Pt(e,s,j),ot=rt-V,xt=U!==void 0?lt+U+V:t.width-ot,Vt=O==="right"?t.x+t.width-ot-xt:t.x+ot,me=O==="right"?t.x+t.width-lt-rt:rt;Q?lr(s,Vt,$,xt,tt,4,!0):s.fillRect(Vt,$,xt,tt),s.fillStyle=B,s.fillText(e,me,n+Z/2-1),s.restore()}function md(s,t,e,n,i,r,o,a=!0){var l,c,h,d,u,f,p,v,P;const _=r.align,D=(l=i.textFont)!=null?l:Qt(r),O=o.backgroundColor,j=(c=i.textColor)!=null?c:Jt(O,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Et,Y=(p=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?p:Et,W=(P=(v=i.paddingEnd)!=null?v:H==null?void 0:H.end)!=null?P:Et,G=i.paddingStart,V=jt(D,s),U=n-V/2-B,$=n+V/2+Y-U;if(a&&!is(n,t,$))return;s.save(),s.fillStyle=O,s.strokeStyle=O;const et=r.labelBoxMargin.end;s.font=D;const tt=Pt(e,s,D),Q=et-W,rt=G!==void 0?tt+G+W:t.width-Q,lt=_==="right"?t.x+t.width-Q-rt:t.x+Q,ot=_==="right"?t.x+t.width-tt-et:et;s.fillStyle=O,s.strokeStyle=O,s.fillRect(lt,U,rt,$),s.fillStyle=j,s.fillText(e,ot,n+V/2-1),s.restore()}function vd(s,t,e=Et){return jt(s,t)/2+e}function is(s,t,e){return!(s<t.y+e/2||s>t.y+t.height-e/2)}const bd="badge",Br=4,Rr={badge:gd,rectangle:pd,plain:md};function Fr(s,t,e,n,i,r,o,a,l){var c,h,d,u,f;const p=r.y,v=r.labelText,P=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:bd,D=r.description,O=(d=r.textFont)!=null?d:Qt(a),j=r.bgColor,H=(u=r.lineColor)!=null?u:j,B=Pt(D!=null?D:"",s,O)+8,Y=it(r.y),W=jt(O,s),G=p-W/2,U=p+W/2-G;s.save(),s.fillStyle=j,s.strokeStyle=H;const Z=o.getBounds(x.PANE_UUID(q)),$=Rr[_],et=a.labels.descriptions,tt=Cd(n,Y,U),Q=()=>et&&yd(e,t,n,i,r,a);let rt,lt;const ot=2;a.align==="right"?(rt=Z.x,lt=et?Z.x+Z.width-B:Z.x+Z.width+ot):(rt=et?Z.x+B:Z.x-ot,lt=Z.x+Z.width);const xt=(f=r.lineY)!=null?f:r.y,Vt=()=>tt&&ne(s,()=>qc(s,rt,xt,lt,xt,1)),me=()=>$(s,n,v,p,r,a,l.yAxis,!1),dn={line:()=>{Vt(),Q()},"line-label":()=>{Vt(),me(),Q()},label:()=>{Q(),me()}};P!=="none"&&is(p,n,U)&&dn[P](),s.restore()}const Cd=(s,t,e)=>t>s.y+e/2&&t<s.y+s.height-e/2;function yd(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=Qt(r),f=Pt(h,t,u),p=jt(u,t),v=(o=i.paddingTop)!=null?o:Br,P=(a=i.paddingBottom)!=null?a:Br,_=d-p/2-v,O=d+p/2+P-_;t.save();const j=f+5,H=4,B=f+H*2,Y=n.x+n.width,W=c==="right"?Y-B:n.x+H;bc(s,t,W,_,j,O,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const G=c==="right"?Y-f-H*2:n.x+H*2;t.fillText(h,G,d+p/2-1),t.restore()}class Hr{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()&&ne(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,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const p={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},v={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},P=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),P&&(t.moveTo(...p.start),t.lineTo(...p.end)),t.moveTo(...v.start),t.lineTo(...v.end),t.stroke()),P&&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,f=t.measureText(u).width,p=this.config.components.xAxis.fontSize,v=this.canvasBoundsContainer.getBounds(x.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const P=(n=l==null?void 0:l.left)!=null?n:0,_=(i=l==null?void 0:l.right)!=null?i:0,D=(r=l==null?void 0:l.top)!=null?r:0,O=(o=l==null?void 0:l.bottom)!=null?o:0,j=(a=c==null?void 0:c.top)!=null?a:0,H=f+P+_,B=p+D+O,Y=Math.max(d-H/2,0),W=v.y+j+Se/2;lr(t,Y,W,H,B),t.fillStyle=h.labelTextColor;const G=Math.max(d-f/2,P),V=v.y+j+p+Se/2+D-1;t.fillText(u,G,V),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=Rr[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,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 wd{draw(){}}class Sd extends X{constructor(t,e,n,i,r,o,a,l){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=n,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.crossToolTypeDrawers={},this.model=new fd(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel),this.addChildEntity(this.model);const c=new fe(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const h=new rd(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),d=new Us;d.addDrawer(c,"CLEAR_CANVAS"),d.addDrawer(h,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(d,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new Hr(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new wd)}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 xd{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 Xt{constructor(t){this.data=t,this.next=null}}class _d{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 Xt(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 Xt(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 Pd extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ut({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const 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 Xt(n);return i.getNodePosition(r)}addObject(t){var e,n;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new _d;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((n=t.parentId)!=null?n:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const n=this.getObjectInfoById(t);if(!n)return;const[i,r]=n,o=new Xt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[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 Xt(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 Xt(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 Xt(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 Xt(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 Xt(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()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class Td extends X{constructor(t,e){super();const n=new Pd(t);this.model=n,this.addChildEntity(n);const i=new xd(n,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Md=()=>s=>s.toString(),Ad=(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:Ed(s),shortMonths:Id(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=>Dd(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function Ed(s){var t;return(t=s.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Id(s){var t;return(t=s.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const kr=(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 Md()},Dd=(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=ge(d),f=ge(a),p=ge(l),v=ge(c),P=a<12?"AM":"PM",_=e[s.getDay()],D=_.substring(0,3),O=ge(i),j=r+1,H=ge(j),B=n[r],Y=B.substring(0,3),W=o+"",G=W.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",p+"").replace("m",l+"").replace("ss",v+"").replace("s",c+"").replace("S",h+"").replace("dd",O+"").replace("d",i+"").replace("EEEE",_).replace("EEE",D).replace("YYYY",W).replace("yyyy",W).replace("YY",G).replace("yy",G).replace("aaa",P),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",Y):t=t.replace("MM",H+"").replace("M",j+""),t},ge=s=>typeof s=="number"&&s<10?"0"+s:s,De=(s,t)=>`${s}_${t}`,Ld=(s,t)=>{if(t){const e=jr(t.normal),n=jr(t.hover);return{type:s,normal:e,hover:n}}},jr=s=>{var t;const n=new DOMParser().parseFromString(s,"text/html").querySelector("svg");let i=0;n&&(i=parseInt((t=n.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(s),l=new Image;return l.src=a,{img:l,svgHeight:i}},Od=(s,t,e,n,i)=>{if(i){const r=t[De(n,"hover")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[De(n,"normal")];s.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Bd={"rhombus-small":4,rhombus:6,"rhombus-large":8},Rd=["earnings","dividends","splits","conference-calls"];class Fd{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&&Rd.forEach(l=>{const c=Ld(l,a[l]);c&&(this.customIcons[De(c.type,"normal")]=c.normal,this.customIcons[De(c.type,"hover")]=c.hover)})}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=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(n.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[De(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Od(n,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(n,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);n.lineWidth=u!=null?u:1,n.beginPath(),n.setLineDash(f!=null?f:[]),n.moveTo(c,e.y),n.lineTo(c,t.y+t.height/2),n.stroke(),n.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),n.restore()}drawDefaultEvent(t,e,n,i,r){var o,a,l;const c=n.y+n.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=Gs(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var 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 Gs(s){return Bd[s.style]}const rs=5;class Hd{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)=>{if(!this.config.components.events.eventsVisibility[n.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(n.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[n.type].color;t.strokeStyle=c,t.fillStyle=c;const h=Gs(n);t.fillStyle=this.hitTestCanvasModel.idToColor(n.id);const d=(h+rs)*2;if(a!==void 0){const u=Gs(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const v=h*2+rs;t.fillRect(a+u,e.y,v,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}else t.fillRect(l-h-rs,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var kd=Object.defineProperty,Yr=Object.getOwnPropertySymbols,jd=Object.prototype.hasOwnProperty,Yd=Object.prototype.propertyIsEnumerable,Nr=(s,t,e)=>t in s?kd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Nd=(s,t)=>{for(var e in t||(t={}))jd.call(t,e)&&Nr(s,e,t[e]);if(Yr)for(var e of Yr(t))Yd.call(t,e)&&Nr(s,e,t[e]);return s};const Xr=317,Zs={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class Xd extends gr{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 R,this.touchStartSubject=new R,this.dblClickSubject=new R,this.rightClickSubject=new R,this.hitTestDrawersPredicateSubject=new ut(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,pr(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(Pe(100,_e,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),n=this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=vt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(ht(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=vt(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(()=>Nd({},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*Xr).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/Xr}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!==Ss&&(this.curImgData=this.ctx.getImageData(t*n,e*n,1,1).data,this.prevAnimationFrameId=Ss),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]=$s(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]=$s(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),[f,p]=$s(this.hitTestSubscribers,u),v=f==null?void 0:f.lookup(d),P={point:t,model:v};switch(e){case"mousedown":v&&((n=f==null?void 0:f.onMouseDown)==null||n.call(f,v,t)),p.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":v&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,v,t)),p.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":v&&((r=f==null?void 0:f.onHover)==null||r.call(f,v,t)),p.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(P);break;case"touchstart":v&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,v,t)),p.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(P);break;case"dblclick":v&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,v,t)),this.dblClickSubject.next(P);break;case"contextmenu":v&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,v,t)),this.rightClickSubject.next(P);break;case"zoom":v&&((c=f==null?void 0:f.onZoom)==null||c.call(f,v,t)),p.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const $s=(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 zd=Object.defineProperty,Wd=Object.defineProperties,Vd=Object.getOwnPropertyDescriptors,zr=Object.getOwnPropertySymbols,Ud=Object.prototype.hasOwnProperty,Gd=Object.prototype.propertyIsEnumerable,Wr=(s,t,e)=>t in s?zd(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zd=(s,t)=>{for(var e in t||(t={}))Ud.call(t,e)&&Wr(s,e,t[e]);if(zr)for(var e of zr(t))Gd.call(t,e)&&Wr(s,e,t[e]);return s},$d=(s,t)=>Wd(s,Vd(t));class Kd extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ut(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((n,i)=>$d(Zd({},n),{id:i+e})).sort((n,i)=>n.timestamp-i.timestamp)}getIdRange(){return Zs.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 qd 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=()=>kr(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Kd(e);this.eventsModel=c,this.addChildEntity(c),n.addSubscriber(c);const h=new Fd(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Hd(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){Tt(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class Jd{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;ne(t,()=>this.drawVertical(t)),ne(t,()=>this.drawHorizontal(t)),ne(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=it(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=Mt(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=it(this.viewportModel.toY(i.value)),o=vd(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 Vr 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 Jd(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 Qd{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=Ve(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");Gt(t,h)}getMarkerText(t,e){const n=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${n}`}getMarkerY(t,e,n=!1){const i=this.chartModel.toY(e);if(n){const r=Ve(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 tu extends X{constructor(t,e,n,i,r){super();const o=new Qd(e,n,t,i);r.addDrawer(o,"HIGH_LOW")}}const eu=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],su=24*60*60*1e3;class nu extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new R}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+su;Ka(this.highlights,t,e,iu).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 iu=s=>s.to,Zt=[20,10];class ru{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(),Gt(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,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",p=`${u}px ${f}, monospace`;o.font=p,o.lineWidth=h,o.setLineDash(d),eu.forEach(v=>{var P,_;const D=a[v];if(D){const O=this.config.colors.highlights[v],j=(P=O==null?void 0:O.border)!=null?P:"#ffffff",H=(_=O==null?void 0:O.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=j,D.forEach(B=>{var Y,W,G;const V=this.chartModel.candleFromTimestamp(B.from),U=ft(V.width,this.chartModel.scale.zoomX),Z=V.xStart(this.chartModel.scale),$=B.to-this.chartModel.chartBaseModel.period,et=this.chartModel.candleFromTimestamp($),tt=ft(et.width,this.chartModel.scale.zoomX),Q=et.xStart(this.chartModel.scale)+tt;if(B.border&&this.drawBorders(B.border,o,Z+U,Q-tt,c),o.fillRect(Z,c.y,Q-Z,c.y+c.height),B.label){const rt=(Y=B.label.text)!=null?Y:"",lt=this.config.colors.highlights[B.type];o.save(),o.fillStyle=(W=lt==null?void 0:lt.label)!=null?W:"#ffffff";const ot=Pt(rt,o,p),[xt,Vt]=this.resolveHighlightLabelPosition((G=B.label.placement)!=null?G:"left-left",c,[Z,Q],ot);o.fillText(rt,xt,Vt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,n,i){const[r,o]=n;switch(t){case"right-left":return[o-Zt[1]-i,e.y+Zt[0]];case"left-left":return[r-Zt[1]-i,e.y+Zt[0]];case"right-right":return[o+Zt[1],e.y+Zt[0]];case"left-right":default:return[r+Zt[1],e.y+Zt[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 ou="HIGHLIGHTS_PLUGIN";class au extends X{constructor(t,e,n,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new nu(n),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new ru(this.highlightsModel,n,i,r,e),o.addDrawer(this.highLightsDrawer,ou)}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 lu(){return N(function(s,t){var e,n=!1;s.subscribe(mt(t,function(i){var r=e;e=i,n&&t.next([r,i]),n=!0}))})}function J(s,t){return N(function(e,n){var i=0;e.subscribe(mt(n,function(r){return s.call(t,r,i++)&&n.next(r)}))})}var cu=Object.defineProperty,hu=Object.defineProperties,du=Object.getOwnPropertyDescriptors,Ur=Object.getOwnPropertySymbols,uu=Object.prototype.hasOwnProperty,fu=Object.prototype.propertyIsEnumerable,Gr=(s,t,e)=>t in s?cu(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Zr=(s,t)=>{for(var e in t||(t={}))uu.call(t,e)&&Gr(s,e,t[e]);if(Ur)for(var e of Ur(t))fu.call(t,e)&&Gr(s,e,t[e]);return s},$r=(s,t)=>hu(s,du(t));const zt=4;class gu{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-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+zt,r+zt),t.lineTo(i+zt,r-zt),t.fillStyle=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-zt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-zt),t.lineTo(i,r+zt),t.lineTo(i+zt,r),t.fillStyle=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=Ct(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:$r(Zr({},h),{textAlign:"left"})},u={dateFormat:n.dateFormat,padding:n.padding,textProperties:$r(Zr({},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=qn(n,i.dateFormat,this.formatterFactory);Zn(t,i.textProperties);const a=Ve(t),l=Kn(o);Ja(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Le extends br{constructor(t,e,n,i,r=vr){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 Kr=4;class pu 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=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-p.x-Kr},this.leftKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const p=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-p.x+Kr},this.rightKnotDragTick=f=>{const{delta:p}=f,P=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+p)/P;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:p}=f,v=this.canvasBoundsContainer.getBounds(x.N_MAP_CHART),P=this.chartModel.mainCandleSeries.meanCandleWidth/(v.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-p)*P;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=p};const a=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(x.N_MAP_KNOT_R),c=new Le(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Le(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 Le(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 mu 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 gu(i,e,n,o,l,()=>this.visualCandles);a.addDrawer(d,x.N_MAP_CHART),this.navigationMapMoveHandler=new pu(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(vt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(x.N_MAP),this.chartModel.scale.xChanged.pipe(lu(),J(([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,f,p;for(f=0;f<h;f++)p=it(f*o/h)-r,p in e?(d[f]=e[p].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((v,P)=>[P+c.x,(a+l-v)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(zs),this.canvasModel.fireDraw())}}const qr=()=>{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"},Yp=(s,t)=>s==="apple"||s==="mobile"?3:t,vu=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),bu=!!window.chrome,Jr=typeof InstallTrigger!="undefined",Cu=navigator.platform.indexOf("Win")>-1,Np=s=>{let t=!1;const{wheelDeltaY:e,wheelDeltaX:n}=s;if(e||n){let i;if(vu)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(bu){if(i=e+Math.sign(e)===s.deltaY*-3?e+Math.sign(e)===s.deltaY*-3:e===s.deltaY*-3,Cu){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 Jr?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 Jr&&s.deltaY>=16&&Math.abs(s.deltaY)%16===0&&(t=!1),s.ctrlKey&&(t=!0),t},yu=(s,t)=>s==="percent"?t/4:t;var Ks=Math.pow;class wu 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 f=d.deltaY<0;if(this.config.scale.zoomToCursor){const v=this.canvasBoundsContainer.getBounds(x.CANVAS).width,_=d.offsetX/v;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(We),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Nt(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES),h=new Le(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(J(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Pe(this.wheelThrottleTime,_e,{trailing:!0,leading:!0})).subscribe(e=>{const n=qr(),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=Nt(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 yu(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let n=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(We),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)Su(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Nt(t.state.inverse?-c:c,t.zoomY);t.moveYStart(n+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new ss(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const Su=(s,t)=>{if(!t.enabled)return!1;const e=Math.abs(s.y),n=Ks(Ks(Math.abs(s.x),2)+Ks(e,2),.5),i=Math.abs(Math.acos(e/n));return e>t.yDiff&&i<t.edgeAngle},xu=2;class _u extends X{constructor(t,e,n,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=n,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:n}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:n}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:n}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=Qr(e,i.x,n,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),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||e[0]===e[1]||this.scale.setXScale(n,i)}}const Qr=(s,t,e,n,i=xu)=>Math.sqrt(Math.pow(s-t,2)+Math.pow(e-n,2))>i;class Pu 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 wu(this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel),this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new _u(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const to=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}},eo=(s,t)=>{const e=to(s);return{isHighLowActive:()=>!0,calculateHighLow:n=>{const i=t.calculateHighLow(n);return e(i)}}};function Tu(){return Ln(1)}function so(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];return Tu()(Ye(s,je(s)))}function Mu(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s);return N(function(n,i){(e?so(s,n,e):so(s,n)).subscribe(i)})}function Au(s){return J(function(t,e){return s<=e})}class Eu{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]}}const no=8;class qs extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){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=f,this.initialY=0,this.resizeEvent$=new R,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=p=>{const{delta:v,draggedPixels:P}=p;Math.abs(this.initialY-this.boundsProvider().y+P)>=0&&(this.dragTickCb(v),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const n=new ss(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:kt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:kt()?this.onYDragEndMobile: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(Mu(!1),J(this.dragPredicate),At(),Au(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Eu(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,mr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(mr.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 Iu=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=Rt.getPricePrecision(e,n.pricePrecisions);return e.toFixed(i)}return`${e}`},Du=s=>(t,e)=>{const[n]=s.dataSeries;let i=t;const r=e!=null?e:n;r!==void 0&&(i=Ri(t,r.getBaseline()));const o=i.toFixed(Rt.DEFAULT_PRECISION).replace("-","\u2212")+" %";return o==="\u22120.00 %"?"0.00 %":o},Lu=s=>({percent:Du(s),regular:Iu(s)});class Ou extends X{constructor(t,e,n,i,r,o,a,l,c,h,d=new Set,u={regular:cc}){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=f=>f.map(p=>new Me(this.chartBaseModel.dataFromTimestamp(p.timestamp).centerUnit,p.close)),this.toY=f=>{var p,v;return(v=(p=this.mainDataSeries)==null?void 0:p.view.toY(f))!=null?v:1},this.valueFormatter=(f,p)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(f);const{regular:v,percent:P,logarithmic:_}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(f);case"percent":return P?P(f,p):v(f);case"logarithmic":return _?_(f):v(f);default:return this.regularFormatter(f)}},this.addChildEntity(l),this.setValueFormatters(Lu(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 Xi(this,bt(),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 io=s=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(s.dataSeries).filter(n=>n.highLowProvider.isHighLowActive()).map(n=>n.highLowProvider.calculateHighLow(t));return er(e)}});class Bu{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=Zs.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return Zs.DATA_SERIES}get allDataSeries(){return we(we(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 Wt="#FF00FF";function Xp(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 Ru=(s,t)=>s==="down"?t.lastPrice.textNegative:s==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Fu=(s,t)=>{const e=t.barTheme[`${s}Color`];return e!=null?e:Wt},Hu=(s,t)=>{const e=t.lineTheme[`${s}Color`];return e!=null?e:Wt},ku=(s,t)=>{const e=t.candleTheme[`${s}Color`];return e!=null?e:Wt},ju=(s,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Wt},Yu=(s,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Wt},Nu=(s,t)=>{const e=t.histogram[`${s}Bright`];return e!=null?e:Wt},Xu=(s,t)=>{const e=s==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Wt},ro=(s,t)=>{const e=t.candleTheme[`${s}WickColor`];return e!=null?e:Wt},zu=()=>(console.warn("Fallback for label default color"),Wt),oo=10;class ao extends X{constructor(t,e,n,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new R,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(x.Y_AXIS).height,ui),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(oo-1)):d=1+h/this.lastYPxHeight*(oo-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,p=this.lastYStart-f,v=this.lastYEnd+f;(this.lastYStart!==p||this.lastYEnd!==v)&&(this.scale.setYScale(p,v),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new ss(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,n,{dragPredicate:()=>n.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Wu{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${bt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Yn(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 Vu=0,Uu=.01;class Js{constructor(t,e,n,i,r=!1,o,a,l=Ms,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 R,this.newGeneratedLabelsSubject=new R,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Wu(()=>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=Fi(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=Ns(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=Js.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=Rt.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(e)}return this.adjustIncrementOnAxisType(Uu)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=Ns(e)+t;return Hi(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)*(Vu/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 Gu extends Js{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=yt(n.dataPoints),r=(e=i==null?void 0:i.close)!=null?e:0,o=wc(r,n.pricePrecisions);return this.adjustIncrementOnAxisType(o)}return super.calculateIncrement(t)}}function lo(s,t,e){var n=k(s)||t||e?{next:s,error:t,complete:e}:s;return n?N(function(i,r){var o;(o=n.subscribe)===null||o===void 0||o.call(n);var a=!0;i.subscribe(mt(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)}))}):le}class Zu 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_${bt()}`}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(x.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(ht(t=>t.height),J(t=>_a(t,this.prevYAxisHeight,1.5)),lo(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){this.labels=this.labelsGenerator.generateNumericLabels(),be(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}}class $u extends X{constructor(t,e,n,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=n,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Gu(null,l,o,a,()=>this.state.type,n.labelHeight),this.baseLabelsModel=new Zu(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new $l(e,o,i,n,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(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 Ku extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.scale=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=a,this.cursors=l,this.paneUUID=d,this.extentIdx=u,this.hitTestCanvasModel=f,this.chartResizeHandler=p,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new R,this.axisAlignSetSubject=new R,this.axisAlignMovedSubject=new R,this.setDblClickCallback=_=>this.yAxisScaleHandler.setDblClickCallback(_),this.setDblTapCallback=_=>this.yAxisScaleHandler.setDblTapCallback(_);const P=v?ee(v):{};this.state=Tt(P,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new ao(t,this.state,a,i,r,o,o.getBoundsHitTest(x.PANE_UUID_Y_AXIS(d,u)),f),this.addChildEntity(this.yAxisScaleHandler),this.model=new $u(this.paneUUID,t,this.state,o,n,i,c,h,u,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new ao(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",ku),this.registerLabelColorResolver("bar",Fu),this.registerLabelColorResolver("line",Hu),this.registerLabelColorResolver("area",ju),this.registerLabelColorResolver("scatterPlot",Yu),this.registerLabelColorResolver("histogram",Nu),this.registerLabelColorResolver("baseline",Xu),this.registerLabelColorResolver("trend",ro),this.registerLabelColorResolver("hollow",ro)}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:zu}registerYAxisLabelsProvider(t,e=te.MAIN,n=bt()){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=te.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.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class qu extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_,D,O,j){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=f,this.canvasBoundsContainer=p,this.uuid=v,this.seriesAddedSubject=P,this.seriesRemovedSubject=_,this.hitTestCanvasModel=D,this.chartResizeHandler=O,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new R,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(x.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,Y)=>this.mainExtent.valueFormatter(B,Y);const H=this.createExtentComponent(j);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(x.PANE_UUID(v),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return we(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(At(bi)).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,r){const o=x.PANE_UUID(t);return new Vr(this.mainCanvasModel,e,this.config,n,`PANE_${t}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(o),()=>this.canvasBoundsContainer.getBounds(o),()=>[],i,r,()=>this.config.components.grid.visible)}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 Gc(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(v,P)=>new Ku(this.eventBus,this.config,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,v,P,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Ou(this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((n=t==null?void 0:t.useDefaultHighLow)!=null?n:!0)&&a.autoScaleModel.setHighLowProvider("default",eo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),io(u)));const p=this.createGridComponent(this.uuid,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(p),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(n=>n.idx).includes(e.idx)),this.yExtentComponents.forEach((e,n)=>{e.yAxis.setExtentIdx(n),e.idx=n,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,n,i="right"){const r=ee(n.yAxis.state),o=ee(n.scale.state),a=Tt(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),n.dataSeries.size===0&&e.removeExtentComponents([n])}moveDataSeriesToExistingExtentComponent(t,e,n,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&n.dataSeries.size===0&&e.removeExtentComponents([n]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(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=ce(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=yt(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var Ju=Object.defineProperty,Qu=Object.defineProperties,tf=Object.getOwnPropertyDescriptors,co=Object.getOwnPropertySymbols,ef=Object.prototype.hasOwnProperty,sf=Object.prototype.propertyIsEnumerable,ho=(s,t,e)=>t in s?Ju(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)&&ho(s,e,t[e]);if(co)for(var e of co(t))sf.call(t,e)&&ho(s,e,t[e]);return s},rf=(s,t)=>Qu(s,tf(t));class of extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f,p,v,P,_){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=f,this.mainCanvasModel=p,this.yAxisLabelsCanvasModel=v,this.hitTestCanvasModel=P,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new R,this.paneAddedSubject=new R,this.dataSeriesAddedSubject=new R,this.dataSeriesRemovedSubject=new R,this.hitTestController=new Bu(this.panes,this.dynamicObjectsCanvasModel);const D=this.createPane(q,{useDefaultHighLow:!1,scale:this.mainScale});D.mainExtent.scale.autoScaleModel.setHighLowProvider("series",io(D.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",to(()=>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+no}),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 qs(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 we(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=bt(),e){if(this.panes[t]!==void 0)return this.panes[t];const n=new qu(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&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=ce(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=yt(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 qs&&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 qs&&r.id===n);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,n,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?rf(nf({},n.yAxis.state),{align:l}):void 0,p=c&&c>0;if(!u){const v=a&&a==="above"?d:d+1,P=this.createPane(r,{order:v,initialYAxisState:f,inverse:n.scale.state.inverse,lockToPriceRatio:n.scale.state.lockPriceToBarRatio});P.moveDataSeriesToExistingExtentComponent(t,e,n,P.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!p?u.moveDataSeriesToExistingExtentComponent(t,e,n,o):u.moveDataSeriesToNewExtentComponent(t,e,n,l!=null?l:n.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}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+no),()=>{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 af 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 lf=(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)},os=class extends X{constructor(s,t,e,n){super(),this.chartComponent=s,this.config=t,this.volumesModel=e,this.paneManager=n,t.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[os.UUID]===void 0){const t=this.paneManager.createPane(os.UUID,{paneFormatters:{regular:i=>lf(i,1)},useDefaultHighLow:!1,increment:1});this.pane=t,t.mainExtent.yAxis.setAxisType("regular");const{scale:e}=t,n=eo(()=>({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(os.UUID),delete this.pane}fromY(s){var t,e;return(e=(t=this.pane)==null?void 0:t.scale.fromY(s))!=null?e:0}};let uo=os;uo.UUID="volumes";const as=.3,cf=(s,t)=>{const e=t.barTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},hf=(s,t)=>{const e=t.volume[`${s}BarColor`];return Lt()(e).alpha(as).toString()},df=(s,t)=>{const e=t.lineTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},Qs=(s,t)=>{const e=t.candleTheme[`${s}Color`];return Lt()(e).alpha(as).toString()},uf=3;class ff{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:hf;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();Gt(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=Ct(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?Mt(i.toX(n[o+1].startUnit)):void 0,h=Mt(i.toX(r.startUnit)),d=c!==void 0?c-h:Mt(ft(r.width,i.zoomX));if(this.config.components.volumes.showSeparately){const u=Mt(i.toY(r.candle.volume)),f=ks(i.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=e/(l/uf),f=Math.max(ks(ft(r.candle.volume,u)),2),p=Mt(a.y+l-f);this.drawVolume(t,r,h,p,d,f)}}})}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,ks(c)),a.stroke()):a.fillRect(n,i,r,o)}}const gf=$a(s=>s.candle.volume),fo="volumes";class pf extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=fo,this.volumeMax=new ut(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(vt(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=ce(gf(this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport().flat())))!=null?t:0)}}class mf 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 ut(!1),this.volumeIsSeparateModeChangedSubject=new ut(!1);const c=new pf(e,n);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new uo(e,o,c,a),this.volumesDrawer=new ff(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",Qs),this.registerVolumeColorResolver("trend",Qs),this.registerVolumeColorResolver("hollow",Qs),this.registerVolumeColorResolver("line",df),this.registerVolumeColorResolver("bar",cf)}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?fo:q,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 vf{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,f=this.canvasBoundsContainer.getBounds(x.PANE_UUID(q)),{position:p,offsetY:v,offsetX:P}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=ls(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=bf(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),p){case"left-top":return{x:P+f.x,y:v+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:P+f.x,y:f.height-h-v+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,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,f=this.canvasModel.ctx;let p=0,v=0,P=0,_=0,D=0;if(f.save(),d.firstRowFontSize&&l){f.font=ls(this.config,d.firstRowFontSize);const B=f.measureText(l);p=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=ls(this.config,d.secondRowFontSize);const B=f.measureText(c);v=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,P=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=ls(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,D=(n=d.secondRowBottomPadding)!=null?n:0}const O=(i=d.thirdRowBottomPadding)!=null?i:0,j=(r=d.logoHeight)!=null?r:0,H=p+v+P+_+D+O+j;if(l&&this.drawWaterMark(this.getConfig(p,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(p+P+v,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(p+P+v+D+_,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(p+P+v+D+_+O,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const 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 bf=(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},ls=(s,t)=>{let e;return s.components&&s.components.waterMark&&(e=s.components.waterMark.fontFamily),t+"px "+e};var Cf=Object.defineProperty,go=Object.getOwnPropertySymbols,yf=Object.prototype.hasOwnProperty,wf=Object.prototype.propertyIsEnumerable,po=(s,t,e)=>t in s?Cf(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,mo=(s,t)=>{for(var e in t||(t={}))yf.call(t,e)&&po(s,e,t[e]);if(go)for(var e of go(t))wf.call(t,e)&&po(s,e,t[e]);return s};class Sf 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 vf(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(Tt(r.observeBoundsChanged(x.PANE_UUID(q)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};Tt(e,t),Tt(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return mo(mo({},this.config.components.waterMark),h)}}const vo={x:4,y:4};function xf(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 p=s.measureText(n.text).width+vo.x*2;let v=0;const P=n.x;switch(o){case"start":v=P-p;break;case"end":v=P;break;case"middle":default:v=P-p/2;break}s.fillStyle=h.backgroundColor,s.strokeStyle=h.backgroundColor,s.fillRect(v,u.y,p,u.height),o!=="middle"&&(s.strokeStyle=n.color,s.beginPath(),s.moveTo(P,u.y),s.lineTo(P,u.y+u.height),s.stroke()),s.fillStyle=n.color;const _=v+vo.x,D=u.y+d+a+Se/2;s.fillText(n.text,_,D),s.restore()}class _f{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=>{xf(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=Lt().rgb(r[0].color).alpha(.1).toString(),cr(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const zp="week-weekday",Pf=["second","minute","hour","day","month","year"],Tf=["lessThanSecond"],Mf=s=>Pf.some(t=>t===s),Af=s=>s==="week-weekday",Ef=s=>Tf.some(t=>t===s),bo=s=>{const t={"!":!1,$:!1};return s.includes("!")&&(t["!"]=!0),s.includes("$")&&(t.$=!0),t},tn=s=>parseInt(s,10),Co=s=>{const[t,...e]=s.split("_");if(Mf(t)){const[n]=e,i=bo(n),r=tn(n);return{key:t,value:r,exact:i["!"]}}else if(Af(t)){const[n,i]=e,r=bo(n),o=tn(n),a=tn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Ef(t)?{key:t}:(console.warn(`${s} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class cs{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=cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=n.backgroundColor;const l=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+Se/2),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;if(h<n.x||h>n.width)continue;const 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 en={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},yo=s=>{switch(s.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return en[s.key]+s.value;case"lessThanSecond":return en[s.key];case"week-weekday":return en[s.key]+(s.week==="$"?9:s.week)+s.weekday*10}},wo=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},If=(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 f=r[u],p=f.idx;for(;c<a;){const v=o[c],P=v.idx;if(p>P)c++,n.push(v),d=P,h=1/0;else{h=P;break}}h-p>=t&&p-d>=t&&(n.push(f),d=p)}for(;c<a;)n.push(o[c]),c++}return n},Df=(s,t,e,n,i,r)=>{const o=cs.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 sn(s){"@babel/helpers - typeof";return sn=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},sn(s)}function wt(s,t){if(t.length<s)throw new TypeError(s+" argument"+(s>1?"s":"")+" required, but only "+t.length+" present")}function St(s){wt(1,arguments);var t=Object.prototype.toString.call(s);return s instanceof Date||sn(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 Lf(s){return wt(1,arguments),St(s).getDay()===1}function Of(s){return wt(1,arguments),St(s).getDay()===2}function Bf(s){return wt(1,arguments),St(s).getDay()===3}function Rf(s){return wt(1,arguments),St(s).getDay()===4}function Ff(s){return wt(1,arguments),St(s).getDay()===5}function Hf(s){return wt(1,arguments),St(s).getDay()===6}function kf(s){return wt(1,arguments),St(s).getDay()===0}function jf(s,t){var e;wt(1,arguments);var n=s||{},i=St(n.start),r=St(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(St(l)),l.setDate(l.getDate()+c),l.setHours(0,0,0,0);return a}function Yf(s){wt(1,arguments);var t=St(s);return t.setDate(1),t.setHours(0,0,0,0),t}function Nf(s){wt(1,arguments);var t=St(s),e=t.getMonth();return t.setFullYear(t.getFullYear(),e+1,0),t.setHours(23,59,59,999),t}function So(s){wt(1,arguments);var t=St(s);return t.setHours(0,0,0,0),t}function xo(s,t){wt(2,arguments);var e=So(s),n=So(t);return e.getTime()===n.getTime()}const Xf=s=>{switch(s.key){case"lessThanSecond":return Uf(s);case"month":return Gf(s);case"second":case"minute":case"hour":case"day":case"year":return Zf(s);case"week-weekday":return $f(s);default:return()=>!1}},$t=(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()}},nn=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n!==i},zf=s=>(t,e)=>{const n=$t(t,s),i=$t(e,s);return n>=i},Wf={1:Lf,2:Of,3:Bf,4:Rf,5:Ff,6:Hf,7:kf},Vf=(s,t,e)=>{var n;const i=jf({start:Yf(s),end:Nf(s)}),r=(n=Wf[e])!=null?n:()=>!1;if(t==="$"){for(const o of i.reverse())if(r(o))return xo(s,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return xo(s,a);o++}}return!1},_o=(s,t)=>t===1?s===1:s/t===1,Po=(s,t)=>t===1?!0:s%t===0,Uf=s=>(t,e)=>zf(s.key)(t,e),Gf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?_o($t(t,s.key)+1,s.value):Po($t(t,s.key)+1,s.value);return n&&i},Zf=s=>(t,e)=>{const n=nn(s.key)(t,e),i=s.exact?_o($t(t,s.key),s.value):Po($t(t,s.key),s.value);return n&&i},$f=s=>(t,e)=>{const n=nn(s.key)(t,e),i=Vf(t,s.week,s.weekday);return n&&i},Kf=s=>{switch(s.key){case"second":case"minute":return qf(s.value);case"hour":return Jf(s.value);case"day":return Qf(s.value);case"month":return sg(s.value);case"year":return ng(s.value);case"week-weekday":const t=eg(s.week),e=tg(s.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},qf=s=>s>0&&s<=60,Jf=s=>s>0&&s<=24,Qf=s=>s>0&&s<=31,tg=s=>To(s)?s>=1&&s<=7:!1,eg=s=>s==="$"?!0:To(s)?s>=1&&s<=6:!1,sg=s=>s>0&&s<=12,ng=s=>s>0,To=s=>!isNaN(s)&&isFinite(s),ig=(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 rn(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:ig(a,i,t)};n[r]=l,i=a}return n}const Mo=s=>{const t={},e={};return js(s).forEach(([n,i])=>{const r=Co(n),o=r===null?!1:Kf(r);if(r&&o){const a=yo(r);t[a]=i,e[a]=Xf(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Ao{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?ft(d,h.animationConfig.targetZoomX):ft(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,p=Object.values(this.formatsByWeightMap).reduce((P,_)=>Math.max(_.length,P),1),v=f*p;return Math.round(v/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Mo(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(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>Vi(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}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}=Mo(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(t=[]){const e=this.getAllCandlesWithFake(t),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e);this.labelsGroupedByWeight=wo(i),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=rn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),n=rn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(n,e),r=wo(i),o=ee(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const p=f.map(v=>(v.idx=v.idx+t.length,v.value=a.startUnit+a.width+v.value,v));r[u]?c[h]=d.concat(p):c[h]=p}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t){this.generateWeightedLabels(t)}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=If(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];Df(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=js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=Co(o);if(l){const c=yo(l);i[c]=a}}return i},{});return js(t).reduce((i,[r,o])=>(n[r]&&n[r](e)||(i[r]=o),i),{})}}class rg extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(ts,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const Eo=3;class og extends X{constructor(t,e,n,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=n,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(x.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,p=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(p,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(Eo-1)):u=1+h/this.lastXPxWidth*(Eo-1);const p=(this.lastXWidth*u-this.lastXWidth)/2,v=this.lastXStart-p,P=this.lastXEnd+p;(this.lastXStart!==v||this.lastXEnd!==P)&&this.scale.setXScale(v,P)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Le(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class ag extends X{constructor(t,e,n,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=n,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=P=>this.xAxisScaleHandler.setDblClickCallback(P),this.setDblTapCallback=P=>this.xAxisScaleHandler.setDblTapCallback(P);const p=new Ao(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=p,this.xAxisLabelsModel=new rg(t,[]);const v=new Us;c.addDrawer(v,"X_AXIS"),this.xAxisDrawer=new cs(e,n,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),v.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new _f(e,n,o,this.xAxisLabelsModel),v.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new og(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(x.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(x.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(vt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(J(({prependedCandles:t})=>t.length!==0),ht(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,n;dl.includes(this.config.components.chart.type)&&((n=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||n.call(e,t))})),this.addRxSubscription(vt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Pe(50,_e,{trailing:!0,leading:!0})).subscribe(()=>{this.xAxisLabelsGenerator.recalculateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(ht(()=>yt(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),At((t,e)=>{var n,i;return((n=t==null?void 0:t.candle)==null?void 0:n.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),J(Wn)).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 Ao?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 lg=Object.defineProperty,Io=Object.getOwnPropertySymbols,cg=Object.prototype.hasOwnProperty,hg=Object.prototype.propertyIsEnumerable,Do=(s,t,e)=>t in s?lg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,hs=(s,t)=>{for(var e in t||(t={}))cg.call(t,e)&&Do(s,e,t[e]);if(Io)for(var e of Io(t))hg.call(t,e)&&Do(s,e,t[e]);return s};class dg{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&&hs(hs({},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&&hs(hs({},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=yt(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:Jt("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:Ru(t.lastPriceMovement,i);return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,h,o),rounded:!0}}return{bgColor:l,textColor:n==="plain"?a(t.lastPriceMovement,t.colors):Jt(l,r,o),rounded:!0}}}class ug{constructor(t,e,n,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=n,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,n=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(x.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>Fr(t,n,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>Fr(t,n,e,r,o,l,this.canvasBoundsContainer,i.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(q));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];cr(e,{x:h.x,y:vi(d,h)},{x:h.x+h.width-6,y:vi(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class fg{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;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=Qt(e.state),a=jt(o,r),l=this.getLabelTextColor();r.save(),Gt(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 f=a.scale.toY(u.value);f>h&&f<d&&gg(t,n,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const gg=(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 pg{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const n=this.handlers[t];n!==void 0&&Ga.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 R,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(ts,t)}}class mg extends X{constructor(t,e,n,i){super(),n.observeTouchStart().pipe(ht(r=>i.components.chart.highlightActiveCandle?r:void 0),At()).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 vg{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_${bt()}`,this.canvasResized=new R,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){be(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(zs,e),this.bus.fire(ts))}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 bg=Array.isArray,Cg=Object.getPrototypeOf,yg=Object.prototype,wg=Object.keys;function Sg(s){if(s.length===1){var t=s[0];if(bg(t))return{args:t,keys:null};if(xg(t)){var e=wg(t);return{args:e.map(function(n){return t[n]}),keys:e}}}return{args:s,keys:null}}function xg(s){return s&&typeof s=="object"&&Cg(s)===yg}var _g=Array.isArray;function Pg(s,t){return _g(t)?s.apply(void 0,I([],m(t))):s(t)}function Tg(s){return ht(function(t){return Pg(s,t)})}function Mg(s,t){return s.reduce(function(e,n,i){return e[n]=t[i],e},{})}function Ag(){for(var s=[],t=0;t<arguments.length;t++)s[t]=arguments[t];var e=je(s),n=fa(s),i=Sg(s),r=i.args,o=i.keys;if(r.length===0)return Ye([],e);var a=new pt(Eg(r,e,o?function(l){return Mg(o,l)}:le));return n?a.pipe(Tg(n)):a}function Eg(s,t,e){return e===void 0&&(e=le),function(n){Lo(t,function(){for(var i=s.length,r=new Array(i),o=i,a=i,l=function(h){Lo(t,function(){var d=Ye(s[h],t),u=!1;d.subscribe(mt(n,function(f){r[h]=f,u||(u=!0,a--),a||n.next(e(r.slice()))},function(){--o||n.complete()}))},n)},c=0;c<i;c++)l(c)},n)}}function Lo(s,t,e){s?Ht(e,s,t):t()}class Ig extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ut(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,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=Ag([n,i]).pipe(J(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!kt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Dg(s,t){return N(function(e,n){var i=null,r=0,o=!1,a=function(){return o&&!i&&n.complete()};e.subscribe(mt(n,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(s(l,h)).subscribe(i=mt(n,function(d){return n.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Lg{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 Og{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 Lg(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Bg{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof xr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Rg=Object.defineProperty,Fg=Object.defineProperties,Hg=Object.getOwnPropertyDescriptors,Oo=Object.getOwnPropertySymbols,kg=Object.prototype.hasOwnProperty,jg=Object.prototype.propertyIsEnumerable,Bo=(s,t,e)=>t in s?Rg(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Oe=(s,t)=>{for(var e in t||(t={}))kg.call(t,e)&&Bo(s,e,t[e]);if(Oo)for(var e of Oo(t))jg.call(t,e)&&Bo(s,e,t[e]);return s},on=(s,t)=>Fg(s,Hg(t));class Yg extends X{constructor(t,e,n,i,r,o,a,l,c,h){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.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ut(null),this.longTouchActivatedSubject=new ut(!1),this.xFormatter=()=>"";const d=new Og(this.chartModel),u=new Bg(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Dg(()=>this.scale.initialViewportValidSubject.pipe(J(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(vt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var n;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((n=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:n.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(x.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var n;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((n=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:n.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var n,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!Qr(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(n=this.crossEventProducer.crossToolHover)==null?void 0:n.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(x.PANE_UUID(d)),f=u.y+5,p=u.y+u.height-5,v=c-l.x,P=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=v,D=a.y<f?f:a.y>p?p:a.y+=P;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:D}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=kr(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,q)}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)=>on(Oe({},l),{[c[0]]:c[1].getData(o)}),{});return Oe(Oe({},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=on(Oe({},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,n;if(t){if(kt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(n=t.candleHover)==null?void 0:n.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=on(Oe({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const Ro={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 pe(s){return t=>{t.button===Ro.left&&s(t)}}var Ng=Object.defineProperty,Fo=Object.getOwnPropertySymbols,Xg=Object.prototype.hasOwnProperty,zg=Object.prototype.propertyIsEnumerable,Ho=(s,t,e)=>t in s?Ng(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Wg=(s,t)=>{for(var e in t||(t={}))Xg.call(t,e)&&Ho(s,e,t[e]);if(Fo)for(var e of Fo(t))zg.call(t,e)&&Ho(s,e,t[e]);return s};const oe=class extends X{constructor(s,t){super(),this.eventBus=s,this.element=t,this.xDragStartSubject=new R,this.xDragSubject=new R,this.xDragTickSubject=new R,this.xDragEndSubject=new R,this.yDragStartSubject=new R,this.yDragSubject=new R,this.yDragTickSubject=new R,this.yDragEndSubject=new R,this.mouseMoveSubject=new R,this.mouseMoveDocumentSubject=new R,this.clickSubject=new R,this.clickDocumentSubject=new R,this.dbClickSubject=new R,this.dbTapSubject=new R,this.mouseDownSubject=new R,this.mouseUpSubject=new R,this.mouseUpDocumentSubject=new R,this.wheelSubject=new R,this.touchStartSubject=new R,this.touchStartTimestamp=0,this.touchMoveSubject=new R,this.touchEndSubject=new R,this.touchCancelSubject=new R,this.longTouchStartSubject=new R,this.longTouchEndSubject=new R,this.contextMenuSubject=new R,this.fastTouchScroll=new R,this.mouseLeavesCanvasSubject=new R,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.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=oe.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=Wg({},this.dragStartPoint),oe.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===Ro.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=[],oe.DRAG_START_EVENTS.forEach(e=>{this.element.addEventListener(e,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(e,this.dragStartListener))}),this.trackMousePosition(),oe.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))}),oe.DRAG_END_EVENTS.forEach(e=>{document.addEventListener(e,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,e,this.dragEndListener))}),this.addSubscription(gt(this.element,pe(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(gt(document,pe(e=>this.clickDocumentSubject.next(e)),"click"));const s=qr();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=200)=>{o.preventDefault();let l=!1,c=null;c=setTimeout(()=>{l=!0,this.longTouchStartSubject.next(o)},a);const h=u=>{u.preventDefault(),u.touches.length>1&&c&&clearTimeout(c)},d=u=>{u.preventDefault(),c&&clearTimeout(c),l&&(l=!1,this.longTouchEndSubject.next(u)),this.element.removeEventListener("touchend",d),this.element.removeEventListener("touchmove",h)};this.element.addEventListener("touchmove",h),this.element.addEventListener("touchend",d)};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,f=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,p=d<=250;f&&p&&this.fastTouchScroll.next(o)}};this.addSubscription(gt(this.element,r,"touchend"))}this.addSubscription(gt(this.element,pe(()=>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,pe(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(gt(this.element,pe(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(gt(document,pe(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(zs).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(){oe.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(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(J(()=>!this.dragging))}observeMouseMoveDocument(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(s=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(J(()=>s(this.currentPointDocument.x,this.currentPointDocument.y)),ht(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(s=()=>!0){return this.xDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(s=()=>!0){return this.xDragSubject.pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(s=()=>!0){return this.xDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(s=()=>!0){return this.yDragStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(s=()=>!0){return this.yDragSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(s=()=>!0){return this.yDragEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(s=()=>!0,t=!1){const e=this.mouseMoveSubject.asObservable().pipe(J(()=>!(t&&this.dragging)),ht(()=>s(this.currentPoint.x,this.currentPoint.y))),n=this.observeMouseLeavesCanvas().pipe(ht(()=>!1));return vt(e,n).pipe(At())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(s=()=>!0){return this.clickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(s=()=>!0){return this.dbClickSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(s=()=>!0){return this.dbTapSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeWheel(s=()=>!0){return this.wheelSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(s=()=>!0){return this.touchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(s=()=>!0){return this.touchMoveSubject.asObservable().pipe(J(()=>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(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(s=()=>!0){return this.mouseUpSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(s=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(s=()=>!0){return this.contextMenuSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)),lo(t=>t.preventDefault()))}observeLongTouchStart(s=()=>!0){return this.longTouchStartSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(s=()=>!0){return this.longTouchEndSubject.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(s=()=>!0){return this.fastTouchScroll.asObservable().pipe(J(()=>s(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};let ds=oe;ds.DRAG_START_EVENTS=["mousedown","touchstart"],ds.DRAG_EVENTS=["mousemove","touchmove"],ds.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];var Vg=function(s){z(t,s);function t(e,n,i){e===void 0&&(e=1/0),n===void 0&&(n=1/0),i===void 0&&(i=Fs);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}(R);const an={};function Ug(s){return an[s]||(an[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"})),an[s]}const ko=(s,t=Date.now())=>{const n=Ug(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},jo=60*1e3;class Gg{constructor(t){this.config=t,this.timeZoneChangedSubject=new Vg,this.currentTzOffset=e=>ko(this.config.timezone,e)+new Date(e).getTimezoneOffset()*jo,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=Ad(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+ko(t,e)+new Date(e).getTimezoneOffset()*jo):e=>new Date(e)}}class Zg 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(At((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}class ln{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var n,i;this.parentElement=t;const r=e;ul(r),this.config=r;const o=Ol(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 Gg(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Bl(t);this.elements=c;const h=new pg;this.bus=h;const d=new vg(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 f=_h(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=re(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const p=new fe(this.dynamicObjectsCanvasModel);u.addDrawer(p,"SERIES_CLEAR");const v=re(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),P=re(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Rs(r,h,f,l,d);this.canvasBoundsContainer=_;const D=c.mainCanvas.parentElement;if(D===null)throw new Error("Couldn't get main canvas parent");const O=new ds(h,D);this.canvasInputListener=O,this.chartComponents.push(this.canvasInputListener);const j=new Xd(h,c.hitTestCanvas,O,_,u,r,this.canvasModels,c.chartResizer);this.hitTestCanvasModel=j;const H=new fe(j);u.addDrawer(H,"HIT_TEST_CLEAR");const B=new ja(h);this.canvasAnimation=B;const Y=x.PANE_UUID(q),W=new ar(r,()=>_.getBounds(Y),B);this.scaleModel=W;const G=re(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=G,this.cursorHandler=new Il(c.canvasArea,O,_,j),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Ig(O,_),this.chartComponents.push(this.crossEventProducer);const V=new uc("candle");this.chartBaseModel=V;const U=new Pu(h,W,_,r,B,O,D,V,j);this.chartPanComponent=U,this.chartComponents.push(U),this.userInputListenerComponents.push(U.chartAreaPanHandler);const Z=new Zg(j,B,h);this.hitTestComponent=Z,this.chartComponents.push(Z);const $=new of(V,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,B,O,u,this.cursorHandler,this.crossEventProducer,U,f,v,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=$;const et=this.paneManager.panes[q];this.mainPane=et,this.chartComponents.push($),this.dynamicObjects=new Td(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new id(V,$,h,this.dynamicObjectsCanvasModel,r,W,l,D,_,d);const tt=new Nh(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,j,O,G,U,$,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const Q=this.chartComponent.chartModel;this.chartModel=Q,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),j.addSubscriber($.hitTestController),this.xAxisComponent=new ag(h,r,f,tt,W,_,O,d,this.drawingManager,a,U,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const rt=new fe(f);u.addDrawer(rt,"MAIN_CLEAR");const lt=new mg(D,Q,O,r);this.chartComponents.push(lt),this.watermarkComponent=new Sf($,Q,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const ot=re(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new au(h,r,Q,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(Q)),this.navigationMapComponent=new mu(h,Q,f,r,O,_,u,l,U,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const xt=new tu(r,this.dynamicObjectsCanvasModel,Q,_,u);this.chartComponents.push(xt),this.initYAxisDrawer(v,P),this.yAxisComponent=et.mainExtent.yAxis;const Vt=new dg(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(Vt,te.MAIN),this.volumesComponent=new mf(this.dynamicObjectsCanvasModel,tt,W,_,u,r,$,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const me=new Vr(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(x.ALL_PANES),()=>this.canvasBoundsContainer.getBounds(Y),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,()=>r.components.grid.visible);this.chartComponents.push(me),this.hoverProducer=new Yg(this.crossEventProducer,W,r,Q,O,this.canvasBoundsContainer,this.paneManager,a,U.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new Sd(r,ot,_,u,$,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel),this.chartComponents.push(this.crossToolComponent);const Wo=re(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),cn=new af(this.elements,Wo);this.snapshotComponent=cn,this.chartComponents.push(cn);const hn=new qd(r,this.dynamicObjectsCanvasModel,j,Q,_,u,l,this.cursorHandler);this.eventsComponent=hn,this.chartComponents.push(hn),this.chartComponents.forEach(dn=>dn.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=Na(this.components)}initYAxisDrawer(t,e){const n=new Us,i=new fe(t),r=new fe(e);n.addDrawer(i,"YAXIS_CLEAR"),n.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(n,"Y_AXIS");const o=new fg(this.config,t,this.paneManager);n.addDrawer(o);const a=new ug(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:n=>e.test(n)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const n in e)n in t?typeof t[n]=="object"&&ln.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){Tt(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=vt(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 Yo extends ln{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.data.setChartType(t),this.yAxis.updateOrderedLabels()}createPane(){return this.paneManager.createPane()}}var $g=Object.defineProperty,Kg=Object.defineProperties,qg=Object.getOwnPropertyDescriptors,No=Object.getOwnPropertySymbols,Jg=Object.prototype.hasOwnProperty,Qg=Object.prototype.propertyIsEnumerable,Xo=(s,t,e)=>t in s?$g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,tp=(s,t)=>{for(var e in t||(t={}))Jg.call(t,e)&&Xo(s,e,t[e]);if(No)for(var e of No(t))Qg.call(t,e)&&Xo(s,e,t[e]);return s},ep=(s,t)=>Kg(s,qg(t));function zo(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=us(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ip(t[t.length-1],a,n)):d>3?t=t.concat(sp(t[t.length-1],a,r)):t=t.concat(np(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 f=0;f<t.length;f++){const p=t[f];Object.assign(p,{timestamp:u,isVisible:!0}),u+=1e3*s.period,s.withVolume&&(p.volume=Math.ceil(Math.random()*1e3+200))}return t}function us(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{id:ei(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function sp(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=us(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 np(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=us(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 ip(s,t,e){var n=[],i=Math.random()*e+e/2;function r(u){var f,p;return Math.random()>.5?(f=u.lo-t*.2,p=u.hi+t*1.2):(f=u.lo-t*1.2,p=u.hi+t*.2),{from:f,to:p}}for(var o=r(s),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=us(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=ep(tp({},window.DXChart),{generateCandlesData:zo});function rp(s){return zo(s)}const op=(s,t={})=>new Yo(s,t)})(),window.DXChart=fs})();})();