funhi-chart 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dts/adapters/CandleStorageAdapter.d.ts +14 -0
- package/dist/dts/components/FunhiChartOOP.d.ts +8 -0
- package/dist/dts/core/CandleManager.d.ts +73 -0
- package/dist/dts/core/ChartRenderer.d.ts +46 -0
- package/dist/dts/core/FunhiChartController.d.ts +61 -0
- package/dist/dts/core/TimeframeManager.d.ts +42 -0
- package/dist/dts/core/index.d.ts +8 -0
- package/dist/dts/core/types.d.ts +33 -0
- package/dist/dts/handlers/RealTimeUpdateHandler.d.ts +29 -0
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/validators/CandleValidator.d.ts +38 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
package/dist/index.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* TradingView Lightweight Charts™ v4.2.3
|
|
5
5
|
* Copyright (c) 2025 TradingView, Inc.
|
|
6
6
|
* Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
*/const l={upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},a={upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},c={color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},u={topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},d={baseValue:{type:"price",price:0},topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},f={color:"#26a69a",base:0},m={color:"#2196f3"},p={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var g,b,v;function w(t,e){const i={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[e];t.setLineDash(i)}function y(t,e,i,s){t.beginPath();const n=t.lineWidth%2?.5:0;t.moveTo(i,e+n),t.lineTo(s,e+n),t.stroke()}function S(t,e){if(!t)throw new Error("Assertion failed"+(e?": "+e:""))}function x(t){if(void 0===t)throw new Error("Value is undefined");return t}function M(t){if(null===t)throw new Error("Value is null");return t}function C(t){return M(x(t))}(v=g||(g={}))[v.Simple=0]="Simple",v[v.WithSteps=1]="WithSteps",v[v.Curved=2]="Curved",function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(b||(b={}));const E={khaki:"#f0e68c",azure:"#f0ffff",aliceblue:"#f0f8ff",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",gray:"#808080",green:"#008000",honeydew:"#f0fff0",floralwhite:"#fffaf0",lightblue:"#add8e6",lightcoral:"#f08080",lemonchiffon:"#fffacd",hotpink:"#ff69b4",lightyellow:"#ffffe0",greenyellow:"#adff2f",lightgoldenrodyellow:"#fafad2",limegreen:"#32cd32",linen:"#faf0e6",lightcyan:"#e0ffff",magenta:"#f0f",maroon:"#800000",olive:"#808000",orange:"#ffa500",oldlace:"#fdf5e6",mediumblue:"#0000cd",transparent:"#0000",lime:"#0f0",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",midnightblue:"#191970",orchid:"#da70d6",mediumorchid:"#ba55d3",mediumturquoise:"#48d1cc",orangered:"#ff4500",royalblue:"#4169e1",powderblue:"#b0e0e6",red:"#f00",coral:"#ff7f50",turquoise:"#40e0d0",white:"#fff",whitesmoke:"#f5f5f5",wheat:"#f5deb3",teal:"#008080",steelblue:"#4682b4",bisque:"#ffe4c4",aquamarine:"#7fffd4",aqua:"#0ff",sienna:"#a0522d",silver:"#c0c0c0",springgreen:"#00ff7f",antiquewhite:"#faebd7",burlywood:"#deb887",brown:"#a52a2a",beige:"#f5f5dc",chocolate:"#d2691e",chartreuse:"#7fff00",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cadetblue:"#5f9ea0",tomato:"#ff6347",fuchsia:"#f0f",blue:"#00f",salmon:"#fa8072",blanchedalmond:"#ffebcd",slateblue:"#6a5acd",slategray:"#708090",thistle:"#d8bfd8",tan:"#d2b48c",cyan:"#0ff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",blueviolet:"#8a2be2",black:"#000",darkmagenta:"#8b008b",darkslateblue:"#483d8b",darkkhaki:"#bdb76b",darkorchid:"#9932cc",darkorange:"#ff8c00",darkgreen:"#006400",darkred:"#8b0000",dodgerblue:"#1e90ff",darkslategray:"#2f4f4f",dimgray:"#696969",deepskyblue:"#00bfff",firebrick:"#b22222",forestgreen:"#228b22",indigo:"#4b0082",ivory:"#fffff0",lavenderblush:"#fff0f5",feldspar:"#d19275",indianred:"#cd5c5c",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightskyblue:"#87cefa",lightslategray:"#789",lightslateblue:"#8470ff",snow:"#fffafa",lightseagreen:"#20b2aa",lightsalmon:"#ffa07a",darksalmon:"#e9967a",darkviolet:"#9400d3",mediumpurple:"#9370d8",mediumaquamarine:"#66cdaa",skyblue:"#87ceeb",lavender:"#e6e6fa",lightsteelblue:"#b0c4de",mediumvioletred:"#c71585",mintcream:"#f5fffa",navajowhite:"#ffdead",navy:"#000080",olivedrab:"#6b8e23",palevioletred:"#d87093",violetred:"#d02090",yellow:"#ff0",yellowgreen:"#9acd32",lawngreen:"#7cfc00",pink:"#ffc0cb",paleturquoise:"#afeeee",palegoldenrod:"#eee8aa",darkolivegreen:"#556b2f",darkseagreen:"#8fbc8f",darkturquoise:"#00ced1",peachpuff:"#ffdab9",deeppink:"#ff1493",violet:"#ee82ee",palegreen:"#98fb98",mediumseagreen:"#3cb371",peru:"#cd853f",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",purple:"#800080",seagreen:"#2e8b57",seashell:"#fff5ee",papayawhip:"#ffefd5",mediumslateblue:"#7b68ee",plum:"#dda0dd",mediumspringgreen:"#00fa9a"};function _(t){return t<0?0:t>255?255:Math.round(t)||0}function $(t){return t<=0||t>1?Math.min(Math.max(t,0),1):Math.round(1e4*t)/1e4}const z=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,k=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i,R=/^rgb\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*\)$/,L=/^rgba\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d*\.?\d+)\s*\)$/;function T(t){(t=t.toLowerCase())in E&&(t=E[t]);{const e=L.exec(t)||R.exec(t);if(e)return[_(parseInt(e[1],10)),_(parseInt(e[2],10)),_(parseInt(e[3],10)),$(e.length<5?1:parseFloat(e[4]))]}{const e=k.exec(t);if(e)return[_(parseInt(e[1],16)),_(parseInt(e[2],16)),_(parseInt(e[3],16)),1]}{const e=z.exec(t);if(e)return[_(17*parseInt(e[1],16)),_(17*parseInt(e[2],16)),_(17*parseInt(e[3],16)),1]}throw new Error(`Cannot parse color: ${t}`)}function N(t){return.199*t[0]+.687*t[1]+.114*t[2]}function O(t){const e=T(t);return{t:`rgb(${e[0]}, ${e[1]}, ${e[2]})`,i:N(e)>160?"black":"white"}}class P{constructor(){this.h=[]}l(t,e,i){const s={o:t,_:e,u:!0===i};this.h.push(s)}v(t){const e=this.h.findIndex(e=>t===e.o);e>-1&&this.h.splice(e,1)}p(t){this.h=this.h.filter(e=>e._!==t)}m(t,e,i){const s=[...this.h];this.h=this.h.filter(t=>!t.u),s.forEach(s=>s.o(t,e,i))}M(){return this.h.length>0}S(){this.h=[]}}function F(t,...e){for(const i of e)for(const e in i)void 0!==i[e]&&Object.prototype.hasOwnProperty.call(i,e)&&!["__proto__","constructor","prototype"].includes(e)&&("object"!=typeof i[e]||void 0===t[e]||Array.isArray(i[e])?t[e]=i[e]:F(t[e],i[e]));return t}function V(t){return"number"==typeof t&&isFinite(t)}function D(t){return"number"==typeof t&&t%1==0}function I(t){return"string"==typeof t}function B(t){return"boolean"==typeof t}function A(t){const e=t;if(!e||"object"!=typeof e)return e;let i,s,n;for(s in i=Array.isArray(e)?[]:{},e)e.hasOwnProperty(s)&&(n=e[s],i[s]=n&&"object"==typeof n?A(n):n);return i}function W(t){return null!==t}function j(t){return null===t?void 0:t}const U="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function H(t,e,i){return void 0===e&&(e=U),`${i=void 0!==i?`${i} `:""}${t}px ${e}`}class K{constructor(t){this.k={C:1,T:5,P:NaN,R:"",D:"",V:"",O:"",B:0,A:0,I:0,L:0,N:0},this.F=t}W(){const t=this.k,e=this.j(),i=this.H();return t.P===e&&t.D===i||(t.P=e,t.D=i,t.R=H(e,i),t.L=2.5/12*e,t.B=t.L,t.A=e/12*t.T,t.I=e/12*t.T,t.N=0),t.V=this.$(),t.O=this.U(),this.k}$(){return this.F.W().layout.textColor}U(){return this.F.q()}j(){return this.F.W().layout.fontSize}H(){return this.F.W().layout.fontFamily}}class q{constructor(){this.Y=[]}Z(t){this.Y=t}X(t,e,i){this.Y.forEach(s=>{s.X(t,e,i)})}}class X{X(t,e,i){t.useBitmapCoordinateSpace(t=>this.K(t,e,i))}}class J extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.G||null===this.G.tt)return;const s=this.G.tt,n=this.G,r=Math.max(1,Math.floor(e))%2/2,o=o=>{t.beginPath();for(let h=s.to-1;h>=s.from;--h){const s=n.it[h],l=Math.round(s.nt*e)+r,a=s.st*i,c=o*i+r;t.moveTo(l,a),t.arc(l,a,c,0,2*Math.PI)}t.fill()};n.et>0&&(t.fillStyle=n.rt,o(n.ht+n.et)),t.fillStyle=n.lt,o(n.ht)}}function G(){return{it:[{nt:0,st:0,ot:0,_t:0}],lt:"",rt:"",ht:0,et:0,tt:null}}const Q={from:0,to:1};class Y{constructor(t,e){this.ut=new q,this.ct=[],this.dt=[],this.ft=!0,this.F=t,this.vt=e,this.ut.Z(this.ct)}bt(t){const e=this.F.wt();e.length!==this.ct.length&&(this.dt=e.map(G),this.ct=this.dt.map(t=>{const e=new J;return e.J(t),e}),this.ut.Z(this.ct)),this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.ut}Mt(){const t=2===this.vt.W().mode,e=this.F.wt(),i=this.vt.xt(),s=this.F.St();e.forEach((e,n)=>{var r;const o=this.dt[n],h=e.kt(i);if(t||null===h||!e.yt())return void(o.tt=null);const l=M(e.Ct());o.lt=h.Tt,o.ht=h.ht,o.et=h.Pt,o.it[0]._t=h._t,o.it[0].st=e.Dt().Rt(h._t,l.Vt),o.rt=null!==(r=h.Ot)&&void 0!==r?r:this.F.Bt(o.it[0].st/e.Dt().At()),o.it[0].ot=i,o.it[0].nt=s.It(i),o.tt=Q})}}class Z extends X{constructor(t){super(),this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;const n=this.zt.Lt.yt,r=this.zt.Et.yt;if(!n&&!r)return;const o=Math.round(this.zt.nt*i),h=Math.round(this.zt.st*s);t.lineCap="butt",n&&o>=0&&(t.lineWidth=Math.floor(this.zt.Lt.et*i),t.strokeStyle=this.zt.Lt.V,t.fillStyle=this.zt.Lt.V,w(t,this.zt.Lt.Nt),function(t,e,i,s){t.beginPath();const n=t.lineWidth%2?.5:0;t.moveTo(e+n,0),t.lineTo(e+n,s),t.stroke()}(t,o,0,e.height)),r&&h>=0&&(t.lineWidth=Math.floor(this.zt.Et.et*s),t.strokeStyle=this.zt.Et.V,t.fillStyle=this.zt.Et.V,w(t,this.zt.Et.Nt),y(t,h,0,e.width))}}class tt{constructor(t){this.ft=!0,this.Ft={Lt:{et:1,Nt:0,V:"",yt:!1},Et:{et:1,Nt:0,V:"",yt:!1},nt:0,st:0},this.Wt=new Z(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.yt(),e=M(this.jt.Ht()),i=e.$t().W().crosshair,s=this.Ft;if(2===i.mode)return s.Et.yt=!1,void(s.Lt.yt=!1);s.Et.yt=t&&this.jt.Ut(e),s.Lt.yt=t&&this.jt.qt(),s.Et.et=i.horzLine.width,s.Et.Nt=i.horzLine.style,s.Et.V=i.horzLine.color,s.Lt.et=i.vertLine.width,s.Lt.Nt=i.vertLine.style,s.Lt.V=i.vertLine.color,s.nt=this.jt.Yt(),s.st=this.jt.Zt()}}function et(t,e,i,s,n,r){t.fillRect(e+r,i,s-2*r,r),t.fillRect(e+r,i+n-r,s-2*r,r),t.fillRect(e,i,r,n),t.fillRect(e+s-r,i,r,n)}function it(t,e,i,s,n,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(e,i,s,n),t.restore()}function st(t,e,i,s,n,r){t.beginPath(),t.roundRect?t.roundRect(e,i,s,n,r):(t.lineTo(e+s-r[1],i),0!==r[1]&&t.arcTo(e+s,i,e+s,i+r[1],r[1]),t.lineTo(e+s,i+n-r[2]),0!==r[2]&&t.arcTo(e+s,i+n,e+s-r[2],i+n,r[2]),t.lineTo(e+r[3],i+n),0!==r[3]&&t.arcTo(e,i+n,e,i+n-r[3],r[3]),t.lineTo(e,i+r[0]),0!==r[0]&&t.arcTo(e,i,e+r[0],i,r[0]))}function nt(t,e,i,s,n,r,o=0,h=[0,0,0,0],l=""){if(t.save(),!o||!l||l===r)return st(t,e,i,s,n,h),t.fillStyle=r,t.fill(),void t.restore();const a=o/2;var c;st(t,e+a,i+a,s-o,n-o,(c=-a,h.map(t=>0===t?t:t+c))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==l&&(t.lineWidth=o,t.strokeStyle=l,t.closePath(),t.stroke()),t.restore()}function rt(t,e,i,s,n,r,o){t.save(),t.globalCompositeOperation="copy";const h=t.createLinearGradient(0,0,0,n);h.addColorStop(0,r),h.addColorStop(1,o),t.fillStyle=h,t.fillRect(e,i,s,n),t.restore()}class ot{constructor(t,e){this.J(t,e)}J(t,e){this.zt=t,this.Xt=e}At(t,e){return this.zt.yt?t.P+t.L+t.B:0}X(t,e,i,s){if(!this.zt.yt||0===this.zt.Kt.length)return;const n=this.zt.V,r=this.Xt.t,o=t.useBitmapCoordinateSpace(t=>{const o=t.context;o.font=e.R;const h=this.Gt(t,e,i,s),l=h.Jt;return h.Qt?nt(o,l.ti,l.ii,l.ni,l.si,r,l.ei,[l.ht,0,0,l.ht],r):nt(o,l.ri,l.ii,l.ni,l.si,r,l.ei,[0,l.ht,l.ht,0],r),this.zt.hi&&(o.fillStyle=n,o.fillRect(l.ri,l.li,l.ai-l.ri,l.oi)),this.zt._i&&(o.fillStyle=e.O,o.fillRect(h.Qt?l.ui-l.ei:0,l.ii,l.ei,l.ci-l.ii)),h});t.useMediaCoordinateSpace(({context:t})=>{const i=o.di;t.font=e.R,t.textAlign=o.Qt?"right":"left",t.textBaseline="middle",t.fillStyle=n,t.fillText(this.zt.Kt,i.fi,(i.ii+i.ci)/2+i.pi)})}Gt(t,e,i,s){var n;const{context:r,bitmapSize:o,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,c=this.zt.hi||!this.zt.mi?e.T:0,u=this.zt.bi?e.C:0,d=e.L+this.Xt.wi,f=e.B+this.Xt.gi,m=e.A,p=e.I,g=this.zt.Kt,b=e.P,v=i.Mi(r,g),w=Math.ceil(i.xi(r,g)),y=b+d+f,S=e.C+m+p+w+c,x=Math.max(1,Math.floor(a));let M=Math.round(y*a);M%2!=x%2&&(M+=1);const C=u>0?Math.max(1,Math.floor(u*l)):0,E=Math.round(S*l),_=Math.round(c*l),$=null!==(n=this.Xt.Si)&&void 0!==n?n:this.Xt.ki,z=Math.round($*a)-Math.floor(.5*a),k=Math.floor(z+x/2-M/2),R=k+M,L="right"===s,T=L?h.width-u:u,N=L?o.width-C:C;let O,P,F;return L?(O=N-E,P=N-_,F=T-c-m-u):(O=N+E,P=N+_,F=T+c+m),{Qt:L,Jt:{ii:k,li:z,ci:R,ni:E,si:M,ht:2*l,ei:C,ti:O,ri:N,ai:P,oi:x,ui:o.width},di:{ii:k/a,ci:R/a,fi:F,pi:v}}}}class ht{constructor(t){this.yi={ki:0,t:"#000",gi:0,wi:0},this.Ci={Kt:"",yt:!1,hi:!0,mi:!1,Ot:"",V:"#FFF",_i:!1,bi:!1},this.Ti={Kt:"",yt:!1,hi:!1,mi:!0,Ot:"",V:"#FFF",_i:!0,bi:!0},this.ft=!0,this.Pi=new(t||ot)(this.Ci,this.yi),this.Ri=new(t||ot)(this.Ti,this.yi)}Kt(){return this.Di(),this.Ci.Kt}ki(){return this.Di(),this.yi.ki}bt(){this.ft=!0}At(t,e=!1){return Math.max(this.Pi.At(t,e),this.Ri.At(t,e))}Vi(){return this.yi.Si||0}Oi(t){this.yi.Si=t}Bi(){return this.Di(),this.Ci.yt||this.Ti.yt}Ai(){return this.Di(),this.Ci.yt}gt(t){return this.Di(),this.Ci.hi=this.Ci.hi&&t.W().ticksVisible,this.Ti.hi=this.Ti.hi&&t.W().ticksVisible,this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Pi}Ii(){return this.Di(),this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Ri}Di(){this.ft&&(this.Ci.hi=!0,this.Ti.hi=!1,this.zi(this.Ci,this.Ti,this.yi))}}class lt extends ht{constructor(t,e,i){super(),this.jt=t,this.Li=e,this.Ei=i}zi(t,e,i){if(t.yt=!1,2===this.jt.W().mode)return;const s=this.jt.W().horzLine;if(!s.labelVisible)return;const n=this.Li.Ct();if(!this.jt.yt()||this.Li.Ni()||null===n)return;const r=O(s.labelBackgroundColor);i.t=r.t,t.V=r.i;const o=2/12*this.Li.P();i.wi=o,i.gi=o;const h=this.Ei(this.Li);i.ki=h.ki,t.Kt=this.Li.Fi(h._t,n),t.yt=!0}}const at=/[1-9]/g;class ct{constructor(){this.zt=null}J(t){this.zt=t}X(t,e){if(null===this.zt||!1===this.zt.yt||0===this.zt.Kt.length)return;const i=t.useMediaCoordinateSpace(({context:t})=>(t.font=e.R,Math.round(e.Wi.xi(t,M(this.zt).Kt,at))));if(i<=0)return;const s=e.ji,n=i+2*s,r=n/2,o=this.zt.Hi;let h=this.zt.ki,l=Math.floor(h-r)+.5;l<0?(h+=Math.abs(0-l),l=Math.floor(h-r)+.5):l+n>o&&(h-=Math.abs(o-(l+n)),l=Math.floor(h-r)+.5);const a=l+n,c=Math.ceil(0+e.C+e.T+e.L+e.P+e.B);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:s})=>{const n=M(this.zt);t.fillStyle=n.t;const r=Math.round(l*i),o=Math.round(0*s),h=Math.round(a*i),u=Math.round(c*s),d=Math.round(2*i);if(t.beginPath(),t.moveTo(r,o),t.lineTo(r,u-d),t.arcTo(r,u,r+d,u,d),t.lineTo(h-d,u),t.arcTo(h,u,h,u-d,d),t.lineTo(h,o),t.fill(),n.hi){const r=Math.round(n.ki*i),h=o,l=Math.round((h+e.T)*s);t.fillStyle=n.V;const a=Math.max(1,Math.floor(i)),c=Math.floor(.5*i);t.fillRect(r-c,h,a,l-h)}}),t.useMediaCoordinateSpace(({context:t})=>{const i=M(this.zt),n=0+e.C+e.T+e.L+e.P/2;t.font=e.R,t.textAlign="left",t.textBaseline="middle",t.fillStyle=i.V;const r=e.Wi.Mi(t,"Apr0");t.translate(l+s,n+r),t.fillText(i.Kt,0,0)})}}class ut{constructor(t,e,i){this.ft=!0,this.Wt=new ct,this.Ft={yt:!1,t:"#4c525e",V:"white",Kt:"",Hi:0,ki:NaN,hi:!0},this.vt=t,this.$i=e,this.Ei=i}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt.J(this.Ft),this.Wt}Mt(){const t=this.Ft;if(t.yt=!1,2===this.vt.W().mode)return;const e=this.vt.W().vertLine;if(!e.labelVisible)return;const i=this.$i.St();if(i.Ni())return;t.Hi=i.Hi();const s=this.Ei();if(null===s)return;t.ki=s.ki;const n=i.Ui(this.vt.xt());t.Kt=i.qi(M(n)),t.yt=!0;const r=O(e.labelBackgroundColor);t.t=r.t,t.V=r.i,t.hi=i.W().ticksVisible}}class dt{constructor(){this.Yi=null,this.Zi=0}Xi(){return this.Zi}Ki(t){this.Zi=t}Dt(){return this.Yi}Gi(t){this.Yi=t}Ji(t){return[]}Qi(){return[]}yt(){return!0}}var ft;!function(t){t[t.Normal=0]="Normal",t[t.Magnet=1]="Magnet",t[t.Hidden=2]="Hidden"}(ft||(ft={}));class mt extends dt{constructor(t,e){super(),this.tn=null,this.nn=NaN,this.sn=0,this.en=!0,this.rn=new Map,this.hn=!1,this.ln=NaN,this.an=NaN,this._n=NaN,this.un=NaN,this.$i=t,this.cn=e,this.dn=new Y(t,this),this.fn=((t,e)=>i=>{const s=e(),n=t();if(i===M(this.tn).vn())return{_t:n,ki:s};{const t=M(i.Ct());return{_t:i.pn(s,t),ki:s}}})(()=>this.nn,()=>this.an);const i=((t,e)=>()=>{const i=this.$i.St().mn(t()),s=e();return i&&Number.isFinite(s)?{ot:i,ki:s}:null})(()=>this.sn,()=>this.Yt());this.bn=new ut(this,t,i),this.wn=new tt(this)}W(){return this.cn}gn(t,e){this._n=t,this.un=e}Mn(){this._n=NaN,this.un=NaN}xn(){return this._n}Sn(){return this.un}kn(t,e,i){this.hn||(this.hn=!0),this.en=!0,this.yn(t,e,i)}xt(){return this.sn}Yt(){return this.ln}Zt(){return this.an}yt(){return this.en}Cn(){this.en=!1,this.Tn(),this.nn=NaN,this.ln=NaN,this.an=NaN,this.tn=null,this.Mn()}Pn(t){return null!==this.tn?[this.wn,this.dn]:[]}Ut(t){return t===this.tn&&this.cn.horzLine.visible}qt(){return this.cn.vertLine.visible}Rn(t,e){this.en&&this.tn===t||this.rn.clear();const i=[];return this.tn===t&&i.push(this.Dn(this.rn,e,this.fn)),i}Qi(){return this.en?[this.bn]:[]}Ht(){return this.tn}Vn(){this.wn.bt(),this.rn.forEach(t=>t.bt()),this.bn.bt(),this.dn.bt()}On(t){return t&&!t.vn().Ni()?t.vn():null}yn(t,e,i){this.Bn(t,e,i)&&this.Vn()}Bn(t,e,i){const s=this.ln,n=this.an,r=this.nn,o=this.sn,h=this.tn,l=this.On(i);this.sn=t,this.ln=isNaN(t)?NaN:this.$i.St().It(t),this.tn=i;const a=null!==l?l.Ct():null;return null!==l&&null!==a?(this.nn=e,this.an=l.Rt(e,a)):(this.nn=NaN,this.an=NaN),s!==this.ln||n!==this.an||o!==this.sn||r!==this.nn||h!==this.tn}Tn(){const t=this.$i.wt().map(t=>t.In().An()).filter(W),e=0===t.length?null:Math.max(...t);this.sn=null!==e?e:NaN}Dn(t,e,i){let s=t.get(e);return void 0===s&&(s=new lt(this,e,i),t.set(e,s)),s}}function pt(t){return"left"===t||"right"===t}class gt{constructor(t){this.zn=new Map,this.Ln=[],this.En=t}Nn(t,e){const i=function(t,e){return void 0===t?e:{Fn:Math.max(t.Fn,e.Fn),Wn:t.Wn||e.Wn}}(this.zn.get(t),e);this.zn.set(t,i)}jn(){return this.En}Hn(t){const e=this.zn.get(t);return void 0===e?{Fn:this.En}:{Fn:Math.max(this.En,e.Fn),Wn:e.Wn}}$n(){this.Un(),this.Ln=[{qn:0}]}Yn(t){this.Un(),this.Ln=[{qn:1,Vt:t}]}Zn(t){this.Xn(),this.Ln.push({qn:5,Vt:t})}Un(){this.Xn(),this.Ln.push({qn:6})}Kn(){this.Un(),this.Ln=[{qn:4}]}Gn(t){this.Un(),this.Ln.push({qn:2,Vt:t})}Jn(t){this.Un(),this.Ln.push({qn:3,Vt:t})}Qn(){return this.Ln}ts(t){for(const e of t.Ln)this.ns(e);this.En=Math.max(this.En,t.En),t.zn.forEach((t,e)=>{this.Nn(e,t)})}static ss(){return new gt(2)}static es(){return new gt(3)}ns(t){switch(t.qn){case 0:this.$n();break;case 1:this.Yn(t.Vt);break;case 2:this.Gn(t.Vt);break;case 3:this.Jn(t.Vt);break;case 4:this.Kn();break;case 5:this.Zn(t.Vt);break;case 6:this.Xn()}}Xn(){const t=this.Ln.findIndex(t=>5===t.qn);-1!==t&&this.Ln.splice(t,1)}}function bt(t,e){if(!V(t))return"n/a";if(!D(e))throw new TypeError("invalid length");if(e<0||e>16)throw new TypeError("invalid length");return 0===e?t.toString():("0000000000000000"+t.toString()).slice(-e)}class vt{constructor(t,e){if(e||(e=1),V(t)&&D(t)||(t=100),t<0)throw new TypeError("invalid base");this.Li=t,this.rs=e,this.hs()}format(t){const e=t<0?"−":"";return t=Math.abs(t),e+this.ls(t)}hs(){if(this._s=0,this.Li>0&&this.rs>0){let t=this.Li;for(;t>1;)t/=10,this._s++}}ls(t){const e=this.Li/this.rs;let i=Math.floor(t),s="";const n=void 0!==this._s?this._s:NaN;if(e>1){let r=+(Math.round(t*e)-i*e).toFixed(this._s);r>=e&&(r-=e,i+=1),s="."+bt(+r.toFixed(this._s)*this.rs,n)}else i=Math.round(i*e)/e,n>0&&(s="."+bt(0,n));return i.toFixed(0)+s}}class wt extends vt{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class yt{constructor(t){this.us=t}format(t){let e="";return t<0&&(e="-",t=-t),t<995?e+this.cs(t):t<999995?e+this.cs(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),e+this.cs(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),e+this.cs(t/1e9)+"B")}cs(t){let e;const i=Math.pow(10,this.us);return e=(t=Math.round(t*i)/i)>=1e-15&&t<1?t.toFixed(this.us).replace(/\.?0+$/,""):String(t),e.replace(/(\.[1-9]*)0+$/,(t,e)=>e)}}function St(t,e,i,s,n,r,o){if(0===e.length||s.from>=e.length||s.to<=0)return;const{context:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,c=e[s.from];let u=r(t,c),d=c;if(s.to-s.from<2){const e=n/2;h.beginPath();const i={nt:c.nt-e,st:c.st},s={nt:c.nt+e,st:c.st};h.moveTo(i.nt*l,i.st*a),h.lineTo(s.nt*l,s.st*a),o(t,u,i,s)}else{const n=(e,i)=>{o(t,u,d,i),h.beginPath(),u=e,d=i};let f=d;h.beginPath(),h.moveTo(c.nt*l,c.st*a);for(let o=s.from+1;o<s.to;++o){f=e[o];const s=r(t,f);switch(i){case 0:h.lineTo(f.nt*l,f.st*a);break;case 1:h.lineTo(f.nt*l,e[o-1].st*a),s!==u&&(n(s,f),h.lineTo(f.nt*l,e[o-1].st*a)),h.lineTo(f.nt*l,f.st*a);break;case 2:{const[t,i]=Et(e,o-1,o);h.bezierCurveTo(t.nt*l,t.st*a,i.nt*l,i.st*a,f.nt*l,f.st*a);break}}1!==i&&s!==u&&(n(s,f),h.moveTo(f.nt*l,f.st*a))}(d!==f||d===f&&1===i)&&o(t,u,d,f)}}const xt=6;function Mt(t,e){return{nt:t.nt-e.nt,st:t.st-e.st}}function Ct(t,e){return{nt:t.nt/e,st:t.st/e}}function Et(t,e,i){const s=Math.max(0,e-1),n=Math.min(t.length-1,i+1);var r,o;return[(r=t[e],o=Ct(Mt(t[i],t[s]),xt),{nt:r.nt+o.nt,st:r.st+o.st}),Mt(t[i],Ct(Mt(t[n],t[e]),xt))]}function _t(t,e,i,s,n){const{context:r,horizontalPixelRatio:o,verticalPixelRatio:h}=e;r.lineTo(n.nt*o,t*h),r.lineTo(s.nt*o,t*h),r.closePath(),r.fillStyle=i,r.fill()}class $t extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){var e;if(null===this.G)return;const{it:i,tt:s,ds:n,et:r,Nt:o,fs:h}=this.G,l=null!==(e=this.G.vs)&&void 0!==e?e:this.G.ps?0:t.mediaSize.height;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,w(a,o),a.lineWidth=1,St(t,i,h,s,n,this.bs.bind(this),_t.bind(null,l))}}function zt(t,e,i){return Math.min(Math.max(t,e),i)}function kt(t,e,i){return e-t<=i}function Rt(t){const e=Math.ceil(t);return e%2==0?e-1:e}class Lt{ws(t,e){const i=this.gs,{Ms:s,xs:n,Ss:r,ks:o,ys:h,vs:l}=e;if(void 0===this.Cs||void 0===i||i.Ms!==s||i.xs!==n||i.Ss!==r||i.ks!==o||i.vs!==l||i.ys!==h){const i=t.context.createLinearGradient(0,0,0,h);if(i.addColorStop(0,s),null!=l){const e=zt(l*t.verticalPixelRatio/h,0,1);i.addColorStop(e,n),i.addColorStop(e,r)}i.addColorStop(1,o),this.Cs=i,this.gs=e}return this.Cs}}class Tt extends $t{constructor(){super(...arguments),this.Ts=new Lt}bs(t,e){return this.Ts.ws(t,{Ms:e.Ps,xs:"",Ss:"",ks:e.Rs,ys:t.bitmapSize.height})}}function Nt(t,e){const i=t.context;i.strokeStyle=e,i.stroke()}class Ot extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){if(null===this.G)return;const{it:e,tt:i,ds:s,fs:n,et:r,Nt:o,Ds:h}=this.G;if(null===i)return;const l=t.context;l.lineCap="butt",l.lineWidth=r*t.verticalPixelRatio,w(l,o),l.lineJoin="round";const a=this.Vs.bind(this);void 0!==n&&St(t,e,n,i,s,a,Nt),h&&function(t,e,i,s,n){const{horizontalPixelRatio:r,verticalPixelRatio:o,context:h}=t;let l=null;const a=Math.max(1,Math.floor(r))%2/2,c=i*o+a;for(let i=s.to-1;i>=s.from;--i){const s=e[i];if(s){const e=n(t,s);e!==l&&(h.beginPath(),null!==l&&h.fill(),h.fillStyle=e,l=e);const i=Math.round(s.nt*r)+a,u=s.st*o;h.moveTo(i,u),h.arc(i,u,c,0,2*Math.PI)}}h.fill()}(t,e,h,i,a)}}class Pt extends Ot{Vs(t,e){return e.lt}}function Ft(t,e,i,s,n=0,r=e.length){let o=r-n;for(;0<o;){const r=o>>1,h=n+r;s(e[h],i)===t?(n=h+1,o-=r+1):o=r}return n}const Vt=Ft.bind(null,!0),Dt=Ft.bind(null,!1);function It(t,e){return t.ot<e}function Bt(t,e){return e<t.ot}function At(t,e,i){const s=e.Os(),n=e.ui(),r=Vt(t,s,It),o=Dt(t,n,Bt);if(!i)return{from:r,to:o};let h=r,l=o;return r>0&&r<t.length&&t[r].ot>=s&&(h=r-1),o>0&&o<t.length&&t[o-1].ot<=n&&(l=o+1),{from:h,to:l}}class Wt{constructor(t,e,i){this.Bs=!0,this.As=!0,this.Is=!0,this.zs=[],this.Ls=null,this.Es=t,this.Ns=e,this.Fs=i}bt(t){this.Bs=!0,"data"===t&&(this.As=!0),"options"===t&&(this.Is=!0)}gt(){return this.Es.yt()?(this.Ws(),null===this.Ls?null:this.js):null}Hs(){this.zs=this.zs.map(t=>Object.assign(Object.assign({},t),this.Es.Us().$s(t.ot)))}qs(){this.Ls=null}Ws(){this.As&&(this.Ys(),this.As=!1),this.Is&&(this.Hs(),this.Is=!1),this.Bs&&(this.Zs(),this.Bs=!1)}Zs(){const t=this.Es.Dt(),e=this.Ns.St();if(this.qs(),e.Ni()||t.Ni())return;const i=e.Xs();if(null===i)return;if(0===this.Es.In().Ks())return;const s=this.Es.Ct();null!==s&&(this.Ls=At(this.zs,i,this.Fs),this.Gs(t,e,s.Vt),this.Js())}}class jt extends Wt{constructor(t,e){super(t,e,!0)}Gs(t,e,i){e.Qs(this.zs,j(this.Ls)),t.te(this.zs,i,j(this.Ls))}ie(t,e){return{ot:t,_t:e,nt:NaN,st:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>{const i=e.Vt[3];return this.se(e.ee,i,t)})}}class Ut extends jt{constructor(t,e){super(t,e),this.js=new q,this.re=new Tt,this.he=new Pt,this.js.Z([this.re,this.he])}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.W();this.re.J({fs:t.lineType,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,vs:null,ps:t.invertFilledArea,tt:this.Ls,ds:this.Ns.St().le()}),this.he.J({fs:t.lineVisible?t.lineType:void 0,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,tt:this.Ls,ds:this.Ns.St().le(),Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}class Ht extends X{constructor(){super(...arguments),this.zt=null,this.ae=0,this.oe=0}J(t){this.zt=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.zt||0===this.zt.In.length||null===this.zt.tt)return;this.ae=this._e(e),this.ae>=2&&Math.max(1,Math.floor(e))%2!=this.ae%2&&this.ae--,this.oe=this.zt.ue?Math.min(this.ae,Math.floor(e)):this.ae;let s=null;const n=this.oe<=this.ae&&this.zt.le>=Math.floor(1.5*e);for(let r=this.zt.tt.from;r<this.zt.tt.to;++r){const o=this.zt.In[r];s!==o.ce&&(t.fillStyle=o.ce,s=o.ce);const h=Math.floor(.5*this.oe),l=Math.round(o.nt*e),a=l-h,c=this.oe,u=a+c-1,d=Math.min(o.de,o.fe),f=Math.max(o.de,o.fe),m=Math.round(d*i)-h,p=Math.round(f*i)+h,g=Math.max(p-m,this.oe);t.fillRect(a,m,c,g);const b=Math.ceil(1.5*this.ae);if(n){if(this.zt.ve){const e=l-b;let s=Math.max(m,Math.round(o.pe*i)-h),n=s+c-1;n>m+g-1&&(n=m+g-1,s=n-c+1),t.fillRect(e,s,a-e,n-s+1)}const e=l+b;let s=Math.max(m,Math.round(o.me*i)-h),n=s+c-1;n>m+g-1&&(n=m+g-1,s=n-c+1),t.fillRect(u+1,s,e-u,n-s+1)}}}_e(t){const e=Math.floor(t);return Math.max(e,Math.floor(function(t,e){return Math.floor(.3*t*e)}(M(this.zt).le,t)))}}class Kt extends Wt{constructor(t,e){super(t,e,!1)}Gs(t,e,i){e.Qs(this.zs,j(this.Ls)),t.be(this.zs,i,j(this.Ls))}we(t,e,i){return{ot:t,ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3],nt:NaN,pe:NaN,de:NaN,fe:NaN,me:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>this.se(e.ee,e,t))}}class qt extends Kt{constructor(){super(...arguments),this.js=new Ht}se(t,e,i){return Object.assign(Object.assign({},this.we(t,e,i)),i.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),ve:t.openVisible,ue:t.thinBars,tt:this.Ls})}}class Xt extends $t{constructor(){super(...arguments),this.Ts=new Lt}bs(t,e){const i=this.G;return this.Ts.ws(t,{Ms:e.ke,xs:e.ye,Ss:e.Ce,ks:e.Te,ys:t.bitmapSize.height,vs:i.vs})}}class Jt extends Ot{constructor(){super(...arguments),this.Pe=new Lt}Vs(t,e){const i=this.G;return this.Pe.ws(t,{Ms:e.Re,xs:e.Re,Ss:e.De,ks:e.De,ys:t.bitmapSize.height,vs:i.vs})}}class Gt extends jt{constructor(t,e){super(t,e),this.js=new q,this.Ve=new Xt,this.Oe=new Jt,this.js.Z([this.Ve,this.Oe])}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.Ct();if(null===t)return;const e=this.Es.W(),i=this.Es.Dt().Rt(e.baseValue.price,t.Vt),s=this.Ns.St().le();this.Ve.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineType,vs:i,ps:!1,tt:this.Ls,ds:s}),this.Oe.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineVisible?e.lineType:void 0,Ds:e.pointMarkersVisible?e.pointMarkersRadius||e.lineWidth/2+2:void 0,vs:i,tt:this.Ls,ds:s})}}class Qt extends X{constructor(){super(...arguments),this.zt=null,this.ae=0}J(t){this.zt=t}K(t){if(null===this.zt||0===this.zt.In.length||null===this.zt.tt)return;const{horizontalPixelRatio:e}=t;this.ae=function(t,e){if(t>=2.5&&t<=4)return Math.floor(3*e);const i=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),s=Math.floor(t*i*e),n=Math.floor(t*e),r=Math.min(s,n);return Math.max(Math.floor(e),r)}(this.zt.le,e),this.ae>=2&&Math.floor(e)%2!=this.ae%2&&this.ae--;const i=this.zt.In;this.zt.Be&&this.Ae(t,i,this.zt.tt),this.zt._i&&this.Ie(t,i,this.zt.tt);const s=this.ze(e);(!this.zt._i||this.ae>2*s)&&this.Le(t,i,this.zt.tt)}Ae(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="",h=Math.min(Math.floor(n),Math.floor(this.zt.le*n));h=Math.max(Math.floor(n),Math.min(h,this.ae));const l=Math.floor(.5*h);let a=null;for(let t=i.from;t<i.to;t++){const i=e[t];i.Ee!==o&&(s.fillStyle=i.Ee,o=i.Ee);const c=Math.round(Math.min(i.pe,i.me)*r),u=Math.round(Math.max(i.pe,i.me)*r),d=Math.round(i.de*r),f=Math.round(i.fe*r);let m=Math.round(n*i.nt)-l;const p=m+h-1;null!==a&&(m=Math.max(a+1,m),m=Math.min(m,p));const g=p-m+1;s.fillRect(m,d,g,c-d),s.fillRect(m,u+1,g,f-u),a=p}}ze(t){let e=Math.floor(1*t);this.ae<=2*e&&(e=Math.floor(.5*(this.ae-1)));const i=Math.max(Math.floor(t),e);return this.ae<=2*i?Math.max(Math.floor(t),Math.floor(1*t)):i}Ie(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="";const h=this.ze(n);let l=null;for(let t=i.from;t<i.to;t++){const i=e[t];i.Ne!==o&&(s.fillStyle=i.Ne,o=i.Ne);let a=Math.round(i.nt*n)-Math.floor(.5*this.ae);const c=a+this.ae-1,u=Math.round(Math.min(i.pe,i.me)*r),d=Math.round(Math.max(i.pe,i.me)*r);if(null!==l&&(a=Math.max(l+1,a),a=Math.min(a,c)),this.zt.le*n>2*h)et(s,a,u,c-a+1,d-u+1,h);else{const t=c-a+1;s.fillRect(a,u,t,d-u+1)}l=c}}Le(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="";const h=this.ze(n);for(let t=i.from;t<i.to;t++){const i=e[t];let l=Math.round(Math.min(i.pe,i.me)*r),a=Math.round(Math.max(i.pe,i.me)*r),c=Math.round(i.nt*n)-Math.floor(.5*this.ae),u=c+this.ae-1;if(i.ce!==o){const t=i.ce;s.fillStyle=t,o=t}this.zt._i&&(c+=h,l+=h,u-=h,a-=h),l>a||s.fillRect(c,l,u-c+1,a-l+1)}}}class Yt extends Kt{constructor(){super(...arguments),this.js=new Qt}se(t,e,i){return Object.assign(Object.assign({},this.we(t,e,i)),i.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),Be:t.wickVisible,_i:t.borderVisible,tt:this.Ls})}}class Zt{constructor(t,e){this.Fe=t,this.Li=e}X(t,e,i){this.Fe.draw(t,this.Li,e,i)}}class te extends Wt{constructor(t,e,i){super(t,e,!1),this.wn=i,this.js=new Zt(this.wn.renderer(),e=>{const i=t.Ct();return null===i?null:t.Dt().Rt(e,i.Vt)})}We(t){return this.wn.priceValueBuilder(t)}je(t){return this.wn.isWhitespace(t)}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>Object.assign(Object.assign({ot:e.ee,nt:NaN},t.$s(e.ee)),{He:e.$e}))}Gs(t,e){e.Qs(this.zs,j(this.Ls))}Js(){this.wn.update({bars:this.zs.map(ee),barSpacing:this.Ns.St().le(),visibleRange:this.Ls},this.Es.W())}}function ee(t){return{x:t.nt,time:t.ot,originalData:t.He,barColor:t.ce}}class ie extends X{constructor(){super(...arguments),this.zt=null,this.Ue=[]}J(t){this.zt=t,this.Ue=[]}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.zt||0===this.zt.it.length||null===this.zt.tt)return;this.Ue.length||this.qe(e);const s=Math.max(1,Math.floor(i)),n=Math.round(this.zt.Ye*i)-Math.floor(s/2),r=n+s;for(let e=this.zt.tt.from;e<this.zt.tt.to;e++){const o=this.zt.it[e],h=this.Ue[e-this.zt.tt.from],l=Math.round(o.st*i);let a,c;t.fillStyle=o.ce,l<=n?(a=l,c=r):(a=n,c=l-Math.floor(s/2)+s),t.fillRect(h.Os,a,h.ui-h.Os+1,c-a)}}qe(t){if(null===this.zt||0===this.zt.it.length||null===this.zt.tt)return void(this.Ue=[]);const e=Math.ceil(this.zt.le*t)<=1?0:Math.max(1,Math.floor(t)),i=Math.round(this.zt.le*t)-e;this.Ue=new Array(this.zt.tt.to-this.zt.tt.from);for(let e=this.zt.tt.from;e<this.zt.tt.to;e++){const s=this.zt.it[e],n=Math.round(s.nt*t);let r,o;if(i%2){const t=(i-1)/2;r=n-t,o=n+t}else{const t=i/2;r=n-t,o=n+t-1}this.Ue[e-this.zt.tt.from]={Os:r,ui:o,Ze:n,Xe:s.nt*t,ot:s.ot}}for(let t=this.zt.tt.from+1;t<this.zt.tt.to;t++){const i=this.Ue[t-this.zt.tt.from],s=this.Ue[t-this.zt.tt.from-1];i.ot===s.ot+1&&i.Os-s.ui!==e+1&&(s.Ze>s.Xe?s.ui=i.Os-e-1:i.Os=s.ui+e+1)}let s=Math.ceil(this.zt.le*t);for(let t=this.zt.tt.from;t<this.zt.tt.to;t++){const e=this.Ue[t-this.zt.tt.from];e.ui<e.Os&&(e.ui=e.Os);const i=e.ui-e.Os+1;s=Math.min(i,s)}if(e>0&&s<4)for(let t=this.zt.tt.from;t<this.zt.tt.to;t++){const e=this.Ue[t-this.zt.tt.from];e.ui-e.Os+1>s&&(e.Ze>e.Xe?e.ui-=1:e.Os+=1)}}}class se extends jt{constructor(){super(...arguments),this.js=new ie}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t={it:this.zs,le:this.Ns.St().le(),tt:this.Ls,Ye:this.Es.Dt().Rt(this.Es.W().base,M(this.Es.Ct()).Vt)};this.js.J(t)}}class ne extends jt{constructor(){super(...arguments),this.js=new Pt}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.W(),e={it:this.zs,Nt:t.lineStyle,fs:t.lineVisible?t.lineType:void 0,et:t.lineWidth,Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,tt:this.Ls,ds:this.Ns.St().le()};this.js.J(e)}}const re=/[2-9]/g;class oe{constructor(t=50){this.Ke=0,this.Ge=1,this.Je=1,this.Qe={},this.tr=new Map,this.ir=t}nr(){this.Ke=0,this.tr.clear(),this.Ge=1,this.Je=1,this.Qe={}}xi(t,e,i){return this.sr(t,e,i).width}Mi(t,e,i){const s=this.sr(t,e,i);return((s.actualBoundingBoxAscent||0)-(s.actualBoundingBoxDescent||0))/2}sr(t,e,i){const s=i||re,n=String(e).replace(s,"0");if(this.tr.has(n))return x(this.tr.get(n)).er;if(this.Ke===this.ir){const t=this.Qe[this.Je];delete this.Qe[this.Je],this.tr.delete(t),this.Je++,this.Ke--}t.save(),t.textBaseline="middle";const r=t.measureText(n);return t.restore(),0===r.width&&e.length||(this.tr.set(n,{er:r,rr:this.Ge}),this.Qe[this.Ge]=n,this.Ke++,this.Ge++),r}}class he{constructor(t){this.hr=null,this.k=null,this.lr="right",this.ar=t}_r(t,e,i){this.hr=t,this.k=e,this.lr=i}X(t){null!==this.k&&null!==this.hr&&this.hr.X(t,this.k,this.ar,this.lr)}}class le{constructor(t,e,i){this.ur=t,this.ar=new oe(50),this.cr=e,this.F=i,this.j=-1,this.Wt=new he(this.ar)}gt(){const t=this.F.dr(this.cr);if(null===t)return null;const e=t.vr(this.cr)?t.pr():this.cr.Dt();if(null===e)return null;const i=t.mr(e);if("overlay"===i)return null;const s=this.F.br();return s.P!==this.j&&(this.j=s.P,this.ar.nr()),this.Wt._r(this.ur.Ii(),s,i),this.Wt}}class ae extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}wr(t,e){var i;if(!(null===(i=this.zt)||void 0===i?void 0:i.yt))return null;const{st:s,et:n,gr:r}=this.zt;return e>=s-n-7&&e<=s+n+7?{Mr:this.zt,gr:r}:null}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;if(!1===this.zt.yt)return;const n=Math.round(this.zt.st*s);n<0||n>e.height||(t.lineCap="butt",t.strokeStyle=this.zt.V,t.lineWidth=Math.floor(this.zt.et*i),w(t,this.zt.Nt),y(t,n,0,e.width))}}class ce{constructor(t){this.Sr={st:0,V:"rgba(0, 0, 0, 0)",et:1,Nt:0,yt:!1},this.kr=new ae,this.ft=!0,this.Es=t,this.Ns=t.$t(),this.kr.J(this.Sr)}bt(){this.ft=!0}gt(){return this.Es.yt()?(this.ft&&(this.yr(),this.ft=!1),this.kr):null}}class ue extends ce{constructor(t){super(t)}yr(){this.Sr.yt=!1;const t=this.Es.Dt(),e=t.Cr().Cr;if(2!==e&&3!==e)return;const i=this.Es.W();if(!i.baseLineVisible||!this.Es.yt())return;const s=this.Es.Ct();null!==s&&(this.Sr.yt=!0,this.Sr.st=t.Rt(s.Vt,s.Vt),this.Sr.V=i.baseLineColor,this.Sr.et=i.baseLineWidth,this.Sr.Nt=i.baseLineStyle)}}class de extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}$e(){return this.zt}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){const s=this.zt;if(null===s)return;const n=Math.max(1,Math.floor(e)),r=n%2/2,o=Math.round(s.Xe.x*e)+r,h=s.Xe.y*i;t.fillStyle=s.Tr,t.beginPath();const l=Math.max(2,1.5*s.Pr)*e;t.arc(o,h,l,0,2*Math.PI,!1),t.fill(),t.fillStyle=s.Rr,t.beginPath(),t.arc(o,h,s.ht*e,0,2*Math.PI,!1),t.fill(),t.lineWidth=n,t.strokeStyle=s.Dr,t.beginPath(),t.arc(o,h,s.ht*e+n/2,0,2*Math.PI,!1),t.stroke()}}const fe=[{Vr:0,Or:.25,Br:4,Ar:10,Ir:.25,zr:0,Lr:.4,Er:.8},{Vr:.25,Or:.525,Br:10,Ar:14,Ir:0,zr:0,Lr:.8,Er:0},{Vr:.525,Or:1,Br:14,Ar:14,Ir:0,zr:0,Lr:0,Er:0}];function me(t,e,i,s){return function(t,e){if("transparent"===t)return t;const i=T(t),s=i[3];return`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${e*s})`}(t,i+(s-i)*e)}function pe(t,e){const i=t%2600/2600;let s;for(const t of fe)if(i>=t.Vr&&i<=t.Or){s=t;break}S(void 0!==s,"Last price animation internal logic error");const n=(i-s.Vr)/(s.Or-s.Vr);return{Rr:me(e,n,s.Ir,s.zr),Dr:me(e,n,s.Lr,s.Er),ht:(r=n,o=s.Br,h=s.Ar,o+(h-o)*r)};var r,o,h}class ge{constructor(t){this.Wt=new de,this.ft=!0,this.Nr=!0,this.Fr=performance.now(),this.Wr=this.Fr-1,this.jr=t}Hr(){this.Wr=this.Fr-1,this.bt()}$r(){if(this.bt(),2===this.jr.W().lastPriceAnimation){const t=performance.now(),e=this.Wr-t;if(e>0)return void(e<650&&(this.Wr+=2600));this.Fr=t,this.Wr=t+2600}}bt(){this.ft=!0}Ur(){this.Nr=!0}yt(){return 0!==this.jr.W().lastPriceAnimation}qr(){switch(this.jr.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.Wr}}gt(){return this.ft?(this.Mt(),this.ft=!1,this.Nr=!1):this.Nr&&(this.Yr(),this.Nr=!1),this.Wt}Mt(){this.Wt.J(null);const t=this.jr.$t().St(),e=t.Xs(),i=this.jr.Ct();if(null===e||null===i)return;const s=this.jr.Zr(!0);if(s.Xr||!e.Kr(s.ee))return;const n={x:t.It(s.ee),y:this.jr.Dt().Rt(s._t,i.Vt)},r=s.V,o=this.jr.W().lineWidth,h=pe(this.Gr(),r);this.Wt.J({Tr:r,Pr:o,Rr:h.Rr,Dr:h.Dr,ht:h.ht,Xe:n})}Yr(){const t=this.Wt.$e();if(null!==t){const e=pe(this.Gr(),t.Tr);t.Rr=e.Rr,t.Dr=e.Dr,t.ht=e.ht}}Gr(){return this.qr()?performance.now()-this.Fr:2599}}function be(t,e){return Rt(Math.min(Math.max(t,12),30)*e)}function ve(t,e){switch(t){case"arrowDown":case"arrowUp":return be(e,1);case"circle":return be(e,.8);case"square":return be(e,.7)}}function we(t){return function(t){const e=Math.ceil(t);return e%2!=0?e-1:e}(be(t,1))}function ye(t){return Math.max(be(t,.1),3)}function Se(t,e,i){return e?t:i?Math.ceil(t/2):0}function xe(t,e,i,s,n){const r=ve("square",i),o=(r-1)/2,h=t-o,l=e-o;return s>=h&&s<=h+r&&n>=l&&n<=l+r}function Me(t,e,i,s){const n=(ve("arrowUp",s)-1)/2*i.Jr,r=(Rt(s/2)-1)/2*i.Jr;e.beginPath(),t?(e.moveTo(i.nt-n,i.st),e.lineTo(i.nt,i.st-n),e.lineTo(i.nt+n,i.st),e.lineTo(i.nt+r,i.st),e.lineTo(i.nt+r,i.st+n),e.lineTo(i.nt-r,i.st+n),e.lineTo(i.nt-r,i.st)):(e.moveTo(i.nt-n,i.st),e.lineTo(i.nt,i.st+n),e.lineTo(i.nt+n,i.st),e.lineTo(i.nt+r,i.st),e.lineTo(i.nt+r,i.st-n),e.lineTo(i.nt-r,i.st-n),e.lineTo(i.nt-r,i.st)),e.fill()}class Ce extends X{constructor(){super(...arguments),this.zt=null,this.ar=new oe,this.j=-1,this.H="",this.Qr=""}J(t){this.zt=t}_r(t,e){this.j===t&&this.H===e||(this.j=t,this.H=e,this.Qr=H(t,e),this.ar.nr())}wr(t,e){if(null===this.zt||null===this.zt.tt)return null;for(let i=this.zt.tt.from;i<this.zt.tt.to;i++){const s=this.zt.it[i];if(_e(s,t,e))return{Mr:s.th,gr:s.gr}}return null}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i},s,n){if(null!==this.zt&&null!==this.zt.tt){t.textBaseline="middle",t.font=this.Qr;for(let s=this.zt.tt.from;s<this.zt.tt.to;s++){const n=this.zt.it[s];void 0!==n.Kt&&(n.Kt.Hi=this.ar.xi(t,n.Kt.ih),n.Kt.At=this.j,n.Kt.nt=n.nt-n.Kt.Hi/2),Ee(n,t,e,i)}}}}function Ee(t,e,i,s){e.fillStyle=t.V,void 0!==t.Kt&&function(t,e,i,s,n,r){t.save(),t.scale(n,r),t.fillText(e,i,s),t.restore()}(e,t.Kt.ih,t.Kt.nt,t.Kt.st,i,s),function(t,e,i){if(0!==t.Ks){switch(t.nh){case"arrowDown":return void Me(!1,e,i,t.Ks);case"arrowUp":return void Me(!0,e,i,t.Ks);case"circle":return void function(t,e,i){const s=(ve("circle",i)-1)/2;t.beginPath(),t.arc(e.nt,e.st,s*e.Jr,0,2*Math.PI,!1),t.fill()}(e,i,t.Ks);case"square":return void function(t,e,i){const s=ve("square",i),n=(s-1)*e.Jr/2,r=e.nt-n,o=e.st-n;t.fillRect(r,o,s*e.Jr,s*e.Jr)}(e,i,t.Ks)}t.nh}}(t,e,function(t,e,i){const s=Math.max(1,Math.floor(e))%2/2;return{nt:Math.round(t.nt*e)+s,st:t.st*i,Jr:e}}(t,i,s))}function _e(t,e,i){return!(void 0===t.Kt||!function(t,e,i,s,n,r){const o=s/2;return n>=t&&n<=t+i&&r>=e-o&&r<=e+o}(t.Kt.nt,t.Kt.st,t.Kt.Hi,t.Kt.At,e,i))||function(t,e,i){if(0===t.Ks)return!1;switch(t.nh){case"arrowDown":case"arrowUp":return function(t,e,i,s,n,r){return xe(e,i,s,n,r)}(0,t.nt,t.st,t.Ks,e,i);case"circle":return function(t,e,i,s,n){const r=2+ve("circle",i)/2,o=t-s,h=e-n;return Math.sqrt(o*o+h*h)<=r}(t.nt,t.st,t.Ks,e,i);case"square":return xe(t.nt,t.st,t.Ks,e,i)}}(t,e,i)}function $e(t,e,i,s,n,r,o,h,l){const a=V(i)?i:i.Se,c=V(i)?i:i.Me,u=V(i)?i:i.xe,d=V(e.size)?Math.max(e.size,0):1,f=we(h.le())*d,m=f/2;switch(t.Ks=f,e.position){case"inBar":return t.st=o.Rt(a,l),void(void 0!==t.Kt&&(t.Kt.st=t.st+m+r+.6*n));case"aboveBar":return t.st=o.Rt(c,l)-m-s.sh,void 0!==t.Kt&&(t.Kt.st=t.st-m-.6*n,s.sh+=1.2*n),void(s.sh+=f+r);case"belowBar":return t.st=o.Rt(u,l)+m+s.eh,void 0!==t.Kt&&(t.Kt.st=t.st+m+r+.6*n,s.eh+=1.2*n),void(s.eh+=f+r)}e.position}class ze{constructor(t,e){this.ft=!0,this.rh=!0,this.hh=!0,this.ah=null,this.oh=null,this.Wt=new Ce,this.jr=t,this.$i=e,this.zt={it:[],tt:null}}bt(t){this.ft=!0,this.hh=!0,"data"===t&&(this.rh=!0,this.oh=null)}gt(t){if(!this.jr.yt())return null;this.ft&&this._h();const e=this.$i.W().layout;return this.Wt._r(e.fontSize,e.fontFamily),this.Wt.J(this.zt),this.Wt}uh(){if(this.hh){if(this.jr.dh().length>0){const t=this.$i.St().le(),e=ye(t),i=1.5*we(t)+2*e,s=this.fh();this.ah={above:Se(i,s.aboveBar,s.inBar),below:Se(i,s.belowBar,s.inBar)}}else this.ah=null;this.hh=!1}return this.ah}fh(){return null===this.oh&&(this.oh=this.jr.dh().reduce((t,e)=>(t[e.position]||(t[e.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1})),this.oh}_h(){const t=this.jr.Dt(),e=this.$i.St(),i=this.jr.dh();this.rh&&(this.zt.it=i.map(t=>({ot:t.time,nt:0,st:0,Ks:0,nh:t.shape,V:t.color,th:t.th,gr:t.id,Kt:void 0})),this.rh=!1);const s=this.$i.W().layout;this.zt.tt=null;const n=e.Xs();if(null===n)return;const r=this.jr.Ct();if(null===r)return;if(0===this.zt.it.length)return;let o=NaN;const h=ye(e.le()),l={sh:h,eh:h};this.zt.tt=At(this.zt.it,n,!0);for(let n=this.zt.tt.from;n<this.zt.tt.to;n++){const a=i[n];a.time!==o&&(l.sh=h,l.eh=h,o=a.time);const c=this.zt.it[n];c.nt=e.It(a.time),void 0!==a.text&&a.text.length>0&&(c.Kt={ih:a.text,nt:0,st:0,Hi:0,At:0});const u=this.jr.ph(a.time);null!==u&&$e(c,a,u,l,s.fontSize,h,t,e,r.Vt)}this.ft=!1}}class ke extends ce{constructor(t){super(t)}yr(){const t=this.Sr;t.yt=!1;const e=this.Es.W();if(!e.priceLineVisible||!this.Es.yt())return;const i=this.Es.Zr(0===e.priceLineSource);i.Xr||(t.yt=!0,t.st=i.ki,t.V=this.Es.mh(i.V),t.et=e.priceLineWidth,t.Nt=e.priceLineStyle)}}class Re extends ht{constructor(t){super(),this.jt=t}zi(t,e,i){t.yt=!1,e.yt=!1;const s=this.jt;if(!s.yt())return;const n=s.W(),r=n.lastValueVisible,o=""!==s.bh(),h=0===n.seriesLastValueMode,l=s.Zr(!1);if(l.Xr)return;r&&(t.Kt=this.wh(l,r,h),t.yt=0!==t.Kt.length),(o||h)&&(e.Kt=this.gh(l,r,o,h),e.yt=e.Kt.length>0);const a=s.mh(l.V),c=O(a);i.t=c.t,i.ki=l.ki,e.Ot=s.$t().Bt(l.ki/s.Dt().At()),t.Ot=a,t.V=c.i,e.V=c.i}gh(t,e,i,s){let n="";const r=this.jt.bh();return i&&0!==r.length&&(n+=`${r} `),e&&s&&(n+=this.jt.Dt().Mh()?t.xh:t.Sh),n.trim()}wh(t,e,i){return e?i?this.jt.Dt().Mh()?t.Sh:t.xh:t.Kt:""}}function Le(t,e,i,s){const n=Number.isFinite(e),r=Number.isFinite(i);return n&&r?t(e,i):n||r?n?e:i:s}class Te{constructor(t,e){this.kh=t,this.yh=e}Ch(t){return null!==t&&this.kh===t.kh&&this.yh===t.yh}Th(){return new Te(this.kh,this.yh)}Ph(){return this.kh}Rh(){return this.yh}Dh(){return this.yh-this.kh}Ni(){return this.yh===this.kh||Number.isNaN(this.yh)||Number.isNaN(this.kh)}ts(t){return null===t?this:new Te(Le(Math.min,this.Ph(),t.Ph(),-1/0),Le(Math.max,this.Rh(),t.Rh(),1/0))}Vh(t){if(!V(t))return;if(0===this.yh-this.kh)return;const e=.5*(this.yh+this.kh);let i=this.yh-e,s=this.kh-e;i*=t,s*=t,this.yh=e+i,this.kh=e+s}Oh(t){V(t)&&(this.yh+=t,this.kh+=t)}Bh(){return{minValue:this.kh,maxValue:this.yh}}static Ah(t){return null===t?null:new Te(t.minValue,t.maxValue)}}class Ne{constructor(t,e){this.Ih=t,this.zh=e||null}Lh(){return this.Ih}Eh(){return this.zh}Bh(){return null===this.Ih?null:{priceRange:this.Ih.Bh(),margins:this.zh||void 0}}static Ah(t){return null===t?null:new Ne(Te.Ah(t.priceRange),t.margins)}}class Oe extends ce{constructor(t,e){super(t),this.Nh=e}yr(){const t=this.Sr;t.yt=!1;const e=this.Nh.W();if(!this.Es.yt()||!e.lineVisible)return;const i=this.Nh.Fh();null!==i&&(t.yt=!0,t.st=i,t.V=e.color,t.et=e.lineWidth,t.Nt=e.lineStyle,t.gr=this.Nh.W().id)}}class Pe extends ht{constructor(t,e){super(),this.jr=t,this.Nh=e}zi(t,e,i){t.yt=!1,e.yt=!1;const s=this.Nh.W(),n=s.axisLabelVisible,r=""!==s.title,o=this.jr;if(!n||!o.yt())return;const h=this.Nh.Fh();if(null===h)return;r&&(e.Kt=s.title,e.yt=!0),e.Ot=o.$t().Bt(h/o.Dt().At()),t.Kt=this.Wh(s.price),t.yt=!0;const l=O(s.axisLabelColor||s.color);i.t=l.t;const a=s.axisLabelTextColor||l.i;t.V=a,e.V=a,i.ki=h}Wh(t){const e=this.jr.Ct();return null===e?"":this.jr.Dt().Fi(t,e.Vt)}}class Fe{constructor(t,e){this.jr=t,this.cn=e,this.jh=new Oe(t,this),this.ur=new Pe(t,this),this.Hh=new le(this.ur,t,t.$t())}$h(t){F(this.cn,t),this.bt(),this.jr.$t().Uh()}W(){return this.cn}qh(){return this.jh}Yh(){return this.Hh}Zh(){return this.ur}bt(){this.jh.bt(),this.ur.bt()}Fh(){const t=this.jr,e=t.Dt();if(t.$t().St().Ni()||e.Ni())return null;const i=t.Ct();return null===i?null:e.Rt(this.cn.price,i.Vt)}}class Ve extends dt{constructor(t){super(),this.$i=t}$t(){return this.$i}}const De={Bar:(t,e,i,s)=>{var n;const r=e.upColor,o=e.downColor,h=M(t(i,s)),l=C(h.Vt[0])<=C(h.Vt[3]);return{ce:null!==(n=h.V)&&void 0!==n?n:l?r:o}},Candlestick:(t,e,i,s)=>{var n,r,o;const h=e.upColor,l=e.downColor,a=e.borderUpColor,c=e.borderDownColor,u=e.wickUpColor,d=e.wickDownColor,f=M(t(i,s)),m=C(f.Vt[0])<=C(f.Vt[3]);return{ce:null!==(n=f.V)&&void 0!==n?n:m?h:l,Ne:null!==(r=f.Ot)&&void 0!==r?r:m?a:c,Ee:null!==(o=f.Xh)&&void 0!==o?o:m?u:d}},Custom:(t,e,i,s)=>{var n;return{ce:null!==(n=M(t(i,s)).V)&&void 0!==n?n:e.color}},Area:(t,e,i,s)=>{var n,r,o,h;const l=M(t(i,s));return{ce:null!==(n=l.lt)&&void 0!==n?n:e.lineColor,lt:null!==(r=l.lt)&&void 0!==r?r:e.lineColor,Ps:null!==(o=l.Ps)&&void 0!==o?o:e.topColor,Rs:null!==(h=l.Rs)&&void 0!==h?h:e.bottomColor}},Baseline:(t,e,i,s)=>{var n,r,o,h,l,a;const c=M(t(i,s));return{ce:c.Vt[3]>=e.baseValue.price?e.topLineColor:e.bottomLineColor,Re:null!==(n=c.Re)&&void 0!==n?n:e.topLineColor,De:null!==(r=c.De)&&void 0!==r?r:e.bottomLineColor,ke:null!==(o=c.ke)&&void 0!==o?o:e.topFillColor1,ye:null!==(h=c.ye)&&void 0!==h?h:e.topFillColor2,Ce:null!==(l=c.Ce)&&void 0!==l?l:e.bottomFillColor1,Te:null!==(a=c.Te)&&void 0!==a?a:e.bottomFillColor2}},Line:(t,e,i,s)=>{var n,r;const o=M(t(i,s));return{ce:null!==(n=o.V)&&void 0!==n?n:e.color,lt:null!==(r=o.V)&&void 0!==r?r:e.color}},Histogram:(t,e,i,s)=>{var n;return{ce:null!==(n=M(t(i,s)).V)&&void 0!==n?n:e.color}}};class Ie{constructor(t){this.Kh=(t,e)=>void 0!==e?e.Vt:this.jr.In().Gh(t),this.jr=t,this.Jh=De[t.Qh()]}$s(t,e){return this.Jh(this.Kh,this.jr.W(),t,e)}}var Be;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(Be||(Be={}));const Ae=30;class We{constructor(){this.tl=[],this.il=new Map,this.nl=new Map}sl(){return this.Ks()>0?this.tl[this.tl.length-1]:null}el(){return this.Ks()>0?this.rl(0):null}An(){return this.Ks()>0?this.rl(this.tl.length-1):null}Ks(){return this.tl.length}Ni(){return 0===this.Ks()}Kr(t){return null!==this.hl(t,0)}Gh(t){return this.ll(t)}ll(t,e=0){const i=this.hl(t,e);return null===i?null:Object.assign(Object.assign({},this.al(i)),{ee:this.rl(i)})}ne(){return this.tl}ol(t,e,i){if(this.Ni())return null;let s=null;for(const n of i)s=je(s,this._l(t,e,n));return s}J(t){this.nl.clear(),this.il.clear(),this.tl=t}rl(t){return this.tl[t].ee}al(t){return this.tl[t]}hl(t,e){const i=this.ul(t);if(null===i&&0!==e)switch(e){case-1:return this.cl(t);case 1:return this.dl(t);default:throw new TypeError("Unknown search mode")}return i}cl(t){let e=this.fl(t);return e>0&&(e-=1),e!==this.tl.length&&this.rl(e)<t?e:null}dl(t){const e=this.vl(t);return e!==this.tl.length&&t<this.rl(e)?e:null}ul(t){const e=this.fl(t);return e===this.tl.length||t<this.tl[e].ee?null:e}fl(t){return Vt(this.tl,t,(t,e)=>t.ee<e)}vl(t){return Dt(this.tl,t,(t,e)=>t.ee>e)}pl(t,e,i){let s=null;for(let n=t;n<e;n++){const t=this.tl[n].Vt[i];Number.isNaN(t)||(null===s?s={ml:t,bl:t}:(t<s.ml&&(s.ml=t),t>s.bl&&(s.bl=t)))}return s}_l(t,e,i){if(this.Ni())return null;let s=null;const n=M(this.el()),r=M(this.An()),o=Math.max(t,n),h=Math.min(e,r),l=Math.ceil(o/Ae)*Ae,a=Math.max(l,Math.floor(h/Ae)*Ae);{const t=this.fl(o),n=this.vl(Math.min(h,l,e));s=je(s,this.pl(t,n,i))}let c=this.il.get(i);void 0===c&&(c=new Map,this.il.set(i,c));for(let t=Math.max(l+1,o);t<a;t+=Ae){const e=Math.floor(t/Ae);let n=c.get(e);if(void 0===n){const t=this.fl(e*Ae),s=this.vl((e+1)*Ae-1);n=this.pl(t,s,i),c.set(e,n)}s=je(s,n)}{const t=this.fl(a),e=this.vl(h);s=je(s,this.pl(t,e,i))}return s}}function je(t,e){return null===t?e:null===e?t:{ml:Math.min(t.ml,e.ml),bl:Math.max(t.bl,e.bl)}}class Ue{constructor(t){this.wl=t}X(t,e,i){this.wl.draw(t)}gl(t,e,i){var s,n;null===(n=(s=this.wl).drawBackground)||void 0===n||n.call(s,t)}}class He{constructor(t){this.tr=null,this.wn=t}gt(){var t;const e=this.wn.renderer();if(null===e)return null;if((null===(t=this.tr)||void 0===t?void 0:t.Ml)===e)return this.tr.xl;const i=new Ue(e);return this.tr={Ml:e,xl:i},i}Sl(){var t,e,i;return null!==(i=null===(e=(t=this.wn).zOrder)||void 0===e?void 0:e.call(t))&&void 0!==i?i:"normal"}}function Ke(t){var e,i,s,n,r;return{Kt:t.text(),ki:t.coordinate(),Si:null===(e=t.fixedCoordinate)||void 0===e?void 0:e.call(t),V:t.textColor(),t:t.backColor(),yt:null===(s=null===(i=t.visible)||void 0===i?void 0:i.call(t))||void 0===s||s,hi:null===(r=null===(n=t.tickVisible)||void 0===n?void 0:n.call(t))||void 0===r||r}}class qe{constructor(t,e){this.Wt=new ct,this.kl=t,this.yl=e}gt(){return this.Wt.J(Object.assign({Hi:this.yl.Hi()},Ke(this.kl))),this.Wt}}class Xe extends ht{constructor(t,e){super(),this.kl=t,this.Li=e}zi(t,e,i){const s=Ke(this.kl);i.t=s.t,t.V=s.V;const n=2/12*this.Li.P();i.wi=n,i.gi=n,i.ki=s.ki,i.Si=s.Si,t.Kt=s.Kt,t.yt=s.yt,t.hi=s.hi}}class Je{constructor(t,e){this.Cl=null,this.Tl=null,this.Pl=null,this.Rl=null,this.Dl=null,this.Vl=t,this.jr=e}Ol(){return this.Vl}Vn(){var t,e;null===(e=(t=this.Vl).updateAllViews)||void 0===e||e.call(t)}Pn(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).paneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Cl)||void 0===s?void 0:s.Ml)===n)return this.Cl.xl;const r=n.map(t=>new He(t));return this.Cl={Ml:n,xl:r},r}Qi(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).timeAxisViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Tl)||void 0===s?void 0:s.Ml)===n)return this.Tl.xl;const r=this.jr.$t().St(),o=n.map(t=>new qe(t,r));return this.Tl={Ml:n,xl:o},o}Rn(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).priceAxisViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Pl)||void 0===s?void 0:s.Ml)===n)return this.Pl.xl;const r=this.jr.Dt(),o=n.map(t=>new Xe(t,r));return this.Pl={Ml:n,xl:o},o}Bl(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).priceAxisPaneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Rl)||void 0===s?void 0:s.Ml)===n)return this.Rl.xl;const r=n.map(t=>new He(t));return this.Rl={Ml:n,xl:r},r}Al(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).timeAxisPaneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Dl)||void 0===s?void 0:s.Ml)===n)return this.Dl.xl;const r=n.map(t=>new He(t));return this.Dl={Ml:n,xl:r},r}Il(t,e){var i,s,n;return null!==(n=null===(s=(i=this.Vl).autoscaleInfo)||void 0===s?void 0:s.call(i,t,e))&&void 0!==n?n:null}wr(t,e){var i,s,n;return null!==(n=null===(s=(i=this.Vl).hitTest)||void 0===s?void 0:s.call(i,t,e))&&void 0!==n?n:null}}function Ge(t,e,i,s){t.forEach(t=>{e(t).forEach(t=>{t.Sl()===i&&s.push(t)})})}function Qe(t){return t.Pn()}function Ye(t){return t.Bl()}function Ze(t){return t.Al()}class ti extends Ve{constructor(t,e,i,s,n){super(t),this.zt=new We,this.jh=new ke(this),this.zl=[],this.Ll=new ue(this),this.El=null,this.Nl=null,this.Fl=[],this.Wl=[],this.jl=null,this.Hl=[],this.cn=e,this.$l=i;const r=new Re(this);this.rn=[r],this.Hh=new le(r,this,t),"Area"!==i&&"Line"!==i&&"Baseline"!==i||(this.El=new ge(this)),this.Ul(),this.ql(n)}S(){null!==this.jl&&clearTimeout(this.jl)}mh(t){return this.cn.priceLineColor||t}Zr(t){const e={Xr:!0},i=this.Dt();if(this.$t().St().Ni()||i.Ni()||this.zt.Ni())return e;const s=this.$t().St().Xs(),n=this.Ct();if(null===s||null===n)return e;let r,o;if(t){const t=this.zt.sl();if(null===t)return e;r=t,o=t.ee}else{const t=this.zt.ll(s.ui(),-1);if(null===t)return e;if(r=this.zt.Gh(t.ee),null===r)return e;o=t.ee}const h=r.Vt[3],l=this.Us().$s(o,{Vt:r}),a=i.Rt(h,n.Vt);return{Xr:!1,_t:h,Kt:i.Fi(h,n.Vt),xh:i.Yl(h),Sh:i.Zl(h,n.Vt),V:l.ce,ki:a,ee:o}}Us(){return null!==this.Nl||(this.Nl=new Ie(this)),this.Nl}W(){return this.cn}$h(t){const e=t.priceScaleId;void 0!==e&&e!==this.cn.priceScaleId&&this.$t().Xl(this,e),F(this.cn,t),void 0!==t.priceFormat&&(this.Ul(),this.$t().Kl()),this.$t().Gl(this),this.$t().Jl(),this.wn.bt("options")}J(t,e){this.zt.J(t),this.Ql(),this.wn.bt("data"),this.dn.bt("data"),null!==this.El&&(e&&e.ta?this.El.$r():0===t.length&&this.El.Hr());const i=this.$t().dr(this);this.$t().ia(i),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}na(t){this.Fl=t,this.Ql();const e=this.$t().dr(this);this.dn.bt("data"),this.$t().ia(e),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}sa(){return this.Fl}dh(){return this.Wl}ea(t){const e=new Fe(this,t);return this.zl.push(e),this.$t().Gl(this),e}ra(t){const e=this.zl.indexOf(t);-1!==e&&this.zl.splice(e,1),this.$t().Gl(this)}Qh(){return this.$l}Ct(){const t=this.ha();return null===t?null:{Vt:t.Vt[3],la:t.ot}}ha(){const t=this.$t().St().Xs();if(null===t)return null;const e=t.Os();return this.zt.ll(e,1)}In(){return this.zt}ph(t){const e=this.zt.Gh(t);return null===e?null:"Bar"===this.$l||"Candlestick"===this.$l||"Custom"===this.$l?{ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3]}:e.Vt[3]}aa(t){const e=[];Ge(this.Hl,Qe,"top",e);const i=this.El;return null!==i&&i.yt()?(null===this.jl&&i.qr()&&(this.jl=setTimeout(()=>{this.jl=null,this.$t().oa()},0)),i.Ur(),e.unshift(i),e):e}Pn(){const t=[];this._a()||t.push(this.Ll),t.push(this.wn,this.jh,this.dn);const e=this.zl.map(t=>t.qh());return t.push(...e),Ge(this.Hl,Qe,"normal",t),t}ua(){return this.ca(Qe,"bottom")}da(t){return this.ca(Ye,t)}fa(t){return this.ca(Ze,t)}va(t,e){return this.Hl.map(i=>i.wr(t,e)).filter(t=>null!==t)}Ji(t){return[this.Hh,...this.zl.map(t=>t.Yh())]}Rn(t,e){if(e!==this.Yi&&!this._a())return[];const i=[...this.rn];for(const t of this.zl)i.push(t.Zh());return this.Hl.forEach(t=>{i.push(...t.Rn())}),i}Qi(){const t=[];return this.Hl.forEach(e=>{t.push(...e.Qi())}),t}Il(t,e){if(void 0!==this.cn.autoscaleInfoProvider){const i=this.cn.autoscaleInfoProvider(()=>{const i=this.pa(t,e);return null===i?null:i.Bh()});return Ne.Ah(i)}return this.pa(t,e)}ma(){return this.cn.priceFormat.minMove}ba(){return this.wa}Vn(){var t;this.wn.bt(),this.dn.bt();for(const t of this.rn)t.bt();for(const t of this.zl)t.bt();this.jh.bt(),this.Ll.bt(),null===(t=this.El)||void 0===t||t.bt(),this.Hl.forEach(t=>t.Vn())}Dt(){return M(super.Dt())}kt(t){if("Line"!==this.$l&&"Area"!==this.$l&&"Baseline"!==this.$l||!this.cn.crosshairMarkerVisible)return null;const e=this.zt.Gh(t);return null===e?null:{_t:e.Vt[3],ht:this.ga(),Ot:this.Ma(),Pt:this.xa(),Tt:this.Sa(t)}}bh(){return this.cn.title}yt(){return this.cn.visible}ka(t){this.Hl.push(new Je(t,this))}ya(t){this.Hl=this.Hl.filter(e=>e.Ol()!==t)}Ca(){if(this.wn instanceof te!=0)return t=>this.wn.We(t)}Ta(){if(this.wn instanceof te!=0)return t=>this.wn.je(t)}_a(){return!pt(this.Dt().Pa())}pa(t,e){if(!D(t)||!D(e)||this.zt.Ni())return null;const i="Line"===this.$l||"Area"===this.$l||"Baseline"===this.$l||"Histogram"===this.$l?[3]:[2,1],s=this.zt.ol(t,e,i);let n=null!==s?new Te(s.ml,s.bl):null;if("Histogram"===this.Qh()){const t=this.cn.base,e=new Te(t,t);n=null!==n?n.ts(e):e}let r=this.dn.uh();return this.Hl.forEach(i=>{const s=i.Il(t,e);if(null==s?void 0:s.priceRange){const t=new Te(s.priceRange.minValue,s.priceRange.maxValue);n=null!==n?n.ts(t):t}var o,h,l,a;(null==s?void 0:s.margins)&&(o=r,h=s.margins,r={above:Math.max(null!==(l=null==o?void 0:o.above)&&void 0!==l?l:0,h.above),below:Math.max(null!==(a=null==o?void 0:o.below)&&void 0!==a?a:0,h.below)})}),new Ne(n,r)}ga(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerRadius}return 0}Ma(){switch(this.$l){case"Line":case"Area":case"Baseline":{const t=this.cn.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}xa(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerBorderWidth}return 0}Sa(t){switch(this.$l){case"Line":case"Area":case"Baseline":{const t=this.cn.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Us().$s(t).ce}Ul(){switch(this.cn.priceFormat.type){case"custom":this.wa={format:this.cn.priceFormat.formatter};break;case"volume":this.wa=new yt(this.cn.priceFormat.precision);break;case"percent":this.wa=new wt(this.cn.priceFormat.precision);break;default:{const t=Math.pow(10,this.cn.priceFormat.precision);this.wa=new vt(t,this.cn.priceFormat.minMove*t)}}null!==this.Yi&&this.Yi.Ra()}Ql(){const t=this.$t().St();if(!t.Da()||this.zt.Ni())return void(this.Wl=[]);const e=M(this.zt.el());this.Wl=this.Fl.map((i,s)=>{const n=M(t.Va(i.time,!0)),r=n<e?1:-1;return{time:M(this.zt.ll(n,r)).ee,position:i.position,shape:i.shape,color:i.color,id:i.id,th:s,text:i.text,size:i.size,originalTime:i.originalTime}})}ql(t){switch(this.dn=new ze(this,this.$t()),this.$l){case"Bar":this.wn=new qt(this,this.$t());break;case"Candlestick":this.wn=new Yt(this,this.$t());break;case"Line":this.wn=new ne(this,this.$t());break;case"Custom":this.wn=new te(this,this.$t(),x(t));break;case"Area":this.wn=new Ut(this,this.$t());break;case"Baseline":this.wn=new Gt(this,this.$t());break;case"Histogram":this.wn=new se(this,this.$t());break;default:throw Error("Unknown chart style assigned: "+this.$l)}}ca(t,e){const i=[];return Ge(this.Hl,t,e,i),i}}class ei{constructor(t){this.cn=t}Oa(t,e,i){let s=t;if(0===this.cn.mode)return s;const n=i.vn(),r=n.Ct();if(null===r)return s;const o=n.Rt(t,r),h=i.Ba().filter(t=>t instanceof ti).reduce((t,s)=>{if(i.vr(s)||!s.yt())return t;const n=s.Dt(),r=s.In();if(n.Ni()||!r.Kr(e))return t;const o=r.Gh(e);if(null===o)return t;const h=C(s.Ct());return t.concat([n.Rt(o.Vt[3],h.Vt)])},[]);if(0===h.length)return s;h.sort((t,e)=>Math.abs(t-o)-Math.abs(e-o));const l=h[0];return s=n.pn(l,r),s}}class ii extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;const n=Math.max(1,Math.floor(i));t.lineWidth=n,function(t,e){t.save(),t.lineWidth%2&&t.translate(.5,.5),e(),t.restore()}(t,()=>{const r=M(this.zt);if(r.Aa){t.strokeStyle=r.Ia,w(t,r.za),t.beginPath();for(const s of r.La){const r=Math.round(s.Ea*i);t.moveTo(r,-n),t.lineTo(r,e.height+n)}t.stroke()}if(r.Na){t.strokeStyle=r.Fa,w(t,r.Wa),t.beginPath();for(const i of r.ja){const r=Math.round(i.Ea*s);t.moveTo(-n,r),t.lineTo(e.width+n,r)}t.stroke()}})}}class si{constructor(t){this.Wt=new ii,this.ft=!0,this.tn=t}bt(){this.ft=!0}gt(){if(this.ft){const t=this.tn.$t().W().grid,e={Na:t.horzLines.visible,Aa:t.vertLines.visible,Fa:t.horzLines.color,Ia:t.vertLines.color,Wa:t.horzLines.style,za:t.vertLines.style,ja:this.tn.vn().Ha(),La:(this.tn.$t().St().Ha()||[]).map(t=>({Ea:t.coord}))};this.Wt.J(e),this.ft=!1}return this.Wt}}class ni{constructor(t){this.wn=new si(t)}qh(){return this.wn}}const ri={$a:4,Ua:1e-4};function oi(t,e){const i=100*(t-e)/e;return e<0?-i:i}function hi(t,e){const i=oi(t.Ph(),e),s=oi(t.Rh(),e);return new Te(i,s)}function li(t,e){const i=100*(t-e)/e+100;return e<0?-i:i}function ai(t,e){const i=li(t.Ph(),e),s=li(t.Rh(),e);return new Te(i,s)}function ci(t,e){const i=Math.abs(t);if(i<1e-15)return 0;const s=Math.log10(i+e.Ua)+e.$a;return t<0?-s:s}function ui(t,e){const i=Math.abs(t);if(i<1e-15)return 0;const s=Math.pow(10,i-e.$a)-e.Ua;return t<0?-s:s}function di(t,e){if(null===t)return null;const i=ci(t.Ph(),e),s=ci(t.Rh(),e);return new Te(i,s)}function fi(t,e){if(null===t)return null;const i=ui(t.Ph(),e),s=ui(t.Rh(),e);return new Te(i,s)}function mi(t){if(null===t)return ri;const e=Math.abs(t.Rh()-t.Ph());if(e>=1||e<1e-15)return ri;const i=Math.ceil(Math.abs(Math.log10(e))),s=ri.$a+i;return{$a:s,Ua:1/Math.pow(10,s)}}class pi{constructor(t,e){if(this.qa=t,this.Ya=e,function(t){if(t<0)return!1;for(let e=t;e>1;e/=10)if(e%10!=0)return!1;return!0}(this.qa))this.Za=[2,2.5,2];else{this.Za=[];for(let t=this.qa;1!==t;){if(t%2==0)this.Za.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Za.push(2,2.5),t/=5}if(this.Za.length>100)throw new Error("something wrong with base")}}}Xa(t,e,i){const s=0===this.qa?0:1/this.qa;let n=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-e)))),r=0,o=this.Ya[0];for(;;){const t=kt(n,s,1e-14)&&n>s+1e-14,e=kt(n,i*o,1e-14),h=kt(n,1,1e-14);if(!(t&&e&&h))break;n/=o,o=this.Ya[++r%this.Ya.length]}if(n<=s+1e-14&&(n=s),n=Math.max(1,n),this.Za.length>0&&(h=n,Math.abs(h-1)<1e-14))for(r=0,o=this.Za[0];kt(n,i*o,1e-14)&&n>s+1e-14;)n/=o,o=this.Za[++r%this.Za.length];var h;return n}}class gi{constructor(t,e,i,s){this.Ka=[],this.Li=t,this.qa=e,this.Ga=i,this.Ja=s}Xa(t,e){if(t<e)throw new Error("high < low");const i=this.Li.At(),s=(t-e)*this.Qa()/i,n=new pi(this.qa,[2,2.5,2]),r=new pi(this.qa,[2,2,2.5]),o=new pi(this.qa,[2.5,2,2]),h=[];return h.push(n.Xa(t,e,s),r.Xa(t,e,s),o.Xa(t,e,s)),function(t){if(t.length<1)throw Error("array is empty");let e=t[0];for(let i=1;i<t.length;++i)t[i]<e&&(e=t[i]);return e}(h)}io(){const t=this.Li,e=t.Ct();if(null===e)return void(this.Ka=[]);const i=t.At(),s=this.Ga(i-1,e),n=this.Ga(0,e),r=this.Li.W().entireTextOnly?this.no()/2:0,o=r,h=i-1-r,l=Math.max(s,n),a=Math.min(s,n);if(l===a)return void(this.Ka=[]);let c=this.Xa(l,a),u=l%c;u+=u<0?c:0;const d=l>=a?1:-1;let f=null,m=0;for(let i=l-u;i>a;i-=c){const s=this.Ja(i,e,!0);null!==f&&Math.abs(s-f)<this.Qa()||s<o||s>h||(m<this.Ka.length?(this.Ka[m].Ea=s,this.Ka[m].so=t.eo(i)):this.Ka.push({Ea:s,so:t.eo(i)}),m++,f=s,t.ro()&&(c=this.Xa(i*d,a)))}this.Ka.length=m}Ha(){return this.Ka}no(){return this.Li.P()}Qa(){return Math.ceil(2.5*this.no())}}function bi(t){return t.slice().sort((t,e)=>M(t.Xi())-M(e.Xi()))}var vi;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(vi||(vi={}));const wi=new wt,yi=new vt(100,1);class Si{constructor(t,e,i,s){this.ho=0,this.lo=null,this.Ih=null,this.ao=null,this.oo={_o:!1,uo:null},this.co=0,this.do=0,this.fo=new P,this.vo=new P,this.po=[],this.mo=null,this.bo=null,this.wo=null,this.Mo=null,this.wa=yi,this.xo=mi(null),this.So=t,this.cn=e,this.ko=i,this.yo=s,this.Co=new gi(this,100,this.To.bind(this),this.Po.bind(this))}Pa(){return this.So}W(){return this.cn}$h(t){if(F(this.cn,t),this.Ra(),void 0!==t.mode&&this.Ro({Cr:t.mode}),void 0!==t.scaleMargins){const e=x(t.scaleMargins.top),i=x(t.scaleMargins.bottom);if(e<0||e>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${e}`);if(i<0||i>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${i}`);if(e+i>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${e+i}`);this.Do(),this.bo=null}}Vo(){return this.cn.autoScale}ro(){return 1===this.cn.mode}Mh(){return 2===this.cn.mode}Oo(){return 3===this.cn.mode}Cr(){return{Wn:this.cn.autoScale,Bo:this.cn.invertScale,Cr:this.cn.mode}}Ro(t){const e=this.Cr();let i=null;void 0!==t.Wn&&(this.cn.autoScale=t.Wn),void 0!==t.Cr&&(this.cn.mode=t.Cr,2!==t.Cr&&3!==t.Cr||(this.cn.autoScale=!0),this.oo._o=!1),1===e.Cr&&t.Cr!==e.Cr&&(function(t,e){if(null===t)return!1;const i=ui(t.Ph(),e),s=ui(t.Rh(),e);return isFinite(i)&&isFinite(s)}(this.Ih,this.xo)?(i=fi(this.Ih,this.xo),null!==i&&this.Ao(i)):this.cn.autoScale=!0),1===t.Cr&&t.Cr!==e.Cr&&(i=di(this.Ih,this.xo),null!==i&&this.Ao(i));const s=e.Cr!==this.cn.mode;s&&(2===e.Cr||this.Mh())&&this.Ra(),s&&(3===e.Cr||this.Oo())&&this.Ra(),void 0!==t.Bo&&e.Bo!==t.Bo&&(this.cn.invertScale=t.Bo,this.Io()),this.vo.m(e,this.Cr())}zo(){return this.vo}P(){return this.ko.fontSize}At(){return this.ho}Lo(t){this.ho!==t&&(this.ho=t,this.Do(),this.bo=null)}Eo(){if(this.lo)return this.lo;const t=this.At()-this.No()-this.Fo();return this.lo=t,t}Lh(){return this.Wo(),this.Ih}Ao(t,e){const i=this.Ih;(e||null===i&&null!==t||null!==i&&!i.Ch(t))&&(this.bo=null,this.Ih=t)}Ni(){return this.Wo(),0===this.ho||!this.Ih||this.Ih.Ni()}jo(t){return this.Bo()?t:this.At()-1-t}Rt(t,e){return this.Mh()?t=oi(t,e):this.Oo()&&(t=li(t,e)),this.Po(t,e)}te(t,e,i){this.Wo();const s=this.Fo(),n=M(this.Lh()),r=n.Ph(),o=n.Rh(),h=this.Eo()-1,l=this.Bo(),a=h/(o-r),c=void 0===i?0:i.from,u=void 0===i?t.length:i.to,d=this.Ho();for(let i=c;i<u;i++){const n=t[i],o=n._t;if(isNaN(o))continue;let h=o;null!==d&&(h=d(n._t,e));const c=s+a*(h-r),u=l?c:this.ho-1-c;n.st=u}}be(t,e,i){this.Wo();const s=this.Fo(),n=M(this.Lh()),r=n.Ph(),o=n.Rh(),h=this.Eo()-1,l=this.Bo(),a=h/(o-r),c=void 0===i?0:i.from,u=void 0===i?t.length:i.to,d=this.Ho();for(let i=c;i<u;i++){const n=t[i];let o=n.ge,h=n.Me,c=n.xe,u=n.Se;null!==d&&(o=d(n.ge,e),h=d(n.Me,e),c=d(n.xe,e),u=d(n.Se,e));let f=s+a*(o-r),m=l?f:this.ho-1-f;n.pe=m,f=s+a*(h-r),m=l?f:this.ho-1-f,n.de=m,f=s+a*(c-r),m=l?f:this.ho-1-f,n.fe=m,f=s+a*(u-r),m=l?f:this.ho-1-f,n.me=m}}pn(t,e){const i=this.To(t,e);return this.$o(i,e)}$o(t,e){let i=t;return this.Mh()?i=function(t,e){return e<0&&(t=-t),t/100*e+e}(i,e):this.Oo()&&(i=function(t,e){return t-=100,e<0&&(t=-t),t/100*e+e}(i,e)),i}Ba(){return this.po}Uo(){if(this.mo)return this.mo;let t=[];for(let e=0;e<this.po.length;e++){const i=this.po[e];null===i.Xi()&&i.Ki(e+1),t.push(i)}return t=bi(t),this.mo=t,this.mo}qo(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.Ra(),this.Yo())}Zo(t){const e=this.po.indexOf(t);if(-1===e)throw new Error("source is not attached to scale");this.po.splice(e,1),0===this.po.length&&(this.Ro({Wn:!0}),this.Ao(null)),this.Ra(),this.Yo()}Ct(){let t=null;for(const e of this.po){const i=e.Ct();null!==i&&(null===t||i.la<t.la)&&(t=i)}return null===t?null:t.Vt}Bo(){return this.cn.invertScale}Ha(){const t=null===this.Ct();if(null!==this.bo&&(t||this.bo.Xo===t))return this.bo.Ha;this.Co.io();const e=this.Co.Ha();return this.bo={Ha:e,Xo:t},this.fo.m(),e}Ko(){return this.fo}Go(t){this.Mh()||this.Oo()||null===this.wo&&null===this.ao&&(this.Ni()||(this.wo=this.ho-t,this.ao=M(this.Lh()).Th()))}Jo(t){if(this.Mh()||this.Oo())return;if(null===this.wo)return;this.Ro({Wn:!1}),(t=this.ho-t)<0&&(t=0);let e=(this.wo+.2*(this.ho-1))/(t+.2*(this.ho-1));const i=M(this.ao).Th();e=Math.max(e,.1),i.Vh(e),this.Ao(i)}Qo(){this.Mh()||this.Oo()||(this.wo=null,this.ao=null)}t_(t){this.Vo()||null===this.Mo&&null===this.ao&&(this.Ni()||(this.Mo=t,this.ao=M(this.Lh()).Th()))}i_(t){if(this.Vo())return;if(null===this.Mo)return;const e=M(this.Lh()).Dh()/(this.Eo()-1);let i=t-this.Mo;this.Bo()&&(i*=-1);const s=i*e,n=M(this.ao).Th();n.Oh(s),this.Ao(n,!0),this.bo=null}n_(){this.Vo()||null!==this.Mo&&(this.Mo=null,this.ao=null)}ba(){return this.wa||this.Ra(),this.wa}Fi(t,e){switch(this.cn.mode){case 2:return this.s_(oi(t,e));case 3:return this.ba().format(li(t,e));default:return this.Wh(t)}}eo(t){switch(this.cn.mode){case 2:return this.s_(t);case 3:return this.ba().format(t);default:return this.Wh(t)}}Yl(t){return this.Wh(t,M(this.e_()).ba())}Zl(t,e){return t=oi(t,e),this.s_(t,wi)}r_(){return this.po}h_(t){this.oo={uo:t,_o:!1}}Vn(){this.po.forEach(t=>t.Vn())}Ra(){this.bo=null;const t=this.e_();let e=100;null!==t&&(e=Math.round(1/t.ma())),this.wa=yi,this.Mh()?(this.wa=wi,e=100):this.Oo()?(this.wa=new vt(100,1),e=100):null!==t&&(this.wa=t.ba()),this.Co=new gi(this,e,this.To.bind(this),this.Po.bind(this)),this.Co.io()}Yo(){this.mo=null}e_(){return this.po[0]||null}No(){return this.Bo()?this.cn.scaleMargins.bottom*this.At()+this.do:this.cn.scaleMargins.top*this.At()+this.co}Fo(){return this.Bo()?this.cn.scaleMargins.top*this.At()+this.co:this.cn.scaleMargins.bottom*this.At()+this.do}Wo(){this.oo._o||(this.oo._o=!0,this.l_())}Do(){this.lo=null}Po(t,e){if(this.Wo(),this.Ni())return 0;t=this.ro()&&t?ci(t,this.xo):t;const i=M(this.Lh()),s=this.Fo()+(this.Eo()-1)*(t-i.Ph())/i.Dh();return this.jo(s)}To(t,e){if(this.Wo(),this.Ni())return 0;const i=this.jo(t),s=M(this.Lh()),n=s.Ph()+s.Dh()*((i-this.Fo())/(this.Eo()-1));return this.ro()?ui(n,this.xo):n}Io(){this.bo=null,this.Co.io()}l_(){const t=this.oo.uo;if(null===t)return;let e=null;const i=this.r_();let s=0,n=0;for(const r of i){if(!r.yt())continue;const i=r.Ct();if(null===i)continue;const o=r.Il(t.Os(),t.ui());let h=o&&o.Lh();if(null!==h){switch(this.cn.mode){case 1:h=di(h,this.xo);break;case 2:h=hi(h,i.Vt);break;case 3:h=ai(h,i.Vt)}if(e=null===e?h:e.ts(M(h)),null!==o){const t=o.Eh();null!==t&&(s=Math.max(s,t.above),n=Math.max(n,t.below))}}}if(s===this.co&&n===this.do||(this.co=s,this.do=n,this.bo=null,this.Do()),null!==e){if(e.Ph()===e.Rh()){const t=this.e_(),i=5*(null===t||this.Mh()||this.Oo()?1:t.ma());this.ro()&&(e=fi(e,this.xo)),e=new Te(e.Ph()-i,e.Rh()+i),this.ro()&&(e=di(e,this.xo))}if(this.ro()){const t=fi(e,this.xo),i=mi(t);if(r=i,o=this.xo,r.$a!==o.$a||r.Ua!==o.Ua){const s=null!==this.ao?fi(this.ao,this.xo):null;this.xo=i,e=di(t,i),null!==s&&(this.ao=di(s,i))}}this.Ao(e)}else null===this.Ih&&(this.Ao(new Te(-.5,.5)),this.xo=mi(null));var r,o;this.oo._o=!0}Ho(){return this.Mh()?oi:this.Oo()?li:this.ro()?t=>ci(t,this.xo):null}a_(t,e,i){return void 0===e?(void 0===i&&(i=this.ba()),i.format(t)):e(t)}Wh(t,e){return this.a_(t,this.yo.priceFormatter,e)}s_(t,e){return this.a_(t,this.yo.percentageFormatter,e)}}class xi{constructor(t,e){this.po=[],this.o_=new Map,this.ho=0,this.__=0,this.u_=1e3,this.mo=null,this.c_=new P,this.yl=t,this.$i=e,this.d_=new ni(this);const i=e.W();this.f_=this.v_("left",i.leftPriceScale),this.p_=this.v_("right",i.rightPriceScale),this.f_.zo().l(this.m_.bind(this,this.f_),this),this.p_.zo().l(this.m_.bind(this,this.p_),this),this.b_(i)}b_(t){if(t.leftPriceScale&&this.f_.$h(t.leftPriceScale),t.rightPriceScale&&this.p_.$h(t.rightPriceScale),t.localization&&(this.f_.Ra(),this.p_.Ra()),t.overlayPriceScales){const e=Array.from(this.o_.values());for(const i of e){const e=M(i[0].Dt());e.$h(t.overlayPriceScales),t.localization&&e.Ra()}}}w_(t){switch(t){case"left":return this.f_;case"right":return this.p_}return this.o_.has(t)?x(this.o_.get(t))[0].Dt():null}S(){this.$t().g_().p(this),this.f_.zo().p(this),this.p_.zo().p(this),this.po.forEach(t=>{t.S&&t.S()}),this.c_.m()}M_(){return this.u_}x_(t){this.u_=t}$t(){return this.$i}Hi(){return this.__}At(){return this.ho}S_(t){this.__=t,this.k_()}Lo(t){this.ho=t,this.f_.Lo(t),this.p_.Lo(t),this.po.forEach(e=>{if(this.vr(e)){const i=e.Dt();null!==i&&i.Lo(t)}}),this.k_()}Ba(){return this.po}vr(t){const e=t.Dt();return null===e||this.f_!==e&&this.p_!==e}qo(t,e,i){const s=void 0!==i?i:this.C_().y_+1;this.T_(t,e,s)}Zo(t){const e=this.po.indexOf(t);S(-1!==e,"removeDataSource: invalid data source"),this.po.splice(e,1);const i=M(t.Dt()).Pa();if(this.o_.has(i)){const e=x(this.o_.get(i)),s=e.indexOf(t);-1!==s&&(e.splice(s,1),0===e.length&&this.o_.delete(i))}const s=t.Dt();s&&s.Ba().indexOf(t)>=0&&s.Zo(t),null!==s&&(s.Yo(),this.P_(s)),this.mo=null}mr(t){return t===this.f_?"left":t===this.p_?"right":"overlay"}R_(){return this.f_}D_(){return this.p_}V_(t,e){t.Go(e)}O_(t,e){t.Jo(e),this.k_()}B_(t){t.Qo()}A_(t,e){t.t_(e)}I_(t,e){t.i_(e),this.k_()}z_(t){t.n_()}k_(){this.po.forEach(t=>{t.Vn()})}vn(){let t=null;return this.$i.W().rightPriceScale.visible&&0!==this.p_.Ba().length?t=this.p_:this.$i.W().leftPriceScale.visible&&0!==this.f_.Ba().length?t=this.f_:0!==this.po.length&&(t=this.po[0].Dt()),null===t&&(t=this.p_),t}pr(){let t=null;return this.$i.W().rightPriceScale.visible?t=this.p_:this.$i.W().leftPriceScale.visible&&(t=this.f_),t}P_(t){null!==t&&t.Vo()&&this.L_(t)}E_(t){const e=this.yl.Xs();t.Ro({Wn:!0}),null!==e&&t.h_(e),this.k_()}N_(){this.L_(this.f_),this.L_(this.p_)}F_(){this.P_(this.f_),this.P_(this.p_),this.po.forEach(t=>{this.vr(t)&&this.P_(t.Dt())}),this.k_(),this.$i.Uh()}Uo(){return null===this.mo&&(this.mo=bi(this.po)),this.mo}W_(){return this.c_}j_(){return this.d_}L_(t){const e=t.r_();if(e&&e.length>0&&!this.yl.Ni()){const e=this.yl.Xs();null!==e&&t.h_(e)}t.Vn()}C_(){const t=this.Uo();if(0===t.length)return{H_:0,y_:0};let e=0,i=0;for(let s=0;s<t.length;s++){const n=t[s].Xi();null!==n&&(n<e&&(e=n),n>i&&(i=n))}return{H_:e,y_:i}}T_(t,e,i){let s=this.w_(e);if(null===s&&(s=this.v_(e,this.$i.W().overlayPriceScales)),this.po.push(t),!pt(e)){const i=this.o_.get(e)||[];i.push(t),this.o_.set(e,i)}s.qo(t),t.Gi(s),t.Ki(i),this.P_(s),this.mo=null}m_(t,e,i){e.Cr!==i.Cr&&this.L_(t)}v_(t,e){const i=Object.assign({visible:!0,autoScale:!0},A(e)),s=new Si(t,i,this.$i.W().layout,this.$i.W().localization);return s.Lo(this.At()),s}}class Mi{constructor(t,e,i=50){this.Ke=0,this.Ge=1,this.Je=1,this.tr=new Map,this.Qe=new Map,this.U_=t,this.q_=e,this.ir=i}Y_(t){const e=t.time,i=this.q_.cacheKey(e),s=this.tr.get(i);if(void 0!==s)return s.Z_;if(this.Ke===this.ir){const t=this.Qe.get(this.Je);this.Qe.delete(this.Je),this.tr.delete(x(t)),this.Je++,this.Ke--}const n=this.U_(t);return this.tr.set(i,{Z_:n,rr:this.Ge}),this.Qe.set(this.Ge,i),this.Ke++,this.Ge++,n}}class Ci{constructor(t,e){S(t<=e,"right should be >= left"),this.X_=t,this.K_=e}Os(){return this.X_}ui(){return this.K_}G_(){return this.K_-this.X_+1}Kr(t){return this.X_<=t&&t<=this.K_}Ch(t){return this.X_===t.Os()&&this.K_===t.ui()}}function Ei(t,e){return null===t||null===e?t===e:t.Ch(e)}class _i{constructor(){this.J_=new Map,this.tr=null,this.Q_=!1}tu(t){this.Q_=t,this.tr=null}iu(t,e){this.nu(e),this.tr=null;for(let i=e;i<t.length;++i){const e=t[i];let s=this.J_.get(e.timeWeight);void 0===s&&(s=[],this.J_.set(e.timeWeight,s)),s.push({index:i,time:e.time,weight:e.timeWeight,originalTime:e.originalTime})}}su(t,e){const i=Math.ceil(e/t);return null!==this.tr&&this.tr.eu===i||(this.tr={Ha:this.ru(i),eu:i}),this.tr.Ha}nu(t){if(0===t)return void this.J_.clear();const e=[];this.J_.forEach((i,s)=>{t<=i[0].index?e.push(s):i.splice(Vt(i,t,e=>e.index<t),1/0)});for(const t of e)this.J_.delete(t)}ru(t){let e=[];for(const i of Array.from(this.J_.keys()).sort((t,e)=>e-t)){if(!this.J_.get(i))continue;const s=e;e=[];const n=s.length;let r=0;const o=x(this.J_.get(i)),h=o.length;let l=1/0,a=-1/0;for(let i=0;i<h;i++){const h=o[i],c=h.index;for(;r<n;){const t=s[r],i=t.index;if(!(i<c)){l=i;break}r++,e.push(t),a=i,l=1/0}if(l-c>=t&&c-a>=t)e.push(h),a=c;else if(this.Q_)return s}for(;r<n;r++)e.push(s[r])}return e}}class $i{constructor(t){this.hu=t}lu(){return null===this.hu?null:new Ci(Math.floor(this.hu.Os()),Math.ceil(this.hu.ui()))}au(){return this.hu}static ou(){return new $i(null)}}function zi(t,e){return t.weight>e.weight?t:e}class ki{constructor(t,e,i,s){this.__=0,this._u=null,this.uu=[],this.Mo=null,this.wo=null,this.cu=new _i,this.du=new Map,this.fu=$i.ou(),this.vu=!0,this.pu=new P,this.mu=new P,this.bu=new P,this.wu=null,this.gu=null,this.Mu=[],this.cn=e,this.yo=i,this.xu=e.rightOffset,this.Su=e.barSpacing,this.$i=t,this.q_=s,this.ku(),this.cu.tu(e.uniformDistribution)}W(){return this.cn}yu(t){F(this.yo,t),this.Cu(),this.ku()}$h(t,e){var i;F(this.cn,t),this.cn.fixLeftEdge&&this.Tu(),this.cn.fixRightEdge&&this.Pu(),void 0!==t.barSpacing&&this.$i.Gn(t.barSpacing),void 0!==t.rightOffset&&this.$i.Jn(t.rightOffset),void 0!==t.minBarSpacing&&this.$i.Gn(null!==(i=t.barSpacing)&&void 0!==i?i:this.Su),this.Cu(),this.ku(),this.bu.m()}mn(t){var e,i;return null!==(i=null===(e=this.uu[t])||void 0===e?void 0:e.time)&&void 0!==i?i:null}Ui(t){var e;return null!==(e=this.uu[t])&&void 0!==e?e:null}Va(t,e){if(this.uu.length<1)return null;if(this.q_.key(t)>this.q_.key(this.uu[this.uu.length-1].time))return e?this.uu.length-1:null;const i=Vt(this.uu,this.q_.key(t),(t,e)=>this.q_.key(t.time)<e);return this.q_.key(t)<this.q_.key(this.uu[i].time)?e?i:null:i}Ni(){return 0===this.__||0===this.uu.length||null===this._u}Da(){return this.uu.length>0}Xs(){return this.Ru(),this.fu.lu()}Du(){return this.Ru(),this.fu.au()}Vu(){const t=this.Xs();if(null===t)return null;const e={from:t.Os(),to:t.ui()};return this.Ou(e)}Ou(t){const e=Math.round(t.from),i=Math.round(t.to),s=M(this.Bu()),n=M(this.Au());return{from:M(this.Ui(Math.max(s,e))),to:M(this.Ui(Math.min(n,i)))}}Iu(t){return{from:M(this.Va(t.from,!0)),to:M(this.Va(t.to,!0))}}Hi(){return this.__}S_(t){if(!isFinite(t)||t<=0)return;if(this.__===t)return;const e=this.Du(),i=this.__;if(this.__=t,this.vu=!0,this.cn.lockVisibleTimeRangeOnResize&&0!==i){const e=this.Su*t/i;this.Su=e}if(this.cn.fixLeftEdge&&null!==e&&e.Os()<=0){const e=i-t;this.xu-=Math.round(e/this.Su)+1,this.vu=!0}this.zu(),this.Lu()}It(t){if(this.Ni()||!D(t))return 0;const e=this.Eu()+this.xu-t;return this.__-(e+.5)*this.Su-1}Qs(t,e){const i=this.Eu(),s=void 0===e?0:e.from,n=void 0===e?t.length:e.to;for(let e=s;e<n;e++){const s=t[e].ot,n=i+this.xu-s,r=this.__-(n+.5)*this.Su-1;t[e].nt=r}}Nu(t){return Math.ceil(this.Fu(t))}Jn(t){this.vu=!0,this.xu=t,this.Lu(),this.$i.Wu(),this.$i.Uh()}le(){return this.Su}Gn(t){this.ju(t),this.Lu(),this.$i.Wu(),this.$i.Uh()}Hu(){return this.xu}Ha(){if(this.Ni())return null;if(null!==this.gu)return this.gu;const t=this.Su,e=5*(this.$i.W().layout.fontSize+4)/8*(this.cn.tickMarkMaxCharacterLength||8),i=Math.round(e/t),s=M(this.Xs()),n=Math.max(s.Os(),s.Os()-i),r=Math.max(s.ui(),s.ui()-i),o=this.cu.su(t,e),h=this.Bu()+i,l=this.Au()-i,a=this.$u(),c=this.cn.fixLeftEdge||a,u=this.cn.fixRightEdge||a;let d=0;for(const t of o){if(!(n<=t.index&&t.index<=r))continue;let i;d<this.Mu.length?(i=this.Mu[d],i.coord=this.It(t.index),i.label=this.Uu(t),i.weight=t.weight):(i={needAlignCoordinate:!1,coord:this.It(t.index),label:this.Uu(t),weight:t.weight},this.Mu.push(i)),this.Su>e/2&&!a?i.needAlignCoordinate=!1:i.needAlignCoordinate=c&&t.index<=h||u&&t.index>=l,d++}return this.Mu.length=d,this.gu=this.Mu,this.Mu}qu(){this.vu=!0,this.Gn(this.cn.barSpacing),this.Jn(this.cn.rightOffset)}Yu(t){this.vu=!0,this._u=t,this.Lu(),this.Tu()}Zu(t,e){const i=this.Fu(t),s=this.le(),n=s+e*(s/10);this.Gn(n),this.cn.rightBarStaysOnScroll||this.Jn(this.Hu()+(i-this.Fu(t)))}Go(t){this.Mo&&this.n_(),null===this.wo&&null===this.wu&&(this.Ni()||(this.wo=t,this.Xu()))}Jo(t){if(null===this.wu)return;const e=zt(this.__-t,0,this.__),i=zt(this.__-M(this.wo),0,this.__);0!==e&&0!==i&&this.Gn(this.wu.le*e/i)}Qo(){null!==this.wo&&(this.wo=null,this.Ku())}t_(t){null===this.Mo&&null===this.wu&&(this.Ni()||(this.Mo=t,this.Xu()))}i_(t){if(null===this.Mo)return;const e=(this.Mo-t)/this.le();this.xu=M(this.wu).Hu+e,this.vu=!0,this.Lu()}n_(){null!==this.Mo&&(this.Mo=null,this.Ku())}Gu(){this.Ju(this.cn.rightOffset)}Ju(t,e=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(e)||e<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const i=this.xu,s=performance.now();this.$i.Zn({Qu:t=>(t-s)/e>=1,tc:n=>{const r=(n-s)/e;return r>=1?t:i+(t-i)*r}})}bt(t,e){this.vu=!0,this.uu=t,this.cu.iu(t,e),this.Lu()}nc(){return this.pu}sc(){return this.mu}ec(){return this.bu}Eu(){return this._u||0}rc(t){const e=t.G_();this.ju(this.__/e),this.xu=t.ui()-this.Eu(),this.Lu(),this.vu=!0,this.$i.Wu(),this.$i.Uh()}hc(){const t=this.Bu(),e=this.Au();null!==t&&null!==e&&this.rc(new Ci(t,e+this.cn.rightOffset))}lc(t){const e=new Ci(t.from,t.to);this.rc(e)}qi(t){return void 0!==this.yo.timeFormatter?this.yo.timeFormatter(t.originalTime):this.q_.formatHorzItem(t.time)}$u(){const{handleScroll:t,handleScale:e}=this.$i.W();return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||e.axisDoubleClickReset.time||e.axisPressedMouseMove.time||e.mouseWheel||e.pinch)}Bu(){return 0===this.uu.length?null:0}Au(){return 0===this.uu.length?null:this.uu.length-1}ac(t){return(this.__-1-t)/this.Su}Fu(t){const e=this.ac(t),i=this.Eu()+this.xu-e;return Math.round(1e6*i)/1e6}ju(t){const e=this.Su;this.Su=t,this.zu(),e!==this.Su&&(this.vu=!0,this.oc())}Ru(){if(!this.vu)return;if(this.vu=!1,this.Ni())return void this._c($i.ou());const t=this.Eu(),e=this.__/this.Su,i=this.xu+t,s=new Ci(i-e+1,i);this._c(new $i(s))}zu(){const t=this.uc();if(this.Su<t&&(this.Su=t,this.vu=!0),0!==this.__){const t=.5*this.__;this.Su>t&&(this.Su=t,this.vu=!0)}}uc(){return this.cn.fixLeftEdge&&this.cn.fixRightEdge&&0!==this.uu.length?this.__/this.uu.length:this.cn.minBarSpacing}Lu(){const t=this.cc();null!==t&&this.xu<t&&(this.xu=t,this.vu=!0);const e=this.dc();this.xu>e&&(this.xu=e,this.vu=!0)}cc(){const t=this.Bu(),e=this._u;return null===t||null===e?null:t-e-1+(this.cn.fixLeftEdge?this.__/this.Su:Math.min(2,this.uu.length))}dc(){return this.cn.fixRightEdge?0:this.__/this.Su-Math.min(2,this.uu.length)}Xu(){this.wu={le:this.le(),Hu:this.Hu()}}Ku(){this.wu=null}Uu(t){let e=this.du.get(t.weight);return void 0===e&&(e=new Mi(t=>this.fc(t),this.q_),this.du.set(t.weight,e)),e.Y_(t)}fc(t){return this.q_.formatTickmark(t,this.yo)}_c(t){const e=this.fu;this.fu=t,Ei(e.lu(),this.fu.lu())||this.pu.m(),Ei(e.au(),this.fu.au())||this.mu.m(),this.oc()}oc(){this.gu=null}Cu(){this.oc(),this.du.clear()}ku(){this.q_.updateFormatter(this.yo)}Tu(){if(!this.cn.fixLeftEdge)return;const t=this.Bu();if(null===t)return;const e=this.Xs();if(null===e)return;const i=e.Os()-t;if(i<0){const t=this.xu-i-1;this.Jn(t)}this.zu()}Pu(){this.Lu(),this.zu()}}class Ri{X(t,e,i){t.useMediaCoordinateSpace(t=>this.K(t,e,i))}gl(t,e,i){t.useMediaCoordinateSpace(t=>this.vc(t,e,i))}vc(t,e,i){}}class Li extends Ri{constructor(t){super(),this.mc=new Map,this.zt=t}K(t){}vc(t){if(!this.zt.yt)return;const{context:e,mediaSize:i}=t;let s=0;for(const t of this.zt.bc){if(0===t.Kt.length)continue;e.font=t.R;const n=this.wc(e,t.Kt);n>i.width?t.Zu=i.width/n:t.Zu=1,s+=t.gc*t.Zu}let n=0;switch(this.zt.Mc){case"top":n=0;break;case"center":n=Math.max((i.height-s)/2,0);break;case"bottom":n=Math.max(i.height-s,0)}e.fillStyle=this.zt.V;for(const t of this.zt.bc){e.save();let s=0;switch(this.zt.xc){case"left":e.textAlign="left",s=t.gc/2;break;case"center":e.textAlign="center",s=i.width/2;break;case"right":e.textAlign="right",s=i.width-1-t.gc/2}e.translate(s,n),e.textBaseline="top",e.font=t.R,e.scale(t.Zu,t.Zu),e.fillText(t.Kt,0,t.Sc),e.restore(),n+=t.gc*t.Zu}}wc(t,e){const i=this.kc(t.font);let s=i.get(e);return void 0===s&&(s=t.measureText(e).width,i.set(e,s)),s}kc(t){let e=this.mc.get(t);return void 0===e&&(e=new Map,this.mc.set(t,e)),e}}class Ti{constructor(t){this.ft=!0,this.Ft={yt:!1,V:"",bc:[],Mc:"center",xc:"center"},this.Wt=new Li(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.W(),e=this.Ft;e.yt=t.visible,e.yt&&(e.V=t.color,e.xc=t.horzAlign,e.Mc=t.vertAlign,e.bc=[{Kt:t.text,R:H(t.fontSize,t.fontFamily,t.fontStyle),gc:1.2*t.fontSize,Sc:0,Zu:0}])}}class Ni extends dt{constructor(t,e){super(),this.cn=e,this.wn=new Ti(this)}Rn(){return[]}Pn(){return[this.wn]}W(){return this.cn}Vn(){this.wn.bt()}}var Oi,Pi,Fi,Vi,Di;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Oi||(Oi={}));class Ii{constructor(t,e,i){this.yc=[],this.Cc=[],this.__=0,this.Tc=null,this.Pc=new P,this.Rc=new P,this.Dc=null,this.Vc=t,this.cn=e,this.q_=i,this.Oc=new K(this),this.yl=new ki(this,e.timeScale,this.cn.localization,i),this.vt=new mt(this,e.crosshair),this.Bc=new ei(e.crosshair),this.Ac=new Ni(this,e.watermark),this.Ic(),this.yc[0].x_(2e3),this.zc=this.Lc(0),this.Ec=this.Lc(1)}Kl(){this.Nc(gt.es())}Uh(){this.Nc(gt.ss())}oa(){this.Nc(new gt(1))}Gl(t){const e=this.Fc(t);this.Nc(e)}Wc(){return this.Tc}jc(t){const e=this.Tc;this.Tc=t,null!==e&&this.Gl(e.Hc),null!==t&&this.Gl(t.Hc)}W(){return this.cn}$h(t){F(this.cn,t),this.yc.forEach(e=>e.b_(t)),void 0!==t.timeScale&&this.yl.$h(t.timeScale),void 0!==t.localization&&this.yl.yu(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Pc.m(),this.zc=this.Lc(0),this.Ec=this.Lc(1),this.Kl()}$c(t,e){if("left"===t)return void this.$h({leftPriceScale:e});if("right"===t)return void this.$h({rightPriceScale:e});const i=this.Uc(t);null!==i&&(i.Dt.$h(e),this.Pc.m())}Uc(t){for(const e of this.yc){const i=e.w_(t);if(null!==i)return{Ht:e,Dt:i}}return null}St(){return this.yl}qc(){return this.yc}Yc(){return this.Ac}Zc(){return this.vt}Xc(){return this.Rc}Kc(t,e){t.Lo(e),this.Wu()}S_(t){this.__=t,this.yl.S_(this.__),this.yc.forEach(e=>e.S_(t)),this.Wu()}Ic(t){const e=new xi(this.yl,this);void 0!==t?this.yc.splice(t,0,e):this.yc.push(e);const i=void 0===t?this.yc.length-1:t,s=gt.es();return s.Nn(i,{Fn:0,Wn:!0}),this.Nc(s),e}V_(t,e,i){t.V_(e,i)}O_(t,e,i){t.O_(e,i),this.Jl(),this.Nc(this.Gc(t,2))}B_(t,e){t.B_(e),this.Nc(this.Gc(t,2))}A_(t,e,i){e.Vo()||t.A_(e,i)}I_(t,e,i){e.Vo()||(t.I_(e,i),this.Jl(),this.Nc(this.Gc(t,2)))}z_(t,e){e.Vo()||(t.z_(e),this.Nc(this.Gc(t,2)))}E_(t,e){t.E_(e),this.Nc(this.Gc(t,2))}Jc(t){this.yl.Go(t)}Qc(t,e){const i=this.St();if(i.Ni()||0===e)return;const s=i.Hi();t=Math.max(1,Math.min(t,s)),i.Zu(t,e),this.Wu()}td(t){this.nd(0),this.sd(t),this.ed()}rd(t){this.yl.Jo(t),this.Wu()}hd(){this.yl.Qo(),this.Uh()}nd(t){this.yl.t_(t)}sd(t){this.yl.i_(t),this.Wu()}ed(){this.yl.n_(),this.Uh()}wt(){return this.Cc}ld(t,e,i,s,n){this.vt.gn(t,e);let r=NaN,o=this.yl.Nu(t);const h=this.yl.Xs();null!==h&&(o=Math.min(Math.max(h.Os(),o),h.ui()));const l=s.vn(),a=l.Ct();null!==a&&(r=l.pn(e,a)),r=this.Bc.Oa(r,o,s),this.vt.kn(o,r,s),this.oa(),n||this.Rc.m(this.vt.xt(),{x:t,y:e},i)}ad(t,e,i){const s=i.vn(),n=s.Ct(),r=s.Rt(t,M(n)),o=this.yl.Va(e,!0),h=this.yl.It(M(o));this.ld(h,r,null,i,!0)}od(t){this.Zc().Cn(),this.oa(),t||this.Rc.m(null,null,null)}Jl(){const t=this.vt.Ht();if(null!==t){const e=this.vt.xn(),i=this.vt.Sn();this.ld(e,i,null,t)}this.vt.Vn()}_d(t,e,i){const s=this.yl.mn(0);void 0!==e&&void 0!==i&&this.yl.bt(e,i);const n=this.yl.mn(0),r=this.yl.Eu(),o=this.yl.Xs();if(null!==o&&null!==s&&null!==n){const e=o.Kr(r),h=this.q_.key(s)>this.q_.key(n),l=null!==t&&t>r&&!h,a=this.yl.W().allowShiftVisibleRangeOnWhitespaceReplacement,c=e&&(!(void 0===i)||a)&&this.yl.W().shiftVisibleRangeOnNewBar;if(l&&!c){const e=t-r;this.yl.Jn(this.yl.Hu()-e)}}this.yl.Yu(t)}ia(t){null!==t&&t.F_()}dr(t){const e=this.yc.find(e=>e.Uo().includes(t));return void 0===e?null:e}Wu(){this.Ac.Vn(),this.yc.forEach(t=>t.F_()),this.Jl()}S(){this.yc.forEach(t=>t.S()),this.yc.length=0,this.cn.localization.priceFormatter=void 0,this.cn.localization.percentageFormatter=void 0,this.cn.localization.timeFormatter=void 0}ud(){return this.Oc}br(){return this.Oc.W()}g_(){return this.Pc}dd(t,e,i){const s=this.yc[0],n=this.fd(e,t,s,i);return this.Cc.push(n),1===this.Cc.length?this.Kl():this.Uh(),n}vd(t){const e=this.dr(t),i=this.Cc.indexOf(t);S(-1!==i,"Series not found"),this.Cc.splice(i,1),M(e).Zo(t),t.S&&t.S()}Xl(t,e){const i=M(this.dr(t));i.Zo(t);const s=this.Uc(e);if(null===s){const s=t.Xi();i.qo(t,e,s)}else{const n=s.Ht===i?t.Xi():void 0;s.Ht.qo(t,e,n)}}hc(){const t=gt.ss();t.$n(),this.Nc(t)}pd(t){const e=gt.ss();e.Yn(t),this.Nc(e)}Kn(){const t=gt.ss();t.Kn(),this.Nc(t)}Gn(t){const e=gt.ss();e.Gn(t),this.Nc(e)}Jn(t){const e=gt.ss();e.Jn(t),this.Nc(e)}Zn(t){const e=gt.ss();e.Zn(t),this.Nc(e)}Un(){const t=gt.ss();t.Un(),this.Nc(t)}md(){return this.cn.rightPriceScale.visible?"right":"left"}bd(){return this.Ec}q(){return this.zc}Bt(t){const e=this.Ec,i=this.zc;if(e===i)return e;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Dc||this.Dc.Ps!==i||this.Dc.Rs!==e)this.Dc={Ps:i,Rs:e,wd:new Map};else{const e=this.Dc.wd.get(t);if(void 0!==e)return e}const s=function(t,e,i){const[s,n,r,o]=T(t),[h,l,a,c]=T(e),u=[_(s+i*(h-s)),_(n+i*(l-n)),_(r+i*(a-r)),$(o+i*(c-o))];return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}(i,e,t/100);return this.Dc.wd.set(t,s),s}Gc(t,e){const i=new gt(e);if(null!==t){const s=this.yc.indexOf(t);i.Nn(s,{Fn:e})}return i}Fc(t,e){return void 0===e&&(e=2),this.Gc(this.dr(t),e)}Nc(t){this.Vc&&this.Vc(t),this.yc.forEach(t=>t.j_().qh().bt())}fd(t,e,i,s){const n=new ti(this,t,e,i,s),r=void 0!==t.priceScaleId?t.priceScaleId:this.md();return i.qo(n,r),pt(r)||n.$h(t),n}Lc(t){const e=this.cn.layout;return"gradient"===e.background.type?0===t?e.background.topColor:e.background.bottomColor:e.background.color}}function Bi(t){return!V(t)&&!I(t)}function Ai(t){return V(t)}!function(t){t[t.Disabled=0]="Disabled",t[t.Continuous=1]="Continuous",t[t.OnDataUpdate=2]="OnDataUpdate"}(Pi||(Pi={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Fi||(Fi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Vi||(Vi={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Di||(Di={}));const Wi=t=>t.getUTCFullYear();class ji{constructor(t="yyyy-MM-dd",e="default"){this.gd=t,this.Md=e}Y_(t){return function(t,e,i){return e.replace(/yyyy/g,(t=>bt(Wi(t),4))(t)).replace(/yy/g,(t=>bt(Wi(t)%100,2))(t)).replace(/MMMM/g,((t,e)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(e,{month:"long"}))(t,i)).replace(/MMM/g,((t,e)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(e,{month:"short"}))(t,i)).replace(/MM/g,(t=>bt((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>bt((t=>t.getUTCDate())(t),2))(t))}(t,this.gd,this.Md)}}class Ui{constructor(t){this.xd=t||"%h:%m:%s"}Y_(t){return this.xd.replace("%h",bt(t.getUTCHours(),2)).replace("%m",bt(t.getUTCMinutes(),2)).replace("%s",bt(t.getUTCSeconds(),2))}}const Hi={Sd:"yyyy-MM-dd",kd:"%h:%m:%s",yd:" ",Cd:"default"};class Ki{constructor(t={}){const e=Object.assign(Object.assign({},Hi),t);this.Td=new ji(e.Sd,e.Cd),this.Pd=new Ui(e.kd),this.Rd=e.yd}Y_(t){return`${this.Td.Y_(t)}${this.Rd}${this.Pd.Y_(t)}`}}function qi(t){return 60*t*60*1e3}function Xi(t){return 60*t*1e3}const Ji=[{Dd:1e3,Vd:10},{Dd:Xi(1),Vd:20},{Dd:Xi(5),Vd:21},{Dd:Xi(30),Vd:22},{Dd:qi(1),Vd:30},{Dd:qi(3),Vd:31},{Dd:qi(6),Vd:32},{Dd:qi(12),Vd:33}];function Gi(t,e){if(t.getUTCFullYear()!==e.getUTCFullYear())return 70;if(t.getUTCMonth()!==e.getUTCMonth())return 60;if(t.getUTCDate()!==e.getUTCDate())return 50;for(let i=Ji.length-1;i>=0;--i)if(Math.floor(e.getTime()/Ji[i].Dd)!==Math.floor(t.getTime()/Ji[i].Dd))return Ji[i].Vd;return 0}function Qi(t){let e=t;if(I(t)&&(e=Zi(t)),!Bi(e))throw new Error("time must be of type BusinessDay");const i=new Date(Date.UTC(e.year,e.month-1,e.day,0,0,0,0));return{Od:Math.round(i.getTime()/1e3),Bd:e}}function Yi(t){if(!Ai(t))throw new Error("time must be of type isUTCTimestamp");return{Od:t}}function Zi(t){const e=new Date(t);if(isNaN(e.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:e.getUTCDate(),month:e.getUTCMonth()+1,year:e.getUTCFullYear()}}function ts(t){I(t.time)&&(t.time=Zi(t.time))}class es{options(){return this.cn}setOptions(t){this.cn=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(ts)}(t):ts(t)}createConverterToInternalObj(t){return M(function(t){return 0===t.length?null:Bi(t[0].time)||I(t[0].time)?Qi:Yi}(t))}key(t){return"object"==typeof t&&"Od"in t?t.Od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const e=t;return void 0===e.Bd?new Date(1e3*e.Od).getTime():new Date(Date.UTC(e.Bd.year,e.Bd.month-1,e.Bd.day)).getTime()}convertHorzItemToInternal(t){return Ai(e=t)?Yi(e):Bi(e)?Qi(e):Qi(Zi(e));var e}updateFormatter(t){if(!this.cn)return;const e=t.dateFormat;this.cn.timeScale.timeVisible?this.Ad=new Ki({Sd:e,kd:this.cn.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",yd:" ",Cd:t.locale}):this.Ad=new ji(e,t.locale)}formatHorzItem(t){const e=t;return this.Ad.Y_(new Date(1e3*e.Od))}formatTickmark(t,e){const i=function(t,e,i){switch(t){case 0:case 10:return e?i?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return e?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.cn.timeScale.timeVisible,this.cn.timeScale.secondsVisible),s=this.cn.timeScale;if(void 0!==s.tickMarkFormatter){const n=s.tickMarkFormatter(t.originalTime,i,e.locale);if(null!==n)return n}return function(t,e,i){const s={};switch(e){case 0:s.year="numeric";break;case 1:s.month="short";break;case 2:s.day="numeric";break;case 3:s.hour12=!1,s.hour="2-digit",s.minute="2-digit";break;case 4:s.hour12=!1,s.hour="2-digit",s.minute="2-digit",s.second="2-digit"}const n=void 0===t.Bd?new Date(1e3*t.Od):new Date(Date.UTC(t.Bd.year,t.Bd.month-1,t.Bd.day));return new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds()).toLocaleString(i,s)}(t.time,i,e.locale)}maxTickMarkWeight(t){let e=t.reduce(zi,t[0]).weight;return e>30&&e<50&&(e=30),e}fillWeightsForPoints(t,e){!function(t,e=0){if(0===t.length)return;let i=0===e?null:t[e-1].time.Od,s=null!==i?new Date(1e3*i):null,n=0;for(let r=e;r<t.length;++r){const e=t[r],o=new Date(1e3*e.time.Od);null!==s&&(e.timeWeight=Gi(o,s)),n+=e.time.Od-(i||e.time.Od),i=e.time.Od,s=o}if(0===e&&t.length>1){const e=Math.ceil(n/(t.length-1)),i=new Date(1e3*(t[0].time.Od-e));t[0].timeWeight=Gi(new Date(1e3*t[0].time.Od),i)}}(t,e)}static Id(t){return F({localization:{dateFormat:"dd MMM 'yy"}},null!=t?t:{})}}const is="undefined"!=typeof window;function ss(){return!!is&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ns(){return!!is&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function rs(t){return t+t%2}function os(t,e){return t.zd-e.zd}function hs(t,e,i){const s=(t.zd-e.zd)/(t.ot-e.ot);return Math.sign(s)*Math.min(Math.abs(s),i)}class ls{constructor(t,e,i,s){this.Ld=null,this.Ed=null,this.Nd=null,this.Fd=null,this.Wd=null,this.jd=0,this.Hd=0,this.$d=t,this.Ud=e,this.qd=i,this.rs=s}Yd(t,e){if(null!==this.Ld){if(this.Ld.ot===e)return void(this.Ld.zd=t);if(Math.abs(this.Ld.zd-t)<this.rs)return}this.Fd=this.Nd,this.Nd=this.Ed,this.Ed=this.Ld,this.Ld={ot:e,zd:t}}Vr(t,e){if(null===this.Ld||null===this.Ed)return;if(e-this.Ld.ot>50)return;let i=0;const s=hs(this.Ld,this.Ed,this.Ud),n=os(this.Ld,this.Ed),r=[s],o=[n];if(i+=n,null!==this.Nd){const t=hs(this.Ed,this.Nd,this.Ud);if(Math.sign(t)===Math.sign(s)){const e=os(this.Ed,this.Nd);if(r.push(t),o.push(e),i+=e,null!==this.Fd){const t=hs(this.Nd,this.Fd,this.Ud);if(Math.sign(t)===Math.sign(s)){const e=os(this.Nd,this.Fd);r.push(t),o.push(e),i+=e}}}}let h=0;for(let t=0;t<r.length;++t)h+=o[t]/i*r[t];Math.abs(h)<this.$d||(this.Wd={zd:t,ot:e},this.Hd=h,this.jd=function(t,e){const i=Math.log(e);return Math.log(1*i/-t)/i}(Math.abs(h),this.qd))}tc(t){const e=M(this.Wd),i=t-e.ot;return e.zd+this.Hd*(Math.pow(this.qd,i)-1)/Math.log(this.qd)}Qu(t){return null===this.Wd||this.Zd(t)===this.jd}Zd(t){const e=t-M(this.Wd).ot;return Math.min(e,this.jd)}}class as{constructor(t,e){this.Xd=void 0,this.Kd=void 0,this.Gd=void 0,this.en=!1,this.Jd=t,this.Qd=e,this.tf()}bt(){this.tf()}if(){this.Xd&&this.Jd.removeChild(this.Xd),this.Kd&&this.Jd.removeChild(this.Kd),this.Xd=void 0,this.Kd=void 0}nf(){return this.en!==this.sf()||this.Gd!==this.ef()}ef(){return N(T(this.Qd.W().layout.textColor))>160?"dark":"light"}sf(){return this.Qd.W().layout.attributionLogo}rf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}tf(){this.nf()&&(this.if(),this.en=this.sf(),this.en&&(this.Gd=this.ef(),this.Kd=document.createElement("style"),this.Kd.innerText="a#tv-attr-logo{--fill:#131722;--stroke:#fff;position:absolute;left:10px;bottom:10px;height:19px;width:35px;margin:0;padding:0;border:0;z-index:3;}a#tv-attr-logo[data-dark]{--fill:#D1D4DC;--stroke:#131722;}",this.Xd=document.createElement("a"),this.Xd.href=`https://www.tradingview.com/?utm_medium=lwc-link&utm_campaign=lwc-chart${this.rf()}`,this.Xd.title="Charting by TradingView",this.Xd.id="tv-attr-logo",this.Xd.target="_blank",this.Xd.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 19" width="35" height="19" fill="none"><g fill-rule="evenodd" clip-path="url(#a)" clip-rule="evenodd"><path fill="var(--stroke)" d="M2 0H0v10h6v9h21.4l.5-1.3 6-15 1-2.7H23.7l-.5 1.3-.2.6a5 5 0 0 0-7-.9V0H2Zm20 17h4l5.2-13 .8-2h-7l-1 2.5-.2.5-1.5 3.8-.3.7V17Zm-.8-10a3 3 0 0 0 .7-2.7A3 3 0 1 0 16.8 7h4.4ZM14 7V2H2v6h6v9h4V7h2Z"/><path fill="var(--fill)" d="M14 2H2v6h6v9h6V2Zm12 15h-7l6-15h7l-6 15Zm-7-9a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></g><defs><clipPath id="a"><path fill="var(--stroke)" d="M0 0h35v19H0z"/></clipPath></defs></svg>',this.Xd.toggleAttribute("data-dark","dark"===this.Gd),this.Jd.appendChild(this.Kd),this.Jd.appendChild(this.Xd)))}}function cs(t,e){const i=M(t.ownerDocument).createElement("canvas");t.appendChild(i);const s=(r={options:{allowResizeObserver:!1},transform:(t,e)=>({width:Math.max(t.width,e.width),height:Math.max(t.height,e.height)})},new n(i,r.transform,r.options));var r;return s.resizeCanvasElement(e),s}function us(t){var e;t.width=1,t.height=1,null===(e=t.getContext("2d"))||void 0===e||e.clearRect(0,0,1,1)}function ds(t,e,i,s){t.gl&&t.gl(e,i,s)}function fs(t,e,i,s){t.X(e,i,s)}function ms(t,e,i,s){const n=t(i,s);for(const t of n){const i=t.gt();null!==i&&e(i)}}class ps{constructor(t,e,i){this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this.df=null,this.ff=!1,this.vf=null,this.pf=null,this.mf=!1,this.bf=!1,this.wf=!1,this.gf=null,this.Mf=null,this.xf=null,this.Sf=null,this.kf=null,this.yf=null,this.Cf=null,this.Tf=0,this.Pf=!1,this.Rf=!1,this.Df=!1,this.Vf=0,this.Of=null,this.Bf=!ns(),this.Af=t=>{this.If(t)},this.zf=t=>{if(this.Lf(t)){const e=this.Ef(t);if(++this._f,this.uf&&this._f>1){const{Nf:i}=this.Ff(vs(t),this.cf);i<30&&!this.wf&&this.Wf(e,this.Hf.jf),this.$f()}}else{const e=this.Ef(t);if(++this.hf,this.lf&&this.hf>1){const{Nf:i}=this.Ff(vs(t),this.af);i<5&&!this.bf&&this.Uf(e,this.Hf.qf),this.Yf()}}},this.Zf=t,this.Hf=e,this.cn=i,this.Xf()}S(){null!==this.gf&&(this.gf(),this.gf=null),null!==this.Mf&&(this.Mf(),this.Mf=null),null!==this.Sf&&(this.Sf(),this.Sf=null),null!==this.kf&&(this.kf(),this.kf=null),null!==this.yf&&(this.yf(),this.yf=null),null!==this.xf&&(this.xf(),this.xf=null),this.Kf(),this.Yf()}Gf(t){this.Sf&&this.Sf();const e=this.Jf.bind(this);if(this.Sf=()=>{this.Zf.removeEventListener("mousemove",e)},this.Zf.addEventListener("mousemove",e),this.Lf(t))return;const i=this.Ef(t);this.Uf(i,this.Hf.Qf),this.Bf=!0}Yf(){null!==this.lf&&clearTimeout(this.lf),this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}$f(){null!==this.uf&&clearTimeout(this.uf),this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}Jf(t){if(this.Df||null!==this.pf)return;if(this.Lf(t))return;const e=this.Ef(t);this.Uf(e,this.Hf.tv),this.Bf=!0}iv(t){const e=ys(t.changedTouches,M(this.Of));if(null===e)return;if(this.Vf=ws(t),null!==this.Cf)return;if(this.Rf)return;this.Pf=!0;const i=this.Ff(vs(e),M(this.pf)),{nv:s,sv:n,Nf:r}=i;if(this.mf||!(r<5)){if(!this.mf){const t=.5*s,e=n>=t&&!this.cn.ev(),i=t>n&&!this.cn.rv();e||i||(this.Rf=!0),this.mf=!0,this.wf=!0,this.Kf(),this.$f()}if(!this.Rf){const i=this.Ef(t,e);this.Wf(i,this.Hf.hv),bs(t)}}}lv(t){if(0!==t.button)return;const e=this.Ff(vs(t),M(this.vf)),{Nf:i}=e;if(i>=5&&(this.bf=!0,this.Yf()),this.bf){const e=this.Ef(t);this.Uf(e,this.Hf.av)}}Ff(t,e){const i=Math.abs(e.nt-t.nt),s=Math.abs(e.st-t.st);return{nv:i,sv:s,Nf:i+s}}ov(t){let e=ys(t.changedTouches,M(this.Of));if(null===e&&0===t.touches.length&&(e=t.changedTouches[0]),null===e)return;this.Of=null,this.Vf=ws(t),this.Kf(),this.pf=null,this.yf&&(this.yf(),this.yf=null);const i=this.Ef(t,e);if(this.Wf(i,this.Hf._v),++this._f,this.uf&&this._f>1){const{Nf:t}=this.Ff(vs(e),this.cf);t<30&&!this.wf&&this.Wf(i,this.Hf.jf),this.$f()}else this.wf||(this.Wf(i,this.Hf.uv),this.Hf.uv&&bs(t));0===this._f&&bs(t),0===t.touches.length&&this.ff&&(this.ff=!1,bs(t))}If(t){if(0!==t.button)return;const e=this.Ef(t);if(this.vf=null,this.Df=!1,this.kf&&(this.kf(),this.kf=null),ss()&&this.Zf.ownerDocument.documentElement.removeEventListener("mouseleave",this.Af),!this.Lf(t))if(this.Uf(e,this.Hf.cv),++this.hf,this.lf&&this.hf>1){const{Nf:i}=this.Ff(vs(t),this.af);i<5&&!this.bf&&this.Uf(e,this.Hf.qf),this.Yf()}else this.bf||this.Uf(e,this.Hf.dv)}Kf(){null!==this.df&&(clearTimeout(this.df),this.df=null)}fv(t){if(null!==this.Of)return;const e=t.changedTouches[0];this.Of=e.identifier,this.Vf=ws(t);const i=this.Zf.ownerDocument.documentElement;this.wf=!1,this.mf=!1,this.Rf=!1,this.pf=vs(e),this.yf&&(this.yf(),this.yf=null);{const e=this.iv.bind(this),s=this.ov.bind(this);this.yf=()=>{i.removeEventListener("touchmove",e),i.removeEventListener("touchend",s)},i.addEventListener("touchmove",e,{passive:!1}),i.addEventListener("touchend",s,{passive:!1}),this.Kf(),this.df=setTimeout(this.vv.bind(this,t),240)}const s=this.Ef(t,e);this.Wf(s,this.Hf.pv),this.uf||(this._f=0,this.uf=setTimeout(this.$f.bind(this),500),this.cf=vs(e))}mv(t){if(0!==t.button)return;const e=this.Zf.ownerDocument.documentElement;ss()&&e.addEventListener("mouseleave",this.Af),this.bf=!1,this.vf=vs(t),this.kf&&(this.kf(),this.kf=null);{const t=this.lv.bind(this),i=this.If.bind(this);this.kf=()=>{e.removeEventListener("mousemove",t),e.removeEventListener("mouseup",i)},e.addEventListener("mousemove",t),e.addEventListener("mouseup",i)}if(this.Df=!0,this.Lf(t))return;const i=this.Ef(t);this.Uf(i,this.Hf.bv),this.lf||(this.hf=0,this.lf=setTimeout(this.Yf.bind(this),500),this.af=vs(t))}Xf(){this.Zf.addEventListener("mouseenter",this.Gf.bind(this)),this.Zf.addEventListener("touchcancel",this.Kf.bind(this));{const t=this.Zf.ownerDocument,e=t=>{this.Hf.wv&&(t.composed&&this.Zf.contains(t.composedPath()[0])||t.target&&this.Zf.contains(t.target)||this.Hf.wv())};this.Mf=()=>{t.removeEventListener("touchstart",e)},this.gf=()=>{t.removeEventListener("mousedown",e)},t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0})}ns()&&(this.xf=()=>{this.Zf.removeEventListener("dblclick",this.zf)},this.Zf.addEventListener("dblclick",this.zf)),this.Zf.addEventListener("mouseleave",this.gv.bind(this)),this.Zf.addEventListener("touchstart",this.fv.bind(this),{passive:!0}),function(t){is&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}(this.Zf),this.Zf.addEventListener("mousedown",this.mv.bind(this)),this.Mv(),this.Zf.addEventListener("touchmove",()=>{},{passive:!1})}Mv(){void 0===this.Hf.xv&&void 0===this.Hf.Sv&&void 0===this.Hf.kv||(this.Zf.addEventListener("touchstart",t=>this.yv(t.touches),{passive:!0}),this.Zf.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Cf&&void 0!==this.Hf.Sv){const e=gs(t.touches[0],t.touches[1])/this.Tf;this.Hf.Sv(this.Cf,e),bs(t)}},{passive:!1}),this.Zf.addEventListener("touchend",t=>{this.yv(t.touches)}))}yv(t){1===t.length&&(this.Pf=!1),2!==t.length||this.Pf||this.ff?this.Cv():this.Tv(t)}Tv(t){const e=this.Zf.getBoundingClientRect()||{left:0,top:0};this.Cf={nt:(t[0].clientX-e.left+(t[1].clientX-e.left))/2,st:(t[0].clientY-e.top+(t[1].clientY-e.top))/2},this.Tf=gs(t[0],t[1]),void 0!==this.Hf.xv&&this.Hf.xv(),this.Kf()}Cv(){null!==this.Cf&&(this.Cf=null,void 0!==this.Hf.kv&&this.Hf.kv())}gv(t){if(this.Sf&&this.Sf(),this.Lf(t))return;if(!this.Bf)return;const e=this.Ef(t);this.Uf(e,this.Hf.Pv),this.Bf=!ns()}vv(t){const e=ys(t.touches,M(this.Of));if(null===e)return;const i=this.Ef(t,e);this.Wf(i,this.Hf.Rv),this.wf=!0,this.ff=!0}Lf(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:ws(t)<this.Vf+500}Wf(t,e){e&&e.call(this.Hf,t)}Uf(t,e){e&&e.call(this.Hf,t)}Ef(t,e){const i=e||t,s=this.Zf.getBoundingClientRect()||{left:0,top:0};return{clientX:i.clientX,clientY:i.clientY,pageX:i.pageX,pageY:i.pageY,screenX:i.screenX,screenY:i.screenY,localX:i.clientX-s.left,localY:i.clientY-s.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Dv:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Vv:t.type,Ov:i.target,Bv:t.view,Av:()=>{"touchstart"!==t.type&&bs(t)}}}}function gs(t,e){const i=t.clientX-e.clientX,s=t.clientY-e.clientY;return Math.sqrt(i*i+s*s)}function bs(t){t.cancelable&&t.preventDefault()}function vs(t){return{nt:t.pageX,st:t.pageY}}function ws(t){return t.timeStamp||performance.now()}function ys(t,e){for(let i=0;i<t.length;++i)if(t[i].identifier===e)return t[i];return null}function Ss(t){return{Hc:t.Hc,Iv:{gr:t.zv.externalId},Lv:t.zv.cursorStyle}}function xs(t,e,i){for(const s of t){const t=s.gt();if(null!==t&&t.wr){const n=t.wr(e,i);if(null!==n)return{Bv:s,Iv:n}}}return null}function Ms(t,e){return i=>{var s,n,r,o;return(null!==(n=null===(s=i.Dt())||void 0===s?void 0:s.Pa())&&void 0!==n?n:"")!==e?[]:null!==(o=null===(r=i.da)||void 0===r?void 0:r.call(i,t))&&void 0!==o?o:[]}}function Cs(t,e,i,s){if(!t.length)return;let n=0;const r=i/2,o=t[0].At(s,!0);let h=1===e?r-(t[0].Vi()-o/2):t[0].Vi()-o/2-r;h=Math.max(0,h);for(let r=1;r<t.length;r++){const o=t[r],l=t[r-1],a=l.At(s,!1),c=o.Vi(),u=l.Vi();if(1===e?c>u-a:c<u+a){const s=u-a*e;o.Oi(s);const r=s-e*a/2;if((1===e?r<0:r>i)&&h>0){const s=1===e?-1-r:r-i,o=Math.min(s,h);for(let i=n;i<t.length;i++)t[i].Oi(t[i].Vi()+e*o);h-=o}}else n=r,h=1===e?u-a-c:c-(u+a)}}class Es{constructor(t,i,s,n){this.Li=null,this.Ev=null,this.Nv=!1,this.Fv=new oe(200),this.Qr=null,this.Wv=0,this.jv=!1,this.Hv=()=>{this.jv||this.tn.$v().$t().Uh()},this.Uv=()=>{this.jv||this.tn.$v().$t().Uh()},this.tn=t,this.cn=i,this.ko=i.layout,this.Oc=s,this.qv="left"===n,this.Yv=Ms("normal",n),this.Zv=Ms("top",n),this.Xv=Ms("bottom",n),this.Kv=document.createElement("div"),this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Kv.style.width="25px",this.Kv.style.left="0",this.Kv.style.position="relative",this.Gv=cs(this.Kv,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const r=this.Gv.canvasElement;r.style.position="absolute",r.style.zIndex="1",r.style.left="0",r.style.top="0",this.Jv=cs(this.Kv,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const o=this.Jv.canvasElement;o.style.position="absolute",o.style.zIndex="2",o.style.left="0",o.style.top="0";const h={bv:this.Qv.bind(this),pv:this.Qv.bind(this),av:this.tp.bind(this),hv:this.tp.bind(this),wv:this.ip.bind(this),cv:this.np.bind(this),_v:this.np.bind(this),qf:this.sp.bind(this),jf:this.sp.bind(this),Qf:this.ep.bind(this),Pv:this.rp.bind(this)};this.hp=new ps(this.Jv.canvasElement,h,{ev:()=>!this.cn.handleScroll.vertTouchDrag,rv:()=>!0})}S(){this.hp.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose(),null!==this.Li&&this.Li.Ko().p(this),this.Li=null}lp(){return this.Kv}P(){return this.ko.fontSize}ap(){const t=this.Oc.W();return this.Qr!==t.R&&(this.Fv.nr(),this.Qr=t.R),t}op(){if(null===this.Li)return 0;let t=0;const e=this.ap(),i=M(this.Gv.canvasElement.getContext("2d"));i.save();const s=this.Li.Ha();i.font=this._p(),s.length>0&&(t=Math.max(this.Fv.xi(i,s[0].so),this.Fv.xi(i,s[s.length-1].so)));const n=this.up();for(let e=n.length;e--;){const s=this.Fv.xi(i,n[e].Kt());s>t&&(t=s)}const r=this.Li.Ct();if(null!==r&&null!==this.Ev&&2!==(o=this.cn.crosshair).mode&&o.horzLine.visible&&o.horzLine.labelVisible){const e=this.Li.pn(1,r),s=this.Li.pn(this.Ev.height-2,r);t=Math.max(t,this.Fv.xi(i,this.Li.Fi(Math.floor(Math.min(e,s))+.11111111111111,r)),this.Fv.xi(i,this.Li.Fi(Math.ceil(Math.max(e,s))-.11111111111111,r)))}var o;i.restore();const h=t||34;return rs(Math.ceil(e.C+e.T+e.A+e.I+5+h))}cp(t){null!==this.Ev&&i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`)}dp(){return M(this.Ev).width}Gi(t){this.Li!==t&&(null!==this.Li&&this.Li.Ko().p(this),this.Li=t,t.Ko().l(this.fo.bind(this),this))}Dt(){return this.Li}nr(){const t=this.tn.fp();this.tn.$v().$t().E_(t,M(this.Dt()))}vp(t){if(null===this.Ev)return;if(1!==t){this.pp(),this.Gv.applySuggestedBitmapSize();const t=h(this.Gv);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t)}),this.tn.bp(t,this.Xv),this.wp(t),this.tn.bp(t,this.Yv),this.gp(t))}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.Mp(e),this.tn.bp(e,this.Zv))}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}bt(){var t;null===(t=this.Li)||void 0===t||t.Ha()}Qv(t){if(null===this.Li||this.Li.Ni()||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp();this.Nv=!0,e.V_(i,this.Li,t.localY)}tp(t){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp(),s=this.Li;e.O_(i,s,t.localY)}ip(){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const t=this.tn.$v().$t(),e=this.tn.fp(),i=this.Li;this.Nv&&(this.Nv=!1,t.B_(e,i))}np(t){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp();this.Nv=!1,e.B_(i,this.Li)}sp(t){this.cn.handleScale.axisDoubleClickReset.price&&this.nr()}ep(t){null!==this.Li&&(!this.tn.$v().$t().W().handleScale.axisPressedMouseMove.price||this.Li.Mh()||this.Li.Oo()||this.kp(1))}rp(t){this.kp(0)}up(){const t=[],e=null===this.Li?void 0:this.Li;return(i=>{for(let s=0;s<i.length;++s){const n=i[s].Rn(this.tn.fp(),e);for(let e=0;e<n.length;e++)t.push(n[e])}})(this.tn.fp().Uo()),t}mp({context:t,bitmapSize:e}){const{width:i,height:s}=e,n=this.tn.fp().$t(),r=n.q(),o=n.bd();r===o?it(t,0,0,i,s,r):rt(t,0,0,i,s,r,o)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:i}){if(null===this.Ev||null===this.Li||!this.Li.W().borderVisible)return;t.fillStyle=this.Li.W().borderColor;const s=Math.max(1,Math.floor(this.ap().C*i));let n;n=this.qv?e.width-s:0,t.fillRect(n,0,s,e.height)}wp(t){if(null===this.Ev||null===this.Li)return;const e=this.Li.Ha(),i=this.Li.W(),s=this.ap(),n=this.qv?this.Ev.width-s.T:0;i.borderVisible&&i.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:o})=>{t.fillStyle=i.borderColor;const h=Math.max(1,Math.floor(o)),l=Math.floor(.5*o),a=Math.round(s.T*r);t.beginPath();for(const i of e)t.rect(Math.floor(n*r),Math.round(i.Ea*o)-l,a,h);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{var r;t.font=this._p(),t.fillStyle=null!==(r=i.textColor)&&void 0!==r?r:this.ko.textColor,t.textAlign=this.qv?"right":"left",t.textBaseline="middle";const o=this.qv?Math.round(n-s.A):Math.round(n+s.T+s.A),h=e.map(e=>this.Fv.Mi(t,e.so));for(let i=e.length;i--;){const s=e[i];t.fillText(s.so,o,s.Ea+h[i])}})}pp(){if(null===this.Ev||null===this.Li)return;const t=[],e=this.Li.Uo().slice(),i=this.tn.fp(),s=this.ap();this.Li===i.pr()&&this.tn.fp().Uo().forEach(t=>{i.vr(t)&&e.push(t)});const n=this.Li;e.forEach(e=>{e.Rn(i,n).forEach(e=>{e.Oi(null),e.Bi()&&t.push(e)})}),t.forEach(t=>t.Oi(t.ki())),this.Li.W().alignLabels&&this.yp(t,s)}yp(t,e){if(null===this.Ev)return;const i=this.Ev.height/2,s=t.filter(t=>t.ki()<=i),n=t.filter(t=>t.ki()>i);s.sort((t,e)=>e.ki()-t.ki()),n.sort((t,e)=>t.ki()-e.ki());for(const i of t){const t=Math.floor(i.At(e)/2),s=i.ki();s>-t&&s<t&&i.Oi(t),s>this.Ev.height-t&&s<this.Ev.height+t&&i.Oi(this.Ev.height-t)}Cs(s,1,this.Ev.height,e),Cs(n,-1,this.Ev.height,e)}gp(t){if(null===this.Ev)return;const e=this.up(),i=this.ap(),s=this.qv?"right":"left";e.forEach(e=>{e.Ai()&&e.gt(M(this.Li)).X(t,i,this.Fv,s)})}Mp(t){if(null===this.Ev||null===this.Li)return;const e=this.tn.$v().$t(),i=[],s=this.tn.fp(),n=e.Zc().Rn(s,this.Li);n.length&&i.push(n);const r=this.ap(),o=this.qv?"right":"left";i.forEach(e=>{e.forEach(e=>{e.gt(M(this.Li)).X(t,r,this.Fv,o)})})}kp(t){this.Kv.style.cursor=1===t?"ns-resize":"default"}fo(){const t=this.op();this.Wv<t&&this.tn.$v().$t().Kl(),this.Wv=t}_p(){return H(this.ko.fontSize,this.ko.fontFamily)}}function _s(t,e){var i,s;return null!==(s=null===(i=t.ua)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function $s(t,e){var i,s;return null!==(s=null===(i=t.Pn)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function zs(t,e){var i,s;return null!==(s=null===(i=t.Ji)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function ks(t,e){var i,s;return null!==(s=null===(i=t.aa)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}class Rs{constructor(t,i){this.Ev=e({width:0,height:0}),this.Cp=null,this.Tp=null,this.Pp=null,this.Rp=null,this.Dp=!1,this.Vp=new P,this.Op=new P,this.Bp=0,this.Ap=!1,this.Ip=null,this.zp=!1,this.Lp=null,this.Ep=null,this.jv=!1,this.Hv=()=>{this.jv||null===this.Np||this.$i().Uh()},this.Uv=()=>{this.jv||null===this.Np||this.$i().Uh()},this.Qd=t,this.Np=i,this.Np.W_().l(this.Fp.bind(this),this,!0),this.Wp=document.createElement("td"),this.Wp.style.padding="0",this.Wp.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.jp=document.createElement("td"),this.jp.style.padding="0",this.Hp=document.createElement("td"),this.Hp.style.padding="0",this.Wp.appendChild(s),this.Gv=cs(s,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const n=this.Gv.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Jv=cs(s,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const r=this.Jv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0",this.$p=document.createElement("tr"),this.$p.appendChild(this.jp),this.$p.appendChild(this.Wp),this.$p.appendChild(this.Hp),this.Up(),this.hp=new ps(this.Jv.canvasElement,this,{ev:()=>null===this.Ip&&!this.Qd.W().handleScroll.vertTouchDrag,rv:()=>null===this.Ip&&!this.Qd.W().handleScroll.horzTouchDrag})}S(){null!==this.Cp&&this.Cp.S(),null!==this.Tp&&this.Tp.S(),this.Pp=null,this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose(),null!==this.Np&&this.Np.W_().p(this),this.hp.S()}fp(){return M(this.Np)}qp(t){var e,i;null!==this.Np&&this.Np.W_().p(this),this.Np=t,null!==this.Np&&this.Np.W_().l(Rs.prototype.Fp.bind(this),this,!0),this.Up(),this.Qd.Yp().indexOf(this)===this.Qd.Yp().length-1?(this.Pp=null!==(e=this.Pp)&&void 0!==e?e:new as(this.Wp,this.Qd),this.Pp.bt()):(null===(i=this.Pp)||void 0===i||i.if(),this.Pp=null)}$v(){return this.Qd}lp(){return this.$p}Up(){if(null!==this.Np&&(this.Zp(),0!==this.$i().wt().length)){if(null!==this.Cp){const t=this.Np.R_();this.Cp.Gi(M(t))}if(null!==this.Tp){const t=this.Np.D_();this.Tp.Gi(M(t))}}}Xp(){null!==this.Cp&&this.Cp.bt(),null!==this.Tp&&this.Tp.bt()}M_(){return null!==this.Np?this.Np.M_():0}x_(t){this.Np&&this.Np.x_(t)}Qf(t){if(!this.Np)return;this.Kp();const e=t.localX,i=t.localY;this.Gp(e,i,t)}bv(t){this.Kp(),this.Jp(),this.Gp(t.localX,t.localY,t)}tv(t){var e;if(!this.Np)return;this.Kp();const i=t.localX,s=t.localY;this.Gp(i,s,t);const n=this.wr(i,s);this.Qd.Qp(null!==(e=null==n?void 0:n.Lv)&&void 0!==e?e:null),this.$i().jc(n&&{Hc:n.Hc,Iv:n.Iv})}dv(t){null!==this.Np&&(this.Kp(),this.tm(t))}qf(t){null!==this.Np&&this.im(this.Op,t)}jf(t){this.qf(t)}av(t){this.Kp(),this.nm(t),this.Gp(t.localX,t.localY,t)}cv(t){null!==this.Np&&(this.Kp(),this.Ap=!1,this.sm(t))}uv(t){null!==this.Np&&this.tm(t)}Rv(t){if(this.Ap=!0,null===this.Ip){const e={x:t.localX,y:t.localY};this.rm(e,e,t)}}Pv(t){null!==this.Np&&(this.Kp(),this.Np.$t().jc(null),this.hm())}lm(){return this.Vp}am(){return this.Op}xv(){this.Bp=1,this.$i().Un()}Sv(t,e){if(!this.Qd.W().handleScale.pinch)return;const i=5*(e-this.Bp);this.Bp=e,this.$i().Qc(t.nt,i)}pv(t){this.Ap=!1,this.zp=null!==this.Ip,this.Jp();const e=this.$i().Zc();null!==this.Ip&&e.yt()&&(this.Lp={x:e.Yt(),y:e.Zt()},this.Ip={x:t.localX,y:t.localY})}hv(t){if(null===this.Np)return;const e=t.localX,i=t.localY;if(null===this.Ip)this.nm(t);else{this.zp=!1;const s=M(this.Lp),n=s.x+(e-this.Ip.x),r=s.y+(i-this.Ip.y);this.Gp(n,r,t)}}_v(t){0===this.$v().W().trackingMode.exitMode&&(this.zp=!0),this.om(),this.sm(t)}wr(t,e){const i=this.Np;return null===i?null:function(t,e,i){const s=t.Uo(),n=function(t,e,i){var s,n;let r,o;for(const a of t){const t=null!==(n=null===(s=a.va)||void 0===s?void 0:s.call(a,e,i))&&void 0!==n?n:[];for(const e of t)h=e.zOrder,(!(l=null==r?void 0:r.zOrder)||"top"===h&&"top"!==l||"normal"===h&&"bottom"===l)&&(r=e,o=a)}var h,l;return r&&o?{zv:r,Hc:o}:null}(s,e,i);if("top"===(null==n?void 0:n.zv.zOrder))return Ss(n);for(const r of s){if(n&&n.Hc===r&&"bottom"!==n.zv.zOrder&&!n.zv.isBackground)return Ss(n);const s=xs(r.Pn(t),e,i);if(null!==s)return{Hc:r,Bv:s.Bv,Iv:s.Iv};if(n&&n.Hc===r&&"bottom"!==n.zv.zOrder&&n.zv.isBackground)return Ss(n)}return(null==n?void 0:n.zv)?Ss(n):null}(i,t,e)}_m(t,i){M("left"===i?this.Cp:this.Tp).cp(e({width:t,height:this.Ev.height}))}um(){return this.Ev}cp(t){i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Wp.style.width=t.width+"px",this.Wp.style.height=t.height+"px")}dm(){const t=M(this.Np);t.P_(t.R_()),t.P_(t.D_());for(const e of t.Ba())if(t.vr(e)){const i=e.Dt();null!==i&&t.P_(i),e.Vn()}}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}vp(t){if(0===t)return;if(null===this.Np)return;if(t>1&&this.dm(),null!==this.Cp&&this.Cp.vp(t),null!==this.Tp&&this.Tp.vp(t),1!==t){this.Gv.applySuggestedBitmapSize();const t=h(this.Gv);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mp(t)}),this.Np&&(this.fm(t,_s),this.vm(t),this.pm(t),this.fm(t,$s),this.fm(t,zs)))}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.bm(e),this.fm(e,ks))}wm(){return this.Cp}gm(){return this.Tp}bp(t,e){this.fm(t,e)}Fp(){null!==this.Np&&this.Np.W_().p(this),this.Np=null}tm(t){this.im(this.Vp,t)}im(t,e){const i=e.localX,s=e.localY;t.M()&&t.m(this.$i().St().Nu(i),{x:i,y:s},e)}mp({context:t,bitmapSize:e}){const{width:i,height:s}=e,n=this.$i(),r=n.q(),o=n.bd();r===o?it(t,0,0,i,s,o):rt(t,0,0,i,s,r,o)}vm(t){const e=M(this.Np).j_().qh().gt();null!==e&&e.X(t,!1)}pm(t){const e=this.$i().Yc();this.Mm(t,$s,ds,e),this.Mm(t,$s,fs,e)}bm(t){this.Mm(t,$s,fs,this.$i().Zc())}fm(t,e){const i=M(this.Np).Uo();for(const s of i)this.Mm(t,e,ds,s);for(const s of i)this.Mm(t,e,fs,s)}Mm(t,e,i,s){const n=M(this.Np),r=n.$t().Wc(),o=null!==r&&r.Hc===s,h=null!==r&&o&&void 0!==r.Iv?r.Iv.Mr:void 0;ms(e,e=>i(e,t,o,h),s,n)}Zp(){if(null===this.Np)return;const t=this.Qd,e=this.Np.R_().W().visible,i=this.Np.D_().W().visible;e||null===this.Cp||(this.jp.removeChild(this.Cp.lp()),this.Cp.S(),this.Cp=null),i||null===this.Tp||(this.Hp.removeChild(this.Tp.lp()),this.Tp.S(),this.Tp=null);const s=t.$t().ud();e&&null===this.Cp&&(this.Cp=new Es(this,t.W(),s,"left"),this.jp.appendChild(this.Cp.lp())),i&&null===this.Tp&&(this.Tp=new Es(this,t.W(),s,"right"),this.Hp.appendChild(this.Tp.lp()))}xm(t){return t.Dv&&this.Ap||null!==this.Ip}Sm(t){return Math.max(0,Math.min(t,this.Ev.width-1))}km(t){return Math.max(0,Math.min(t,this.Ev.height-1))}Gp(t,e,i){this.$i().ld(this.Sm(t),this.km(e),i,M(this.Np))}hm(){this.$i().od()}om(){this.zp&&(this.Ip=null,this.hm())}rm(t,e,i){this.Ip=t,this.zp=!1,this.Gp(e.x,e.y,i);const s=this.$i().Zc();this.Lp={x:s.Yt(),y:s.Zt()}}$i(){return this.Qd.$t()}sm(t){if(!this.Dp)return;const e=this.$i(),i=this.fp();if(e.z_(i,i.vn()),this.Rp=null,this.Dp=!1,e.ed(),null!==this.Ep){const t=performance.now(),i=e.St();this.Ep.Vr(i.Hu(),t),this.Ep.Qu(t)||e.Zn(this.Ep)}}Kp(){this.Ip=null}Jp(){if(this.Np){if(this.$i().Un(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)M(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Np.vn().Ni()&&this.$i().St().Ni()}}nm(t){if(null===this.Np)return;const e=this.$i(),i=e.St();if(i.Ni())return;const s=this.Qd.W(),n=s.handleScroll,r=s.kineticScroll;if((!n.pressedMouseMove||t.Dv)&&(!n.horzTouchDrag&&!n.vertTouchDrag||!t.Dv))return;const o=this.Np.vn(),h=performance.now();if(null!==this.Rp||this.xm(t)||(this.Rp={x:t.clientX,y:t.clientY,Od:h,ym:t.localX,Cm:t.localY}),null!==this.Rp&&!this.Dp&&(this.Rp.x!==t.clientX||this.Rp.y!==t.clientY)){if(t.Dv&&r.touch||!t.Dv&&r.mouse){const t=i.le();this.Ep=new ls(.2/t,7/t,.997,15/t),this.Ep.Yd(i.Hu(),this.Rp.Od)}else this.Ep=null;o.Ni()||e.A_(this.Np,o,t.localY),e.nd(t.localX),this.Dp=!0}this.Dp&&(o.Ni()||e.I_(this.Np,o,t.localY),e.sd(t.localX),null!==this.Ep&&this.Ep.Yd(i.Hu(),h))}}class Ls{constructor(t,i,s,n,r){this.ft=!0,this.Ev=e({width:0,height:0}),this.Hv=()=>this.vp(3),this.qv="left"===t,this.Oc=s.ud,this.cn=i,this.Tm=n,this.Pm=r,this.Kv=document.createElement("div"),this.Kv.style.width="25px",this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Gv=cs(this.Kv,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv)}S(){this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Kv}um(){return this.Ev}cp(t){i(this.Ev,t)||(this.Ev=t,this.Gv.resizeCanvasElement(t),this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.ft=!0)}vp(t){if(t<3&&!this.ft)return;if(0===this.Ev.width||0===this.Ev.height)return;this.ft=!1,this.Gv.applySuggestedBitmapSize();const e=h(this.Gv);null!==e&&e.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t)})}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(!this.Tm())return;t.fillStyle=this.cn.timeScale.borderColor;const n=Math.floor(this.Oc.W().C*i),r=Math.floor(this.Oc.W().C*s),o=this.qv?e.width-n:0;t.fillRect(o,0,n,r)}mp({context:t,bitmapSize:e}){it(t,0,0,e.width,e.height,this.Pm())}}function Ts(t){return e=>{var i,s;return null!==(s=null===(i=e.fa)||void 0===i?void 0:i.call(e,t))&&void 0!==s?s:[]}}const Ns=Ts("normal"),Os=Ts("top"),Ps=Ts("bottom");class Fs{constructor(t,i){this.Rm=null,this.Dm=null,this.k=null,this.Vm=!1,this.Ev=e({width:0,height:0}),this.Om=new P,this.Fv=new oe(5),this.jv=!1,this.Hv=()=>{this.jv||this.Qd.$t().Uh()},this.Uv=()=>{this.jv||this.Qd.$t().Uh()},this.Qd=t,this.q_=i,this.cn=t.W().layout,this.Xd=document.createElement("tr"),this.Bm=document.createElement("td"),this.Bm.style.padding="0",this.Am=document.createElement("td"),this.Am.style.padding="0",this.Kv=document.createElement("td"),this.Kv.style.height="25px",this.Kv.style.padding="0",this.Im=document.createElement("div"),this.Im.style.width="100%",this.Im.style.height="100%",this.Im.style.position="relative",this.Im.style.overflow="hidden",this.Kv.appendChild(this.Im),this.Gv=cs(this.Im,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const s=this.Gv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Jv=cs(this.Im,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const n=this.Jv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Xd.appendChild(this.Bm),this.Xd.appendChild(this.Kv),this.Xd.appendChild(this.Am),this.zm(),this.Qd.$t().g_().l(this.zm.bind(this),this),this.hp=new ps(this.Jv.canvasElement,this,{ev:()=>!0,rv:()=>!this.Qd.W().handleScroll.horzTouchDrag})}S(){this.hp.S(),null!==this.Rm&&this.Rm.S(),null!==this.Dm&&this.Dm.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Xd}Lm(){return this.Rm}Em(){return this.Dm}bv(t){if(this.Vm)return;this.Vm=!0;const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.Jc(t.localX)}pv(t){this.bv(t)}wv(){const t=this.Qd.$t();!t.St().Ni()&&this.Vm&&(this.Vm=!1,this.Qd.W().handleScale.axisPressedMouseMove.time&&t.hd())}av(t){const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.rd(t.localX)}hv(t){this.av(t)}cv(){this.Vm=!1;const t=this.Qd.$t();t.St().Ni()&&!this.Qd.W().handleScale.axisPressedMouseMove.time||t.hd()}_v(){this.cv()}qf(){this.Qd.W().handleScale.axisDoubleClickReset.time&&this.Qd.$t().Kn()}jf(){this.qf()}Qf(){this.Qd.$t().W().handleScale.axisPressedMouseMove.time&&this.kp(1)}Pv(){this.kp(0)}um(){return this.Ev}Nm(){return this.Om}Fm(t,s,n){i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.Om.m(t)),null!==this.Rm&&this.Rm.cp(e({width:s,height:t.height})),null!==this.Dm&&this.Dm.cp(e({width:n,height:t.height}))}Wm(){const t=this.jm();return Math.ceil(t.C+t.T+t.P+t.L+t.B+t.Hm)}bt(){this.Qd.$t().St().Ha()}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}vp(t){if(0===t)return;if(1!==t){this.Gv.applySuggestedBitmapSize();const e=h(this.Gv);null!==e&&(e.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t),this.$m(e,Ps)}),this.wp(e),this.$m(e,Ns)),null!==this.Rm&&this.Rm.vp(t),null!==this.Dm&&this.Dm.vp(t)}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.Um([...this.Qd.$t().wt(),this.Qd.$t().Zc()],e),this.$m(e,Os))}$m(t,e){const i=this.Qd.$t().wt();for(const s of i)ms(e,e=>ds(e,t,!1,void 0),s,void 0);for(const s of i)ms(e,e=>fs(e,t,!1,void 0),s,void 0)}mp({context:t,bitmapSize:e}){it(t,0,0,e.width,e.height,this.Qd.$t().bd())}Ie({context:t,bitmapSize:e,verticalPixelRatio:i}){if(this.Qd.W().timeScale.borderVisible){t.fillStyle=this.qm();const s=Math.max(1,Math.floor(this.jm().C*i));t.fillRect(0,0,e.width,s)}}wp(t){const e=this.Qd.$t().St(),i=e.Ha();if(!i||0===i.length)return;const s=this.q_.maxTickMarkWeight(i),n=this.jm(),r=e.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:e,verticalPixelRatio:s})=>{t.strokeStyle=this.qm(),t.fillStyle=this.qm();const r=Math.max(1,Math.floor(e)),o=Math.floor(.5*e);t.beginPath();const h=Math.round(n.T*s);for(let s=i.length;s--;){const n=Math.round(i[s].coord*e);t.rect(n-o,0,r,h)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const e=n.C+n.T+n.L+n.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.$(),t.font=this._p();for(const n of i)if(n.weight<s){const i=n.needAlignCoordinate?this.Ym(t,n.coord,n.label):n.coord;t.fillText(n.label,i,e)}this.Qd.W().timeScale.allowBoldLabels&&(t.font=this.Zm());for(const n of i)if(n.weight>=s){const i=n.needAlignCoordinate?this.Ym(t,n.coord,n.label):n.coord;t.fillText(n.label,i,e)}})}Ym(t,e,i){const s=this.Fv.xi(t,i),n=s/2,r=Math.floor(e-n)+.5;return r<0?e+=Math.abs(0-r):r+s>this.Ev.width&&(e-=Math.abs(this.Ev.width-(r+s))),e}Um(t,e){const i=this.jm();for(const s of t)for(const t of s.Qi())t.gt().X(e,i)}qm(){return this.Qd.W().timeScale.borderColor}$(){return this.cn.textColor}j(){return this.cn.fontSize}_p(){return H(this.j(),this.cn.fontFamily)}Zm(){return H(this.j(),this.cn.fontFamily,"bold")}jm(){null===this.k&&(this.k={C:1,N:NaN,L:NaN,B:NaN,ji:NaN,T:5,P:NaN,R:"",Wi:new oe,Hm:0});const t=this.k,e=this._p();if(t.R!==e){const i=this.j();t.P=i,t.R=e,t.L=3*i/12,t.B=3*i/12,t.ji=9*i/12,t.N=0,t.Hm=4*i/12,t.Wi.nr()}return this.k}kp(t){this.Kv.style.cursor=1===t?"ew-resize":"default"}zm(){const t=this.Qd.$t(),e=t.W();e.leftPriceScale.visible||null===this.Rm||(this.Bm.removeChild(this.Rm.lp()),this.Rm.S(),this.Rm=null),e.rightPriceScale.visible||null===this.Dm||(this.Am.removeChild(this.Dm.lp()),this.Dm.S(),this.Dm=null);const i={ud:this.Qd.$t().ud()},s=()=>e.leftPriceScale.borderVisible&&t.St().W().borderVisible,n=()=>t.bd();e.leftPriceScale.visible&&null===this.Rm&&(this.Rm=new Ls("left",e,i,s,n),this.Bm.appendChild(this.Rm.lp())),e.rightPriceScale.visible&&null===this.Dm&&(this.Dm=new Ls("right",e,i,s,n),this.Am.appendChild(this.Dm.lp()))}}const Vs=!!is&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!is&&((null===(Ds=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===Ds?void 0:Ds.platform)?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);var Ds;class Is{constructor(t,e,i){var s;this.Xm=[],this.Km=0,this.ho=0,this.__=0,this.Gm=0,this.Jm=0,this.Qm=null,this.tb=!1,this.Vp=new P,this.Op=new P,this.Rc=new P,this.ib=null,this.nb=null,this.Jd=t,this.cn=e,this.q_=i,this.Xd=document.createElement("div"),this.Xd.classList.add("tv-lightweight-charts"),this.Xd.style.overflow="hidden",this.Xd.style.direction="ltr",this.Xd.style.width="100%",this.Xd.style.height="100%",(s=this.Xd).style.userSelect="none",s.style.webkitUserSelect="none",s.style.msUserSelect="none",s.style.MozUserSelect="none",s.style.webkitTapHighlightColor="transparent",this.sb=document.createElement("table"),this.sb.setAttribute("cellspacing","0"),this.Xd.appendChild(this.sb),this.eb=this.rb.bind(this),Bs(this.cn)&&this.hb(!0),this.$i=new Ii(this.Vc.bind(this),this.cn,i),this.$t().Xc().l(this.lb.bind(this),this),this.ab=new Fs(this,this.q_),this.sb.appendChild(this.ab.lp());const n=e.autoSize&&this.ob();let r=this.cn.width,o=this.cn.height;if(n||0===r||0===o){const e=t.getBoundingClientRect();r=r||e.width,o=o||e.height}this._b(r,o),this.ub(),t.appendChild(this.Xd),this.cb(),this.$i.St().ec().l(this.$i.Kl.bind(this.$i),this),this.$i.g_().l(this.$i.Kl.bind(this.$i),this)}$t(){return this.$i}W(){return this.cn}Yp(){return this.Xm}fb(){return this.ab}S(){this.hb(!1),0!==this.Km&&window.cancelAnimationFrame(this.Km),this.$i.Xc().p(this),this.$i.St().ec().p(this),this.$i.g_().p(this),this.$i.S();for(const t of this.Xm)this.sb.removeChild(t.lp()),t.lm().p(this),t.am().p(this),t.S();this.Xm=[],M(this.ab).S(),null!==this.Xd.parentElement&&this.Xd.parentElement.removeChild(this.Xd),this.Rc.S(),this.Vp.S(),this.Op.S(),this.pb()}_b(t,i,s=!1){if(this.ho===i&&this.__===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return e({width:i-i%2,height:s-s%2})}(e({width:t,height:i}));this.ho=n.height,this.__=n.width;const r=this.ho+"px",o=this.__+"px";M(this.Xd).style.height=r,M(this.Xd).style.width=o,this.sb.style.height=r,this.sb.style.width=o,s?this.mb(gt.es(),performance.now()):this.$i.Kl()}vp(t){void 0===t&&(t=gt.es());for(let e=0;e<this.Xm.length;e++)this.Xm[e].vp(t.Hn(e).Fn);this.cn.timeScale.visible&&this.ab.vp(t.jn())}$h(t){const e=Bs(this.cn);this.$i.$h(t);const i=Bs(this.cn);i!==e&&this.hb(i),this.cb(),this.bb(t)}lm(){return this.Vp}am(){return this.Op}Xc(){return this.Rc}wb(){null!==this.Qm&&(this.mb(this.Qm,performance.now()),this.Qm=null);const t=this.gb(null),e=document.createElement("canvas");e.width=t.width,e.height=t.height;const i=M(e.getContext("2d"));return this.gb(i),e}Mb(t){return("left"!==t||this.xb())&&("right"!==t||this.Sb())?0===this.Xm.length?0:M("left"===t?this.Xm[0].wm():this.Xm[0].gm()).dp():0}kb(){return this.cn.autoSize&&null!==this.ib}yb(){return this.Xd}Qp(t){this.nb=t,this.nb?this.yb().style.setProperty("cursor",t):this.yb().style.removeProperty("cursor")}Cb(){return this.nb}Tb(){return x(this.Xm[0]).um()}bb(t){(void 0!==t.autoSize||!this.ib||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.ib&&this.ob(),!1===t.autoSize&&null!==this.ib&&this.pb(),t.autoSize||void 0===t.width&&void 0===t.height||this._b(t.width||this.__,t.height||this.ho))}gb(t){let i=0,s=0;const n=this.Xm[0],r=(e,i)=>{let s=0;for(let n=0;n<this.Xm.length;n++){const r=this.Xm[n],o=M("left"===e?r.wm():r.gm()),h=o.xp();null!==t&&o.Sp(t,i,s),s+=h.height}};this.xb()&&(r("left",0),i+=M(n.wm()).xp().width);for(let e=0;e<this.Xm.length;e++){const n=this.Xm[e],r=n.xp();null!==t&&n.Sp(t,i,s),s+=r.height}i+=n.xp().width,this.Sb()&&(r("right",i),i+=M(n.gm()).xp().width);const o=(e,i,s)=>{M("left"===e?this.ab.Lm():this.ab.Em()).Sp(M(t),i,s)};if(this.cn.timeScale.visible){const e=this.ab.xp();if(null!==t){let i=0;this.xb()&&(o("left",i,s),i=M(n.wm()).xp().width),this.ab.Sp(t,i,s),i+=e.width,this.Sb()&&o("right",i,s)}s+=e.height}return e({width:i,height:s})}Pb(){let t=0,i=0,s=0;for(const e of this.Xm)this.xb()&&(i=Math.max(i,M(e.wm()).op(),this.cn.leftPriceScale.minimumWidth)),this.Sb()&&(s=Math.max(s,M(e.gm()).op(),this.cn.rightPriceScale.minimumWidth)),t+=e.M_();i=rs(i),s=rs(s);const n=this.__,r=this.ho,o=Math.max(n-i-s,0),h=this.cn.timeScale.visible;let l=h?Math.max(this.ab.Wm(),this.cn.timeScale.minimumHeight):0;var a;l=(a=l)+a%2;const c=0+l,u=r<c?0:r-c,d=u/t;let f=0;for(let t=0;t<this.Xm.length;++t){const n=this.Xm[t];n.qp(this.$i.qc()[t]);let r=0,h=0;h=t===this.Xm.length-1?u-f:Math.round(n.M_()*d),r=Math.max(h,2),f+=r,n.cp(e({width:o,height:r})),this.xb()&&n._m(i,"left"),this.Sb()&&n._m(s,"right"),n.fp()&&this.$i.Kc(n.fp(),r)}this.ab.Fm(e({width:h?o:0,height:l}),h?i:0,h?s:0),this.$i.S_(o),this.Gm!==i&&(this.Gm=i),this.Jm!==s&&(this.Jm=s)}hb(t){t?this.Xd.addEventListener("wheel",this.eb,{passive:!1}):this.Xd.removeEventListener("wheel",this.eb)}Rb(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return Vs?1/window.devicePixelRatio:1}rb(t){if(!(0!==t.deltaX&&this.cn.handleScroll.mouseWheel||0!==t.deltaY&&this.cn.handleScale.mouseWheel))return;const e=this.Rb(t),i=e*t.deltaX/100,s=-e*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==s&&this.cn.handleScale.mouseWheel){const e=Math.sign(s)*Math.min(1,Math.abs(s)),i=t.clientX-this.Xd.getBoundingClientRect().left;this.$t().Qc(i,e)}0!==i&&this.cn.handleScroll.mouseWheel&&this.$t().td(-80*i)}mb(t,e){var i;const s=t.jn();3===s&&this.Db(),3!==s&&2!==s||(this.Vb(t),this.Ob(t,e),this.ab.bt(),this.Xm.forEach(t=>{t.Xp()}),3===(null===(i=this.Qm)||void 0===i?void 0:i.jn())&&(this.Qm.ts(t),this.Db(),this.Vb(this.Qm),this.Ob(this.Qm,e),t=this.Qm,this.Qm=null)),this.vp(t)}Ob(t,e){for(const i of t.Qn())this.ns(i,e)}Vb(t){const e=this.$i.qc();for(let i=0;i<e.length;i++)t.Hn(i).Wn&&e[i].N_()}ns(t,e){const i=this.$i.St();switch(t.qn){case 0:i.hc();break;case 1:i.lc(t.Vt);break;case 2:i.Gn(t.Vt);break;case 3:i.Jn(t.Vt);break;case 4:i.qu();break;case 5:t.Vt.Qu(e)||i.Jn(t.Vt.tc(e))}}Vc(t){null!==this.Qm?this.Qm.ts(t):this.Qm=t,this.tb||(this.tb=!0,this.Km=window.requestAnimationFrame(t=>{if(this.tb=!1,this.Km=0,null!==this.Qm){const e=this.Qm;this.Qm=null,this.mb(e,t);for(const i of e.Qn())if(5===i.qn&&!i.Vt.Qu(t)){this.$t().Zn(i.Vt);break}}}))}Db(){this.ub()}ub(){const t=this.$i.qc(),e=t.length,i=this.Xm.length;for(let t=e;t<i;t++){const t=x(this.Xm.pop());this.sb.removeChild(t.lp()),t.lm().p(this),t.am().p(this),t.S()}for(let s=i;s<e;s++){const e=new Rs(this,t[s]);e.lm().l(this.Bb.bind(this),this),e.am().l(this.Ab.bind(this),this),this.Xm.push(e),this.sb.insertBefore(e.lp(),this.ab.lp())}for(let i=0;i<e;i++){const e=t[i],s=this.Xm[i];s.fp()!==e?s.qp(e):s.Up()}this.cb(),this.Pb()}Ib(t,e,i){var s;const n=new Map;let r;if(null!==t&&this.$i.wt().forEach(e=>{const i=e.In().ll(t);null!==i&&n.set(e,i)}),null!==t){const e=null===(s=this.$i.St().Ui(t))||void 0===s?void 0:s.originalTime;void 0!==e&&(r=e)}const o=this.$t().Wc(),h=null!==o&&o.Hc instanceof ti?o.Hc:void 0,l=null!==o&&void 0!==o.Iv?o.Iv.gr:void 0;return{zb:r,ee:null!=t?t:void 0,Lb:null!=e?e:void 0,Eb:h,Nb:n,Fb:l,Wb:null!=i?i:void 0}}Bb(t,e,i){this.Vp.m(()=>this.Ib(t,e,i))}Ab(t,e,i){this.Op.m(()=>this.Ib(t,e,i))}lb(t,e,i){this.Rc.m(()=>this.Ib(t,e,i))}cb(){const t=this.cn.timeScale.visible?"":"none";this.ab.lp().style.display=t}xb(){return this.Xm[0].fp().R_().W().visible}Sb(){return this.Xm[0].fp().D_().W().visible}ob(){return"ResizeObserver"in window&&(this.ib=new ResizeObserver(t=>{const e=t.find(t=>t.target===this.Jd);e&&this._b(e.contentRect.width,e.contentRect.height)}),this.ib.observe(this.Jd,{box:"border-box"}),!0)}pb(){null!==this.ib&&this.ib.disconnect(),this.ib=null}}function Bs(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function As(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}function Ws(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.color&&(r.V=i.color),r}function js(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.lineColor&&(r.lt=i.lineColor),void 0!==i.topColor&&(r.Ps=i.topColor),void 0!==i.bottomColor&&(r.Rs=i.bottomColor),r}function Us(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.topLineColor&&(r.Re=i.topLineColor),void 0!==i.bottomLineColor&&(r.De=i.bottomLineColor),void 0!==i.topFillColor1&&(r.ke=i.topFillColor1),void 0!==i.topFillColor2&&(r.ye=i.topFillColor2),void 0!==i.bottomFillColor1&&(r.Ce=i.bottomFillColor1),void 0!==i.bottomFillColor2&&(r.Te=i.bottomFillColor2),r}function Hs(t,e,i,s){const n={ee:e,ot:t,Vt:[i.open,i.high,i.low,i.close],zb:s};return void 0!==i.color&&(n.V=i.color),n}function Ks(t,e,i,s){const n={ee:e,ot:t,Vt:[i.open,i.high,i.low,i.close],zb:s};return void 0!==i.color&&(n.V=i.color),void 0!==i.borderColor&&(n.Ot=i.borderColor),void 0!==i.wickColor&&(n.Xh=i.wickColor),n}function qs(t,e,i,s,n){const r=x(n)(i),o=Math.max(...r),h=Math.min(...r),l=r[r.length-1],a=[l,o,h,l],c=i,{time:u,color:d}=c;return{ee:e,ot:t,Vt:a,zb:s,$e:As(c,["time","color"]),V:d}}function Xs(t){return void 0!==t.Vt}function Js(t,e){return void 0!==e.customValues&&(t.jb=e.customValues),t}function Gs(t){return(e,i,s,n,r,o)=>function(t,e){return e?e(t):void 0===(i=t).open&&void 0===i.value;var i}(s,o)?Js({ot:e,ee:i,zb:n},s):Js(t(e,i,s,n,r),s)}function Qs(t){return{Candlestick:Gs(Ks),Bar:Gs(Hs),Area:Gs(js),Baseline:Gs(Us),Histogram:Gs(Ws),Line:Gs(Ws),Custom:Gs(qs)}[t]}function Ys(t){return{ee:0,Hb:new Map,la:t}}function Zs(t,e){if(void 0!==t&&0!==t.length)return{$b:e.key(t[0].ot),Ub:e.key(t[t.length-1].ot)}}function tn(t){let e;return t.forEach(t=>{void 0===e&&(e=t.zb)}),x(e)}class en{constructor(t){this.qb=new Map,this.Yb=new Map,this.Zb=new Map,this.Xb=[],this.q_=t}S(){this.qb.clear(),this.Yb.clear(),this.Zb.clear(),this.Xb=[]}Kb(t,e){let i=0!==this.qb.size,s=!1;const n=this.Yb.get(t);if(void 0!==n)if(1===this.Yb.size)i=!1,s=!0,this.qb.clear();else for(const e of this.Xb)e.pointData.Hb.delete(t)&&(s=!0);let r=[];if(0!==e.length){const i=e.map(t=>t.time),n=this.q_.createConverterToInternalObj(e),o=Qs(t.Qh()),h=t.Ca(),l=t.Ta();r=e.map((e,r)=>{const a=n(e.time),c=this.q_.key(a);let u=this.qb.get(c);void 0===u&&(u=Ys(a),this.qb.set(c,u),s=!0);const d=o(a,u.ee,e,i[r],h,l);return u.Hb.set(t,d),d})}i&&this.Gb(),this.Jb(t,r);let o=-1;if(s){const t=[];this.qb.forEach(e=>{t.push({timeWeight:0,time:e.la,pointData:e,originalTime:tn(e.Hb)})}),t.sort((t,e)=>this.q_.key(t.time)-this.q_.key(e.time)),o=this.Qb(t)}return this.tw(t,o,function(t,e,i){const s=Zs(t,i),n=Zs(e,i);if(void 0!==s&&void 0!==n)return{ta:s.Ub>=n.Ub&&s.$b>=n.$b}}(this.Yb.get(t),n,this.q_))}vd(t){return this.Kb(t,[])}iw(t,e){const i=e;!function(t){void 0===t.zb&&(t.zb=t.time)}(i),this.q_.preprocessData(e);const s=this.q_.createConverterToInternalObj([e])(e.time),n=this.Zb.get(t);if(void 0!==n&&this.q_.key(s)<this.q_.key(n))throw new Error(`Cannot update oldest data, last time=${n}, new time=${s}`);let r=this.qb.get(this.q_.key(s));const o=void 0===r;void 0===r&&(r=Ys(s),this.qb.set(this.q_.key(s),r));const h=Qs(t.Qh()),l=t.Ca(),a=t.Ta(),c=h(s,r.ee,e,i.zb,l,a);r.Hb.set(t,c),this.nw(t,c);const u={ta:Xs(c)};if(!o)return this.tw(t,-1,u);const d={timeWeight:0,time:r.la,pointData:r,originalTime:tn(r.Hb)},f=Vt(this.Xb,this.q_.key(d.time),(t,e)=>this.q_.key(t.time)<e);this.Xb.splice(f,0,d);for(let t=f;t<this.Xb.length;++t)sn(this.Xb[t].pointData,t);return this.q_.fillWeightsForPoints(this.Xb,f),this.tw(t,f,u)}nw(t,e){let i=this.Yb.get(t);void 0===i&&(i=[],this.Yb.set(t,i));const s=0!==i.length?i[i.length-1]:null;null===s||this.q_.key(e.ot)>this.q_.key(s.ot)?Xs(e)&&i.push(e):Xs(e)?i[i.length-1]=e:i.splice(-1,1),this.Zb.set(t,e.ot)}Jb(t,e){0!==e.length?(this.Yb.set(t,e.filter(Xs)),this.Zb.set(t,e[e.length-1].ot)):(this.Yb.delete(t),this.Zb.delete(t))}Gb(){for(const t of this.Xb)0===t.pointData.Hb.size&&this.qb.delete(this.q_.key(t.time))}Qb(t){let e=-1;for(let i=0;i<this.Xb.length&&i<t.length;++i){const s=this.Xb[i],n=t[i];if(this.q_.key(s.time)!==this.q_.key(n.time)){e=i;break}n.timeWeight=s.timeWeight,sn(n.pointData,i)}if(-1===e&&this.Xb.length!==t.length&&(e=Math.min(this.Xb.length,t.length)),-1===e)return-1;for(let i=e;i<t.length;++i)sn(t[i].pointData,i);return this.q_.fillWeightsForPoints(t,e),this.Xb=t,e}sw(){if(0===this.Yb.size)return null;let t=0;return this.Yb.forEach(e=>{0!==e.length&&(t=Math.max(t,e[e.length-1].ee))}),t}tw(t,e,i){const s={ew:new Map,St:{Eu:this.sw()}};if(-1!==e)this.Yb.forEach((e,n)=>{s.ew.set(n,{$e:e,rw:n===t?i:void 0})}),this.Yb.has(t)||s.ew.set(t,{$e:[],rw:i}),s.St.hw=this.Xb,s.St.lw=e;else{const e=this.Yb.get(t);s.ew.set(t,{$e:e||[],rw:i})}return s}}function sn(t,e){t.ee=e,t.Hb.forEach(t=>{t.ee=e})}function nn(t){const e={value:t.Vt[3],time:t.zb};return void 0!==t.jb&&(e.customValues=t.jb),e}function rn(t){const e=nn(t);return void 0!==t.V&&(e.color=t.V),e}function on(t){const e=nn(t);return void 0!==t.lt&&(e.lineColor=t.lt),void 0!==t.Ps&&(e.topColor=t.Ps),void 0!==t.Rs&&(e.bottomColor=t.Rs),e}function hn(t){const e=nn(t);return void 0!==t.Re&&(e.topLineColor=t.Re),void 0!==t.De&&(e.bottomLineColor=t.De),void 0!==t.ke&&(e.topFillColor1=t.ke),void 0!==t.ye&&(e.topFillColor2=t.ye),void 0!==t.Ce&&(e.bottomFillColor1=t.Ce),void 0!==t.Te&&(e.bottomFillColor2=t.Te),e}function ln(t){const e={open:t.Vt[0],high:t.Vt[1],low:t.Vt[2],close:t.Vt[3],time:t.zb};return void 0!==t.jb&&(e.customValues=t.jb),e}function an(t){const e=ln(t);return void 0!==t.V&&(e.color=t.V),e}function cn(t){const e=ln(t),{V:i,Ot:s,Xh:n}=t;return void 0!==i&&(e.color=i),void 0!==s&&(e.borderColor=s),void 0!==n&&(e.wickColor=n),e}function un(t){return{Area:on,Line:rn,Baseline:hn,Histogram:rn,Bar:an,Candlestick:cn,Custom:dn}[t]}function dn(t){const e=t.zb;return Object.assign(Object.assign({},t.$e),{time:e})}const fn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},mn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},pn={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:U,attributionLogo:!0},gn={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0},bn={rightOffset:0,barSpacing:6,minBarSpacing:.5,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0},vn={color:"rgba(0, 0, 0, 0)",visible:!1,fontSize:48,fontFamily:U,fontStyle:"",text:"",horzAlign:"center",vertAlign:"center"};function wn(){return{width:0,height:0,autoSize:!1,layout:pn,crosshair:fn,grid:mn,overlayPriceScales:Object.assign({},gn),leftPriceScale:Object.assign(Object.assign({},gn),{visible:!1}),rightPriceScale:Object.assign(Object.assign({},gn),{visible:!0}),timeScale:bn,watermark:vn,localization:{locale:is?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class yn{constructor(t,e){this.aw=t,this.ow=e}applyOptions(t){this.aw.$t().$c(this.ow,t)}options(){return this.Li().W()}width(){return pt(this.ow)?this.aw.Mb(this.ow):0}Li(){return M(this.aw.$t().Uc(this.ow)).Dt}}function Sn(t,e,i){const s=As(t,["time","originalTime"]),n=Object.assign({time:e},s);return void 0!==i&&(n.originalTime=i),n}const xn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Mn{constructor(t){this.Nh=t}applyOptions(t){this.Nh.$h(t)}options(){return this.Nh.W()}_w(){return this.Nh}}class Cn{constructor(t,e,i,s,n){this.uw=new P,this.Es=t,this.cw=e,this.dw=i,this.q_=n,this.fw=s}S(){this.uw.S()}priceFormatter(){return this.Es.ba()}priceToCoordinate(t){const e=this.Es.Ct();return null===e?null:this.Es.Dt().Rt(t,e.Vt)}coordinateToPrice(t){const e=this.Es.Ct();return null===e?null:this.Es.Dt().pn(t,e.Vt)}barsInLogicalRange(t){if(null===t)return null;const e=new $i(new Ci(t.from,t.to)).lu(),i=this.Es.In();if(i.Ni())return null;const s=i.ll(e.Os(),1),n=i.ll(e.ui(),-1),r=M(i.el()),o=M(i.An());if(null!==s&&null!==n&&s.ee>n.ee)return{barsBefore:t.from-r,barsAfter:o-t.to};const h={barsBefore:null===s||s.ee===r?t.from-r:s.ee-r,barsAfter:null===n||n.ee===o?o-t.to:o-n.ee};return null!==s&&null!==n&&(h.from=s.zb,h.to=n.zb),h}setData(t){this.q_,this.Es.Qh(),this.cw.pw(this.Es,t),this.mw("full")}update(t){this.Es.Qh(),this.cw.bw(this.Es,t),this.mw("update")}dataByIndex(t,e){const i=this.Es.In().ll(t,e);return null===i?null:un(this.seriesType())(i)}data(){const t=un(this.seriesType());return this.Es.In().ne().map(e=>t(e))}subscribeDataChanged(t){this.uw.l(t)}unsubscribeDataChanged(t){this.uw.v(t)}setMarkers(t){this.q_;const e=t.map(t=>Sn(t,this.q_.convertHorzItemToInternal(t.time),t.time));this.Es.na(e)}markers(){return this.Es.sa().map(t=>Sn(t,t.originalTime,void 0))}applyOptions(t){this.Es.$h(t)}options(){return A(this.Es.W())}priceScale(){return this.dw.priceScale(this.Es.Dt().Pa())}createPriceLine(t){const e=F(A(xn),t),i=this.Es.ea(e);return new Mn(i)}removePriceLine(t){this.Es.ra(t._w())}seriesType(){return this.Es.Qh()}attachPrimitive(t){this.Es.ka(t),t.attached&&t.attached({chart:this.fw,series:this,requestUpdate:()=>this.Es.$t().Kl()})}detachPrimitive(t){this.Es.ya(t),t.detached&&t.detached()}mw(t){this.uw.M()&&this.uw.m(t)}}class En{constructor(t,e,i){this.ww=new P,this.mu=new P,this.Om=new P,this.$i=t,this.yl=t.St(),this.ab=e,this.yl.nc().l(this.gw.bind(this)),this.yl.sc().l(this.Mw.bind(this)),this.ab.Nm().l(this.xw.bind(this)),this.q_=i}S(){this.yl.nc().p(this),this.yl.sc().p(this),this.ab.Nm().p(this),this.ww.S(),this.mu.S(),this.Om.S()}scrollPosition(){return this.yl.Hu()}scrollToPosition(t,e){e?this.yl.Ju(t,1e3):this.$i.Jn(t)}scrollToRealTime(){this.yl.Gu()}getVisibleRange(){const t=this.yl.Vu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const e={from:this.q_.convertHorzItemToInternal(t.from),to:this.q_.convertHorzItemToInternal(t.to)},i=this.yl.Iu(e);this.$i.pd(i)}getVisibleLogicalRange(){const t=this.yl.Du();return null===t?null:{from:t.Os(),to:t.ui()}}setVisibleLogicalRange(t){S(t.from<=t.to,"The from index cannot be after the to index."),this.$i.pd(t)}resetTimeScale(){this.$i.Kn()}fitContent(){this.$i.hc()}logicalToCoordinate(t){const e=this.$i.St();return e.Ni()?null:e.It(t)}coordinateToLogical(t){return this.yl.Ni()?null:this.yl.Nu(t)}timeToCoordinate(t){const e=this.q_.convertHorzItemToInternal(t),i=this.yl.Va(e,!1);return null===i?null:this.yl.It(i)}coordinateToTime(t){const e=this.$i.St(),i=e.Nu(t),s=e.Ui(i);return null===s?null:s.originalTime}width(){return this.ab.um().width}height(){return this.ab.um().height}subscribeVisibleTimeRangeChange(t){this.ww.l(t)}unsubscribeVisibleTimeRangeChange(t){this.ww.v(t)}subscribeVisibleLogicalRangeChange(t){this.mu.l(t)}unsubscribeVisibleLogicalRangeChange(t){this.mu.v(t)}subscribeSizeChange(t){this.Om.l(t)}unsubscribeSizeChange(t){this.Om.v(t)}applyOptions(t){this.yl.$h(t)}options(){return Object.assign(Object.assign({},A(this.yl.W())),{barSpacing:this.yl.le()})}gw(){this.ww.M()&&this.ww.m(this.getVisibleRange())}Mw(){this.mu.M()&&this.mu.m(this.getVisibleLogicalRange())}xw(t){this.Om.m(t.width,t.height)}}function _n(t){return function(t){if(B(t.handleScale)){const e=t.handleScale;t.handleScale={axisDoubleClickReset:{time:e,price:e},axisPressedMouseMove:{time:e,price:e},mouseWheel:e,pinch:e}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:e,axisDoubleClickReset:i}=t.handleScale;B(e)&&(t.handleScale.axisPressedMouseMove={time:e,price:e}),B(i)&&(t.handleScale.axisDoubleClickReset={time:i,price:i})}const e=t.handleScroll;B(e)&&(t.handleScroll={horzTouchDrag:e,vertTouchDrag:e,mouseWheel:e,pressedMouseMove:e})}(t),t}class $n{constructor(t,e,i){this.Sw=new Map,this.kw=new Map,this.yw=new P,this.Cw=new P,this.Tw=new P,this.Pw=new en(e);const s=void 0===i?A(wn()):F(A(wn()),_n(i));this.q_=e,this.aw=new Is(t,s,e),this.aw.lm().l(t=>{this.yw.M()&&this.yw.m(this.Rw(t()))},this),this.aw.am().l(t=>{this.Cw.M()&&this.Cw.m(this.Rw(t()))},this),this.aw.Xc().l(t=>{this.Tw.M()&&this.Tw.m(this.Rw(t()))},this);const n=this.aw.$t();this.Dw=new En(n,this.aw.fb(),this.q_)}remove(){this.aw.lm().p(this),this.aw.am().p(this),this.aw.Xc().p(this),this.Dw.S(),this.aw.S(),this.Sw.clear(),this.kw.clear(),this.yw.S(),this.Cw.S(),this.Tw.S(),this.Pw.S()}resize(t,e,i){this.autoSizeActive()||this.aw._b(t,e,i)}addCustomSeries(t,e){const i=C(t),s=Object.assign(Object.assign({},m),i.defaultOptions());return this.Vw("Custom",s,e,i)}addAreaSeries(t){return this.Vw("Area",u,t)}addBaselineSeries(t){return this.Vw("Baseline",d,t)}addBarSeries(t){return this.Vw("Bar",a,t)}addCandlestickSeries(t={}){return function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(t),this.Vw("Candlestick",l,t)}addHistogramSeries(t){return this.Vw("Histogram",f,t)}addLineSeries(t){return this.Vw("Line",c,t)}removeSeries(t){const e=x(this.Sw.get(t)),i=this.Pw.vd(e);this.aw.$t().vd(e),this.Ow(i),this.Sw.delete(t),this.kw.delete(e)}pw(t,e){this.Ow(this.Pw.Kb(t,e))}bw(t,e){this.Ow(this.Pw.iw(t,e))}subscribeClick(t){this.yw.l(t)}unsubscribeClick(t){this.yw.v(t)}subscribeCrosshairMove(t){this.Tw.l(t)}unsubscribeCrosshairMove(t){this.Tw.v(t)}subscribeDblClick(t){this.Cw.l(t)}unsubscribeDblClick(t){this.Cw.v(t)}priceScale(t){return new yn(this.aw,t)}timeScale(){return this.Dw}applyOptions(t){this.aw.$h(_n(t))}options(){return this.aw.W()}takeScreenshot(){return this.aw.wb()}autoSizeActive(){return this.aw.kb()}chartElement(){return this.aw.yb()}paneSize(){const t=this.aw.Tb();return{height:t.height,width:t.width}}setCrosshairPosition(t,e,i){const s=this.Sw.get(i);if(void 0===s)return;const n=this.aw.$t().dr(s);null!==n&&this.aw.$t().ad(t,e,n)}clearCrosshairPosition(){this.aw.$t().od(!0)}Vw(t,e,i={},s){!function(t){if(void 0===t||"custom"===t.type)return;const e=t;void 0!==e.minMove&&void 0===e.precision&&(e.precision=function(t){if(t>=1)return 0;let e=0;for(;e<8;e++){const i=Math.round(t);if(Math.abs(i-t)<1e-8)return e;t*=10}return e}(e.minMove))}(i.priceFormat);const n=F(A(p),A(e),i),r=this.aw.$t().dd(t,n,s),o=new Cn(r,this,this,this,this.q_);return this.Sw.set(o,r),this.kw.set(r,o),o}Ow(t){const e=this.aw.$t();e._d(t.St.Eu,t.St.hw,t.St.lw),t.ew.forEach((t,e)=>e.J(t.$e,t.rw)),e.Wu()}Bw(t){return x(this.kw.get(t))}Rw(t){const e=new Map;t.Nb.forEach((t,i)=>{const s=i.Qh(),n=un(s)(t);if("Custom"!==s)S(function(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}(n));else{const t=i.Ta();S(!t||!1===t(n))}e.set(this.Bw(i),n)});const i=void 0!==t.Eb&&this.kw.has(t.Eb)?this.Bw(t.Eb):void 0;return{time:t.zb,logical:t.ee,point:t.Lb,hoveredSeries:i,hoveredObjectId:t.Fb,seriesData:e,sourceEvent:t.Wb}}}function zn(t,e){return function(t,e,i){let s;if(I(t)){const e=document.getElementById(t);S(null!==e,`Cannot find element in DOM with id=${t}`),s=e}else s=t;const n=new $n(s,e,i);return e.setOptions(n.options()),n}(t,new es,es.Id(e))}Object.assign(Object.assign({},p),m);const kn=e=>{const[i]=t.useState(e||null),[s,n]=t.useState(!1),[r,o]=t.useState(!1);t.useEffect(()=>{if(!i)return n(!1),void o(!1);o(!0);const t=()=>{console.log("✅ [useSocket] Connected to Socket.IO server"),n(!0),o(!1)},e=()=>{console.log("🔌 [useSocket] Disconnected from Socket.IO server"),n(!1),o(!1)},s=t=>{console.error("❌ [useSocket] Connection error:",t),o(!1)};return i.connected&&(n(!0),o(!1)),i.on("connect",t),i.on("disconnect",e),i.on("connect_error",s),()=>{i.off("connect",t),i.off("disconnect",e),i.off("connect_error",s)}},[i]);const h=t.useCallback(()=>{console.log("🔍 [useSocket] Connect called - connection managed by provider")},[]),l=t.useCallback(()=>{console.log("🔍 [useSocket] Disconnect called - connection managed by provider")},[]),a=t.useCallback((t,e=60,s,n,r)=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot subscribe"),!1;try{return i.emit("ohlcv:subscribe",{mint:t,timeFrame:e}),s&&i.on("ohlcv:initial",s),n&&i.on("ohlcv:update",n),r&&i.on("ohlcv:newCandle",r),console.log(`📊 [useSocket] Subscribed to OHLCV updates for ${t} (${e}s)`),!0}catch(t){return console.error("❌ [useSocket] Failed to subscribe to OHLCV:",t),!1}},[i]),c=t.useCallback((t,e=60,s,n,r)=>{if(!i?.connected)return!1;try{return i.emit("ohlcv:unsubscribe",{mint:t,timeFrame:e}),s&&i.off("ohlcv:initial",s),n&&i.off("ohlcv:update",n),r&&i.off("ohlcv:newCandle",r),console.log(`📊 [useSocket] Unsubscribed from OHLCV updates for ${t} (${e}s)`),!0}catch(t){return console.error("❌ [useSocket] Failed to unsubscribe from OHLCV:",t),!1}},[i]),u=t.useCallback((t,e)=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot subscribe"),!1;try{return i.emit("price:subscribe",{mint:t}),e&&i.on("price:update",e),console.log(`💰 [useSocket] Subscribed to price updates for ${t}`),!0}catch(t){return console.error("❌ [useSocket] Failed to subscribe to price:",t),!1}},[i]),d=t.useCallback((t,e)=>{if(!i?.connected)return!1;try{return i.emit("price:unsubscribe",{mint:t}),e&&i.off("price:update",e),console.log(`💰 [useSocket] Unsubscribed from price updates for ${t}`),!0}catch(t){return console.error("❌ [useSocket] Failed to unsubscribe from price:",t),!1}},[i]),f=t.useCallback(t=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot send test message"),!1;try{return i.emit("test-message",{message:t,timestamp:Date.now()}),i.once("test-response",t=>{console.log("🧪 [useSocket] Test response received:",t)}),!0}catch(t){return console.error("❌ [useSocket] Failed to send test message:",t),!1}},[i]);return{socket:i,isConnected:s,isConnecting:r,connect:h,disconnect:l,subscribeToOHLCV:a,unsubscribeFromOHLCV:c,subscribeToPrice:u,unsubscribeFromPrice:d,testConnection:f}};function Rn(e,i){const[s,n]=t.useState(null),[r,o]=t.useState(!1),[h,l]=t.useState(null),[a,c]=t.useState(null),[u,d]=t.useState(!1);t.useEffect(()=>{i&&(n(i),c(Date.now()),d(!0),o(!1))},[i]);const f=t.useMemo(()=>{if(!s||!s.market)return{currentPrice:0,currentMarketCap:0,currentVolume:0,performance24h:{value:"0.00%",isPositive:!1,raw:0},performance7d:{value:"0.00%",isPositive:!1,raw:0},performance1m:{value:"0.00%",isPositive:!1,raw:0},performanceAllTime:{value:"0.00%",isPositive:!1,raw:0},high24h:0,low24h:0,volume24h:0,return24h:0};const t=parseFloat(s.market?.price||"0")||0,e=parseFloat(s.market?.marketCap||"0")||0;let i=parseFloat(s.volume?.current||"0")||0;i<=.01&&(i=parseFloat(s.blockchain?.currentRealSol||"0")||0);const n={value:s.performance?.["24H"]?.percentage||"0.00%",isPositive:s.performance?.["24H"]?.isPositive||!1,raw:s.performance?.["24H"]?.gain||0},r={value:s.performance?.["7D"]?.percentage||"0.00%",isPositive:s.performance?.["7D"]?.isPositive||!1,raw:s.performance?.["7D"]?.gain||0},o={value:s.performance?.["1M"]?.percentage||"0.00%",isPositive:s.performance?.["1M"]?.isPositive||!1,raw:s.performance?.["1M"]?.gain||0},h={value:s.performance?.["All Time"]?.percentage||"0.00%",isPositive:s.performance?.["All Time"]?.isPositive||!1,raw:s.performance?.["All Time"]?.gain||0},l=parseFloat(s["24H"]?.high||"0")||0,a=parseFloat(s["24H"]?.low||"0")||0;let c=parseFloat(s.volume?.["24h"]||"0")||0;c<=.01&&(c=parseFloat(s.blockchain?.currentRealSol||"0")||0);return{currentPrice:t,currentMarketCap:e,currentVolume:i,performance24h:n,performance7d:r,performance1m:o,performanceAllTime:h,high24h:l,low24h:a,volume24h:c,return24h:parseFloat(s["24H"]?.return||"0")||0}},[s]),m=t.useCallback(t=>t>.01,[]);return{analytics:s,...f,isRealVolume:m,loading:r,error:h,connected:u,lastUpdate:a}}function Ln(t,e){return function(){return t.apply(e,arguments)}}const{toString:Tn}=Object.prototype,{getPrototypeOf:Nn}=Object,{iterator:On,toStringTag:Pn}=Symbol,Fn=(Vn=Object.create(null),t=>{const e=Tn.call(t);return Vn[e]||(Vn[e]=e.slice(8,-1).toLowerCase())});var Vn;const Dn=t=>(t=t.toLowerCase(),e=>Fn(e)===t),In=t=>e=>typeof e===t,{isArray:Bn}=Array,An=In("undefined");function Wn(t){return null!==t&&!An(t)&&null!==t.constructor&&!An(t.constructor)&&Hn(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const jn=Dn("ArrayBuffer");const Un=In("string"),Hn=In("function"),Kn=In("number"),qn=t=>null!==t&&"object"==typeof t,Xn=t=>{if("object"!==Fn(t))return!1;const e=Nn(t);return!(null!==e&&e!==Object.prototype&&null!==Object.getPrototypeOf(e)||Pn in t||On in t)},Jn=Dn("Date"),Gn=Dn("File"),Qn=Dn("Blob"),Yn=Dn("FileList"),Zn=Dn("URLSearchParams"),[tr,er,ir,sr]=["ReadableStream","Request","Response","Headers"].map(Dn);function nr(t,e,{allOwnKeys:i=!1}={}){if(null==t)return;let s,n;if("object"!=typeof t&&(t=[t]),Bn(t))for(s=0,n=t.length;s<n;s++)e.call(null,t[s],s,t);else{if(Wn(t))return;const n=i?Object.getOwnPropertyNames(t):Object.keys(t),r=n.length;let o;for(s=0;s<r;s++)o=n[s],e.call(null,t[o],o,t)}}function rr(t,e){if(Wn(t))return null;e=e.toLowerCase();const i=Object.keys(t);let s,n=i.length;for(;n-- >0;)if(s=i[n],e===s.toLowerCase())return s;return null}const or="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,hr=t=>!An(t)&&t!==or;const lr=(ar="undefined"!=typeof Uint8Array&&Nn(Uint8Array),t=>ar&&t instanceof ar);var ar;const cr=Dn("HTMLFormElement"),ur=(({hasOwnProperty:t})=>(e,i)=>t.call(e,i))(Object.prototype),dr=Dn("RegExp"),fr=(t,e)=>{const i=Object.getOwnPropertyDescriptors(t),s={};nr(i,(i,n)=>{let r;!1!==(r=e(i,n,t))&&(s[n]=r||i)}),Object.defineProperties(t,s)};const mr=Dn("AsyncFunction"),pr=(gr="function"==typeof setImmediate,br=Hn(or.postMessage),gr?setImmediate:br?(vr=`axios@${Math.random()}`,wr=[],or.addEventListener("message",({source:t,data:e})=>{t===or&&e===vr&&wr.length&&wr.shift()()},!1),t=>{wr.push(t),or.postMessage(vr,"*")}):t=>setTimeout(t));var gr,br,vr,wr;const yr="undefined"!=typeof queueMicrotask?queueMicrotask.bind(or):"undefined"!=typeof process&&process.nextTick||pr;var Sr={isArray:Bn,isArrayBuffer:jn,isBuffer:Wn,isFormData:t=>{let e;return t&&("function"==typeof FormData&&t instanceof FormData||Hn(t.append)&&("formdata"===(e=Fn(t))||"object"===e&&Hn(t.toString)&&"[object FormData]"===t.toString()))},isArrayBufferView:function(t){let e;return e="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer&&jn(t.buffer),e},isString:Un,isNumber:Kn,isBoolean:t=>!0===t||!1===t,isObject:qn,isPlainObject:Xn,isEmptyObject:t=>{if(!qn(t)||Wn(t))return!1;try{return 0===Object.keys(t).length&&Object.getPrototypeOf(t)===Object.prototype}catch(t){return!1}},isReadableStream:tr,isRequest:er,isResponse:ir,isHeaders:sr,isUndefined:An,isDate:Jn,isFile:Gn,isBlob:Qn,isRegExp:dr,isFunction:Hn,isStream:t=>qn(t)&&Hn(t.pipe),isURLSearchParams:Zn,isTypedArray:lr,isFileList:Yn,forEach:nr,merge:function t(){const{caseless:e,skipUndefined:i}=hr(this)&&this||{},s={},n=(n,r)=>{const o=e&&rr(s,r)||r;Xn(s[o])&&Xn(n)?s[o]=t(s[o],n):Xn(n)?s[o]=t({},n):Bn(n)?s[o]=n.slice():i&&An(n)||(s[o]=n)};for(let t=0,e=arguments.length;t<e;t++)arguments[t]&&nr(arguments[t],n);return s},extend:(t,e,i,{allOwnKeys:s}={})=>(nr(e,(e,s)=>{i&&Hn(e)?t[s]=Ln(e,i):t[s]=e},{allOwnKeys:s}),t),trim:t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:t=>(65279===t.charCodeAt(0)&&(t=t.slice(1)),t),inherits:(t,e,i,s)=>{t.prototype=Object.create(e.prototype,s),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),i&&Object.assign(t.prototype,i)},toFlatObject:(t,e,i,s)=>{let n,r,o;const h={};if(e=e||{},null==t)return e;do{for(n=Object.getOwnPropertyNames(t),r=n.length;r-- >0;)o=n[r],s&&!s(o,t,e)||h[o]||(e[o]=t[o],h[o]=!0);t=!1!==i&&Nn(t)}while(t&&(!i||i(t,e))&&t!==Object.prototype);return e},kindOf:Fn,kindOfTest:Dn,endsWith:(t,e,i)=>{t=String(t),(void 0===i||i>t.length)&&(i=t.length),i-=e.length;const s=t.indexOf(e,i);return-1!==s&&s===i},toArray:t=>{if(!t)return null;if(Bn(t))return t;let e=t.length;if(!Kn(e))return null;const i=new Array(e);for(;e-- >0;)i[e]=t[e];return i},forEachEntry:(t,e)=>{const i=(t&&t[On]).call(t);let s;for(;(s=i.next())&&!s.done;){const i=s.value;e.call(t,i[0],i[1])}},matchAll:(t,e)=>{let i;const s=[];for(;null!==(i=t.exec(e));)s.push(i);return s},isHTMLForm:cr,hasOwnProperty:ur,hasOwnProp:ur,reduceDescriptors:fr,freezeMethods:t=>{fr(t,(e,i)=>{if(Hn(t)&&-1!==["arguments","caller","callee"].indexOf(i))return!1;const s=t[i];Hn(s)&&(e.enumerable=!1,"writable"in e?e.writable=!1:e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+i+"'")}))})},toObjectSet:(t,e)=>{const i={},s=t=>{t.forEach(t=>{i[t]=!0})};return Bn(t)?s(t):s(String(t).split(e)),i},toCamelCase:t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,e,i){return e.toUpperCase()+i}),noop:()=>{},toFiniteNumber:(t,e)=>null!=t&&Number.isFinite(t=+t)?t:e,findKey:rr,global:or,isContextDefined:hr,isSpecCompliantForm:function(t){return!!(t&&Hn(t.append)&&"FormData"===t[Pn]&&t[On])},toJSONObject:t=>{const e=new Array(10),i=(t,s)=>{if(qn(t)){if(e.indexOf(t)>=0)return;if(Wn(t))return t;if(!("toJSON"in t)){e[s]=t;const n=Bn(t)?[]:{};return nr(t,(t,e)=>{const r=i(t,s+1);!An(r)&&(n[e]=r)}),e[s]=void 0,n}}return t};return i(t,0)},isAsyncFn:mr,isThenable:t=>t&&(qn(t)||Hn(t))&&Hn(t.then)&&Hn(t.catch),setImmediate:pr,asap:yr,isIterable:t=>null!=t&&Hn(t[On])};function xr(t,e,i,s,n){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=t,this.name="AxiosError",e&&(this.code=e),i&&(this.config=i),s&&(this.request=s),n&&(this.response=n,this.status=n.status?n.status:null)}Sr.inherits(xr,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:Sr.toJSONObject(this.config),code:this.code,status:this.status}}});const Mr=xr.prototype,Cr={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{Cr[t]={value:t}}),Object.defineProperties(xr,Cr),Object.defineProperty(Mr,"isAxiosError",{value:!0}),xr.from=(t,e,i,s,n,r)=>{const o=Object.create(Mr);Sr.toFlatObject(t,o,function(t){return t!==Error.prototype},t=>"isAxiosError"!==t);const h=t&&t.message?t.message:"Error",l=null==e&&t?t.code:e;return xr.call(o,h,l,i,s,n),t&&null==o.cause&&Object.defineProperty(o,"cause",{value:t,configurable:!0}),o.name=t&&t.name||"Error",r&&Object.assign(o,r),o};function Er(t){return Sr.isPlainObject(t)||Sr.isArray(t)}function _r(t){return Sr.endsWith(t,"[]")?t.slice(0,-2):t}function $r(t,e,i){return t?t.concat(e).map(function(t,e){return t=_r(t),!i&&e?"["+t+"]":t}).join(i?".":""):e}const zr=Sr.toFlatObject(Sr,{},null,function(t){return/^is[A-Z]/.test(t)});function kr(t,e,i){if(!Sr.isObject(t))throw new TypeError("target must be an object");e=e||new FormData;const s=(i=Sr.toFlatObject(i,{metaTokens:!0,dots:!1,indexes:!1},!1,function(t,e){return!Sr.isUndefined(e[t])})).metaTokens,n=i.visitor||a,r=i.dots,o=i.indexes,h=(i.Blob||"undefined"!=typeof Blob&&Blob)&&Sr.isSpecCompliantForm(e);if(!Sr.isFunction(n))throw new TypeError("visitor must be a function");function l(t){if(null===t)return"";if(Sr.isDate(t))return t.toISOString();if(Sr.isBoolean(t))return t.toString();if(!h&&Sr.isBlob(t))throw new xr("Blob is not supported. Use a Buffer instead.");return Sr.isArrayBuffer(t)||Sr.isTypedArray(t)?h&&"function"==typeof Blob?new Blob([t]):Buffer.from(t):t}function a(t,i,n){let h=t;if(t&&!n&&"object"==typeof t)if(Sr.endsWith(i,"{}"))i=s?i:i.slice(0,-2),t=JSON.stringify(t);else if(Sr.isArray(t)&&function(t){return Sr.isArray(t)&&!t.some(Er)}(t)||(Sr.isFileList(t)||Sr.endsWith(i,"[]"))&&(h=Sr.toArray(t)))return i=_r(i),h.forEach(function(t,s){!Sr.isUndefined(t)&&null!==t&&e.append(!0===o?$r([i],s,r):null===o?i:i+"[]",l(t))}),!1;return!!Er(t)||(e.append($r(n,i,r),l(t)),!1)}const c=[],u=Object.assign(zr,{defaultVisitor:a,convertValue:l,isVisitable:Er});if(!Sr.isObject(t))throw new TypeError("data must be an object");return function t(i,s){if(!Sr.isUndefined(i)){if(-1!==c.indexOf(i))throw Error("Circular reference detected in "+s.join("."));c.push(i),Sr.forEach(i,function(i,r){!0===(!(Sr.isUndefined(i)||null===i)&&n.call(e,i,Sr.isString(r)?r.trim():r,s,u))&&t(i,s?s.concat(r):[r])}),c.pop()}}(t),e}function Rr(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(t){return e[t]})}function Lr(t,e){this._pairs=[],t&&kr(t,this,e)}const Tr=Lr.prototype;function Nr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Or(t,e,i){if(!e)return t;const s=i&&i.encode||Nr;Sr.isFunction(i)&&(i={serialize:i});const n=i&&i.serialize;let r;if(r=n?n(e,i):Sr.isURLSearchParams(e)?e.toString():new Lr(e,i).toString(s),r){const e=t.indexOf("#");-1!==e&&(t=t.slice(0,e)),t+=(-1===t.indexOf("?")?"?":"&")+r}return t}Tr.append=function(t,e){this._pairs.push([t,e])},Tr.toString=function(t){const e=t?function(e){return t.call(this,e,Rr)}:Rr;return this._pairs.map(function(t){return e(t[0])+"="+e(t[1])},"").join("&")};class Pr{constructor(){this.handlers=[]}use(t,e,i){return this.handlers.push({fulfilled:t,rejected:e,synchronous:!!i&&i.synchronous,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){Sr.forEach(this.handlers,function(e){null!==e&&t(e)})}}var Fr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Vr={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:Lr,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const Dr="undefined"!=typeof window&&"undefined"!=typeof document,Ir="object"==typeof navigator&&navigator||void 0,Br=Dr&&(!Ir||["ReactNative","NativeScript","NS"].indexOf(Ir.product)<0),Ar="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,Wr=Dr&&window.location.href||"http://localhost";var jr={...Object.freeze({__proto__:null,hasBrowserEnv:Dr,hasStandardBrowserEnv:Br,hasStandardBrowserWebWorkerEnv:Ar,navigator:Ir,origin:Wr}),...Vr};function Ur(t){function e(t,i,s,n){let r=t[n++];if("__proto__"===r)return!0;const o=Number.isFinite(+r),h=n>=t.length;if(r=!r&&Sr.isArray(s)?s.length:r,h)return Sr.hasOwnProp(s,r)?s[r]=[s[r],i]:s[r]=i,!o;s[r]&&Sr.isObject(s[r])||(s[r]=[]);return e(t,i,s[r],n)&&Sr.isArray(s[r])&&(s[r]=function(t){const e={},i=Object.keys(t);let s;const n=i.length;let r;for(s=0;s<n;s++)r=i[s],e[r]=t[r];return e}(s[r])),!o}if(Sr.isFormData(t)&&Sr.isFunction(t.entries)){const i={};return Sr.forEachEntry(t,(t,s)=>{e(function(t){return Sr.matchAll(/\w+|\[(\w*)]/g,t).map(t=>"[]"===t[0]?"":t[1]||t[0])}(t),s,i,0)}),i}return null}const Hr={transitional:Fr,adapter:["xhr","http","fetch"],transformRequest:[function(t,e){const i=e.getContentType()||"",s=i.indexOf("application/json")>-1,n=Sr.isObject(t);n&&Sr.isHTMLForm(t)&&(t=new FormData(t));if(Sr.isFormData(t))return s?JSON.stringify(Ur(t)):t;if(Sr.isArrayBuffer(t)||Sr.isBuffer(t)||Sr.isStream(t)||Sr.isFile(t)||Sr.isBlob(t)||Sr.isReadableStream(t))return t;if(Sr.isArrayBufferView(t))return t.buffer;if(Sr.isURLSearchParams(t))return e.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let r;if(n){if(i.indexOf("application/x-www-form-urlencoded")>-1)return function(t,e){return kr(t,new jr.classes.URLSearchParams,{visitor:function(t,e,i,s){return jr.isNode&&Sr.isBuffer(t)?(this.append(e,t.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...e})}(t,this.formSerializer).toString();if((r=Sr.isFileList(t))||i.indexOf("multipart/form-data")>-1){const e=this.env&&this.env.FormData;return kr(r?{"files[]":t}:t,e&&new e,this.formSerializer)}}return n||s?(e.setContentType("application/json",!1),function(t,e,i){if(Sr.isString(t))try{return(e||JSON.parse)(t),Sr.trim(t)}catch(t){if("SyntaxError"!==t.name)throw t}return(i||JSON.stringify)(t)}(t)):t}],transformResponse:[function(t){const e=this.transitional||Hr.transitional,i=e&&e.forcedJSONParsing,s="json"===this.responseType;if(Sr.isResponse(t)||Sr.isReadableStream(t))return t;if(t&&Sr.isString(t)&&(i&&!this.responseType||s)){const i=!(e&&e.silentJSONParsing)&&s;try{return JSON.parse(t,this.parseReviver)}catch(t){if(i){if("SyntaxError"===t.name)throw xr.from(t,xr.ERR_BAD_RESPONSE,this,null,this.response);throw t}}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:jr.classes.FormData,Blob:jr.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Sr.forEach(["delete","get","head","post","put","patch"],t=>{Hr.headers[t]={}});const Kr=Sr.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const qr=Symbol("internals");function Xr(t){return t&&String(t).trim().toLowerCase()}function Jr(t){return!1===t||null==t?t:Sr.isArray(t)?t.map(Jr):String(t)}function Gr(t,e,i,s,n){return Sr.isFunction(s)?s.call(this,e,i):(n&&(e=i),Sr.isString(e)?Sr.isString(s)?-1!==e.indexOf(s):Sr.isRegExp(s)?s.test(e):void 0:void 0)}let Qr=class{constructor(t){t&&this.set(t)}set(t,e,i){const s=this;function n(t,e,i){const n=Xr(e);if(!n)throw new Error("header name must be a non-empty string");const r=Sr.findKey(s,n);(!r||void 0===s[r]||!0===i||void 0===i&&!1!==s[r])&&(s[r||e]=Jr(t))}const r=(t,e)=>Sr.forEach(t,(t,i)=>n(t,i,e));if(Sr.isPlainObject(t)||t instanceof this.constructor)r(t,e);else if(Sr.isString(t)&&(t=t.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim()))r((t=>{const e={};let i,s,n;return t&&t.split("\n").forEach(function(t){n=t.indexOf(":"),i=t.substring(0,n).trim().toLowerCase(),s=t.substring(n+1).trim(),!i||e[i]&&Kr[i]||("set-cookie"===i?e[i]?e[i].push(s):e[i]=[s]:e[i]=e[i]?e[i]+", "+s:s)}),e})(t),e);else if(Sr.isObject(t)&&Sr.isIterable(t)){let i,s,n={};for(const e of t){if(!Sr.isArray(e))throw TypeError("Object iterator must return a key-value pair");n[s=e[0]]=(i=n[s])?Sr.isArray(i)?[...i,e[1]]:[i,e[1]]:e[1]}r(n,e)}else null!=t&&n(e,t,i);return this}get(t,e){if(t=Xr(t)){const i=Sr.findKey(this,t);if(i){const t=this[i];if(!e)return t;if(!0===e)return function(t){const e=Object.create(null),i=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let s;for(;s=i.exec(t);)e[s[1]]=s[2];return e}(t);if(Sr.isFunction(e))return e.call(this,t,i);if(Sr.isRegExp(e))return e.exec(t);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,e){if(t=Xr(t)){const i=Sr.findKey(this,t);return!(!i||void 0===this[i]||e&&!Gr(0,this[i],i,e))}return!1}delete(t,e){const i=this;let s=!1;function n(t){if(t=Xr(t)){const n=Sr.findKey(i,t);!n||e&&!Gr(0,i[n],n,e)||(delete i[n],s=!0)}}return Sr.isArray(t)?t.forEach(n):n(t),s}clear(t){const e=Object.keys(this);let i=e.length,s=!1;for(;i--;){const n=e[i];t&&!Gr(0,this[n],n,t,!0)||(delete this[n],s=!0)}return s}normalize(t){const e=this,i={};return Sr.forEach(this,(s,n)=>{const r=Sr.findKey(i,n);if(r)return e[r]=Jr(s),void delete e[n];const o=t?function(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,e,i)=>e.toUpperCase()+i)}(n):String(n).trim();o!==n&&delete e[n],e[o]=Jr(s),i[o]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const e=Object.create(null);return Sr.forEach(this,(i,s)=>{null!=i&&!1!==i&&(e[s]=t&&Sr.isArray(i)?i.join(", "):i)}),e}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,e])=>t+": "+e).join("\n")}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...e){const i=new this(t);return e.forEach(t=>i.set(t)),i}static accessor(t){const e=(this[qr]=this[qr]={accessors:{}}).accessors,i=this.prototype;function s(t){const s=Xr(t);e[s]||(!function(t,e){const i=Sr.toCamelCase(" "+e);["get","set","has"].forEach(s=>{Object.defineProperty(t,s+i,{value:function(t,i,n){return this[s].call(this,e,t,i,n)},configurable:!0})})}(i,t),e[s]=!0)}return Sr.isArray(t)?t.forEach(s):s(t),this}};function Yr(t,e){const i=this||Hr,s=e||i,n=Qr.from(s.headers);let r=s.data;return Sr.forEach(t,function(t){r=t.call(i,r,n.normalize(),e?e.status:void 0)}),n.normalize(),r}function Zr(t){return!(!t||!t.__CANCEL__)}function to(t,e,i){xr.call(this,null==t?"canceled":t,xr.ERR_CANCELED,e,i),this.name="CanceledError"}function eo(t,e,i){const s=i.config.validateStatus;i.status&&s&&!s(i.status)?e(new xr("Request failed with status code "+i.status,[xr.ERR_BAD_REQUEST,xr.ERR_BAD_RESPONSE][Math.floor(i.status/100)-4],i.config,i.request,i)):t(i)}Qr.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Sr.reduceDescriptors(Qr.prototype,({value:t},e)=>{let i=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(t){this[i]=t}}}),Sr.freezeMethods(Qr),Sr.inherits(to,xr,{__CANCEL__:!0});const io=(t,e,i=3)=>{let s=0;const n=function(t,e){t=t||10;const i=new Array(t),s=new Array(t);let n,r=0,o=0;return e=void 0!==e?e:1e3,function(h){const l=Date.now(),a=s[o];n||(n=l),i[r]=h,s[r]=l;let c=o,u=0;for(;c!==r;)u+=i[c++],c%=t;if(r=(r+1)%t,r===o&&(o=(o+1)%t),l-n<e)return;const d=a&&l-a;return d?Math.round(1e3*u/d):void 0}}(50,250);return function(t,e){let i,s,n=0,r=1e3/e;const o=(e,r=Date.now())=>{n=r,i=null,s&&(clearTimeout(s),s=null),t(...e)};return[(...t)=>{const e=Date.now(),h=e-n;h>=r?o(t,e):(i=t,s||(s=setTimeout(()=>{s=null,o(i)},r-h)))},()=>i&&o(i)]}(i=>{const r=i.loaded,o=i.lengthComputable?i.total:void 0,h=r-s,l=n(h);s=r;t({loaded:r,total:o,progress:o?r/o:void 0,bytes:h,rate:l||void 0,estimated:l&&o&&r<=o?(o-r)/l:void 0,event:i,lengthComputable:null!=o,[e?"download":"upload"]:!0})},i)},so=(t,e)=>{const i=null!=t;return[s=>e[0]({lengthComputable:i,total:t,loaded:s}),e[1]]},no=t=>(...e)=>Sr.asap(()=>t(...e));var ro=jr.hasStandardBrowserEnv?((t,e)=>i=>(i=new URL(i,jr.origin),t.protocol===i.protocol&&t.host===i.host&&(e||t.port===i.port)))(new URL(jr.origin),jr.navigator&&/(msie|trident)/i.test(jr.navigator.userAgent)):()=>!0,oo=jr.hasStandardBrowserEnv?{write(t,e,i,s,n,r){const o=[t+"="+encodeURIComponent(e)];Sr.isNumber(i)&&o.push("expires="+new Date(i).toGMTString()),Sr.isString(s)&&o.push("path="+s),Sr.isString(n)&&o.push("domain="+n),!0===r&&o.push("secure"),document.cookie=o.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function ho(t,e,i){let s=!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e);return t&&(s||0==i)?function(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}(t,e):e}const lo=t=>t instanceof Qr?{...t}:t;function ao(t,e){e=e||{};const i={};function s(t,e,i,s){return Sr.isPlainObject(t)&&Sr.isPlainObject(e)?Sr.merge.call({caseless:s},t,e):Sr.isPlainObject(e)?Sr.merge({},e):Sr.isArray(e)?e.slice():e}function n(t,e,i,n){return Sr.isUndefined(e)?Sr.isUndefined(t)?void 0:s(void 0,t,0,n):s(t,e,0,n)}function r(t,e){if(!Sr.isUndefined(e))return s(void 0,e)}function o(t,e){return Sr.isUndefined(e)?Sr.isUndefined(t)?void 0:s(void 0,t):s(void 0,e)}function h(i,n,r){return r in e?s(i,n):r in t?s(void 0,i):void 0}const l={url:r,method:r,data:r,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:h,headers:(t,e,i)=>n(lo(t),lo(e),0,!0)};return Sr.forEach(Object.keys({...t,...e}),function(s){const r=l[s]||n,o=r(t[s],e[s],s);Sr.isUndefined(o)&&r!==h||(i[s]=o)}),i}var co=t=>{const e=ao({},t);let{data:i,withXSRFToken:s,xsrfHeaderName:n,xsrfCookieName:r,headers:o,auth:h}=e;if(e.headers=o=Qr.from(o),e.url=Or(ho(e.baseURL,e.url,e.allowAbsoluteUrls),t.params,t.paramsSerializer),h&&o.set("Authorization","Basic "+btoa((h.username||"")+":"+(h.password?unescape(encodeURIComponent(h.password)):""))),Sr.isFormData(i))if(jr.hasStandardBrowserEnv||jr.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if(Sr.isFunction(i.getHeaders)){const t=i.getHeaders(),e=["content-type","content-length"];Object.entries(t).forEach(([t,i])=>{e.includes(t.toLowerCase())&&o.set(t,i)})}if(jr.hasStandardBrowserEnv&&(s&&Sr.isFunction(s)&&(s=s(e)),s||!1!==s&&ro(e.url))){const t=n&&r&&oo.read(r);t&&o.set(n,t)}return e};var uo="undefined"!=typeof XMLHttpRequest&&function(t){return new Promise(function(e,i){const s=co(t);let n=s.data;const r=Qr.from(s.headers).normalize();let o,h,l,a,c,{responseType:u,onUploadProgress:d,onDownloadProgress:f}=s;function m(){a&&a(),c&&c(),s.cancelToken&&s.cancelToken.unsubscribe(o),s.signal&&s.signal.removeEventListener("abort",o)}let p=new XMLHttpRequest;function g(){if(!p)return;const s=Qr.from("getAllResponseHeaders"in p&&p.getAllResponseHeaders());eo(function(t){e(t),m()},function(t){i(t),m()},{data:u&&"text"!==u&&"json"!==u?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:s,config:t,request:p}),p=null}p.open(s.method.toUpperCase(),s.url,!0),p.timeout=s.timeout,"onloadend"in p?p.onloadend=g:p.onreadystatechange=function(){p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))&&setTimeout(g)},p.onabort=function(){p&&(i(new xr("Request aborted",xr.ECONNABORTED,t,p)),p=null)},p.onerror=function(e){const s=new xr(e&&e.message?e.message:"Network Error",xr.ERR_NETWORK,t,p);s.event=e||null,i(s),p=null},p.ontimeout=function(){let e=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const n=s.transitional||Fr;s.timeoutErrorMessage&&(e=s.timeoutErrorMessage),i(new xr(e,n.clarifyTimeoutError?xr.ETIMEDOUT:xr.ECONNABORTED,t,p)),p=null},void 0===n&&r.setContentType(null),"setRequestHeader"in p&&Sr.forEach(r.toJSON(),function(t,e){p.setRequestHeader(e,t)}),Sr.isUndefined(s.withCredentials)||(p.withCredentials=!!s.withCredentials),u&&"json"!==u&&(p.responseType=s.responseType),f&&([l,c]=io(f,!0),p.addEventListener("progress",l)),d&&p.upload&&([h,a]=io(d),p.upload.addEventListener("progress",h),p.upload.addEventListener("loadend",a)),(s.cancelToken||s.signal)&&(o=e=>{p&&(i(!e||e.type?new to(null,t,p):e),p.abort(),p=null)},s.cancelToken&&s.cancelToken.subscribe(o),s.signal&&(s.signal.aborted?o():s.signal.addEventListener("abort",o)));const b=function(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}(s.url);b&&-1===jr.protocols.indexOf(b)?i(new xr("Unsupported protocol "+b+":",xr.ERR_BAD_REQUEST,t)):p.send(n||null)})};const fo=(t,e)=>{const{length:i}=t=t?t.filter(Boolean):[];if(e||i){let i,s=new AbortController;const n=function(t){if(!i){i=!0,o();const e=t instanceof Error?t:this.reason;s.abort(e instanceof xr?e:new to(e instanceof Error?e.message:e))}};let r=e&&setTimeout(()=>{r=null,n(new xr(`timeout ${e} of ms exceeded`,xr.ETIMEDOUT))},e);const o=()=>{t&&(r&&clearTimeout(r),r=null,t.forEach(t=>{t.unsubscribe?t.unsubscribe(n):t.removeEventListener("abort",n)}),t=null)};t.forEach(t=>t.addEventListener("abort",n));const{signal:h}=s;return h.unsubscribe=()=>Sr.asap(o),h}},mo=function*(t,e){let i=t.byteLength;if(i<e)return void(yield t);let s,n=0;for(;n<i;)s=n+e,yield t.slice(n,s),n=s},po=async function*(t){if(t[Symbol.asyncIterator])return void(yield*t);const e=t.getReader();try{for(;;){const{done:t,value:i}=await e.read();if(t)break;yield i}}finally{await e.cancel()}},go=(t,e,i,s)=>{const n=async function*(t,e){for await(const i of po(t))yield*mo(i,e)}(t,e);let r,o=0,h=t=>{r||(r=!0,s&&s(t))};return new ReadableStream({async pull(t){try{const{done:e,value:s}=await n.next();if(e)return h(),void t.close();let r=s.byteLength;if(i){let t=o+=r;i(t)}t.enqueue(new Uint8Array(s))}catch(t){throw h(t),t}},cancel:t=>(h(t),n.return())},{highWaterMark:2})},{isFunction:bo}=Sr,vo=(({Request:t,Response:e})=>({Request:t,Response:e}))(Sr.global),{ReadableStream:wo,TextEncoder:yo}=Sr.global,So=(t,...e)=>{try{return!!t(...e)}catch(t){return!1}},xo=t=>{t=Sr.merge.call({skipUndefined:!0},vo,t);const{fetch:e,Request:i,Response:s}=t,n=e?bo(e):"function"==typeof fetch,r=bo(i),o=bo(s);if(!n)return!1;const h=n&&bo(wo),l=n&&("function"==typeof yo?(a=new yo,t=>a.encode(t)):async t=>new Uint8Array(await new i(t).arrayBuffer()));var a;const c=r&&h&&So(()=>{let t=!1;const e=new i(jr.origin,{body:new wo,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e}),u=o&&h&&So(()=>Sr.isReadableStream(new s("").body)),d={stream:u&&(t=>t.body)};n&&["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!d[t]&&(d[t]=(e,i)=>{let s=e&&e[t];if(s)return s.call(e);throw new xr(`Response type '${t}' is not supported`,xr.ERR_NOT_SUPPORT,i)})});const f=async(t,e)=>{const s=Sr.toFiniteNumber(t.getContentLength());return null==s?(async t=>{if(null==t)return 0;if(Sr.isBlob(t))return t.size;if(Sr.isSpecCompliantForm(t)){const e=new i(jr.origin,{method:"POST",body:t});return(await e.arrayBuffer()).byteLength}return Sr.isArrayBufferView(t)||Sr.isArrayBuffer(t)?t.byteLength:(Sr.isURLSearchParams(t)&&(t+=""),Sr.isString(t)?(await l(t)).byteLength:void 0)})(e):s};return async t=>{let{url:n,method:o,data:h,signal:l,cancelToken:a,timeout:m,onDownloadProgress:p,onUploadProgress:g,responseType:b,headers:v,withCredentials:w="same-origin",fetchOptions:y}=co(t),S=e||fetch;b=b?(b+"").toLowerCase():"text";let x=fo([l,a&&a.toAbortSignal()],m),M=null;const C=x&&x.unsubscribe&&(()=>{x.unsubscribe()});let E;try{if(g&&c&&"get"!==o&&"head"!==o&&0!==(E=await f(v,h))){let t,e=new i(n,{method:"POST",body:h,duplex:"half"});if(Sr.isFormData(h)&&(t=e.headers.get("content-type"))&&v.setContentType(t),e.body){const[t,i]=so(E,io(no(g)));h=go(e.body,65536,t,i)}}Sr.isString(w)||(w=w?"include":"omit");const e=r&&"credentials"in i.prototype,l={...y,signal:x,method:o.toUpperCase(),headers:v.normalize().toJSON(),body:h,duplex:"half",credentials:e?w:void 0};M=r&&new i(n,l);let a=await(r?S(M,y):S(n,l));const m=u&&("stream"===b||"response"===b);if(u&&(p||m&&C)){const t={};["status","statusText","headers"].forEach(e=>{t[e]=a[e]});const e=Sr.toFiniteNumber(a.headers.get("content-length")),[i,n]=p&&so(e,io(no(p),!0))||[];a=new s(go(a.body,65536,i,()=>{n&&n(),C&&C()}),t)}b=b||"text";let _=await d[Sr.findKey(d,b)||"text"](a,t);return!m&&C&&C(),await new Promise((e,i)=>{eo(e,i,{data:_,headers:Qr.from(a.headers),status:a.status,statusText:a.statusText,config:t,request:M})})}catch(e){if(C&&C(),e&&"TypeError"===e.name&&/Load failed|fetch/i.test(e.message))throw Object.assign(new xr("Network Error",xr.ERR_NETWORK,t,M),{cause:e.cause||e});throw xr.from(e,e&&e.code,t,M)}}},Mo=new Map,Co=t=>{let e=t?t.env:{};const{fetch:i,Request:s,Response:n}=e,r=[s,n,i];let o,h,l=r.length,a=Mo;for(;l--;)o=r[l],h=a.get(o),void 0===h&&a.set(o,h=l?new Map:xo(e)),a=h;return h};Co();const Eo={http:null,xhr:uo,fetch:{get:Co}};Sr.forEach(Eo,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch(t){}Object.defineProperty(t,"adapterName",{value:e})}});const _o=t=>`- ${t}`,$o=t=>Sr.isFunction(t)||null===t||!1===t;var zo=(t,e)=>{t=Sr.isArray(t)?t:[t];const{length:i}=t;let s,n;const r={};for(let o=0;o<i;o++){let i;if(s=t[o],n=s,!$o(s)&&(n=Eo[(i=String(s)).toLowerCase()],void 0===n))throw new xr(`Unknown adapter '${i}'`);if(n&&(Sr.isFunction(n)||(n=n.get(e))))break;r[i||"#"+o]=n}if(!n){const t=Object.entries(r).map(([t,e])=>`adapter ${t} `+(!1===e?"is not supported by the environment":"is not available in the build"));throw new xr("There is no suitable adapter to dispatch the request "+(i?t.length>1?"since :\n"+t.map(_o).join("\n"):" "+_o(t[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return n};function ko(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new to(null,t)}function Ro(t){ko(t),t.headers=Qr.from(t.headers),t.data=Yr.call(t,t.transformRequest),-1!==["post","put","patch"].indexOf(t.method)&&t.headers.setContentType("application/x-www-form-urlencoded",!1);return zo(t.adapter||Hr.adapter,t)(t).then(function(e){return ko(t),e.data=Yr.call(t,t.transformResponse,e),e.headers=Qr.from(e.headers),e},function(e){return Zr(e)||(ko(t),e&&e.response&&(e.response.data=Yr.call(t,t.transformResponse,e.response),e.response.headers=Qr.from(e.response.headers))),Promise.reject(e)})}const Lo="1.12.2",To={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{To[t]=function(i){return typeof i===t||"a"+(e<1?"n ":" ")+t}});const No={};To.transitional=function(t,e,i){function s(t,e){return"[Axios v"+Lo+"] Transitional option '"+t+"'"+e+(i?". "+i:"")}return(i,n,r)=>{if(!1===t)throw new xr(s(n," has been removed"+(e?" in "+e:"")),xr.ERR_DEPRECATED);return e&&!No[n]&&(No[n]=!0,console.warn(s(n," has been deprecated since v"+e+" and will be removed in the near future"))),!t||t(i,n,r)}},To.spelling=function(t){return(e,i)=>(console.warn(`${i} is likely a misspelling of ${t}`),!0)};var Oo={assertOptions:function(t,e,i){if("object"!=typeof t)throw new xr("options must be an object",xr.ERR_BAD_OPTION_VALUE);const s=Object.keys(t);let n=s.length;for(;n-- >0;){const r=s[n],o=e[r];if(o){const e=t[r],i=void 0===e||o(e,r,t);if(!0!==i)throw new xr("option "+r+" must be "+i,xr.ERR_BAD_OPTION_VALUE);continue}if(!0!==i)throw new xr("Unknown option "+r,xr.ERR_BAD_OPTION)}},validators:To};const Po=Oo.validators;let Fo=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Pr,response:new Pr}}async request(t,e){try{return await this._request(t,e)}catch(t){if(t instanceof Error){let e={};Error.captureStackTrace?Error.captureStackTrace(e):e=new Error;const i=e.stack?e.stack.replace(/^.+\n/,""):"";try{t.stack?i&&!String(t.stack).endsWith(i.replace(/^.+\n.+\n/,""))&&(t.stack+="\n"+i):t.stack=i}catch(t){}}throw t}}_request(t,e){"string"==typeof t?(e=e||{}).url=t:e=t||{},e=ao(this.defaults,e);const{transitional:i,paramsSerializer:s,headers:n}=e;void 0!==i&&Oo.assertOptions(i,{silentJSONParsing:Po.transitional(Po.boolean),forcedJSONParsing:Po.transitional(Po.boolean),clarifyTimeoutError:Po.transitional(Po.boolean)},!1),null!=s&&(Sr.isFunction(s)?e.paramsSerializer={serialize:s}:Oo.assertOptions(s,{encode:Po.function,serialize:Po.function},!0)),void 0!==e.allowAbsoluteUrls||(void 0!==this.defaults.allowAbsoluteUrls?e.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:e.allowAbsoluteUrls=!0),Oo.assertOptions(e,{baseUrl:Po.spelling("baseURL"),withXsrfToken:Po.spelling("withXSRFToken")},!0),e.method=(e.method||this.defaults.method||"get").toLowerCase();let r=n&&Sr.merge(n.common,n[e.method]);n&&Sr.forEach(["delete","get","head","post","put","patch","common"],t=>{delete n[t]}),e.headers=Qr.concat(r,n);const o=[];let h=!0;this.interceptors.request.forEach(function(t){"function"==typeof t.runWhen&&!1===t.runWhen(e)||(h=h&&t.synchronous,o.unshift(t.fulfilled,t.rejected))});const l=[];let a;this.interceptors.response.forEach(function(t){l.push(t.fulfilled,t.rejected)});let c,u=0;if(!h){const t=[Ro.bind(this),void 0];for(t.unshift(...o),t.push(...l),c=t.length,a=Promise.resolve(e);u<c;)a=a.then(t[u++],t[u++]);return a}c=o.length;let d=e;for(;u<c;){const t=o[u++],e=o[u++];try{d=t(d)}catch(t){e.call(this,t);break}}try{a=Ro.call(this,d)}catch(t){return Promise.reject(t)}for(u=0,c=l.length;u<c;)a=a.then(l[u++],l[u++]);return a}getUri(t){return Or(ho((t=ao(this.defaults,t)).baseURL,t.url,t.allowAbsoluteUrls),t.params,t.paramsSerializer)}};Sr.forEach(["delete","get","head","options"],function(t){Fo.prototype[t]=function(e,i){return this.request(ao(i||{},{method:t,url:e,data:(i||{}).data}))}}),Sr.forEach(["post","put","patch"],function(t){function e(e){return function(i,s,n){return this.request(ao(n||{},{method:t,headers:e?{"Content-Type":"multipart/form-data"}:{},url:i,data:s}))}}Fo.prototype[t]=e(),Fo.prototype[t+"Form"]=e(!0)});const Vo={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Vo).forEach(([t,e])=>{Vo[e]=t});const Do=function t(e){const i=new Fo(e),s=Ln(Fo.prototype.request,i);return Sr.extend(s,Fo.prototype,i,{allOwnKeys:!0}),Sr.extend(s,i,null,{allOwnKeys:!0}),s.create=function(i){return t(ao(e,i))},s}(Hr);Do.Axios=Fo,Do.CanceledError=to,Do.CancelToken=class t{constructor(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");let e;this.promise=new Promise(function(t){e=t});const i=this;this.promise.then(t=>{if(!i._listeners)return;let e=i._listeners.length;for(;e-- >0;)i._listeners[e](t);i._listeners=null}),this.promise.then=t=>{let e;const s=new Promise(t=>{i.subscribe(t),e=t}).then(t);return s.cancel=function(){i.unsubscribe(e)},s},t(function(t,s,n){i.reason||(i.reason=new to(t,s,n),e(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){this.reason?t(this.reason):this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const e=this._listeners.indexOf(t);-1!==e&&this._listeners.splice(e,1)}toAbortSignal(){const t=new AbortController,e=e=>{t.abort(e)};return this.subscribe(e),t.signal.unsubscribe=()=>this.unsubscribe(e),t.signal}static source(){let e;const i=new t(function(t){e=t});return{token:i,cancel:e}}},Do.isCancel=Zr,Do.VERSION=Lo,Do.toFormData=kr,Do.AxiosError=xr,Do.Cancel=Do.CanceledError,Do.all=function(t){return Promise.all(t)},Do.spread=function(t){return function(e){return t.apply(null,e)}},Do.isAxiosError=function(t){return Sr.isObject(t)&&!0===t.isAxiosError},Do.mergeConfig=ao,Do.AxiosHeaders=Qr,Do.formToJSON=t=>Ur(Sr.isHTMLForm(t)?new FormData(t):t),Do.getAdapter=zo,Do.HttpStatusCode=Vo,Do.default=Do;const{Axios:Io,AxiosError:Bo,CanceledError:Ao,isCancel:Wo,CancelToken:jo,VERSION:Uo,all:Ho,Cancel:Ko,isAxiosError:qo,spread:Xo,toFormData:Jo,AxiosHeaders:Go,HttpStatusCode:Qo,formToJSON:Yo,getAdapter:Zo,mergeConfig:th}=Do,eh={BASE_URL:"undefined"!=typeof window&&window.FUNHI_CHART_API_URL?window.FUNHI_CHART_API_URL:process.env.NEXT_PUBLIC_BACKEND_URL||"",TIMEOUT:1e4,MAX_RETRIES:3,RETRY_DELAY:1e3};const ih=new class{constructor(){this.baseURL=`${eh.BASE_URL}/api/ohlcv`,this.savingQueue=new Map,this.BATCH_DELAY=5e3,this.BATCH_SIZE=50}async saveCandles(t){try{const{mint:e,candles:i,timeFrame:s=60}=t;if(!e||!i||0===i.length)return console.warn("⚠️ [CandleStorage] Invalid save request:",t),!1;return!!(await Do.post(`${this.baseURL}/candles/save`,{mint:e,candles:i,timeFrame:s})).data.success&&(console.log(`💾 [CandleStorage] Saved ${i.length} candles for ${e}`),!0)}catch(t){return console.error("❌ [CandleStorage] Error saving candles:",t),!1}}async saveCandle(t){try{const{mint:e,candle:i,timeFrame:s=60}=t;if(!e||!i)return console.warn("⚠️ [CandleStorage] Invalid save request:",t),!1;const n=`${e}_${s}`,r=this.savingQueue.get(n);if(r)clearTimeout(r.timeout),r.candles.push(i),r.candles.length>=this.BATCH_SIZE?await this.flushQueue(n,e,s):r.timeout=setTimeout(()=>{this.flushQueue(n,e,s)},this.BATCH_DELAY);else{const t=setTimeout(()=>{this.flushQueue(n,e,s)},this.BATCH_DELAY);this.savingQueue.set(n,{candles:[i],timeout:t})}return!0}catch(t){return console.error("❌ [CandleStorage] Error queuing candle:",t),!1}}async flushQueue(t,e,i){const s=this.savingQueue.get(t);s&&0!==s.candles.length&&(this.savingQueue.delete(t),await this.saveCandles({mint:e,candles:s.candles,timeFrame:i}))}async getCandles(t){try{const{mint:e,timeFrame:i=60,limit:s=5e4}=t;if(!e)return console.warn("⚠️ [CandleStorage] Invalid get request:",t),[];const n=await Do.get(`${this.baseURL}/candles/${e}`,{params:{timeFrame:i,limit:s},timeout:8e3,validateStatus:t=>t>=200&&t<500});if(n.data.success&&n.data.data&&n.data.data.candles){const t=n.data.data.candles.length;return t>0?console.log(`✅ [CandleStorage] Retrieved ${t} candles for ${e}`):console.log(`ℹ️ [CandleStorage] No candles found for ${e} in database`),n.data.data.candles}return n.data.warning&&console.warn(`⚠️ [CandleStorage] ${n.data.warning}`),[]}catch(e){return"ECONNABORTED"===e.code?console.error("❌ [CandleStorage] Request timeout getting candles for",t.mint):e.response?console.error("❌ [CandleStorage] Server error getting candles:",e.response.status,e.response.data):e.request?console.error("❌ [CandleStorage] Network error getting candles - no response received"):console.error("❌ [CandleStorage] Error getting candles:",e.message),[]}}async flushAll(){const t=[];for(const[e,i]of this.savingQueue.entries()){clearTimeout(i.timeout);const[s,n]=e.split("_"),r=parseInt(n);t.push(this.flushQueue(e,s,r))}await Promise.all(t)}};const sh=new class{constructor(){this.timeframes={"1m":60,"5m":300,"15m":900,"30m":1800,"1h":3600,"4h":14400,"1d":86400}}aggregateCandles(t,e){try{if(60===e)return t;if(!Array.isArray(t)||0===t.length)return console.warn("⚠️ [CandleAggregation] No candles to aggregate"),[];const i=[...t].sort((t,e)=>t.time-e.time),s=[];let n=[],r=null;for(const t of i){const i=Math.floor(t.time/e)*e;if(null===r&&(r=i),i===r)n.push(t);else{if(n.length>0){const t=this.aggregateGroup(n,r);s.push(t)}n=[t],r=i}}if(n.length>0&&null!==r){const t=this.aggregateGroup(n,r);s.push(t)}return console.log(`📊 [CandleAggregation] Aggregated ${t.length} 1m candles into ${s.length} ${this.getTimeframeLabel(e)} candles`),s}catch(t){return console.error("❌ [CandleAggregation] Error aggregating candles:",t),[]}}aggregateGroup(t,e){const i=[...t].sort((t,e)=>t.time-e.time),s=i[0].open,n=i[i.length-1].close,r=Math.max(...i.map(t=>t.high)),o=Math.min(...i.map(t=>t.low)),h=i.reduce((t,e)=>t+(e.volume||0),0);return{time:e,open:s,high:r,low:o,close:n,volume:h}}getTimeframeLabel(t){for(const[e,i]of Object.entries(this.timeframes))if(i===t)return e;return`${t}s`}getTimeframeSeconds(t){return this.timeframes[t]||60}fillGaps(t,e){try{if(!Array.isArray(t)||t.length<2)return t;const i=[...t].sort((t,e)=>t.time-e.time),s=[];for(let t=0;t<i.length-1;t++){const n=i[t],r=i[t+1];s.push(n);let o=n.time+e;for(;o<r.time;)s.push({time:o,open:n.close,high:n.close,low:n.close,close:n.close,volume:0}),o+=e}return s.push(i[i.length-1]),s.length>i.length&&console.log(`🔧 [CandleAggregation] Filled ${s.length-i.length} gaps in ${this.getTimeframeLabel(e)} candles`),s}catch(e){return console.error("❌ [CandleAggregation] Error filling gaps:",e),t}}getCurrentCandle(t,e){try{if(!Array.isArray(t)||0===t.length)return null;const i=Math.floor(Date.now()/1e3),s=Math.floor(i/e)*e,n=t.filter(t=>Math.floor(t.time/e)*e===s);return 0===n.length?null:this.aggregateGroup(n,s)}catch(t){return console.error("❌ [CandleAggregation] Error getting current candle:",t),null}}updateRealtimeCandle(t,e,i){try{if(!e)return t;const s=Math.floor(e.time/i)*i,n=t.findIndex(t=>t.time===s);if(n>=0){const i=t[n],r={time:s,open:i.open,high:Math.max(i.high,e.high),low:Math.min(i.low,e.low),close:e.close,volume:i.volume+(e.volume||0)},o=[...t];return o[n]=r,o}{const i={time:s,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume||0};return[...t,i].sort((t,e)=>t.time-e.time)}}catch(e){return console.error("❌ [CandleAggregation] Error updating realtime candle:",e),t}}isValidCandle(t){return t&&"number"==typeof t.time&&"number"==typeof t.open&&"number"==typeof t.high&&"number"==typeof t.low&&"number"==typeof t.close&&t.high>=t.low&&t.high>=t.open&&t.high>=t.close&&t.low<=t.open&&t.low<=t.close}cleanCandles(t){if(!Array.isArray(t))return[];const e=t.filter(t=>this.isValidCandle(t));return e.length<t.length&&console.warn(`⚠️ [CandleAggregation] Removed ${t.length-e.length} invalid candles`),e}getRequiredOneMinuteCandles(t,e=200){const i=t/60;return Math.ceil(e*i)}};exports.API_CONFIG=eh,exports.FunhiChart=({mint:e,ticker:i,tokenName:s,socket:n,isConnected:r,currentMarketCap:o,analyticsConnected:h,analyticsLoading:l})=>{const a=t.useRef(null),c=t.useRef(null),u=t.useRef(null),d=t.useRef([]),f=t.useRef([]),m=t.useRef([]),p=t.useRef([]),g=t.useRef([]),b=t.useRef([]),v=t.useRef(null),w=t.useRef(null),y=t.useRef(null),S=t.useRef(null),x=t.useRef(null),M=t.useRef(null),C=t.useRef(0),E=t.useRef(0),_=t.useRef(0),$=t.useRef(0),z=t.useRef(0),k=t.useRef(0),R=t.useRef(null),[L,T]=t.useState([]),[N,O]=t.useState(null),[P,F]=t.useState(0),[V,D]=t.useState([]),[I,B]=t.useState(null),[A,W]=t.useState(0),[j,U]=t.useState([]),[H,K]=t.useState(null),[q,X]=t.useState(0),[J,G]=t.useState([]),[Q,Y]=t.useState(null),[Z,tt]=t.useState(0),[et,it]=t.useState([]),[st,nt]=t.useState(null),[rt,ot]=t.useState(0),[ht,lt]=t.useState([]),[at,ct]=t.useState(null),[ut,dt]=t.useState(0),[mt,pt]=t.useState(0),[gt,bt]=t.useState(!0),[vt,wt]=t.useState(!1),[yt,St]=t.useState(null),[xt,Mt]=t.useState(null),Ct=t.useRef(0),Et=t.useRef(0),_t=kn(),$t=n||_t.socket,zt=void 0!==r?r:_t.isConnected,kt=Rn(),Rt=void 0!==o?o:kt.currentMarketCap,Lt=void 0!==h?h:kt.connected,Tt=void 0!==l?l:kt.loading,Nt=t.useMemo(()=>[{label:"1m",value:"1m",seconds:60},{label:"5m",value:"5m",seconds:300},{label:"15m",value:"15m",seconds:900},{label:"1h",value:"1h",seconds:3600},{label:"4h",value:"4h",seconds:14400},{label:"1d",value:"1d",seconds:86400}],[]),[Ot,Pt]=t.useState(Nt[0]),Ft=t.useCallback(()=>{switch(Ot.seconds){case 60:default:return d.current;case 300:return f.current;case 900:return m.current;case 3600:return p.current;case 14400:return g.current;case 86400:return b.current}},[Ot.seconds]),Vt=t.useCallback(t=>t>=1e9?`$${(t/1e9).toFixed(t>=1e10?2:3)}B`:t>=1e6?`$${(t/1e6).toFixed(t>=1e7?2:3)}M`:t>=1e4?`$${(t/1e3).toFixed(t>=1e5?1:2)}K`:t>=1e3?`$${(t/1e3).toFixed(2)}K`:t>=1?`$${t.toFixed(2)}`:`$${t.toFixed(4)}`,[]),Dt=t.useCallback(async(t,i)=>{const s=Nt.find(e=>e.seconds===t)?.label||`${t}s`;try{const n=i?`${i} candles`:"all available candles";console.log(`📊 [Chart-${s}] Loading ${n} from database`);const r=i??Number.MAX_SAFE_INTEGER,o=(await ih.getCandles({mint:e,timeFrame:t,limit:r})).reduce((t,e)=>{const i=Math.max(1e-4*e.open,.01),s=Math.abs(e.open-e.close);let n={...e};if(s<i&&e.open>0){const t=e.close>=e.open?1:-1;n.close=e.open+t*i,n.high=Math.max(e.high||e.open,n.close),n.low=Math.min(e.low||e.open,n.close)}const r=t.findIndex(t=>t.time===n.time);return r>=0?t[r]=n:t.push(n),t},[]),h=o.sort((t,e)=>t.time-e.time);return console.log(`✅ [Chart-${s}] Loaded ${h.length} candles`),h}catch(t){return console.error(`❌ [Chart-${s}] Error loading candles:`,t),[]}},[e,Nt]),It=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=60*Math.floor(i/60),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1m] Invalid price data: ${t}`),null;if(s!==C.current){let e=null,i=1;if(v.current&&v.current.close>0&&isFinite(v.current.close)&&(v.current.time<s?(e=v.current.close,v.current.open>0&&(i=v.current.close>=v.current.open?1:-1),console.log(`✅ [Chart-1m] Method 1: Using currentCandle ref close (${v.current.time}) as new candle open: $${e.toFixed(2)}`)):v.current.time===s&&console.warn(`⚠️ [Chart-1m] Current candle ref is already for new bucket ${s}, skipping`)),null===e){const t=d.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s&&t.close>0&&isFinite(t.close));r&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`✅ [Chart-1m] Method 2: Using last completed candle from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&v.current&&v.current.close>0&&isFinite(v.current.close)&&(e=v.current.close,v.current.open>0&&(i=v.current.close>=v.current.open?1:-1),console.log(`✅ [Chart-1m] Method 3 (PRIMARY): Using currentCandle ref close (${v.current.time}) as new candle open: $${e.toFixed(2)}`)),v.current&&v.current.open>0&&v.current.high>0&&v.current.low>0&&v.current.close>0){const t={...v.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),T(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,d.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return d.current=s,s})}null===e&&(console.error("❌ [Chart-1m] CRITICAL: No previous candle close found after all attempts! This should not happen."),console.error(" - currentCandle1mRef.current:",v.current),console.error(" - candles1mRef.current length:",d.current?.length||0),console.error(" - bucketStart:",s,`(${new Date(1e3*s).toLocaleTimeString()})`),console.error(` - Using current price as last resort: $${t.toFixed(2)}`),e=t);const n=e;console.log(`🕯️ [Chart-1m] Creating new candle at ${new Date(1e3*s).toLocaleTimeString()}: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return v.current=l,C.current=s,O(l),F(s),T(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,d.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return d.current=i,i}),console.log(`🆕 [Chart-1m] New candle: $${t.toFixed(2)}`),l}if(v.current){const i=Math.floor(e/1e3),s=60*Math.floor(i/60);if(v.current.time!==s)return console.warn(`⚠️ [Chart-1m] Skipping update for historical candle (time: ${v.current.time}, current: ${s})`),null;const n=v.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return v.current=e,O(e),T(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,d.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r,console.log(`🛡️ [Chart-1m] PRESERVING body: open=$${n.open.toFixed(2)}, close=$${l.toFixed(2)}, bodySize=$${r.toFixed(4)}, priceDiff=$${o.toFixed(4)}, direction=${e>0?"UP":"DOWN"}, price=$${t.toFixed(2)}`)}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1;const i=n.open+e*r;Math.abs(i-l)>1e-4&&(console.log(`🔒 [Chart-1m] ENFORCING minimum body: was $${l.toFixed(2)}, now $${i.toFixed(2)}, direction=${e>0?"UP":"DOWN"}, price=$${t.toFixed(2)}`),l=i)}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),v.current=a,O(a),a.time!==s?(console.warn(`⚠️ [Chart-1m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(T(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,d.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return d.current=e,e}return t}),a)}return null},[]),Bt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=300*Math.floor(i/300),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-5m] Invalid price data: ${t}`),null;if(s!==E.current){let e=null,i=1;if(w.current&&w.current.close>0&&isFinite(w.current.close)&&w.current.time<s&&(e=w.current.close,w.current.open>0&&(i=w.current.close>=w.current.open?1:-1),console.log(`✅ [Chart-5m] Using currentCandle ref close (${w.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=f.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-5m] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&w.current&&w.current.close>0&&isFinite(w.current.close)&&(e=w.current.close,w.current.open>0&&(i=w.current.close>=w.current.open?1:-1),console.log(`✅ [Chart-5m] Method 3 (PRIMARY): Using currentCandle ref close (${w.current.time}) as new candle open: $${e.toFixed(2)}`)),w.current&&w.current.open>0&&w.current.high>0&&w.current.low>0&&w.current.close>0){const t={...w.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-5m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),D(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,f.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return f.current=s,s})}null===e&&(console.error("❌ [Chart-5m] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-5m] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return w.current=l,E.current=s,B(l),W(s),D(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,f.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return f.current=i,i}),console.log(`🆕 [Chart-5m] New candle: $${t.toFixed(2)}`),l}if(w.current){const i=Math.floor(e/1e3),s=300*Math.floor(i/300);if(w.current.time!==s)return console.warn(`⚠️ [Chart-5m] Skipping update for historical candle (time: ${w.current.time}, current: ${s})`),null;const n=w.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-5m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return w.current=e,B(e),D(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,f.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),w.current=a,B(a),a.time!==s?(console.warn(`⚠️ [Chart-5m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(D(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,f.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return f.current=e,e}return t}),a)}return null},[]),At=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=900*Math.floor(i/900),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-15m] Invalid price data: ${t}`),null;if(s!==_.current){let e=null,i=1;if(y.current&&y.current.close>0&&isFinite(y.current.close)&&y.current.time<s&&(e=y.current.close,y.current.open>0&&(i=y.current.close>=y.current.open?1:-1),console.log(`✅ [Chart-15m] Using currentCandle ref close (${y.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=m.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-15m] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&y.current&&y.current.close>0&&isFinite(y.current.close)&&(e=y.current.close,y.current.open>0&&(i=y.current.close>=y.current.open?1:-1),console.log(`✅ [Chart-15m] Method 3 (PRIMARY): Using currentCandle ref close (${y.current.time}) as new candle open: $${e.toFixed(2)}`)),y.current&&y.current.open>0&&y.current.high>0&&y.current.low>0&&y.current.close>0){const t={...y.current};t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),U(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,m.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return m.current=s,s}),null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-15m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`))}null===e&&(console.error("❌ [Chart-15m] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-15m] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return y.current=l,_.current=s,K(l),X(s),U(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,m.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return m.current=i,i}),console.log(`🆕 [Chart-15m] New candle: $${t.toFixed(2)}`),l}if(y.current){const i=Math.floor(e/1e3),s=900*Math.floor(i/900);if(y.current.time!==s)return console.warn(`⚠️ [Chart-15m] Skipping update for historical candle (time: ${y.current.time}, current: ${s})`),null;const n=y.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-15m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return y.current=e,K(e),U(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,m.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),y.current=a,K(a),a.time!==s?(console.warn(`⚠️ [Chart-15m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(U(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,m.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return m.current=e,e}return t}),a)}return null},[]),Wt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=3600*Math.floor(i/3600),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1h] Invalid price data: ${t}`),null;if(s!==$.current){let e=null,i=1;if(S.current&&S.current.close>0&&isFinite(S.current.close)&&S.current.time<s&&(e=S.current.close,S.current.open>0&&(i=S.current.close>=S.current.open?1:-1),console.log(`✅ [Chart-1h] Using currentCandle ref close (${S.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=p.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-1h] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&S.current&&S.current.close>0&&isFinite(S.current.close)&&(e=S.current.close,S.current.open>0&&(i=S.current.close>=S.current.open?1:-1),console.log(`✅ [Chart-1h] Method 3 (PRIMARY): Using currentCandle ref close (${S.current.time}) as new candle open: $${e.toFixed(2)}`)),S.current&&S.current.open>0&&S.current.high>0&&S.current.low>0&&S.current.close>0){const t={...S.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1h] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),G(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,p.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return p.current=s,s})}null===e&&(console.error("❌ [Chart-1h] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-1h] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return S.current=l,$.current=s,Y(l),tt(s),G(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,p.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return p.current=i,i}),console.log(`🆕 [Chart-1h] New candle: $${t.toFixed(2)}`),l}if(S.current){const i=Math.floor(e/1e3),s=3600*Math.floor(i/3600);if(S.current.time!==s)return console.warn(`⚠️ [Chart-1h] Skipping update for historical candle (time: ${S.current.time}, current: ${s})`),null;const n=S.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1h] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return S.current=e,Y(e),G(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,p.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),S.current=a,Y(a),a.time!==s?(console.warn(`⚠️ [Chart-1h] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(G(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,p.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return p.current=e,e}return t}),a)}return null},[]),jt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=14400*Math.floor(i/14400),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-4h] Invalid price data: ${t}`),null;if(s!==z.current){let e=null,i=1;if(x.current&&x.current.close>0&&isFinite(x.current.close)&&x.current.time<s&&(e=x.current.close,x.current.open>0&&(i=x.current.close>=x.current.open?1:-1),console.log(`✅ [Chart-4h] Using currentCandle ref close (${x.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=g.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-4h] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&x.current&&x.current.close>0&&isFinite(x.current.close)&&(e=x.current.close,x.current.open>0&&(i=x.current.close>=x.current.open?1:-1),console.log(`✅ [Chart-4h] Method 3 (PRIMARY): Using currentCandle ref close (${x.current.time}) as new candle open: $${e.toFixed(2)}`)),x.current&&x.current.open>0&&x.current.high>0&&x.current.low>0&&x.current.close>0){const t={...x.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-4h] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),it(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,g.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return g.current=s,s})}null===e&&(console.error("❌ [Chart-4h] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-4h] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return x.current=l,z.current=s,nt(l),ot(s),it(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,g.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return g.current=i,i}),console.log(`🆕 [Chart-4h] New candle: $${t.toFixed(2)}`),l}if(x.current){const i=Math.floor(e/1e3),s=14400*Math.floor(i/14400);if(x.current.time!==s)return console.warn(`⚠️ [Chart-4h] Skipping update for historical candle (time: ${x.current.time}, current: ${s})`),null;const n=x.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-4h] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return x.current=e,nt(e),it(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,g.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),x.current=a,nt(a),a.time!==s?(console.warn(`⚠️ [Chart-4h] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(it(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,g.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return g.current=e,e}return t}),a)}return null},[]),Ut=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=86400*Math.floor(i/86400),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1d] Invalid price data: ${t}`),null;if(s!==k.current){let e=null,i=1;if(M.current&&M.current.close>0&&isFinite(M.current.close)&&M.current.time<s&&(e=M.current.close,M.current.open>0&&(i=M.current.close>=M.current.open?1:-1),console.log(`✅ [Chart-1d] Using currentCandle ref close (${M.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=b.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-1d] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&M.current&&M.current.close>0&&isFinite(M.current.close)&&(e=M.current.close,M.current.open>0&&(i=M.current.close>=M.current.open?1:-1),console.log(`✅ [Chart-1d] Method 3 (PRIMARY): Using currentCandle ref close (${M.current.time}) as new candle open: $${e.toFixed(2)}`)),M.current&&M.current.open>0&&M.current.high>0&&M.current.low>0&&M.current.close>0){const t={...M.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1d] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),lt(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,b.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return b.current=s,s})}null===e&&(console.error("❌ [Chart-1d] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-1d] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return M.current=l,k.current=s,ct(l),dt(s),lt(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,b.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return b.current=i,i}),console.log(`🆕 [Chart-1d] New candle: $${t.toFixed(2)}`),l}if(M.current){const i=Math.floor(e/1e3),s=86400*Math.floor(i/86400);if(M.current.time!==s)return console.warn(`⚠️ [Chart-1d] Skipping update for historical candle (time: ${M.current.time}, current: ${s})`),null;const n=M.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1d] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return M.current=e,ct(e),lt(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,b.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),M.current=a,ct(a),a.time!==s?(console.warn(`⚠️ [Chart-1d] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(lt(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,b.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return b.current=e,e}return t}),a)}return null},[]);t.useEffect(()=>{Ct.current=mt},[mt]),t.useEffect(()=>{R.current=Ot},[Ot]),t.useEffect(()=>{if(!a.current)return;const t=zn(a.current,{layout:{background:{color:"#ffffff"},textColor:"#333333"},grid:{vertLines:{color:"#f0f0f0"},horzLines:{color:"#f0f0f0"}},crosshair:{mode:ft.Normal},rightPriceScale:{borderColor:"#cccccc"},timeScale:{borderColor:"#cccccc",timeVisible:!0,secondsVisible:!1,rightOffset:12,barSpacing:8,minBarSpacing:4},height:384,localization:{priceFormatter:t=>Vt(t)},watermark:{visible:!0,fontSize:64,horzAlign:"center",vertAlign:"center",color:"rgba(0, 0, 0, 0.03)",text:i?`${i}/SOL`:`${e.substring(0,4)}...${e.substring(e.length-4)}/SOL`}});c.current=t;const s=t.addCandlestickSeries({upColor:"#26a69a",downColor:"#ef5350",borderVisible:!0,borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350"});u.current=s,Dt(Ot.seconds).then(t=>{if(t.length>0){let e=t[t.length-1],i=t;if(Rt>0){const s=Math.floor(Date.now()/1e3),n=Math.floor(s/Ot.seconds)*Ot.seconds;if(e.time===n){const s=Math.max(1e-4*e.open,.01),n=Math.abs(e.open-Rt);let r=Rt;if(n<s&&e.open>0){const t=Rt>=e.open?1:-1;r=e.open+t*s}e={...e,high:Math.max(e.high,Rt,r),low:Math.min(e.low,Rt,r),close:r},i=[...t],i[i.length-1]=e,console.log(`🔄 [Chart-Init] Updated initial ${Ot.label} candle with current MC: $${Rt.toFixed(2)}`)}}switch(Ot.seconds){case 60:T(i),F(e.time),O(e),d.current=i,C.current=e.time,v.current=e,console.log(`✅ [Chart-Init] 1m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 300:D(i),W(e.time),B(e),f.current=i,E.current=e.time,w.current=e,console.log(`✅ [Chart-Init] 5m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 900:U(i),X(e.time),K(e),m.current=i,_.current=e.time,y.current=e,console.log(`✅ [Chart-Init] 15m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 3600:G(i),tt(e.time),Y(e),p.current=i,$.current=e.time,S.current=e,console.log(`✅ [Chart-Init] 1h refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 14400:it(i),ot(e.time),nt(e),g.current=i,z.current=e.time,x.current=e,console.log(`✅ [Chart-Init] 4h refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 86400:lt(i),dt(e.time),ct(e),b.current=i,k.current=e.time,M.current=e,console.log(`✅ [Chart-Init] 1d refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`)}s.setData(i.map(t=>({...t,time:t.time}))),console.log(`✅ [Chart-${Ot.label}] Loaded and displayed ${i.length} candles`),60!==Ot.seconds&&Dt(60).then(t=>{if(t.length>0){d.current=t;const e=t[t.length-1];C.current=e.time,v.current=e,console.log(`✅ [Chart-Init] 1m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),300!==Ot.seconds&&Dt(300).then(t=>{if(t.length>0){f.current=t;const e=t[t.length-1];E.current=e.time,w.current=e,console.log(`✅ [Chart-Init] 5m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),900!==Ot.seconds&&Dt(900).then(t=>{if(t.length>0){m.current=t;const e=t[t.length-1];_.current=e.time,y.current=e,console.log(`✅ [Chart-Init] 15m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),3600!==Ot.seconds&&Dt(3600).then(t=>{if(t.length>0){p.current=t;const e=t[t.length-1];$.current=e.time,S.current=e,console.log(`✅ [Chart-Init] 1h refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),14400!==Ot.seconds&&Dt(14400).then(t=>{if(t.length>0){g.current=t;const e=t[t.length-1];z.current=e.time,x.current=e,console.log(`✅ [Chart-Init] 4h refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),86400!==Ot.seconds&&Dt(86400).then(t=>{if(t.length>0){b.current=t;const e=t[t.length-1];k.current=e.time,M.current=e,console.log(`✅ [Chart-Init] 1d refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{})}bt(!1)}).catch(t=>{console.error(`❌ [Chart-${Ot.label}] Load error:`,t),bt(!1)});const n=()=>{a.current&&t.applyOptions({width:a.current.clientWidth})};return window.addEventListener("resize",n),n(),()=>{window.removeEventListener("resize",n),t.remove()}},[e,Dt,Vt,Ot,i]);const Ht=t.useCallback(async t=>{const e=Nt.find(e=>e.value===t);if(e&&e.value!==Ot.value){if(vt)return void console.log(`⚠️ [Chart] Timeframe switch already in progress, ignoring ${e.label}`);console.log(`🔄 [Chart] Switching to ${e.label}`),wt(!0),St(e.label),bt(!0);try{let t=[];switch(e.seconds){case 60:t=d.current;break;case 300:t=f.current;break;case 900:t=m.current;break;case 3600:t=p.current;break;case 14400:t=g.current;break;case 86400:t=b.current}if(t.length>0){console.log(`✅ [Chart] Using ${t.length} cached ${e.label} candles`);let i=t,s=t[t.length-1];if(Ct.current>0){const n=Math.floor(Date.now()/1e3),r=Math.floor(n/e.seconds)*e.seconds;if(s&&s.time===r){const n=Math.max(1e-4*s.open,.01),r=Math.abs(s.open-Ct.current);let o=Ct.current;if(r<n&&s.open>0){const t=Ct.current>=s.open?1:-1;o=s.open+t*n}const h={...s,high:Math.max(s.high,Ct.current,o),low:Math.min(s.low,Ct.current,o),close:o};i=[...t],i[i.length-1]=h,s=h,console.log(`🔄 [Chart] Updated current ${e.label} candle with latest MC: $${Ct.current.toFixed(2)}`)}}switch(e.seconds){case 60:T(i),F(s.time),O(s),d.current=i,C.current=s.time,v.current=s;break;case 300:D(i),W(s.time),B(s),f.current=i,E.current=s.time,w.current=s;break;case 900:U(i),X(s.time),K(s),m.current=i,_.current=s.time,y.current=s;break;case 3600:G(i),tt(s.time),Y(s),p.current=i,$.current=s.time,S.current=s;break;case 14400:it(i),ot(s.time),nt(s),g.current=i,z.current=s.time,x.current=s;break;case 86400:lt(i),dt(s.time),ct(s),b.current=i,k.current=s.time,M.current=s}u.current&&u.current.setData(i.map(t=>({...t,time:t.time}))),setTimeout(()=>{Pt(e),bt(!1),wt(!1),St(null),console.log(`✅ [Chart] Switched to ${e.label} with ${i.length} cached candles`)},0)}else{console.log(`📊 [Chart] Loading ${e.label} candles`);const t=await Dt(e.seconds);if(t.length>0){let i=t[t.length-1],s=t;if(Ct.current>0){const n=Math.floor(Date.now()/1e3),r=Math.floor(n/e.seconds)*e.seconds;if(i.time===r){const n=Math.max(1e-4*i.open,.01),r=Math.abs(i.open-Ct.current);let o=Ct.current;if(r<n&&i.open>0){const t=Ct.current>=i.open?1:-1;o=i.open+t*n}i={...i,high:Math.max(i.high,Ct.current,o),low:Math.min(i.low,Ct.current,o),close:o},s=[...t],s[s.length-1]=i,console.log(`🔄 [Chart] Updated loaded ${e.label} candle with current MC: $${Ct.current.toFixed(2)}`)}}switch(e.seconds){case 60:T(s),F(i.time),O(i),d.current=s,C.current=i.time,v.current=i;break;case 300:D(s),W(i.time),B(i),f.current=s,E.current=i.time,w.current=i;break;case 900:U(s),X(i.time),K(i),m.current=s,_.current=i.time,y.current=i;break;case 3600:G(s),tt(i.time),Y(i),p.current=s,$.current=i.time,S.current=i;break;case 14400:it(s),ot(i.time),nt(i),g.current=s,z.current=i.time,x.current=i;break;case 86400:lt(s),dt(i.time),ct(i),b.current=s,k.current=i.time,M.current=i}u.current&&u.current.setData(s.map(t=>({...t,time:t.time}))),setTimeout(()=>{Pt(e),bt(!1),wt(!1),St(null),console.log(`✅ [Chart] Switched to ${e.label} with ${s.length} loaded candles`)},0)}else setTimeout(()=>{Pt(e),bt(!1),wt(!1),St(null),console.log(`⚠️ [Chart] No candles loaded for ${e.label}`)},0)}}catch(t){console.error("❌ [Chart] Switch error:",t),setTimeout(()=>{Pt(e),bt(!1),wt(!1),St(null)},0)}}},[Nt,Ot,Dt,vt]);if(t.useEffect(()=>{if(!e||!u.current||Rt<=0)return;if(!isFinite(Rt)||Rt<=0)return void console.warn(`⚠️ [Chart-Isolated] Invalid market cap data: ${Rt}`);console.log(`💰 [Chart-Isolated] Real-time update: $${Rt.toFixed(2)}`);const t=Date.now();requestAnimationFrame(()=>{It(Rt,t),Bt(Rt,t),At(Rt,t),Wt(Rt,t),jt(Rt,t),Ut(Rt,t),pt(Rt),bt(!1);const e=Ft();if(e.length>0){const t=e.filter(t=>t&&t.open>0&&t.high>0&&t.low>0&&t.close>0&&isFinite(t.open)&&isFinite(t.high)&&isFinite(t.low)&&isFinite(t.close));t.length>0&&u.current&&(u.current.setData(t.map(t=>({...t,time:t.time}))),requestAnimationFrame(()=>{c.current&&c.current.timeScale().scrollToRealTime()}))}})},[e,Rt,It,Bt,At,Wt,jt,Ut,Ft]),t.useEffect(()=>{if(!$t||!zt||!e)return;const t=t=>{if(t.mint===e&&(console.log(`📡 [Chart-Isolated] Received multi-timeframe candles from backend for ${e}`,t.candles?Object.keys(t.candles):"no candles"),t.candles)){const e=t.candles,i=(t,e)=>{const i=Math.floor(Date.now()/1e3),s=Math.floor(i/t)*t;if(e.time!==s)return void console.warn(`⚠️ [Chart-Socket] Skipping backend update for historical candle: time=${e.time}, currentBucket=${s}, timeframe=${t}s`);let n=e.open,r=e.close;const o=Math.max(1e-4*n,.01),h=Math.abs(n-r);let l=null;switch(t){case 60:l=v.current;break;case 300:l=w.current;break;case 900:l=y.current;break;case 3600:l=S.current;break;case 14400:l=x.current;break;case 86400:l=M.current}if(l&&l.time===e.time&&l.open>0&&l){const e=Math.abs(l.close-l.open);if(e>=.5*o&&e<=2*o){if(Math.abs(l.open-r)<2*o)r=l.close,n=l.open,console.log(`🛡️ [Chart] Preserving minimum body size for ${t}s candle from frontend`);else if(h<o){r=n+(r>=n?1:-1)*o}}else if(h<o&&n>0){r=n+(r>=n?1:-1)*o}}else if(h<o&&n>0){r=n+(r>=n?1:-1)*o}if(Math.abs(r-n)<o&&n>0){r=n+(r>=n||l&&l.close>=l.open?1:-1)*o}const a={time:e.time,open:n,high:Math.max(e.high||n,n,r),low:Math.min(e.low||n,n,r),close:r,volume:e.volume||0};if(a.time===s)switch(t){case 60:v.current=a,C.current=a.time,O(a),F(a.time),T(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,d.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return d.current=e,e}return t});break;case 300:w.current=a,E.current=a.time,B(a),W(a.time),D(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,f.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return f.current=e,e}return t});break;case 900:y.current=a,_.current=a.time,K(a),X(a.time),U(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,m.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return m.current=e,e}return t});break;case 3600:S.current=a,$.current=a.time,Y(a),tt(a.time),G(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,p.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return p.current=e,e}return t});break;case 14400:x.current=a,z.current=a.time,nt(a),ot(a.time),it(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,g.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return g.current=e,e}return t});break;case 86400:M.current=a,k.current=a.time,ct(a),dt(a.time),lt(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,b.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return b.current=e,e}return t})}else console.warn(`⚠️ [Chart-Socket] Prevented update: candle time ${a.time} doesn't match current bucket ${s}`)};e["1m"]&&(i(60,e["1m"]),console.log("✅ [Chart-Isolated] Updated 1m from backend with full OHLC")),e["5m"]&&(i(300,e["5m"]),console.log("✅ [Chart-Isolated] Updated 5m from backend with full OHLC")),e["15m"]&&(i(900,e["15m"]),console.log("✅ [Chart-Isolated] Updated 15m from backend with full OHLC")),e["1h"]&&(i(3600,e["1h"]),console.log("✅ [Chart-Isolated] Updated 1h from backend with full OHLC")),e["4h"]&&(i(14400,e["4h"]),console.log("✅ [Chart-Isolated] Updated 4h from backend with full OHLC")),e["1d"]&&(i(86400,e["1d"]),console.log("✅ [Chart-Isolated] Updated 1d from backend with full OHLC"));const s=Ft();s.length>0&&u.current&&(u.current.setData(s.map(t=>({...t,time:t.time}))),requestAnimationFrame(()=>{c.current&&c.current.timeScale().scrollToRealTime()}))}};return $t.on("multiTimeframeCandleUpdate",t),()=>{$t.off("multiTimeframeCandleUpdate",t)}},[$t,zt,e,Ft]),t.useEffect(()=>{const t=Ft();if((gt||Tt)&&0===t.length){const t=setTimeout(()=>bt(!1),1e4);return()=>clearTimeout(t)}},[gt,Tt,Ft]),xt)return t.createElement("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg"},t.createElement("div",{className:"text-red-800 font-medium"},"Chart Error"),t.createElement("div",{className:"text-red-600 text-sm"},xt),t.createElement("button",{onClick:()=>Mt(null),className:"mt-2 px-3 py-1 bg-red-100 text-red-700 rounded text-sm hover:bg-red-200"},"Dismiss"));const Kt=Ft();return t.createElement("div",{className:"w-full"},t.createElement("div",{className:"mb-4 flex flex-wrap gap-2 items-center"},t.createElement("div",{className:"flex flex-wrap gap-2"},Nt.map(e=>{const i=Ot.value===e.value,s=vt&&yt===e.label,n=vt;return t.createElement("button",{key:e.value,onClick:()=>Ht(e.value),disabled:n,className:`\n px-3 py-2 rounded-lg text-sm font-medium transition-all duration-200 relative\n ${i?"bg-blue-600 text-white":n?"bg-gray-100 text-gray-400 cursor-not-allowed":"bg-gray-100 text-gray-700 hover:bg-gray-200"}\n ${s?"animate-pulse":""}\n `},s&&t.createElement("div",{className:"absolute inset-0 flex items-center justify-center"},t.createElement("div",{className:"flex space-x-1"},t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse"}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.2s"}}))),t.createElement("span",{className:s?"opacity-0":"opacity-100"},e.label))})),t.createElement("div",{className:"ml-auto flex items-center gap-2 text-sm"},t.createElement("div",{className:"w-2 h-2 rounded-full "+(Lt?"bg-green-500":"bg-red-500")}),t.createElement("span",{className:Lt?"text-green-600":"text-red-600"},Lt?"Connected":"Disconnected"),vt&&yt&&t.createElement("span",{className:"text-blue-600"},"• Switching to ",yt,"..."),!vt&>&&!Tt&&t.createElement("span",{className:"text-blue-600"},"• Loading candles..."),Tt&&t.createElement("span",{className:"text-blue-600"},"• Connecting to analytics..."),!vt&&!gt&&!Tt&&Kt.length>0&&t.createElement("span",{className:"text-green-600"},"• ",Kt.length," ",Ot.label," candles • ",Vt(mt)))),t.createElement("div",{ref:a,className:"relative w-full h-96 transition-all duration-300 "+(vt?"opacity-75 scale-[0.98]":"opacity-100 scale-100")},(vt||gt&&!Tt)&&t.createElement("div",{className:"absolute inset-0 bg-gradient-to-br from-white via-blue-50 to-white bg-opacity-90 flex items-center justify-center rounded-lg z-10 backdrop-blur-sm"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"flex justify-center items-center mb-4"},t.createElement("div",{className:"relative"},t.createElement("div",{className:"w-12 h-12 border-4 border-blue-200 rounded-full"}),t.createElement("div",{className:"absolute top-0 left-0 w-12 h-12 border-4 border-blue-600 rounded-full border-t-transparent animate-spin"}))),t.createElement("div",{className:"text-gray-700 font-medium text-lg"},vt&&yt?`Switching to ${yt} timeframe...`:"Loading real-time data..."),t.createElement("div",{className:"mt-3 flex justify-center space-x-1"},t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce"}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})))),!vt&&!gt&&!Tt&&0===Kt.length&&t.createElement("div",{className:"absolute inset-0 bg-white bg-opacity-75 flex items-center justify-center rounded-lg z-10"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"text-gray-600 mb-2"},"No ",Ot.label," market data available"),t.createElement("div",{className:"text-sm text-gray-500"},"Waiting for real-time data...")))))},exports.candleAggregation=sh,exports.candleStorageService=ih,exports.useOptimizedTokenAnalytics=Rn,exports.useSocket=kn;
|
|
7
|
+
*/const l={upColor:"#26a69a",downColor:"#ef5350",wickVisible:!0,borderVisible:!0,borderColor:"#378658",borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickColor:"#737375",wickUpColor:"#26a69a",wickDownColor:"#ef5350"},a={upColor:"#26a69a",downColor:"#ef5350",openVisible:!0,thinBars:!0},c={color:"#2196f3",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},u={topColor:"rgba( 46, 220, 135, 0.4)",bottomColor:"rgba( 40, 221, 100, 0)",invertFilledArea:!1,lineColor:"#33D778",lineStyle:0,lineWidth:3,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},d={baseValue:{type:"price",price:0},topFillColor1:"rgba(38, 166, 154, 0.28)",topFillColor2:"rgba(38, 166, 154, 0.05)",topLineColor:"rgba(38, 166, 154, 1)",bottomFillColor1:"rgba(239, 83, 80, 0.05)",bottomFillColor2:"rgba(239, 83, 80, 0.28)",bottomLineColor:"rgba(239, 83, 80, 1)",lineWidth:3,lineStyle:0,lineType:0,lineVisible:!0,crosshairMarkerVisible:!0,crosshairMarkerRadius:4,crosshairMarkerBorderColor:"",crosshairMarkerBorderWidth:2,crosshairMarkerBackgroundColor:"",lastPriceAnimation:0,pointMarkersVisible:!1},f={color:"#26a69a",base:0},m={color:"#2196f3"},p={title:"",visible:!0,lastValueVisible:!0,priceLineVisible:!0,priceLineSource:0,priceLineWidth:1,priceLineColor:"",priceLineStyle:2,baseLineVisible:!0,baseLineWidth:1,baseLineColor:"#B2B5BE",baseLineStyle:0,priceFormat:{type:"price",precision:2,minMove:.01}};var g,b,v;function w(t,e){const i={0:[],1:[t.lineWidth,t.lineWidth],2:[2*t.lineWidth,2*t.lineWidth],3:[6*t.lineWidth,6*t.lineWidth],4:[t.lineWidth,4*t.lineWidth]}[e];t.setLineDash(i)}function y(t,e,i,s){t.beginPath();const n=t.lineWidth%2?.5:0;t.moveTo(i,e+n),t.lineTo(s,e+n),t.stroke()}function C(t,e){if(!t)throw new Error("Assertion failed"+(e?": "+e:""))}function S(t){if(void 0===t)throw new Error("Value is undefined");return t}function M(t){if(null===t)throw new Error("Value is null");return t}function x(t){return M(S(t))}(v=g||(g={}))[v.Simple=0]="Simple",v[v.WithSteps=1]="WithSteps",v[v.Curved=2]="Curved",function(t){t[t.Solid=0]="Solid",t[t.Dotted=1]="Dotted",t[t.Dashed=2]="Dashed",t[t.LargeDashed=3]="LargeDashed",t[t.SparseDotted=4]="SparseDotted"}(b||(b={}));const E={khaki:"#f0e68c",azure:"#f0ffff",aliceblue:"#f0f8ff",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",gray:"#808080",green:"#008000",honeydew:"#f0fff0",floralwhite:"#fffaf0",lightblue:"#add8e6",lightcoral:"#f08080",lemonchiffon:"#fffacd",hotpink:"#ff69b4",lightyellow:"#ffffe0",greenyellow:"#adff2f",lightgoldenrodyellow:"#fafad2",limegreen:"#32cd32",linen:"#faf0e6",lightcyan:"#e0ffff",magenta:"#f0f",maroon:"#800000",olive:"#808000",orange:"#ffa500",oldlace:"#fdf5e6",mediumblue:"#0000cd",transparent:"#0000",lime:"#0f0",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",midnightblue:"#191970",orchid:"#da70d6",mediumorchid:"#ba55d3",mediumturquoise:"#48d1cc",orangered:"#ff4500",royalblue:"#4169e1",powderblue:"#b0e0e6",red:"#f00",coral:"#ff7f50",turquoise:"#40e0d0",white:"#fff",whitesmoke:"#f5f5f5",wheat:"#f5deb3",teal:"#008080",steelblue:"#4682b4",bisque:"#ffe4c4",aquamarine:"#7fffd4",aqua:"#0ff",sienna:"#a0522d",silver:"#c0c0c0",springgreen:"#00ff7f",antiquewhite:"#faebd7",burlywood:"#deb887",brown:"#a52a2a",beige:"#f5f5dc",chocolate:"#d2691e",chartreuse:"#7fff00",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cadetblue:"#5f9ea0",tomato:"#ff6347",fuchsia:"#f0f",blue:"#00f",salmon:"#fa8072",blanchedalmond:"#ffebcd",slateblue:"#6a5acd",slategray:"#708090",thistle:"#d8bfd8",tan:"#d2b48c",cyan:"#0ff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",blueviolet:"#8a2be2",black:"#000",darkmagenta:"#8b008b",darkslateblue:"#483d8b",darkkhaki:"#bdb76b",darkorchid:"#9932cc",darkorange:"#ff8c00",darkgreen:"#006400",darkred:"#8b0000",dodgerblue:"#1e90ff",darkslategray:"#2f4f4f",dimgray:"#696969",deepskyblue:"#00bfff",firebrick:"#b22222",forestgreen:"#228b22",indigo:"#4b0082",ivory:"#fffff0",lavenderblush:"#fff0f5",feldspar:"#d19275",indianred:"#cd5c5c",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightskyblue:"#87cefa",lightslategray:"#789",lightslateblue:"#8470ff",snow:"#fffafa",lightseagreen:"#20b2aa",lightsalmon:"#ffa07a",darksalmon:"#e9967a",darkviolet:"#9400d3",mediumpurple:"#9370d8",mediumaquamarine:"#66cdaa",skyblue:"#87ceeb",lavender:"#e6e6fa",lightsteelblue:"#b0c4de",mediumvioletred:"#c71585",mintcream:"#f5fffa",navajowhite:"#ffdead",navy:"#000080",olivedrab:"#6b8e23",palevioletred:"#d87093",violetred:"#d02090",yellow:"#ff0",yellowgreen:"#9acd32",lawngreen:"#7cfc00",pink:"#ffc0cb",paleturquoise:"#afeeee",palegoldenrod:"#eee8aa",darkolivegreen:"#556b2f",darkseagreen:"#8fbc8f",darkturquoise:"#00ced1",peachpuff:"#ffdab9",deeppink:"#ff1493",violet:"#ee82ee",palegreen:"#98fb98",mediumseagreen:"#3cb371",peru:"#cd853f",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",purple:"#800080",seagreen:"#2e8b57",seashell:"#fff5ee",papayawhip:"#ffefd5",mediumslateblue:"#7b68ee",plum:"#dda0dd",mediumspringgreen:"#00fa9a"};function _(t){return t<0?0:t>255?255:Math.round(t)||0}function $(t){return t<=0||t>1?Math.min(Math.max(t,0),1):Math.round(1e4*t)/1e4}const z=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i,k=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i,R=/^rgb\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*\)$/,N=/^rgba\(\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d{1,10})\s*,\s*(-?\d*\.?\d+)\s*\)$/;function T(t){(t=t.toLowerCase())in E&&(t=E[t]);{const e=N.exec(t)||R.exec(t);if(e)return[_(parseInt(e[1],10)),_(parseInt(e[2],10)),_(parseInt(e[3],10)),$(e.length<5?1:parseFloat(e[4]))]}{const e=k.exec(t);if(e)return[_(parseInt(e[1],16)),_(parseInt(e[2],16)),_(parseInt(e[3],16)),1]}{const e=z.exec(t);if(e)return[_(17*parseInt(e[1],16)),_(17*parseInt(e[2],16)),_(17*parseInt(e[3],16)),1]}throw new Error(`Cannot parse color: ${t}`)}function L(t){return.199*t[0]+.687*t[1]+.114*t[2]}function O(t){const e=T(t);return{t:`rgb(${e[0]}, ${e[1]}, ${e[2]})`,i:L(e)>160?"black":"white"}}class F{constructor(){this.h=[]}l(t,e,i){const s={o:t,_:e,u:!0===i};this.h.push(s)}v(t){const e=this.h.findIndex(e=>t===e.o);e>-1&&this.h.splice(e,1)}p(t){this.h=this.h.filter(e=>e._!==t)}m(t,e,i){const s=[...this.h];this.h=this.h.filter(t=>!t.u),s.forEach(s=>s.o(t,e,i))}M(){return this.h.length>0}S(){this.h=[]}}function P(t,...e){for(const i of e)for(const e in i)void 0!==i[e]&&Object.prototype.hasOwnProperty.call(i,e)&&!["__proto__","constructor","prototype"].includes(e)&&("object"!=typeof i[e]||void 0===t[e]||Array.isArray(i[e])?t[e]=i[e]:P(t[e],i[e]));return t}function D(t){return"number"==typeof t&&isFinite(t)}function V(t){return"number"==typeof t&&t%1==0}function I(t){return"string"==typeof t}function B(t){return"boolean"==typeof t}function A(t){const e=t;if(!e||"object"!=typeof e)return e;let i,s,n;for(s in i=Array.isArray(e)?[]:{},e)e.hasOwnProperty(s)&&(n=e[s],i[s]=n&&"object"==typeof n?A(n):n);return i}function U(t){return null!==t}function W(t){return null===t?void 0:t}const j="-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif";function H(t,e,i){return void 0===e&&(e=j),`${i=void 0!==i?`${i} `:""}${t}px ${e}`}class K{constructor(t){this.k={C:1,T:5,P:NaN,R:"",D:"",V:"",O:"",B:0,A:0,I:0,L:0,N:0},this.F=t}W(){const t=this.k,e=this.j(),i=this.H();return t.P===e&&t.D===i||(t.P=e,t.D=i,t.R=H(e,i),t.L=2.5/12*e,t.B=t.L,t.A=e/12*t.T,t.I=e/12*t.T,t.N=0),t.V=this.$(),t.O=this.U(),this.k}$(){return this.F.W().layout.textColor}U(){return this.F.q()}j(){return this.F.W().layout.fontSize}H(){return this.F.W().layout.fontFamily}}class q{constructor(){this.Y=[]}Z(t){this.Y=t}X(t,e,i){this.Y.forEach(s=>{s.X(t,e,i)})}}class X{X(t,e,i){t.useBitmapCoordinateSpace(t=>this.K(t,e,i))}}class J extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.G||null===this.G.tt)return;const s=this.G.tt,n=this.G,r=Math.max(1,Math.floor(e))%2/2,o=o=>{t.beginPath();for(let h=s.to-1;h>=s.from;--h){const s=n.it[h],l=Math.round(s.nt*e)+r,a=s.st*i,c=o*i+r;t.moveTo(l,a),t.arc(l,a,c,0,2*Math.PI)}t.fill()};n.et>0&&(t.fillStyle=n.rt,o(n.ht+n.et)),t.fillStyle=n.lt,o(n.ht)}}function G(){return{it:[{nt:0,st:0,ot:0,_t:0}],lt:"",rt:"",ht:0,et:0,tt:null}}const Q={from:0,to:1};class Y{constructor(t,e){this.ut=new q,this.ct=[],this.dt=[],this.ft=!0,this.F=t,this.vt=e,this.ut.Z(this.ct)}bt(t){const e=this.F.wt();e.length!==this.ct.length&&(this.dt=e.map(G),this.ct=this.dt.map(t=>{const e=new J;return e.J(t),e}),this.ut.Z(this.ct)),this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.ut}Mt(){const t=2===this.vt.W().mode,e=this.F.wt(),i=this.vt.xt(),s=this.F.St();e.forEach((e,n)=>{var r;const o=this.dt[n],h=e.kt(i);if(t||null===h||!e.yt())return void(o.tt=null);const l=M(e.Ct());o.lt=h.Tt,o.ht=h.ht,o.et=h.Pt,o.it[0]._t=h._t,o.it[0].st=e.Dt().Rt(h._t,l.Vt),o.rt=null!==(r=h.Ot)&&void 0!==r?r:this.F.Bt(o.it[0].st/e.Dt().At()),o.it[0].ot=i,o.it[0].nt=s.It(i),o.tt=Q})}}class Z extends X{constructor(t){super(),this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;const n=this.zt.Lt.yt,r=this.zt.Et.yt;if(!n&&!r)return;const o=Math.round(this.zt.nt*i),h=Math.round(this.zt.st*s);t.lineCap="butt",n&&o>=0&&(t.lineWidth=Math.floor(this.zt.Lt.et*i),t.strokeStyle=this.zt.Lt.V,t.fillStyle=this.zt.Lt.V,w(t,this.zt.Lt.Nt),function(t,e,i,s){t.beginPath();const n=t.lineWidth%2?.5:0;t.moveTo(e+n,0),t.lineTo(e+n,s),t.stroke()}(t,o,0,e.height)),r&&h>=0&&(t.lineWidth=Math.floor(this.zt.Et.et*s),t.strokeStyle=this.zt.Et.V,t.fillStyle=this.zt.Et.V,w(t,this.zt.Et.Nt),y(t,h,0,e.width))}}class tt{constructor(t){this.ft=!0,this.Ft={Lt:{et:1,Nt:0,V:"",yt:!1},Et:{et:1,Nt:0,V:"",yt:!1},nt:0,st:0},this.Wt=new Z(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.yt(),e=M(this.jt.Ht()),i=e.$t().W().crosshair,s=this.Ft;if(2===i.mode)return s.Et.yt=!1,void(s.Lt.yt=!1);s.Et.yt=t&&this.jt.Ut(e),s.Lt.yt=t&&this.jt.qt(),s.Et.et=i.horzLine.width,s.Et.Nt=i.horzLine.style,s.Et.V=i.horzLine.color,s.Lt.et=i.vertLine.width,s.Lt.Nt=i.vertLine.style,s.Lt.V=i.vertLine.color,s.nt=this.jt.Yt(),s.st=this.jt.Zt()}}function et(t,e,i,s,n,r){t.fillRect(e+r,i,s-2*r,r),t.fillRect(e+r,i+n-r,s-2*r,r),t.fillRect(e,i,r,n),t.fillRect(e+s-r,i,r,n)}function it(t,e,i,s,n,r){t.save(),t.globalCompositeOperation="copy",t.fillStyle=r,t.fillRect(e,i,s,n),t.restore()}function st(t,e,i,s,n,r){t.beginPath(),t.roundRect?t.roundRect(e,i,s,n,r):(t.lineTo(e+s-r[1],i),0!==r[1]&&t.arcTo(e+s,i,e+s,i+r[1],r[1]),t.lineTo(e+s,i+n-r[2]),0!==r[2]&&t.arcTo(e+s,i+n,e+s-r[2],i+n,r[2]),t.lineTo(e+r[3],i+n),0!==r[3]&&t.arcTo(e,i+n,e,i+n-r[3],r[3]),t.lineTo(e,i+r[0]),0!==r[0]&&t.arcTo(e,i,e+r[0],i,r[0]))}function nt(t,e,i,s,n,r,o=0,h=[0,0,0,0],l=""){if(t.save(),!o||!l||l===r)return st(t,e,i,s,n,h),t.fillStyle=r,t.fill(),void t.restore();const a=o/2;var c;st(t,e+a,i+a,s-o,n-o,(c=-a,h.map(t=>0===t?t:t+c))),"transparent"!==r&&(t.fillStyle=r,t.fill()),"transparent"!==l&&(t.lineWidth=o,t.strokeStyle=l,t.closePath(),t.stroke()),t.restore()}function rt(t,e,i,s,n,r,o){t.save(),t.globalCompositeOperation="copy";const h=t.createLinearGradient(0,0,0,n);h.addColorStop(0,r),h.addColorStop(1,o),t.fillStyle=h,t.fillRect(e,i,s,n),t.restore()}class ot{constructor(t,e){this.J(t,e)}J(t,e){this.zt=t,this.Xt=e}At(t,e){return this.zt.yt?t.P+t.L+t.B:0}X(t,e,i,s){if(!this.zt.yt||0===this.zt.Kt.length)return;const n=this.zt.V,r=this.Xt.t,o=t.useBitmapCoordinateSpace(t=>{const o=t.context;o.font=e.R;const h=this.Gt(t,e,i,s),l=h.Jt;return h.Qt?nt(o,l.ti,l.ii,l.ni,l.si,r,l.ei,[l.ht,0,0,l.ht],r):nt(o,l.ri,l.ii,l.ni,l.si,r,l.ei,[0,l.ht,l.ht,0],r),this.zt.hi&&(o.fillStyle=n,o.fillRect(l.ri,l.li,l.ai-l.ri,l.oi)),this.zt._i&&(o.fillStyle=e.O,o.fillRect(h.Qt?l.ui-l.ei:0,l.ii,l.ei,l.ci-l.ii)),h});t.useMediaCoordinateSpace(({context:t})=>{const i=o.di;t.font=e.R,t.textAlign=o.Qt?"right":"left",t.textBaseline="middle",t.fillStyle=n,t.fillText(this.zt.Kt,i.fi,(i.ii+i.ci)/2+i.pi)})}Gt(t,e,i,s){var n;const{context:r,bitmapSize:o,mediaSize:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,c=this.zt.hi||!this.zt.mi?e.T:0,u=this.zt.bi?e.C:0,d=e.L+this.Xt.wi,f=e.B+this.Xt.gi,m=e.A,p=e.I,g=this.zt.Kt,b=e.P,v=i.Mi(r,g),w=Math.ceil(i.xi(r,g)),y=b+d+f,C=e.C+m+p+w+c,S=Math.max(1,Math.floor(a));let M=Math.round(y*a);M%2!=S%2&&(M+=1);const x=u>0?Math.max(1,Math.floor(u*l)):0,E=Math.round(C*l),_=Math.round(c*l),$=null!==(n=this.Xt.Si)&&void 0!==n?n:this.Xt.ki,z=Math.round($*a)-Math.floor(.5*a),k=Math.floor(z+S/2-M/2),R=k+M,N="right"===s,T=N?h.width-u:u,L=N?o.width-x:x;let O,F,P;return N?(O=L-E,F=L-_,P=T-c-m-u):(O=L+E,F=L+_,P=T+c+m),{Qt:N,Jt:{ii:k,li:z,ci:R,ni:E,si:M,ht:2*l,ei:x,ti:O,ri:L,ai:F,oi:S,ui:o.width},di:{ii:k/a,ci:R/a,fi:P,pi:v}}}}class ht{constructor(t){this.yi={ki:0,t:"#000",gi:0,wi:0},this.Ci={Kt:"",yt:!1,hi:!0,mi:!1,Ot:"",V:"#FFF",_i:!1,bi:!1},this.Ti={Kt:"",yt:!1,hi:!1,mi:!0,Ot:"",V:"#FFF",_i:!0,bi:!0},this.ft=!0,this.Pi=new(t||ot)(this.Ci,this.yi),this.Ri=new(t||ot)(this.Ti,this.yi)}Kt(){return this.Di(),this.Ci.Kt}ki(){return this.Di(),this.yi.ki}bt(){this.ft=!0}At(t,e=!1){return Math.max(this.Pi.At(t,e),this.Ri.At(t,e))}Vi(){return this.yi.Si||0}Oi(t){this.yi.Si=t}Bi(){return this.Di(),this.Ci.yt||this.Ti.yt}Ai(){return this.Di(),this.Ci.yt}gt(t){return this.Di(),this.Ci.hi=this.Ci.hi&&t.W().ticksVisible,this.Ti.hi=this.Ti.hi&&t.W().ticksVisible,this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Pi}Ii(){return this.Di(),this.Pi.J(this.Ci,this.yi),this.Ri.J(this.Ti,this.yi),this.Ri}Di(){this.ft&&(this.Ci.hi=!0,this.Ti.hi=!1,this.zi(this.Ci,this.Ti,this.yi))}}class lt extends ht{constructor(t,e,i){super(),this.jt=t,this.Li=e,this.Ei=i}zi(t,e,i){if(t.yt=!1,2===this.jt.W().mode)return;const s=this.jt.W().horzLine;if(!s.labelVisible)return;const n=this.Li.Ct();if(!this.jt.yt()||this.Li.Ni()||null===n)return;const r=O(s.labelBackgroundColor);i.t=r.t,t.V=r.i;const o=2/12*this.Li.P();i.wi=o,i.gi=o;const h=this.Ei(this.Li);i.ki=h.ki,t.Kt=this.Li.Fi(h._t,n),t.yt=!0}}const at=/[1-9]/g;class ct{constructor(){this.zt=null}J(t){this.zt=t}X(t,e){if(null===this.zt||!1===this.zt.yt||0===this.zt.Kt.length)return;const i=t.useMediaCoordinateSpace(({context:t})=>(t.font=e.R,Math.round(e.Wi.xi(t,M(this.zt).Kt,at))));if(i<=0)return;const s=e.ji,n=i+2*s,r=n/2,o=this.zt.Hi;let h=this.zt.ki,l=Math.floor(h-r)+.5;l<0?(h+=Math.abs(0-l),l=Math.floor(h-r)+.5):l+n>o&&(h-=Math.abs(o-(l+n)),l=Math.floor(h-r)+.5);const a=l+n,c=Math.ceil(0+e.C+e.T+e.L+e.P+e.B);t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:i,verticalPixelRatio:s})=>{const n=M(this.zt);t.fillStyle=n.t;const r=Math.round(l*i),o=Math.round(0*s),h=Math.round(a*i),u=Math.round(c*s),d=Math.round(2*i);if(t.beginPath(),t.moveTo(r,o),t.lineTo(r,u-d),t.arcTo(r,u,r+d,u,d),t.lineTo(h-d,u),t.arcTo(h,u,h,u-d,d),t.lineTo(h,o),t.fill(),n.hi){const r=Math.round(n.ki*i),h=o,l=Math.round((h+e.T)*s);t.fillStyle=n.V;const a=Math.max(1,Math.floor(i)),c=Math.floor(.5*i);t.fillRect(r-c,h,a,l-h)}}),t.useMediaCoordinateSpace(({context:t})=>{const i=M(this.zt),n=0+e.C+e.T+e.L+e.P/2;t.font=e.R,t.textAlign="left",t.textBaseline="middle",t.fillStyle=i.V;const r=e.Wi.Mi(t,"Apr0");t.translate(l+s,n+r),t.fillText(i.Kt,0,0)})}}class ut{constructor(t,e,i){this.ft=!0,this.Wt=new ct,this.Ft={yt:!1,t:"#4c525e",V:"white",Kt:"",Hi:0,ki:NaN,hi:!0},this.vt=t,this.$i=e,this.Ei=i}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt.J(this.Ft),this.Wt}Mt(){const t=this.Ft;if(t.yt=!1,2===this.vt.W().mode)return;const e=this.vt.W().vertLine;if(!e.labelVisible)return;const i=this.$i.St();if(i.Ni())return;t.Hi=i.Hi();const s=this.Ei();if(null===s)return;t.ki=s.ki;const n=i.Ui(this.vt.xt());t.Kt=i.qi(M(n)),t.yt=!0;const r=O(e.labelBackgroundColor);t.t=r.t,t.V=r.i,t.hi=i.W().ticksVisible}}class dt{constructor(){this.Yi=null,this.Zi=0}Xi(){return this.Zi}Ki(t){this.Zi=t}Dt(){return this.Yi}Gi(t){this.Yi=t}Ji(t){return[]}Qi(){return[]}yt(){return!0}}var ft;!function(t){t[t.Normal=0]="Normal",t[t.Magnet=1]="Magnet",t[t.Hidden=2]="Hidden"}(ft||(ft={}));class mt extends dt{constructor(t,e){super(),this.tn=null,this.nn=NaN,this.sn=0,this.en=!0,this.rn=new Map,this.hn=!1,this.ln=NaN,this.an=NaN,this._n=NaN,this.un=NaN,this.$i=t,this.cn=e,this.dn=new Y(t,this),this.fn=((t,e)=>i=>{const s=e(),n=t();if(i===M(this.tn).vn())return{_t:n,ki:s};{const t=M(i.Ct());return{_t:i.pn(s,t),ki:s}}})(()=>this.nn,()=>this.an);const i=((t,e)=>()=>{const i=this.$i.St().mn(t()),s=e();return i&&Number.isFinite(s)?{ot:i,ki:s}:null})(()=>this.sn,()=>this.Yt());this.bn=new ut(this,t,i),this.wn=new tt(this)}W(){return this.cn}gn(t,e){this._n=t,this.un=e}Mn(){this._n=NaN,this.un=NaN}xn(){return this._n}Sn(){return this.un}kn(t,e,i){this.hn||(this.hn=!0),this.en=!0,this.yn(t,e,i)}xt(){return this.sn}Yt(){return this.ln}Zt(){return this.an}yt(){return this.en}Cn(){this.en=!1,this.Tn(),this.nn=NaN,this.ln=NaN,this.an=NaN,this.tn=null,this.Mn()}Pn(t){return null!==this.tn?[this.wn,this.dn]:[]}Ut(t){return t===this.tn&&this.cn.horzLine.visible}qt(){return this.cn.vertLine.visible}Rn(t,e){this.en&&this.tn===t||this.rn.clear();const i=[];return this.tn===t&&i.push(this.Dn(this.rn,e,this.fn)),i}Qi(){return this.en?[this.bn]:[]}Ht(){return this.tn}Vn(){this.wn.bt(),this.rn.forEach(t=>t.bt()),this.bn.bt(),this.dn.bt()}On(t){return t&&!t.vn().Ni()?t.vn():null}yn(t,e,i){this.Bn(t,e,i)&&this.Vn()}Bn(t,e,i){const s=this.ln,n=this.an,r=this.nn,o=this.sn,h=this.tn,l=this.On(i);this.sn=t,this.ln=isNaN(t)?NaN:this.$i.St().It(t),this.tn=i;const a=null!==l?l.Ct():null;return null!==l&&null!==a?(this.nn=e,this.an=l.Rt(e,a)):(this.nn=NaN,this.an=NaN),s!==this.ln||n!==this.an||o!==this.sn||r!==this.nn||h!==this.tn}Tn(){const t=this.$i.wt().map(t=>t.In().An()).filter(U),e=0===t.length?null:Math.max(...t);this.sn=null!==e?e:NaN}Dn(t,e,i){let s=t.get(e);return void 0===s&&(s=new lt(this,e,i),t.set(e,s)),s}}function pt(t){return"left"===t||"right"===t}class gt{constructor(t){this.zn=new Map,this.Ln=[],this.En=t}Nn(t,e){const i=function(t,e){return void 0===t?e:{Fn:Math.max(t.Fn,e.Fn),Wn:t.Wn||e.Wn}}(this.zn.get(t),e);this.zn.set(t,i)}jn(){return this.En}Hn(t){const e=this.zn.get(t);return void 0===e?{Fn:this.En}:{Fn:Math.max(this.En,e.Fn),Wn:e.Wn}}$n(){this.Un(),this.Ln=[{qn:0}]}Yn(t){this.Un(),this.Ln=[{qn:1,Vt:t}]}Zn(t){this.Xn(),this.Ln.push({qn:5,Vt:t})}Un(){this.Xn(),this.Ln.push({qn:6})}Kn(){this.Un(),this.Ln=[{qn:4}]}Gn(t){this.Un(),this.Ln.push({qn:2,Vt:t})}Jn(t){this.Un(),this.Ln.push({qn:3,Vt:t})}Qn(){return this.Ln}ts(t){for(const e of t.Ln)this.ns(e);this.En=Math.max(this.En,t.En),t.zn.forEach((t,e)=>{this.Nn(e,t)})}static ss(){return new gt(2)}static es(){return new gt(3)}ns(t){switch(t.qn){case 0:this.$n();break;case 1:this.Yn(t.Vt);break;case 2:this.Gn(t.Vt);break;case 3:this.Jn(t.Vt);break;case 4:this.Kn();break;case 5:this.Zn(t.Vt);break;case 6:this.Xn()}}Xn(){const t=this.Ln.findIndex(t=>5===t.qn);-1!==t&&this.Ln.splice(t,1)}}function bt(t,e){if(!D(t))return"n/a";if(!V(e))throw new TypeError("invalid length");if(e<0||e>16)throw new TypeError("invalid length");return 0===e?t.toString():("0000000000000000"+t.toString()).slice(-e)}class vt{constructor(t,e){if(e||(e=1),D(t)&&V(t)||(t=100),t<0)throw new TypeError("invalid base");this.Li=t,this.rs=e,this.hs()}format(t){const e=t<0?"−":"";return t=Math.abs(t),e+this.ls(t)}hs(){if(this._s=0,this.Li>0&&this.rs>0){let t=this.Li;for(;t>1;)t/=10,this._s++}}ls(t){const e=this.Li/this.rs;let i=Math.floor(t),s="";const n=void 0!==this._s?this._s:NaN;if(e>1){let r=+(Math.round(t*e)-i*e).toFixed(this._s);r>=e&&(r-=e,i+=1),s="."+bt(+r.toFixed(this._s)*this.rs,n)}else i=Math.round(i*e)/e,n>0&&(s="."+bt(0,n));return i.toFixed(0)+s}}class wt extends vt{constructor(t=100){super(t)}format(t){return`${super.format(t)}%`}}class yt{constructor(t){this.us=t}format(t){let e="";return t<0&&(e="-",t=-t),t<995?e+this.cs(t):t<999995?e+this.cs(t/1e3)+"K":t<999999995?(t=1e3*Math.round(t/1e3),e+this.cs(t/1e6)+"M"):(t=1e6*Math.round(t/1e6),e+this.cs(t/1e9)+"B")}cs(t){let e;const i=Math.pow(10,this.us);return e=(t=Math.round(t*i)/i)>=1e-15&&t<1?t.toFixed(this.us).replace(/\.?0+$/,""):String(t),e.replace(/(\.[1-9]*)0+$/,(t,e)=>e)}}function Ct(t,e,i,s,n,r,o){if(0===e.length||s.from>=e.length||s.to<=0)return;const{context:h,horizontalPixelRatio:l,verticalPixelRatio:a}=t,c=e[s.from];let u=r(t,c),d=c;if(s.to-s.from<2){const e=n/2;h.beginPath();const i={nt:c.nt-e,st:c.st},s={nt:c.nt+e,st:c.st};h.moveTo(i.nt*l,i.st*a),h.lineTo(s.nt*l,s.st*a),o(t,u,i,s)}else{const n=(e,i)=>{o(t,u,d,i),h.beginPath(),u=e,d=i};let f=d;h.beginPath(),h.moveTo(c.nt*l,c.st*a);for(let o=s.from+1;o<s.to;++o){f=e[o];const s=r(t,f);switch(i){case 0:h.lineTo(f.nt*l,f.st*a);break;case 1:h.lineTo(f.nt*l,e[o-1].st*a),s!==u&&(n(s,f),h.lineTo(f.nt*l,e[o-1].st*a)),h.lineTo(f.nt*l,f.st*a);break;case 2:{const[t,i]=Et(e,o-1,o);h.bezierCurveTo(t.nt*l,t.st*a,i.nt*l,i.st*a,f.nt*l,f.st*a);break}}1!==i&&s!==u&&(n(s,f),h.moveTo(f.nt*l,f.st*a))}(d!==f||d===f&&1===i)&&o(t,u,d,f)}}const St=6;function Mt(t,e){return{nt:t.nt-e.nt,st:t.st-e.st}}function xt(t,e){return{nt:t.nt/e,st:t.st/e}}function Et(t,e,i){const s=Math.max(0,e-1),n=Math.min(t.length-1,i+1);var r,o;return[(r=t[e],o=xt(Mt(t[i],t[s]),St),{nt:r.nt+o.nt,st:r.st+o.st}),Mt(t[i],xt(Mt(t[n],t[e]),St))]}function _t(t,e,i,s,n){const{context:r,horizontalPixelRatio:o,verticalPixelRatio:h}=e;r.lineTo(n.nt*o,t*h),r.lineTo(s.nt*o,t*h),r.closePath(),r.fillStyle=i,r.fill()}class $t extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){var e;if(null===this.G)return;const{it:i,tt:s,ds:n,et:r,Nt:o,fs:h}=this.G,l=null!==(e=this.G.vs)&&void 0!==e?e:this.G.ps?0:t.mediaSize.height;if(null===s)return;const a=t.context;a.lineCap="butt",a.lineJoin="round",a.lineWidth=r,w(a,o),a.lineWidth=1,Ct(t,i,h,s,n,this.bs.bind(this),_t.bind(null,l))}}function zt(t,e,i){return Math.min(Math.max(t,e),i)}function kt(t,e,i){return e-t<=i}function Rt(t){const e=Math.ceil(t);return e%2==0?e-1:e}class Nt{ws(t,e){const i=this.gs,{Ms:s,xs:n,Ss:r,ks:o,ys:h,vs:l}=e;if(void 0===this.Cs||void 0===i||i.Ms!==s||i.xs!==n||i.Ss!==r||i.ks!==o||i.vs!==l||i.ys!==h){const i=t.context.createLinearGradient(0,0,0,h);if(i.addColorStop(0,s),null!=l){const e=zt(l*t.verticalPixelRatio/h,0,1);i.addColorStop(e,n),i.addColorStop(e,r)}i.addColorStop(1,o),this.Cs=i,this.gs=e}return this.Cs}}class Tt extends $t{constructor(){super(...arguments),this.Ts=new Nt}bs(t,e){return this.Ts.ws(t,{Ms:e.Ps,xs:"",Ss:"",ks:e.Rs,ys:t.bitmapSize.height})}}function Lt(t,e){const i=t.context;i.strokeStyle=e,i.stroke()}class Ot extends X{constructor(){super(...arguments),this.G=null}J(t){this.G=t}K(t){if(null===this.G)return;const{it:e,tt:i,ds:s,fs:n,et:r,Nt:o,Ds:h}=this.G;if(null===i)return;const l=t.context;l.lineCap="butt",l.lineWidth=r*t.verticalPixelRatio,w(l,o),l.lineJoin="round";const a=this.Vs.bind(this);void 0!==n&&Ct(t,e,n,i,s,a,Lt),h&&function(t,e,i,s,n){const{horizontalPixelRatio:r,verticalPixelRatio:o,context:h}=t;let l=null;const a=Math.max(1,Math.floor(r))%2/2,c=i*o+a;for(let i=s.to-1;i>=s.from;--i){const s=e[i];if(s){const e=n(t,s);e!==l&&(h.beginPath(),null!==l&&h.fill(),h.fillStyle=e,l=e);const i=Math.round(s.nt*r)+a,u=s.st*o;h.moveTo(i,u),h.arc(i,u,c,0,2*Math.PI)}}h.fill()}(t,e,h,i,a)}}class Ft extends Ot{Vs(t,e){return e.lt}}function Pt(t,e,i,s,n=0,r=e.length){let o=r-n;for(;0<o;){const r=o>>1,h=n+r;s(e[h],i)===t?(n=h+1,o-=r+1):o=r}return n}const Dt=Pt.bind(null,!0),Vt=Pt.bind(null,!1);function It(t,e){return t.ot<e}function Bt(t,e){return e<t.ot}function At(t,e,i){const s=e.Os(),n=e.ui(),r=Dt(t,s,It),o=Vt(t,n,Bt);if(!i)return{from:r,to:o};let h=r,l=o;return r>0&&r<t.length&&t[r].ot>=s&&(h=r-1),o>0&&o<t.length&&t[o-1].ot<=n&&(l=o+1),{from:h,to:l}}class Ut{constructor(t,e,i){this.Bs=!0,this.As=!0,this.Is=!0,this.zs=[],this.Ls=null,this.Es=t,this.Ns=e,this.Fs=i}bt(t){this.Bs=!0,"data"===t&&(this.As=!0),"options"===t&&(this.Is=!0)}gt(){return this.Es.yt()?(this.Ws(),null===this.Ls?null:this.js):null}Hs(){this.zs=this.zs.map(t=>Object.assign(Object.assign({},t),this.Es.Us().$s(t.ot)))}qs(){this.Ls=null}Ws(){this.As&&(this.Ys(),this.As=!1),this.Is&&(this.Hs(),this.Is=!1),this.Bs&&(this.Zs(),this.Bs=!1)}Zs(){const t=this.Es.Dt(),e=this.Ns.St();if(this.qs(),e.Ni()||t.Ni())return;const i=e.Xs();if(null===i)return;if(0===this.Es.In().Ks())return;const s=this.Es.Ct();null!==s&&(this.Ls=At(this.zs,i,this.Fs),this.Gs(t,e,s.Vt),this.Js())}}class Wt extends Ut{constructor(t,e){super(t,e,!0)}Gs(t,e,i){e.Qs(this.zs,W(this.Ls)),t.te(this.zs,i,W(this.Ls))}ie(t,e){return{ot:t,_t:e,nt:NaN,st:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>{const i=e.Vt[3];return this.se(e.ee,i,t)})}}class jt extends Wt{constructor(t,e){super(t,e),this.js=new q,this.re=new Tt,this.he=new Ft,this.js.Z([this.re,this.he])}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.W();this.re.J({fs:t.lineType,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,vs:null,ps:t.invertFilledArea,tt:this.Ls,ds:this.Ns.St().le()}),this.he.J({fs:t.lineVisible?t.lineType:void 0,it:this.zs,Nt:t.lineStyle,et:t.lineWidth,tt:this.Ls,ds:this.Ns.St().le(),Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0})}}class Ht extends X{constructor(){super(...arguments),this.zt=null,this.ae=0,this.oe=0}J(t){this.zt=t}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.zt||0===this.zt.In.length||null===this.zt.tt)return;this.ae=this._e(e),this.ae>=2&&Math.max(1,Math.floor(e))%2!=this.ae%2&&this.ae--,this.oe=this.zt.ue?Math.min(this.ae,Math.floor(e)):this.ae;let s=null;const n=this.oe<=this.ae&&this.zt.le>=Math.floor(1.5*e);for(let r=this.zt.tt.from;r<this.zt.tt.to;++r){const o=this.zt.In[r];s!==o.ce&&(t.fillStyle=o.ce,s=o.ce);const h=Math.floor(.5*this.oe),l=Math.round(o.nt*e),a=l-h,c=this.oe,u=a+c-1,d=Math.min(o.de,o.fe),f=Math.max(o.de,o.fe),m=Math.round(d*i)-h,p=Math.round(f*i)+h,g=Math.max(p-m,this.oe);t.fillRect(a,m,c,g);const b=Math.ceil(1.5*this.ae);if(n){if(this.zt.ve){const e=l-b;let s=Math.max(m,Math.round(o.pe*i)-h),n=s+c-1;n>m+g-1&&(n=m+g-1,s=n-c+1),t.fillRect(e,s,a-e,n-s+1)}const e=l+b;let s=Math.max(m,Math.round(o.me*i)-h),n=s+c-1;n>m+g-1&&(n=m+g-1,s=n-c+1),t.fillRect(u+1,s,e-u,n-s+1)}}}_e(t){const e=Math.floor(t);return Math.max(e,Math.floor(function(t,e){return Math.floor(.3*t*e)}(M(this.zt).le,t)))}}class Kt extends Ut{constructor(t,e){super(t,e,!1)}Gs(t,e,i){e.Qs(this.zs,W(this.Ls)),t.be(this.zs,i,W(this.Ls))}we(t,e,i){return{ot:t,ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3],nt:NaN,pe:NaN,de:NaN,fe:NaN,me:NaN}}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>this.se(e.ee,e,t))}}class qt extends Kt{constructor(){super(...arguments),this.js=new Ht}se(t,e,i){return Object.assign(Object.assign({},this.we(t,e,i)),i.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),ve:t.openVisible,ue:t.thinBars,tt:this.Ls})}}class Xt extends $t{constructor(){super(...arguments),this.Ts=new Nt}bs(t,e){const i=this.G;return this.Ts.ws(t,{Ms:e.ke,xs:e.ye,Ss:e.Ce,ks:e.Te,ys:t.bitmapSize.height,vs:i.vs})}}class Jt extends Ot{constructor(){super(...arguments),this.Pe=new Nt}Vs(t,e){const i=this.G;return this.Pe.ws(t,{Ms:e.Re,xs:e.Re,Ss:e.De,ks:e.De,ys:t.bitmapSize.height,vs:i.vs})}}class Gt extends Wt{constructor(t,e){super(t,e),this.js=new q,this.Ve=new Xt,this.Oe=new Jt,this.js.Z([this.Ve,this.Oe])}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.Ct();if(null===t)return;const e=this.Es.W(),i=this.Es.Dt().Rt(e.baseValue.price,t.Vt),s=this.Ns.St().le();this.Ve.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineType,vs:i,ps:!1,tt:this.Ls,ds:s}),this.Oe.J({it:this.zs,et:e.lineWidth,Nt:e.lineStyle,fs:e.lineVisible?e.lineType:void 0,Ds:e.pointMarkersVisible?e.pointMarkersRadius||e.lineWidth/2+2:void 0,vs:i,tt:this.Ls,ds:s})}}class Qt extends X{constructor(){super(...arguments),this.zt=null,this.ae=0}J(t){this.zt=t}K(t){if(null===this.zt||0===this.zt.In.length||null===this.zt.tt)return;const{horizontalPixelRatio:e}=t;this.ae=function(t,e){if(t>=2.5&&t<=4)return Math.floor(3*e);const i=1-.2*Math.atan(Math.max(4,t)-4)/(.5*Math.PI),s=Math.floor(t*i*e),n=Math.floor(t*e),r=Math.min(s,n);return Math.max(Math.floor(e),r)}(this.zt.le,e),this.ae>=2&&Math.floor(e)%2!=this.ae%2&&this.ae--;const i=this.zt.In;this.zt.Be&&this.Ae(t,i,this.zt.tt),this.zt._i&&this.Ie(t,i,this.zt.tt);const s=this.ze(e);(!this.zt._i||this.ae>2*s)&&this.Le(t,i,this.zt.tt)}Ae(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="",h=Math.min(Math.floor(n),Math.floor(this.zt.le*n));h=Math.max(Math.floor(n),Math.min(h,this.ae));const l=Math.floor(.5*h);let a=null;for(let t=i.from;t<i.to;t++){const i=e[t];i.Ee!==o&&(s.fillStyle=i.Ee,o=i.Ee);const c=Math.round(Math.min(i.pe,i.me)*r),u=Math.round(Math.max(i.pe,i.me)*r),d=Math.round(i.de*r),f=Math.round(i.fe*r);let m=Math.round(n*i.nt)-l;const p=m+h-1;null!==a&&(m=Math.max(a+1,m),m=Math.min(m,p));const g=p-m+1;s.fillRect(m,d,g,c-d),s.fillRect(m,u+1,g,f-u),a=p}}ze(t){let e=Math.floor(1*t);this.ae<=2*e&&(e=Math.floor(.5*(this.ae-1)));const i=Math.max(Math.floor(t),e);return this.ae<=2*i?Math.max(Math.floor(t),Math.floor(1*t)):i}Ie(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="";const h=this.ze(n);let l=null;for(let t=i.from;t<i.to;t++){const i=e[t];i.Ne!==o&&(s.fillStyle=i.Ne,o=i.Ne);let a=Math.round(i.nt*n)-Math.floor(.5*this.ae);const c=a+this.ae-1,u=Math.round(Math.min(i.pe,i.me)*r),d=Math.round(Math.max(i.pe,i.me)*r);if(null!==l&&(a=Math.max(l+1,a),a=Math.min(a,c)),this.zt.le*n>2*h)et(s,a,u,c-a+1,d-u+1,h);else{const t=c-a+1;s.fillRect(a,u,t,d-u+1)}l=c}}Le(t,e,i){if(null===this.zt)return;const{context:s,horizontalPixelRatio:n,verticalPixelRatio:r}=t;let o="";const h=this.ze(n);for(let t=i.from;t<i.to;t++){const i=e[t];let l=Math.round(Math.min(i.pe,i.me)*r),a=Math.round(Math.max(i.pe,i.me)*r),c=Math.round(i.nt*n)-Math.floor(.5*this.ae),u=c+this.ae-1;if(i.ce!==o){const t=i.ce;s.fillStyle=t,o=t}this.zt._i&&(c+=h,l+=h,u-=h,a-=h),l>a||s.fillRect(c,l,u-c+1,a-l+1)}}}class Yt extends Kt{constructor(){super(...arguments),this.js=new Qt}se(t,e,i){return Object.assign(Object.assign({},this.we(t,e,i)),i.$s(t))}Js(){const t=this.Es.W();this.js.J({In:this.zs,le:this.Ns.St().le(),Be:t.wickVisible,_i:t.borderVisible,tt:this.Ls})}}class Zt{constructor(t,e){this.Fe=t,this.Li=e}X(t,e,i){this.Fe.draw(t,this.Li,e,i)}}class te extends Ut{constructor(t,e,i){super(t,e,!1),this.wn=i,this.js=new Zt(this.wn.renderer(),e=>{const i=t.Ct();return null===i?null:t.Dt().Rt(e,i.Vt)})}We(t){return this.wn.priceValueBuilder(t)}je(t){return this.wn.isWhitespace(t)}Ys(){const t=this.Es.Us();this.zs=this.Es.In().ne().map(e=>Object.assign(Object.assign({ot:e.ee,nt:NaN},t.$s(e.ee)),{He:e.$e}))}Gs(t,e){e.Qs(this.zs,W(this.Ls))}Js(){this.wn.update({bars:this.zs.map(ee),barSpacing:this.Ns.St().le(),visibleRange:this.Ls},this.Es.W())}}function ee(t){return{x:t.nt,time:t.ot,originalData:t.He,barColor:t.ce}}class ie extends X{constructor(){super(...arguments),this.zt=null,this.Ue=[]}J(t){this.zt=t,this.Ue=[]}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){if(null===this.zt||0===this.zt.it.length||null===this.zt.tt)return;this.Ue.length||this.qe(e);const s=Math.max(1,Math.floor(i)),n=Math.round(this.zt.Ye*i)-Math.floor(s/2),r=n+s;for(let e=this.zt.tt.from;e<this.zt.tt.to;e++){const o=this.zt.it[e],h=this.Ue[e-this.zt.tt.from],l=Math.round(o.st*i);let a,c;t.fillStyle=o.ce,l<=n?(a=l,c=r):(a=n,c=l-Math.floor(s/2)+s),t.fillRect(h.Os,a,h.ui-h.Os+1,c-a)}}qe(t){if(null===this.zt||0===this.zt.it.length||null===this.zt.tt)return void(this.Ue=[]);const e=Math.ceil(this.zt.le*t)<=1?0:Math.max(1,Math.floor(t)),i=Math.round(this.zt.le*t)-e;this.Ue=new Array(this.zt.tt.to-this.zt.tt.from);for(let e=this.zt.tt.from;e<this.zt.tt.to;e++){const s=this.zt.it[e],n=Math.round(s.nt*t);let r,o;if(i%2){const t=(i-1)/2;r=n-t,o=n+t}else{const t=i/2;r=n-t,o=n+t-1}this.Ue[e-this.zt.tt.from]={Os:r,ui:o,Ze:n,Xe:s.nt*t,ot:s.ot}}for(let t=this.zt.tt.from+1;t<this.zt.tt.to;t++){const i=this.Ue[t-this.zt.tt.from],s=this.Ue[t-this.zt.tt.from-1];i.ot===s.ot+1&&i.Os-s.ui!==e+1&&(s.Ze>s.Xe?s.ui=i.Os-e-1:i.Os=s.ui+e+1)}let s=Math.ceil(this.zt.le*t);for(let t=this.zt.tt.from;t<this.zt.tt.to;t++){const e=this.Ue[t-this.zt.tt.from];e.ui<e.Os&&(e.ui=e.Os);const i=e.ui-e.Os+1;s=Math.min(i,s)}if(e>0&&s<4)for(let t=this.zt.tt.from;t<this.zt.tt.to;t++){const e=this.Ue[t-this.zt.tt.from];e.ui-e.Os+1>s&&(e.Ze>e.Xe?e.ui-=1:e.Os+=1)}}}class se extends Wt{constructor(){super(...arguments),this.js=new ie}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t={it:this.zs,le:this.Ns.St().le(),tt:this.Ls,Ye:this.Es.Dt().Rt(this.Es.W().base,M(this.Es.Ct()).Vt)};this.js.J(t)}}class ne extends Wt{constructor(){super(...arguments),this.js=new Ft}se(t,e,i){return Object.assign(Object.assign({},this.ie(t,e)),i.$s(t))}Js(){const t=this.Es.W(),e={it:this.zs,Nt:t.lineStyle,fs:t.lineVisible?t.lineType:void 0,et:t.lineWidth,Ds:t.pointMarkersVisible?t.pointMarkersRadius||t.lineWidth/2+2:void 0,tt:this.Ls,ds:this.Ns.St().le()};this.js.J(e)}}const re=/[2-9]/g;class oe{constructor(t=50){this.Ke=0,this.Ge=1,this.Je=1,this.Qe={},this.tr=new Map,this.ir=t}nr(){this.Ke=0,this.tr.clear(),this.Ge=1,this.Je=1,this.Qe={}}xi(t,e,i){return this.sr(t,e,i).width}Mi(t,e,i){const s=this.sr(t,e,i);return((s.actualBoundingBoxAscent||0)-(s.actualBoundingBoxDescent||0))/2}sr(t,e,i){const s=i||re,n=String(e).replace(s,"0");if(this.tr.has(n))return S(this.tr.get(n)).er;if(this.Ke===this.ir){const t=this.Qe[this.Je];delete this.Qe[this.Je],this.tr.delete(t),this.Je++,this.Ke--}t.save(),t.textBaseline="middle";const r=t.measureText(n);return t.restore(),0===r.width&&e.length||(this.tr.set(n,{er:r,rr:this.Ge}),this.Qe[this.Ge]=n,this.Ke++,this.Ge++),r}}class he{constructor(t){this.hr=null,this.k=null,this.lr="right",this.ar=t}_r(t,e,i){this.hr=t,this.k=e,this.lr=i}X(t){null!==this.k&&null!==this.hr&&this.hr.X(t,this.k,this.ar,this.lr)}}class le{constructor(t,e,i){this.ur=t,this.ar=new oe(50),this.cr=e,this.F=i,this.j=-1,this.Wt=new he(this.ar)}gt(){const t=this.F.dr(this.cr);if(null===t)return null;const e=t.vr(this.cr)?t.pr():this.cr.Dt();if(null===e)return null;const i=t.mr(e);if("overlay"===i)return null;const s=this.F.br();return s.P!==this.j&&(this.j=s.P,this.ar.nr()),this.Wt._r(this.ur.Ii(),s,i),this.Wt}}class ae extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}wr(t,e){var i;if(!(null===(i=this.zt)||void 0===i?void 0:i.yt))return null;const{st:s,et:n,gr:r}=this.zt;return e>=s-n-7&&e<=s+n+7?{Mr:this.zt,gr:r}:null}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;if(!1===this.zt.yt)return;const n=Math.round(this.zt.st*s);n<0||n>e.height||(t.lineCap="butt",t.strokeStyle=this.zt.V,t.lineWidth=Math.floor(this.zt.et*i),w(t,this.zt.Nt),y(t,n,0,e.width))}}class ce{constructor(t){this.Sr={st:0,V:"rgba(0, 0, 0, 0)",et:1,Nt:0,yt:!1},this.kr=new ae,this.ft=!0,this.Es=t,this.Ns=t.$t(),this.kr.J(this.Sr)}bt(){this.ft=!0}gt(){return this.Es.yt()?(this.ft&&(this.yr(),this.ft=!1),this.kr):null}}class ue extends ce{constructor(t){super(t)}yr(){this.Sr.yt=!1;const t=this.Es.Dt(),e=t.Cr().Cr;if(2!==e&&3!==e)return;const i=this.Es.W();if(!i.baseLineVisible||!this.Es.yt())return;const s=this.Es.Ct();null!==s&&(this.Sr.yt=!0,this.Sr.st=t.Rt(s.Vt,s.Vt),this.Sr.V=i.baseLineColor,this.Sr.et=i.baseLineWidth,this.Sr.Nt=i.baseLineStyle)}}class de extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}$e(){return this.zt}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i}){const s=this.zt;if(null===s)return;const n=Math.max(1,Math.floor(e)),r=n%2/2,o=Math.round(s.Xe.x*e)+r,h=s.Xe.y*i;t.fillStyle=s.Tr,t.beginPath();const l=Math.max(2,1.5*s.Pr)*e;t.arc(o,h,l,0,2*Math.PI,!1),t.fill(),t.fillStyle=s.Rr,t.beginPath(),t.arc(o,h,s.ht*e,0,2*Math.PI,!1),t.fill(),t.lineWidth=n,t.strokeStyle=s.Dr,t.beginPath(),t.arc(o,h,s.ht*e+n/2,0,2*Math.PI,!1),t.stroke()}}const fe=[{Vr:0,Or:.25,Br:4,Ar:10,Ir:.25,zr:0,Lr:.4,Er:.8},{Vr:.25,Or:.525,Br:10,Ar:14,Ir:0,zr:0,Lr:.8,Er:0},{Vr:.525,Or:1,Br:14,Ar:14,Ir:0,zr:0,Lr:0,Er:0}];function me(t,e,i,s){return function(t,e){if("transparent"===t)return t;const i=T(t),s=i[3];return`rgba(${i[0]}, ${i[1]}, ${i[2]}, ${e*s})`}(t,i+(s-i)*e)}function pe(t,e){const i=t%2600/2600;let s;for(const t of fe)if(i>=t.Vr&&i<=t.Or){s=t;break}C(void 0!==s,"Last price animation internal logic error");const n=(i-s.Vr)/(s.Or-s.Vr);return{Rr:me(e,n,s.Ir,s.zr),Dr:me(e,n,s.Lr,s.Er),ht:(r=n,o=s.Br,h=s.Ar,o+(h-o)*r)};var r,o,h}class ge{constructor(t){this.Wt=new de,this.ft=!0,this.Nr=!0,this.Fr=performance.now(),this.Wr=this.Fr-1,this.jr=t}Hr(){this.Wr=this.Fr-1,this.bt()}$r(){if(this.bt(),2===this.jr.W().lastPriceAnimation){const t=performance.now(),e=this.Wr-t;if(e>0)return void(e<650&&(this.Wr+=2600));this.Fr=t,this.Wr=t+2600}}bt(){this.ft=!0}Ur(){this.Nr=!0}yt(){return 0!==this.jr.W().lastPriceAnimation}qr(){switch(this.jr.W().lastPriceAnimation){case 0:return!1;case 1:return!0;case 2:return performance.now()<=this.Wr}}gt(){return this.ft?(this.Mt(),this.ft=!1,this.Nr=!1):this.Nr&&(this.Yr(),this.Nr=!1),this.Wt}Mt(){this.Wt.J(null);const t=this.jr.$t().St(),e=t.Xs(),i=this.jr.Ct();if(null===e||null===i)return;const s=this.jr.Zr(!0);if(s.Xr||!e.Kr(s.ee))return;const n={x:t.It(s.ee),y:this.jr.Dt().Rt(s._t,i.Vt)},r=s.V,o=this.jr.W().lineWidth,h=pe(this.Gr(),r);this.Wt.J({Tr:r,Pr:o,Rr:h.Rr,Dr:h.Dr,ht:h.ht,Xe:n})}Yr(){const t=this.Wt.$e();if(null!==t){const e=pe(this.Gr(),t.Tr);t.Rr=e.Rr,t.Dr=e.Dr,t.ht=e.ht}}Gr(){return this.qr()?performance.now()-this.Fr:2599}}function be(t,e){return Rt(Math.min(Math.max(t,12),30)*e)}function ve(t,e){switch(t){case"arrowDown":case"arrowUp":return be(e,1);case"circle":return be(e,.8);case"square":return be(e,.7)}}function we(t){return function(t){const e=Math.ceil(t);return e%2!=0?e-1:e}(be(t,1))}function ye(t){return Math.max(be(t,.1),3)}function Ce(t,e,i){return e?t:i?Math.ceil(t/2):0}function Se(t,e,i,s,n){const r=ve("square",i),o=(r-1)/2,h=t-o,l=e-o;return s>=h&&s<=h+r&&n>=l&&n<=l+r}function Me(t,e,i,s){const n=(ve("arrowUp",s)-1)/2*i.Jr,r=(Rt(s/2)-1)/2*i.Jr;e.beginPath(),t?(e.moveTo(i.nt-n,i.st),e.lineTo(i.nt,i.st-n),e.lineTo(i.nt+n,i.st),e.lineTo(i.nt+r,i.st),e.lineTo(i.nt+r,i.st+n),e.lineTo(i.nt-r,i.st+n),e.lineTo(i.nt-r,i.st)):(e.moveTo(i.nt-n,i.st),e.lineTo(i.nt,i.st+n),e.lineTo(i.nt+n,i.st),e.lineTo(i.nt+r,i.st),e.lineTo(i.nt+r,i.st-n),e.lineTo(i.nt-r,i.st-n),e.lineTo(i.nt-r,i.st)),e.fill()}class xe extends X{constructor(){super(...arguments),this.zt=null,this.ar=new oe,this.j=-1,this.H="",this.Qr=""}J(t){this.zt=t}_r(t,e){this.j===t&&this.H===e||(this.j=t,this.H=e,this.Qr=H(t,e),this.ar.nr())}wr(t,e){if(null===this.zt||null===this.zt.tt)return null;for(let i=this.zt.tt.from;i<this.zt.tt.to;i++){const s=this.zt.it[i];if(_e(s,t,e))return{Mr:s.th,gr:s.gr}}return null}K({context:t,horizontalPixelRatio:e,verticalPixelRatio:i},s,n){if(null!==this.zt&&null!==this.zt.tt){t.textBaseline="middle",t.font=this.Qr;for(let s=this.zt.tt.from;s<this.zt.tt.to;s++){const n=this.zt.it[s];void 0!==n.Kt&&(n.Kt.Hi=this.ar.xi(t,n.Kt.ih),n.Kt.At=this.j,n.Kt.nt=n.nt-n.Kt.Hi/2),Ee(n,t,e,i)}}}}function Ee(t,e,i,s){e.fillStyle=t.V,void 0!==t.Kt&&function(t,e,i,s,n,r){t.save(),t.scale(n,r),t.fillText(e,i,s),t.restore()}(e,t.Kt.ih,t.Kt.nt,t.Kt.st,i,s),function(t,e,i){if(0!==t.Ks){switch(t.nh){case"arrowDown":return void Me(!1,e,i,t.Ks);case"arrowUp":return void Me(!0,e,i,t.Ks);case"circle":return void function(t,e,i){const s=(ve("circle",i)-1)/2;t.beginPath(),t.arc(e.nt,e.st,s*e.Jr,0,2*Math.PI,!1),t.fill()}(e,i,t.Ks);case"square":return void function(t,e,i){const s=ve("square",i),n=(s-1)*e.Jr/2,r=e.nt-n,o=e.st-n;t.fillRect(r,o,s*e.Jr,s*e.Jr)}(e,i,t.Ks)}t.nh}}(t,e,function(t,e,i){const s=Math.max(1,Math.floor(e))%2/2;return{nt:Math.round(t.nt*e)+s,st:t.st*i,Jr:e}}(t,i,s))}function _e(t,e,i){return!(void 0===t.Kt||!function(t,e,i,s,n,r){const o=s/2;return n>=t&&n<=t+i&&r>=e-o&&r<=e+o}(t.Kt.nt,t.Kt.st,t.Kt.Hi,t.Kt.At,e,i))||function(t,e,i){if(0===t.Ks)return!1;switch(t.nh){case"arrowDown":case"arrowUp":return function(t,e,i,s,n,r){return Se(e,i,s,n,r)}(0,t.nt,t.st,t.Ks,e,i);case"circle":return function(t,e,i,s,n){const r=2+ve("circle",i)/2,o=t-s,h=e-n;return Math.sqrt(o*o+h*h)<=r}(t.nt,t.st,t.Ks,e,i);case"square":return Se(t.nt,t.st,t.Ks,e,i)}}(t,e,i)}function $e(t,e,i,s,n,r,o,h,l){const a=D(i)?i:i.Se,c=D(i)?i:i.Me,u=D(i)?i:i.xe,d=D(e.size)?Math.max(e.size,0):1,f=we(h.le())*d,m=f/2;switch(t.Ks=f,e.position){case"inBar":return t.st=o.Rt(a,l),void(void 0!==t.Kt&&(t.Kt.st=t.st+m+r+.6*n));case"aboveBar":return t.st=o.Rt(c,l)-m-s.sh,void 0!==t.Kt&&(t.Kt.st=t.st-m-.6*n,s.sh+=1.2*n),void(s.sh+=f+r);case"belowBar":return t.st=o.Rt(u,l)+m+s.eh,void 0!==t.Kt&&(t.Kt.st=t.st+m+r+.6*n,s.eh+=1.2*n),void(s.eh+=f+r)}e.position}class ze{constructor(t,e){this.ft=!0,this.rh=!0,this.hh=!0,this.ah=null,this.oh=null,this.Wt=new xe,this.jr=t,this.$i=e,this.zt={it:[],tt:null}}bt(t){this.ft=!0,this.hh=!0,"data"===t&&(this.rh=!0,this.oh=null)}gt(t){if(!this.jr.yt())return null;this.ft&&this._h();const e=this.$i.W().layout;return this.Wt._r(e.fontSize,e.fontFamily),this.Wt.J(this.zt),this.Wt}uh(){if(this.hh){if(this.jr.dh().length>0){const t=this.$i.St().le(),e=ye(t),i=1.5*we(t)+2*e,s=this.fh();this.ah={above:Ce(i,s.aboveBar,s.inBar),below:Ce(i,s.belowBar,s.inBar)}}else this.ah=null;this.hh=!1}return this.ah}fh(){return null===this.oh&&(this.oh=this.jr.dh().reduce((t,e)=>(t[e.position]||(t[e.position]=!0),t),{inBar:!1,aboveBar:!1,belowBar:!1})),this.oh}_h(){const t=this.jr.Dt(),e=this.$i.St(),i=this.jr.dh();this.rh&&(this.zt.it=i.map(t=>({ot:t.time,nt:0,st:0,Ks:0,nh:t.shape,V:t.color,th:t.th,gr:t.id,Kt:void 0})),this.rh=!1);const s=this.$i.W().layout;this.zt.tt=null;const n=e.Xs();if(null===n)return;const r=this.jr.Ct();if(null===r)return;if(0===this.zt.it.length)return;let o=NaN;const h=ye(e.le()),l={sh:h,eh:h};this.zt.tt=At(this.zt.it,n,!0);for(let n=this.zt.tt.from;n<this.zt.tt.to;n++){const a=i[n];a.time!==o&&(l.sh=h,l.eh=h,o=a.time);const c=this.zt.it[n];c.nt=e.It(a.time),void 0!==a.text&&a.text.length>0&&(c.Kt={ih:a.text,nt:0,st:0,Hi:0,At:0});const u=this.jr.ph(a.time);null!==u&&$e(c,a,u,l,s.fontSize,h,t,e,r.Vt)}this.ft=!1}}class ke extends ce{constructor(t){super(t)}yr(){const t=this.Sr;t.yt=!1;const e=this.Es.W();if(!e.priceLineVisible||!this.Es.yt())return;const i=this.Es.Zr(0===e.priceLineSource);i.Xr||(t.yt=!0,t.st=i.ki,t.V=this.Es.mh(i.V),t.et=e.priceLineWidth,t.Nt=e.priceLineStyle)}}class Re extends ht{constructor(t){super(),this.jt=t}zi(t,e,i){t.yt=!1,e.yt=!1;const s=this.jt;if(!s.yt())return;const n=s.W(),r=n.lastValueVisible,o=""!==s.bh(),h=0===n.seriesLastValueMode,l=s.Zr(!1);if(l.Xr)return;r&&(t.Kt=this.wh(l,r,h),t.yt=0!==t.Kt.length),(o||h)&&(e.Kt=this.gh(l,r,o,h),e.yt=e.Kt.length>0);const a=s.mh(l.V),c=O(a);i.t=c.t,i.ki=l.ki,e.Ot=s.$t().Bt(l.ki/s.Dt().At()),t.Ot=a,t.V=c.i,e.V=c.i}gh(t,e,i,s){let n="";const r=this.jt.bh();return i&&0!==r.length&&(n+=`${r} `),e&&s&&(n+=this.jt.Dt().Mh()?t.xh:t.Sh),n.trim()}wh(t,e,i){return e?i?this.jt.Dt().Mh()?t.Sh:t.xh:t.Kt:""}}function Ne(t,e,i,s){const n=Number.isFinite(e),r=Number.isFinite(i);return n&&r?t(e,i):n||r?n?e:i:s}class Te{constructor(t,e){this.kh=t,this.yh=e}Ch(t){return null!==t&&this.kh===t.kh&&this.yh===t.yh}Th(){return new Te(this.kh,this.yh)}Ph(){return this.kh}Rh(){return this.yh}Dh(){return this.yh-this.kh}Ni(){return this.yh===this.kh||Number.isNaN(this.yh)||Number.isNaN(this.kh)}ts(t){return null===t?this:new Te(Ne(Math.min,this.Ph(),t.Ph(),-1/0),Ne(Math.max,this.Rh(),t.Rh(),1/0))}Vh(t){if(!D(t))return;if(0===this.yh-this.kh)return;const e=.5*(this.yh+this.kh);let i=this.yh-e,s=this.kh-e;i*=t,s*=t,this.yh=e+i,this.kh=e+s}Oh(t){D(t)&&(this.yh+=t,this.kh+=t)}Bh(){return{minValue:this.kh,maxValue:this.yh}}static Ah(t){return null===t?null:new Te(t.minValue,t.maxValue)}}class Le{constructor(t,e){this.Ih=t,this.zh=e||null}Lh(){return this.Ih}Eh(){return this.zh}Bh(){return null===this.Ih?null:{priceRange:this.Ih.Bh(),margins:this.zh||void 0}}static Ah(t){return null===t?null:new Le(Te.Ah(t.priceRange),t.margins)}}class Oe extends ce{constructor(t,e){super(t),this.Nh=e}yr(){const t=this.Sr;t.yt=!1;const e=this.Nh.W();if(!this.Es.yt()||!e.lineVisible)return;const i=this.Nh.Fh();null!==i&&(t.yt=!0,t.st=i,t.V=e.color,t.et=e.lineWidth,t.Nt=e.lineStyle,t.gr=this.Nh.W().id)}}class Fe extends ht{constructor(t,e){super(),this.jr=t,this.Nh=e}zi(t,e,i){t.yt=!1,e.yt=!1;const s=this.Nh.W(),n=s.axisLabelVisible,r=""!==s.title,o=this.jr;if(!n||!o.yt())return;const h=this.Nh.Fh();if(null===h)return;r&&(e.Kt=s.title,e.yt=!0),e.Ot=o.$t().Bt(h/o.Dt().At()),t.Kt=this.Wh(s.price),t.yt=!0;const l=O(s.axisLabelColor||s.color);i.t=l.t;const a=s.axisLabelTextColor||l.i;t.V=a,e.V=a,i.ki=h}Wh(t){const e=this.jr.Ct();return null===e?"":this.jr.Dt().Fi(t,e.Vt)}}class Pe{constructor(t,e){this.jr=t,this.cn=e,this.jh=new Oe(t,this),this.ur=new Fe(t,this),this.Hh=new le(this.ur,t,t.$t())}$h(t){P(this.cn,t),this.bt(),this.jr.$t().Uh()}W(){return this.cn}qh(){return this.jh}Yh(){return this.Hh}Zh(){return this.ur}bt(){this.jh.bt(),this.ur.bt()}Fh(){const t=this.jr,e=t.Dt();if(t.$t().St().Ni()||e.Ni())return null;const i=t.Ct();return null===i?null:e.Rt(this.cn.price,i.Vt)}}class De extends dt{constructor(t){super(),this.$i=t}$t(){return this.$i}}const Ve={Bar:(t,e,i,s)=>{var n;const r=e.upColor,o=e.downColor,h=M(t(i,s)),l=x(h.Vt[0])<=x(h.Vt[3]);return{ce:null!==(n=h.V)&&void 0!==n?n:l?r:o}},Candlestick:(t,e,i,s)=>{var n,r,o;const h=e.upColor,l=e.downColor,a=e.borderUpColor,c=e.borderDownColor,u=e.wickUpColor,d=e.wickDownColor,f=M(t(i,s)),m=x(f.Vt[0])<=x(f.Vt[3]);return{ce:null!==(n=f.V)&&void 0!==n?n:m?h:l,Ne:null!==(r=f.Ot)&&void 0!==r?r:m?a:c,Ee:null!==(o=f.Xh)&&void 0!==o?o:m?u:d}},Custom:(t,e,i,s)=>{var n;return{ce:null!==(n=M(t(i,s)).V)&&void 0!==n?n:e.color}},Area:(t,e,i,s)=>{var n,r,o,h;const l=M(t(i,s));return{ce:null!==(n=l.lt)&&void 0!==n?n:e.lineColor,lt:null!==(r=l.lt)&&void 0!==r?r:e.lineColor,Ps:null!==(o=l.Ps)&&void 0!==o?o:e.topColor,Rs:null!==(h=l.Rs)&&void 0!==h?h:e.bottomColor}},Baseline:(t,e,i,s)=>{var n,r,o,h,l,a;const c=M(t(i,s));return{ce:c.Vt[3]>=e.baseValue.price?e.topLineColor:e.bottomLineColor,Re:null!==(n=c.Re)&&void 0!==n?n:e.topLineColor,De:null!==(r=c.De)&&void 0!==r?r:e.bottomLineColor,ke:null!==(o=c.ke)&&void 0!==o?o:e.topFillColor1,ye:null!==(h=c.ye)&&void 0!==h?h:e.topFillColor2,Ce:null!==(l=c.Ce)&&void 0!==l?l:e.bottomFillColor1,Te:null!==(a=c.Te)&&void 0!==a?a:e.bottomFillColor2}},Line:(t,e,i,s)=>{var n,r;const o=M(t(i,s));return{ce:null!==(n=o.V)&&void 0!==n?n:e.color,lt:null!==(r=o.V)&&void 0!==r?r:e.color}},Histogram:(t,e,i,s)=>{var n;return{ce:null!==(n=M(t(i,s)).V)&&void 0!==n?n:e.color}}};class Ie{constructor(t){this.Kh=(t,e)=>void 0!==e?e.Vt:this.jr.In().Gh(t),this.jr=t,this.Jh=Ve[t.Qh()]}$s(t,e){return this.Jh(this.Kh,this.jr.W(),t,e)}}var Be;!function(t){t[t.NearestLeft=-1]="NearestLeft",t[t.None=0]="None",t[t.NearestRight=1]="NearestRight"}(Be||(Be={}));const Ae=30;class Ue{constructor(){this.tl=[],this.il=new Map,this.nl=new Map}sl(){return this.Ks()>0?this.tl[this.tl.length-1]:null}el(){return this.Ks()>0?this.rl(0):null}An(){return this.Ks()>0?this.rl(this.tl.length-1):null}Ks(){return this.tl.length}Ni(){return 0===this.Ks()}Kr(t){return null!==this.hl(t,0)}Gh(t){return this.ll(t)}ll(t,e=0){const i=this.hl(t,e);return null===i?null:Object.assign(Object.assign({},this.al(i)),{ee:this.rl(i)})}ne(){return this.tl}ol(t,e,i){if(this.Ni())return null;let s=null;for(const n of i)s=We(s,this._l(t,e,n));return s}J(t){this.nl.clear(),this.il.clear(),this.tl=t}rl(t){return this.tl[t].ee}al(t){return this.tl[t]}hl(t,e){const i=this.ul(t);if(null===i&&0!==e)switch(e){case-1:return this.cl(t);case 1:return this.dl(t);default:throw new TypeError("Unknown search mode")}return i}cl(t){let e=this.fl(t);return e>0&&(e-=1),e!==this.tl.length&&this.rl(e)<t?e:null}dl(t){const e=this.vl(t);return e!==this.tl.length&&t<this.rl(e)?e:null}ul(t){const e=this.fl(t);return e===this.tl.length||t<this.tl[e].ee?null:e}fl(t){return Dt(this.tl,t,(t,e)=>t.ee<e)}vl(t){return Vt(this.tl,t,(t,e)=>t.ee>e)}pl(t,e,i){let s=null;for(let n=t;n<e;n++){const t=this.tl[n].Vt[i];Number.isNaN(t)||(null===s?s={ml:t,bl:t}:(t<s.ml&&(s.ml=t),t>s.bl&&(s.bl=t)))}return s}_l(t,e,i){if(this.Ni())return null;let s=null;const n=M(this.el()),r=M(this.An()),o=Math.max(t,n),h=Math.min(e,r),l=Math.ceil(o/Ae)*Ae,a=Math.max(l,Math.floor(h/Ae)*Ae);{const t=this.fl(o),n=this.vl(Math.min(h,l,e));s=We(s,this.pl(t,n,i))}let c=this.il.get(i);void 0===c&&(c=new Map,this.il.set(i,c));for(let t=Math.max(l+1,o);t<a;t+=Ae){const e=Math.floor(t/Ae);let n=c.get(e);if(void 0===n){const t=this.fl(e*Ae),s=this.vl((e+1)*Ae-1);n=this.pl(t,s,i),c.set(e,n)}s=We(s,n)}{const t=this.fl(a),e=this.vl(h);s=We(s,this.pl(t,e,i))}return s}}function We(t,e){return null===t?e:null===e?t:{ml:Math.min(t.ml,e.ml),bl:Math.max(t.bl,e.bl)}}class je{constructor(t){this.wl=t}X(t,e,i){this.wl.draw(t)}gl(t,e,i){var s,n;null===(n=(s=this.wl).drawBackground)||void 0===n||n.call(s,t)}}class He{constructor(t){this.tr=null,this.wn=t}gt(){var t;const e=this.wn.renderer();if(null===e)return null;if((null===(t=this.tr)||void 0===t?void 0:t.Ml)===e)return this.tr.xl;const i=new je(e);return this.tr={Ml:e,xl:i},i}Sl(){var t,e,i;return null!==(i=null===(e=(t=this.wn).zOrder)||void 0===e?void 0:e.call(t))&&void 0!==i?i:"normal"}}function Ke(t){var e,i,s,n,r;return{Kt:t.text(),ki:t.coordinate(),Si:null===(e=t.fixedCoordinate)||void 0===e?void 0:e.call(t),V:t.textColor(),t:t.backColor(),yt:null===(s=null===(i=t.visible)||void 0===i?void 0:i.call(t))||void 0===s||s,hi:null===(r=null===(n=t.tickVisible)||void 0===n?void 0:n.call(t))||void 0===r||r}}class qe{constructor(t,e){this.Wt=new ct,this.kl=t,this.yl=e}gt(){return this.Wt.J(Object.assign({Hi:this.yl.Hi()},Ke(this.kl))),this.Wt}}class Xe extends ht{constructor(t,e){super(),this.kl=t,this.Li=e}zi(t,e,i){const s=Ke(this.kl);i.t=s.t,t.V=s.V;const n=2/12*this.Li.P();i.wi=n,i.gi=n,i.ki=s.ki,i.Si=s.Si,t.Kt=s.Kt,t.yt=s.yt,t.hi=s.hi}}class Je{constructor(t,e){this.Cl=null,this.Tl=null,this.Pl=null,this.Rl=null,this.Dl=null,this.Vl=t,this.jr=e}Ol(){return this.Vl}Vn(){var t,e;null===(e=(t=this.Vl).updateAllViews)||void 0===e||e.call(t)}Pn(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).paneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Cl)||void 0===s?void 0:s.Ml)===n)return this.Cl.xl;const r=n.map(t=>new He(t));return this.Cl={Ml:n,xl:r},r}Qi(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).timeAxisViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Tl)||void 0===s?void 0:s.Ml)===n)return this.Tl.xl;const r=this.jr.$t().St(),o=n.map(t=>new qe(t,r));return this.Tl={Ml:n,xl:o},o}Rn(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).priceAxisViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Pl)||void 0===s?void 0:s.Ml)===n)return this.Pl.xl;const r=this.jr.Dt(),o=n.map(t=>new Xe(t,r));return this.Pl={Ml:n,xl:o},o}Bl(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).priceAxisPaneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Rl)||void 0===s?void 0:s.Ml)===n)return this.Rl.xl;const r=n.map(t=>new He(t));return this.Rl={Ml:n,xl:r},r}Al(){var t,e,i,s;const n=null!==(i=null===(e=(t=this.Vl).timeAxisPaneViews)||void 0===e?void 0:e.call(t))&&void 0!==i?i:[];if((null===(s=this.Dl)||void 0===s?void 0:s.Ml)===n)return this.Dl.xl;const r=n.map(t=>new He(t));return this.Dl={Ml:n,xl:r},r}Il(t,e){var i,s,n;return null!==(n=null===(s=(i=this.Vl).autoscaleInfo)||void 0===s?void 0:s.call(i,t,e))&&void 0!==n?n:null}wr(t,e){var i,s,n;return null!==(n=null===(s=(i=this.Vl).hitTest)||void 0===s?void 0:s.call(i,t,e))&&void 0!==n?n:null}}function Ge(t,e,i,s){t.forEach(t=>{e(t).forEach(t=>{t.Sl()===i&&s.push(t)})})}function Qe(t){return t.Pn()}function Ye(t){return t.Bl()}function Ze(t){return t.Al()}class ti extends De{constructor(t,e,i,s,n){super(t),this.zt=new Ue,this.jh=new ke(this),this.zl=[],this.Ll=new ue(this),this.El=null,this.Nl=null,this.Fl=[],this.Wl=[],this.jl=null,this.Hl=[],this.cn=e,this.$l=i;const r=new Re(this);this.rn=[r],this.Hh=new le(r,this,t),"Area"!==i&&"Line"!==i&&"Baseline"!==i||(this.El=new ge(this)),this.Ul(),this.ql(n)}S(){null!==this.jl&&clearTimeout(this.jl)}mh(t){return this.cn.priceLineColor||t}Zr(t){const e={Xr:!0},i=this.Dt();if(this.$t().St().Ni()||i.Ni()||this.zt.Ni())return e;const s=this.$t().St().Xs(),n=this.Ct();if(null===s||null===n)return e;let r,o;if(t){const t=this.zt.sl();if(null===t)return e;r=t,o=t.ee}else{const t=this.zt.ll(s.ui(),-1);if(null===t)return e;if(r=this.zt.Gh(t.ee),null===r)return e;o=t.ee}const h=r.Vt[3],l=this.Us().$s(o,{Vt:r}),a=i.Rt(h,n.Vt);return{Xr:!1,_t:h,Kt:i.Fi(h,n.Vt),xh:i.Yl(h),Sh:i.Zl(h,n.Vt),V:l.ce,ki:a,ee:o}}Us(){return null!==this.Nl||(this.Nl=new Ie(this)),this.Nl}W(){return this.cn}$h(t){const e=t.priceScaleId;void 0!==e&&e!==this.cn.priceScaleId&&this.$t().Xl(this,e),P(this.cn,t),void 0!==t.priceFormat&&(this.Ul(),this.$t().Kl()),this.$t().Gl(this),this.$t().Jl(),this.wn.bt("options")}J(t,e){this.zt.J(t),this.Ql(),this.wn.bt("data"),this.dn.bt("data"),null!==this.El&&(e&&e.ta?this.El.$r():0===t.length&&this.El.Hr());const i=this.$t().dr(this);this.$t().ia(i),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}na(t){this.Fl=t,this.Ql();const e=this.$t().dr(this);this.dn.bt("data"),this.$t().ia(e),this.$t().Gl(this),this.$t().Jl(),this.$t().Uh()}sa(){return this.Fl}dh(){return this.Wl}ea(t){const e=new Pe(this,t);return this.zl.push(e),this.$t().Gl(this),e}ra(t){const e=this.zl.indexOf(t);-1!==e&&this.zl.splice(e,1),this.$t().Gl(this)}Qh(){return this.$l}Ct(){const t=this.ha();return null===t?null:{Vt:t.Vt[3],la:t.ot}}ha(){const t=this.$t().St().Xs();if(null===t)return null;const e=t.Os();return this.zt.ll(e,1)}In(){return this.zt}ph(t){const e=this.zt.Gh(t);return null===e?null:"Bar"===this.$l||"Candlestick"===this.$l||"Custom"===this.$l?{ge:e.Vt[0],Me:e.Vt[1],xe:e.Vt[2],Se:e.Vt[3]}:e.Vt[3]}aa(t){const e=[];Ge(this.Hl,Qe,"top",e);const i=this.El;return null!==i&&i.yt()?(null===this.jl&&i.qr()&&(this.jl=setTimeout(()=>{this.jl=null,this.$t().oa()},0)),i.Ur(),e.unshift(i),e):e}Pn(){const t=[];this._a()||t.push(this.Ll),t.push(this.wn,this.jh,this.dn);const e=this.zl.map(t=>t.qh());return t.push(...e),Ge(this.Hl,Qe,"normal",t),t}ua(){return this.ca(Qe,"bottom")}da(t){return this.ca(Ye,t)}fa(t){return this.ca(Ze,t)}va(t,e){return this.Hl.map(i=>i.wr(t,e)).filter(t=>null!==t)}Ji(t){return[this.Hh,...this.zl.map(t=>t.Yh())]}Rn(t,e){if(e!==this.Yi&&!this._a())return[];const i=[...this.rn];for(const t of this.zl)i.push(t.Zh());return this.Hl.forEach(t=>{i.push(...t.Rn())}),i}Qi(){const t=[];return this.Hl.forEach(e=>{t.push(...e.Qi())}),t}Il(t,e){if(void 0!==this.cn.autoscaleInfoProvider){const i=this.cn.autoscaleInfoProvider(()=>{const i=this.pa(t,e);return null===i?null:i.Bh()});return Le.Ah(i)}return this.pa(t,e)}ma(){return this.cn.priceFormat.minMove}ba(){return this.wa}Vn(){var t;this.wn.bt(),this.dn.bt();for(const t of this.rn)t.bt();for(const t of this.zl)t.bt();this.jh.bt(),this.Ll.bt(),null===(t=this.El)||void 0===t||t.bt(),this.Hl.forEach(t=>t.Vn())}Dt(){return M(super.Dt())}kt(t){if("Line"!==this.$l&&"Area"!==this.$l&&"Baseline"!==this.$l||!this.cn.crosshairMarkerVisible)return null;const e=this.zt.Gh(t);return null===e?null:{_t:e.Vt[3],ht:this.ga(),Ot:this.Ma(),Pt:this.xa(),Tt:this.Sa(t)}}bh(){return this.cn.title}yt(){return this.cn.visible}ka(t){this.Hl.push(new Je(t,this))}ya(t){this.Hl=this.Hl.filter(e=>e.Ol()!==t)}Ca(){if(this.wn instanceof te!=0)return t=>this.wn.We(t)}Ta(){if(this.wn instanceof te!=0)return t=>this.wn.je(t)}_a(){return!pt(this.Dt().Pa())}pa(t,e){if(!V(t)||!V(e)||this.zt.Ni())return null;const i="Line"===this.$l||"Area"===this.$l||"Baseline"===this.$l||"Histogram"===this.$l?[3]:[2,1],s=this.zt.ol(t,e,i);let n=null!==s?new Te(s.ml,s.bl):null;if("Histogram"===this.Qh()){const t=this.cn.base,e=new Te(t,t);n=null!==n?n.ts(e):e}let r=this.dn.uh();return this.Hl.forEach(i=>{const s=i.Il(t,e);if(null==s?void 0:s.priceRange){const t=new Te(s.priceRange.minValue,s.priceRange.maxValue);n=null!==n?n.ts(t):t}var o,h,l,a;(null==s?void 0:s.margins)&&(o=r,h=s.margins,r={above:Math.max(null!==(l=null==o?void 0:o.above)&&void 0!==l?l:0,h.above),below:Math.max(null!==(a=null==o?void 0:o.below)&&void 0!==a?a:0,h.below)})}),new Le(n,r)}ga(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerRadius}return 0}Ma(){switch(this.$l){case"Line":case"Area":case"Baseline":{const t=this.cn.crosshairMarkerBorderColor;if(0!==t.length)return t}}return null}xa(){switch(this.$l){case"Line":case"Area":case"Baseline":return this.cn.crosshairMarkerBorderWidth}return 0}Sa(t){switch(this.$l){case"Line":case"Area":case"Baseline":{const t=this.cn.crosshairMarkerBackgroundColor;if(0!==t.length)return t}}return this.Us().$s(t).ce}Ul(){switch(this.cn.priceFormat.type){case"custom":this.wa={format:this.cn.priceFormat.formatter};break;case"volume":this.wa=new yt(this.cn.priceFormat.precision);break;case"percent":this.wa=new wt(this.cn.priceFormat.precision);break;default:{const t=Math.pow(10,this.cn.priceFormat.precision);this.wa=new vt(t,this.cn.priceFormat.minMove*t)}}null!==this.Yi&&this.Yi.Ra()}Ql(){const t=this.$t().St();if(!t.Da()||this.zt.Ni())return void(this.Wl=[]);const e=M(this.zt.el());this.Wl=this.Fl.map((i,s)=>{const n=M(t.Va(i.time,!0)),r=n<e?1:-1;return{time:M(this.zt.ll(n,r)).ee,position:i.position,shape:i.shape,color:i.color,id:i.id,th:s,text:i.text,size:i.size,originalTime:i.originalTime}})}ql(t){switch(this.dn=new ze(this,this.$t()),this.$l){case"Bar":this.wn=new qt(this,this.$t());break;case"Candlestick":this.wn=new Yt(this,this.$t());break;case"Line":this.wn=new ne(this,this.$t());break;case"Custom":this.wn=new te(this,this.$t(),S(t));break;case"Area":this.wn=new jt(this,this.$t());break;case"Baseline":this.wn=new Gt(this,this.$t());break;case"Histogram":this.wn=new se(this,this.$t());break;default:throw Error("Unknown chart style assigned: "+this.$l)}}ca(t,e){const i=[];return Ge(this.Hl,t,e,i),i}}class ei{constructor(t){this.cn=t}Oa(t,e,i){let s=t;if(0===this.cn.mode)return s;const n=i.vn(),r=n.Ct();if(null===r)return s;const o=n.Rt(t,r),h=i.Ba().filter(t=>t instanceof ti).reduce((t,s)=>{if(i.vr(s)||!s.yt())return t;const n=s.Dt(),r=s.In();if(n.Ni()||!r.Kr(e))return t;const o=r.Gh(e);if(null===o)return t;const h=x(s.Ct());return t.concat([n.Rt(o.Vt[3],h.Vt)])},[]);if(0===h.length)return s;h.sort((t,e)=>Math.abs(t-o)-Math.abs(e-o));const l=h[0];return s=n.pn(l,r),s}}class ii extends X{constructor(){super(...arguments),this.zt=null}J(t){this.zt=t}K({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(null===this.zt)return;const n=Math.max(1,Math.floor(i));t.lineWidth=n,function(t,e){t.save(),t.lineWidth%2&&t.translate(.5,.5),e(),t.restore()}(t,()=>{const r=M(this.zt);if(r.Aa){t.strokeStyle=r.Ia,w(t,r.za),t.beginPath();for(const s of r.La){const r=Math.round(s.Ea*i);t.moveTo(r,-n),t.lineTo(r,e.height+n)}t.stroke()}if(r.Na){t.strokeStyle=r.Fa,w(t,r.Wa),t.beginPath();for(const i of r.ja){const r=Math.round(i.Ea*s);t.moveTo(-n,r),t.lineTo(e.width+n,r)}t.stroke()}})}}class si{constructor(t){this.Wt=new ii,this.ft=!0,this.tn=t}bt(){this.ft=!0}gt(){if(this.ft){const t=this.tn.$t().W().grid,e={Na:t.horzLines.visible,Aa:t.vertLines.visible,Fa:t.horzLines.color,Ia:t.vertLines.color,Wa:t.horzLines.style,za:t.vertLines.style,ja:this.tn.vn().Ha(),La:(this.tn.$t().St().Ha()||[]).map(t=>({Ea:t.coord}))};this.Wt.J(e),this.ft=!1}return this.Wt}}class ni{constructor(t){this.wn=new si(t)}qh(){return this.wn}}const ri={$a:4,Ua:1e-4};function oi(t,e){const i=100*(t-e)/e;return e<0?-i:i}function hi(t,e){const i=oi(t.Ph(),e),s=oi(t.Rh(),e);return new Te(i,s)}function li(t,e){const i=100*(t-e)/e+100;return e<0?-i:i}function ai(t,e){const i=li(t.Ph(),e),s=li(t.Rh(),e);return new Te(i,s)}function ci(t,e){const i=Math.abs(t);if(i<1e-15)return 0;const s=Math.log10(i+e.Ua)+e.$a;return t<0?-s:s}function ui(t,e){const i=Math.abs(t);if(i<1e-15)return 0;const s=Math.pow(10,i-e.$a)-e.Ua;return t<0?-s:s}function di(t,e){if(null===t)return null;const i=ci(t.Ph(),e),s=ci(t.Rh(),e);return new Te(i,s)}function fi(t,e){if(null===t)return null;const i=ui(t.Ph(),e),s=ui(t.Rh(),e);return new Te(i,s)}function mi(t){if(null===t)return ri;const e=Math.abs(t.Rh()-t.Ph());if(e>=1||e<1e-15)return ri;const i=Math.ceil(Math.abs(Math.log10(e))),s=ri.$a+i;return{$a:s,Ua:1/Math.pow(10,s)}}class pi{constructor(t,e){if(this.qa=t,this.Ya=e,function(t){if(t<0)return!1;for(let e=t;e>1;e/=10)if(e%10!=0)return!1;return!0}(this.qa))this.Za=[2,2.5,2];else{this.Za=[];for(let t=this.qa;1!==t;){if(t%2==0)this.Za.push(2),t/=2;else{if(t%5!=0)throw new Error("unexpected base");this.Za.push(2,2.5),t/=5}if(this.Za.length>100)throw new Error("something wrong with base")}}}Xa(t,e,i){const s=0===this.qa?0:1/this.qa;let n=Math.pow(10,Math.max(0,Math.ceil(Math.log10(t-e)))),r=0,o=this.Ya[0];for(;;){const t=kt(n,s,1e-14)&&n>s+1e-14,e=kt(n,i*o,1e-14),h=kt(n,1,1e-14);if(!(t&&e&&h))break;n/=o,o=this.Ya[++r%this.Ya.length]}if(n<=s+1e-14&&(n=s),n=Math.max(1,n),this.Za.length>0&&(h=n,Math.abs(h-1)<1e-14))for(r=0,o=this.Za[0];kt(n,i*o,1e-14)&&n>s+1e-14;)n/=o,o=this.Za[++r%this.Za.length];var h;return n}}class gi{constructor(t,e,i,s){this.Ka=[],this.Li=t,this.qa=e,this.Ga=i,this.Ja=s}Xa(t,e){if(t<e)throw new Error("high < low");const i=this.Li.At(),s=(t-e)*this.Qa()/i,n=new pi(this.qa,[2,2.5,2]),r=new pi(this.qa,[2,2,2.5]),o=new pi(this.qa,[2.5,2,2]),h=[];return h.push(n.Xa(t,e,s),r.Xa(t,e,s),o.Xa(t,e,s)),function(t){if(t.length<1)throw Error("array is empty");let e=t[0];for(let i=1;i<t.length;++i)t[i]<e&&(e=t[i]);return e}(h)}io(){const t=this.Li,e=t.Ct();if(null===e)return void(this.Ka=[]);const i=t.At(),s=this.Ga(i-1,e),n=this.Ga(0,e),r=this.Li.W().entireTextOnly?this.no()/2:0,o=r,h=i-1-r,l=Math.max(s,n),a=Math.min(s,n);if(l===a)return void(this.Ka=[]);let c=this.Xa(l,a),u=l%c;u+=u<0?c:0;const d=l>=a?1:-1;let f=null,m=0;for(let i=l-u;i>a;i-=c){const s=this.Ja(i,e,!0);null!==f&&Math.abs(s-f)<this.Qa()||s<o||s>h||(m<this.Ka.length?(this.Ka[m].Ea=s,this.Ka[m].so=t.eo(i)):this.Ka.push({Ea:s,so:t.eo(i)}),m++,f=s,t.ro()&&(c=this.Xa(i*d,a)))}this.Ka.length=m}Ha(){return this.Ka}no(){return this.Li.P()}Qa(){return Math.ceil(2.5*this.no())}}function bi(t){return t.slice().sort((t,e)=>M(t.Xi())-M(e.Xi()))}var vi;!function(t){t[t.Normal=0]="Normal",t[t.Logarithmic=1]="Logarithmic",t[t.Percentage=2]="Percentage",t[t.IndexedTo100=3]="IndexedTo100"}(vi||(vi={}));const wi=new wt,yi=new vt(100,1);class Ci{constructor(t,e,i,s){this.ho=0,this.lo=null,this.Ih=null,this.ao=null,this.oo={_o:!1,uo:null},this.co=0,this.do=0,this.fo=new F,this.vo=new F,this.po=[],this.mo=null,this.bo=null,this.wo=null,this.Mo=null,this.wa=yi,this.xo=mi(null),this.So=t,this.cn=e,this.ko=i,this.yo=s,this.Co=new gi(this,100,this.To.bind(this),this.Po.bind(this))}Pa(){return this.So}W(){return this.cn}$h(t){if(P(this.cn,t),this.Ra(),void 0!==t.mode&&this.Ro({Cr:t.mode}),void 0!==t.scaleMargins){const e=S(t.scaleMargins.top),i=S(t.scaleMargins.bottom);if(e<0||e>1)throw new Error(`Invalid top margin - expect value between 0 and 1, given=${e}`);if(i<0||i>1)throw new Error(`Invalid bottom margin - expect value between 0 and 1, given=${i}`);if(e+i>1)throw new Error(`Invalid margins - sum of margins must be less than 1, given=${e+i}`);this.Do(),this.bo=null}}Vo(){return this.cn.autoScale}ro(){return 1===this.cn.mode}Mh(){return 2===this.cn.mode}Oo(){return 3===this.cn.mode}Cr(){return{Wn:this.cn.autoScale,Bo:this.cn.invertScale,Cr:this.cn.mode}}Ro(t){const e=this.Cr();let i=null;void 0!==t.Wn&&(this.cn.autoScale=t.Wn),void 0!==t.Cr&&(this.cn.mode=t.Cr,2!==t.Cr&&3!==t.Cr||(this.cn.autoScale=!0),this.oo._o=!1),1===e.Cr&&t.Cr!==e.Cr&&(function(t,e){if(null===t)return!1;const i=ui(t.Ph(),e),s=ui(t.Rh(),e);return isFinite(i)&&isFinite(s)}(this.Ih,this.xo)?(i=fi(this.Ih,this.xo),null!==i&&this.Ao(i)):this.cn.autoScale=!0),1===t.Cr&&t.Cr!==e.Cr&&(i=di(this.Ih,this.xo),null!==i&&this.Ao(i));const s=e.Cr!==this.cn.mode;s&&(2===e.Cr||this.Mh())&&this.Ra(),s&&(3===e.Cr||this.Oo())&&this.Ra(),void 0!==t.Bo&&e.Bo!==t.Bo&&(this.cn.invertScale=t.Bo,this.Io()),this.vo.m(e,this.Cr())}zo(){return this.vo}P(){return this.ko.fontSize}At(){return this.ho}Lo(t){this.ho!==t&&(this.ho=t,this.Do(),this.bo=null)}Eo(){if(this.lo)return this.lo;const t=this.At()-this.No()-this.Fo();return this.lo=t,t}Lh(){return this.Wo(),this.Ih}Ao(t,e){const i=this.Ih;(e||null===i&&null!==t||null!==i&&!i.Ch(t))&&(this.bo=null,this.Ih=t)}Ni(){return this.Wo(),0===this.ho||!this.Ih||this.Ih.Ni()}jo(t){return this.Bo()?t:this.At()-1-t}Rt(t,e){return this.Mh()?t=oi(t,e):this.Oo()&&(t=li(t,e)),this.Po(t,e)}te(t,e,i){this.Wo();const s=this.Fo(),n=M(this.Lh()),r=n.Ph(),o=n.Rh(),h=this.Eo()-1,l=this.Bo(),a=h/(o-r),c=void 0===i?0:i.from,u=void 0===i?t.length:i.to,d=this.Ho();for(let i=c;i<u;i++){const n=t[i],o=n._t;if(isNaN(o))continue;let h=o;null!==d&&(h=d(n._t,e));const c=s+a*(h-r),u=l?c:this.ho-1-c;n.st=u}}be(t,e,i){this.Wo();const s=this.Fo(),n=M(this.Lh()),r=n.Ph(),o=n.Rh(),h=this.Eo()-1,l=this.Bo(),a=h/(o-r),c=void 0===i?0:i.from,u=void 0===i?t.length:i.to,d=this.Ho();for(let i=c;i<u;i++){const n=t[i];let o=n.ge,h=n.Me,c=n.xe,u=n.Se;null!==d&&(o=d(n.ge,e),h=d(n.Me,e),c=d(n.xe,e),u=d(n.Se,e));let f=s+a*(o-r),m=l?f:this.ho-1-f;n.pe=m,f=s+a*(h-r),m=l?f:this.ho-1-f,n.de=m,f=s+a*(c-r),m=l?f:this.ho-1-f,n.fe=m,f=s+a*(u-r),m=l?f:this.ho-1-f,n.me=m}}pn(t,e){const i=this.To(t,e);return this.$o(i,e)}$o(t,e){let i=t;return this.Mh()?i=function(t,e){return e<0&&(t=-t),t/100*e+e}(i,e):this.Oo()&&(i=function(t,e){return t-=100,e<0&&(t=-t),t/100*e+e}(i,e)),i}Ba(){return this.po}Uo(){if(this.mo)return this.mo;let t=[];for(let e=0;e<this.po.length;e++){const i=this.po[e];null===i.Xi()&&i.Ki(e+1),t.push(i)}return t=bi(t),this.mo=t,this.mo}qo(t){-1===this.po.indexOf(t)&&(this.po.push(t),this.Ra(),this.Yo())}Zo(t){const e=this.po.indexOf(t);if(-1===e)throw new Error("source is not attached to scale");this.po.splice(e,1),0===this.po.length&&(this.Ro({Wn:!0}),this.Ao(null)),this.Ra(),this.Yo()}Ct(){let t=null;for(const e of this.po){const i=e.Ct();null!==i&&(null===t||i.la<t.la)&&(t=i)}return null===t?null:t.Vt}Bo(){return this.cn.invertScale}Ha(){const t=null===this.Ct();if(null!==this.bo&&(t||this.bo.Xo===t))return this.bo.Ha;this.Co.io();const e=this.Co.Ha();return this.bo={Ha:e,Xo:t},this.fo.m(),e}Ko(){return this.fo}Go(t){this.Mh()||this.Oo()||null===this.wo&&null===this.ao&&(this.Ni()||(this.wo=this.ho-t,this.ao=M(this.Lh()).Th()))}Jo(t){if(this.Mh()||this.Oo())return;if(null===this.wo)return;this.Ro({Wn:!1}),(t=this.ho-t)<0&&(t=0);let e=(this.wo+.2*(this.ho-1))/(t+.2*(this.ho-1));const i=M(this.ao).Th();e=Math.max(e,.1),i.Vh(e),this.Ao(i)}Qo(){this.Mh()||this.Oo()||(this.wo=null,this.ao=null)}t_(t){this.Vo()||null===this.Mo&&null===this.ao&&(this.Ni()||(this.Mo=t,this.ao=M(this.Lh()).Th()))}i_(t){if(this.Vo())return;if(null===this.Mo)return;const e=M(this.Lh()).Dh()/(this.Eo()-1);let i=t-this.Mo;this.Bo()&&(i*=-1);const s=i*e,n=M(this.ao).Th();n.Oh(s),this.Ao(n,!0),this.bo=null}n_(){this.Vo()||null!==this.Mo&&(this.Mo=null,this.ao=null)}ba(){return this.wa||this.Ra(),this.wa}Fi(t,e){switch(this.cn.mode){case 2:return this.s_(oi(t,e));case 3:return this.ba().format(li(t,e));default:return this.Wh(t)}}eo(t){switch(this.cn.mode){case 2:return this.s_(t);case 3:return this.ba().format(t);default:return this.Wh(t)}}Yl(t){return this.Wh(t,M(this.e_()).ba())}Zl(t,e){return t=oi(t,e),this.s_(t,wi)}r_(){return this.po}h_(t){this.oo={uo:t,_o:!1}}Vn(){this.po.forEach(t=>t.Vn())}Ra(){this.bo=null;const t=this.e_();let e=100;null!==t&&(e=Math.round(1/t.ma())),this.wa=yi,this.Mh()?(this.wa=wi,e=100):this.Oo()?(this.wa=new vt(100,1),e=100):null!==t&&(this.wa=t.ba()),this.Co=new gi(this,e,this.To.bind(this),this.Po.bind(this)),this.Co.io()}Yo(){this.mo=null}e_(){return this.po[0]||null}No(){return this.Bo()?this.cn.scaleMargins.bottom*this.At()+this.do:this.cn.scaleMargins.top*this.At()+this.co}Fo(){return this.Bo()?this.cn.scaleMargins.top*this.At()+this.co:this.cn.scaleMargins.bottom*this.At()+this.do}Wo(){this.oo._o||(this.oo._o=!0,this.l_())}Do(){this.lo=null}Po(t,e){if(this.Wo(),this.Ni())return 0;t=this.ro()&&t?ci(t,this.xo):t;const i=M(this.Lh()),s=this.Fo()+(this.Eo()-1)*(t-i.Ph())/i.Dh();return this.jo(s)}To(t,e){if(this.Wo(),this.Ni())return 0;const i=this.jo(t),s=M(this.Lh()),n=s.Ph()+s.Dh()*((i-this.Fo())/(this.Eo()-1));return this.ro()?ui(n,this.xo):n}Io(){this.bo=null,this.Co.io()}l_(){const t=this.oo.uo;if(null===t)return;let e=null;const i=this.r_();let s=0,n=0;for(const r of i){if(!r.yt())continue;const i=r.Ct();if(null===i)continue;const o=r.Il(t.Os(),t.ui());let h=o&&o.Lh();if(null!==h){switch(this.cn.mode){case 1:h=di(h,this.xo);break;case 2:h=hi(h,i.Vt);break;case 3:h=ai(h,i.Vt)}if(e=null===e?h:e.ts(M(h)),null!==o){const t=o.Eh();null!==t&&(s=Math.max(s,t.above),n=Math.max(n,t.below))}}}if(s===this.co&&n===this.do||(this.co=s,this.do=n,this.bo=null,this.Do()),null!==e){if(e.Ph()===e.Rh()){const t=this.e_(),i=5*(null===t||this.Mh()||this.Oo()?1:t.ma());this.ro()&&(e=fi(e,this.xo)),e=new Te(e.Ph()-i,e.Rh()+i),this.ro()&&(e=di(e,this.xo))}if(this.ro()){const t=fi(e,this.xo),i=mi(t);if(r=i,o=this.xo,r.$a!==o.$a||r.Ua!==o.Ua){const s=null!==this.ao?fi(this.ao,this.xo):null;this.xo=i,e=di(t,i),null!==s&&(this.ao=di(s,i))}}this.Ao(e)}else null===this.Ih&&(this.Ao(new Te(-.5,.5)),this.xo=mi(null));var r,o;this.oo._o=!0}Ho(){return this.Mh()?oi:this.Oo()?li:this.ro()?t=>ci(t,this.xo):null}a_(t,e,i){return void 0===e?(void 0===i&&(i=this.ba()),i.format(t)):e(t)}Wh(t,e){return this.a_(t,this.yo.priceFormatter,e)}s_(t,e){return this.a_(t,this.yo.percentageFormatter,e)}}class Si{constructor(t,e){this.po=[],this.o_=new Map,this.ho=0,this.__=0,this.u_=1e3,this.mo=null,this.c_=new F,this.yl=t,this.$i=e,this.d_=new ni(this);const i=e.W();this.f_=this.v_("left",i.leftPriceScale),this.p_=this.v_("right",i.rightPriceScale),this.f_.zo().l(this.m_.bind(this,this.f_),this),this.p_.zo().l(this.m_.bind(this,this.p_),this),this.b_(i)}b_(t){if(t.leftPriceScale&&this.f_.$h(t.leftPriceScale),t.rightPriceScale&&this.p_.$h(t.rightPriceScale),t.localization&&(this.f_.Ra(),this.p_.Ra()),t.overlayPriceScales){const e=Array.from(this.o_.values());for(const i of e){const e=M(i[0].Dt());e.$h(t.overlayPriceScales),t.localization&&e.Ra()}}}w_(t){switch(t){case"left":return this.f_;case"right":return this.p_}return this.o_.has(t)?S(this.o_.get(t))[0].Dt():null}S(){this.$t().g_().p(this),this.f_.zo().p(this),this.p_.zo().p(this),this.po.forEach(t=>{t.S&&t.S()}),this.c_.m()}M_(){return this.u_}x_(t){this.u_=t}$t(){return this.$i}Hi(){return this.__}At(){return this.ho}S_(t){this.__=t,this.k_()}Lo(t){this.ho=t,this.f_.Lo(t),this.p_.Lo(t),this.po.forEach(e=>{if(this.vr(e)){const i=e.Dt();null!==i&&i.Lo(t)}}),this.k_()}Ba(){return this.po}vr(t){const e=t.Dt();return null===e||this.f_!==e&&this.p_!==e}qo(t,e,i){const s=void 0!==i?i:this.C_().y_+1;this.T_(t,e,s)}Zo(t){const e=this.po.indexOf(t);C(-1!==e,"removeDataSource: invalid data source"),this.po.splice(e,1);const i=M(t.Dt()).Pa();if(this.o_.has(i)){const e=S(this.o_.get(i)),s=e.indexOf(t);-1!==s&&(e.splice(s,1),0===e.length&&this.o_.delete(i))}const s=t.Dt();s&&s.Ba().indexOf(t)>=0&&s.Zo(t),null!==s&&(s.Yo(),this.P_(s)),this.mo=null}mr(t){return t===this.f_?"left":t===this.p_?"right":"overlay"}R_(){return this.f_}D_(){return this.p_}V_(t,e){t.Go(e)}O_(t,e){t.Jo(e),this.k_()}B_(t){t.Qo()}A_(t,e){t.t_(e)}I_(t,e){t.i_(e),this.k_()}z_(t){t.n_()}k_(){this.po.forEach(t=>{t.Vn()})}vn(){let t=null;return this.$i.W().rightPriceScale.visible&&0!==this.p_.Ba().length?t=this.p_:this.$i.W().leftPriceScale.visible&&0!==this.f_.Ba().length?t=this.f_:0!==this.po.length&&(t=this.po[0].Dt()),null===t&&(t=this.p_),t}pr(){let t=null;return this.$i.W().rightPriceScale.visible?t=this.p_:this.$i.W().leftPriceScale.visible&&(t=this.f_),t}P_(t){null!==t&&t.Vo()&&this.L_(t)}E_(t){const e=this.yl.Xs();t.Ro({Wn:!0}),null!==e&&t.h_(e),this.k_()}N_(){this.L_(this.f_),this.L_(this.p_)}F_(){this.P_(this.f_),this.P_(this.p_),this.po.forEach(t=>{this.vr(t)&&this.P_(t.Dt())}),this.k_(),this.$i.Uh()}Uo(){return null===this.mo&&(this.mo=bi(this.po)),this.mo}W_(){return this.c_}j_(){return this.d_}L_(t){const e=t.r_();if(e&&e.length>0&&!this.yl.Ni()){const e=this.yl.Xs();null!==e&&t.h_(e)}t.Vn()}C_(){const t=this.Uo();if(0===t.length)return{H_:0,y_:0};let e=0,i=0;for(let s=0;s<t.length;s++){const n=t[s].Xi();null!==n&&(n<e&&(e=n),n>i&&(i=n))}return{H_:e,y_:i}}T_(t,e,i){let s=this.w_(e);if(null===s&&(s=this.v_(e,this.$i.W().overlayPriceScales)),this.po.push(t),!pt(e)){const i=this.o_.get(e)||[];i.push(t),this.o_.set(e,i)}s.qo(t),t.Gi(s),t.Ki(i),this.P_(s),this.mo=null}m_(t,e,i){e.Cr!==i.Cr&&this.L_(t)}v_(t,e){const i=Object.assign({visible:!0,autoScale:!0},A(e)),s=new Ci(t,i,this.$i.W().layout,this.$i.W().localization);return s.Lo(this.At()),s}}class Mi{constructor(t,e,i=50){this.Ke=0,this.Ge=1,this.Je=1,this.tr=new Map,this.Qe=new Map,this.U_=t,this.q_=e,this.ir=i}Y_(t){const e=t.time,i=this.q_.cacheKey(e),s=this.tr.get(i);if(void 0!==s)return s.Z_;if(this.Ke===this.ir){const t=this.Qe.get(this.Je);this.Qe.delete(this.Je),this.tr.delete(S(t)),this.Je++,this.Ke--}const n=this.U_(t);return this.tr.set(i,{Z_:n,rr:this.Ge}),this.Qe.set(this.Ge,i),this.Ke++,this.Ge++,n}}class xi{constructor(t,e){C(t<=e,"right should be >= left"),this.X_=t,this.K_=e}Os(){return this.X_}ui(){return this.K_}G_(){return this.K_-this.X_+1}Kr(t){return this.X_<=t&&t<=this.K_}Ch(t){return this.X_===t.Os()&&this.K_===t.ui()}}function Ei(t,e){return null===t||null===e?t===e:t.Ch(e)}class _i{constructor(){this.J_=new Map,this.tr=null,this.Q_=!1}tu(t){this.Q_=t,this.tr=null}iu(t,e){this.nu(e),this.tr=null;for(let i=e;i<t.length;++i){const e=t[i];let s=this.J_.get(e.timeWeight);void 0===s&&(s=[],this.J_.set(e.timeWeight,s)),s.push({index:i,time:e.time,weight:e.timeWeight,originalTime:e.originalTime})}}su(t,e){const i=Math.ceil(e/t);return null!==this.tr&&this.tr.eu===i||(this.tr={Ha:this.ru(i),eu:i}),this.tr.Ha}nu(t){if(0===t)return void this.J_.clear();const e=[];this.J_.forEach((i,s)=>{t<=i[0].index?e.push(s):i.splice(Dt(i,t,e=>e.index<t),1/0)});for(const t of e)this.J_.delete(t)}ru(t){let e=[];for(const i of Array.from(this.J_.keys()).sort((t,e)=>e-t)){if(!this.J_.get(i))continue;const s=e;e=[];const n=s.length;let r=0;const o=S(this.J_.get(i)),h=o.length;let l=1/0,a=-1/0;for(let i=0;i<h;i++){const h=o[i],c=h.index;for(;r<n;){const t=s[r],i=t.index;if(!(i<c)){l=i;break}r++,e.push(t),a=i,l=1/0}if(l-c>=t&&c-a>=t)e.push(h),a=c;else if(this.Q_)return s}for(;r<n;r++)e.push(s[r])}return e}}class $i{constructor(t){this.hu=t}lu(){return null===this.hu?null:new xi(Math.floor(this.hu.Os()),Math.ceil(this.hu.ui()))}au(){return this.hu}static ou(){return new $i(null)}}function zi(t,e){return t.weight>e.weight?t:e}class ki{constructor(t,e,i,s){this.__=0,this._u=null,this.uu=[],this.Mo=null,this.wo=null,this.cu=new _i,this.du=new Map,this.fu=$i.ou(),this.vu=!0,this.pu=new F,this.mu=new F,this.bu=new F,this.wu=null,this.gu=null,this.Mu=[],this.cn=e,this.yo=i,this.xu=e.rightOffset,this.Su=e.barSpacing,this.$i=t,this.q_=s,this.ku(),this.cu.tu(e.uniformDistribution)}W(){return this.cn}yu(t){P(this.yo,t),this.Cu(),this.ku()}$h(t,e){var i;P(this.cn,t),this.cn.fixLeftEdge&&this.Tu(),this.cn.fixRightEdge&&this.Pu(),void 0!==t.barSpacing&&this.$i.Gn(t.barSpacing),void 0!==t.rightOffset&&this.$i.Jn(t.rightOffset),void 0!==t.minBarSpacing&&this.$i.Gn(null!==(i=t.barSpacing)&&void 0!==i?i:this.Su),this.Cu(),this.ku(),this.bu.m()}mn(t){var e,i;return null!==(i=null===(e=this.uu[t])||void 0===e?void 0:e.time)&&void 0!==i?i:null}Ui(t){var e;return null!==(e=this.uu[t])&&void 0!==e?e:null}Va(t,e){if(this.uu.length<1)return null;if(this.q_.key(t)>this.q_.key(this.uu[this.uu.length-1].time))return e?this.uu.length-1:null;const i=Dt(this.uu,this.q_.key(t),(t,e)=>this.q_.key(t.time)<e);return this.q_.key(t)<this.q_.key(this.uu[i].time)?e?i:null:i}Ni(){return 0===this.__||0===this.uu.length||null===this._u}Da(){return this.uu.length>0}Xs(){return this.Ru(),this.fu.lu()}Du(){return this.Ru(),this.fu.au()}Vu(){const t=this.Xs();if(null===t)return null;const e={from:t.Os(),to:t.ui()};return this.Ou(e)}Ou(t){const e=Math.round(t.from),i=Math.round(t.to),s=M(this.Bu()),n=M(this.Au());return{from:M(this.Ui(Math.max(s,e))),to:M(this.Ui(Math.min(n,i)))}}Iu(t){return{from:M(this.Va(t.from,!0)),to:M(this.Va(t.to,!0))}}Hi(){return this.__}S_(t){if(!isFinite(t)||t<=0)return;if(this.__===t)return;const e=this.Du(),i=this.__;if(this.__=t,this.vu=!0,this.cn.lockVisibleTimeRangeOnResize&&0!==i){const e=this.Su*t/i;this.Su=e}if(this.cn.fixLeftEdge&&null!==e&&e.Os()<=0){const e=i-t;this.xu-=Math.round(e/this.Su)+1,this.vu=!0}this.zu(),this.Lu()}It(t){if(this.Ni()||!V(t))return 0;const e=this.Eu()+this.xu-t;return this.__-(e+.5)*this.Su-1}Qs(t,e){const i=this.Eu(),s=void 0===e?0:e.from,n=void 0===e?t.length:e.to;for(let e=s;e<n;e++){const s=t[e].ot,n=i+this.xu-s,r=this.__-(n+.5)*this.Su-1;t[e].nt=r}}Nu(t){return Math.ceil(this.Fu(t))}Jn(t){this.vu=!0,this.xu=t,this.Lu(),this.$i.Wu(),this.$i.Uh()}le(){return this.Su}Gn(t){this.ju(t),this.Lu(),this.$i.Wu(),this.$i.Uh()}Hu(){return this.xu}Ha(){if(this.Ni())return null;if(null!==this.gu)return this.gu;const t=this.Su,e=5*(this.$i.W().layout.fontSize+4)/8*(this.cn.tickMarkMaxCharacterLength||8),i=Math.round(e/t),s=M(this.Xs()),n=Math.max(s.Os(),s.Os()-i),r=Math.max(s.ui(),s.ui()-i),o=this.cu.su(t,e),h=this.Bu()+i,l=this.Au()-i,a=this.$u(),c=this.cn.fixLeftEdge||a,u=this.cn.fixRightEdge||a;let d=0;for(const t of o){if(!(n<=t.index&&t.index<=r))continue;let i;d<this.Mu.length?(i=this.Mu[d],i.coord=this.It(t.index),i.label=this.Uu(t),i.weight=t.weight):(i={needAlignCoordinate:!1,coord:this.It(t.index),label:this.Uu(t),weight:t.weight},this.Mu.push(i)),this.Su>e/2&&!a?i.needAlignCoordinate=!1:i.needAlignCoordinate=c&&t.index<=h||u&&t.index>=l,d++}return this.Mu.length=d,this.gu=this.Mu,this.Mu}qu(){this.vu=!0,this.Gn(this.cn.barSpacing),this.Jn(this.cn.rightOffset)}Yu(t){this.vu=!0,this._u=t,this.Lu(),this.Tu()}Zu(t,e){const i=this.Fu(t),s=this.le(),n=s+e*(s/10);this.Gn(n),this.cn.rightBarStaysOnScroll||this.Jn(this.Hu()+(i-this.Fu(t)))}Go(t){this.Mo&&this.n_(),null===this.wo&&null===this.wu&&(this.Ni()||(this.wo=t,this.Xu()))}Jo(t){if(null===this.wu)return;const e=zt(this.__-t,0,this.__),i=zt(this.__-M(this.wo),0,this.__);0!==e&&0!==i&&this.Gn(this.wu.le*e/i)}Qo(){null!==this.wo&&(this.wo=null,this.Ku())}t_(t){null===this.Mo&&null===this.wu&&(this.Ni()||(this.Mo=t,this.Xu()))}i_(t){if(null===this.Mo)return;const e=(this.Mo-t)/this.le();this.xu=M(this.wu).Hu+e,this.vu=!0,this.Lu()}n_(){null!==this.Mo&&(this.Mo=null,this.Ku())}Gu(){this.Ju(this.cn.rightOffset)}Ju(t,e=400){if(!isFinite(t))throw new RangeError("offset is required and must be finite number");if(!isFinite(e)||e<=0)throw new RangeError("animationDuration (optional) must be finite positive number");const i=this.xu,s=performance.now();this.$i.Zn({Qu:t=>(t-s)/e>=1,tc:n=>{const r=(n-s)/e;return r>=1?t:i+(t-i)*r}})}bt(t,e){this.vu=!0,this.uu=t,this.cu.iu(t,e),this.Lu()}nc(){return this.pu}sc(){return this.mu}ec(){return this.bu}Eu(){return this._u||0}rc(t){const e=t.G_();this.ju(this.__/e),this.xu=t.ui()-this.Eu(),this.Lu(),this.vu=!0,this.$i.Wu(),this.$i.Uh()}hc(){const t=this.Bu(),e=this.Au();null!==t&&null!==e&&this.rc(new xi(t,e+this.cn.rightOffset))}lc(t){const e=new xi(t.from,t.to);this.rc(e)}qi(t){return void 0!==this.yo.timeFormatter?this.yo.timeFormatter(t.originalTime):this.q_.formatHorzItem(t.time)}$u(){const{handleScroll:t,handleScale:e}=this.$i.W();return!(t.horzTouchDrag||t.mouseWheel||t.pressedMouseMove||t.vertTouchDrag||e.axisDoubleClickReset.time||e.axisPressedMouseMove.time||e.mouseWheel||e.pinch)}Bu(){return 0===this.uu.length?null:0}Au(){return 0===this.uu.length?null:this.uu.length-1}ac(t){return(this.__-1-t)/this.Su}Fu(t){const e=this.ac(t),i=this.Eu()+this.xu-e;return Math.round(1e6*i)/1e6}ju(t){const e=this.Su;this.Su=t,this.zu(),e!==this.Su&&(this.vu=!0,this.oc())}Ru(){if(!this.vu)return;if(this.vu=!1,this.Ni())return void this._c($i.ou());const t=this.Eu(),e=this.__/this.Su,i=this.xu+t,s=new xi(i-e+1,i);this._c(new $i(s))}zu(){const t=this.uc();if(this.Su<t&&(this.Su=t,this.vu=!0),0!==this.__){const t=.5*this.__;this.Su>t&&(this.Su=t,this.vu=!0)}}uc(){return this.cn.fixLeftEdge&&this.cn.fixRightEdge&&0!==this.uu.length?this.__/this.uu.length:this.cn.minBarSpacing}Lu(){const t=this.cc();null!==t&&this.xu<t&&(this.xu=t,this.vu=!0);const e=this.dc();this.xu>e&&(this.xu=e,this.vu=!0)}cc(){const t=this.Bu(),e=this._u;return null===t||null===e?null:t-e-1+(this.cn.fixLeftEdge?this.__/this.Su:Math.min(2,this.uu.length))}dc(){return this.cn.fixRightEdge?0:this.__/this.Su-Math.min(2,this.uu.length)}Xu(){this.wu={le:this.le(),Hu:this.Hu()}}Ku(){this.wu=null}Uu(t){let e=this.du.get(t.weight);return void 0===e&&(e=new Mi(t=>this.fc(t),this.q_),this.du.set(t.weight,e)),e.Y_(t)}fc(t){return this.q_.formatTickmark(t,this.yo)}_c(t){const e=this.fu;this.fu=t,Ei(e.lu(),this.fu.lu())||this.pu.m(),Ei(e.au(),this.fu.au())||this.mu.m(),this.oc()}oc(){this.gu=null}Cu(){this.oc(),this.du.clear()}ku(){this.q_.updateFormatter(this.yo)}Tu(){if(!this.cn.fixLeftEdge)return;const t=this.Bu();if(null===t)return;const e=this.Xs();if(null===e)return;const i=e.Os()-t;if(i<0){const t=this.xu-i-1;this.Jn(t)}this.zu()}Pu(){this.Lu(),this.zu()}}class Ri{X(t,e,i){t.useMediaCoordinateSpace(t=>this.K(t,e,i))}gl(t,e,i){t.useMediaCoordinateSpace(t=>this.vc(t,e,i))}vc(t,e,i){}}class Ni extends Ri{constructor(t){super(),this.mc=new Map,this.zt=t}K(t){}vc(t){if(!this.zt.yt)return;const{context:e,mediaSize:i}=t;let s=0;for(const t of this.zt.bc){if(0===t.Kt.length)continue;e.font=t.R;const n=this.wc(e,t.Kt);n>i.width?t.Zu=i.width/n:t.Zu=1,s+=t.gc*t.Zu}let n=0;switch(this.zt.Mc){case"top":n=0;break;case"center":n=Math.max((i.height-s)/2,0);break;case"bottom":n=Math.max(i.height-s,0)}e.fillStyle=this.zt.V;for(const t of this.zt.bc){e.save();let s=0;switch(this.zt.xc){case"left":e.textAlign="left",s=t.gc/2;break;case"center":e.textAlign="center",s=i.width/2;break;case"right":e.textAlign="right",s=i.width-1-t.gc/2}e.translate(s,n),e.textBaseline="top",e.font=t.R,e.scale(t.Zu,t.Zu),e.fillText(t.Kt,0,t.Sc),e.restore(),n+=t.gc*t.Zu}}wc(t,e){const i=this.kc(t.font);let s=i.get(e);return void 0===s&&(s=t.measureText(e).width,i.set(e,s)),s}kc(t){let e=this.mc.get(t);return void 0===e&&(e=new Map,this.mc.set(t,e)),e}}class Ti{constructor(t){this.ft=!0,this.Ft={yt:!1,V:"",bc:[],Mc:"center",xc:"center"},this.Wt=new Ni(this.Ft),this.jt=t}bt(){this.ft=!0}gt(){return this.ft&&(this.Mt(),this.ft=!1),this.Wt}Mt(){const t=this.jt.W(),e=this.Ft;e.yt=t.visible,e.yt&&(e.V=t.color,e.xc=t.horzAlign,e.Mc=t.vertAlign,e.bc=[{Kt:t.text,R:H(t.fontSize,t.fontFamily,t.fontStyle),gc:1.2*t.fontSize,Sc:0,Zu:0}])}}class Li extends dt{constructor(t,e){super(),this.cn=e,this.wn=new Ti(this)}Rn(){return[]}Pn(){return[this.wn]}W(){return this.cn}Vn(){this.wn.bt()}}var Oi,Fi,Pi,Di,Vi;!function(t){t[t.OnTouchEnd=0]="OnTouchEnd",t[t.OnNextTap=1]="OnNextTap"}(Oi||(Oi={}));class Ii{constructor(t,e,i){this.yc=[],this.Cc=[],this.__=0,this.Tc=null,this.Pc=new F,this.Rc=new F,this.Dc=null,this.Vc=t,this.cn=e,this.q_=i,this.Oc=new K(this),this.yl=new ki(this,e.timeScale,this.cn.localization,i),this.vt=new mt(this,e.crosshair),this.Bc=new ei(e.crosshair),this.Ac=new Li(this,e.watermark),this.Ic(),this.yc[0].x_(2e3),this.zc=this.Lc(0),this.Ec=this.Lc(1)}Kl(){this.Nc(gt.es())}Uh(){this.Nc(gt.ss())}oa(){this.Nc(new gt(1))}Gl(t){const e=this.Fc(t);this.Nc(e)}Wc(){return this.Tc}jc(t){const e=this.Tc;this.Tc=t,null!==e&&this.Gl(e.Hc),null!==t&&this.Gl(t.Hc)}W(){return this.cn}$h(t){P(this.cn,t),this.yc.forEach(e=>e.b_(t)),void 0!==t.timeScale&&this.yl.$h(t.timeScale),void 0!==t.localization&&this.yl.yu(t.localization),(t.leftPriceScale||t.rightPriceScale)&&this.Pc.m(),this.zc=this.Lc(0),this.Ec=this.Lc(1),this.Kl()}$c(t,e){if("left"===t)return void this.$h({leftPriceScale:e});if("right"===t)return void this.$h({rightPriceScale:e});const i=this.Uc(t);null!==i&&(i.Dt.$h(e),this.Pc.m())}Uc(t){for(const e of this.yc){const i=e.w_(t);if(null!==i)return{Ht:e,Dt:i}}return null}St(){return this.yl}qc(){return this.yc}Yc(){return this.Ac}Zc(){return this.vt}Xc(){return this.Rc}Kc(t,e){t.Lo(e),this.Wu()}S_(t){this.__=t,this.yl.S_(this.__),this.yc.forEach(e=>e.S_(t)),this.Wu()}Ic(t){const e=new Si(this.yl,this);void 0!==t?this.yc.splice(t,0,e):this.yc.push(e);const i=void 0===t?this.yc.length-1:t,s=gt.es();return s.Nn(i,{Fn:0,Wn:!0}),this.Nc(s),e}V_(t,e,i){t.V_(e,i)}O_(t,e,i){t.O_(e,i),this.Jl(),this.Nc(this.Gc(t,2))}B_(t,e){t.B_(e),this.Nc(this.Gc(t,2))}A_(t,e,i){e.Vo()||t.A_(e,i)}I_(t,e,i){e.Vo()||(t.I_(e,i),this.Jl(),this.Nc(this.Gc(t,2)))}z_(t,e){e.Vo()||(t.z_(e),this.Nc(this.Gc(t,2)))}E_(t,e){t.E_(e),this.Nc(this.Gc(t,2))}Jc(t){this.yl.Go(t)}Qc(t,e){const i=this.St();if(i.Ni()||0===e)return;const s=i.Hi();t=Math.max(1,Math.min(t,s)),i.Zu(t,e),this.Wu()}td(t){this.nd(0),this.sd(t),this.ed()}rd(t){this.yl.Jo(t),this.Wu()}hd(){this.yl.Qo(),this.Uh()}nd(t){this.yl.t_(t)}sd(t){this.yl.i_(t),this.Wu()}ed(){this.yl.n_(),this.Uh()}wt(){return this.Cc}ld(t,e,i,s,n){this.vt.gn(t,e);let r=NaN,o=this.yl.Nu(t);const h=this.yl.Xs();null!==h&&(o=Math.min(Math.max(h.Os(),o),h.ui()));const l=s.vn(),a=l.Ct();null!==a&&(r=l.pn(e,a)),r=this.Bc.Oa(r,o,s),this.vt.kn(o,r,s),this.oa(),n||this.Rc.m(this.vt.xt(),{x:t,y:e},i)}ad(t,e,i){const s=i.vn(),n=s.Ct(),r=s.Rt(t,M(n)),o=this.yl.Va(e,!0),h=this.yl.It(M(o));this.ld(h,r,null,i,!0)}od(t){this.Zc().Cn(),this.oa(),t||this.Rc.m(null,null,null)}Jl(){const t=this.vt.Ht();if(null!==t){const e=this.vt.xn(),i=this.vt.Sn();this.ld(e,i,null,t)}this.vt.Vn()}_d(t,e,i){const s=this.yl.mn(0);void 0!==e&&void 0!==i&&this.yl.bt(e,i);const n=this.yl.mn(0),r=this.yl.Eu(),o=this.yl.Xs();if(null!==o&&null!==s&&null!==n){const e=o.Kr(r),h=this.q_.key(s)>this.q_.key(n),l=null!==t&&t>r&&!h,a=this.yl.W().allowShiftVisibleRangeOnWhitespaceReplacement,c=e&&(!(void 0===i)||a)&&this.yl.W().shiftVisibleRangeOnNewBar;if(l&&!c){const e=t-r;this.yl.Jn(this.yl.Hu()-e)}}this.yl.Yu(t)}ia(t){null!==t&&t.F_()}dr(t){const e=this.yc.find(e=>e.Uo().includes(t));return void 0===e?null:e}Wu(){this.Ac.Vn(),this.yc.forEach(t=>t.F_()),this.Jl()}S(){this.yc.forEach(t=>t.S()),this.yc.length=0,this.cn.localization.priceFormatter=void 0,this.cn.localization.percentageFormatter=void 0,this.cn.localization.timeFormatter=void 0}ud(){return this.Oc}br(){return this.Oc.W()}g_(){return this.Pc}dd(t,e,i){const s=this.yc[0],n=this.fd(e,t,s,i);return this.Cc.push(n),1===this.Cc.length?this.Kl():this.Uh(),n}vd(t){const e=this.dr(t),i=this.Cc.indexOf(t);C(-1!==i,"Series not found"),this.Cc.splice(i,1),M(e).Zo(t),t.S&&t.S()}Xl(t,e){const i=M(this.dr(t));i.Zo(t);const s=this.Uc(e);if(null===s){const s=t.Xi();i.qo(t,e,s)}else{const n=s.Ht===i?t.Xi():void 0;s.Ht.qo(t,e,n)}}hc(){const t=gt.ss();t.$n(),this.Nc(t)}pd(t){const e=gt.ss();e.Yn(t),this.Nc(e)}Kn(){const t=gt.ss();t.Kn(),this.Nc(t)}Gn(t){const e=gt.ss();e.Gn(t),this.Nc(e)}Jn(t){const e=gt.ss();e.Jn(t),this.Nc(e)}Zn(t){const e=gt.ss();e.Zn(t),this.Nc(e)}Un(){const t=gt.ss();t.Un(),this.Nc(t)}md(){return this.cn.rightPriceScale.visible?"right":"left"}bd(){return this.Ec}q(){return this.zc}Bt(t){const e=this.Ec,i=this.zc;if(e===i)return e;if(t=Math.max(0,Math.min(100,Math.round(100*t))),null===this.Dc||this.Dc.Ps!==i||this.Dc.Rs!==e)this.Dc={Ps:i,Rs:e,wd:new Map};else{const e=this.Dc.wd.get(t);if(void 0!==e)return e}const s=function(t,e,i){const[s,n,r,o]=T(t),[h,l,a,c]=T(e),u=[_(s+i*(h-s)),_(n+i*(l-n)),_(r+i*(a-r)),$(o+i*(c-o))];return`rgba(${u[0]}, ${u[1]}, ${u[2]}, ${u[3]})`}(i,e,t/100);return this.Dc.wd.set(t,s),s}Gc(t,e){const i=new gt(e);if(null!==t){const s=this.yc.indexOf(t);i.Nn(s,{Fn:e})}return i}Fc(t,e){return void 0===e&&(e=2),this.Gc(this.dr(t),e)}Nc(t){this.Vc&&this.Vc(t),this.yc.forEach(t=>t.j_().qh().bt())}fd(t,e,i,s){const n=new ti(this,t,e,i,s),r=void 0!==t.priceScaleId?t.priceScaleId:this.md();return i.qo(n,r),pt(r)||n.$h(t),n}Lc(t){const e=this.cn.layout;return"gradient"===e.background.type?0===t?e.background.topColor:e.background.bottomColor:e.background.color}}function Bi(t){return!D(t)&&!I(t)}function Ai(t){return D(t)}!function(t){t[t.Disabled=0]="Disabled",t[t.Continuous=1]="Continuous",t[t.OnDataUpdate=2]="OnDataUpdate"}(Fi||(Fi={})),function(t){t[t.LastBar=0]="LastBar",t[t.LastVisible=1]="LastVisible"}(Pi||(Pi={})),function(t){t.Solid="solid",t.VerticalGradient="gradient"}(Di||(Di={})),function(t){t[t.Year=0]="Year",t[t.Month=1]="Month",t[t.DayOfMonth=2]="DayOfMonth",t[t.Time=3]="Time",t[t.TimeWithSeconds=4]="TimeWithSeconds"}(Vi||(Vi={}));const Ui=t=>t.getUTCFullYear();class Wi{constructor(t="yyyy-MM-dd",e="default"){this.gd=t,this.Md=e}Y_(t){return function(t,e,i){return e.replace(/yyyy/g,(t=>bt(Ui(t),4))(t)).replace(/yy/g,(t=>bt(Ui(t)%100,2))(t)).replace(/MMMM/g,((t,e)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(e,{month:"long"}))(t,i)).replace(/MMM/g,((t,e)=>new Date(t.getUTCFullYear(),t.getUTCMonth(),1).toLocaleString(e,{month:"short"}))(t,i)).replace(/MM/g,(t=>bt((t=>t.getUTCMonth()+1)(t),2))(t)).replace(/dd/g,(t=>bt((t=>t.getUTCDate())(t),2))(t))}(t,this.gd,this.Md)}}class ji{constructor(t){this.xd=t||"%h:%m:%s"}Y_(t){return this.xd.replace("%h",bt(t.getUTCHours(),2)).replace("%m",bt(t.getUTCMinutes(),2)).replace("%s",bt(t.getUTCSeconds(),2))}}const Hi={Sd:"yyyy-MM-dd",kd:"%h:%m:%s",yd:" ",Cd:"default"};class Ki{constructor(t={}){const e=Object.assign(Object.assign({},Hi),t);this.Td=new Wi(e.Sd,e.Cd),this.Pd=new ji(e.kd),this.Rd=e.yd}Y_(t){return`${this.Td.Y_(t)}${this.Rd}${this.Pd.Y_(t)}`}}function qi(t){return 60*t*60*1e3}function Xi(t){return 60*t*1e3}const Ji=[{Dd:1e3,Vd:10},{Dd:Xi(1),Vd:20},{Dd:Xi(5),Vd:21},{Dd:Xi(30),Vd:22},{Dd:qi(1),Vd:30},{Dd:qi(3),Vd:31},{Dd:qi(6),Vd:32},{Dd:qi(12),Vd:33}];function Gi(t,e){if(t.getUTCFullYear()!==e.getUTCFullYear())return 70;if(t.getUTCMonth()!==e.getUTCMonth())return 60;if(t.getUTCDate()!==e.getUTCDate())return 50;for(let i=Ji.length-1;i>=0;--i)if(Math.floor(e.getTime()/Ji[i].Dd)!==Math.floor(t.getTime()/Ji[i].Dd))return Ji[i].Vd;return 0}function Qi(t){let e=t;if(I(t)&&(e=Zi(t)),!Bi(e))throw new Error("time must be of type BusinessDay");const i=new Date(Date.UTC(e.year,e.month-1,e.day,0,0,0,0));return{Od:Math.round(i.getTime()/1e3),Bd:e}}function Yi(t){if(!Ai(t))throw new Error("time must be of type isUTCTimestamp");return{Od:t}}function Zi(t){const e=new Date(t);if(isNaN(e.getTime()))throw new Error(`Invalid date string=${t}, expected format=yyyy-mm-dd`);return{day:e.getUTCDate(),month:e.getUTCMonth()+1,year:e.getUTCFullYear()}}function ts(t){I(t.time)&&(t.time=Zi(t.time))}class es{options(){return this.cn}setOptions(t){this.cn=t,this.updateFormatter(t.localization)}preprocessData(t){Array.isArray(t)?function(t){t.forEach(ts)}(t):ts(t)}createConverterToInternalObj(t){return M(function(t){return 0===t.length?null:Bi(t[0].time)||I(t[0].time)?Qi:Yi}(t))}key(t){return"object"==typeof t&&"Od"in t?t.Od:this.key(this.convertHorzItemToInternal(t))}cacheKey(t){const e=t;return void 0===e.Bd?new Date(1e3*e.Od).getTime():new Date(Date.UTC(e.Bd.year,e.Bd.month-1,e.Bd.day)).getTime()}convertHorzItemToInternal(t){return Ai(e=t)?Yi(e):Bi(e)?Qi(e):Qi(Zi(e));var e}updateFormatter(t){if(!this.cn)return;const e=t.dateFormat;this.cn.timeScale.timeVisible?this.Ad=new Ki({Sd:e,kd:this.cn.timeScale.secondsVisible?"%h:%m:%s":"%h:%m",yd:" ",Cd:t.locale}):this.Ad=new Wi(e,t.locale)}formatHorzItem(t){const e=t;return this.Ad.Y_(new Date(1e3*e.Od))}formatTickmark(t,e){const i=function(t,e,i){switch(t){case 0:case 10:return e?i?4:3:2;case 20:case 21:case 22:case 30:case 31:case 32:case 33:return e?3:2;case 50:return 2;case 60:return 1;case 70:return 0}}(t.weight,this.cn.timeScale.timeVisible,this.cn.timeScale.secondsVisible),s=this.cn.timeScale;if(void 0!==s.tickMarkFormatter){const n=s.tickMarkFormatter(t.originalTime,i,e.locale);if(null!==n)return n}return function(t,e,i){const s={};switch(e){case 0:s.year="numeric";break;case 1:s.month="short";break;case 2:s.day="numeric";break;case 3:s.hour12=!1,s.hour="2-digit",s.minute="2-digit";break;case 4:s.hour12=!1,s.hour="2-digit",s.minute="2-digit",s.second="2-digit"}const n=void 0===t.Bd?new Date(1e3*t.Od):new Date(Date.UTC(t.Bd.year,t.Bd.month-1,t.Bd.day));return new Date(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate(),n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds()).toLocaleString(i,s)}(t.time,i,e.locale)}maxTickMarkWeight(t){let e=t.reduce(zi,t[0]).weight;return e>30&&e<50&&(e=30),e}fillWeightsForPoints(t,e){!function(t,e=0){if(0===t.length)return;let i=0===e?null:t[e-1].time.Od,s=null!==i?new Date(1e3*i):null,n=0;for(let r=e;r<t.length;++r){const e=t[r],o=new Date(1e3*e.time.Od);null!==s&&(e.timeWeight=Gi(o,s)),n+=e.time.Od-(i||e.time.Od),i=e.time.Od,s=o}if(0===e&&t.length>1){const e=Math.ceil(n/(t.length-1)),i=new Date(1e3*(t[0].time.Od-e));t[0].timeWeight=Gi(new Date(1e3*t[0].time.Od),i)}}(t,e)}static Id(t){return P({localization:{dateFormat:"dd MMM 'yy"}},null!=t?t:{})}}const is="undefined"!=typeof window;function ss(){return!!is&&window.navigator.userAgent.toLowerCase().indexOf("firefox")>-1}function ns(){return!!is&&/iPhone|iPad|iPod/.test(window.navigator.platform)}function rs(t){return t+t%2}function os(t,e){return t.zd-e.zd}function hs(t,e,i){const s=(t.zd-e.zd)/(t.ot-e.ot);return Math.sign(s)*Math.min(Math.abs(s),i)}class ls{constructor(t,e,i,s){this.Ld=null,this.Ed=null,this.Nd=null,this.Fd=null,this.Wd=null,this.jd=0,this.Hd=0,this.$d=t,this.Ud=e,this.qd=i,this.rs=s}Yd(t,e){if(null!==this.Ld){if(this.Ld.ot===e)return void(this.Ld.zd=t);if(Math.abs(this.Ld.zd-t)<this.rs)return}this.Fd=this.Nd,this.Nd=this.Ed,this.Ed=this.Ld,this.Ld={ot:e,zd:t}}Vr(t,e){if(null===this.Ld||null===this.Ed)return;if(e-this.Ld.ot>50)return;let i=0;const s=hs(this.Ld,this.Ed,this.Ud),n=os(this.Ld,this.Ed),r=[s],o=[n];if(i+=n,null!==this.Nd){const t=hs(this.Ed,this.Nd,this.Ud);if(Math.sign(t)===Math.sign(s)){const e=os(this.Ed,this.Nd);if(r.push(t),o.push(e),i+=e,null!==this.Fd){const t=hs(this.Nd,this.Fd,this.Ud);if(Math.sign(t)===Math.sign(s)){const e=os(this.Nd,this.Fd);r.push(t),o.push(e),i+=e}}}}let h=0;for(let t=0;t<r.length;++t)h+=o[t]/i*r[t];Math.abs(h)<this.$d||(this.Wd={zd:t,ot:e},this.Hd=h,this.jd=function(t,e){const i=Math.log(e);return Math.log(1*i/-t)/i}(Math.abs(h),this.qd))}tc(t){const e=M(this.Wd),i=t-e.ot;return e.zd+this.Hd*(Math.pow(this.qd,i)-1)/Math.log(this.qd)}Qu(t){return null===this.Wd||this.Zd(t)===this.jd}Zd(t){const e=t-M(this.Wd).ot;return Math.min(e,this.jd)}}class as{constructor(t,e){this.Xd=void 0,this.Kd=void 0,this.Gd=void 0,this.en=!1,this.Jd=t,this.Qd=e,this.tf()}bt(){this.tf()}if(){this.Xd&&this.Jd.removeChild(this.Xd),this.Kd&&this.Jd.removeChild(this.Kd),this.Xd=void 0,this.Kd=void 0}nf(){return this.en!==this.sf()||this.Gd!==this.ef()}ef(){return L(T(this.Qd.W().layout.textColor))>160?"dark":"light"}sf(){return this.Qd.W().layout.attributionLogo}rf(){const t=new URL(location.href);return t.hostname?"&utm_source="+t.hostname+t.pathname:""}tf(){this.nf()&&(this.if(),this.en=this.sf(),this.en&&(this.Gd=this.ef(),this.Kd=document.createElement("style"),this.Kd.innerText="a#tv-attr-logo{--fill:#131722;--stroke:#fff;position:absolute;left:10px;bottom:10px;height:19px;width:35px;margin:0;padding:0;border:0;z-index:3;}a#tv-attr-logo[data-dark]{--fill:#D1D4DC;--stroke:#131722;}",this.Xd=document.createElement("a"),this.Xd.href=`https://www.tradingview.com/?utm_medium=lwc-link&utm_campaign=lwc-chart${this.rf()}`,this.Xd.title="Charting by TradingView",this.Xd.id="tv-attr-logo",this.Xd.target="_blank",this.Xd.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 19" width="35" height="19" fill="none"><g fill-rule="evenodd" clip-path="url(#a)" clip-rule="evenodd"><path fill="var(--stroke)" d="M2 0H0v10h6v9h21.4l.5-1.3 6-15 1-2.7H23.7l-.5 1.3-.2.6a5 5 0 0 0-7-.9V0H2Zm20 17h4l5.2-13 .8-2h-7l-1 2.5-.2.5-1.5 3.8-.3.7V17Zm-.8-10a3 3 0 0 0 .7-2.7A3 3 0 1 0 16.8 7h4.4ZM14 7V2H2v6h6v9h4V7h2Z"/><path fill="var(--fill)" d="M14 2H2v6h6v9h6V2Zm12 15h-7l6-15h7l-6 15Zm-7-9a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z"/></g><defs><clipPath id="a"><path fill="var(--stroke)" d="M0 0h35v19H0z"/></clipPath></defs></svg>',this.Xd.toggleAttribute("data-dark","dark"===this.Gd),this.Jd.appendChild(this.Kd),this.Jd.appendChild(this.Xd)))}}function cs(t,e){const i=M(t.ownerDocument).createElement("canvas");t.appendChild(i);const s=(r={options:{allowResizeObserver:!1},transform:(t,e)=>({width:Math.max(t.width,e.width),height:Math.max(t.height,e.height)})},new n(i,r.transform,r.options));var r;return s.resizeCanvasElement(e),s}function us(t){var e;t.width=1,t.height=1,null===(e=t.getContext("2d"))||void 0===e||e.clearRect(0,0,1,1)}function ds(t,e,i,s){t.gl&&t.gl(e,i,s)}function fs(t,e,i,s){t.X(e,i,s)}function ms(t,e,i,s){const n=t(i,s);for(const t of n){const i=t.gt();null!==i&&e(i)}}class ps{constructor(t,e,i){this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY},this.df=null,this.ff=!1,this.vf=null,this.pf=null,this.mf=!1,this.bf=!1,this.wf=!1,this.gf=null,this.Mf=null,this.xf=null,this.Sf=null,this.kf=null,this.yf=null,this.Cf=null,this.Tf=0,this.Pf=!1,this.Rf=!1,this.Df=!1,this.Vf=0,this.Of=null,this.Bf=!ns(),this.Af=t=>{this.If(t)},this.zf=t=>{if(this.Lf(t)){const e=this.Ef(t);if(++this._f,this.uf&&this._f>1){const{Nf:i}=this.Ff(vs(t),this.cf);i<30&&!this.wf&&this.Wf(e,this.Hf.jf),this.$f()}}else{const e=this.Ef(t);if(++this.hf,this.lf&&this.hf>1){const{Nf:i}=this.Ff(vs(t),this.af);i<5&&!this.bf&&this.Uf(e,this.Hf.qf),this.Yf()}}},this.Zf=t,this.Hf=e,this.cn=i,this.Xf()}S(){null!==this.gf&&(this.gf(),this.gf=null),null!==this.Mf&&(this.Mf(),this.Mf=null),null!==this.Sf&&(this.Sf(),this.Sf=null),null!==this.kf&&(this.kf(),this.kf=null),null!==this.yf&&(this.yf(),this.yf=null),null!==this.xf&&(this.xf(),this.xf=null),this.Kf(),this.Yf()}Gf(t){this.Sf&&this.Sf();const e=this.Jf.bind(this);if(this.Sf=()=>{this.Zf.removeEventListener("mousemove",e)},this.Zf.addEventListener("mousemove",e),this.Lf(t))return;const i=this.Ef(t);this.Uf(i,this.Hf.Qf),this.Bf=!0}Yf(){null!==this.lf&&clearTimeout(this.lf),this.hf=0,this.lf=null,this.af={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}$f(){null!==this.uf&&clearTimeout(this.uf),this._f=0,this.uf=null,this.cf={nt:Number.NEGATIVE_INFINITY,st:Number.POSITIVE_INFINITY}}Jf(t){if(this.Df||null!==this.pf)return;if(this.Lf(t))return;const e=this.Ef(t);this.Uf(e,this.Hf.tv),this.Bf=!0}iv(t){const e=ys(t.changedTouches,M(this.Of));if(null===e)return;if(this.Vf=ws(t),null!==this.Cf)return;if(this.Rf)return;this.Pf=!0;const i=this.Ff(vs(e),M(this.pf)),{nv:s,sv:n,Nf:r}=i;if(this.mf||!(r<5)){if(!this.mf){const t=.5*s,e=n>=t&&!this.cn.ev(),i=t>n&&!this.cn.rv();e||i||(this.Rf=!0),this.mf=!0,this.wf=!0,this.Kf(),this.$f()}if(!this.Rf){const i=this.Ef(t,e);this.Wf(i,this.Hf.hv),bs(t)}}}lv(t){if(0!==t.button)return;const e=this.Ff(vs(t),M(this.vf)),{Nf:i}=e;if(i>=5&&(this.bf=!0,this.Yf()),this.bf){const e=this.Ef(t);this.Uf(e,this.Hf.av)}}Ff(t,e){const i=Math.abs(e.nt-t.nt),s=Math.abs(e.st-t.st);return{nv:i,sv:s,Nf:i+s}}ov(t){let e=ys(t.changedTouches,M(this.Of));if(null===e&&0===t.touches.length&&(e=t.changedTouches[0]),null===e)return;this.Of=null,this.Vf=ws(t),this.Kf(),this.pf=null,this.yf&&(this.yf(),this.yf=null);const i=this.Ef(t,e);if(this.Wf(i,this.Hf._v),++this._f,this.uf&&this._f>1){const{Nf:t}=this.Ff(vs(e),this.cf);t<30&&!this.wf&&this.Wf(i,this.Hf.jf),this.$f()}else this.wf||(this.Wf(i,this.Hf.uv),this.Hf.uv&&bs(t));0===this._f&&bs(t),0===t.touches.length&&this.ff&&(this.ff=!1,bs(t))}If(t){if(0!==t.button)return;const e=this.Ef(t);if(this.vf=null,this.Df=!1,this.kf&&(this.kf(),this.kf=null),ss()&&this.Zf.ownerDocument.documentElement.removeEventListener("mouseleave",this.Af),!this.Lf(t))if(this.Uf(e,this.Hf.cv),++this.hf,this.lf&&this.hf>1){const{Nf:i}=this.Ff(vs(t),this.af);i<5&&!this.bf&&this.Uf(e,this.Hf.qf),this.Yf()}else this.bf||this.Uf(e,this.Hf.dv)}Kf(){null!==this.df&&(clearTimeout(this.df),this.df=null)}fv(t){if(null!==this.Of)return;const e=t.changedTouches[0];this.Of=e.identifier,this.Vf=ws(t);const i=this.Zf.ownerDocument.documentElement;this.wf=!1,this.mf=!1,this.Rf=!1,this.pf=vs(e),this.yf&&(this.yf(),this.yf=null);{const e=this.iv.bind(this),s=this.ov.bind(this);this.yf=()=>{i.removeEventListener("touchmove",e),i.removeEventListener("touchend",s)},i.addEventListener("touchmove",e,{passive:!1}),i.addEventListener("touchend",s,{passive:!1}),this.Kf(),this.df=setTimeout(this.vv.bind(this,t),240)}const s=this.Ef(t,e);this.Wf(s,this.Hf.pv),this.uf||(this._f=0,this.uf=setTimeout(this.$f.bind(this),500),this.cf=vs(e))}mv(t){if(0!==t.button)return;const e=this.Zf.ownerDocument.documentElement;ss()&&e.addEventListener("mouseleave",this.Af),this.bf=!1,this.vf=vs(t),this.kf&&(this.kf(),this.kf=null);{const t=this.lv.bind(this),i=this.If.bind(this);this.kf=()=>{e.removeEventListener("mousemove",t),e.removeEventListener("mouseup",i)},e.addEventListener("mousemove",t),e.addEventListener("mouseup",i)}if(this.Df=!0,this.Lf(t))return;const i=this.Ef(t);this.Uf(i,this.Hf.bv),this.lf||(this.hf=0,this.lf=setTimeout(this.Yf.bind(this),500),this.af=vs(t))}Xf(){this.Zf.addEventListener("mouseenter",this.Gf.bind(this)),this.Zf.addEventListener("touchcancel",this.Kf.bind(this));{const t=this.Zf.ownerDocument,e=t=>{this.Hf.wv&&(t.composed&&this.Zf.contains(t.composedPath()[0])||t.target&&this.Zf.contains(t.target)||this.Hf.wv())};this.Mf=()=>{t.removeEventListener("touchstart",e)},this.gf=()=>{t.removeEventListener("mousedown",e)},t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0})}ns()&&(this.xf=()=>{this.Zf.removeEventListener("dblclick",this.zf)},this.Zf.addEventListener("dblclick",this.zf)),this.Zf.addEventListener("mouseleave",this.gv.bind(this)),this.Zf.addEventListener("touchstart",this.fv.bind(this),{passive:!0}),function(t){is&&void 0!==window.chrome&&t.addEventListener("mousedown",t=>{if(1===t.button)return t.preventDefault(),!1})}(this.Zf),this.Zf.addEventListener("mousedown",this.mv.bind(this)),this.Mv(),this.Zf.addEventListener("touchmove",()=>{},{passive:!1})}Mv(){void 0===this.Hf.xv&&void 0===this.Hf.Sv&&void 0===this.Hf.kv||(this.Zf.addEventListener("touchstart",t=>this.yv(t.touches),{passive:!0}),this.Zf.addEventListener("touchmove",t=>{if(2===t.touches.length&&null!==this.Cf&&void 0!==this.Hf.Sv){const e=gs(t.touches[0],t.touches[1])/this.Tf;this.Hf.Sv(this.Cf,e),bs(t)}},{passive:!1}),this.Zf.addEventListener("touchend",t=>{this.yv(t.touches)}))}yv(t){1===t.length&&(this.Pf=!1),2!==t.length||this.Pf||this.ff?this.Cv():this.Tv(t)}Tv(t){const e=this.Zf.getBoundingClientRect()||{left:0,top:0};this.Cf={nt:(t[0].clientX-e.left+(t[1].clientX-e.left))/2,st:(t[0].clientY-e.top+(t[1].clientY-e.top))/2},this.Tf=gs(t[0],t[1]),void 0!==this.Hf.xv&&this.Hf.xv(),this.Kf()}Cv(){null!==this.Cf&&(this.Cf=null,void 0!==this.Hf.kv&&this.Hf.kv())}gv(t){if(this.Sf&&this.Sf(),this.Lf(t))return;if(!this.Bf)return;const e=this.Ef(t);this.Uf(e,this.Hf.Pv),this.Bf=!ns()}vv(t){const e=ys(t.touches,M(this.Of));if(null===e)return;const i=this.Ef(t,e);this.Wf(i,this.Hf.Rv),this.wf=!0,this.ff=!0}Lf(t){return t.sourceCapabilities&&void 0!==t.sourceCapabilities.firesTouchEvents?t.sourceCapabilities.firesTouchEvents:ws(t)<this.Vf+500}Wf(t,e){e&&e.call(this.Hf,t)}Uf(t,e){e&&e.call(this.Hf,t)}Ef(t,e){const i=e||t,s=this.Zf.getBoundingClientRect()||{left:0,top:0};return{clientX:i.clientX,clientY:i.clientY,pageX:i.pageX,pageY:i.pageY,screenX:i.screenX,screenY:i.screenY,localX:i.clientX-s.left,localY:i.clientY-s.top,ctrlKey:t.ctrlKey,altKey:t.altKey,shiftKey:t.shiftKey,metaKey:t.metaKey,Dv:!t.type.startsWith("mouse")&&"contextmenu"!==t.type&&"click"!==t.type,Vv:t.type,Ov:i.target,Bv:t.view,Av:()=>{"touchstart"!==t.type&&bs(t)}}}}function gs(t,e){const i=t.clientX-e.clientX,s=t.clientY-e.clientY;return Math.sqrt(i*i+s*s)}function bs(t){t.cancelable&&t.preventDefault()}function vs(t){return{nt:t.pageX,st:t.pageY}}function ws(t){return t.timeStamp||performance.now()}function ys(t,e){for(let i=0;i<t.length;++i)if(t[i].identifier===e)return t[i];return null}function Cs(t){return{Hc:t.Hc,Iv:{gr:t.zv.externalId},Lv:t.zv.cursorStyle}}function Ss(t,e,i){for(const s of t){const t=s.gt();if(null!==t&&t.wr){const n=t.wr(e,i);if(null!==n)return{Bv:s,Iv:n}}}return null}function Ms(t,e){return i=>{var s,n,r,o;return(null!==(n=null===(s=i.Dt())||void 0===s?void 0:s.Pa())&&void 0!==n?n:"")!==e?[]:null!==(o=null===(r=i.da)||void 0===r?void 0:r.call(i,t))&&void 0!==o?o:[]}}function xs(t,e,i,s){if(!t.length)return;let n=0;const r=i/2,o=t[0].At(s,!0);let h=1===e?r-(t[0].Vi()-o/2):t[0].Vi()-o/2-r;h=Math.max(0,h);for(let r=1;r<t.length;r++){const o=t[r],l=t[r-1],a=l.At(s,!1),c=o.Vi(),u=l.Vi();if(1===e?c>u-a:c<u+a){const s=u-a*e;o.Oi(s);const r=s-e*a/2;if((1===e?r<0:r>i)&&h>0){const s=1===e?-1-r:r-i,o=Math.min(s,h);for(let i=n;i<t.length;i++)t[i].Oi(t[i].Vi()+e*o);h-=o}}else n=r,h=1===e?u-a-c:c-(u+a)}}class Es{constructor(t,i,s,n){this.Li=null,this.Ev=null,this.Nv=!1,this.Fv=new oe(200),this.Qr=null,this.Wv=0,this.jv=!1,this.Hv=()=>{this.jv||this.tn.$v().$t().Uh()},this.Uv=()=>{this.jv||this.tn.$v().$t().Uh()},this.tn=t,this.cn=i,this.ko=i.layout,this.Oc=s,this.qv="left"===n,this.Yv=Ms("normal",n),this.Zv=Ms("top",n),this.Xv=Ms("bottom",n),this.Kv=document.createElement("div"),this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Kv.style.width="25px",this.Kv.style.left="0",this.Kv.style.position="relative",this.Gv=cs(this.Kv,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const r=this.Gv.canvasElement;r.style.position="absolute",r.style.zIndex="1",r.style.left="0",r.style.top="0",this.Jv=cs(this.Kv,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const o=this.Jv.canvasElement;o.style.position="absolute",o.style.zIndex="2",o.style.left="0",o.style.top="0";const h={bv:this.Qv.bind(this),pv:this.Qv.bind(this),av:this.tp.bind(this),hv:this.tp.bind(this),wv:this.ip.bind(this),cv:this.np.bind(this),_v:this.np.bind(this),qf:this.sp.bind(this),jf:this.sp.bind(this),Qf:this.ep.bind(this),Pv:this.rp.bind(this)};this.hp=new ps(this.Jv.canvasElement,h,{ev:()=>!this.cn.handleScroll.vertTouchDrag,rv:()=>!0})}S(){this.hp.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose(),null!==this.Li&&this.Li.Ko().p(this),this.Li=null}lp(){return this.Kv}P(){return this.ko.fontSize}ap(){const t=this.Oc.W();return this.Qr!==t.R&&(this.Fv.nr(),this.Qr=t.R),t}op(){if(null===this.Li)return 0;let t=0;const e=this.ap(),i=M(this.Gv.canvasElement.getContext("2d"));i.save();const s=this.Li.Ha();i.font=this._p(),s.length>0&&(t=Math.max(this.Fv.xi(i,s[0].so),this.Fv.xi(i,s[s.length-1].so)));const n=this.up();for(let e=n.length;e--;){const s=this.Fv.xi(i,n[e].Kt());s>t&&(t=s)}const r=this.Li.Ct();if(null!==r&&null!==this.Ev&&2!==(o=this.cn.crosshair).mode&&o.horzLine.visible&&o.horzLine.labelVisible){const e=this.Li.pn(1,r),s=this.Li.pn(this.Ev.height-2,r);t=Math.max(t,this.Fv.xi(i,this.Li.Fi(Math.floor(Math.min(e,s))+.11111111111111,r)),this.Fv.xi(i,this.Li.Fi(Math.ceil(Math.max(e,s))-.11111111111111,r)))}var o;i.restore();const h=t||34;return rs(Math.ceil(e.C+e.T+e.A+e.I+5+h))}cp(t){null!==this.Ev&&i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`)}dp(){return M(this.Ev).width}Gi(t){this.Li!==t&&(null!==this.Li&&this.Li.Ko().p(this),this.Li=t,t.Ko().l(this.fo.bind(this),this))}Dt(){return this.Li}nr(){const t=this.tn.fp();this.tn.$v().$t().E_(t,M(this.Dt()))}vp(t){if(null===this.Ev)return;if(1!==t){this.pp(),this.Gv.applySuggestedBitmapSize();const t=h(this.Gv);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t)}),this.tn.bp(t,this.Xv),this.wp(t),this.tn.bp(t,this.Yv),this.gp(t))}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.Mp(e),this.tn.bp(e,this.Zv))}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}bt(){var t;null===(t=this.Li)||void 0===t||t.Ha()}Qv(t){if(null===this.Li||this.Li.Ni()||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp();this.Nv=!0,e.V_(i,this.Li,t.localY)}tp(t){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp(),s=this.Li;e.O_(i,s,t.localY)}ip(){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const t=this.tn.$v().$t(),e=this.tn.fp(),i=this.Li;this.Nv&&(this.Nv=!1,t.B_(e,i))}np(t){if(null===this.Li||!this.cn.handleScale.axisPressedMouseMove.price)return;const e=this.tn.$v().$t(),i=this.tn.fp();this.Nv=!1,e.B_(i,this.Li)}sp(t){this.cn.handleScale.axisDoubleClickReset.price&&this.nr()}ep(t){null!==this.Li&&(!this.tn.$v().$t().W().handleScale.axisPressedMouseMove.price||this.Li.Mh()||this.Li.Oo()||this.kp(1))}rp(t){this.kp(0)}up(){const t=[],e=null===this.Li?void 0:this.Li;return(i=>{for(let s=0;s<i.length;++s){const n=i[s].Rn(this.tn.fp(),e);for(let e=0;e<n.length;e++)t.push(n[e])}})(this.tn.fp().Uo()),t}mp({context:t,bitmapSize:e}){const{width:i,height:s}=e,n=this.tn.fp().$t(),r=n.q(),o=n.bd();r===o?it(t,0,0,i,s,r):rt(t,0,0,i,s,r,o)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:i}){if(null===this.Ev||null===this.Li||!this.Li.W().borderVisible)return;t.fillStyle=this.Li.W().borderColor;const s=Math.max(1,Math.floor(this.ap().C*i));let n;n=this.qv?e.width-s:0,t.fillRect(n,0,s,e.height)}wp(t){if(null===this.Ev||null===this.Li)return;const e=this.Li.Ha(),i=this.Li.W(),s=this.ap(),n=this.qv?this.Ev.width-s.T:0;i.borderVisible&&i.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:r,verticalPixelRatio:o})=>{t.fillStyle=i.borderColor;const h=Math.max(1,Math.floor(o)),l=Math.floor(.5*o),a=Math.round(s.T*r);t.beginPath();for(const i of e)t.rect(Math.floor(n*r),Math.round(i.Ea*o)-l,a,h);t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{var r;t.font=this._p(),t.fillStyle=null!==(r=i.textColor)&&void 0!==r?r:this.ko.textColor,t.textAlign=this.qv?"right":"left",t.textBaseline="middle";const o=this.qv?Math.round(n-s.A):Math.round(n+s.T+s.A),h=e.map(e=>this.Fv.Mi(t,e.so));for(let i=e.length;i--;){const s=e[i];t.fillText(s.so,o,s.Ea+h[i])}})}pp(){if(null===this.Ev||null===this.Li)return;const t=[],e=this.Li.Uo().slice(),i=this.tn.fp(),s=this.ap();this.Li===i.pr()&&this.tn.fp().Uo().forEach(t=>{i.vr(t)&&e.push(t)});const n=this.Li;e.forEach(e=>{e.Rn(i,n).forEach(e=>{e.Oi(null),e.Bi()&&t.push(e)})}),t.forEach(t=>t.Oi(t.ki())),this.Li.W().alignLabels&&this.yp(t,s)}yp(t,e){if(null===this.Ev)return;const i=this.Ev.height/2,s=t.filter(t=>t.ki()<=i),n=t.filter(t=>t.ki()>i);s.sort((t,e)=>e.ki()-t.ki()),n.sort((t,e)=>t.ki()-e.ki());for(const i of t){const t=Math.floor(i.At(e)/2),s=i.ki();s>-t&&s<t&&i.Oi(t),s>this.Ev.height-t&&s<this.Ev.height+t&&i.Oi(this.Ev.height-t)}xs(s,1,this.Ev.height,e),xs(n,-1,this.Ev.height,e)}gp(t){if(null===this.Ev)return;const e=this.up(),i=this.ap(),s=this.qv?"right":"left";e.forEach(e=>{e.Ai()&&e.gt(M(this.Li)).X(t,i,this.Fv,s)})}Mp(t){if(null===this.Ev||null===this.Li)return;const e=this.tn.$v().$t(),i=[],s=this.tn.fp(),n=e.Zc().Rn(s,this.Li);n.length&&i.push(n);const r=this.ap(),o=this.qv?"right":"left";i.forEach(e=>{e.forEach(e=>{e.gt(M(this.Li)).X(t,r,this.Fv,o)})})}kp(t){this.Kv.style.cursor=1===t?"ns-resize":"default"}fo(){const t=this.op();this.Wv<t&&this.tn.$v().$t().Kl(),this.Wv=t}_p(){return H(this.ko.fontSize,this.ko.fontFamily)}}function _s(t,e){var i,s;return null!==(s=null===(i=t.ua)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function $s(t,e){var i,s;return null!==(s=null===(i=t.Pn)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function zs(t,e){var i,s;return null!==(s=null===(i=t.Ji)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}function ks(t,e){var i,s;return null!==(s=null===(i=t.aa)||void 0===i?void 0:i.call(t,e))&&void 0!==s?s:[]}class Rs{constructor(t,i){this.Ev=e({width:0,height:0}),this.Cp=null,this.Tp=null,this.Pp=null,this.Rp=null,this.Dp=!1,this.Vp=new F,this.Op=new F,this.Bp=0,this.Ap=!1,this.Ip=null,this.zp=!1,this.Lp=null,this.Ep=null,this.jv=!1,this.Hv=()=>{this.jv||null===this.Np||this.$i().Uh()},this.Uv=()=>{this.jv||null===this.Np||this.$i().Uh()},this.Qd=t,this.Np=i,this.Np.W_().l(this.Fp.bind(this),this,!0),this.Wp=document.createElement("td"),this.Wp.style.padding="0",this.Wp.style.position="relative";const s=document.createElement("div");s.style.width="100%",s.style.height="100%",s.style.position="relative",s.style.overflow="hidden",this.jp=document.createElement("td"),this.jp.style.padding="0",this.Hp=document.createElement("td"),this.Hp.style.padding="0",this.Wp.appendChild(s),this.Gv=cs(s,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const n=this.Gv.canvasElement;n.style.position="absolute",n.style.zIndex="1",n.style.left="0",n.style.top="0",this.Jv=cs(s,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const r=this.Jv.canvasElement;r.style.position="absolute",r.style.zIndex="2",r.style.left="0",r.style.top="0",this.$p=document.createElement("tr"),this.$p.appendChild(this.jp),this.$p.appendChild(this.Wp),this.$p.appendChild(this.Hp),this.Up(),this.hp=new ps(this.Jv.canvasElement,this,{ev:()=>null===this.Ip&&!this.Qd.W().handleScroll.vertTouchDrag,rv:()=>null===this.Ip&&!this.Qd.W().handleScroll.horzTouchDrag})}S(){null!==this.Cp&&this.Cp.S(),null!==this.Tp&&this.Tp.S(),this.Pp=null,this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose(),null!==this.Np&&this.Np.W_().p(this),this.hp.S()}fp(){return M(this.Np)}qp(t){var e,i;null!==this.Np&&this.Np.W_().p(this),this.Np=t,null!==this.Np&&this.Np.W_().l(Rs.prototype.Fp.bind(this),this,!0),this.Up(),this.Qd.Yp().indexOf(this)===this.Qd.Yp().length-1?(this.Pp=null!==(e=this.Pp)&&void 0!==e?e:new as(this.Wp,this.Qd),this.Pp.bt()):(null===(i=this.Pp)||void 0===i||i.if(),this.Pp=null)}$v(){return this.Qd}lp(){return this.$p}Up(){if(null!==this.Np&&(this.Zp(),0!==this.$i().wt().length)){if(null!==this.Cp){const t=this.Np.R_();this.Cp.Gi(M(t))}if(null!==this.Tp){const t=this.Np.D_();this.Tp.Gi(M(t))}}}Xp(){null!==this.Cp&&this.Cp.bt(),null!==this.Tp&&this.Tp.bt()}M_(){return null!==this.Np?this.Np.M_():0}x_(t){this.Np&&this.Np.x_(t)}Qf(t){if(!this.Np)return;this.Kp();const e=t.localX,i=t.localY;this.Gp(e,i,t)}bv(t){this.Kp(),this.Jp(),this.Gp(t.localX,t.localY,t)}tv(t){var e;if(!this.Np)return;this.Kp();const i=t.localX,s=t.localY;this.Gp(i,s,t);const n=this.wr(i,s);this.Qd.Qp(null!==(e=null==n?void 0:n.Lv)&&void 0!==e?e:null),this.$i().jc(n&&{Hc:n.Hc,Iv:n.Iv})}dv(t){null!==this.Np&&(this.Kp(),this.tm(t))}qf(t){null!==this.Np&&this.im(this.Op,t)}jf(t){this.qf(t)}av(t){this.Kp(),this.nm(t),this.Gp(t.localX,t.localY,t)}cv(t){null!==this.Np&&(this.Kp(),this.Ap=!1,this.sm(t))}uv(t){null!==this.Np&&this.tm(t)}Rv(t){if(this.Ap=!0,null===this.Ip){const e={x:t.localX,y:t.localY};this.rm(e,e,t)}}Pv(t){null!==this.Np&&(this.Kp(),this.Np.$t().jc(null),this.hm())}lm(){return this.Vp}am(){return this.Op}xv(){this.Bp=1,this.$i().Un()}Sv(t,e){if(!this.Qd.W().handleScale.pinch)return;const i=5*(e-this.Bp);this.Bp=e,this.$i().Qc(t.nt,i)}pv(t){this.Ap=!1,this.zp=null!==this.Ip,this.Jp();const e=this.$i().Zc();null!==this.Ip&&e.yt()&&(this.Lp={x:e.Yt(),y:e.Zt()},this.Ip={x:t.localX,y:t.localY})}hv(t){if(null===this.Np)return;const e=t.localX,i=t.localY;if(null===this.Ip)this.nm(t);else{this.zp=!1;const s=M(this.Lp),n=s.x+(e-this.Ip.x),r=s.y+(i-this.Ip.y);this.Gp(n,r,t)}}_v(t){0===this.$v().W().trackingMode.exitMode&&(this.zp=!0),this.om(),this.sm(t)}wr(t,e){const i=this.Np;return null===i?null:function(t,e,i){const s=t.Uo(),n=function(t,e,i){var s,n;let r,o;for(const a of t){const t=null!==(n=null===(s=a.va)||void 0===s?void 0:s.call(a,e,i))&&void 0!==n?n:[];for(const e of t)h=e.zOrder,(!(l=null==r?void 0:r.zOrder)||"top"===h&&"top"!==l||"normal"===h&&"bottom"===l)&&(r=e,o=a)}var h,l;return r&&o?{zv:r,Hc:o}:null}(s,e,i);if("top"===(null==n?void 0:n.zv.zOrder))return Cs(n);for(const r of s){if(n&&n.Hc===r&&"bottom"!==n.zv.zOrder&&!n.zv.isBackground)return Cs(n);const s=Ss(r.Pn(t),e,i);if(null!==s)return{Hc:r,Bv:s.Bv,Iv:s.Iv};if(n&&n.Hc===r&&"bottom"!==n.zv.zOrder&&n.zv.isBackground)return Cs(n)}return(null==n?void 0:n.zv)?Cs(n):null}(i,t,e)}_m(t,i){M("left"===i?this.Cp:this.Tp).cp(e({width:t,height:this.Ev.height}))}um(){return this.Ev}cp(t){i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Wp.style.width=t.width+"px",this.Wp.style.height=t.height+"px")}dm(){const t=M(this.Np);t.P_(t.R_()),t.P_(t.D_());for(const e of t.Ba())if(t.vr(e)){const i=e.Dt();null!==i&&t.P_(i),e.Vn()}}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}vp(t){if(0===t)return;if(null===this.Np)return;if(t>1&&this.dm(),null!==this.Cp&&this.Cp.vp(t),null!==this.Tp&&this.Tp.vp(t),1!==t){this.Gv.applySuggestedBitmapSize();const t=h(this.Gv);null!==t&&(t.useBitmapCoordinateSpace(t=>{this.mp(t)}),this.Np&&(this.fm(t,_s),this.vm(t),this.pm(t),this.fm(t,$s),this.fm(t,zs)))}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.bm(e),this.fm(e,ks))}wm(){return this.Cp}gm(){return this.Tp}bp(t,e){this.fm(t,e)}Fp(){null!==this.Np&&this.Np.W_().p(this),this.Np=null}tm(t){this.im(this.Vp,t)}im(t,e){const i=e.localX,s=e.localY;t.M()&&t.m(this.$i().St().Nu(i),{x:i,y:s},e)}mp({context:t,bitmapSize:e}){const{width:i,height:s}=e,n=this.$i(),r=n.q(),o=n.bd();r===o?it(t,0,0,i,s,o):rt(t,0,0,i,s,r,o)}vm(t){const e=M(this.Np).j_().qh().gt();null!==e&&e.X(t,!1)}pm(t){const e=this.$i().Yc();this.Mm(t,$s,ds,e),this.Mm(t,$s,fs,e)}bm(t){this.Mm(t,$s,fs,this.$i().Zc())}fm(t,e){const i=M(this.Np).Uo();for(const s of i)this.Mm(t,e,ds,s);for(const s of i)this.Mm(t,e,fs,s)}Mm(t,e,i,s){const n=M(this.Np),r=n.$t().Wc(),o=null!==r&&r.Hc===s,h=null!==r&&o&&void 0!==r.Iv?r.Iv.Mr:void 0;ms(e,e=>i(e,t,o,h),s,n)}Zp(){if(null===this.Np)return;const t=this.Qd,e=this.Np.R_().W().visible,i=this.Np.D_().W().visible;e||null===this.Cp||(this.jp.removeChild(this.Cp.lp()),this.Cp.S(),this.Cp=null),i||null===this.Tp||(this.Hp.removeChild(this.Tp.lp()),this.Tp.S(),this.Tp=null);const s=t.$t().ud();e&&null===this.Cp&&(this.Cp=new Es(this,t.W(),s,"left"),this.jp.appendChild(this.Cp.lp())),i&&null===this.Tp&&(this.Tp=new Es(this,t.W(),s,"right"),this.Hp.appendChild(this.Tp.lp()))}xm(t){return t.Dv&&this.Ap||null!==this.Ip}Sm(t){return Math.max(0,Math.min(t,this.Ev.width-1))}km(t){return Math.max(0,Math.min(t,this.Ev.height-1))}Gp(t,e,i){this.$i().ld(this.Sm(t),this.km(e),i,M(this.Np))}hm(){this.$i().od()}om(){this.zp&&(this.Ip=null,this.hm())}rm(t,e,i){this.Ip=t,this.zp=!1,this.Gp(e.x,e.y,i);const s=this.$i().Zc();this.Lp={x:s.Yt(),y:s.Zt()}}$i(){return this.Qd.$t()}sm(t){if(!this.Dp)return;const e=this.$i(),i=this.fp();if(e.z_(i,i.vn()),this.Rp=null,this.Dp=!1,e.ed(),null!==this.Ep){const t=performance.now(),i=e.St();this.Ep.Vr(i.Hu(),t),this.Ep.Qu(t)||e.Zn(this.Ep)}}Kp(){this.Ip=null}Jp(){if(this.Np){if(this.$i().Un(),document.activeElement!==document.body&&document.activeElement!==document.documentElement)M(document.activeElement).blur();else{const t=document.getSelection();null!==t&&t.removeAllRanges()}!this.Np.vn().Ni()&&this.$i().St().Ni()}}nm(t){if(null===this.Np)return;const e=this.$i(),i=e.St();if(i.Ni())return;const s=this.Qd.W(),n=s.handleScroll,r=s.kineticScroll;if((!n.pressedMouseMove||t.Dv)&&(!n.horzTouchDrag&&!n.vertTouchDrag||!t.Dv))return;const o=this.Np.vn(),h=performance.now();if(null!==this.Rp||this.xm(t)||(this.Rp={x:t.clientX,y:t.clientY,Od:h,ym:t.localX,Cm:t.localY}),null!==this.Rp&&!this.Dp&&(this.Rp.x!==t.clientX||this.Rp.y!==t.clientY)){if(t.Dv&&r.touch||!t.Dv&&r.mouse){const t=i.le();this.Ep=new ls(.2/t,7/t,.997,15/t),this.Ep.Yd(i.Hu(),this.Rp.Od)}else this.Ep=null;o.Ni()||e.A_(this.Np,o,t.localY),e.nd(t.localX),this.Dp=!0}this.Dp&&(o.Ni()||e.I_(this.Np,o,t.localY),e.sd(t.localX),null!==this.Ep&&this.Ep.Yd(i.Hu(),h))}}class Ns{constructor(t,i,s,n,r){this.ft=!0,this.Ev=e({width:0,height:0}),this.Hv=()=>this.vp(3),this.qv="left"===t,this.Oc=s.ud,this.cn=i,this.Tm=n,this.Pm=r,this.Kv=document.createElement("div"),this.Kv.style.width="25px",this.Kv.style.height="100%",this.Kv.style.overflow="hidden",this.Gv=cs(this.Kv,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv)}S(){this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Kv}um(){return this.Ev}cp(t){i(this.Ev,t)||(this.Ev=t,this.Gv.resizeCanvasElement(t),this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.ft=!0)}vp(t){if(t<3&&!this.ft)return;if(0===this.Ev.width||0===this.Ev.height)return;this.ft=!1,this.Gv.applySuggestedBitmapSize();const e=h(this.Gv);null!==e&&e.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t)})}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}Ie({context:t,bitmapSize:e,horizontalPixelRatio:i,verticalPixelRatio:s}){if(!this.Tm())return;t.fillStyle=this.cn.timeScale.borderColor;const n=Math.floor(this.Oc.W().C*i),r=Math.floor(this.Oc.W().C*s),o=this.qv?e.width-n:0;t.fillRect(o,0,n,r)}mp({context:t,bitmapSize:e}){it(t,0,0,e.width,e.height,this.Pm())}}function Ts(t){return e=>{var i,s;return null!==(s=null===(i=e.fa)||void 0===i?void 0:i.call(e,t))&&void 0!==s?s:[]}}const Ls=Ts("normal"),Os=Ts("top"),Fs=Ts("bottom");class Ps{constructor(t,i){this.Rm=null,this.Dm=null,this.k=null,this.Vm=!1,this.Ev=e({width:0,height:0}),this.Om=new F,this.Fv=new oe(5),this.jv=!1,this.Hv=()=>{this.jv||this.Qd.$t().Uh()},this.Uv=()=>{this.jv||this.Qd.$t().Uh()},this.Qd=t,this.q_=i,this.cn=t.W().layout,this.Xd=document.createElement("tr"),this.Bm=document.createElement("td"),this.Bm.style.padding="0",this.Am=document.createElement("td"),this.Am.style.padding="0",this.Kv=document.createElement("td"),this.Kv.style.height="25px",this.Kv.style.padding="0",this.Im=document.createElement("div"),this.Im.style.width="100%",this.Im.style.height="100%",this.Im.style.position="relative",this.Im.style.overflow="hidden",this.Kv.appendChild(this.Im),this.Gv=cs(this.Im,e({width:16,height:16})),this.Gv.subscribeSuggestedBitmapSizeChanged(this.Hv);const s=this.Gv.canvasElement;s.style.position="absolute",s.style.zIndex="1",s.style.left="0",s.style.top="0",this.Jv=cs(this.Im,e({width:16,height:16})),this.Jv.subscribeSuggestedBitmapSizeChanged(this.Uv);const n=this.Jv.canvasElement;n.style.position="absolute",n.style.zIndex="2",n.style.left="0",n.style.top="0",this.Xd.appendChild(this.Bm),this.Xd.appendChild(this.Kv),this.Xd.appendChild(this.Am),this.zm(),this.Qd.$t().g_().l(this.zm.bind(this),this),this.hp=new ps(this.Jv.canvasElement,this,{ev:()=>!0,rv:()=>!this.Qd.W().handleScroll.horzTouchDrag})}S(){this.hp.S(),null!==this.Rm&&this.Rm.S(),null!==this.Dm&&this.Dm.S(),this.Jv.unsubscribeSuggestedBitmapSizeChanged(this.Uv),us(this.Jv.canvasElement),this.Jv.dispose(),this.Gv.unsubscribeSuggestedBitmapSizeChanged(this.Hv),us(this.Gv.canvasElement),this.Gv.dispose()}lp(){return this.Xd}Lm(){return this.Rm}Em(){return this.Dm}bv(t){if(this.Vm)return;this.Vm=!0;const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.Jc(t.localX)}pv(t){this.bv(t)}wv(){const t=this.Qd.$t();!t.St().Ni()&&this.Vm&&(this.Vm=!1,this.Qd.W().handleScale.axisPressedMouseMove.time&&t.hd())}av(t){const e=this.Qd.$t();!e.St().Ni()&&this.Qd.W().handleScale.axisPressedMouseMove.time&&e.rd(t.localX)}hv(t){this.av(t)}cv(){this.Vm=!1;const t=this.Qd.$t();t.St().Ni()&&!this.Qd.W().handleScale.axisPressedMouseMove.time||t.hd()}_v(){this.cv()}qf(){this.Qd.W().handleScale.axisDoubleClickReset.time&&this.Qd.$t().Kn()}jf(){this.qf()}Qf(){this.Qd.$t().W().handleScale.axisPressedMouseMove.time&&this.kp(1)}Pv(){this.kp(0)}um(){return this.Ev}Nm(){return this.Om}Fm(t,s,n){i(this.Ev,t)||(this.Ev=t,this.jv=!0,this.Gv.resizeCanvasElement(t),this.Jv.resizeCanvasElement(t),this.jv=!1,this.Kv.style.width=`${t.width}px`,this.Kv.style.height=`${t.height}px`,this.Om.m(t)),null!==this.Rm&&this.Rm.cp(e({width:s,height:t.height})),null!==this.Dm&&this.Dm.cp(e({width:n,height:t.height}))}Wm(){const t=this.jm();return Math.ceil(t.C+t.T+t.P+t.L+t.B+t.Hm)}bt(){this.Qd.$t().St().Ha()}xp(){return this.Gv.bitmapSize}Sp(t,e,i){const s=this.xp();s.width>0&&s.height>0&&t.drawImage(this.Gv.canvasElement,e,i)}vp(t){if(0===t)return;if(1!==t){this.Gv.applySuggestedBitmapSize();const e=h(this.Gv);null!==e&&(e.useBitmapCoordinateSpace(t=>{this.mp(t),this.Ie(t),this.$m(e,Fs)}),this.wp(e),this.$m(e,Ls)),null!==this.Rm&&this.Rm.vp(t),null!==this.Dm&&this.Dm.vp(t)}this.Jv.applySuggestedBitmapSize();const e=h(this.Jv);null!==e&&(e.useBitmapCoordinateSpace(({context:t,bitmapSize:e})=>{t.clearRect(0,0,e.width,e.height)}),this.Um([...this.Qd.$t().wt(),this.Qd.$t().Zc()],e),this.$m(e,Os))}$m(t,e){const i=this.Qd.$t().wt();for(const s of i)ms(e,e=>ds(e,t,!1,void 0),s,void 0);for(const s of i)ms(e,e=>fs(e,t,!1,void 0),s,void 0)}mp({context:t,bitmapSize:e}){it(t,0,0,e.width,e.height,this.Qd.$t().bd())}Ie({context:t,bitmapSize:e,verticalPixelRatio:i}){if(this.Qd.W().timeScale.borderVisible){t.fillStyle=this.qm();const s=Math.max(1,Math.floor(this.jm().C*i));t.fillRect(0,0,e.width,s)}}wp(t){const e=this.Qd.$t().St(),i=e.Ha();if(!i||0===i.length)return;const s=this.q_.maxTickMarkWeight(i),n=this.jm(),r=e.W();r.borderVisible&&r.ticksVisible&&t.useBitmapCoordinateSpace(({context:t,horizontalPixelRatio:e,verticalPixelRatio:s})=>{t.strokeStyle=this.qm(),t.fillStyle=this.qm();const r=Math.max(1,Math.floor(e)),o=Math.floor(.5*e);t.beginPath();const h=Math.round(n.T*s);for(let s=i.length;s--;){const n=Math.round(i[s].coord*e);t.rect(n-o,0,r,h)}t.fill()}),t.useMediaCoordinateSpace(({context:t})=>{const e=n.C+n.T+n.L+n.P/2;t.textAlign="center",t.textBaseline="middle",t.fillStyle=this.$(),t.font=this._p();for(const n of i)if(n.weight<s){const i=n.needAlignCoordinate?this.Ym(t,n.coord,n.label):n.coord;t.fillText(n.label,i,e)}this.Qd.W().timeScale.allowBoldLabels&&(t.font=this.Zm());for(const n of i)if(n.weight>=s){const i=n.needAlignCoordinate?this.Ym(t,n.coord,n.label):n.coord;t.fillText(n.label,i,e)}})}Ym(t,e,i){const s=this.Fv.xi(t,i),n=s/2,r=Math.floor(e-n)+.5;return r<0?e+=Math.abs(0-r):r+s>this.Ev.width&&(e-=Math.abs(this.Ev.width-(r+s))),e}Um(t,e){const i=this.jm();for(const s of t)for(const t of s.Qi())t.gt().X(e,i)}qm(){return this.Qd.W().timeScale.borderColor}$(){return this.cn.textColor}j(){return this.cn.fontSize}_p(){return H(this.j(),this.cn.fontFamily)}Zm(){return H(this.j(),this.cn.fontFamily,"bold")}jm(){null===this.k&&(this.k={C:1,N:NaN,L:NaN,B:NaN,ji:NaN,T:5,P:NaN,R:"",Wi:new oe,Hm:0});const t=this.k,e=this._p();if(t.R!==e){const i=this.j();t.P=i,t.R=e,t.L=3*i/12,t.B=3*i/12,t.ji=9*i/12,t.N=0,t.Hm=4*i/12,t.Wi.nr()}return this.k}kp(t){this.Kv.style.cursor=1===t?"ew-resize":"default"}zm(){const t=this.Qd.$t(),e=t.W();e.leftPriceScale.visible||null===this.Rm||(this.Bm.removeChild(this.Rm.lp()),this.Rm.S(),this.Rm=null),e.rightPriceScale.visible||null===this.Dm||(this.Am.removeChild(this.Dm.lp()),this.Dm.S(),this.Dm=null);const i={ud:this.Qd.$t().ud()},s=()=>e.leftPriceScale.borderVisible&&t.St().W().borderVisible,n=()=>t.bd();e.leftPriceScale.visible&&null===this.Rm&&(this.Rm=new Ns("left",e,i,s,n),this.Bm.appendChild(this.Rm.lp())),e.rightPriceScale.visible&&null===this.Dm&&(this.Dm=new Ns("right",e,i,s,n),this.Am.appendChild(this.Dm.lp()))}}const Ds=!!is&&!!navigator.userAgentData&&navigator.userAgentData.brands.some(t=>t.brand.includes("Chromium"))&&!!is&&((null===(Vs=null===navigator||void 0===navigator?void 0:navigator.userAgentData)||void 0===Vs?void 0:Vs.platform)?"Windows"===navigator.userAgentData.platform:navigator.userAgent.toLowerCase().indexOf("win")>=0);var Vs;class Is{constructor(t,e,i){var s;this.Xm=[],this.Km=0,this.ho=0,this.__=0,this.Gm=0,this.Jm=0,this.Qm=null,this.tb=!1,this.Vp=new F,this.Op=new F,this.Rc=new F,this.ib=null,this.nb=null,this.Jd=t,this.cn=e,this.q_=i,this.Xd=document.createElement("div"),this.Xd.classList.add("tv-lightweight-charts"),this.Xd.style.overflow="hidden",this.Xd.style.direction="ltr",this.Xd.style.width="100%",this.Xd.style.height="100%",(s=this.Xd).style.userSelect="none",s.style.webkitUserSelect="none",s.style.msUserSelect="none",s.style.MozUserSelect="none",s.style.webkitTapHighlightColor="transparent",this.sb=document.createElement("table"),this.sb.setAttribute("cellspacing","0"),this.Xd.appendChild(this.sb),this.eb=this.rb.bind(this),Bs(this.cn)&&this.hb(!0),this.$i=new Ii(this.Vc.bind(this),this.cn,i),this.$t().Xc().l(this.lb.bind(this),this),this.ab=new Ps(this,this.q_),this.sb.appendChild(this.ab.lp());const n=e.autoSize&&this.ob();let r=this.cn.width,o=this.cn.height;if(n||0===r||0===o){const e=t.getBoundingClientRect();r=r||e.width,o=o||e.height}this._b(r,o),this.ub(),t.appendChild(this.Xd),this.cb(),this.$i.St().ec().l(this.$i.Kl.bind(this.$i),this),this.$i.g_().l(this.$i.Kl.bind(this.$i),this)}$t(){return this.$i}W(){return this.cn}Yp(){return this.Xm}fb(){return this.ab}S(){this.hb(!1),0!==this.Km&&window.cancelAnimationFrame(this.Km),this.$i.Xc().p(this),this.$i.St().ec().p(this),this.$i.g_().p(this),this.$i.S();for(const t of this.Xm)this.sb.removeChild(t.lp()),t.lm().p(this),t.am().p(this),t.S();this.Xm=[],M(this.ab).S(),null!==this.Xd.parentElement&&this.Xd.parentElement.removeChild(this.Xd),this.Rc.S(),this.Vp.S(),this.Op.S(),this.pb()}_b(t,i,s=!1){if(this.ho===i&&this.__===t)return;const n=function(t){const i=Math.floor(t.width),s=Math.floor(t.height);return e({width:i-i%2,height:s-s%2})}(e({width:t,height:i}));this.ho=n.height,this.__=n.width;const r=this.ho+"px",o=this.__+"px";M(this.Xd).style.height=r,M(this.Xd).style.width=o,this.sb.style.height=r,this.sb.style.width=o,s?this.mb(gt.es(),performance.now()):this.$i.Kl()}vp(t){void 0===t&&(t=gt.es());for(let e=0;e<this.Xm.length;e++)this.Xm[e].vp(t.Hn(e).Fn);this.cn.timeScale.visible&&this.ab.vp(t.jn())}$h(t){const e=Bs(this.cn);this.$i.$h(t);const i=Bs(this.cn);i!==e&&this.hb(i),this.cb(),this.bb(t)}lm(){return this.Vp}am(){return this.Op}Xc(){return this.Rc}wb(){null!==this.Qm&&(this.mb(this.Qm,performance.now()),this.Qm=null);const t=this.gb(null),e=document.createElement("canvas");e.width=t.width,e.height=t.height;const i=M(e.getContext("2d"));return this.gb(i),e}Mb(t){return("left"!==t||this.xb())&&("right"!==t||this.Sb())?0===this.Xm.length?0:M("left"===t?this.Xm[0].wm():this.Xm[0].gm()).dp():0}kb(){return this.cn.autoSize&&null!==this.ib}yb(){return this.Xd}Qp(t){this.nb=t,this.nb?this.yb().style.setProperty("cursor",t):this.yb().style.removeProperty("cursor")}Cb(){return this.nb}Tb(){return S(this.Xm[0]).um()}bb(t){(void 0!==t.autoSize||!this.ib||void 0===t.width&&void 0===t.height)&&(t.autoSize&&!this.ib&&this.ob(),!1===t.autoSize&&null!==this.ib&&this.pb(),t.autoSize||void 0===t.width&&void 0===t.height||this._b(t.width||this.__,t.height||this.ho))}gb(t){let i=0,s=0;const n=this.Xm[0],r=(e,i)=>{let s=0;for(let n=0;n<this.Xm.length;n++){const r=this.Xm[n],o=M("left"===e?r.wm():r.gm()),h=o.xp();null!==t&&o.Sp(t,i,s),s+=h.height}};this.xb()&&(r("left",0),i+=M(n.wm()).xp().width);for(let e=0;e<this.Xm.length;e++){const n=this.Xm[e],r=n.xp();null!==t&&n.Sp(t,i,s),s+=r.height}i+=n.xp().width,this.Sb()&&(r("right",i),i+=M(n.gm()).xp().width);const o=(e,i,s)=>{M("left"===e?this.ab.Lm():this.ab.Em()).Sp(M(t),i,s)};if(this.cn.timeScale.visible){const e=this.ab.xp();if(null!==t){let i=0;this.xb()&&(o("left",i,s),i=M(n.wm()).xp().width),this.ab.Sp(t,i,s),i+=e.width,this.Sb()&&o("right",i,s)}s+=e.height}return e({width:i,height:s})}Pb(){let t=0,i=0,s=0;for(const e of this.Xm)this.xb()&&(i=Math.max(i,M(e.wm()).op(),this.cn.leftPriceScale.minimumWidth)),this.Sb()&&(s=Math.max(s,M(e.gm()).op(),this.cn.rightPriceScale.minimumWidth)),t+=e.M_();i=rs(i),s=rs(s);const n=this.__,r=this.ho,o=Math.max(n-i-s,0),h=this.cn.timeScale.visible;let l=h?Math.max(this.ab.Wm(),this.cn.timeScale.minimumHeight):0;var a;l=(a=l)+a%2;const c=0+l,u=r<c?0:r-c,d=u/t;let f=0;for(let t=0;t<this.Xm.length;++t){const n=this.Xm[t];n.qp(this.$i.qc()[t]);let r=0,h=0;h=t===this.Xm.length-1?u-f:Math.round(n.M_()*d),r=Math.max(h,2),f+=r,n.cp(e({width:o,height:r})),this.xb()&&n._m(i,"left"),this.Sb()&&n._m(s,"right"),n.fp()&&this.$i.Kc(n.fp(),r)}this.ab.Fm(e({width:h?o:0,height:l}),h?i:0,h?s:0),this.$i.S_(o),this.Gm!==i&&(this.Gm=i),this.Jm!==s&&(this.Jm=s)}hb(t){t?this.Xd.addEventListener("wheel",this.eb,{passive:!1}):this.Xd.removeEventListener("wheel",this.eb)}Rb(t){switch(t.deltaMode){case t.DOM_DELTA_PAGE:return 120;case t.DOM_DELTA_LINE:return 32}return Ds?1/window.devicePixelRatio:1}rb(t){if(!(0!==t.deltaX&&this.cn.handleScroll.mouseWheel||0!==t.deltaY&&this.cn.handleScale.mouseWheel))return;const e=this.Rb(t),i=e*t.deltaX/100,s=-e*t.deltaY/100;if(t.cancelable&&t.preventDefault(),0!==s&&this.cn.handleScale.mouseWheel){const e=Math.sign(s)*Math.min(1,Math.abs(s)),i=t.clientX-this.Xd.getBoundingClientRect().left;this.$t().Qc(i,e)}0!==i&&this.cn.handleScroll.mouseWheel&&this.$t().td(-80*i)}mb(t,e){var i;const s=t.jn();3===s&&this.Db(),3!==s&&2!==s||(this.Vb(t),this.Ob(t,e),this.ab.bt(),this.Xm.forEach(t=>{t.Xp()}),3===(null===(i=this.Qm)||void 0===i?void 0:i.jn())&&(this.Qm.ts(t),this.Db(),this.Vb(this.Qm),this.Ob(this.Qm,e),t=this.Qm,this.Qm=null)),this.vp(t)}Ob(t,e){for(const i of t.Qn())this.ns(i,e)}Vb(t){const e=this.$i.qc();for(let i=0;i<e.length;i++)t.Hn(i).Wn&&e[i].N_()}ns(t,e){const i=this.$i.St();switch(t.qn){case 0:i.hc();break;case 1:i.lc(t.Vt);break;case 2:i.Gn(t.Vt);break;case 3:i.Jn(t.Vt);break;case 4:i.qu();break;case 5:t.Vt.Qu(e)||i.Jn(t.Vt.tc(e))}}Vc(t){null!==this.Qm?this.Qm.ts(t):this.Qm=t,this.tb||(this.tb=!0,this.Km=window.requestAnimationFrame(t=>{if(this.tb=!1,this.Km=0,null!==this.Qm){const e=this.Qm;this.Qm=null,this.mb(e,t);for(const i of e.Qn())if(5===i.qn&&!i.Vt.Qu(t)){this.$t().Zn(i.Vt);break}}}))}Db(){this.ub()}ub(){const t=this.$i.qc(),e=t.length,i=this.Xm.length;for(let t=e;t<i;t++){const t=S(this.Xm.pop());this.sb.removeChild(t.lp()),t.lm().p(this),t.am().p(this),t.S()}for(let s=i;s<e;s++){const e=new Rs(this,t[s]);e.lm().l(this.Bb.bind(this),this),e.am().l(this.Ab.bind(this),this),this.Xm.push(e),this.sb.insertBefore(e.lp(),this.ab.lp())}for(let i=0;i<e;i++){const e=t[i],s=this.Xm[i];s.fp()!==e?s.qp(e):s.Up()}this.cb(),this.Pb()}Ib(t,e,i){var s;const n=new Map;let r;if(null!==t&&this.$i.wt().forEach(e=>{const i=e.In().ll(t);null!==i&&n.set(e,i)}),null!==t){const e=null===(s=this.$i.St().Ui(t))||void 0===s?void 0:s.originalTime;void 0!==e&&(r=e)}const o=this.$t().Wc(),h=null!==o&&o.Hc instanceof ti?o.Hc:void 0,l=null!==o&&void 0!==o.Iv?o.Iv.gr:void 0;return{zb:r,ee:null!=t?t:void 0,Lb:null!=e?e:void 0,Eb:h,Nb:n,Fb:l,Wb:null!=i?i:void 0}}Bb(t,e,i){this.Vp.m(()=>this.Ib(t,e,i))}Ab(t,e,i){this.Op.m(()=>this.Ib(t,e,i))}lb(t,e,i){this.Rc.m(()=>this.Ib(t,e,i))}cb(){const t=this.cn.timeScale.visible?"":"none";this.ab.lp().style.display=t}xb(){return this.Xm[0].fp().R_().W().visible}Sb(){return this.Xm[0].fp().D_().W().visible}ob(){return"ResizeObserver"in window&&(this.ib=new ResizeObserver(t=>{const e=t.find(t=>t.target===this.Jd);e&&this._b(e.contentRect.width,e.contentRect.height)}),this.ib.observe(this.Jd,{box:"border-box"}),!0)}pb(){null!==this.ib&&this.ib.disconnect(),this.ib=null}}function Bs(t){return Boolean(t.handleScroll.mouseWheel||t.handleScale.mouseWheel)}function As(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}function Us(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.color&&(r.V=i.color),r}function Ws(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.lineColor&&(r.lt=i.lineColor),void 0!==i.topColor&&(r.Ps=i.topColor),void 0!==i.bottomColor&&(r.Rs=i.bottomColor),r}function js(t,e,i,s){const n=i.value,r={ee:e,ot:t,Vt:[n,n,n,n],zb:s};return void 0!==i.topLineColor&&(r.Re=i.topLineColor),void 0!==i.bottomLineColor&&(r.De=i.bottomLineColor),void 0!==i.topFillColor1&&(r.ke=i.topFillColor1),void 0!==i.topFillColor2&&(r.ye=i.topFillColor2),void 0!==i.bottomFillColor1&&(r.Ce=i.bottomFillColor1),void 0!==i.bottomFillColor2&&(r.Te=i.bottomFillColor2),r}function Hs(t,e,i,s){const n={ee:e,ot:t,Vt:[i.open,i.high,i.low,i.close],zb:s};return void 0!==i.color&&(n.V=i.color),n}function Ks(t,e,i,s){const n={ee:e,ot:t,Vt:[i.open,i.high,i.low,i.close],zb:s};return void 0!==i.color&&(n.V=i.color),void 0!==i.borderColor&&(n.Ot=i.borderColor),void 0!==i.wickColor&&(n.Xh=i.wickColor),n}function qs(t,e,i,s,n){const r=S(n)(i),o=Math.max(...r),h=Math.min(...r),l=r[r.length-1],a=[l,o,h,l],c=i,{time:u,color:d}=c;return{ee:e,ot:t,Vt:a,zb:s,$e:As(c,["time","color"]),V:d}}function Xs(t){return void 0!==t.Vt}function Js(t,e){return void 0!==e.customValues&&(t.jb=e.customValues),t}function Gs(t){return(e,i,s,n,r,o)=>function(t,e){return e?e(t):void 0===(i=t).open&&void 0===i.value;var i}(s,o)?Js({ot:e,ee:i,zb:n},s):Js(t(e,i,s,n,r),s)}function Qs(t){return{Candlestick:Gs(Ks),Bar:Gs(Hs),Area:Gs(Ws),Baseline:Gs(js),Histogram:Gs(Us),Line:Gs(Us),Custom:Gs(qs)}[t]}function Ys(t){return{ee:0,Hb:new Map,la:t}}function Zs(t,e){if(void 0!==t&&0!==t.length)return{$b:e.key(t[0].ot),Ub:e.key(t[t.length-1].ot)}}function tn(t){let e;return t.forEach(t=>{void 0===e&&(e=t.zb)}),S(e)}class en{constructor(t){this.qb=new Map,this.Yb=new Map,this.Zb=new Map,this.Xb=[],this.q_=t}S(){this.qb.clear(),this.Yb.clear(),this.Zb.clear(),this.Xb=[]}Kb(t,e){let i=0!==this.qb.size,s=!1;const n=this.Yb.get(t);if(void 0!==n)if(1===this.Yb.size)i=!1,s=!0,this.qb.clear();else for(const e of this.Xb)e.pointData.Hb.delete(t)&&(s=!0);let r=[];if(0!==e.length){const i=e.map(t=>t.time),n=this.q_.createConverterToInternalObj(e),o=Qs(t.Qh()),h=t.Ca(),l=t.Ta();r=e.map((e,r)=>{const a=n(e.time),c=this.q_.key(a);let u=this.qb.get(c);void 0===u&&(u=Ys(a),this.qb.set(c,u),s=!0);const d=o(a,u.ee,e,i[r],h,l);return u.Hb.set(t,d),d})}i&&this.Gb(),this.Jb(t,r);let o=-1;if(s){const t=[];this.qb.forEach(e=>{t.push({timeWeight:0,time:e.la,pointData:e,originalTime:tn(e.Hb)})}),t.sort((t,e)=>this.q_.key(t.time)-this.q_.key(e.time)),o=this.Qb(t)}return this.tw(t,o,function(t,e,i){const s=Zs(t,i),n=Zs(e,i);if(void 0!==s&&void 0!==n)return{ta:s.Ub>=n.Ub&&s.$b>=n.$b}}(this.Yb.get(t),n,this.q_))}vd(t){return this.Kb(t,[])}iw(t,e){const i=e;!function(t){void 0===t.zb&&(t.zb=t.time)}(i),this.q_.preprocessData(e);const s=this.q_.createConverterToInternalObj([e])(e.time),n=this.Zb.get(t);if(void 0!==n&&this.q_.key(s)<this.q_.key(n))throw new Error(`Cannot update oldest data, last time=${n}, new time=${s}`);let r=this.qb.get(this.q_.key(s));const o=void 0===r;void 0===r&&(r=Ys(s),this.qb.set(this.q_.key(s),r));const h=Qs(t.Qh()),l=t.Ca(),a=t.Ta(),c=h(s,r.ee,e,i.zb,l,a);r.Hb.set(t,c),this.nw(t,c);const u={ta:Xs(c)};if(!o)return this.tw(t,-1,u);const d={timeWeight:0,time:r.la,pointData:r,originalTime:tn(r.Hb)},f=Dt(this.Xb,this.q_.key(d.time),(t,e)=>this.q_.key(t.time)<e);this.Xb.splice(f,0,d);for(let t=f;t<this.Xb.length;++t)sn(this.Xb[t].pointData,t);return this.q_.fillWeightsForPoints(this.Xb,f),this.tw(t,f,u)}nw(t,e){let i=this.Yb.get(t);void 0===i&&(i=[],this.Yb.set(t,i));const s=0!==i.length?i[i.length-1]:null;null===s||this.q_.key(e.ot)>this.q_.key(s.ot)?Xs(e)&&i.push(e):Xs(e)?i[i.length-1]=e:i.splice(-1,1),this.Zb.set(t,e.ot)}Jb(t,e){0!==e.length?(this.Yb.set(t,e.filter(Xs)),this.Zb.set(t,e[e.length-1].ot)):(this.Yb.delete(t),this.Zb.delete(t))}Gb(){for(const t of this.Xb)0===t.pointData.Hb.size&&this.qb.delete(this.q_.key(t.time))}Qb(t){let e=-1;for(let i=0;i<this.Xb.length&&i<t.length;++i){const s=this.Xb[i],n=t[i];if(this.q_.key(s.time)!==this.q_.key(n.time)){e=i;break}n.timeWeight=s.timeWeight,sn(n.pointData,i)}if(-1===e&&this.Xb.length!==t.length&&(e=Math.min(this.Xb.length,t.length)),-1===e)return-1;for(let i=e;i<t.length;++i)sn(t[i].pointData,i);return this.q_.fillWeightsForPoints(t,e),this.Xb=t,e}sw(){if(0===this.Yb.size)return null;let t=0;return this.Yb.forEach(e=>{0!==e.length&&(t=Math.max(t,e[e.length-1].ee))}),t}tw(t,e,i){const s={ew:new Map,St:{Eu:this.sw()}};if(-1!==e)this.Yb.forEach((e,n)=>{s.ew.set(n,{$e:e,rw:n===t?i:void 0})}),this.Yb.has(t)||s.ew.set(t,{$e:[],rw:i}),s.St.hw=this.Xb,s.St.lw=e;else{const e=this.Yb.get(t);s.ew.set(t,{$e:e||[],rw:i})}return s}}function sn(t,e){t.ee=e,t.Hb.forEach(t=>{t.ee=e})}function nn(t){const e={value:t.Vt[3],time:t.zb};return void 0!==t.jb&&(e.customValues=t.jb),e}function rn(t){const e=nn(t);return void 0!==t.V&&(e.color=t.V),e}function on(t){const e=nn(t);return void 0!==t.lt&&(e.lineColor=t.lt),void 0!==t.Ps&&(e.topColor=t.Ps),void 0!==t.Rs&&(e.bottomColor=t.Rs),e}function hn(t){const e=nn(t);return void 0!==t.Re&&(e.topLineColor=t.Re),void 0!==t.De&&(e.bottomLineColor=t.De),void 0!==t.ke&&(e.topFillColor1=t.ke),void 0!==t.ye&&(e.topFillColor2=t.ye),void 0!==t.Ce&&(e.bottomFillColor1=t.Ce),void 0!==t.Te&&(e.bottomFillColor2=t.Te),e}function ln(t){const e={open:t.Vt[0],high:t.Vt[1],low:t.Vt[2],close:t.Vt[3],time:t.zb};return void 0!==t.jb&&(e.customValues=t.jb),e}function an(t){const e=ln(t);return void 0!==t.V&&(e.color=t.V),e}function cn(t){const e=ln(t),{V:i,Ot:s,Xh:n}=t;return void 0!==i&&(e.color=i),void 0!==s&&(e.borderColor=s),void 0!==n&&(e.wickColor=n),e}function un(t){return{Area:on,Line:rn,Baseline:hn,Histogram:rn,Bar:an,Candlestick:cn,Custom:dn}[t]}function dn(t){const e=t.zb;return Object.assign(Object.assign({},t.$e),{time:e})}const fn={vertLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},horzLine:{color:"#9598A1",width:1,style:3,visible:!0,labelVisible:!0,labelBackgroundColor:"#131722"},mode:1},mn={vertLines:{color:"#D6DCDE",style:0,visible:!0},horzLines:{color:"#D6DCDE",style:0,visible:!0}},pn={background:{type:"solid",color:"#FFFFFF"},textColor:"#191919",fontSize:12,fontFamily:j,attributionLogo:!0},gn={autoScale:!0,mode:0,invertScale:!1,alignLabels:!0,borderVisible:!0,borderColor:"#2B2B43",entireTextOnly:!1,visible:!1,ticksVisible:!1,scaleMargins:{bottom:.1,top:.2},minimumWidth:0},bn={rightOffset:0,barSpacing:6,minBarSpacing:.5,fixLeftEdge:!1,fixRightEdge:!1,lockVisibleTimeRangeOnResize:!1,rightBarStaysOnScroll:!1,borderVisible:!0,borderColor:"#2B2B43",visible:!0,timeVisible:!1,secondsVisible:!0,shiftVisibleRangeOnNewBar:!0,allowShiftVisibleRangeOnWhitespaceReplacement:!1,ticksVisible:!1,uniformDistribution:!1,minimumHeight:0,allowBoldLabels:!0},vn={color:"rgba(0, 0, 0, 0)",visible:!1,fontSize:48,fontFamily:j,fontStyle:"",text:"",horzAlign:"center",vertAlign:"center"};function wn(){return{width:0,height:0,autoSize:!1,layout:pn,crosshair:fn,grid:mn,overlayPriceScales:Object.assign({},gn),leftPriceScale:Object.assign(Object.assign({},gn),{visible:!1}),rightPriceScale:Object.assign(Object.assign({},gn),{visible:!0}),timeScale:bn,watermark:vn,localization:{locale:is?navigator.language:"",dateFormat:"dd MMM 'yy"},handleScroll:{mouseWheel:!0,pressedMouseMove:!0,horzTouchDrag:!0,vertTouchDrag:!0},handleScale:{axisPressedMouseMove:{time:!0,price:!0},axisDoubleClickReset:{time:!0,price:!0},mouseWheel:!0,pinch:!0},kineticScroll:{mouse:!1,touch:!0},trackingMode:{exitMode:1}}}class yn{constructor(t,e){this.aw=t,this.ow=e}applyOptions(t){this.aw.$t().$c(this.ow,t)}options(){return this.Li().W()}width(){return pt(this.ow)?this.aw.Mb(this.ow):0}Li(){return M(this.aw.$t().Uc(this.ow)).Dt}}function Cn(t,e,i){const s=As(t,["time","originalTime"]),n=Object.assign({time:e},s);return void 0!==i&&(n.originalTime=i),n}const Sn={color:"#FF0000",price:0,lineStyle:2,lineWidth:1,lineVisible:!0,axisLabelVisible:!0,title:"",axisLabelColor:"",axisLabelTextColor:""};class Mn{constructor(t){this.Nh=t}applyOptions(t){this.Nh.$h(t)}options(){return this.Nh.W()}_w(){return this.Nh}}class xn{constructor(t,e,i,s,n){this.uw=new F,this.Es=t,this.cw=e,this.dw=i,this.q_=n,this.fw=s}S(){this.uw.S()}priceFormatter(){return this.Es.ba()}priceToCoordinate(t){const e=this.Es.Ct();return null===e?null:this.Es.Dt().Rt(t,e.Vt)}coordinateToPrice(t){const e=this.Es.Ct();return null===e?null:this.Es.Dt().pn(t,e.Vt)}barsInLogicalRange(t){if(null===t)return null;const e=new $i(new xi(t.from,t.to)).lu(),i=this.Es.In();if(i.Ni())return null;const s=i.ll(e.Os(),1),n=i.ll(e.ui(),-1),r=M(i.el()),o=M(i.An());if(null!==s&&null!==n&&s.ee>n.ee)return{barsBefore:t.from-r,barsAfter:o-t.to};const h={barsBefore:null===s||s.ee===r?t.from-r:s.ee-r,barsAfter:null===n||n.ee===o?o-t.to:o-n.ee};return null!==s&&null!==n&&(h.from=s.zb,h.to=n.zb),h}setData(t){this.q_,this.Es.Qh(),this.cw.pw(this.Es,t),this.mw("full")}update(t){this.Es.Qh(),this.cw.bw(this.Es,t),this.mw("update")}dataByIndex(t,e){const i=this.Es.In().ll(t,e);return null===i?null:un(this.seriesType())(i)}data(){const t=un(this.seriesType());return this.Es.In().ne().map(e=>t(e))}subscribeDataChanged(t){this.uw.l(t)}unsubscribeDataChanged(t){this.uw.v(t)}setMarkers(t){this.q_;const e=t.map(t=>Cn(t,this.q_.convertHorzItemToInternal(t.time),t.time));this.Es.na(e)}markers(){return this.Es.sa().map(t=>Cn(t,t.originalTime,void 0))}applyOptions(t){this.Es.$h(t)}options(){return A(this.Es.W())}priceScale(){return this.dw.priceScale(this.Es.Dt().Pa())}createPriceLine(t){const e=P(A(Sn),t),i=this.Es.ea(e);return new Mn(i)}removePriceLine(t){this.Es.ra(t._w())}seriesType(){return this.Es.Qh()}attachPrimitive(t){this.Es.ka(t),t.attached&&t.attached({chart:this.fw,series:this,requestUpdate:()=>this.Es.$t().Kl()})}detachPrimitive(t){this.Es.ya(t),t.detached&&t.detached()}mw(t){this.uw.M()&&this.uw.m(t)}}class En{constructor(t,e,i){this.ww=new F,this.mu=new F,this.Om=new F,this.$i=t,this.yl=t.St(),this.ab=e,this.yl.nc().l(this.gw.bind(this)),this.yl.sc().l(this.Mw.bind(this)),this.ab.Nm().l(this.xw.bind(this)),this.q_=i}S(){this.yl.nc().p(this),this.yl.sc().p(this),this.ab.Nm().p(this),this.ww.S(),this.mu.S(),this.Om.S()}scrollPosition(){return this.yl.Hu()}scrollToPosition(t,e){e?this.yl.Ju(t,1e3):this.$i.Jn(t)}scrollToRealTime(){this.yl.Gu()}getVisibleRange(){const t=this.yl.Vu();return null===t?null:{from:t.from.originalTime,to:t.to.originalTime}}setVisibleRange(t){const e={from:this.q_.convertHorzItemToInternal(t.from),to:this.q_.convertHorzItemToInternal(t.to)},i=this.yl.Iu(e);this.$i.pd(i)}getVisibleLogicalRange(){const t=this.yl.Du();return null===t?null:{from:t.Os(),to:t.ui()}}setVisibleLogicalRange(t){C(t.from<=t.to,"The from index cannot be after the to index."),this.$i.pd(t)}resetTimeScale(){this.$i.Kn()}fitContent(){this.$i.hc()}logicalToCoordinate(t){const e=this.$i.St();return e.Ni()?null:e.It(t)}coordinateToLogical(t){return this.yl.Ni()?null:this.yl.Nu(t)}timeToCoordinate(t){const e=this.q_.convertHorzItemToInternal(t),i=this.yl.Va(e,!1);return null===i?null:this.yl.It(i)}coordinateToTime(t){const e=this.$i.St(),i=e.Nu(t),s=e.Ui(i);return null===s?null:s.originalTime}width(){return this.ab.um().width}height(){return this.ab.um().height}subscribeVisibleTimeRangeChange(t){this.ww.l(t)}unsubscribeVisibleTimeRangeChange(t){this.ww.v(t)}subscribeVisibleLogicalRangeChange(t){this.mu.l(t)}unsubscribeVisibleLogicalRangeChange(t){this.mu.v(t)}subscribeSizeChange(t){this.Om.l(t)}unsubscribeSizeChange(t){this.Om.v(t)}applyOptions(t){this.yl.$h(t)}options(){return Object.assign(Object.assign({},A(this.yl.W())),{barSpacing:this.yl.le()})}gw(){this.ww.M()&&this.ww.m(this.getVisibleRange())}Mw(){this.mu.M()&&this.mu.m(this.getVisibleLogicalRange())}xw(t){this.Om.m(t.width,t.height)}}function _n(t){return function(t){if(B(t.handleScale)){const e=t.handleScale;t.handleScale={axisDoubleClickReset:{time:e,price:e},axisPressedMouseMove:{time:e,price:e},mouseWheel:e,pinch:e}}else if(void 0!==t.handleScale){const{axisPressedMouseMove:e,axisDoubleClickReset:i}=t.handleScale;B(e)&&(t.handleScale.axisPressedMouseMove={time:e,price:e}),B(i)&&(t.handleScale.axisDoubleClickReset={time:i,price:i})}const e=t.handleScroll;B(e)&&(t.handleScroll={horzTouchDrag:e,vertTouchDrag:e,mouseWheel:e,pressedMouseMove:e})}(t),t}class $n{constructor(t,e,i){this.Sw=new Map,this.kw=new Map,this.yw=new F,this.Cw=new F,this.Tw=new F,this.Pw=new en(e);const s=void 0===i?A(wn()):P(A(wn()),_n(i));this.q_=e,this.aw=new Is(t,s,e),this.aw.lm().l(t=>{this.yw.M()&&this.yw.m(this.Rw(t()))},this),this.aw.am().l(t=>{this.Cw.M()&&this.Cw.m(this.Rw(t()))},this),this.aw.Xc().l(t=>{this.Tw.M()&&this.Tw.m(this.Rw(t()))},this);const n=this.aw.$t();this.Dw=new En(n,this.aw.fb(),this.q_)}remove(){this.aw.lm().p(this),this.aw.am().p(this),this.aw.Xc().p(this),this.Dw.S(),this.aw.S(),this.Sw.clear(),this.kw.clear(),this.yw.S(),this.Cw.S(),this.Tw.S(),this.Pw.S()}resize(t,e,i){this.autoSizeActive()||this.aw._b(t,e,i)}addCustomSeries(t,e){const i=x(t),s=Object.assign(Object.assign({},m),i.defaultOptions());return this.Vw("Custom",s,e,i)}addAreaSeries(t){return this.Vw("Area",u,t)}addBaselineSeries(t){return this.Vw("Baseline",d,t)}addBarSeries(t){return this.Vw("Bar",a,t)}addCandlestickSeries(t={}){return function(t){void 0!==t.borderColor&&(t.borderUpColor=t.borderColor,t.borderDownColor=t.borderColor),void 0!==t.wickColor&&(t.wickUpColor=t.wickColor,t.wickDownColor=t.wickColor)}(t),this.Vw("Candlestick",l,t)}addHistogramSeries(t){return this.Vw("Histogram",f,t)}addLineSeries(t){return this.Vw("Line",c,t)}removeSeries(t){const e=S(this.Sw.get(t)),i=this.Pw.vd(e);this.aw.$t().vd(e),this.Ow(i),this.Sw.delete(t),this.kw.delete(e)}pw(t,e){this.Ow(this.Pw.Kb(t,e))}bw(t,e){this.Ow(this.Pw.iw(t,e))}subscribeClick(t){this.yw.l(t)}unsubscribeClick(t){this.yw.v(t)}subscribeCrosshairMove(t){this.Tw.l(t)}unsubscribeCrosshairMove(t){this.Tw.v(t)}subscribeDblClick(t){this.Cw.l(t)}unsubscribeDblClick(t){this.Cw.v(t)}priceScale(t){return new yn(this.aw,t)}timeScale(){return this.Dw}applyOptions(t){this.aw.$h(_n(t))}options(){return this.aw.W()}takeScreenshot(){return this.aw.wb()}autoSizeActive(){return this.aw.kb()}chartElement(){return this.aw.yb()}paneSize(){const t=this.aw.Tb();return{height:t.height,width:t.width}}setCrosshairPosition(t,e,i){const s=this.Sw.get(i);if(void 0===s)return;const n=this.aw.$t().dr(s);null!==n&&this.aw.$t().ad(t,e,n)}clearCrosshairPosition(){this.aw.$t().od(!0)}Vw(t,e,i={},s){!function(t){if(void 0===t||"custom"===t.type)return;const e=t;void 0!==e.minMove&&void 0===e.precision&&(e.precision=function(t){if(t>=1)return 0;let e=0;for(;e<8;e++){const i=Math.round(t);if(Math.abs(i-t)<1e-8)return e;t*=10}return e}(e.minMove))}(i.priceFormat);const n=P(A(p),A(e),i),r=this.aw.$t().dd(t,n,s),o=new xn(r,this,this,this,this.q_);return this.Sw.set(o,r),this.kw.set(r,o),o}Ow(t){const e=this.aw.$t();e._d(t.St.Eu,t.St.hw,t.St.lw),t.ew.forEach((t,e)=>e.J(t.$e,t.rw)),e.Wu()}Bw(t){return S(this.kw.get(t))}Rw(t){const e=new Map;t.Nb.forEach((t,i)=>{const s=i.Qh(),n=un(s)(t);if("Custom"!==s)C(function(t){return function(t){return void 0!==t.open}(t)||function(t){return void 0!==t.value}(t)}(n));else{const t=i.Ta();C(!t||!1===t(n))}e.set(this.Bw(i),n)});const i=void 0!==t.Eb&&this.kw.has(t.Eb)?this.Bw(t.Eb):void 0;return{time:t.zb,logical:t.ee,point:t.Lb,hoveredSeries:i,hoveredObjectId:t.Fb,seriesData:e,sourceEvent:t.Wb}}}function zn(t,e){return function(t,e,i){let s;if(I(t)){const e=document.getElementById(t);C(null!==e,`Cannot find element in DOM with id=${t}`),s=e}else s=t;const n=new $n(s,e,i);return e.setOptions(n.options()),n}(t,new es,es.Id(e))}Object.assign(Object.assign({},p),m);const kn=e=>{const[i]=t.useState(e||null),[s,n]=t.useState(!1),[r,o]=t.useState(!1);t.useEffect(()=>{if(!i)return n(!1),void o(!1);o(!0);const t=()=>{console.log("✅ [useSocket] Connected to Socket.IO server"),n(!0),o(!1)},e=()=>{console.log("🔌 [useSocket] Disconnected from Socket.IO server"),n(!1),o(!1)},s=t=>{console.error("❌ [useSocket] Connection error:",t),o(!1)};return i.connected&&(n(!0),o(!1)),i.on("connect",t),i.on("disconnect",e),i.on("connect_error",s),()=>{i.off("connect",t),i.off("disconnect",e),i.off("connect_error",s)}},[i]);const h=t.useCallback(()=>{console.log("🔍 [useSocket] Connect called - connection managed by provider")},[]),l=t.useCallback(()=>{console.log("🔍 [useSocket] Disconnect called - connection managed by provider")},[]),a=t.useCallback((t,e=60,s,n,r)=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot subscribe"),!1;try{return i.emit("ohlcv:subscribe",{mint:t,timeFrame:e}),s&&i.on("ohlcv:initial",s),n&&i.on("ohlcv:update",n),r&&i.on("ohlcv:newCandle",r),console.log(`📊 [useSocket] Subscribed to OHLCV updates for ${t} (${e}s)`),!0}catch(t){return console.error("❌ [useSocket] Failed to subscribe to OHLCV:",t),!1}},[i]),c=t.useCallback((t,e=60,s,n,r)=>{if(!i?.connected)return!1;try{return i.emit("ohlcv:unsubscribe",{mint:t,timeFrame:e}),s&&i.off("ohlcv:initial",s),n&&i.off("ohlcv:update",n),r&&i.off("ohlcv:newCandle",r),console.log(`📊 [useSocket] Unsubscribed from OHLCV updates for ${t} (${e}s)`),!0}catch(t){return console.error("❌ [useSocket] Failed to unsubscribe from OHLCV:",t),!1}},[i]),u=t.useCallback((t,e)=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot subscribe"),!1;try{return i.emit("price:subscribe",{mint:t}),e&&i.on("price:update",e),console.log(`💰 [useSocket] Subscribed to price updates for ${t}`),!0}catch(t){return console.error("❌ [useSocket] Failed to subscribe to price:",t),!1}},[i]),d=t.useCallback((t,e)=>{if(!i?.connected)return!1;try{return i.emit("price:unsubscribe",{mint:t}),e&&i.off("price:update",e),console.log(`💰 [useSocket] Unsubscribed from price updates for ${t}`),!0}catch(t){return console.error("❌ [useSocket] Failed to unsubscribe from price:",t),!1}},[i]),f=t.useCallback(t=>{if(!i?.connected)return console.warn("⚠️ [useSocket] Socket not connected, cannot send test message"),!1;try{return i.emit("test-message",{message:t,timestamp:Date.now()}),i.once("test-response",t=>{console.log("🧪 [useSocket] Test response received:",t)}),!0}catch(t){return console.error("❌ [useSocket] Failed to send test message:",t),!1}},[i]);return{socket:i,isConnected:s,isConnecting:r,connect:h,disconnect:l,subscribeToOHLCV:a,unsubscribeFromOHLCV:c,subscribeToPrice:u,unsubscribeFromPrice:d,testConnection:f}};function Rn(e,i){const[s,n]=t.useState(null),[r,o]=t.useState(!1),[h,l]=t.useState(null),[a,c]=t.useState(null),[u,d]=t.useState(!1);t.useEffect(()=>{i&&(n(i),c(Date.now()),d(!0),o(!1))},[i]);const f=t.useMemo(()=>{if(!s||!s.market)return{currentPrice:0,currentMarketCap:0,currentVolume:0,performance24h:{value:"0.00%",isPositive:!1,raw:0},performance7d:{value:"0.00%",isPositive:!1,raw:0},performance1m:{value:"0.00%",isPositive:!1,raw:0},performanceAllTime:{value:"0.00%",isPositive:!1,raw:0},high24h:0,low24h:0,volume24h:0,return24h:0};const t=parseFloat(s.market?.price||"0")||0,e=parseFloat(s.market?.marketCap||"0")||0;let i=parseFloat(s.volume?.current||"0")||0;i<=.01&&(i=parseFloat(s.blockchain?.currentRealSol||"0")||0);const n={value:s.performance?.["24H"]?.percentage||"0.00%",isPositive:s.performance?.["24H"]?.isPositive||!1,raw:s.performance?.["24H"]?.gain||0},r={value:s.performance?.["7D"]?.percentage||"0.00%",isPositive:s.performance?.["7D"]?.isPositive||!1,raw:s.performance?.["7D"]?.gain||0},o={value:s.performance?.["1M"]?.percentage||"0.00%",isPositive:s.performance?.["1M"]?.isPositive||!1,raw:s.performance?.["1M"]?.gain||0},h={value:s.performance?.["All Time"]?.percentage||"0.00%",isPositive:s.performance?.["All Time"]?.isPositive||!1,raw:s.performance?.["All Time"]?.gain||0},l=parseFloat(s["24H"]?.high||"0")||0,a=parseFloat(s["24H"]?.low||"0")||0;let c=parseFloat(s.volume?.["24h"]||"0")||0;c<=.01&&(c=parseFloat(s.blockchain?.currentRealSol||"0")||0);return{currentPrice:t,currentMarketCap:e,currentVolume:i,performance24h:n,performance7d:r,performance1m:o,performanceAllTime:h,high24h:l,low24h:a,volume24h:c,return24h:parseFloat(s["24H"]?.return||"0")||0}},[s]),m=t.useCallback(t=>t>.01,[]);return{analytics:s,...f,isRealVolume:m,loading:r,error:h,connected:u,lastUpdate:a}}function Nn(t,e){return function(){return t.apply(e,arguments)}}const{toString:Tn}=Object.prototype,{getPrototypeOf:Ln}=Object,{iterator:On,toStringTag:Fn}=Symbol,Pn=(Dn=Object.create(null),t=>{const e=Tn.call(t);return Dn[e]||(Dn[e]=e.slice(8,-1).toLowerCase())});var Dn;const Vn=t=>(t=t.toLowerCase(),e=>Pn(e)===t),In=t=>e=>typeof e===t,{isArray:Bn}=Array,An=In("undefined");function Un(t){return null!==t&&!An(t)&&null!==t.constructor&&!An(t.constructor)&&Hn(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const Wn=Vn("ArrayBuffer");const jn=In("string"),Hn=In("function"),Kn=In("number"),qn=t=>null!==t&&"object"==typeof t,Xn=t=>{if("object"!==Pn(t))return!1;const e=Ln(t);return!(null!==e&&e!==Object.prototype&&null!==Object.getPrototypeOf(e)||Fn in t||On in t)},Jn=Vn("Date"),Gn=Vn("File"),Qn=Vn("Blob"),Yn=Vn("FileList"),Zn=Vn("URLSearchParams"),[tr,er,ir,sr]=["ReadableStream","Request","Response","Headers"].map(Vn);function nr(t,e,{allOwnKeys:i=!1}={}){if(null==t)return;let s,n;if("object"!=typeof t&&(t=[t]),Bn(t))for(s=0,n=t.length;s<n;s++)e.call(null,t[s],s,t);else{if(Un(t))return;const n=i?Object.getOwnPropertyNames(t):Object.keys(t),r=n.length;let o;for(s=0;s<r;s++)o=n[s],e.call(null,t[o],o,t)}}function rr(t,e){if(Un(t))return null;e=e.toLowerCase();const i=Object.keys(t);let s,n=i.length;for(;n-- >0;)if(s=i[n],e===s.toLowerCase())return s;return null}const or="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,hr=t=>!An(t)&&t!==or;const lr=(ar="undefined"!=typeof Uint8Array&&Ln(Uint8Array),t=>ar&&t instanceof ar);var ar;const cr=Vn("HTMLFormElement"),ur=(({hasOwnProperty:t})=>(e,i)=>t.call(e,i))(Object.prototype),dr=Vn("RegExp"),fr=(t,e)=>{const i=Object.getOwnPropertyDescriptors(t),s={};nr(i,(i,n)=>{let r;!1!==(r=e(i,n,t))&&(s[n]=r||i)}),Object.defineProperties(t,s)};const mr=Vn("AsyncFunction"),pr=(gr="function"==typeof setImmediate,br=Hn(or.postMessage),gr?setImmediate:br?(vr=`axios@${Math.random()}`,wr=[],or.addEventListener("message",({source:t,data:e})=>{t===or&&e===vr&&wr.length&&wr.shift()()},!1),t=>{wr.push(t),or.postMessage(vr,"*")}):t=>setTimeout(t));var gr,br,vr,wr;const yr="undefined"!=typeof queueMicrotask?queueMicrotask.bind(or):"undefined"!=typeof process&&process.nextTick||pr;var Cr={isArray:Bn,isArrayBuffer:Wn,isBuffer:Un,isFormData:t=>{let e;return t&&("function"==typeof FormData&&t instanceof FormData||Hn(t.append)&&("formdata"===(e=Pn(t))||"object"===e&&Hn(t.toString)&&"[object FormData]"===t.toString()))},isArrayBufferView:function(t){let e;return e="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer&&Wn(t.buffer),e},isString:jn,isNumber:Kn,isBoolean:t=>!0===t||!1===t,isObject:qn,isPlainObject:Xn,isEmptyObject:t=>{if(!qn(t)||Un(t))return!1;try{return 0===Object.keys(t).length&&Object.getPrototypeOf(t)===Object.prototype}catch(t){return!1}},isReadableStream:tr,isRequest:er,isResponse:ir,isHeaders:sr,isUndefined:An,isDate:Jn,isFile:Gn,isBlob:Qn,isRegExp:dr,isFunction:Hn,isStream:t=>qn(t)&&Hn(t.pipe),isURLSearchParams:Zn,isTypedArray:lr,isFileList:Yn,forEach:nr,merge:function t(){const{caseless:e,skipUndefined:i}=hr(this)&&this||{},s={},n=(n,r)=>{const o=e&&rr(s,r)||r;Xn(s[o])&&Xn(n)?s[o]=t(s[o],n):Xn(n)?s[o]=t({},n):Bn(n)?s[o]=n.slice():i&&An(n)||(s[o]=n)};for(let t=0,e=arguments.length;t<e;t++)arguments[t]&&nr(arguments[t],n);return s},extend:(t,e,i,{allOwnKeys:s}={})=>(nr(e,(e,s)=>{i&&Hn(e)?t[s]=Nn(e,i):t[s]=e},{allOwnKeys:s}),t),trim:t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:t=>(65279===t.charCodeAt(0)&&(t=t.slice(1)),t),inherits:(t,e,i,s)=>{t.prototype=Object.create(e.prototype,s),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),i&&Object.assign(t.prototype,i)},toFlatObject:(t,e,i,s)=>{let n,r,o;const h={};if(e=e||{},null==t)return e;do{for(n=Object.getOwnPropertyNames(t),r=n.length;r-- >0;)o=n[r],s&&!s(o,t,e)||h[o]||(e[o]=t[o],h[o]=!0);t=!1!==i&&Ln(t)}while(t&&(!i||i(t,e))&&t!==Object.prototype);return e},kindOf:Pn,kindOfTest:Vn,endsWith:(t,e,i)=>{t=String(t),(void 0===i||i>t.length)&&(i=t.length),i-=e.length;const s=t.indexOf(e,i);return-1!==s&&s===i},toArray:t=>{if(!t)return null;if(Bn(t))return t;let e=t.length;if(!Kn(e))return null;const i=new Array(e);for(;e-- >0;)i[e]=t[e];return i},forEachEntry:(t,e)=>{const i=(t&&t[On]).call(t);let s;for(;(s=i.next())&&!s.done;){const i=s.value;e.call(t,i[0],i[1])}},matchAll:(t,e)=>{let i;const s=[];for(;null!==(i=t.exec(e));)s.push(i);return s},isHTMLForm:cr,hasOwnProperty:ur,hasOwnProp:ur,reduceDescriptors:fr,freezeMethods:t=>{fr(t,(e,i)=>{if(Hn(t)&&-1!==["arguments","caller","callee"].indexOf(i))return!1;const s=t[i];Hn(s)&&(e.enumerable=!1,"writable"in e?e.writable=!1:e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+i+"'")}))})},toObjectSet:(t,e)=>{const i={},s=t=>{t.forEach(t=>{i[t]=!0})};return Bn(t)?s(t):s(String(t).split(e)),i},toCamelCase:t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(t,e,i){return e.toUpperCase()+i}),noop:()=>{},toFiniteNumber:(t,e)=>null!=t&&Number.isFinite(t=+t)?t:e,findKey:rr,global:or,isContextDefined:hr,isSpecCompliantForm:function(t){return!!(t&&Hn(t.append)&&"FormData"===t[Fn]&&t[On])},toJSONObject:t=>{const e=new Array(10),i=(t,s)=>{if(qn(t)){if(e.indexOf(t)>=0)return;if(Un(t))return t;if(!("toJSON"in t)){e[s]=t;const n=Bn(t)?[]:{};return nr(t,(t,e)=>{const r=i(t,s+1);!An(r)&&(n[e]=r)}),e[s]=void 0,n}}return t};return i(t,0)},isAsyncFn:mr,isThenable:t=>t&&(qn(t)||Hn(t))&&Hn(t.then)&&Hn(t.catch),setImmediate:pr,asap:yr,isIterable:t=>null!=t&&Hn(t[On])};function Sr(t,e,i,s,n){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=t,this.name="AxiosError",e&&(this.code=e),i&&(this.config=i),s&&(this.request=s),n&&(this.response=n,this.status=n.status?n.status:null)}Cr.inherits(Sr,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:Cr.toJSONObject(this.config),code:this.code,status:this.status}}});const Mr=Sr.prototype,xr={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{xr[t]={value:t}}),Object.defineProperties(Sr,xr),Object.defineProperty(Mr,"isAxiosError",{value:!0}),Sr.from=(t,e,i,s,n,r)=>{const o=Object.create(Mr);Cr.toFlatObject(t,o,function(t){return t!==Error.prototype},t=>"isAxiosError"!==t);const h=t&&t.message?t.message:"Error",l=null==e&&t?t.code:e;return Sr.call(o,h,l,i,s,n),t&&null==o.cause&&Object.defineProperty(o,"cause",{value:t,configurable:!0}),o.name=t&&t.name||"Error",r&&Object.assign(o,r),o};function Er(t){return Cr.isPlainObject(t)||Cr.isArray(t)}function _r(t){return Cr.endsWith(t,"[]")?t.slice(0,-2):t}function $r(t,e,i){return t?t.concat(e).map(function(t,e){return t=_r(t),!i&&e?"["+t+"]":t}).join(i?".":""):e}const zr=Cr.toFlatObject(Cr,{},null,function(t){return/^is[A-Z]/.test(t)});function kr(t,e,i){if(!Cr.isObject(t))throw new TypeError("target must be an object");e=e||new FormData;const s=(i=Cr.toFlatObject(i,{metaTokens:!0,dots:!1,indexes:!1},!1,function(t,e){return!Cr.isUndefined(e[t])})).metaTokens,n=i.visitor||a,r=i.dots,o=i.indexes,h=(i.Blob||"undefined"!=typeof Blob&&Blob)&&Cr.isSpecCompliantForm(e);if(!Cr.isFunction(n))throw new TypeError("visitor must be a function");function l(t){if(null===t)return"";if(Cr.isDate(t))return t.toISOString();if(Cr.isBoolean(t))return t.toString();if(!h&&Cr.isBlob(t))throw new Sr("Blob is not supported. Use a Buffer instead.");return Cr.isArrayBuffer(t)||Cr.isTypedArray(t)?h&&"function"==typeof Blob?new Blob([t]):Buffer.from(t):t}function a(t,i,n){let h=t;if(t&&!n&&"object"==typeof t)if(Cr.endsWith(i,"{}"))i=s?i:i.slice(0,-2),t=JSON.stringify(t);else if(Cr.isArray(t)&&function(t){return Cr.isArray(t)&&!t.some(Er)}(t)||(Cr.isFileList(t)||Cr.endsWith(i,"[]"))&&(h=Cr.toArray(t)))return i=_r(i),h.forEach(function(t,s){!Cr.isUndefined(t)&&null!==t&&e.append(!0===o?$r([i],s,r):null===o?i:i+"[]",l(t))}),!1;return!!Er(t)||(e.append($r(n,i,r),l(t)),!1)}const c=[],u=Object.assign(zr,{defaultVisitor:a,convertValue:l,isVisitable:Er});if(!Cr.isObject(t))throw new TypeError("data must be an object");return function t(i,s){if(!Cr.isUndefined(i)){if(-1!==c.indexOf(i))throw Error("Circular reference detected in "+s.join("."));c.push(i),Cr.forEach(i,function(i,r){!0===(!(Cr.isUndefined(i)||null===i)&&n.call(e,i,Cr.isString(r)?r.trim():r,s,u))&&t(i,s?s.concat(r):[r])}),c.pop()}}(t),e}function Rr(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(t){return e[t]})}function Nr(t,e){this._pairs=[],t&&kr(t,this,e)}const Tr=Nr.prototype;function Lr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Or(t,e,i){if(!e)return t;const s=i&&i.encode||Lr;Cr.isFunction(i)&&(i={serialize:i});const n=i&&i.serialize;let r;if(r=n?n(e,i):Cr.isURLSearchParams(e)?e.toString():new Nr(e,i).toString(s),r){const e=t.indexOf("#");-1!==e&&(t=t.slice(0,e)),t+=(-1===t.indexOf("?")?"?":"&")+r}return t}Tr.append=function(t,e){this._pairs.push([t,e])},Tr.toString=function(t){const e=t?function(e){return t.call(this,e,Rr)}:Rr;return this._pairs.map(function(t){return e(t[0])+"="+e(t[1])},"").join("&")};class Fr{constructor(){this.handlers=[]}use(t,e,i){return this.handlers.push({fulfilled:t,rejected:e,synchronous:!!i&&i.synchronous,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){Cr.forEach(this.handlers,function(e){null!==e&&t(e)})}}var Pr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Dr={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:Nr,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const Vr="undefined"!=typeof window&&"undefined"!=typeof document,Ir="object"==typeof navigator&&navigator||void 0,Br=Vr&&(!Ir||["ReactNative","NativeScript","NS"].indexOf(Ir.product)<0),Ar="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,Ur=Vr&&window.location.href||"http://localhost";var Wr={...Object.freeze({__proto__:null,hasBrowserEnv:Vr,hasStandardBrowserEnv:Br,hasStandardBrowserWebWorkerEnv:Ar,navigator:Ir,origin:Ur}),...Dr};function jr(t){function e(t,i,s,n){let r=t[n++];if("__proto__"===r)return!0;const o=Number.isFinite(+r),h=n>=t.length;if(r=!r&&Cr.isArray(s)?s.length:r,h)return Cr.hasOwnProp(s,r)?s[r]=[s[r],i]:s[r]=i,!o;s[r]&&Cr.isObject(s[r])||(s[r]=[]);return e(t,i,s[r],n)&&Cr.isArray(s[r])&&(s[r]=function(t){const e={},i=Object.keys(t);let s;const n=i.length;let r;for(s=0;s<n;s++)r=i[s],e[r]=t[r];return e}(s[r])),!o}if(Cr.isFormData(t)&&Cr.isFunction(t.entries)){const i={};return Cr.forEachEntry(t,(t,s)=>{e(function(t){return Cr.matchAll(/\w+|\[(\w*)]/g,t).map(t=>"[]"===t[0]?"":t[1]||t[0])}(t),s,i,0)}),i}return null}const Hr={transitional:Pr,adapter:["xhr","http","fetch"],transformRequest:[function(t,e){const i=e.getContentType()||"",s=i.indexOf("application/json")>-1,n=Cr.isObject(t);n&&Cr.isHTMLForm(t)&&(t=new FormData(t));if(Cr.isFormData(t))return s?JSON.stringify(jr(t)):t;if(Cr.isArrayBuffer(t)||Cr.isBuffer(t)||Cr.isStream(t)||Cr.isFile(t)||Cr.isBlob(t)||Cr.isReadableStream(t))return t;if(Cr.isArrayBufferView(t))return t.buffer;if(Cr.isURLSearchParams(t))return e.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let r;if(n){if(i.indexOf("application/x-www-form-urlencoded")>-1)return function(t,e){return kr(t,new Wr.classes.URLSearchParams,{visitor:function(t,e,i,s){return Wr.isNode&&Cr.isBuffer(t)?(this.append(e,t.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...e})}(t,this.formSerializer).toString();if((r=Cr.isFileList(t))||i.indexOf("multipart/form-data")>-1){const e=this.env&&this.env.FormData;return kr(r?{"files[]":t}:t,e&&new e,this.formSerializer)}}return n||s?(e.setContentType("application/json",!1),function(t,e,i){if(Cr.isString(t))try{return(e||JSON.parse)(t),Cr.trim(t)}catch(t){if("SyntaxError"!==t.name)throw t}return(i||JSON.stringify)(t)}(t)):t}],transformResponse:[function(t){const e=this.transitional||Hr.transitional,i=e&&e.forcedJSONParsing,s="json"===this.responseType;if(Cr.isResponse(t)||Cr.isReadableStream(t))return t;if(t&&Cr.isString(t)&&(i&&!this.responseType||s)){const i=!(e&&e.silentJSONParsing)&&s;try{return JSON.parse(t,this.parseReviver)}catch(t){if(i){if("SyntaxError"===t.name)throw Sr.from(t,Sr.ERR_BAD_RESPONSE,this,null,this.response);throw t}}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Wr.classes.FormData,Blob:Wr.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Cr.forEach(["delete","get","head","post","put","patch"],t=>{Hr.headers[t]={}});const Kr=Cr.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const qr=Symbol("internals");function Xr(t){return t&&String(t).trim().toLowerCase()}function Jr(t){return!1===t||null==t?t:Cr.isArray(t)?t.map(Jr):String(t)}function Gr(t,e,i,s,n){return Cr.isFunction(s)?s.call(this,e,i):(n&&(e=i),Cr.isString(e)?Cr.isString(s)?-1!==e.indexOf(s):Cr.isRegExp(s)?s.test(e):void 0:void 0)}let Qr=class{constructor(t){t&&this.set(t)}set(t,e,i){const s=this;function n(t,e,i){const n=Xr(e);if(!n)throw new Error("header name must be a non-empty string");const r=Cr.findKey(s,n);(!r||void 0===s[r]||!0===i||void 0===i&&!1!==s[r])&&(s[r||e]=Jr(t))}const r=(t,e)=>Cr.forEach(t,(t,i)=>n(t,i,e));if(Cr.isPlainObject(t)||t instanceof this.constructor)r(t,e);else if(Cr.isString(t)&&(t=t.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim()))r((t=>{const e={};let i,s,n;return t&&t.split("\n").forEach(function(t){n=t.indexOf(":"),i=t.substring(0,n).trim().toLowerCase(),s=t.substring(n+1).trim(),!i||e[i]&&Kr[i]||("set-cookie"===i?e[i]?e[i].push(s):e[i]=[s]:e[i]=e[i]?e[i]+", "+s:s)}),e})(t),e);else if(Cr.isObject(t)&&Cr.isIterable(t)){let i,s,n={};for(const e of t){if(!Cr.isArray(e))throw TypeError("Object iterator must return a key-value pair");n[s=e[0]]=(i=n[s])?Cr.isArray(i)?[...i,e[1]]:[i,e[1]]:e[1]}r(n,e)}else null!=t&&n(e,t,i);return this}get(t,e){if(t=Xr(t)){const i=Cr.findKey(this,t);if(i){const t=this[i];if(!e)return t;if(!0===e)return function(t){const e=Object.create(null),i=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let s;for(;s=i.exec(t);)e[s[1]]=s[2];return e}(t);if(Cr.isFunction(e))return e.call(this,t,i);if(Cr.isRegExp(e))return e.exec(t);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,e){if(t=Xr(t)){const i=Cr.findKey(this,t);return!(!i||void 0===this[i]||e&&!Gr(0,this[i],i,e))}return!1}delete(t,e){const i=this;let s=!1;function n(t){if(t=Xr(t)){const n=Cr.findKey(i,t);!n||e&&!Gr(0,i[n],n,e)||(delete i[n],s=!0)}}return Cr.isArray(t)?t.forEach(n):n(t),s}clear(t){const e=Object.keys(this);let i=e.length,s=!1;for(;i--;){const n=e[i];t&&!Gr(0,this[n],n,t,!0)||(delete this[n],s=!0)}return s}normalize(t){const e=this,i={};return Cr.forEach(this,(s,n)=>{const r=Cr.findKey(i,n);if(r)return e[r]=Jr(s),void delete e[n];const o=t?function(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,e,i)=>e.toUpperCase()+i)}(n):String(n).trim();o!==n&&delete e[n],e[o]=Jr(s),i[o]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const e=Object.create(null);return Cr.forEach(this,(i,s)=>{null!=i&&!1!==i&&(e[s]=t&&Cr.isArray(i)?i.join(", "):i)}),e}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,e])=>t+": "+e).join("\n")}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...e){const i=new this(t);return e.forEach(t=>i.set(t)),i}static accessor(t){const e=(this[qr]=this[qr]={accessors:{}}).accessors,i=this.prototype;function s(t){const s=Xr(t);e[s]||(!function(t,e){const i=Cr.toCamelCase(" "+e);["get","set","has"].forEach(s=>{Object.defineProperty(t,s+i,{value:function(t,i,n){return this[s].call(this,e,t,i,n)},configurable:!0})})}(i,t),e[s]=!0)}return Cr.isArray(t)?t.forEach(s):s(t),this}};function Yr(t,e){const i=this||Hr,s=e||i,n=Qr.from(s.headers);let r=s.data;return Cr.forEach(t,function(t){r=t.call(i,r,n.normalize(),e?e.status:void 0)}),n.normalize(),r}function Zr(t){return!(!t||!t.__CANCEL__)}function to(t,e,i){Sr.call(this,null==t?"canceled":t,Sr.ERR_CANCELED,e,i),this.name="CanceledError"}function eo(t,e,i){const s=i.config.validateStatus;i.status&&s&&!s(i.status)?e(new Sr("Request failed with status code "+i.status,[Sr.ERR_BAD_REQUEST,Sr.ERR_BAD_RESPONSE][Math.floor(i.status/100)-4],i.config,i.request,i)):t(i)}Qr.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Cr.reduceDescriptors(Qr.prototype,({value:t},e)=>{let i=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(t){this[i]=t}}}),Cr.freezeMethods(Qr),Cr.inherits(to,Sr,{__CANCEL__:!0});const io=(t,e,i=3)=>{let s=0;const n=function(t,e){t=t||10;const i=new Array(t),s=new Array(t);let n,r=0,o=0;return e=void 0!==e?e:1e3,function(h){const l=Date.now(),a=s[o];n||(n=l),i[r]=h,s[r]=l;let c=o,u=0;for(;c!==r;)u+=i[c++],c%=t;if(r=(r+1)%t,r===o&&(o=(o+1)%t),l-n<e)return;const d=a&&l-a;return d?Math.round(1e3*u/d):void 0}}(50,250);return function(t,e){let i,s,n=0,r=1e3/e;const o=(e,r=Date.now())=>{n=r,i=null,s&&(clearTimeout(s),s=null),t(...e)};return[(...t)=>{const e=Date.now(),h=e-n;h>=r?o(t,e):(i=t,s||(s=setTimeout(()=>{s=null,o(i)},r-h)))},()=>i&&o(i)]}(i=>{const r=i.loaded,o=i.lengthComputable?i.total:void 0,h=r-s,l=n(h);s=r;t({loaded:r,total:o,progress:o?r/o:void 0,bytes:h,rate:l||void 0,estimated:l&&o&&r<=o?(o-r)/l:void 0,event:i,lengthComputable:null!=o,[e?"download":"upload"]:!0})},i)},so=(t,e)=>{const i=null!=t;return[s=>e[0]({lengthComputable:i,total:t,loaded:s}),e[1]]},no=t=>(...e)=>Cr.asap(()=>t(...e));var ro=Wr.hasStandardBrowserEnv?((t,e)=>i=>(i=new URL(i,Wr.origin),t.protocol===i.protocol&&t.host===i.host&&(e||t.port===i.port)))(new URL(Wr.origin),Wr.navigator&&/(msie|trident)/i.test(Wr.navigator.userAgent)):()=>!0,oo=Wr.hasStandardBrowserEnv?{write(t,e,i,s,n,r){const o=[t+"="+encodeURIComponent(e)];Cr.isNumber(i)&&o.push("expires="+new Date(i).toGMTString()),Cr.isString(s)&&o.push("path="+s),Cr.isString(n)&&o.push("domain="+n),!0===r&&o.push("secure"),document.cookie=o.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function ho(t,e,i){let s=!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e);return t&&(s||0==i)?function(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}(t,e):e}const lo=t=>t instanceof Qr?{...t}:t;function ao(t,e){e=e||{};const i={};function s(t,e,i,s){return Cr.isPlainObject(t)&&Cr.isPlainObject(e)?Cr.merge.call({caseless:s},t,e):Cr.isPlainObject(e)?Cr.merge({},e):Cr.isArray(e)?e.slice():e}function n(t,e,i,n){return Cr.isUndefined(e)?Cr.isUndefined(t)?void 0:s(void 0,t,0,n):s(t,e,0,n)}function r(t,e){if(!Cr.isUndefined(e))return s(void 0,e)}function o(t,e){return Cr.isUndefined(e)?Cr.isUndefined(t)?void 0:s(void 0,t):s(void 0,e)}function h(i,n,r){return r in e?s(i,n):r in t?s(void 0,i):void 0}const l={url:r,method:r,data:r,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:h,headers:(t,e,i)=>n(lo(t),lo(e),0,!0)};return Cr.forEach(Object.keys({...t,...e}),function(s){const r=l[s]||n,o=r(t[s],e[s],s);Cr.isUndefined(o)&&r!==h||(i[s]=o)}),i}var co=t=>{const e=ao({},t);let{data:i,withXSRFToken:s,xsrfHeaderName:n,xsrfCookieName:r,headers:o,auth:h}=e;if(e.headers=o=Qr.from(o),e.url=Or(ho(e.baseURL,e.url,e.allowAbsoluteUrls),t.params,t.paramsSerializer),h&&o.set("Authorization","Basic "+btoa((h.username||"")+":"+(h.password?unescape(encodeURIComponent(h.password)):""))),Cr.isFormData(i))if(Wr.hasStandardBrowserEnv||Wr.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if(Cr.isFunction(i.getHeaders)){const t=i.getHeaders(),e=["content-type","content-length"];Object.entries(t).forEach(([t,i])=>{e.includes(t.toLowerCase())&&o.set(t,i)})}if(Wr.hasStandardBrowserEnv&&(s&&Cr.isFunction(s)&&(s=s(e)),s||!1!==s&&ro(e.url))){const t=n&&r&&oo.read(r);t&&o.set(n,t)}return e};var uo="undefined"!=typeof XMLHttpRequest&&function(t){return new Promise(function(e,i){const s=co(t);let n=s.data;const r=Qr.from(s.headers).normalize();let o,h,l,a,c,{responseType:u,onUploadProgress:d,onDownloadProgress:f}=s;function m(){a&&a(),c&&c(),s.cancelToken&&s.cancelToken.unsubscribe(o),s.signal&&s.signal.removeEventListener("abort",o)}let p=new XMLHttpRequest;function g(){if(!p)return;const s=Qr.from("getAllResponseHeaders"in p&&p.getAllResponseHeaders());eo(function(t){e(t),m()},function(t){i(t),m()},{data:u&&"text"!==u&&"json"!==u?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:s,config:t,request:p}),p=null}p.open(s.method.toUpperCase(),s.url,!0),p.timeout=s.timeout,"onloadend"in p?p.onloadend=g:p.onreadystatechange=function(){p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))&&setTimeout(g)},p.onabort=function(){p&&(i(new Sr("Request aborted",Sr.ECONNABORTED,t,p)),p=null)},p.onerror=function(e){const s=new Sr(e&&e.message?e.message:"Network Error",Sr.ERR_NETWORK,t,p);s.event=e||null,i(s),p=null},p.ontimeout=function(){let e=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const n=s.transitional||Pr;s.timeoutErrorMessage&&(e=s.timeoutErrorMessage),i(new Sr(e,n.clarifyTimeoutError?Sr.ETIMEDOUT:Sr.ECONNABORTED,t,p)),p=null},void 0===n&&r.setContentType(null),"setRequestHeader"in p&&Cr.forEach(r.toJSON(),function(t,e){p.setRequestHeader(e,t)}),Cr.isUndefined(s.withCredentials)||(p.withCredentials=!!s.withCredentials),u&&"json"!==u&&(p.responseType=s.responseType),f&&([l,c]=io(f,!0),p.addEventListener("progress",l)),d&&p.upload&&([h,a]=io(d),p.upload.addEventListener("progress",h),p.upload.addEventListener("loadend",a)),(s.cancelToken||s.signal)&&(o=e=>{p&&(i(!e||e.type?new to(null,t,p):e),p.abort(),p=null)},s.cancelToken&&s.cancelToken.subscribe(o),s.signal&&(s.signal.aborted?o():s.signal.addEventListener("abort",o)));const b=function(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}(s.url);b&&-1===Wr.protocols.indexOf(b)?i(new Sr("Unsupported protocol "+b+":",Sr.ERR_BAD_REQUEST,t)):p.send(n||null)})};const fo=(t,e)=>{const{length:i}=t=t?t.filter(Boolean):[];if(e||i){let i,s=new AbortController;const n=function(t){if(!i){i=!0,o();const e=t instanceof Error?t:this.reason;s.abort(e instanceof Sr?e:new to(e instanceof Error?e.message:e))}};let r=e&&setTimeout(()=>{r=null,n(new Sr(`timeout ${e} of ms exceeded`,Sr.ETIMEDOUT))},e);const o=()=>{t&&(r&&clearTimeout(r),r=null,t.forEach(t=>{t.unsubscribe?t.unsubscribe(n):t.removeEventListener("abort",n)}),t=null)};t.forEach(t=>t.addEventListener("abort",n));const{signal:h}=s;return h.unsubscribe=()=>Cr.asap(o),h}},mo=function*(t,e){let i=t.byteLength;if(i<e)return void(yield t);let s,n=0;for(;n<i;)s=n+e,yield t.slice(n,s),n=s},po=async function*(t){if(t[Symbol.asyncIterator])return void(yield*t);const e=t.getReader();try{for(;;){const{done:t,value:i}=await e.read();if(t)break;yield i}}finally{await e.cancel()}},go=(t,e,i,s)=>{const n=async function*(t,e){for await(const i of po(t))yield*mo(i,e)}(t,e);let r,o=0,h=t=>{r||(r=!0,s&&s(t))};return new ReadableStream({async pull(t){try{const{done:e,value:s}=await n.next();if(e)return h(),void t.close();let r=s.byteLength;if(i){let t=o+=r;i(t)}t.enqueue(new Uint8Array(s))}catch(t){throw h(t),t}},cancel:t=>(h(t),n.return())},{highWaterMark:2})},{isFunction:bo}=Cr,vo=(({Request:t,Response:e})=>({Request:t,Response:e}))(Cr.global),{ReadableStream:wo,TextEncoder:yo}=Cr.global,Co=(t,...e)=>{try{return!!t(...e)}catch(t){return!1}},So=t=>{t=Cr.merge.call({skipUndefined:!0},vo,t);const{fetch:e,Request:i,Response:s}=t,n=e?bo(e):"function"==typeof fetch,r=bo(i),o=bo(s);if(!n)return!1;const h=n&&bo(wo),l=n&&("function"==typeof yo?(a=new yo,t=>a.encode(t)):async t=>new Uint8Array(await new i(t).arrayBuffer()));var a;const c=r&&h&&Co(()=>{let t=!1;const e=new i(Wr.origin,{body:new wo,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e}),u=o&&h&&Co(()=>Cr.isReadableStream(new s("").body)),d={stream:u&&(t=>t.body)};n&&["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!d[t]&&(d[t]=(e,i)=>{let s=e&&e[t];if(s)return s.call(e);throw new Sr(`Response type '${t}' is not supported`,Sr.ERR_NOT_SUPPORT,i)})});const f=async(t,e)=>{const s=Cr.toFiniteNumber(t.getContentLength());return null==s?(async t=>{if(null==t)return 0;if(Cr.isBlob(t))return t.size;if(Cr.isSpecCompliantForm(t)){const e=new i(Wr.origin,{method:"POST",body:t});return(await e.arrayBuffer()).byteLength}return Cr.isArrayBufferView(t)||Cr.isArrayBuffer(t)?t.byteLength:(Cr.isURLSearchParams(t)&&(t+=""),Cr.isString(t)?(await l(t)).byteLength:void 0)})(e):s};return async t=>{let{url:n,method:o,data:h,signal:l,cancelToken:a,timeout:m,onDownloadProgress:p,onUploadProgress:g,responseType:b,headers:v,withCredentials:w="same-origin",fetchOptions:y}=co(t),C=e||fetch;b=b?(b+"").toLowerCase():"text";let S=fo([l,a&&a.toAbortSignal()],m),M=null;const x=S&&S.unsubscribe&&(()=>{S.unsubscribe()});let E;try{if(g&&c&&"get"!==o&&"head"!==o&&0!==(E=await f(v,h))){let t,e=new i(n,{method:"POST",body:h,duplex:"half"});if(Cr.isFormData(h)&&(t=e.headers.get("content-type"))&&v.setContentType(t),e.body){const[t,i]=so(E,io(no(g)));h=go(e.body,65536,t,i)}}Cr.isString(w)||(w=w?"include":"omit");const e=r&&"credentials"in i.prototype,l={...y,signal:S,method:o.toUpperCase(),headers:v.normalize().toJSON(),body:h,duplex:"half",credentials:e?w:void 0};M=r&&new i(n,l);let a=await(r?C(M,y):C(n,l));const m=u&&("stream"===b||"response"===b);if(u&&(p||m&&x)){const t={};["status","statusText","headers"].forEach(e=>{t[e]=a[e]});const e=Cr.toFiniteNumber(a.headers.get("content-length")),[i,n]=p&&so(e,io(no(p),!0))||[];a=new s(go(a.body,65536,i,()=>{n&&n(),x&&x()}),t)}b=b||"text";let _=await d[Cr.findKey(d,b)||"text"](a,t);return!m&&x&&x(),await new Promise((e,i)=>{eo(e,i,{data:_,headers:Qr.from(a.headers),status:a.status,statusText:a.statusText,config:t,request:M})})}catch(e){if(x&&x(),e&&"TypeError"===e.name&&/Load failed|fetch/i.test(e.message))throw Object.assign(new Sr("Network Error",Sr.ERR_NETWORK,t,M),{cause:e.cause||e});throw Sr.from(e,e&&e.code,t,M)}}},Mo=new Map,xo=t=>{let e=t?t.env:{};const{fetch:i,Request:s,Response:n}=e,r=[s,n,i];let o,h,l=r.length,a=Mo;for(;l--;)o=r[l],h=a.get(o),void 0===h&&a.set(o,h=l?new Map:So(e)),a=h;return h};xo();const Eo={http:null,xhr:uo,fetch:{get:xo}};Cr.forEach(Eo,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch(t){}Object.defineProperty(t,"adapterName",{value:e})}});const _o=t=>`- ${t}`,$o=t=>Cr.isFunction(t)||null===t||!1===t;var zo=(t,e)=>{t=Cr.isArray(t)?t:[t];const{length:i}=t;let s,n;const r={};for(let o=0;o<i;o++){let i;if(s=t[o],n=s,!$o(s)&&(n=Eo[(i=String(s)).toLowerCase()],void 0===n))throw new Sr(`Unknown adapter '${i}'`);if(n&&(Cr.isFunction(n)||(n=n.get(e))))break;r[i||"#"+o]=n}if(!n){const t=Object.entries(r).map(([t,e])=>`adapter ${t} `+(!1===e?"is not supported by the environment":"is not available in the build"));throw new Sr("There is no suitable adapter to dispatch the request "+(i?t.length>1?"since :\n"+t.map(_o).join("\n"):" "+_o(t[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return n};function ko(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new to(null,t)}function Ro(t){ko(t),t.headers=Qr.from(t.headers),t.data=Yr.call(t,t.transformRequest),-1!==["post","put","patch"].indexOf(t.method)&&t.headers.setContentType("application/x-www-form-urlencoded",!1);return zo(t.adapter||Hr.adapter,t)(t).then(function(e){return ko(t),e.data=Yr.call(t,t.transformResponse,e),e.headers=Qr.from(e.headers),e},function(e){return Zr(e)||(ko(t),e&&e.response&&(e.response.data=Yr.call(t,t.transformResponse,e.response),e.response.headers=Qr.from(e.response.headers))),Promise.reject(e)})}const No="1.12.2",To={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{To[t]=function(i){return typeof i===t||"a"+(e<1?"n ":" ")+t}});const Lo={};To.transitional=function(t,e,i){function s(t,e){return"[Axios v"+No+"] Transitional option '"+t+"'"+e+(i?". "+i:"")}return(i,n,r)=>{if(!1===t)throw new Sr(s(n," has been removed"+(e?" in "+e:"")),Sr.ERR_DEPRECATED);return e&&!Lo[n]&&(Lo[n]=!0,console.warn(s(n," has been deprecated since v"+e+" and will be removed in the near future"))),!t||t(i,n,r)}},To.spelling=function(t){return(e,i)=>(console.warn(`${i} is likely a misspelling of ${t}`),!0)};var Oo={assertOptions:function(t,e,i){if("object"!=typeof t)throw new Sr("options must be an object",Sr.ERR_BAD_OPTION_VALUE);const s=Object.keys(t);let n=s.length;for(;n-- >0;){const r=s[n],o=e[r];if(o){const e=t[r],i=void 0===e||o(e,r,t);if(!0!==i)throw new Sr("option "+r+" must be "+i,Sr.ERR_BAD_OPTION_VALUE);continue}if(!0!==i)throw new Sr("Unknown option "+r,Sr.ERR_BAD_OPTION)}},validators:To};const Fo=Oo.validators;let Po=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Fr,response:new Fr}}async request(t,e){try{return await this._request(t,e)}catch(t){if(t instanceof Error){let e={};Error.captureStackTrace?Error.captureStackTrace(e):e=new Error;const i=e.stack?e.stack.replace(/^.+\n/,""):"";try{t.stack?i&&!String(t.stack).endsWith(i.replace(/^.+\n.+\n/,""))&&(t.stack+="\n"+i):t.stack=i}catch(t){}}throw t}}_request(t,e){"string"==typeof t?(e=e||{}).url=t:e=t||{},e=ao(this.defaults,e);const{transitional:i,paramsSerializer:s,headers:n}=e;void 0!==i&&Oo.assertOptions(i,{silentJSONParsing:Fo.transitional(Fo.boolean),forcedJSONParsing:Fo.transitional(Fo.boolean),clarifyTimeoutError:Fo.transitional(Fo.boolean)},!1),null!=s&&(Cr.isFunction(s)?e.paramsSerializer={serialize:s}:Oo.assertOptions(s,{encode:Fo.function,serialize:Fo.function},!0)),void 0!==e.allowAbsoluteUrls||(void 0!==this.defaults.allowAbsoluteUrls?e.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:e.allowAbsoluteUrls=!0),Oo.assertOptions(e,{baseUrl:Fo.spelling("baseURL"),withXsrfToken:Fo.spelling("withXSRFToken")},!0),e.method=(e.method||this.defaults.method||"get").toLowerCase();let r=n&&Cr.merge(n.common,n[e.method]);n&&Cr.forEach(["delete","get","head","post","put","patch","common"],t=>{delete n[t]}),e.headers=Qr.concat(r,n);const o=[];let h=!0;this.interceptors.request.forEach(function(t){"function"==typeof t.runWhen&&!1===t.runWhen(e)||(h=h&&t.synchronous,o.unshift(t.fulfilled,t.rejected))});const l=[];let a;this.interceptors.response.forEach(function(t){l.push(t.fulfilled,t.rejected)});let c,u=0;if(!h){const t=[Ro.bind(this),void 0];for(t.unshift(...o),t.push(...l),c=t.length,a=Promise.resolve(e);u<c;)a=a.then(t[u++],t[u++]);return a}c=o.length;let d=e;for(;u<c;){const t=o[u++],e=o[u++];try{d=t(d)}catch(t){e.call(this,t);break}}try{a=Ro.call(this,d)}catch(t){return Promise.reject(t)}for(u=0,c=l.length;u<c;)a=a.then(l[u++],l[u++]);return a}getUri(t){return Or(ho((t=ao(this.defaults,t)).baseURL,t.url,t.allowAbsoluteUrls),t.params,t.paramsSerializer)}};Cr.forEach(["delete","get","head","options"],function(t){Po.prototype[t]=function(e,i){return this.request(ao(i||{},{method:t,url:e,data:(i||{}).data}))}}),Cr.forEach(["post","put","patch"],function(t){function e(e){return function(i,s,n){return this.request(ao(n||{},{method:t,headers:e?{"Content-Type":"multipart/form-data"}:{},url:i,data:s}))}}Po.prototype[t]=e(),Po.prototype[t+"Form"]=e(!0)});const Do={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Do).forEach(([t,e])=>{Do[e]=t});const Vo=function t(e){const i=new Po(e),s=Nn(Po.prototype.request,i);return Cr.extend(s,Po.prototype,i,{allOwnKeys:!0}),Cr.extend(s,i,null,{allOwnKeys:!0}),s.create=function(i){return t(ao(e,i))},s}(Hr);Vo.Axios=Po,Vo.CanceledError=to,Vo.CancelToken=class t{constructor(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");let e;this.promise=new Promise(function(t){e=t});const i=this;this.promise.then(t=>{if(!i._listeners)return;let e=i._listeners.length;for(;e-- >0;)i._listeners[e](t);i._listeners=null}),this.promise.then=t=>{let e;const s=new Promise(t=>{i.subscribe(t),e=t}).then(t);return s.cancel=function(){i.unsubscribe(e)},s},t(function(t,s,n){i.reason||(i.reason=new to(t,s,n),e(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){this.reason?t(this.reason):this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const e=this._listeners.indexOf(t);-1!==e&&this._listeners.splice(e,1)}toAbortSignal(){const t=new AbortController,e=e=>{t.abort(e)};return this.subscribe(e),t.signal.unsubscribe=()=>this.unsubscribe(e),t.signal}static source(){let e;const i=new t(function(t){e=t});return{token:i,cancel:e}}},Vo.isCancel=Zr,Vo.VERSION=No,Vo.toFormData=kr,Vo.AxiosError=Sr,Vo.Cancel=Vo.CanceledError,Vo.all=function(t){return Promise.all(t)},Vo.spread=function(t){return function(e){return t.apply(null,e)}},Vo.isAxiosError=function(t){return Cr.isObject(t)&&!0===t.isAxiosError},Vo.mergeConfig=ao,Vo.AxiosHeaders=Qr,Vo.formToJSON=t=>jr(Cr.isHTMLForm(t)?new FormData(t):t),Vo.getAdapter=zo,Vo.HttpStatusCode=Do,Vo.default=Vo;const{Axios:Io,AxiosError:Bo,CanceledError:Ao,isCancel:Uo,CancelToken:Wo,VERSION:jo,all:Ho,Cancel:Ko,isAxiosError:qo,spread:Xo,toFormData:Jo,AxiosHeaders:Go,HttpStatusCode:Qo,formToJSON:Yo,getAdapter:Zo,mergeConfig:th}=Vo,eh={BASE_URL:"undefined"!=typeof window&&window.FUNHI_CHART_API_URL?window.FUNHI_CHART_API_URL:process.env.NEXT_PUBLIC_BACKEND_URL||"",TIMEOUT:1e4,MAX_RETRIES:3,RETRY_DELAY:1e3};const ih=new class{constructor(){this.baseURL=`${eh.BASE_URL}/api/ohlcv`,this.savingQueue=new Map,this.BATCH_DELAY=5e3,this.BATCH_SIZE=50}async saveCandles(t){try{const{mint:e,candles:i,timeFrame:s=60}=t;if(!e||!i||0===i.length)return console.warn("⚠️ [CandleStorage] Invalid save request:",t),!1;return!!(await Vo.post(`${this.baseURL}/candles/save`,{mint:e,candles:i,timeFrame:s})).data.success&&(console.log(`💾 [CandleStorage] Saved ${i.length} candles for ${e}`),!0)}catch(t){return console.error("❌ [CandleStorage] Error saving candles:",t),!1}}async saveCandle(t){try{const{mint:e,candle:i,timeFrame:s=60}=t;if(!e||!i)return console.warn("⚠️ [CandleStorage] Invalid save request:",t),!1;const n=`${e}_${s}`,r=this.savingQueue.get(n);if(r)clearTimeout(r.timeout),r.candles.push(i),r.candles.length>=this.BATCH_SIZE?await this.flushQueue(n,e,s):r.timeout=setTimeout(()=>{this.flushQueue(n,e,s)},this.BATCH_DELAY);else{const t=setTimeout(()=>{this.flushQueue(n,e,s)},this.BATCH_DELAY);this.savingQueue.set(n,{candles:[i],timeout:t})}return!0}catch(t){return console.error("❌ [CandleStorage] Error queuing candle:",t),!1}}async flushQueue(t,e,i){const s=this.savingQueue.get(t);s&&0!==s.candles.length&&(this.savingQueue.delete(t),await this.saveCandles({mint:e,candles:s.candles,timeFrame:i}))}async getCandles(t){try{const{mint:e,timeFrame:i=60,limit:s=5e4}=t;if(!e)return console.warn("⚠️ [CandleStorage] Invalid get request:",t),[];const n=await Vo.get(`${this.baseURL}/candles/${e}`,{params:{timeFrame:i,limit:s},timeout:8e3,validateStatus:t=>t>=200&&t<500});if(n.data.success&&n.data.data&&n.data.data.candles){const t=n.data.data.candles.length;return t>0?console.log(`✅ [CandleStorage] Retrieved ${t} candles for ${e}`):console.log(`ℹ️ [CandleStorage] No candles found for ${e} in database`),n.data.data.candles}return n.data.warning&&console.warn(`⚠️ [CandleStorage] ${n.data.warning}`),[]}catch(e){return"ECONNABORTED"===e.code?console.error("❌ [CandleStorage] Request timeout getting candles for",t.mint):e.response?console.error("❌ [CandleStorage] Server error getting candles:",e.response.status,e.response.data):e.request?console.error("❌ [CandleStorage] Network error getting candles - no response received"):console.error("❌ [CandleStorage] Error getting candles:",e.message),[]}}async flushAll(){const t=[];for(const[e,i]of this.savingQueue.entries()){clearTimeout(i.timeout);const[s,n]=e.split("_"),r=parseInt(n);t.push(this.flushQueue(e,s,r))}await Promise.all(t)}};class sh{static validate(t){return t&&t.time>0&&t.open>0&&t.high>0&&t.low>0&&t.close>0&&isFinite(t.open)&&isFinite(t.high)&&isFinite(t.low)&&isFinite(t.close)&&t.high>=Math.max(t.open,t.close)&&t.low<=Math.min(t.open,t.close)}static ensureMinimumBodySize(t,e){const i=e||Math.max(t.open*this.MIN_BODY_PERCENTAGE,this.MIN_BODY_ABSOLUTE),s=Math.abs(t.open-t.close);if(Math.abs(t.close-t.open)>=i)return t;let n;n=s>1e-4?t.close>=t.open?1:-1:1;const r=t.open+n*i;return{...t,close:r,high:Math.max(t.high,r),low:Math.min(t.low,r)}}static validateOHLC(t){return{...t,high:Math.max(t.open,t.high,t.close),low:Math.min(t.open,t.low,t.close)}}static isCurrentBucket(t,e,i){const s=Math.floor(i/1e3),n=Math.floor(s/e)*e;return t.time===n}static validatePrice(t){return t>0&&isFinite(t)}static calculateMinBodySize(t){return Math.max(t*this.MIN_BODY_PERCENTAGE,this.MIN_BODY_ABSOLUTE)}}sh.MIN_BODY_PERCENTAGE=1e-4,sh.MIN_BODY_ABSOLUTE=.01;class nh{constructor(t){this.candles=[],this.currentCandle=null,this.lastCandleTime=0,this.lastProcessedTimestamp=0,this.debounceMs=50,this.timeframeSeconds=t}createOrUpdate(t,e){const i=Date.now();if(this.lastProcessedTimestamp&&i-this.lastProcessedTimestamp<this.debounceMs)return null;if(this.lastProcessedTimestamp=i,!sh.validatePrice(t))return console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] Invalid price data: ${t}`),null;const s=Math.floor(e/1e3),n=this.calculateBucketStart(s);return n!==this.lastCandleTime?this.createNewCandle(t,e,n):this.currentCandle?this.updateCurrentCandle(t,e,n):null}createNewCandle(t,e,i){const s=this.getPreviousCandleClose(i),n=this.getPreviousCandleDirection();if(this.currentCandle&&this.isValidCandle(this.currentCandle)){const t=sh.validateOHLC(this.currentCandle);this.addCandleToHistory(t)}const r=s??t;null===s&&console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] No previous candle close found, using current price: $${t.toFixed(2)}`);const o=this.buildNewCandle(i,r,t,n);return this.currentCandle=o,this.lastCandleTime=i,this.addCandleToHistory(o),console.log(`🆕 [CandleManager-${this.timeframeSeconds}s] New candle: time=${i}, open=$${r.toFixed(2)}, close=$${o.close.toFixed(2)}`),{candle:o,isNewCandle:!0,wasUpdated:!1}}updateCurrentCandle(t,e,i){if(this.currentCandle.time!==i)return console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] Skipping update for historical candle (time: ${this.currentCandle.time}, current: ${i})`),null;if(!this.isValidCandle(this.currentCandle)){console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] Invalid existing candle, recreating`);const e={time:this.currentCandle.time,open:t,high:t,low:t,close:t,volume:0};return this.currentCandle=e,this.updateCandleInHistory(e,i),{candle:e,isNewCandle:!1,wasUpdated:!0}}const s=this.updateCandlePrice(this.currentCandle,t),n=sh.validateOHLC(s);return n.time!==i?(console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] Prevented update of historical candle: time=${n.time}, currentBucket=${i}`),{candle:n,isNewCandle:!1,wasUpdated:!1}):(this.currentCandle=n,this.updateCandleInHistory(n,i),{candle:n,isNewCandle:!1,wasUpdated:!0})}updateCandlePrice(t,e){const i=sh.calculateMinBodySize(t.open),s=Math.abs(t.open-e),n=Math.abs(t.close-t.open);let r=e;if(n>0&&n<=10*i&&t.open>0)if(s<100*i){const s=e>=t.open?1:-1;r=t.open+s*i}else{r=e;if(Math.abs(r-t.open)<i){const s=e>=t.open?1:-1;r=t.open+s*i}}else if(s<i&&t.open>0){const s=e>=t.open?1:-1;r=t.open+s*i}if(Math.abs(r-t.open)<i&&t.open>0){let s;s=e!==t.open&&Math.abs(e-t.open)>1e-4?e>=t.open?1:-1:t.close!==t.open&&Math.abs(t.close-t.open)>1e-4?t.close>=t.open?1:-1:1,r=t.open+s*i}return{...t,high:Math.max(t.high,e,r),low:Math.min(t.low,e,r),close:r}}buildNewCandle(t,e,i,s){const n=sh.calculateMinBodySize(e),r=Math.abs(e-i);let o=i;if(r<n){let t;t=0===r||Math.abs(i-e)<1e-4?s??1:i>=e?1:-1,o=e+t*n}if(Math.abs(o-e)<n&&e>0){o=e+(i>=e||1===s?1:-1)*n}return{time:t,open:e,high:Math.max(e,o,i),low:Math.min(e,o,i),close:o,volume:0}}getPreviousCandleClose(t){if(this.currentCandle&&this.currentCandle.close>0&&isFinite(this.currentCandle.close)&&this.currentCandle.time<t)return this.currentCandle.close;if(this.candles.length>0){const e=[...this.candles].sort((t,e)=>e.time-t.time),i=e.find(e=>e.time<t&&e.close>0&&isFinite(e.close));if(i)return i.close}return this.currentCandle&&this.currentCandle.close>0&&isFinite(this.currentCandle.close)?this.currentCandle.close:null}getPreviousCandleDirection(){return this.currentCandle&&this.currentCandle.open>0?this.currentCandle.close>=this.currentCandle.open?1:-1:1}calculateBucketStart(t){return Math.floor(t/this.timeframeSeconds)*this.timeframeSeconds}isValidCandle(t){return t.open>0&&t.high>0&&t.low>0&&t.close>0}addCandleToHistory(t){const e=this.candles.findIndex(e=>e.time===t.time);e>=0?this.candles[e]=t:(this.candles.push(t),this.candles.sort((t,e)=>t.time-e.time))}updateCandleInHistory(t,e){if(t.time!==e)return;const i=this.candles.findIndex(t=>t.time===e);i>=0&&this.candles[i].time===e?this.candles[i]=t:t.time===e&&(this.candles.push(t),this.candles.sort((t,e)=>t.time-e.time))}getCandles(){return[...this.candles]}getCurrentCandle(){return this.currentCandle}getLastCandleTime(){return this.lastCandleTime}loadCandles(t){if(0===t.length)return;const e=t.reduce((t,e)=>{const i=sh.ensureMinimumBodySize(e),s=sh.validateOHLC(i),n=t.findIndex(t=>t.time===s.time);return n>=0?t[n]=s:t.push(s),t},[]);if(this.candles=e.sort((t,e)=>t.time-e.time),this.candles.length>0){const t=this.candles[this.candles.length-1];this.currentCandle=t,this.lastCandleTime=t.time}}updateFromExternal(t,e){if(t.time!==e)return void console.warn(`⚠️ [CandleManager-${this.timeframeSeconds}s] Skipping external update for historical candle`);const i=sh.ensureMinimumBodySize(t),s=sh.validateOHLC(i);this.currentCandle=s,this.lastCandleTime=s.time,this.updateCandleInHistory(s,e)}reset(){this.candles=[],this.currentCandle=null,this.lastCandleTime=0,this.lastProcessedTimestamp=0}}class rh{constructor(t){this.timeframes=t,this.managers=new Map,t.forEach(t=>{this.managers.set(t.seconds,new nh(t.seconds))})}getManager(t){return this.managers.get(t)}updateAll(t,e){this.managers.forEach(i=>{i.createOrUpdate(t,e)})}getCandles(t){const e=this.managers.get(t);return e?e.getCandles():[]}getCurrentCandle(t){const e=this.managers.get(t);return e?e.getCurrentCandle():null}loadCandles(t,e){const i=this.managers.get(t);i&&i.loadCandles(e)}updateFromExternal(t,e,i){const s=this.managers.get(t);s&&s.updateFromExternal(e,i)}getTimeframes(){return[...this.timeframes]}reset(){this.managers.forEach(t=>t.reset())}}class oh{constructor(t,e){this.chart=null,this.series=null,this.container=null,this.container=t,this.options=e}initialize(){if(!this.container)throw new Error("Chart container is not set");this.chart=zn(this.container,{layout:{background:{color:"#ffffff"},textColor:"#333333"},grid:{vertLines:{color:"#f0f0f0"},horzLines:{color:"#f0f0f0"}},crosshair:{mode:ft.Normal},rightPriceScale:{borderColor:"#cccccc"},timeScale:{borderColor:"#cccccc",timeVisible:!0,secondsVisible:!1,rightOffset:12,barSpacing:8,minBarSpacing:4},height:this.options.height||384,localization:{priceFormatter:this.options.formatPrice},watermark:{visible:!0,fontSize:64,horzAlign:"center",vertAlign:"center",color:"rgba(0, 0, 0, 0.03)",text:this.options.ticker?`${this.options.ticker}/SOL`:`${this.options.mint.substring(0,4)}...${this.options.mint.substring(this.options.mint.length-4)}/SOL`}}),this.series=this.chart.addCandlestickSeries({upColor:"#26a69a",downColor:"#ef5350",borderVisible:!0,borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350"});const t=()=>{this.container&&this.chart&&this.chart.applyOptions({width:this.container.clientWidth})};window.addEventListener("resize",t),t()}updateData(t){if(!this.series)return;const e=t.filter(t=>t&&t.open>0&&t.high>0&&t.low>0&&t.close>0&&isFinite(t.open)&&isFinite(t.high)&&isFinite(t.low)&&isFinite(t.close));e.length>0&&(this.series.setData(e.map(t=>({...t,time:t.time}))),requestAnimationFrame(()=>{this.chart&&this.chart.timeScale().scrollToRealTime()}))}setTimeframe(t){}resize(){this.container&&this.chart&&this.chart.applyOptions({width:this.container.clientWidth})}destroy(){this.chart&&(this.chart.remove(),this.chart=null,this.series=null)}getChart(){return this.chart}getSeries(){return this.series}}class hh{async loadCandles(t,e,i){try{const s=i??Number.MAX_SAFE_INTEGER,n=(await ih.getCandles({mint:t,timeFrame:e,limit:s})).reduce((t,e)=>{const i=t.findIndex(t=>t.time===e.time);return i>=0?t[i]=e:t.push(e),t},[]);return n.sort((t,e)=>t.time-e.time)}catch(t){return console.error("❌ [CandleStorageAdapter] Error loading candles:",t),[]}}async saveCandles(t,e,i){try{await ih.saveCandles({mint:t,timeFrame:e,candles:i})}catch(t){console.error("❌ [CandleStorageAdapter] Error saving candles:",t)}}}class lh{constructor(t){this.debounceMs=50,this.lastUpdate=0,this.timeframeManager=t}handlePriceUpdate(t,e){this.debounce(e)&&this.timeframeManager.updateAll(t,e)}handleSocketUpdate(t,e){t.mint===e&&t.candles&&Object.entries(t.candles).forEach(([t,e])=>{const i=this.getTimeframeSeconds(t);if(i){const t=Math.floor(Date.now()/1e3),s=Math.floor(t/i)*i;if(e.time===s){const t={time:e.time,open:e.open,high:e.high||e.open,low:e.low||e.open,close:e.close,volume:e.volume||0};this.timeframeManager.updateFromExternal(i,t,s)}}})}debounce(t){const e=Date.now();return!(this.lastUpdate&&e-this.lastUpdate<this.debounceMs)&&(this.lastUpdate=e,!0)}getTimeframeSeconds(t){return{"1m":60,"5m":300,"15m":900,"1h":3600,"4h":14400,"1d":86400}[t]||null}}class ah{constructor(t){this.config=t,this.currentTimeframe=t.timeframes[0],this.timeframeManager=new rh(t.timeframes),this.storageAdapter=new hh,this.updateHandler=new lh(this.timeframeManager);const e={mint:t.mint,ticker:t.ticker,formatPrice:t.formatPrice};this.chartRenderer=new oh(t.container,e)}async initialize(){this.chartRenderer.initialize(),await this.loadTimeframeData(this.currentTimeframe.seconds);const t=this.getCurrentCandles();t.length>0&&this.chartRenderer.updateData(t)}async loadTimeframeData(t){const e=await this.storageAdapter.loadCandles(this.config.mint,t);e.length>0&&this.timeframeManager.loadCandles(t,e)}updatePrice(t){const e=Date.now();this.updateHandler.handlePriceUpdate(t,e);const i=this.getCurrentCandles();i.length>0&&this.chartRenderer.updateData(i)}handleSocketUpdate(t){this.updateHandler.handleSocketUpdate(t,this.config.mint);const e=this.getCurrentCandles();e.length>0&&this.chartRenderer.updateData(e)}async switchTimeframe(t){const e=this.config.timeframes.find(e=>e.seconds===t);if(!e)return void console.warn(`⚠️ [FunhiChartController] Timeframe ${t}s not found`);0===this.timeframeManager.getCandles(t).length&&await this.loadTimeframeData(t),this.currentTimeframe=e;const i=this.getCurrentCandles();i.length>0&&this.chartRenderer.updateData(i)}getCurrentCandles(){return this.timeframeManager.getCandles(this.currentTimeframe.seconds)}getCurrentTimeframe(){return this.currentTimeframe}getCurrentCandle(t){return this.timeframeManager.getCurrentCandle(t)}resize(){this.chartRenderer.resize()}destroy(){this.chartRenderer.destroy(),this.timeframeManager.reset()}}const ch=new class{constructor(){this.timeframes={"1m":60,"5m":300,"15m":900,"30m":1800,"1h":3600,"4h":14400,"1d":86400}}aggregateCandles(t,e){try{if(60===e)return t;if(!Array.isArray(t)||0===t.length)return console.warn("⚠️ [CandleAggregation] No candles to aggregate"),[];const i=[...t].sort((t,e)=>t.time-e.time),s=[];let n=[],r=null;for(const t of i){const i=Math.floor(t.time/e)*e;if(null===r&&(r=i),i===r)n.push(t);else{if(n.length>0){const t=this.aggregateGroup(n,r);s.push(t)}n=[t],r=i}}if(n.length>0&&null!==r){const t=this.aggregateGroup(n,r);s.push(t)}return console.log(`📊 [CandleAggregation] Aggregated ${t.length} 1m candles into ${s.length} ${this.getTimeframeLabel(e)} candles`),s}catch(t){return console.error("❌ [CandleAggregation] Error aggregating candles:",t),[]}}aggregateGroup(t,e){const i=[...t].sort((t,e)=>t.time-e.time),s=i[0].open,n=i[i.length-1].close,r=Math.max(...i.map(t=>t.high)),o=Math.min(...i.map(t=>t.low)),h=i.reduce((t,e)=>t+(e.volume||0),0);return{time:e,open:s,high:r,low:o,close:n,volume:h}}getTimeframeLabel(t){for(const[e,i]of Object.entries(this.timeframes))if(i===t)return e;return`${t}s`}getTimeframeSeconds(t){return this.timeframes[t]||60}fillGaps(t,e){try{if(!Array.isArray(t)||t.length<2)return t;const i=[...t].sort((t,e)=>t.time-e.time),s=[];for(let t=0;t<i.length-1;t++){const n=i[t],r=i[t+1];s.push(n);let o=n.time+e;for(;o<r.time;)s.push({time:o,open:n.close,high:n.close,low:n.close,close:n.close,volume:0}),o+=e}return s.push(i[i.length-1]),s.length>i.length&&console.log(`🔧 [CandleAggregation] Filled ${s.length-i.length} gaps in ${this.getTimeframeLabel(e)} candles`),s}catch(e){return console.error("❌ [CandleAggregation] Error filling gaps:",e),t}}getCurrentCandle(t,e){try{if(!Array.isArray(t)||0===t.length)return null;const i=Math.floor(Date.now()/1e3),s=Math.floor(i/e)*e,n=t.filter(t=>Math.floor(t.time/e)*e===s);return 0===n.length?null:this.aggregateGroup(n,s)}catch(t){return console.error("❌ [CandleAggregation] Error getting current candle:",t),null}}updateRealtimeCandle(t,e,i){try{if(!e)return t;const s=Math.floor(e.time/i)*i,n=t.findIndex(t=>t.time===s);if(n>=0){const i=t[n],r={time:s,open:i.open,high:Math.max(i.high,e.high),low:Math.min(i.low,e.low),close:e.close,volume:i.volume+(e.volume||0)},o=[...t];return o[n]=r,o}{const i={time:s,open:e.open,high:e.high,low:e.low,close:e.close,volume:e.volume||0};return[...t,i].sort((t,e)=>t.time-e.time)}}catch(e){return console.error("❌ [CandleAggregation] Error updating realtime candle:",e),t}}isValidCandle(t){return t&&"number"==typeof t.time&&"number"==typeof t.open&&"number"==typeof t.high&&"number"==typeof t.low&&"number"==typeof t.close&&t.high>=t.low&&t.high>=t.open&&t.high>=t.close&&t.low<=t.open&&t.low<=t.close}cleanCandles(t){if(!Array.isArray(t))return[];const e=t.filter(t=>this.isValidCandle(t));return e.length<t.length&&console.warn(`⚠️ [CandleAggregation] Removed ${t.length-e.length} invalid candles`),e}getRequiredOneMinuteCandles(t,e=200){const i=t/60;return Math.ceil(e*i)}};exports.API_CONFIG=eh,exports.FunhiChart=({mint:e,ticker:i,tokenName:s,socket:n,isConnected:r,currentMarketCap:o,analyticsConnected:h,analyticsLoading:l})=>{const a=t.useRef(null),c=t.useRef(null),u=t.useRef(null),d=t.useRef([]),f=t.useRef([]),m=t.useRef([]),p=t.useRef([]),g=t.useRef([]),b=t.useRef([]),v=t.useRef(null),w=t.useRef(null),y=t.useRef(null),C=t.useRef(null),S=t.useRef(null),M=t.useRef(null),x=t.useRef(0),E=t.useRef(0),_=t.useRef(0),$=t.useRef(0),z=t.useRef(0),k=t.useRef(0),R=t.useRef(null),[N,T]=t.useState([]),[L,O]=t.useState(null),[F,P]=t.useState(0),[D,V]=t.useState([]),[I,B]=t.useState(null),[A,U]=t.useState(0),[W,j]=t.useState([]),[H,K]=t.useState(null),[q,X]=t.useState(0),[J,G]=t.useState([]),[Q,Y]=t.useState(null),[Z,tt]=t.useState(0),[et,it]=t.useState([]),[st,nt]=t.useState(null),[rt,ot]=t.useState(0),[ht,lt]=t.useState([]),[at,ct]=t.useState(null),[ut,dt]=t.useState(0),[mt,pt]=t.useState(0),[gt,bt]=t.useState(!0),[vt,wt]=t.useState(!1),[yt,Ct]=t.useState(null),[St,Mt]=t.useState(null),xt=t.useRef(0),Et=t.useRef(0),_t=kn(),$t=n||_t.socket,zt=void 0!==r?r:_t.isConnected,kt=Rn(),Rt=void 0!==o?o:kt.currentMarketCap,Nt=void 0!==h?h:kt.connected,Tt=void 0!==l?l:kt.loading,Lt=t.useMemo(()=>[{label:"1m",value:"1m",seconds:60},{label:"5m",value:"5m",seconds:300},{label:"15m",value:"15m",seconds:900},{label:"1h",value:"1h",seconds:3600},{label:"4h",value:"4h",seconds:14400},{label:"1d",value:"1d",seconds:86400}],[]),[Ot,Ft]=t.useState(Lt[0]),Pt=t.useCallback(()=>{switch(Ot.seconds){case 60:default:return d.current;case 300:return f.current;case 900:return m.current;case 3600:return p.current;case 14400:return g.current;case 86400:return b.current}},[Ot.seconds]),Dt=t.useCallback(t=>t>=1e9?`$${(t/1e9).toFixed(t>=1e10?2:3)}B`:t>=1e6?`$${(t/1e6).toFixed(t>=1e7?2:3)}M`:t>=1e4?`$${(t/1e3).toFixed(t>=1e5?1:2)}K`:t>=1e3?`$${(t/1e3).toFixed(2)}K`:t>=1?`$${t.toFixed(2)}`:`$${t.toFixed(4)}`,[]),Vt=t.useCallback(async(t,i)=>{const s=Lt.find(e=>e.seconds===t)?.label||`${t}s`;try{const n=i?`${i} candles`:"all available candles";console.log(`📊 [Chart-${s}] Loading ${n} from database`);const r=i??Number.MAX_SAFE_INTEGER,o=(await ih.getCandles({mint:e,timeFrame:t,limit:r})).reduce((t,e)=>{const i=Math.max(1e-4*e.open,.01),s=Math.abs(e.open-e.close);let n={...e};if(s<i&&e.open>0){const t=e.close>=e.open?1:-1;n.close=e.open+t*i,n.high=Math.max(e.high||e.open,n.close),n.low=Math.min(e.low||e.open,n.close)}const r=t.findIndex(t=>t.time===n.time);return r>=0?t[r]=n:t.push(n),t},[]),h=o.sort((t,e)=>t.time-e.time);return console.log(`✅ [Chart-${s}] Loaded ${h.length} candles`),h}catch(t){return console.error(`❌ [Chart-${s}] Error loading candles:`,t),[]}},[e,Lt]),It=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=60*Math.floor(i/60),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1m] Invalid price data: ${t}`),null;if(s!==x.current){let e=null,i=1;if(v.current&&v.current.close>0&&isFinite(v.current.close)&&(v.current.time<s?(e=v.current.close,v.current.open>0&&(i=v.current.close>=v.current.open?1:-1),console.log(`✅ [Chart-1m] Method 1: Using currentCandle ref close (${v.current.time}) as new candle open: $${e.toFixed(2)}`)):v.current.time===s&&console.warn(`⚠️ [Chart-1m] Current candle ref is already for new bucket ${s}, skipping`)),null===e){const t=d.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s&&t.close>0&&isFinite(t.close));r&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`✅ [Chart-1m] Method 2: Using last completed candle from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&v.current&&v.current.close>0&&isFinite(v.current.close)&&(e=v.current.close,v.current.open>0&&(i=v.current.close>=v.current.open?1:-1),console.log(`✅ [Chart-1m] Method 3 (PRIMARY): Using currentCandle ref close (${v.current.time}) as new candle open: $${e.toFixed(2)}`)),v.current&&v.current.open>0&&v.current.high>0&&v.current.low>0&&v.current.close>0){const t={...v.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),T(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,d.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return d.current=s,s})}null===e&&(console.error("❌ [Chart-1m] CRITICAL: No previous candle close found after all attempts! This should not happen."),console.error(" - currentCandle1mRef.current:",v.current),console.error(" - candles1mRef.current length:",d.current?.length||0),console.error(" - bucketStart:",s,`(${new Date(1e3*s).toLocaleTimeString()})`),console.error(` - Using current price as last resort: $${t.toFixed(2)}`),e=t);const n=e;console.log(`🕯️ [Chart-1m] Creating new candle at ${new Date(1e3*s).toLocaleTimeString()}: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return v.current=l,x.current=s,O(l),P(s),T(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,d.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return d.current=i,i}),console.log(`🆕 [Chart-1m] New candle: $${t.toFixed(2)}`),l}if(v.current){const i=Math.floor(e/1e3),s=60*Math.floor(i/60);if(v.current.time!==s)return console.warn(`⚠️ [Chart-1m] Skipping update for historical candle (time: ${v.current.time}, current: ${s})`),null;const n=v.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return v.current=e,O(e),T(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,d.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r,console.log(`🛡️ [Chart-1m] PRESERVING body: open=$${n.open.toFixed(2)}, close=$${l.toFixed(2)}, bodySize=$${r.toFixed(4)}, priceDiff=$${o.toFixed(4)}, direction=${e>0?"UP":"DOWN"}, price=$${t.toFixed(2)}`)}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1;const i=n.open+e*r;Math.abs(i-l)>1e-4&&(console.log(`🔒 [Chart-1m] ENFORCING minimum body: was $${l.toFixed(2)}, now $${i.toFixed(2)}, direction=${e>0?"UP":"DOWN"}, price=$${t.toFixed(2)}`),l=i)}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),v.current=a,O(a),a.time!==s?(console.warn(`⚠️ [Chart-1m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(T(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,d.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return d.current=e,e}return t}),a)}return null},[]),Bt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=300*Math.floor(i/300),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-5m] Invalid price data: ${t}`),null;if(s!==E.current){let e=null,i=1;if(w.current&&w.current.close>0&&isFinite(w.current.close)&&w.current.time<s&&(e=w.current.close,w.current.open>0&&(i=w.current.close>=w.current.open?1:-1),console.log(`✅ [Chart-5m] Using currentCandle ref close (${w.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=f.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-5m] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&w.current&&w.current.close>0&&isFinite(w.current.close)&&(e=w.current.close,w.current.open>0&&(i=w.current.close>=w.current.open?1:-1),console.log(`✅ [Chart-5m] Method 3 (PRIMARY): Using currentCandle ref close (${w.current.time}) as new candle open: $${e.toFixed(2)}`)),w.current&&w.current.open>0&&w.current.high>0&&w.current.low>0&&w.current.close>0){const t={...w.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-5m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),V(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,f.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return f.current=s,s})}null===e&&(console.error("❌ [Chart-5m] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-5m] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return w.current=l,E.current=s,B(l),U(s),V(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,f.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return f.current=i,i}),console.log(`🆕 [Chart-5m] New candle: $${t.toFixed(2)}`),l}if(w.current){const i=Math.floor(e/1e3),s=300*Math.floor(i/300);if(w.current.time!==s)return console.warn(`⚠️ [Chart-5m] Skipping update for historical candle (time: ${w.current.time}, current: ${s})`),null;const n=w.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-5m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return w.current=e,B(e),V(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,f.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),w.current=a,B(a),a.time!==s?(console.warn(`⚠️ [Chart-5m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(V(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,f.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return f.current=e,e}return t}),a)}return null},[]),At=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=900*Math.floor(i/900),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-15m] Invalid price data: ${t}`),null;if(s!==_.current){let e=null,i=1;if(y.current&&y.current.close>0&&isFinite(y.current.close)&&y.current.time<s&&(e=y.current.close,y.current.open>0&&(i=y.current.close>=y.current.open?1:-1),console.log(`✅ [Chart-15m] Using currentCandle ref close (${y.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=m.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-15m] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&y.current&&y.current.close>0&&isFinite(y.current.close)&&(e=y.current.close,y.current.open>0&&(i=y.current.close>=y.current.open?1:-1),console.log(`✅ [Chart-15m] Method 3 (PRIMARY): Using currentCandle ref close (${y.current.time}) as new candle open: $${e.toFixed(2)}`)),y.current&&y.current.open>0&&y.current.high>0&&y.current.low>0&&y.current.close>0){const t={...y.current};t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),j(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,m.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return m.current=s,s}),null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-15m] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`))}null===e&&(console.error("❌ [Chart-15m] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-15m] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return y.current=l,_.current=s,K(l),X(s),j(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,m.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return m.current=i,i}),console.log(`🆕 [Chart-15m] New candle: $${t.toFixed(2)}`),l}if(y.current){const i=Math.floor(e/1e3),s=900*Math.floor(i/900);if(y.current.time!==s)return console.warn(`⚠️ [Chart-15m] Skipping update for historical candle (time: ${y.current.time}, current: ${s})`),null;const n=y.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-15m] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return y.current=e,K(e),j(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,m.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),y.current=a,K(a),a.time!==s?(console.warn(`⚠️ [Chart-15m] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(j(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,m.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return m.current=e,e}return t}),a)}return null},[]),Ut=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=3600*Math.floor(i/3600),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1h] Invalid price data: ${t}`),null;if(s!==$.current){let e=null,i=1;if(C.current&&C.current.close>0&&isFinite(C.current.close)&&C.current.time<s&&(e=C.current.close,C.current.open>0&&(i=C.current.close>=C.current.open?1:-1),console.log(`✅ [Chart-1h] Using currentCandle ref close (${C.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=p.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-1h] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&C.current&&C.current.close>0&&isFinite(C.current.close)&&(e=C.current.close,C.current.open>0&&(i=C.current.close>=C.current.open?1:-1),console.log(`✅ [Chart-1h] Method 3 (PRIMARY): Using currentCandle ref close (${C.current.time}) as new candle open: $${e.toFixed(2)}`)),C.current&&C.current.open>0&&C.current.high>0&&C.current.low>0&&C.current.close>0){const t={...C.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1h] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),G(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,p.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return p.current=s,s})}null===e&&(console.error("❌ [Chart-1h] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-1h] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return C.current=l,$.current=s,Y(l),tt(s),G(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,p.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return p.current=i,i}),console.log(`🆕 [Chart-1h] New candle: $${t.toFixed(2)}`),l}if(C.current){const i=Math.floor(e/1e3),s=3600*Math.floor(i/3600);if(C.current.time!==s)return console.warn(`⚠️ [Chart-1h] Skipping update for historical candle (time: ${C.current.time}, current: ${s})`),null;const n=C.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1h] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return C.current=e,Y(e),G(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,p.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),C.current=a,Y(a),a.time!==s?(console.warn(`⚠️ [Chart-1h] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(G(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,p.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return p.current=e,e}return t}),a)}return null},[]),Wt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=14400*Math.floor(i/14400),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-4h] Invalid price data: ${t}`),null;if(s!==z.current){let e=null,i=1;if(S.current&&S.current.close>0&&isFinite(S.current.close)&&S.current.time<s&&(e=S.current.close,S.current.open>0&&(i=S.current.close>=S.current.open?1:-1),console.log(`✅ [Chart-4h] Using currentCandle ref close (${S.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=g.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-4h] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&S.current&&S.current.close>0&&isFinite(S.current.close)&&(e=S.current.close,S.current.open>0&&(i=S.current.close>=S.current.open?1:-1),console.log(`✅ [Chart-4h] Method 3 (PRIMARY): Using currentCandle ref close (${S.current.time}) as new candle open: $${e.toFixed(2)}`)),S.current&&S.current.open>0&&S.current.high>0&&S.current.low>0&&S.current.close>0){const t={...S.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-4h] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),it(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,g.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return g.current=s,s})}null===e&&(console.error("❌ [Chart-4h] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-4h] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return S.current=l,z.current=s,nt(l),ot(s),it(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,g.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return g.current=i,i}),console.log(`🆕 [Chart-4h] New candle: $${t.toFixed(2)}`),l}if(S.current){const i=Math.floor(e/1e3),s=14400*Math.floor(i/14400);if(S.current.time!==s)return console.warn(`⚠️ [Chart-4h] Skipping update for historical candle (time: ${S.current.time}, current: ${s})`),null;const n=S.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-4h] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return S.current=e,nt(e),it(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,g.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),S.current=a,nt(a),a.time!==s?(console.warn(`⚠️ [Chart-4h] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(it(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,g.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return g.current=e,e}return t}),a)}return null},[]),jt=t.useCallback((t,e)=>{const i=Math.floor(e/1e3),s=86400*Math.floor(i/86400),n=Date.now();if(Et.current&&n-Et.current<50)return null;if(Et.current=n,!t||t<=0||!isFinite(t))return console.warn(`⚠️ [Chart-1d] Invalid price data: ${t}`),null;if(s!==k.current){let e=null,i=1;if(M.current&&M.current.close>0&&isFinite(M.current.close)&&M.current.time<s&&(e=M.current.close,M.current.open>0&&(i=M.current.close>=M.current.open?1:-1),console.log(`✅ [Chart-1d] Using currentCandle ref close (${M.current.time}) as new candle open: $${e.toFixed(2)}`)),null===e){const t=b.current||[];if(t.length>0){const n=[...t].sort((t,e)=>e.time-t.time),r=n.find(t=>t.time<s);r&&r.close>0&&isFinite(r.close)&&(e=r.close,r.open>0&&(i=r.close>=r.open?1:-1),console.log(`🔄 [Chart-1d] Using last completed candle close from array (${r.time}) as new candle open: $${e.toFixed(2)}`))}}if(null===e&&M.current&&M.current.close>0&&isFinite(M.current.close)&&(e=M.current.close,M.current.open>0&&(i=M.current.close>=M.current.open?1:-1),console.log(`✅ [Chart-1d] Method 3 (PRIMARY): Using currentCandle ref close (${M.current.time}) as new candle open: $${e.toFixed(2)}`)),M.current&&M.current.open>0&&M.current.high>0&&M.current.low>0&&M.current.close>0){const t={...M.current};null===e&&(e=t.close,t.open>0&&(i=t.close>=t.open?1:-1),console.log(`✅ [Chart-1d] Method 4: Using finalized candle close (${t.time}) as new candle open: $${e.toFixed(2)}`)),t.high=Math.max(t.open,t.high,t.close),t.low=Math.min(t.open,t.low,t.close),lt(e=>{const i=e.findIndex(e=>e.time===t.time);if(i>=0){const s=[...e];return s[i]=t,b.current=s,s}const s=[...e,t].sort((t,e)=>t.time-e.time);return b.current=s,s})}null===e&&(console.error("❌ [Chart-1d] CRITICAL: No previous candle close found after all attempts!"),e=t);const n=e;console.log(`🕯️ [Chart-1d] Creating new candle: open=$${n.toFixed(2)} (from previous close), current price=$${t.toFixed(2)}`);let r=t;const o=Math.abs(n-t),h=Math.max(1e-4*n,.01);if(o<h){let e;e=0===o||Math.abs(t-n)<1e-4?null!==i?i:1:t>=n?1:-1,r=n+e*h}if(Math.abs(r-n)<h&&n>0){r=n+(t>=n||null!==i&&1===i?1:-1)*h}const l={time:s,open:n,high:Math.max(n,r,t),low:Math.min(n,r,t),close:r,volume:0};return M.current=l,k.current=s,ct(l),dt(s),lt(t=>{const e=t.findIndex(t=>t.time===l.time);if(e>=0){const i=[...t];return i[e]=l,b.current=i,i}const i=[...t,l].sort((t,e)=>t.time-e.time);return b.current=i,i}),console.log(`🆕 [Chart-1d] New candle: $${t.toFixed(2)}`),l}if(M.current){const i=Math.floor(e/1e3),s=86400*Math.floor(i/86400);if(M.current.time!==s)return console.warn(`⚠️ [Chart-1d] Skipping update for historical candle (time: ${M.current.time}, current: ${s})`),null;const n=M.current;if(n.open<=0||n.high<=0||n.low<=0||n.close<=0){console.warn("⚠️ [Chart-1d] Invalid existing candle data, recreating");const e={time:n.time,open:t,high:t,low:t,close:t,volume:0};return M.current=e,ct(e),lt(t=>{const i=t.findIndex(t=>t.time===e.time&&t.time===s);if(i>=0){const s=[...t];return s[i]=e,b.current=s,s}return t}),e}const r=Math.max(1e-4*n.open,.01),o=Math.abs(n.open-t),h=Math.abs(n.close-n.open);let l=t;if(h>0&&h<=10*r&&n.open>0)if(o<100*r){const e=t>=n.open?1:-1;l=n.open+e*r}else{l=t;if(Math.abs(l-n.open)<r){const e=t>=n.open?1:-1;l=n.open+e*r}}else if(o<r&&n.open>0){const e=t>=n.open?1:-1;l=n.open+e*r}if(Math.abs(l-n.open)<r&&n.open>0){let e;e=t!==n.open&&Math.abs(t-n.open)>1e-4?t>=n.open?1:-1:n.close!==n.open&&Math.abs(n.close-n.open)>1e-4?n.close>=n.open?1:-1:1,l=n.open+e*r}const a={...n,high:Math.max(n.high,t,l),low:Math.min(n.low,t,l),close:l};return a.high=Math.max(a.open,a.high,a.close),a.low=Math.min(a.open,a.low,a.close),M.current=a,ct(a),a.time!==s?(console.warn(`⚠️ [Chart-1d] Prevented update of historical candle: time=${a.time}, currentBucket=${s}`),a):(lt(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,b.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return b.current=e,e}return t}),a)}return null},[]);t.useEffect(()=>{xt.current=mt},[mt]),t.useEffect(()=>{R.current=Ot},[Ot]),t.useEffect(()=>{if(!a.current)return;const t=zn(a.current,{layout:{background:{color:"#ffffff"},textColor:"#333333"},grid:{vertLines:{color:"#f0f0f0"},horzLines:{color:"#f0f0f0"}},crosshair:{mode:ft.Normal},rightPriceScale:{borderColor:"#cccccc"},timeScale:{borderColor:"#cccccc",timeVisible:!0,secondsVisible:!1,rightOffset:12,barSpacing:8,minBarSpacing:4},height:384,localization:{priceFormatter:t=>Dt(t)},watermark:{visible:!0,fontSize:64,horzAlign:"center",vertAlign:"center",color:"rgba(0, 0, 0, 0.03)",text:i?`${i}/SOL`:`${e.substring(0,4)}...${e.substring(e.length-4)}/SOL`}});c.current=t;const s=t.addCandlestickSeries({upColor:"#26a69a",downColor:"#ef5350",borderVisible:!0,borderUpColor:"#26a69a",borderDownColor:"#ef5350",wickUpColor:"#26a69a",wickDownColor:"#ef5350"});u.current=s,Vt(Ot.seconds).then(t=>{if(t.length>0){let e=t[t.length-1],i=t;if(Rt>0){const s=Math.floor(Date.now()/1e3),n=Math.floor(s/Ot.seconds)*Ot.seconds;if(e.time===n){const s=Math.max(1e-4*e.open,.01),n=Math.abs(e.open-Rt);let r=Rt;if(n<s&&e.open>0){const t=Rt>=e.open?1:-1;r=e.open+t*s}e={...e,high:Math.max(e.high,Rt,r),low:Math.min(e.low,Rt,r),close:r},i=[...t],i[i.length-1]=e,console.log(`🔄 [Chart-Init] Updated initial ${Ot.label} candle with current MC: $${Rt.toFixed(2)}`)}}switch(Ot.seconds){case 60:T(i),P(e.time),O(e),d.current=i,x.current=e.time,v.current=e,console.log(`✅ [Chart-Init] 1m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 300:V(i),U(e.time),B(e),f.current=i,E.current=e.time,w.current=e,console.log(`✅ [Chart-Init] 5m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 900:j(i),X(e.time),K(e),m.current=i,_.current=e.time,y.current=e,console.log(`✅ [Chart-Init] 15m refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 3600:G(i),tt(e.time),Y(e),p.current=i,$.current=e.time,C.current=e,console.log(`✅ [Chart-Init] 1h refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 14400:it(i),ot(e.time),nt(e),g.current=i,z.current=e.time,S.current=e,console.log(`✅ [Chart-Init] 4h refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`);break;case 86400:lt(i),dt(e.time),ct(e),b.current=i,k.current=e.time,M.current=e,console.log(`✅ [Chart-Init] 1d refs initialized: lastCandle.time=${e.time}, close=$${e.close.toFixed(2)}`)}s.setData(i.map(t=>({...t,time:t.time}))),console.log(`✅ [Chart-${Ot.label}] Loaded and displayed ${i.length} candles`),60!==Ot.seconds&&Vt(60).then(t=>{if(t.length>0){d.current=t;const e=t[t.length-1];x.current=e.time,v.current=e,console.log(`✅ [Chart-Init] 1m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),300!==Ot.seconds&&Vt(300).then(t=>{if(t.length>0){f.current=t;const e=t[t.length-1];E.current=e.time,w.current=e,console.log(`✅ [Chart-Init] 5m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),900!==Ot.seconds&&Vt(900).then(t=>{if(t.length>0){m.current=t;const e=t[t.length-1];_.current=e.time,y.current=e,console.log(`✅ [Chart-Init] 15m refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),3600!==Ot.seconds&&Vt(3600).then(t=>{if(t.length>0){p.current=t;const e=t[t.length-1];$.current=e.time,C.current=e,console.log(`✅ [Chart-Init] 1h refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),14400!==Ot.seconds&&Vt(14400).then(t=>{if(t.length>0){g.current=t;const e=t[t.length-1];z.current=e.time,S.current=e,console.log(`✅ [Chart-Init] 4h refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{}),86400!==Ot.seconds&&Vt(86400).then(t=>{if(t.length>0){b.current=t;const e=t[t.length-1];k.current=e.time,M.current=e,console.log(`✅ [Chart-Init] 1d refs initialized from DB: close=$${e.close.toFixed(2)}`)}}).catch(()=>{})}bt(!1)}).catch(t=>{console.error(`❌ [Chart-${Ot.label}] Load error:`,t),bt(!1)});const n=()=>{a.current&&t.applyOptions({width:a.current.clientWidth})};return window.addEventListener("resize",n),n(),()=>{window.removeEventListener("resize",n),t.remove()}},[e,Vt,Dt,Ot,i]);const Ht=t.useCallback(async t=>{const e=Lt.find(e=>e.value===t);if(e&&e.value!==Ot.value){if(vt)return void console.log(`⚠️ [Chart] Timeframe switch already in progress, ignoring ${e.label}`);console.log(`🔄 [Chart] Switching to ${e.label}`),wt(!0),Ct(e.label),bt(!0);try{let t=[];switch(e.seconds){case 60:t=d.current;break;case 300:t=f.current;break;case 900:t=m.current;break;case 3600:t=p.current;break;case 14400:t=g.current;break;case 86400:t=b.current}if(t.length>0){console.log(`✅ [Chart] Using ${t.length} cached ${e.label} candles`);let i=t,s=t[t.length-1];if(xt.current>0){const n=Math.floor(Date.now()/1e3),r=Math.floor(n/e.seconds)*e.seconds;if(s&&s.time===r){const n=Math.max(1e-4*s.open,.01),r=Math.abs(s.open-xt.current);let o=xt.current;if(r<n&&s.open>0){const t=xt.current>=s.open?1:-1;o=s.open+t*n}const h={...s,high:Math.max(s.high,xt.current,o),low:Math.min(s.low,xt.current,o),close:o};i=[...t],i[i.length-1]=h,s=h,console.log(`🔄 [Chart] Updated current ${e.label} candle with latest MC: $${xt.current.toFixed(2)}`)}}switch(e.seconds){case 60:T(i),P(s.time),O(s),d.current=i,x.current=s.time,v.current=s;break;case 300:V(i),U(s.time),B(s),f.current=i,E.current=s.time,w.current=s;break;case 900:j(i),X(s.time),K(s),m.current=i,_.current=s.time,y.current=s;break;case 3600:G(i),tt(s.time),Y(s),p.current=i,$.current=s.time,C.current=s;break;case 14400:it(i),ot(s.time),nt(s),g.current=i,z.current=s.time,S.current=s;break;case 86400:lt(i),dt(s.time),ct(s),b.current=i,k.current=s.time,M.current=s}u.current&&u.current.setData(i.map(t=>({...t,time:t.time}))),setTimeout(()=>{Ft(e),bt(!1),wt(!1),Ct(null),console.log(`✅ [Chart] Switched to ${e.label} with ${i.length} cached candles`)},0)}else{console.log(`📊 [Chart] Loading ${e.label} candles`);const t=await Vt(e.seconds);if(t.length>0){let i=t[t.length-1],s=t;if(xt.current>0){const n=Math.floor(Date.now()/1e3),r=Math.floor(n/e.seconds)*e.seconds;if(i.time===r){const n=Math.max(1e-4*i.open,.01),r=Math.abs(i.open-xt.current);let o=xt.current;if(r<n&&i.open>0){const t=xt.current>=i.open?1:-1;o=i.open+t*n}i={...i,high:Math.max(i.high,xt.current,o),low:Math.min(i.low,xt.current,o),close:o},s=[...t],s[s.length-1]=i,console.log(`🔄 [Chart] Updated loaded ${e.label} candle with current MC: $${xt.current.toFixed(2)}`)}}switch(e.seconds){case 60:T(s),P(i.time),O(i),d.current=s,x.current=i.time,v.current=i;break;case 300:V(s),U(i.time),B(i),f.current=s,E.current=i.time,w.current=i;break;case 900:j(s),X(i.time),K(i),m.current=s,_.current=i.time,y.current=i;break;case 3600:G(s),tt(i.time),Y(i),p.current=s,$.current=i.time,C.current=i;break;case 14400:it(s),ot(i.time),nt(i),g.current=s,z.current=i.time,S.current=i;break;case 86400:lt(s),dt(i.time),ct(i),b.current=s,k.current=i.time,M.current=i}u.current&&u.current.setData(s.map(t=>({...t,time:t.time}))),setTimeout(()=>{Ft(e),bt(!1),wt(!1),Ct(null),console.log(`✅ [Chart] Switched to ${e.label} with ${s.length} loaded candles`)},0)}else setTimeout(()=>{Ft(e),bt(!1),wt(!1),Ct(null),console.log(`⚠️ [Chart] No candles loaded for ${e.label}`)},0)}}catch(t){console.error("❌ [Chart] Switch error:",t),setTimeout(()=>{Ft(e),bt(!1),wt(!1),Ct(null)},0)}}},[Lt,Ot,Vt,vt]);if(t.useEffect(()=>{if(!e||!u.current||Rt<=0)return;if(!isFinite(Rt)||Rt<=0)return void console.warn(`⚠️ [Chart-Isolated] Invalid market cap data: ${Rt}`);console.log(`💰 [Chart-Isolated] Real-time update: $${Rt.toFixed(2)}`);const t=Date.now();requestAnimationFrame(()=>{It(Rt,t),Bt(Rt,t),At(Rt,t),Ut(Rt,t),Wt(Rt,t),jt(Rt,t),pt(Rt),bt(!1);const e=Pt();if(e.length>0){const t=e.filter(t=>t&&t.open>0&&t.high>0&&t.low>0&&t.close>0&&isFinite(t.open)&&isFinite(t.high)&&isFinite(t.low)&&isFinite(t.close));t.length>0&&u.current&&(u.current.setData(t.map(t=>({...t,time:t.time}))),requestAnimationFrame(()=>{c.current&&c.current.timeScale().scrollToRealTime()}))}})},[e,Rt,It,Bt,At,Ut,Wt,jt,Pt]),t.useEffect(()=>{if(!$t||!zt||!e)return;const t=t=>{if(t.mint===e&&(console.log(`📡 [Chart-Isolated] Received multi-timeframe candles from backend for ${e}`,t.candles?Object.keys(t.candles):"no candles"),t.candles)){const e=t.candles,i=(t,e)=>{const i=Math.floor(Date.now()/1e3),s=Math.floor(i/t)*t;if(e.time!==s)return void console.warn(`⚠️ [Chart-Socket] Skipping backend update for historical candle: time=${e.time}, currentBucket=${s}, timeframe=${t}s`);let n=e.open,r=e.close;const o=Math.max(1e-4*n,.01),h=Math.abs(n-r);let l=null;switch(t){case 60:l=v.current;break;case 300:l=w.current;break;case 900:l=y.current;break;case 3600:l=C.current;break;case 14400:l=S.current;break;case 86400:l=M.current}if(l&&l.time===e.time&&l.open>0&&l){const e=Math.abs(l.close-l.open);if(e>=.5*o&&e<=2*o){if(Math.abs(l.open-r)<2*o)r=l.close,n=l.open,console.log(`🛡️ [Chart] Preserving minimum body size for ${t}s candle from frontend`);else if(h<o){r=n+(r>=n?1:-1)*o}}else if(h<o&&n>0){r=n+(r>=n?1:-1)*o}}else if(h<o&&n>0){r=n+(r>=n?1:-1)*o}if(Math.abs(r-n)<o&&n>0){r=n+(r>=n||l&&l.close>=l.open?1:-1)*o}const a={time:e.time,open:n,high:Math.max(e.high||n,n,r),low:Math.min(e.low||n,n,r),close:r,volume:e.volume||0};if(a.time===s)switch(t){case 60:v.current=a,x.current=a.time,O(a),P(a.time),T(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,d.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return d.current=e,e}return t});break;case 300:w.current=a,E.current=a.time,B(a),U(a.time),V(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,f.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return f.current=e,e}return t});break;case 900:y.current=a,_.current=a.time,K(a),X(a.time),j(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,m.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return m.current=e,e}return t});break;case 3600:C.current=a,$.current=a.time,Y(a),tt(a.time),G(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,p.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return p.current=e,e}return t});break;case 14400:S.current=a,z.current=a.time,nt(a),ot(a.time),it(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,g.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return g.current=e,e}return t});break;case 86400:M.current=a,k.current=a.time,ct(a),dt(a.time),lt(t=>{const e=t.findIndex(t=>t.time===s);if(e>=0&&t[e].time===s){const i=[...t];return i[e]=a,b.current=i,i}if(a.time===s){const e=[...t,a].sort((t,e)=>t.time-e.time);return b.current=e,e}return t})}else console.warn(`⚠️ [Chart-Socket] Prevented update: candle time ${a.time} doesn't match current bucket ${s}`)};e["1m"]&&(i(60,e["1m"]),console.log("✅ [Chart-Isolated] Updated 1m from backend with full OHLC")),e["5m"]&&(i(300,e["5m"]),console.log("✅ [Chart-Isolated] Updated 5m from backend with full OHLC")),e["15m"]&&(i(900,e["15m"]),console.log("✅ [Chart-Isolated] Updated 15m from backend with full OHLC")),e["1h"]&&(i(3600,e["1h"]),console.log("✅ [Chart-Isolated] Updated 1h from backend with full OHLC")),e["4h"]&&(i(14400,e["4h"]),console.log("✅ [Chart-Isolated] Updated 4h from backend with full OHLC")),e["1d"]&&(i(86400,e["1d"]),console.log("✅ [Chart-Isolated] Updated 1d from backend with full OHLC"));const s=Pt();s.length>0&&u.current&&(u.current.setData(s.map(t=>({...t,time:t.time}))),requestAnimationFrame(()=>{c.current&&c.current.timeScale().scrollToRealTime()}))}};return $t.on("multiTimeframeCandleUpdate",t),()=>{$t.off("multiTimeframeCandleUpdate",t)}},[$t,zt,e,Pt]),t.useEffect(()=>{const t=Pt();if((gt||Tt)&&0===t.length){const t=setTimeout(()=>bt(!1),1e4);return()=>clearTimeout(t)}},[gt,Tt,Pt]),St)return t.createElement("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg"},t.createElement("div",{className:"text-red-800 font-medium"},"Chart Error"),t.createElement("div",{className:"text-red-600 text-sm"},St),t.createElement("button",{onClick:()=>Mt(null),className:"mt-2 px-3 py-1 bg-red-100 text-red-700 rounded text-sm hover:bg-red-200"},"Dismiss"));const Kt=Pt();return t.createElement("div",{className:"w-full"},t.createElement("div",{className:"mb-4 flex flex-wrap gap-2 items-center"},t.createElement("div",{className:"flex flex-wrap gap-2"},Lt.map(e=>{const i=Ot.value===e.value,s=vt&&yt===e.label,n=vt;return t.createElement("button",{key:e.value,onClick:()=>Ht(e.value),disabled:n,className:`\n px-3 py-2 rounded-lg text-sm font-medium transition-all duration-200 relative\n ${i?"bg-blue-600 text-white":n?"bg-gray-100 text-gray-400 cursor-not-allowed":"bg-gray-100 text-gray-700 hover:bg-gray-200"}\n ${s?"animate-pulse":""}\n `},s&&t.createElement("div",{className:"absolute inset-0 flex items-center justify-center"},t.createElement("div",{className:"flex space-x-1"},t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse"}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.2s"}}))),t.createElement("span",{className:s?"opacity-0":"opacity-100"},e.label))})),t.createElement("div",{className:"ml-auto flex items-center gap-2 text-sm"},t.createElement("div",{className:"w-2 h-2 rounded-full "+(Nt?"bg-green-500":"bg-red-500")}),t.createElement("span",{className:Nt?"text-green-600":"text-red-600"},Nt?"Connected":"Disconnected"),vt&&yt&&t.createElement("span",{className:"text-blue-600"},"• Switching to ",yt,"..."),!vt&>&&!Tt&&t.createElement("span",{className:"text-blue-600"},"• Loading candles..."),Tt&&t.createElement("span",{className:"text-blue-600"},"• Connecting to analytics..."),!vt&&!gt&&!Tt&&Kt.length>0&&t.createElement("span",{className:"text-green-600"},"• ",Kt.length," ",Ot.label," candles • ",Dt(mt)))),t.createElement("div",{ref:a,className:"relative w-full h-96 transition-all duration-300 "+(vt?"opacity-75 scale-[0.98]":"opacity-100 scale-100")},(vt||gt&&!Tt)&&t.createElement("div",{className:"absolute inset-0 bg-gradient-to-br from-white via-blue-50 to-white bg-opacity-90 flex items-center justify-center rounded-lg z-10 backdrop-blur-sm"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"flex justify-center items-center mb-4"},t.createElement("div",{className:"relative"},t.createElement("div",{className:"w-12 h-12 border-4 border-blue-200 rounded-full"}),t.createElement("div",{className:"absolute top-0 left-0 w-12 h-12 border-4 border-blue-600 rounded-full border-t-transparent animate-spin"}))),t.createElement("div",{className:"text-gray-700 font-medium text-lg"},vt&&yt?`Switching to ${yt} timeframe...`:"Loading real-time data..."),t.createElement("div",{className:"mt-3 flex justify-center space-x-1"},t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce"}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})))),!vt&&!gt&&!Tt&&0===Kt.length&&t.createElement("div",{className:"absolute inset-0 bg-white bg-opacity-75 flex items-center justify-center rounded-lg z-10"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"text-gray-600 mb-2"},"No ",Ot.label," market data available"),t.createElement("div",{className:"text-sm text-gray-500"},"Waiting for real-time data...")))))},exports.FunhiChartOOP=({mint:e,ticker:i,tokenName:s,socket:n,isConnected:r,currentMarketCap:o,analyticsConnected:h,analyticsLoading:l})=>{const a=t.useRef(null),c=t.useRef(null),[u,d]=t.useState(!0),[f,m]=t.useState(!1),[p,g]=t.useState(null),[b,v]=t.useState(null),[w,y]=t.useState(null),C=kn(),S=n||C.socket,M=void 0!==r?r:C.isConnected,x=Rn(),E=void 0!==o?o:x.currentMarketCap,_=void 0!==h?h:x.connected,$=void 0!==l?l:x.loading,z=t.useMemo(()=>[{label:"1m",value:"1m",seconds:60},{label:"5m",value:"5m",seconds:300},{label:"15m",value:"15m",seconds:900},{label:"1h",value:"1h",seconds:3600},{label:"4h",value:"4h",seconds:14400},{label:"1d",value:"1d",seconds:86400}],[]),k=t.useCallback(t=>t>=1e9?`$${(t/1e9).toFixed(t>=1e10?2:3)}B`:t>=1e6?`$${(t/1e6).toFixed(t>=1e7?2:3)}M`:t>=1e4?`$${(t/1e3).toFixed(t>=1e5?1:2)}K`:t>=1e3?`$${(t/1e3).toFixed(2)}K`:t>=1?`$${t.toFixed(2)}`:`$${t.toFixed(4)}`,[]);t.useEffect(()=>{if(a.current&&e)try{const t={mint:e,ticker:i,tokenName:s,timeframes:z,container:a.current,formatPrice:k},n=new ah(t);return c.current=n,n.initialize().then(()=>{y(n.getCurrentTimeframe()),d(!1)}).catch(t=>{console.error("❌ [FunhiChartOOP] Initialization error:",t),v(t.message||"Failed to initialize chart"),d(!1)}),()=>{n.destroy(),c.current=null}}catch(t){console.error("❌ [FunhiChartOOP] Controller creation error:",t),v(t.message||"Failed to create chart controller"),d(!1)}},[e,i,s,z,k]),t.useEffect(()=>{!c.current||E<=0||(!isFinite(E)||E<=0?console.warn(`⚠️ [FunhiChartOOP] Invalid market cap data: ${E}`):c.current.updatePrice(E))},[E]),t.useEffect(()=>{if(!(S&&M&&e&&c.current))return;const t=t=>{t.mint===e&&c.current?.handleSocketUpdate(t)};return S.on("multiTimeframeCandleUpdate",t),()=>{S.off("multiTimeframeCandleUpdate",t)}},[S,M,e]);const R=t.useCallback(async t=>{if(!c.current)return;const e=z.find(e=>e.value===t);if(e&&e.value!==w?.value)if(f)console.log("⚠️ [FunhiChartOOP] Timeframe switch already in progress");else{console.log(`🔄 [FunhiChartOOP] Switching to ${e.label}`),m(!0),g(e.label),d(!0);try{await c.current.switchTimeframe(e.seconds),y(e),d(!1),m(!1),g(null),console.log(`✅ [FunhiChartOOP] Switched to ${e.label}`)}catch(t){console.error("❌ [FunhiChartOOP] Switch error:",t),d(!1),m(!1),g(null)}}},[z,w,f]);if(t.useEffect(()=>{const t=()=>{c.current?.resize()};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),t.useEffect(()=>{if((u||$)&&c.current){if(0===c.current.getCurrentCandles().length){const t=setTimeout(()=>d(!1),1e4);return()=>clearTimeout(t)}}},[u,$]),b)return t.createElement("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg"},t.createElement("div",{className:"text-red-800 font-medium"},"Chart Error"),t.createElement("div",{className:"text-red-600 text-sm"},b),t.createElement("button",{onClick:()=>v(null),className:"mt-2 px-3 py-1 bg-red-100 text-red-700 rounded text-sm hover:bg-red-200"},"Dismiss"));const N=c.current?.getCurrentCandles()||[],T=E||0;return t.createElement("div",{className:"w-full"},t.createElement("div",{className:"mb-4 flex flex-wrap gap-2 items-center"},t.createElement("div",{className:"flex flex-wrap gap-2"},z.map(e=>{const i=w?.value===e.value,s=f&&p===e.label,n=f;return t.createElement("button",{key:e.value,onClick:()=>R(e.value),disabled:n,className:`\n px-3 py-2 rounded-lg text-sm font-medium transition-all duration-200 relative\n ${i?"bg-blue-600 text-white":n?"bg-gray-100 text-gray-400 cursor-not-allowed":"bg-gray-100 text-gray-700 hover:bg-gray-200"}\n ${s?"animate-pulse":""}\n `},s&&t.createElement("div",{className:"absolute inset-0 flex items-center justify-center"},t.createElement("div",{className:"flex space-x-1"},t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse"}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-1 h-1 bg-white rounded-full animate-pulse",style:{animationDelay:"0.2s"}}))),t.createElement("span",{className:s?"opacity-0":"opacity-100"},e.label))})),t.createElement("div",{className:"ml-auto flex items-center gap-2 text-sm"},t.createElement("div",{className:"w-2 h-2 rounded-full "+(_?"bg-green-500":"bg-red-500")}),t.createElement("span",{className:_?"text-green-600":"text-red-600"},_?"Connected":"Disconnected"),f&&p&&t.createElement("span",{className:"text-blue-600"},"• Switching to ",p,"..."),!f&&u&&!$&&t.createElement("span",{className:"text-blue-600"},"• Loading candles..."),$&&t.createElement("span",{className:"text-blue-600"},"• Connecting to analytics..."),!f&&!u&&!$&&N.length>0&&t.createElement("span",{className:"text-green-600"},"• ",N.length," ",w?.label," candles • ",k(T)))),t.createElement("div",{ref:a,className:"relative w-full h-96 transition-all duration-300 "+(f?"opacity-75 scale-[0.98]":"opacity-100 scale-100")},(f||u&&!$)&&t.createElement("div",{className:"absolute inset-0 bg-gradient-to-br from-white via-blue-50 to-white bg-opacity-90 flex items-center justify-center rounded-lg z-10 backdrop-blur-sm"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"flex justify-center items-center mb-4"},t.createElement("div",{className:"relative"},t.createElement("div",{className:"w-12 h-12 border-4 border-blue-200 rounded-full"}),t.createElement("div",{className:"absolute top-0 left-0 w-12 h-12 border-4 border-blue-600 rounded-full border-t-transparent animate-spin"}))),t.createElement("div",{className:"text-gray-700 font-medium text-lg"},f&&p?`Switching to ${p} timeframe...`:"Loading real-time data..."),t.createElement("div",{className:"mt-3 flex justify-center space-x-1"},t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce"}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),t.createElement("div",{className:"w-2 h-2 bg-blue-600 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})))),!f&&!u&&!$&&0===N.length&&t.createElement("div",{className:"absolute inset-0 bg-white bg-opacity-75 flex items-center justify-center rounded-lg z-10"},t.createElement("div",{className:"text-center"},t.createElement("div",{className:"text-gray-600 mb-2"},"No ",w?.label," market data available"),t.createElement("div",{className:"text-sm text-gray-500"},"Waiting for real-time data...")))))},exports.candleAggregation=ch,exports.candleStorageService=ih,exports.useOptimizedTokenAnalytics=Rn,exports.useSocket=kn;
|
|
8
8
|
//# sourceMappingURL=index.js.map
|