@devexperts/dxcharts-lite 2.7.27 → 2.7.28

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.
@@ -21,4 +21,4 @@ ${n?` <p style="position: absolute; visibility: hidden;">If you have any sugge
21
21
  `:""} </div>
22
22
  </div>
23
23
  </div>
24
- `);function wc(n){const t=document.createElement("template");return t.innerHTML=yc(n.devexpertsPromoLink),t}function Sc(n){const t={},e=Array.from(n.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(s=>{var i;t[(i=s.getAttribute("data-element"))!=null?i:""]=s}),Cc(t))return t;throw new Error("Some chart elements are missing")}function xc(n){if(n.length>1){const t=n.reduce((i,r,o)=>{if(o!==n.length-1){const a=n[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,s;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,s=r)}if(s)return s}}const _c=n=>t=>n?new Date(t).setHours(0,0,0,0):t,Oe=(n,t={},e,s=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=_c(!!c),u=d(n),f=d((r=(i=ge(e))==null?void 0:i.timestamp)!=null?r:0),g=d((a=(o=St(e))==null?void 0:o.timestamp)!=null?a:0);return u>g?h?{index:e.length-1+Math.ceil((u-g)/s),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:at((u-f)/s),exact:!0}:{index:-1,exact:!0}:Yt(e,u,m=>d(m.timestamp))},Vm=n=>{const t=n[0],e=n[n.length-1];return n.length>0&&[t,e].some(s=>s!==void 0&&s.impVolatility!==null&&s.impVolatility!==void 0&&!isNaN(s.impVolatility))},zi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},Vi={paintConfig:[zi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var Pc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,Tc=Object.prototype.hasOwnProperty,Mc=Object.prototype.propertyIsEnumerable,Gi=(n,t,e)=>t in n?Pc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ac=(n,t)=>{for(var e in t||(t={}))Tc.call(t,e)&&Gi(n,e,t[e]);if(Ui)for(var e of Ui(t))Mc.call(t,e)&&Gi(n,e,t[e]);return n};class Ec{constructor(t,e,s,i){this.series=t,this.config=e,this.yAxisBoundsProvider=s,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,s=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Ac({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:s}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:zi).color;return{textColor:se(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function Ic(n,t){if(n.filter(a=>a!==null).length<=1)return n.map(a=>a.y);const e=t-2,s=n.map((a,l)=>Dc(a,l,e)).filter(li).sort(Lc),i=new Array(s.length),r=s.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=s.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=s[a],c=s[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<s.length;a++){const l=s[a],c=s[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const Dc=(n,t,e)=>n?{top:n.y-e/2,bottom:n.y+e/2,labelWeight:n.weight,actualIndex:t}:null,Lc=(n,t)=>{const e=n.top,s=t.top;return e>s?1:e<s||e===s&&n.labelWeight<t.labelWeight?-1:0};var Oc=Object.defineProperty,Bc=Object.defineProperties,Rc=Object.getOwnPropertyDescriptors,Zi=Object.getOwnPropertySymbols,Fc=Object.prototype.hasOwnProperty,Hc=Object.prototype.propertyIsEnumerable,$i=(n,t,e)=>t in n?Oc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ki=(n,t)=>{for(var e in t||(t={}))Fc.call(t,e)&&$i(n,e,t[e]);if(Zi)for(var e of Zi(t))Hc.call(t,e)&&$i(n,e,t[e]);return n},qi=(n,t)=>Bc(n,Rc(t));const ie={MAIN:"MAIN"};class kc extends X{constructor(t,e,s,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=s,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new F,this.animFrameId=`anim_cache_${wt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,yt(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Lt(50,Rt,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,s])=>{this.addToGroup(s,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Pe(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const s=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=mt(Object.values(i).map(l=>l.getUnorderedLabels())),o=mt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=Ic(o,s);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,s){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][s]=t))}updateLabelsCoordinates(t,e){return qi(Ki({},t),{labels:t.labels.map((s,i)=>qi(Ki({},s),{lineY:s.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,s){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[s]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var s;const i=(s=this.labelsProviders[t])!=null?s:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Ft=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Ks=()=>{rs.removeEventListener("change",Ks),Ft=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),rs.addEventListener("change",Ks)};rs.addEventListener("change",Ks);const jc=()=>Ft,Um=n=>round(Ft*n)/Ft,Et=n=>at(Ft*n)/Ft,qs=n=>pl(Ft*n)/Ft,re=n=>JSON.parse(JSON.stringify(n));function Js(n){return Object.entries(n)}const Ji=(n,t)=>{for(const[e,s]of Array.from(n.entries()))if(s===t)return e};function Qi(n){return Object.keys(n)}function tr(n,t){if(Object.is(n,t))return!0;if(typeof n!="object"||n===null||typeof t!="object"||t===null)return!1;const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!tr(n[e[i]],t[e[i]]))return!1;return!0}const Yc=n=>Object.keys(n).length===0&&n.constructor===Object;function er(n){n===void 0&&(n={});var t=n.connector,e=t===void 0?function(){return new F}:t,s=n.resetOnError,i=s===void 0?!0:s,r=n.resetOnComplete,o=r===void 0?!0:r,a=n.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,g=!1,m=!1,x=function(){d==null||d.unsubscribe(),d=void 0},_=function(){x(),h=u=void 0,g=m=!1},A=function(){var L=h;_(),L==null||L.unsubscribe()};return N(function(L,Y){f++,!m&&!g&&x();var H=u=u!=null?u:e();Y.add(function(){f--,f===0&&!m&&!g&&(d=Qs(A,l))}),H.subscribe(Y),!h&&f>0&&(h=new _e({next:function(B){return H.next(B)},error:function(B){m=!0,x(),d=Qs(_,i,B),H.error(B)},complete:function(){g=!0,x(),d=Qs(_,o),H.complete()}}),Dt(L).subscribe(h))})(c)}}function Qs(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];if(t===!0){n();return}if(t!==!1){var i=new _e({next:function(){i.unsubscribe(),n()}});return Dt(t.apply(void 0,ot([],R(e)))).subscribe(i)}}const os=(n,t)=>n/t,vt=(n,t)=>n/t,Ht=(n,t)=>n*t,sr=(n,t)=>(n-t)*100/t,nr=(n,t)=>n*t/100+t,ir=n=>Math.log2(n),tn=n=>Math.pow(2,n);class Nc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new F,this.xChanged=this.changed.pipe(dt(()=>({start:this.xStart,end:this.xEnd})),Tt((t,e)=>t.start===e.start&&t.end===e.end),er()),this.yChanged=this.changed.pipe(dt(()=>({start:this.yStart,end:this.yEnd})),Tt((t,e)=>t.start===e.start&&t.end===e.end),er()),this.initialViewportValidSubject=new ft(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+vt(t-this.xStart,this.zoomX)}xPixels(t){return vt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+vt(t-this.yStart,this.zoomY):e.y+e.height-vt(t-this.yStart,this.zoomY)}yPixels(t){return vt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Ht(e+vt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),s=t-e.y;return this.inverseY?Ht(s+vt(this.yStart,this.zoomY),this.zoomY):Ht(e.height-s+vt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return os(e-t,this.getBounds().width)}calculateZoomY(t,e){return os(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,s=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),s&&this.fireChanged()}setYScale(t,e,s=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),s&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const Xc=(n,t)=>!Qi(n).some(e=>n[e]!==t[e]);class Wc{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let s;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Yt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Yt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),s=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else s=t();return s}}class rr{constructor(t,e,s,i){this.dataSeries=t,this.scale=e,this.getAxisType=s,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Wc(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const s=this.percentAnimationHandler.getBaselineForPercent(e);return sr(t,s);case"logarithmic":return t<=0?t:ir(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return nr(t,this.getBaseline());case"logarithmic":return tn(t);case"regular":return t}}}const Zt=16;var zc=Object.defineProperty,Vc=Object.defineProperties,Uc=Object.getOwnPropertyDescriptors,or=Object.getOwnPropertySymbols,Gc=Object.prototype.hasOwnProperty,Zc=Object.prototype.propertyIsEnumerable,ar=(n,t,e)=>t in n?zc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,lr=(n,t)=>{for(var e in t||(t={}))Gc.call(t,e)&&ar(n,e,t[e]);if(or)for(var e of or(t))Zc.call(t,e)&&ar(n,e,t[e]);return n},$c=(n,t)=>Vc(n,Uc(t));class Be{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Et(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Be(this.centerUnit,this.close)}}class cr extends X{constructor(t,e,s,i,r){var o;super(),this.extentComponent=t,this.id=e,this.htId=s,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=l=>{var c;return(c=this.config.paintConfig[l])!=null?c:this.config.paintConfig[0]},this.getBaseline=(l=this.dataIdxStart)=>{var c,h,d;return(c=this.visualPoints[l])!=null&&c.close&&((h=this.visualPoints[l])==null?void 0:h.close)>=0?(d=this.visualPoints[l])==null?void 0:d.close:1},this.getTextForPoint=l=>`${l.close}`,this.getLastVisualSeriesPoint=()=>{const l=this.visualPoints;if(l.length!==0)return l[this.dataIdxEnd]},this.getLastDataSeriesPoint=()=>{const l=this.visualPoints;return St(l)};const a=r!=null?r:re(Vi);this.config=At(a,Vi),this.scale=t.scale,this.view=new rr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Ec(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=qc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=di(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=di(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.pipe(Lt(Zt,Rt,{trailing:!0,leading:!0}),dt(()=>this.calculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)),Tt((t,e)=>t.dataIdxStart===e.dataIdxStart&&t.dataIdxEnd===e.dataIdxEnd)).subscribe(()=>{this.recalculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)})),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const s=lr({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new rr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=s.yAxis.model.fancyLabelsModel.labelsProviders[ie.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[ie.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(ie.MAIN,a,r),s.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(ie.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,s)=>({centerUnit:s,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.centerUnit).index,i=Yt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let s=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);s=r.dataIdxStart,i=r.dataIdxEnd}return Ol(this.visualPoints2D,s,i)}}const Kc=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.close>t.high&&(t.high=s.close,t.highIdx=e),s.close<t.low&&(t.low=s.close,t.lowIdx=e)}return t},qc=n=>({isHighLowActive:()=>n.config.highLowActive&&n.config.visible,calculateHighLow:t=>{const e=Kc(n.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return $c(lr({},e),{high:n.view.toAxisUnits(e.high),low:n.view.toAxisUnits(e.low)})}}),Jc=n=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(n);return gt.makeDecimal(n,i)};class as extends Be{constructor(t,e,s,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=s,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),s=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>s?[s,e]:[e,s];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const me=60,Re=(n,t,e=me)=>{const s=hr(n,t,e);return{id:xi(s,s),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:s,volume:NaN,expansion:!0,idx:t}},Qc=(n,t,e=me)=>({close:NaN,timestamp:hr(n,t,e)});function hr(n,t,e=me){var s,i;const r=Me(t);if(n.length===0)return 0;const o=St(n);if(r>=n.length&&o)return dr(o,n.length-1,r,e);const a=ge(n);return r<0&&a?dr(a,0,r,e):(i=(s=n[r])==null?void 0:s.timestamp)!=null?i:0}const dr=(n,t,e,s=me)=>n.timestamp+(e-(t!=null?t:0))*s,en=(n,t,e,s,i=me)=>{const r=Re(n,s,i);r.volume=e;let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new as(o,e,r.open,r.close,r.lo,r.hi,ts(r.open,r.close),r)},th=(n,t,e,s,i=me)=>{const r=Qc(n,s,i);let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new Be(o,r.close)};class eh{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new F,this.dataSetSubject=new F,this.dataRemovedSubject=new F,this.dataPrependSubject=new F,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},s=this.mainDataPoints){const i=Oe(t,e,s,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=xc(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?en(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):th(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var sh=Object.defineProperty,ur=Object.getOwnPropertySymbols,nh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,fr=(n,t,e)=>t in n?sh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,rh=(n,t)=>{for(var e in t||(t={}))nh.call(t,e)&&fr(n,e,t[e]);if(ur)for(var e of ur(t))ih.call(t,e)&&fr(n,e,t[e]);return n};class oh{constructor(t,e,s=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=s,this.prevState={},this.isColorsChanged=()=>!tr(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=rh({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const ah=(n,t,e,s,i,r,o)=>{const a=jc(),l=[e*a,s*a,i*a,r*a];let c=n.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=at(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?at(u*o):at(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},gr=(n,{x:t,width:e,activeCandle:s})=>new as(t,e,n.open,n.close,n.hi,n.lo,ts(n.open,n.close),n,!0,sn(n,s)),lh=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,Ul((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,sn(n,s),n.close>n.open)},pr=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,ts((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,sn(n,s),n.close>n.open)},ch=pr,sn=(n,t)=>{const e=t&&t.id===n.id;return e!=null?e:!1},mr=()=>Vs,Fe=class ce{static autoDetectIncrementOfValueRange(t){const e=this.getDigitsInNumber(t);return t===0?.01:Math.pow(10,e-3)}static getDigitsInNumber(t){const e=i=>at(Math.log10((i^i>>31)-(i>>31)))+1;let s=e(t);return s===1&&t<1&&(s=e(t*1e9)-9),s}static getPriceIncrement(t,e=[]){if(!this.validatePriceIncrementsOrPrecisions(e))return this.DEFAULT_INCREMENT;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;const i=1e-6;for(;s<e.length&&t>e[s]+Math.min(e[s-1],e[s+1])*i;)s+=2;return s>=e.length||t<e[s]-Math.min(e[s-1],e[s+1])*i?e[s-1]:Math.min(e[s-1],e[s+1])}static getPricePrecision(t,e){if(!this.validatePriceIncrementsOrPrecisions(e))return 0;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;for(;s<e.length&&t>e[s];)s+=2;return Math.round(e[s-1])}static roundPriceToIncrement(t,e,s){const i=ce.getPriceIncrement(s||t,e);return gt.roundToNearest(t,i)}static computePrecisions(t){const e=[...t];for(let s=0;s<t.length;s+=2)e[s]=ce.calculatePrecision(t[s]);for(let s=1;s<t.length;s+=2)e[s]=t[s]+Math.min(t[s-1],t[s+1])*ce.RELATIVE_EPS;return e}static calculatePrecision(t){let e=t>1?Math.abs(Math.floor(t)-t):t;for(let s=0;s<ce.MAXIMUM_PRECISION;s++){const i=Math.floor(e+.5),r=Math.abs(e*ce.RELATIVE_EPS);if(i>=e-r&&i<=e+r)return s;e*=10}return ce.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(t){return!(t.length===0||!Array.isArray(t)||t.findIndex(e=>e!==0)===-1)}};Fe.DEFAULT_INCREMENT=.01,Fe.DEFAULT_PRECISION=2,Fe.RELATIVE_EPS=1e-8,Fe.MAXIMUM_PRECISION=10;let ve=Fe;const hh=(n,t)=>{var e;const s=(e=St(t))!=null?e:1;return Math.pow(10,-s)};var dh=Object.defineProperty,uh=Object.defineProperties,fh=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,gh=Object.prototype.hasOwnProperty,ph=Object.prototype.propertyIsEnumerable,br=(n,t,e)=>t in n?dh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,mh=(n,t)=>{for(var e in t||(t={}))gh.call(t,e)&&br(n,e,t[e]);if(vr)for(var e of vr(t))ph.call(t,e)&&br(n,e,t[e]);return n},vh=(n,t)=>uh(n,fh(t));const bh=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:n.scale.xStart,s=t?t.xEnd:n.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=n.calculateDataViewportIndexes(e,s),o=n.visualPoints.slice(i,r+1),a=Cr(o),l=()=>{var c,h;return(h=(c=n.visualPoints[i])==null?void 0:c.close)!=null?h:1};return vh(mh({},a),{low:n.view.toAxisUnits(a.low,l),high:n.view.toAxisUnits(a.high,l)})}}),Cr=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.high>t.high&&(t.high=s.high,t.highIdx=e),s.low<t.low&&(t.low=s.low,t.lowIdx=e)}return t};class Ch{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){yh(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const yh=(n,t,e,s)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=yr(i),o=s.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=n.calculateZoomY(t.yStart,t.yEnd)};function yr(n){if(n.length===0)return wh();let t=n[0].high,e=n[0].low;return n.forEach(s=>{isFinite(s.high)&&s.high>=t&&(t=s.high),isFinite(s.low)&&s.low<=e&&(e=s.low)}),{low:e,high:t}}const wh=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),wr=(n,t)=>n/t,Sh=(n,t)=>n/t,xh=(n,t)=>n*t,Sr=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=wr(e,s),r=n.yEnd-n.yStart;t.zoomY=Sh(t.zoomX,i);const o=t.zoomY/s,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},_h=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=wr(e,s),r=n.xEnd-n.xStart;t.zoomX=xh(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},Ph=(n,t)=>{const e=n.xStart;n.xStart=t,n.xEnd=n.xEnd+(t-e)},Th=(n,t)=>{const e=n.yStart;n.yStart=t,n.yEnd=n.yEnd+(t-e)},xr=(n,t,e,s,i)=>{const r=(t.xEnd-t.xStart)*s,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=n.calculateZoomX(t.xStart,t.xEnd),t},Mh=(n,t,e,s)=>xr(n,t,1,e,s),Ah=Ee,Eh=.9,Ih=(n,t,e,s)=>{t.currentAnimation&&t.currentAnimation.animationInProgress&&t.currentAnimation.getProgress()>Eh&&(t.currentAnimation.finishAnimation(),t.currentAnimation=void 0),s&&s.doAutoYScale(e),ls(n,t,e)},ls=(n,t,e)=>{const s=n.startViewportMovementAnimation(t,{duration:Ah,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},fe,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=s};var Dh=Object.defineProperty,Lh=Object.defineProperties,Oh=Object.getOwnPropertyDescriptors,_r=Object.getOwnPropertySymbols,Bh=Object.prototype.hasOwnProperty,Rh=Object.prototype.propertyIsEnumerable,Pr=(n,t,e)=>t in n?Dh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,oe=(n,t)=>{for(var e in t||(t={}))Bh.call(t,e)&&Pr(n,e,t[e]);if(_r)for(var e of _r(t))Rh.call(t,e)&&Pr(n,e,t[e]);return n},Tr=(n,t)=>Lh(n,Oh(t));const Fh=new F,Hh=new F,kh=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class Mr extends Nc{constructor(t,e,s){super(),this.config=t,this.getBounds=e,this.canvasAnimation=s,this.scaleInversedSubject=new F,this.beforeStartAnimationSubject=new F,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.autoScaleZoomSubscription=null,this.autoScalePanSubscription=null,this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=re(t.scale),this.autoScaleModel=new Ch(this),this.offsets=this.config.components.offsets,this.initAutoScaleThrottling()}doActivate(){super.doActivate(),this.scaleInversedSubject=new F,this.beforeStartAnimationSubject=new F,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){this.autoScaleZoomSubscription&&(this.autoScaleZoomSubscription.unsubscribe(),this.autoScaleZoomSubscription=null),this.autoScalePanSubscription&&(this.autoScalePanSubscription.unsubscribe(),this.autoScalePanSubscription=null),super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=oe(oe({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,s=!1,i){const r=this.config.scale.disableAnimations||s;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();xr(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){const s=this.config.scale.disableAnimations||this.config.components.yAxis.type==="percent";s&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const i=this.export();Mh(this,i,e,t),this.zoomXTo(i,t,s)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.currentAnimation=void 0,this.canvasAnimation.forceStopAnimation(fe),this.doAutoScale())}zoomXTo(t,e,s){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Sr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),s?this.apply(o):((i=this.currentAnimation)==null||i.tick(),ls(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const s=this.getBounds().width,i=.001;if(s>0){const r=os(this.config.components.chart.minCandles,s),a=t!==r&&t-r<=i&&e,l=os(s/this.config.components.chart.minWidth,s),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,s=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Tr(oe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Sr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),s||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),Ae?Ih(this.canvasAnimation,this,l,this.state.auto?this.autoScaleModel:void 0):ls(this.canvasAnimation,this,l)))}setXScaleWithoutYScale(t){var e;const s=this.export(),i=t.slice(Math.max(t.length-this.state.defaultViewportItems,0)),r=i[i.length-1],o=r.startUnit+r.width+this.offsets.right,a=o-this.getBounds().width*this.zoomX,l=Tr(oe({},s),{xStart:a,xEnd:o}),c=this.scalePostProcessor(s,l);this.state.auto&&this.autoScaleModel.doAutoYScale(c),(e=this.currentAnimation)==null||e.tick(),ls(this.canvasAnimation,this,c)}setYScale(t,e,s=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio&&this.initialViewportValidSubject.getValue()){this.setLockedYScale(t,e,s,i);return}super.setYScale(t,e,s);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,s=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,s);const o=this.export(),a=this.scalePostProcessor(i,o);_h(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),s=oe({},e);this.haltAnimation(),Ph(e,t);const i=this.scalePostProcessor(s,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Th(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Xc(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}initAutoScaleThrottling(){this.autoScaleZoomSubscription=Fh.pipe(Lt(Zt,Rt,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=oe({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)}),this.autoScalePanSubscription=Hh.pipe(Lt(Zt,Rt,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=oe({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)})}}class jh extends Mr{constructor(t,e,s,i){super(e,s,i),this.delegate=t,this.config=e,this.getBounds=s}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Yh=es().colors;class $t extends cr{constructor(t,e,s,i,r,o,a,l,c=Yh){super(t,e,s),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=kh(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new F,this.meanCandleWidth=Vs,this._instrument=o,this.instrument=o,this.highLowProvider=bh(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=ve.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.startUnit).index,i=Yt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}applyPriceMovement(){const t=St(this.dataPoints);t&&(this.lastPriceMovement=ts(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Cr(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=At(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var s,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(s=this.candleWidthByChartType[r])!=null?s:mr;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,g=(i=this.candlesTransformersByChartType[r])!=null?i:gr;o.push(g(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,s)=>e+s.width,0)/t.length:this.meanCandleWidth=Vs}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Gm(n){switch(n){case"line":case"area":return!0;default:return!1}}class Nh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=!!i.color;if(s instanceof $t){const a=mt(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=s.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:s.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=s.extentComponent.getBounds(),c=a[0],h=s.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],g=a[d],m=s.view.toX(g.centerUnit),x=s.view.toY(g.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(at(m),_),t.moveTo(at(m),x);else if(f===void 0){t.lineTo(at(m),x),t.stroke(),t.lineTo(at(m),_),t.lineTo(at(h),_),t.closePath();let A;i.color?t.fillStyle=i.color:t.fillStyle=s.colors.areaTheme.startColor&&s.colors.areaTheme.stopColor?(A=t.createLinearGradient(0,0,0,l.height),A.addColorStop(0,s.colors.areaTheme.startColor),A.addColorStop(1,s.colors.areaTheme.stopColor),A):"",o||t.fill()}else t.lineTo(m,x)}}}}function Ar(n,t,e,s,i,r=4,o=!0,a=!1){n.save(),n.beginPath(),n.moveTo(t+r,e),n.lineTo(t+s-r,e),n.quadraticCurveTo(t+s,e,t+s,e+r),n.lineTo(t+s,e+i-r),n.quadraticCurveTo(t+s,e+i,t+s-r,e+i),n.lineTo(t+r,e+i),n.quadraticCurveTo(t,e+i,t,e+i-r),n.lineTo(t,e+r),n.quadraticCurveTo(t,e,t+r,e),n.closePath(),o&&n.fill(),a&&n.stroke(),n.restore()}function Xh(n,t,e,s,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,g=c==="right"?h:-h,m=h;n.save(),n.beginPath(),l?n.moveTo(r+g,o):n.moveTo(r,o),l?(n.lineTo(r+f-g,o),n.quadraticCurveTo(r+f,o,r+f,o-m),n.lineTo(r+f,e+m),n.quadraticCurveTo(r+f,e,r+f-g,e),n.lineTo(t+g,e)):(n.lineTo(r+f,o),n.lineTo(r+f,e),n.lineTo(t,e)),l?(n.quadraticCurveTo(t,e,t-g/3,e+m/3),n.lineTo(s+g/3,i-m/3),n.quadraticCurveTo(s,i,s+g/3,i+m/3),n.lineTo(r-g/3,o-m/3),n.quadraticCurveTo(r,o,r+g/3,o)):(n.lineTo(s,i),n.lineTo(r,o)),n.closePath(),d&&n.fill(),u&&n.stroke(),n.restore()}function Wh(n,t,e,s,i,r=1,o=[]){n.save(),n.setLineDash(o),n.lineWidth=r,n.beginPath(),n.moveTo(t,e),n.lineTo(s,i),n.stroke(),n.closePath(),n.restore()}function ae(n,t){n.save(),n.lineWidth%2&&n.translate(.5,.5),t(),n.restore()}function Er(n,t,e){const s=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);n.fillRect(s,i,r,o)}const Kt=(n,t)=>{n.beginPath(),n.rect(t.x,t.y,t.width,t.height),n.clip(),n.closePath()},Zm=n=>Array.isArray(n[0])?n:[n];class zh{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,s){const i=t.ctx,r=s&&this.paneManager.panes[s];e&&(i.save(),r&&Kt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const s=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||s&&!Yc(s)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const qt=(n,t,e,s,i=t)=>{s.hoverWidth?n.lineWidth=s.hoverWidth:e.highlighted?n.lineWidth=t!==i?t+1:i:n.lineWidth=t};class Vh{constructor(t){this.config=t}setFillStyle(t,e,s,i){if(e.color)t.strokeStyle=e.color;else{const r=s.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.barLineWidth,s,i),ae(t,()=>{for(const o of r){this.setFillStyle(t,i,s,o),t.beginPath();const a=s.view.toX(o.centerUnit),l=s.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(s.view),f=Et(s.view.xPixels(o.width)/2),g=s.view.toY(o.close),m=s.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,g),t.lineTo(a+f,g),t.moveTo(l,m),t.lineTo(a,m),t.stroke()}})}}}class Uh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,s,i){if(i!==void 0&&s instanceof $t){const r=mt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(M.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],g=s.view.toX(c.centerUnit),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close),_=u?s.view.toY(u.close)<l:!1,A=x<l;if(u!==void 0&&_!==A){Ir(t,s,i,_);const L=s.view.toX(u.centerUnit),Y=s.view.toY(u.close),H=m-L,B=x-Y,j=H/B,$=x-l,W=j*$,U=L+(H-W);t.lineTo(U,l),t.stroke(),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(U,l)}u===void 0?(t.beginPath(),t.moveTo(m,x)):f===void 0?(Ir(t,s,i,A),t.lineTo(m,x),t.stroke(),t.lineTo(m,l),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(g,l),t.lineTo(m,l),t.strokeStyle=s.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(m,x)}}}}const Ir=(n,t,e,s)=>{e.color?(n.fillStyle=e.color,n.strokeStyle=e.color):(n.fillStyle=s?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,n.strokeStyle=s?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Gh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.candleLineWidth,s,i,this.config.candleLineWidth),ae(t,()=>{this.pixelLength=1/Ft,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=s.colors;a&&l&&this.drawCandle(t,i,s,o)}})}}drawCandle(t,e,s,i){const{candleTheme:r,activeCandleTheme:o}=s.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=s.view.toX(i.startUnit),d=s.view.xPixels(i.width),u=i.bodyHeight(s.view),[f,g,m,x]=i.yBodyKeyPoints(s.view),_=g===m?g+1:m,A=f===x?f+1:x,L=l[`${a}Color`],Y=a==="none"?L:l[`${a}WickColor`];t.fillStyle=L,e.color?t.strokeStyle=e.color:t.strokeStyle=Y;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.moveTo(h+1,g),t.lineTo(h+1,_),t.stroke();else if(d===3){const j=d/Ft;this.drawCandlesWicks(t,h+j,f,A,g,_),c||(t.beginPath(),t.moveTo(h+j,g),t.lineTo(h+j,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,g+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const j=i.x(s.view);this.drawCandlesWicks(t,j,f,A,g,_);const $=this.config.candlePaddingPercent,W=Math.max(d*$/2,this.pixelLength),U=h+W,G=d-W*2;if(!c){e.color&&(t.fillStyle=e.color);const V=e.hoverWidth?d+W:G,Q=e.hoverWidth?u+e.hoverWidth+W:u;t.fillRect(U,g,V,Q)}H&&this.drawCandleBorder(t,e,l,i,U+this.halfLineWidthCU,g+this.halfLineWidthCU,G-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,s,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,s),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,s,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?s[`${c}Color`]:s[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class Zh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof $t){const r=e.flat(),o=s.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=s.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(s.view),f=s.view.toY(l.close),g=Et(s.view.xPixels(l.width));t.fillRect(u,f,g,h);const m=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(m.addColorStop(0,d[`${c}Cap`]),m.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=m),g===0?(t.beginPath(),t.strokeStyle=m,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,g,a-f-h)}}}}class $h{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.lineWidth,s,i,this.config.selectedWidth);const o=s.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=s.view.toX(l.centerUnit),u=s.view.toY(l.close),f=s.view.toX(c.centerUnit),g=s.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,g),t.stroke()}}}}const Kh=1.5;class qh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=i.hoverWidth?i.hoverWidth/2:Kh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of mt(e)){t.beginPath();const l=s.view.toX(a.centerUnit),c=s.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const Jh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Qh{constructor(t,e,s){this.drawer=t,this.config=e,this.chartBounds=s}draw(t,e,s,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,s,i),this.afterDraw(t,s))}beforeDraw(t){t.restore(),t.save(),Kt(t,this.chartBounds())}isChartTypeAllowed(){return Jh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Kt(t,e.scale.getBounds())}}class td{constructor(t){this.chartModel=t}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(at(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Et(vt(h.width,u)),g=Et(h.bodyHeight(this.chartModel.scale)),m=h.xCenter(this.chartModel.scale)-f/2,x=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,A=Et(f*_/2),L=m+A,Y=f-A*2;t.fillRect(L,x,Y,g)}})})}}const ed=(n,t,e,s)=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);s===0?t.moveTo(o,a):t.lineTo(o,a)},Dr=(n,t,e)=>{n.length!==0&&n.forEach((s,i)=>{ed(s,t,e,i)})},sd=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,nd=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,id=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,rd=n=>sd.exec(n),od=n=>nd.exec(n),$m=n=>id.exec(n);function ad(n){const t=rd(n)||od(n);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(s){return parseInt(s,16)}):e}const Lr={};function ld(n,t){let e=Lr[n+t];if(!e){const s=ad(n);e=s&&"rgba("+s.join(",")+","+t+")",Lr[n+t]=e}return e}const Or="#383838";class cd{constructor(){}draw(t,e,s,i){const r=s.config.additionalVisibilityPredicatesMap,o=(r==null?void 0:r.showLine)!==void 0?r.showLine:s.config.visible,a=(r==null?void 0:r.showCloud)!==void 0?r.showCloud:s.config.visible;o&&e.forEach((l,c)=>{var h;const d=s.getPaintConfig(c);qt(t,d.lineWidth,s,i,d.hoveredLineWidth);const u=(h=i.color)!=null?h:d.color;t.strokeStyle=u,this.drawLine(t,l,s.view)}),a&&s.linkedDataSeriesModels.forEach((l,c)=>{const h=l.config.additionalVisibilityPredicatesMap,d=(h==null?void 0:h.showCloud)!==void 0?h.showCloud:l.config.visible;if(Br(l.config.type)&&Br(s.config.type)&&d){const u=s,f=u.getSeriesInViewport(u.scale.xStart-1,u.scale.xEnd+1),g=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1);f.forEach((m,x)=>{var _,A;const L=[],Y=Math.min(m.length,(A=(_=g[x])==null?void 0:_.length)!=null?A:0);for(let j=0;j<Y;j++){const $=[m[j].clone(),g[x][j].clone()];L.push({diffPoints:$})}const H=u.getPaintConfig(x).color,B=l.getPaintConfig(c).color;this.drawDifference(t,H,B,L,u,l,i,r)})}})}drawLine(t,e,s){t.beginPath(),Dr(e,t,s),t.stroke()}drawDifference(t,e,s,i,r,o,a,l){const[c,h]=[[],[]];i.forEach(x=>{const[_,A]=x.diffPoints;c.push(_),h.push(A)});const d=this.mapDataSeriesDiffPointsIntoPoints(c,r.view),u=this.mapDataSeriesDiffPointsIntoPoints(h,o.view),f=l==null?void 0:l.backgroundColor,g=f!==void 0?f:s,m=f!==void 0?f:e;this.fillCloud(t,g,d,u,a,l),this.fillCloud(t,m,u,d,a,l)}fillCloud(t,e,s,i,r,o){var a,l,c,h;t.save(),t.beginPath();const d=(l=(a=ge(s))==null?void 0:a.x)!=null?l:0,u=(h=(c=St(s))==null?void 0:c.x)!=null?h:0;t.lineTo(d,0),s.forEach(g=>{t.lineTo(g.x,g.y)}),t.lineTo(u,0),t.closePath(),t.clip(),t.beginPath(),s.forEach((g,m)=>{m===0?t.moveTo(g.x,g.y):t.lineTo(g.x,g.y)}),i.slice().reverse().forEach(g=>{t.lineTo(g.x,g.y)}),t.closePath();const f=(o==null?void 0:o.backgroundColor)!==void 0;r.color?t.fillStyle=r.color:f?t.fillStyle=e!=null?e:Or:t.fillStyle=ld(e!=null?e:Or,.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(s=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const Br=n=>n==="DIFFERENCE";class hd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0);e.forEach((o,a)=>{var l;const c=s.getPaintConfig(a);qt(t,c.lineWidth,s,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.moveTo(d,at(r)),t.lineTo(d,at(u))}),t.stroke()})}}class dd{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);qt(t,l.lineWidth,s,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,s.view)})}drawLinePath(t,e,s){t.beginPath(),Dr(e,t,s),t.stroke()}}class ud{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class fd{constructor(t){this.config=t}draw(t,e,s,i){t.save(),e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=s.getTextForPoint(h),u=Mt(d,t,c),f=Xt(c,t),g=s.view.toX(h.centerUnit)-u/2,m=s.view.toY(h.close)+f;t.fillText(d,g,m)})}),t.restore()}}class gd{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=s.view.toX(c.centerUnit),d=s.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,s,i){t.beginPath(),t.moveTo(e-i/2,s),t.lineTo(e,s-i),t.lineTo(e+i/2,s),t.fill()}}const cs="resized_local",hs="draw",Km="draw_last_candle",be={width:20,height:20};class Rr{constructor(t,e,s,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=s,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.lastDPR=0,this.type=nn;var a;i.push(this),this.parent=vd(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:s}=t,i=window.devicePixelRatio;e===this.width&&s===this.height&&i===this.lastDPR||(this.lastDPR=i,this.canvas.style.height=s+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=s*i,this.width=e,this.height=s,this.ctx.scale(i,i))}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const s=e.height;s!==this.height&&(t.style.height=s+"px",this.height=s,t.height=s,this.prevHeight=s)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>be.width&&this.height>be.height}}const nn={name:"candle"},pd={candle:nn,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function md(n,t,e,s,i,r,o){var a;const l=le(n,t,i,r,o,e);return l.type=(a=pd[s])!=null?a:nn,l}function le(n,t,e,s,i,r,o){const a=new Rr(n,t,s,i,r,o);return Fr(a,e),a}function Fr(n,t){const e=n.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",n.width=t.fixedSize.width,n.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function vd(n){let t=n;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const ds="HIT_TEST_",tv=null;class bd{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${wt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(s=>{s.indexOf(ds)!==-1&&this.drawersMap[s].draw()})},t.on(hs,s=>{e.wasResized()&&(this.canvasIdsList&&(s&&s.length!==0?this.canvasIdsList=this.canvasIdsList.concat(s):this.canvasIdsList=void 0),Qn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(ds)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(ds)===-1){const s=this.drawersMap[e];if(!t||t.length===0){s.draw();return}Il(t,s.getCanvasIds()).length&&s.draw()}})}isDrawable(){var t,e,s,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>be.width&&((i=(s=this.chartResizeHandler.previousBCR)==null?void 0:s.width)!=null?i:0)>be.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=wt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(s);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(s);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const s=this.drawingOrder.indexOf(e);s!==-1&&this.drawingOrder.splice(s,1)}})}reorderDrawers(t){this.drawingOrder=ci(this.drawingOrder,t)}}class Hr{static paneResizer(t){return`PANE_RESIZER_${t}`}}const Cd=7;class yd{constructor(t,e,s,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=s,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Kt(t,e.getBounds()),e.dataSeries.forEach(s=>this.drawSeries(t,s)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const s=e.config.type,i=this.seriesDrawers[s];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:Cd};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const kr={dragPredicate:()=>!0};class jr extends X{constructor(t,e,s,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=s,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class us extends jr{constructor(t,e,s,i,r=kr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const wd="BASELINE_RESIZER";class Sd extends X{constructor(t,e,s,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=s,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ft(!1),this.baselineYPercents=50,this.ht=Zs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(M.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&hc(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new us(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(M.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(M.CHART),e=this.canvasBoundContainer.getBounds(M.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const s=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=s,this.canvasBoundContainer.bounds[wd]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(M.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const xd=n=>{var t;try{const e=Te(n.close,n.open,n.hi,n.lo);if(!isFinite(e))throw new Error("Received candle without any price");const s=Te(n.hi,Math.max(n.open,n.close),e),i=Te(n.lo,Math.min(n.open,n.close),e),r=Te(n.open,n.lo,e),o=Te(n.close,n.hi,e),a=Number.isNaN(n.vwap)?void 0:n.vwap;return{id:n.id,hi:s,lo:i,open:r,close:o,timestamp:n.timestamp,volume:(t=n.volume)!=null?t:0,expansion:n.expansion,idx:n.idx,impVolatility:n.impVolatility,openInterest:n.openInterest,vwap:a,typicalPrice:n.typicalPrice}}catch(e){console.warn(e);return}},He=(n,t=0)=>{for(let e=t;e<n.length;++e)n[e].idx=e},Yr=n=>{n.forEach(t=>{t.idx=void 0})},_d=n=>n!==void 0;class Pd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0),o=mt(e),a=s.getPaintConfig(0);qt(t,a.lineWidth,s,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=Td(o,c),L=A&&l.close<A;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(L?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,j),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!L&&l.close<0&&(t.strokeStyle=(g=i.color)!=null?g:a.multiplyColors[1]||a.color||"#FF00FF"),L&&l.close>0&&(t.strokeStyle=(m=i.color)!=null?m:a.multiplyColors[2]||a.color||"#FF00FF"),!L&&l.close>0&&(t.strokeStyle=(x=i.color)!=null?x:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,j),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const Y=s.view.toX(l.centerUnit),H=s.view.toY(l.close);t.moveTo(Y,r),t.lineTo(Y,H),t.stroke()})}}const Td=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0},Md=(n,t)=>{let e=0;return(...s)=>{clearTimeout(e),e=+setTimeout(()=>n(...s),t)}};class Ad{constructor(){}draw(t,e,s,i){const r=mt(e),o=s.getPaintConfig(0);qt(t,o.lineWidth,s,i,o.hoveredLineWidth),t.lineCap="round",r.forEach((a,l)=>{var c,h;const d=Ed(r,l)||r[0],u=d&&a.close<d.close;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(h=i.color)!=null?h:(u?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF";const f=s.view.toX(a.centerUnit),g=s.view.toY(a.close),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close);t.beginPath(),t.moveTo(m,x),t.lineTo(f,g),t.stroke();return}})}}const Ed=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t]:void 0},Ce="#FF00FF";class Id{constructor(){}draw(t,e,s,i){const r=mt(e),o=s.getPaintConfig(0),a=i.hoverWidth?i.hoverWidth/2:o.lineWidth;r.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=Dd(r,c),L=A&&l.close<A;if(((h=o.multiplyColors)==null?void 0:h.length)===2){t.fillStyle=(d=i.color)!=null?d:(L?o.multiplyColors[1]:o.multiplyColors[0])||o.color||Ce;const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.arc(B,j,a,0,Math.PI*2),t.fill();return}if(((u=o.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.fillStyle=(f=i.color)!=null?f:o.multiplyColors[0]||o.color||Ce),!L&&l.close<0&&(t.fillStyle=(g=i.color)!=null?g:o.multiplyColors[1]||o.color||Ce),L&&l.close>0&&(t.fillStyle=(m=i.color)!=null?m:o.multiplyColors[2]||o.color||Ce),!L&&l.close>0&&(t.fillStyle=(x=i.color)!=null?x:o.multiplyColors[3]||o.color||Ce),t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.arc(B,j,a,0,Math.PI*2),t.fill();return}t.fillStyle=(_=i.color)!=null?_:o.color||Ce,t.beginPath();const Y=s.view.toX(l.centerUnit),H=s.view.toY(l.close);t.arc(Y,H,a,0,Math.PI*2),t.fill()})}}const Dd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0};var Ld=Object.defineProperty,Nr=Object.getOwnPropertySymbols,Od=Object.prototype.hasOwnProperty,Bd=Object.prototype.propertyIsEnumerable,Xr=(n,t,e)=>t in n?Ld(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Wr=(n,t)=>{for(var e in t||(t={}))Od.call(t,e)&&Xr(n,e,t[e]);if(Nr)for(var e of Nr(t))Bd.call(t,e)&&Xr(n,e,t[e]);return n};class Rd{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class Fd extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.chartModel=t,this.canvasModel=e,this.config=s,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=g,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ft(!0),this.strToBarType=x=>{var _;return(_=this.barTypeValues.find(A=>A===x))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Sd(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const m=new yd(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(m,ds+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new oh(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(M.PANE_UUID(K),s.components.chart.cursor),this.dataSeriesDrawer=new zh(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(Md(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Zt))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",gr),this.registerCandlesTransformer("trend",pr),this.registerCandlesTransformer("hollow",lh),this.registerCandlesTransformer("line",ch)}get barTypeValues(){return Qi(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Gh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Vh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new $h(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new qh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Nh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new Uh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new Zh(this.config.components.chart.histogram));const e=M.PANE_UUID(K),s=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new dd),this.registerDataSeriesTypeDrawer("LINEAR_TREND",new Ad),this.registerDataSeriesTypeDrawer("HISTOGRAM",new hd),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Pd),this.registerDataSeriesTypeDrawer("POINTS",new ud),this.registerDataSeriesTypeDrawer("TREND_POINTS",new Id),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Qh(new td(this.chartModel),this.config,s)),this.registerDataSeriesTypeDrawer("TEXT",new fd(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new gd),this.registerDataSeriesTypeDrawer("DIFFERENCE",new cd)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(Wr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,s=!0){return this.chartModel.setTimestampRange(t,e,s)}setXScale(t,e,s=!0){return this.scale.setXScale(t,e,s)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=Wr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=s,this.chartModel.setAllSeries({candles:t.candles,instrument:s},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Yr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(s)}setSecondarySeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,s);if(this.updatePriceIncrementsIfNeeded(s),i)return i}setAllSeries(t,e=[]){var s;const i=(s=t.instrument)!=null?s:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,s=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,s)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!ve.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[ve.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}function zr(n,t){return t===void 0&&(t=is),N(function(e,s){var i=null,r=null,o=null,a=function(){if(i){i.unsubscribe(),i=null;var c=r;r=null,s.next(c)}};function l(){var c=o+n,h=t.now();if(h<c){i=this.schedule(void 0,c-h),s.add(i);return}a()}e.subscribe(Ct(s,function(c){r=c,o=t.now(),i||(i=t.schedule(l,n),s.add(i))},function(){a(),s.complete()},void 0,function(){r=i=null}))})}class Vr extends $t{constructor(t,e,s,i,r,o,a,l,c,h){super(e,s,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var Hd=Object.defineProperty,Ur=Object.getOwnPropertySymbols,kd=Object.prototype.hasOwnProperty,jd=Object.prototype.propertyIsEnumerable,Gr=(n,t,e)=>t in n?Hd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Yd=(n,t)=>{for(var e in t||(t={}))kd.call(t,e)&&Gr(n,e,t[e]);if(Ur)for(var e of Ur(t))jd.call(t,e)&&Gr(n,e,t[e]);return n};const Nd=(n,t,e,s)=>{var i,r,o,a;const l=Yd({},n),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Bl(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=n.xStart,u=n.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Ht(s.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Xd=n=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const s=t.slice(Math.max(t.length-n.state.defaultViewportItems,0)),i=s[0],r=s[s.length-1];n.setXScale(i.startUnit,r.startUnit+r.width+n.offsets.right)}e.yScale&&n.doAutoScale(!0),n.fireChanged()}},Wd=(n,t)=>(e,s=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=s===null?0:t.mainCandleSeries.meanCandleWidth*2,c=s?o-l:o+l,h=s?a+l:a-l;n.setXScale(c,h)};var zd=Object.defineProperty,Vd=Object.defineProperties,Ud=Object.getOwnPropertyDescriptors,Zr=Object.getOwnPropertySymbols,Gd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,$r=(n,t,e)=>t in n?zd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ke=(n,t)=>{for(var e in t||(t={}))Gd.call(t,e)&&$r(n,e,t[e]);if(Zr)for(var e of Zr(t))Zd.call(t,e)&&$r(n,e,t[e]);return n},rn=(n,t)=>Vd(n,Ud(t));class $d{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,s)=>rn(ke({},e),{[s]:0}),{})}createColorPool(t){return t.reduce((e,s,i)=>(e[`color${i}`]=rn(ke({},re(this.config.colors)),{lineTheme:ke({},s.lineTheme),areaTheme:ke({},s.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,s="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,s=i);return this.usedChartColors[s]=this.usedChartColors[s]+1,this.symbolsToColorKeys[t]=s,this.secondaryChartColorsPool[s]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var s,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=rn(ke({},e),{lineTheme:Object.assign(r.lineTheme,(s=o.lineTheme)!=null?s:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Kd=Object.defineProperty,Kr=Object.getOwnPropertySymbols,qd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,qr=(n,t,e)=>t in n?Kd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,fs=(n,t)=>{for(var e in t||(t={}))qd.call(t,e)&&qr(n,e,t[e]);if(Kr)for(var e of Kr(t))Jd.call(t,e)&&qr(n,e,t[e]);return n};class Qd extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=s,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new F,this.mainInstrumentChangedSubject=new F,this.offsetsChanged=new F,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(xd).filter(_d),{sortCandles:g}=this.config.components.chart;return g?g(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new $d(this.config);const d=new Vr(this.chartBaseModel,this.paneManager.panes[K].mainExtent,wt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Rd,this.candlesTransformersByChartType,this.candleWidthByChartType,fs({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Nd(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Xd(o),this.timeFrameViewportTransformer=Wd(o,this),this.pane=this.paneManager.panes[K]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(K)).pipe(Tt(Yi)).subscribe(t=>{this.handleChartResize(t)})),this.addRxSubscription(this.scale.changed.pipe(zr(Zt)).subscribe(()=>this.paneManager.yExtents.forEach(t=>t.yAxis.updateOrderedLabels(!0))))}handleChartResize(t){if(t.width>be.width&&t.height>be.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),s=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=s;return}if(s!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Ht(s-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=s,this.prevChartWidth=e;return}const i=Ht(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=s,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(s=>{const i=s.dataPoints;return Yr(i),{candles:i,instrument:s.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,s=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,s&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var s;this.mainCandleSeries.instrument=(s=t.instrument)!=null?s:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),He(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doBasicXScale(){this.scale.setXScaleWithoutYScale(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=fs({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const s=[t,...e];if(!this.candleSeries.every(l=>s.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Qr(this.mainCandleSeries.dataPoints,i),o=r.candles;He(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),g=Qr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(g,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candleSeries.forEach(l=>{l.recalculateDataViewportIndexes()}),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(s=>{const i=Yt(s.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;s.dataPoints=s.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=fs(fs({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const s=new $t(this.paneManager.panes[K].mainExtent,wt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return s.config.type="line",this.candleSeries.push(s),s}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[K].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const s=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)s.push(a);else{let l=Jr(e,o,-1);if(l||(l=Jr(e,o,1)),l){const c=Gl(l,o,!0);s.push(c)}}}),s}updateSecondaryCandleSeriesConfig(t,e,s){const i=At(t,es().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=s,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),s=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=s.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,s=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,s)}candleFromUnit(t,e=!1,s=this.mainCandleSeries){var i,r;const o=Yt(s.visualPoints,t,d=>d.startUnit),a=s.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Me((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Re(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Re(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},s=this.mainCandleSeries){const i=s.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(s=>s.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(s=>s.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,s,i;const r=t-((i=(s=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:s.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,s=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,s)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return St(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return St(t)}getMaxCandlesFitLength(){return at(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((s,i)=>{const r=i.timestamp,o=Oe(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,s[o.index]=i),s},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}isLastCandleInViewport(){const t=this.getLastCandle();return t&&t.idx?this.isCandleInViewport(t.idx):!1}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const s=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Oe(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const g=f>=o.length-1,m=c&&h.timestamp<c.timestamp;if(g&&!m&&(c=h),a&&c&&s&&l){const x=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:mr;this.scale.moveXStart(this.scale.xStart+x(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return yt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=this.getCandles(),e=0,s){const i=this.getCandlesCount(),r=s!=null?s:i+this.FAKE_CANDLES_DEFAULT;t=t.slice(Math.max(0,e),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Re(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=e;c<l;c++)a.push(Re(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...t,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const s=t.slice(),i=[];return e.forEach(r=>{const a=Oe(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?s[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...s]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const s=this.findSeriesBySymbol(e);if(s.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}s.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),He(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const s=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(s<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,s).concat(e.dataPoints.slice(i+1)),He(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(s=>this.removeCandleByIdx(this.candleIdxFromId(s,e)))}addCandlesById(t,e,s){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=s.dataPoints.slice(0,i),o=s.dataPoints.slice(i);s.dataPoints=r.concat(t).concat(o),He(s.dataPoints),s.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Jr=(n,t,e)=>{if(t>=n.length)return n[n.length-1];for(let s=t;s<n.length&&s>=0;s+=e){const i=n[s];if(i)return i}},Qr=(n,t)=>{const e=n.slice(),s=[],i=[];return t.forEach(r=>{const a=Oe(r.timestamp,{extrapolate:!0},n).index;a<0?s.push(r):a>=n.length?i.push(r):n[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:s,appended:i,candles:[...s,...e,...i]}};class ye{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class on{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const s=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(s,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Ji(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=Ji(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=mt(Array.from(this.drawers).map(([,s])=>s.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class tu{constructor(t,e,s,i){this.model=t,this.config=e,this.crossToolCanvasModel=s,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var eu=Object.defineProperty,su=Object.defineProperties,nu=Object.getOwnPropertyDescriptors,to=Object.getOwnPropertySymbols,iu=Object.prototype.hasOwnProperty,ru=Object.prototype.propertyIsEnumerable,eo=(n,t,e)=>t in n?eu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ou=(n,t)=>{for(var e in t||(t={}))iu.call(t,e)&&eo(n,e,t[e]);if(to)for(var e of to(t))ru.call(t,e)&&eo(n,e,t[e]);return n},au=(n,t)=>su(n,nu(t));class lu extends X{constructor(t,e,s,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=s,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.chartModel=a,this.currentHoverSubject=new ft(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?Nt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(Nt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,K]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget,s=this.config.discrete){var i;const r=s?this.chartModel.toX((i=this.chartModel.candleFromX(t.x,!0).idx)!=null?i:0):t.x;if(this.currentHover===null?this.currentHover={x:r,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=r,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===K)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:s,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(M.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=s.x+l,d=s.y+c,u=o.y+a,f=o.y+o.height-a,g=h<a?a:h>o.width-a?o.width-a:h,m=d<u?u:d>f?f:d,x=(e=this.hoverProducer.createHover(g,m,t.paneId))!=null?e:t,_=au(ou({},x),{x:g,y:m});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const Ot=4;function cu(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g;const m=r.align,x=(l=i.textFont)!=null?l:ne(r),_=i.bgColor,A=(c=i.textColor)!=null?c:se(_,o.labelTextColor,o.labelInvertedTextColor),L=(h=i.paddingTop)!=null?h:Ot,Y=(d=i.paddingBottom)!=null?d:Ot,H=(u=i.paddingEnd)!=null?u:Ot,B=Me(Xt(x,n)/2),j=s-B-L,W=s+B+Y-j;if(a&&!gs(s,t,W))return;n.save(),n.fillStyle=_,n.strokeStyle=_;const U=Me(t.width/6),G=m==="right"?t.x:t.x+t.width,V=m==="right"?G+U:G-U,Q=r.labelBoxMargin.end,J=Q-H,et=t.width-U-J;Xh(n,V,j,G,j+Me(W/2),V,j+W,et,(g=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?g:!1,m),n.fillStyle=A,n.font=x;const tt=m==="right"?t.x+t.width-Mt(e,n,x)-Q:t.x+Q;n.fillText(e,tt,s+B-1),n.restore()}function hu(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x,_,A;const L=r.align,Y=(l=i.textFont)!=null?l:ne(r),H=i.bgColor,B=(c=i.textColor)!=null?c:se(H,o.labelTextColor,o.labelInvertedTextColor),j=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,$=(u=(d=i.paddingTop)!=null?d:j==null?void 0:j.top)!=null?u:Ot,W=(g=(f=i.paddingBottom)!=null?f:j==null?void 0:j.bottom)!=null?g:Ot,U=(x=(m=i.paddingEnd)!=null?m:j==null?void 0:j.end)!=null?x:Ot,G=i.paddingStart,V=Xt(Y,n),Q=s-V/2-$,et=s+V/2+W-Q,tt=(A=i.rounded)!=null?A:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!gs(s,t,et))return;n.save(),n.fillStyle=H,n.strokeStyle=H;const st=r.labelBoxMargin.end;n.font=Y;const ut=Mt(e,n,Y),lt=st-U,xt=G!==void 0?ut+G+U:t.width-lt,Gt=L==="right"?t.x+t.width-lt-xt:t.x+lt,xe=L==="right"?t.x+t.width-ut-st:st;tt?Ar(n,Gt,Q,xt,et,4,!0):n.fillRect(Gt,Q,xt,et),n.fillStyle=B,n.fillText(e,xe,s+V/2-1),n.restore()}function du(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x;const _=r.align,A=(l=i.textFont)!=null?l:ne(r),L=o.backgroundColor,Y=(c=i.textColor)!=null?c:se(L,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Ot,j=(g=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?g:Ot,$=(x=(m=i.paddingEnd)!=null?m:H==null?void 0:H.end)!=null?x:Ot,W=i.paddingStart,U=Xt(A,n),G=s-U/2-B,Q=s+U/2+j-G;if(a&&!gs(s,t,Q))return;n.save(),n.fillStyle=L,n.strokeStyle=L;const J=r.labelBoxMargin.end;n.font=A;const et=Mt(e,n,A),tt=J-$,st=W!==void 0?et+W+$:t.width-tt,ut=_==="right"?t.x+t.width-tt-st:t.x+tt,lt=_==="right"?t.x+t.width-et-J:J;n.fillStyle=L,n.strokeStyle=L,n.fillRect(ut,G,st,Q),n.fillStyle=Y,n.fillText(e,lt,s+U/2-1),n.restore()}function uu(n,t,e=Ot){return Xt(n,t)/2+e}function gs(n,t,e){return!(n<t.y+e/2||n>t.y+t.height-e/2)}const fu="badge",so=4,no={badge:cu,rectangle:hu,plain:du};function io(n,t,e,s,i,r,o,a,l){var c,h,d,u,f;const g=r.y,m=r.labelText,x=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:fu,A=r.description,L=(d=r.textFont)!=null?d:ne(a),Y=r.bgColor,H=(u=r.lineColor)!=null?u:Y,B=Mt(A!=null?A:"",n,L)+8,j=at(r.y),$=Xt(L,n),W=g-$/2,G=g+$/2-W;n.save(),n.fillStyle=Y,n.strokeStyle=H;const V=o.getBounds(M.PANE_UUID(K)),Q=no[_],J=a.labels.descriptions,et=gu(s,j,G),tt=()=>J&&pu(e,t,s,i,r,a);let st,ut;const lt=2;a.align==="right"?(st=V.x,ut=J?V.x+V.width-B:V.x+V.width+lt):(st=J?V.x+B:V.x-lt,ut=V.x+V.width);const xt=(f=r.lineY)!=null?f:r.y,Gt=()=>et&&ae(n,()=>Wh(n,st,xt,ut,xt,1,r.lineDash)),xe=()=>Q(n,s,Je(m),g,r,a,l.yAxis,!1),xs={line:()=>{Gt(),tt()},"line-label":()=>{Gt(),xe(),tt()},label:()=>{tt(),xe()}};x!=="none"&&gs(g,s,G)&&xs[x](),n.restore()}const gu=(n,t,e)=>t>n.y+e/2&&t<n.y+n.height-e/2;function pu(n,t,e,s,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=ne(r),f=Mt(h,t,u),g=Xt(u,t),m=(o=i.paddingTop)!=null?o:so,x=(a=i.paddingBottom)!=null?a:so,_=d-g/2-m,L=d+g/2+x-_;t.save();const Y=f+5,H=4,B=f+H*2,j=s.x+s.width,$=c==="right"?j-B:s.x+H;ah(n,t,$,_,Y,L,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const W=c==="right"?j-f-H*2:s.x+H*2;t.fillText(h,W,d+g/2-1),t.restore()}class ro{constructor(t,e,s,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=s,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&ae(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var s,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(M.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES,{extensionY:1e-4}),h=(s=this.config.components.xAxis.padding.top)!=null?s:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const g={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},m={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},x=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),x&&(t.moveTo(...g.start),t.lineTo(...g.end)),t.moveTo(...m.start),t.lineTo(...m.end),t.stroke()),x&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var s,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,g=this.config.components.xAxis.fontSize,m=this.canvasBoundsContainer.getBounds(M.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const x=(s=l==null?void 0:l.left)!=null?s:0,_=(i=l==null?void 0:l.right)!=null?i:0,A=(r=l==null?void 0:l.top)!=null?r:0,L=(o=l==null?void 0:l.bottom)!=null?o:0,Y=(a=c==null?void 0:c.top)!=null?a:0,H=f+x+_,B=g+A+L,j=Math.max(d-H/2,0),$=m.y+Y+De/2;Ar(t,j,$,H,B),t.fillStyle=h.labelTextColor;const W=Math.max(d-f/2,x),U=m.y+Y+g+De/2+A-1;t.fillText(u,W,U),t.restore()}}drawYLabel(t,e){const s=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=no[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:s==null?void 0:s.bottom,paddingEnd:s==null?void 0:s.end,paddingTop:s==null?void 0:s.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class mu{draw(){}}class vu extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=s,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.chartModel=c,this.crossToolTypeDrawers={},this.model=new lu(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel,this.chartModel),this.addChildEntity(this.model);const h=new ye(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const d=new tu(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),u=new on;u.addDrawer(h,"CLEAR_CANVAS"),u.addDrawer(d,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(u,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new ro(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new ro(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new mu)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class bu{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,s])=>{for(const i of s){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class zt{constructor(t){this.data=t,this.next=null}}class Cu{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new zt(t);if(this.head===null)this._head=e;else{let s=this.head;for(;s.next;)s=s.next;s.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const s=new zt(e);if(t===0)s.next=this.head,this._head=s;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;s.next=i,r.next=s,t===this.length-1&&(this._tail=s)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,s=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,s=e,e=e.next;s.next=e.next,t===this.length-1&&(this._tail=s)}this.length--}getNodePosition(t){let e=0,s=this.head;for(;s;){if(s.data===t.data)return e;s=s.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class yu extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ft({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const s=e.paneId,r=this.objects[s];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[s,i]=e,r=new zt(s);return i.getNodePosition(r)}addObject(t){var e,s;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new Cu;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((s=t.parentId)!=null?s:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new zt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[s]=e;this.removeObject(s.id),this.addObject(t)}moveToPosition(t,e){const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new zt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(s),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,s),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,s),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,s),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class wu extends X{constructor(t,e){super();const s=new yu(t);this.model=s,this.addChildEntity(s);const i=new bu(s,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Su=()=>n=>n.toString(),xu=(n,t)=>{var e;const s="date.get"+(t((e=n.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return s+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:_u(n),shortMonths:Pu(n),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=n.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Tu(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function _u(n){var t;return(t=n.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Pu(n){var t;return(t=n.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const oo=(n,t,e)=>{if(n){if(typeof n=="string")return e(n);if(Array.isArray(n)){const s=n.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(s.length>0){const i=s[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Su()},Tu=(n,t,e,s)=>{t||(t="M/d/yyyy");const i=n.getDate(),r=n.getMonth(),o=n.getFullYear(),a=n.getHours(),l=n.getMinutes(),c=n.getSeconds(),h=n.getMilliseconds(),d=a%12,u=we(d),f=we(a),g=we(l),m=we(c),x=a<12?"AM":"PM",_=e[n.getDay()],A=_.substring(0,3),L=we(i),Y=r+1,H=we(Y),B=s[r],j=B.substring(0,3),$=o+"",W=$.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",g+"").replace("m",l+"").replace("ss",m+"").replace("s",c+"").replace("S",h+"").replace("dd",L+"").replace("d",i+"").replace("EEEE",_).replace("EEE",A).replace("YYYY",$).replace("yyyy",$).replace("YY",W).replace("yy",W).replace("aaa",x),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",j):t=t.replace("MM",H+"").replace("M",Y+""),t},we=n=>typeof n=="number"&&n<10?"0"+n:n,je=(n,t)=>`${n}_${t}`,Mu=(n,t)=>{if(t){const e=ao(t.normal),s=ao(t.hover);return{type:n,normal:e,hover:s}}},ao=n=>{var t;const s=new DOMParser().parseFromString(n,"text/html").querySelector("svg");let i=0;s&&(i=parseInt((t=s.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(n),l=new Image;return l.src=a,{img:l,svgHeight:i}},Au=(n,t,e,s,i)=>{if(i){const r=t[je(s,"hover")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[je(s,"normal")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Eu={"rhombus-small":4,rhombus:6,"rhombus-large":8},Iu=["earnings","dividends","splits","conference-calls"];class Du{constructor(t,e,s,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&Iu.forEach(l=>{const c=Mu(l,a[l]);c&&(this.customIcons[je(c.type,"normal")]=c.normal,this.customIcons[je(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(M.EVENTS),e=this.canvasBoundsContainer.getBounds(M.ALL_PANES),s=this.canvasModel.ctx;s.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(s.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[je(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Au(s,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(s,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);s.lineWidth=u!=null?u:1,s.beginPath(),s.setLineDash(f!=null?f:[]),s.moveTo(c,e.y),s.lineTo(c,t.y+t.height/2),s.stroke(),s.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),s.restore()}drawDefaultEvent(t,e,s,i,r){var o,a,l;const c=s.y+s.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=an(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var s;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(M.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(s=this.config.components.xAxis.padding.top)!=null?s:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function an(n){return Eu[n.style]}const ps=5;class Lu{constructor(t,e,s,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(M.EVENTS);t.save(),this.model.events.forEach((s,i)=>{if(!this.config.components.events.eventsVisibility[s.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(s.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[s.type].color;t.strokeStyle=c,t.fillStyle=c;const h=an(s);t.fillStyle=this.hitTestCanvasModel.idToColor(s.id);const d=(h+ps)*2;if(a!==void 0){const u=an(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const m=h*2+ps;t.fillRect(a+u,e.y,m,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Ou=Object.defineProperty,lo=Object.getOwnPropertySymbols,Bu=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,co=(n,t,e)=>t in n?Ou(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Fu=(n,t)=>{for(var e in t||(t={}))Bu.call(t,e)&&co(n,e,t[e]);if(lo)for(var e of lo(t))Ru.call(t,e)&&co(n,e,t[e]);return n};const ho=317,ln={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class Hu extends Rr{constructor(t,e,s,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=s,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new F,this.touchStartSubject=new F,this.dblClickSubject=new F,this.rightClickSubject=new F,this.hitTestDrawersPredicateSubject=new ft(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,Fr(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Lt(100,Rt,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),s=this.canvasInputListener.observeTouchStart().pipe(dt(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=yt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(dt(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=yt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(dt(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(dt(()=>Fu({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,s,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*ho).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/ho}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const s=window.devicePixelRatio;return this.prevAnimationFrameId!==Hs&&(this.curImgData=this.ctx.getImageData(t*s,e*s,1,1).data,this.prevAnimationFrameId=Hs),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),s=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(s),[r]=cn(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(s)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const s=this.getPixel(t.x,t.y),i=this.colorToId(s[0]*65536+s[1]*256+s[2]),r=Number(i),[o]=cn(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var s,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,g]=cn(this.hitTestSubscribers,u),m=f==null?void 0:f.lookup(d),x={point:t,model:m};switch(e){case"mousedown":m&&((s=f==null?void 0:f.onMouseDown)==null||s.call(f,m,t)),g.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":m&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,m,t)),g.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":m&&((r=f==null?void 0:f.onHover)==null||r.call(f,m,t)),g.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(x);break;case"touchstart":m&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,m,t)),g.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(x);break;case"dblclick":m&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,m,t)),this.dblClickSubject.next(x);break;case"contextmenu":m&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,m,t)),this.rightClickSubject.next(x);break;case"zoom":m&&((c=f==null?void 0:f.onZoom)==null||c.call(f,m,t)),g.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const cn=(n,t)=>{let e;const s=[];return n.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:s.push(i)}),[e,s]};var ku=Object.defineProperty,ju=Object.defineProperties,Yu=Object.getOwnPropertyDescriptors,uo=Object.getOwnPropertySymbols,Nu=Object.prototype.hasOwnProperty,Xu=Object.prototype.propertyIsEnumerable,fo=(n,t,e)=>t in n?ku(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Wu=(n,t)=>{for(var e in t||(t={}))Nu.call(t,e)&&fo(n,e,t[e]);if(uo)for(var e of uo(t))Xu.call(t,e)&&fo(n,e,t[e]);return n},zu=(n,t)=>ju(n,Yu(t));class Vu extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ft(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((s,i)=>zu(Wu({},s),{id:i+e})).sort((s,i)=>s.timestamp-i.timestamp)}getIdRange(){return ln.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Uu extends X{constructor(t,e,s,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>oo(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Vu(e);this.eventsModel=c,this.addChildEntity(c),s.addSubscriber(c);const h=new Du(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Lu(s,i,t,r,c,()=>s.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(M.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){At(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class Gu{constructor(t,e,s,i,r,o,a,l,c=()=>!0,h,d,u){this.canvasModel=t,this.viewportModel=e,this.config=s,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.extentIdx=h,this.getBaseline=d,this.mainExtentIdx=u}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;ae(t,()=>this.drawVertical(t)),ae(t,()=>this.drawHorizontal(t)),ae(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.extentIdx===0&&this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const s=this.xBoundsProvider(),i=at(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(s.x,i),t.lineTo(s.x+s.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.xBoundsProvider(),i=s.x+s.width;for(const r of e){const o=Et(this.viewportModel.toX(r.value));o>s.x&&o<i&&(t.beginPath(),t.moveTo(o,s.y),t.lineTo(o,s.y+s.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length>0&&this.config.components.grid.horizontal&&this.extentIdx===this.mainExtentIdx){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.yBoundsProvider();for(const i of e){const r=at(this.viewportModel.toY(i.value)),o=uu(i.text,t,Ot);r>s.y+o&&r<s.y+s.height-o&&(t.beginPath(),t.moveTo(s.x,r),t.lineTo(s.x+s.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class go extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new Gu(t,e,s,i,a,l,c,h,f,d,u,g)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class Zu{constructor(t,e,s,i){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:s,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+s,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,s,i){const r=this.getMarkerY(t,s,i==="low"),o=Qe(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(s,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Kt(t,h)}getMarkerText(t,e){const s=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${s}`}getMarkerY(t,e,s=!1){const i=this.chartModel.toY(e);if(s){const r=Qe(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(M.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,s){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(M.CHART),o=4,a=t.measureText(s).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class $u extends X{constructor(t,e,s,i,r){super();const o=new Zu(e,s,t,i);r.addDrawer(o,"HIGH_LOW")}}const Ku=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],qu=1440*60*1e3;class Ju extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new F}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+qu;kl(this.highlights,t,e,Qu).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,s)=>e.to-s.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const Qu=n=>n.to,Jt=[20,10];class tf{constructor(t,e,s,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,s,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(M.ALL_PANES);o.save(),Kt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(s=this.config.components.highlights.fontSize)!=null?s:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",g=`${u}px ${f}, monospace`;o.font=g,o.lineWidth=h,o.setLineDash(d),Ku.forEach(m=>{var x,_;const A=a[m];if(A){const L=this.config.colors.highlights[m],Y=(x=L==null?void 0:L.border)!=null?x:"#ffffff",H=(_=L==null?void 0:L.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=Y,A.forEach(B=>{var j,$,W;const U=this.chartModel.candleFromTimestamp(B.from),G=vt(U.width,this.chartModel.scale.zoomX),V=U.xStart(this.chartModel.scale),Q=B.to-this.chartModel.chartBaseModel.period,J=this.chartModel.candleFromTimestamp(Q),et=vt(J.width,this.chartModel.scale.zoomX),tt=J.xStart(this.chartModel.scale)+et;if(B.border&&this.drawBorders(B.border,o,V+G,tt-et,c),o.fillRect(V,c.y,tt-V,c.y+c.height),B.label){const st=(j=B.label.text)!=null?j:"",ut=this.config.colors.highlights[B.type];o.save(),o.fillStyle=($=ut==null?void 0:ut.label)!=null?$:"#ffffff";const lt=Mt(st,o,g),[xt,Gt]=this.resolveHighlightLabelPosition((W=B.label.placement)!=null?W:"left-left",c,[V,tt],lt);o.fillText(st,xt,Gt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,s,i){const[r,o]=s;switch(t){case"right-left":return[o-Jt[1]-i,e.y+Jt[0]];case"left-left":return[r-Jt[1]-i,e.y+Jt[0]];case"right-right":return[o+Jt[1],e.y+Jt[0]];default:return[r+Jt[1],e.y+Jt[0]]}}drawBorders(t,e,s,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(s,r.y),e.lineTo(s,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const ef="HIGHLIGHTS_PLUGIN";class sf extends X{constructor(t,e,s,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new Ju(s),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new tf(this.highlightsModel,s,i,r,e),o.addDrawer(this.highLightsDrawer,ef)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function nf(){return N(function(n,t){var e,s=!1;n.subscribe(Ct(t,function(i){var r=e;e=i,s&&t.next([r,i]),s=!0}))})}function Z(n,t){return N(function(e,s){var i=0;e.subscribe(Ct(s,function(r){return n.call(t,r,i++)&&s.next(r)}))})}var rf=Object.defineProperty,of=Object.defineProperties,af=Object.getOwnPropertyDescriptors,po=Object.getOwnPropertySymbols,lf=Object.prototype.hasOwnProperty,cf=Object.prototype.propertyIsEnumerable,mo=(n,t,e)=>t in n?rf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,vo=(n,t)=>{for(var e in t||(t={}))lf.call(t,e)&&mo(n,e,t[e]);if(po)for(var e of po(t))cf.call(t,e)&&mo(n,e,t[e]);return n},bo=(n,t)=>of(n,af(t));const Vt=4;class hf{constructor(t,e,s,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(M.N_MAP),s=this.canvasBoundsContainer.getBounds(M.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(M.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(M.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(M.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(M.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),s.width!==0&&this.drawLeftArrowButton(c,s,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,s,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,s,i){t.x<=s.x+s.width&&(t.x=s.x+s.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,s,i,r){this.blockDrawSliderOnLeftArrow(e,s,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,s,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Vt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Vt,r+Vt),t.lineTo(i+Vt,r-Vt),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Vt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Vt),t.lineTo(i,r+Vt),t.lineTo(i+Vt,r),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,s,i){const r=s.components.navigationMap.knots.border;t.fillStyle=s.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=s.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=s.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=s.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=mt(this.chartModel.mainCandleSeries.getSeriesInViewport()),s=this.config.components.navigationMap.timeLabels,i=s.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(M.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(M.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:s.fontFamily,textSize:`${s.fontSize}px`},d={dateFormat:s.dateFormat,padding:s.padding,textProperties:bo(vo({},h),{textAlign:"left"})},u={dateFormat:s.dateFormat,padding:s.padding,textProperties:bo(vo({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,s,i){const r=i.padding,o=Ci(s,i.dateFormat,this.formatterFactory);gi(t,i.textProperties);const a=Qe(t),l=mi(o);Yl(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ye extends jr{constructor(t,e,s,i,r=kr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const Co=4;class df extends X{constructor(t,e,s,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=s,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-g.x-Co},this.leftKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-g.x+Co},this.rightKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:g}=f,m=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),x=this.chartModel.mainCandleSeries.meanCandleWidth/(m.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-g)*x;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=g};const a=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_KNOT_R),c=new Ye(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Ye(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_SLIDER_WINDOW),u=new Ye(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const s=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=s.dataIdxStart/(s.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=s.dataIdxEnd/(s.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class uf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=s,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new hf(i,e,s,o,l,()=>this.visualCandles);a.addDrawer(d,M.N_MAP_CHART),this.navigationMapMoveHandler=new df(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(M.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(M.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(M.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(M.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(M.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(M.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(M.N_MAP),this.chartModel.scale.xChanged.pipe(nf(),Z(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const s=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-s,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),h=c.width,d=[];let u=0,f,g;for(f=0;f<h;f++)g=at(f*o/h)-r,g in e?(d[f]=e[g].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((m,x)=>[x+c.x,(a+l-m)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(cs),this.canvasModel.fireDraw())}}const ms=()=>{const n=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(s=>navigator.userAgent.match(s));return n?"apple":e?"mobile":"other"},ev=(n,t)=>n==="apple"||n==="mobile"?3:t;var hn=Math.pow;class yo extends X{constructor(t,e,s,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=Zt,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const m=this.canvasBoundsContainer.getBounds(M.CANVAS).width,_=d.offsetX/m;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(fe),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Ht(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),h=new Ye(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Lt(this.wheelThrottleTime,Rt,{trailing:!0,leading:!0})).subscribe(e=>{const s=ms(),i=s==="apple"||s==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Ht(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return yl(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let s=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(fe),this.currentPoint={x:0,y:0},s=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)ff(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Ht(t.state.inverse?-c:c,t.zoomY);t.moveYStart(s+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new us(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const ff=(n,t)=>{if(!t.enabled)return!1;const e=Math.abs(n.y),s=hn(hn(Math.abs(n.x),2)+hn(e,2),.5),i=Math.abs(Math.acos(e/s));return e>t.yDiff&&i<t.edgeAngle},gf=2;class pf extends X{constructor(t,e,s,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=s,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:s}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:s}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:s}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=wo(e,i.x,s,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),s=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];s[r]=a.pageX-e.left-i}return s}pinchHandler(t,e){const s=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=s+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;s>=i||e[0]===e[1]||this.scale.setXScale(s,i)}}const wo=(n,t,e,s,i=gf)=>Math.sqrt(Math.pow(n-t,2)+Math.pow(e-s,2))>i,sv={MAX_DIMENSION:2048,MAX_TOTAL_PIXELS:18e5,ZOOM_OPTIMIZED_PIXELS:12e5},mf=2e6,vf=24,bf=20,Cf=16,yf=10,wf=1e3,nv=5e4,iv={MIN:60,LOW:80,MEDIUM:100,HIGH:120,MAX:150};class Sf extends yo{constructor(t,e,s,i,r,o,a,l){super(t,e,s,i,r,o,a,l),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=Zt,this.wheelSubscription=null,this.initFrameId=null,this.isActivated=!1,this.lastWheelTime=0,this.wheelCount=0,this.consecutiveLowWheelEvents=0,this.chartPanningOptions={horizontal:!0,vertical:!0}}doActivate(){this.isActivated||(this.isActivated=!0,super.doActivate(),this.canvasInputListener.initializeRectCache(),this.createWheelSubscription(),this.initFrameId=requestAnimationFrame(()=>{this.bus.fireDraw()}),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:t})=>{this.lastXStart+=t})),this.addRxSubscription(this.bus.observe(cs).pipe(zr(100)).subscribe(()=>{this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation()})))}createWheelSubscription(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null);const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),e=this.canvasBoundsContainer.getBounds(M.CANVAS),s=e.width*e.height;s>0?s>mf?this.wheelThrottleTime=vf:this.wheelThrottleTime=bf:this.wheelThrottleTime=Cf,this.wheelSubscription=this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Z(i=>ms()==="apple"?Math.abs(i.deltaY)>1||Math.abs(i.deltaX)>1:!0),Lt(this.wheelThrottleTime,Rt,{trailing:!0,leading:!0})).subscribe(i=>{const r=performance.now();this.lastWheelTime||(this.lastWheelTime=r,this.wheelCount=0),this.wheelCount++,r-this.lastWheelTime>wf&&(Math.round(this.wheelCount*1e3/(r-this.lastWheelTime))<yf?(this.consecutiveLowWheelEvents++,this.consecutiveLowWheelEvents>=1&&(this.triggerPerformanceCleanup(),this.consecutiveLowWheelEvents=0)):this.consecutiveLowWheelEvents=0,this.lastWheelTime=r,this.wheelCount=0);const o=ms(),a=o==="apple"||o==="mobile"?-1:1,l=0+i.deltaX*a,c=0+i.deltaY*a;if(i.ctrlKey){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw();return}if(c!==0&&Math.abs(c)>Math.abs(l)){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw()}if(l!==0&&Math.abs(l)>Math.abs(c)){const h=Ht(l,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-h),this.bus.fireDraw();return}}),this.addRxSubscription(this.wheelSubscription)}triggerPerformanceCleanup(){window.dispatchEvent(new Event("resize")),window.gc&&window.gc(),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation(),this.consecutiveLowWheelEvents=0,this.wheelCount=0,this.lastWheelTime=0}doDeactivate(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.isActivated=!1,super.doDeactivate()}}class xf extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=s,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c;const h=[this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel],d=Ae?new Sf(...h):new yo(...h);this.chartAreaPanHandler=d,this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new pf(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const So=n=>t=>{const{top:e,bottom:s}=n(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*s/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},xo=(n,t)=>{const e=So(n);return{isHighLowActive:()=>!0,calculateHighLow:s=>{const i=t.calculateHighLow(s);return e(i)}}};function _f(){return Vn(1)}function _o(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return _f()(Ge(n,Ue(n)))}function Pf(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n);return N(function(s,i){(e?_o(n,s,e):_o(n,s)).subscribe(i)})}function Tf(n){return Z(function(t,e){return n<=e})}class Mf{constructor(t,e,s,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=s,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),s=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(s.fillStyle=i.getColor(0),s.fillRect(e.x,e.y-r,e.width,e.height+2*r)),s.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?s.fillRect(e.x,e.y,e.width,e.height):s.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const Po=8;class dn extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=s,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new F,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=g=>{const{delta:m,draggedPixels:x}=g;Math.abs(this.initialY-this.boundsProvider().y+x)>=0&&(this.dragTickCb(m),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const s=new us(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:Nt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:Nt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(s),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Pf(!1),Z(this.dragPredicate),Tt(),Tf(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Mf(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,Hr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(Hr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const un=1/32,Af=n=>{const t=Math.floor(n),e=n-t,s=Math.round(e*64),r=Math.floor(s/2).toString().padStart(2,"0");return`${t}'${r}`},To=n=>n.match(/^\-?0*(\d+)'(\d{2})$/),rv=n=>!!To(n),ov=n=>{const t=To(n);if(t){const e=parseInt(t[1],10),i=parseInt(t[2],10)*un;return e+i}return Number(n)},Ef=(n,t)=>e=>{let s;if(typeof e=="number")s=e;else if(typeof e=="string")s=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return Af(s);const[r]=n.dataSeries;if(r!==void 0){const o=ve.getPricePrecision(s,r.pricePrecisions);return s.toFixed(o)}return`${s}`},If=n=>(t,e)=>{if(t===0)return"0.00 %";const[s]=n.dataSeries;let i=t;const r=e!=null?e:s;r!==void 0&&(i=sr(t,r.getBaseline()));const o=Je(i.toFixed(ve.DEFAULT_PRECISION))+" %";return o===`${ti}0.00 %`?"0.00 %":o},Df=(n,t)=>({percent:If(n),regular:Ef(n,t)});class Lf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u=new Set,f={regular:Jc}){super(),this.config=t,this.paneUUID=e,this.idx=s,this.paneComponent=i,this.chartBaseModel=r,this.canvasBoundsContainer=o,this.hitTestController=a,this.dynamicObjectsCanvasModel=l,this.scale=c,this.dragNDrop=d,this.dataSeries=u,this.formatters=f,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(m=>new Be(this.chartBaseModel.dataFromTimestamp(m.timestamp).centerUnit,m.close)),this.toY=g=>{var m,x;return(x=(m=this.mainDataSeries)==null?void 0:m.view.toY(g))!=null?x:1},this.valueFormatter=(g,m)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(g);const{regular:x,percent:_,logarithmic:A}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(g);case"percent":return _?_(g,m):x(g);case"logarithmic":return A?A(g):x(g);default:return this.regularFormatter(g)}},this.addChildEntity(c),this.setValueFormatters(Df(this,t)),this.yAxis=h(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new cr(this,wt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){if(this.dataSeries.add(t),this.dataSeries.size===1)this.mainDataSeries=t;else if(this.paneComponent.yExtentComponents.length>1&&this.paneUUID!==K){this.mainDataSeries=t;const e=Array.from(this.paneComponent.mainExtent.dataSeries);this.paneComponent.mainExtent.mainDataSeries=e[e.length-1]}this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,s;return(s=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?s:this.scale.fromY(t)}}const Mo=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(n.dataSeries),s=e.filter(o=>o.highLowProvider.isHighLowActive()),i=s.length>0?s:e;if(i.length===0)return{low:0,high:100};const r=i.map(o=>o.highLowProvider.calculateHighLow(t)).filter(o=>o.high>=o.low);return r.length===0?{low:0,high:100}:yr(r)}});class Of{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=ln.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return ln.DATA_SERIES}get allDataSeries(){return Ie(Ie(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(s=>s.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(s=>s.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Ut="#FF00FF";function av(n,t,e,s){const i=n.yAxis.backgroundColor,r=n.chartAreaTheme.backgroundColor,o=n.chartAreaTheme.backgroundGradientTopColor,a=n.chartAreaTheme.backgroundGradientBottomColor,l=s.align==="left"?o:a,c=n.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const Bf=(n,t)=>n==="down"?t.lastPrice.textNegative:n==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Rf=(n,t)=>{const e=t.barTheme[`${n}Color`];return e!=null?e:Ut},Ff=(n,t)=>{const e=t.lineTheme[`${n}Color`];return e!=null?e:Ut},Hf=(n,t)=>{const e=t.candleTheme[`${n}Color`];return e!=null?e:Ut},kf=(n,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Ut},jf=(n,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Ut},Yf=(n,t)=>{const e=t.histogram[`${n}Bright`];return e!=null?e:Ut},Nf=(n,t)=>{const e=n==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Ut},Ao=(n,t)=>{const e=t.candleTheme[`${n}WickColor`];return e!=null?e:Ut},Xf=()=>(console.warn("Fallback for label default color"),Ut),Eo=10;class Io extends X{constructor(t,e,s,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new F,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(M.Y_AXIS).height,Bi),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(Eo-1)):d=1+h/this.lastYPxHeight*(Eo-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,g=this.lastYStart-f,m=this.lastYEnd+f;(this.lastYStart!==g||this.lastYEnd!==m)&&(this.scale.setYScale(g,m),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new us(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,s,{dragPredicate:()=>s.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Wf{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${wt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Qn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const zf=0,Vf=.01;class fn{constructor(t,e,s,i,r=!1,o,a,l=Ns,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=s,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new F,this.newGeneratedLabelsSubject=new F,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Wf(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,s){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=gt.roundToNearest(t,s);for(;r<e;){const o=gt.roundToNearest(r,s),a=Je(this.valueFormatter(o));i.push({value:o,text:a}),r=gt.roundDecimal(r+s)}return i}generatePercentLabels(t,e,s){const i=[],r=this.baseLineProvider();let o=gt.roundToNearest(t,s);for(;o<e;){const a=gt.roundToNearest(o,s),l=nr(a,r),c=Je(this.valueFormatter(l));i.push({value:a,text:c}),o=gt.roundDecimal(o+s)}return i}generateLogarithmLabels(t,e,s){const i=[];let r=gt.roundToNearest(t,s);for(;r<e;){const o=tn(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=gt.roundDecimal(r+s)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[s,i]=this.calculateMinMax(),r=this.getAxisStep(s,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(s,i,r):a==="percent"?o=this.generatePercentLabels(s,i,r):o=this.generateRegularLabels(s,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),s=this.lengthProvider(),i=fn.getLabelBounds(t,e,s);return[i[0],i[1]]}getAxisStep(t,e,s){const i=e-t,r=s/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const s=(e=this.treasuryFormat)!=null&&e.enabled?un:ve.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(s)}return this.adjustIncrementOnAxisType(Vf)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=tn(e)+t;return ir(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,s){const i=Math.abs((e-t)*(zf/s));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let s=e,i=e,r=0;for(;s<t&&s>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),s=i*this.gridDistanceMultipliers[r++];return s}}class Uf extends fn{constructor(t,e,s,i,r=()=>"regular",o=23,a){super(t,()=>[s.yStart,s.yEnd],()=>s.getBounds().height,i,!1,r,()=>{var l,c;return(c=(l=e())==null?void 0:l.getBaseline())!=null?c:1},void 0,o,a),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,s)=>s.text.length>e.length?s.text:e,"")}updateTreasuryFormat(t){this.treasuryFormat=t}calculateIncrement(t){var e,s;const i=this.dataSeriesProvider();if(i){const r=St(i.dataPoints),o=(e=r==null?void 0:r.close)!=null?e:0,a=hh(o,i.pricePrecisions),l=(s=this.treasuryFormat)!=null&&s.enabled?un:a;return this.adjustIncrementOnAxisType(l)}return super.calculateIncrement(t)}}function Do(n,t,e){var s=k(n)||t||e?{next:n,error:t,complete:e}:n;return s?N(function(i,r){var o;(o=s.subscribe)===null||o===void 0||o.call(s);var a=!0;i.subscribe(Ct(r,function(l){var c;(c=s.next)===null||c===void 0||c.call(s,l),r.next(l)},function(){var l;a=!1,(l=s.complete)===null||l===void 0||l.call(s),r.complete()},function(l){var c;a=!1,(c=s.error)===null||c===void 0||c.call(s,l),r.error(l)},function(){var l,c;a&&((l=s.unsubscribe)===null||l===void 0||l.call(s)),(c=s.finalize)===null||c===void 0||c.call(s)}))}):ue}class Gf extends X{constructor(t,e,s,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=s,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${wt()}`}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(dt(t=>t.height),Z(t=>fl(t,this.prevYAxisHeight,1.5)),Do(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,Pe(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){Pe(this.animFrameId,()=>{this.labels=this.labelsGenerator.generateNumericLabels(),this.canvasBoundsContainer.updateYAxisWidths()})}}class Zf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=s,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Uf(null,l,o,a,()=>this.state.type,s.labelHeight,s),this.baseLabelsModel=new Gf(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new kc(e,o,i,s,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(s=>s.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(s=>s.labels).map(s=>s.labelText)).reduce((s,i)=>i.length>s.length?i:s,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class $f extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x){super(),this.eventBus=t,this.config=e,this.mainCanvasModel=s,this.canvasModel=i,this.scale=r,this.canvasInputListeners=o,this.canvasBoundsContainer=a,this.chartPanComponent=l,this.cursors=c,this.paneUUID=u,this.extentIdx=f,this.hitTestCanvasModel=g,this.chartResizeHandler=m,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new F,this.axisAlignSetSubject=new F,this.axisAlignMovedSubject=new F,this.setDblClickCallback=A=>this.yAxisScaleHandler.setDblClickCallback(A),this.setDblTapCallback=A=>this.yAxisScaleHandler.setDblTapCallback(A);const _=x?re(x):{};this.state=At(_,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new Io(t,this.state,l,r,o,a,a.getBoundsHitTest(M.PANE_UUID_Y_AXIS(u,f)),g),this.addChildEntity(this.yAxisScaleHandler),this.model=new Zf(this.paneUUID,t,this.state,a,i,r,h,d,f,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new Io(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Hf),this.registerLabelColorResolver("bar",Rf),this.registerLabelColorResolver("line",Ff),this.registerLabelColorResolver("area",kf),this.registerLabelColorResolver("scatterPlot",jf),this.registerLabelColorResolver("histogram",Yf),this.registerLabelColorResolver("baseline",Nf),this.registerLabelColorResolver("trend",Ao),this.registerLabelColorResolver("hollow",Ao)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Xf}registerYAxisLabelsProvider(t,e=ie.MAIN,s=wt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,s),s}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}updateCustomYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=ie.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor(),this.mainCanvasModel.fireDraw())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Kf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_,A,L,Y){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=s,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=g,this.uuid=m,this.seriesAddedSubject=x,this.seriesRemovedSubject=_,this.hitTestCanvasModel=A,this.chartResizeHandler=L,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new F,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,j)=>this.mainExtent.valueFormatter(B,j);const H=this.createExtentComponent(Y);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID(m),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return Ie(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(this.uuid)).pipe(Tt(Yi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,s;return(s=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?s:this.scale.toY(t)}createGridComponent(t,e,s,i,r,o){var a,l;const c=M.PANE_UUID(t),h=(l=(a=this.mainExtent)==null?void 0:a.idx)!=null?l:0;return new go(this.mainCanvasModel,s,this.config,i,`PANE_${t}_${e}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(c),()=>this.canvasBoundsContainer.getBounds(c),()=>[],r,e,o,()=>this.config.components.grid.visible,h)}createYPanHandler(t,e){const s=M.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(s));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const s=M.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(s,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(s)}createExtentComponent(t){var e,s;const i=this.yExtentComponents.length,r=M.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new jh(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(m,x)=>new $f(this.eventBus,this.config,this.mainCanvasModel,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,m,x,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Lf(this.config.components.yAxis,this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((s=t==null?void 0:t.useDefaultHighLow)==null||s)&&a.autoScaleModel.setHighLowProvider("default",xo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),Mo(u)));const g=this.createGridComponent(this.uuid,u.idx,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(g),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(s=>s.idx).includes(e.idx)),this.yExtentComponents.forEach((e,s)=>{e.yAxis.setExtentIdx(s),e.idx=s,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,s,i="right"){const r=re(s.yAxis.state),o=re(s.scale.state),a=At(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),s.dataSeries.size===0&&e.removeExtentComponents([s])}moveDataSeriesToExistingExtentComponent(t,e,s,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&s.dataSeries.size===0&&e.removeExtentComponents([s]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(s=>s.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=ge(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=St(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var qf=Object.defineProperty,Jf=Object.defineProperties,Qf=Object.getOwnPropertyDescriptors,Lo=Object.getOwnPropertySymbols,tg=Object.prototype.hasOwnProperty,eg=Object.prototype.propertyIsEnumerable,Oo=(n,t,e)=>t in n?qf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sg=(n,t)=>{for(var e in t||(t={}))tg.call(t,e)&&Oo(n,e,t[e]);if(Lo)for(var e of Lo(t))eg.call(t,e)&&Oo(n,e,t[e]);return n},ng=(n,t)=>Jf(n,Qf(t));class ig extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=s,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=g,this.yAxisLabelsCanvasModel=m,this.hitTestCanvasModel=x,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new F,this.paneAddedSubject=new F,this.dataSeriesAddedSubject=new F,this.dataSeriesRemovedSubject=new F,this.hitTestController=new Of(this.panes,this.dynamicObjectsCanvasModel);const A=this.createPane(K,{useDefaultHighLow:!1,scale:this.mainScale});A.mainExtent.scale.autoScaleModel.setHighLowProvider("series",Mo(A.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",So(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+Po}),s=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=M.PANE_UUID_RESIZER(t),o=new dn(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,s,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return Ie(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(s=>this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID(s.uuid))(t.x,t.y))}createPane(t=wt(),e){if(this.panes[t]!==void 0)return this.panes[t];const s=new Kf(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&s.addChildEntity(this.addResizer(t)),s.addSubscription(this.addBounds(t,e==null?void 0:e.order)),s.addSubscription(this.addCursors(t)),s.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,s.ht)),this.panes[t]=s,s.activate(),this.recalculateState(),s.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),s}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,s;const i=ge(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}canMovePaneDown(t){var e,s;const i=St(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(s=>s.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const s=M.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof dn&&r.id===s);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],s=M.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof dn&&r.id===s);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,s,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?ng(sg({},s.yAxis.state),{align:l}):void 0,g=c&&c>0;if(!u){const m=a&&a==="above"?d:d+1,x=this.createPane(r,{order:m,initialYAxisState:f,inverse:s.scale.state.inverse,lockToPriceRatio:s.scale.state.lockPriceToBarRatio});x.moveDataSeriesToExistingExtentComponent(t,e,s,x.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!g?u.moveDataSeriesToExistingExtentComponent(t,e,s,o):u.moveDataSeriesToNewExtentComponent(t,e,s,l!=null?l:s.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const s=M.PANE_UUID(t),i=M.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(s,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+Po),()=>{this.cursorHandler.removeCursorForCanvasEl(s),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class rg extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,s=this.canvasModel.ctx;if(s){s.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return s.drawImage(this.elements.backgroundCanvas,0,0,i,r),s.drawImage(this.elements.mainCanvas,0,0,i,r),s.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),s.drawImage(this.elements.crossToolCanvas,0,0,i,r),s.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(s),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const og=(n,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function s(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return s(n)},Bo=class _s extends X{constructor(t,e,s,i){super(),this.chartComponent=t,this.config=e,this.volumesModel=s,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var t,e;return!((t=this.pane)!=null&&t.scale.isViewportValid())&&((e=this.pane)==null?void 0:e.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var t;return(t=this.pane)==null?void 0:t.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[_s.UUID]===void 0){const e=this.paneManager.createPane(_s.UUID,{paneFormatters:{regular:r=>og(r,1)},useDefaultHighLow:!1,increment:1});this.pane=e,e.mainExtent.yAxis.setAxisType("regular");const{scale:s}=e,i=xo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);s.autoScaleModel.setHighLowProvider("volumes",i),s.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(_s.UUID),delete this.pane}fromY(t){var e,s;return(s=(e=this.pane)==null?void 0:e.scale.fromY(t))!=null?s:0}};Bo.UUID="volumes";let ag=Bo;const vs=.3,lg=(n,t)=>{const e=t.barTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},cg=(n,t)=>{const e=t.volume[`${n}BarColor`];return Bt()(e).alpha(vs).toString()},hg=(n,t)=>{const e=t.lineTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},gn=(n,t)=>{const e=t.candleTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},dg=3;class ug{constructor(t,e,s,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=s,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const s=(e=this.volumesColorByChartTypeMap[t])!=null?e:cg;this.volumeBarColors.down=s("down",this.config.colors),this.volumeBarColors.up=s("up",this.config.colors),this.volumeBarColors.none=s("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const s=this.getViewportModel().getBounds();Kt(e,s),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const s=this.getViewportModel();if(!s.isViewportValid())return;const i=mt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1));i.forEach((r,o)=>{if(r.candle.volume){const a=s.getBounds(),l=a.height;if(l<=0)return;const c=i[o+1]!==void 0?Et(s.toX(i[o+1].startUnit)):void 0,h=Et(s.toX(r.startUnit)),d=c!==void 0?c-h:Et(vt(r.width,s.zoomX));if(this.config.components.volumes.showSeparately){const u=Et(s.toY(r.candle.volume)),f=qs(s.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=l/dg;if(u<=0)return;const f=e/u;if(!isFinite(f)||f<=0)return;const g=Math.max(qs(vt(r.candle.volume,f)),2),m=Math.min(g,l),x=Et(a.y+l-m);this.drawVolume(t,r,h,x,d,m)}}})}drawVolume(t,e,s,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(s,l),a.lineTo(s,qs(c)),a.stroke()):a.fillRect(s,i,r,o)}}const fg=Hl(n=>n.candle.volume),Ro="volumes";class gg extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=Ro,this.volumeMax=new ft(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;const e=this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport(this.scale.xStart-1,this.scale.xEnd+1);this.volumeMax.next((t=ge(fg(e.flat())))!=null?t:0)}}class pg extends X{constructor(t,e,s,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ft(!1),this.volumeIsSeparateModeChangedSubject=new ft(!1);const c=new gg(e,s);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new ag(e,o,c,a),this.volumesDrawer=new ug(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:s},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",gn),this.registerVolumeColorResolver("trend",gn),this.registerVolumeColorResolver("hollow",gn),this.registerVolumeColorResolver("line",hg),this.registerVolumeColorResolver("bar",lg)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t),this.syncVolumesDynamicObject())}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.syncVolumesDynamicObject(),this.canvasModel.fireDraw()}syncVolumesDynamicObject(){if(!this.config.components.volumes.visible){this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id);return}const e=this.config.components.volumes.showSeparately?Ro:K,s={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(s);return}this.dynamicObjectsComponent.model.updateObject(s)}}class mg{constructor(t,e,s,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=s,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(M.PANE_UUID(K)),{position:g,offsetY:m,offsetX:x}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=bs(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=vg(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),g){case"left-top":return{x:x+f.x,y:m+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:x+f.x,y:f.height-h-m+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,s,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let g=0,m=0,x=0,_=0,A=0;if(f.save(),d.firstRowFontSize&&l){f.font=bs(this.config,d.firstRowFontSize);const B=f.measureText(l);g=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=bs(this.config,d.secondRowFontSize);const B=f.measureText(c);m=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,x=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=bs(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,A=(s=d.secondRowBottomPadding)!=null?s:0}const L=(i=d.thirdRowBottomPadding)!=null?i:0,Y=(r=d.logoHeight)!=null?r:0,H=g+m+x+_+A+L+Y;if(l&&this.drawWaterMark(this.getConfig(g,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(g+x+m,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(g+x+m+A+_,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(g+x+m+A+_+L,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const s=this.canvasModel.ctx;s.font=t.font,s.fillStyle=t.color;const i=t.x,r=t.y;s.fillText(e,i,r)}reset(){}}const vg=(n,t,e,s)=>{const r=((a,l)=>t.getBounds(M.CHART).width/l*a)(e,s);let o;return n.components&&n.components.waterMark&&(o=n.components.waterMark.fontFamily),r+"px "+o},bs=(n,t)=>{let e;return n.components&&n.components.waterMark&&(e=n.components.waterMark.fontFamily),t+"px "+e};var bg=Object.defineProperty,Fo=Object.getOwnPropertySymbols,Cg=Object.prototype.hasOwnProperty,yg=Object.prototype.propertyIsEnumerable,Ho=(n,t,e)=>t in n?bg(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ko=(n,t)=>{for(var e in t||(t={}))Cg.call(t,e)&&Ho(n,e,t[e]);if(Fo)for(var e of Fo(t))yg.call(t,e)&&Ho(n,e,t[e]);return n};class wg extends X{constructor(t,e,s,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=s,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new mg(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(At(r.observeBoundsChanged(M.PANE_UUID(K)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};At(e,t),At(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return ko(ko({},this.config.components.waterMark),h)}}const jo={x:4,y:4};function Sg(n,t,e,s){var i,r;const o=(i=s.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(M.X_AXIS);n.save(),n.font=`bold ${a}px ${l}`;const g=n.measureText(s.text).width+jo.x*2;let m=0;const x=s.x;switch(o){case"start":m=x-g;break;case"end":m=x;break;default:m=x-g/2;break}n.fillStyle=h.backgroundColor,n.strokeStyle=h.backgroundColor,n.fillRect(m,u.y,g,u.height),o!=="middle"&&(n.strokeStyle=s.color,n.beginPath(),n.moveTo(x,u.y),n.lineTo(x,u.y+u.height),n.stroke()),n.fillStyle=s.color;const _=m+jo.x,A=u.y+d+a+De/2;n.fillText(s.text,_,A),n.restore()}class xg{constructor(t,e,s,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=s,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Sg(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},s=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(s).forEach(i=>{const r=s[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(M.X_AXIS);t.fillStyle=Bt().rgb(r[0].color).alpha(.1).toString(),Er(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const lv="week-weekday",_g=["second","minute","hour","day","month","year"],Pg=["lessThanSecond"],Tg=n=>_g.some(t=>t===n),Mg=n=>n==="week-weekday",Ag=n=>Pg.some(t=>t===n),Yo=n=>{const t={"!":!1,$:!1};return n.includes("!")&&(t["!"]=!0),n.includes("$")&&(t.$=!0),t},pn=n=>parseInt(n,10),No=n=>{const[t,...e]=n.split("_");if(Tg(t)){const[s]=e,i=Yo(s),r=pn(s);return{key:t,value:r,exact:i["!"]}}else if(Mg(t)){const[s,i]=e,r=Yo(s),o=pn(s),a=pn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Ag(t)?{key:t}:(console.warn(`${n} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class Cs{constructor(t,e,s,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=s,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,s=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=Cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=s.backgroundColor;const l=this.canvasBoundsContainer.getBounds(M.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+De/2),e.restore()}}drawLabels(t,e,s,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Mt(c.text,t,l)/2;if(h<s.x||h>s.width)continue;const d=s.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const mn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},Xo=n=>{switch(n.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return mn[n.key]+n.value;case"lessThanSecond":return mn[n.key];case"week-weekday":return mn[n.key]+(n.week==="$"?9:n.week)+n.weekday*10}},Wo=n=>{const t={};for(const e of n){const s=t[e.weight];s===void 0?t[e.weight]=[e]:s.push(e)}return t},Eg=(n,t)=>{const e=Object.keys(n).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let s=[];for(const i of e){const r=n[i];if(!r)continue;const o=[...s];s=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],g=f.idx;for(;c<a;){const m=o[c],x=m.idx;if(g>x)c++,s.push(m),d=x,h=1/0;else{h=x;break}}h-g>=t&&g-d>=t&&(s.push(f),d=g)}for(;c<a;)s.push(o[c]),c++}return s},Ig=(n,t,e,s,i,r)=>{const o=Cs.getFontFromConfig(t),a=Mt(e.text,n,o),l=Mt(s.text,n,o),c=i.toX(e.value)+a/2;return i.toX(s.value)-l/2-c<r},cv=7,Dg=365.2425,dv=-(Math.pow(10,8)*24*60*60*1e3),uv=6048e5,fv=864e5,gv=6e4,pv=36e5,mv=1e3,vv=525600,bv=43200,Cv=1440,yv=60,wv=3,Sv=12,xv=4,Lg=3600,_v=60,zo=Lg*24,Pv=zo*7,Av=zo*Dg/12*3,Vo=Symbol.for("constructDateFrom");function vn(n,t){return typeof n=="function"?n(t):n&&typeof n=="object"&&Vo in n?n[Vo](t):n instanceof Date?new n.constructor(t):new Date(t)}const Ev=null;function kt(n,t){return vn(t||n,n)}const Iv=null;function Og(n,t){return kt(n,t==null?void 0:t.in).getDay()===1}const Dv=null;function Bg(n,t){return kt(n,t==null?void 0:t.in).getDay()===2}const Lv=null;function Rg(n,t){return kt(n,t==null?void 0:t.in).getDay()===3}const Ov=null;function Fg(n,t){return kt(n,t==null?void 0:t.in).getDay()===4}const Bv=null;function Hg(n,t){return kt(n,t==null?void 0:t.in).getDay()===5}const Rv=null;function kg(n,t){return kt(n,t==null?void 0:t.in).getDay()===6}const Fv=null;function jg(n,t){return kt(n,t==null?void 0:t.in).getDay()===0}const Hv=null;function Uo(n,...t){const e=vn.bind(null,n||t.find(s=>typeof s=="object"));return t.map(e)}function Yg(n,t){const[e,s]=Uo(n,t.start,t.end);return{start:e,end:s}}function Ng(n,t){var c;const{start:e,end:s}=Yg(t==null?void 0:t.in,n);let i=+e>+s;const r=i?+e:+s,o=i?s:e;o.setHours(0,0,0,0);let a=(c=t==null?void 0:t.step)!=null?c:1;if(!a)return[];a<0&&(a=-a,i=!i);const l=[];for(;+o<=r;)l.push(vn(e,o)),o.setDate(o.getDate()+a),o.setHours(0,0,0,0);return i?l.reverse():l}const kv=null;function Xg(n,t){const e=kt(n,t==null?void 0:t.in);return e.setDate(1),e.setHours(0,0,0,0),e}const jv=null;function Wg(n,t){const e=kt(n,t==null?void 0:t.in),s=e.getMonth();return e.setFullYear(e.getFullYear(),s+1,0),e.setHours(23,59,59,999),e}const Yv=null;function Go(n,t){const e=kt(n,t==null?void 0:t.in);return e.setHours(0,0,0,0),e}const Nv=null;function Zo(n,t,e){const[s,i]=Uo(e==null?void 0:e.in,n,t);return+Go(s)==+Go(i)}const Xv=null,zg=n=>{switch(n.key){case"lessThanSecond":return Zg(n);case"month":return $g(n);case"second":case"minute":case"hour":case"day":case"year":return Kg(n);case"week-weekday":return qg(n);default:return()=>!1}},Qt=(n,t)=>{switch(t){case"lessThanSecond":return n.getMilliseconds();case"month":return n.getMonth();case"second":return n.getSeconds();case"minute":return n.getMinutes();case"hour":return n.getHours();case"day":return n.getDate();case"year":return n.getFullYear();case"week-weekday":return n.getDate()}},bn=n=>(t,e)=>{const s=Qt(t,n),i=Qt(e,n);return s!==i},Vg=n=>(t,e)=>{const s=Qt(t,n),i=Qt(e,n);return s>=i},Ug={1:Og,2:Bg,3:Rg,4:Fg,5:Hg,6:kg,7:jg},Gg=(n,t,e)=>{var s;const i=Ng({start:Xg(n),end:Wg(n)}),r=(s=Ug[e])!=null?s:(()=>!1);if(t==="$"){for(const o of i.reverse())if(r(o))return Zo(n,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return Zo(n,a);o++}}return!1},$o=(n,t)=>t===1?n===1:n/t===1,Ko=(n,t)=>t===1?!0:n%t===0,Zg=n=>(t,e)=>Vg(n.key)(t,e),$g=n=>(t,e)=>{const s=bn(n.key)(t,e),i=n.exact?$o(Qt(t,n.key)+1,n.value):Ko(Qt(t,n.key)+1,n.value);return s&&i},Kg=n=>(t,e)=>{const s=bn(n.key)(t,e),i=n.exact?$o(Qt(t,n.key),n.value):Ko(Qt(t,n.key),n.value);return s&&i},qg=n=>(t,e)=>{const s=bn(n.key)(t,e),i=Gg(t,n.week,n.weekday);return s&&i},Jg=n=>{switch(n.key){case"second":case"minute":return Qg(n.value);case"hour":return tp(n.value);case"day":return ep(n.value);case"month":return ip(n.value);case"year":return rp(n.value);case"week-weekday":const t=np(n.week),e=sp(n.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},Qg=n=>n>0&&n<=60,tp=n=>n>0&&n<=24,ep=n=>n>0&&n<=31,sp=n=>qo(n)?n>=1&&n<=7:!1,np=n=>n==="$"?!0:qo(n)?n>=1&&n<=6:!1,ip=n=>n>0&&n<=12,rp=n=>n>0,qo=n=>!isNaN(n)&&isFinite(n),op=(n,t,e)=>{var s,i;for(const[r,o]of e)if(o(n,t))return r;return(i=(s=e[e.length-1])==null?void 0:s[0])!=null?i:0};function Cn(n,t,e){const s=new Array(n.length);let i=e(0);for(let r=0;r<n.length;r++){const o=n[r],a=e(o.candle.timestamp),l={weight:op(a,i,t)};s[r]=l,i=a}return s}const Jo=n=>{const t={},e={};return Js(n).forEach(([s,i])=>{const r=No(s),o=r===null?!1:Jg(r);if(r&&o){const a=Xo(r);t[a]=i,e[a]=zg(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Qo{constructor(t,e,s,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=s,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.labelCache=new Map,this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?vt(d,h.animationConfig.targetZoomX):vt(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,g=Object.values(this.formatsByWeightMap).reduce((x,_)=>Math.max(_.length,x),1),m=f*g;return Math.round(m/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Jo(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(M.X_AXIS),s=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||s.push(i)}return s}getLabelsFromChartType(){var t,e;const s=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(s):s}getVisualCandleAtIndex(t,e,s,i,r){return t>=0&&t<s.length?s[t]:en(e,s,i,t,r)}getVisualCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>en(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}getViewportCandlesWithFake(){var t;const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0||this.scale.xEnd-this.scale.xStart<=1)return[];const s=this.chartModel.mainCandleSeries.meanCandleWidth,i=this.chartModel.getPeriod(),r=this.chartModel.mainCandleSeries.dataPoints,o=this.canvasBoundsContainer.getBounds(M.CHART),a=0,l=o.width,c=this.scale.fromX(a),h=this.scale.fromX(l);let d=0;if(e.length>0){const L=e[0];d=L.centerUnit-((t=L.candle.idx)!=null?t:0)*s}const u=500,f=500,g=Math.floor((c-d)/s)-u,m=Math.ceil((h-d)/s)+u,x=Math.floor(g/f)*f,_=Math.ceil(m/f)*f,A=[];for(let L=x;L<=_;L++)A.push(this.getVisualCandleAtIndex(L,r,e,s,i));return[...A]}getAllCandlesWithFake(t=[]){return this.config.components.chart.minCandlesOffset?this.getVisualCandlesWithFake(t):this.getViewportCandlesWithFake()}mapWeightedPointsToLabels(t,e){var s;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(s=a.candle.idx)!=null?s:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){this.clearLabelCache();const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:s}=Jo(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(s).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=Cn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),s=Cn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(s,e),r=Wo(i),o=re(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const g=f.map(m=>(m.idx=m.idx+t.length,m.value=a.startUnit+a.width+m.value,m));r[u]?c[h]=d.concat(g):c[h]=g}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t,e=!1){var s;const i=this.getAllCandlesWithFake(t),r=Cn(i,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone));let o=[];if(e)for(let a=0;a<i.length;a++){const l=(s=i[a].candle.idx)!=null?s:a,c=i[a].candle.timestamp,h=`${l}_${c}`;let d=this.labelCache.get(h);d||(d=this.mapWeightedPointsToLabels([r[a]],[i[a]])[0],this.labelCache.set(h,d)),o.push(d)}else o=this.mapWeightedPointsToLabels(r,i);this.labelsGroupedByWeight=Wo(o),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const s=Eg(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=s,this.weightedCache={labels:s,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,s;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Ig(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((s=a.weight)!=null?s:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const s=Js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=No(o);if(l){const c=Xo(l);i[c]=a}}return i},{});return Js(t).reduce((i,[r,o])=>(s[r]&&s[r](e)||(i[r]=o),i),{})}clearLabelCache(){this.labelCache.clear()}}class ap extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(hs,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const ta=3;class lp extends X{constructor(t,e,s,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(M.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,g=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(g,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(ta-1)):u=1+h/this.lastXPxWidth*(ta-1);const g=(this.lastXWidth*u-this.lastXWidth)/2,m=this.lastXStart-g,x=this.lastXEnd+g;(this.lastXStart!==m||this.lastXEnd!==x)&&this.scale.setXScale(m,x)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Ye(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class cp extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=s,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=x=>this.xAxisScaleHandler.setDblClickCallback(x),this.setDblTapCallback=x=>this.xAxisScaleHandler.setDblTapCallback(x);const g=new Qo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=g,this.xAxisLabelsModel=new ap(t,[]);const m=new on;c.addDrawer(m,"X_AXIS"),this.xAxisDrawer=new Cs(e,s,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),m.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new xg(e,s,o,this.xAxisLabelsModel),m.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new lp(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(M.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(M.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(Z(({prependedCandles:t})=>t.length!==0),dt(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,s;Ql.includes(this.config.components.chart.type)&&((s=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||s.call(e,t))})),this.config.components.chart.minCandlesOffset?this.addRxSubscription(yt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Lt(50,Rt,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.recalculateLabels())):this.addRxSubscription(yt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Lt(150,Rt,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.generateLabels(void 0,!0))),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(dt(()=>St(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Tt((t,e)=>{var s,i;return((s=t==null?void 0:t.candle)==null?void 0:s.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),Z(li)).subscribe(t=>{var e,s;return(s=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:s.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Qo?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var hp=Object.defineProperty,ea=Object.getOwnPropertySymbols,dp=Object.prototype.hasOwnProperty,up=Object.prototype.propertyIsEnumerable,sa=(n,t,e)=>t in n?hp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ys=(n,t)=>{for(var e in t||(t={}))dp.call(t,e)&&sa(n,e,t[e]);if(ea)for(var e of ea(t))up.call(t,e)&&sa(n,e,t[e]);return n};class fp{constructor(t,e,s,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=s,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const s=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=s&&ys(ys({},s),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&ys(ys({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=St(t.dataPoints);if(e){const s=t.view.toY(e.close);if(isFinite(s)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:s,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const s=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:se("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:Bf(t.lastPriceMovement,i);return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):se(l,h,o),rounded:!0}}return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):se(l,r,o),rounded:!0}}}class gp{constructor(t,e,s,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=s,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,s=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(M.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>io(t,s,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>io(t,s,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,s={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=s[r.subGroupId])!=null?o:[];if(s[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(K));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];Er(e,{x:h.x,y:ji(d,h)},{x:h.x+h.width-6,y:ji(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class pp{constructor(t,e,s){this.fullConfig=t,this.canvasModel=e,this.paneManager=s}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const s=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=ne(e.state),a=Xt(o,r),l=this.getLabelTextColor();r.save(),Kt(r,i),this.drawLabels(r,s,i,a,o,l,e),r.restore()}})}drawLabels(t,e,s,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=s.y+c,d=s.y+s.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&mp(t,s,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const mp=(n,t,e,s,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Mt(e,n,r)-o:t.x+o;n.fillText(e,l,s+i/2-1)};class vp{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const s=this.handlers[t];s!==void 0&&Rl.call(s,e)},this.add=(t,e,s)=>(e in this.handlers?t.call(this.handlers[e],s):this.handlers[e]=[s],this.unsub.bind(this,e,s)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new F,s=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,s),e.unsubscribe=()=>{this.unsub(t,s),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var s;if(!this.muted){const i=(s=this.handlers[t])!=null?s:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(hs,t)}}class bp extends X{constructor(t,e,s,i){super(),s.observeTouchStart().pipe(dt(r=>i.components.chart.highlightActiveCandle?r:void 0),Tt()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,s){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=s.candleFromX(r);o&&s.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const s=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-s.left-i}}class Cp{constructor(t,e,s,i,r){this.frameElement=t,this.resizerElement=e,this.bus=s,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${wt()}`,this.canvasResized=new F,this.recentlyResized=!1,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Pe(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.recentlyResized=!0,this.canvasModels.forEach(s=>this.previousBCR&&s.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(cs,e),this.bus.fire(hs))}clearResizedFlag(){this.recentlyResized=!1}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.recentlyResized}}var yp=Array.isArray,wp=Object.getPrototypeOf,Sp=Object.prototype,xp=Object.keys;function _p(n){if(n.length===1){var t=n[0];if(yp(t))return{args:t,keys:null};if(Pp(t)){var e=xp(t);return{args:e.map(function(s){return t[s]}),keys:e}}}return{args:n,keys:null}}function Pp(n){return n&&typeof n=="object"&&wp(n)===Sp}var Tp=Array.isArray;function Mp(n,t){return Tp(t)?n.apply(void 0,ot([],R(t))):n(t)}function na(n){return dt(function(t){return Mp(n,t)})}function Ap(n,t){return n.reduce(function(e,s,i){return e[s]=t[i],e},{})}function Ep(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=tl(n),i=_p(n),r=i.args,o=i.keys;if(r.length===0)return Ge([],e);var a=new pt(Ip(r,e,o?function(l){return Ap(o,l)}:ue));return s?a.pipe(na(s)):a}function Ip(n,t,e){return e===void 0&&(e=ue),function(s){ia(t,function(){for(var i=n.length,r=new Array(i),o=i,a=i,l=function(h){ia(t,function(){var d=Ge(n[h],t),u=!1;d.subscribe(Ct(s,function(f){r[h]=f,u||(u=!0,a--),a||s.next(e(r.slice()))},function(){--o||s.complete()}))},s)},c=0;c<i;c++)l(c)},s)}}function ia(n,t,e){n?jt(e,n,t):t()}class Dp extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ft(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,s){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,s)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const s=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Ep([s,i]).pipe(Z(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!Nt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Lp(n,t){return N(function(e,s){var i=null,r=0,o=!1,a=function(){return o&&!i&&s.complete()};e.subscribe(Ct(s,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(n(l,h)).subscribe(i=Ct(s,function(d){return s.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Op{constructor(t,e,s,i){this.visualCandle=t,this.price=e,this.priceFormatter=s,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Bp{constructor(t){this.chartModel=t}getData(t){const{x:e,y:s}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(s);return o&&new Op(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Rp{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof Vr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Fp=Object.defineProperty,Hp=Object.defineProperties,kp=Object.getOwnPropertyDescriptors,ra=Object.getOwnPropertySymbols,jp=Object.prototype.hasOwnProperty,Yp=Object.prototype.propertyIsEnumerable,oa=(n,t,e)=>t in n?Fp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ne=(n,t)=>{for(var e in t||(t={}))jp.call(t,e)&&oa(n,e,t[e]);if(ra)for(var e of ra(t))Yp.call(t,e)&&oa(n,e,t[e]);return n},yn=(n,t)=>Hp(n,kp(t));class Np extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=s,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ft(null),this.longTouchActivatedSubject=new ft(!1),this.xFormatter=()=>"";const d=new Bp(this.chartModel),u=new Rp(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Lp(()=>this.scale.initialViewportValidSubject.pipe(Z(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(yt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var s;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((s=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:s.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var s;if(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1)return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((s=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:s.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var s,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!wo(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(s=this.crossEventProducer.crossToolHover)==null?void 0:s.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(M.PANE_UUID(d)),f=u.y+5,g=u.y+u.height-5,m=c-l.x,x=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=m,A=a.y<f?f:a.y>g?g:a.y+=x;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:A}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=oo(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),s=this.scale.toY(t.close);return this.createHover(e,s,K)}createHover(t,e,s){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:s},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>yn(Ne({},l),{[c[0]]:c[1].getData(o)}),{});return Ne(Ne({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const s=yn(Ne({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(s)}}createAndFireHover([t,e,s]){const i=this.createHover(t,e,s);this.fireHover(i)}fireHover(t){var e,s;if(t){if(Nt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(s=t.candleHover)==null?void 0:s.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}registerHoverProducerPart(t,e){this.hoverProducerParts=yn(Ne({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const aa={left:0,middle:1,right:2};function bt(n,t,e,s){return n.addEventListener(e,t,s),function(){n.removeEventListener(e,t,s)}}function Se(n){return t=>{t.button===aa.left&&n(t)}}var Xp=["addListener","removeListener"],Wp=["addEventListener","removeEventListener"],zp=["on","off"];function wn(n,t,e,s){if(k(e)&&(s=e,e=void 0),s)return wn(n,t,e).pipe(na(s));var i=R(Gp(n)?Wp.map(function(a){return function(l){return n[a](t,l,e)}}):Vp(n)?Xp.map(la(n,t)):Up(n)?zp.map(la(n,t)):[],2),r=i[0],o=i[1];if(!r&&Ls(n))return Bs(function(a){return wn(a,t,e)})(Dt(n));if(!r)throw new TypeError("Invalid event target");return new pt(function(a){var l=function(){for(var c=[],h=0;h<arguments.length;h++)c[h]=arguments[h];return a.next(1<c.length?c:c[0])};return r(l),function(){return o(l)}})}function la(n,t){return function(e){return function(s){return n[e](t,s)}}}function Vp(n){return k(n.addListener)&&k(n.removeListener)}function Up(n){return k(n.on)&&k(n.off)}function Gp(n){return k(n.addEventListener)&&k(n.removeEventListener)}var Zp=Object.defineProperty,ca=Object.getOwnPropertySymbols,$p=Object.prototype.hasOwnProperty,Kp=Object.prototype.propertyIsEnumerable,ha=(n,t,e)=>t in n?Zp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,qp=(n,t)=>{for(var e in t||(t={}))$p.call(t,e)&&ha(n,e,t[e]);if(ca)for(var e of ca(t))Kp.call(t,e)&&ha(n,e,t[e]);return n};const ws=class he extends X{constructor(t,e){super(),this.eventBus=t,this.element=e,this.xDragStartSubject=new F,this.xDragSubject=new F,this.xDragTickSubject=new F,this.xDragEndSubject=new F,this.yDragStartSubject=new F,this.yDragSubject=new F,this.yDragTickSubject=new F,this.yDragEndSubject=new F,this.mouseMoveSubject=new F,this.mouseMoveDocumentSubject=new F,this.clickSubject=new F,this.clickDocumentSubject=new F,this.dbClickSubject=new F,this.dbTapSubject=new F,this.mouseDownSubject=new F,this.mouseUpSubject=new F,this.mouseUpDocumentSubject=new F,this.wheelSubject=new F,this.touchStartSubject=new F,this.touchStartTimestamp=0,this.touchMoveSubject=new F,this.touchEndSubject=new F,this.touchCancelSubject=new F,this.longTouchStartSubject=new F,this.longTouchEndSubject=new F,this.contextMenuSubject=new F,this.fastTouchScroll=new F,this.mouseLeavesCanvasSubject=new F,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.cachedElementRect=null,this.rectCacheValid=!1,this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=s=>{this.isDraggable(s)&&(this.updateCurrentPoints(s),this.dragging=!0,this.dragStartEvent=s,this.cleanupDocumentDragListeners(),this.dragStartPoint=he.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=qp({},this.dragStartPoint),he.DRAG_EVENTS.forEach(i=>{document.addEventListener(i,this.dragProcessListener,!0);const r=document.removeEventListener.bind(document,i,this.dragProcessListener,!0);this.documentDragListeners.push(r),this.addSubscription(r)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.cleanupDocumentDragListeners(),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=s=>{this.updateCurrentDocumentPoint(s),this.updateCurrentMousePoint(s)}}getElementRect(){if(this.rectCacheValid&&this.cachedElementRect)return this.cachedElementRect;try{if(!this.element||!this.element.isConnected)return this.createFallbackRect();const t=this.element.getBoundingClientRect();return this.cachedElementRect=t,this.rectCacheValid=!0,t}catch(t){return this.createFallbackRect()}}createFallbackRect(){return typeof DOMRect!="undefined"?new DOMRect(0,0,0,0):{x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON:()=>({})}}invalidateRectCache(){this.rectCacheValid=!1}initializeRectCache(){this.invalidateRectCache();const t=this.getElementRect();this.canvasBounds.x=t.left,this.canvasBounds.y=t.top,this.canvasBounds.width=t.width,this.canvasBounds.height=t.height}cleanupDocumentDragListeners(){if(!this.documentDragListeners||!Array.isArray(this.documentDragListeners)){this.documentDragListeners=[];return}this.documentDragListeners.forEach(t=>{try{t()}catch(e){console.warn("Error cleaning up drag listener:",e)}}),this.documentDragListeners=[]}doDeactivate(){this.invalidateRectCache(),this.cachedElementRect=null,this.cleanupDocumentDragListeners(),super.doDeactivate()}isDraggable(t){return t instanceof MouseEvent?t.button===aa.left:t instanceof TouchEvent}startDragging(t){this.updateCurrentPoints(t),this.dragStartListener(t)}movePointer(t){this.updateCurrentPoints(t),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const t=e=>(e.preventDefault(),!1);this.element.addEventListener("selectstart",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",t,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],he.DRAG_START_EVENTS.forEach(s=>{this.element.addEventListener(s,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(s,this.dragStartListener))}),this.trackMousePosition(),he.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragListener)),this.element.addEventListener(s,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,s,this.updateElementOffsetListener))}),he.DRAG_END_EVENTS.forEach(s=>{document.addEventListener(s,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragEndListener))}),this.addSubscription(bt(this.element,Se(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(bt(document,Se(s=>this.clickDocumentSubject.next(s)),"click"));const t=ms();if(t==="apple"||t==="mobile"){let s=null;const i=a=>{a.preventDefault(),s?(this.dbTapSubject.next(this.currentPoint),clearTimeout(s),s=null):s=window.setTimeout(()=>{s=null},250)};this.addSubscription(bt(this.element,i,"touchend"));const r=(a,l=200)=>{a.preventDefault();let c=!1,h=null;h=setTimeout(()=>{c=!0,this.longTouchStartSubject.next(a)},l);const d=f=>{f.preventDefault(),f.touches.length>1&&h&&clearTimeout(h)},u=f=>{f.preventDefault(),h&&clearTimeout(h),c&&(c=!1,this.longTouchEndSubject.next(f)),this.element.removeEventListener("touchend",u),this.element.removeEventListener("touchmove",d)};this.element.addEventListener("touchmove",d),this.element.addEventListener("touchend",u)};this.addSubscription(bt(this.element,a=>r(a),"touchstart"));const o=a=>{if(a.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const h=this.touchStartTimestamp,u=Date.now()-h,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,m=u<=250;g&&m&&this.fastTouchScroll.next(a)}};this.addSubscription(bt(this.element,o,"touchend"))}this.addSubscription(bt(this.element,Se(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(bt(this.element,s=>{this.touchStartSubject.next(s),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(bt(this.element,s=>this.touchMoveSubject.next(s),"touchmove",!0)),this.addSubscription(bt(this.element,s=>this.touchEndSubject.next(s),"touchend")),this.addSubscription(bt(this.element,s=>this.touchCancelSubject.next(s),"touchcancel")),this.addSubscription(bt(this.element,s=>{this.updateCurrentPoints(s),this.wheelSubject.next(s),s.preventDefault()},"wheel")),this.addSubscription(bt(this.element,s=>this.contextMenuSubject.next(s),"contextmenu")),this.addSubscription(bt(this.element,Se(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(bt(this.element,Se(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(bt(document,Se(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(cs).subscribe(()=>{this.invalidateRectCache();const s=this.getElementRect();this.canvasBounds.x=s.left,this.canvasBounds.y=s.top,this.canvasBounds.width=s.width,this.canvasBounds.height=s.height})),this.addRxSubscription(wn(document,"scroll",{capture:!0,passive:!0}).pipe(Lt(Zt,is,{trailing:!0})).subscribe(()=>this.invalidateRectCache()));const e=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",e,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",e,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){he.DRAG_EVENTS.forEach(t=>{document.addEventListener(t,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(t,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(t){"pageX"in t?this.currentPointDocument.x=t.pageX:t.touches!==void 0&&(this.currentPointDocument.x=t.touches[0].pageX),"pageY"in t?this.currentPointDocument.y=t.pageY:t.touches!==void 0&&(this.currentPointDocument.y=t.touches[0].pageY)}updateCurrentMousePoint(t){const e=this.getElementRect();"clientX"in t?this.currentPoint.x=t.clientX-e.left:t.touches!==void 0&&(this.currentPoint.x=t.touches[0].clientX-e.left),"clientY"in t?this.currentPoint.y=t.clientY-e.top:t.touches!==void 0&&(this.currentPoint.y=t.touches[0].clientY-e.top)}static copyPoint(t){return{x:t.x,y:t.y}}observeMouseMove(t=()=>!0){return this.mouseMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(Z(()=>!this.dragging))}observeMouseMoveDocument(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPointDocument.x,this.currentPointDocument.y)),dt(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(t=()=>!0){return this.xDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(t=()=>!0){return this.xDragSubject.pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(t=()=>!0){return this.xDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(t=()=>!0){return this.yDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(t=()=>!0){return this.yDragSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(t=()=>!0){return this.yDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(t=()=>!0,e=!1){const s=this.mouseMoveSubject.asObservable().pipe(Z(()=>!(e&&this.dragging)),dt(()=>t(this.currentPoint.x,this.currentPoint.y))),i=this.observeMouseLeavesCanvas().pipe(dt(()=>!1));return yt(s,i).pipe(Tt())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(t=()=>!0){return this.clickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(t=()=>!0){return this.dbClickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(t=()=>!0){return this.dbTapSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeWheel(t=()=>!0){return this.wheelSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(t=()=>!0){return this.touchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(t=()=>!0){return this.touchMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(t=()=>!0){return this.mouseDownSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(t=()=>!0){return this.mouseUpSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(t=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(t=()=>!0){return this.contextMenuSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)),Do(e=>e.preventDefault()))}observeLongTouchStart(t=()=>!0){return this.longTouchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(t=()=>!0){return this.longTouchEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(t=()=>!0){return this.fastTouchScroll.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};ws.DRAG_START_EVENTS=["mousedown","touchstart"],ws.DRAG_EVENTS=["mousemove","touchmove"],ws.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];let Jp=ws;var Qp=(function(n){z(t,n);function t(e,s,i){e===void 0&&(e=1/0),s===void 0&&(s=1/0),i===void 0&&(i=$s);var r=n.call(this)||this;return r._bufferSize=e,r._windowTime=s,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=s===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,s),r}return t.prototype.next=function(e){var s=this,i=s.isStopped,r=s._buffer,o=s._infiniteTimeWindow,a=s._timestampProvider,l=s._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),n.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var s=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),s},t.prototype._trimBuffer=function(){var e=this,s=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*s;if(s<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t})(F);const Sn={};function tm(n){return Sn[n]||(Sn[n]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:n,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),Sn[n]}const da=(n,t=Date.now())=>{const s=tm(n).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(s);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},ua=60*1e3;class em{constructor(t){this.config=t,this.timeZoneChangedSubject=new Qp,this.currentTzOffset=e=>da(this.config.timezone,e)+new Date(e).getTimezoneOffset()*ua,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const s=t.createFormatterFunction;e=i=>s(i).bind(t)}else e=xu(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+da(t,e)+new Date(e).getTimezoneOffset()*ua):e=>new Date(e)}}class sm extends X{constructor(t,e,s){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=s}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(Tt((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}var nm=Object.defineProperty,im=Object.defineProperties,rm=Object.getOwnPropertyDescriptors,fa=Object.getOwnPropertySymbols,om=Object.prototype.hasOwnProperty,am=Object.prototype.propertyIsEnumerable,ga=(n,t,e)=>t in n?nm(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,lm=(n,t)=>{for(var e in t||(t={}))om.call(t,e)&&ga(n,e,t[e]);if(fa)for(var e of fa(t))am.call(t,e)&&ga(n,e,t[e]);return n},cm=(n,t)=>im(n,rm(t));class hm extends ai{constructor(t){super(t),this.animations={},this.animFrameId="animation",this.animationInProgressSubject=new ft(!1),this.microtaskQueued=!1}startViewportMovementAnimation(t,e,s=fe,i){const r=new ni(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new ei(cm(lm({},i),{duration:i&&i.duration||Ee}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ee,i){const r=new si({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0,delete this.animations[t]),Object.keys(this.animations).length===0&&this.stopInterval()}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.microtaskQueued||(this.microtaskQueued=!0,queueMicrotask(()=>{this.microtaskQueued=!1,this.processAnimation(),this.eventBus.fireDraw()}))}stopInterval(){hl(this.animFrameId),this.microtaskQueued=!1}}class xn{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var s,i;this.parentElement=t;const r=e;tc(r),this.config=r;const o=wc(r);t.innerHTML="",t.appendChild(o.content),this.id=(s=t.getAttribute("data-id"))!=null?s:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new em(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Sc(t);this.elements=c;const h=new vp;this.bus=h;const d=new Cp(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new bd(h,d);this.drawingManager=u;const f=md(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=le(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const g=new ye(this.dynamicObjectsCanvasModel);u.addDrawer(g,"SERIES_CLEAR");const m=le(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),x=le(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Zs(r,h,f,l,d);this.canvasBoundsContainer=_;const A=c.mainCanvas.parentElement;if(A===null)throw new Error("Couldn't get main canvas parent");const L=new Jp(h,A);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const Y=[h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer],H=new Hu(...Y);this.hitTestCanvasModel=H;const B=new ye(H);u.addDrawer(B,"HIT_TEST_CLEAR");const j=Ae?new hm(h):new ai(h);this.canvasAnimation=j;const $=M.PANE_UUID(K),W=new Mr(r,()=>_.getBounds($),j);this.scaleModel=W;const U=le(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=U,this.cursorHandler=new bc(c.canvasArea,L,_,H),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Dp(L,_),this.chartComponents.push(this.crossEventProducer);const G=new eh("candle");this.chartBaseModel=G;const V=new xf(h,W,_,r,j,L,A,G,H);this.chartPanComponent=V,this.chartComponents.push(V),this.userInputListenerComponents.push(V.chartAreaPanHandler);const Q=new sm(H,j,h);this.hitTestComponent=Q,this.chartComponents.push(Q);const J=new ig(G,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,j,L,u,this.cursorHandler,this.crossEventProducer,V,f,m,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=J;const et=this.paneManager.panes[K];this.mainPane=et,this.chartComponents.push(J),this.dynamicObjects=new wu(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Qd(G,J,h,this.dynamicObjectsCanvasModel,r,W,l,A,_,d);const tt=new Fd(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,H,L,U,V,J,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const st=this.chartComponent.chartModel;this.chartModel=st,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),H.addSubscriber(J.hitTestController),this.xAxisComponent=new cp(h,r,f,tt,W,_,L,d,this.drawingManager,a,V,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const ut=new ye(f);u.addDrawer(ut,"MAIN_CLEAR");const lt=new bp(A,st,L,r);this.chartComponents.push(lt),this.watermarkComponent=new wg(J,st,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const xt=le(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new sf(h,r,st,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(st)),this.navigationMapComponent=new uf(h,st,f,r,L,_,u,l,V,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Gt=new $u(r,this.dynamicObjectsCanvasModel,st,_,u);this.chartComponents.push(Gt),this.initYAxisDrawer(m,x),this.yAxisComponent=et.mainExtent.yAxis;const xe=new fp(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(xe,ie.MAIN),this.volumesComponent=new pg(this.dynamicObjectsCanvasModel,tt,W,_,u,r,J,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const Ca=new go(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(M.ALL_PANES),()=>this.canvasBoundsContainer.getBounds($),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,void 0,()=>r.components.grid.visible,this.mainPane.mainExtent.idx);this.chartComponents.push(Ca),this.hoverProducer=new Np(this.crossEventProducer,W,r,st,L,this.canvasBoundsContainer,this.paneManager,a,V.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new vu(r,xt,_,u,J,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel,this.chartModel),this.chartComponents.push(this.crossToolComponent);const ya=le(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),_n=new rg(this.elements,ya);this.snapshotComponent=_n,this.chartComponents.push(_n);const xs=new Uu(r,this.dynamicObjectsCanvasModel,H,st,_,u,l,this.cursorHandler);this.eventsComponent=xs,this.chartComponents.push(xs),this.chartComponents.forEach(xm=>xm.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=El(this.components)}initYAxisDrawer(t,e){const s=new on,i=new ye(t),r=new ye(e);s.addDrawer(i,"YAXIS_CLEAR"),s.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(s,"Y_AXIS");const o=new pp(this.config,t,this.paneManager);s.addDrawer(o);const a=new gp(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:s=>e.test(s)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const s in e)s in t?typeof t[s]=="object"&&xn.mergeConfig(t[s],e[s]):t[s]=e[s];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,s,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(s=t.dash)!=null?s:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){At(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(s).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,s=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,s).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(s).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=yt(this.canvasInputListener.observeYDrag(s),this.canvasInputListener.observeXDrag(s)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const s=t(this);this.components.push(s),e&&e(s),s.activate()}}class pa extends xn{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var s;(s=this.paneManager.panes[t])==null||s.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.setAllSeries(e,s)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.updateAllSeries(e,s)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}setTreasuryFormat(t){this.config.components.yAxis.treasuryFormat=t,this.paneManager.yExtents.forEach(e=>{e.yAxis.model.labelsGenerator.updateTreasuryFormat(t),e.yAxis.model.labelsGenerator.doGenerateLabels(),e.yAxis.model.fancyLabelsModel.updateLabels(!0),e.yAxis.model.baseLabelsModel.updateLabels()})}createPane(){return this.paneManager.createPane()}}var dm=Object.defineProperty,um=Object.defineProperties,fm=Object.getOwnPropertyDescriptors,ma=Object.getOwnPropertySymbols,gm=Object.prototype.hasOwnProperty,pm=Object.prototype.propertyIsEnumerable,va=(n,t,e)=>t in n?dm(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,mm=(n,t)=>{for(var e in t||(t={}))gm.call(t,e)&&va(n,e,t[e]);if(ma)for(var e of ma(t))pm.call(t,e)&&va(n,e,t[e]);return n},vm=(n,t)=>um(n,fm(t));function ba(n){n=n||{},n.quantity=n.quantity||200,n.startY=n.startY||50,n.avgCandleSize=n.avgCandleSize||2,n.avgTrendLength=n.avgTrendLength||{},n.avgTrendLength.sw=n.avgTrendLength.sw||10,n.avgTrendLength.down=n.avgTrendLength.down||10,n.avgTrendLength.up=n.avgTrendLength.up||10,n.withVolume=n.withVolume===!0||!1,n.period=n.period||3600;var t=[],e=n.quantity||200,s=10,i=10,r=10;n.avgTrendLength&&(s=n.avgTrendLength.sw||10,i=n.avgTrendLength.down||10,r=n.avgTrendLength.up||10);var o=n.startY||50,a=n.avgCandleSize||2,l=o-a,c=o+a,h=Ss(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ym(t[t.length-1],a,s)):d>3?t=t.concat(bm(t[t.length-1],a,r)):t=t.concat(Cm(t[t.length-1],a,i))}t=t.slice(0,n.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*n.period;for(let f=0;f<t.length;f++){const g=t[f];Object.assign(g,{timestamp:u,isVisible:!0}),u+=1e3*n.period,n.withVolume&&(g.volume=Math.ceil(Math.random()*1e3+200))}return t}function Ss(n,t,e,s){var i=Math.random()*(t-n)+n,r;if(s&&s==="bull"||!s&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>n?a:n}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:xi(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function bm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.lo,o=n.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),s.push(c)}return s}function Cm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.hi-t*1.2,o=n.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),s.push(c)}return s}function ym(n,t,e){var s=[],i=Math.random()*e+e/2;function r(u){var f,g;return Math.random()>.5?(f=u.lo-t*.2,g=u.hi+t*1.2):(f=u.lo-t*1.2,g=u.hi+t*.2),{from:f,to:g}}for(var o=r(n),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=Ss(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),s.push(d)}return s}window.DXChart=vm(mm({},window.DXChart),{generateCandlesData:ba});function wm(n){return ba(n)}const Sm=((n,t={})=>new pa(n,t))})(),window.DXChart=Ps})();})();
24
+ `);function wc(n){const t=document.createElement("template");return t.innerHTML=yc(n.devexpertsPromoLink),t}function Sc(n){const t={},e=Array.from(n.querySelectorAll("[data-element]"));if(e.length!==0&&e.forEach(s=>{var i;t[(i=s.getAttribute("data-element"))!=null?i:""]=s}),Cc(t))return t;throw new Error("Some chart elements are missing")}function xc(n){if(n.length>1){const t=n.reduce((i,r,o)=>{if(o!==n.length-1){const a=n[o+1].timestamp-r.timestamp;i[a]?i[a]++:i[a]=1}return i},{});let e=0,s;for(const i of Object.keys(t)){const r=parseInt(i,10),o=t[r];o>e&&r>0&&(e=o,s=r)}if(s)return s}}const _c=n=>t=>n?new Date(t).setHours(0,0,0,0):t,Oe=(n,t={},e,s=1e3)=>{var i,r,o,a;const{extrapolate:l,isDaysPeriod:c}=t,h=!!l,d=_c(!!c),u=d(n),f=d((r=(i=ge(e))==null?void 0:i.timestamp)!=null?r:0),g=d((a=(o=St(e))==null?void 0:o.timestamp)!=null?a:0);return u>g?h?{index:e.length-1+Math.ceil((u-g)/s),exact:!0}:{index:e.length-1,exact:!0}:u<f?h?{index:at((u-f)/s),exact:!0}:{index:-1,exact:!0}:Yt(e,u,m=>d(m.timestamp))},Vm=n=>{const t=n[0],e=n[n.length-1];return n.length>0&&[t,e].some(s=>s!==void 0&&s.impVolatility!==null&&s.impVolatility!==void 0&&!isNaN(s.impVolatility))},zi={color:"#FF00FF",lineWidth:1,hoveredLineWidth:2,offset:0},Vi={paintConfig:[zi],type:"LINEAR",highLowActive:!0,visible:!0,labelLastValue:"viewport",labelMode:"label",labelAppearanceType:"badge"};var Pc=Object.defineProperty,Ui=Object.getOwnPropertySymbols,Tc=Object.prototype.hasOwnProperty,Mc=Object.prototype.propertyIsEnumerable,Gi=(n,t,e)=>t in n?Pc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ac=(n,t)=>{for(var e in t||(t={}))Tc.call(t,e)&&Gi(n,e,t[e]);if(Ui)for(var e of Ui(t))Mc.call(t,e)&&Gi(n,e,t[e]);return n};class Ec{constructor(t,e,s,i){this.series=t,this.config=e,this.yAxisBoundsProvider=s,this.axisState=i}getUnorderedLabels(){if(!this.config.visible)return[];const e=this.config.labelLastValue==="series"?this.series.getLastDataSeriesPoint:this.series.getLastVisualSeriesPoint,s=this.yAxisBoundsProvider(),i=this.config.labelMode,r=this.config.labelAppearanceType,o=e();if(o===void 0)return[];const a=this.series.view.toY(o.close);if(!isFinite(a))return[];const l=this.series.valueFormatter(o.close),c=this.getLabelDrawConfig();return[{labels:[Ac({y:a,description:this.series.name,mode:i,labelType:r,labelText:l},c)],axisState:this.axisState,bounds:s}]}getLabelDrawConfig(){var t;const e=this.series.config,i=((t=e.paintConfig[0])!=null?t:zi).color;return{textColor:se(i,"white","black"),bgColor:i,paddingBottom:e.labelPaddingBottom,paddingEnd:e.labelPaddingEnd,paddingTop:e.labelPaddingTop}}}function Ic(n,t){if(n.filter(a=>a!==null).length<=1)return n.map(a=>a.y);const e=t-2,s=n.map((a,l)=>Dc(a,l,e)).filter(li).sort(Lc),i=new Array(s.length),r=s.reduce((a,l)=>Math.min(a,l.labelWeight),Number.POSITIVE_INFINITY),o=s.findIndex(a=>a.labelWeight===r);for(let a=o;a>=0;a--){const l=s[a],c=s[a-1];if(l){if(c&&c.bottom>l.top){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.bottom=l.top-h,c.top=c.bottom-t}i[l.actualIndex]=(l.top+l.bottom)/2}}for(let a=o;a<s.length;a++){const l=s[a],c=s[a+1];if(!l)break;if(c&&c.top<l.bottom){const h=Math.abs(c.labelWeight-l.labelWeight)===1?2:0;c.top=l.bottom+h,c.bottom=c.top+t}i[l.actualIndex]=(l.top+l.bottom)/2}return i}const Dc=(n,t,e)=>n?{top:n.y-e/2,bottom:n.y+e/2,labelWeight:n.weight,actualIndex:t}:null,Lc=(n,t)=>{const e=n.top,s=t.top;return e>s?1:e<s||e===s&&n.labelWeight<t.labelWeight?-1:0};var Oc=Object.defineProperty,Bc=Object.defineProperties,Rc=Object.getOwnPropertyDescriptors,Zi=Object.getOwnPropertySymbols,Fc=Object.prototype.hasOwnProperty,Hc=Object.prototype.propertyIsEnumerable,$i=(n,t,e)=>t in n?Oc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ki=(n,t)=>{for(var e in t||(t={}))Fc.call(t,e)&&$i(n,e,t[e]);if(Zi)for(var e of Zi(t))Hc.call(t,e)&&$i(n,e,t[e]);return n},qi=(n,t)=>Bc(n,Rc(t));const ie={MAIN:"MAIN"};class kc extends X{constructor(t,e,s,i,r,o,a,l){super(),this.eventBus=t,this.scale=e,this.canvasBoundsContainer=s,this.state=i,this.canvasModel=r,this.paneUUID=o,this.updateYAxisWidth=a,this.chartResizeHandler=l,this.orderedLabels=[],this.customLabels={},this._labelsProviders={},this.labelsPositionRecalculatedSubject=new F,this.animFrameId=`anim_cache_${wt()}`,this.initModel()}get labelsProviders(){return this._labelsProviders}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.canvasBoundsContainer.barResizerChangedSubject,this.scale.changed,yt(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(this.paneUUID)),this.chartResizeHandler.canvasResized).pipe(Lt(50,Rt,{trailing:!0,leading:!0}))).subscribe(()=>{this.updateLabels()}))}initModel(){this.initLabelsGroups(),this.recalculateLabels(),this.canvasModel.fireDraw()}initLabelsGroups(){for(const t of Object.keys(this.labelsProviders))this.createGroup(t),Object.entries(this.labelsProviders[t]).forEach(([e,s])=>{this.addToGroup(s,t,e)})}updateLabels(t=!1){this.recalculateLabels(),Pe(this.animFrameId,()=>{t&&this.updateYAxisWidth(),this.canvasModel.fireDraw()})}recalculateLabels(){var t,e;this.orderedLabels=[];const s=this.state.fontSize+((t=this.state.labelBoxMargin.top)!=null?t:0)+((e=this.state.labelBoxMargin.bottom)!=null?e:0);for(const i of Object.values(this.labelsProviders)){const r=mt(Object.values(i).map(l=>l.getUnorderedLabels())),o=mt(r.map(l=>l.labels)).map(l=>{var c;return{y:l.y,weight:(c=l.labelWeight)!=null?c:Number.POSITIVE_INFINITY}}),a=Ic(o,s);r.forEach(l=>{const c=a.splice(0,l.labels.length);this.orderedLabels.push(this.updateLabelsCoordinates(l,c))})}this.orderedLabels=this.orderedLabels.reverse()}createGroup(t){!this.labelsProviders[t]&&(this.labelsProviders[t]={})}addToGroup(t,e,s){this.labelsProviders[e]&&(Object.values(this.labelsProviders[e]).includes(t)||(this.labelsProviders[e][s]=t))}updateLabelsCoordinates(t,e){return qi(Ki({},t),{labels:t.labels.map((s,i)=>qi(Ki({},s),{lineY:s.y,y:e[i]}))})}observeLabelsPositionsRecalculated(){return this.labelsPositionRecalculatedSubject.asObservable()}registerYAxisLabelsProvider(t,e,s){var i;const r=(i=this.labelsProviders[t])!=null?i:{};r[s]=e,this.labelsProviders[t]=r,this.initModel()}unregisterYAxisLabelsProvider(t,e){var s;const i=(s=this.labelsProviders[t])!=null?s:{};delete i[e],this.labelsProviders[t]&&Object.keys(this.labelsProviders[t]).length===0&&delete this.labelsProviders[t],this.initModel()}}let Ft=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);const Ks=()=>{rs.removeEventListener("change",Ks),Ft=window.devicePixelRatio,rs=window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`),rs.addEventListener("change",Ks)};rs.addEventListener("change",Ks);const jc=()=>Ft,Um=n=>round(Ft*n)/Ft,Et=n=>at(Ft*n)/Ft,qs=n=>pl(Ft*n)/Ft,re=n=>JSON.parse(JSON.stringify(n));function Js(n){return Object.entries(n)}const Ji=(n,t)=>{for(const[e,s]of Array.from(n.entries()))if(s===t)return e};function Qi(n){return Object.keys(n)}function tr(n,t){if(Object.is(n,t))return!0;if(typeof n!="object"||n===null||typeof t!="object"||t===null)return!1;const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;for(let i=0,r=e.length;i<r;i++)if(!hasOwnProperty.call(t,e[i])||!tr(n[e[i]],t[e[i]]))return!1;return!0}const Yc=n=>Object.keys(n).length===0&&n.constructor===Object;function er(n){n===void 0&&(n={});var t=n.connector,e=t===void 0?function(){return new F}:t,s=n.resetOnError,i=s===void 0?!0:s,r=n.resetOnComplete,o=r===void 0?!0:r,a=n.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var h,d,u,f=0,g=!1,m=!1,x=function(){d==null||d.unsubscribe(),d=void 0},_=function(){x(),h=u=void 0,g=m=!1},A=function(){var L=h;_(),L==null||L.unsubscribe()};return N(function(L,Y){f++,!m&&!g&&x();var H=u=u!=null?u:e();Y.add(function(){f--,f===0&&!m&&!g&&(d=Qs(A,l))}),H.subscribe(Y),!h&&f>0&&(h=new _e({next:function(B){return H.next(B)},error:function(B){m=!0,x(),d=Qs(_,i,B),H.error(B)},complete:function(){g=!0,x(),d=Qs(_,o),H.complete()}}),Dt(L).subscribe(h))})(c)}}function Qs(n,t){for(var e=[],s=2;s<arguments.length;s++)e[s-2]=arguments[s];if(t===!0){n();return}if(t!==!1){var i=new _e({next:function(){i.unsubscribe(),n()}});return Dt(t.apply(void 0,ot([],R(e)))).subscribe(i)}}const os=(n,t)=>n/t,vt=(n,t)=>n/t,Ht=(n,t)=>n*t,sr=(n,t)=>(n-t)*100/t,nr=(n,t)=>n*t/100+t,ir=n=>Math.log2(n),tn=n=>Math.pow(2,n);class Nc extends X{constructor(){super(...arguments),this._xStart=0,this._xEnd=0,this._yStart=0,this._yEnd=0,this._zoomX=1,this._zoomY=1,this._inverseY=!1,this.changed=new F,this.xChanged=this.changed.pipe(dt(()=>({start:this.xStart,end:this.xEnd})),Tt((t,e)=>t.start===e.start&&t.end===e.end),er()),this.yChanged=this.changed.pipe(dt(()=>({start:this.yStart,end:this.yEnd})),Tt((t,e)=>t.start===e.start&&t.end===e.end),er()),this.initialViewportValidSubject=new ft(!1)}doActivate(){super.doActivate(),this.addRxSubscription(this.changed.subscribe(()=>{!this.initialViewportValidSubject.getValue()&&this.initialViewportValidSubject.next(this.isViewportValid())}))}doDeactivate(){super.doDeactivate(),this.changed.complete()}toX(t){return this.getBounds().x+vt(t-this.xStart,this.zoomX)}xPixels(t){return vt(t,this.zoomX)}toY(t){const e=this.getBounds();return this.inverseY?e.y+vt(t-this.yStart,this.zoomY):e.y+e.height-vt(t-this.yStart,this.zoomY)}yPixels(t){return vt(t,this.zoomY)}fromX(t){const e=t-this.getBounds().x;return Ht(e+vt(this.xStart,this.zoomX),this.zoomX)}fromY(t){const e=this.getBounds(),s=t-e.y;return this.inverseY?Ht(s+vt(this.yStart,this.zoomY),this.zoomY):Ht(e.height-s+vt(this.yStart,this.zoomY),this.zoomY)}recalculateZoomX(){this.zoomX=this.calculateZoomX(this.xStart,this.xEnd)}recalculateZoomY(){this.zoomY=this.calculateZoomY(this.yStart,this.yEnd)}calculateZoomX(t,e){return os(e-t,this.getBounds().width)}calculateZoomY(t,e){return os(e-t,this.getBounds().height)}recalculateZoom(t=!0){this.recalculateZoomX(),this.recalculateZoomY(),t&&this.fireChanged()}setXScale(t,e,s=!0){this.xStart=t,this.xEnd=e,this.recalculateZoomX(),s&&this.fireChanged()}setYScale(t,e,s=!0){this.yStart=t,this.yEnd=e,this.recalculateZoomY(),s&&this.fireChanged()}export(){return{xStart:this.xStart,xEnd:this.xEnd,yStart:this.yStart,yEnd:this.yEnd,zoomX:this.zoomX,zoomY:this.zoomY,inverseY:this.inverseY}}apply(t){this.xStart=t.xStart,this.xEnd=t.xEnd,this.yStart=t.yStart,this.yEnd=t.yEnd,this.zoomX=t.zoomX,this.zoomY=t.zoomY,this.inverseY=t.inverseY,this.fireChanged()}fireChanged(){this.changed.next()}get xStart(){return this._xStart}set xStart(t){this._xStart=t}get xEnd(){return this._xEnd}set xEnd(t){this._xEnd=t}get yStart(){return this._yStart}set yStart(t){this._yStart=t}get yEnd(){return this._yEnd}set yEnd(t){this._yEnd=t}get zoomX(){return this._zoomX}set zoomX(t){this._zoomX=t}get zoomY(){return this._zoomY}set zoomY(t){this._zoomY=t}get inverseY(){return this._inverseY}set inverseY(t){this._inverseY=t}isViewportValid(t=!0){const e=t===!1||this.zoomX>0&&this.zoomY>0;return this.xStart!==this.xEnd&&this.yStart!==this.yEnd&&isFinite(this.yStart)&&isFinite(this.yEnd)&&e}}const Xc=(n,t)=>!Qi(n).some(e=>n[e]!==t[e]);class Wc{constructor(t,e){this.scale=t,this.dataSeries=e,this.prevAnimationId=""}getBaselineForPercent(t){const e=this.scale.currentAnimation;let s;if(e!=null&&e.animationInProgress){e.id!==this.prevAnimationId&&(this.initialBaseline=void 0,this.targetBaseline=void 0,this.prevAnimationId=e.id);const i=e.easingFn(e.getProgress());this.initialBaseline===void 0&&(this.initialBaseline=t(Yt(this.dataSeries.visualPoints,e.xStart,r=>r.centerUnit).index)),this.targetBaseline===void 0&&(this.targetBaseline=t(Yt(this.dataSeries.visualPoints,e.animationConfig.targetXStart,r=>r.centerUnit).index)),s=this.initialBaseline+(this.targetBaseline-this.initialBaseline)*i}else s=t();return s}}class rr{constructor(t,e,s,i){this.dataSeries=t,this.scale=e,this.getAxisType=s,this.getBaseline=i,this.toY=r=>this.scale.toY(this.toAxisUnits(r)),this.toX=r=>this.scale.toX(r),this.xPixels=r=>this.scale.xPixels(r),this.yPixels=r=>this.scale.yPixels(r),this.percentAnimationHandler=new Wc(this.scale,this.dataSeries)}toAxisUnits(t,e=this.getBaseline){switch(this.getAxisType()){case"percent":const s=this.percentAnimationHandler.getBaselineForPercent(e);return sr(t,s);case"logarithmic":return t<=0?t:ir(t);case"regular":return t}}priceFromY(t){const e=this.scale.fromY(t);return this.fromAxisUnits(e)}fromAxisUnits(t){switch(this.getAxisType()){case"percent":return nr(t,this.getBaseline());case"logarithmic":return tn(t);case"regular":return t}}}const Zt=16;var zc=Object.defineProperty,Vc=Object.defineProperties,Uc=Object.getOwnPropertyDescriptors,or=Object.getOwnPropertySymbols,Gc=Object.prototype.hasOwnProperty,Zc=Object.prototype.propertyIsEnumerable,ar=(n,t,e)=>t in n?zc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,lr=(n,t)=>{for(var e in t||(t={}))Gc.call(t,e)&&ar(n,e,t[e]);if(or)for(var e of or(t))Zc.call(t,e)&&ar(n,e,t[e]);return n},$c=(n,t)=>Vc(n,Uc(t));class Be{constructor(t,e){this.centerUnit=t,this.close=e}y(t){return Et(t.toY(this.close))}x(t){return t.toX(this.centerUnit)}clone(){return new Be(this.centerUnit,this.close)}}class cr extends X{constructor(t,e,s,i,r){var o;super(),this.extentComponent=t,this.id=e,this.htId=s,this.parentId=i,this.name="",this.highlighted=!1,this._dataPoints=[],this.pricePrecisions=[2],this.linkedDataSeriesModels=[],this._dataPointsFlat=[],this._visualPoints=[],this._visualPointsFlat=[],this.dataIdxStart=0,this.dataIdxEnd=0,this.getPaintConfig=l=>{var c;return(c=this.config.paintConfig[l])!=null?c:this.config.paintConfig[0]},this.getBaseline=(l=this.dataIdxStart)=>{var c,h,d;return(c=this.visualPoints[l])!=null&&c.close&&((h=this.visualPoints[l])==null?void 0:h.close)>=0?(d=this.visualPoints[l])==null?void 0:d.close:1},this.getTextForPoint=l=>`${l.close}`,this.getLastVisualSeriesPoint=()=>{const l=this.visualPoints;if(l.length!==0)return l[this.dataIdxEnd]},this.getLastDataSeriesPoint=()=>{const l=this.visualPoints;return St(l)};const a=r!=null?r:re(Vi);this.config=At(a,Vi),this.scale=t.scale,this.view=new rr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider=new Ec(this,this.config,t.getYAxisBounds,(o=t.yAxis)==null?void 0:o.state),this.highLowProvider=qc(this),t.addDataSeries(this),this.activate()}get dataPoints2D(){return this._dataPoints}get dataPoints(){return this._dataPointsFlat}set dataPoints(t){this._dataPoints=di(t),this._dataPointsFlat=this._dataPoints.flat(),this.visualPoints=this._toVisualPoints(this._dataPoints)}get visualPoints(){return this._visualPointsFlat}get visualPoints2D(){return this._visualPoints}set visualPoints(t){this._visualPoints=di(t),this._visualPointsFlat=this._visualPoints.flat()}doActivate(){this.addRxSubscription(this.scale.xChanged.pipe(Lt(Zt,Rt,{trailing:!0,leading:!0}),dt(()=>this.calculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)),Tt((t,e)=>t.dataIdxStart===e.dataIdxStart&&t.dataIdxEnd===e.dataIdxEnd)).subscribe(()=>{this.recalculateDataViewportIndexes(this.scale.xStart,this.scale.xEnd)})),this.addRxSubscription(this.scale.scaleInversedSubject.subscribe(()=>{this.recalculateVisualPoints(),this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}))}setDataPoints(t){this.dataPoints=t,this.extentComponent.paneComponent.updateView()}_toVisualPoints(t){return t.map(e=>this.toVisualPoints(e))}moveToExtent(t){var e;const s=lr({},this.extentComponent);this.extentComponent.removeDataSeries(this),this.extentComponent=t,this.scale=t.scale,this.view=new rr(this,this.scale,()=>this.extentComponent.yAxis.getAxisType(),this.getBaseline),this.yAxisLabelProvider.yAxisBoundsProvider=t.getYAxisBounds,this.yAxisLabelProvider.axisState=(e=t.yAxis)==null?void 0:e.state;const i=s.yAxis.model.fancyLabelsModel.labelsProviders[ie.MAIN],r=i&&Object.keys(i).find(a=>this.parentId&&a===this.parentId),o=this.extentComponent.yAxis.model.fancyLabelsModel.labelsProviders[ie.MAIN];if(r){const a=i[r];a.yAxisBoundsProvider=t.getYAxisBounds,(!o||o&&!o[r])&&(this.extentComponent.yAxis.model.fancyLabelsModel.registerYAxisLabelsProvider(ie.MAIN,a,r),s.yAxis.model.fancyLabelsModel.unregisterYAxisLabelsProvider(ie.MAIN,r))}this.deactivate(),this.activate(),t.addDataSeries(this)}toVisualPoints(t){return t.map((e,s)=>({centerUnit:s,close:e.close}))}setType(t){this.config.type=t,this.extentComponent.dynamicObjectsCanvasModel.fireDraw()}recalculateVisualPoints(){this.visualPoints=this._toVisualPoints(this.dataPoints2D)}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.centerUnit).index,i=Yt(this.visualPoints,e,r=>r.centerUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}valueFormatter(t){return this.extentComponent.formatters.regular(t)}getSeriesInViewport(t,e){let s=this.dataIdxStart,i=this.dataIdxEnd;if(e!==void 0&&t!==void 0){const r=this.calculateDataViewportIndexes(t,e);s=r.dataIdxStart,i=r.dataIdxEnd}return Ol(this.visualPoints2D,s,i)}}const Kc=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.close>t.high&&(t.high=s.close,t.highIdx=e),s.close<t.low&&(t.low=s.close,t.lowIdx=e)}return t},qc=n=>({isHighLowActive:()=>n.config.highLowActive&&n.config.visible,calculateHighLow:t=>{const e=Kc(n.getSeriesInViewport(t==null?void 0:t.xStart,t==null?void 0:t.xEnd).flat());return $c(lr({},e),{high:n.view.toAxisUnits(e.high),low:n.view.toAxisUnits(e.low)})}}),Jc=n=>{const e=r=>Math.ceil(Math.log(Math.abs(r))*Math.LOG10E),i=((r,o=5)=>Math.max(0,o-Math.max(0,e(r))))(n);return gt.makeDecimal(n,i)};class as extends Be{constructor(t,e,s,i,r,o,a,l,c=!1,h=!1,d=!1){super(t,i),this.startUnit=t-e/2,this.endUnit=t+e/2,this.width=e,this.open=s,this.high=r,this.low=o,this.name=a,this.candle=l,this.hasBorder=c,this.isActive=h,this.isHollow=d}bodyHeight(t){return Math.max(Math.abs(t.toY(this.open)-t.toY(this.close)),1)}candleHeight(t){return Math.abs(t.toY(this.high)-t.toY(this.low))}bodyAsVLine(t){if(this.width<2)return[this.centerUnit,this.yLineStart(t),this.width,this.candleHeight(t)]}bodyRect(t){return[this.startUnit,this.yBodyStart(t),this.width,this.bodyHeight(t)]}getCandle(){return this.candle}yBodyKeyPoints(t){const e=t.toY(this.high),s=t.toY(this.low),i=t.toY(this.open),r=t.toY(this.close),[o,a]=i>r?[r,i]:[i,r],[l,c]=e>s?[s,e]:[e,s];return[l,o,a,c]}yLineEnd(t){return Math.max(t.toY(this.high),t.toY(this.low))}yLineStart(t){return Math.min(t.toY(this.high),t.toY(this.low))}yBodyStart(t){return Math.min(t.toY(this.open),t.toY(this.close))}yBodyEnd(t){return Math.max(t.toY(this.open),t.toY(this.close))}xCenter(t){return this.x(t)}xStart(t){return t.toX(this.startUnit)}}const me=60,Re=(n,t,e=me)=>{const s=hr(n,t,e);return{id:xi(s,s),hi:NaN,lo:NaN,open:NaN,close:NaN,timestamp:s,volume:NaN,expansion:!0,idx:t}},Qc=(n,t,e=me)=>({close:NaN,timestamp:hr(n,t,e)});function hr(n,t,e=me){var s,i;const r=Me(t);if(n.length===0)return 0;const o=St(n);if(r>=n.length&&o)return dr(o,n.length-1,r,e);const a=ge(n);return r<0&&a?dr(a,0,r,e):(i=(s=n[r])==null?void 0:s.timestamp)!=null?i:0}const dr=(n,t,e,s=me)=>n.timestamp+(e-(t!=null?t:0))*s,en=(n,t,e,s,i=me)=>{const r=Re(n,s,i);r.volume=e;let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new as(o,e,r.open,r.close,r.lo,r.hi,ts(r.open,r.close),r)},th=(n,t,e,s,i=me)=>{const r=Qc(n,s,i);let o;if(t.length===0)o=0;else if(s>=t.length){const a=t[t.length-1],c=(s-(t.length-1))*e;o=a.centerUnit+c}else{const a=t[0],c=-s*e;o=a.centerUnit-c}return new Be(o,r.close)};class eh{constructor(t){this.type=t,this.mainDataPoints=[],this.mainVisualPoints=[],this.dataUpdatedSubject=new F,this.dataSetSubject=new F,this.dataRemovedSubject=new F,this.dataPrependSubject=new F,this.meanDataWidth=1,this.period=1}dataFromTimestamp(t,e={extrapolate:!0},s=this.mainDataPoints){const i=Oe(t,e,s,this.period);return this.dataFromIdx(i.index)}recalculatePeriod(){const t=xc(this.mainDataPoints);t&&(this.period=t)}dataFromIdx(t){const e=this.mainVisualPoints[t];return e||(this.type==="candle"?en(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period):th(this.mainDataPoints,this.mainVisualPoints,this.meanDataWidth,t,this.period))}}var sh=Object.defineProperty,ur=Object.getOwnPropertySymbols,nh=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,fr=(n,t,e)=>t in n?sh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,rh=(n,t)=>{for(var e in t||(t={}))nh.call(t,e)&&fr(n,e,t[e]);if(ur)for(var e of ur(t))ih.call(t,e)&&fr(n,e,t[e]);return n};class oh{constructor(t,e,s=()=>!0){this.canvasModel=t,this.config=e,this.drawPredicate=s,this.prevState={},this.isColorsChanged=()=>!tr(this.config.colors.chartAreaTheme,this.prevState)}draw(){if(this.drawPredicate()||this.isColorsChanged()){this.canvasModel.clear();const t=this.canvasModel.ctx;if(this.config.colors.chartAreaTheme.backgroundMode==="gradient"){const e=t.createLinearGradient(0,0+this.canvasModel.height/2,this.canvasModel.width,0+this.canvasModel.height/2);e.addColorStop(0,this.config.colors.chartAreaTheme.backgroundGradientTopColor),e.addColorStop(1,this.config.colors.chartAreaTheme.backgroundGradientBottomColor),t.fillStyle=e}else t.fillStyle=this.config.colors.chartAreaTheme.backgroundColor;t.fillRect(0,0,this.canvasModel.width,this.canvasModel.height)}this.prevState=rh({},this.config.colors.chartAreaTheme)}getCanvasIds(){return[this.canvasModel.canvasId]}}const ah=(n,t,e,s,i,r,o)=>{const a=jc(),l=[e*a,s*a,i*a,r*a];let c=n.getImageData(...l);if(o!==void 0){const h=c.data[3]/255;if(h===1)for(let d=3;d<c.data.length;d+=4)c.data[d]=at(c.data[d]*o);else for(let d=0;d<c.data.length;d++){const u=c.data[d];c.data[d]=d%4===3?at(u*o):at(h*u)}c=new ImageData(c.data,c.width,c.height,{colorSpace:c.colorSpace})}t.putImageData(c,l[0],l[1])},gr=(n,{x:t,width:e,activeCandle:s})=>new as(t,e,n.open,n.close,n.hi,n.lo,ts(n.open,n.close),n,!0,sn(n,s)),lh=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,Ul((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,sn(n,s),n.close>n.open)},pr=(n,{x:t,width:e,activeCandle:s,prevCandle:i})=>{var r;return new as(t,e,n.open,n.close,n.hi,n.lo,ts((r=i==null?void 0:i.close)!=null?r:n.close,n.close),n,!0,sn(n,s),n.close>n.open)},ch=pr,sn=(n,t)=>{const e=t&&t.id===n.id;return e!=null?e:!1},mr=()=>Vs,Fe=class ce{static autoDetectIncrementOfValueRange(t){const e=this.getDigitsInNumber(t);return t===0?.01:Math.pow(10,e-3)}static getDigitsInNumber(t){const e=i=>at(Math.log10((i^i>>31)-(i>>31)))+1;let s=e(t);return s===1&&t<1&&(s=e(t*1e9)-9),s}static getPriceIncrement(t,e=[]){if(!this.validatePriceIncrementsOrPrecisions(e))return this.DEFAULT_INCREMENT;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;const i=1e-6;for(;s<e.length&&t>e[s]+Math.min(e[s-1],e[s+1])*i;)s+=2;return s>=e.length||t<e[s]-Math.min(e[s-1],e[s+1])*i?e[s-1]:Math.min(e[s-1],e[s+1])}static getPricePrecision(t,e){if(!this.validatePriceIncrementsOrPrecisions(e))return 0;if(isNaN(t))return Math.round(e[0]);t=Math.abs(t);let s=1;for(;s<e.length&&t>e[s];)s+=2;return Math.round(e[s-1])}static roundPriceToIncrement(t,e,s){const i=ce.getPriceIncrement(s||t,e);return gt.roundToNearest(t,i)}static computePrecisions(t){const e=[...t];for(let s=0;s<t.length;s+=2)e[s]=ce.calculatePrecision(t[s]);for(let s=1;s<t.length;s+=2)e[s]=t[s]+Math.min(t[s-1],t[s+1])*ce.RELATIVE_EPS;return e}static calculatePrecision(t){let e=t>1?Math.abs(Math.floor(t)-t):t;for(let s=0;s<ce.MAXIMUM_PRECISION;s++){const i=Math.floor(e+.5),r=Math.abs(e*ce.RELATIVE_EPS);if(i>=e-r&&i<=e+r)return s;e*=10}return ce.MAXIMUM_PRECISION}static validatePriceIncrementsOrPrecisions(t){return!(t.length===0||!Array.isArray(t)||t.findIndex(e=>e!==0)===-1)}};Fe.DEFAULT_INCREMENT=.01,Fe.DEFAULT_PRECISION=2,Fe.RELATIVE_EPS=1e-8,Fe.MAXIMUM_PRECISION=10;let ve=Fe;const hh=(n,t)=>{var e;const s=(e=St(t))!=null?e:1;return Math.pow(10,-s)};var dh=Object.defineProperty,uh=Object.defineProperties,fh=Object.getOwnPropertyDescriptors,vr=Object.getOwnPropertySymbols,gh=Object.prototype.hasOwnProperty,ph=Object.prototype.propertyIsEnumerable,br=(n,t,e)=>t in n?dh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,mh=(n,t)=>{for(var e in t||(t={}))gh.call(t,e)&&br(n,e,t[e]);if(vr)for(var e of vr(t))ph.call(t,e)&&br(n,e,t[e]);return n},vh=(n,t)=>uh(n,fh(t));const bh=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=t?t.xStart:n.scale.xStart,s=t?t.xEnd:n.scale.xEnd,{dataIdxStart:i,dataIdxEnd:r}=n.calculateDataViewportIndexes(e,s),o=n.visualPoints.slice(i,r+1),a=Cr(o),l=()=>{var c,h;return(h=(c=n.visualPoints[i])==null?void 0:c.close)!=null?h:1};return vh(mh({},a),{low:n.view.toAxisUnits(a.low,l),high:n.view.toAxisUnits(a.high,l)})}}),Cr=n=>{const t={high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER,highIdx:0,lowIdx:0};for(let e=0;e<n.length;e++){const s=n[e];s.high>t.high&&(t.high=s.high,t.highIdx=e),s.low<t.low&&(t.low=s.low,t.lowIdx=e)}return t};class Ch{constructor(t,e){this.delegate=t,this.highLowPostProcessor={},this.highLowProviders=e!=null?e:{}}setHighLowProvider(t,e){this.highLowProviders[t]=e}deleteHighLowProvider(t){delete this.highLowProviders[t]}setHighLowPostProcessor(t,e){this.highLowPostProcessor[t]=e}doAutoYScale(t){yh(this.delegate,t,Object.values(this.highLowProviders),Object.values(this.highLowPostProcessor))}}const yh=(n,t,e,s)=>{const i=e.filter(a=>a.isHighLowActive()).map(a=>a.calculateHighLow(t)),r=yr(i),o=s.reduce((a,l)=>l(a),r);t.yStart=o.low,t.yEnd=o.high,t.zoomY=n.calculateZoomY(t.yStart,t.yEnd)};function yr(n){if(n.length===0)return wh();let t=n[0].high,e=n[0].low;return n.forEach(s=>{isFinite(s.high)&&s.high>=t&&(t=s.high),isFinite(s.low)&&s.low<=e&&(e=s.low)}),{low:e,high:t}}const wh=()=>({high:Number.MIN_SAFE_INTEGER,low:Number.MAX_SAFE_INTEGER}),wr=(n,t)=>n/t,Sh=(n,t)=>n/t,xh=(n,t)=>n*t,Sr=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=wr(e,s),r=n.yEnd-n.yStart;t.zoomY=Sh(t.zoomX,i);const o=t.zoomY/s,l=r*o-r;t.yEnd=t.yEnd+l/2,t.yStart=t.yStart-l/2},_h=(n,t)=>{const e=n.zoomX,s=n.zoomY,i=wr(e,s),r=n.xEnd-n.xStart;t.zoomX=xh(t.zoomY,i);const o=t.zoomX/e,l=r*o-r;t.xStart=t.xStart-l},Ph=(n,t)=>{const e=n.xStart;n.xStart=t,n.xEnd=n.xEnd+(t-e)},Th=(n,t)=>{const e=n.yStart;n.yStart=t,n.yEnd=n.yEnd+(t-e)},xr=(n,t,e,s,i)=>{const r=(t.xEnd-t.xStart)*s,o=r*e,a=r*(1-e);return i?(t.xStart=t.xStart+o,t.xEnd=t.xEnd-a):(t.xStart=t.xStart-o,t.xEnd=t.xEnd+a),t.zoomX=n.calculateZoomX(t.xStart,t.xEnd),t},Mh=(n,t,e,s)=>xr(n,t,1,e,s),Ah=Ee,Eh=.9,Ih=(n,t,e,s)=>{t.currentAnimation&&t.currentAnimation.animationInProgress&&t.currentAnimation.getProgress()>Eh&&(t.currentAnimation.finishAnimation(),t.currentAnimation=void 0),s&&s.doAutoYScale(e),ls(n,t,e)},ls=(n,t,e)=>{const s=n.startViewportMovementAnimation(t,{duration:Ah,targetXStart:e.xStart,targetXEnd:e.xEnd,targetYStart:e.yStart,targetYEnd:e.yEnd,targetZoomX:e.zoomX,targetZoomY:e.zoomY},fe,()=>t.xStart===e.xStart&&t.xEnd===e.xEnd&&t.yStart===e.yStart&&t.yEnd===e.yEnd);t.currentAnimation=s};var Dh=Object.defineProperty,Lh=Object.defineProperties,Oh=Object.getOwnPropertyDescriptors,_r=Object.getOwnPropertySymbols,Bh=Object.prototype.hasOwnProperty,Rh=Object.prototype.propertyIsEnumerable,Pr=(n,t,e)=>t in n?Dh(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,oe=(n,t)=>{for(var e in t||(t={}))Bh.call(t,e)&&Pr(n,e,t[e]);if(_r)for(var e of _r(t))Rh.call(t,e)&&Pr(n,e,t[e]);return n},Tr=(n,t)=>Lh(n,Oh(t));const Fh=new F,Hh=new F,kh=()=>({high:Number.NEGATIVE_INFINITY,low:Number.POSITIVE_INFINITY,highIdx:0,lowIdx:0});class Mr extends Nc{constructor(t,e,s){super(),this.config=t,this.getBounds=e,this.canvasAnimation=s,this.scaleInversedSubject=new F,this.beforeStartAnimationSubject=new F,this.zoomReached={zoomIn:!1,zoomOut:!1},this.history=[],this.xConstraints=[],this.autoScaleZoomSubscription=null,this.autoScalePanSubscription=null,this.scalePostProcessor=(i,r)=>this.xConstraints.reduce((o,a)=>a(i,o),r),this.state=re(t.scale),this.autoScaleModel=new Ch(this),this.offsets=this.config.components.offsets,this.initAutoScaleThrottling()}doActivate(){super.doActivate(),this.scaleInversedSubject=new F,this.beforeStartAnimationSubject=new F,this.zoomReached=this.calculateZoomReached(this.export().zoomX),this.addRxSubscription(this.scaleInversedSubject.subscribe(()=>{this.fireChanged()}))}doDeactivate(){this.autoScaleZoomSubscription&&(this.autoScaleZoomSubscription.unsubscribe(),this.autoScaleZoomSubscription=null),this.autoScalePanSubscription&&(this.autoScalePanSubscription.unsubscribe(),this.autoScalePanSubscription=null),super.doDeactivate(),this.scaleInversedSubject.complete(),this.beforeStartAnimationSubject.complete()}addXConstraint(t){this.xConstraints=[...this.xConstraints,t]}updateOffsets(t){this.offsets=oe(oe({},this.offsets),t),this.doAutoScale(!0)}getOffsets(){return this.offsets}zoomXToPercent(t,e,s=!1,i){const r=this.config.scale.disableAnimations||s;r&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const o=this.export();xr(this,o,t,i,e),this.zoomXTo(o,e,r)}zoomXToEnd(t,e){const s=this.config.scale.disableAnimations||this.config.components.yAxis.type==="percent";s&&this.haltAnimation(),this.beforeStartAnimationSubject.next();const i=this.export();Mh(this,i,e,t),this.zoomXTo(i,t,s)}haltAnimation(){var t;(t=this.currentAnimation)!=null&&t.animationInProgress&&(this.currentAnimation.finishAnimation(),this.currentAnimation=void 0,this.canvasAnimation.forceStopAnimation(fe),this.doAutoScale())}zoomXTo(t,e,s){var i;const r=this.export(),o=this.scalePostProcessor(r,t);this.zoomReached=this.calculateZoomReached(o.zoomX,e),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Sr(r,o),this.state.auto&&this.autoScaleModel.doAutoYScale(o),s?this.apply(o):((i=this.currentAnimation)==null||i.tick(),ls(this.canvasAnimation,this,o)))}calculateZoomReached(t,e=!0){const s=this.getBounds().width,i=.001;if(s>0){const r=os(this.config.components.chart.minCandles,s),a=t!==r&&t-r<=i&&e,l=os(s/this.config.components.chart.minWidth,s),h=t-l>=i&&!e;return{zoomIn:a,zoomOut:h}}return{zoomIn:!1,zoomOut:!1}}setXScale(t,e,s=!0){var i;const r=this.export(),o=this.calculateZoomX(t,e);if(r.xStart===t&&r.xEnd===e&&r.zoomX>0)return;const a=Tr(oe({},r),{zoomX:o,xStart:t,xEnd:e}),l=this.scalePostProcessor(r,a),c=l.xEnd-l.xStart<r.xEnd-r.xStart;this.zoomReached=this.calculateZoomReached(o,c),!(this.zoomReached.zoomIn||this.zoomReached.zoomOut)&&(this.state.lockPriceToBarRatio&&Sr(r,l),this.state.auto&&this.autoScaleModel.doAutoYScale(l),s||this.config.scale.disableAnimations?(this.haltAnimation(),this.apply(l)):((i=this.currentAnimation)==null||i.tick(),Ae?Ih(this.canvasAnimation,this,l,this.state.auto?this.autoScaleModel:void 0):ls(this.canvasAnimation,this,l)))}setXScaleWithoutYScale(t){var e;const s=this.export(),i=t.slice(Math.max(t.length-this.state.defaultViewportItems,0)),r=i[i.length-1],o=r.startUnit+r.width+this.offsets.right,a=o-this.getBounds().width*this.zoomX,l=Tr(oe({},s),{xStart:a,xEnd:o}),c=this.scalePostProcessor(s,l);this.state.auto&&this.autoScaleModel.doAutoYScale(c),(e=this.currentAnimation)==null||e.tick(),ls(this.canvasAnimation,this,c)}setYScale(t,e,s=!1){const i=this.export();if(i.yStart===t&&i.yEnd===e&&i.zoomY>0)return;if(this.state.lockPriceToBarRatio&&this.initialViewportValidSubject.getValue()){this.setLockedYScale(t,e,s,i);return}super.setYScale(t,e,s);const r=this.export(),o=this.scalePostProcessor(i,r);this.state.auto&&this.autoScaleModel.doAutoYScale(o),this.apply(o)}setLockedYScale(t,e,s=!1,i){const r=e<i.yEnd;if(this.zoomReached.zoomOut&&r===!1||this.zoomReached.zoomIn&&r===!0)return;super.setYScale(t,e,s);const o=this.export(),a=this.scalePostProcessor(i,o);_h(i,a),this.zoomReached=this.calculateZoomReached(a.zoomX,r),this.apply(a),this.fireChanged()}moveXStart(t){const e=this.export(),s=oe({},e);this.haltAnimation(),Ph(e,t);const i=this.scalePostProcessor(s,e);this.state.auto&&this.autoScaleModel.doAutoYScale(i),this.apply(i)}moveYStart(t){if(this.haltAnimation(),!this.state.auto){const e=this.export();Th(e,t),this.apply(e)}}doAutoScale(t=!1){if(!this.isViewportAnimationInProgress()&&this.state.auto||t){const e=this.export();this.autoScaleModel.doAutoYScale(e),Xc(e,this.export())||this.apply(e)}}isViewportAnimationInProgress(){const t=this.currentAnimation;return t==null?void 0:t.animationInProgress}pushToHistory(t){this.history.push(t)}popFromHistory(){return this.history.pop()}clearHistory(){this.history=[]}isDefaultXBounds(){return this.xStart===0&&this.xEnd===0}isDefaultYBounds(){return this.yStart===0&&this.yEnd===0}isScaleReady(){return!this.isDefaultXBounds()&&!this.isDefaultYBounds()}autoScale(t=!0){this.config.components.yAxis.type==="percent"?this.state.auto=!0:this.state.auto=t,t&&(this.clearHistory(),this.doAutoScale())}setLockPriceToBarRatio(t=!1){const{type:e}=this.config.components.yAxis;if(e==="percent"||e==="logarithmic"){this.state.lockPriceToBarRatio=!1;return}this.state.lockPriceToBarRatio=t}initAutoScaleThrottling(){this.autoScaleZoomSubscription=Fh.pipe(Lt(Zt,Rt,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=oe({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)}),this.autoScalePanSubscription=Hh.pipe(Lt(Zt,Rt,{trailing:!0,leading:!1})).subscribe(()=>{const t=this.export(),e=oe({},t),s=this.scalePostProcessor(e,t);this.autoScaleModel.doAutoYScale(s)})}}class jh extends Mr{constructor(t,e,s,i){super(e,s,i),this.delegate=t,this.config=e,this.getBounds=s}doActivate(){this.addRxSubscription(this.delegate.xChanged.subscribe(()=>this.doAutoScale(this.state.auto)))}get xStart(){return this.delegate.xStart}set xStart(t){this.delegate.xStart=t}get xEnd(){return this.delegate.xEnd}set xEnd(t){this.delegate.xEnd=t}get zoomX(){return this.delegate.zoomX}set zoomX(t){this.delegate.zoomX=t}observeXChanged(){return this.delegate.xChanged}fireChanged(){this.delegate.changed.next(),this.changed.next()}}const Yh=es().colors;class $t extends cr{constructor(t,e,s,i,r,o,a,l,c=Yh){super(t,e,s),this.eventBus=i,this.candlesTransformersByChartType=a,this.candleWidthByChartType=l,this.colors=c,this.zippedHighLow=kh(),this.lastPriceMovement="none",this.lastVisualCandleChangedSubject=new F,this.meanCandleWidth=Vs,this._instrument=o,this.instrument=o,this.highLowProvider=bh(this),this.scale=r,this.name=o.symbol}get dataPoints(){return super.dataPoints}set dataPoints(t){super.dataPoints=t,this.applyPriceMovement()}get instrument(){return this._instrument}set instrument(t){var e;this._instrument=t,this.pricePrecisions=ve.computePrecisions((e=t.priceIncrements)!=null?e:[.01])}recalculateDataViewportIndexes(t=this.scale.xStart,e=this.scale.xEnd){const{dataIdxStart:s,dataIdxEnd:i}=this.calculateDataViewportIndexes(t,e);this.dataIdxStart=s,this.dataIdxEnd=i,this.recalculateZippedHighLow(),this.eventBus.fireDraw()}calculateDataViewportIndexes(t,e){const s=Yt(this.visualPoints,t,r=>r.startUnit).index,i=Yt(this.visualPoints,e,r=>r.startUnit).index;return{dataIdxStart:s,dataIdxEnd:i}}applyPriceMovement(){const t=St(this.dataPoints);t&&(this.lastPriceMovement=ts(t.open,t.close))}recalculateVisualPoints(){super.recalculateVisualPoints(),this.recalculateMeanCandleWidth(this.visualPoints)}recalculateZippedHighLow(){return this.zippedHighLow=Cr(this.visualPoints.slice(this.dataIdxStart,this.dataIdxEnd+1))}updateCurrentPrice(t){this.previousPrice=this.currentPrice||t,this.currentPrice=t,this.currentPrice!==this.previousPrice&&(this.lastPriceMovement=this.currentPrice>this.previousPrice?"up":"down")}updateCandleSeriesColors(t){this.colors=At(t,this.colors),this.recalculateVisualPoints()}observeLastVisualCandleChanged(){return this.lastVisualCandleChangedSubject.asObservable()}doDeactivate(){super.doDeactivate()}toVisualPoints(t,e=0){var s,i;if(t.length===0)return[];const r=this.config.type,o=[];let a=e;const l=(s=this.candleWidthByChartType[r])!=null?s:mr;for(let c=0;c<t.length;c++){const h=t[c],d=t[c-1],u=l(h),f=a+u/2,g=(i=this.candlesTransformersByChartType[r])!=null?i:gr;o.push(g(h,{x:f,width:u,prevCandle:d,activeCandle:this.activeCandle},o[c-1])),a+=u}return o}recalculateMeanCandleWidth(t){t.length!==0?this.meanCandleWidth=t.reduce((e,s)=>e+s.width,0)/t.length:this.meanCandleWidth=Vs}setActiveCandle(t){this.activeCandle=t,this.recalculateVisualPoints()}clearData(){this.dataPoints=[],this.clearVisualCandles(),this.clearPrices()}clearPrices(){this.previousPrice=void 0,this.currentPrice=void 0,this.lastPriceMovement="none"}clearVisualCandles(){this.visualPoints=[]}}function Gm(n){switch(n){case"line":case"area":return!0;default:return!1}}class Nh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=!!i.color;if(s instanceof $t){const a=mt(e);if(a.length===0)return;i.color?t.strokeStyle=i.color:t.strokeStyle=s.colors.areaTheme.lineColor,o?t.lineWidth=(r=i.hoverWidth)!=null?r:this.config.selectedWidth*3:s.highlighted?t.lineWidth=this.config.selectedWidth:t.lineWidth=this.config.areaLineWidth;const l=s.extentComponent.getBounds(),c=a[0],h=s.view.toX(c.centerUnit);for(let d=0;d<a.length;d++){const u=a[d-1],f=a[d+1],g=a[d],m=s.view.toX(g.centerUnit),x=s.view.toY(g.close),_=l.y+l.height;if(u===void 0)t.beginPath(),t.lineTo(at(m),_),t.moveTo(at(m),x);else if(f===void 0){t.lineTo(at(m),x),t.stroke(),t.lineTo(at(m),_),t.lineTo(at(h),_),t.closePath();let A;i.color?t.fillStyle=i.color:t.fillStyle=s.colors.areaTheme.startColor&&s.colors.areaTheme.stopColor?(A=t.createLinearGradient(0,0,0,l.height),A.addColorStop(0,s.colors.areaTheme.startColor),A.addColorStop(1,s.colors.areaTheme.stopColor),A):"",o||t.fill()}else t.lineTo(m,x)}}}}function Ar(n,t,e,s,i,r=4,o=!0,a=!1){n.save(),n.beginPath(),n.moveTo(t+r,e),n.lineTo(t+s-r,e),n.quadraticCurveTo(t+s,e,t+s,e+r),n.lineTo(t+s,e+i-r),n.quadraticCurveTo(t+s,e+i,t+s-r,e+i),n.lineTo(t+r,e+i),n.quadraticCurveTo(t,e+i,t,e+i-r),n.lineTo(t,e+r),n.quadraticCurveTo(t,e,t+r,e),n.closePath(),o&&n.fill(),a&&n.stroke(),n.restore()}function Xh(n,t,e,s,i,r,o,a,l,c,h=4,d=!0,u=!1){const f=c==="right"?a:-a,g=c==="right"?h:-h,m=h;n.save(),n.beginPath(),l?n.moveTo(r+g,o):n.moveTo(r,o),l?(n.lineTo(r+f-g,o),n.quadraticCurveTo(r+f,o,r+f,o-m),n.lineTo(r+f,e+m),n.quadraticCurveTo(r+f,e,r+f-g,e),n.lineTo(t+g,e)):(n.lineTo(r+f,o),n.lineTo(r+f,e),n.lineTo(t,e)),l?(n.quadraticCurveTo(t,e,t-g/3,e+m/3),n.lineTo(s+g/3,i-m/3),n.quadraticCurveTo(s,i,s+g/3,i+m/3),n.lineTo(r-g/3,o-m/3),n.quadraticCurveTo(r,o,r+g/3,o)):(n.lineTo(s,i),n.lineTo(r,o)),n.closePath(),d&&n.fill(),u&&n.stroke(),n.restore()}function Wh(n,t,e,s,i,r=1,o=[]){n.save(),n.setLineDash(o),n.lineWidth=r,n.beginPath(),n.moveTo(t,e),n.lineTo(s,i),n.stroke(),n.closePath(),n.restore()}function ae(n,t){n.save(),n.lineWidth%2&&n.translate(.5,.5),t(),n.restore()}function Er(n,t,e){const s=Math.min(t.x,e.x)+.5,i=Math.min(t.y,e.y),r=Math.abs(t.x-e.x),o=Math.abs(t.y-e.y);n.fillRect(s,i,r,o)}const Kt=(n,t)=>{n.beginPath(),n.rect(t.x,t.y,t.width,t.height),n.clip(),n.closePath()},Zm=n=>Array.isArray(n[0])?n:[n];class zh{constructor(t,e){this.paneManager=t,this.seriesDrawers=e}draw(t,e,s){const i=t.ctx,r=s&&this.paneManager.panes[s];e&&(i.save(),r&&Kt(i,r.getBounds()),this.drawSeries(i,e),i.restore())}drawSeries(t,e){const s=e.config.additionalVisibilityPredicatesMap;if(e.config.visible||s&&!Yc(s)){const i=e.config.type,r=this.seriesDrawers[i];if(r){const o=e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1);o&&o.length>=1&&r.draw(t,o,e,{})}else console.error(`Data series drawer with type ${i} isn't registered!`)}}}const qt=(n,t,e,s,i=t)=>{s.hoverWidth?n.lineWidth=s.hoverWidth:e.highlighted?n.lineWidth=t!==i?t+1:i:n.lineWidth=t};class Vh{constructor(t){this.config=t}setFillStyle(t,e,s,i){if(e.color)t.strokeStyle=e.color;else{const r=s.colors.barTheme;r&&(t.strokeStyle=r[`${i.name}Color`])}}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.barLineWidth,s,i),ae(t,()=>{for(const o of r){this.setFillStyle(t,i,s,o),t.beginPath();const a=s.view.toX(o.centerUnit),l=s.view.toX(o.startUnit),[c,h,d,u]=o.yBodyKeyPoints(s.view),f=Et(s.view.xPixels(o.width)/2),g=s.view.toY(o.close),m=s.view.toY(o.open);this.config.showWicks?(t.moveTo(a,c),t.lineTo(a,u)):(t.moveTo(a,h),t.lineTo(a,d)),t.moveTo(a,g),t.lineTo(a+f,g),t.moveTo(l,m),t.lineTo(a,m),t.stroke()}})}}}class Uh{constructor(t,e){this.baseLineModel=t,this.canvasBoundContainer=e}draw(t,e,s,i){if(i!==void 0&&s instanceof $t){const r=mt(e),o=this.baseLineModel.baselineYPercents,a=this.canvasBoundContainer.getBounds(M.CHART),l=a.y+a.height*(o/100),c=r[0];for(let h=0;h<r.length;h++){const d=r[h],u=r[h-1],f=r[h+1],g=s.view.toX(c.centerUnit),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close),_=u?s.view.toY(u.close)<l:!1,A=x<l;if(u!==void 0&&_!==A){Ir(t,s,i,_);const L=s.view.toX(u.centerUnit),Y=s.view.toY(u.close),H=m-L,B=x-Y,j=H/B,$=x-l,W=j*$,U=L+(H-W);t.lineTo(U,l),t.stroke(),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(U,l)}u===void 0?(t.beginPath(),t.moveTo(m,x)):f===void 0?(Ir(t,s,i,A),t.lineTo(m,x),t.stroke(),t.lineTo(m,l),t.lineTo(g,l),t.closePath(),t.fill(),t.beginPath(),t.moveTo(g,l),t.lineTo(m,l),t.strokeStyle=s.colors.baseLineTheme.baselineColor,t.stroke()):t.lineTo(m,x)}}}}const Ir=(n,t,e,s)=>{e.color?(n.fillStyle=e.color,n.strokeStyle=e.color):(n.fillStyle=s?t.colors.baseLineTheme.upperSectionFillColor:t.colors.baseLineTheme.lowerSectionFillColor,n.strokeStyle=s?t.colors.baseLineTheme.upperSectionStrokeColor:t.colors.baseLineTheme.lowerSectionStrokeColor)};class Gh{constructor(t){this.config=t,this.pixelLength=1,this.lineWidthCU=1,this.halfLineWidthCU=1}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.candleLineWidth,s,i,this.config.candleLineWidth),ae(t,()=>{this.pixelLength=1/Ft,this.halfLineWidthCU=t.lineWidth/2,this.lineWidthCU=t.lineWidth;for(const o of r){const{candleTheme:a,activeCandleTheme:l}=s.colors;a&&l&&this.drawCandle(t,i,s,o)}})}}drawCandle(t,e,s,i){const{candleTheme:r,activeCandleTheme:o}=s.colors,a=i.name,l=i.isActive?o:r,c=i.isHollow;e.color?t.fillStyle=e.color:c?t.fillStyle=l[`${a}WickColor`]:t.fillStyle=l[`${a}Color`];const h=s.view.toX(i.startUnit),d=s.view.xPixels(i.width),u=i.bodyHeight(s.view),[f,g,m,x]=i.yBodyKeyPoints(s.view),_=g===m?g+1:m,A=f===x?f+1:x,L=l[`${a}Color`],Y=a==="none"?L:l[`${a}WickColor`];t.fillStyle=L,e.color?t.strokeStyle=e.color:t.strokeStyle=Y;const H=c||(i.hasBorder&&i.isActive?this.config.showActiveCandlesBorder:this.config.showCandlesBorder),B=this.config.showWicks;if(d<2)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.stroke();else if(d<3)t.beginPath(),t.moveTo(h,B?f:g),t.lineTo(h,B?A:_),t.moveTo(h+1,g),t.lineTo(h+1,_),t.stroke();else if(d===3){const j=d/Ft;this.drawCandlesWicks(t,h+j,f,A,g,_),c||(t.beginPath(),t.moveTo(h+j,g),t.lineTo(h+j,_),t.stroke()),this.drawCandleBorder(t,e,l,i,h+this.halfLineWidthCU,g+this.halfLineWidthCU,d-this.lineWidthCU,u-this.lineWidthCU)}else{const j=i.x(s.view);this.drawCandlesWicks(t,j,f,A,g,_);const $=this.config.candlePaddingPercent,W=Math.max(d*$/2,this.pixelLength),U=h+W,G=d-W*2;if(!c){e.color&&(t.fillStyle=e.color);const V=e.hoverWidth?d+W:G,Q=e.hoverWidth?u+e.hoverWidth+W:u;t.fillRect(U,g,V,Q)}H&&this.drawCandleBorder(t,e,l,i,U+this.halfLineWidthCU,g+this.halfLineWidthCU,G-this.lineWidthCU,u-this.lineWidthCU)}}drawCandlesWicks(t,e,s,i,r,o){this.config.showWicks&&(t.beginPath(),t.moveTo(e,s),t.lineTo(e,r),t.moveTo(e,o),t.lineTo(e,i),t.stroke())}drawCandleBorder(t,e,s,i,r,o,a,l){if(e.color)t.strokeStyle=e.color;else{const c=i.name;t.strokeStyle=c==="none"?s[`${c}Color`]:s[`${c}WickColor`]}t.strokeRect(r,o,a,l)}}class Zh{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof $t){const r=e.flat(),o=s.scale.getBounds(),a=o.y+o.height;for(const l of r){t.beginPath();const c=l.name,h=this.config.barCapSize,d=s.colors.histogram;if(d===void 0)return;i.color?t.fillStyle=i.color:t.fillStyle=d[`${c}Bright`];const u=l.xStart(s.view),f=s.view.toY(l.close),g=Et(s.view.xPixels(l.width));t.fillRect(u,f,g,h);const m=t.createLinearGradient(0,f+h,0,a);i.color?t.fillStyle=i.color:(m.addColorStop(0,d[`${c}Cap`]),m.addColorStop(1,d[`${c}Bottom`]),t.fillStyle=m),g===0?(t.beginPath(),t.strokeStyle=m,t.moveTo(u,f+h),t.lineTo(u,a),t.stroke(),t.closePath()):t.fillRect(u,f+h,g,a-f-h)}}}}class $h{constructor(t){this.config=t}draw(t,e,s,i){if(s instanceof $t){const r=mt(e);qt(t,this.config.lineWidth,s,i,this.config.selectedWidth);const o=s.colors.lineTheme;t.lineCap="round",i.color&&(t.strokeStyle=i.color);for(let a=1;a<r.length;a++){const l=r[a-1],c=r[a],h=c.name;i.color||(t.strokeStyle=o[`${h}Color`]);const d=s.view.toX(l.centerUnit),u=s.view.toY(l.close),f=s.view.toX(c.centerUnit),g=s.view.toY(c.close);t.beginPath(),t.moveTo(d,u),t.lineTo(f,g),t.stroke()}}}}const Kh=1.5;class qh{constructor(t){this.config=t}draw(t,e,s,i){var r;const o=i.hoverWidth?i.hoverWidth/2:Kh;t.fillStyle=(r=i.color)!=null?r:this.config.mainColor;for(const a of mt(e)){t.beginPath();const l=s.view.toX(a.centerUnit),c=s.view.toY(a.close);t.arc(l,c,o,0,Math.PI*2,!0),t.fill()}}}const Jh=["candle","bar","line","area","scatterPlot","hollow","histogram","baseline","trend"];class Qh{constructor(t,e,s){this.drawer=t,this.config=e,this.chartBounds=s}draw(t,e,s,i){this.isChartTypeAllowed()&&(this.beforeDraw(t),this.drawer.draw(t,e,s,i),this.afterDraw(t,s))}beforeDraw(t){t.restore(),t.save(),Kt(t,this.chartBounds())}isChartTypeAllowed(){return Jh.includes(this.config.components.chart.type)}afterDraw(t,e){t.restore(),t.save(),Kt(t,e.scale.getBounds())}}class td{constructor(t){this.chartModel=t}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=this.chartModel.getVisualCandle(at(c.centerUnit)),d=c.close;if(h&&d===1){const u=this.chartModel.scale.zoomX,f=Et(vt(h.width,u)),g=Et(h.bodyHeight(this.chartModel.scale)),m=h.xCenter(this.chartModel.scale)-f/2,x=h.yBodyStart(this.chartModel.scale),_=this.chartModel.config.components.chart.candlePaddingPercent,A=Et(f*_/2),L=m+A,Y=f-A*2;t.fillRect(L,x,Y,g)}})})}}const ed=(n,t,e,s)=>{const{centerUnit:i,close:r}=n,o=e.toX(i),a=e.toY(r);s===0?t.moveTo(o,a):t.lineTo(o,a)},Dr=(n,t,e)=>{n.length!==0&&n.forEach((s,i)=>{ed(s,t,e,i)})},sd=/^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,nd=/^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i,id=/^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/,rd=n=>sd.exec(n),od=n=>nd.exec(n),$m=n=>id.exec(n);function ad(n){const t=rd(n)||od(n);let e=[];return t&&(e=t.slice(2,5),t[1]==="#")?e.map(function(s){return parseInt(s,16)}):e}const Lr={};function ld(n,t){let e=Lr[n+t];if(!e){const s=ad(n);e=s&&"rgba("+s.join(",")+","+t+")",Lr[n+t]=e}return e}const Or="#383838";class cd{constructor(){}draw(t,e,s,i){const r=s.config.additionalVisibilityPredicatesMap,o=(r==null?void 0:r.showLine)!==void 0?r.showLine:s.config.visible,a=(r==null?void 0:r.showCloud)!==void 0?r.showCloud:s.config.visible;o&&e.forEach((l,c)=>{var h;const d=s.getPaintConfig(c);qt(t,d.lineWidth,s,i,d.hoveredLineWidth);const u=(h=i.color)!=null?h:d.color;t.strokeStyle=u,this.drawLine(t,l,s.view)}),a&&s.linkedDataSeriesModels.forEach((l,c)=>{const h=l.config.additionalVisibilityPredicatesMap,d=(h==null?void 0:h.showCloud)!==void 0?h.showCloud:l.config.visible;if(Br(l.config.type)&&Br(s.config.type)&&d){const u=s,f=u.getSeriesInViewport(u.scale.xStart-1,u.scale.xEnd+1),g=l.getSeriesInViewport(l.scale.xStart-1,l.scale.xEnd+1);f.forEach((m,x)=>{var _,A;const L=[],Y=Math.min(m.length,(A=(_=g[x])==null?void 0:_.length)!=null?A:0);for(let j=0;j<Y;j++){const $=[m[j].clone(),g[x][j].clone()];L.push({diffPoints:$})}const H=u.getPaintConfig(x).color,B=l.getPaintConfig(c).color;this.drawDifference(t,H,B,L,u,l,i,r)})}})}drawLine(t,e,s){t.beginPath(),Dr(e,t,s),t.stroke()}drawDifference(t,e,s,i,r,o,a,l){const[c,h]=[[],[]];i.forEach(x=>{const[_,A]=x.diffPoints;c.push(_),h.push(A)});const d=this.mapDataSeriesDiffPointsIntoPoints(c,r.view),u=this.mapDataSeriesDiffPointsIntoPoints(h,o.view),f=l==null?void 0:l.backgroundColor,g=f!==void 0?f:s,m=f!==void 0?f:e;this.fillCloud(t,g,d,u,a,l),this.fillCloud(t,m,u,d,a,l)}fillCloud(t,e,s,i,r,o){var a,l,c,h;t.save(),t.beginPath();const d=(l=(a=ge(s))==null?void 0:a.x)!=null?l:0,u=(h=(c=St(s))==null?void 0:c.x)!=null?h:0;t.lineTo(d,0),s.forEach(g=>{t.lineTo(g.x,g.y)}),t.lineTo(u,0),t.closePath(),t.clip(),t.beginPath(),s.forEach((g,m)=>{m===0?t.moveTo(g.x,g.y):t.lineTo(g.x,g.y)}),i.slice().reverse().forEach(g=>{t.lineTo(g.x,g.y)}),t.closePath();const f=(o==null?void 0:o.backgroundColor)!==void 0;r.color?t.fillStyle=r.color:f?t.fillStyle=e!=null?e:Or:t.fillStyle=ld(e!=null?e:Or,.3),t.fill(),t.restore()}mapDataSeriesDiffPointsIntoPoints(t,e){return t.map(s=>{const{centerUnit:i,close:r}=s,o=e.toX(i),a=e.toY(r);return{x:o,y:a}})}}const Br=n=>n==="DIFFERENCE";class hd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0);e.forEach((o,a)=>{var l;const c=s.getPaintConfig(a);qt(t,c.lineWidth,s,i,c.hoveredLineWidth),t.strokeStyle=(l=i.color)!=null?l:c.color,t.beginPath(),o.forEach(h=>{const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.moveTo(d,at(r)),t.lineTo(d,at(u))}),t.stroke()})}}class dd{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);qt(t,l.lineWidth,s,i,l.hoveredLineWidth),t.strokeStyle=(a=i.color)!=null?a:l.color,this.drawLinePath(t,r,s.view)})}drawLinePath(t,e,s){t.beginPath(),Dr(e,t,s),t.stroke()}}class ud{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o),c=i.hoverWidth?i.hoverWidth/2:l.lineWidth;t.fillStyle=(a=i.color)!=null?a:l.color,t.lineWidth=1,r.forEach(h=>{t.beginPath();const d=s.view.toX(h.centerUnit),u=s.view.toY(h.close);t.arc(d,u,c,0,Math.PI*2),t.fill()})})}}class fd{constructor(t){this.config=t}draw(t,e,s,i){t.save(),e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color;const c=l.lineWidth+"px "+this.config.components.yAxis.fontFamily;t.font=c,r.forEach(h=>{const d=s.getTextForPoint(h),u=Mt(d,t,c),f=Xt(c,t),g=s.view.toX(h.centerUnit)-u/2,m=s.view.toY(h.close)+f;t.fillText(d,g,m)})}),t.restore()}}class gd{constructor(){}draw(t,e,s,i){e.forEach((r,o)=>{var a;const l=s.getPaintConfig(o);t.fillStyle=(a=i.color)!=null?a:l.color,r.forEach(c=>{const h=s.view.toX(c.centerUnit),d=s.view.toY(c.close);this.drawCandleTriangle(t,h,d,l.lineWidth)})})}drawCandleTriangle(t,e,s,i){t.beginPath(),t.moveTo(e-i/2,s),t.lineTo(e,s-i),t.lineTo(e+i/2,s),t.fill()}}const cs="resized_local",hs="draw",Km="draw_last_candle",be={width:20,height:20};class Rr{constructor(t,e,s,i,r,o={}){this.eventBus=t,this.canvas=e,this.drawingManager=s,this.resizer=r,this.width=0,this.height=0,this.prevHeight=0,this.prevWidth=0,this.lastDPR=0,this.type=nn;var a;i.push(this),this.parent=vd(e);const l=e.getContext("2d",o);if(l===null)throw new Error("Couldn't get 2d context????");this.context=l,this._canvasId=(a=e.getAttribute("data-element"))!=null?a:"",this.updateCanvasWidthHeight(e,this.getChartResizerElement().getBoundingClientRect())}updateDPR(t){const{width:e,height:s}=t,i=window.devicePixelRatio;e===this.width&&s===this.height&&i===this.lastDPR||(this.lastDPR=i,this.canvas.style.height=s+"px",this.canvas.style.width=e+"px",this.canvas.width=e*i,this.canvas.height=s*i,this.width=e,this.height=s,this.ctx.scale(i,i))}get canvasId(){return this._canvasId}get ctx(){return this.context}clear(){this.context.clearRect(0,0,this.width,this.height)}isLinked(){var t,e;return(e=(t=this.type)==null?void 0:t.linked)!=null?e:!1}fireDraw(){this.eventBus.fireDraw([this.canvasId])}updateCanvasWidthHeight(t,e=this.getChartResizerElement().getBoundingClientRect()){t.clientWidth!==this.width&&(t.width=t.clientWidth,this.width=t.clientWidth);const s=e.height;s!==this.height&&(t.style.height=s+"px",this.height=s,t.height=s,this.prevHeight=s)}getChartResizerElement(){var t;return(t=this.resizer)!=null?t:this.parent}isReady(){return this.width>be.width&&this.height>be.height}}const nn={name:"candle"},pd={candle:nn,bar:{name:"candle"},line:{name:"line",linked:!0},area:{name:"area",linked:!0}};function md(n,t,e,s,i,r,o){var a;const l=le(n,t,i,r,o,e);return l.type=(a=pd[s])!=null?a:nn,l}function le(n,t,e,s,i,r,o){const a=new Rr(n,t,s,i,r,o);return Fr(a,e),a}function Fr(n,t){const e=n.canvas;t.fixedSize&&(e.width=t.fixedSize.width,e.height=t.fixedSize.height,e.style.width=t.fixedSize.width+"px",e.style.height=t.fixedSize.height+"px",n.width=t.fixedSize.width,n.height=t.fixedSize.height),e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.direction="ltr"}function vd(n){let t=n;for(;t;){if(t.nodeType===1&&t.hasAttribute("data-chart-container"))return t;if(t.parentElement!==null)t=t.parentElement;else break}return t}const ds="HIT_TEST_",tv=null;class bd{constructor(t,e){this.chartResizeHandler=e,this.drawingOrder=[],this.drawersMap={},this.canvasIdsList=[],this.animFrameId=`draw_${wt()}`,this.drawHitTestCanvas=()=>{this.drawingOrder.forEach(s=>{s.indexOf(ds)!==-1&&this.drawersMap[s].draw()})},t.on(hs,s=>{e.wasResized()&&(this.canvasIdsList&&(s&&s.length!==0?this.canvasIdsList=this.canvasIdsList.concat(s):this.canvasIdsList=void 0),Qn(this.animFrameId,()=>{this.forceDraw(this.canvasIdsList),this.canvasIdsList=[],this.drawHitTestCanvas()}))})}redrawCanvasesImmediate(){this.chartResizeHandler.fireUpdates(),this.forceDraw()}drawLastBar(){this.drawingOrder.forEach(t=>{if(t.indexOf(ds)===-1){const e=this.drawersMap[t];e.drawLastBar&&e.drawLastBar()}})}forceDraw(t){this.isDrawable()&&this.drawingOrder.forEach(e=>{if(e.indexOf(ds)===-1){const s=this.drawersMap[e];if(!t||t.length===0){s.draw();return}Il(t,s.getCanvasIds()).length&&s.draw()}})}isDrawable(){var t,e,s,i;return((e=(t=this.chartResizeHandler.previousBCR)==null?void 0:t.height)!=null?e:0)>be.width&&((i=(s=this.chartResizeHandler.previousBCR)==null?void 0:s.width)!=null?i:0)>be.height}drawHitTestOnly(){this.drawHitTestCanvas()}addDrawer(t,e=wt()){this.drawingOrder.indexOf(e)===-1&&this.drawingOrder.push(e),this.drawersMap[e]=t}addDrawerAfter(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(e);this.drawingOrder.splice(i,1);const r=this.drawingOrder.indexOf(s);this.drawingOrder.splice(r+1,0,e),this.reorderDrawers(this.drawingOrder)}addDrawerBefore(t,e,s){this.addDrawer(t,e);const i=this.drawingOrder.indexOf(s);if(i!==-1){const r=this.drawingOrder.indexOf(e);return this.drawingOrder.splice(r,1),this.drawingOrder.splice(i,0,e),this.reorderDrawers(this.drawingOrder),!0}return!1}getDrawerByName(t){return this.drawersMap[t]}getNameByDrawer(t){for(const e in this.drawersMap)if(this.drawersMap[e]===t)return e}removeDrawerByName(t){const e=this.drawersMap[t];this.removeDrawer(e)}removeDrawer(t){Object.keys(this.drawersMap).forEach(e=>{if(this.drawersMap[e]===t){delete this.drawersMap[e];const s=this.drawingOrder.indexOf(e);s!==-1&&this.drawingOrder.splice(s,1)}})}reorderDrawers(t){this.drawingOrder=ci(this.drawingOrder,t)}}class Hr{static paneResizer(t){return`PANE_RESIZER_${t}`}}const Cd=7;class yd{constructor(t,e,s,i=()=>!0){this.seriesDrawers=t,this.canvasModel=e,this.paneManager=s,this.drawPredicate=i}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;this.paneManager.yExtents.forEach(e=>{t.save(),Kt(t,e.getBounds()),e.dataSeries.forEach(s=>this.drawSeries(t,s)),t.restore()})}}drawSeries(t,e){if(e.config.visible){const s=e.config.type,i=this.seriesDrawers[s];if(i){const r={color:this.canvasModel.idToColor(e.htId),hoverWidth:Cd};i.draw(t,e.getSeriesInViewport(e.scale.xStart-1,e.scale.xEnd+1),e,r)}}}getCanvasIds(){return[this.canvasModel.canvasId]}}const kr={dragPredicate:()=>!0};class jr extends X{constructor(t,e,s,i,r){super(),this.hitTest=t,this.dragCallbacks=e,this.canvasInputListener=s,this.chartPanComponent=i,this.dragComponentOptions=r,this.dragging=!1,this.draggedPixels=0,this.onDragStart=o=>{this.dragComponentOptions.dragPredicate()&&(this.dragging=!0,this.draggedPixels=0,this.dragCallbacks.onDragStart&&this.dragCallbacks.onDragStart(o))},this.onDragTick=o=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.draggedPixels+=o,this.dragCallbacks.onDragTick({delta:o,draggedPixels:this.draggedPixels}))},this.onDragEnd=()=>{this.dragComponentOptions.dragPredicate()&&this.dragging&&(this.dragging=!1,this.dragCallbacks.onDragEnd&&this.dragCallbacks.onDragEnd(this.draggedPixels))}}}class us extends jr{constructor(t,e,s,i,r=kr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeYDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeYDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeYDragEnd().subscribe(this.onDragEnd))}}const wd="BASELINE_RESIZER";class Sd extends X{constructor(t,e,s,i,r,o,a){super(),this.chartModel=t,this.chartPanComponent=e,this.canvasModel=s,this.canvasInputListener=i,this.config=r,this.canvasBoundContainer=o,this.cursorHandler=a,this.resizerBounds={x:0,y:0,pageX:0,pageY:0,height:0,width:0},this.dragPredicate=new ft(!1),this.baselineYPercents=50,this.ht=Zs.hitTestOf(this.resizerBounds,{extensionY:this.config.components.paneResizer.dragZone}),this.dragStartCb=()=>{this.chartPanComponent.deactivatePanHandlers(),this.dragPredicate.next(!0)},this.dragEndCb=()=>{this.chartPanComponent.activateChartPanHandlers(),this.dragPredicate.next(!1)},this.dragTickCb=c=>{const{delta:h}=c,d=this.canvasBoundContainer.getBounds(M.CHART),u=this.canvasInputListener.getCurrentPoint().y;h!==0&&hc(u,d)&&(this.moveBaseLine(u),this.canvasModel.fireDraw())};const l=new us(this.ht,{onDragTick:this.dragTickCb,onDragStart:this.dragStartCb,onDragEnd:this.dragEndCb},i,e);this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundContainer.observeBoundsChanged(M.CHART).subscribe(()=>this.recalculateBounds())),this.chartModel.chartTypeChanged.subscribe(t=>{t==="baseline"?this.cursorHandler.setCursorForBounds("BASELINE_RESIZER",this.resizerBounds,this.config.components.baseline.cursor,this.config.components.baseline.dragZone):this.cursorHandler.removeCursorForCanvasEl("BASELINE_RESIZER")})}recalculateBounds(){const t=this.canvasBoundContainer.getBounds(M.CHART),e=this.canvasBoundContainer.getBounds(M.Y_AXIS);this.resizerBounds.x=t.x,this.resizerBounds.width=t.width+e.width,this.resizerBounds.height=this.config.components.baseline.height;const s=t.y+t.height*(this.baselineYPercents/100);this.resizerBounds.y=s,this.canvasBoundContainer.bounds[wd]=this.resizerBounds}moveBaseLine(t){const e=this.canvasBoundContainer.getBounds(M.CHART);this.baselineYPercents=(t-e.y)*100/e.height,this.resizerBounds.y=t}doDeactivate(){super.doDeactivate()}}const xd=n=>{var t;try{const e=Te(n.close,n.open,n.hi,n.lo);if(!isFinite(e))throw new Error("Received candle without any price");const s=Te(n.hi,Math.max(n.open,n.close),e),i=Te(n.lo,Math.min(n.open,n.close),e),r=Te(n.open,n.lo,e),o=Te(n.close,n.hi,e),a=Number.isNaN(n.vwap)?void 0:n.vwap;return{id:n.id,hi:s,lo:i,open:r,close:o,timestamp:n.timestamp,volume:(t=n.volume)!=null?t:0,expansion:n.expansion,idx:n.idx,impVolatility:n.impVolatility,openInterest:n.openInterest,vwap:a,typicalPrice:n.typicalPrice}}catch(e){console.warn(e);return}},He=(n,t=0)=>{for(let e=t;e<n.length;++e)n[e].idx=e},Yr=n=>{n.forEach(t=>{t.idx=void 0})},_d=n=>n!==void 0;class Pd{constructor(){}draw(t,e,s,i){const r=s.view.toY(0),o=mt(e),a=s.getPaintConfig(0);qt(t,a.lineWidth,s,i,a.hoveredLineWidth),o.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=Td(o,c),L=A&&l.close<A;if(((h=a.multiplyColors)==null?void 0:h.length)===2){t.strokeStyle=(d=i.color)!=null?d:(L?a.multiplyColors[1]:a.multiplyColors[0])||a.color||"#FF00FF",t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,j),t.stroke();return}if(((u=a.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.strokeStyle=(f=i.color)!=null?f:a.multiplyColors[0]||a.color||"#FF00FF"),!L&&l.close<0&&(t.strokeStyle=(g=i.color)!=null?g:a.multiplyColors[1]||a.color||"#FF00FF"),L&&l.close>0&&(t.strokeStyle=(m=i.color)!=null?m:a.multiplyColors[2]||a.color||"#FF00FF"),!L&&l.close>0&&(t.strokeStyle=(x=i.color)!=null?x:a.multiplyColors[3]||a.color||"#FF00FF"),t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.moveTo(B,r),t.lineTo(B,j),t.stroke();return}t.strokeStyle=(_=i.color)!=null?_:a.color||"#FF00FF",t.beginPath();const Y=s.view.toX(l.centerUnit),H=s.view.toY(l.close);t.moveTo(Y,r),t.lineTo(Y,H),t.stroke()})}}const Td=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0},Md=(n,t)=>{let e=0;return(...s)=>{clearTimeout(e),e=+setTimeout(()=>n(...s),t)}};class Ad{constructor(){}draw(t,e,s,i){const r=mt(e),o=s.getPaintConfig(0);qt(t,o.lineWidth,s,i,o.hoveredLineWidth),t.lineCap="round",r.forEach((a,l)=>{var c,h;const d=Ed(r,l)||r[0],u=d&&a.close<d.close;if(((c=o.multiplyColors)==null?void 0:c.length)===2){t.strokeStyle=(h=i.color)!=null?h:(u?o.multiplyColors[1]:o.multiplyColors[0])||o.color||"#FF00FF";const f=s.view.toX(a.centerUnit),g=s.view.toY(a.close),m=s.view.toX(d.centerUnit),x=s.view.toY(d.close);t.beginPath(),t.moveTo(m,x),t.lineTo(f,g),t.stroke();return}})}}const Ed=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t]:void 0},Ce="#FF00FF";class Id{constructor(){}draw(t,e,s,i){const r=mt(e),o=s.getPaintConfig(0),a=i.hoverWidth?i.hoverWidth/2:o.lineWidth;r.forEach((l,c)=>{var h,d,u,f,g,m,x,_;const A=Dd(r,c),L=A&&l.close<A;if(((h=o.multiplyColors)==null?void 0:h.length)===2){t.fillStyle=(d=i.color)!=null?d:(L?o.multiplyColors[1]:o.multiplyColors[0])||o.color||Ce;const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.arc(B,j,a,0,Math.PI*2),t.fill();return}if(((u=o.multiplyColors)==null?void 0:u.length)===4){L&&l.close<0&&(t.fillStyle=(f=i.color)!=null?f:o.multiplyColors[0]||o.color||Ce),!L&&l.close<0&&(t.fillStyle=(g=i.color)!=null?g:o.multiplyColors[1]||o.color||Ce),L&&l.close>0&&(t.fillStyle=(m=i.color)!=null?m:o.multiplyColors[2]||o.color||Ce),!L&&l.close>0&&(t.fillStyle=(x=i.color)!=null?x:o.multiplyColors[3]||o.color||Ce),t.beginPath();const B=s.view.toX(l.centerUnit),j=s.view.toY(l.close);t.arc(B,j,a,0,Math.PI*2),t.fill();return}t.fillStyle=(_=i.color)!=null?_:o.color||Ce,t.beginPath();const Y=s.view.toX(l.centerUnit),H=s.view.toY(l.close);t.arc(Y,H,a,0,Math.PI*2),t.fill()})}}const Dd=(n,t)=>{do t--;while(t>=0&&!isFinite(n[t]&&n[t].close));return n[t]?n[t].close:void 0};var Ld=Object.defineProperty,Nr=Object.getOwnPropertySymbols,Od=Object.prototype.hasOwnProperty,Bd=Object.prototype.propertyIsEnumerable,Xr=(n,t,e)=>t in n?Ld(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Wr=(n,t)=>{for(var e in t||(t={}))Od.call(t,e)&&Xr(n,e,t[e]);if(Nr)for(var e of Nr(t))Bd.call(t,e)&&Xr(n,e,t[e]);return n};class Rd{constructor(){this.symbol="MOCK",this.priceIncrements=[.01]}}class Fd extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.chartModel=t,this.canvasModel=e,this.config=s,this.scale=i,this.canvasBoundsContainer=r,this.drawingManager=o,this.hitTestCanvasModel=a,this.canvasInputListener=l,this.paneManager=d,this.dynamicObjects=f,this.chartResizeHandler=g,this._dataSeriesDrawers={},this.backgroundDrawerPredicateSubject=new ft(!0),this.strToBarType=x=>{var _;return(_=this.barTypeValues.find(A=>A===x))!=null?_:"candle"},this.addChildEntity(this.chartModel),this.registerDefaultCandlesTransformers(),this.baselineModel=new Sd(this.chartModel,h,this.canvasModel,this.canvasInputListener,this.config,this.canvasBoundsContainer,u),this.addChildEntity(this.baselineModel);const m=new yd(this._dataSeriesDrawers,this.hitTestCanvasModel,d,()=>this.hitTestCanvasModel.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(m,ds+"DATA_SERIES","HIT_TEST_EVENTS"),this.registerDefaultDataSeriesDrawers(),this.backgroundDrawer=new oh(c,this.config,()=>this.backgroundDrawerPredicateSubject.getValue()),o.addDrawer(this.backgroundDrawer,"MAIN_BACKGROUND"),u.setCursorForCanvasEl(M.PANE_UUID(K),s.components.chart.cursor),this.dataSeriesDrawer=new zh(d,this.dataSeriesDrawers)}doActivate(){super.doActivate(),this.dynamicObjects.model.addObject({id:this.chartModel.mainCandleSeries.id,paneId:this.chartModel.mainCandleSeries.extentComponent.paneUUID,model:this.chartModel.mainCandleSeries,drawer:this.dataSeriesDrawer}),this.addRxSubscription(this.paneManager.dataSeriesAddedSubject.subscribe(t=>{this.dynamicObjects.model.addObject({id:t.id,paneId:t.extentComponent.paneUUID,parentId:t.parentId,model:t,drawer:this.dataSeriesDrawer})})),this.addRxSubscription(this.paneManager.dataSeriesRemovedSubject.subscribe(t=>{this.dynamicObjects.model.removeObject(t.id)})),this.addRxSubscription(this.canvasBoundsContainer.observeAnyBoundsChanged().subscribe(Md(()=>{this.backgroundDrawerPredicateSubject.next(!1)},Zt))),this.addRxSubscription(this.chartResizeHandler.canvasResized.subscribe(()=>{this.backgroundDrawerPredicateSubject.next(!0)}))}registerDefaultCandlesTransformers(){this.registerCandlesTransformer("candle",gr),this.registerCandlesTransformer("trend",pr),this.registerCandlesTransformer("hollow",lh),this.registerCandlesTransformer("line",ch)}get barTypeValues(){return Qi(this._dataSeriesDrawers)}get dataSeriesDrawers(){return this._dataSeriesDrawers}registerCandlesTransformer(t,e){this.chartModel.registerCandlesTransformer(t,e)}registerLastCandleLabelHandler(t,e){this.chartModel.registerLastCandleLabelHandler(t,e)}registerCandlesWidthCalculator(t,e){this.chartModel.registerCandlesWidthCalculator(t,e)}registerDefaultDataSeriesDrawers(){const t=new Gh(this.config.components.chart);this.registerDataSeriesTypeDrawer("candle",t),this.registerDataSeriesTypeDrawer("trend",t),this.registerDataSeriesTypeDrawer("hollow",t),this.registerDataSeriesTypeDrawer("bar",new Vh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("line",new $h(this.config.components.chart)),this.registerDataSeriesTypeDrawer("scatterPlot",new qh(this.config.colors.scatterPlot)),this.registerDataSeriesTypeDrawer("area",new Nh(this.config.components.chart)),this.registerDataSeriesTypeDrawer("baseline",new Uh(this.baselineModel,this.canvasBoundsContainer)),this.registerDataSeriesTypeDrawer("histogram",new Zh(this.config.components.chart.histogram));const e=M.PANE_UUID(K),s=()=>this.canvasBoundsContainer.getBounds(e);this.registerDataSeriesTypeDrawer("LINEAR",new dd),this.registerDataSeriesTypeDrawer("LINEAR_TREND",new Ad),this.registerDataSeriesTypeDrawer("HISTOGRAM",new hd),this.registerDataSeriesTypeDrawer("TREND_HISTOGRAM",new Pd),this.registerDataSeriesTypeDrawer("POINTS",new ud),this.registerDataSeriesTypeDrawer("TREND_POINTS",new Id),this.registerDataSeriesTypeDrawer("COLOR_CANDLE",new Qh(new td(this.chartModel),this.config,s)),this.registerDataSeriesTypeDrawer("TEXT",new fd(this.config)),this.registerDataSeriesTypeDrawer("TRIANGLE",new gd),this.registerDataSeriesTypeDrawer("DIFFERENCE",new cd)}setChartType(t){this.config.components.chart.type=t,this.chartModel.rememberCurrentTimeframe(),this.chartModel.mainCandleSeries.setType(t),this.chartModel.mainCandleSeries.updateCandleSeriesColors(Wr({},this.config.colors)),this.chartModel.mainCandleSeries.recalculateVisualPoints(),this.chartModel.chartTypeChanged.next(t)}resetChartScale(){this.chartModel.doBasicScale()}setTimestampRange(t,e,s=!0){return this.chartModel.setTimestampRange(t,e,s)}setXScale(t,e,s=!0){return this.scale.setXScale(t,e,s)}setShowWicks(t){this.config.components.chart.showWicks=t,this.canvasModel.fireDraw()}setApplyBackgroundToAxes(t){this.config.components.chart.applyBackgroundToAxes=Wr({},t),this.chartModel.bus.fireDraw()}setMainSeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument;this.chartModel.mainCandleSeries.instrument=s,this.chartModel.setAllSeries({candles:t.candles,instrument:s},this.chartModel.getSecondarySeries().map(i=>{var r;const o=(r=i.instrument)!=null?r:this.chartModel.mainCandleSeries.instrument,a=i.dataPoints;return Yr(a),{candles:a,instrument:o}})),this.updatePriceIncrementsIfNeeded(s)}setSecondarySeries(t){var e;const s=(e=t.instrument)!=null?e:this.chartModel.mainCandleSeries.instrument,i=this.chartModel.setSecondaryCandleSeries(t.candles,s);if(this.updatePriceIncrementsIfNeeded(s),i)return i}setAllSeries(t,e=[]){var s;const i=(s=t.instrument)!=null?s:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(i),e.forEach(r=>{var o;const a=(o=r.instrument)!=null?o:this.chartModel.mainCandleSeries.instrument;this.updatePriceIncrementsIfNeeded(a)}),this.chartModel.setAllSeries(t,e)}toXFromCandleIndex(t){return this.chartModel.toX(t)}toXFromTimestamp(t){return this.chartModel.candleFromTimestamp(t).xCenter(this.chartModel.scale)}toY(t){return this.chartModel.toY(t)}updateAllSeries(t,e=[]){this.chartModel.updateAllSeries(t,e),this.canvasModel.fireDraw()}removeDataFrom(t){this.chartModel.removeDataFrom(t)}removeSecondarySeries(t){this.chartModel.removeSecondaryCandleSeries(t)}prependCandles(t,e){this.chartModel.prependCandles(t,e)}addLastCandle(t,e){this.chartModel.addLastCandle(t,e)}removeCandleByIdx(t,e){this.chartModel.removeCandleByIdx(t,e)}removeCandlesByIdsSequence(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIdsSequence(t,e)}removeCandlesByIds(t,e=this.chartModel.mainCandleSeries){this.chartModel.removeCandlesByIds(t,e)}addCandlesById(t,e,s=this.chartModel.mainCandleSeries){this.chartModel.addCandlesById(t,e,s)}updateLastCandle(t,e){this.chartModel.updateLastCandle(t,e)}updateCandles(t,e){this.chartModel.updateCandles(t,e)}setOffsets(t){this.chartModel.setOffsets(t)}getDataSeriesDrawer(t){return this._dataSeriesDrawers[t]}registerDataSeriesTypeDrawer(t,e){this._dataSeriesDrawers[t]=e}updatePriceIncrementsIfNeeded(t){(!t.priceIncrements||!ve.validatePriceIncrementsOrPrecisions(t.priceIncrements))&&(t.priceIncrements=[ve.autoDetectIncrementOfValueRange(this.scale.yEnd-this.scale.yStart)])}observeOffsetsChanged(){return this.chartModel.offsetsChanged}observeChartTypeChanged(){return this.chartModel.chartTypeChanged}observeCandlesChanged(){return this.chartModel.observeCandlesChanged()}observeCandlesUpdated(){return this.chartModel.candlesUpdatedSubject}observeCandlesPrepended(){return this.chartModel.candlesPrependSubject}}function zr(n,t){return t===void 0&&(t=is),N(function(e,s){var i=null,r=null,o=null,a=function(){if(i){i.unsubscribe(),i=null;var c=r;r=null,s.next(c)}};function l(){var c=o+n,h=t.now();if(h<c){i=this.schedule(void 0,c-h),s.add(i);return}a()}e.subscribe(Ct(s,function(c){r=c,o=t.now(),i||(i=t.schedule(l,n),s.add(i))},function(){a(),s.complete()},void 0,function(){r=i=null}))})}class Vr extends $t{constructor(t,e,s,i,r,o,a,l,c,h){super(e,s,i,r,o,a,l,c,h),this.baseModel=t}set visualPoints(t){super.visualPoints=t,this.baseModel.mainVisualPoints=super.visualPoints}get visualPoints(){return super.visualPoints}set dataPoints(t){super.dataPoints=t,this.baseModel.mainDataPoints=super.dataPoints}get dataPoints(){return super.dataPoints}recalculateMeanCandleWidth(t){super.recalculateMeanCandleWidth(t),this.baseModel.meanDataWidth=this.meanCandleWidth}}var Hd=Object.defineProperty,Ur=Object.getOwnPropertySymbols,kd=Object.prototype.hasOwnProperty,jd=Object.prototype.propertyIsEnumerable,Gr=(n,t,e)=>t in n?Hd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Yd=(n,t)=>{for(var e in t||(t={}))kd.call(t,e)&&Gr(n,e,t[e]);if(Ur)for(var e of Ur(t))jd.call(t,e)&&Gr(n,e,t[e]);return n};const Nd=(n,t,e,s)=>{var i,r,o,a;const l=Yd({},n),c=(r=(i=t[e])==null?void 0:i.startUnit)!=null?r:0,h=(a=(o=Bl(-e,t))==null?void 0:o.startUnit)!=null?a:0;let d=n.xStart,u=n.xEnd;return l.xStart>=h&&(d=h,u=u-(l.xStart-h)),l.xEnd<c&&(d=c-Ht(s.width,l.zoomX),u=c),l.xStart=d,l.xEnd=u,l},Xd=n=>(t,e={xScale:!0,yScale:!0})=>{if(t.length!==0){if(e.xScale){const s=t.slice(Math.max(t.length-n.state.defaultViewportItems,0)),i=s[0],r=s[s.length-1];n.setXScale(i.startUnit,r.startUnit+r.width+n.offsets.right)}e.yScale&&n.doAutoScale(!0),n.fireChanged()}},Wd=(n,t)=>(e,s=null)=>{const[i,r]=e,o=t.candleFromTimestamp(i).startUnit,a=t.candleFromTimestamp(r).startUnit,l=s===null?0:t.mainCandleSeries.meanCandleWidth*2,c=s?o-l:o+l,h=s?a+l:a-l;n.setXScale(c,h)};var zd=Object.defineProperty,Vd=Object.defineProperties,Ud=Object.getOwnPropertyDescriptors,Zr=Object.getOwnPropertySymbols,Gd=Object.prototype.hasOwnProperty,Zd=Object.prototype.propertyIsEnumerable,$r=(n,t,e)=>t in n?zd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ke=(n,t)=>{for(var e in t||(t={}))Gd.call(t,e)&&$r(n,e,t[e]);if(Zr)for(var e of Zr(t))Zd.call(t,e)&&$r(n,e,t[e]);return n},rn=(n,t)=>Vd(n,Ud(t));class $d{constructor(t){this.config=t,this.usedChartColors={},this.symbolsToColorKeys={},this.secondaryChartColorsPool=this.createColorPool(this.config.colors.secondaryChartTheme),this.usedChartColors=Object.keys(this.secondaryChartColorsPool).reduce((e,s)=>rn(ke({},e),{[s]:0}),{})}createColorPool(t){return t.reduce((e,s,i)=>(e[`color${i}`]=rn(ke({},re(this.config.colors)),{lineTheme:ke({},s.lineTheme),areaTheme:ke({},s.areaTheme)}),e),{})}takeColorFromPool(t){let e=Number.MAX_SAFE_INTEGER,s="";for(const[i,r]of Object.entries(this.usedChartColors))r<e&&(e=r,s=i);return this.usedChartColors[s]=this.usedChartColors[s]+1,this.symbolsToColorKeys[t]=s,this.secondaryChartColorsPool[s]}addColorToPool(t){const e=this.symbolsToColorKeys[t];this.usedChartColors[e]&&(this.usedChartColors[e]=this.usedChartColors[e]-1)}updateColorConfig(t,e){var s,i;const r=this.secondaryChartColorsPool[this.usedChartColors[t]];if(r){const o=e;this.secondaryChartColorsPool[this.usedChartColors[t]]=rn(ke({},e),{lineTheme:Object.assign(r.lineTheme,(s=o.lineTheme)!=null?s:{}),areaTheme:Object.assign(r.areaTheme,(i=o.areaTheme)!=null?i:{})})}}}var Kd=Object.defineProperty,Kr=Object.getOwnPropertySymbols,qd=Object.prototype.hasOwnProperty,Jd=Object.prototype.propertyIsEnumerable,qr=(n,t,e)=>t in n?Kd(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,fs=(n,t)=>{for(var e in t||(t={}))qd.call(t,e)&&qr(n,e,t[e]);if(Kr)for(var e of Kr(t))Jd.call(t,e)&&qr(n,e,t[e]);return n};class Qd extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.chartBaseModel=t,this.paneManager=e,this.bus=s,this.canvasModel=i,this.config=r,this.scale=o,this.formatterFactory=a,this.mainCanvasParent=l,this.canvasBoundsContainer=c,this.chartResizeHandler=h,this.prevChartWidth=0,this.prevYWidth=0,this.candleSeries=[],this.chartTypeChanged=new F,this.mainInstrumentChangedSubject=new F,this.offsetsChanged=new F,this.candlesTransformersByChartType={},this.lastCandleLabelsByChartType={},this.candleWidthByChartType={},this.lastTimeFrame=[0,0],this.FAKE_CANDLES_DEFAULT=100,this.toY=u=>this.mainCandleSeries.view.toY(u),this.prepareCandles=u=>{const f=u.map(xd).filter(_d),{sortCandles:g}=this.config.components.chart;return g?g(f):f},this.chartTypeChanged.next(this.config.components.chart.type),this.secondaryChartColors=new $d(this.config);const d=new Vr(this.chartBaseModel,this.paneManager.panes[K].mainExtent,wt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,new Rd,this.candlesTransformersByChartType,this.candleWidthByChartType,fs({},this.config.colors));d.config.type=this.config.components.chart.type,this.candleSeries.push(d),this.config.components.chart.minCandlesOffset>0&&o.addXConstraint((u,f)=>Nd(f,this.mainCandleSeries.visualPoints,this.config.components.chart.minCandlesOffset,o.getBounds())),this.basicScaleViewportTransformer=Xd(o),this.timeFrameViewportTransformer=Wd(o,this),this.pane=this.paneManager.panes[K]}get mainCandleSeries(){return this.candleSeries[0]}get secondaryCandleSeries(){return this.candleSeries.filter(t=>t!==this.mainCandleSeries)}get candlesUpdatedSubject(){return this.chartBaseModel.dataUpdatedSubject}get candlesSetSubject(){return this.chartBaseModel.dataSetSubject}get candlesRemovedSubject(){return this.chartBaseModel.dataRemovedSubject}get candlesPrependSubject(){return this.chartBaseModel.dataPrependSubject}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(K)).pipe(Tt(Yi)).subscribe(t=>{this.handleChartResize(t)})),this.addRxSubscription(this.scale.changed.pipe(zr(Zt)).subscribe(()=>this.paneManager.yExtents.forEach(t=>t.yAxis.updateOrderedLabels(!0))))}handleChartResize(t){if(t.width>be.width&&t.height>be.height){const e=this.canvasBoundsContainer.getEffectiveChartWidth(),s=this.canvasBoundsContainer.getEffectiveYAxisWidth();if(this.prevChartWidth===0&&this.scale){this.scale.isViewportValid(!1)?this.scale.recalculateZoom():this.doBasicScale(),this.prevChartWidth=e,this.prevYWidth=s;return}if(s!==this.prevYWidth){if(this.config.scale.keepZoomXOnYAxisChange){const r=Ht(s-this.prevYWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart,this.scale.xEnd-r)}else this.scale.recalculateZoomX();this.prevYWidth=s,this.prevChartWidth=e;return}const i=Ht(e-this.prevChartWidth,this.scale.zoomX);this.scale.setXScale(this.scale.xStart-i,this.scale.xEnd),this.scale.recalculateZoomY(),this.prevYWidth=s,this.prevChartWidth=e}}setMainCandleSeries(t,e){this.mainCandleSeries.instrument=e,this.setAllSeries({candles:t,instrument:e},this.getSecondarySeries().map(s=>{const i=s.dataPoints;return Yr(i),{candles:i,instrument:s.instrument}}))}setSecondaryCandleSeries(t,e=this.mainCandleSeries.instrument,s=!0){const i=this.prepareCandles(t),r=this.reindexCandlesBasedOnSeries(this.mainCandleSeries.dataPoints,i),o=this.secondarySeriesAdjustments(this.mainCandleSeries.dataPoints,r),l=this.secondaryCandleSeries.some(c=>c.instrument.symbol===e.symbol)?this.secondaryCandleSeries.find(c=>c.instrument.symbol===e.symbol):this.createSecondaryCandleSeriesModel(e);if(l)return l.dataPoints=o,s&&(this.scale.doAutoScale(),l.recalculateVisualPoints(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()),l}setAllSeries(t,e=[]){var s;this.mainCandleSeries.instrument=(s=t.instrument)!=null?s:this.mainCandleSeries.instrument,t.instrument&&this.mainInstrumentChangedSubject.next(t.instrument),this.rememberCurrentTimeframe();const i=this.prepareCandles(t.candles);this.mainCandleSeries.clearData(),He(i),this.mainCandleSeries.dataPoints=i,this.secondaryCandleSeries.filter(r=>e.filter(o=>{var a;return((a=o.instrument)==null?void 0:a.symbol)===r.instrument.symbol}).length===0).forEach(r=>this.removeSecondaryCandleSeries(r)),e.map(r=>this.setSecondaryCandleSeries(r.candles,r.instrument,!1)),this.candleSeries.forEach(r=>{r.recalculateDataViewportIndexes(),r.recalculateVisualPoints()}),this.chartBaseModel.recalculatePeriod(),this.autoScaleOnCandles(),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesSetSubject.next(),this.canvasModel.fireDraw()}autoScaleOnCandles(){this.scale.state.autoScaleOnCandles&&(this.doBasicScale(),this.scale.autoScale(!0))}doBasicScale(){this.basicScaleViewportTransformer(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doBasicXScale(){this.scale.setXScaleWithoutYScale(this.mainCandleSeries.visualPoints),this.bus.fireDraw()}doPreviousTimeFrameScale(t=null){this.timeFrameViewportTransformer(this.lastTimeFrame,t),this.scale.state.autoScaleOnCandles&&this.scale.doAutoScale(!0),this.bus.fireDraw()}rememberCurrentTimeframe(){this.mainCandleSeries.visualPoints.length!==0&&(this.lastTimeFrame=[this.candleFromX(this.scale.toX(this.scale.xStart),!0).timestamp,this.candleFromX(this.scale.toX(this.scale.xEnd),!0).timestamp])}updateAllSeries(t,e=[]){t=fs({},t),t.instrument||(t.instrument=this.mainCandleSeries.instrument);const s=[t,...e];if(!this.candleSeries.every(l=>s.find(c=>{var h;return((h=c.instrument)==null?void 0:h.symbol)===l.instrument.symbol}))||e.length!==this.secondaryCandleSeries.length){console.error("All series update failed. Instruments for series are different.");return}const i=this.prepareCandles(t.candles),r=Qr(this.mainCandleSeries.dataPoints,i),o=r.candles;He(o),this.mainCandleSeries.dataPoints=o,e.map(l=>{var c,h,d,u;const f=this.prepareCandles(l.candles),g=Qr((u=(d=this.findSecondarySeriesBySymbol((h=(c=l.instrument)==null?void 0:c.symbol)!=null?h:""))==null?void 0:d.dataPoints)!=null?u:[],f).candles;return this.setSecondaryCandleSeries(g,l.instrument,!1)}),this.candleSeries.forEach(l=>{l.recalculateVisualPoints()});const a=this.chartBaseModel.mainVisualPoints.slice(0,r.prepended.length).reduce((l,c)=>l+c.width,0);this.scale.moveXStart(this.scale.xStart+a),this.candleSeries.forEach(l=>{l.recalculateDataViewportIndexes()}),this.candlesPrependSubject.next({prependedCandlesWidth:a,prependedCandles:r.prepended}),this.chartBaseModel.recalculatePeriod(),this.candlesUpdatedSubject.next(),this.bus.fireDraw()}removeDataFrom(t){Object.values(this.paneManager.panes).forEach(e=>{e.dataSeries.forEach(s=>{const i=Yt(s.dataPoints,t,o=>o.timestamp),r=i.exact?i.index:i.index+1;s.dataPoints=s.dataPoints.slice(0,r)})}),this.candlesChangedRedraw()}createSecondaryCandleSeriesModel(t){const e=fs(fs({},this.config.colors),this.secondaryChartColors.takeColorFromPool(t.symbol));return this.createCandleSeriesModel(t,e)}createCandleSeriesModel(t,e){const s=new $t(this.paneManager.panes[K].mainExtent,wt(),this.paneManager.hitTestController.getNewDataSeriesHitTestId(),this.bus,this.scale,t,this.candlesTransformersByChartType,this.candleWidthByChartType,e);return s.config.type="line",this.candleSeries.push(s),s}removeSecondaryCandleSeries(t){return this.secondaryChartColors.addColorToPool(t.instrument.symbol),this.candleSeries=this.candleSeries.filter(e=>e!==t),t.deactivate(),this.paneManager.panes[K].removeDataSeries(t),this.scale.doAutoScale(),t.colors}secondarySeriesAdjustments(t,e){const s=[];return t.forEach(i=>{const r=this.candleIdxFromId(i.id),o=r>0?r:0,a=e[o];if(a)s.push(a);else{let l=Jr(e,o,-1);if(l||(l=Jr(e,o,1)),l){const c=Gl(l,o,!0);s.push(c)}}}),s}updateSecondaryCandleSeriesConfig(t,e,s){const i=At(t,es().colors);this.secondaryChartColors.updateColorConfig(e,i);const r=this.findSecondarySeriesBySymbol(e);r&&(r.config.type=s,r.updateCandleSeriesColors(i)),this.bus.fireDraw([this.canvasModel.canvasId])}setAutoScale(t){this.scale.autoScale(t)}setOffsets(t){this.scale.updateOffsets(t);const e=this.getCandlesCountWithRightOffset(),s=this.mainCandleSeries.visualPoints;this.hasCandles()&&e>=s.length&&this.scale.setXScale(this.scale.xStart,this.candleFromIdx(e).startUnit),this.offsetsChanged.next(),this.bus.fireDraw()}getOffsets(){return this.scale.getOffsets()}fromY(t){return this.scale.fromY(t)}priceFromY(t,e){return(e!=null?e:this.mainCandleSeries).view.priceFromY(t)}fromX(t){return this.scale.fromX(t)}toX(t){const e=this.candleFromIdx(t);return this.scale.toX(e.centerUnit)}candleFromX(t,e=!1,s=this.mainCandleSeries){const i=this.scale.fromX(t);return this.candleFromUnit(i,e,s)}candleFromUnit(t,e=!1,s=this.mainCandleSeries){var i,r;const o=Yt(s.visualPoints,t,d=>d.startUnit),a=s.visualPoints,l=this.getLastVisualCandle();a[o.index]!==void 0&&(t<0||l&&t>l.startUnit+l.width)&&(o.index+=Me((t-a[o.index].centerUnit)/this.mainCandleSeries.meanCandleWidth));const c=o.index,h=Math.max(Math.min(a.length-1,c),0);return(c<0||c>=a.length)&&e?Re(this.mainCandleSeries.dataPoints,c,this.chartBaseModel.period):(r=(i=a[h])==null?void 0:i.candle)!=null?r:Re(this.mainCandleSeries.dataPoints,h,this.chartBaseModel.period)}candleFromTimestamp(t,e={extrapolate:!0},s=this.mainCandleSeries){const i=s.dataPoints;return this.chartBaseModel.dataFromTimestamp(t,e,i)}candleFromId(t,e=this.mainCandleSeries){return e.visualPoints.find(s=>s.candle.id===t)}candleIdxFromId(t,e=this.mainCandleSeries){return e.visualPoints.findIndex(s=>s.candle.id===t)}candleFromIdx(t){return this.chartBaseModel.dataFromIdx(t)}isReady(){return this.canvasModel.isReady()&&this.hasCandles()}registerCandlesTransformer(t,e){this.candlesTransformersByChartType[t]=e}registerCandlesWidthCalculator(t,e){this.candleWidthByChartType[t]=e}registerLastCandleLabelHandler(t,e){this.lastCandleLabelsByChartType[t]=e}hasCandles(){return this.mainCandleSeries.visualPoints.length!==0}getVisualCandle(t){var e,s,i;const r=t-((i=(s=(e=this.mainCandleSeries.visualPoints[0])==null?void 0:e.candle)==null?void 0:s.idx)!=null?i:0);return this.mainCandleSeries.visualPoints[r]}getFirstIdx(){return this.mainCandleSeries.dataIdxStart}getLastIdx(){return this.mainCandleSeries.dataIdxEnd}getFirstTimestamp(t=!0){return t?this.candleFromIdx(this.getFirstIdx()).candle.timestamp:this.candleFromUnit(this.scale.xStart,!0).timestamp}getLastTimestamp(t=!0){return t?this.candleFromIdx(this.getLastIdx()).candle.timestamp:this.candleFromUnit(this.scale.xEnd,!0).timestamp}setTimestampRange(t,e,s=!0){const i=this.candleFromTimestamp(t).startUnit,r=this.candleFromTimestamp(e),o=r.startUnit+r.width;return this.scale.setXScale(i,o,s)}getLastCandle(){const t=this.mainCandleSeries.dataPoints;return St(t)}getLastVisualCandle(){const t=this.mainCandleSeries.visualPoints;return St(t)}getMaxCandlesFitLength(){return at(this.canvasBoundsContainer.getEffectiveChartWidth()/this.config.components.chart.minWidth)}getSecondarySeries(){return this.secondaryCandleSeries}isSeriesInstrument(t,e){return t.instrument.symbol===e}findSeriesBySymbol(t){return this.candleSeries.filter(e=>this.isSeriesInstrument(e,t))}findSecondarySeriesBySymbol(t){return this.secondaryCandleSeries.find(e=>this.isSeriesInstrument(e,t))}reindexCandlesBasedOnSeries(t,e){return e.reduce((s,i)=>{const r=i.timestamp,o=Oe(r,{extrapolate:!1},t,this.chartBaseModel.period);return o.index>=0&&o.index<t.length&&(i.idx=o.index,s[o.index]=i),s},[])}getPeriod(){return this.chartBaseModel.period}isCandleInViewport(t){return this.getFirstIdx()<=t&&t<=this.getLastIdx()}isLastCandleInViewport(){const t=this.getLastCandle();return t&&t.idx?this.isCandleInViewport(t.idx):!1}updateCandles(t,e=this.mainCandleSeries.instrument.symbol){const s=this.mainCandleSeries.instrument.symbol===e,i=this.findSeriesBySymbol(e);if(i.length===0){console.warn("updateCandles failed. Can't find series",e);return}i.forEach(r=>{const o=r.dataPoints;let a=!1,l=!1,c;t.forEach(h=>{var d;if(!h)return;const u=Oe(h.timestamp,{extrapolate:!0},o,this.getPeriod()),f=Math.min(u.index,o.length);a=a||f===o.length,o[f]=h,h.idx=f,r.dataPoints=o,r.recalculateDataViewportIndexes(),l=l||this.isCandleInViewport(f);const g=f>=o.length-1,m=c&&h.timestamp<c.timestamp;if(g&&!m&&(c=h),a&&c&&s&&l){const x=(d=this.candleWidthByChartType[this.config.components.chart.type])!=null?d:mr;this.scale.moveXStart(this.scale.xStart+x(c))}}),c&&(r.updateCurrentPrice(c.close),this.paneManager.yExtents.forEach(h=>h.yAxis.updateOrderedLabels(!0))),l&&c&&t.length===1?this.canvasModel.fireDraw():r.recalculateVisualPoints()}),this.config.scale.auto&&this.scale.doAutoScale(),this.candlesUpdatedSubject.next()}observeCandlesChanged(){return yt(this.candlesSetSubject,this.candlesUpdatedSubject)}getCandles(){return this.mainCandleSeries.dataPoints}getCandlesWithFake(t=this.getCandles(),e=0,s){const i=this.getCandlesCount(),r=s!=null?s:i+this.FAKE_CANDLES_DEFAULT;t=t.slice(Math.max(0,e),Math.min(i,r));const o=[],a=[];for(let c=i;c<r;c++)o.push(Re(this.mainCandleSeries.dataPoints,c,this.getPeriod()));const l=Math.min(0,r);for(let c=e;c<l;c++)a.push(Re(this.mainCandleSeries.dataPoints,c,this.getPeriod()));return[...a,...t,...o]}getCandlesCount(){return this.mainCandleSeries.dataPoints.length}getCandlesCountWithRightOffset(){return this.getCandlesCount()+this.getOffsets().right}clearData(){this.candleSeries.forEach(t=>t.clearData())}prependCandles(t,e){const s=t.slice(),i=[];return e.forEach(r=>{const a=Oe(r.timestamp,{extrapolate:!1},t).index;a<0?i.push(r):t[a].id===r.id?s[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:i,candles:[...i,...s]}}addLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}updateLastCandle(t,e=this.mainCandleSeries.instrument.symbol){this.updateCandles([t],e)}removeCandleByIdx(t,e=this.mainCandleSeries.instrument.symbol){if(t<0)return;const s=this.findSeriesBySymbol(e);if(s.length===0){console.warn("removeCandle by id failed. Can't find series",e);return}s.forEach(i=>{i.dataPoints=i.dataPoints.slice(0,t).concat(i.dataPoints.slice(t+1)),He(i.dataPoints),i.recalculateVisualPoints()}),this.candlesChangedRedraw()}removeCandlesByIdsSequence(t,e){const s=this.candleIdxFromId(t[0],e),i=this.candleIdxFromId(t[t.length-1],e);if(s<0||i<0){console.warn("Candle is not found");return}e.dataPoints=e.dataPoints.slice(0,s).concat(e.dataPoints.slice(i+1)),He(e.dataPoints,i),e.recalculateVisualPoints(),this.candlesChangedRedraw()}removeCandlesByIds(t,e){t.forEach(s=>this.removeCandleByIdx(this.candleIdxFromId(s,e)))}addCandlesById(t,e,s){const i=this.candleIdxFromId(e);if(i<0){console.warn("Selected start candle is not found");return}const r=s.dataPoints.slice(0,i),o=s.dataPoints.slice(i);s.dataPoints=r.concat(t).concat(o),He(s.dataPoints),s.recalculateVisualPoints(),this.candlesChangedRedraw()}candlesChangedRedraw(){this.candlesRemovedSubject.next(),this.candlesUpdatedSubject.next(),this.canvasModel.fireDraw()}}const Jr=(n,t,e)=>{if(t>=n.length)return n[n.length-1];for(let s=t;s<n.length&&s>=0;s+=e){const i=n[s];if(i)return i}},Qr=(n,t)=>{const e=n.slice(),s=[],i=[];return t.forEach(r=>{const a=Oe(r.timestamp,{extrapolate:!0},n).index;a<0?s.push(r):a>=n.length?i.push(r):n[a].timestamp===r.timestamp?e[a]=r:console.warn(`Couldn't update candle with timestamp ${r.timestamp}`)}),{prepended:s,appended:i,candles:[...s,...e,...i]}};class ye{constructor(t){this.canvasModel=t}draw(){this.canvasModel.clear()}getCanvasIds(){return[this.canvasModel.canvasId]}}class on{constructor(t){this.drawers=t!=null?t:new Map}draw(){this.drawers.forEach(t=>t.draw())}addDrawer(t,e){const s=e!=null?e:"drawer"+this.drawers.size;this.drawers.set(s,t)}drawLastBar(){this.drawers.forEach(t=>t.drawLastBar&&t.drawLastBar())}removeDrawer(t){const e=Ji(this.drawers,t);e?this.drawers.delete(e):console.warn("Couldn't find drawer type")}removeDrawerByName(t){this.drawers.delete(t)}getDrawer(t){return this.drawers.get(t)}moveTop(t){const e=Ji(this.drawers,t);e?this.moveTopByName(e):console.warn("Couldn't find drawer type")}moveTopByName(t){if(this.drawers.size===1)return;const e=this.drawers.get(t);this.drawers.delete(t),e&&this.drawers.set(t,e)}getSize(){return this.drawers.size}getAll(){return this.drawers}getCanvasIds(){const t=mt(Array.from(this.drawers).map(([,s])=>s.getCanvasIds())),e=new Set([...t]);return Array.from(e)}}class tu{constructor(t,e,s,i){this.model=t,this.config=e,this.crossToolCanvasModel=s,this.crossToolTypeDrawers=i}draw(){const t=this.crossToolTypeDrawers[this.config.components.crossTool.type];t?this.model.currentHover&&t.draw(this.crossToolCanvasModel.ctx,this.model.currentHover):console.error(`No cross tool drawer type registered for drawer type ${this.config.components.crossTool.type}`)}getCanvasIds(){return[this.crossToolCanvasModel.canvasId]}}var eu=Object.defineProperty,su=Object.defineProperties,nu=Object.getOwnPropertyDescriptors,to=Object.getOwnPropertySymbols,iu=Object.prototype.hasOwnProperty,ru=Object.prototype.propertyIsEnumerable,eo=(n,t,e)=>t in n?eu(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ou=(n,t)=>{for(var e in t||(t={}))iu.call(t,e)&&eo(n,e,t[e]);if(to)for(var e of to(t))ru.call(t,e)&&eo(n,e,t[e]);return n},au=(n,t)=>su(n,nu(t));class lu extends X{constructor(t,e,s,i,r,o,a){super(),this.config=t,this.crossToolCanvasModel=e,this.crossEventProducer=s,this.hoverProducer=i,this.canvasBoundsContainer=r,this.baselineModel=o,this.chartModel=a,this.currentHoverSubject=new ft(null)}get currentHover(){return this.currentHoverSubject.getValue()}set currentHover(t){this.currentHoverSubject.next(t)}setType(t){this.config.type=t}doActivate(){super.doActivate(),this.addRxSubscription(this.hoverProducer.hoverSubject.subscribe(t=>{this.crossEventProducer.crossSubject.getValue()!==null&&t!==null?Nt()?this.updateCrossToolMobile(t):this.updateCrossTool(t):this.currentHover=null,this.fireDraw()})),this.addRxSubscription(this.baselineModel.dragPredicate.subscribe(t=>{if(Nt())if(t)this.hoverProducer.deactivate();else{const e=this.crossEventProducer.crossToolTouchInfo;e.isSet&&this.crossEventProducer.crossSubject.next([e.temp.x,e.temp.y,K]),this.hoverProducer.activate()}}))}fireDraw(){this.config.type!=="none"&&this.crossToolCanvasModel.fireDraw()}updateCrossTool(t,e=this.config.magnetTarget,s=this.config.discrete){var i;const r=s?this.chartModel.toX((i=this.chartModel.candleFromX(t.x,!0).idx)!=null?i:0):t.x;if(this.currentHover===null?this.currentHover={x:r,y:0,time:t.timeFormatted,paneId:t.paneId}:(this.currentHover.x=r,this.currentHover.time=t.timeFormatted),t.candleHover&&t.paneId===K)switch(e){case"O":this.currentHover.y=t.candleHover.openY;break;case"C":this.currentHover.y=t.candleHover.closeY;break;case"H":this.currentHover.y=t.candleHover.highY;break;case"L":this.currentHover.y=t.candleHover.lowY;break;case"OHLC":this.currentHover.y=t.candleHover.closestOHLCY;break;case"none":this.currentHover.y=t.y;break}else this.currentHover.y=t.y;this.currentHover.paneId=t.paneId,this.currentHoverSubject.next(this.currentHover)}updateCrossToolMobile(t){var e;if(!this.hoverProducer.longTouchActivatedSubject.getValue())return;const{fixed:s,temp:i,isSet:r}=this.crossEventProducer.crossToolTouchInfo;if(!r){this.updateCrossTool(t);return}const o=this.canvasBoundsContainer.getBounds(M.PANE_UUID(t.paneId)),a=5,l=t.x-i.x,c=t.y-i.y,h=s.x+l,d=s.y+c,u=o.y+a,f=o.y+o.height-a,g=h<a?a:h>o.width-a?o.width-a:h,m=d<u?u:d>f?f:d,x=(e=this.hoverProducer.createHover(g,m,t.paneId))!=null?e:t,_=au(ou({},x),{x:g,y:m});this.crossEventProducer.crossToolHover=_,this.updateCrossTool(_)}}const Ot=4;function cu(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g;const m=r.align,x=(l=i.textFont)!=null?l:ne(r),_=i.bgColor,A=(c=i.textColor)!=null?c:se(_,o.labelTextColor,o.labelInvertedTextColor),L=(h=i.paddingTop)!=null?h:Ot,Y=(d=i.paddingBottom)!=null?d:Ot,H=(u=i.paddingEnd)!=null?u:Ot,B=Me(Xt(x,n)/2),j=s-B-L,W=s+B+Y-j;if(a&&!gs(s,t,W))return;n.save(),n.fillStyle=_,n.strokeStyle=_;const U=Me(t.width/6),G=m==="right"?t.x:t.x+t.width,V=m==="right"?G+U:G-U,Q=r.labelBoxMargin.end,J=Q-H,et=t.width-U-J;Xh(n,V,j,G,j+Me(W/2),V,j+W,et,(g=(f=r.typeConfig.badge)==null?void 0:f.rounded)!=null?g:!1,m),n.fillStyle=A,n.font=x;const tt=m==="right"?t.x+t.width-Mt(e,n,x)-Q:t.x+Q;n.fillText(e,tt,s+B-1),n.restore()}function hu(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x,_,A;const L=r.align,Y=(l=i.textFont)!=null?l:ne(r),H=i.bgColor,B=(c=i.textColor)!=null?c:se(H,o.labelTextColor,o.labelInvertedTextColor),j=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,$=(u=(d=i.paddingTop)!=null?d:j==null?void 0:j.top)!=null?u:Ot,W=(g=(f=i.paddingBottom)!=null?f:j==null?void 0:j.bottom)!=null?g:Ot,U=(x=(m=i.paddingEnd)!=null?m:j==null?void 0:j.end)!=null?x:Ot,G=i.paddingStart,V=Xt(Y,n),Q=s-V/2-$,et=s+V/2+W-Q,tt=(A=i.rounded)!=null?A:(_=r.typeConfig.rectangle)==null?void 0:_.rounded;if(a&&!gs(s,t,et))return;n.save(),n.fillStyle=H,n.strokeStyle=H;const st=r.labelBoxMargin.end;n.font=Y;const ut=Mt(e,n,Y),lt=st-U,xt=G!==void 0?ut+G+U:t.width-lt,Gt=L==="right"?t.x+t.width-lt-xt:t.x+lt,xe=L==="right"?t.x+t.width-ut-st:st;tt?Ar(n,Gt,Q,xt,et,4,!0):n.fillRect(Gt,Q,xt,et),n.fillStyle=B,n.fillText(e,xe,s+V/2-1),n.restore()}function du(n,t,e,s,i,r,o,a=!0){var l,c,h,d,u,f,g,m,x;const _=r.align,A=(l=i.textFont)!=null?l:ne(r),L=o.backgroundColor,Y=(c=i.textColor)!=null?c:se(L,o.labelTextColor,o.labelInvertedTextColor),H=(h=r.typeConfig.rectangle)==null?void 0:h.paddings,B=(u=(d=i.paddingTop)!=null?d:H==null?void 0:H.top)!=null?u:Ot,j=(g=(f=i.paddingBottom)!=null?f:H==null?void 0:H.bottom)!=null?g:Ot,$=(x=(m=i.paddingEnd)!=null?m:H==null?void 0:H.end)!=null?x:Ot,W=i.paddingStart,U=Xt(A,n),G=s-U/2-B,Q=s+U/2+j-G;if(a&&!gs(s,t,Q))return;n.save(),n.fillStyle=L,n.strokeStyle=L;const J=r.labelBoxMargin.end;n.font=A;const et=Mt(e,n,A),tt=J-$,st=W!==void 0?et+W+$:t.width-tt,ut=_==="right"?t.x+t.width-tt-st:t.x+tt,lt=_==="right"?t.x+t.width-et-J:J;n.fillStyle=L,n.strokeStyle=L,n.fillRect(ut,G,st,Q),n.fillStyle=Y,n.fillText(e,lt,s+U/2-1),n.restore()}function uu(n,t,e=Ot){return Xt(n,t)/2+e}function gs(n,t,e){return!(n<t.y+e/2||n>t.y+t.height-e/2)}const fu="badge",so=4,no={badge:cu,rectangle:hu,plain:du};function io(n,t,e,s,i,r,o,a,l){var c,h,d,u,f;const g=r.y,m=r.labelText,x=(c=r.mode)!=null?c:"label",_=(h=r.labelType)!=null?h:fu,A=r.description,L=(d=r.textFont)!=null?d:ne(a),Y=r.bgColor,H=(u=r.lineColor)!=null?u:Y,B=Mt(A!=null?A:"",n,L)+8,j=at(r.y),$=Xt(L,n),W=g-$/2,G=g+$/2-W;n.save(),n.fillStyle=Y,n.strokeStyle=H;const V=o.getBounds(M.PANE_UUID(K)),Q=no[_],J=a.labels.descriptions,et=gu(s,j,G),tt=()=>J&&pu(e,t,s,i,r,a);let st,ut;const lt=2;a.align==="right"?(st=V.x,ut=J?V.x+V.width-B:V.x+V.width+lt):(st=J?V.x+B:V.x-lt,ut=V.x+V.width);const xt=(f=r.lineY)!=null?f:r.y,Gt=()=>et&&ae(n,()=>Wh(n,st,xt,ut,xt,1,r.lineDash)),xe=()=>Q(n,s,Je(m),g,r,a,l.yAxis,!1),xs={line:()=>{Gt(),tt()},"line-label":()=>{Gt(),xe(),tt()},label:()=>{tt(),xe()}};x!=="none"&&gs(g,s,G)&&xs[x](),n.restore()}const gu=(n,t,e)=>t>n.y+e/2&&t<n.y+n.height-e/2;function pu(n,t,e,s,i,r){var o,a,l;const c=r.align||"right",h=i.description;if(!h||h.length===0)return;const d=i.y,u=ne(r),f=Mt(h,t,u),g=Xt(u,t),m=(o=i.paddingTop)!=null?o:so,x=(a=i.paddingBottom)!=null?a:so,_=d-g/2-m,L=d+g/2+x-_;t.save();const Y=f+5,H=4,B=f+H*2,j=s.x+s.width,$=c==="right"?j-B:s.x+H;ah(n,t,$,_,Y,L,.8),t.fillStyle=(l=i.descColor)!=null?l:i.bgColor,t.font=u;const W=c==="right"?j-f-H*2:s.x+H*2;t.fillText(h,W,d+g/2-1),t.restore()}class ro{constructor(t,e,s,i=()=>!0,r){this.config=t,this.canvasBoundsContainer=e,this.paneManager=s,this.crossDrawPredicate=i,this.noLines=r}draw(t,e){this.crossDrawPredicate()&&ae(t,()=>this.drawCrossTool(t,e))}drawCrossTool(t,e){var s,i,r,o,a;const l=this.canvasBoundsContainer.getBounds(M.ALL_PANES),c=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES,{extensionY:1e-4}),h=(s=this.config.components.xAxis.padding.top)!=null?s:0,d=(r=this.config.components.yAxis.typeConfig[(i=this.config.components.crossTool.yLabel.type)!=null?i:"badge"])==null?void 0:r.paddings,u=(o=d==null?void 0:d.start)!=null?o:0,f=(a=this.paneManager.panes[e.paneId])==null?void 0:a.ht;if(c(e.x,l.y)){const g={start:[l.x,e.y],end:[l.x+l.width+u,e.y]},m={start:[e.x,l.y],end:[e.x,l.y+l.height+h]},x=f==null?void 0:f(e.x,e.y);this.noLines||(t.strokeStyle=this.config.colors.crossTool.lineColor,t.setLineDash(this.config.components.crossTool.lineDash),t.beginPath(),x&&(t.moveTo(...g.start),t.lineTo(...g.end)),t.moveTo(...m.start),t.lineTo(...m.end),t.stroke()),x&&this.drawYLabel(t,e),this.drawXLabel(t,e)}}drawXLabel(t,e){var s,i,r,o,a;const l=this.config.components.crossTool.xLabel.padding,c=this.config.components.crossTool.xLabel.margin,h=this.config.colors.crossTool;if(this.config.components.xAxis.visible){t.font=this.config.components.xAxis.fontSize+"px "+this.config.components.xAxis.fontFamily;const d=e.x,u=e.time,f=t.measureText(u).width,g=this.config.components.xAxis.fontSize,m=this.canvasBoundsContainer.getBounds(M.X_AXIS);t.save(),t.fillStyle=h.labelBoxColor;const x=(s=l==null?void 0:l.left)!=null?s:0,_=(i=l==null?void 0:l.right)!=null?i:0,A=(r=l==null?void 0:l.top)!=null?r:0,L=(o=l==null?void 0:l.bottom)!=null?o:0,Y=(a=c==null?void 0:c.top)!=null?a:0,H=f+x+_,B=g+A+L,j=Math.max(d-H/2,0),$=m.y+Y+De/2;Ar(t,j,$,H,B),t.fillStyle=h.labelTextColor;const W=Math.max(d-f/2,x),U=m.y+Y+g+De/2+A-1;t.fillText(u,W,U),t.restore()}}drawYLabel(t,e){const s=this.config.components.crossTool.yLabel.padding,i=this.config.colors.crossTool;if(this.config.components.yAxis.visible){const r=this.paneManager.panes[e.paneId],o=e.y,a=this.config.components.crossTool.yLabel.type;if(!r)return;for(const l of r.yExtentComponents){const c=l.regularValueFromY(o),h=l.valueFormatter(c),d=this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(r.uuid,l.idx)),u=no[a],f=a==="plain"?i.lineColor:i.labelTextColor;u(t,d,h,o,{textColor:f,bgColor:i.labelBoxColor,paddingBottom:s==null?void 0:s.bottom,paddingEnd:s==null?void 0:s.end,paddingTop:s==null?void 0:s.top},l.yAxis.state,this.config.colors.yAxis,!0)}}}}class mu{draw(){}}class vu extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.config=t,this.crossToolCanvasModel=e,this.canvasBoundsContainer=s,this.drawingManager=i,this.paneManager=r,this.crossEventProducer=o,this.hoverProducer=a,this.baselineModel=l,this.chartModel=c,this.crossToolTypeDrawers={},this.model=new lu(t.components.crossTool,this.crossToolCanvasModel,this.crossEventProducer,this.hoverProducer,this.canvasBoundsContainer,this.baselineModel,this.chartModel),this.addChildEntity(this.model);const h=new ye(this.crossToolCanvasModel);this.registerDefaultDrawerTypes();const d=new tu(this.model,this.config,this.crossToolCanvasModel,this.crossToolTypeDrawers),u=new on;u.addDrawer(h,"CLEAR_CANVAS"),u.addDrawer(d,"CROSS_TOOL_DRAWER"),this.drawingManager.addDrawer(u,"CROSS_TOOL")}registerDefaultDrawerTypes(){this.registerCrossToolTypeDrawer("cross-and-labels",new ro(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0)),this.registerCrossToolTypeDrawer("just-labels",new ro(this.config,this.canvasBoundsContainer,this.paneManager,()=>!0,!0)),this.registerCrossToolTypeDrawer("none",new mu)}setVisible(t){this.model.setType(t?"cross-and-labels":"none")}setType(t){this.model.setType(t)}observeCrossToolChanged(){return this.model.currentHoverSubject}setMagnetTarget(t){this.config.components.crossTool.magnetTarget=t}registerCrossToolTypeDrawer(t,e){this.crossToolTypeDrawers[t]=e}}class bu{constructor(t,e){this.dynamicObjectsModel=t,this.canvasModel=e}draw(){const t=this.dynamicObjectsModel.objects;Object.entries(t).forEach(([e,s])=>{for(const i of s){const{model:r,drawer:o}=i;o.draw(this.canvasModel,r,e)}})}getCanvasIds(){return[this.canvasModel.canvasId]}}class zt{constructor(t){this.data=t,this.next=null}}class Cu{constructor(t){if(this._head=null,this._tail=null,this.length=0,this._head=t!=null?t:null,this.head!==null){let e=this.head;for(;e.next;)e=e.next;this._tail=e,this.length++}}insertAtEnd(t){const e=new zt(t);if(this.head===null)this._head=e;else{let s=this.head;for(;s.next;)s=s.next;s.next=e}this._tail=e,this.length++}insertAt(t,e){if(!this.head||t<0||t>this.length)return null;const s=new zt(e);if(t===0)s.next=this.head,this._head=s;else{let i=this.head,r=i,o=0;for(;i&&o<t;)o++,r=i,i=i.next;s.next=i,r.next=s,t===this.length-1&&(this._tail=s)}this.length++}removeAt(t){if(!this.head||t<0||t>=this.length)return null;let e=this.head,s=e,i=0;if(t===0)this._head=e.next;else{for(;e.next&&i<t;)i++,s=e,e=e.next;s.next=e.next,t===this.length-1&&(this._tail=s)}this.length--}getNodePosition(t){let e=0,s=this.head;for(;s;){if(s.data===t.data)return e;s=s.next,e++}return-1}size(){return this.length}get head(){return this._head}get tail(){return this._tail}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.data,t=t.next}}class yu extends X{constructor(t){super(),this.canvasModel=t,this.modelIdToObjectMap=new Map,this._uniqueObjects={},this._objects=new ft({})}getObjectInfoById(t){const e=this.modelIdToObjectMap.get(t);if(!e)return;const s=e.paneId,r=this.objects[s];if(r)return[e,r]}getObjectPosition(t){const e=this.getObjectInfoById(t);if(!e)return-1;const[s,i]=e,r=new zt(s);return i.getNodePosition(r)}addObject(t){var e,s;const i=t.paneId,r=this.objects,o=(e=r[i])!=null?e:new Cu;Object.keys(r).find(a=>a===i)||(r[i]=o),o.insertAtEnd(t),this.modelIdToObjectMap.set(t.id,t),this.uniqueObjects[i]||(this.uniqueObjects[i]=new Set),this.uniqueObjects[i].add((s=t.parentId)!=null?s:t.id),this.setDynamicObjects(r)}removeObject(t){var e;const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new zt(i),a=r.getNodePosition(o);r.removeAt(a),this.modelIdToObjectMap.delete(t),this.uniqueObjects[i.paneId]&&this.uniqueObjects[i.paneId].delete((e=i.parentId)!=null?e:i.id),r.size()===0&&delete this.objects[i.paneId],this.setDynamicObjects(this.objects)}updateObject(t){const e=this.getObjectInfoById(t.id);if(!e)return;const[s]=e;this.removeObject(s.id),this.addObject(t)}moveToPosition(t,e){const s=this.getObjectInfoById(t);if(!s)return;const[i,r]=s,o=new zt(i),a=r.getNodePosition(o);a!==e&&(a<e?(r.insertAt(e,i),r.removeAt(a)):(r.removeAt(a),r.insertAt(e,i)),this.setDynamicObjects(this.objects))}bringToFront(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>=0&&o<i.size()&&(i.removeAt(o),i.insertAtEnd(s),this.setDynamicObjects(this.objects))}bringToBack(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>0&&o<=i.size()&&(i.removeAt(o),i.insertAt(0,s),this.setDynamicObjects(this.objects))}moveForward(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>=0&&o+1<i.size()&&(i.removeAt(o),i.insertAt(o+1,s),this.setDynamicObjects(this.objects))}moveBackwards(t){const e=this.getObjectInfoById(t);if(!e)return;const[s,i]=e,r=new zt(s),o=i.getNodePosition(r);o>0&&o<i.size()&&(i.removeAt(o),i.insertAt(o-1,s),this.setDynamicObjects(this.objects))}get objects(){return this._objects.getValue()}get uniqueObjects(){return this._uniqueObjects}setDynamicObjects(t){this._objects.next(t),this.canvasModel.fireDraw()}}class wu extends X{constructor(t,e){super();const s=new yu(t);this.model=s,this.addChildEntity(s);const i=new bu(s,t);e.addDrawer(i,"DYNAMIC_OBJECTS")}}const Su=()=>n=>n.toString(),xu=(n,t)=>{var e;const s="date.get"+(t((e=n.timezone)!=null?e:"")?"":"UTC"),i={YYYY:r("FullYear"),YY:r("FullYear")+" % 100",MMM:o("shortMonths","Month"),MMMM:a(o("shortMonths","Month")),M:"1+"+r("Month"),d:r("Date"),H:r("Hours"),m:r("Minutes"),s:r("Seconds"),sss:r("Milliseconds"),EEE:o("shortDays","Day"),SSS:"this.addTwoZeros("+r("Milliseconds")+")",T:"date.getTime()"};["s","m","H","d","M"].forEach(function(l){i[l+l]="this.addZero("+i[l]+")"});function r(l){return s+l+"()"}function o(l,c){return"this."+l+"["+r(c)+"]"}function a(l){return l+".toUpperCase()"}return function(l){var c;const h={shortDays:_u(n),shortMonths:Pu(n),addZero(d){return d<10?"0"+d:d},addTwoZeros(d){return(d<100?"0":"")+(d<10?"0":"")+d},tzDate:t((c=n.timezone)!=null?c:"")||function(d){return new Date(+d)}};return d=>Tu(h.tzDate(d),l,h.shortDays,h.shortMonths)}};function _u(n){var t;return(t=n.shortDays)!=null?t:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}function Pu(n){var t;return(t=n.shortMonths)!=null?t:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}const oo=(n,t,e)=>{if(n){if(typeof n=="string")return e(n);if(Array.isArray(n)){const s=n.filter(i=>{if(i.showWhen){const r=[];return i.showWhen.periodLessThen&&r.push(()=>{var o,a;return t<((a=(o=i.showWhen)==null?void 0:o.periodLessThen)!=null?a:0)}),i.showWhen.periodMoreThen&&r.push(()=>{var o,a;return t>=((a=(o=i.showWhen)==null?void 0:o.periodMoreThen)!=null?a:0)}),r.every(o=>o())}else return!0});if(s.length>0){const i=s[0];if(i.format)return e(i.format);if(i.customFormatter)return i.customFormatter}}}return Su()},Tu=(n,t,e,s)=>{t||(t="M/d/yyyy");const i=n.getDate(),r=n.getMonth(),o=n.getFullYear(),a=n.getHours(),l=n.getMinutes(),c=n.getSeconds(),h=n.getMilliseconds(),d=a%12,u=we(d),f=we(a),g=we(l),m=we(c),x=a<12?"AM":"PM",_=e[n.getDay()],A=_.substring(0,3),L=we(i),Y=r+1,H=we(Y),B=s[r],j=B.substring(0,3),$=o+"",W=$.substring(2,4);return t=t.replace("hh",u+"").replace("h",d+"").replace("HH",f+"").replace("H",a+"").replace("mm",g+"").replace("m",l+"").replace("ss",m+"").replace("s",c+"").replace("S",h+"").replace("dd",L+"").replace("d",i+"").replace("EEEE",_).replace("EEE",A).replace("YYYY",$).replace("yyyy",$).replace("YY",W).replace("yy",W).replace("aaa",x),t.indexOf("MMM")>-1?t=t.replace("MMMM",B).replace("MMM",j):t=t.replace("MM",H+"").replace("M",Y+""),t},we=n=>typeof n=="number"&&n<10?"0"+n:n,je=(n,t)=>`${n}_${t}`,Mu=(n,t)=>{if(t){const e=ao(t.normal),s=ao(t.hover);return{type:n,normal:e,hover:s}}},ao=n=>{var t;const s=new DOMParser().parseFromString(n,"text/html").querySelector("svg");let i=0;s&&(i=parseInt((t=s.getAttribute("height"))!=null?t:"",10));const a="data:image/svg+xml;base64,"+btoa(n),l=new Image;return l.src=a,{img:l,svgHeight:i}},Au=(n,t,e,s,i)=>{if(i){const r=t[je(s,"hover")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}else{const r=t[je(s,"normal")];n.drawImage(r.img,e.x-r.svgHeight/2,e.y-r.svgHeight/2)}},Eu={"rhombus-small":4,rhombus:6,"rhombus-large":8},Iu=["earnings","dividends","splits","conference-calls"];class Du{constructor(t,e,s,i,r,o){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.formatterProvider=o,this.customIcons={};const a=this.config.components.events.icons;a&&Iu.forEach(l=>{const c=Mu(l,a[l]);c&&(this.customIcons[je(c.type,"normal")]=c.normal,this.customIcons[je(c.type,"hover")]=c.hover)})}draw(){if(!this.config.components.events.visible)return;const t=this.canvasBoundsContainer.getBounds(M.EVENTS),e=this.canvasBoundsContainer.getBounds(M.ALL_PANES),s=this.canvasModel.ctx;s.save(),this.model.events.filter(i=>this.config.components.events.eventsVisibility[i.type]).forEach(i=>{var r,o,a,l;const c=this.chartModel.candleFromTimestamp(i.timestamp).xCenter(this.chartModel.scale);if(c>e.x&&c<e.x+e.width){const h=this.config.colors.events[i.type];if(s.strokeStyle=(o=(r=h.line)!=null?r:h.normal)!=null?o:h.color,this.customIcons[je(i.type,"hover")]!==void 0){const d={x:c,y:t.y+t.height/2},u=this.model.hoveredEvent.getValue()===i;Au(s,this.customIcons,d,i.type,u)}else this.drawDefaultEvent(s,c,t,i,h);if(this.model.hoveredEvent.getValue()===i){const d=this.config.components.events.line,u=d&&d[i.type]&&((a=d[i.type])==null?void 0:a.width),f=d&&d[i.type]&&((l=d[i.type])==null?void 0:l.dash);s.lineWidth=u!=null?u:1,s.beginPath(),s.setLineDash(f!=null?f:[]),s.moveTo(c,e.y),s.lineTo(c,t.y+t.height/2),s.stroke(),s.closePath(),this.config.components.xAxis.visible&&this.drawLabel(c,i)}}}),s.restore()}drawDefaultEvent(t,e,s,i,r){var o,a,l;const c=s.y+s.height/2;t.fillStyle=(o=r.normal)!=null?o:r.color,t.lineWidth=1.5;const h=an(i);t.beginPath(),t.moveTo(e-h,c),t.lineTo(e,c-h),t.lineTo(e+h,c),t.lineTo(e,c+h),t.closePath(),this.model.hoveredEvent.getValue()===i?(t.fillStyle=(a=r.hover)!=null?a:r.color,t.fill()):(t.strokeStyle=(l=r.normal)!=null?l:r.color,t.stroke())}drawLabel(t,e){var s;const i=this.canvasModel.ctx,r=this.canvasBoundsContainer.getBounds(M.X_AXIS),o=this.config.components.xAxis.fontFamily,a=this.config.components.xAxis.fontSize,l=(s=this.config.components.xAxis.padding.top)!=null?s:0,c=r.y+a-1+l;i.font=`${a}px ${o}`;const h=this.formatterProvider()(e.timestamp),d=i.measureText(h).width;i.fillStyle=this.config.colors.xAxis.backgroundColor,i.strokeStyle=this.config.colors.xAxis.backgroundColor,i.fillRect(t-d/2,r.y+1,d,r.height-1),i.fillStyle=this.config.colors.events[e.type].color,i.fillText(h,t-d/2,c)}getCanvasIds(){return[this.canvasModel.canvasId]}}function an(n){return Eu[n.style]}const ps=5;class Lu{constructor(t,e,s,i,r,o=()=>!0){this.hitTestCanvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i,this.model=r,this.drawPredicate=o}draw(){if(this.drawPredicate()){const t=this.hitTestCanvasModel.ctx,e=this.canvasBoundsContainer.getBounds(M.EVENTS);t.save(),this.model.events.forEach((s,i)=>{if(!this.config.components.events.eventsVisibility[s.type])return;const o=this.model.events[i-1],a=o&&this.chartModel.candleFromTimestamp(o.timestamp).xCenter(this.chartModel.scale),l=this.chartModel.candleFromTimestamp(s.timestamp).xCenter(this.chartModel.scale);if(l>e.x&&l<e.x+e.width){const c=this.config.colors.events[s.type].color;t.strokeStyle=c,t.fillStyle=c;const h=an(s);t.fillStyle=this.hitTestCanvasModel.idToColor(s.id);const d=(h+ps)*2;if(a!==void 0){const u=an(o);if(this.config.components.events.eventsVisibility[o.type]&&a+u>l-d/2){const m=h*2+ps;t.fillRect(a+u,e.y,m,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}else t.fillRect(l-h-ps,e.y,d,e.height)}}),t.restore()}}getCanvasIds(){return[this.hitTestCanvasModel.canvasId]}}var Ou=Object.defineProperty,lo=Object.getOwnPropertySymbols,Bu=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,co=(n,t,e)=>t in n?Ou(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Fu=(n,t)=>{for(var e in t||(t={}))Bu.call(t,e)&&co(n,e,t[e]);if(lo)for(var e of lo(t))Ru.call(t,e)&&co(n,e,t[e]);return n};const ho=317,ln={DRAWINGS:[1,4999],NEWS:[5e3,5999],DATA_SERIES:[6e3,9999],EVENTS:[1e4,12999],EXECUTED_ORDERS:[13e3,15999]};class Hu extends Rr{constructor(t,e,s,i,r,o,a,l){super(t,e,r,a,l,{willReadFrequently:!0,desynchronized:!0}),this.canvasInputListener=s,this.canvasBoundsContainer=i,this.hitTestSubscribers=[],this.eventsSubscriptions=[],this.hoverSubject=new F,this.touchStartSubject=new F,this.dblClickSubject=new F,this.rightClickSubject=new F,this.hitTestDrawersPredicateSubject=new ft(!0),this.curImgData=new Uint8ClampedArray(4),this.prevAnimationFrameId=-1,Fr(this,o),e.style.visibility="hidden",this.enableUserControls()}enableUserControls(){if(this.eventsSubscriptions.length===0){const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),e=this.canvasInputListener.observeMouseMove().pipe(Lt(100,Rt,{trailing:!0})).subscribe(c=>this.eventHandler(c,"hover")),s=this.canvasInputListener.observeTouchStart().pipe(dt(()=>this.canvasInputListener.currentPoint)).subscribe(c=>this.eventHandler(c,"touchstart")),i=yt(this.canvasInputListener.observeMouseDown(t),this.canvasInputListener.observeTouchStart().pipe(dt(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mousedown")),r=yt(this.canvasInputListener.observeMouseUp(t),this.canvasInputListener.observeTouchEndDocument().pipe(dt(()=>this.canvasInputListener.currentPoint))).subscribe(c=>this.eventHandler(c,"mouseup")),o=this.canvasInputListener.observeDbClick(t).subscribe(c=>this.eventHandler(c,"dblclick")),a=this.canvasInputListener.observeContextMenu(t).pipe(dt(()=>Fu({},this.canvasInputListener.currentPoint))).subscribe(c=>{this.eventHandler(c,"contextmenu")}),l=this.canvasInputListener.observeWheel(t).subscribe(c=>setTimeout(()=>this.eventHandler(c,"zoom"),0));this.eventsSubscriptions.push(e,i,o,a,l,s,r)}}disableUserControls(){this.eventsSubscriptions.forEach(t=>t.unsubscribe()),this.eventsSubscriptions=[]}addSubscriber(t){this.hitTestSubscribers.push(t)}removeSubscriber(t){this.hitTestSubscribers=this.hitTestSubscribers.filter(e=>e===t)}idToColor(t){const e=(t*ho).toString(16);return"#000000".substr(0,7-e.length)+e}colorToId(t){return t/ho}observeHoverOnElement(){return this.hoverSubject.asObservable()}observeTouchStartOnElement(){return this.touchStartSubject.asObservable()}observeDblClickOnElement(){return this.dblClickSubject.asObservable()}observeRightClickOnElement(){return this.rightClickSubject.asObservable()}getPixel(t,e){const s=window.devicePixelRatio;return this.prevAnimationFrameId!==Hs&&(this.curImgData=this.ctx.getImageData(t*s,e*s,1,1).data,this.prevAnimationFrameId=Hs),this.curImgData}resolveModel(t){const e=this.getPixel(t.x,t.y),s=this.colorToId(e[0]*65536+e[1]*256+e[2]),i=Number(s),[r]=cn(this.hitTestSubscribers,i);return r==null?void 0:r.lookup(s)}resolveCursor(t){var e;if(!this.hitTestSubscribers.some(l=>l.resolveCursor!==void 0))return;const s=this.getPixel(t.x,t.y),i=this.colorToId(s[0]*65536+s[1]*256+s[2]),r=Number(i),[o]=cn(this.hitTestSubscribers,r),a=o==null?void 0:o.lookup(i);return(e=o==null?void 0:o.resolveCursor)==null?void 0:e.call(o,t,a)}eventHandler(t,e){var s,i,r,o,a,l,c;const h=this.getPixel(t.x,t.y),d=this.colorToId(h[0]*65536+h[1]*256+h[2]),u=Number(d),[f,g]=cn(this.hitTestSubscribers,u),m=f==null?void 0:f.lookup(d),x={point:t,model:m};switch(e){case"mousedown":m&&((s=f==null?void 0:f.onMouseDown)==null||s.call(f,m,t)),g.forEach(_=>_.onMouseDown&&_.onMouseDown(null,t));break;case"mouseup":m&&((i=f==null?void 0:f.onMouseUp)==null||i.call(f,m,t)),g.forEach(_=>_.onMouseUp&&_.onMouseUp(null,t));break;case"hover":m&&((r=f==null?void 0:f.onHover)==null||r.call(f,m,t)),g.forEach(_=>_.onHover&&_.onHover(null,t)),this.hoverSubject.next(x);break;case"touchstart":m&&((o=f==null?void 0:f.onTouchStart)==null||o.call(f,m,t)),g.forEach(_=>_.onTouchStart&&_.onTouchStart(null,t)),this.touchStartSubject.next(x);break;case"dblclick":m&&((a=f==null?void 0:f.onDblClick)==null||a.call(f,m,t)),this.dblClickSubject.next(x);break;case"contextmenu":m&&((l=f==null?void 0:f.onRightClick)==null||l.call(f,m,t)),this.rightClickSubject.next(x);break;case"zoom":m&&((c=f==null?void 0:f.onZoom)==null||c.call(f,m,t)),g.forEach(_=>_.onZoom&&_.onZoom(null,t));break;default:break}}}const cn=(n,t)=>{let e;const s=[];return n.forEach(i=>{const[r,o]=i.getIdRange();t>=r&&t<=o?e=i:s.push(i)}),[e,s]};var ku=Object.defineProperty,ju=Object.defineProperties,Yu=Object.getOwnPropertyDescriptors,uo=Object.getOwnPropertySymbols,Nu=Object.prototype.hasOwnProperty,Xu=Object.prototype.propertyIsEnumerable,fo=(n,t,e)=>t in n?ku(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Wu=(n,t)=>{for(var e in t||(t={}))Nu.call(t,e)&&fo(n,e,t[e]);if(uo)for(var e of uo(t))Xu.call(t,e)&&fo(n,e,t[e]);return n},zu=(n,t)=>ju(n,Yu(t));class Vu extends X{constructor(t){super(),this.canvasModel=t,this.events=[],this.hoveredEvent=new ft(null)}setEvents(t){this.events=this.indexEvents(t)}indexEvents(t){const e=this.getIdRange()[0];return t.map((s,i)=>zu(Wu({},s),{id:i+e})).sort((s,i)=>s.timestamp-i.timestamp)}getIdRange(){return ln.EVENTS}lookup(t){return this.events.filter(e=>e.id===t)[0]}onHover(t,e){this.hoveredEvent.getValue()!==t&&(t&&(t.point=e),this.hoveredEvent.next(t),this.canvasModel.fireDraw())}onTouchStart(t,e){this.onHover(t,e)}}class Uu extends X{constructor(t,e,s,i,r,o,a,l){super(),this.config=t,this.canvasModel=e,this.canvasBoundsContainer=r,this.drawingManager=o,this.formatterFactory=a,this.eventsXAxisLabelFormatterProvider=()=>oo(this.config.components.events.xAxisLabelFormat,i.getPeriod(),this.formatterFactory);const c=new Vu(e);this.eventsModel=c,this.addChildEntity(c),s.addSubscriber(c);const h=new Du(e,i,t,r,c,this.eventsXAxisLabelFormatterProvider);this.drawingManager.addDrawer(h,"EVENTS");const d=new Lu(s,i,t,r,c,()=>s.hitTestDrawersPredicateSubject.getValue());this.drawingManager.addDrawerBefore(d,"HIT_TEST_EVENTS","HIT_TEST_DRAWINGS"),l.setCursorForCanvasEl(M.EVENTS,t.components.events.cursor)}setEvents(t){this.eventsModel.setEvents(t),this.canvasModel.fireDraw()}setVisible(t){this.config.components.events.visible=t,this.canvasBoundsContainer.recalculateBounds(),this.canvasModel.fireDraw()}setEventTypeVisible(t){At(this.config.components.events.eventsVisibility,t,{overrideExisting:!0,addIfMissing:!1}),this.canvasModel.fireDraw()}observeEventHovered(){return this.eventsModel.hoveredEvent.asObservable()}}class Gu{constructor(t,e,s,i,r,o,a,l,c=()=>!0,h,d,u){this.canvasModel=t,this.viewportModel=e,this.config=s,this.yAxisState=i,this.xBoundsProvider=r,this.yBoundsProvider=o,this.xLabelsProvider=a,this.yLabelsProvider=l,this.drawPredicate=c,this.extentIdx=h,this.getBaseline=d,this.mainExtentIdx=u}draw(){if(this.drawPredicate()){const t=this.canvasModel.ctx;ae(t,()=>this.drawVertical(t)),ae(t,()=>this.drawHorizontal(t)),ae(t,()=>this.drawZeroLine(t))}}drawZeroLine(t){const e=this.yLabelsProvider();if(this.extentIdx===0&&this.getBaseline&&this.yAxisState.type==="percent"&&this.yAxisState.zeroPercentLine&&e.length){const s=this.xBoundsProvider(),i=at(this.getBaseline());t.beginPath(),t.strokeStyle=this.config.colors.yAxis.zeroPercentLine,t.setLineDash([]),t.moveTo(s.x,i),t.lineTo(s.x+s.width,i),t.stroke(),t.closePath()}}drawVertical(t){const e=this.xLabelsProvider();if(e.length&&this.config.components.grid.vertical){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.xBoundsProvider(),i=s.x+s.width;for(const r of e){const o=Et(this.viewportModel.toX(r.value));o>s.x&&o<i&&(t.beginPath(),t.moveTo(o,s.y),t.lineTo(o,s.y+s.height),t.stroke())}}}drawHorizontal(t){const e=this.yLabelsProvider();if(e.length>0&&this.config.components.grid.horizontal&&this.extentIdx===this.mainExtentIdx){t.lineWidth=this.config.components.grid.width,t.strokeStyle=this.config.colors.chartAreaTheme.gridColor,t.setLineDash(this.config.components.grid.dash||[]);const s=this.yBoundsProvider();for(const i of e){const r=at(this.viewportModel.toY(i.value)),o=uu(i.text,t,Ot);r>s.y+o&&r<s.y+s.height-o&&(t.beginPath(),t.moveTo(s.x,r),t.lineTo(s.x+s.width,r),t.stroke())}}}getCanvasIds(){return[this.canvasModel.canvasId]}}class go extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g){super(),this.drawerName=r,this.drawingManager=o,this.drawer=new Gu(t,e,s,i,a,l,c,h,f,d,u,g)}doDeactivate(){super.doDeactivate(),this.drawingManager.removeDrawer(this.drawer)}doActivate(){super.doActivate(),this.drawingManager.addDrawer(this.drawer,this.drawerName)}}class Zu{constructor(t,e,s,i){this.canvasModel=t,this.chartModel=e,this.config=s,this.canvasBoundsContainer=i}draw(){if(this.config.components.highLow.visible&&this.chartModel.isReady()){const{high:t,low:e,highIdx:s,lowIdx:i}=this.chartModel.mainCandleSeries.zippedHighLow,r=this.chartModel.mainCandleSeries.dataIdxStart,o=r+s,a=r+i,l=this.canvasModel.ctx;l.save(),l.font=this.config.components.highLow.font,this.drawMarkerLabel(l,o,t,"high"),this.drawMarkerLabel(l,a,e,"low"),l.restore()}}drawMarkerLabel(t,e,s,i){const r=this.getMarkerY(t,s,i==="low"),o=Qe(t,!1),a=i==="low"?r-o:r;if(!this.checkMarkerInBounds(a))return;const l=this.getMarkerText(s,i),c=this.getMarkerX(t,e,l);t.fillStyle=i==="high"?this.config.colors.highLowTheme.highColor:this.config.colors.highLowTheme.lowColor,t.fillText(l,c,r);const h=this.canvasBoundsContainer.getBounds("PANE_CHART");Kt(t,h)}getMarkerText(t,e){const s=this.chartModel.pane.regularFormatter(t);return`${e==="high"?this.config.components.highLow.prefix.high:this.config.components.highLow.prefix.low} ${s}`}getMarkerY(t,e,s=!1){const i=this.chartModel.toY(e);if(s){const r=Qe(t,!1);return i+r}return i}checkMarkerInBounds(t){const e=this.canvasBoundsContainer.getBounds(M.CHART);return t>e.y&&t<e.y+e.height}getMarkerX(t,e,s){let i=this.chartModel.toX(e);const r=this.canvasBoundsContainer.getBounds(M.CHART),o=4,a=t.measureText(s).width;return i+o+a>r.width&&(i=i-(o+a)),i+o}getCanvasIds(){return[this.canvasModel.canvasId]}}class $u extends X{constructor(t,e,s,i,r){super();const o=new Zu(e,s,t,i);r.addDrawer(o,"HIGH_LOW")}}const Ku=["AFTER_MARKET","PRE_MARKET","NO_TRADING","REGULAR"],qu=1440*60*1e3;class Ju extends X{constructor(t){super(),this.chartModel=t,this.highlights=[],this.visualHighlights={},this.highlightsUpdatedSubject=new F}activate(){this.addRxSubscription(this.chartModel.scale.xChanged.subscribe(()=>this.highlights.length&&this.recalculateVisualHighlights()))}getHighlights(){return this.highlights}getVisualHighlights(){return this.visualHighlights}recalculateVisualHighlights(){this.visualHighlights={};const t=this.chartModel.getFirstTimestamp(),e=this.chartModel.getLastTimestamp()+qu;kl(this.highlights,t,e,Qu).forEach(i=>{var r;this.visualHighlights[i.type]||(this.visualHighlights[i.type]=[]),(r=this.visualHighlights[i.type])==null||r.push(i)})}setHighlights(t){this.highlights=t,this.highlights.sort((e,s)=>e.to-s.to),this.highlightsUpdatedSubject.next(this.highlights),this.highlights.length?this.recalculateVisualHighlights():this.visualHighlights={}}observeHighlightsUpdated(){return this.highlightsUpdatedSubject.asObservable()}}const Qu=n=>n.to,Jt=[20,10];class tf{constructor(t,e,s,i,r){this.highlightsModel=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.config=r}draw(){var t,e,s,i;if(this.config.components.highlights.visible){const r=this.chartModel.getCandles(),o=this.canvasModel.ctx,a=this.highlightsModel.getVisualHighlights();if(this.highlightsModel.getHighlights().length&&r.length!==0&&this.chartModel.scale.isScaleReady()){const c=this.canvasBoundsContainer.getBounds(M.ALL_PANES);o.save(),Kt(o,c);const h=(t=this.config.components.highlights.border.width)!=null?t:1,d=(e=this.config.components.highlights.border.dash)!=null?e:[0,0],u=(s=this.config.components.highlights.fontSize)!=null?s:11,f=(i=this.config.components.highlights.fontFamily)!=null?i:"monospace",g=`${u}px ${f}, monospace`;o.font=g,o.lineWidth=h,o.setLineDash(d),Ku.forEach(m=>{var x,_;const A=a[m];if(A){const L=this.config.colors.highlights[m],Y=(x=L==null?void 0:L.border)!=null?x:"#ffffff",H=(_=L==null?void 0:L.background)!=null?_:"#ffffff";o.save(),o.beginPath(),o.fillStyle=H,o.strokeStyle=Y,A.forEach(B=>{var j,$,W;const U=this.chartModel.candleFromTimestamp(B.from),G=vt(U.width,this.chartModel.scale.zoomX),V=U.xStart(this.chartModel.scale),Q=B.to-this.chartModel.chartBaseModel.period,J=this.chartModel.candleFromTimestamp(Q),et=vt(J.width,this.chartModel.scale.zoomX),tt=J.xStart(this.chartModel.scale)+et;if(B.border&&this.drawBorders(B.border,o,V+G,tt-et,c),o.fillRect(V,c.y,tt-V,c.y+c.height),B.label){const st=(j=B.label.text)!=null?j:"",ut=this.config.colors.highlights[B.type];o.save(),o.fillStyle=($=ut==null?void 0:ut.label)!=null?$:"#ffffff";const lt=Mt(st,o,g),[xt,Gt]=this.resolveHighlightLabelPosition((W=B.label.placement)!=null?W:"left-left",c,[V,tt],lt);o.fillText(st,xt,Gt),o.restore()}}),o.closePath(),o.restore()}}),o.restore()}}}resolveHighlightLabelPosition(t,e,s,i){const[r,o]=s;switch(t){case"right-left":return[o-Jt[1]-i,e.y+Jt[0]];case"left-left":return[r-Jt[1]-i,e.y+Jt[0]];case"right-right":return[o+Jt[1],e.y+Jt[0]];default:return[r+Jt[1],e.y+Jt[0]]}}drawBorders(t,e,s,i,r){const o=t.left,a=t.right;o&&(e.beginPath(),e.moveTo(s,r.y),e.lineTo(s,r.y+r.height),e.stroke(),e.closePath()),a&&(e.beginPath(),e.moveTo(i,r.y),e.lineTo(i,r.y+r.height),e.stroke(),e.closePath())}getCanvasIds(){return[this.canvasModel.canvasId]}}const ef="HIGHLIGHTS_PLUGIN";class sf extends X{constructor(t,e,s,i,r,o){super(),this.eventBus=t,this.config=e,this.highlightsModel=new Ju(s),this.addChildEntity(this.highlightsModel),this.highLightsDrawer=new tf(this.highlightsModel,s,i,r,e),o.addDrawer(this.highLightsDrawer,ef)}getHighlights(){return this.highlightsModel.getHighlights()}setHighlights(t){this.highlightsModel.setHighlights(t)}setHighlightsVisible(t=!0){this.config.components.highlights.visible=t,this.eventBus.fireDraw(this.highLightsDrawer.getCanvasIds())}observeHighlightsUpdated(){return this.highlightsModel.observeHighlightsUpdated()}}function nf(){return N(function(n,t){var e,s=!1;n.subscribe(Ct(t,function(i){var r=e;e=i,s&&t.next([r,i]),s=!0}))})}function Z(n,t){return N(function(e,s){var i=0;e.subscribe(Ct(s,function(r){return n.call(t,r,i++)&&s.next(r)}))})}var rf=Object.defineProperty,of=Object.defineProperties,af=Object.getOwnPropertyDescriptors,po=Object.getOwnPropertySymbols,lf=Object.prototype.hasOwnProperty,cf=Object.prototype.propertyIsEnumerable,mo=(n,t,e)=>t in n?rf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,vo=(n,t)=>{for(var e in t||(t={}))lf.call(t,e)&&mo(n,e,t[e]);if(po)for(var e of po(t))cf.call(t,e)&&mo(n,e,t[e]);return n},bo=(n,t)=>of(n,af(t));const Vt=4;class hf{constructor(t,e,s,i,r,o){this.config=t,this.chartModel=e,this.canvasModel=s,this.canvasBoundsContainer=i,this.formatterFactory=r,this.visualCandlesProvider=o}draw(){if(this.config.components.navigationMap.visible){const t=this.visualCandlesProvider();if(t.length){const e=this.canvasBoundsContainer.getBounds(M.N_MAP),s=this.canvasBoundsContainer.getBounds(M.N_MAP_BTN_L),i=this.canvasBoundsContainer.getBounds(M.N_MAP_BTN_R),r=this.canvasBoundsContainer.getBounds(M.N_MAP_KNOT_L),o=this.canvasBoundsContainer.getBounds(M.N_MAP_KNOT_R),a=this.canvasBoundsContainer.getBounds(M.N_MAP_SLIDER_WINDOW),l=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),c=this.canvasModel.ctx;c.fillStyle=this.config.colors.navigationMap.backgroundColor,c.fillRect(e.x,e.y,e.width,e.height),c.strokeStyle=this.config.colors.paneResizer.lineColor,c.lineWidth=1,c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.width,e.y),c.closePath(),c.stroke(),s.width!==0&&this.drawLeftArrowButton(c,s,this.config),i.width!==0&&this.drawRightArrowButton(c,i,this.config),c.fillStyle=this.config.colors.navigationMap.mapFillColor,c.beginPath(),c.moveTo(l.x,l.y+l.height);for(const h of t)c.lineTo(h[0],h[1]);if(c.lineTo(l.x+l.width,l.y+l.height),c.lineTo(l.x,l.y+l.height),c.closePath(),this.config.colors.navigationMap.mapGradientTopColor&&this.config.colors.navigationMap.mapGradientBottomColor){const h=c.createLinearGradient(l.x,l.y,l.x,l.y+l.height);h.addColorStop(0,this.config.colors.navigationMap.mapGradientTopColor),h.addColorStop(1,this.config.colors.navigationMap.mapGradientBottomColor),c.fillStyle=h}c.fill(),this.config.colors.navigationMap.mapColor&&(c.strokeStyle=this.config.colors.navigationMap.mapColor,c.stroke()),this.drawSlider(c,r,o,s,a),this.drawTimeLabels(c)}}}blockDrawSliderOnLeftArrow(t,e,s,i){t.x<=s.x+s.width&&(t.x=s.x+s.width,i.x=t.x+t.width,e.x=i.x+i.width)}drawSlider(t,e,s,i,r){this.blockDrawSliderOnLeftArrow(e,s,i,r),this.drawKnotButton(t,e,this.config,!0),this.drawKnotButton(t,s,this.config,!1),t.fillStyle=this.config.colors.navigationMap.sliderColor,t.fillRect(r.x,r.y,r.width,r.height)}drawLeftArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Vt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r),t.lineTo(i+Vt,r+Vt),t.lineTo(i+Vt,r-Vt),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawRightArrowButton(t,e,s){t.fillStyle=s.colors.navigationMap.buttonColor,t.fillRect(e.x,e.y,e.width,e.height),t.beginPath();const i=Math.round(e.x+e.width/2-Vt/2),r=Math.round(e.y+e.height/2);t.moveTo(i,r-Vt),t.lineTo(i,r+Vt),t.lineTo(i+Vt,r),t.fillStyle=s.colors.navigationMap.buttonArrowColor,t.fill()}drawKnotButton(t,e,s,i){const r=s.components.navigationMap.knots.border;t.fillStyle=s.colors.navigationMap.knotColor;const o=i?e.x-r:e.x+r;t.fillRect(o,e.y,e.width,e.height),t.lineWidth=s.components.navigationMap.knots.lineWidth,r>0&&(t.beginPath(),t.moveTo(o,e.y),t.lineTo(o,e.y+e.height),t.lineTo(o+e.width,e.y+e.height),t.lineTo(o+e.width,e.y),t.lineTo(o,e.y),t.lineWidth=r,t.strokeStyle=s.colors.navigationMap.knotBorderColor,t.stroke()),t.beginPath(),t.moveTo(o+e.width/2,e.y+e.height/4),t.lineTo(o+e.width/2,e.y+3*e.height/4),t.strokeStyle=s.colors.navigationMap.knotLineColor,t.stroke()}drawTimeLabels(t){const e=mt(this.chartModel.mainCandleSeries.getSeriesInViewport()),s=this.config.components.navigationMap.timeLabels,i=s.visible;if(e.length&&i){const r=e[0].candle.timestamp,o=e[e.length-1].candle.timestamp,a=this.canvasBoundsContainer.getBounds(M.N_MAP_LABEL_L),l=this.canvasBoundsContainer.getBounds(M.N_MAP_LABEL_R),h={textFill:this.config.colors.navigationMap.timeLabelsTextColor,textFontFamily:s.fontFamily,textSize:`${s.fontSize}px`},d={dateFormat:s.dateFormat,padding:s.padding,textProperties:bo(vo({},h),{textAlign:"left"})},u={dateFormat:s.dateFormat,padding:s.padding,textProperties:bo(vo({},h),{textAlign:"right"})};this.drawTimeLabel(t,a,r,d),this.drawTimeLabel(t,l,o,u)}}drawTimeLabel(t,e,s,i){const r=i.padding,o=Ci(s,i.dateFormat,this.formatterFactory);gi(t,i.textProperties);const a=Qe(t),l=mi(o);Yl(t,l,e.x+r.x,e.y+a+r.y,i.textProperties)}getCanvasIds(){return[this.canvasModel.canvasId]}}class Ye extends jr{constructor(t,e,s,i,r=kr){super(t,e,s,i,r)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeXDragStart(this.hitTest).subscribe(this.onDragStart)),this.addRxSubscription(this.canvasInputListener.observeXDrag().subscribe(this.onDragTick)),this.addRxSubscription(this.canvasInputListener.observeXDragEnd().subscribe(this.onDragEnd))}}const Co=4;class df extends X{constructor(t,e,s,i,r,o){super(),this.bus=t,this.chartModel=e,this.scale=s,this.canvasInputListeners=i,this.canvasBoundsContainer=r,this.chartPanComponent=o,this.leftKnotDragStartXRelative=0,this.rightKnotDragStartXRelative=0,this.lastMousePosition=0,this.leftKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART);this.leftKnotDragStartXRelative=f.x-g.x-Co},this.leftKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART).width,_=(this.leftKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.leftRatio=_,this.scale.setXScale(Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.leftRatio),this.scale.xEnd)},this.rightKnotDragStart=f=>{const g=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART);this.rightKnotDragStartXRelative=f.x-g.x+Co},this.rightKnotDragTick=f=>{const{delta:g}=f,x=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART).width,_=(this.rightKnotDragStartXRelative+g)/x;this.canvasBoundsContainer.rightRatio=_,this.scale.setXScale(this.scale.xStart,Math.round(this.chartModel.mainCandleSeries.dataPoints.length*this.canvasBoundsContainer.rightRatio))},this.sliderDragStart=()=>{this.lastMousePosition=0},this.sliderDragTick=f=>{const{delta:g}=f,m=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),x=this.chartModel.mainCandleSeries.meanCandleWidth/(m.width/this.chartModel.mainCandleSeries.dataPoints.length),_=(this.lastMousePosition-g)*x;this.scale.moveXStart(this.scale.xStart-_),this.lastMousePosition=g};const a=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_KNOT_L),l=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_KNOT_R),c=new Ye(a,{onDragStart:this.leftKnotDragStart,onDragTick:this.leftKnotDragTick},this.canvasInputListeners,this.chartPanComponent),h=new Ye(l,{onDragStart:this.rightKnotDragStart,onDragTick:this.rightKnotDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(c),this.addChildEntity(h);const d=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_SLIDER_WINDOW),u=new Ye(d,{onDragStart:this.sliderDragStart,onDragTick:this.sliderDragTick},this.canvasInputListeners,this.chartPanComponent);this.addChildEntity(u)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_BTN_L);this.addRxSubscription(this.canvasInputListeners.observeClick(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(t).subscribe(()=>{this.scale.moveXStart(this.scale.xStart-1)}));const e=this.canvasBoundsContainer.getBoundsHitTest(M.N_MAP_BTN_R);this.addRxSubscription(this.canvasInputListeners.observeClick(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.canvasInputListeners.observeTouchStart(e).subscribe(()=>{this.scale.moveXStart(this.scale.xStart+1)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>{const s=this.chartModel.mainCandleSeries;this.canvasBoundsContainer.leftRatio=s.dataIdxStart/(s.dataPoints.length-1),this.canvasBoundsContainer.rightRatio=s.dataIdxEnd/(s.dataPoints.length-1),this.canvasBoundsContainer.recalculateNavigationMapElementBounds(),this.bus.fireDraw()}))}}class uf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.eventBus=t,this.chartModel=e,this.canvasModel=s,this.config=i,this.canvasInputListeners=r,this.canvasBoundsContainer=o,this.chartPanComponent=c,this.visualCandles=[];const d=new hf(i,e,s,o,l,()=>this.visualCandles);a.addDrawer(d,M.N_MAP_CHART),this.navigationMapMoveHandler=new df(this.eventBus,this.chartModel,this.chartModel.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.chartPanComponent),h.setCursorForCanvasEl(M.N_MAP_CHART,i.components.navigationMap.cursors.chart),h.setCursorForCanvasEl(M.N_MAP_BTN_L,i.components.navigationMap.cursors.buttonLeft),h.setCursorForCanvasEl(M.N_MAP_BTN_R,i.components.navigationMap.cursors.buttonRight),h.setCursorForCanvasEl(M.N_MAP_KNOT_L,i.components.navigationMap.cursors.leftResizer),h.setCursorForCanvasEl(M.N_MAP_KNOT_R,i.components.navigationMap.cursors.rightResizer),h.setCursorForCanvasEl(M.N_MAP_SLIDER_WINDOW,i.components.navigationMap.cursors.slider)}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartModel.observeCandlesChanged(),this.canvasBoundsContainer.observeBoundsChanged(M.N_MAP),this.chartModel.scale.xChanged.pipe(nf(),Z(([t,e])=>{const i=t.start<0||t.end>0,r=e.start<0||e.end>0;return i&&!r||r}))).subscribe(()=>{this.config.components.navigationMap.visible&&(this.visualCandles=this.makeVisualCandles(),this.canvasModel.fireDraw())}))}makeVisualCandles(){var t;const e=this.chartModel.getCandles();if(!e.length)return[];const s=this.chartModel.mainCandleSeries.dataIdxStart,i=this.chartModel.mainCandleSeries.dataIdxEnd,r=Math.round(Math.max(-s,0)),o=Math.max(this.chartModel.getCandlesCountWithRightOffset(),i)+r;let a=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY;const c=this.canvasBoundsContainer.getBounds(M.N_MAP_CHART),h=c.width,d=[];let u=0,f,g;for(f=0;f<h;f++)g=at(f*o/h)-r,g in e?(d[f]=e[g].close,u=(t=d[f])!=null?t:0,a=Math.max(a,u),l=Math.min(l,u)):d[f]=0;return a-=l,d.map((m,x)=>[x+c.x,(a+l-m)*c.height/a+c.y])}setVisible(t=!0){var e;(e=this.config.components)!=null&&e.navigationMap&&(this.config.components.navigationMap.visible=t,this.eventBus.fire(cs),this.canvasModel.fireDraw())}}const ms=()=>{const n=/Mac|iPod|iPhone|iPad/i.test(navigator.userAgent),e=[/Android/i,/webOS/i,/BlackBerry/i,/Windows Phone/i].some(s=>navigator.userAgent.match(s));return n?"apple":e?"mobile":"other"},ev=(n,t)=>n==="apple"||n==="mobile"?3:t;var hn=Math.pow;class yo extends X{constructor(t,e,s,i,r,o,a,l){super(),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=Zt,this.chartPanningOptions={horizontal:!0,vertical:!0},this.zoomXHandler=(d,u)=>{const f=d.deltaY<0;if(this.config.scale.zoomToCursor){const m=this.canvasBoundsContainer.getBounds(M.CANVAS).width,_=d.offsetX/m;this.scale.zoomXToPercent(_,f,!1,u)}else this.scale.zoomXToEnd(f,u);this.bus.fireDraw()},this.onXDragStart=()=>{this.canvasAnimation.forceStopAnimation(fe),this.xDraggedCandlesDelta=0,this.lastXStart=this.scale.xStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=d=>{const{delta:u}=d;this.currentPoint.x=u;const f=Ht(u,this.scale.zoomX);this.scale.moveXStart(this.lastXStart-f),this.bus.fireDraw()},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)};const c=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),h=new Ye(c,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.horizontal});this.addChildEntity(h)}doActivate(){super.doActivate();const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Lt(this.wheelThrottleTime,Rt,{trailing:!0,leading:!0})).subscribe(e=>{const s=ms(),i=s==="apple"||s==="mobile"?-1:1,r=0+e.deltaX*i,o=0+e.deltaY*i;if(e.ctrlKey){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw();return}if(o!==0&&Math.abs(o)>Math.abs(r)){const a=this.calculateDynamicSesitivity(e,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(e,a),this.bus.fireDraw()}if(r!==0&&Math.abs(r)>Math.abs(o)){const a=Ht(r,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-a),this.bus.fireDraw();return}})),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:e})=>{this.lastXStart+=e}))}calculateDynamicSesitivity(t,e){const i=Math.max(Math.abs(t.deltaY),Math.abs(t.deltaX)),r=e*i/100;return yl(this.config.components.yAxis.type,r)}registerChartYPanHandler(t,e){let s=t.yStart;const i=()=>{this.canvasAnimation.forceStopAnimation(fe),this.currentPoint={x:0,y:0},s=t.yStart,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},r=l=>{const{delta:c}=l;if(this.currentPoint.y=c,t.state.auto)ff(this.currentPoint,t.state.autoScaleDisableOnDrag)&&t.autoScale(!1);else{const h=Ht(t.state.inverse?-c:c,t.zoomY);t.moveYStart(s+h)}},o=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},a=new us(e,{onDragTick:r,onDragStart:i,onDragEnd:o},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>this.chartPanningOptions.vertical});return this.addChildEntity(a),a}}const ff=(n,t)=>{if(!t.enabled)return!1;const e=Math.abs(n.y),s=hn(hn(Math.abs(n.x),2)+hn(e,2),.5),i=Math.abs(Math.acos(e/s));return e>t.yDiff&&i<t.edgeAngle},gf=2;class pf extends X{constructor(t,e,s,i,r){super(),this.chartAreaPanHandler=t,this.scale=e,this.canvasInputListeners=s,this.mainCanvasParent=i,this.hitTest=r,this.touchedCandleIndexes=[0,0],this.canvasTouchInfo={touchStart:{x:0,y:0},isMoving:!1}}doActivate(){this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(t=>this.handleTouchStartEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(t=>this.handleTouchMoveEvent(t))),this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(t=>this.handleTouchEndEvent(t)))}handleTouchStartEvent(t){const{clientX:e,clientY:s}=t.touches[0];t.touches.length===1&&(this.canvasTouchInfo.touchStart={x:e,y:s}),t.touches.length===2&&(this.chartAreaPanHandler.deactivate(),this.touchedCandleIndexes=this.getXPositions(t).map(i=>this.scale.fromX(i)))}handleTouchMoveEvent(t){const{clientX:e,clientY:s}=t.touches[0],{touchStart:i}=this.canvasTouchInfo;t.touches.length===1&&(this.canvasTouchInfo.isMoving=wo(e,i.x,s,i.y)),t.touches.length===2&&this.pinchHandler(this.touchedCandleIndexes,this.getXPositions(t))}handleTouchEndEvent(t){this.canvasTouchInfo.isMoving=!1,t.touches.length===0&&this.chartAreaPanHandler.activate()}getXPositions(t){const e=this.mainCanvasParent.getBoundingClientRect(),s=[0,0],i=document.body.scrollLeft||document.documentElement.scrollLeft;for(let r=0,o=t.touches.length;r<o;r++){const a=t.touches[r];s[r]=a.pageX-e.left-i}return s}pinchHandler(t,e){const s=(e[0]*t[1]-e[1]*t[0])/(e[0]-e[1]),i=s+(t[0]-t[1])/(e[0]-e[1])*this.scale.getBounds().width;s>=i||e[0]===e[1]||this.scale.setXScale(s,i)}}const wo=(n,t,e,s,i=gf)=>Math.sqrt(Math.pow(n-t,2)+Math.pow(e-s,2))>i,sv={MAX_DIMENSION:2048,MAX_TOTAL_PIXELS:18e5,ZOOM_OPTIMIZED_PIXELS:12e5},mf=2e6,vf=24,bf=20,Cf=16,yf=10,wf=1e3,nv=5e4,iv={MIN:60,LOW:80,MEDIUM:100,HIGH:120,MAX:150};class Sf extends yo{constructor(t,e,s,i,r,o,a,l){super(t,e,s,i,r,o,a,l),this.bus=t,this.config=e,this.scale=s,this.canvasInputListener=i,this.canvasBoundsContainer=r,this.canvasAnimation=o,this.chartPanComponent=a,this.hitTestCanvasModel=l,this.currentPoint={x:0,y:0},this.xDraggedCandlesDelta=0,this.lastXStart=0,this.wheelThrottleTime=Zt,this.wheelSubscription=null,this.initFrameId=null,this.isActivated=!1,this.lastWheelTime=0,this.wheelCount=0,this.consecutiveLowWheelEvents=0,this.chartPanningOptions={horizontal:!0,vertical:!0}}doActivate(){this.isActivated||(this.isActivated=!0,super.doActivate(),this.canvasInputListener.initializeRectCache(),this.createWheelSubscription(),this.initFrameId=requestAnimationFrame(()=>{this.bus.fireDraw()}),this.addRxSubscription(this.chartPanComponent.chartBaseModel.dataPrependSubject.asObservable().subscribe(({prependedCandlesWidth:t})=>{this.lastXStart+=t})),this.addRxSubscription(this.bus.observe(cs).pipe(zr(100)).subscribe(()=>{this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation()})))}createWheelSubscription(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null);const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES),e=this.canvasBoundsContainer.getBounds(M.CANVAS),s=e.width*e.height;s>0?s>mf?this.wheelThrottleTime=vf:this.wheelThrottleTime=bf:this.wheelThrottleTime=Cf,this.wheelSubscription=this.canvasInputListener.observeWheel(t).pipe(Z(()=>this.chartPanningOptions.horizontal&&this.chartPanningOptions.vertical),Z(i=>ms()==="apple"?Math.abs(i.deltaY)>1||Math.abs(i.deltaX)>1:!0),Lt(this.wheelThrottleTime,Rt,{trailing:!0,leading:!0})).subscribe(i=>{const r=performance.now();this.lastWheelTime||(this.lastWheelTime=r,this.wheelCount=0),this.wheelCount++,r-this.lastWheelTime>wf&&(Math.round(this.wheelCount*1e3/(r-this.lastWheelTime))<yf?(this.consecutiveLowWheelEvents++,this.consecutiveLowWheelEvents>=1&&(this.triggerPerformanceCleanup(),this.consecutiveLowWheelEvents=0)):this.consecutiveLowWheelEvents=0,this.lastWheelTime=r,this.wheelCount=0);const o=ms(),a=o==="apple"||o==="mobile"?-1:1,l=0+i.deltaX*a,c=0+i.deltaY*a;if(i.ctrlKey){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw();return}if(c!==0&&Math.abs(c)>Math.abs(l)){const h=this.calculateDynamicSesitivity(i,this.config.scale.zoomSensitivity.wheel);this.zoomXHandler(i,h),this.bus.fireDraw()}if(l!==0&&Math.abs(l)>Math.abs(c)){const h=Ht(l,this.scale.zoomX);this.scale.moveXStart(this.scale.xStart-h),this.bus.fireDraw();return}}),this.addRxSubscription(this.wheelSubscription)}triggerPerformanceCleanup(){window.dispatchEvent(new Event("resize")),window.gc&&window.gc(),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.scale&&typeof this.scale.haltAnimation=="function"&&this.scale.haltAnimation(),this.consecutiveLowWheelEvents=0,this.wheelCount=0,this.lastWheelTime=0}doDeactivate(){this.wheelSubscription&&(this.wheelSubscription.unsubscribe(),this.wheelSubscription=null),this.initFrameId&&(cancelAnimationFrame(this.initFrameId),this.initFrameId=null),this.isActivated=!1,super.doDeactivate()}}class xf extends X{constructor(t,e,s,i,r,o,a,l,c){super(),this.eventBus=t,this.mainScale=e,this.canvasBoundsContainer=s,this.config=i,this.canvasAnimation=r,this.canvasInputListener=o,this.mainCanvasParent=a,this.chartBaseModel=l,this.hitTestCanvasModel=c;const h=[this.eventBus,this.config,this.mainScale,this.canvasInputListener,this.canvasBoundsContainer,this.canvasAnimation,this,this.hitTestCanvasModel],d=Ae?new Sf(...h):new yo(...h);this.chartAreaPanHandler=d,this.addChildEntity(this.chartAreaPanHandler),this.mainCanvasTouchHandler=new pf(this.chartAreaPanHandler,this.mainScale,this.canvasInputListener,this.mainCanvasParent,this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES)),this.addChildEntity(this.mainCanvasTouchHandler)}activateChartPanHandlers(){this.activate()}deactivatePanHandlers(){this.deactivate()}setChartPanningOptions(t,e){this.chartAreaPanHandler.chartPanningOptions={horizontal:t,vertical:e}}}const So=n=>t=>{const{top:e,bottom:s}=n(),i=t.high-t.low,r=i===0?1:i,o=r*e/100,a=r*s/100,l=t.low-a,c=t.high+o;return{low:l,high:c}},xo=(n,t)=>{const e=So(n);return{isHighLowActive:()=>!0,calculateHighLow:s=>{const i=t.calculateHighLow(s);return e(i)}}};function _f(){return Vn(1)}function _o(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];return _f()(Ge(n,Ue(n)))}function Pf(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n);return N(function(s,i){(e?_o(n,s,e):_o(n,s)).subscribe(i)})}function Tf(n){return Z(function(t,e){return n<=e})}class Mf{constructor(t,e,s,i,r){this.config=t,this.boundsProvider=e,this.canvasModel=s,this.canvasAnimation=i,this.animationId=r}draw(){if(this.config.components.paneResizer.visible){const t=this.config.components.paneResizer.fixedMode,e=this.boundsProvider(),s=this.canvasModel.ctx,i=this.canvasAnimation.getColorAlphaAnimation(this.animationId),r=this.config.components.paneResizer.dragZone;!t&&i&&(s.fillStyle=i.getColor(0),s.fillRect(e.x,e.y-r,e.width,e.height+2*r)),s.fillStyle=this.config.colors.paneResizer.lineColor,this.config.animation.paneResizer.bgMode?s.fillRect(e.x,e.y,e.width,e.height):s.fillRect(e.x,e.y-r,e.width,e.height+2*r)}}getCanvasIds(){return[this.canvasModel.canvasId]}}const Po=8;class dn extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.id=t,this.boundsProvider=e,this.hitTest=s,this.dragTickCb=i,this.dragPredicate=r,this.chartPanComponent=o,this.canvasModel=a,this.drawingManager=l,this.canvasInputListener=c,this.canvasAnimation=h,this.config=d,this.canvasBoundsContainer=u,this.hitTestCanvasModel=f,this.initialY=0,this.resizeEvent$=new F,this.onYDragStartMobile=()=>{this.config.components.crossTool.type="none",this.onYDragStart()},this.onYDragStart=()=>{this.initialY=this.boundsProvider().y,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1),this.chartPanComponent.deactivatePanHandlers()},this.onYDragEndMobile=()=>{this.config.components.crossTool.type="cross-and-labels",this.onYDragEnd()},this.onYDragEnd=()=>{this.initialY=this.boundsProvider().y,this.canvasBoundsContainer.graphsHeightRatioChangedSubject.next(this.canvasBoundsContainer.graphsHeightRatio),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0),this.chartPanComponent.activateChartPanHandlers()},this.onYDragTick=g=>{const{delta:m,draggedPixels:x}=g;Math.abs(this.initialY-this.boundsProvider().y+x)>=0&&(this.dragTickCb(m),this.resizeEvent$.next())},this.animationId=`${this.id}_RESIZER`}doActivate(){if(super.doActivate(),!this.config.components.paneResizer.fixedMode){const s=new us(this.hitTest,{onDragTick:this.onYDragTick,onDragStart:Nt()?this.onYDragStartMobile:this.onYDragStart,onDragEnd:Nt()?this.onYDragEndMobile:this.onYDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:this.dragPredicate});this.addChildEntity(s),this.config.animation.paneResizer.enabled&&this.addRxSubscription(this.canvasInputListener.observeMouseEnter(this.hitTest,!0).pipe(Pf(!1),Z(this.dragPredicate),Tt(),Tf(1)).subscribe(i=>{i?this.handleHoverAnimation("appearing"):this.handleHoverAnimation("fading")}))}const e=new Mf(this.config,this.boundsProvider,this.canvasModel,this.canvasAnimation,this.animationId);this.drawingManager.addDrawer(e,Hr.paneResizer(this.id)),this.addSubscription(()=>this.drawingManager.removeDrawerByName(Hr.paneResizer(this.id)))}doDeactivate(){super.doDeactivate(),this.resizeEvent$.complete()}handleHoverAnimation(t){let e;this.config.animation.paneResizer.bgMode?(e=this.canvasAnimation.getColorAlphaAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorAlphaAnimation(this.animationId,[{color:this.config.colors.paneResizer.bgHoverColor,type:t}])):(e=this.canvasAnimation.getColorTransitionAnimation(this.animationId),(!e||!e.animationInProgress)&&this.canvasAnimation.startColorTransitionAnimation(this.animationId,[{startColor:this.config.colors.paneResizer.bgColor,endColor:this.config.colors.paneResizer.bgHoverColor,type:t}],this.config.animation.paneResizer.duration)),e&&e.animationInProgress&&e.revert()}}const un=1/32,Af=n=>{const t=Math.floor(n),e=n-t,s=Math.round(e*64),r=Math.floor(s/2).toString().padStart(2,"0");return`${t}'${r}`},To=n=>n.match(/^\-?0*(\d+)'(\d{2})$/),rv=n=>!!To(n),ov=n=>{const t=To(n);if(t){const e=parseInt(t[1],10),i=parseInt(t[2],10)*un;return e+i}return Number(n)},Ef=(n,t)=>e=>{let s;if(typeof e=="number")s=e;else if(typeof e=="string")s=Number(e);else return"\u2014";const i=t.treasuryFormat;if(i&&i.enabled)return Af(s);const[r]=n.dataSeries;if(r!==void 0){const o=ve.getPricePrecision(s,r.pricePrecisions);return s.toFixed(o)}return`${s}`},If=n=>(t,e)=>{if(t===0)return"0.00 %";const[s]=n.dataSeries;let i=t;const r=e!=null?e:s;r!==void 0&&(i=sr(t,r.getBaseline()));const o=Je(i.toFixed(ve.DEFAULT_PRECISION))+" %";return o===`${ti}0.00 %`?"0.00 %":o},Df=(n,t)=>({percent:If(n),regular:Ef(n,t)});class Lf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u=new Set,f={regular:Jc}){super(),this.config=t,this.paneUUID=e,this.idx=s,this.paneComponent=i,this.chartBaseModel=r,this.canvasBoundsContainer=o,this.hitTestController=a,this.dynamicObjectsCanvasModel=l,this.scale=c,this.dragNDrop=d,this.dataSeries=u,this.formatters=f,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.yAxisHT=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_Y_AXIS(this.paneUUID,this.idx)),this.toVisualPoints=g=>g.map(m=>new Be(this.chartBaseModel.dataFromTimestamp(m.timestamp).centerUnit,m.close)),this.toY=g=>{var m,x;return(x=(m=this.mainDataSeries)==null?void 0:m.view.toY(g))!=null?x:1},this.valueFormatter=(g,m)=>{if(!this.formatters[this.yAxis.getAxisType()])return this.formatters.regular(g);const{regular:x,percent:_,logarithmic:A}=this.formatters;switch(this.yAxis.getAxisType()){case"regular":return this.formatters.regular(g);case"percent":return _?_(g,m):x(g);case"logarithmic":return A?A(g):x(g);default:return this.regularFormatter(g)}},this.addChildEntity(c),this.setValueFormatters(Df(this,t)),this.yAxis=h(this.valueFormatter.bind(this),()=>this.mainDataSeries),this.addChildEntity(this.yAxis)}doDeactivate(){super.doDeactivate(),this.dataSeries.forEach(t=>{this.paneComponent.seriesRemovedSubject.next(t),t.deactivate()})}getBounds(){return this.scale.getBounds()}getBaseline(){var t,e;return(e=(t=this.mainDataSeries)==null?void 0:t.getBaseline())!=null?e:1}createDataSeries(){const t=new cr(this,wt(),this.hitTestController.getNewDataSeriesHitTestId());return t.toVisualPoints=this.toVisualPoints,t}addDataSeries(t){if(this.dataSeries.add(t),this.dataSeries.size===1)this.mainDataSeries=t;else if(this.paneComponent.yExtentComponents.length>1&&this.paneUUID!==K){this.mainDataSeries=t;const e=Array.from(this.paneComponent.mainExtent.dataSeries);this.paneComponent.mainExtent.mainDataSeries=e[e.length-1]}this.paneComponent.updateView(),this.paneComponent.seriesAddedSubject.next(t)}removeDataSeries(t){this.dataSeries.delete(t),this.paneComponent.updateView(),this.paneComponent.seriesRemovedSubject.next(t)}get regularFormatter(){return this.formatters.regular}setValueFormatters(t){this.formatters=t}regularValueFromY(t){var e,s;return(s=(e=this.mainDataSeries)==null?void 0:e.view.priceFromY(t))!=null?s:this.scale.fromY(t)}}const Mo=n=>({isHighLowActive:()=>!0,calculateHighLow:t=>{const e=Array.from(n.dataSeries),s=e.filter(o=>o.highLowProvider.isHighLowActive()),i=s.length>0?s:e;if(i.length===0)return{low:0,high:100};const r=i.map(o=>o.highLowProvider.calculateHighLow(t)).filter(o=>o.high>=o.low);return r.length===0?{low:0,high:100}:yr(r)}});class Of{constructor(t,e){this.panes=t,this.canvasModel=e,this.dataSeriesIdCounter=ln.DATA_SERIES[0],this.getNewDataSeriesHitTestId=()=>this.dataSeriesIdCounter++}getIdRange(){return ln.DATA_SERIES}get allDataSeries(){return Ie(Ie(Object.values(this.panes),t=>t.yExtentComponents),t=>Array.from(t.dataSeries))}lookup(t){return this.allDataSeries.find(s=>s.htId===t)}onHover(t){this.allDataSeries.forEach(e=>e.highlighted=e.htId===(t==null?void 0:t.htId)),this.canvasModel.fireDraw()}onMouseDown(t){t&&this.handleYExtentDragStart(t)}onMouseUp(){this.handleYExtentDragEnd()}handleYExtentDragStart(t){Object.values(this.panes).forEach(e=>e.yExtentComponents.forEach(s=>s.dragNDrop.deactivate())),t.extentComponent.dragNDrop.activate()}handleYExtentDragEnd(){Object.values(this.panes).forEach(t=>t.yExtentComponents.forEach(e=>e.dragNDrop.activate()))}}const Ut="#FF00FF";function av(n,t,e,s){const i=n.yAxis.backgroundColor,r=n.chartAreaTheme.backgroundColor,o=n.chartAreaTheme.backgroundGradientTopColor,a=n.chartAreaTheme.backgroundGradientBottomColor,l=s.align==="left"?o:a,c=n.chartAreaTheme.backgroundMode==="gradient"?l:r,h=i==="transparent"?c:i;return getLabelTextColorByBackgroundColor(h,t,e)}const Bf=(n,t)=>n==="down"?t.lastPrice.textNegative:n==="up"?t.lastPrice.textPositive:t.lastPrice.textSelected,Rf=(n,t)=>{const e=t.barTheme[`${n}Color`];return e!=null?e:Ut},Ff=(n,t)=>{const e=t.lineTheme[`${n}Color`];return e!=null?e:Ut},Hf=(n,t)=>{const e=t.candleTheme[`${n}Color`];return e!=null?e:Ut},kf=(n,t)=>{const e=t.areaTheme.lineColor;return e!=null?e:Ut},jf=(n,t)=>{const e=t.scatterPlot.mainColor;return e!=null?e:Ut},Yf=(n,t)=>{const e=t.histogram[`${n}Bright`];return e!=null?e:Ut},Nf=(n,t)=>{const e=n==="up"?t.baseLineTheme.upperSectionStrokeColor:t.baseLineTheme.lowerSectionStrokeColor;return e!=null?e:Ut},Ao=(n,t)=>{const e=t.candleTheme[`${n}WickColor`];return e!=null?e:Ut},Xf=()=>(console.warn("Fallback for label default color"),Ut),Eo=10;class Io extends X{constructor(t,e,s,i,r,o,a,l){if(super(),this.bus=t,this.config=e,this.scale=i,this.canvasInputListener=r,this.bounds=o,this.hitTest=a,this.hitTestCanvasModel=l,this.yAxisDragEndSubject=new F,this.lastYStart=0,this.lastYEnd=0,this.lastYHeight=0,this.lastYPxHeight=0,this.onYDragStart=()=>{this.scale.haltAnimation(),this.lastYStart=this.scale.yStart,this.lastYEnd=this.scale.yEnd,this.lastYHeight=this.scale.yEnd-this.scale.yStart,this.lastYPxHeight=Math.max(this.bounds.getBounds(M.Y_AXIS).height,Bi),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onYDragTick=c=>{let{delta:h}=c;this.touches&&this.touches.length>1&&(h=Math.min(this.touches[0].clientY,this.touches[1].clientY)===this.touches[0].clientY?h:-h);let d;h<0?d=1/(1+-h/this.lastYPxHeight*(Eo-1)):d=1+h/this.lastYPxHeight*(Eo-1);const f=(this.lastYHeight*d-this.lastYHeight)/2,g=this.lastYStart-f,m=this.lastYEnd+f;(this.lastYStart!==g||this.lastYEnd!==m)&&(this.scale.setYScale(g,m),this.scale.state.auto=!1,this.bus.fireDraw())},this.onYDragEnd=()=>{this.yAxisDragEndSubject.next(),this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>i.autoScale(!0),this.dblTapCallback=()=>i.autoScale(!0),e.customScale){const c=new us(a,{onDragTick:this.onYDragTick,onDragStart:this.onYDragStart,onDragEnd:this.onYDragEnd},r,s,{dragPredicate:()=>s.chartAreaPanHandler.chartPanningOptions.vertical&&e.type!=="percent"});this.addChildEntity(c),this.dragNDropYComponent=c}}isDragging(){return this.dragNDropYComponent?Math.abs(this.dragNDropYComponent.draggedPixels)>0:!1}doActivate(){this.config.customScaleDblClick&&(this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>{this.dblClickCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback(),this.bus.fireDraw()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})))}}class Wf{constructor(t,e=()=>!0){this.dataProvider=t,this.dataUpdatedPredicate=e,this.calculatedInThisFrame=!1,this.animFrameId=`anim_cache_${wt()}`}calculateOrGet(){var t;return this.calculatedInThisFrame||(this.cache=this.dataProvider(),this.dataUpdatedPredicate()&&(this.calculatedInThisFrame=!0),Qn(this.animFrameId,()=>{this.calculatedInThisFrame=!1})),(t=this.cache)!=null?t:this.dataProvider()}forceCalculateOrGet(){return this.invalidate(),this.calculateOrGet()}getLastCachedValue(){return this.cache}updateCacheValue(t){this.cache=t}invalidate(){this.cache=void 0,this.calculatedInThisFrame=!1}}const zf=0,Vf=.01;class fn{constructor(t,e,s,i,r=!1,o,a,l=Ns,c=23,h){this.increment=t,this.startEndProvider=e,this.lengthProvider=s,this.valueFormatter=i,this.withZero=r,this.axisTypeProvider=o,this.baseLineProvider=a,this.labelFilter=l,this.singleLabelHeightPixels=c,this.yAxisConfig=h,this.gridDistanceMultipliers=[2,4,5,10],this.lastSingleLabelHeightValue=0,this.distanceBetweenLabelsChangeSubject=new F,this.newGeneratedLabelsSubject=new F,this.lastStart=0,this.lastEnd=0,this.labelsCache=new Wf(()=>this.labelFilter(this.doGenerateLabels())),this.treasuryFormat=this.yAxisConfig&&this.yAxisConfig.treasuryFormat}generateRegularLabels(t,e,s){const i=[];this.withZero&&i.push({value:0,text:"0"});let r=gt.roundToNearest(t,s);for(;r<e;){const o=gt.roundToNearest(r,s),a=Je(this.valueFormatter(o));i.push({value:o,text:a}),r=gt.roundDecimal(r+s)}return i}generatePercentLabels(t,e,s){const i=[],r=this.baseLineProvider();let o=gt.roundToNearest(t,s);for(;o<e;){const a=gt.roundToNearest(o,s),l=nr(a,r),c=Je(this.valueFormatter(l));i.push({value:a,text:c}),o=gt.roundDecimal(o+s)}return i}generateLogarithmLabels(t,e,s){const i=[];let r=gt.roundToNearest(t,s);for(;r<e;){const o=tn(r),a=this.valueFormatter(o);i.push({value:r,text:a}),r=gt.roundDecimal(r+s)}return i}doGenerateLabels(){var t;const e=this.lengthProvider();if(e<=0)return[];const[s,i]=this.calculateMinMax(),r=this.getAxisStep(s,i,e);this.lastSingleLabelHeightValue||(this.lastSingleLabelHeightValue=r);let o;const a=this.axisTypeProvider();if(a==="logarithmic"?o=this.generateLogarithmLabels(s,i,r):a==="percent"?o=this.generatePercentLabels(s,i,r):o=this.generateRegularLabels(s,i,r),this.lastSingleLabelHeightValue!==r&&this.labelsCache.cache){const l=(t=this.labelsCache.getLastCachedValue())!=null?t:[];this.distanceBetweenLabelsChangeSubject.next([l,o]),this.lastSingleLabelHeightValue=r}return this.newGeneratedLabelsSubject.next(o),o}calculateMinMax(){const[t,e]=this.startEndProvider(),s=this.lengthProvider(),i=fn.getLabelBounds(t,e,s);return[i[0],i[1]]}getAxisStep(t,e,s){const i=e-t,r=s/this.singleLabelHeightPixels,o=this.calculateIncrement(i),a=i/r;return this.calculateAxisStep(a,o)}observeDistanceBetweenLabelsChanged(){return this.distanceBetweenLabelsChangeSubject.asObservable()}observeLabelsChanged(){return this.newGeneratedLabelsSubject.asObservable()}calculateIncrement(t){var e;if(this.increment)return this.increment;if(!isNaN(t)){const s=(e=this.treasuryFormat)!=null&&e.enabled?un:ve.autoDetectIncrementOfValueRange(t);return this.adjustIncrementOnAxisType(s)}return this.adjustIncrementOnAxisType(Vf)}adjustIncrementOnAxisType(t){switch(this.axisTypeProvider()){case"percent":return t;case"logarithmic":const[e]=this.calculateMinMax(),i=tn(e)+t;return ir(i)-e;case"regular":return t}}generateNumericLabels(){const[t,e]=this.startEndProvider();return(t!==this.lastStart||e!==this.lastEnd)&&this.labelsCache.invalidate(),this.lastStart=t,this.lastEnd=e,this.labelsCache.calculateOrGet()}static getLabelBounds(t,e,s){const i=Math.abs((e-t)*(zf/s));return[t-i,e+i]}calculateAxisStep(t,e){if(e===0)return console.error("NumericAxisLabelsGenerator failed at calculateAxisStep: increment = 0"),0;let s=e,i=e,r=0;for(;s<t&&s>0;)r>=this.gridDistanceMultipliers.length&&(r=0,i*=10),s=i*this.gridDistanceMultipliers[r++];return s}}class Uf extends fn{constructor(t,e,s,i,r=()=>"regular",o=23,a){super(t,()=>[s.yStart,s.yEnd],()=>s.getBounds().height,i,!1,r,()=>{var l,c;return(c=(l=e())==null?void 0:l.getBaseline())!=null?c:1},void 0,o,a),this.dataSeriesProvider=e}getLargestLabel(){var t;return((t=this.labelsCache.getLastCachedValue())!=null?t:[]).reduce((e,s)=>s.text.length>e.length?s.text:e,"")}updateTreasuryFormat(t){this.treasuryFormat=t}calculateIncrement(t){var e,s;const i=this.dataSeriesProvider();if(i){const r=St(i.dataPoints),o=(e=r==null?void 0:r.close)!=null?e:0,a=hh(o,i.pricePrecisions),l=(s=this.treasuryFormat)!=null&&s.enabled?un:a;return this.adjustIncrementOnAxisType(l)}return super.calculateIncrement(t)}}function Do(n,t,e){var s=k(n)||t||e?{next:n,error:t,complete:e}:n;return s?N(function(i,r){var o;(o=s.subscribe)===null||o===void 0||o.call(s);var a=!0;i.subscribe(Ct(r,function(l){var c;(c=s.next)===null||c===void 0||c.call(s,l),r.next(l)},function(){var l;a=!1,(l=s.complete)===null||l===void 0||l.call(s),r.complete()},function(l){var c;a=!1,(c=s.error)===null||c===void 0||c.call(s,l),r.error(l)},function(){var l,c;a&&((l=s.unsubscribe)===null||l===void 0||l.call(s)),(c=s.finalize)===null||c===void 0||c.call(s)}))}):ue}class Gf extends X{constructor(t,e,s,i,r){super(),this.scale=t,this.labelsGenerator=e,this.canvasBoundsContainer=s,this.paneUUID=i,this.extentIdx=r,this.labels=[],this.prevYAxisHeight=0,this.animFrameId=`anim_cache_${wt()}`}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.scale.yChanged,this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx)).pipe(dt(t=>t.height),Z(t=>fl(t,this.prevYAxisHeight,1.5)),Do(t=>{this.labelsGenerator.labelsCache.invalidate(),this.prevYAxisHeight=t}))).subscribe(()=>this.updateLabels()))}recalculateLabels(){const t=this.labelsGenerator.doGenerateLabels();this.labels=t,Pe(this.animFrameId,()=>this.canvasBoundsContainer.updateYAxisWidths())}updateLabels(){Pe(this.animFrameId,()=>{this.labels=this.labelsGenerator.generateNumericLabels(),this.canvasBoundsContainer.updateYAxisWidths()})}}class Zf extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.paneUUID=t,this.state=s,this.canvasBoundsContainer=i,this.extentIdx=c,this.labelsGenerator=new Uf(null,l,o,a,()=>this.state.type,s.labelHeight,s),this.baseLabelsModel=new Gf(o,this.labelsGenerator,this.canvasBoundsContainer,t,c),this.addChildEntity(this.baseLabelsModel),this.fancyLabelsModel=new kc(e,o,i,s,r,t,()=>this.canvasBoundsContainer.updateYAxisWidths(),h),this.addChildEntity(this.fancyLabelsModel)}doActivate(){const t={getLargestLabel:()=>{var e;return((e=this.labelsGenerator.labelsCache.getLastCachedValue())!=null?e:[]).map(s=>s.text).concat(this.fancyLabelsModel.orderedLabels.flatMap(s=>s.labels).map(s=>s.labelText)).reduce((s,i)=>i.length>s.length?i:s,"")},getYAxisIndex:()=>this.extentIdx,getYAxisState:()=>this.state,getPaneUUID:()=>this.paneUUID};this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t),this.addSubscription(()=>this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(t))}}class $f extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x){super(),this.eventBus=t,this.config=e,this.mainCanvasModel=s,this.canvasModel=i,this.scale=r,this.canvasInputListeners=o,this.canvasBoundsContainer=a,this.chartPanComponent=l,this.cursors=c,this.paneUUID=u,this.extentIdx=f,this.hitTestCanvasModel=g,this.chartResizeHandler=m,this.labelsColorByChartTypeMap={},this.axisTypeSetSubject=new F,this.axisAlignSetSubject=new F,this.axisAlignMovedSubject=new F,this.setDblClickCallback=A=>this.yAxisScaleHandler.setDblClickCallback(A),this.setDblTapCallback=A=>this.yAxisScaleHandler.setDblTapCallback(A);const _=x?re(x):{};this.state=At(_,e.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),this.yAxisScaleHandler=new Io(t,this.state,l,r,o,a,a.getBoundsHitTest(M.PANE_UUID_Y_AXIS(u,f)),g),this.addChildEntity(this.yAxisScaleHandler),this.model=new Zf(this.paneUUID,t,this.state,a,i,r,h,d,f,this.chartResizeHandler),this.addChildEntity(this.model),this.updateCursor(),this.registerDefaultLabelColorResolvers()}setExtentIdx(t){this.extentIdx=t,this.model.extentIdx=t,this.yAxisScaleHandler.deactivate(),this.removeChildEntity(this.yAxisScaleHandler),this.yAxisScaleHandler=new Io(this.eventBus,this.state,this.chartPanComponent,this.scale,this.canvasInputListeners,this.canvasBoundsContainer,this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_Y_AXIS(this.paneUUID,t)),this.hitTestCanvasModel),this.addChildEntity(this.yAxisScaleHandler)}registerDefaultLabelColorResolvers(){this.registerLabelColorResolver("candle",Hf),this.registerLabelColorResolver("bar",Rf),this.registerLabelColorResolver("line",Ff),this.registerLabelColorResolver("area",kf),this.registerLabelColorResolver("scatterPlot",jf),this.registerLabelColorResolver("histogram",Yf),this.registerLabelColorResolver("baseline",Nf),this.registerLabelColorResolver("trend",Ao),this.registerLabelColorResolver("hollow",Ao)}doActivate(){this.addRxSubscription(this.scale.beforeStartAnimationSubject.subscribe(()=>this.state.type==="percent"&&this.scale.haltAnimation()))}updateCursor(){this.state.type==="percent"?this.cursors.setCursorForCanvasEl(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.resizeDisabledCursor):this.cursors.setCursorForCanvasEl(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx),this.state.cursor)}updateOrderedLabels(t=!1){this.model.fancyLabelsModel.updateLabels(t)}registerLabelColorResolver(t,e){this.labelsColorByChartTypeMap[t]=e}getLabelsColorResolver(t){var e;return(e=this.labelsColorByChartTypeMap[t])!=null?e:Xf}registerYAxisLabelsProvider(t,e=ie.MAIN,s=wt()){return this.model.fancyLabelsModel.registerYAxisLabelsProvider(e,t,s),s}addSimpleYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}updateCustomYAxisLabel(t,e){this.model.fancyLabelsModel.customLabels[t]=e,this.canvasModel.fireDraw()}deleteSimpleYAxisLabel(t){delete this.model.fancyLabelsModel.customLabels[t],this.canvasModel.fireDraw()}getAxisType(){return this.state.type}unregisterYAxisLabelsProvider(t=ie.MAIN,e){return this.model.fancyLabelsModel.unregisterYAxisLabelsProvider(t,e),e}getBounds(){return this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.paneUUID,this.extentIdx))}registerYAxisWidthContributor(t){this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(t)}setAxisType(t){t!==this.state.type&&(this.state.type=t,this.config.components.yAxis.type=t,this.axisTypeSetSubject.next(t),this.scale.autoScale(!0),this.model.fancyLabelsModel.updateLabels(!0),this.updateCursor(),this.mainCanvasModel.fireDraw())}setYAxisAlign(t){this.state.align=t,this.canvasBoundsContainer.updateYAxisWidths(),this.axisAlignSetSubject.next(t),this.eventBus.fireDraw()}setVisible(t){this.state.visible=t,this.config.components.yAxis.visible=t,t?this.activate():this.deactivate(),this.model.fancyLabelsModel.updateLabels(),this.model.baseLabelsModel.updateLabels()}isVisible(){return this.state.visible}setLockPriceToBarRatio(t=!1){this.scale.setLockPriceToBarRatio(t)}changeLabelMode(t,e){this.state.labels.settings[t].mode=e,this.model.fancyLabelsModel.updateLabels()}changeLabelAppearance(t,e){this.state.labels.settings[t].type=e,this.model.fancyLabelsModel.updateLabels()}togglePriceScaleInverse(t=!1){this.scale.state.inverse=t,this.scale.inverseY=t,this.model.fancyLabelsModel.updateLabels(),this.scale.scaleInversedSubject.next(t),this.canvasModel.fireDraw()}changeLabelsDescriptionVisibility(t){this.state.labels.descriptions=t,this.canvasModel.fireDraw()}}class Kf extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_,A,L,Y){super(),this.chartBaseModel=t,this.mainCanvasModel=e,this.yAxisLabelsCanvasModel=s,this.dynamicObjectsCanvasModel=i,this.hitTestController=r,this.config=o,this.mainScale=a,this.drawingManager=l,this.chartPanComponent=c,this.canvasInputListener=h,this.canvasAnimation=d,this.cursorHandler=u,this.eventBus=f,this.canvasBoundsContainer=g,this.uuid=m,this.seriesAddedSubject=x,this.seriesRemovedSubject=_,this.hitTestCanvasModel=A,this.chartResizeHandler=L,this.yExtentComponents=[],this.yExtentComponentsChangedSubject=new F,this.getYAxisBounds=()=>this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(this.uuid)),this.valueFormatter=(B,j)=>this.mainExtent.valueFormatter(B,j);const H=this.createExtentComponent(Y);this.mainExtent=H,this.ht=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID(m),{extensionY:-this.config.components.paneResizer.dragZone})}get scale(){return this.mainExtent.scale}get yAxis(){return this.mainExtent.yAxis}get dataSeries(){return Ie(this.yExtentComponents,t=>Array.from(t.dataSeries))}get visible(){return this.canvasBoundsContainer.graphsHeightRatio[this.uuid]>0}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasBoundsContainer.observeBoundsChanged(M.PANE_UUID(this.uuid)).pipe(Tt(Yi)).subscribe(()=>{this.yExtentComponents.forEach(t=>t.scale.recalculateZoomY()),this.dynamicObjectsCanvasModel.fireDraw()}))}toY(t){var e,s;return(s=(e=this.mainExtent.mainDataSeries)==null?void 0:e.view.toY(t))!=null?s:this.scale.toY(t)}createGridComponent(t,e,s,i,r,o){var a,l;const c=M.PANE_UUID(t),h=(l=(a=this.mainExtent)==null?void 0:a.idx)!=null?l:0;return new go(this.mainCanvasModel,s,this.config,i,`PANE_${t}_${e}_grid_drawer`,this.drawingManager,()=>this.canvasBoundsContainer.getBounds(c),()=>this.canvasBoundsContainer.getBounds(c),()=>[],r,e,o,()=>this.config.components.grid.visible,h)}createYPanHandler(t,e){const s=M.PANE_UUID(t),i=this.chartPanComponent.chartAreaPanHandler.registerChartYPanHandler(e,this.canvasBoundsContainer.getBoundsHitTest(s));return[()=>{this.chartPanComponent.chartAreaPanHandler.removeChildEntity(i),i.disable()},i]}addCursors(t,e){const s=M.PANE_UUID_Y_AXIS(this.uuid,t);return this.cursorHandler.setCursorForCanvasEl(s,e.state.cursor),()=>this.cursorHandler.removeCursorForCanvasEl(s)}createExtentComponent(t){var e,s;const i=this.yExtentComponents.length,r=M.PANE_UUID(this.uuid),o=()=>this.canvasBoundsContainer.getBounds(r),a=(e=t==null?void 0:t.scale)!=null?e:new jh(this.mainScale,this.config,o,this.canvasAnimation),l=t==null?void 0:t.initialYAxisState,[c,h]=this.createYPanHandler(this.uuid,a),d=(m,x)=>new $f(this.eventBus,this.config,this.mainCanvasModel,this.yAxisLabelsCanvasModel,a,this.canvasInputListener,this.canvasBoundsContainer,this.chartPanComponent,this.cursorHandler,m,x,this.uuid,i,this.hitTestCanvasModel,this.chartResizeHandler,l),u=new Lf(this.config.components.yAxis,this.uuid,i,this,this.chartBaseModel,this.canvasBoundsContainer,this.hitTestController,this.dynamicObjectsCanvasModel,a,d,h);u.addSubscription(c),u.addSubscription(this.addCursors(i,u.yAxis)),t!=null&&t.paneFormatters&&u.setValueFormatters(t.paneFormatters),u.yAxis.togglePriceScaleInverse(t==null?void 0:t.inverse),u.scale.setLockPriceToBarRatio(t==null?void 0:t.lockToPriceRatio),((s=t==null?void 0:t.useDefaultHighLow)==null||s)&&a.autoScaleModel.setHighLowProvider("default",xo(()=>({top:10,bottom:10,left:0,right:0,visible:!0}),Mo(u)));const g=this.createGridComponent(this.uuid,u.idx,a,u.yAxis.state,()=>u.yAxis.model.baseLabelsModel.labels,()=>u.toY(u.getBaseline()));return u.addChildEntity(g),u.activate(),this.yExtentComponents.push(u),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next(),u}removeExtentComponents(t){t.forEach(e=>e.disable()),this.yExtentComponents=this.yExtentComponents.filter(e=>!t.map(s=>s.idx).includes(e.idx)),this.yExtentComponents.forEach((e,s)=>{e.yAxis.setExtentIdx(s),e.idx=s,e.yAxis.updateCursor()}),this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponentsChangedSubject.next()}moveDataSeriesToNewExtentComponent(t,e,s,i="right"){const r=re(s.yAxis.state),o=re(s.scale.state),a=At(r,this.config.components.yAxis,{overrideExisting:!1,addIfMissing:!0}),l=this.createExtentComponent({initialYAxisState:a,inverse:o.inverse,lockToPriceRatio:o.lockPriceToBarRatio});l.yAxis.setYAxisAlign(i),t.forEach(c=>c.moveToExtent(l)),s.dataSeries.size===0&&e.removeExtentComponents([s])}moveDataSeriesToExistingExtentComponent(t,e,s,i,r){t.forEach(o=>o.moveToExtent(i)),!r&&s.dataSeries.size===0&&e.removeExtentComponents([s]),this.yExtentComponentsChangedSubject.next()}updateView(){this.yExtentComponents.forEach(t=>{t.scale.doAutoScale(),t.yAxis.model.labelsGenerator.generateNumericLabels()}),this.canvasBoundsContainer.updateYAxisWidths(),this.eventBus.fireDraw()}mergeYExtents(){for(let t=1;t<this.yExtentComponents.length;t++){const e=this.yExtentComponents[t];e.dataSeries.forEach(s=>s.moveToExtent(this.mainExtent)),e.disable()}this.canvasBoundsContainer.updateYAxisWidths(),this.yExtentComponents=[this.mainExtent]}getBounds(){return this.mainExtent.getBounds()}createDataSeries(){var t;return(t=this.mainExtent)==null?void 0:t.createDataSeries()}addDataSeries(t){this.mainExtent.addDataSeries(t),this.updateView()}removeDataSeries(t){this.mainExtent.removeDataSeries(t),this.updateView()}getAxisType(){return"regular"}moveUp(){this.canvasBoundsContainer.movePaneUp(this.uuid)}moveDown(){this.canvasBoundsContainer.movePaneDown(this.uuid)}canMoveUp(){const t=ge(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}canMoveDown(){const t=St(this.canvasBoundsContainer.panesOrder.filter(e=>this.canvasBoundsContainer.graphsHeightRatio[e]>0));return this.uuid!==t&&this.visible}get regularFormatter(){return this.mainExtent.formatters.regular}setPaneValueFormatters(t){this.mainExtent.setValueFormatters(t)}regularValueFromY(t){return this.mainExtent.regularValueFromY(t)}}var qf=Object.defineProperty,Jf=Object.defineProperties,Qf=Object.getOwnPropertyDescriptors,Lo=Object.getOwnPropertySymbols,tg=Object.prototype.hasOwnProperty,eg=Object.prototype.propertyIsEnumerable,Oo=(n,t,e)=>t in n?qf(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,sg=(n,t)=>{for(var e in t||(t={}))tg.call(t,e)&&Oo(n,e,t[e]);if(Lo)for(var e of Lo(t))eg.call(t,e)&&Oo(n,e,t[e]);return n},ng=(n,t)=>Jf(n,Qf(t));class ig extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f,g,m,x,_){super(),this.chartBaseModel=t,this.dynamicObjectsCanvasModel=e,this.userInputListenerComponents=s,this.eventBus=i,this.mainScale=r,this.canvasBoundsContainer=o,this.config=a,this.canvasAnimation=l,this.canvasInputListener=c,this.drawingManager=h,this.cursorHandler=d,this.crossEventProducer=u,this.chartPanComponent=f,this.mainCanvasModel=g,this.yAxisLabelsCanvasModel=m,this.hitTestCanvasModel=x,this.chartResizeHandler=_,this.panes={},this.paneRemovedSubject=new F,this.paneAddedSubject=new F,this.dataSeriesAddedSubject=new F,this.dataSeriesRemovedSubject=new F,this.hitTestController=new Of(this.panes,this.dynamicObjectsCanvasModel);const A=this.createPane(K,{useDefaultHighLow:!1,scale:this.mainScale});A.mainExtent.scale.autoScaleModel.setHighLowProvider("series",Mo(A.mainExtent)),r.autoScaleModel.setHighLowPostProcessor("offsets",So(()=>this.mainScale.getOffsets()))}get panesOrder(){return this.canvasBoundsContainer.panesOrder}addBounds(t,e){return this.canvasBoundsContainer.addPaneBounds(t,e),()=>this.canvasBoundsContainer.removePaneBounds(t)}addResizer(t){const e=this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID_RESIZER(t),{extensionY:this.config.components.paneResizer.dragZone+Po}),s=()=>this.chartBaseModel.mainVisualPoints.length!==0,i=()=>{this.canvasBoundsContainer.resizePaneVertically(t,this.canvasInputListener.getCurrentPoint().y),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])},r=M.PANE_UUID_RESIZER(t),o=new dn(r,()=>this.canvasBoundsContainer.getBounds(r),e,i,s,this.chartPanComponent,this.mainCanvasModel,this.drawingManager,this.canvasInputListener,this.canvasAnimation,this.config,this.canvasBoundsContainer,this.hitTestCanvasModel);return this.userInputListenerComponents.push(o),o}get yExtents(){return Ie(Object.values(this.panes),t=>t.yExtentComponents)}getPaneIfHit(t){return Object.values(this.panes).find(s=>this.canvasBoundsContainer.getBoundsHitTest(M.PANE_UUID(s.uuid))(t.x,t.y))}createPane(t=wt(),e){if(this.panes[t]!==void 0)return this.panes[t];const s=new Kf(this.chartBaseModel,this.mainCanvasModel,this.yAxisLabelsCanvasModel,this.dynamicObjectsCanvasModel,this.hitTestController,this.config,this.mainScale,this.drawingManager,this.chartPanComponent,this.canvasInputListener,this.canvasAnimation,this.cursorHandler,this.eventBus,this.canvasBoundsContainer,t,this.dataSeriesAddedSubject,this.dataSeriesRemovedSubject,this.hitTestCanvasModel,this.chartResizeHandler,e);return this.config.components.paneResizer.visible&&s.addChildEntity(this.addResizer(t)),s.addSubscription(this.addBounds(t,e==null?void 0:e.order)),s.addSubscription(this.addCursors(t)),s.addSubscription(this.crossEventProducer.subscribeMouseOverHT(t,s.ht)),this.panes[t]=s,s.activate(),this.recalculateState(),s.mainExtent.scale.autoScale(!0),this.paneAddedSubject.next(this.panes),s}movePaneUp(t){this.canvasBoundsContainer.movePaneUp(t)}movePaneDown(t){this.canvasBoundsContainer.movePaneDown(t)}canMovePaneUp(t){var e,s;const i=ge(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}canMovePaneDown(t){var e,s;const i=St(this.canvasBoundsContainer.panesOrder.filter(r=>{var o,a;return(a=(o=this.panes[r])==null?void 0:o.visible)!=null?a:!1}));return t!==i&&((s=(e=this.panes[t])==null?void 0:e.visible)!=null?s:!1)}removePane(t){const e=this.panes[t];e!==void 0&&(this.paneRemovedSubject.next(e),e.disable(),e.yExtentComponents.forEach(s=>s.disable()),delete this.panes[t],this.recalculateState())}hidePane(t){const e=this.panes[t];if(e===void 0||!e.visible)return;const s=M.PANE_UUID_RESIZER(t),i=this.userInputListenerComponents.find(r=>r instanceof dn&&r.id===s);i==null||i.disable(),this.canvasBoundsContainer.hidePaneBounds(t),this.recalculateState()}showPane(t){const e=this.panes[t],s=M.PANE_UUID_RESIZER(t);if(e===void 0||e.visible)return;const i=this.userInputListenerComponents.find(r=>r instanceof dn&&r.id===s);i==null||i.enable(),this.canvasBoundsContainer.showPaneBounds(t),this.recalculateState()}moveDataSeriesToPane(t,e,s,i){const{paneUUID:r,extent:o,direction:a,align:l,extentIdx:c,isForceKeepPane:h,index:d=0}=i,u=r&&this.panes[r],f=l?ng(sg({},s.yAxis.state),{align:l}):void 0,g=c&&c>0;if(!u){const m=a&&a==="above"?d:d+1,x=this.createPane(r,{order:m,initialYAxisState:f,inverse:s.scale.state.inverse,lockToPriceRatio:s.scale.state.lockPriceToBarRatio});x.moveDataSeriesToExistingExtentComponent(t,e,s,x.mainExtent,h),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid);return}o&&!g?u.moveDataSeriesToExistingExtentComponent(t,e,s,o):u.moveDataSeriesToNewExtentComponent(t,e,s,l!=null?l:s.yAxis.state.align),!h&&e.yExtentComponents.length===0&&this.removePane(e.uuid)}addCursors(t,e=this.config.components.chart.cursor){const s=M.PANE_UUID(t),i=M.PANE_UUID_RESIZER(t);return this.cursorHandler.setCursorForCanvasEl(s,e),this.config.components.paneResizer.visible&&this.cursorHandler.setCursorForCanvasEl(i,this.config.components.paneResizer.cursor,this.config.components.paneResizer.dragZone+Po),()=>{this.cursorHandler.removeCursorForCanvasEl(s),this.config.components.paneResizer.visible&&this.cursorHandler.removeCursorForCanvasEl(i)}}recalculateState(){Object.values(this.panes).forEach(t=>t.scale.recalculateZoomY()),this.eventBus.fireDraw([this.mainCanvasModel.canvasId,"dynamicObjectsCanvas"])}}class rg extends X{constructor(t,e){super(),this.elements=t,this.canvasModel=e}doActivate(){super.doActivate()}createSnapshot(t){const e=this.canvasModel.canvas,s=this.canvasModel.ctx;if(s){s.clearRect(0,0,e.width,e.height);const i=e.width/window.devicePixelRatio,r=e.height/window.devicePixelRatio;return s.drawImage(this.elements.backgroundCanvas,0,0,i,r),s.drawImage(this.elements.mainCanvas,0,0,i,r),s.drawImage(this.elements.dynamicObjectsCanvas,0,0,i,r),s.drawImage(this.elements.crossToolCanvas,0,0,i,r),s.drawImage(this.elements.yAxisLabelsCanvas,0,0,i,r),t&&t(s),new Promise((o,a)=>this.elements.snapshotCanvas.toBlob(l=>l?o(l):a("Blob is null")))}else return console.error("Snapshot isn't supported"),Promise.reject()}}const og=(n,t=1)=>{function e(i){let r;const o=Math.pow(10,t);return i=Math.round(i*o)/o,i>=1e-15&&i<1?r=i.toFixed(t).replace(/\.?0+$/,""):r=String(i),r.replace(/(\.[1-9]*)0+$/,(a,l)=>l)}function s(i){let r="";return i<0&&(r="-",i=-i),i<995?r+e(i):i<999995?r+e(i/1e3)+"K":i<999999995?(i=1e3*Math.round(i/1e3),r+e(i/1e6)+"M"):(i=1e6*Math.round(i/1e6),r+e(i/1e9)+"B")}return s(n)},Bo=class _s extends X{constructor(t,e,s,i){super(),this.chartComponent=t,this.config=e,this.volumesModel=s,this.paneManager=i,e.components.volumes.showSeparately&&this.activateSeparateVolumes()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(()=>{var t,e;return!((t=this.pane)!=null&&t.scale.isViewportValid())&&((e=this.pane)==null?void 0:e.scale.doAutoScale(!0))})),this.addRxSubscription(this.volumesModel.volumeMax.subscribe(()=>{var t;return(t=this.pane)==null?void 0:t.scale.doAutoScale()}))}activateSeparateVolumes(){if(this.paneManager.panes[_s.UUID]===void 0){const e=this.paneManager.createPane(_s.UUID,{paneFormatters:{regular:r=>og(r,1)},useDefaultHighLow:!1,increment:1});this.pane=e,e.mainExtent.yAxis.setAxisType("regular");const{scale:s}=e,i=xo(()=>({top:10,bottom:0,left:0,right:0,visible:!0}),this.volumesModel.highLowProvider);s.autoScaleModel.setHighLowProvider("volumes",i),s.doAutoScale(!0)}}deactiveSeparateVolumes(){this.paneManager.removePane(_s.UUID),delete this.pane}fromY(t){var e,s;return(s=(e=this.pane)==null?void 0:e.scale.fromY(t))!=null?s:0}};Bo.UUID="volumes";let ag=Bo;const vs=.3,lg=(n,t)=>{const e=t.barTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},cg=(n,t)=>{const e=t.volume[`${n}BarColor`];return Bt()(e).alpha(vs).toString()},hg=(n,t)=>{const e=t.lineTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},gn=(n,t)=>{const e=t.candleTheme[`${n}Color`];return Bt()(e).alpha(vs).toString()},dg=3;class ug{constructor(t,e,s,i,r,o){this.config=t,this.volumesModel=e,this.chartModel=s,this.getViewportModel=i,this.volumesColorByChartTypeMap=r,this.drawPredicate=o,this.volumeBarColors={down:"#FF00FF",up:"#FF00FF",none:"#FF00FF"}}calculateColors(t){var e;const s=(e=this.volumesColorByChartTypeMap[t])!=null?e:cg;this.volumeBarColors.down=s("down",this.config.colors),this.volumeBarColors.up=s("up",this.config.colors),this.volumeBarColors.none=s("none",this.config.colors)}draw(t){if(this.config.components.volumes.visible&&this.drawPredicate()){this.calculateColors(this.config.components.chart.type);const e=t.ctx;e.save();const s=this.getViewportModel().getBounds();Kt(e,s),this.drawVolumes(t),e.restore()}}drawLastBar(){this.config.components.volumes.visible}drawVolumes(t){const e=this.volumesModel.volumeMax.getValue();if(e===0)return;const s=this.getViewportModel();if(!s.isViewportValid())return;const i=mt(this.chartModel.mainCandleSeries.getSeriesInViewport(this.chartModel.scale.xStart-1,this.chartModel.scale.xEnd+1));i.forEach((r,o)=>{if(r.candle.volume){const a=s.getBounds(),l=a.height;if(l<=0)return;const c=i[o+1]!==void 0?Et(s.toX(i[o+1].startUnit)):void 0,h=Et(s.toX(r.startUnit)),d=c!==void 0?c-h:Et(vt(r.width,s.zoomX));if(this.config.components.volumes.showSeparately){const u=Et(s.toY(r.candle.volume)),f=qs(s.toY(0))-u;this.drawVolume(t,r,h,u,d,f)}else{const u=l/dg;if(u<=0)return;const f=e/u;if(!isFinite(f)||f<=0)return;const g=Math.max(qs(vt(r.candle.volume,f)),2),m=Math.min(g,l),x=Et(a.y+l-m);this.drawVolume(t,r,h,x,d,m)}}})}drawVolume(t,e,s,i,r,o){const a=t.ctx,l=i,c=i+o,h=e.name;a.fillStyle=this.volumeBarColors[h],a.strokeStyle=this.volumeBarColors[h],r===0?(a.beginPath(),a.moveTo(s,l),a.lineTo(s,qs(c)),a.stroke()):a.fillRect(s,i,r,o)}}const fg=Hl(n=>n.candle.volume),Ro="volumes";class gg extends X{constructor(t,e){super(),this.chartComponent=t,this.scale=e,this.id=Ro,this.volumeMax=new ft(0),this.highLowProvider={calculateHighLow:()=>({high:this.volumeMax.getValue(),low:0}),isHighLowActive:()=>!0}}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartComponent.chartModel.observeCandlesChanged(),this.scale.xChanged).subscribe(()=>this.updateVolumeMax())),this.addRxSubscription(this.chartComponent.chartModel.mainCandleSeries.observeLastVisualCandleChanged().subscribe(()=>this.recalculateLastVisualVolume()))}recalculateLastVisualVolume(){}updateVolumeMax(){var t;const e=this.chartComponent.chartModel.mainCandleSeries.getSeriesInViewport(this.scale.xStart-1,this.scale.xEnd+1);this.volumeMax.next((t=ge(fg(e.flat())))!=null?t:0)}}class pg extends X{constructor(t,e,s,i,r,o,a,l){super(),this.canvasModel=t,this.canvasBoundsContainer=i,this.config=o,this.dynamicObjectsComponent=l,this.volumesColorByChartTypeMap={},this.volumeVisibilityChangedSubject=new ft(!1),this.volumeIsSeparateModeChangedSubject=new ft(!1);const c=new gg(e,s);this.volumesModel=c,this.addChildEntity(c),this.separateVolumes=new ag(e,o,c,a),this.volumesDrawer=new ug(o,this.volumesModel,e.chartModel,()=>{var h,d;return this.config.components.volumes.showSeparately&&(d=(h=this.separateVolumes.pane)==null?void 0:h.scale)!=null?d:s},this.volumesColorByChartTypeMap,()=>!0),o.components.volumes.visible&&this.syncVolumesDynamicObject(),this.addChildEntity(this.separateVolumes),this.registerDefaultVolumeColorResolvers(),this.volumeVisibilityChangedSubject.next(o.components.volumes.visible),this.volumeIsSeparateModeChangedSubject.next(o.components.volumes.showSeparately)}registerDefaultVolumeColorResolvers(){this.registerVolumeColorResolver("candle",gn),this.registerVolumeColorResolver("trend",gn),this.registerVolumeColorResolver("hollow",gn),this.registerVolumeColorResolver("line",hg),this.registerVolumeColorResolver("bar",lg)}setShowVolumesSeparatly(t){this.config.components.volumes.showSeparately!==t&&(this.config.components.volumes.showSeparately=t,t?this.separateVolumes.activateSeparateVolumes():this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(t),this.syncVolumesDynamicObject())}doDeactivate(){super.doDeactivate(),this.setVisible(!1)}registerVolumeColorResolver(t,e){this.volumesColorByChartTypeMap[t]=e}setVisible(t=!0){this.config.components.volumes.visible=t,this.volumeVisibilityChangedSubject.next(t),this.config.components.volumes.showSeparately&&(t?(this.separateVolumes.activateSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!0)):(this.separateVolumes.deactiveSeparateVolumes(),this.volumeIsSeparateModeChangedSubject.next(!1))),this.canvasBoundsContainer.recalculatePanesHeightRatios(),this.syncVolumesDynamicObject(),this.canvasModel.fireDraw()}syncVolumesDynamicObject(){if(!this.config.components.volumes.visible){this.dynamicObjectsComponent.model.removeObject(this.volumesModel.id);return}const e=this.config.components.volumes.showSeparately?Ro:K,s={id:this.volumesModel.id,paneId:e,drawer:this.volumesDrawer,model:this.volumesModel};if(this.dynamicObjectsComponent.model.getObjectPosition(this.volumesModel.id)===-1){this.dynamicObjectsComponent.model.addObject(s);return}this.dynamicObjectsComponent.model.updateObject(s)}}class mg{constructor(t,e,s,i,r){this.config=t,this.canvasBoundsContainer=e,this.canvasModel=s,this.waterMarkConfigProvider=i,this.watermarkDataProvider=r,this.getConfig=(o=0,a,l,c,h,d)=>{const u=this.canvasModel.ctx,f=this.canvasBoundsContainer.getBounds(M.PANE_UUID(K)),{position:g,offsetY:m,offsetX:x}=this.config.components.waterMark;let _;switch(d?_=d:(u.font=bs(this.config,l),_=u.measureText(a).width,f.width-10<_&&(u.font=vg(this.config,this.canvasBoundsContainer,l,_),_=u.measureText(a).width)),g){case"left-top":return{x:x+f.x,y:m+o+f.y,font:u.font,text:a,color:c};case"left-bottom":return{x:x+f.x,y:f.height-h-m+o+f.y,font:u.font,text:a,color:c};case"center":return{x:f.width/2-_/2+f.x,y:(f.height-h)/2+o+f.y,font:u.font,text:a,color:c}}}}draw(){var t,e,s,i,r,o,a;if((t=this.config.components.waterMark)!=null&&t.visible&&this.config.colors){const{firstRow:l,secondRow:c,thirdRow:h}=this.watermarkDataProvider(),d=this.waterMarkConfigProvider(),u=this.config.colors.waterMarkTheme,f=this.canvasModel.ctx;let g=0,m=0,x=0,_=0,A=0;if(f.save(),d.firstRowFontSize&&l){f.font=bs(this.config,d.firstRowFontSize);const B=f.measureText(l);g=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent}if(d.secondRowFontSize&&c){f.font=bs(this.config,d.secondRowFontSize);const B=f.measureText(c);m=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,x=(e=d.firstRowBottomPadding)!=null?e:0}if(d.thirdRowFontSize&&h){f.font=bs(this.config,d.thirdRowFontSize);const B=f.measureText(h);_=B.actualBoundingBoxAscent+B.actualBoundingBoxDescent,A=(s=d.secondRowBottomPadding)!=null?s:0}const L=(i=d.thirdRowBottomPadding)!=null?i:0,Y=(r=d.logoHeight)!=null?r:0,H=g+m+x+_+A+L+Y;if(l&&this.drawWaterMark(this.getConfig(g,l,d.firstRowFontSize,u.firstRowColor,H)),c&&this.drawWaterMark(this.getConfig(g+x+m,c,d.secondRowFontSize,u.secondRowColor,H)),h&&this.drawWaterMark(this.getConfig(g+x+m+A+_,h,d.thirdRowFontSize,u.thirdRowColor,H)),this.logoImage){const B=this.getConfig(g+x+m+A+_+L,"",d.thirdRowFontSize,u.thirdRowColor,H,d.logoWidth);this.canvasModel.ctx.drawImage(this.logoImage,B.x,B.y,(o=d.logoWidth)!=null?o:0,(a=d.logoHeight)!=null?a:0)}f.restore()}}getCanvasIds(){return[this.canvasModel.canvasId]}setLogoImage(t){this.logoImage=t}drawWaterMark(t){const e=t.text;if(!e||!e.length)return;const s=this.canvasModel.ctx;s.font=t.font,s.fillStyle=t.color;const i=t.x,r=t.y;s.fillText(e,i,r)}reset(){}}const vg=(n,t,e,s)=>{const r=((a,l)=>t.getBounds(M.CHART).width/l*a)(e,s);let o;return n.components&&n.components.waterMark&&(o=n.components.waterMark.fontFamily),r+"px "+o},bs=(n,t)=>{let e;return n.components&&n.components.waterMark&&(e=n.components.waterMark.fontFamily),t+"px "+e};var bg=Object.defineProperty,Fo=Object.getOwnPropertySymbols,Cg=Object.prototype.hasOwnProperty,yg=Object.prototype.propertyIsEnumerable,Ho=(n,t,e)=>t in n?bg(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ko=(n,t)=>{for(var e in t||(t={}))Cg.call(t,e)&&Ho(n,e,t[e]);if(Fo)for(var e of Fo(t))yg.call(t,e)&&Ho(n,e,t[e]);return n};class wg extends X{constructor(t,e,s,i,r,o,a){super(),this.paneManager=t,this.chartModel=e,this.eventBus=s,this.config=i,this.canvasModel=o,this.waterMarkConfig=this.config.components.waterMark,this.waterMarkData=this.getWaterMarkData(),this.waterMarkDrawer=new mg(this.config,r,o,()=>this.waterMarkConfig,()=>this.waterMarkData),this.addRxSubscription(At(r.observeBoundsChanged(M.PANE_UUID(K)),this.paneManager.paneAddedSubject).subscribe(l=>{this.waterMarkConfig=this.recalculateTextSize(l.width,l.height)})),this.addRxSubscription(this.chartModel.candlesSetSubject.subscribe(()=>{this.waterMarkData=this.getWaterMarkData()})),a.addDrawerAfter(this.waterMarkDrawer,"WATERMARK","DYNAMIC_OBJECTS")}setWaterMarkVisible(t){this.config.components&&this.config.components.waterMark&&(this.config.components.waterMark.visible=t,this.canvasModel.fireDraw())}setWaterMarkData(t){this.waterMarkData=t,this.canvasModel.fireDraw()}getWaterMarkData(){return this.waterMarkData||{}}setWaterMarkConfig(t){if(!(!t||!this.config.components)){if(!this.config.components.waterMark)this.config.components.waterMark=JSON.parse(JSON.stringify(t));else{const e={};At(e,t),At(e,this.config.components.waterMark),this.config.components.waterMark=e}this.canvasModel.fireDraw()}}setLogoImage(t){this.waterMarkDrawer.setLogoImage(t)}recalculateTextSize(t,e){const r=d=>.15*Math.log(d)/Math.log(1.5)+1,o=r(t/1920),a=r(e/1080),l=Math.min(o,a),c=l>=0?l:0,h={firstRowFontSize:Math.round(this.config.components.waterMark.firstRowFontSize*c),secondRowFontSize:Math.round(this.config.components.waterMark.secondRowFontSize*c),thirdRowFontSize:Math.round(this.config.components.waterMark.thirdRowFontSize*c)};return ko(ko({},this.config.components.waterMark),h)}}const jo={x:4,y:4};function Sg(n,t,e,s){var i,r;const o=(i=s.alignType)!=null?i:"middle",{fontSize:a,fontFamily:l,padding:c}=e.components.xAxis,h=e.colors.xAxis,d=(r=c.top)!=null?r:0,u=t.getBounds(M.X_AXIS);n.save(),n.font=`bold ${a}px ${l}`;const g=n.measureText(s.text).width+jo.x*2;let m=0;const x=s.x;switch(o){case"start":m=x-g;break;case"end":m=x;break;default:m=x-g/2;break}n.fillStyle=h.backgroundColor,n.strokeStyle=h.backgroundColor,n.fillRect(m,u.y,g,u.height),o!=="middle"&&(n.strokeStyle=s.color,n.beginPath(),n.moveTo(x,u.y),n.lineTo(x,u.y+u.height),n.stroke()),n.fillStyle=s.color;const _=m+jo.x,A=u.y+d+a+De/2;n.fillText(s.text,_,A),n.restore()}class xg{constructor(t,e,s,i){this.config=t,this.canvasModel=e,this.canvasBoundsContainer=s,this.xAxisLabelsModel=i}draw(){const t=this.canvasModel.ctx;this.drawHighlightedBackgroundBetweenLabels(),this.xAxisLabelsModel.labels.forEach(e=>{Sg(t,this.canvasBoundsContainer,this.config,e)})}drawHighlightedBackgroundBetweenLabels(){const t=this.canvasModel.ctx,e={},s=this.xAxisLabelsModel.labels.reduce((i,r)=>{if(r.subGroupId!==void 0){let o=i[r.subGroupId];o||(o=[],i[r.subGroupId]=o),o.push(r)}return i},e);Object.keys(s).forEach(i=>{const r=s[i];if(r.length===2){const o=this.canvasBoundsContainer.getBounds(M.X_AXIS);t.fillStyle=Bt().rgb(r[0].color).alpha(.1).toString(),Er(t,{x:r[0].x,y:o.y},{x:r[1].x,y:o.y+o.height})}})}getCanvasIds(){return[this.canvasModel.canvasId]}}const lv="week-weekday",_g=["second","minute","hour","day","month","year"],Pg=["lessThanSecond"],Tg=n=>_g.some(t=>t===n),Mg=n=>n==="week-weekday",Ag=n=>Pg.some(t=>t===n),Yo=n=>{const t={"!":!1,$:!1};return n.includes("!")&&(t["!"]=!0),n.includes("$")&&(t.$=!0),t},pn=n=>parseInt(n,10),No=n=>{const[t,...e]=n.split("_");if(Tg(t)){const[s]=e,i=Yo(s),r=pn(s);return{key:t,value:r,exact:i["!"]}}else if(Mg(t)){const[s,i]=e,r=Yo(s),o=pn(s),a=pn(i);return{key:t,week:r.$?"$":o,weekday:a}}else return Ag(t)?{key:t}:(console.warn(`${n} is not fit, check the documentation to see available formats in dxchart-lite documentation.`),null)};class Cs{constructor(t,e,s,i,r,o=()=>!0){this.config=t,this.canvasModel=e,this.viewportModel=s,this.canvasBoundsContainer=i,this.labelsProvider=r,this.drawPredicate=o}draw(){var t;if(this.drawPredicate()){const e=this.canvasModel.ctx,s=this.config.colors.xAxis,i=this.config.components.xAxis.fontFamily,r=Cs.getFontFromConfig(this.config),o=this.config.components.xAxis.fontSize,a=(t=this.config.components.xAxis.padding.top)!=null?t:0;e.save(),e.font=r,e.fillStyle=s.backgroundColor;const l=this.canvasBoundsContainer.getBounds(M.X_AXIS);this.config.components.chart.applyBackgroundToAxes.x||e.fillRect(l.x,l.y,l.width,l.height);const c=this.config.colors.xAxis.labelTextColor,h=this.labelsProvider();this.drawLabels(e,h,l,c,o,i,a+De/2),e.restore()}}drawLabels(t,e,s,i,r,o,a){const l=`${r}px ${o}`;t.fillStyle=i;for(const c of e){const h=this.viewportModel.toX(c.value)-Mt(c.text,t,l)/2;if(h<s.x||h>s.width)continue;const d=s.y+r-1+a,u=c.text;t.font=l,t.fillText(u,h,d)}}static getFontFromConfig(t){return`${t.components.xAxis.fontStyle} ${t.components.xAxis.fontSize}px ${t.components.xAxis.fontFamily}`}getCanvasIds(){return[this.canvasModel.canvasId]}}const mn={lessThanSecond:0,second:100,minute:200,hour:300,day:400,"week-weekday":500,month:600,year:1e4},Xo=n=>{switch(n.key){case"second":case"minute":case"hour":case"day":case"month":case"year":return mn[n.key]+n.value;case"lessThanSecond":return mn[n.key];case"week-weekday":return mn[n.key]+(n.week==="$"?9:n.week)+n.weekday*10}},Wo=n=>{const t={};for(const e of n){const s=t[e.weight];s===void 0?t[e.weight]=[e]:s.push(e)}return t},Eg=(n,t)=>{const e=Object.keys(n).map(i=>parseInt(i,10)).sort((i,r)=>r-i);let s=[];for(const i of e){const r=n[i];if(!r)continue;const o=[...s];s=[];const a=o.length,l=r.length;let c=0,h=1/0,d=-1/0;for(let u=0;u<l;u++){const f=r[u],g=f.idx;for(;c<a;){const m=o[c],x=m.idx;if(g>x)c++,s.push(m),d=x,h=1/0;else{h=x;break}}h-g>=t&&g-d>=t&&(s.push(f),d=g)}for(;c<a;)s.push(o[c]),c++}return s},Ig=(n,t,e,s,i,r)=>{const o=Cs.getFontFromConfig(t),a=Mt(e.text,n,o),l=Mt(s.text,n,o),c=i.toX(e.value)+a/2;return i.toX(s.value)-l/2-c<r},cv=7,Dg=365.2425,dv=-(Math.pow(10,8)*24*60*60*1e3),uv=6048e5,fv=864e5,gv=6e4,pv=36e5,mv=1e3,vv=525600,bv=43200,Cv=1440,yv=60,wv=3,Sv=12,xv=4,Lg=3600,_v=60,zo=Lg*24,Pv=zo*7,Av=zo*Dg/12*3,Vo=Symbol.for("constructDateFrom");function vn(n,t){return typeof n=="function"?n(t):n&&typeof n=="object"&&Vo in n?n[Vo](t):n instanceof Date?new n.constructor(t):new Date(t)}const Ev=null;function kt(n,t){return vn(t||n,n)}const Iv=null;function Og(n,t){return kt(n,t==null?void 0:t.in).getDay()===1}const Dv=null;function Bg(n,t){return kt(n,t==null?void 0:t.in).getDay()===2}const Lv=null;function Rg(n,t){return kt(n,t==null?void 0:t.in).getDay()===3}const Ov=null;function Fg(n,t){return kt(n,t==null?void 0:t.in).getDay()===4}const Bv=null;function Hg(n,t){return kt(n,t==null?void 0:t.in).getDay()===5}const Rv=null;function kg(n,t){return kt(n,t==null?void 0:t.in).getDay()===6}const Fv=null;function jg(n,t){return kt(n,t==null?void 0:t.in).getDay()===0}const Hv=null;function Uo(n,...t){const e=vn.bind(null,n||t.find(s=>typeof s=="object"));return t.map(e)}function Yg(n,t){const[e,s]=Uo(n,t.start,t.end);return{start:e,end:s}}function Ng(n,t){var c;const{start:e,end:s}=Yg(t==null?void 0:t.in,n);let i=+e>+s;const r=i?+e:+s,o=i?s:e;o.setHours(0,0,0,0);let a=(c=t==null?void 0:t.step)!=null?c:1;if(!a)return[];a<0&&(a=-a,i=!i);const l=[];for(;+o<=r;)l.push(vn(e,o)),o.setDate(o.getDate()+a),o.setHours(0,0,0,0);return i?l.reverse():l}const kv=null;function Xg(n,t){const e=kt(n,t==null?void 0:t.in);return e.setDate(1),e.setHours(0,0,0,0),e}const jv=null;function Wg(n,t){const e=kt(n,t==null?void 0:t.in),s=e.getMonth();return e.setFullYear(e.getFullYear(),s+1,0),e.setHours(23,59,59,999),e}const Yv=null;function Go(n,t){const e=kt(n,t==null?void 0:t.in);return e.setHours(0,0,0,0),e}const Nv=null;function Zo(n,t,e){const[s,i]=Uo(e==null?void 0:e.in,n,t);return+Go(s)==+Go(i)}const Xv=null,zg=n=>{switch(n.key){case"lessThanSecond":return Zg(n);case"month":return $g(n);case"second":case"minute":case"hour":case"day":case"year":return Kg(n);case"week-weekday":return qg(n);default:return()=>!1}},Qt=(n,t)=>{switch(t){case"lessThanSecond":return n.getMilliseconds();case"month":return n.getMonth();case"second":return n.getSeconds();case"minute":return n.getMinutes();case"hour":return n.getHours();case"day":return n.getDate();case"year":return n.getFullYear();case"week-weekday":return n.getDate()}},bn=n=>(t,e)=>{const s=Qt(t,n),i=Qt(e,n);return s!==i},Vg=n=>(t,e)=>{const s=Qt(t,n),i=Qt(e,n);return s>=i},Ug={1:Og,2:Bg,3:Rg,4:Fg,5:Hg,6:kg,7:jg},Gg=(n,t,e)=>{var s;const i=Ng({start:Xg(n),end:Wg(n)}),r=(s=Ug[e])!=null?s:(()=>!1);if(t==="$"){for(const o of i.reverse())if(r(o))return Zo(n,o)}else{let o=1;for(const a of i)if(r(a)){if(o===t)return Zo(n,a);o++}}return!1},$o=(n,t)=>t===1?n===1:n/t===1,Ko=(n,t)=>t===1?!0:n%t===0,Zg=n=>(t,e)=>Vg(n.key)(t,e),$g=n=>(t,e)=>{const s=bn(n.key)(t,e),i=n.exact?$o(Qt(t,n.key)+1,n.value):Ko(Qt(t,n.key)+1,n.value);return s&&i},Kg=n=>(t,e)=>{const s=bn(n.key)(t,e),i=n.exact?$o(Qt(t,n.key),n.value):Ko(Qt(t,n.key),n.value);return s&&i},qg=n=>(t,e)=>{const s=bn(n.key)(t,e),i=Gg(t,n.week,n.weekday);return s&&i},Jg=n=>{switch(n.key){case"second":case"minute":return Qg(n.value);case"hour":return tp(n.value);case"day":return ep(n.value);case"month":return ip(n.value);case"year":return rp(n.value);case"week-weekday":const t=np(n.week),e=sp(n.weekday);return t&&e;case"lessThanSecond":return!0;default:return!1}},Qg=n=>n>0&&n<=60,tp=n=>n>0&&n<=24,ep=n=>n>0&&n<=31,sp=n=>qo(n)?n>=1&&n<=7:!1,np=n=>n==="$"?!0:qo(n)?n>=1&&n<=6:!1,ip=n=>n>0&&n<=12,rp=n=>n>0,qo=n=>!isNaN(n)&&isFinite(n),op=(n,t,e)=>{var s,i;for(const[r,o]of e)if(o(n,t))return r;return(i=(s=e[e.length-1])==null?void 0:s[0])!=null?i:0};function Cn(n,t,e){const s=new Array(n.length);let i=e(0);for(let r=0;r<n.length;r++){const o=n[r],a=e(o.candle.timestamp),l={weight:op(a,i,t)};s[r]=l,i=a}return s}const Jo=n=>{const t={},e={};return Js(n).forEach(([s,i])=>{const r=No(s),o=r===null?!1:Jg(r);if(r&&o){const a=Xo(r);t[a]=i,e[a]=zg(r)}}),{weightToTimeFormatsDict:t,weightToTimeFormatMatcherDict:e}};class Qo{constructor(t,e,s,i,r,o,a){this.eventBus=t,this.config=e,this.chartModel=s,this.scale=i,this.timeZoneModel=r,this.canvasModel=o,this.canvasBoundsContainer=a,this.labelsGroupedByWeight={},this.levelsCache={},this.labelCache=new Map,this.weightToTimeFormatMatcherArray=[],this.weightToTimeFormatsDict={},this.extendedLabelsFilterConfig={minute_1:h=>h>=2},this.calculateCoverUpLevel=()=>{const h=this.scale.currentAnimation,d=this.chartModel.mainCandleSeries.meanCandleWidth;if(Object.getOwnPropertyNames(this.labelsGroupedByWeight).length===0)return-1;const u=h!=null&&h.animationInProgress?vt(d,h.animationConfig.targetZoomX):vt(d,this.scale.zoomX);if(!isFinite(u))return-1;const f=this.config.components.xAxis.fontSize,g=Object.values(this.formatsByWeightMap).reduce((x,_)=>Math.max(_.length,x),1),m=f*g;return Math.round(m/u)},this.formatsByWeightMap=e.components.xAxis.formatsForLabelsConfig;const{weightToTimeFormatsDict:l,weightToTimeFormatMatcherDict:c}=Jo(this.formatsByWeightMap);this.weightToTimeFormatMatcherArray=Object.entries(c).map(([h,d])=>[parseInt(h,10),d]).sort(([h],[d])=>d-h),this.weightToTimeFormatsDict=l}get labels(){return this.filterLabelsInViewport(this.getLabelsFromChartType())}filterLabelsInViewport(t){const e=this.canvasBoundsContainer.getBounds(M.X_AXIS),s=[];for(const i of t){const r=this.scale.toX(i.value);r<0||r>e.width||s.push(i)}return s}getLabelsFromChartType(){var t,e;const s=(e=(t=this.weightedCache)==null?void 0:t.labels)!=null?e:[];return this.config.components.chart.type==="equivolume"?this.postProcessing(s):s}getVisualCandleAtIndex(t,e,s,i,r){return t>=0&&t<s.length?s[t]:en(e,s,i,t,r)}getVisualCandlesWithFake(t=[]){const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0)return[];const i=Array.from({length:750}).map((r,o)=>en(this.chartModel.mainCandleSeries.dataPoints,this.chartModel.mainCandleSeries.visualPoints,this.chartModel.mainCandleSeries.meanCandleWidth,e.length+o,this.chartModel.getPeriod()));return[...t,...e,...i]}getViewportCandlesWithFake(){var t;const e=this.chartModel.mainCandleSeries.visualPoints;if(e.length===0||this.scale.xEnd-this.scale.xStart<=1)return[];const s=this.chartModel.mainCandleSeries.meanCandleWidth,i=this.chartModel.getPeriod(),r=this.chartModel.mainCandleSeries.dataPoints,o=this.canvasBoundsContainer.getBounds(M.CHART),a=0,l=o.width,c=this.scale.fromX(a),h=this.scale.fromX(l);let d=0;if(e.length>0){const L=e[0];d=L.centerUnit-((t=L.candle.idx)!=null?t:0)*s}const u=500,f=500,g=Math.floor((c-d)/s)-u,m=Math.ceil((h-d)/s)+u,x=Math.floor(g/f)*f,_=Math.ceil(m/f)*f,A=[];for(let L=x;L<=_;L++)A.push(this.getVisualCandleAtIndex(L,r,e,s,i));return[...A]}getAllCandlesWithFake(t=[]){return this.config.components.chart.minCandlesOffset?this.getVisualCandlesWithFake(t):this.getViewportCandlesWithFake()}mapWeightedPointsToLabels(t,e){var s;const i=new Array(t.length);for(let r=0;r<t.length;++r){const o=t[r],a=e[r],l=this.weightToTimeFormatsDict[o.weight],c=this.timeZoneModel.getDateTimeFormatter(l)(a.candle.timestamp);i[r]={weight:o.weight,idx:(s=a.candle.idx)!=null?s:0,value:a.centerUnit,time:a.candle.timestamp,text:c}}return i}setFormatsForLabelsConfig(t){this.clearLabelCache();const{weightToTimeFormatsDict:e,weightToTimeFormatMatcherDict:s}=Jo(t);this.formatsByWeightMap=t,this.weightToTimeFormatMatcherArray=Object.entries(s).map(([i,r])=>[parseInt(i,10),r]).sort(([i],[r])=>r-i),this.weightToTimeFormatsDict=e,this.generateLabels()}getLabelsFromCache(t){if(this.levelsCache[t])return this.levelsCache[t]}updateLastLabel(t){const e=this.chartModel.mainCandleSeries.visualPoints[this.chartModel.mainCandleSeries.visualPoints.length-2];if(e){const i=Cn([e,t],this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),r=this.mapWeightedPointsToLabels([i[1]],[t]),[o]=r;this.labelsGroupedByWeight=Object.entries(this.labelsGroupedByWeight).reduce((a,[l,c])=>{const h=c.findIndex(u=>u.idx===o.idx);let d=c;if(h!==-1&&(d=c.filter(u=>u.idx!==o.idx)),parseInt(l,10)===o.weight){const u=d.findIndex(f=>f.idx>o.idx);u!==-1?d=[...d.slice(0,u),o,...d.slice(u)]:d.push(o)}return a[l]=d,a},{}),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}}updateHistoryLabels(t){const e=t.concat(this.chartModel.mainCandleSeries.visualPoints[t.length]),s=Cn(e,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone)),i=this.mapWeightedPointsToLabels(s,e),r=Wo(i),o=re(r);for(const c in this.labelsGroupedByWeight)o[c]===void 0&&(o[c]=this.labelsGroupedByWeight[c]);const a=this.chartModel.mainCandleSeries.visualPoints[t.length-1],l=Object.entries(o).sort(([c],[h])=>parseInt(h,10)-parseInt(c,10)).reduce((c,[h,d])=>{const u=parseInt(h,10),f=this.labelsGroupedByWeight[u];if(u===this.weightToTimeFormatMatcherArray[0][0]&&f.shift(),f){const g=f.map(m=>(m.idx=m.idx+t.length,m.value=a.startUnit+a.width+m.value,m));r[u]?c[h]=d.concat(g):c[h]=g}else c[h]=d;return c},{});this.labelsGroupedByWeight=l,this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}generateLabels(t,e=!1){var s;const i=this.getAllCandlesWithFake(t),r=Cn(i,this.weightToTimeFormatMatcherArray,this.timeZoneModel.tzOffset(this.config.timezone));let o=[];if(e)for(let a=0;a<i.length;a++){const l=(s=i[a].candle.idx)!=null?s:a,c=i[a].candle.timestamp,h=`${l}_${c}`;let d=this.labelCache.get(h);d||(d=this.mapWeightedPointsToLabels([r[a]],[i[a]])[0],this.labelCache.set(h,d)),o.push(d)}else o=this.mapWeightedPointsToLabels(r,i);this.labelsGroupedByWeight=Wo(o),this.weightedCache=void 0,this.levelsCache={},this.recalculateCachedLabels()}recalculateLabels(){this.recalculateCachedLabels()}recalculateCachedLabels(){const t=this.calculateCoverUpLevel();if(!(t<0)&&(this.weightedCache===void 0||t!==this.weightedCache.coverUpLevel)){const e=this.getLabelsFromCache(t);if(e){this.weightedCache={labels:e,coverUpLevel:t};return}const s=Eg(this.filterLabelsByExtendedRules(this.labelsGroupedByWeight,t),t);this.levelsCache[t]=s,this.weightedCache={labels:s,coverUpLevel:t},this.eventBus.fireDraw()}}postProcessing(t){var e,s;const i=[];let r=0,o=1;for(;o<=t.length-1;){const a=t[r],l=t[o];Ig(this.canvasModel.ctx,this.config,a,l,this.scale,30)?((e=l.weight)!=null?e:0)>((s=a.weight)!=null?s:0)&&(r=o):(i.push(a),r=o,o===t.length-1&&i.push(l)),o++}return i}filterLabelsByExtendedRules(t,e){const s=Js(this.extendedLabelsFilterConfig).reduce((i,r)=>{if(!r)return i;const[o,a]=r;if(a){const l=No(o);if(l){const c=Xo(l);i[c]=a}}return i},{});return Js(t).reduce((i,[r,o])=>(s[r]&&s[r](e)||(i[r]=o),i),{})}clearLabelCache(){this.labelCache.clear()}}class ap extends X{constructor(t,e){super(),this.eventBus=t,this.labelProviders=e,this.labels=[],this.initModel(),this.addSubscription(this.eventBus.on(hs,()=>this.recalculateLabels()))}initModel(){this.recalculateLabels()}recalculateLabels(){this.labels=[];for(const t of this.labelProviders)this.labels.push(...t.getUnorderedLabels())}}const ta=3;class lp extends X{constructor(t,e,s,i,r,o,a){super(),this.scale=t,this.canvasInputListener=e,this.canvasBoundsContainer=s,this.chartPanComponent=i,this.chartModel=r,this.hitTest=o,this.hitTestCanvasModel=a,this.lastXStart=0,this.lastXEnd=0,this.lastXWidth=0,this.lastXPxWidth=0,this.onXDragStart=()=>{this.lastXStart=this.scale.xStart,this.lastXEnd=this.scale.xEnd,this.lastXWidth=this.scale.xEnd-this.scale.xStart;const c=this.canvasBoundsContainer.getBounds(M.X_AXIS);this.lastXPxWidth=c.width-this.canvasInputListener.currentPoint.x,this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!1)},this.onXDragTick=c=>{let{delta:h}=c;if(!this.touches||this.touches.length===1){const d=this.lastXPxWidth-h;if(d<0)return;const u=this.lastXPxWidth/d,f=this.lastXWidth*u,g=this.lastXStart+(this.lastXWidth-f);this.scale.setXScale(g,this.scale.xEnd);return}if(this.touches.length>1){h=Math.min(this.touches[0].clientX,this.touches[1].clientX)===this.touches[0].clientX?h:-h;let u;h<0?u=1/(1+-h/this.lastXPxWidth*(ta-1)):u=1+h/this.lastXPxWidth*(ta-1);const g=(this.lastXWidth*u-this.lastXWidth)/2,m=this.lastXStart-g,x=this.lastXEnd+g;(this.lastXStart!==m||this.lastXEnd!==x)&&this.scale.setXScale(m,x)}},this.onXDragEnd=()=>{this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!0)},this.setDblTapCallback=c=>this.dblTapCallback=c,this.setDblClickCallback=c=>this.dblClickCallback=c,this.dblClickCallback=()=>r.doBasicScale(),this.dblTapCallback=()=>r.doBasicScale();const l=new Ye(o,{onDragStart:this.onXDragStart,onDragTick:this.onXDragTick,onDragEnd:this.onXDragEnd},this.canvasInputListener,this.chartPanComponent,{dragPredicate:()=>i.chartAreaPanHandler.chartPanningOptions.horizontal});this.addChildEntity(l)}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasInputListener.observeDbClick(this.hitTest).subscribe(()=>this.dblClickCallback())),this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(()=>{var t;if(this.touches&&((t=this.touches)==null?void 0:t.length)>1){this.touches=void 0;return}this.dblTapCallback()})),this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(t=>{this.touches=t.touches})),this.addRxSubscription(this.chartModel.candlesPrependSubject.subscribe(({prependedCandlesWidth:t})=>this.lastXStart+=t))}}class cp extends X{constructor(t,e,s,i,r,o,a,l,c,h,d,u,f){super(),this.eventBus=t,this.config=e,this.canvasModel=s,this.chartComponent=i,this.scale=r,this.chartResizeHandler=l,this.timeZoneModel=h,this.setDblClickCallback=x=>this.xAxisScaleHandler.setDblClickCallback(x),this.setDblTapCallback=x=>this.xAxisScaleHandler.setDblTapCallback(x);const g=new Qo(t,e,i.chartModel,r,h,this.canvasModel,o);this.xAxisLabelsGenerator=g,this.xAxisLabelsModel=new ap(t,[]);const m=new on;c.addDrawer(m,"X_AXIS"),this.xAxisDrawer=new Cs(e,s,r,o,()=>this.xAxisLabelsGenerator.labels,()=>e.components.xAxis.visible),m.addDrawer(this.xAxisDrawer),this.xAxisLabelsDrawer=new xg(e,s,o,this.xAxisLabelsModel),m.addDrawer(this.xAxisLabelsDrawer),this.xAxisScaleHandler=new lp(r,a,o,d,this.chartComponent.chartModel,o.getBoundsHitTest(M.X_AXIS),f),this.addChildEntity(this.xAxisScaleHandler),u.setCursorForCanvasEl(M.X_AXIS,e.components.xAxis.cursor)}doActivate(){super.doActivate(),this.addRxSubscription(yt(this.chartComponent.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>{this.xAxisLabelsGenerator.generateLabels()})),this.addRxSubscription(this.chartComponent.chartModel.candlesPrependSubject.pipe(Z(({prependedCandles:t})=>t.length!==0),dt(({prependedCandles:t})=>this.chartComponent.chartModel.mainCandleSeries.visualPoints.slice(0,t.length))).subscribe(t=>{var e,s;Ql.includes(this.config.components.chart.type)&&((s=(e=this.xAxisLabelsGenerator).updateHistoryLabels)==null||s.call(e,t))})),this.config.components.chart.minCandlesOffset?this.addRxSubscription(yt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Lt(50,Rt,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.recalculateLabels())):this.addRxSubscription(yt(this.scale.xChanged,this.chartResizeHandler.canvasResized).pipe(Lt(150,Rt,{trailing:!0,leading:!0})).subscribe(()=>this.xAxisLabelsGenerator.generateLabels(void 0,!0))),this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.pipe(dt(()=>St(this.chartComponent.chartModel.mainCandleSeries.visualPoints)),Tt((t,e)=>{var s,i;return((s=t==null?void 0:t.candle)==null?void 0:s.id)===((i=e==null?void 0:e.candle)==null?void 0:i.id)}),Z(li)).subscribe(t=>{var e,s;return(s=(e=this.xAxisLabelsGenerator)==null?void 0:e.updateLastLabel)==null?void 0:s.call(e,t)}))}getDrawer(){return this.xAxisDrawer}registerXAxisLabelsProvider(t){this.xAxisLabelsModel.labelProviders.push(t)}setVisible(t){var e;(e=this.config.components)!=null&&e.xAxis&&(this.config.components.xAxis.visible=t,this.eventBus.fireDraw())}setFormatsForLabelsConfig(t){this.xAxisLabelsGenerator instanceof Qo?this.xAxisLabelsGenerator.setFormatsForLabelsConfig(t):console.error("Format config for x-axis is not available")}isVisible(){var t,e;return(e=(t=this.config.components)==null?void 0:t.xAxis.visible)!=null?e:!1}}var hp=Object.defineProperty,ea=Object.getOwnPropertySymbols,dp=Object.prototype.hasOwnProperty,up=Object.prototype.propertyIsEnumerable,sa=(n,t,e)=>t in n?hp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,ys=(n,t)=>{for(var e in t||(t={}))dp.call(t,e)&&sa(n,e,t[e]);if(ea)for(var e of ea(t))up.call(t,e)&&sa(n,e,t[e]);return n};class fp{constructor(t,e,s,i,r){this.chartModel=t,this.chartConfig=e,this.yAxisConfig=s,this.lastCandleLabelsByChartType=i,this.resolveLabelColorFn=r}getUnorderedLabels(){const t=[];if(!(this.yAxisConfig.labels.settings.lastPrice.mode!=="none"&&this.yAxisConfig.visible))return t;const s=this.getYAxisVisualLabel(this.chartModel.mainCandleSeries),i=s&&ys(ys({},s),this.getLabelDrawConfig(this.chartModel.mainCandleSeries,!0));if(i){const r={labels:[i]},o=this.lastCandleLabelsByChartType[this.chartConfig.components.chart.type];o==null||o(r,this.chartModel.mainCandleSeries),t.push(r)}return this.chartModel.candleSeries.forEach((r,o)=>{if(o===0)return;const a=this.getYAxisVisualLabel(r),l=a&&ys(ys({},a),this.getLabelDrawConfig(r,!1));if(l){const c={labels:[l]},h=this.lastCandleLabelsByChartType[r.config.type];h==null||h(c,this.chartModel.mainCandleSeries),t.push(c)}}),t}getYAxisVisualLabel(t){const e=St(t.dataPoints);if(e){const s=t.view.toY(e.close);if(isFinite(s)){const i=this.yAxisConfig.labels.settings.lastPrice.mode,r=this.yAxisConfig.labels.settings.lastPrice.type;return{y:s,labelWeight:0,labelText:this.chartModel.pane.valueFormatter(e.close,t),mode:i,labelType:r,description:t.instrument.symbol}}}return null}getLabelDrawConfig(t,e){const s=this.yAxisConfig.labels.settings.lastPrice.type,i=t.colors.labels,{rectLabelTextColor:r="white",rectLabelInvertedTextColor:o="black"}=this.chartConfig.colors.yAxis,a=this.resolveLabelColorFn(t.config.type);if(!i)return{bgColor:"#FFFFFF",textColor:se("#FFFFFF","#000000",o),rounded:!0};const l=a(t.lastPriceMovement,t.colors);if(e){const h=t.config.type==="scatterPlot"?r:Bf(t.lastPriceMovement,i);return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):se(l,h,o),rounded:!0}}return{bgColor:l,textColor:s==="plain"?a(t.lastPriceMovement,t.colors):se(l,r,o),rounded:!0}}}class gp{constructor(t,e,s,i,r,o){this.yAxisLabelsCanvasModel=t,this.yAxisDescriptionsCanvasModel=e,this.backgroundCanvasModel=s,this.canvasBoundsContainer=i,this.fullConfig=r,this.paneManager=o}draw(){const t=this.yAxisLabelsCanvasModel.ctx,e=this.backgroundCanvasModel.ctx,s=this.yAxisDescriptionsCanvasModel.ctx;this.paneManager.yExtents.forEach(i=>{if(i.yAxis.state.visible){const r=i.getYAxisBounds(),o=this.canvasBoundsContainer.getBounds(M.ALL_PANES),a=i.yAxis.model.fancyLabelsModel.orderedLabels;this.drawHighlightedBackgroundBetweenLabels(a),a.forEach(l=>{var c;const h=(c=l.bounds)!=null?c:r;l.labels.forEach(d=>io(t,s,e,h,o,d,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}),Object.values(i.yAxis.model.fancyLabelsModel.customLabels).forEach(l=>io(t,s,e,r,o,l,this.canvasBoundsContainer,i.yAxis.state,this.fullConfig.colors))}})}drawHighlightedBackgroundBetweenLabels(t){const e=this.yAxisLabelsCanvasModel.ctx,s={};t.forEach(i=>{i.labels.forEach(r=>{var o,a,l;if(r.subGroupId){const c=(o=s[r.subGroupId])!=null?o:[];if(s[r.subGroupId]=c,c.push(r),c.length===2){const h=(a=i.bounds)!=null?a:this.canvasBoundsContainer.getBounds(M.PANE_UUID_Y_AXIS(K));e.save(),e.fillStyle=(l=c[0].highlightColor)!=null?l:c[0].bgColor;const[d,u]=c[0].y>c[1].y?[c[1].y,c[0].y]:[c[0].y,c[1].y];Er(e,{x:h.x,y:ji(d,h)},{x:h.x+h.width-6,y:ji(u,h)}),e.restore()}}})})}getCanvasIds(){return[this.yAxisLabelsCanvasModel.canvasId]}}class pp{constructor(t,e,s){this.fullConfig=t,this.canvasModel=e,this.paneManager=s}draw(){this.paneManager.yExtents.forEach(t=>{const e=t.yAxis;if(e.state.visible){const s=e.model.baseLabelsModel.labels,i=e.getBounds(),r=this.canvasModel.ctx;this.fullConfig.components.chart.applyBackgroundToAxes.y||(r.fillStyle=this.getBackgroundColor(),r.fillRect(i.x,i.y,i.width,i.height));const o=ne(e.state),a=Xt(o,r),l=this.getLabelTextColor();r.save(),Kt(r,i),this.drawLabels(r,s,i,a,o,l,e),r.restore()}})}drawLabels(t,e,s,i,r,o,a){t.fillStyle=o,t.font=r;const l=t.measureText("00.0"),c=l.actualBoundingBoxAscent+l.actualBoundingBoxDescent,h=s.y+c,d=s.y+s.height-c;e.forEach(u=>{const f=a.scale.toY(u.value);f>h&&f<d&&mp(t,s,u.text,f,i,r,a.state.labelBoxMargin.end,a.state.align)})}getCanvasIds(){return[this.canvasModel.canvasId]}getBackgroundColor(){return this.fullConfig.colors.yAxis.backgroundColor}getLabelTextColor(){return this.fullConfig.colors.yAxis.labelTextColor}}const mp=(n,t,e,s,i,r,o,a)=>{const l=a==="right"?t.x+t.width-Mt(e,n,r)-o:t.x+o;n.fillText(e,l,s+i/2-1)};class vp{constructor(){this.UNKNOWN_ARR=[],this.handlers={},this.muted=!1,this.unsub=(t,e)=>{const s=this.handlers[t];s!==void 0&&Rl.call(s,e)},this.add=(t,e,s)=>(e in this.handlers?t.call(this.handlers[e],s):this.handlers[e]=[s],this.unsub.bind(this,e,s)),this.on=(t,e)=>this.add(this.UNKNOWN_ARR.push,t,e),this.observe=t=>{const e=new F,s=e.next.bind(e),i=e.unsubscribe.bind(e);return this.on(t,s),e.unsubscribe=()=>{this.unsub(t,s),i()},e.asObservable()},this.onPrior=(t,e)=>this.add(this.UNKNOWN_ARR.unshift,t,e),this.off=this.unsub,this.fire=(t,...e)=>{var s;if(!this.muted){const i=(s=this.handlers[t])!=null?s:[];let r;for(r=0,i.length;r<i.length;r++)i[r].apply(null,e)}},this.fireAsync=(t,e)=>{if(!this.muted)return window.setTimeout(this.fire.bind(this,t,e),0)},this.setMuted=t=>{this.muted=t},this.clear=()=>{this.handlers={}}}fireDraw(t){this.fire(hs,t)}}class bp extends X{constructor(t,e,s,i){super(),s.observeTouchStart().pipe(dt(r=>i.components.chart.highlightActiveCandle?r:void 0),Tt()).subscribe(r=>{r&&this.setCandleAsActive(r,t,e)})}setCandleAsActive(t,e,s){if(t.touches.length===1){const i=t.touches.item(0);if(i!==null){const r=this.getTouchXPosition(i,e),o=s.candleFromX(r);o&&s.mainCandleSeries.setActiveCandle(o)}}}getTouchXPosition(t,e){const s=e.getBoundingClientRect(),i=document.body.scrollLeft||document.documentElement.scrollLeft;return t.pageX-s.left-i}}class Cp{constructor(t,e,s,i,r){this.frameElement=t,this.resizerElement=e,this.bus=s,this.canvasModels=i,this.config=r,this.previousBCR=void 0,this.animFrameId=`resize_${wt()}`,this.canvasResized=new F,this.recentlyResized=!1,this.elementResizeDetector=new ResizeObserver(()=>this.handleResize())}subscribeResize(){this.elementResizeDetector.observe(this.resizerElement)}handleResize(){Pe(this.animFrameId,()=>this.fireUpdates())}fireUpdates(){const t=this.resizerElement.getBoundingClientRect(),e={x:t.x,y:t.y,width:t.width,height:t.height};this.config||(this.frameElement.style.height=this.resizerElement.clientHeight+"px"),(this.previousBCR===void 0||this.isBCRDimensionsDiffer(this.previousBCR,e))&&(this.previousBCR=e,this.recentlyResized=!0,this.canvasModels.forEach(s=>this.previousBCR&&s.updateDPR(this.previousBCR)),this.canvasResized.next(e),this.bus.fire(cs,e),this.bus.fire(hs))}clearResizedFlag(){this.recentlyResized=!1}isBCRDimensionsDiffer(t,e){return t.height!==e.height||t.width!==e.width}unsubscribeAnimationUpdate(){if(this.resizerElement)try{this.elementResizeDetector.unobserve(this.resizerElement)}catch(t){console.warn("ChartResizeHandler.ts, unsubscribeAnimationUpdate failed")}}wasResized(){return this.recentlyResized}}var yp=Array.isArray,wp=Object.getPrototypeOf,Sp=Object.prototype,xp=Object.keys;function _p(n){if(n.length===1){var t=n[0];if(yp(t))return{args:t,keys:null};if(Pp(t)){var e=xp(t);return{args:e.map(function(s){return t[s]}),keys:e}}}return{args:n,keys:null}}function Pp(n){return n&&typeof n=="object"&&wp(n)===Sp}var Tp=Array.isArray;function Mp(n,t){return Tp(t)?n.apply(void 0,ot([],R(t))):n(t)}function na(n){return dt(function(t){return Mp(n,t)})}function Ap(n,t){return n.reduce(function(e,s,i){return e[s]=t[i],e},{})}function Ep(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=Ue(n),s=tl(n),i=_p(n),r=i.args,o=i.keys;if(r.length===0)return Ge([],e);var a=new pt(Ip(r,e,o?function(l){return Ap(o,l)}:ue));return s?a.pipe(na(s)):a}function Ip(n,t,e){return e===void 0&&(e=ue),function(s){ia(t,function(){for(var i=n.length,r=new Array(i),o=i,a=i,l=function(h){ia(t,function(){var d=Ge(n[h],t),u=!1;d.subscribe(Ct(s,function(f){r[h]=f,u||(u=!0,a--),a||s.next(e(r.slice()))},function(){--o||s.complete()}))},s)},c=0;c<i;c++)l(c)},s)}}function ia(n,t,e){n?jt(e,n,t):t()}class Dp extends X{constructor(t,e){super(),this.canvasInputListener=t,this.canvasBoundsContainer=e,this.panesSubscriptions={},this.crossSubject=new ft(null),this.crossToolHover=null,this.crossToolTouchInfo={fixed:{x:0,y:0},temp:{x:0,y:0},isSet:!1,isCommonTap:!1}}doActivate(){super.doActivate()}fireCrossClose(){this.crossSubject.next(null)}unsubscribeMouseOver(t){var e;(e=this.panesSubscriptions[t])==null||e.unsubscribe()}subscribeMouseOver(t,e,s){const i=e.map(o=>this.canvasBoundsContainer.getBoundsHitTest(o,s)),r=(o,a)=>i.some(l=>l(o,a));return this.subscribeMouseOverHT(t,r)}subscribeMouseOverHT(t,e){const s=this.canvasInputListener.observeMouseMoveDocument(),i=this.canvasInputListener.observeMouseEnter(e);let r=!1;const o=Ep([s,i]).pipe(Z(([,a])=>!r||r&&a)).subscribe(([a,l])=>{if(l){const c=[a.x,a.y,t];this.crossSubject.next(c),r=!1}!l&&!Nt()&&(this.crossSubject.next(null),r=!0)});return this.panesSubscriptions[t]=o,()=>o.unsubscribe()}}function Lp(n,t){return N(function(e,s){var i=null,r=0,o=!1,a=function(){return o&&!i&&s.complete()};e.subscribe(Ct(s,function(l){i==null||i.unsubscribe();var c=0,h=r++;Dt(n(l,h)).subscribe(i=Ct(s,function(d){return s.next(t?t(l,d,h,c++):d)},function(){i=null,a()}))},function(){o=!0,a()}))})}class Op{constructor(t,e,s,i){this.visualCandle=t,this.price=e,this.priceFormatter=s,this.toY=i}get high(){return this.visualCandle.high}get low(){return this.visualCandle.low}get open(){return this.visualCandle.open}get close(){return this.visualCandle.close}get volume(){return this.visualCandle.candle.volume}get openY(){return this.toY(this.open)}get closeY(){return this.toY(this.close)}get highY(){return this.toY(this.high)}get lowY(){return this.toY(this.low)}get openFormatted(){return this.priceFormatter(this.open)}get closeFormatted(){return this.priceFormatter(this.close)}get highFormatted(){return this.priceFormatter(this.high)}get lowFormatted(){return this.priceFormatter(this.low)}get closestOHLCY(){return this.toY([this.close,this.open,this.high,this.low].sort((t,e)=>Math.abs(t-this.price)-Math.abs(e-this.price))[0])}}class Bp{constructor(t){this.chartModel=t}getData(t){const{x:e,y:s}=t,r=this.chartModel.candleFromX(e).idx||0,o=this.chartModel.getVisualCandle(r),a=this.chartModel.priceFromY(s);return o&&new Op(o,a,this.chartModel.pane.regularFormatter,this.chartModel.toY)}}class Rp{constructor(t){this.chartModel=t}getData(t){if(this.chartModel.candleSeries.length===1&&this.chartModel.candleSeries[0]instanceof Vr)return;const{x:e}=t,i=this.chartModel.candleFromX(e).idx||0;return this.chartModel.candleSeries.map(o=>{const a=o.dataPoints[i],l=this.chartModel.pane.regularFormatter(a==null?void 0:a.close);return{instrument:o.instrument.symbol,price:l,id:o.id,htId:o.htId}})}}var Fp=Object.defineProperty,Hp=Object.defineProperties,kp=Object.getOwnPropertyDescriptors,ra=Object.getOwnPropertySymbols,jp=Object.prototype.hasOwnProperty,Yp=Object.prototype.propertyIsEnumerable,oa=(n,t,e)=>t in n?Fp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,Ne=(n,t)=>{for(var e in t||(t={}))jp.call(t,e)&&oa(n,e,t[e]);if(ra)for(var e of ra(t))Yp.call(t,e)&&oa(n,e,t[e]);return n},yn=(n,t)=>Hp(n,kp(t));class Np extends X{constructor(t,e,s,i,r,o,a,l,c,h){super(),this.crossEventProducer=t,this.scale=e,this.config=s,this.chartModel=i,this.canvasInputListener=r,this.canvasBoundsContainer=o,this.paneManager=a,this.timeZoneModel=l,this.mainCanvasTouchHandler=c,this.formatterFactory=h,this.hoverSubject=new ft(null),this.longTouchActivatedSubject=new ft(!1),this.longTouchCrosshairSuppressed=!1,this.xFormatter=()=>"";const d=new Bp(this.chartModel),u=new Rp(this.chartModel);this.hoverProducerParts={candleHover:d,compareSeriesHover:u}}get hover(){return this.hoverSubject.getValue()}doActivate(){super.doActivate(),this.addRxSubscription(this.chartModel.candlesSetSubject.pipe(Lp(()=>this.scale.initialViewportValidSubject.pipe(Z(Boolean)))).subscribe(()=>{const e=this.chartModel.getLastVisualCandle();e&&this.createAndFireHoverFromCandle(e)})),this.addRxSubscription(this.chartModel.candlesUpdatedSubject.subscribe(()=>{const e=this.chartModel.getLastVisualCandle();this.hover!==null&&e!==void 0&&e.candle.timestamp<=this.hover.timestamp&&this.updateHover(e)})),this.addRxSubscription(this.crossEventProducer.crossSubject.subscribe(e=>{e===null?this.hoverSubject.next(null):this.createAndFireHover(e)})),this.addRxSubscription(this.scale.xChanged.subscribe(()=>this.fireLastCross())),this.addRxSubscription(yt(this.chartModel.candlesSetSubject,this.timeZoneModel.observeTimeZoneChanged()).subscribe(()=>this.recalculateCrossToolXFormatter())),this.addRxSubscription(this.canvasInputListener.observeTouchStart().subscribe(e=>{var s;this.crossEventProducer.crossToolTouchInfo.isCommonTap=!0;const{clientX:i,clientY:r}=e.touches[0];if(this.longTouchActivatedSubject.getValue())this.crossEventProducer.crossToolTouchInfo.temp={x:i-this.canvasBoundsContainer.canvasOnPageLocation.x,y:r-this.canvasBoundsContainer.canvasOnPageLocation.y};else{const o=((s=this.paneManager.getPaneIfHit({x:i,y:r}))==null?void 0:s.uuid)||"";this.createAndFireHover([i,r,o])}}));const t=this.canvasBoundsContainer.getBoundsHitTest(M.ALL_PANES);this.addRxSubscription(this.canvasInputListener.observeLongTouchStart(t).subscribe(e=>{var s;if(this.longTouchCrosshairSuppressed||(this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isCommonTap=!1,this.mainCanvasTouchHandler.canvasTouchInfo.isMoving||this.chartModel.config.components.crossTool.type==="none"||e.touches.length>1))return;this.longTouchActivatedSubject.next(!0),this.crossEventProducer.crossToolTouchInfo.isSet=!1;const r=e.touches[0].clientX-this.canvasBoundsContainer.canvasOnPageLocation.x,o=e.touches[0].clientY-this.canvasBoundsContainer.canvasOnPageLocation.y;this.crossEventProducer.crossToolTouchInfo.fixed={x:r,y:o};const a=((s=this.paneManager.getPaneIfHit({x:r,y:o}))==null?void 0:s.uuid)||"";this.createAndFireHover([r,o,a]),this.crossEventProducer.crossSubject.next([r,o,a]),this.paneManager.chartPanComponent.setChartPanningOptions(!1,!1)})),this.addRxSubscription(this.canvasInputListener.observeTouchEndDocument().subscribe(e=>{var s,i;const{clientX:r,clientY:o}=e.changedTouches[0],{fixed:a,temp:l}=this.crossEventProducer.crossToolTouchInfo,c=r-this.canvasBoundsContainer.canvasOnPageLocation.x,h=o-this.canvasBoundsContainer.canvasOnPageLocation.y;if(this.crossEventProducer.crossToolTouchInfo.isCommonTap&&!wo(c,l.x,h,l.y)){this.paneManager.chartPanComponent.setChartPanningOptions(!0,!0),this.longTouchActivatedSubject.next(!1),this.crossEventProducer.fireCrossClose(),this.crossEventProducer.crossToolHover=null,this.crossEventProducer.crossToolTouchInfo.isSet=!1;return}if(!this.crossEventProducer.crossToolTouchInfo.isSet)this.crossEventProducer.crossToolTouchInfo.isSet=!0,this.crossEventProducer.crossToolTouchInfo.temp={x:this.crossEventProducer.crossToolTouchInfo.fixed.x,y:this.crossEventProducer.crossToolTouchInfo.fixed.y},this.crossEventProducer.crossToolTouchInfo.fixed={x:c,y:h},this.crossEventProducer.crossToolTouchInfo.isSet=!0;else{const d=(i=(s=this.crossEventProducer.crossToolHover)==null?void 0:s.paneId)!=null?i:"CHART",u=this.canvasBoundsContainer.getBounds(M.PANE_UUID(d)),f=u.y+5,g=u.y+u.height-5,m=c-l.x,x=h-l.y,_=a.x<0?0:a.x>u.width?u.width:a.x+=m,A=a.y<f?f:a.y>g?g:a.y+=x;this.crossEventProducer.crossToolTouchInfo.fixed={x:_,y:A}}}))}recalculateCrossToolXFormatter(){const t=this.config.components.crossTool.xAxisLabelFormat;this.xFormatter=oo(t,this.chartModel.getPeriod(),this.formatterFactory)}createHoverFromCandle(t){const e=t.xCenter(this.scale),s=this.scale.toY(t.close);return this.createHover(e,s,K)}createHover(t,e,s){if(this.chartModel.getCandles().length===0)return;const r=this.chartModel.candleFromX(t,!0).timestamp,o={x:t,y:e,timestamp:r,timeFormatted:this.xFormatter(r),paneId:s},a=Object.entries(this.hoverProducerParts).reduce((l,c)=>yn(Ne({},l),{[c[0]]:c[1].getData(o)}),{});return Ne(Ne({},o),a)}createAndFireHoverFromCandle(t){const e=this.createHoverFromCandle(t);this.fireHover(e)}updateHover(t){const e=this.createHoverFromCandle(t);if(this.hover&&e){const s=yn(Ne({},e),{x:this.hover.x,y:this.hover.y});this.fireHover(s)}}createAndFireHover([t,e,s]){const i=this.createHover(t,e,s);this.fireHover(i)}fireHover(t){var e,s;if(t){if(Nt()&&this.config.components.crossTool.type!=="none"){const i=this.crossEventProducer.crossToolHover,r=i?(e=i.candleHover)==null?void 0:e.visualCandle.candle:(s=t.candleHover)==null?void 0:s.visualCandle.candle;r&&this.chartModel.mainCandleSeries.setActiveCandle(r)}this.hoverSubject.next(t)}else this.crossEventProducer.fireCrossClose()}fireLastCross(){const t=this.crossEventProducer.crossSubject.getValue();t&&this.createAndFireHover(t)}setLongTouchCrosshairSuppressed(t){this.longTouchCrosshairSuppressed=t}registerHoverProducerPart(t,e){this.hoverProducerParts=yn(Ne({},this.hoverProducerParts),{[t]:e})}unregisterHoverProducerPart(t){delete this.hoverProducerParts[t]}}const aa={left:0,middle:1,right:2};function bt(n,t,e,s){return n.addEventListener(e,t,s),function(){n.removeEventListener(e,t,s)}}function Se(n){return t=>{t.button===aa.left&&n(t)}}var Xp=["addListener","removeListener"],Wp=["addEventListener","removeEventListener"],zp=["on","off"];function wn(n,t,e,s){if(k(e)&&(s=e,e=void 0),s)return wn(n,t,e).pipe(na(s));var i=R(Gp(n)?Wp.map(function(a){return function(l){return n[a](t,l,e)}}):Vp(n)?Xp.map(la(n,t)):Up(n)?zp.map(la(n,t)):[],2),r=i[0],o=i[1];if(!r&&Ls(n))return Bs(function(a){return wn(a,t,e)})(Dt(n));if(!r)throw new TypeError("Invalid event target");return new pt(function(a){var l=function(){for(var c=[],h=0;h<arguments.length;h++)c[h]=arguments[h];return a.next(1<c.length?c:c[0])};return r(l),function(){return o(l)}})}function la(n,t){return function(e){return function(s){return n[e](t,s)}}}function Vp(n){return k(n.addListener)&&k(n.removeListener)}function Up(n){return k(n.on)&&k(n.off)}function Gp(n){return k(n.addEventListener)&&k(n.removeEventListener)}var Zp=Object.defineProperty,ca=Object.getOwnPropertySymbols,$p=Object.prototype.hasOwnProperty,Kp=Object.prototype.propertyIsEnumerable,ha=(n,t,e)=>t in n?Zp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,qp=(n,t)=>{for(var e in t||(t={}))$p.call(t,e)&&ha(n,e,t[e]);if(ca)for(var e of ca(t))Kp.call(t,e)&&ha(n,e,t[e]);return n};const ws=class he extends X{constructor(t,e){super(),this.eventBus=t,this.element=e,this.xDragStartSubject=new F,this.xDragSubject=new F,this.xDragTickSubject=new F,this.xDragEndSubject=new F,this.yDragStartSubject=new F,this.yDragSubject=new F,this.yDragTickSubject=new F,this.yDragEndSubject=new F,this.mouseMoveSubject=new F,this.mouseMoveDocumentSubject=new F,this.clickSubject=new F,this.clickDocumentSubject=new F,this.dbClickSubject=new F,this.dbTapSubject=new F,this.mouseDownSubject=new F,this.mouseUpSubject=new F,this.mouseUpDocumentSubject=new F,this.wheelSubject=new F,this.touchStartSubject=new F,this.touchStartTimestamp=0,this.touchMoveSubject=new F,this.touchEndSubject=new F,this.touchCancelSubject=new F,this.longTouchStartSubject=new F,this.longTouchEndSubject=new F,this.contextMenuSubject=new F,this.fastTouchScroll=new F,this.mouseLeavesCanvasSubject=new F,this.dragStartPoint={x:0,y:0},this.prevDragPoint={x:0,y:0},this.currentPoint={x:0,y:0},this.currentPointDocument={x:0,y:0},this.dragging=!1,this.canvasBounds={x:0,y:0,pageX:0,pageY:0,width:0,height:0},this.cachedElementRect=null,this.rectCacheValid=!1,this.documentDragListeners=[],this.dragProcessListener=()=>{this.xDragSubject.next(this.currentPoint.x-this.dragStartPoint.x),this.yDragSubject.next(this.currentPoint.y-this.dragStartPoint.y),this.xDragTickSubject.next(this.currentPoint.x-this.prevDragPoint.x),this.yDragTickSubject.next(this.currentPoint.y-this.prevDragPoint.y),this.prevDragPoint.x=this.currentPoint.x,this.prevDragPoint.y=this.currentPoint.y},this.dragStartListener=s=>{this.isDraggable(s)&&(this.updateCurrentPoints(s),this.dragging=!0,this.dragStartEvent=s,this.cleanupDocumentDragListeners(),this.dragStartPoint=he.copyPoint(this.currentPoint),this.xDragStartSubject.next(this.dragStartPoint),this.yDragStartSubject.next(this.dragStartPoint),this.prevDragPoint=qp({},this.dragStartPoint),he.DRAG_EVENTS.forEach(i=>{document.addEventListener(i,this.dragProcessListener,!0);const r=document.removeEventListener.bind(document,i,this.dragProcessListener,!0);this.documentDragListeners.push(r),this.addSubscription(r)}),this.dragProcessListener())},this.dragListener=()=>this.mouseMoveDocumentSubject.next(this.currentPoint),this.updateElementOffsetListener=()=>this.mouseMoveSubject.next(this.currentPoint),this.dragEndListener=()=>{this.dragging=!1,this.cleanupDocumentDragListeners(),this.xDragEndSubject.next(),this.yDragEndSubject.next()},this.updateCurrentPoints=s=>{this.updateCurrentDocumentPoint(s),this.updateCurrentMousePoint(s)}}getElementRect(){if(this.rectCacheValid&&this.cachedElementRect)return this.cachedElementRect;try{if(!this.element||!this.element.isConnected)return this.createFallbackRect();const t=this.element.getBoundingClientRect();return this.cachedElementRect=t,this.rectCacheValid=!0,t}catch(t){return this.createFallbackRect()}}createFallbackRect(){return typeof DOMRect!="undefined"?new DOMRect(0,0,0,0):{x:0,y:0,width:0,height:0,top:0,right:0,bottom:0,left:0,toJSON:()=>({})}}invalidateRectCache(){this.rectCacheValid=!1}initializeRectCache(){this.invalidateRectCache();const t=this.getElementRect();this.canvasBounds.x=t.left,this.canvasBounds.y=t.top,this.canvasBounds.width=t.width,this.canvasBounds.height=t.height}cleanupDocumentDragListeners(){if(!this.documentDragListeners||!Array.isArray(this.documentDragListeners)){this.documentDragListeners=[];return}this.documentDragListeners.forEach(t=>{try{t()}catch(e){console.warn("Error cleaning up drag listener:",e)}}),this.documentDragListeners=[]}doDeactivate(){this.invalidateRectCache(),this.cachedElementRect=null,this.cleanupDocumentDragListeners(),super.doDeactivate()}isDraggable(t){return t instanceof MouseEvent?t.button===aa.left:t instanceof TouchEvent}startDragging(t){this.updateCurrentPoints(t),this.dragStartListener(t)}movePointer(t){this.updateCurrentPoints(t),this.dragListener(),this.updateElementOffsetListener(),this.dragging&&this.dragProcessListener()}stopDragging(){this.dragEndListener()}fixTextSelection(){const t=e=>(e.preventDefault(),!1);this.element.addEventListener("selectstart",t,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"selectstart",t,!1))}doActivate(){this.fixTextSelection(),this.documentDragListeners=[],he.DRAG_START_EVENTS.forEach(s=>{this.element.addEventListener(s,this.dragStartListener),this.addSubscription(()=>this.element.removeEventListener(s,this.dragStartListener))}),this.trackMousePosition(),he.DRAG_EVENTS.forEach(s=>{document.addEventListener(s,this.dragListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragListener)),this.element.addEventListener(s,this.updateElementOffsetListener),this.addSubscription(this.element.removeEventListener.bind(this.element,s,this.updateElementOffsetListener))}),he.DRAG_END_EVENTS.forEach(s=>{document.addEventListener(s,this.dragEndListener),this.addSubscription(document.removeEventListener.bind(document,s,this.dragEndListener))}),this.addSubscription(bt(this.element,Se(()=>this.clickSubject.next(this.currentPoint)),"click")),this.addSubscription(bt(document,Se(s=>this.clickDocumentSubject.next(s)),"click"));const t=ms();if(t==="apple"||t==="mobile"){let s=null;const i=a=>{a.preventDefault(),s?(this.dbTapSubject.next(this.currentPoint),clearTimeout(s),s=null):s=window.setTimeout(()=>{s=null},250)};this.addSubscription(bt(this.element,i,"touchend"));const r=(a,l=200)=>{a.preventDefault();let c=!1,h=null;h=setTimeout(()=>{c=!0,this.longTouchStartSubject.next(a)},l);const d=f=>{f.preventDefault(),f.touches.length>1&&h&&clearTimeout(h)},u=f=>{f.preventDefault(),h&&clearTimeout(h),c&&(c=!1,this.longTouchEndSubject.next(f)),this.element.removeEventListener("touchend",u),this.element.removeEventListener("touchmove",d)};this.element.addEventListener("touchmove",d),this.element.addEventListener("touchend",u)};this.addSubscription(bt(this.element,a=>r(a),"touchstart"));const o=a=>{if(a.preventDefault(),this.prevDragPoint.x>this.dragStartPoint.x){const h=this.touchStartTimestamp,u=Date.now()-h,g=(this.prevDragPoint.x-this.dragStartPoint.x)/this.canvasBounds.width*100>35,m=u<=250;g&&m&&this.fastTouchScroll.next(a)}};this.addSubscription(bt(this.element,o,"touchend"))}this.addSubscription(bt(this.element,Se(()=>this.dbClickSubject.next(this.currentPoint)),"dblclick")),this.addSubscription(bt(this.element,s=>{this.touchStartSubject.next(s),this.touchStartTimestamp=Date.now()},"touchstart")),this.addSubscription(bt(this.element,s=>this.touchMoveSubject.next(s),"touchmove",!0)),this.addSubscription(bt(this.element,s=>this.touchEndSubject.next(s),"touchend")),this.addSubscription(bt(this.element,s=>this.touchCancelSubject.next(s),"touchcancel")),this.addSubscription(bt(this.element,s=>{this.updateCurrentPoints(s),this.wheelSubject.next(s),s.preventDefault()},"wheel")),this.addSubscription(bt(this.element,s=>this.contextMenuSubject.next(s),"contextmenu")),this.addSubscription(bt(this.element,Se(()=>this.mouseDownSubject.next(this.currentPoint)),"mousedown")),this.addSubscription(bt(this.element,Se(()=>this.mouseUpSubject.next(this.currentPoint)),"mouseup")),this.addSubscription(bt(document,Se(()=>this.mouseUpDocumentSubject.next(this.currentPoint)),"mouseup")),this.addRxSubscription(this.eventBus.observe(cs).subscribe(()=>{this.invalidateRectCache();const s=this.getElementRect();this.canvasBounds.x=s.left,this.canvasBounds.y=s.top,this.canvasBounds.width=s.width,this.canvasBounds.height=s.height})),this.addRxSubscription(wn(document,"scroll",{capture:!0,passive:!0}).pipe(Lt(Zt,is,{trailing:!0})).subscribe(()=>this.invalidateRectCache()));const e=()=>{this.mouseLeavesCanvasSubject.next(!0)};this.element.addEventListener("mouseleave",e,!1),this.addSubscription(this.element.removeEventListener.bind(this.element,"mouseleave",e,!1))}getCurrentMousePoint(){return this.currentPoint}trackMousePosition(){he.DRAG_EVENTS.forEach(t=>{document.addEventListener(t,this.updateCurrentPoints,!0),this.addSubscription(()=>document.removeEventListener(t,this.updateCurrentPoints,!0))})}updateCurrentDocumentPoint(t){"pageX"in t?this.currentPointDocument.x=t.pageX:t.touches!==void 0&&(this.currentPointDocument.x=t.touches[0].pageX),"pageY"in t?this.currentPointDocument.y=t.pageY:t.touches!==void 0&&(this.currentPointDocument.y=t.touches[0].pageY)}updateCurrentMousePoint(t){const e=this.getElementRect();"clientX"in t?this.currentPoint.x=t.clientX-e.left:t.touches!==void 0&&(this.currentPoint.x=t.touches[0].clientX-e.left),"clientY"in t?this.currentPoint.y=t.clientY-e.top:t.touches!==void 0&&(this.currentPoint.y=t.touches[0].clientY-e.top)}static copyPoint(t){return{x:t.x,y:t.y}}observeMouseMove(t=()=>!0){return this.mouseMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveNoDrag(){return this.mouseMoveSubject.asObservable().pipe(Z(()=>!this.dragging))}observeMouseMoveDocument(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseMoveDocumentAnyElement(t=()=>!0){return this.mouseMoveDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPointDocument.x,this.currentPointDocument.y)),dt(()=>this.currentPointDocument))}observeClickOnDocument(){return this.clickDocumentSubject.asObservable()}observeXDragStart(t=()=>!0){return this.xDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDrag(t=()=>!0){return this.xDragSubject.pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragEnd(t=()=>!0){return this.xDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeXDragTick(){return this.xDragTickSubject.asObservable()}observeYDragStart(t=()=>!0){return this.yDragStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDrag(t=()=>!0){return this.yDragSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragEnd(t=()=>!0){return this.yDragEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeYDragTick(){return this.yDragTickSubject.asObservable()}observeMouseEnter(t=()=>!0,e=!1){const s=this.mouseMoveSubject.asObservable().pipe(Z(()=>!(e&&this.dragging)),dt(()=>t(this.currentPoint.x,this.currentPoint.y))),i=this.observeMouseLeavesCanvas().pipe(dt(()=>!1));return yt(s,i).pipe(Tt())}observeMouseLeavesCanvas(){return this.mouseLeavesCanvasSubject.asObservable()}observeClick(t=()=>!0){return this.clickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbClick(t=()=>!0){return this.dbClickSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeDbTap(t=()=>!0){return this.dbTapSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeWheel(t=()=>!0){return this.wheelSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchStart(t=()=>!0){return this.touchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchMove(t=()=>!0){return this.touchMoveSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeTouchEndDocument(){return this.touchEndSubject.asObservable()}observeTouchCancelDocument(){return this.touchCancelSubject.asObservable()}observeMouseDown(t=()=>!0){return this.mouseDownSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUp(t=()=>!0){return this.mouseUpSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeMouseUpDocument(t=()=>!0){return this.mouseUpDocumentSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeContextMenu(t=()=>!0){return this.contextMenuSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)),Do(e=>e.preventDefault()))}observeLongTouchStart(t=()=>!0){return this.longTouchStartSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeLongTouchEnd(t=()=>!0){return this.longTouchEndSubject.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}observeFastTouchScroll(t=()=>!0){return this.fastTouchScroll.asObservable().pipe(Z(()=>t(this.currentPoint.x,this.currentPoint.y)))}getCurrentPoint(){return this.currentPoint}};ws.DRAG_START_EVENTS=["mousedown","touchstart"],ws.DRAG_EVENTS=["mousemove","touchmove"],ws.DRAG_END_EVENTS=["mouseup","touchend","touchcancel"];let Jp=ws;var Qp=(function(n){z(t,n);function t(e,s,i){e===void 0&&(e=1/0),s===void 0&&(s=1/0),i===void 0&&(i=$s);var r=n.call(this)||this;return r._bufferSize=e,r._windowTime=s,r._timestampProvider=i,r._buffer=[],r._infiniteTimeWindow=!0,r._infiniteTimeWindow=s===1/0,r._bufferSize=Math.max(1,e),r._windowTime=Math.max(1,s),r}return t.prototype.next=function(e){var s=this,i=s.isStopped,r=s._buffer,o=s._infiniteTimeWindow,a=s._timestampProvider,l=s._windowTime;i||(r.push(e),!o&&r.push(a.now()+l)),this._trimBuffer(),n.prototype.next.call(this,e)},t.prototype._subscribe=function(e){this._throwIfClosed(),this._trimBuffer();for(var s=this._innerSubscribe(e),i=this,r=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),l=0;l<a.length&&!e.closed;l+=r?1:2)e.next(a[l]);return this._checkFinalizedStatuses(e),s},t.prototype._trimBuffer=function(){var e=this,s=e._bufferSize,i=e._timestampProvider,r=e._buffer,o=e._infiniteTimeWindow,a=(o?1:2)*s;if(s<1/0&&a<r.length&&r.splice(0,r.length-a),!o){for(var l=i.now(),c=0,h=1;h<r.length&&r[h]<=l;h+=2)c=h;c&&r.splice(0,c+1)}},t})(F);const Sn={};function tm(n){return Sn[n]||(Sn[n]=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:n,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})),Sn[n]}const da=(n,t=Date.now())=>{const s=tm(n).format(t),i=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(s);if(i){const r=Date.UTC(+i[3],+i[1]-1,+i[2],+i[4]%24,+i[5],+i[6]);let o=t;const a=o%1e3;return o-=a>=0?a:1e3+a,r-o}return 0},ua=60*1e3;class em{constructor(t){this.config=t,this.timeZoneChangedSubject=new Qp,this.currentTzOffset=e=>da(this.config.timezone,e)+new Date(e).getTimezoneOffset()*ua,this.formatterCache={},this.dateTimeFormatterFactory=this.initFormatterFactory(this.config.dateFormatter)}setTimeZone(t){this.config.timezone=t,this.formatterCache={},this.timeZoneChangedSubject.next(t)}observeTimeZoneChanged(){return this.timeZoneChangedSubject.asObservable()}initFormatterFactory(t){let e;if(t&&typeof t=="function")e=t;else if(t&&t.createFormatterFunction&&typeof t.createFormatterFunction=="function"){const s=t.createFormatterFunction;e=i=>s(i).bind(t)}else e=xu(this.config,this.tzOffset);return e}getFormatterFactory(){return this.dateTimeFormatterFactory}getDateTimeFormatter(t){return this.formatterCache[t]===void 0&&(this.formatterCache[t]=this.dateTimeFormatterFactory(t)),this.formatterCache[t]}tzOffset(t){return t?e=>new Date(e+da(t,e)+new Date(e).getTimezoneOffset()*ua):e=>new Date(e)}}class sm extends X{constructor(t,e,s){super(),this.hitTestCanvasModel=t,this.canvasAnimation=e,this.eventBus=s}doActivate(){super.doActivate(),this.addRxSubscription(this.canvasAnimation.animationInProgressSubject.subscribe(()=>{const t=this.canvasAnimation.animationInProgressSubject.getValue();this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(!t)})),this.addRxSubscription(this.hitTestCanvasModel.hitTestDrawersPredicateSubject.pipe(Tt((t,e)=>t!==e&&t===!0&&e===!1)).subscribe(()=>this.eventBus.fireDraw([this.hitTestCanvasModel.canvasId])))}}var nm=Object.defineProperty,im=Object.defineProperties,rm=Object.getOwnPropertyDescriptors,fa=Object.getOwnPropertySymbols,om=Object.prototype.hasOwnProperty,am=Object.prototype.propertyIsEnumerable,ga=(n,t,e)=>t in n?nm(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,lm=(n,t)=>{for(var e in t||(t={}))om.call(t,e)&&ga(n,e,t[e]);if(fa)for(var e of fa(t))am.call(t,e)&&ga(n,e,t[e]);return n},cm=(n,t)=>im(n,rm(t));class hm extends ai{constructor(t){super(t),this.animations={},this.animFrameId="animation",this.animationInProgressSubject=new ft(!1),this.microtaskQueued=!1}startViewportMovementAnimation(t,e,s=fe,i){const r=new ni(t,e,i);return this.animations[s]=r,this.processAnimation(),r}startColorAlphaAnimation(t,e,s,i){const r=new ei(cm(lm({},i),{duration:i&&i.duration||Ee}),e,s);return this.animations[t]=r,this.processAnimation(),r}startColorTransitionAnimation(t,e,s=Ee,i){const r=new si({duration:s},e,i);return this.animations[t]=r,this.processAnimation(),r}getAnimation(t){return this.animations[t]}getColorAlphaAnimation(t){return this.getAnimation(t)}getColorTransitionAnimation(t){return this.getAnimation(t)}forceStopAnimation(t){const e=this.animations[t];e&&(e.animationInProgress=!1,e.animationStartTime=0,delete this.animations[t]),Object.keys(this.animations).length===0&&this.stopInterval()}tick(){let t=!0;for(const e of Object.keys(this.animations)){const s=this.animations[e];s.tick(),s.animationInProgress&&(t=!1)}this.animationInProgressSubject.next(!t),t?this.stopInterval():this.microtaskQueued||(this.microtaskQueued=!0,queueMicrotask(()=>{this.microtaskQueued=!1,this.processAnimation(),this.eventBus.fireDraw()}))}stopInterval(){hl(this.animFrameId),this.microtaskQueued=!1}}class xn{constructor(t,e={}){this.components=[],this.chartComponents=[],this.userInputListenerComponents=[],this.canvasModels=[];var s,i;this.parentElement=t;const r=e;tc(r),this.config=r;const o=wc(r);t.innerHTML="",t.appendChild(o.content),this.id=(s=t.getAttribute("data-id"))!=null?s:"",r.fixedSize&&(t.style.width=r.fixedSize.width+"px",t.style.height=r.fixedSize.height+"px");const a=new em(r);this.timeZoneModel=a;const l=this.timeZoneModel.getFormatterFactory(),c=Sc(t);this.elements=c;const h=new vp;this.bus=h;const d=new Cp(t,(i=c.chartResizer)!=null?i:t,h,this.canvasModels,r);this.chartResizeHandler=d,d.subscribeResize(),this.components.push(d.unsubscribeAnimationUpdate.bind(d));const u=new bd(h,d);this.drawingManager=u;const f=md(h,c.mainCanvas,c.chartResizer,this.config.components.chart.type,this.config,u,this.canvasModels);this.mainCanvasModel=f,this.dynamicObjectsCanvasModel=le(h,c.dynamicObjectsCanvas,r,u,this.canvasModels,c.chartResizer);const g=new ye(this.dynamicObjectsCanvasModel);u.addDrawer(g,"SERIES_CLEAR");const m=le(h,c.yAxisLabelsCanvas,r,u,this.canvasModels,c.chartResizer),x=le(h,c.yAxisDescriptionsCanvas,r,u,this.canvasModels,c.chartResizer),_=new Zs(r,h,f,l,d);this.canvasBoundsContainer=_;const A=c.mainCanvas.parentElement;if(A===null)throw new Error("Couldn't get main canvas parent");const L=new Jp(h,A);this.canvasInputListener=L,this.chartComponents.push(this.canvasInputListener);const Y=[h,c.hitTestCanvas,L,_,u,r,this.canvasModels,c.chartResizer],H=new Hu(...Y);this.hitTestCanvasModel=H;const B=new ye(H);u.addDrawer(B,"HIT_TEST_CLEAR");const j=Ae?new hm(h):new ai(h);this.canvasAnimation=j;const $=M.PANE_UUID(K),W=new Mr(r,()=>_.getBounds($),j);this.scaleModel=W;const U=le(h,c.backgroundCanvas,r,u,this.canvasModels,c.chartResizer,{willReadFrequently:!0});this.backgroundCanvasModel=U,this.cursorHandler=new bc(c.canvasArea,L,_,H),this.chartComponents.push(this.cursorHandler),this.crossEventProducer=new Dp(L,_),this.chartComponents.push(this.crossEventProducer);const G=new eh("candle");this.chartBaseModel=G;const V=new xf(h,W,_,r,j,L,A,G,H);this.chartPanComponent=V,this.chartComponents.push(V),this.userInputListenerComponents.push(V.chartAreaPanHandler);const Q=new sm(H,j,h);this.hitTestComponent=Q,this.chartComponents.push(Q);const J=new ig(G,this.dynamicObjectsCanvasModel,this.userInputListenerComponents,h,W,_,r,j,L,u,this.cursorHandler,this.crossEventProducer,V,f,m,this.hitTestCanvasModel,this.chartResizeHandler);this.paneManager=J;const et=this.paneManager.panes[K];this.mainPane=et,this.chartComponents.push(J),this.dynamicObjects=new wu(this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.dynamicObjects),this.chartModel=new Qd(G,J,h,this.dynamicObjectsCanvasModel,r,W,l,A,_,d);const tt=new Fd(this.chartModel,this.dynamicObjectsCanvasModel,r,W,_,u,H,L,U,V,J,this.cursorHandler,this.dynamicObjects,this.chartResizeHandler);this.chartComponents.push(tt),this.chartComponent=tt;const st=this.chartComponent.chartModel;this.chartModel=st,this.canvasBoundsContainer.setMainCandleSeries(this.chartModel.mainCandleSeries),H.addSubscriber(J.hitTestController),this.xAxisComponent=new cp(h,r,f,tt,W,_,L,d,this.drawingManager,a,V,this.cursorHandler,this.hitTestCanvasModel),this.chartComponents.push(this.xAxisComponent),this.userInputListenerComponents.push(this.xAxisComponent.xAxisScaleHandler);const ut=new ye(f);u.addDrawer(ut,"MAIN_CLEAR");const lt=new bp(A,st,L,r);this.chartComponents.push(lt),this.watermarkComponent=new wg(J,st,h,r,_,this.dynamicObjectsCanvasModel,u),this.chartComponents.push(this.watermarkComponent);const xt=le(h,c.crossToolCanvas,r,u,this.canvasModels,c.chartResizer);this.highlightsComponent=new sf(h,r,st,f,_,u),this.chartComponents.push(this.highlightsComponent),r.useUTCTimeOverride&&r.dateFormatter&&!r.dateFormatter.utcTimeOverride&&(r.dateFormatter.utcTimeOverride=this.createUTCTimeOverrideConfig(st)),this.navigationMapComponent=new uf(h,st,f,r,L,_,u,l,V,this.cursorHandler),this.chartComponents.push(this.navigationMapComponent),this.userInputListenerComponents.push(this.navigationMapComponent.navigationMapMoveHandler);const Gt=new $u(r,this.dynamicObjectsCanvasModel,st,_,u);this.chartComponents.push(Gt),this.initYAxisDrawer(m,x),this.yAxisComponent=et.mainExtent.yAxis;const xe=new fp(this.chartModel,this.config,et.mainExtent.yAxis.state,this.chartModel.lastCandleLabelsByChartType,this.yAxisComponent.getLabelsColorResolver.bind(this.yAxisComponent));this.yAxisComponent.registerYAxisLabelsProvider(xe,ie.MAIN),this.volumesComponent=new pg(this.dynamicObjectsCanvasModel,tt,W,_,u,r,J,this.dynamicObjects),this.chartComponents.push(this.volumesComponent);const Ca=new go(f,W,r,this.yAxisComponent.state,"GRID",u,()=>this.canvasBoundsContainer.getBounds(M.ALL_PANES),()=>this.canvasBoundsContainer.getBounds($),()=>this.xAxisComponent.xAxisLabelsGenerator.labels,()=>[],void 0,void 0,()=>r.components.grid.visible,this.mainPane.mainExtent.idx);this.chartComponents.push(Ca),this.hoverProducer=new Np(this.crossEventProducer,W,r,st,L,this.canvasBoundsContainer,this.paneManager,a,V.mainCanvasTouchHandler,l),this.chartComponents.push(this.hoverProducer),this.crossToolComponent=new vu(r,xt,_,u,J,this.crossEventProducer,this.hoverProducer,this.chartComponent.baselineModel,this.chartModel),this.chartComponents.push(this.crossToolComponent);const ya=le(h,c.snapshotCanvas,r,u,this.canvasModels,c.chartResizer),_n=new rg(this.elements,ya);this.snapshotComponent=_n,this.chartComponents.push(_n);const xs=new Uu(r,this.dynamicObjectsCanvasModel,H,st,_,u,l,this.cursorHandler);this.eventsComponent=xs,this.chartComponents.push(xs),this.chartComponents.forEach(xm=>xm.activate()),this.enableUserControls(),u.reorderDrawers(r.drawingOrder),this.clearer=El(this.components)}initYAxisDrawer(t,e){const s=new on,i=new ye(t),r=new ye(e);s.addDrawer(i,"YAXIS_CLEAR"),s.addDrawer(r,"Y_AXIS_DESCRIPTIONS_CLEAR"),this.drawingManager.addDrawer(s,"Y_AXIS");const o=new pp(this.config,t,this.paneManager);s.addDrawer(o);const a=new gp(t,e,this.backgroundCanvasModel,this.canvasBoundsContainer,this.config,this.paneManager);this.drawingManager.addDrawer(a,"Y_AXIS_PRICE_LABELS")}createUTCTimeOverrideConfig(t){const e=new RegExp("HH|H|mm|m|s|ss|sss|SSS");return{pattern:"MM/dd/YY",test:s=>e.test(s)&&(t.getPeriod()||0)>=86400}}static mergeConfig(t,e){for(const s in e)s in t?typeof t[s]=="object"&&xn.mergeConfig(t[s],e[s]):t[s]=e[s];return t}getConfig(){return this.config}disableUserControls(){this.userInputListenerComponents.forEach(t=>t.deactivate()),this.hitTestCanvasModel.disableUserControls()}enableUserControls(){this.userInputListenerComponents.forEach(t=>t.activate()),this.hitTestCanvasModel.enableUserControls()}setGridConfig(t){var e,s,i,r,o;const a=this.config.components.grid;a.visible=(e=t.visible)!=null?e:!1,a.dash=(s=t.dash)!=null?s:[0,0],a.width=(i=t.width)!=null?i:1,a.color=(r=t.color)!=null?r:"#FFFFFF",this.config.colors.chartAreaTheme.gridColor=(o=t.color)!=null?o:"#FFFFFF",this.redraw()}setGridVisible(t){this.config.components&&this.config.components.grid&&(this.config.components.grid.visible=t,this.redraw())}setGridVertical(t){this.config.components.grid.vertical=t,this.redraw()}setGridHorizontal(t){this.config.components.grid.horizontal=t,this.redraw()}redraw(){this.bus.fireDraw()}getOffsets(){return this.config.components&&this.config.components.offsets}setShowCandleBorders(t=!0){this.config.components&&this.config.components.chart&&(this.config.components.chart.showCandlesBorder=t,this.redraw())}setHighLowVisible(t=!0){this.config.components&&this.config.components.highLow&&(this.config.components.highLow.visible=t,this.redraw())}setCrossToolVisible(t="cross-and-labels"){this.config.components&&this.config.components.crossTool&&(this.config.components.crossTool.type=t,this.redraw())}setHighlightsVisible(t=!0){var e;(e=this.config.components)!=null&&e.highlights&&(this.config.components.highlights.visible=t,this.redraw())}setHighlightsData(t){this.highlightsComponent.setHighlights(t)}setColors(t){At(this.config.colors,t,{addIfMissing:!0,overrideExisting:!0}),this.redraw()}addMouseMoveOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeMouseMove(s).subscribe(e);return()=>i.unsubscribe()}addMouseEnterOnChartElementHandler(t,e,s=!1){const i=this.canvasBoundsContainer.getBoundsHitTest(t),r=this.canvasInputListener.observeMouseEnter(i,s).subscribe(e);return()=>r.unsubscribe()}addClickOnChartElementHandler(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=this.canvasInputListener.observeClick(s).subscribe(e);return()=>i.unsubscribe()}addDragEventsListener(t,e){const s=this.canvasBoundsContainer.getBoundsHitTest(t),i=yt(this.canvasInputListener.observeYDrag(s),this.canvasInputListener.observeXDrag(s)).subscribe(e);return()=>i.unsubscribe()}registerComponent(t,e){const s=t(this);this.components.push(s),e&&e(s),s.activate()}}class pa extends xn{constructor(t,e={}){super(t,e),this.yAxis=this.yAxisComponent,this.xAxis=this.xAxisComponent,this.watermark=this.watermarkComponent,this.highlights=this.highlightsComponent,this.events=this.eventsComponent,this.snapshot=this.snapshotComponent,this.crosshair=this.crossToolComponent,this.navigationMap=this.navigationMapComponent,this.volumes=this.volumesComponent,this.cursors=this.cursorHandler,this.data=this.chartComponent,this.scale=this.scaleModel,this.panning=this.chartPanComponent,this.bounds=this.canvasBoundsContainer,this.hover=this.hoverProducer}registerPaneFormatters(t,e){var s;(s=this.paneManager.panes[t])==null||s.setPaneValueFormatters(e)}destroy(){this.bus.setMuted(!0),this.chartComponents.forEach(t=>t.disable()),this.parentElement.childNodes.forEach(t=>t.remove()),this.parentElement.style.width="",this.parentElement.style.height=""}showSeparateVolumes(t=!1){this.volumes&&(this.volumes.setShowVolumesSeparatly(t),this.bounds.updateYAxisWidths())}setData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.setAllSeries(e,s)}else this.chartComponent.setMainSeries(t)}updateData(t){if(Array.isArray(t)){if(t.length===0)return;const[e,...s]=t;this.chartComponent.updateAllSeries(e,s)}else this.chartComponent.updateAllSeries(t)}setAutoScale(t=!0){this.scale.autoScale(t)}setRtl(t){this.config.rtl=t,this.bus.fireDraw()}setChartType(t){this.data.setChartType(t),this.yAxis.updateOrderedLabels()}setTreasuryFormat(t){this.config.components.yAxis.treasuryFormat=t,this.paneManager.yExtents.forEach(e=>{e.yAxis.model.labelsGenerator.updateTreasuryFormat(t),e.yAxis.model.labelsGenerator.doGenerateLabels(),e.yAxis.model.fancyLabelsModel.updateLabels(!0),e.yAxis.model.baseLabelsModel.updateLabels()})}createPane(){return this.paneManager.createPane()}}var dm=Object.defineProperty,um=Object.defineProperties,fm=Object.getOwnPropertyDescriptors,ma=Object.getOwnPropertySymbols,gm=Object.prototype.hasOwnProperty,pm=Object.prototype.propertyIsEnumerable,va=(n,t,e)=>t in n?dm(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,mm=(n,t)=>{for(var e in t||(t={}))gm.call(t,e)&&va(n,e,t[e]);if(ma)for(var e of ma(t))pm.call(t,e)&&va(n,e,t[e]);return n},vm=(n,t)=>um(n,fm(t));function ba(n){n=n||{},n.quantity=n.quantity||200,n.startY=n.startY||50,n.avgCandleSize=n.avgCandleSize||2,n.avgTrendLength=n.avgTrendLength||{},n.avgTrendLength.sw=n.avgTrendLength.sw||10,n.avgTrendLength.down=n.avgTrendLength.down||10,n.avgTrendLength.up=n.avgTrendLength.up||10,n.withVolume=n.withVolume===!0||!1,n.period=n.period||3600;var t=[],e=n.quantity||200,s=10,i=10,r=10;n.avgTrendLength&&(s=n.avgTrendLength.sw||10,i=n.avgTrendLength.down||10,r=n.avgTrendLength.up||10);var o=n.startY||50,a=n.avgCandleSize||2,l=o-a,c=o+a,h=Ss(l,c,a);for(t.push(h);t.length<e;){var d=Math.random()*10;d>6?t=t.concat(ym(t[t.length-1],a,s)):d>3?t=t.concat(bm(t[t.length-1],a,r)):t=t.concat(Cm(t[t.length-1],a,i))}t=t.slice(0,n.quantity);let u=Math.round(new Date().getTime()/3e5)*3e5;u-=e*1e3*n.period;for(let f=0;f<t.length;f++){const g=t[f];Object.assign(g,{timestamp:u,isVisible:!0}),u+=1e3*n.period,n.withVolume&&(g.volume=Math.ceil(Math.random()*1e3+200))}return t}function Ss(n,t,e,s){var i=Math.random()*(t-n)+n,r;if(s&&s==="bull"||!s&&Math.random()>.5){var o=i+e;r=o<t?o:t}else{var a=i-e;r=a>n?a:n}var l=Math.max(i,r)+Math.random()*e*.2,c=Math.min(i,r)-Math.random()*e*.2;return{id:xi(0,l+c+i+r),hi:l,lo:c,open:i,close:r,timestamp:0,volume:0}}function bm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.lo,o=n.hi+t*1.2,a=0;a<i;a++){var l=Math.random()>.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.1+.1),o=c.hi+t*(Math.random()*1.3+.1),Math.random()>.9&&(o=c.hi+t),s.push(c)}return s}function Cm(n,t,e){for(var s=[],i=Math.random()*e+e/2,r=n.hi-t*1.2,o=n.hi,a=0;a<i;a++){var l=Math.random()<.9?"bear":"bull",c=Ss(r,o,t,l);r=c.lo-t*(Math.random()*.3+.1),o=c.hi-t*(Math.random()*.1+.1),Math.random()>.9&&(o=c.lo-t),s.push(c)}return s}function ym(n,t,e){var s=[],i=Math.random()*e+e/2;function r(u){var f,g;return Math.random()>.5?(f=u.lo-t*.2,g=u.hi+t*1.2):(f=u.lo-t*1.2,g=u.hi+t*.2),{from:f,to:g}}for(var o=r(n),a=o.from,l=o.to,c=0;c<i;c++){var h=Math.random()<.5?"bear":"bull",d=Ss(a,l,t,h);o=r(d),a=o.from,l=o.to,Math.random()>.9&&(Math.random()>.5?a=d.lo-t:l=d.hi+t),s.push(d)}return s}window.DXChart=vm(mm({},window.DXChart),{generateCandlesData:ba});function wm(n){return ba(n)}const Sm=((n,t={})=>new pa(n,t))})(),window.DXChart=Ps})();})();